This commit is contained in:
dcone%netscape.com 1998-08-05 17:01:56 +00:00
Родитель d9a83cc808
Коммит 56aa38d1db
9 изменённых файлов: 1944 добавлений и 0 удалений

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

@ -0,0 +1,134 @@
/* -*- 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 "nsAppShell.h"
#include "nsIAppShell.h"
#include <stdlib.h>
#include <Fonts.h>
#include <TextEdit.h>
#include <Dialogs.h>
#include <Traps.h>
#include <Events.h>
#include <Menus.h>
//XtAppContext gAppContext;
//-------------------------------------------------------------------------
//
// nsISupports implementation macro
//
//-------------------------------------------------------------------------
NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID);
void nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
{
mDispatchListener = aDispatchListener;
mToolKit = new nsToolkit();
}
//-------------------------------------------------------------------------
//
// Create the application shell
//
//-------------------------------------------------------------------------
void nsAppShell::Create(int* argc, char ** argv)
{
}
//-------------------------------------------------------------------------
//
// Enter a message handler loop
//
//-------------------------------------------------------------------------
nsresult nsAppShell::Run()
{
EventRecord theevent;
RgnHandle fMouseRgn=NULL;
long sleep=0;
PRInt16 haveevent;
mRunning = TRUE;
while(mRunning)
{
haveevent = WaitNextEvent(everyEvent,&theevent,sleep,fMouseRgn);
if(haveevent)
{
switch(theevent.what)
{
}
}
}
//if (mDispatchListener)
//mDispatchListener->AfterDispatch();
return NS_OK;
}
//-------------------------------------------------------------------------
//
// Exit a message handler loop
//
//-------------------------------------------------------------------------
void nsAppShell::Exit()
{
mRunning = FALSE;
}
//-------------------------------------------------------------------------
//
// nsAppShell constructor
//
//-------------------------------------------------------------------------
nsAppShell::nsAppShell()
{
mRefCnt = 0;
mDispatchListener = 0;
}
//-------------------------------------------------------------------------
//
// nsAppShell destructor
//
//-------------------------------------------------------------------------
nsAppShell::~nsAppShell()
{
}
//-------------------------------------------------------------------------
//
// GetNativeData
//
//-------------------------------------------------------------------------
void* nsAppShell::GetNativeData(PRUint32 aDataType)
{
if (aDataType == NS_NATIVE_SHELL)
{
//return mTopLevel;
}
return nsnull;
}

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

@ -0,0 +1,58 @@
/* -*- 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 nsAppShell_h__
#define nsAppShell_h__
#include "nsIAppShell.h"
#include "nsToolKit.h"
/**
* Native MOTIF Application shell wrapper
*/
class nsAppShell : public nsIAppShell
{
private:
//Widget mTopLevel;
//XtAppContext mAppContext;
nsDispatchListener* mDispatchListener;
nsToolkit* mToolKit;
PRBool mRunning;
public:
nsAppShell();
virtual ~nsAppShell();
NS_DECL_ISUPPORTS
// nsIAppShellInterface
virtual void Create(int* argc, char ** argv);
virtual nsresult Run();
virtual void Exit();
virtual void SetDispatchListener(nsDispatchListener* aDispatchListener);
virtual void* GetNativeData(PRUint32 aDataType);
};
#endif // nsAppShell_h__

191
widget/src/mac/nsButton.cpp Normal file
Просмотреть файл

