Last few changes to make everything work.

This commit is contained in:
rods 1998-06-23 21:18:43 +00:00
Родитель 974947c4ce
Коммит 435573468e
10 изменённых файлов: 226 добавлений и 60 удалений

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

@ -44,6 +44,7 @@ EXTRA_DSO_LDOPTS+= -lXm -lXt -lX11 -lm
endif
CPPSRCS= \
nsComboBox.cpp \
nsTextAreaWidget.cpp \
nsListBox.cpp \
nsRadioButton.cpp \
@ -60,6 +61,7 @@ CPPSRCS= \
nsToolkit.cpp
CPP_OBJS= \
./$(OBJDIR)/nsComboBox.o \
./$(OBJDIR)/nsTextAreaWidget.o \
./$(OBJDIR)/nsListBox.o \
./$(OBJDIR)/nsRadioButton.o \

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

@ -35,6 +35,7 @@ nsCheckButton::nsCheckButton(nsISupports *aOuter) :
nsWindow(aOuter),
mIsArmed(PR_FALSE)
{
mLowerLeft = PR_TRUE;
}
//-------------------------------------------------------------------------
@ -58,6 +59,7 @@ void nsCheckButton::Create(nsIWidget *aParent,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
@ -70,6 +72,7 @@ void nsCheckButton::Create(nsIWidget *aParent,
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
mWidget = ::XtVaCreateManagedWidget("",
xmToggleButtonWidgetClass,
parentWidget,
@ -79,7 +82,16 @@ void nsCheckButton::Create(nsIWidget *aParent,
XmNhighlightOnEnter, False,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
XmNresizeHeight, False,
XmNresizeWidth, False,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNadjustMargin, False,
XmNspacing, 0,
XmNisAligned, False,
XmNentryBorder, 0,
XmNborderWidth, 0,
0);
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);

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

@ -52,7 +52,6 @@ void nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
str = XmStringCreateLocalized(val);
printf("String being added [%s] %d\n", val, aPosition);
XmListAddItem(mWidget, str, (int)aPosition);
NS_FREE_STR_BUF(val);
}
@ -228,12 +227,12 @@ nsresult nsListBox::QueryObject(const nsIID& aIID, void** aInstancePtr)
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
if (result == NS_NOINTERFACE) {
if (aIID.Equals(kInsListBoxIID)) {
*aInstancePtr = (void*) ((nsIListBox*)this);
*aInstancePtr = (void*) ((nsIListBox*)&mAggWidget);
AddRef();
result = NS_OK;
}
else if (aIID.Equals(kInsListWidgetIID)) {
*aInstancePtr = (void*) ((nsIListWidget*)this);
*aInstancePtr = (void*) ((nsIListWidget*)&mAggWidget);
AddRef();
result = NS_OK;
}

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

@ -76,9 +76,41 @@ void nsRadioButton::Create(nsIWidget *aParent,
XmNheight, aRect.height,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
XmNrecomputeSize, False,
XmNresizeHeight, False,
XmNresizeWidth, False,
XmNradioAlwaysOne, False,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNadjustMargin, False,
XmNspacing, 0,
// XmNentryAlignment, XmALIGNMENT_CENTER,
// XmNentryVerticalAlignment, XmALIGNMENT_CENTER,
XmNisAligned, False,
XmNentryBorder, 0,
XmNorientation, XmVERTICAL,
XmNborderWidth, 0,
0);
mRadioBtn = ::XmCreateToggleButton(mWidget, "", nsnull, 0);
XtVaSetValues(mRadioBtn,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNx, 0,
XmNy, 0,
XmNrecomputeSize, False,
XmNresizeHeight, False,
XmNresizeWidth, False,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNadjustMargin, False,
XmNspacing, 0,
XmNisAligned, False,
XmNentryBorder, 0,
XmNborderWidth, 0,
0);
XtManageChild(mRadioBtn);
if (DBG) fprintf(stderr, "Button 0x%x this 0x%x\n", mWidget, this);
@ -90,14 +122,19 @@ void nsRadioButton::Create(nsIWidget *aParent,
XtAddCallback(mRadioBtn,
XmNarmCallback,
nsXtWidget_Toggle_ArmCallback,
nsXtWidget_RadioButton_ArmCallback,
this);
XtAddCallback(mRadioBtn,
XmNdisarmCallback,
nsXtWidget_Toggle_DisArmCallback,
nsXtWidget_RadioButton_DisArmCallback,
this);
/*XtAddCallback(mRadioBtn,
XmNvalueChangedCallback,
nsXtWidget_Toggle_ValueChangedCallback,
this);*/
}

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

@ -111,12 +111,18 @@ void nsTextAreaWidget::Create(nsNativeWindow aParent,
nsresult nsTextAreaWidget::QueryObject(REFNSIID aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
if (aIID.Equals(kITextWidgetIID)) {
AddRef();
*aInstancePtr = (void**) &mAggWidget;
return NS_OK;
}
if (aIID.Equals(kITextAreaWidgetIID)) {
AddRef();
*aInstancePtr = (void**) &mAggWidget;
return NS_OK;
}
return nsWindow::QueryObject(aIID, aInstancePtr);
}

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

@ -33,6 +33,7 @@
#include "nsTextAreaWidget.h"
#include "nsFileWidget.h"
#include "nsListBox.h"
#include "nsComboBox.h"
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
@ -46,6 +47,7 @@ static NS_DEFINE_IID(kCTextAreaWidgetCID, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
static NS_DEFINE_IID(kCButtonCID, NS_BUTTON_CID);
static NS_DEFINE_IID(kCListBoxCID, NS_LISTBOX_CID);
static NS_DEFINE_IID(kCComboBoxCID, NS_COMBOBOX_CID);
static NS_DEFINE_IID(kIWidget, NS_IWIDGET_IID);
@ -163,6 +165,9 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCListBoxCID)) {
inst = new nsListBox(aOuter);
}
else if (mClassID.Equals(kCComboBoxCID)) {
inst = new nsComboBox(aOuter);
}
else if (mClassID.Equals(kCFileWidgetCID)) {
inst = new nsFileWidget(aOuter);
}

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

@ -181,6 +181,10 @@ nsWindow::nsWindow(nsISupports *aOuter):
else
mOuter = &mInner;
mGC = nsnull ;
mShown = PR_FALSE;
mVisible = PR_FALSE;
mDisplayed = PR_FALSE;
mLowerLeft = PR_FALSE;
}
@ -509,10 +513,9 @@ void nsWindow::RemoveChild(nsIWidget* aChild)
//-------------------------------------------------------------------------
void nsWindow::Show(PRBool bState)
{
if (bState)
XtManageChild(mWidget);
else
XtUnmanageChild(mWidget);
mShown = bState;
UpdateVisibilityFlag();
UpdateDisplay();
}
//-------------------------------------------------------------------------
@ -522,8 +525,11 @@ void nsWindow::Show(PRBool bState)
//-------------------------------------------------------------------------
void nsWindow::Move(PRUint32 aX, PRUint32 aY)
{
XtVaSetValues(mWidget, XmNx, aX, XmNy, aY, nsnull);
mBounds.x = aX;
mBounds.y = aY;
UpdateVisibilityFlag();
UpdateDisplay();
XtVaSetValues(mWidget, XmNx, aX, XmNy, GetYCoord(aY), nsnull);
}
//-------------------------------------------------------------------------
@ -537,6 +543,8 @@ void nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint)
gInstanceClassName, aWidth, aHeight, (aRepaint?"true":"false"));
mBounds.width = aWidth;
mBounds.height = aHeight;
UpdateVisibilityFlag();
UpdateDisplay();
XtVaSetValues(mWidget, XmNwidth, aWidth, XmNheight, aHeight, nsnull);
}
@ -552,7 +560,9 @@ void nsWindow::Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, PRUint32 aHeigh
mBounds.y = aY;
mBounds.width = aWidth;
mBounds.height = aHeight;
XtVaSetValues(mWidget, XmNx, aX, XmNy, aY,
UpdateVisibilityFlag();
UpdateDisplay();
XtVaSetValues(mWidget, XmNx, aX, XmNy, GetYCoord(aY),
XmNwidth, aWidth, XmNheight, aHeight, nsnull);
}
@ -690,6 +700,29 @@ nsIFontMetrics* nsWindow::GetFont(void)
//-------------------------------------------------------------------------
void nsWindow::SetFont(const nsFont &aFont)
{
#if 0
if (mContext == nsnull) {
return;
}
nsIFontCache* fontCache = mContext->GetFontCache();
if (fontCache != nsnull) {
nsIFontMetrics* metrics = fontCache->GetMetricsFor(aFont);
if (metrics != nsnull) {
//HFONT hfont = metrics->GetFontHandle();
// Draw in the new font
//XtVaSetValues(mWidget, XmNfont, metrics->GetFontHandle(), NULL);
NS_RELEASE(metrics);
} else {
printf("****** Error: Metrics is NULL!\n");
}
NS_RELEASE(fontCache);
} else {
printf("****** Error: FontCache is NULL!\n");
}
#endif
}
@ -930,6 +963,7 @@ PRBool nsWindow::ConvertStatus(nsEventStatus aStatus)
PRBool nsWindow::DispatchEvent(nsGUIEvent* event)
{
PRBool result = PR_FALSE;
event->widgetSupports = mOuter;
if (nsnull != mEventCallback) {
result = ConvertStatus((*mEventCallback)(event));
@ -958,45 +992,15 @@ PRBool nsWindow::DispatchMouseEvent(nsMouseEvent aEvent)
// call the event callback
if (nsnull != mEventCallback) {
result = DispatchEvent(&aEvent);
//printf("**result=%d%\n",result);
/*if (aEventType == NS_MOUSE_MOVE) {
//MouseTrailer * mouseTrailer = MouseTrailer::GetMouseTrailer(0);
//MouseTrailer::SetMouseTrailerWindow(this);
//mouseTrailer->CreateTimer();
nsRect rect;
GetBounds(rect);
rect.x = 0;
rect.y = 0;
//printf("Rect[%d, %d, %d, %d] Point[%d,%d]\n", rect.x, rect.y, rect.width, rect.height, event.position.x, event.position.y);
//printf("mCurrentWindow 0x%X\n", mCurrentWindow);
if (rect.Contains(event.point.x, event.point.y)) {
if (mCurrentWindow == NULL || mCurrentWindow != this) {
if ((nsnull != mCurrentWindow) && (!mCurrentWindow->mIsDestroying)) {
mCurrentWindow->DispatchMouseEvent(NS_MOUSE_EXIT);
}
mCurrentWindow = this;
mCurrentWindow->DispatchMouseEvent(NS_MOUSE_ENTER);
}
}
} else if (aEventType == NS_MOUSE_EXIT) {
if (mCurrentWindow == this) {
mCurrentWindow = nsnull;
}
}*/
return result;
}
/*if (nsnull != mMouseListener) {
switch (aEventType) {
if (nsnull != mMouseListener) {
switch (aEvent.message) {
case NS_MOUSE_MOVE: {
result = ConvertStatus(mMouseListener->MouseMoved(event));
/*result = ConvertStatus(mMouseListener->MouseMoved(event));
nsRect rect;
GetBounds(rect);
if (rect.Contains(event.point.x, event.point.y)) {
@ -1006,24 +1010,24 @@ PRBool nsWindow::DispatchMouseEvent(nsMouseEvent aEvent)
}
} else {
//printf("Mouse exit");
}
}*/
} break;
case NS_MOUSE_LEFT_BUTTON_DOWN:
case NS_MOUSE_MIDDLE_BUTTON_DOWN:
case NS_MOUSE_RIGHT_BUTTON_DOWN:
result = ConvertStatus(mMouseListener->MousePressed(event));
result = ConvertStatus(mMouseListener->MousePressed(aEvent));
break;
case NS_MOUSE_LEFT_BUTTON_UP:
case NS_MOUSE_MIDDLE_BUTTON_UP:
case NS_MOUSE_RIGHT_BUTTON_UP:
result = ConvertStatus(mMouseListener->MouseReleased(event));
result = ConvertStatus(mMouseListener->MouseClicked(event));
result = ConvertStatus(mMouseListener->MouseReleased(aEvent));
result = ConvertStatus(mMouseListener->MouseClicked(aEvent));
break;
} // switch
} */
}
return result;
}
@ -1149,4 +1153,50 @@ PRBool nsWindow::GetResized()
return(mResized);
}
void nsWindow::UpdateVisibilityFlag()
{
Widget parent = XtParent(mWidget);
if (parent) {
PRUint32 pWidth = 0;
PRUint32 pHeight = 0;
XtVaGetValues(parent, XmNwidth, &pWidth, XmNheight, &pHeight, nsnull);
if ((mBounds.y + mBounds.height) > pHeight) {
mVisible = PR_FALSE;
return;
}
if (mBounds.y < 0)
mVisible = PR_FALSE;
}
mVisible = PR_TRUE;
}
void nsWindow::UpdateDisplay()
{
// If not displayed and needs to be displayed
if ((PR_FALSE==mDisplayed) &&
(PR_TRUE==mShown) &&
(PR_TRUE==mVisible)) {
XtManageChild(mWidget);
mDisplayed = PR_TRUE;
}
// Displayed and needs to be removed
if (PR_TRUE==mDisplayed) {
if ((PR_FALSE==mShown) || (PR_FALSE==mVisible)) {
XtUnmanageChild(mWidget);
mDisplayed = PR_FALSE;
}
}
}
PRUint32 nsWindow::GetYCoord(PRUint32 aNewY)
{
if (PR_TRUE==mLowerLeft) {
return(aNewY - 12 /*KLUDGE fix this later mBounds.height */);
}
return(aNewY);
}

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

