зеркало из https://github.com/mozilla/gecko-dev.git
added nsFileWidget
This commit is contained in:
Родитель
ccea853a2f
Коммит
f4f1ab4161
|
@ -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 \
|
||||
|
|
|
@ -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 <Xm/FileSB.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
@ -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__
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Загрузка…
Ссылка в новой задаче