lots and lots of code cleanup.

This commit is contained in:
pavlov%pavlov.net 1998-12-19 18:04:06 +00:00
Родитель 0a03230a26
Коммит 340357e342
17 изменённых файлов: 248 добавлений и 388 удалений

Просмотреть файл

@ -62,14 +62,9 @@ CPPSRCS= \
nsWidget.cpp \
nsWindow.cpp
CSRCS = gtklayout.c \
$(NULL)
TARGETS = $(LIBRARY)
MKSHLIB :=
include $(topsrcdir)/config/rules.mk
gtklayout.o nsWindow.o: gtklayout.h

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -80,39 +80,6 @@ nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
return nsWidget::QueryInterface(aIID,aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Armed
//
//-------------------------------------------------------------------------
void nsCheckButton::Armed()
{
mIsArmed = PR_TRUE;
mValueWasSet = PR_FALSE;
mInitialState = GTK_TOGGLE_BUTTON(mWidget)->active;
}
//-------------------------------------------------------------------------
//
// DisArmed
//
//-------------------------------------------------------------------------
void nsCheckButton::DisArmed()
{
if (mValueWasSet) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), PR_TRUE);
/*
XmToggleButtonSetState(mWidget, mNewValue, PR_TRUE);
*/
} else {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), PR_TRUE);
/*
XmToggleButtonSetState(mWidget, mInitialState, PR_TRUE);
*/
}
mIsArmed = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Set this button label
@ -120,11 +87,6 @@ void nsCheckButton::DisArmed()
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::SetState(const PRBool aState)
{
int state = aState;
if (mIsArmed) {
mNewValue = aState;
mValueWasSet = PR_TRUE;
}
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), aState);
return NS_OK;
}
@ -136,16 +98,8 @@ NS_METHOD nsCheckButton::SetState(const PRBool aState)
//-------------------------------------------------------------------------
NS_METHOD nsCheckButton::GetState(PRBool& aState)
{
int state = GTK_TOGGLE_BUTTON(mWidget)->active;
if (mIsArmed) {
if (mValueWasSet) {
aState = mNewValue;
} else {
gint state = GTK_TOGGLE_BUTTON(mWidget)->active;
aState = state;
}
} else {
aState = state;
}
return NS_OK;
}

Просмотреть файл

@ -49,20 +49,9 @@ public:
virtual PRBool OnPaint(nsPaintEvent &aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
// These are needed to Override the auto check behavior
void Armed();
void DisArmed();
protected:
NS_IMETHOD nsCheckButton::CreateNative(GtkWidget *parentWindow);
GtkWidget *mLabel;
private:
PRBool mInitialState;
PRBool mNewValue;
PRBool mValueWasSet;
PRBool mIsArmed;
};
#endif // nsCheckButton_h__

Просмотреть файл

@ -42,7 +42,7 @@ nsComboBox::nsComboBox() : nsWidget(), nsIListWidget(), nsIComboBox()
{
NS_INIT_REFCNT();
mMultiSelect = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
// mBackground = NS_RGB(124, 124, 124);
mItems = nsnull;
mNumItems = 0;

Просмотреть файл

@ -360,6 +360,7 @@ gint nsGtkWidget_Toggle_Callback(GtkWidget *w, gpointer p)
//==============================================================
gint nsGtkWidget_CheckButton_Toggle_Callback(GtkWidget *w, gpointer p)
{
#if 0
nsCheckButton *checkBtn = (nsCheckButton*)gtk_object_get_user_data(GTK_OBJECT(w));
if (GTK_TOGGLE_BUTTON(w)->active)
checkBtn->Armed();
@ -367,6 +368,7 @@ gint nsGtkWidget_CheckButton_Toggle_Callback(GtkWidget *w, gpointer p)
checkBtn->DisArmed();
return PR_FALSE;
#endif
}
//==============================================================
@ -406,7 +408,6 @@ gint nsGtkWidget_RadioButton_DisArmCallback(GtkWidget *w, gpointer p)
//==============================================================
gint nsGtkWidget_Scrollbar_Callback(GtkWidget *w, gpointer p)
{
// nsScrollbar *widget = (nsScrollbar*)gtk_object_get_user_data(GTK_OBJECT(w));
nsScrollbar *widget = (nsScrollbar*) p;
nsScrollbarEvent sevent;

Просмотреть файл

@ -36,7 +36,7 @@ nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
{
NS_INIT_REFCNT();
mMultiSelect = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
// mBackground = NS_RGB(124, 124, 124);
}
//-------------------------------------------------------------------------
@ -46,6 +46,11 @@ nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox()
//-------------------------------------------------------------------------
nsListBox::~nsListBox()
{
if (mCList)
{
::gtk_widget_destroy(mCList);
mCList = nsnull;
}
}
//-------------------------------------------------------------------------
@ -337,7 +342,7 @@ NS_METHOD nsListBox::CreateNative(GtkWidget *parentWindow)
gtk_widget_set_name(mWidget, "nsListBox");
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (mWidget),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_ALWAYS);
GTK_POLICY_AUTOMATIC);
mCList = ::gtk_clist_new(1);
gtk_clist_column_titles_hide(GTK_CLIST(mCList));