@ -0,0 +1,191 @@
/* -*- 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 "nsButton.h"
#include "nsIButton.h"
#include "nsToolkit.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include "nsXtEventHandler.h"
#include <Xm/PushB.h>
#define DBG 0
//-------------------------------------------------------------------------
//
// nsButton constructor
//
//-------------------------------------------------------------------------
nsButton::nsButton(nsISupports *aOuter) : nsWindow(aOuter)
{
}
void nsButton::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else if (aAppShell) {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
mWidget = ::XtVaCreateManagedWidget("button",
xmPushButtonWidgetClass,
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("nsButton");
}
void nsButton::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
// nsButton destructor
//
//-------------------------------------------------------------------------
nsButton::~nsButton()
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsButton::QueryObject(REFNSIID aIID, void** aInstancePtr)
{
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
if (aIID.Equals(kIButtonIID)) {
AddRef();
*aInstancePtr = (void**) &mAggWidget;
return NS_OK;
}
return nsWindow::QueryObject(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Set this button label
//
//-------------------------------------------------------------------------
void nsButton::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 nsButton::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);
}
//-------------------------------------------------------------------------
//
// paint message. Don't send the paint out
//
//-------------------------------------------------------------------------
PRBool nsButton::OnPaint(nsPaintEvent &aEvent)
{
//printf("** nsButton::OnPaint **\n");
return PR_FALSE;
}
PRBool nsButton::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
#define GET_OUTER() ((nsButton*) ((char*)this - nsButton::GetOuterOffset()))
void nsButton::AggButton::GetLabel(nsString& aBuffer)
{
GET_OUTER()->GetLabel(aBuffer);
}
void nsButton::AggButton::SetLabel(const nsString& aText)
{
GET_OUTER()->SetLabel(aText);
}
//----------------------------------------------------------------------
BASE_IWIDGET_IMPL(nsButton, AggButton);

90
widget/src/mac/nsButton.h Normal file
Просмотреть файл

@ -0,0 +1,90 @@
/* -*- 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 nsButton_h__
#define nsButton_h__
//#include "nsdefs.h"
#include "nsWindow.h"
#include "nsIButton.h"
/**
* Native Motif button wrapper
*/
class nsButton : public nsWindow
{
public:
nsButton(nsISupports *aOuter);
virtual ~nsButton();
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
// nsIButton part
virtual void SetLabel(const nsString& aText);
virtual void GetLabel(nsString& aBuffer);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
private:
// this should not be public
static PRInt32 GetOuterOffset() {
return offsetof(nsButton,mAggWidget);
}
// Aggregator class and instance variable used to aggregate in the
// nsIButton interface to nsButton w/o using multiple
// inheritance.
class AggButton : public nsIButton {
public:
AggButton();
virtual ~AggButton();
AGGREGATE_METHOD_DEF
// nsIButton
virtual void SetLabel(const nsString &aText);
virtual void GetLabel(nsString &aBuffer);
};
AggButton mAggWidget;
friend class AggButton;
};
#endif // nsButton_h__

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

