diff --git a/widget/src/motif/Makefile b/widget/src/motif/Makefile index b6959ff5d7de..e877af029e90 100644 --- a/widget/src/motif/Makefile +++ b/widget/src/motif/Makefile @@ -44,6 +44,7 @@ EXTRA_DSO_LDOPTS+= -lXm -lXt -lX11 -lm endif CPPSRCS= \ +# nsFileWidget.cpp \ nsTextHelper.cpp \ nsTextWidget.cpp \ nsCheckButton.cpp \ @@ -56,6 +57,7 @@ CPPSRCS= \ nsToolkit.cpp CPP_OBJS= \ +# ./$(OBJDIR)/nsFileWidget.o \ ./$(OBJDIR)/nsTextHelper.o \ ./$(OBJDIR)/nsTextWidget.o \ ./$(OBJDIR)/nsCheckButton.o \ diff --git a/widget/src/motif/nsFileWidget.cpp b/widget/src/motif/nsFileWidget.cpp new file mode 100644 index 000000000000..39dc7318a710 --- /dev/null +++ b/widget/src/motif/nsFileWidget.cpp @@ -0,0 +1,249 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * 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 "nsFileWidget.h" +#include +#include "nsXtEventHandler.h" + +#define DBG 0 +//------------------------------------------------------------------------- +// +// nsFileWidget constructor +// +//------------------------------------------------------------------------- +nsFileWidget::nsFileWidget(nsISupports *aOuter) : nsWindow(aOuter) +{ + //mWnd = NULL; + mNumberOfFilters = 0; +} + + +void nsFileWidget:: Create(nsIWidget *aParent, + nsString& aTitle, + nsMode aMode, + nsIDeviceContext *aContext, + nsIToolkit *aToolkit, + void *aInitData) +{ + //mWnd = (aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0; + mTitle.SetLength(0); + mTitle.Append(aTitle); + mMode = aMode; + + 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 = XmCreateFileSelectionDialog(parentWidget, "filesb", NULL, 0); + + XtAddCallback(mWidget, XmNcancelCallback, nsXtWidget_FSBCancel_Callback, NULL); + XtAddCallback(mWidget, XmNokCallback, nsXtWidget_FSBOk_Callback, NULL); + + XtManageChild(mWidget); +} + +void nsFileWidget::Create(nsNativeWindow aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsFileWidget::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); + + if (aIID.Equals(kIFileWidgetIID)) { + AddRef(); + *aInstancePtr = (void**) &mAggWidget; + return NS_OK; + } + return nsWindow::QueryInterface(aIID, aInstancePtr); +} + + +//------------------------------------------------------------------------- +// +// Show - Display the file dialog +// +//------------------------------------------------------------------------- + +void nsFileWidget::Show(PRBool bState) +{ + nsresult result = nsEventStatus_eIgnore; + + /*char fileBuffer[MAX_PATH]; + fileBuffer[0] = '\0'; + OPENFILENAME ofn; + memset(&ofn, 0, sizeof(ofn)); + + ofn.lStructSize = sizeof(ofn); + + nsString filterList; + GetFilterListArray(filterList); + char *filterBuffer = filterList.ToNewCString(); + char *title = mTitle.ToNewCString(); + ofn.lpstrTitle = title; + ofn.lpstrFilter = filterBuffer; + ofn.nFilterIndex = 1; + ofn.hwndOwner = mWnd; + ofn.lpstrFile = fileBuffer; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_SHAREAWARE | OFN_NOCHANGEDIR | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + + BOOL result; + + // Save current directory, so we can reset if it changes. + char* currentDirectory = new char[MAX_PATH+1]; + VERIFY(::GetCurrentDirectory(MAX_PATH, currentDirectory) > 0); + + if (mMode == eMode_load) { + result = GetOpenFileName(&ofn); + } + else if (mMode == eMode_save) { + result = GetSaveFileName(&ofn); + } + else { + NS_ASSERTION(0, "Only load and save are supported modes"); + } + + VERIFY(::SetCurrentDirectory(currentDirectory)); + + // Clean up filter buffers + delete filterBuffer; + delete title; + + // Set user-selected location of file or directory + mFile.SetLength(0); + if (result==PR_TRUE) { + mFile.Append(fileBuffer); + } + */ +} + +//------------------------------------------------------------------------- +// +// Convert filter titles + filters into a Windows filter string +// +//------------------------------------------------------------------------- + +void nsFileWidget::GetFilterListArray(nsString& aFilterList) +{ + aFilterList.SetLength(0); + for (PRUint32 i = 0; i < mNumberOfFilters; i++) { + const nsString& title = mTitles[i]; + const nsString& filter = mFilters[i]; + + aFilterList.Append(title); + aFilterList.Append('\0'); + aFilterList.Append(filter); + aFilterList.Append('\0'); + } + aFilterList.Append('\0'); +} + +//------------------------------------------------------------------------- +// +// Set the list of filters +// +//------------------------------------------------------------------------- + +void nsFileWidget::SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]) +{ + mNumberOfFilters = aNumberOfFilters; + mTitles = aTitles; + mFilters = aFilters; +} + +//------------------------------------------------------------------------- +// +// Get the file + path +// +//------------------------------------------------------------------------- + +void nsFileWidget::GetFile(nsString& aFile) +{ + aFile.SetLength(0); + aFile.Append(mFile); +} + + +//------------------------------------------------------------------------- +// +// nsFileWidget destructor +// +//------------------------------------------------------------------------- +nsFileWidget::~nsFileWidget() +{ +} + +#define GET_OUTER() ((nsFileWidget*) ((char*)this - nsFileWidget::GetOuterOffset())) + +//---------------------------------------------------------------------- + +BASE_IWIDGET_IMPL_NO_SHOW(nsFileWidget, AggFileWidget); + +void nsFileWidget::AggFileWidget::Create( nsIWidget *aParent, + nsString& aTitle, + nsMode aMode, + nsIDeviceContext *aContext = nsnull, + nsIToolkit *aToolkit = nsnull, + void *aInitData = nsnull) +{ + GET_OUTER()->Create(aParent, aTitle, aMode, aContext, aToolkit, aInitData); +} + +void nsFileWidget::AggFileWidget::Show(PRBool bState) +{ + GET_OUTER()->Show(bState); +} + +void nsFileWidget::AggFileWidget::GetFile(nsString& aFile) +{ + GET_OUTER()->GetFile(aFile); +} + +void nsFileWidget::AggFileWidget::SetFilterList(PRUint32 aNumberOfFilters, + const nsString aTitles[], + const nsString aFilters[]) +{ + GET_OUTER()->SetFilterList(aNumberOfFilters, aTitles, aFilters); +} + +PRBool nsFileWidget::AggFileWidget::Show() +{ + GET_OUTER()->Show(PR_TRUE); + return PR_TRUE; +} + + diff --git a/widget/src/motif/nsFileWidget.h b/widget/src/motif/nsFileWidget.h new file mode 100644 index 000000000000..720ac204a10c --- /dev/null +++ b/widget/src/motif/nsFileWidget.h @@ -0,0 +1,115 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * 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 nsFileWidget_h__ +#define nsFileWidget_h__ + +#include "nsToolkit.h" +#include "nsIWidget.h" +#include "nsIFileWidget.h" +#include "nsWindow.h" + +/** + * Native Motif FileSelector wrapper + */ + +class nsFileWidget : public nsWindow +{ + public: + nsFileWidget(nsISupports *aOuter); + virtual ~nsFileWidget(); + 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); + + // nsIWidget interface + + virtual void Create( nsIWidget *aParent, + nsString& aTitle, + nsMode aMode, + nsIDeviceContext *aContext = nsnull, + nsIToolkit *aToolkit = nsnull, + void *aInitData = nsnull); + + // nsIFileWidget part + virtual void Show(PRBool bState); + virtual void GetFile(nsString& aFile); + virtual void SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]); + + protected: + + nsString mTitle; + nsMode mMode; + nsString mFile; + PRUint32 mNumberOfFilters; + const nsString* mTitles; + const nsString* mFilters; + + void GetFilterListArray(nsString& aFilterList); + + private: + + // this should not be public + static PRInt32 GetOuterOffset() { + return offsetof(nsFileWidget,mAggWidget); + } + + + // Aggregator class and instance variable used to aggregate in the + // nsIFileWidget interface to nsFileWidget w/o using multiple + // inheritance. + class AggFileWidget : public nsIFileWidget { + public: + AggFileWidget(); + virtual ~AggFileWidget(); + + AGGRRGATE_METHOD_DEF + + // nsIFileWidget + virtual void Create( nsIWidget *aParent, + nsString& aTitle, + nsMode aMode, + nsIDeviceContext *aContext = nsnull, + nsIToolkit *aToolkit = nsnull, + void *aInitData = nsnull); + + virtual void GetFile(nsString& aFile); + virtual void SetFilterList(PRUint32 aNumberOfFilters, + const nsString aTitles[], + const nsString aFilters[]); + + virtual PRBool Show(); + }; + AggFileWidget mAggWidget; + + +}; + +#endif // nsFileWidget_h__ diff --git a/widget/src/motif/nsWindow.h b/widget/src/motif/nsWindow.h index a93c2a147cf2..6425b90bd2a4 100644 --- a/widget/src/motif/nsWindow.h +++ b/widget/src/motif/nsWindow.h @@ -224,7 +224,7 @@ public: \ virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); -#define BASE_IWIDGET_IMPL(_classname, _aggname) \ +#define BASE_IWIDGET_IMPL_NO_SHOW(_classname, _aggname) \ _classname::_aggname::_aggname() \ { \ } \ @@ -281,10 +281,6 @@ public: \ { \ GET_OUTER()->RemoveChild(aChild); \ } \ - void _classname::_aggname::Show(PRBool bState) \ - { \ - GET_OUTER()->Show(bState); \ - } \ void _classname::_aggname::Move(PRUint32 aX, PRUint32 aY) \ { \ GET_OUTER()->Move(aX, aY); \ @@ -450,6 +446,15 @@ public: \ return GET_OUTER()->OnScroll(aEvent, cPos); \ } +#define BASE_IWIDGET_IMPL_SHOW(_classname, _aggname) \ + void _classname::_aggname::Show(PRBool bState) \ + { \ + GET_OUTER()->Show(bState); \ + } + +#define BASE_IWIDGET_IMPL(_classname, _aggname) \ + BASE_IWIDGET_IMPL_NO_SHOW(_classname, _aggname) \ + BASE_IWIDGET_IMPL_SHOW(_classname, _aggname) diff --git a/widget/src/motif/nsXtEventHandler.cpp b/widget/src/motif/nsXtEventHandler.cpp index 7ff2609416c6..daba15c86908 100644 --- a/widget/src/motif/nsXtEventHandler.cpp +++ b/widget/src/motif/nsXtEventHandler.cpp @@ -137,16 +137,6 @@ void nsXtWidget_LeaveMask_EventHandler(Widget w, XtPointer p, XEvent * event, Bo 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) { @@ -315,3 +305,12 @@ void nsXtWidget_Text_Callback(Widget w, XtPointer p, XtPointer call_data) if (DBG) fprintf(stderr, "Out nsXtWidget_Text_Callback\n"); } +//============================================================== +void nsXtWidget_FSBCancel_Callback(Widget w, XtPointer p, XtPointer call_data) +{ +} + +//============================================================== +void nsXtWidget_FSBOk_Callback(Widget w, XtPointer p, XtPointer call_data) +{ +} diff --git a/widget/src/motif/nsXtEventHandler.h b/widget/src/motif/nsXtEventHandler.h index 8bea2270e45d..cc2f32d26fd7 100644 --- a/widget/src/motif/nsXtEventHandler.h +++ b/widget/src/motif/nsXtEventHandler.h @@ -28,10 +28,11 @@ 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 + +void nsXtWidget_FSBCancel_Callback(Widget w, XtPointer p, XtPointer call_data); +void nsXtWidget_FSBOk_Callback(Widget w, XtPointer p, XtPointer call_data); + //---------------------------------------------------- void nsXtWidget_Scrollbar_Callback(Widget w, XtPointer p, XtPointer call_data); void nsXtWidget_Toggle_Callback(Widget w, XtPointer p, XtPointer call_data);