mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-23 18:26:15 +00:00
Fix for bug 6159. Reviewed by pollmann and approved by leaf.
Form check boxes were out of whack by one. I removed the pathetically lame hack i added before (which didn't work) and added a new and improved pathetically dumb hack that really fixes the problem. Yes folks, toggle the toggle button 3 times to work around artificial intelligence in the gtktogglebutton widget.
This commit is contained in:
parent
8f55891950
commit
7230523635
@ -33,7 +33,6 @@ nsCheckButton::nsCheckButton() : nsWidget() , nsICheckButton()
|
||||
mLabel = nsnull;
|
||||
mCheckButton = nsnull;
|
||||
mState = PR_FALSE;
|
||||
mFirstTime = PR_TRUE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
@ -103,6 +102,10 @@ void nsCheckButton::InitCallbacks(char * aName)
|
||||
"destroy",
|
||||
GTK_SIGNAL_FUNC(DestroySignal),
|
||||
this);
|
||||
|
||||
InstallSignal(mCheckButton,
|
||||
"toggled",
|
||||
GTK_SIGNAL_FUNC(nsCheckButton::ToggledSignal));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -136,10 +139,13 @@ NS_METHOD nsCheckButton::SetState(const PRBool aState)
|
||||
{
|
||||
mState = aState;
|
||||
|
||||
if (mWidget && mCheckButton)
|
||||
if (mWidget && mCheckButton)
|
||||
{
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mCheckButton),
|
||||
(gboolean) mState);
|
||||
GtkToggleButton * item = GTK_TOGGLE_BUTTON(mCheckButton);
|
||||
|
||||
item->active = (gboolean) mState;
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(item));
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@ -153,17 +159,6 @@ NS_METHOD nsCheckButton::SetState(const PRBool aState)
|
||||
NS_METHOD nsCheckButton::GetState(PRBool& aState)
|
||||
{
|
||||
aState = mState;
|
||||
|
||||
// Pathetically lame hack to work around artificial intelligence
|
||||
// in the GtkToggleButton widget. Because the gtk toggle widget
|
||||
// changes its state on button press, we are out of whack by one
|
||||
//
|
||||
if (mFirstTime)
|
||||
{
|
||||
mFirstTime = PR_FALSE;
|
||||
|
||||
aState = !mState;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -212,3 +207,34 @@ NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* virtual */ void
|
||||
nsCheckButton::OnToggledSignal(const gboolean aState)
|
||||
{
|
||||
// Untoggle the sonofabitch
|
||||
if (mWidget && mCheckButton)
|
||||
{
|
||||
GtkToggleButton * item = GTK_TOGGLE_BUTTON(mCheckButton);
|
||||
|
||||
item->active = !item->active;
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(item));
|
||||
}
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* static */ gint
|
||||
nsCheckButton::ToggledSignal(GtkWidget * aWidget,
|
||||
gpointer aData)
|
||||
{
|
||||
NS_ASSERTION( nsnull != aWidget, "widget is null");
|
||||
|
||||
nsCheckButton * button = (nsCheckButton *) aData;
|
||||
|
||||
NS_ASSERTION( nsnull != button, "instance pointer is null");
|
||||
|
||||
button->OnToggledSignal(GTK_TOGGLE_BUTTON(aWidget)->active);
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
virtual PRBool OnPaint(nsPaintEvent & aEvent) { return PR_FALSE; }
|
||||
virtual PRBool OnResize(nsRect &aRect) { return PR_FALSE; }
|
||||
|
||||
virtual void OnToggledSignal(const gboolean aState);
|
||||
|
||||
protected:
|
||||
NS_IMETHOD CreateNative(GtkWidget *parentWindow);
|
||||
@ -63,8 +64,10 @@ protected:
|
||||
// gecko check controlling frame.
|
||||
PRBool mState;
|
||||
|
||||
// See GetState()
|
||||
PRBool mFirstTime;
|
||||
private:
|
||||
|
||||
static gint ToggledSignal(GtkWidget * aWidget,
|
||||
gpointer aData);
|
||||
};
|
||||
|
||||
#endif // nsCheckButton_h__
|
||||
|
@ -1153,12 +1153,11 @@ nsWidget::InstallRealizeSignal(GtkWidget * aWidget)
|
||||
|
||||
#undef TRACE_MOUSE_EVENTS
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
static void
|
||||
DebugPrintMouseEvent(nsMouseEvent & aEvent,
|
||||
char * sMessage,
|
||||
nsWidget * aInstance,
|
||||
GtkWidget * aGtkWidget)
|
||||
#ifdef DEBUG
|
||||
void
|
||||
nsWidget::DebugPrintMouseEvent(nsMouseEvent & aEvent,
|
||||
char * sMessage,
|
||||
GtkWidget * aGtkWidget)
|
||||
{
|
||||
char * eventName = nsnull;
|
||||
|
||||
@ -1233,13 +1232,13 @@ DebugPrintMouseEvent(nsMouseEvent & aEvent,
|
||||
printf("%4d %s(this=%p,name=%s,event=%s,x=%d,y=%d)\n",
|
||||
sPrintCount++,
|
||||
sMessage,
|
||||
aInstance,
|
||||
this,
|
||||
gtk_widget_get_name(aGtkWidget),
|
||||
eventName,
|
||||
aEvent.point.x,
|
||||
aEvent.point.y);
|
||||
}
|
||||
#endif // TRACE_MOUSE_EVENTS
|
||||
#endif // DEBUG
|
||||
//////////////////////////////////////////////////////////////////
|
||||
/* virtual */ void
|
||||
nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent)
|
||||
@ -1301,7 +1300,7 @@ nsWidget::OnMotionNotifySignal(GdkEventMotion * aGdkMotionEvent)
|
||||
}
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
DebugPrintMouseEvent(event,"Motion",this,mWidget);
|
||||
DebugPrintMouseEvent(event,"Motion",mWidget);
|
||||
#endif
|
||||
|
||||
AddRef();
|
||||
@ -1340,7 +1339,7 @@ nsWidget::OnEnterNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
|
||||
}
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
DebugPrintMouseEvent(event,"Enter",this,mWidget);
|
||||
DebugPrintMouseEvent(event,"Enter",mWidget);
|
||||
#endif
|
||||
|
||||
AddRef();
|
||||
@ -1379,7 +1378,7 @@ nsWidget::OnLeaveNotifySignal(GdkEventCrossing * aGdkCrossingEvent)
|
||||
}
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
DebugPrintMouseEvent(event,"Leave",this,mWidget);
|
||||
DebugPrintMouseEvent(event,"Leave",mWidget);
|
||||
#endif
|
||||
|
||||
AddRef();
|
||||
@ -1458,7 +1457,7 @@ nsWidget::OnButtonPressSignal(GdkEventButton * aGdkButtonEvent)
|
||||
InitMouseEvent(aGdkButtonEvent, event, eventType);
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
DebugPrintMouseEvent(event,"ButtonPress",this,mWidget);
|
||||
DebugPrintMouseEvent(event,"ButtonPress",mWidget);
|
||||
#endif
|
||||
|
||||
// Set the button motion target and remeber the widget and root coords
|
||||
@ -1506,7 +1505,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent)
|
||||
InitMouseEvent(aGdkButtonEvent, event, eventType);
|
||||
|
||||
#ifdef TRACE_MOUSE_EVENTS
|
||||
DebugPrintMouseEvent(event,"ButtonRelease",this,mWidget);
|
||||
DebugPrintMouseEvent(event,"ButtonRelease",mWidget);
|
||||
#endif
|
||||
|
||||
if (nsnull != sButtonMotionTarget)
|
||||
@ -1527,7 +1526,7 @@ nsWidget::OnButtonReleaseSignal(GdkEventButton * aGdkButtonEvent)
|
||||
/* virtual */ void
|
||||
nsWidget::OnRealize()
|
||||
{
|
||||
printf("nsWidget::OnRealize(%p)\n",this);
|
||||
// printf("nsWidget::OnRealize(%p)\n",this);
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -223,6 +223,9 @@ private:
|
||||
static gint RealizeSignal(GtkWidget * aWidget,
|
||||
gpointer aData);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// GTK event support methods
|
||||
@ -239,7 +242,12 @@ private:
|
||||
nsMouseEvent & anEvent,
|
||||
PRUint32 aEventType);
|
||||
|
||||
protected:
|
||||
#ifdef DEBUG
|
||||
void DebugPrintMouseEvent(nsMouseEvent & aEvent,
|
||||
char * sMessage,
|
||||
GtkWidget * aGtkWidget);
|
||||
#endif
|
||||
|
||||
GtkWidget *mWidget;
|
||||
nsIWidget *mParent;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user