Normalize widget api on UNIX and win, add LAF interface, make sample

apps function again.
This commit is contained in:
scullin%netscape.com 1998-07-29 18:51:45 +00:00
Родитель 551a6d7af4
Коммит 498c4d6e98
12 изменённых файлов: 111 добавлений и 54 удалений

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

@ -26,7 +26,7 @@ EXPORTS=nsui.h nsIWidget.h nsIButton.h nsICheckButton.h nsIListWidget.h \
nsIListBox.h nsIFileWidget.h nsIScrollbar.h nsGUIEvent.h \
nsIRadioButton.h nsIRadioGroup.h nsIMouseListener.h \
nsIEventListener.h nsIToolkit.h nsWidgetsCID.h nsITabWidget.h \
nsITooltipWidget.h nsIAppShell.h nsStringUtil.h
nsITooltipWidget.h nsIAppShell.h nsStringUtil.h nsILookAndFeel.h
include <$(DEPTH)\config\rules.mak>

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

@ -60,6 +60,7 @@ public:
nsString& aTitle,
nsMode aMode,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
void *aInitData = 0) = 0;

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

@ -28,6 +28,7 @@
#include "nsGUIEvent.h"
// forward declarations
class nsIAppShell;
class nsIToolkit;
class nsIFontMetrics;
class nsIToolkit;
@ -129,6 +130,10 @@ class nsIWidget : public nsISupports {
* @param parent or null if it's a top level window
* @param aRect the widget dimension
* @param aHandleEventFunction the event handler callback function
* @param aContext
* @param aAppShell the parent application shell. If nsnull,
* the parent window's application shell will be used.
* @param aToolkit
* @param aInitData data that is used for widget initialization
*
*/
@ -136,6 +141,7 @@ class nsIWidget : public nsISupports {
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull) = 0;
@ -159,10 +165,11 @@ class nsIWidget : public nsISupports {
* @param aHandleEventFunction the event handler callback function
*/
virtual void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIToolkit *aToolkit = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull) = 0;
/**
@ -380,6 +387,7 @@ class nsIWidget : public nsISupports {
virtual void* GetNativeData(PRUint32 aDataType) = 0;
virtual nsIRenderingContext* GetRenderingContext() = 0;
virtual nsIDeviceContext* GetDeviceContext() = 0;
virtual nsIAppShell *GetAppShell() = 0;
//@}
/**

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

@ -96,3 +96,8 @@
{ 0x2d96b3df, 0xc051, 0x11d1, \
{0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} }
/* 21B51DE0-21A3-11d2-B6E0-00805F8A2676 */
#define NS_LOOKANDFEEL_CID \
{ 0x21b51de0, 0x21a3, 0x11d2, \
{ 0xb6, 0xe0, 0x0, 0x80, 0x5f, 0x8a, 0x26, 0x76 } }

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

@ -49,8 +49,9 @@ OBJS = \
.\$(OBJDIR)\nsFileWidget.obj \
.\$(OBJDIR)\nsScrollbar.obj \
.\$(OBJDIR)\nsTabWidget.obj \
.\$(OBJDIR)\nsTooltipWidget.obj \
.\$(OBJDIR)\nsAppShell.obj \
.\$(OBJDIR)\nsTooltipWidget.obj \
.\$(OBJDIR)\nsAppShell.obj \
.\$(OBJDIR)\nsLookAndFeel.obj \
$(NULL)
LINCS= \

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

@ -157,6 +157,7 @@ void nsFileWidget:: Create(nsIWidget *aParent,
nsString& aTitle,
nsMode aMode,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
void *aInitData)
{

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

@ -46,6 +46,7 @@ class nsFileWidget : public nsIFileWidget, public nsObject
nsString& aTitle,
nsMode aMode,
nsIDeviceContext *aContext = nsnull,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
void *aInitData = nsnull);

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

@ -26,6 +26,7 @@
#include "nsComboBox.h"
#include "nsFileWidget.h"
#include "nsListBox.h"
#include "nsLookAndFeel.h"
#include "nsRadioButton.h"
#include "nsRadioGroup.h"
#include "nsScrollbar.h"
@ -54,7 +55,7 @@ static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kCTabWidget, NS_TABWIDGET_CID);
static NS_DEFINE_IID(kCTooltipWidget, NS_TOOLTIPWIDGET_CID);
static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID);
static NS_DEFINE_IID(kCLookAndFeel, NS_LOOKANDFEEL_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
@ -198,6 +199,9 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter,
else if (mClassID.Equals(kCAppShell)) {
inst = (nsObject*)new nsAppShell(aOuter);
}
else if (mClassID.Equals(kCLookAndFeel)) {
inst = (nsObject*)new nsLookAndFeel(aOuter);
}
if (inst == NULL) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -17,6 +17,7 @@
*/
#include "nsWindow.h"
#include "nsIAppShell.h"
#include "nsIFontMetrics.h"
#include "nsIFontCache.h"
#include "nsGUIEvent.h"
@ -354,6 +355,7 @@ nsWindow::nsWindow(nsISupports *aOuter) : nsObject(aOuter)
mChildren = NULL;
mEventCallback = NULL;
mToolkit = NULL;
mAppShell = NULL;
mMouseListener = NULL;
mEventListener = NULL;
mBackground = ::GetSysColor(COLOR_BTNFACE);
@ -418,6 +420,7 @@ void nsWindow::Create(nsIWidget *aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
@ -441,6 +444,9 @@ void nsWindow::Create(nsIWidget *aParent,
}
mAppShell = aAppShell;
NS_IF_ADDREF(mAppShell);
//
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
@ -521,6 +527,7 @@ void nsWindow::Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell,
nsIToolkit *aToolkit,
nsWidgetInitData *aInitData)
{
@ -538,6 +545,9 @@ void nsWindow::Create(nsNativeWidget aParent,
}
mAppShell = aAppShell;
NS_IF_ADDREF(aAppShell);
//
// Switch to the "main gui thread" if necessary... This method must
// be executed on the "gui thread"...
@ -637,6 +647,7 @@ void nsWindow::Destroy()
if (mTooltip) {
VERIFY(::DestroyWindow(mTooltip));
}
NS_IF_RELEASE(mAppShell);
}
@ -1197,6 +1208,17 @@ nsIDeviceContext* nsWindow::GetDeviceContext()
return mContext;
}
//-------------------------------------------------------------------------
//
// Return the App Shell
//
//-------------------------------------------------------------------------
nsIAppShell *nsWindow::GetAppShell()
{
NS_IF_ADDREF(mAppShell);
return mAppShell;
}
//-------------------------------------------------------------------------
//
@ -1233,23 +1255,25 @@ BOOL nsWindow::CallMethod(MethodInfo *info)
switch (info->methodId) {
case nsWindow::CREATE:
NS_ASSERTION(info->nArgs == 6, "Wrong number of arguments to CallMethod");
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
Create((nsIWidget*)(info->args[0]),
(nsRect&)*(nsRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIToolkit*)(info->args[4]),
(nsWidgetInitData*)(info->args[5]));
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
break;
case nsWindow::CREATE_NATIVE:
NS_ASSERTION(info->nArgs == 6, "Wrong number of arguments to CallMethod");
NS_ASSERTION(info->nArgs == 7, "Wrong number of arguments to CallMethod");
Create((nsNativeWidget)(info->args[0]),
(nsRect&)*(nsRect*)(info->args[1]),
(EVENT_CALLBACK)(info->args[2]),
(nsIDeviceContext*)(info->args[3]),
(nsIToolkit*)(info->args[4]),
(nsWidgetInitData*)(info->args[5]));
(nsIAppShell *)(info->args[4]),
(nsIToolkit*)(info->args[5]),
(nsWidgetInitData*)(info->args[6]));
return TRUE;
case nsWindow::DESTROY:

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

