changed signature of OnResize

This commit is contained in:
rods 1998-06-10 22:42:34 +00:00
parent e09efc1dca
commit 67d326a651
14 changed files with 103 additions and 61 deletions

View File

@ -67,7 +67,7 @@ nsresult nsAppShell::Run()
void nsAppShell::Exit()
{
//PostQuitMessage(0);
exit(0);
}
//-------------------------------------------------------------------------

View File

@ -73,7 +73,7 @@ void nsButton::Create(nsIWidget *aParent,
// save the event callback function
mEventCallback = aHandleEventFunction;
InitCallbacks();
InitCallbacks("nsButton");
}
@ -160,7 +160,7 @@ PRBool nsButton::OnPaint(nsPaintEvent &aEvent)
return PR_FALSE;
}
PRBool nsButton::OnResize(nsRect &aWindowRect)
PRBool nsButton::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}

View File

@ -54,7 +54,7 @@ public:
virtual void SetLabel(const nsString& aText);
virtual void GetLabel(nsString& aBuffer);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnResize(nsSizeEvent &aEvent);
private:

View File

@ -255,7 +255,7 @@ PRBool nsCheckButton::OnPaint(nsPaintEvent &aEvent)
return PR_FALSE;
}
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
PRBool nsCheckButton::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}

View File

@ -56,7 +56,7 @@ public:
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsPaintEvent &aEvent);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnResize(nsSizeEvent &aEvent);
virtual void SetState(PRBool aState);
virtual PRBool GetState();

View File