@ -126,6 +126,8 @@ public:
virtual void SetIgnoreResize(PRBool aIgnore);
virtual PRBool IgnoreResize();
virtual PRUint32 GetYCoord(PRUint32 aNewY);
// Resize event management
void SetResizeRect(nsRect& aRect);
void SetResized(PRBool aResized);
@ -142,6 +144,9 @@ protected:
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData);
virtual void UpdateVisibilityFlag();
virtual void UpdateDisplay();
Widget mWidget;
EVENT_CALLBACK mEventCallback;
nsIDeviceContext *mContext;
@ -158,10 +163,14 @@ protected:
nsRect mBounds;
PRBool mIgnoreResize;
PRBool mShown;
PRBool mVisible;
PRBool mDisplayed;
// Resize event management
nsRect mResizeRect;
int mResized;
PRBool mLowerLeft;
nsISupports* mOuter;

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

@ -21,6 +21,7 @@
#include "nsWindow.h"
#include "nsCheckButton.h"
#include "nsRadioButton.h"
#include "nsFileWidget.h"
#include "nsGUIEvent.h"
@ -40,8 +41,10 @@ void nsXtWidget_InitNSEvent(XEvent * anXEv,
anEvent.message = aEventType;
anEvent.widget = (nsWindow *) p;
if (anXEv != NULL) {
anEvent.point.x = anXEv->xbutton.x;
anEvent.point.y = anXEv->xbutton.y;
}
anEvent.time = 0; //TBD
@ -56,10 +59,11 @@ void nsXtWidget_InitNSMouseEvent(XEvent * anXEv,
// Do base initialization
nsXtWidget_InitNSEvent(anXEv, p, anEvent, aEventType);
// Do Mouse Event specific intialization
if (anXEv != NULL) { // Do Mouse Event specific intialization
anEvent.time = anXEv->xbutton.time;
anEvent.isShift = anXEv->xbutton.state | ShiftMask;
anEvent.isControl = anXEv->xbutton.state | ControlMask;
}
//anEvent.isAlt = GetKeyState(VK_LMENU) < 0 || GetKeyState(VK_RMENU) < 0;
////anEvent.clickCount = (aEventType == NS_MOUSE_LEFT_DOUBLECLICK ||
@ -351,6 +355,46 @@ void nsXtWidget_Toggle_DisArmCallback(Widget w, XtPointer p, XtPointer call_data
}
//==============================================================
void nsXtWidget_RadioButton_ArmCallback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In ***************** nsXtWidget_RadioButton_ArmCallback\n");
nsRadioButton * radioBtn = (nsRadioButton *) p ;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
if (DBG) fprintf(stderr, "Callback struct 0x%x Set %d\n", cbs, cbs->set);fflush(stderr);
radioBtn->Armed();
nsMouseEvent mevent;
nsXtWidget_InitNSMouseEvent(cbs->event, p, mevent, NS_MOUSE_LEFT_BUTTON_DOWN);
radioBtn->DispatchMouseEvent(mevent);
}
//==============================================================
void nsXtWidget_RadioButton_DisArmCallback(Widget w, XtPointer p, XtPointer call_data)
{
if (DBG) fprintf(stderr, "In ***************** nsXtWidget_RadioButton_DisArmCallback\n");
nsRadioButton * radioBtn = (nsRadioButton *) p ;
nsScrollbarEvent sevent;
XmToggleButtonCallbackStruct * cbs = (XmToggleButtonCallbackStruct*)call_data;
if (DBG) fprintf(stderr, "Callback struct 0x%x Set %d\n", cbs, cbs->set);fflush(stderr);
radioBtn->DisArmed();
if (DBG) fprintf(stderr, "Out ***************** nsXtWidget_Scrollbar_Callback\n");
nsMouseEvent mevent;
nsXtWidget_InitNSMouseEvent(cbs->event, p, mevent, NS_MOUSE_LEFT_BUTTON_UP);
radioBtn->DispatchMouseEvent(mevent);
}
//==============================================================
void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data)
{

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

@ -38,6 +38,8 @@ 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);
void nsXtWidget_RadioButton_ArmCallback(Widget w, XtPointer p, XtPointer call_data);
void nsXtWidget_RadioButton_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);