Просмотреть файл

@ -37,6 +37,7 @@ NS_IMPL_RELEASE(nsRadioButton)
nsRadioButton::nsRadioButton() : nsWidget(), nsIRadioButton()
{
NS_INIT_REFCNT();
mLabel = nsnull;
}
@ -82,35 +83,6 @@ NS_METHOD nsRadioButton::CreateNative(GtkWidget *parentWindow)
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Armed
//
//-------------------------------------------------------------------------
void nsRadioButton::Armed()
{
mIsArmed = PR_TRUE;
mValueWasSet = PR_FALSE;
mInitialState = GTK_TOGGLE_BUTTON(mWidget)->active;
}
//-------------------------------------------------------------------------
//
// DisArmed
//
//-------------------------------------------------------------------------
void nsRadioButton::DisArmed()
{
if (mValueWasSet) {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), PR_TRUE);
// XmToggleButtonSetState(mRadioBtn, mNewValue, PR_TRUE);
} else {
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), PR_TRUE);
// XmToggleButtonSetState(mRadioBtn, mInitialState, PR_TRUE);
}
mIsArmed = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Set this button label
@ -118,12 +90,6 @@ void nsRadioButton::DisArmed()
//-------------------------------------------------------------------------
NS_METHOD nsRadioButton::SetState(const PRBool aState)
{
int state = aState;
if (mIsArmed) {
mNewValue = aState;
mValueWasSet = PR_TRUE;
}
// XmToggleButtonSetState(mRadioBtn, aState, PR_TRUE);
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(mWidget), aState);
return NS_OK;
}
@ -134,18 +100,9 @@ NS_METHOD nsRadioButton::SetState(const PRBool aState)
//-------------------------------------------------------------------------
NS_METHOD nsRadioButton::GetState(PRBool& aState)
{
// int state = XmToggleButtonGetState(mRadioBtn);
int state = GTK_TOGGLE_BUTTON(mWidget)->active;
if (mIsArmed) {
if (mValueWasSet) {
return mNewValue;
} else {
return state;
}
} else {
return state;
}
}
//-------------------------------------------------------------------------
//

Просмотреть файл

@ -59,12 +59,6 @@ protected:
NS_IMETHOD nsRadioButton::CreateNative(GtkWidget *parentWindow);
GtkWidget *mLabel;
private:
PRBool mInitialState;
PRBool mNewValue;
PRBool mValueWasSet;
PRBool mIsArmed;
};
#endif // nsRadioButton_h__

Просмотреть файл