@ -52,7 +52,6 @@ void nsScrollbar::Create(nsIWidget *aParent,
{
Widget parentWidget = nsnull;
//fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
@ -60,11 +59,8 @@ void nsScrollbar::Create(nsIWidget *aParent,
parentWidget = (Widget) aInitData ;
}
fprintf(stderr, "Parent 0x%x\n", parentWidget);
int procDir = mOrientation == XmVERTICAL? XmMAX_ON_BOTTOM:XmMAX_ON_RIGHT;
fprintf(stderr, "mOrient %d %d %d %d\n", mOrientation, XmVERTICAL, XmMAX_ON_BOTTOM, procDir);
mWidget = ::XtVaCreateManagedWidget("scrollbar",
xmScrollBarWidgetClass,
parentWidget,
@ -80,8 +76,6 @@ fprintf(stderr, "mOrient %d %d %d %d\n", mOrientation, XmVERTICAL, XmMAX_ON_BOTT
XmNy, aRect.y,
nsnull);
fprintf(stderr, "Scrollbar 0x%x this 0x%x\n", mWidget, this);
// save the event callback function
mEventCallback = aHandleEventFunction;
@ -159,10 +153,8 @@ nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr)
//-------------------------------------------------------------------------
void nsScrollbar::SetMaxRange(PRUint32 aEndRange)
{
fprintf(stderr, "Setting Max Range to %d 0x%x\n", aEndRange, mWidget);
int max = aEndRange;
XtVaGetValues(mWidget, XmNmaximum, &max, nsnull);
fprintf(stderr, "Max is %d\n", max);
max = aEndRange;
XtVaSetValues(mWidget, XmNmaximum, max, nsnull);
@ -176,21 +168,8 @@ void nsScrollbar::SetMaxRange(PRUint32 aEndRange)
//-------------------------------------------------------------------------
PRUint32 nsScrollbar::GetMaxRange()
{
/*int value = 0;
int slider_size = 0;
int increment = 0;
int page_increment = 0;
XmScrollBarGetValues(mWidget,
&value,
&slider_size,
&increment,
&page_increment) ;
printf("%d %d %d %d\n", value, slider_size, increment, page_increment);
return (PRUint32)slider_size;*/
int maxRange = 0;
XtVaGetValues(mWidget, XmNmaximum, &maxRange, nsnull);
printf("Got Range %d\n", maxRange);
return (PRUint32)maxRange;
}
@ -202,11 +181,6 @@ PRUint32 nsScrollbar::GetMaxRange()
//-------------------------------------------------------------------------
void nsScrollbar::SetPosition(PRUint32 aPos)
{
//fprintf(stderr, "Setting SetPosition to %d 0x%x\n", aPos, mWidget);
//int pos = aPos;
//XtVaGetValues(mWidget, XmNvalue, &pos, nsnull);
//fprintf(stderr, "pos is %d\n", pos);
int pos = aPos;
XtVaSetValues(mWidget, XmNvalue, pos, nsnull);
}
@ -304,7 +278,7 @@ PRBool nsScrollbar::OnPaint(nsPaintEvent & aEvent)
}
PRBool nsScrollbar::OnResize(nsRect &aWindowRect)
PRBool nsScrollbar::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
@ -319,7 +293,6 @@ PRBool nsScrollbar::OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos)
{
PRBool result = PR_TRUE;
int newPosition;
fprintf(stderr, "Scrollbar %d pos %d\n", aEvent.message, cPos);
switch (aEvent.message) {

View File

@ -65,7 +65,7 @@ public:
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnResize(nsSizeEvent &aEvent);
private:

View File

@ -87,7 +87,7 @@ void nsTextWidget::Create(nsIWidget *aParent,
// save the event callback function
mEventCallback = aHandleEventFunction;
InitCallbacks();
InitCallbacks("nsTextWidget");
if (mMakeReadOnly) {
SetReadOnly(PR_TRUE);
@ -139,7 +139,7 @@ PRBool nsTextWidget::OnPaint(nsPaintEvent & aEvent)
//--------------------------------------------------------------
PRBool nsTextWidget::OnResize(nsRect &aWindowRect)
PRBool nsTextWidget::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}

View File

@ -53,7 +53,7 @@ public:
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnResize(nsSizeEvent &aEvent);
// nsTextHelper Interface
virtual void SelectAll();

View File

@ -108,8 +108,6 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
fprintf(stderr, "Creating Widget\n");
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}

View File

@ -38,6 +38,8 @@
#include "stdio.h"
#define DBG 0
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
NS_IMPL_QUERY_INTERFACE(nsWindow, kIWidgetIID)
@ -126,7 +128,8 @@ nsWindow::~nsWindow()
// aNativeParent is equal to aWidgetParent->GetNativeData(NS_NATIVE_WIDGET)
//-------------------------------------------------------------------------
void nsWindow::CreateWindow(nsNativeWindow aNativeParent, nsIWidget *aWidgetParent,
void nsWindow::CreateWindow(nsNativeWindow aNativeParent,
nsIWidget *aWidgetParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
@ -211,6 +214,7 @@ void nsWindow::CreateWindow(nsNativeWindow aNativeParent, nsIWidget *aWidgetPare
XmNwidth, aRect.width,
XmNheight, aRect.height,
nsnull);
frameParent = mainWindow;
}
else
@ -240,6 +244,12 @@ void nsWindow::CreateWindow(nsNativeWindow aNativeParent, nsIWidget *aWidgetPare
InitCallbacks();
XtAddCallback(mWidget,
XmNresizeCallback,
nsXtWidget_Resize_Callback,
this);
}
@ -249,8 +259,9 @@ void nsWindow::CreateWindow(nsNativeWindow aNativeParent, nsIWidget *aWidgetPare
// Initialize all the Callbacks
//
//-------------------------------------------------------------------------
void nsWindow::InitCallbacks()
void nsWindow::InitCallbacks(char * aName)
{
if (DBG) fprintf(stderr, "Setting Up Callbacks 0x%x [%s]\n", this, (aName != nsnull?aName:"<unknown>"));
// setup the event Handlers
XtAddEventHandler(mWidget,
ButtonPressMask,
@ -294,6 +305,17 @@ void nsWindow::InitCallbacks()
nsXtWidget_ExposureMask_EventHandler,
this);
/*XtAddEventHandler(mWidget,
ResizeRedirectMask,
PR_FALSE,
nsXtWidget_ResizeRedirectMask_EventHandler,
this);*/
/*XtAddCallback(mWidget,
XmNresizeCallback,
nsXtWidget_Resize_Callback,
NULL);*/
}
@ -469,7 +491,7 @@ void nsWindow::GetBounds(nsRect &aRect)
aRect.height = attrs.height;
} else {
printf("Bad bounds computed for nsIWidget\n");
//printf("Bad bounds computed for nsIWidget\n");
// XXX If this code gets hit, one should question why and how
// and fix it there.
@ -843,7 +865,6 @@ PRBool nsWindow::OnPaint(nsPaintEvent &event)
event.rect = &rr;
event.renderingContext = nsnull;
static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID);
static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID);
@ -878,9 +899,12 @@ void nsWindow::OnDestroy()
{
}
PRBool nsWindow::OnResize(nsRect &aWindowRect)
PRBool nsWindow::OnResize(nsSizeEvent &aEvent)
{
return FALSE;
if (mEventCallback) {
return(DispatchEvent(&aEvent));
}
return FALSE;
}
PRBool nsWindow::OnKey(PRUint32 aEventType, PRUint32 aKeyCode)

View File

@ -109,14 +109,14 @@ public:
virtual void OnDestroy();
virtual PRBool OnPaint(nsPaintEvent &event);
virtual PRBool OnResize(nsRect &aWindowRect);
virtual PRBool OnResize(nsSizeEvent &aEvent);
virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode);
virtual PRBool DispatchFocus(PRUint32 aEventType);
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
protected:
void InitCallbacks();
void InitCallbacks(char * aName = nsnull);
void CreateWindow(nsNativeWindow aNativeParent, nsIWidget *aWidgetParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
@ -218,7 +218,7 @@ public: \
virtual PRBool DispatchMouseEvent(nsMouseEvent aEvent); \
virtual void OnDestroy(); \
virtual PRBool OnPaint(nsPaintEvent & event); \
virtual PRBool OnResize(nsRect &aWindowRect); \
virtual PRBool OnResize(nsSizeEvent &aEvent); \
virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode); \
virtual PRBool DispatchFocus(PRUint32 aEventType); \
virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos);
@ -433,9 +433,9 @@ public: \
{ \
GET_OUTER()->OnDestroy(); \
} \
PRBool _classname::_aggname::OnResize(nsRect &aWindowRect) \
PRBool _classname::_aggname::OnResize(nsSizeEvent &aEvent) \
{ \
GET_OUTER()->OnResize(aWindowRect); \
GET_OUTER()->OnResize(aEvent); \
} \
PRBool _classname::_aggname::OnKey(PRUint32 aEventType, PRUint32 aKeyCode) \
{ \

View File

@ -25,6 +25,7 @@
#include "stdio.h"
#define DBG 0
void nsXtWidget_InitNSEvent(XEvent * anXEv,
XtPointer p,
@ -62,6 +63,7 @@ void nsXtWidget_InitNSMouseEvent(XEvent * anXEv,
void nsXtWidget_ExposureMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b)
{
if (DBG) fprintf(stderr, "In nsXtWidget_ExposureMask_EventHandler\n");
nsPaintEvent pevent ;
nsWindow * widgetWindow = (nsWindow *) p ;
@ -72,6 +74,7 @@ void nsXtWidget_ExposureMask_EventHandler(Widget w, XtPointer p, XEvent * event,
widgetWindow->OnPaint(pevent);
if (DBG) fprintf(stderr, "Out nsXtWidget_ExposureMask_EventHandler\n");
}
//==============================================================
@ -95,19 +98,24 @@ void nsXtWidget_ButtonReleaseMask_EventHandler(Widget w, XtPointer p, XEvent * e
//==============================================================
void nsXtWidget_ButtonMotionMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b)
{
//if (DBG) fprintf(stderr, "nsXtWidget_ButtonMotionMask_EventHandler\n");
nsPaintEvent pevent ;
nsWindow * widgetWindow = (nsWindow *) p ;
nsMouseEvent mevent;
nsXtWidget_InitNSMouseEvent(event, p, mevent, NS_MOUSE_MOVE);
widgetWindow->DispatchMouseEvent(mevent);
}
//==============================================================
void nsXtWidget_MotionMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b)
{
//if (DBG) fprintf(stderr, "nsXtWidget_ButtonMotionMask_EventHandler\n");
nsWindow * widgetWindow = (nsWindow *) p ;
nsMouseEvent mevent;
nsXtWidget_InitNSMouseEvent(event, p, mevent, NS_MOUSE_MOVE);
widgetWindow->DispatchMouseEvent(mevent);
}
//==============================================================
@ -122,24 +130,34 @@ void nsXtWidget_EnterMask_EventHandler(Widget w, XtPointer p, XEvent * event, Bo
//==============================================================
void nsXtWidget_LeaveMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b)
{
if (DBG) fprintf(stderr, "***************** nsXtWidget_LeaveMask_EventHandler\n");
nsWindow * widgetWindow = (nsWindow *) p ;
//fprintf(stderr, "***************** nsXtWidget_LeaveMask_EventHandler\n");
nsMouseEvent mevent;
nsXtWidget_InitNSMouseEvent(event, p, mevent, NS_MOUSE_EXIT);
widgetWindow->DispatchMouseEvent(mevent);
}
//==============================================================
void nsXtWidget_ResizeRedirectMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b)
{
if (DBG) fprintf(stderr, "***************** nsXtWidget_ResizeRedirectMask_EventHandler\n");
//nsWindow * widgetWindow = (nsWindow *) p ;
//nsMouseEvent mevent;
//nsXtWidget_InitNSMouseEvent(event, p, mevent, NS_MOUSE_EXIT);
//widgetWindow->DispatchMouseEvent(mevent);
}
//==============================================================
void nsXtWidget_Toggle_Callback(Widget w, XtPointer p, XtPointer call_data)
{
nsWindow * widgetWindow = (nsWindow *) p ;
//fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
if (DBG) fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
nsScrollbarEvent sevent;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
if (DBG) fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
/*nsGUIEvent event;
nsXtWidget_InitNSEvent(event, p, event, NS_MOUSE_MOVE);
@ -154,7 +172,7 @@ void nsXtWidget_Toggle_ArmCallback(Widget w, XtPointer p, XtPointer call_data)
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
if (DBG) fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
checkBtn->Armed();
}
@ -162,16 +180,17 @@ void nsXtWidget_Toggle_ArmCallback(Widget w, XtPointer p, XtPointer call_data)
//==============================================================
void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In ***************** nsXtWidget_Scrollbar_Callback\n");
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);
if (DBG) fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
checkBtn->DisArmed();
if (DBG) fprintf(stderr, "Out ***************** nsXtWidget_Scrollbar_Callback\n");
}
@ -179,12 +198,12 @@ void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data
void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
{
nsWindow * widgetWindow = (nsWindow *) p ;
//fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
if (DBG) fprintf(stderr, "***************** nsXtWidget_Scrollbar_Callback\n");
nsScrollbarEvent sevent;
XmScrollBarCallbackStruct * cbs = (XmScrollBarCallbackStruct*) call_data;
//fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
if (DBG) fprintf(stderr, "Callback struct 0x%x\n", cbs);fflush(stderr);
sevent.widget = (nsWindow *) p;
if (cbs->event != nsnull) {
@ -223,7 +242,7 @@ void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
break;
default:
fprintf(stderr, "In Default processing for scrollbar reason is [%d]\n", cbs->reason);
if (DBG) fprintf(stderr, "In Default processing for scrollbar reason is [%d]\n", cbs->reason);
break;
}
widgetWindow->OnScroll(sevent, cbs->value);
@ -231,9 +250,33 @@ void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
//==============================================================
void nsXtWidget_Resize_Callback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In nsXtWidget_Resize_Callback\n");
nsWindow * widgetWindow = (nsWindow *) p ;
XmDrawingAreaCallbackStruct * cbs = (XmDrawingAreaCallbackStruct *)call_data;
if (cbs->reason == XmCR_RESIZE) {
nsSizeEvent event;
nsRect rect;
event.message = NS_SIZE;
event.widget = (nsWindow *) p;
if (cbs->event != NULL) {
event.point.x = cbs->event->xbutton.x;
event.point.y = cbs->event->xbutton.y;
}
event.time = 0; //TBD
event.windowSize = (nsRect *)&rect;
widgetWindow->GetBounds(rect);
widgetWindow->OnResize(event);
}
}
//==============================================================
void nsXtWidget_Text_Callback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In nsXtWidget_Text_Callback\n");
nsWindow * widgetWindow = (nsWindow *) p ;
static char * passwd;
char * newStr;
@ -262,12 +305,13 @@ void nsXtWidget_Text_Callback(Widget w, XtPointer p, XtPointer call_data)
strcpy (newStr, passwd);
XtFree (passwd);
} else
newStr[0] = NULL;
newStr[0] = 0;
passwd = newStr;
strncat (passwd, cbs->text->ptr, cbs->text->length);
passwd[cbs->endPos + cbs->text->length] = 0;
for (len = 0; len < cbs->text->length; len++)
cbs->text->ptr[len] = '*';
if (DBG) fprintf(stderr, "Out nsXtWidget_Text_Callback\n");
}

View File

@ -28,6 +28,7 @@ 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);
void nsXtWidget_ResizeRedirectMask_EventHandler(Widget w, XtPointer p, XEvent * event, Boolean * b);
//----------------------------------------------------
// Callbacks
@ -38,6 +39,8 @@ void nsXtWidget_Toggle_ArmCallback(Widget w, XtPointer p, XtPointer call_data);
void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data);
void nsXtWidget_Text_Callback(Widget w, XtPointer p, XtPointer call_data);
void nsXtWidget_Resize_Callback(Widget w, XtPointer p, XtPointer call_data);
#endif // __nsXtEventHandler.h