mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 03:19:06 +00:00
added CheckButton support
This commit is contained in:
parent
9a382ec099
commit
537197a767
@ -45,6 +45,7 @@ EXTRA_DSO_LDOPTS+= -lX11 -lm
|
||||
endif
|
||||
|
||||
CPPSRCS= \
|
||||
nsCheckButton.cpp \
|
||||
nsScrollbar.cpp \
|
||||
nsButton.cpp \
|
||||
nsAppShell.cpp \
|
||||
@ -54,6 +55,7 @@ CPPSRCS= \
|
||||
nsToolkit.cpp
|
||||
|
||||
CPP_OBJS= \
|
||||
./$(OBJDIR)/nsCheckButton.o \
|
||||
./$(OBJDIR)/nsButton.o \
|
||||
./$(OBJDIR)/nsScrollbar.o \
|
||||
./$(OBJDIR)/nsAppShell.o \
|
||||
|
295
widget/src/motif/nsCheckButton.cpp
Normal file
295
widget/src/motif/nsCheckButton.cpp
Normal file
@ -0,0 +1,295 @@
|
||||
/* -*- 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
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCheckButton.h"
|
||||
#include "nsColor.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include "nsString.h"
|
||||
#include "nsStringUtil.h"
|
||||
|
||||
#include "nsXtEventHandler.h"
|
||||
#include <Xm/ToggleB.h>
|
||||
|
||||
#define DBG 0
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsCheckButton constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsCheckButton::nsCheckButton(nsISupports *aOuter) :
|
||||
nsWindow(aOuter),
|
||||
mIsArmed(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsCheckButton destructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsCheckButton::~nsCheckButton()
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsCheckButton Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
Widget parentWidget = nsnull;
|
||||
|
||||
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
|
||||
|
||||
if (aParent) {
|
||||
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||
} else {
|
||||
parentWidget = (Widget) aInitData ;
|
||||
}
|
||||
|
||||
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
|
||||
|
||||
mWidget = ::XtVaCreateManagedWidget("button",
|
||||
xmToggleButtonWidgetClass,
|
||||
parentWidget,
|
||||
XmNwidth, aRect.width,
|
||||
XmNheight, aRect.height,
|
||||
XmNrecomputeSize, False,
|
||||
XmNhighlightOnEnter, False,
|
||||
XmNx, aRect.x,
|
||||
XmNy, aRect.y,
|
||||
nsnull);
|
||||
|
||||
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
|
||||
|
||||
// save the event callback function
|
||||
mEventCallback = aHandleEventFunction;
|
||||
|
||||
InitCallbacks();
|
||||
|
||||
/*XtAddCallback(mWidget,
|
||||
XmNvalueChangedCallback,
|
||||
nsXtWidget_Toggle_Callback,
|
||||
this);*/
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNarmCallback,
|
||||
nsXtWidget_Toggle_ArmCallback,
|
||||
this);
|
||||
|
||||
XtAddCallback(mWidget,
|
||||
XmNdisarmCallback,
|
||||
nsXtWidget_Toggle_DisArmCallback,
|
||||
this);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsCheckButton Creator
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::Create(nsNativeWindow aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData)
|
||||
{
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Query interface implementation
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsresult nsCheckButton::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
||||
|
||||
if (aIID.Equals(kICheckButtonIID)) {
|
||||
AddRef();
|
||||
*aInstancePtr = (void**) &mAggWidget;
|
||||
return NS_OK;
|
||||
}
|
||||
return nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Armed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::Armed()
|
||||
{
|
||||
mIsArmed = PR_TRUE;
|
||||
mValueWasSet = PR_FALSE;
|
||||
mInitialState = XmToggleButtonGetState(mWidget);
|
||||
if (DBG) printf("Arm: InitialValue: %d\n", mInitialState);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// DisArmed
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::DisArmed()
|
||||
{
|
||||
if (DBG) printf("DisArm: InitialValue: %d\n", mInitialState);
|
||||
if (DBG) printf("DisArm: ActualValue: %d\n", XmToggleButtonGetState(mWidget));
|
||||
if (DBG) printf("DisArm: mValueWasSet %d\n", mValueWasSet);
|
||||
if (DBG) printf("DisArm: mNewValue %d\n", mNewValue);
|
||||
|
||||
if (mValueWasSet) {
|
||||
XmToggleButtonSetState(mWidget, mNewValue, TRUE);
|
||||
} else {
|
||||
XmToggleButtonSetState(mWidget, mInitialState, TRUE);
|
||||
}
|
||||
mIsArmed = PR_FALSE;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::SetState(PRBool aState)
|
||||
{
|
||||
int state = aState;
|
||||
if (mIsArmed) {
|
||||
mNewValue = aState;
|
||||
mValueWasSet = PR_TRUE;
|
||||
}
|
||||
XmToggleButtonSetState(mWidget, aState, TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsCheckButton::GetState()
|
||||
{
|
||||
int state = XmToggleButtonGetState(mWidget);
|
||||
if (mIsArmed) {
|
||||
if (mValueWasSet) {
|
||||
return mNewValue;
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
} else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Set this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::SetLabel(const nsString& aText)
|
||||
{
|
||||
NS_ALLOC_STR_BUF(label, aText, 256);
|
||||
XmString str;
|
||||
str = XmStringCreate(label, XmFONTLIST_DEFAULT_TAG);
|
||||
XtVaSetValues(mWidget, XmNlabelString, str, nsnull);
|
||||
NS_FREE_STR_BUF(label);
|
||||
XmStringFree(str);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Get this button label
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
void nsCheckButton::GetLabel(nsString& aBuffer)
|
||||
{
|
||||
XmString str;
|
||||
XtVaGetValues(mWidget, XmNlabelString, &str, nsnull);
|
||||
char * text;
|
||||
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
|
||||
aBuffer.SetLength(0);
|
||||
aBuffer.Append(text);
|
||||
XtFree(text);
|
||||
}
|
||||
XmStringFree(str);
|
||||
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// move, paint, resizes message - ignore
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
PRBool nsCheckButton::OnMove(PRInt32, PRInt32)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsCheckButton::OnPaint(nsPaintEvent &aEvent)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
#define GET_OUTER() \
|
||||
((nsCheckButton*) ((char*)this - nsCheckButton::GetOuterOffset()))
|
||||
|
||||
PRBool nsCheckButton::AggCheckButton::GetState()
|
||||
{
|
||||
return GET_OUTER()->GetState();
|
||||
}
|
||||
|
||||
void nsCheckButton::AggCheckButton::SetState(PRBool aState)
|
||||
{
|
||||
GET_OUTER()->SetState(aState);
|
||||
}
|
||||
|
||||
void nsCheckButton::AggCheckButton::SetLabel(const nsString& aText)
|
||||
{
|
||||
GET_OUTER()->SetLabel(aText);
|
||||
}
|
||||
|
||||
void nsCheckButton::AggCheckButton::GetLabel(nsString& aText)
|
||||
{
|
||||
GET_OUTER()->GetLabel(aText);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
BASE_IWIDGET_IMPL(nsCheckButton, AggCheckButton);
|
||||
|
103
widget/src/motif/nsCheckButton.h
Normal file
103
widget/src/motif/nsCheckButton.h
Normal file
@ -0,0 +1,103 @@
|
||||
/* -*- 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
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsCheckButton_h__
|
||||
#define nsCheckButton_h__
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsICheckButton.h"
|
||||
|
||||
/**
|
||||
* Native Motif Checkbox wrapper
|
||||
*/
|
||||
|
||||
class nsCheckButton : public nsWindow
|
||||
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
nsCheckButton(nsISupports *aOuter);
|
||||
virtual ~nsCheckButton();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
void Create(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
void Create(nsNativeWindow aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext = nsnull,
|
||||
nsIToolkit *aToolkit = nsnull,
|
||||
nsWidgetInitData *aInitData = nsnull);
|
||||
|
||||
// nsICheckButton part
|
||||
virtual void SetLabel(const nsString& aText);
|
||||
virtual void GetLabel(nsString& aBuffer);
|
||||
|
||||
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||
virtual PRBool OnPaint(nsPaintEvent &aEvent);
|
||||
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||
|
||||
virtual void SetState(PRBool aState);
|
||||
virtual PRBool GetState();
|
||||
|
||||
// These are needed to Override the auto check behavior
|
||||
void Armed();
|
||||
void DisArmed();
|
||||
|
||||
private:
|
||||
|
||||
// this should not be public
|
||||
static PRInt32 GetOuterOffset() {
|
||||
return offsetof(nsCheckButton,mAggWidget);
|
||||
}
|
||||
|
||||
Boolean mInitialState;
|
||||
Boolean mNewValue;
|
||||
Boolean mValueWasSet;
|
||||
Boolean mIsArmed;
|
||||
|
||||
// Aggregator class and instance variable used to aggregate in the
|
||||
// nsIButton interface to nsCheckButton w/o using multiple
|
||||
// inheritance.
|
||||
class AggCheckButton : public nsICheckButton {
|
||||
public:
|
||||
AggCheckButton();
|
||||
virtual ~AggCheckButton();
|
||||
|
||||
AGGRRGATE_METHOD_DEF
|
||||
|
||||
// nsICheckButton
|
||||
virtual void SetLabel(const nsString &aText);
|
||||
virtual void GetLabel(nsString &aBuffer);
|
||||
virtual void SetState(PRBool aState);
|
||||
virtual PRBool GetState();
|
||||
|
||||
|
||||
};
|
||||
AggCheckButton mAggWidget;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif // nsCheckButton_h__
|
@ -20,6 +20,7 @@
|
||||
#include "nsXtEventHandler.h"
|
||||
|
||||
#include "nsWindow.h"
|
||||
#include "nsCheckButton.h"
|
||||
#include "nsGUIEvent.h"
|
||||
|
||||
#include "stdio.h"
|
||||
@ -128,6 +129,52 @@ void nsXtWidget_LeaveMask_EventHandler(Widget w, XtPointer p, XEvent * event, Bo
|
||||
widgetWindow->DispatchMouseEvent(mevent);
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
void nsXtWidget_Toggle_Callback(Widget w, XtPointer p, XtPointer call_data)
|
||||
{
|
||||
nsWindow * widgetWindow = (nsWindow *) p ;
|
||||
//fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
|
||||
|
||||
nsScrollbarEvent sevent;
|
||||
|
||||
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
|
||||
|
||||
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
|
||||
|
||||
/*nsGUIEvent event;
|
||||
nsXtWidget_InitNSEvent(event, p, event, NS_MOUSE_MOVE);
|
||||
widgetWindow->DispatchMouseEvent(mevent);
|
||||
*/
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
void nsXtWidget_Toggle_ArmCallback(Widget w, XtPointer p, XtPointer call_data)
|
||||
{
|
||||
nsCheckButton * checkBtn = (nsCheckButton *) p ;
|
||||
|
||||
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
|
||||
|
||||
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
|
||||
checkBtn->Armed();
|
||||
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data)
|
||||
{
|
||||
nsCheckButton * checkBtn = (nsCheckButton *) p ;
|
||||
//fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
|
||||
|
||||
nsScrollbarEvent sevent;
|
||||
|
||||
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
|
||||
|
||||
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
|
||||
|
||||
checkBtn->DisArmed();
|
||||
|
||||
}
|
||||
|
||||
//==============================================================
|
||||
void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
|
||||
{
|
||||
@ -137,7 +184,7 @@ void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
|
||||
nsScrollbarEvent sevent;
|
||||
|
||||
XmScrollBarCallbackStruct * cbs = (XmScrollBarCallbackStruct*) call_data;
|
||||
fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
|
||||
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
|
||||
|
||||
sevent.widget = (nsWindow *) p;
|
||||
if (cbs->event != nsnull) {
|
||||
|
@ -28,7 +28,14 @@ void nsXtWidget_ButtonMotionMask_EventHandler(Widget w, XtPointer p, XEvent * ev
|
||||
void nsXtWidget_MotionMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b);
|
||||
void nsXtWidget_EnterMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b);
|
||||
void nsXtWidget_LeaveMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b);
|
||||
|
||||
//----------------------------------------------------
|
||||
// Callbacks
|
||||
//----------------------------------------------------
|
||||
void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data);
|
||||
void nsXtWidget_Toggle_Callback(Widget w, XtPointer p, XtPointer call_data);
|
||||
void nsXtWidget_Toggle_ArmCallback(Widget w, XtPointer p, XtPointer call_data);
|
||||
void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data);
|
||||
|
||||
#endif // __nsXtEventHandler.h
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user