@ -59,12 +59,14 @@ public:
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
virtual void Create(nsNativeWidget aParent,
const nsRect &aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext *aContext,
nsIAppShell *aAppShell = nsnull,
nsIToolkit *aToolkit = nsnull,
nsWidgetInitData *aInitData = nsnull);
virtual void Destroy();
@ -98,6 +100,7 @@ public:
virtual nsIRenderingContext* GetRenderingContext();
virtual void SetColorMap(nsColorMap *aColorMap);
virtual nsIDeviceContext* GetDeviceContext();
virtual nsIAppShell * GetAppShell();
virtual void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
virtual nsIToolkit* GetToolkit();
virtual void SetBorderStyle(nsBorderStyle aBorderStyle);
@ -171,6 +174,7 @@ protected:
EVENT_CALLBACK mEventCallback;
nsIDeviceContext *mContext;
nsIFontMetrics *mFontMetrics;
nsIAppShell *mAppShell;
nsToolkit *mToolkit;
nsIMouseListener * mMouseListener;
@ -252,10 +256,11 @@ protected:
const nsRect &aRect, \
EVENT_CALLBACK aHandleEventFunction, \
nsIDeviceContext *aContext, \
nsIAppShell *aAppShell = nsnull, \
nsIToolkit *aToolkit = nsnull, \
nsWidgetInitData *aInitData = nsnull) \
{ \
nsWindow::Create(aParent, aRect, aHandleEventFunction, aContext, aToolkit, aInitData); \
nsWindow::Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); \
} \
#define BASE_WINDOWS_METHODS \
@ -263,10 +268,11 @@ protected:
const nsRect &aRect, \
EVENT_CALLBACK aHandleEventFunction, \
nsIDeviceContext *aContext, \
nsIAppShell *aAppShell = nsnull, \
nsIToolkit *aToolkit = nsnull, \
nsWidgetInitData *aInitData = nsnull) \
{ \
nsWindow::Create(aParent, aRect, aHandleEventFunction, aContext, aToolkit, aInitData); \
nsWindow::Create(aParent, aRect, aHandleEventFunction, aContext, aAppShell, aToolkit, aInitData); \
} \
void Destroy(void) \
{ \
@ -366,6 +372,10 @@ protected:
{ \
return nsWindow::GetDeviceContext(); \
} \
nsIAppShell* GetAppShell() \
{ \
return nsWindow::GetAppShell(); \
} \
void Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) \
{ \
nsWindow::Scroll(aDx, aDy, aClipRect); \

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

@ -21,6 +21,7 @@
#include "nsIButton.h"
#include "nsICheckButton.h"
#include "nsILookAndFeel.h"
#include "nsIRadioButton.h"
#include "nsITextWidget.h"
#include "nsIScrollbar.h"
@ -61,6 +62,7 @@ static NS_DEFINE_IID(kIScrollbarIID, NS_ISCROLLBAR_IID);
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
//
@ -83,7 +85,8 @@ nsEventStatus PR_CALLBACK HandleEventMain(nsGUIEvent *aEvent)
if (next) {
nsIWidget *widget;
if (NS_OK == next->QueryInterface(kIWidgetIID, (void**)&widget)) {
widget->Resize(0, 0, 200, ((nsSizeEvent*)aEvent)->windowSize->height - 26, PR_TRUE);
widget->Resize(0, 0, 200,
((nsSizeEvent*)aEvent)->windowSize->height, PR_TRUE);
NS_RELEASE(widget);
}
}
@ -93,10 +96,10 @@ nsEventStatus PR_CALLBACK HandleEventMain(nsGUIEvent *aEvent)
}
scribbleData.drawPane->Resize(200,
0,
((nsSizeEvent*)aEvent)->windowSize->width - 206,
((nsSizeEvent*)aEvent)->windowSize->height - 26,
PR_TRUE);
0,
((nsSizeEvent*)aEvent)->windowSize->width - 200,
((nsSizeEvent*)aEvent)->windowSize->height,
PR_TRUE);
break;
}
@ -421,6 +424,7 @@ nsresult CreateApplication(int * argc, char ** argv)
static NS_DEFINE_IID(kCVertScrollbarCID, NS_VERTSCROLLBAR_CID);
static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID);
static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID);
static NS_DEFINE_IID(kCLookAndFeelCID, NS_LOOKANDFEEL_CID);
NSRepository::RegisterFactory(kCAppShellCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
NSRepository::RegisterFactory(kCWindowCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
@ -435,7 +439,8 @@ nsresult CreateApplication(int * argc, char ** argv)
NSRepository::RegisterFactory(kCVertScrollbarCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
NSRepository::RegisterFactory(kCTextAreaCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
NSRepository::RegisterFactory(kCTextFieldCID, WIDGET_DLL, PR_FALSE, PR_FALSE);
NSRepository::RegisterFactory(kCLookAndFeelCID, WIDGET_DLL, PR_FALSE, PR_FALSE)
;
//NS_InitToolkit(PR_GetCurrentThread());
nsresult res;
@ -451,36 +456,37 @@ nsresult CreateApplication(int * argc, char ** argv)
// Create an application shell
nsIAppShell *appShell;
NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID, (void**)&appShell);
NSRepository::CreateInstance(kCAppShellCID, nsnull, kIAppShellIID,
(void**)&appShell);
appShell->Create(argc, argv);
nsILookAndFeel *laf;
NSRepository::CreateInstance(kCLookAndFeelCID, nsnull, kILookAndFeelIID,
(void**)&laf);
//
// create the main window
//
NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID, (void **)&(scribbleData.mainWindow));
//nsRect rect(100, 100, 600, 600);
//scribbleData.mainWindow->Create((nsIWidget*)NULL, rect, HandleEventMain, NULL);
#ifdef XP_PC
NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID,
(void **)&(scribbleData.mainWindow));
nsRect rect(100, 100, 600, 700);
scribbleData.mainWindow->Create((nsIWidget*)NULL, rect, HandleEventMain, NULL);
#endif
#ifdef XP_UNIX
nsRect rect(100, 100, 400, 580);
scribbleData.mainWindow->Create((nsNativeWidget)NULL, rect, HandleEventMain,
(nsIDeviceContext *)nsnull,
(nsIToolkit *)nsnull,
(nsWidgetInitData*)appShell->GetNativeData(NS_NATIVE_SHELL));
#endif
scribbleData.mainWindow->SetBackgroundColor(NS_RGB(255, 255, 255));
scribbleData.mainWindow->Create((nsIWidget*)NULL,
rect,
HandleEventMain,
NULL,
appShell);
scribbleData.mainWindow->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
scribbleData.mainWindow->SetTitle("Scribble");
//
// create the control pane
//
nsIWidget *controlPane;
rect.SetRect(0, 0, 200, 580);
rect.SetRect(0, 0, 200, 700);
NSRepository::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&controlPane);
controlPane->Create(scribbleData.mainWindow, rect, HandleEventControlPane, NULL);
controlPane->SetBackgroundColor(NS_RGB(255, 255, 255));
controlPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
controlPane->Show(PR_TRUE);
//
// Add the scribble/lines section
@ -494,7 +500,7 @@ nsresult CreateApplication(int * argc, char ** argv)
nsString cbLabel("Scribble");
scribbleData.scribble->SetLabel(cbLabel);
scribbleData.scribble->SetState(PR_FALSE);
//scribbleData.scribble->SetBackgroundColor(NS_RGB(255, 255, 255));
scribbleData.scribble->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
scribbleData.scribble->Show(PR_TRUE);
// create the "Lines" check button
@ -505,7 +511,7 @@ nsresult CreateApplication(int * argc, char ** argv)
nsString cbLabel1("Lines");
scribbleData.lines->SetLabel(cbLabel1);
scribbleData.lines->SetState(PR_TRUE);
//scribbleData.lines->SetBackgroundColor(NS_RGB(255, 255, 255));
scribbleData.lines->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
scribbleData.lines->Show(PR_TRUE);
//
// Add the circle/rectangle section
@ -519,7 +525,7 @@ nsresult CreateApplication(int * argc, char ** argv)
checkButton->Create(controlPane, rect, HandleEventCheck, NULL);
nsString cbLabel2("Circles");
checkButton->SetLabel(cbLabel2);
checkButton->SetBackgroundColor(NS_RGB(255, 255, 255));
checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
checkButton->Show(PR_TRUE);
NS_RELEASE(checkButton);
@ -530,7 +536,7 @@ nsresult CreateApplication(int * argc, char ** argv)
checkButton->Create(controlPane, rect, HandleEventCheck, NULL);
nsString cbLabel3("Rectangles");
checkButton->SetLabel(cbLabel3);
checkButton->SetBackgroundColor(NS_RGB(255, 255, 255));
checkButton->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
checkButton->Show(PR_TRUE);
NS_RELEASE(checkButton);
@ -587,16 +593,19 @@ nsresult CreateApplication(int * argc, char ** argv)
//
// create the draw pane
//
rect.SetRect(200, 0, 400, 580);
rect.SetRect(200, 0, 400, 700);
NSRepository::CreateInstance(kCChildCID, nsnull, kIWidgetIID, (void **)&scribbleData.drawPane);
scribbleData.drawPane->Create(scribbleData.mainWindow, rect, HandleEventGraphicPane, NULL);
scribbleData.drawPane->SetBackgroundColor(NS_RGB(255, 255, 255));
scribbleData.drawPane->SetBackgroundColor(laf->GetColor(nsLAF::WindowBackground));
scribbleData.drawPane->Show(PR_TRUE);
//
// show. We are in business...
//
scribbleData.mainWindow->Show(PR_TRUE);
laf->Release();
return(appShell->Run());
}

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

@ -1171,17 +1171,10 @@ nsresult WidgetTest(int *argc, char **argv)
// create the main window
//
NSRepository::CreateInstance(kCWindowCID, nsnull, kIWidgetIID, (void**)&window);
#ifdef XP_PC
nsRect rect(100, 100, 600, 700);
window->Create((nsIWidget*)NULL, rect, HandleEvent, NULL);
#endif
#ifdef XP_UNIX
nsRect rect(0, 0, 600, 700);
window->Create((nsNativeWidget)NULL, rect, HandleEvent,
(nsIDeviceContext *)nsnull,
(nsIToolkit *)nsnull,
(nsWidgetInitData*)appShell->GetNativeData(NS_NATIVE_SHELL));
#endif
window->Create((nsIWidget*) nsnull, rect, HandleEvent,
(nsIDeviceContext *) nsnull,
appShell);
window->SetTitle("TOP-LEVEL window");
window->Show(PR_TRUE);
window->SetBackgroundColor(NS_RGB(196, 196, 196));