@ -0,0 +1,312 @@
/* -*- 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)
{
mLowerLeft = PR_TRUE;
}
//-------------------------------------------------------------------------
//
// nsCheckButton destructor
//
//-------------------------------------------------------------------------
nsCheckButton::~nsCheckButton()
{
}
//-------------------------------------------------------------------------
//
// nsCheckButton Creator
//
//-------------------------------------------------------------------------
void nsCheckButton::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
mWidget = ::XtVaCreateManagedWidget("",
xmToggleButtonWidgetClass,
parentWidget,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNrecomputeSize, False,
XmNhighlightOnEnter, False,
XmNx, aRect.x,
XmNy, aRect.y,
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);
// 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(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsCheckButton::QueryObject(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::QueryObject(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(nsSizeEvent &aEvent)
{
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);

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

@ -0,0 +1,105 @@
/* -*- 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 QueryObject(REFNSIID aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = 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(nsSizeEvent &aEvent);
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();
AGGREGATE_METHOD_DEF
// nsICheckButton
virtual void SetLabel(const nsString &aText);
virtual void GetLabel(nsString &aBuffer);
virtual void SetState(PRBool aState);
virtual PRBool GetState();
};
AggCheckButton mAggWidget;
friend class AggCheckButton;
};
#endif // nsCheckButton_h__

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

@ -0,0 +1,579 @@
/* -*- 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 "nsComboBox.h"
#include "nsColor.h"
#include "nsGUIEvent.h"
#include "nsString.h"
#include "nsStringUtil.h"
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#define DBG 0
#define INITIAL_MAX_ITEMS 128
#define ITEMS_GROWSIZE 128
//-------------------------------------------------------------------------
//
// nsComboBox constructor
//
//-------------------------------------------------------------------------
nsComboBox::nsComboBox(nsISupports *aOuter) : nsWindow(aOuter)
{
mMultiSelect = PR_FALSE;
mBackground = NS_RGB(124, 124, 124);
mMaxNumItems = INITIAL_MAX_ITEMS;
mItems = (Widget *)new long[INITIAL_MAX_ITEMS];
mNumItems = 0;
}
//-------------------------------------------------------------------------
//
// nsComboBox:: destructor
//
//-------------------------------------------------------------------------
nsComboBox::~nsComboBox()
{
if (mItems != nsnull) {
delete[] mItems;
}
}
//-------------------------------------------------------------------------
//
// initializer
//
//-------------------------------------------------------------------------
void nsComboBox::SetMultipleSelection(PRBool aMultipleSelections)
{
mMultiSelect = aMultipleSelections;
}
//-------------------------------------------------------------------------
//
// AddItemAt
//
//-------------------------------------------------------------------------
void nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
{
NS_ALLOC_STR_BUF(val, aItem, 256);
XmString str;
Arg args[30];
int argc = 0;
str = XmStringCreateLocalized(val);
XtSetArg(args[argc], XmNlabelString, str); argc++;
Widget btn = XmCreatePushButton(mPullDownMenu, val, args, argc);
XtManageChild(btn);
if (mNumItems == mMaxNumItems) {
// [TODO] Grow array here by ITEMS_GROWSIZE
}
mItems[mNumItems++] = btn;
NS_FREE_STR_BUF(val);
}
//-------------------------------------------------------------------------
//
// Finds an item at a postion
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
{
NS_ALLOC_STR_BUF(val, aItem, 256);
int i;
PRInt32 index = -1;
for (i=0;i<mNumItems && index == -1;i++) {
XmString str;
XtVaGetValues(mItems[i], XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
if (!strcmp(text, val)) {
index = i;
}
XtFree(text);
}
}
NS_FREE_STR_BUF(val);
return index;
}
//-------------------------------------------------------------------------
//
// CountItems - Get Item Count
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetItemCount()
{
return (PRInt32)mNumItems;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
{
if (aPosition >= 0 && aPosition < mNumItems) {
XtUnmanageChild(mItems[aPosition]);
XtDestroyWidget(mItems[aPosition]);
int i;
for (i=aPosition ; i < mNumItems-1; i++) {
mItems[i] = mItems[i+1];
}
mItems[mNumItems-1] = NULL;
mNumItems--;
return PR_TRUE;
}
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
{
PRBool result = PR_FALSE;
if (aPosition < 0 || aPosition >= mNumItems) {
return result;
}
XmString str;
XtVaGetValues(mItems[aPosition], XmNlabelString, &str, nsnull);
char * text;
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &text)) {
anItem = text;
XtFree(text);
}
return result;
}
//-------------------------------------------------------------------------
//
// Gets the selected of selected item
//
//-------------------------------------------------------------------------
void nsComboBox::GetSelectedItem(nsString& aItem)
{
Widget w;
XtVaGetValues(mWidget, XmNmenuHistory, &w, NULL);
int i;
for (i=0;i<mNumItems;i++) {
if (mItems[i] == w) {
GetItemAt(aItem, i);
}
}
}
//-------------------------------------------------------------------------
//
// Gets the list of selected otems
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetSelectedIndex()
{
if (!mMultiSelect) {
Widget w;
XtVaGetValues(mWidget, XmNmenuHistory, &w, NULL);
int i;
for (i=0;i<mNumItems;i++) {
if (mItems[i] == w) {
return (PRInt32)i;
}
}
} else {
NS_ASSERTION(0, "Multi selection list box does not support GetSlectedIndex()");
}
return -1;
}
//-------------------------------------------------------------------------
//
// SelectItem
//
//-------------------------------------------------------------------------
void nsComboBox::SelectItem(PRInt32 aPosition)
{
if (!mMultiSelect) {
if (aPosition >= 0 && aPosition < mNumItems) {
XtVaSetValues(mWidget,
XmNmenuHistory, mItems[aPosition],
NULL);
}
} else {
// this is an error
}
}
//-------------------------------------------------------------------------
//
// GetSelectedCount
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::GetSelectedCount()
{
if (!mMultiSelect) {
PRInt32 inx = GetSelectedIndex();
return (inx == -1? 0 : 1);
} else {
return 0;//::SendMessage(mWnd, LB_GETSELCOUNT, (int)0, (LPARAM)0);
}
}
//-------------------------------------------------------------------------
//
// GetSelectedIndices
//
//-------------------------------------------------------------------------
void nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
{
// this is an error
}
//-------------------------------------------------------------------------
//
// Deselect
//
//-------------------------------------------------------------------------
void nsComboBox::Deselect()
{
if (!mMultiSelect) {
//::SendMessage(mWnd, LB_SETCURSEL, (WPARAM)-1, (LPARAM)0);
} else {
// this is an error
}
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsComboBox::QueryObject(const nsIID& aIID, void** aInstancePtr)
{
nsresult result = nsWindow::QueryObject(aIID, aInstancePtr);
static NS_DEFINE_IID(kIComboBoxIID, NS_ICOMBOBOX_IID);
static NS_DEFINE_IID(kIListWidgetIID, NS_ILISTWIDGET_IID);
if (result == NS_NOINTERFACE) {
if (aIID.Equals(kIComboBoxIID)) {
*aInstancePtr = (void*) ((nsIComboBox*)&mAggWidget);
AddRef();
result = NS_OK;
}
else if (aIID.Equals(kIListWidgetIID)) {
*aInstancePtr = (void*) ((nsIListWidget*)&mAggWidget);
AddRef();
result = NS_OK;
}
}
return result;
}
//-------------------------------------------------------------------------
//
// nsComboBox Creator
//
//-------------------------------------------------------------------------
void nsComboBox::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
aParent->AddChild(this);
Widget parentWidget = nsnull;
if (DBG) fprintf(stderr, "aParent 0x%x\n", aParent);
if (aParent) {
parentWidget = (Widget) aParent->GetNativeData(NS_NATIVE_WIDGET);
} else if (aAppShell) {
parentWidget = (Widget) aAppShell->GetNativeData(NS_NATIVE_SHELL);
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
/*mWidget = ::XtVaCreateManagedWidget("",
xmListWidgetClass,
parentWidget,
XmNitemCount, 0,
XmNwidth, aRect.width,
XmNheight, aRect.height,
XmNx, aRect.x,
XmNy, aRect.y,
nsnull);
*/
Arg args[30];
int argc;
argc = 0;
XtSetArg(args[argc], XmNx, 0); argc++;
XtSetArg(args[argc], XmNy, 0); argc++;
mPullDownMenu = XmCreatePulldownMenu(parentWidget, "pulldown", args, argc);
argc = 0;
XtSetArg(args[argc], XmNmarginHeight, 0); argc++;
XtSetArg(args[argc], XmNmarginWidth, 0); argc++;
XtSetArg(args[argc], XmNrecomputeSize, False); argc++;
XtSetArg(args[argc], XmNresizeHeight, False); argc++;
XtSetArg(args[argc], XmNresizeWidth, False); argc++;
XtSetArg(args[argc], XmNspacing, False); argc++;
XtSetArg(args[argc], XmNborderWidth, 0); argc++;
XtSetArg(args[argc], XmNnavigationType, XmTAB_GROUP); argc++;
XtSetArg(args[argc], XmNtraversalOn, True); argc++;
XtSetArg(args[argc], XmNorientation, XmVERTICAL); argc++;
XtSetArg(args[argc], XmNadjustMargin, False); argc++;
XtSetArg(args[argc], XmNsubMenuId, mPullDownMenu); argc++;
XtSetArg(args[argc], XmNuserData, (XtPointer)this); argc++;
XtSetArg(args[argc], XmNx, aRect.x); argc++;
XtSetArg(args[argc], XmNy, aRect.y); argc++;
XtSetArg(args[argc], XmNwidth, aRect.width); argc++;
XtSetArg(args[argc], XmNheight, aRect.height); argc++;
mWidget = XmCreateOptionMenu(parentWidget, "", args, argc);
mOptionMenu = XmOptionLabelGadget(mWidget);
XtUnmanageChild(mOptionMenu);
/*XtVaSetValues(mWidget,
XmNx, aRect.x,
XmNy, aRect.y,
XmNwidth, aRect.width,
XmNheight, aRect.height,
nsnull);*/
//XtManageChild(mPullDownMenu);
//XtManageChild(mOptionMenu);
//XtSetMappedWhenManaged(mOptionMenu, False);
//XtManageChild(mOptionMenu);
//if (DBG)
// save the event callback function
mEventCallback = aHandleEventFunction;
//InitCallbacks();
}
//-------------------------------------------------------------------------
//
// nsComboBox Creator
//
//-------------------------------------------------------------------------
void nsComboBox::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
// move, paint, resizes message - ignore
//
//-------------------------------------------------------------------------
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//
// paint message. Don't send the paint out
//
//-------------------------------------------------------------------------
PRBool nsComboBox::OnPaint(nsPaintEvent &aEvent)
{
return PR_FALSE;
}
PRBool nsComboBox::OnResize(nsSizeEvent &aEvent)
{
return PR_FALSE;
}
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
#define GET_OUTER() ((nsComboBox*) ((char*)this - nsComboBox::GetOuterOffset()))
//-------------------------------------------------------------------------
//
// SetMultipleSelection
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::SetMultipleSelection(PRBool aMultipleSelections)
{
GET_OUTER()->SetMultipleSelection(aMultipleSelections);
}
//-------------------------------------------------------------------------
//
// AddItemAt
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
{
GET_OUTER()->AddItemAt(aItem, aPosition);
}
//-------------------------------------------------------------------------
//
// Finds an item at a postion
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::AggComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
{
return GET_OUTER()->FindItem(aItem, aStartPos);
}
//-------------------------------------------------------------------------
//
// CountItems - Get Item Count
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::AggComboBox::GetItemCount()
{
return GET_OUTER()->GetItemCount();
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::AggComboBox::RemoveItemAt(PRInt32 aPosition)
{
return GET_OUTER()->RemoveItemAt(aPosition);
}
//-------------------------------------------------------------------------
//
// Removes an Item at a specified location
//
//-------------------------------------------------------------------------
PRBool nsComboBox::AggComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
{
return GET_OUTER()->GetItemAt(anItem, aPosition);
}
//-------------------------------------------------------------------------
//
// Gets the selected of selected item
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::GetSelectedItem(nsString& aItem)
{
GET_OUTER()->GetSelectedItem(aItem);
}
//-------------------------------------------------------------------------
//
// Gets the list of selected otems
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::AggComboBox::GetSelectedIndex()
{
return GET_OUTER()->GetSelectedIndex();
}
//-------------------------------------------------------------------------
//
// SelectItem
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::SelectItem(PRInt32 aPosition)
{
GET_OUTER()->SelectItem(aPosition);
}
//-------------------------------------------------------------------------
//
// GetSelectedCount
//
//-------------------------------------------------------------------------
PRInt32 nsComboBox::AggComboBox::GetSelectedCount()
{
return GET_OUTER()->GetSelectedCount();
}
//-------------------------------------------------------------------------
//
// GetSelectedIndices
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
{
GET_OUTER()->GetSelectedIndices(aIndices, aSize);
}
//-------------------------------------------------------------------------
//
// Deselect
//
//-------------------------------------------------------------------------
void nsComboBox::AggComboBox::Deselect()
{
GET_OUTER()->Deselect();
}
//----------------------------------------------------------------------
BASE_IWIDGET_IMPL(nsComboBox, AggComboBox);

121
widget/src/mac/nsComboBox.h Normal file
Просмотреть файл

@ -0,0 +1,121 @@
/* -*- 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 nsComboBox_h__
#define nsComboBox_h__
#include "nsWindow.h"
#include "nsIComboBox.h"
/**
* Native Motif Listbox wrapper
*/
class nsComboBox : public nsWindow
{
public:
nsComboBox(nsISupports *aOuter);
virtual ~nsComboBox();
// nsISupports. Forward to the nsObject base class
NS_IMETHOD QueryObject(const nsIID& aIID, void** aInstancePtr);
void Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
virtual PRBool OnPaint(nsPaintEvent & aEvent);
virtual PRBool OnResize(nsSizeEvent &aEvent);
// nsIComboBox interface
void SetMultipleSelection(PRBool aMultipleSelections);
void AddItemAt(nsString &aItem, PRInt32 aPosition);
PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
PRInt32 GetItemCount();
PRBool RemoveItemAt(PRInt32 aPosition);
PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
void GetSelectedItem(nsString& aItem);
PRInt32 GetSelectedIndex();
PRInt32 GetSelectedCount();
void GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
void SelectItem(PRInt32 aPosition);
void Deselect() ;
protected:
Widget mPullDownMenu;
Widget mOptionMenu;
PRBool mMultiSelect;
Widget * mItems; // an array of Widgets
int mMaxNumItems;
int mNumItems;
private:
// this should not be public
static PRInt32 GetOuterOffset() {
return offsetof(nsComboBox,mAggWidget);
}
// Aggregator class and instance variable used to aggregate in the
// nsIComboBox interface to nsComboBox w/o using multiple
// inheritance.
class AggComboBox : public nsIComboBox {
public:
AggComboBox();
virtual ~AggComboBox();
AGGREGATE_METHOD_DEF
// nsIComboBox
void SetMultipleSelection(PRBool aMultipleSelections);
void AddItemAt(nsString &aItem, PRInt32 aPosition);
PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
PRInt32 GetItemCount();
PRBool RemoveItemAt(PRInt32 aPosition);
PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
void GetSelectedItem(nsString& aItem);
PRInt32 GetSelectedIndex();
PRInt32 GetSelectedCount();
void GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
void SelectItem(PRInt32 aPosition);
void Deselect() ;
};
AggComboBox mAggWidget;
friend class AggComboBox;
};
#endif // nsComboBox_h__

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

@ -0,0 +1,354 @@
/* -*- 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"
#include "nsStringUtil.h"
#define DBG 0
extern XtAppContext gAppContext;
//-------------------------------------------------------------------------
//
// nsFileWidget constructor
//
//-------------------------------------------------------------------------
nsFileWidget::nsFileWidget(nsISupports *aOuter) : nsWindow(aOuter),
mIOwnEventLoop(PR_FALSE)
{
//mWnd = NULL;
mNumberOfFilters = 0;
}
void nsFileWidget::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
nsString title("Load");
Create(aParent, title, eMode_load, aContext, aAppShell, aToolkit, aInitData);
}
//-------------------------------------------------------------------------
void nsFileWidget:: Create(nsIWidget *aParent,
nsString& aTitle,
nsMode aMode,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
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 ;
}
InitToolkit(aToolkit, aParent);
InitDeviceContext(aContext, parentWidget);
if (DBG) fprintf(stderr, "Parent 0x%x\n", parentWidget);
mWidget = XmCreateFileSelectionDialog(parentWidget, "filesb", NULL, 0);
NS_ALLOC_STR_BUF(title, aTitle, 256);
XmString str;
str = XmStringCreate(title, XmFONTLIST_DEFAULT_TAG);
XtVaSetValues(mWidget, XmNdialogTitle, str, nsnull);
NS_FREE_STR_BUF(title);
XmStringFree(str);
XtAddCallback(mWidget, XmNcancelCallback, nsXtWidget_FSBCancel_Callback, this);
XtAddCallback(mWidget, XmNokCallback, nsXtWidget_FSBOk_Callback, this);
//XtManageChild(mWidget);
}
void nsFileWidget::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
}
//-------------------------------------------------------------------------
//
// Query interface implementation
//
//-------------------------------------------------------------------------
nsresult nsFileWidget::QueryObject(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::QueryObject(aIID, aInstancePtr);
}
//-------------------------------------------------------------------------
//
// Ok's the dialog
//
//-------------------------------------------------------------------------
void nsFileWidget::OnOk()
{
XtUnmanageChild(mWidget);
mWasCancelled = PR_FALSE;
mIOwnEventLoop = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Cancel the dialog
//
//-------------------------------------------------------------------------
void nsFileWidget::OnCancel()
{
XtUnmanageChild(mWidget);
mWasCancelled = PR_TRUE;
mIOwnEventLoop = PR_FALSE;
}
//-------------------------------------------------------------------------
//
// Show - Display the file dialog
//
//-------------------------------------------------------------------------
void nsFileWidget::Show(PRBool bState)
{
nsresult result = nsEventStatus_eIgnore;
XtManageChild(mWidget);
// XXX Kludge: gAppContext is a global set in nsAppShell
XEvent event;
mIOwnEventLoop = PR_TRUE;
while (mIOwnEventLoop) {
XtAppNextEvent(gAppContext, &event);
XtDispatchEvent(&event);
}
if (!mWasCancelled) {
XmString str;
char * fileBuf;
XtVaGetValues(mWidget, XmNdirSpec, &str, nsnull);
if (XmStringGetLtoR(str, XmFONTLIST_DEFAULT_TAG, &fileBuf)) {
// Set user-selected location of file or directory
mFile.SetLength(0);
mFile.Append(fileBuf);
XmStringFree(str);
XtFree(fileBuf);
}
}
/*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);
}
//-------------------------------------------------------------------------
//
// Get the file + path
//
//-------------------------------------------------------------------------
void nsFileWidget::SetDefaultString(nsString& aString)
{
mDefault = aString;
}
//-------------------------------------------------------------------------
//
// 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,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
void *aInitData)
{
GET_OUTER()->Create(aParent, aTitle, aMode, aContext, aAppShell, aToolkit, aInitData);
}
void nsFileWidget::AggFileWidget::OnOk()
{
GET_OUTER()->OnOk();
}
void nsFileWidget::AggFileWidget::OnCancel()
{
GET_OUTER()->OnCancel();
}
void nsFileWidget::AggFileWidget::Show(PRBool bState)
{
GET_OUTER()->Show(bState);
}
void nsFileWidget::AggFileWidget::GetFile(nsString& aFile)
{
GET_OUTER()->GetFile(aFile);
}
void nsFileWidget::AggFileWidget::SetDefaultString(nsString& aFile)
{
GET_OUTER()->SetDefaultString(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;
}