@ -1,5 +1,5 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
@ -41,35 +41,6 @@ nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWidget(), nsIScrollbar()
GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
}
//-------------------------------------------------------------------------
//
// Create the native scrollbar widget
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::CreateNative(GtkWidget *parentWindow)
{
// Create scrollbar, random default values
mAdjustment = gtk_adjustment_new(0, 0, 100, 1, 25, 25);
if (mOrientation == GTK_ORIENTATION_HORIZONTAL) {
mWidget = gtk_hscrollbar_new(GTK_ADJUSTMENT(mAdjustment));
} else {
mWidget = gtk_vscrollbar_new(GTK_ADJUSTMENT(mAdjustment));
}
gtk_widget_set_name(mWidget, "nsScrollbar");
gtk_object_set_user_data(GTK_OBJECT(mAdjustment), mWidget);
gtk_signal_connect(GTK_OBJECT (mAdjustment),
"changed",
GTK_SIGNAL_FUNC(nsGtkWidget_Scrollbar_Callback),
this);
gtk_signal_connect(GTK_OBJECT (mAdjustment),
"value_changed",
GTK_SIGNAL_FUNC(nsGtkWidget_Scrollbar_Callback),
this);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// nsScrollbar destructor
@ -79,6 +50,36 @@ nsScrollbar::~nsScrollbar()
{
}
//-------------------------------------------------------------------------
//
// Create the native scrollbar widget
//
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::CreateNative (GtkWidget * parentWindow)
{
// Create scrollbar, random default values
mAdjustment = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 1, 25, 25));
switch (mOrientation)
{
case GTK_ORIENTATION_HORIZONTAL:
mWidget = gtk_hscrollbar_new (mAdjustment);
break;
case GTK_ORIENTATION_VERTICAL:
mWidget = gtk_vscrollbar_new (mAdjustment);
break;
}
gtk_widget_set_name (mWidget, "nsScrollbar");
gtk_signal_connect (GTK_OBJECT (mAdjustment),
"value_changed",
GTK_SIGNAL_FUNC (nsGtkWidget_Scrollbar_Callback),
this);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Query interface implementation
@ -86,7 +87,8 @@ nsScrollbar::~nsScrollbar()
//-------------------------------------------------------------------------
nsresult nsScrollbar::QueryInterface (const nsIID & aIID, void **aInstancePtr)
{
if (aInstancePtr == NULL) {
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
@ -95,7 +97,8 @@ nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr)
static NS_DEFINE_IID (kInsScrollbarIID, NS_ISCROLLBAR_IID);
// if not asking for parent, check for our interface IID
if (result == NS_NOINTERFACE && aIID.Equals(kInsScrollbarIID)) {
if (result == NS_NOINTERFACE && aIID.Equals (kInsScrollbarIID))
{
*aInstancePtr = (void *) ((nsIScrollbar *) this);
AddRef ();
result = NS_OK;
@ -111,7 +114,7 @@ nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr)
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetMaxRange (PRUint32 aEndRange)
{
GTK_ADJUSTMENT(mAdjustment)->upper = aEndRange;
GTK_ADJUSTMENT (mAdjustment)->upper = (float) aEndRange;
gtk_signal_emit_by_name (GTK_OBJECT (mAdjustment), "changed");
return NS_OK;
}
@ -136,7 +139,7 @@ NS_METHOD nsScrollbar::GetMaxRange(PRUint32 & aMaxRange)
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetPosition (PRUint32 aPos)
{
gtk_adjustment_set_value(GTK_ADJUSTMENT(mAdjustment), aPos);
gtk_adjustment_set_value (GTK_ADJUSTMENT (mAdjustment), (float) aPos);
return NS_OK;
}
@ -160,9 +163,10 @@ NS_METHOD nsScrollbar::GetPosition(PRUint32 & aPos)
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetThumbSize (PRUint32 aSize)
{
if (aSize > 0) {
GTK_ADJUSTMENT(mAdjustment)->page_increment = aSize;
GTK_ADJUSTMENT(mAdjustment)->page_size = aSize;
if (aSize > 0)
{
GTK_ADJUSTMENT (mAdjustment)->page_increment = (float) aSize;
GTK_ADJUSTMENT (mAdjustment)->page_size = (float) aSize;
gtk_signal_emit_by_name (GTK_OBJECT (mAdjustment), "changed");
}
return NS_OK;
@ -188,8 +192,9 @@ NS_METHOD nsScrollbar::GetThumbSize(PRUint32 & aThumbSize)
//-------------------------------------------------------------------------
NS_METHOD nsScrollbar::SetLineIncrement (PRUint32 aLineIncrement)
{
if (aLineIncrement > 0) {
GTK_ADJUSTMENT(mAdjustment)->step_increment = aLineIncrement;
if (aLineIncrement > 0)
{
GTK_ADJUSTMENT (mAdjustment)->step_increment = (float) aLineIncrement;
gtk_signal_emit_by_name (GTK_OBJECT (mAdjustment), "changed");
}
return NS_OK;
@ -275,7 +280,8 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
PRBool result = PR_TRUE;
float newPosition;
switch (aEvent.message) {
switch (aEvent.message)
{
// scroll one line right or down
case NS_SCROLLBAR_LINE_NEXT:
@ -293,8 +299,9 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = newPosition;
if (mEventCallback)
{
aEvent.position = (PRUint32) newPosition;
result = ConvertStatus ((*mEventCallback) (&aEvent));
newPosition = aEvent.position;
}
@ -314,8 +321,9 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
// if an event callback is registered, give it the chance
// to change the decrement
if (mEventCallback) {
aEvent.position = newPosition;
if (mEventCallback)
{
aEvent.position = (PRUint32) newPosition;
aEvent.widget = (nsWidget *) this;
result = ConvertStatus ((*mEventCallback) (&aEvent));
newPosition = aEvent.position;
@ -338,8 +346,9 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = newPosition;
if (mEventCallback)
{
aEvent.position = (PRUint32) newPosition;
result = ConvertStatus ((*mEventCallback) (&aEvent));
newPosition = aEvent.position;
}
@ -355,8 +364,9 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = newPosition;
if (mEventCallback)
{
aEvent.position = (PRUint32) newPosition;
result = ConvertStatus ((*mEventCallback) (&aEvent));
newPosition = aEvent.position;
}
@ -372,8 +382,9 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
// if an event callback is registered, give it the chance
// to change the increment
if (mEventCallback) {
aEvent.position = newPosition;
if (mEventCallback)
{
aEvent.position = (PRUint32) newPosition;
result = ConvertStatus ((*mEventCallback) (&aEvent));
newPosition = aEvent.position;
}

Просмотреть файл

@ -61,7 +61,7 @@ protected:
private:
int mOrientation;
GtkObject* mAdjustment;
GtkAdjustment *mAdjustment;
int AdjustScrollBarPosition(int aPosition);
};

Просмотреть файл

@ -125,7 +125,6 @@ NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
{
mIsPassword = aIsPassword?PR_FALSE:PR_TRUE;
if (GTK_IS_ENTRY(mWidget)) {
g_print("gtk_entry_set_visibility(GTK_ENTRY(%p), %d);\n",mWidget, mIsPassword);
gtk_entry_set_visibility(GTK_ENTRY(mWidget), mIsPassword);
}
// this won't work for gtk_texts
@ -139,7 +138,6 @@ NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldReadOnlyF
"SetReadOnly - Widget is NULL, Create may not have been called!");
aOldReadOnlyFlag = mIsReadOnly;
mIsReadOnly = aReadOnlyFlag?PR_FALSE:PR_TRUE;
g_print("gtk_editable_set_editable(GTK_EDITABLE(%p), %d);\n",mWidget, mIsReadOnly);
gtk_editable_set_editable(GTK_EDITABLE(mWidget), mIsReadOnly);
return NS_OK;
}

Просмотреть файл

@ -19,6 +19,27 @@
#include "nsToolkit.h"
#include "nsGUIEvent.h"
//-------------------------------------------------------------------------
//
// constructor
//
//-------------------------------------------------------------------------
nsToolkit::nsToolkit()
{
NS_INIT_REFCNT();
/* XSetErrorHandler(nsToolkitErrorHandler); */
}
//-------------------------------------------------------------------------
//
// destructor
//
//-------------------------------------------------------------------------
nsToolkit::~nsToolkit()
{
}
void RunPump(void* arg)
{
}
@ -41,27 +62,6 @@ void RunPump(void* arg)
//}
//-------------------------------------------------------------------------
//
// constructor
//
//-------------------------------------------------------------------------
nsToolkit::nsToolkit()
{
NS_INIT_REFCNT();
/* XSetErrorHandler(nsToolkitErrorHandler); */
}
//-------------------------------------------------------------------------
//
// destructor
//
//-------------------------------------------------------------------------
nsToolkit::~nsToolkit()
{
}
//-------------------------------------------------------------------------
//
// nsISupports implementation macro

Просмотреть файл

@ -58,6 +58,13 @@ nsWidget::nsWidget()
nsWidget::~nsWidget()
{
if (mWidget)
{
if (GTK_IS_WIDGET(mWidget))
gtk_widget_destroy(mWidget);
mWidget = nsnull;
}
nsBaseWidget::Destroy();
}
NS_METHOD nsWidget::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect)
@ -81,6 +88,7 @@ NS_METHOD nsWidget::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect)
NS_IMETHODIMP nsWidget::Destroy(void)
{
::gtk_widget_destroy(mWidget);
mWidget = nsnull;
return NS_OK;
}
@ -132,7 +140,9 @@ NS_METHOD nsWidget::Show(PRBool bState)
NS_METHOD nsWidget::IsVisible(PRBool &aState)
{
gint RealVis = GTK_WIDGET_VISIBLE(mWidget);
aState = mShown;
g_return_val_if_fail(RealVis == mShown, NS_ERROR_FAILURE);
return NS_OK;
}
@ -219,47 +229,6 @@ NS_METHOD nsWidget::GetBounds(nsRect &aRect)
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the foreground color
//
//-------------------------------------------------------------------------
nscolor nsWidget::GetForegroundColor(void)
{
/* can we safely cache this? */
return mForeground;
}
//-------------------------------------------------------------------------
//
// Set the foreground color
//
//-------------------------------------------------------------------------
NS_METHOD nsWidget::SetForegroundColor(const nscolor &aColor)
{
GtkStyle *style;
GdkColor color;
mForeground = aColor;
NSCOLOR_TO_GDKCOLOR(color, aColor);
style = gtk_style_copy(mWidget->style);
style->fg[GTK_STATE_NORMAL] = color;
gtk_widget_set_style(mWidget, style);
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get the background color
//
//-------------------------------------------------------------------------
nscolor nsWidget::GetBackgroundColor(void)
{
/* can we safely cache this? */
return mBackground;
}
//-------------------------------------------------------------------------
//
// Set the background color
@ -271,6 +240,9 @@ NS_METHOD nsWidget::SetBackgroundColor(const nscolor &aColor)
GdkColor color;
mBackground = aColor;
nsBaseWidget::SetBackgroundColor(aColor);
/* FIXME do we need the rest of this? (look at the windows code) */
NSCOLOR_TO_GDKCOLOR(color, aColor);
#ifdef DBG
g_print("nsWidget::SetBackgroundColor %d %d %d\n", color.red, color.blue, color.green);
@ -304,17 +276,6 @@ NS_METHOD nsWidget::SetFont(const nsFont &aFont)
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Get this component cursor
//
//-------------------------------------------------------------------------
nsCursor nsWidget::GetCursor(void)
{
NS_NOTYETIMPLEMENTED("nsWidget::GetCursor");
return eCursor_standard;
}
//-------------------------------------------------------------------------
//
// Set this component cursor

Просмотреть файл

@ -74,20 +74,15 @@ class nsWidget : public nsBaseWidget
NS_IMETHOD GetBounds(nsRect &aRect);
nscolor GetForegroundColor(void);
NS_IMETHOD SetForegroundColor(const nscolor &aColor);
nscolor GetBackgroundColor(void);
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
nsIFontMetrics *GetFont(void);
NS_IMETHOD SetFont(const nsFont &aFont);
nsCursor GetCursor(void);
NS_IMETHOD SetCursor(nsCursor aCursor);
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
void* GetNativeData(PRUint32 aDataType);
nsIRenderingContext *GetRenderingContext(void);
nsIDeviceContext *GetDeviceContext(void);

Просмотреть файл

@ -548,8 +548,8 @@ NS_METHOD nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect)
GtkAdjustment* vert = gtk_layout_get_vadjustment(GTK_LAYOUT(mWidget));
horiz->value -= aDx;
vert->value -= aDy;
gtk_signal_emit_by_name(GTK_OBJECT(horiz), "value_changed");
gtk_signal_emit_by_name(GTK_OBJECT(vert), "value_changed");
gtk_adjustment_value_changed(horiz);
gtk_adjustment_value_changed(vert);
}
return NS_OK;
}