diff --git a/widget/src/beos/Makefile.in b/widget/src/beos/Makefile.in new file mode 100644 index 000000000000..86a535b3c47f --- /dev/null +++ b/widget/src/beos/Makefile.in @@ -0,0 +1,85 @@ +#!gmake +# +# 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/NP\ +# +# 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. + + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +include $(topsrcdir)/config/config.mk + +LIBRARY_NAME = raptorwidgetbeos_s + +MODULE=widget + +REQUIRES=util img xpcom raptor netlib + +DEFINES += -D_IMPL_NS_WIDGET + +INCLUDES+= -I$(srcdir)/../xpwidgets -I$(srcdir)/. -I@top_srcdir@/gfx/src/beos + +INCLUDES += $(TK_CFLAGS) + +CPPSRCS = \ + nsPopUpMenu.cpp \ + nsMenuBar.cpp \ + nsMenu.cpp \ + nsMenuItem.cpp \ + nsObject.cpp \ + nsWindow.cpp \ + nsButton.cpp \ + nsCheckButton.cpp \ + nsRadioButton.cpp \ + nsDragService.cpp \ + nsListBox.cpp \ + nsComboBox.cpp \ + nsTextWidget.cpp \ + nsTextHelper.cpp \ + nsTextAreaWidget.cpp\ + nsFileWidget.cpp \ + nsScrollbar.cpp \ + nsTabWidget.cpp \ + nsTooltipWidget.cpp \ + nsAppShell.cpp \ + nsLabel.cpp \ + nsToolkit.cpp \ + nsSound.cpp \ + nsFontRetrieverService.cpp \ + nsFontSizeIterator.cpp \ + nsClipboard.cpp \ + nsLookAndFeel.cpp \ + $(NULL) + +TARGETS = $(LIBRARY) + +MKSHLIB := + +# we don't want the shared lib, but we want to force the creation of a static lib. +override NO_SHARED_LIB=1 +override NO_STATIC_LIB= + +include $(topsrcdir)/config/rules.mk + + + + + + + diff --git a/widget/src/beos/nsAppShell.cpp b/widget/src/beos/nsAppShell.cpp new file mode 100644 index 000000000000..65eec39e719e --- /dev/null +++ b/widget/src/beos/nsAppShell.cpp @@ -0,0 +1,294 @@ +/* -*- 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 "nsIWidget.h" +#include "nsIAppShell.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" +#include "nsTimer.h" +#include "plevent.h" + +#include +#include +#include + +struct ThreadInterfaceData +{ + void *data; + int32 sync; +}; + +static sem_id my_find_sem(const char *name) +{ + sem_id ret = B_ERROR; + + /* Get the sem_info for every sempahore in this team. */ + sem_info info; + int32 cookie = 0; + + while(get_next_sem_info(0, &cookie, &info) == B_OK) + if(strcmp(name, info.name) == 0) + { + ret = info.sem; + break; + } + + return ret; +} + +//------------------------------------------------------------------------- +// +// nsISupports implementation macro +// +//------------------------------------------------------------------------- +NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID); +NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID); + +static bool GetAppSig(char *sig) +{ + app_info appInfo; + BFile file; + BAppFileInfo appFileInfo; + image_info info; + int32 cookie = 0; + *sig = 0; + return get_next_image_info(0, &cookie, &info) == B_OK && + file.SetTo(info.name, B_READ_ONLY) == B_OK && + appFileInfo.SetTo(&file) == B_OK && + appFileInfo.GetSignature(sig) == B_OK; +} + +class nsBeOSApp : public BApplication +{ + sem_id init; +public: + nsBeOSApp(const char *signature, sem_id initsem); + virtual void ReadyToRun(void); +}; + +nsBeOSApp::nsBeOSApp(const char *signature, sem_id initsem) + : BApplication(signature), init(initsem) +{ +} + +void nsBeOSApp::ReadyToRun(void) +{ + release_sem(init); +} + +int32 bapp_thread(void *arg) +{ + // create and start BApplication + char sig[B_MIME_TYPE_LENGTH + 1]; + GetAppSig(sig); + nsBeOSApp *app = new nsBeOSApp(sig, (sem_id)arg); + app->Run(); + return 0; +} + +//------------------------------------------------------------------------- +// +// nsAppShell constructor +// +//------------------------------------------------------------------------- +nsAppShell::nsAppShell() +{ + NS_INIT_REFCNT(); + mDispatchListener = 0; + + sem_id initsem = create_sem(0, "bapp init"); + resume_thread(spawn_thread(bapp_thread, "BApplication", B_NORMAL_PRIORITY, (void *)initsem)); + acquire_sem(initsem); + delete_sem(initsem); +} + + +//------------------------------------------------------------------------- +// +// Create the application shell +// +//------------------------------------------------------------------------- + +NS_METHOD nsAppShell::Create(int* argc, char ** argv) +{ + // system wide unique names + // NOTE: this needs to be run from within the main application thread + char portname[64]; + char semname[64]; + sprintf(portname, "event%lx", PR_GetCurrentThread()); + sprintf(semname, "sync%lx", PR_GetCurrentThread()); + + if((eventport = find_port(portname)) < 0) + { + // we're here first + eventport = create_port(100, portname); + syncsem = create_sem(0, semname); + } + else + { + // the PLEventQueue stuff (in plevent.c) created the queue before we started + syncsem = my_find_sem(semname); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener) +{ + mDispatchListener = aDispatchListener; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Enter a message handler loop +// +//------------------------------------------------------------------------- + +nsresult nsAppShell::Run() +{ + int32 code; + ThreadInterfaceData id; + + NS_ADDREF_THIS(); + + while(read_port(eventport, &code, &id, sizeof(id)) >= 0) + { + switch(code) + { + case WM_TIMER : + { + TimerImpl *tobj = (TimerImpl *)id.data; + tobj->FireTimeout(); + if(! id.sync) + NS_RELEASE(tobj); + } + break; + + case WM_CALLMETHOD : + { + MethodInfo *mInfo = (MethodInfo *)id.data; + mInfo->Invoke(); + if(! id.sync) + delete mInfo; + } + break; + + case 'natv' : // native queue PLEvent + { + PREventQueue *queue = (PREventQueue *)id.data; + PR_ProcessPendingEvents(queue); + } + break; + + default : + printf("nsAppShell::Run - UNKNOWN EVENT\n"); + break; + } + + if(mDispatchListener) + mDispatchListener->AfterDispatch(); + + if(id.sync) + release_sem(syncsem); + } + + Release(); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Exit a message handler loop +// +//------------------------------------------------------------------------- + +NS_METHOD nsAppShell::Exit() +{ + // interrupt message flow + close_port(eventport); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsAppShell destructor +// +//------------------------------------------------------------------------- +nsAppShell::~nsAppShell() +{ + if(be_app->Lock()) + be_app->Quit(); +} + +//------------------------------------------------------------------------- +// +// GetNativeData +// +//------------------------------------------------------------------------- +void* nsAppShell::GetNativeData(PRUint32 aDataType) +{ + if (aDataType == NS_NATIVE_SHELL) { + return NULL; + } + return nsnull; +} + +//------------------------------------------------------------------------- +// +// Spinup - do any preparation necessary for running a message loop +// +//------------------------------------------------------------------------- +NS_METHOD nsAppShell::Spinup() +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Spindown - do any cleanup necessary for finishing a message loop +// +//------------------------------------------------------------------------- +NS_METHOD nsAppShell::Spindown() +{ + return NS_OK; +} + +NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent) +{ + printf("nsAppShell::GetNativeEvent - FIXME: not implemented\n"); + return NS_OK; +} + +NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent) +{ + printf("nsAppShell::DispatchNativeEvent - FIXME: not implemented\n"); + return NS_OK; +} + +NS_METHOD nsAppShell::EventIsForModalWindow(PRBool aRealEvent, void *aEvent, nsIWidget *aWidget, PRBool *aForWindow) +{ + printf("nsAppShell::EventIsForModalWindow - FIXME: not implemented\n"); + *aForWindow = PR_FALSE; + return NS_OK; +} + diff --git a/widget/src/beos/nsAppShell.h b/widget/src/beos/nsAppShell.h new file mode 100644 index 000000000000..5ab76d6c8e4c --- /dev/null +++ b/widget/src/beos/nsAppShell.h @@ -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 "nsObject.h" +#include "nsIAppShell.h" +#include + +/** + * Native BeOS Application shell wrapper + */ + +class nsAppShell : public nsIAppShell +{ + public: + nsAppShell(); + virtual ~nsAppShell(); + + NS_DECL_ISUPPORTS + + // nsIAppShellInterface + + NS_IMETHOD Create(int* argc, char ** argv); + virtual nsresult Run(); + NS_IMETHOD Spinup(); + NS_IMETHOD Spindown(); + NS_IMETHOD GetNativeEvent(PRBool &aRealEvent, void *&aEvent); + NS_IMETHOD DispatchNativeEvent(PRBool aRealEvent, void * aEvent); + NS_IMETHOD EventIsForModalWindow(PRBool aRealEvent, void *aEvent, + nsIWidget *aWidget, PRBool *aForWindow); + NS_IMETHOD Exit(); + NS_IMETHOD SetDispatchListener(nsDispatchListener* aDispatchListener); + virtual void* GetNativeData(PRUint32 aDataType); + + private: + nsDispatchListener *mDispatchListener; + port_id eventport; + sem_id syncsem; +}; + +#endif // nsAppShell_h__ diff --git a/widget/src/beos/nsButton.cpp b/widget/src/beos/nsButton.cpp new file mode 100644 index 000000000000..2dea67752135 --- /dev/null +++ b/widget/src/beos/nsButton.cpp @@ -0,0 +1,282 @@ +/* -*- 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 "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); + + +NS_IMPL_ADDREF(nsButton) +NS_IMPL_RELEASE(nsButton) + +//------------------------------------------------------------------------- +// +// nsButton constructor +// +//------------------------------------------------------------------------- +nsButton::nsButton() : nsWindow() , nsIButton() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// nsButton destructor +// +//------------------------------------------------------------------------- +nsButton::~nsButton() +{ +} + +/** + * Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID + * @modify gpk 8/4/98 + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsButton::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID); + if (aIID.Equals(kIButton)) { + *aInstancePtr = (void*) ((nsIButton*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWindow::QueryInterface(aIID,aInstancePtr); +} + + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsButton::SetLabel(const nsString& aText) +{ + mLabel = aText; + if(NULL == mView) { + return NS_ERROR_FAILURE; + } + NS_ALLOC_STR_BUF(label, aText, 256); + if(mButton) + { + if(mButton->Looper()) + mButton->LockLooper(); + + mButton->SetLabel(label); + + if(mButton->Looper()) + mButton->UnlockLooper(); + } + NS_FREE_STR_BUF(label); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsButton::GetLabel(nsString& aBuffer) +{ + aBuffer = mLabel; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsButton::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsButton::OnPaint(nsRect &r) +{ + //printf("** nsButton::OnPaint **\n"); + return PR_FALSE; +} + +PRBool nsButton::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +/** + * Renders the Button for Printing + * + **/ +NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + float appUnits; + float devUnits; + float scale; + nsIDeviceContext * context; + aRenderingContext.GetDeviceContext(context); + + context->GetCanonicalPixelScale(scale); + context->GetAppUnitsToDevUnits(devUnits); + context->GetDevUnitsToAppUnits(appUnits); + + nsRect rect; + GetBoundsAppUnits(rect, appUnits); + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscolor bgColor = NS_RGB(255,255,255); + nscolor fgColor = NS_RGB(0,0,0); + nscolor hltColor = NS_RGB(240,240,240); + nscolor sdwColor = NS_RGB(128,128,128); + + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor); + } + + aRenderingContext.SetColor(bgColor); + aRenderingContext.FillRect(rect); + + /*aRenderingContext.SetColor(bgColor); + for (int i=0;iGetMetricsFor(*mFont, metrics); + metrics->GetMaxAscent(textHeight); + + nscoord x = ((rect.width - textWidth) / 2) + rect.x; + nscoord y = ((rect.height - textHeight) / 2) + rect.y; + aRenderingContext.DrawString(mLabel, x, y); + + + NS_RELEASE(context); + return NS_OK; +} + +BView *nsButton::CreateBeOSView() +{ + return mButton = new nsButtonBeOS(this, BRect(0, 0, 0, 0), "", ""); +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS Button +//------------------------------------------------------------------------- +nsButtonBeOS::nsButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, const char *aLabel, uint32 aResizingMode, uint32 aFlags ) + : BButton( aFrame, aName, aLabel, new BMessage('clik'), aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ +} + +void nsButtonBeOS::AttachedToWindow() +{ + SetTarget(this); +} + +void nsButtonBeOS::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { + case 'clik' : + { + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 args[5]; + args[0] = NS_MOUSE_LEFT_CLICK; + args[1] = (uint32)0; + args[2] = (uint32)0; + args[3] = 1; + args[4] = modifiers(); + MethodInfo *info = new MethodInfo(w, w, nsWindow::BTNCLICK, 5, args); + t->CallMethodAsync(info); + NS_RELEASE(t); + } + } + break; + + default : + BButton::MessageReceived(msg); + } +} + diff --git a/widget/src/beos/nsButton.h b/widget/src/beos/nsButton.h new file mode 100644 index 000000000000..8600d34ae567 --- /dev/null +++ b/widget/src/beos/nsButton.h @@ -0,0 +1,77 @@ +/* -*- 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 "nsSwitchToUIThread.h" + +#include "nsIButton.h" + +#include + +/** + * Native Win32 button wrapper + */ + +class nsButton : public nsWindow, + public nsIButton +{ + +public: + nsButton(); + virtual ~nsButton(); + + //nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIButton part + NS_IMETHOD SetLabel(const nsString& aText); + NS_IMETHOD GetLabel(nsString& aBuffer); + + // nsBaseWidget + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + nsString mLabel; + virtual BView *CreateBeOSView(); + BButton *mButton; +}; + +// +// A BButton subclass +// +class nsButtonBeOS : public BButton, public nsIWidgetStore { + public: + nsButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + const char *aLabel, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); + void AttachedToWindow(); + void MessageReceived(BMessage *msg); +}; + +#endif // nsButton_h__ diff --git a/widget/src/beos/nsCList.h b/widget/src/beos/nsCList.h new file mode 100644 index 000000000000..ed1586f59b5d --- /dev/null +++ b/widget/src/beos/nsCList.h @@ -0,0 +1,102 @@ +/* -*- 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 CLIST_H +#define CLIST_H + +#include + +// ----------------------------------------------------------------------- +// +// Simple circular linked-list implementation... +// +// ----------------------------------------------------------------------- + +// Foreward declarations... +struct CList; + +#define OBJECT_PTR_FROM_CLIST(className, listElement) \ + ((char*)listElement - offsetof(className, m_link)) + + +struct CList { + CList *next; + CList *prev; + + CList() { + next = prev = this; + } + + ~CList() { + Remove(); + } + + // + // Append an element to the end of this list + // + void Append(CList &element) { + element.next = this; + element.prev = prev; + prev->next = &element; + prev = &element; + } + + // + // Add an element to the beginning of this list + // + void Add(CList &element) { + element.next = next; + element.prev = this; + next->prev = &element; + next = &element; + } + + // + // Append this element to the end of a list + // + void AppendToList(CList &list) { + list.Append(*this); + } + + // + // Add this element to the beginning of a list + // + void AddToList(CList &list) { + list.Add(*this); + } + + // + // Remove this element from the list and re-initialize + // + void Remove(void) { + prev->next = next; + next->prev = prev; + + next = prev = this; + } + + // + // Is this list empty ? + // + bool IsEmpty(void) { + return (next == this); + } +}; + +#endif // CLIST_H + diff --git a/widget/src/beos/nsCheckButton.cpp b/widget/src/beos/nsCheckButton.cpp new file mode 100644 index 000000000000..8979d585e9cc --- /dev/null +++ b/widget/src/beos/nsCheckButton.cpp @@ -0,0 +1,237 @@ +/* -*- 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 "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" + +NS_IMPL_ADDREF(nsCheckButton) +NS_IMPL_RELEASE(nsCheckButton) + +//------------------------------------------------------------------------- +// +// nsCheckButton constructor +// +//------------------------------------------------------------------------- +nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(), + mState(PR_FALSE) +{ + NS_INIT_REFCNT(); +} + + +//------------------------------------------------------------------------- +// +// nsCheckButton destructor +// +//------------------------------------------------------------------------- +nsCheckButton::~nsCheckButton() +{ +} + + +/** + * Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID + * @modify gpk 8/4/98 + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); + if (aIID.Equals(kICheckButtonIID)) { + *aInstancePtr = (void*) ((nsICheckButton*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + return nsWindow::QueryInterface(aIID,aInstancePtr); +} + + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::SetState(const PRBool aState) +{ + mState = aState; + if(mCheckBox && mCheckBox->LockLooper()) + { + mCheckBox->SetValue(aState ? 1 : 0); + mCheckBox->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::GetState(PRBool& aState) +{ + aState = mState; + if(mCheckBox && mCheckBox->LockLooper()) + { + aState = mCheckBox->Value() ? PR_TRUE : PR_FALSE; + mCheckBox->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::SetLabel(const nsString& aText) +{ + char label[256]; + aText.ToCString(label, 256); + label[255] = '\0'; + if(mCheckBox && mCheckBox->LockLooper()) + { + mCheckBox->SetLabel(label); + mCheckBox->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer) +{ + if(mCheckBox && mCheckBox->LockLooper()) + { + aBuffer.SetLength(0); + aBuffer.Append(mCheckBox->Label()); + mCheckBox->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsCheckButton::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsCheckButton::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsCheckButton::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +/** + * Renders the CheckButton for Printing + * + **/ +NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + nsRect rect; + float appUnits; + float scale; + nsIDeviceContext * context; + aRenderingContext.GetDeviceContext(context); + + context->GetCanonicalPixelScale(scale); + context->GetDevUnitsToAppUnits(appUnits); + + GetBoundsAppUnits(rect, appUnits); + + nscoord one = nscoord(PRFloat64(rect.height) * 1.0/20.0); + nscoord three = nscoord(PRFloat64(rect.width) * 3.0/20.0); + nscoord five = nscoord(PRFloat64(rect.width) * 5.0/20.0); + nscoord six = nscoord(PRFloat64(rect.height) * 5.0/20.0); + nscoord eight = nscoord(PRFloat64(rect.height) * 7.0/20.0); + nscoord nine = nscoord(PRFloat64(rect.width) * 9.0/20.0); + nscoord ten = nscoord(PRFloat64(rect.height) * 9.0/20.0); + + rect.x += three; + rect.y += nscoord(PRFloat64(rect.height) * 3.5 /20.0); + rect.width = nscoord(PRFloat64(rect.width) * 12.0/20.0); + rect.height = nscoord(PRFloat64(rect.height) * 12.0/20.0); + + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscoord onePixel = nscoord((appUnits+0.6F)); + DrawScaledRect(aRenderingContext, rect, scale, appUnits); + nscoord x = rect.x; + nscoord y = rect.y; + + if (mState) { + nscoord inc = nscoord(PRFloat64(rect.height) * 0.75/20.0); + nscoord yy = 0; + for (nscoord i=0;i<4;i++) { + DrawScaledLine(aRenderingContext, x+three, y+eight+yy, x+five, y+ten+yy, scale, appUnits, PR_FALSE); // top + DrawScaledLine(aRenderingContext, x+five, y+ten+yy, x+nine, y+six+yy, scale, appUnits, PR_FALSE); // top + //aRenderingContext.DrawLine(x+three, y+eight+yy, x+five, y+ten+yy); + //aRenderingContext.DrawLine(x+five, y+ten+yy, x+nine, y+six+yy); + yy += nscoord(scale); + } + } + + NS_RELEASE(context); + return NS_OK; +} + +BView *nsCheckButton::CreateBeOSView() +{ + return mCheckBox = new nsCheckBoxBeOS(this, BRect(0, 0, 0, 0), "", "", NULL); +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS CheckBox +//------------------------------------------------------------------------- +nsCheckBoxBeOS::nsCheckBoxBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, const char *aLabel, BMessage *aMessage, + uint32 aResizingMode, uint32 aFlags ) + : BCheckBox( aFrame, aName, aLabel, aMessage, aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ +} diff --git a/widget/src/beos/nsCheckButton.h b/widget/src/beos/nsCheckButton.h new file mode 100644 index 000000000000..897bd7b85e7a --- /dev/null +++ b/widget/src/beos/nsCheckButton.h @@ -0,0 +1,77 @@ +/* -*- 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 "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsICheckButton.h" + +#include + +/** + * Native Win32 Checkbox wrapper + */ + +class nsCheckButton : public nsWindow, + public nsICheckButton +{ + +public: + nsCheckButton(); + virtual ~nsCheckButton(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsICheckButton part + NS_IMETHOD SetLabel(const nsString &aText); + NS_IMETHOD GetLabel(nsString &aBuffer); + NS_IMETHOD SetState(const PRBool aState); + NS_IMETHOD GetState(PRBool& aState); + + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + + +protected: + PRBool mState; + virtual BView *CreateBeOSView(); + BCheckBox *mCheckBox; +}; + +// +// A BCheckBox subclass +// +class nsCheckBoxBeOS : public BCheckBox, public nsIWidgetStore { + public: + nsCheckBoxBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + const char *aLabel, BMessage *aMessage, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); +}; + +#endif // nsCheckButton_h__ diff --git a/widget/src/beos/nsClipboard.cpp b/widget/src/beos/nsClipboard.cpp new file mode 100644 index 000000000000..a60a27c4b3da --- /dev/null +++ b/widget/src/beos/nsClipboard.cpp @@ -0,0 +1,523 @@ +/* -*- 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 "nsClipboard.h" + +#include "nsCOMPtr.h" + +#include "nsIClipboardOwner.h" +#include "nsITransferable.h" // kTextMime + +#include "nsIWidget.h" +#include "nsIServiceManager.h" +#include "nsWidgetsCID.h" + +#include + +// The class statics: +BView *nsClipboard::sView = 0; + +NS_IMPL_ADDREF_INHERITED(nsClipboard, nsBaseClipboard) +NS_IMPL_RELEASE_INHERITED(nsClipboard, nsBaseClipboard) + +static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID); + +#if defined(DEBUG_akkana) || defined(DEBUG_mcafee) +#define DEBUG_CLIPBOARD +#endif + + +//------------------------------------------------------------------------- +// +// nsClipboard constructor +// +//------------------------------------------------------------------------- +nsClipboard::nsClipboard() : nsBaseClipboard() +{ +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::nsClipboard()\n"); +#endif /* DEBUG_CLIPBOARD */ + + //NS_INIT_REFCNT(); + mIgnoreEmptyNotification = PR_FALSE; + mClipboardOwner = nsnull; + mTransferable = nsnull; +// mSelectionData.data = nsnull; +// mSelectionData.length = 0; +} + +//------------------------------------------------------------------------- +// +// nsClipboard destructor +// +//------------------------------------------------------------------------- +nsClipboard::~nsClipboard() +{ +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::~nsClipboard()\n"); +#endif /* DEBUG_CLIPBOARD */ + +// // Remove all our event handlers: +// if (sView && +// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window) +// gtk_selection_remove_all(sWidget); +// +// // free the selection data, if any +// if (mSelectionData.data != nsnull) +// g_free(mSelectionData.data); +} + +/** + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsClipboard::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + nsresult rv = NS_NOINTERFACE; + + if (aIID.Equals(nsIClipboard::GetIID())) { + *aInstancePtr = (void*) ((nsIClipboard*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return rv; +} + + +void nsClipboard::SetTopLevelView(BView *v) +{ + // Don't set up any more event handlers if we're being called twice + // for the same toplevel widget + if (sView == v) + return; + + if (sView != 0 && sView->Window() != 0) + return; + + if(v == 0 || v->Window() == 0) + { +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::SetTopLevelView: widget passed in is null or has no window!\n"); +#endif /* DEBUG_CLIPBOARD */ + return; + } + +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::SetTopLevelView\n"); +#endif /* DEBUG_CLIPBOARD */ + +// // If we're changing from one widget to another +// // (shouldn't generally happen), clear the old event handlers: +// if (sView && +// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window) +// gtk_selection_remove_all(sWidget); +// +// sWidget = w; +// +// // Get the clipboard from the service manager. +// nsresult rv; +// NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv); +// +// if (!NS_SUCCEEDED(rv)) { +// printf("Couldn't get clipboard service!\n"); +// return; +// } +// +// // Handle selection requests if we called gtk_selection_add_target: +// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_get", +// GTK_SIGNAL_FUNC(nsClipboard::SelectionGetCB), +// clipboard); +// +// // When someone else takes the selection away: +// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_clear_event", +// GTK_SIGNAL_FUNC(nsClipboard::SelectionClearCB), +// clipboard); +// +// // Set up the paste handler: +// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_received", +// GTK_SIGNAL_FUNC(nsClipboard::SelectionReceivedCB), +// clipboard); +// +//#if 0 +// // Handle selection requests if we called gtk_selection_add_targets: +// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_request_event", +// GTK_SIGNAL_FUNC(nsClipboard::SelectionRequestCB), +// clipboard); +// +// // Watch this, experimenting with Gtk :-) +// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_notify_event", +// GTK_SIGNAL_FUNC(nsClipboard::SelectionNotifyCB), +// clipboard); +//#endif +// +// // Hmm, sometimes we need this, sometimes not. I'm not clear why. +// // See also long comment above on why we don't register a whole target list. +// +// // Register all the target types we handle: +// gtk_selection_add_target(sWidget, +// GDK_SELECTION_PRIMARY, +// GDK_SELECTION_TYPE_STRING, +// GDK_SELECTION_TYPE_STRING); +} + + +/** + * + * + */ +NS_IMETHODIMP nsClipboard::SetNativeClipboardData() +{ + mIgnoreEmptyNotification = PR_TRUE; + +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::SetNativeClipboardData()\n"); +#endif /* DEBUG_CLIPBOARD */ + + // make sure we have a good transferable + if (nsnull == mTransferable) { + printf(" SetNativeClipboardData: no transferable!\n"); + return NS_ERROR_FAILURE; + } + +// // If we're already the selection owner, don't need to do anything, +// // we'll already get the events: +// if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window) +// return NS_OK; +// +// // Clear the native clipboard +// if (sWidget && +// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window) +// gtk_selection_remove_all(sWidget); +// +// +// // register as the selection owner: +// gint have_selection = +// gtk_selection_owner_set(sWidget, +// GDK_SELECTION_PRIMARY, +// GDK_CURRENT_TIME); +// if (have_selection == 0) +// return NS_ERROR_FAILURE; + + mIgnoreEmptyNotification = PR_FALSE; + + return NS_OK; +} + + +// +// The blocking Paste routine +// +NS_IMETHODIMP +nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable) +{ + nsresult rv = NS_OK; + +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::GetNativeClipboardData()\n"); +#endif /* DEBUG_CLIPBOARD */ + + // make sure we have a good transferable + if (nsnull == aTransferable) { + printf(" GetNativeClipboardData: Transferable is null!\n"); + return NS_ERROR_FAILURE; + } + + // Dunno why we need to do this, copying the win32 code ... + nsCOMPtr trans = do_QueryInterface(aTransferable); + if (!trans) + return rv; + +// // +// // We can't call the copy callback when we're blocking on the paste callback; +// // so if this app is already the selection owner, we need to copy our own +// // data without going through the X server. +// // +// if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window) +// { +// // XXX only support text/plain for now +// nsAutoString dataFlavor(kTextMime); +// +// // Get data out of our existing transferable. +// void *clipboardData; +// PRUint32 dataLength; +// rv = mTransferable->GetTransferData(&dataFlavor, +// &clipboardData, +// &dataLength); +// if (NS_SUCCEEDED(rv)) +// rv = trans->SetTransferData(&dataFlavor, +// clipboardData, dataLength); +// return rv; +// } +// +//#define ONLY_SUPPORT_PLAIN_TEXT 1 +//#ifdef ONLY_SUPPORT_PLAIN_TEXT +// gtk_selection_convert(sWidget, GDK_SELECTION_PRIMARY, +// GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME); +// // Tried to use straight Xlib call but this would need more work: +// //XConvertSelection(GDK_WINDOW_XDISPLAY(sWidget->window), +// // XA_PRIMARY, XA_STRING, gdk_selection_property, +// // GDK_WINDOW_XWINDOW(sWidget->window), GDK_CURRENT_TIME); +// +//#else /* ONLY_SUPPORT_PLAIN_TEXT */ +// // +// // XXX This code isn't implemented for Unix yet! +// // Instead of SetTransferData it will have to call gtk_selection_convert. +// // +// +// // Get the transferable list of data flavors +// nsVoidArray * dfList; +// aTransferable->GetTransferDataFlavors(&dfList); +// +// // Walk through flavors and see which flavor matches the one being pasted: +// PRUint32 i; +// PRUint32 cnt = 0; +// nsresult rv = dfList->Count(&cnt); +// NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed"); +// for (i=0;iElementAt(i); +// if (nsnull != df) { +// UINT format = GetFormat(*df); +// +// void * data; +// PRUint32 dataLen; +// +// if (nsnull != aDataObject) { +// res = GetNativeDataOffClipboard(aDataObject, format, &data, &dataLen); +// if (NS_OK == res) { +// trans->SetTransferData(df, data, dataLen); +// } +// } else if (nsnull != aWindow) { +// res = GetNativeDataOffClipboard(aWindow, format, &data, &dataLen); +// if (NS_OK == res) { +// trans->SetTransferData(df, data, dataLen); +// } +// } +// } +// } +//#endif /* ONLY_SUPPORT_PLAIN_TEXT */ +// +// // +// // We've told X what type to send, and we just have to wait +// // for the callback saying that the data have been transferred. +// // +// +// // Set a flag saying that we're blocking waiting for the callback: +// mBlocking = PR_TRUE; +//#ifdef DEBUG_CLIPBOARD +// printf("Waiting for the callback\n"); +//#endif /* DEBUG_CLIPBOARD */ +// +// // Now we need to wait until the callback comes in ... +// // i is in case we get a runaway (yuck). +// for (int i=0; mBlocking == PR_TRUE && i < 10000; ++i) +// { +// gtk_main_iteration_do(PR_TRUE); +// } +// +//#ifdef DEBUG_CLIPBOARD +// printf("Got the callback: '%s', %d\n", +// mSelectionData.data, mSelectionData.length); +//#endif /* DEBUG_CLIPBOARD */ +// +// // We're back from the callback, no longer blocking: +// mBlocking = PR_FALSE; +// +// // +// // Now we have data in mSelectionData.data. +// // We just have to copy it to the transferable. +// // +// nsAutoString dataFlavor(kTextMime); +// trans->SetTransferData(&dataFlavor, mSelectionData.data, mSelectionData.length); +// +// // Can't free the selection data -- the transferable just saves a pointer. +// // But the transferable is responsible for freeing it, so we have to +// // consider it freed now: +// //g_free(mSelectionData.data); +// mSelectionData.data = nsnull; +// mSelectionData.length = 0; + + return NS_OK; +} + +// +// Called when the data from a paste comes in: +// +//void +//nsClipboard::SelectionReceivedCB (GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData) +//{ +//#ifdef DEBUG_CLIPBOARD +// printf(" nsClipboard::SelectionReceivedCB\n"); +//#endif /* DEBUG_CLIPBOARD */ +// +// // ARGHH! GTK doesn't pass the arg to the callback, so we can't +// // get "this" back! Until we solve this, get it from the service mgr: +// nsresult rv; +// NS_WITH_SERVICE(nsIClipboard, iclipboard, kCClipboardCID, &rv); +// +// if (NS_FAILED(rv)) { +// printf("Couldn't get clipboard service!\n"); +// return; +// } +// nsClipboard* clipboard = (nsClipboard*)iclipboard; +// if (!clipboard) { +// printf("couldn't convert nsIClipboard to nsClipboard\n"); +// return; +// } +// +// clipboard->SelectionReceiver(aWidget, aSelectionData); +//} +// +//void +//nsClipboard::SelectionReceiver (GtkWidget *aWidget, +// GtkSelectionData *aSelectionData) +//{ +// mBlocking = PR_FALSE; +// +// if (aSelectionData->length < 0) +// { +// printf("Error retrieving selection: length was %d\n", +// aSelectionData->length); +// return; +// } +// +// switch (aSelectionData->type) +// { +// case GDK_SELECTION_TYPE_STRING: +// mSelectionData = *aSelectionData; +// mSelectionData.data = g_new(guchar, aSelectionData->length + 1); +// memcpy(mSelectionData.data, +// aSelectionData->data, aSelectionData->length); +// // Null terminate in case anyone cares, +// // and so we can print the string for debugging: +// mSelectionData.data[aSelectionData->length] = '\0'; +// mSelectionData.length = aSelectionData->length; +// return; +// +// default: +// printf("Can't convert type %s (%ld) to string\n", +// gdk_atom_name (aSelectionData->type), aSelectionData->type); +// return; +// } +//} +// +/** + * No-op. + * + */ +NS_IMETHODIMP nsClipboard::ForceDataToClipboard() +{ +#ifdef DEBUG_CLIPBOARD + printf(" nsClipboard::ForceDataToClipboard()\n"); +#endif /* DEBUG_CLIPBOARD */ + + // make sure we have a good transferable + if (nsnull == mTransferable) { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +// +//// This is the callback which is called when another app +//// requests the selection. +//// +//void nsClipboard::SelectionGetCB(GtkWidget *widget, +// GtkSelectionData *aSelectionData, +// guint /*info*/, +// guint /*time*/, +// gpointer aData) +//{ +//#ifdef DEBUG_CLIPBOARD +// printf(" nsClipboard::SelectionGetCB\n"); +//#endif /* DEBUG_CLIPBOARD */ +// +// nsClipboard *clipboard = (nsClipboard *)aData; +// +// void *clipboardData; +// PRUint32 dataLength; +// nsresult rv; +// +// // Make sure we have a transferable: +// if (!clipboard->mTransferable) { +// printf("Clipboard has no transferable!\n"); +// return; +// } +// +// // XXX hack, string-only for now. +// // Create string data-flavor. +// nsString dataFlavor (kTextMime); +// +// // Get data out of transferable. +// rv = clipboard->mTransferable->GetTransferData(&dataFlavor, +// &clipboardData, +// &dataLength); +// +// // Currently we only offer the data in GDK_SELECTION_TYPE_STRING format. +// if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) { +// gtk_selection_data_set(aSelectionData, +// GDK_SELECTION_TYPE_STRING, 8, +// (unsigned char *)clipboardData, +// dataLength); +// } +// else +// printf("Transferable didn't support the data flavor\n"); +//} +// +// +// +//// Called when another app requests selection ownership: +//void nsClipboard::SelectionClearCB(GtkWidget *widget, +// GdkEventSelection *event, +// gpointer data) +//{ +//#ifdef DEBUG_CLIPBOARD +// printf(" nsClipboard::SelectionClearCB\n"); +//#endif /* DEBUG_CLIPBOARD */ +//} +// +// +//// The routine called when another app asks for the content of the selection +//void +//nsClipboard::SelectionRequestCB (GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData) +//{ +//#ifdef DEBUG_CLIPBOARD +// printf(" nsClipboard::SelectionRequestCB\n"); +//#endif /* DEBUG_CLIPBOARD */ +//} +// +//void +//nsClipboard::SelectionNotifyCB (GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData) +//{ +//#ifdef DEBUG_CLIPBOARD +// printf(" nsClipboard::SelectionNotifyCB\n"); +//#endif /* DEBUG_CLIPBOARD */ +//} diff --git a/widget/src/beos/nsClipboard.h b/widget/src/beos/nsClipboard.h new file mode 100644 index 000000000000..7289ecf9a54f --- /dev/null +++ b/widget/src/beos/nsClipboard.h @@ -0,0 +1,88 @@ +/* -*- 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 nsClipboard_h__ +#define nsClipboard_h__ + +#include "nsBaseClipboard.h" +#include + +class nsITransferable; +class nsIClipboardOwner; +class nsIWidget; + +/** + * Native BeOS Clipboard wrapper + */ + +class nsClipboard : public nsBaseClipboard +{ + +public: + nsClipboard(); + virtual ~nsClipboard(); + + //nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIClipboard + NS_IMETHOD ForceDataToClipboard(); + + static void SetTopLevelView(BView *v); + + +protected: + NS_IMETHOD SetNativeClipboardData(); + NS_IMETHOD GetNativeClipboardData(nsITransferable * aTransferable); + + PRBool mIgnoreEmptyNotification; + + static BView *sView; + +// // Used for communicating pasted data +// // from the asynchronous X routines back to a blocking paste: +// GtkSelectionData mSelectionData; +// PRBool mBlocking; +// +// void SelectionReceiver(GtkWidget *aWidget, +// GtkSelectionData *aSelectionData); +// +// static void SelectionGetCB(GtkWidget *widget, +// GtkSelectionData *selection_data, +// guint /*info*/, +// guint /*time*/, +// gpointer data); +// +// static void SelectionClearCB(GtkWidget *widget, +// GdkEventSelection *event, +// gpointer data ); +// +// static void SelectionRequestCB(GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData); +// +// static void SelectionReceivedCB(GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData); +// +// static void SelectionNotifyCB(GtkWidget *aWidget, +// GtkSelectionData *aSelectionData, +// gpointer aData); +}; + +#endif // nsClipboard_h__ diff --git a/widget/src/beos/nsComboBox.cpp b/widget/src/beos/nsComboBox.cpp new file mode 100644 index 000000000000..b6e12cee588c --- /dev/null +++ b/widget/src/beos/nsComboBox.cpp @@ -0,0 +1,380 @@ +/* -*- 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 "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +NS_IMPL_ADDREF(nsComboBox) +NS_IMPL_RELEASE(nsComboBox) + +//------------------------------------------------------------------------- +// +// nsComboBox constructor +// +//------------------------------------------------------------------------- +nsComboBox::nsComboBox() : nsWindow(), nsIListWidget(), nsIComboBox() +{ + NS_INIT_REFCNT(); + mBackground = NS_RGB(124, 124, 124); + mDropDownHeight = 60; // Default to 60 pixels for drop-down list height +} + +//------------------------------------------------------------------------- +// +// destructor +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition) +{ + if(mMenuField && mMenuField->LockLooper()) + { + NS_ALLOC_STR_BUF(val, aItem, 256); + mMenuField->Menu()->AddItem(new BMenuItem(val, 0), aPosition); + NS_FREE_STR_BUF(val); + mMenuField->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Finds an item at a postion +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos) +{ +#if 0 + NS_ALLOC_STR_BUF(val, aItem, 256); + int index = ::SendMessage(mWnd, CB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val); + NS_FREE_STR_BUF(val); + + return index; +#endif + printf("nsListBox::FindItem not implemented\n"); + return -1; +} + +//------------------------------------------------------------------------- +// +// CountItems - Get Item Count +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::GetItemCount() +{ + PRInt32 result = 0; + if(mMenuField && mMenuField->LockLooper()) + { + result = mMenuField->Menu()->CountItems(); + mMenuField->UnlockLooper(); + } + return result; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition) +{ + if(mMenuField && mMenuField->LockLooper()) + { + BMenuItem *it = mMenuField->Menu()->RemoveItem(aPosition); + delete it; + mMenuField->UnlockLooper(); + return it ? PR_TRUE : PR_FALSE; + } + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition) +{ + PRBool result = PR_FALSE; + anItem.SetLength(0); + if(mMenuField && mMenuField->LockLooper()) + { + BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition); + anItem.Append(it->Label()); + mMenuField->UnlockLooper(); + result = PR_TRUE; + } + return result; +} + +//------------------------------------------------------------------------- +// +// Gets the selected of selected item +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem) +{ + GetItemAt(aItem, GetSelectedIndex()); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Gets the list of selected otems +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::GetSelectedIndex() +{ + PRInt32 index = -1; + if(mMenuField && mMenuField->LockLooper()) + { + BMenuItem *it = mMenuField->Menu()->FindMarked(); + index = it ? mMenuField->Menu()->IndexOf(it) : -1; + mMenuField->UnlockLooper(); + } + return index; +} + +//------------------------------------------------------------------------- +// +// SelectItem +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition) +{ + if(mMenuField && mMenuField->LockLooper()) + { + BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition); + if(it) + it->SetMarked(true); + mMenuField->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Deselect +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::Deselect() +{ + if(mMenuField && mMenuField->LockLooper()) + { + BMenuItem *it = mMenuField->Menu()->FindMarked(); + if(it) + it->SetMarked(false); + mMenuField->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// destructor +// +//------------------------------------------------------------------------- +nsComboBox::~nsComboBox() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + static NS_DEFINE_IID(kInsComboBoxIID, NS_ICOMBOBOX_IID); + static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID); + + if (aIID.Equals(kInsComboBoxIID)) { + *aInstancePtr = (void*) ((nsIComboBox*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (aIID.Equals(kInsListWidgetIID)) { + *aInstancePtr = (void*) ((nsIListWidget*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWindow::QueryInterface(aIID,aInstancePtr); +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsComboBox::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsComboBox::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsComboBox::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +//------------------------------------------------------------------------- +// +// Cache the drop down list height in mDropDownHeight +// +//------------------------------------------------------------------------- + +NS_METHOD nsComboBox::PreCreateWidget(nsWidgetInitData *aInitData) +{ + nsComboBoxInitData* comboData = (nsComboBoxInitData*)aInitData; + mDropDownHeight = comboData->mDropDownHeight; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Modify the height passed to create and resize to be +// the combo box drop down list height. (Note: Windows uses +// the height of the window to specify the drop-down list size, +// not the height of combobox text area. +// +//------------------------------------------------------------------------- + +PRInt32 nsComboBox::GetHeight(PRInt32 aProposedHeight) +{ + return(mDropDownHeight); +} + + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsComboBox::GetBounds(nsRect &aRect) +{ +#if 0 + nsWindow::GetNonClientBounds(aRect); +#endif +printf("nsListBox::GetBounds not wrong\n"); // the following is just a placeholder + nsWindow::GetClientBounds(aRect); + return NS_OK; +} + +/** + * Renders the TextWidget for Printing + * + **/ +NS_METHOD nsComboBox::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + nsBaseWidget::Paint(aRenderingContext, aDirtyRect); + /*nsRect rect; + GetBoundsAppUnits(rect, aTwipsConversion); + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscolor bgColor = NS_RGB(255,255,255); + nscolor fgColor = NS_RGB(0,0,0); + nscolor hltColor = NS_RGB(240,240,240); + nscolor sdwColor = NS_RGB(128,128,128); + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor); + } + + nsIDeviceContext * context; + //nsDrawingSurface surface; + aRenderingContext.GetDeviceContext(context); + //context->GetDrawingSurface(aRenderingContext, surface); + + //HDC the_hdc = ((nsDrawingSurfaceWin *)&surface)->mDC; + + //::SendMessage(mWnd, WM_PAINT, (WPARAM)the_hdc, NULL); + + + // shrink by one pixel + + nscoord onePixel = nscoord((aTwipsConversion+0.6F)); + nscoord twoPixels = onePixel*2; + + nsString text("(ComboBox)"); + //GetSelectedItem(text); + + + aRenderingContext.SetColor(bgColor); + aRenderingContext.FillRect(rect); + + aRenderingContext.SetColor(NS_RGB(0,0,0)); + aRenderingContext.DrawRect(rect); + + + aRenderingContext.SetFont(*mFont); + + nscoord textWidth; + nscoord textHeight; + aRenderingContext.GetWidth(text, textWidth); + + nsIFontMetrics* metrics; + context->GetMetricsFor(*mFont, metrics); + metrics->GetMaxAscent(textHeight); + + nscoord x = (twoPixels * 2) + rect.x; + nscoord y = ((rect.height - textHeight) / 2) + rect.y; + //aRenderingContext.DrawString(text, x, y); + */ + return NS_OK; +} + + +BView *nsComboBox::CreateBeOSView() +{ + return mMenuField = new nsMenuFieldBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), ""); +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS MenuField +//------------------------------------------------------------------------- +nsMenuFieldBeOS::nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, uint32 aResizingMode, uint32 aFlags ) + : BMenuField( aFrame, aName, "", new BPopUpMenu(""), aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ + SetDivider(0); +} diff --git a/widget/src/beos/nsComboBox.h b/widget/src/beos/nsComboBox.h new file mode 100644 index 000000000000..85652132807e --- /dev/null +++ b/widget/src/beos/nsComboBox.h @@ -0,0 +1,93 @@ +/* -*- 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 "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" +#include "nsIComboBox.h" + +#include +#include +#include + +/** + * Native Win32 Combobox wrapper + */ + +class nsComboBox : public nsWindow, + public nsIListWidget, + public nsIComboBox +{ + +public: + nsComboBox(); + ~nsComboBox(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIWidget overrides + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + + // nsIWidget + NS_IMETHOD GetBounds(nsRect &aRect); + + // nsIComboBox interface + NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition); + virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos); + virtual PRInt32 GetItemCount(); + virtual PRBool RemoveItemAt(PRInt32 aPosition); + virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition); + NS_IMETHOD GetSelectedItem(nsString& aItem); + virtual PRInt32 GetSelectedIndex(); + NS_IMETHOD SelectItem(PRInt32 aPosition); + NS_IMETHOD Deselect() ; + + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + +protected: + + // Modify the height passed to create and resize to be + // the combo box drop down list height. + PRInt32 GetHeight(PRInt32 aProposedHeight); + PRInt32 mDropDownHeight; + BView *CreateBeOSView(); + BMenuField *mMenuField; +}; + +// +// A BMenuField subclass +// +class nsMenuFieldBeOS : public BMenuField, public nsIWidgetStore { + public: + nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); +}; + +#endif // nsComboBox_h__ diff --git a/widget/src/beos/nsDialog.cpp b/widget/src/beos/nsDialog.cpp new file mode 100644 index 000000000000..7aa2e16ef8c2 --- /dev/null +++ b/widget/src/beos/nsDialog.cpp @@ -0,0 +1,165 @@ +/* -*- 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 "nsDialog.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsIAppShell.h" +#include "nsIFontMetrics.h" +#include "nsGUIEvent.h" +#include "nsIRenderingContext.h" +#include "nsIDeviceContext.h" +#include "nsRect.h" +#include "nsTransform2D.h" +#include "nsStringUtil.h" +#include "nsGfxCIID.h" +#include "resource.h" + +NS_IMPL_ADDREF(nsDialog) +NS_IMPL_RELEASE(nsDialog) + +//------------------------------------------------------------------------- +// +// nsDialog constructor +// +//------------------------------------------------------------------------- +nsDialog::nsDialog() : nsWindow(), nsIDialog() +{ + NS_INIT_REFCNT(); +} + + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsDialog::Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return nsWindow::Create(aParent,aRect,aHandleEventFunction,aContext,aAppShell,aToolkit,aInitData); + +} + + +//------------------------------------------------------------------------- +// +// nsDialog destructor +// +//------------------------------------------------------------------------- +nsDialog::~nsDialog() +{ +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsDialog::SetLabel(const nsString& aText) +{ +#if 0 + NS_ALLOC_STR_BUF(label, aText, 256); + VERIFY(::SetWindowText(mWnd, label)); + NS_FREE_STR_BUF(label); +#endif +printf("nsDialog::SetLabel not implemented\n"); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsDialog::GetLabel(nsString& aBuffer) +{ +#if 0 + int actualSize = ::GetWindowTextLength(mWnd)+1; + NS_ALLOC_CHAR_BUF(label, 256, actualSize); + ::GetWindowText(mWnd, label, actualSize); + aBuffer.SetLength(0); + aBuffer.Append(label); + NS_FREE_CHAR_BUF(label); +#endif +printf("nsDialog::SetLabel not implemented\n"); + return NS_OK; +} + + + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsDialog::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsDialogIID, NS_IDIALOG_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsDialogIID)) { + *aInstancePtr = (void*) ((nsIDialog*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsDialog::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsDialog::OnPaint(nsRect &r) +{ + return nsWindow::OnPaint(r); +} + +PRBool nsDialog::OnResize(nsRect &aWindowRect) +{ + return nsWindow::OnResize(aWindowRect); +} + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsDialog::GetBounds(nsRect &aRect) +{ + return nsWindow::GetBounds(aRect); +} + diff --git a/widget/src/beos/nsDragService.cpp b/widget/src/beos/nsDragService.cpp new file mode 100644 index 000000000000..fd496d3215be --- /dev/null +++ b/widget/src/beos/nsDragService.cpp @@ -0,0 +1,230 @@ +/* -*- 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 "nsDragService.h" +#include "nsITransferable.h" +#include "nsIServiceManager.h" + +#include "nsWidgetsCID.h" + +static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID); +static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID); + +// The class statics: +BView *nsDragService::sView = 0; + +NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService) +NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService) + +//------------------------------------------------------------------------- +// static variables +//------------------------------------------------------------------------- + //static PRBool gHaveDrag = PR_FALSE; + +//------------------------------------------------------------------------- +// +// DragService constructor +// +//------------------------------------------------------------------------- +nsDragService::nsDragService() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// DragService destructor +// +//------------------------------------------------------------------------- +nsDragService::~nsDragService() +{ +} + +/** + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + nsresult rv = NS_NOINTERFACE; + + if (aIID.Equals(nsIDragService::GetIID())) { + *aInstancePtr = (void*) ((nsIDragService*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return rv; +} + +//--------------------------------------------------------- +NS_IMETHODIMP nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType) + +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_IMETHODIMP nsDragService::GetData (nsITransferable * aTransferable, + PRUint32 aItemIndex) +{ + return NS_ERROR_FAILURE; +} + +//------------------------------------------------------------------------- +void nsDragService::SetTopLevelView(BView *v) +{ + printf(" nsDragService::SetTopLevelWidget\n"); + + // Don't set up any more event handlers if we're being called twice + // for the same toplevel widget + if (sView == v) + return; + + sView = v; + + // Get the DragService from the service manager. + nsresult rv; + NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv); + + if (NS_FAILED(rv)) { + return; + } + +#if 0 + gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave", + GTK_SIGNAL_FUNC (nsDragService::DragLeave), dragService); + + gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion", + GTK_SIGNAL_FUNC (nsDragService::DragMotion), dragService); + + gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop", + GTK_SIGNAL_FUNC (nsDragService::DragDrop), dragService); + + gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received", + GTK_SIGNAL_FUNC (nsDragService::DragDataReceived), dragService); +#endif + +} + +//------------------------------------------------------------------------- +//void +//nsDragService::DragLeave (GtkWidget *widget, +// GdkDragContext *context, +// guint time) +//{ +// g_print("leave\n"); +// //gHaveDrag = PR_FALSE; +//} +// +////------------------------------------------------------------------------- +//PRBool +//nsDragService::DragMotion(GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// guint time) +//{ +// g_print("drag motion\n"); +// GtkWidget *source_widget; +// +//#if 0 +// if (!gHaveDrag) { +// gHaveDrag = PR_TRUE; +// } +//#endif +// +// source_widget = gtk_drag_get_source_widget (context); +// g_print("motion, source %s\n", source_widget ? +// gtk_type_name (GTK_OBJECT (source_widget)->klass->type) : +// "unknown"); +// +// gdk_drag_status (context, context->suggested_action, time); +// +// return PR_TRUE; +//} +// +////------------------------------------------------------------------------- +//PRBool +//nsDragService::DragDrop(GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// guint time) +//{ +// g_print("drop\n"); +// //gHaveDrag = PR_FALSE; +// +// if (context->targets){ +// gtk_drag_get_data (widget, context, +// GPOINTER_TO_INT (context->targets->data), +// time); +// return PR_TRUE; +// } +// +// return PR_FALSE; +//} +// +////------------------------------------------------------------------------- +//void +//nsDragService::DragDataReceived (GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// GtkSelectionData *data, +// guint info, +// guint time) +//{ +// if ((data->length >= 0) && (data->format == 8)) { +// g_print ("Received \"%s\"\n", (gchar *)data->data); +// gtk_drag_finish (context, PR_TRUE, PR_FALSE, time); +// return; +// } +// +// gtk_drag_finish (context, PR_FALSE, PR_FALSE, time); +//} +// +////------------------------------------------------------------------------- +//void +//nsDragService::DragDataGet(GtkWidget *widget, +// GdkDragContext *context, +// GtkSelectionData *selection_data, +// guint info, +// guint time, +// gpointer data) +//{ +// gtk_selection_data_set (selection_data, +// selection_data->target, +// 8, (guchar *)"I'm Data!", 9); +//} +// +////------------------------------------------------------------------------- +//void +//nsDragService::DragDataDelete(GtkWidget *widget, +// GdkDragContext *context, +// gpointer data) +//{ +// g_print ("Delete the data!\n"); +//} diff --git a/widget/src/beos/nsDragService.h b/widget/src/beos/nsDragService.h new file mode 100644 index 000000000000..9da2ddc99017 --- /dev/null +++ b/widget/src/beos/nsDragService.h @@ -0,0 +1,91 @@ +/* -*- 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 nsDragService_h__ +#define nsDragService_h__ + +#include "nsBaseDragService.h" +#include + + +/** + * Native BeOS DragService wrapper + */ + +class nsDragService : public nsBaseDragService +{ + +public: + nsDragService(); + virtual ~nsDragService(); + + //nsISupports + NS_DECL_ISUPPORTS_INHERITED + + + //nsIDragService + NS_IMETHOD StartDragSession (nsITransferable * aTransferable, + PRUint32 aActionType); + + // Native Impl. + NS_IMETHOD GetData (nsITransferable * aTransferable, PRUint32 aItemIndex); + + static void SetTopLevelView(BView *v); + + static BView *sView; + +protected: + static PRBool gHaveDrag; + +// static void DragLeave(GtkWidget *widget, +// GdkDragContext *context, +// guint time); +// +// static PRBool DragMotion(GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// guint time); +// +// static PRBool DragDrop(GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// guint time); +// +// static void DragDataReceived(GtkWidget *widget, +// GdkDragContext *context, +// gint x, +// gint y, +// GtkSelectionData *data, +// guint info, +// guint time); +// +// static void DragDataGet(GtkWidget *widget, +// GdkDragContext *context, +// GtkSelectionData *selection_data, +// guint info, +// guint time, +// gpointer data); +// +// static void DragDataDelete(GtkWidget *widget, +// GdkDragContext *context, +// gpointer data); +}; + +#endif // nsDragService_h__ diff --git a/widget/src/beos/nsDropTarget.cpp b/widget/src/beos/nsDropTarget.cpp new file mode 100644 index 000000000000..3e6b2c2c838e --- /dev/null +++ b/widget/src/beos/nsDropTarget.cpp @@ -0,0 +1,251 @@ +/* -*- 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 "stdafx.h" +//#include "olebase.h" +//#include "idropsrc.h" +#include "nsDropTarget.h" +//#include "contndoc.h" +#include "stdio.h" +#include "nsIWidget.h" + +#include "nsWindow.h" +//Don't forget to RegisterDragDrop and to +//CoLockObjectExternal. +//You must RevokeDragDrop before destroying this object +// +nsDropTarget::nsDropTarget(nsIWidget * aWindow) +{ + printf("nsDropTarget::nsDropTarget\n"); + m_refs = 0; + m_pWin = aWindow; + NS_ADDREF(aWindow); +} + +//Destructor for nsDropTarget +//Doesn't do a whole lot! +// +nsDropTarget::~nsDropTarget() +{ + printf("nsDropTarget::Drop\n"); + ; +} + +//QueryInterface for IDropTarget +//Notice that this QueryInterface does not refer to another object's QueryInterface, +//this is a totally stand-alone separate object +// +STDMETHODIMP nsDropTarget::QueryInterface(REFIID riid, LPVOID FAR* ppv) +{ + printf("nsDropTarget::QueryInterface\n"); + if (riid == IID_IUnknown) + *ppv = this; + else if (riid == IID_IDropTarget) + *ppv = this; + else{ + *ppv = NULL; + } + if (*ppv != NULL){ + ((LPUNKNOWN)(*ppv))->AddRef(); + return NOERROR; + } + +//If for some reason our constructor did not create the requested interface +//don't pass the NULL interface without telling the caller that we don't support +//the requested interface. + return ResultFromScode(E_NOINTERFACE); +} + +//A private AddRef for IDropTarget +// +STDMETHODIMP_(ULONG) nsDropTarget::AddRef(void) +{ + printf("nsDropTarget::AddRef\n"); + return ++m_refs; +} + +//A private Release for IDropTarget +// +STDMETHODIMP_(ULONG) nsDropTarget::Release(void) +{ + printf("nsDropTarget::Release\n"); + if(--m_refs == 0){ + //And now we can delete this object + delete this; + } + + return m_refs; +} + +// +//This helper function tells us what the drag/drop effect would be at +//the point pointl. Since our object accepts being a drop target anywhere +//in the window, we will ignore pointl +// +DWORD nsDropTarget::FindDragDropEffect(DWORD grfKeyState, POINTL /* pointl */) +{ + printf("nsDropTarget::FindDragDropEffect\n"); + DWORD dwRet; + + // no modifier -- DROPEFFECT_MOVE or source default + // SHIFT -- DROPEFFECT_MOVE + // CTRL -- DROPEFFECT_COPY + // CTRL-SHIFT -- DROPEFFECT_LINK + + dwRet = 0;//OleStdGetDropEffect(grfKeyState); + if (dwRet == 0) + dwRet = DROPEFFECT_COPY; + + return dwRet; +} + + +//Notification that a DropSource is over the current DropTarget +// +STDMETHODIMP nsDropTarget::DragEnter (LPDATAOBJECT pDataObj, + DWORD grfKeyState, + POINTL pointl, + LPDWORD pdwEffect) +{ + printf("nsDropTarget::DragEnter\n"); + *pdwEffect = FindDragDropEffect(grfKeyState, pointl); + return NOERROR; +} + +//Provides user feedback when a DropSource is over a DropTarget +// +STDMETHODIMP nsDropTarget::DragOver (DWORD grfKeyState, + POINTL pointl, + LPDWORD pdwEffect) +{ + printf("nsDropTarget::DragOver\n"); + *pdwEffect = FindDragDropEffect(grfKeyState, pointl); + return NOERROR; +} + + +//The DropSource is leaving our target window +//so its cleanup time!!! +// +STDMETHODIMP nsDropTarget::DragLeave (void) +{ + printf("nsDropTarget::DragLeave\n"); + return NOERROR; +} + +//Drops the DropSource +// +STDMETHODIMP nsDropTarget::Drop (LPDATAOBJECT pIDataObject, + DWORD grfKeyState, + POINTL pointl, + LPDWORD pdwEffect) +{ + printf("nsDropTarget::Drop\n"); + printf("pIDataObject 0x%x\n", pIDataObject); + pIDataObject->AddRef(); + if (nsnull != m_pWin) { + nsEventStatus status; + nsDragDropEvent event; + ((nsWindow *)m_pWin)->InitEvent(event, NS_DRAGDROP_EVENT); + event.mType = nsDragDropEventStatus_eDrop; + event.mIsFileURL = PR_FALSE; + event.mURL = nsnull; + m_pWin->DispatchEvent(&event, status); + } + + //pdwEffect = FindDragDropEffect(grfKeyState, pointl); + + + if (pIDataObject != NULL) { + IDataObject * presistStorage; + //printf("QueryInterface for persist\n"); + pIDataObject->QueryInterface(IID_IDataObject,(LPVOID *)&presistStorage); + //printf("Done QueryInterface for persist\n"); + if (presistStorage != NULL) { + printf("$$$$$$$$$$$$$$$ Got it!\n"); + FORMATETC pFE; + presistStorage->QueryGetData(&pFE); + + pFE.tymed = TYMED_FILE; + + STGMEDIUM pSTM; + HRESULT st = presistStorage->GetDataHere(&pFE, &pSTM); + printf("st 0x%X\n", st); + if (NOERROR != st) { + return FALSE; + } +//TYMED_STORAGE, TYMED_STREAM, TYMED_HGLOBAL, or TYMED_FILE + //printf("%s\n", pSTM.lpszFileName); + { + + //HRESULT hr = pIDataObject->GetData(&pFE, &pSTM); + //printf("hr 0x%X\n", hr); + //if (NOERROR != hr) { + // return FALSE; + //} + + const CLIPFORMAT format = pFE.cfFormat; + switch(format) { + case CF_BITMAP: + //hr = SetBitmap(*pFE, stm); + break; + case CF_DIB: + //hr = SetDib(*pFE, stm); + break; + case CF_TEXT: + //hr = SetText(*pFE, stm); + break; + case CF_METAFILEPICT: + //hr = SetMetafilePict(*pFE, stm); + break; + default: + //if (format == GetRcfFormat()) { + // hr = SetRcf(*pFE, stm); + //} + break; + } + + //return (SUCCEEDED(hr)); + + } + + + } else { + printf("^^^^^^^^^^^^^^^^^ Didn't!\n"); + } + } + + +/* if (m_pContainDoc->m_pOleSiteObject) + delete m_pContainDoc->m_pOleSiteObject; + m_pContainDoc->m_pOleSiteObject = new COleSiteObject(m_pContainDoc); + FORMATETC fmtetc; + fmtetc.cfFormat = NULL; + fmtetc.ptd = NULL; + fmtetc.lindex = -1; + fmtetc.dwAspect = DVASPECT_CONTENT; + fmtetc.tymed = TYMED_NULL; + m_pContainDoc->m_pOleSiteObject->AddSiteFromData(m_pContainDoc, + pIDataObject, + &fmtetc); +*/ + pIDataObject->Release(); + + DragLeave(); + + return NOERROR; +} diff --git a/widget/src/beos/nsFileWidget.cpp b/widget/src/beos/nsFileWidget.cpp new file mode 100644 index 000000000000..c41a4ee33b66 --- /dev/null +++ b/widget/src/beos/nsFileWidget.cpp @@ -0,0 +1,277 @@ +/* -*- 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. + */ + +// Define so header files for openfilename are included +#ifdef WIN32_LEAN_AND_MEAN +#undef WIN32_LEAN_AND_MEAN +#endif + +#include "nsFileWidget.h" + +//NS_IMPL_ISUPPORTS(nsFileWidget, NS_IFILEWIDGET_IID) +NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); +NS_IMPL_ISUPPORTS(nsFileWidget, kIFileWidgetIID); + +//------------------------------------------------------------------------- +// +// nsFileWidget constructor +// +//------------------------------------------------------------------------- +nsFileWidget::nsFileWidget() : nsIFileWidget() +{ + NS_INIT_REFCNT(); +// mWnd = NULL; + mNumberOfFilters = 0; +} + +//------------------------------------------------------------------------- +// +// Show - Display the file dialog +// +//------------------------------------------------------------------------- + +PRBool nsFileWidget::Show() +{ +printf("nsFileWidget::Show not implemented\n"); +#if 0 + char fileBuffer[MAX_PATH+1] = ""; + mDefault.ToCString(fileBuffer,MAX_PATH); + + OPENFILENAME ofn; + memset(&ofn, 0, sizeof(ofn)); + + ofn.lStructSize = sizeof(ofn); + + nsString filterList; + GetFilterListArray(filterList); + char *filterBuffer = filterList.ToNewCString(); + char *title = mTitle.ToNewCString(); + char *initialDir = mDisplayDirectory.ToNewCString(); + if (mDisplayDirectory.Length() > 0) { + ofn.lpstrInitialDir = initialDir; + } + + ofn.lpstrTitle = title; + ofn.lpstrFilter = filterBuffer; + ofn.nFilterIndex = 1; + ofn.hwndOwner = mWnd; + ofn.lpstrFile = fileBuffer; + ofn.nMaxFile = MAX_PATH; + ofn.Flags = OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + + PRBool 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"); + } + + // Store the current directory in mDisplayDirectory + char* newCurrentDirectory = new char[MAX_PATH+1]; + VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0); + mDisplayDirectory.SetLength(0); + mDisplayDirectory.Append(newCurrentDirectory); + delete newCurrentDirectory; + + + VERIFY(::SetCurrentDirectory(currentDirectory)); + delete currentDirectory; + + // Clean up filter buffers + delete filterBuffer; + delete title; + delete initialDir; + + // Set user-selected location of file or directory + mFile.SetLength(0); + if (result == PR_TRUE) { + mFile.Append(fileBuffer); + } + + return((PRBool)result); +#endif + return PR_TRUE; +} + +//------------------------------------------------------------------------- +// +// 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 +// +//------------------------------------------------------------------------- + +NS_METHOD nsFileWidget::SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]) +{ + mNumberOfFilters = aNumberOfFilters; + mTitles = aTitles; + mFilters = aFilters; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get the file + path +// +//------------------------------------------------------------------------- + +NS_METHOD nsFileWidget::GetFile(nsFileSpec& aFile) +{ + aFile = mFile; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the file + path +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDefaultString(const nsString& aString) +{ + mDefault = aString; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(const nsFileSpec& aDirectory) +{ + mDisplayDirectory = aDirectory; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetDisplayDirectory(nsFileSpec& aDirectory) +{ + aDirectory = mDisplayDirectory; + return NS_OK; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::Create(nsIWidget *aParent, + const nsString& aTitle, + nsFileDlgMode aMode, + nsIDeviceContext *aContext = nsnull, + nsIAppShell *aAppShell = nsnull, + nsIToolkit *aToolkit = nsnull, + void *aInitData = nsnull) +{ +// mWnd = (HWND) ((aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0); + mTitle.SetLength(0); + mTitle.Append(aTitle); + mMode = aMode; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// nsFileWidget destructor +// +//------------------------------------------------------------------------- +nsFileWidget::~nsFileWidget() +{ +} + + +nsFileDlgResults nsFileWidget::GetFile(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec) +{ + Create(aParent, promptString, eMode_load, nsnull, nsnull); + if (Show() == PR_TRUE) + { + GetFile(theFileSpec); + return nsFileDlgResults_OK; + } + + return nsFileDlgResults_Cancel; +} + +nsFileDlgResults nsFileWidget::GetFolder(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec) +{ + Create(aParent, promptString, eMode_getfolder, nsnull, nsnull); + if (Show() == PR_TRUE) + { + GetFile(theFileSpec); + return nsFileDlgResults_OK; + } + + return nsFileDlgResults_Cancel; +} + +nsFileDlgResults nsFileWidget::PutFile(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec) +{ + Create(aParent, promptString, eMode_save, nsnull, nsnull); + if (Show() == PR_TRUE) + { + GetFile(theFileSpec); + return nsFileDlgResults_OK; + } + return nsFileDlgResults_Cancel; +} + +NS_METHOD nsFileWidget::GetSelectedType(PRInt16& theType) +{ + theType = mSelectedType; + return NS_OK; +} + diff --git a/widget/src/beos/nsFileWidget.h b/widget/src/beos/nsFileWidget.h new file mode 100644 index 000000000000..09c0bab0e283 --- /dev/null +++ b/widget/src/beos/nsFileWidget.h @@ -0,0 +1,94 @@ +/* -*- 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 "nsObject.h" +#include "nsToolkit.h" +#include "nsIWidget.h" +#include "nsIFileWidget.h" + +/** + * Native Win32 FileSelector wrapper + */ + +class nsFileWidget : public nsIFileWidget +{ + public: + nsFileWidget(); + virtual ~nsFileWidget(); + + NS_DECL_ISUPPORTS + + PRBool OnPaint(nsRect &r); + + // nsIWidget interface + + NS_IMETHOD Create(nsIWidget *aParent, + const nsString& aTitle, + nsFileDlgMode aMode, + nsIDeviceContext *aContext = nsnull, + nsIAppShell *aAppShell = nsnull, + nsIToolkit *aToolkit = nsnull, + void *aInitData = nsnull); + + // nsIFileWidget part + virtual PRBool Show(); + NS_IMETHOD GetFile(nsFileSpec& aFile); + NS_IMETHOD SetDefaultString(const nsString& aFile); + NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, + const nsString aTitles[], + const nsString aFilters[]); + + NS_IMETHOD GetDisplayDirectory(nsFileSpec& aDirectory); + NS_IMETHOD SetDisplayDirectory(const nsFileSpec& aDirectory); + + virtual nsFileDlgResults GetFile(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec); + + virtual nsFileDlgResults GetFolder(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec); + + virtual nsFileDlgResults PutFile(nsIWidget *aParent, + const nsString &promptString, + nsFileSpec &theFileSpec); + + + NS_IMETHOD GetSelectedType(PRInt16& theType); + + protected: + +// HWND mWnd; + nsString mTitle; + nsFileDlgMode mMode; + nsString mFile; + PRUint32 mNumberOfFilters; + const nsString* mTitles; + const nsString* mFilters; + nsString mDefault; + nsFileSpec mDisplayDirectory; + PRInt16 mSelectedType; + + + void GetFilterListArray(nsString& aFilterList); +}; + +#endif // nsFileWidget_h__ diff --git a/widget/src/beos/nsFontRetrieverService.cpp b/widget/src/beos/nsFontRetrieverService.cpp new file mode 100644 index 000000000000..501ba282f758 --- /dev/null +++ b/widget/src/beos/nsFontRetrieverService.cpp @@ -0,0 +1,418 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsFontRetrieverService.h" +#include "nsIWidget.h" +#include + +#include "nsFont.h" +#include "nsVoidArray.h" +#include "nsFontSizeIterator.h" + +NS_IMPL_ADDREF(nsFontRetrieverService) +NS_IMPL_RELEASE(nsFontRetrieverService) + + +//---------------------------------------------------------- +nsFontRetrieverService::nsFontRetrieverService() +{ + NS_INIT_REFCNT(); + + mFontList = nsnull; + mSizeIter = nsnull; + mNameIterInx = 0; + +} + +//---------------------------------------------------------- +nsFontRetrieverService::~nsFontRetrieverService() +{ + if (nsnull != mFontList) { + for (PRInt32 i=0;iCount();i++) { + FontInfo * font = (FontInfo *)mFontList->ElementAt(i); + if (font->mSizes) { + delete font->mSizes; + } + delete font; + } + delete mFontList; + } + NS_IF_RELEASE(mSizeIter); +} + +/** + * @param aIID The name of the class implementing the method + * @param _classiiddef The name of the #define symbol that defines the IID + * for the class (e.g. NS_ISUPPORTS_IID) + * +*/ +nsresult nsFontRetrieverService::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + nsresult rv = NS_NOINTERFACE; + + if (aIID.Equals(nsIFontRetrieverService::GetIID())) { + *aInstancePtr = (void*) ((nsIFontRetrieverService*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(nsIFontNameIterator::GetIID())) { + *aInstancePtr = (void*) ((nsIFontNameIterator*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return rv; +} + + +//---------------------------------------------------------- +//-- nsIFontRetrieverService +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::CreateFontNameIterator( nsIFontNameIterator** aIterator ) +{ + if (nsnull == aIterator) { + return NS_ERROR_FAILURE; + } + + if (nsnull == mFontList) { + LoadFontList(); + } + *aIterator = this; + NS_ADDREF_THIS(); + return NS_OK; +} + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::CreateFontSizeIterator( const nsString & aFontName, + nsIFontSizeIterator** aIterator ) +{ + // save value in case someone externally is using it + PRInt32 saveIterInx = mNameIterInx; + + PRBool found = PR_FALSE; + Reset(); + do { + nsAutoString name; + Get(&name); + if (name.Equals(aFontName)) { + found = PR_TRUE; + break; + } + } while (Advance() == NS_OK); + + if (found) { + if (nsnull == mSizeIter) { + mSizeIter = new nsFontSizeIterator(); + } + NS_ASSERTION( nsnull != mSizeIter, "nsFontSizeIterator instance pointer is null"); + + *aIterator = (nsIFontSizeIterator *)mSizeIter; + NS_ADDREF(mSizeIter); + + FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx); + mSizeIter->SetFontInfo(fontInfo); + mNameIterInx = saveIterInx; + return NS_OK; + } + mNameIterInx = saveIterInx; + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------- +//-- nsIFontNameIterator +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::Reset() +{ + mNameIterInx = 0; + return NS_OK; +} + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName ) +{ + if (mNameIterInx < mFontList->Count()) { + FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx); + *aFontName = fontInfo->mName; + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::Advance() +{ + if (mNameIterInx < mFontList->Count()-1) { + mNameIterInx++; + return NS_OK; + } + return NS_ERROR_FAILURE; +} + +//------------------------------ +static FontInfo * GetFontInfo(nsVoidArray * aFontList, char * aName) +{ + nsAutoString name(aName); + PRInt32 i; + PRInt32 cnt = aFontList->Count(); + for (i=0;iElementAt(i); + if (fontInfo->mName.Equals(name)) { + return fontInfo; + } + } + + FontInfo * fontInfo = new FontInfo(); + fontInfo->mName = aName; + //printf("Adding [%s]\n", aName);fflush(stdout); + fontInfo->mIsScalable = PR_FALSE; // X fonts aren't scalable right?? + fontInfo->mSizes = nsnull; + aFontList->AppendElement(fontInfo); + return fontInfo; +} + +//------------------------------ +static void AddSizeToFontInfo(FontInfo * aFontInfo, PRInt32 aSize) +{ + nsVoidArray * sizes; + if (nsnull == aFontInfo->mSizes) { + sizes = new nsVoidArray(); + aFontInfo->mSizes = sizes; + } else { + sizes = aFontInfo->mSizes; + } + PRInt32 i; + PRInt32 cnt = sizes->Count(); + for (i=0;iElementAt(i); + if (size == aSize) { + return; + } + } + sizes->AppendElement((void *)aSize); +} + +//--------------------------------------------------- +// XXX - Hack - Parts of this will need to be reworked +// +// This method does brute force parcing for 4 different formats: +// +// 1) The format -*-*-*-*-*-* etc. +// -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-8 +// +// 2) Name-size format +// lucidasans-10 +// +// 3) Name-style-size +// lucidasans-bold-10 +// +// 4) Name only (implicit size) +// 6x13 +// +//-------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::LoadFontList() +{ +// char * pattern = "*"; +// int nnames = 1024; +// +// int available = nnames+1; +// int i; +// char **fonts; +// XFontStruct *info; +// +// if (nsnull == mFontList) { +// mFontList = new nsVoidArray(); +// if (nsnull == mFontList) { +// return NS_ERROR_FAILURE; +// } +// } +// +// /* Get list of fonts matching pattern */ +// for (;;) { +// // the following line is VERY slow to return +// fonts = XListFontsWithInfo(GDK_DISPLAY(), pattern, nnames, +// &available, &info); +// if (fonts == NULL || available < nnames) +// break; +// +// XFreeFontInfo(fonts, info, available); +// nnames = available * 2; +// } +// +// if (fonts == NULL) { +// fprintf(stderr, "pattern \"%s\" unmatched\n", pattern); +// return NS_ERROR_FAILURE; +// } +// +//#if 0 // debug +// // print out all the retrieved fonts +// printf("-----------------------------\n"); +// for (i=0; imSizes) { +// font->mSizes = new nsVoidArray(); +// } +// ptr = end+1; // skip past the dash that was set to zero +// +// cnt = 0; +// // now skip ahead 4 dashes +// do { +// if (*ptr == '-') cnt++; +// ptr++; +// } while (cnt < 4); +// +// // find the dash after the size +// end = strchr(ptr, '-'); +// +// if (end) { +// *end = 0; +// PRInt32 size; +// sscanf(ptr, "%d", &size); +// AddSizeToFontInfo(font, size); +// } +// } +// } else { // formats 2,3,4 +// +// // no leading dash means the start of the +// // buffer is the start of the name +// // this checks for a dash at the end of the font name +// // which means there is a size at the end +// char * end = strchr(buffer, '-'); +// if (end) { // Format 2,3 +// *end = 0; +// // Check to see if we need to create a new FontInfo obj +// // and set the currentName var to this guys font name +// if (strcmp(currentName, buffer) || NULL == font) { +// font = GetFontInfo(mFontList, buffer); +// strcpy(currentName, buffer); +// } +// end++; // advance past the dash +// // check to see if we have a number +// ptr = end; +// if (isalpha(*ptr)) { // Format 3 +// // skip until next dash +// end = strchr(ptr, '-'); +// if (end) { +// *end = 0; +// ptr = end+1; +// } +// } +// PRInt32 size; +// // yes, it has a dash at the end so it must have the size +// // check to see if the size is terminated by a dash +// // it shouldn't be +// char * end2 = strchr(ptr, '-'); +// if (end2) *end2 = 0; // put terminator at the dash +// sscanf(end, "%d", &size); +// AddSizeToFontInfo(font, size); +// +// } else { // Format #4 +// // The font has an implicit size, +// // so there is nothing to parse for size +// // so we can't really do much here +// // Check to see if we need to create a new FontInfo obj +// // and set the currentName var to this guys font name +// if (strcmp(currentName, buffer) || NULL == font) { +// font = GetFontInfo(mFontList, buffer); +// strcpy(currentName, buffer); +// } +// } +// } +// +// } +// +// XFreeFontInfo(fonts, info, available); + + return NS_OK; +} + + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontRetrieverService::IsFontScalable(const nsString & aFontName, + PRBool* aResult ) +{ + // save value in case someone externally is using it + PRInt32 saveIterInx = mNameIterInx; + + PRBool found = PR_FALSE; + Reset(); + do { + nsAutoString name; + Get(&name); + if (name.Equals(aFontName)) { + found = PR_TRUE; + break; + } + } while (Advance() == NS_OK); + + if (found) { + FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx); + *aResult = fontInfo->mIsScalable; + mNameIterInx = saveIterInx; + return NS_OK; + } + + mNameIterInx = saveIterInx; + return NS_ERROR_FAILURE; +} diff --git a/widget/src/beos/nsFontRetrieverService.h b/widget/src/beos/nsFontRetrieverService.h new file mode 100644 index 000000000000..9032fc138498 --- /dev/null +++ b/widget/src/beos/nsFontRetrieverService.h @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 __nsFontRetrieverService +#define __nsFontRetrieverService + +#include "nsIFontRetrieverService.h" +#include "nsIFontNameIterator.h" + +class nsVoidArray; +class nsFontSizeIterator; + +class nsFontRetrieverService: public nsIFontRetrieverService, + public nsIFontNameIterator { +public: + nsFontRetrieverService(); + virtual ~nsFontRetrieverService(); + + NS_DECL_ISUPPORTS + + // nsIFontRetrieverService + NS_IMETHOD CreateFontNameIterator( nsIFontNameIterator** aIterator ); + + NS_IMETHOD CreateFontSizeIterator( const nsString & aFontName, nsIFontSizeIterator** aIterator ); + NS_IMETHOD IsFontScalable( const nsString & aFontName, PRBool* aResult ); + + // nsIFontNameIterator + + NS_IMETHOD Reset(); + NS_IMETHOD Get( nsString* aFontName ); + NS_IMETHOD Advance(); + + + +protected: + NS_IMETHOD LoadFontList(); + + nsVoidArray * mFontList; + + PRInt32 mNameIterInx; + + nsFontSizeIterator * mSizeIter; +}; + +#endif diff --git a/widget/src/beos/nsFontSizeIterator.cpp b/widget/src/beos/nsFontSizeIterator.cpp new file mode 100644 index 000000000000..dc56075403ef --- /dev/null +++ b/widget/src/beos/nsFontSizeIterator.cpp @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsFontSizeIterator.h" + +#include "nsFont.h" +#include "nsVoidArray.h" + + +NS_IMPL_ADDREF(nsFontSizeIterator) +NS_IMPL_RELEASE(nsFontSizeIterator) +NS_IMPL_QUERY_INTERFACE(nsFontSizeIterator, nsIFontSizeIterator::GetIID()) + +//---------------------------------------------------------- +nsFontSizeIterator::nsFontSizeIterator() +{ + NS_INIT_REFCNT(); + mFontInfo = nsnull; + mSizeIterInx = 0; + +} + +//---------------------------------------------------------- +nsFontSizeIterator::~nsFontSizeIterator() +{ +} + +///---------------------------------------------------------- +//-- nsIFontNameIterator +//---------------------------------------------------------- +NS_IMETHODIMP nsFontSizeIterator::Reset() +{ + mSizeIterInx = 0; + return NS_OK; +} + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontSizeIterator::Get( double* aFontSize ) +{ + if (nsnull != mFontInfo->mSizes && + mFontInfo->mSizes->Count() > 0 && + mSizeIterInx < mFontInfo->mSizes->Count()) { + PRUint32 size = (PRUint32)mFontInfo->mSizes->ElementAt(mSizeIterInx); + *aFontSize = (double)size; + return NS_OK; + } + return NS_ERROR_FAILURE; +} + + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontSizeIterator::Advance() +{ + if (nsnull != mFontInfo->mSizes && + mFontInfo->mSizes->Count() > 0 && + mSizeIterInx < mFontInfo->mSizes->Count()-2) { + mSizeIterInx++; + return NS_OK; + } + + return NS_ERROR_FAILURE; +} + +//---------------------------------------------------------- +NS_IMETHODIMP nsFontSizeIterator::SetFontInfo( FontInfo * aFontInfo ) +{ + mFontInfo = aFontInfo; + return NS_OK; +} diff --git a/widget/src/beos/nsFontSizeIterator.h b/widget/src/beos/nsFontSizeIterator.h new file mode 100644 index 000000000000..45cce5062616 --- /dev/null +++ b/widget/src/beos/nsFontSizeIterator.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 __nsFontSizeIterator +#define __nsFontSizeIterator + +#include "nsIFontSizeIterator.h" +#include "nsString.h" + +class nsVoidArray; + +typedef struct { + nsString mName; + PRBool mIsScalable; + nsVoidArray * mSizes; +} FontInfo; + + +class nsFontSizeIterator: public nsIFontSizeIterator { +public: + nsFontSizeIterator(); + virtual ~nsFontSizeIterator(); + + NS_DECL_ISUPPORTS + + // nsIFontSizeIterator + NS_IMETHOD Reset(); + NS_IMETHOD Get( double* aFontSize ); + NS_IMETHOD Advance(); + + // Native impl + NS_IMETHOD SetFontInfo( FontInfo * aFontInfo ); + +protected: + + FontInfo * mFontInfo; + PRInt32 mSizeIterInx; // current index of iter +}; + +#endif diff --git a/widget/src/beos/nsLabel.cpp b/widget/src/beos/nsLabel.cpp new file mode 100644 index 000000000000..27157f2ccff4 --- /dev/null +++ b/widget/src/beos/nsLabel.cpp @@ -0,0 +1,222 @@ +/* -*- 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 "nsLabel.h" +#include "nsILabel.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" +#include "nsIFontMetrics.h" +#include "nsIDeviceContext.h" + +NS_IMPL_ADDREF(nsLabel) +NS_IMPL_RELEASE(nsLabel) + +//------------------------------------------------------------------------- +// +// nsLabel constructor +// +//------------------------------------------------------------------------- +nsLabel::nsLabel() : nsWindow(), nsILabel() +{ + NS_INIT_REFCNT(); + mAlignment = eAlign_Left; +} + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsLabelInitData* data = (nsLabelInitData *) aInitData; + mAlignment = data->mAlignment; + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsLabel destructor +// +//------------------------------------------------------------------------- +nsLabel::~nsLabel() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsLabel::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kILabelIID)) { + *aInstancePtr = (void*) ((nsILabel*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment) +{ + mAlignment = aAlignment; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::SetLabel(const nsString& aText) +{ + char label[256]; + aText.ToCString(label, 256); + label[255] = '\0'; + if(mStringView && mStringView->LockLooper()) + { + mStringView->SetText(label); + mStringView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::GetLabel(nsString& aBuffer) +{ + if(mStringView && mStringView->LockLooper()) + { + aBuffer.SetLength(0); + aBuffer.Append(mStringView->Text()); + mStringView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsLabel::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsLabel::OnPaint(nsRect &r) +{ + //printf("** nsLabel::OnPaint **\n"); + return PR_FALSE; +} + +PRBool nsLabel::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsLabel::GetBounds(nsRect &aRect) +{ + return nsWindow::GetBounds(aRect); +} + +//------------------------------------------------------------------------- +NS_METHOD nsLabel::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) +{ + if (nsnull == mContext) { + return NS_ERROR_FAILURE; + } + //nsIFontMetrics * fm = GetFont();; + // mDeviceContext->GetMetricsFor(mFont, &fm); + + nsIFontMetrics* metrics; + mContext->GetMetricsFor(*mFont, metrics); + + nsString text; + GetLabel(text); + + nsIRenderingContext *cx; + mContext->CreateRenderingContext(this, cx); + cx->SetFont(metrics); + nscoord string_height, string_width; + metrics->GetHeight(string_height); + cx->GetWidth(text, string_width); + NS_RELEASE(cx); + NS_RELEASE(metrics); + + if (mPreferredWidth != 0) { + aWidth = mPreferredWidth; + } else { + aWidth = string_width+8; + } + + if (mPreferredHeight != 0) { + aHeight = mPreferredHeight; + } else { + aHeight = string_height+8; + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsLabel::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) +{ + mPreferredWidth = aWidth; + mPreferredHeight = aHeight; + return NS_OK; +} + +BView *nsLabel::CreateBeOSView() +{ + return mStringView = new nsStringViewBeOS(this, BRect(0, 0, 0, 0), "", ""); +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS StringView +//------------------------------------------------------------------------- +nsStringViewBeOS::nsStringViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, const char *text, uint32 aResizingMode, uint32 aFlags ) + : BStringView( aFrame, aName, text, aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ +} diff --git a/widget/src/beos/nsLabel.h b/widget/src/beos/nsLabel.h new file mode 100644 index 000000000000..fcc56d2b996f --- /dev/null +++ b/widget/src/beos/nsLabel.h @@ -0,0 +1,78 @@ +/* -*- 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 nsLabel_h__ +#define nsLabel_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsILabel.h" + +#include + +/** + * Native Win32 Label wrapper + */ + +class nsLabel : public nsWindow, + public nsILabel +{ + +public: + nsLabel(); + virtual ~nsLabel(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsILabel part + NS_IMETHOD SetLabel(const nsString &aText); + NS_IMETHOD GetLabel(nsString &aBuffer); + NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + + NS_IMETHOD GetBounds(nsRect &aRect); + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + + NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); + NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); + +protected: + nsLabelAlignment mAlignment; + BStringView *mStringView; + BView *CreateBeOSView(); +}; + +// +// A BStringView subclass +// +class nsStringViewBeOS : public BStringView, public nsIWidgetStore { + public: + nsStringViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + const char *text, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); +}; + +#endif // nsLabel_h__ diff --git a/widget/src/beos/nsListBox.cpp b/widget/src/beos/nsListBox.cpp new file mode 100644 index 000000000000..79f55b32a1cf --- /dev/null +++ b/widget/src/beos/nsListBox.cpp @@ -0,0 +1,389 @@ +/* -*- 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 "nsListBox.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + + +NS_IMPL_ADDREF(nsListBox) +NS_IMPL_RELEASE(nsListBox) + +//------------------------------------------------------------------------- +// +// initializer +// +//------------------------------------------------------------------------- + +NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections) +{ + mMultiSelect = aMultipleSelections; + if(mListView && mListView->LockLooper()) + { + mListView->SetListType(aMultipleSelections ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST); + mListView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsListBoxInitData* data = (nsListBoxInitData *) aInitData; + mMultiSelect = data->mMultiSelect; + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// destructor +// +//------------------------------------------------------------------------- + +NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) +{ + if(mListView && mListView->LockLooper()) + { + NS_ALLOC_STR_BUF(val, aItem, 256); + mListView->AddItem(new BStringItem(val), aPosition); + NS_FREE_STR_BUF(val); + mListView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Finds an item at a postion +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos) +{ +#if 0 + NS_ALLOC_STR_BUF(val, aItem, 256); + int index = ::SendMessage(mWnd, LB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val); + NS_FREE_STR_BUF(val); + + return index; +#endif + printf("nsListBox::FindItem not implemented\n"); + return -1; +} + +//------------------------------------------------------------------------- +// +// CountItems - Get Item Count +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetItemCount() +{ + PRInt32 result = 0; + if(mListView && mListView->LockLooper()) + { + result = mListView->CountItems(); + mListView->UnlockLooper(); + } + return result; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsListBox::RemoveItemAt(PRInt32 aPosition) +{ + if(mListView && mListView->LockLooper()) + { + BListItem *it = mListView->RemoveItem(aPosition); + delete it; + mListView->UnlockLooper(); + return it ? PR_TRUE : PR_FALSE; + } + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) +{ + PRBool result = PR_FALSE; + anItem.SetLength(0); + if(mListView && mListView->LockLooper()) + { + BListItem *it = mListView->ItemAt(aPosition); + BStringItem *str; + if((str = dynamic_cast(it)) != 0) + { + anItem.Append(str->Text()); + result = PR_TRUE; + } + mListView->UnlockLooper(); + } + return result; +} + +//------------------------------------------------------------------------- +// +// Gets the selected of selected item +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::GetSelectedItem(nsString& aItem) +{ + if (!mMultiSelect) { + GetItemAt(aItem, GetSelectedIndex()); + } else { + NS_ASSERTION(0, "Multi selection list box does not support GetSelectedItem()"); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Gets the list of selected otems +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetSelectedIndex() +{ + if (!mMultiSelect) + { + PRInt32 index = -1; + if(mListView && mListView->LockLooper()) + { + index = mListView->CurrentSelection(); + mListView->UnlockLooper(); + } + return index; + } else { + NS_ASSERTION(0, "Multi selection list box does not support GetSelectedIndex()"); + } + return 0; +} + +//------------------------------------------------------------------------- +// +// SelectItem +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::SelectItem(PRInt32 aPosition) +{ + if(mListView && mListView->LockLooper()) + { + mListView->Select(aPosition); + mListView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// GetSelectedCount +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetSelectedCount() +{ + if (!mMultiSelect) { + PRInt32 inx = GetSelectedIndex(); + return (inx == -1? 0 : 1); + } else { + PRInt32 count = 0; + if(mListView && mListView->LockLooper()) + { + int index = 0; + while((index = mListView->CurrentSelection(index)) != -1) + count++; + mListView->UnlockLooper(); + } + return count; + } +} + +//------------------------------------------------------------------------- +// +// GetSelectedIndices +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + if(mListView && mListView->LockLooper()) + { + int index = 0; + for(int i = 0; i < aSize; i++) + { + if(index != -1) + index = mListView->CurrentSelection(index); + aIndices[i] = index; + } + mListView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// SetSelectedIndices +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + if(mListView && mListView->LockLooper()) + { + mListView->Select(aIndices[0], false); + for(int i = 1; i < aSize; i++) + mListView->Select(aIndices[i], true); + mListView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Deselect +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::Deselect() +{ + if(mListView && mListView->LockLooper()) + { + mListView->DeselectAll(); + mListView->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// nsListBox constructor +// +//------------------------------------------------------------------------- +nsListBox::nsListBox() : nsWindow(), nsIListWidget(), nsIListBox() +{ + NS_INIT_REFCNT(); + mMultiSelect = PR_FALSE; + mBackground = NS_RGB(124, 124, 124); +} + +//------------------------------------------------------------------------- +// +// nsListBox:: destructor +// +//------------------------------------------------------------------------- +nsListBox::~nsListBox() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsListBoxIID, NS_ILISTBOX_IID); + static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID); + if (result == NS_NOINTERFACE) { + if (aIID.Equals(kInsListBoxIID)) { + *aInstancePtr = (void*) ((nsIListBox*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + else if (aIID.Equals(kInsListWidgetIID)) { + *aInstancePtr = (void*) ((nsIListWidget*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + } + + return result; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsListBox::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsListBox::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsListBox::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +//------------------------------------------------------------------------- +// +// Clear window before paint +// +//------------------------------------------------------------------------- + +PRBool nsListBox::AutoErase() +{ + return(PR_TRUE); +} + + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsListBox::GetBounds(nsRect &aRect) +{ +#if 0 + nsWindow::GetNonClientBounds(aRect); +#endif +printf("nsListBox::GetBounds not wrong\n"); // the following is just a placeholder + nsWindow::GetClientBounds(aRect); + return NS_OK; +} + +BView *nsListBox::CreateBeOSView() +{ + return mListView = new nsListViewBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), ""); +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS ListView +//------------------------------------------------------------------------- +nsListViewBeOS::nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, uint32 aResizingMode, uint32 aFlags ) + : BListView( aFrame, aName, + ((nsListBox *)aWidgetWindow)->mMultiSelect ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST, + aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ +} diff --git a/widget/src/beos/nsListBox.h b/widget/src/beos/nsListBox.h new file mode 100644 index 000000000000..148ccdc18348 --- /dev/null +++ b/widget/src/beos/nsListBox.h @@ -0,0 +1,91 @@ +/* -*- 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 nsListBox_h__ +#define nsListBox_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" +#include "nsIListBox.h" + +#include +#include + +/** + * Native Win32 Listbox wrapper + */ + +class nsListBox : public nsWindow, + public nsIListWidget, + public nsIListBox +{ + +public: + nsListBox(); + virtual ~nsListBox(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + + NS_IMETHOD GetBounds(nsRect &aRect); + + + // nsIListBox interface + NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections); + NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition); + PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos); + PRInt32 GetItemCount(); + PRBool RemoveItemAt(PRInt32 aPosition); + PRBool GetItemAt(nsString& anItem, PRInt32 aPosition); + NS_IMETHOD GetSelectedItem(nsString& aItem); + PRInt32 GetSelectedIndex(); + PRInt32 GetSelectedCount(); + NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + NS_IMETHOD SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + NS_IMETHOD SelectItem(PRInt32 aPosition); + NS_IMETHOD Deselect() ; + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + + // nsWindow interface + virtual PRBool AutoErase(); +protected: + PRBool mMultiSelect; + virtual BView *CreateBeOSView(); + BListView *mListView; + + friend class nsListViewBeOS; +}; + +// +// A BListView subclass +// +class nsListViewBeOS : public BListView, public nsIWidgetStore { + public: + nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); +}; + +#endif // nsListBox_h__ diff --git a/widget/src/beos/nsLookAndFeel.cpp b/widget/src/beos/nsLookAndFeel.cpp new file mode 100644 index 000000000000..cc9fc3818823 --- /dev/null +++ b/widget/src/beos/nsLookAndFeel.cpp @@ -0,0 +1,184 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nsLookAndFeel.h" +#include "nsFont.h" + +//static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +//NS_IMPL_ISUPPORTS(nsLookAndFeel, NS_ILOOKANDFEEL_IID) + +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +NS_IMPL_ISUPPORTS(nsLookAndFeel, kILookAndFeelIID); + +nsLookAndFeel::nsLookAndFeel() : nsILookAndFeel() +{ + NS_INIT_REFCNT(); +} + +nsLookAndFeel::~nsLookAndFeel() +{ +} + +NS_IMETHODIMP nsLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor) +{ + nsresult res = NS_OK; + int idx; + switch (aID) { + case eColor_WindowBackground: + aColor = NS_RGB(0xff,0xff,0xff); + break; + case eColor_WindowForeground: + aColor = NS_RGB(0x00,0x00,0x00); + break; + case eColor_WidgetBackground: + aColor = NS_RGB(192, 192, 192); + break; + case eColor_WidgetForeground: + aColor = NS_RGB(0x00,0x00,0x00); + break; + case eColor_WidgetSelectBackground: + aColor = NS_RGB(0x80,0x80,0x80); + break; + case eColor_WidgetSelectForeground: + aColor = NS_RGB(0x00,0x00,0x80); + break; + case eColor_Widget3DHighlight: + aColor = NS_RGB(0xa0,0xa0,0xa0); + break; + case eColor_Widget3DShadow: + aColor = NS_RGB(0x40,0x40,0x40); + break; + case eColor_TextBackground: + aColor = NS_RGB(0xff,0xff,0xff); + break; + case eColor_TextForeground: + aColor = NS_RGB(0x00,0x00,0x00); + break; + case eColor_TextSelectBackground: + aColor = NS_RGB(0x00,0x00,0x80); + break; + case eColor_TextSelectForeground: + aColor = NS_RGB(0xff,0xff,0xff); + break; + default: + aColor = NS_RGB(0xff,0xff,0xff); + res = NS_ERROR_FAILURE; + break; + } + + return res; +} + +NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) +{ + nsresult res = NS_OK; + switch (aID) { + case eMetric_WindowTitleHeight: + aMetric = 0; + break; + case eMetric_WindowBorderWidth: + aMetric = 0; + break; + case eMetric_WindowBorderHeight: + aMetric = 0; + break; + case eMetric_Widget3DBorder: + aMetric = 0; + break; + case eMetric_TextFieldHeight: + aMetric = 24; + break; + case eMetric_ButtonHorizontalInsidePaddingNavQuirks: + aMetric = 10; + break; + case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: + aMetric = 8; + break; + case eMetric_CheckboxSize: + aMetric = 12; + break; + case eMetric_RadioboxSize: + aMetric = 12; + break; + case eMetric_TextHorizontalInsideMinimumPadding: + aMetric = 3; + break; + case eMetric_TextVerticalInsidePadding: + aMetric = 0; + break; + case eMetric_TextShouldUseVerticalInsidePadding: + aMetric = 0; + break; + case eMetric_TextShouldUseHorizontalInsideMinimumPadding: + aMetric = 1; + break; + case eMetric_ListShouldUseHorizontalInsideMinimumPadding: + aMetric = 0; + break; + case eMetric_ListHorizontalInsideMinimumPadding: + aMetric = 3; + break; + case eMetric_ListShouldUseVerticalInsidePadding: + aMetric = 0; + break; + case eMetric_ListVerticalInsidePadding: + aMetric = 0; + break; + default: + aMetric = -1; + res = NS_ERROR_FAILURE; + } + return res; +} + +NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric) +{ + nsresult res = NS_OK; + switch (aID) { + case eMetricFloat_TextFieldVerticalInsidePadding: + aMetric = 0.25f; + break; + case eMetricFloat_TextFieldHorizontalInsidePadding: + aMetric = 0.95f; + break; + case eMetricFloat_TextAreaVerticalInsidePadding: + aMetric = 0.40f; + break; + case eMetricFloat_TextAreaHorizontalInsidePadding: + aMetric = 0.40f; + break; + case eMetricFloat_ListVerticalInsidePadding: + aMetric = 0.10f; + break; + case eMetricFloat_ListHorizontalInsidePadding: + aMetric = 0.40f; + break; + case eMetricFloat_ButtonVerticalInsidePadding: + aMetric = 0.25f; + break; + case eMetricFloat_ButtonHorizontalInsidePadding: + aMetric = 0.25f; + break; + default: + aMetric = -1.0; + res = NS_ERROR_FAILURE; + } + return res; +} + + diff --git a/widget/src/beos/nsLookAndFeel.h b/widget/src/beos/nsLookAndFeel.h new file mode 100644 index 000000000000..4f64a050fd6e --- /dev/null +++ b/widget/src/beos/nsLookAndFeel.h @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 __nsLookAndFeel +#define __nsLookAndFeel +#include "nsObject.h" +#include "nsILookAndFeel.h" + +class nsLookAndFeel: public nsILookAndFeel { +public: + nsLookAndFeel(); + virtual ~nsLookAndFeel(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD GetColor(const nsColorID aID, nscolor &aColor); + NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric); + NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric); +}; + +#endif diff --git a/widget/src/beos/nsMenu.cpp b/widget/src/beos/nsMenu.cpp new file mode 100644 index 000000000000..5f284eb9ce15 --- /dev/null +++ b/widget/src/beos/nsMenu.cpp @@ -0,0 +1,620 @@ +/* -*- 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 "nsMenu.h" +#include "nsIComponentManager.h" +#include "nsIDOMElement.h" +#include "nsIDOMNode.h" +#include "nsIMenuBar.h" +#include "nsIMenuItem.h" +#include "nsIMenuListener.h" +#include "nsString.h" +#include "nsCOMPtr.h" +#include "nsWidgetsCID.h" + +static NS_DEFINE_CID(kMenuCID, NS_MENU_CID); +static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsresult nsMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + *aInstancePtr = NULL; + + if (aIID.Equals(nsIMenu::GetIID())) { + *aInstancePtr = (void*)(nsIMenu*) this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)(nsIMenu*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(nsIMenuListener::GetIID())) { + *aInstancePtr = (void*)(nsIMenuListener*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsMenu) +NS_IMPL_RELEASE(nsMenu) + +//------------------------------------------------------------------------- +// +// nsMenu constructor +// +//------------------------------------------------------------------------- +nsMenu::nsMenu() : nsIMenu() +{ + NS_INIT_REFCNT(); + mMenu = nsnull; + mMenuBarParent = nsnull; + mMenuParent = nsnull; + mListener = nsnull; + NS_NewISupportsArray(&mItems); + + mDOMNode = nsnull; + mWebShell = nsnull; + mDOMElement = nsnull; +} + +//------------------------------------------------------------------------- +// +// nsMenu destructor +// +//------------------------------------------------------------------------- +nsMenu::~nsMenu() +{ + NS_IF_RELEASE(mMenuBarParent); + NS_IF_RELEASE(mMenuParent); + NS_IF_RELEASE(mListener); + + // Remove all references to the items + mItems->Clear(); +} + + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel) +{ + if(aParent) + { + nsIMenuBar * menubar = nsnull; + aParent->QueryInterface(nsIMenuBar::GetIID(), (void**) &menubar); + if(menubar) + { + mMenuBarParent = menubar; + NS_RELEASE(menubar); + } + else + { + nsIMenu * menu = nsnull; + aParent->QueryInterface(nsIMenu::GetIID(), (void**) &menu); + if(menu) + { + mMenuParent = menu; + NS_RELEASE(menu); + } + } + } + + mLabel = aLabel; + char *str = mLabel.ToNewCString(); + mMenu = new BMenu(str); + delete [] str; + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetParent(nsISupports*& aParent) +{ + + aParent = nsnull; + if (nsnull != mMenuParent) { + return mMenuParent->QueryInterface(kISupportsIID,(void**)&aParent); + } else if (nsnull != mMenuBarParent) { + return mMenuBarParent->QueryInterface(kISupportsIID,(void**)&aParent); + } + + return NS_ERROR_FAILURE; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetLabel(nsString &aText) +{ + aText = mLabel; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::SetLabel(const nsString &aText) +{ + mLabel = aText; + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddItem(nsISupports * aItem) +{ + if(aItem) + { + nsIMenuItem * menuitem = nsnull; + aItem->QueryInterface(nsIMenuItem::GetIID(), + (void**)&menuitem); + if(menuitem) + { + AddMenuItem(menuitem); // nsMenu now owns this + NS_RELEASE(menuitem); + } + else + { + nsIMenu * menu = nsnull; + aItem->QueryInterface(nsIMenu::GetIID(), + (void**)&menu); + if(menu) + { + AddMenu(menu); // nsMenu now owns this + NS_RELEASE(menu); + } + } + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddSeparator() +{ + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + nsresult rv = nsComponentManager::CreateInstance( + kMenuItemCID, nsnull, nsIMenuItem::GetIID(), (void**)&pnsMenuItem); + if (NS_OK == rv) { + nsString tmp = "separator"; + nsISupports * supports = nsnull; + QueryInterface(kISupportsIID, (void**) &supports); + pnsMenuItem->Create(supports, tmp, PR_TRUE); + NS_RELEASE(supports); + + pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports); + AddItem(supports); // Parent should now own menu item + NS_RELEASE(supports); + + NS_RELEASE(pnsMenuItem); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// This does not return a ref counted object +// This is NOT an nsIMenu method +nsIMenuBar * nsMenu::GetMenuBar(nsIMenu * aMenu) +{ + if (!aMenu) { + return nsnull; + } + + nsMenu * menu = (nsMenu *)aMenu; + + if (menu->GetMenuBarParent()) { + return menu->GetMenuBarParent(); + } + + if (menu->GetMenuParent()) { + return GetMenuBar(menu->GetMenuParent()); + } + + return nsnull; +} + +//------------------------------------------------------------------------- +// This does not return a ref counted object +// This is NOT an nsIMenu method +nsIWidget * nsMenu::GetParentWidget() +{ + nsIWidget * parent = nsnull; + nsIMenuBar * menuBar = GetMenuBar(this); + if (menuBar) { + menuBar->GetParent(parent); + } + + return parent; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenuItem(nsIMenuItem * aMenuItem) +{ + PRUint32 cnt; + nsresult rv = mItems->Count(&cnt); + if (NS_FAILED(rv)) return rv; + return InsertItemAt(cnt, (nsISupports *)aMenuItem); +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenu(nsIMenu * aMenu) +{ + PRUint32 cnt; + nsresult rv = mItems->Count(&cnt); + if (NS_FAILED(rv)) return rv; + return InsertItemAt(cnt, (nsISupports *)aMenu); +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetItemCount(PRUint32 &aCount) +{ + return mItems->Count(&aCount); +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetItemAt(const PRUint32 aCount, nsISupports *& aMenuItem) +{ + aMenuItem = (nsISupports *)mItems->ElementAt(aCount); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::InsertItemAt(const PRUint32 aCount, nsISupports * aMenuItem) +{ + bool status = false; + + mItems->InsertElementAt(aMenuItem, (PRInt32)aCount); + + nsCOMPtr menuItem(do_QueryInterface(aMenuItem)); + if (menuItem) { + BMenuItem *it; + void *data; + menuItem->GetNativeData(data); + it = (BMenuItem *)data; + mMenu->AddItem(it, aCount); + status = true; + } else { + nsCOMPtr menu(do_QueryInterface(aMenuItem)); + if (menu) { + BMenu *m; + void *data; + menu->GetNativeData(&data); + m = (BMenu *)data; + mMenu->AddItem(m, aCount); + status = true; + } + } + + return (status ? NS_OK : NS_ERROR_FAILURE); +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveItem(const PRUint32 aCount) +{ +printf("nsMenu::RemoveItem - FIXME: not implemented\n"); +#if 0 + //nsISupports * supports = (nsISupports *)mItems->ElementAt(aCount); + mItems->RemoveElementAt(aCount); + + return (::RemoveMenu(mMenu, aCount, MF_BYPOSITION) ? NS_OK:NS_ERROR_FAILURE); +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveAll() +{ +printf("nsMenu::RemoveAll - FIXME: not implemented\n"); +#if 0 + while (mItems->Count()) { + mItems->RemoveElementAt(0); + ::RemoveMenu(mMenu, 0, MF_BYPOSITION); + } +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetNativeData(void ** aData) +{ + *aData = (void *)mMenu; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenuListener(nsIMenuListener * aMenuListener) +{ + mListener = aMenuListener; + NS_ADDREF(mListener); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveMenuListener(nsIMenuListener * aMenuListener) +{ + if (aMenuListener == mListener) { + NS_IF_RELEASE(mListener); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// nsIMenuListener interface +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + if (nsnull != mListener) { + mListener->MenuSelected(aMenuEvent); + } + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenu::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + if (nsnull != mListener) { + mListener->MenuSelected(aMenuEvent); + } + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuDeselected(const nsMenuEvent & aMenuEvent) +{ + if (nsnull != mListener) { + mListener->MenuDeselected(aMenuEvent); + } + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuConstruct(const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell) +{ + //g_print("nsMenu::MenuConstruct called \n"); + if(menuNode){ + SetDOMNode((nsIDOMNode*)menuNode); + } + + if(!aWebShell){ + aWebShell = mWebShell; + } + + // First open the menu. + nsCOMPtr domElement = do_QueryInterface(mDOMNode); + if (domElement) + domElement->SetAttribute("open", "true"); + + // Begin menuitem inner loop + nsCOMPtr menuitemNode; + ((nsIDOMNode*)mDOMNode)->GetFirstChild(getter_AddRefs(menuitemNode)); + + unsigned short menuIndex = 0; + + while (menuitemNode) { + nsCOMPtr menuitemElement(do_QueryInterface(menuitemNode)); + if (menuitemElement) { + nsString menuitemNodeType; + nsString menuitemName; + menuitemElement->GetNodeName(menuitemNodeType); + if (menuitemNodeType.Equals("menuitem")) { + // LoadMenuItem + LoadMenuItem(this, + menuitemElement, + menuitemNode, + menuIndex, + (nsIWebShell*)aWebShell); + } else if (menuitemNodeType.Equals("separator")) { + AddSeparator(); + } else if (menuitemNodeType.Equals("menu")) { + // Load a submenu + LoadSubMenu(this, menuitemElement, menuitemNode); + } + } + + ++menuIndex; + + nsCOMPtr oldmenuitemNode(menuitemNode); + oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); + } // end menu item innner loop + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent) +{ + // Close the node. + nsCOMPtr domElement = do_QueryInterface(mDOMNode); + if (domElement) + domElement->RemoveAttribute("open"); + + //g_print("nsMenu::MenuDestruct called \n"); + RemoveAll(); + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +/** +* Set DOMNode +* +*/ +NS_METHOD nsMenu::SetDOMNode(nsIDOMNode * aMenuNode) +{ + mDOMNode = aMenuNode; + return NS_OK; +} + +//------------------------------------------------------------------------- +/** +* Set DOMElement +* +*/ +NS_METHOD nsMenu::SetDOMElement(nsIDOMElement * aMenuElement) +{ + mDOMElement = aMenuElement; + return NS_OK; +} + +//------------------------------------------------------------------------- +/** +* Set WebShell +* +*/ +NS_METHOD nsMenu::SetWebShell(nsIWebShell * aWebShell) +{ + mWebShell = aWebShell; + return NS_OK; +} + +//---------------------------------------- +void nsMenu::LoadMenuItem(nsIMenu * pParentMenu, + nsIDOMElement * menuitemElement, + nsIDOMNode * menuitemNode, + unsigned short menuitemIndex, + nsIWebShell * aWebShell) +{ + static const char* NS_STRING_TRUE = "true"; + nsString disabled; + nsString menuitemName; + nsString menuitemCmd; + + menuitemElement->GetAttribute(nsAutoString("disabled"), disabled); + menuitemElement->GetAttribute(nsAutoString("name"), menuitemName); + menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd); + + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, + nsnull, + nsIMenuItem::GetIID(), + (void**)&pnsMenuItem); + if (NS_OK == rv) { + pnsMenuItem->Create(pParentMenu, menuitemName, PR_FALSE); + + nsISupports * supports = nsnull; + pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports); + pParentMenu->AddItem(supports); // Parent should now own menu item + NS_RELEASE(supports); + + if(disabled == NS_STRING_TRUE ) { + pnsMenuItem->SetEnabled(PR_FALSE); + } + + // Create MenuDelegate - this is the intermediator inbetween + // the DOM node and the nsIMenuItem + // The nsWebShellWindow wacthes for Document changes and then notifies the + // the appropriate nsMenuDelegate object + nsCOMPtr domElement(do_QueryInterface(menuitemNode)); + if (!domElement) { + //return NS_ERROR_FAILURE; + return; + } + + nsAutoString cmdAtom("onclick"); + nsString cmdName; + + domElement->GetAttribute(cmdAtom, cmdName); + + pnsMenuItem->SetCommand(cmdName); + // DO NOT use passed in webshell because of messed up windows dynamic loading + // code. + pnsMenuItem->SetWebShell(mWebShell); + pnsMenuItem->SetDOMElement(domElement); + + NS_RELEASE(pnsMenuItem); + + } + return; +} + +//---------------------------------------- +void nsMenu::LoadSubMenu(nsIMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode) +{ + nsString menuName; + menuElement->GetAttribute(nsAutoString("name"), menuName); + //printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks + + // Create nsMenu + nsIMenu * pnsMenu = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuCID, + nsnull, + nsIMenu::GetIID(), + (void**)&pnsMenu); + if (NS_OK == rv) { + // Call Create + nsISupports * supports = nsnull; + pParentMenu->QueryInterface(kISupportsIID, (void**) &supports); + pnsMenu->Create(supports, menuName); + NS_RELEASE(supports); // Balance QI + + // Set nsMenu Name + pnsMenu->SetLabel(menuName); + + supports = nsnull; + pnsMenu->QueryInterface(kISupportsIID, (void**) &supports); + pParentMenu->AddItem(supports); // parent takes ownership + NS_RELEASE(supports); + + pnsMenu->SetWebShell(mWebShell); + pnsMenu->SetDOMNode(menuNode); + + /* + // Begin menuitem inner loop + unsigned short menuIndex = 0; + + nsCOMPtr menuitemNode; + menuNode->GetFirstChild(getter_AddRefs(menuitemNode)); + while (menuitemNode) { + nsCOMPtr menuitemElement(do_QueryInterface(menuitemNode)); + if (menuitemElement) { + nsString menuitemNodeType; + menuitemElement->GetNodeName(menuitemNodeType); + +#ifdef DEBUG_saari + printf("Type [%s] %d\n", menuitemNodeType.ToNewCString(), menuitemNodeType.Equals("separator")); +#endif + + if (menuitemNodeType.Equals("menuitem")) { + // Load a menuitem + LoadMenuItem(pnsMenu, menuitemElement, menuitemNode, menuIndex, mWebShell); + } else if (menuitemNodeType.Equals("separator")) { + pnsMenu->AddSeparator(); + } else if (menuitemNodeType.Equals("menu")) { + // Add a submenu + LoadSubMenu(pnsMenu, menuitemElement, menuitemNode); + } + } + ++menuIndex; + nsCOMPtr oldmenuitemNode(menuitemNode); + oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); + } // end menu item innner loop + */ + } +} diff --git a/widget/src/beos/nsMenu.h b/widget/src/beos/nsMenu.h new file mode 100644 index 000000000000..12cf180084a0 --- /dev/null +++ b/widget/src/beos/nsMenu.h @@ -0,0 +1,115 @@ +/* -*- 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 nsMenu_h__ +#define nsMenu_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsIMenu.h" +#include "nsISupportsArray.h" + +#include +class nsIMenuListener; + +/** + * Native BeOS Menu wrapper + */ + +class nsMenu : public nsIMenu, public nsIMenuListener +{ + +public: + nsMenu(); + virtual ~nsMenu(); + + NS_DECL_ISUPPORTS + + //nsIMenuListener interface + nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell); + nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); + + NS_IMETHOD Create(nsISupports * aParent, const nsString &aLabel); + + // nsIMenu Methods + NS_IMETHOD GetParent(nsISupports *&aParent); + NS_IMETHOD GetLabel(nsString &aText); + NS_IMETHOD SetLabel(const nsString &aText); + NS_IMETHOD AddItem(nsISupports * aItem); + NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem); + NS_IMETHOD AddMenu(nsIMenu * aMenu); + NS_IMETHOD AddSeparator(); + NS_IMETHOD GetItemCount(PRUint32 &aCount); + NS_IMETHOD GetItemAt(const PRUint32 aPos, nsISupports *& aMenuItem); + NS_IMETHOD InsertItemAt(const PRUint32 aPos, nsISupports * aMenuItem); + NS_IMETHOD RemoveItem(const PRUint32 aPos); + NS_IMETHOD RemoveAll(); + NS_IMETHOD GetNativeData(void** aData); + NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener); + NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener); + + NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode); + NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement); + NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + + // Native Impl Methods + // These are not ref counted + nsIMenu * GetMenuParent() { return mMenuParent; } + nsIMenuBar * GetMenuBarParent() { return mMenuBarParent; } + BMenu * GetNativeMenu() { return mMenu; } + +protected: + void LoadMenuItem( + nsIMenu * pParentMenu, + nsIDOMElement * menuitemElement, + nsIDOMNode * menuitemNode, + unsigned short menuitemIndex, + nsIWebShell * aWebShell); + + void LoadSubMenu( + nsIMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode); + + nsIMenuBar * GetMenuBar(nsIMenu * aMenu); + nsIWidget * GetParentWidget(); + + nsString mLabel; + BMenu *mMenu; + + nsIMenuBar * mMenuBarParent; + nsIMenu * mMenuParent; + + nsISupportsArray * mItems; + nsIMenuListener * mListener; + + nsIDOMNode * mDOMNode; + nsIWebShell * mWebShell; + nsIDOMElement * mDOMElement; +}; + +#endif // nsMenu_h__ diff --git a/widget/src/beos/nsMenuBar.cpp b/widget/src/beos/nsMenuBar.cpp new file mode 100644 index 000000000000..fa875fcc63ed --- /dev/null +++ b/widget/src/beos/nsMenuBar.cpp @@ -0,0 +1,319 @@ +/* -*- 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 "nsMenuBar.h" +#include "nsMenuItem.h" +#include "nsIComponentManager.h" +#include "nsIDOMNode.h" +#include "nsIMenu.h" +#include "nsIWebShell.h" +#include "nsIWidget.h" + +#include "nsString.h" + +#include "nsCOMPtr.h" +#include "nsWidgetsCID.h" + +#include + +static NS_DEFINE_CID(kMenuBarCID, NS_MENUBAR_CID); +static NS_DEFINE_CID(kMenuCID, NS_MENU_CID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); + +nsresult nsMenuBar::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + *aInstancePtr = NULL; + + if (aIID.Equals(nsIMenuBar::GetIID())) { + *aInstancePtr = (void*) ((nsIMenuBar*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*) ((nsISupports*)(nsIMenuBar*) this); + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(nsIMenuListener::GetIID())) { + *aInstancePtr = (void*) ((nsIMenuListener*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsMenuBar) +NS_IMPL_RELEASE(nsMenuBar) + +//------------------------------------------------------------------------- +// +// nsMenuBar constructor +// +//------------------------------------------------------------------------- +nsMenuBar::nsMenuBar() : nsIMenuBar(), nsIMenuListener() +{ + NS_INIT_REFCNT(); + mMenu = nsnull; + mParent = nsnull; + mItems = new nsVoidArray(); +} + +//------------------------------------------------------------------------- +// +// nsMenuBar destructor +// +//------------------------------------------------------------------------- +nsMenuBar::~nsMenuBar() +{ + NS_IF_RELEASE(mParent); + + // Remove all references to the menus + mItems->Clear(); +} + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::Create(nsIWidget *aParent) +{ + SetParent(aParent); + mMenu = new BMenuBar(BRect(0, 0, 0, 0), B_EMPTY_STRING); +// mParent->SetMenuBar(this); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent) +{ + aParent = mParent; + NS_ADDREF(mParent); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::SetParent(nsIWidget *aParent) +{ + NS_IF_RELEASE(mParent); + mParent = aParent; + NS_IF_ADDREF(mParent); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu) +{ + InsertMenuAt(mItems->Count(), aMenu); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetMenuCount(PRUint32 &aCount) +{ + aCount = mItems->Count(); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetMenuAt(const PRUint32 aPos, nsIMenu *& aMenu) +{ + aMenu = (nsIMenu *)mItems->ElementAt(aPos); + NS_ADDREF(aMenu); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::InsertMenuAt(const PRUint32 aPos, nsIMenu *& aMenu) +{ + nsString name; + aMenu->GetLabel(name); + char * nameStr = name.ToNewCString(); + + mItems->InsertElementAt(aMenu, (PRInt32)aPos); + NS_ADDREF(aMenu); + + BMenu *nativeMenu; + void *data; + aMenu->GetNativeData(&data); + nativeMenu = (BMenu *)data; + mMenu->AddItem(nativeMenu, aPos); + delete[] nameStr; + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::RemoveMenu(const PRUint32 aPos) +{ + nsIMenu * menu = (nsIMenu *)mItems->ElementAt(aPos); + NS_RELEASE(menu); + mItems->RemoveElementAt(aPos); + delete mMenu->RemoveItem(aPos); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::RemoveAll() +{ +printf("nsMenuBar::RemoveAll - FIXME: not implemented\n"); +#if 0 + while (mItems->Count()) { + nsISupports * supports = (nsISupports *)mItems->ElementAt(0); + NS_RELEASE(supports); + mItems->RemoveElementAt(0); + + ::RemoveMenu(mMenu, 0, MF_BYPOSITION); + } +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetNativeData(void *& aData) +{ + aData = (void *)mMenu; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::SetNativeData(void * aData) +{ + // Temporary hack for MacOS. Will go away when nsMenuBar handles it's own + // construction + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::Paint() +{ + mParent->Invalidate(PR_TRUE); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsMenuListener interface +// +//------------------------------------------------------------------------- +nsEventStatus nsMenuBar::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuDeselected(const nsMenuEvent & aMenuEvent) +{ + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menubarNode, + void * aWebShell) +{ + mWebShell = (nsIWebShell*) aWebShell; + mDOMNode = (nsIDOMNode*)menubarNode; + + nsIMenuBar * pnsMenuBar = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuBarCID, + nsnull, + nsIMenuBar::GetIID(), + (void**)&pnsMenuBar); + if (NS_OK == rv) { + if (nsnull != pnsMenuBar) { + pnsMenuBar->Create(aParentWindow); + + // set pnsMenuBar as a nsMenuListener on aParentWindow + nsCOMPtr menuListener; + pnsMenuBar->QueryInterface(nsIMenuListener::GetIID(), getter_AddRefs(menuListener)); + aParentWindow->AddMenuListener(menuListener); + + nsCOMPtr menuNode; + ((nsIDOMNode*)menubarNode)->GetFirstChild(getter_AddRefs(menuNode)); + while (menuNode) { + nsCOMPtr menuElement(do_QueryInterface(menuNode)); + if (menuElement) { + nsString menuNodeType; + nsString menuName; + menuElement->GetNodeName(menuNodeType); + if (menuNodeType.Equals("menu")) { + menuElement->GetAttribute(nsAutoString("name"), menuName); + // Don't create the menu yet, just add in the top level names + + // Create nsMenu + nsIMenu * pnsMenu = nsnull; + rv = nsComponentManager::CreateInstance(kMenuCID, nsnull, nsIMenu::GetIID(), (void**)&pnsMenu); + if (NS_OK == rv) { + // Call Create + nsISupports * supports = nsnull; + pnsMenuBar->QueryInterface(kISupportsIID, (void**) &supports); + pnsMenu->Create(supports, menuName); + NS_RELEASE(supports); + + pnsMenu->SetLabel(menuName); + pnsMenu->SetDOMNode(menuNode); + pnsMenu->SetDOMElement(menuElement); + pnsMenu->SetWebShell(mWebShell); + + // Make nsMenu a child of nsMenuBar + // nsMenuBar takes ownership of the nsMenu + pnsMenuBar->AddMenu(pnsMenu); + + // Release the menu now that the menubar owns it + NS_RELEASE(pnsMenu); + } + } + + } + nsCOMPtr oldmenuNode(menuNode); + oldmenuNode->GetNextSibling(getter_AddRefs(menuNode)); + } // end while (nsnull != menuNode) + + // Give the aParentWindow this nsMenuBar to hold onto. + // The parent window should take ownership at this point + aParentWindow->SetMenuBar(pnsMenuBar); + + // HACK: force a paint for now + pnsMenuBar->Paint(); + + NS_RELEASE(pnsMenuBar); + } // end if ( nsnull != pnsMenuBar ) + } + + return nsEventStatus_eIgnore; + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuDestruct(const nsMenuEvent & aMenuEvent) +{ + return nsEventStatus_eIgnore; +} diff --git a/widget/src/beos/nsMenuBar.h b/widget/src/beos/nsMenuBar.h new file mode 100644 index 000000000000..5c4794fcbcec --- /dev/null +++ b/widget/src/beos/nsMenuBar.h @@ -0,0 +1,89 @@ +/* -*- 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 nsMenuBar_h__ +#define nsMenuBar_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsIMenuBar.h" +#include "nsIMenuListener.h" +#include "nsVoidArray.h" + + +class nsIDOMNode; +class nsIWebShell; +class nsIWidget; + +#include + +/** + * Native Win32 button wrapper + */ + +class nsMenuBar : public nsIMenuBar, public nsIMenuListener +{ + +public: + nsMenuBar(); + virtual ~nsMenuBar(); + + // nsIMenuListener interface + nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell); + nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); + + NS_DECL_ISUPPORTS + + + NS_IMETHOD Create(nsIWidget * aParent); + + // nsIMenuBar Methods + NS_IMETHOD GetParent(nsIWidget *&aParent); + NS_IMETHOD SetParent(nsIWidget * aParent); + NS_IMETHOD AddMenu(nsIMenu * aMenu); + NS_IMETHOD GetMenuCount(PRUint32 &aCount); + NS_IMETHOD GetMenuAt(const PRUint32 aPos, nsIMenu *& aMenu); + NS_IMETHOD InsertMenuAt(const PRUint32 aPos, nsIMenu *& aMenu); + NS_IMETHOD RemoveMenu(const PRUint32 aPos); + NS_IMETHOD RemoveAll(); + NS_IMETHOD GetNativeData(void*& aData); + NS_IMETHOD Paint(); + NS_IMETHOD SetNativeData(void* aData); + +protected: + PRUint32 mNumMenus; + BMenuBar *mMenu; + nsIWidget * mParent; + + nsIWebShell * mWebShell; + nsIDOMNode * mDOMNode; + + nsVoidArray * mItems; + +}; + +#endif // nsMenuBar_h__ diff --git a/widget/src/beos/nsMenuItem.cpp b/widget/src/beos/nsMenuItem.cpp new file mode 100644 index 000000000000..e013ab8d529f --- /dev/null +++ b/widget/src/beos/nsMenuItem.cpp @@ -0,0 +1,439 @@ +/* -*- 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 "nsMenuItem.h" +#include "nsIMenu.h" +#include "nsIMenuBar.h" +#include "nsIWidget.h" + +#include "nsIPopUpMenu.h" + +#include "nsCOMPtr.h" +#include "nsIContent.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" +#include "nsIDOMElement.h" +#include "nsIDocumentViewer.h" +#include "nsIPresContext.h" +#include "nsIWebShell.h" +#include "nsICharsetConverterManager.h" +#include "nsIPlatformCharset.h" +#include "nsIServiceManager.h" + +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +//NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID) + +nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + *aInstancePtr = NULL; + + if (aIID.Equals(kIMenuItemIID)) { + *aInstancePtr = (void*)(nsIMenuItem*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kIMenuListenerIID)) { + *aInstancePtr = (void*)(nsIMenuListener*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + if (aIID.Equals(kISupportsIID)) { + *aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + return NS_NOINTERFACE; +} + +NS_IMPL_ADDREF(nsMenuItem) +NS_IMPL_RELEASE(nsMenuItem) + + +//------------------------------------------------------------------------- +// +// nsMenuItem constructor +// +//------------------------------------------------------------------------- +nsMenuItem::nsMenuItem() : nsIMenuItem() +{ + NS_INIT_REFCNT(); + mMenuItem = nsnull; + mMenuParent = nsnull; + mPopUpParent = nsnull; + mTarget = nsnull; + mListener = nsnull; + mIsSeparator = PR_FALSE; + mWebShell = nsnull; + mDOMElement = nsnull; +} + +//------------------------------------------------------------------------- +// +// nsMenuItem destructor +// +//------------------------------------------------------------------------- +nsMenuItem::~nsMenuItem() +{ + NS_IF_RELEASE(mMenuParent); + NS_IF_RELEASE(mPopUpParent); + NS_IF_RELEASE(mTarget); +} + +//------------------------------------------------------------------------- +nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent) +{ + nsIWidget * widget = nsnull; // MenuBar's Parent + nsIMenu * menu = nsnull; + nsIMenuBar * menuBar = nsnull; + nsIPopUpMenu * popup = nsnull; + nsISupports * parent = aParent; + + // Bump the ref count on the parent, since it gets released unconditionally.. + NS_ADDREF(parent); + while (1) { + if (NS_OK == parent->QueryInterface(kIMenuIID,(void**)&menu)) { + NS_RELEASE(parent); + if (NS_OK != menu->GetParent(parent)) { + NS_RELEASE(menu); + return nsnull; + } + NS_RELEASE(menu); + + } else if (NS_OK == parent->QueryInterface(kIPopUpMenuIID,(void**)&popup)) { + if (NS_OK != popup->GetParent(widget)) { + widget = nsnull; + } + NS_RELEASE(parent); + NS_RELEASE(popup); + return widget; + + } else if (NS_OK == parent->QueryInterface(kIMenuBarIID,(void**)&menuBar)) { + if (NS_OK != menuBar->GetParent(widget)) { + widget = nsnull; + } + NS_RELEASE(parent); + NS_RELEASE(menuBar); + return widget; + } else { + NS_RELEASE(parent); + return nsnull; + } + } + return nsnull; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::Create(nsISupports *aParent, + const nsString &aLabel, + PRBool aIsSeparator) +{ + if (nsnull == aParent) { + return NS_ERROR_FAILURE; + } + + if(aParent) { + nsIMenu * menu; + aParent->QueryInterface(nsIMenu::GetIID(), (void**) &menu); + mMenuParent = menu; + NS_RELEASE(menu); + } + + nsIWidget *widget = nsnull; // MenuBar's Parent + nsISupports *sups; + if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) { + widget = GetMenuBarParent(sups); + // GetMenuBarParent will call release for us + // NS_RELEASE(sups); + mTarget = widget; + } + + mIsSeparator = aIsSeparator; + mLabel = aLabel; + + // create the native menu item + + if(mIsSeparator) { + mMenuItem = new BSeparatorItem(); + } else { + char * nameStr = mLabel.ToNewCString(); + BMessage *msg = new BMessage('menu'); + msg->AddPointer("nsMenuItem", this); + mMenuItem = new BMenuItem(nameStr, msg); + delete[] nameStr; +// mMenuItem = CreateLocalized(aLabel); + } + +// gtk_widget_show(mMenuItem); +// +// gtk_signal_connect(GTK_OBJECT(mMenuItem), "activate", +// GTK_SIGNAL_FUNC(menu_item_activate_handler), +// this); + + return NS_OK; +} + +//------------------------------------------------------------------------- +BMenu *nsMenuItem::GetNativeParent() +{ + void * voidData; + if (nsnull != mMenuParent) { + mMenuParent->GetNativeData(&voidData); + } else if (nsnull != mPopUpParent) { + mPopUpParent->GetNativeData(voidData); + } else { + return nsnull; + } + return (BMenu *)voidData; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetLabel(nsString &aText) +{ + aText = mLabel; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetLabel(nsString &aText) +{ + mLabel = aText; + + return NS_OK; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand) +{ + aCommand = mCommand; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget) +{ + aTarget = mTarget; + NS_ADDREF(mTarget); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetNativeData(void *& aData) +{ + aData = (void *)mMenuItem; + return NS_OK; +} +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener) +{ + NS_IF_RELEASE(mListener); + mListener = aMenuListener; + NS_ADDREF(mListener); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::RemoveMenuListener(nsIMenuListener * aMenuListener) +{ + if (mListener == aMenuListener) { + NS_IF_RELEASE(mListener); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep) +{ + aIsSep = mIsSeparator; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetEnabled(PRBool aIsEnabled) +{ + mMenuItem->SetEnabled(aIsEnabled ? true : false); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetEnabled(PRBool *aIsEnabled) +{ + *aIsEnabled = mMenuItem->IsEnabled(); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetChecked(PRBool aIsEnabled) +{ + mMenuItem->SetMarked(aIsEnabled ? true : false); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled) +{ + *aIsEnabled = mMenuItem->IsMarked(); + return NS_OK; +} + + +//------------------------------------------------------------------------- +// nsIMenuListener interface +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + if(!mIsSeparator) { + //g_print("nsMenuItem::MenuItemSelected\n"); + DoCommand(); + }else{ + //g_print("nsMenuItem::MenuItemSelected is separator\n"); + } + return nsEventStatus_eIgnore; +} +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + if(mListener) + return mListener->MenuSelected(aMenuEvent); + + //g_print("nsMenuItem::MenuSelected\n"); + return nsEventStatus_eIgnore; +} +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuDeselected(const nsMenuEvent &aMenuEvent) +{ + //g_print("nsMenuItem::MenuDeselected\n"); + return nsEventStatus_eIgnore; +} +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuConstruct(const nsMenuEvent &aMenuEvent, + nsIWidget *aParentWindow, + void *menuNode, + void *aWebShell) +{ + //g_print("nsMenuItem::MenuConstruct\n"); + return nsEventStatus_eIgnore; +} +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuDestruct(const nsMenuEvent &aMenuEvent) +{ + //g_print("nsMenuItem::MenuDestruct\n"); + return nsEventStatus_eIgnore; +} + + +//------------------------------------------------------------------------- +/** + * Sets the JavaScript Command to be invoked when a "gui" event + * occurs on a source widget + * @param aStrCmd the JS command to be cached for later execution + * @return NS_OK + */ +NS_METHOD nsMenuItem::SetCommand(const nsString &aStrCmd) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +/** + * Executes the "cached" JavaScript Command + * @return NS_OK if the command was executed properly, otherwise an error code + */ +NS_METHOD nsMenuItem::DoCommand() +{ + nsresult rv = NS_ERROR_FAILURE; + + if(!mWebShell || !mDOMElement) + return rv; + + nsCOMPtr contentViewerContainer; + contentViewerContainer = do_QueryInterface(mWebShell); + if (!contentViewerContainer) { + NS_ERROR("Webshell doesn't support the content viewer container interface"); + //g_print("Webshell doesn't support the content viewer container interface"); + return rv; + } + + nsCOMPtr contentViewer; + if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) { + NS_ERROR("Unable to retrieve content viewer."); + //g_print("Unable to retrieve content viewer."); + return rv; + } + + nsCOMPtr docViewer; + docViewer = do_QueryInterface(contentViewer); + if (!docViewer) { + NS_ERROR("Document viewer interface not supported by the content viewer."); + //g_print("Document viewer interface not supported by the content viewer."); + return rv; + } + + nsCOMPtr presContext; + if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) { + NS_ERROR("Unable to retrieve the doc viewer's presentation context."); + //g_print("Unable to retrieve the doc viewer's presentation context."); + return rv; + } + + nsEventStatus status = nsEventStatus_eIgnore; + nsMouseEvent event; + event.eventStructType = NS_MOUSE_EVENT; + event.message = NS_MOUSE_LEFT_CLICK; + + nsCOMPtr contentNode; + contentNode = do_QueryInterface(mDOMElement); + if (!contentNode) { + NS_ERROR("DOM Node doesn't support the nsIContent interface required to handle DOM events."); + //g_print("DOM Node doesn't support the nsIContent interface required to handle DOM events."); + return rv; + } + + rv = contentNode->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status); + //g_print("HandleDOMEvent called"); + return rv; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetDOMElement(nsIDOMElement * aDOMElement) +{ + mDOMElement = aDOMElement; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetDOMElement(nsIDOMElement ** aDOMElement) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetWebShell(nsIWebShell * aWebShell) +{ + mWebShell = aWebShell; + return NS_OK; +} + diff --git a/widget/src/beos/nsMenuItem.h b/widget/src/beos/nsMenuItem.h new file mode 100644 index 000000000000..0620230e9a8d --- /dev/null +++ b/widget/src/beos/nsMenuItem.h @@ -0,0 +1,104 @@ +/* -*- 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 nsMenuItem_h__ +#define nsMenuItem_h__ + +#include "nsdefs.h" +#include "nsISupports.h" +#include "nsIWidget.h" +#include "nsSwitchToUIThread.h" + +#include "nsIMenuItem.h" +#include "nsIMenuListener.h" + +#include + +class nsIMenu; +class nsIPopUpMenu; +class nsIMenuListener; + +/** + * Native BeOS MenuItem wrapper + */ + +class nsMenuItem : public nsIMenuItem, public nsIMenuListener +{ + +public: + nsMenuItem(); + virtual ~nsMenuItem(); + + // nsISupports + NS_DECL_ISUPPORTS + + NS_IMETHOD Create(nsISupports *aParent, + const nsString &aLabel, + PRBool aIsSeparator); + + // nsIMenuBar Methods + NS_IMETHOD GetLabel(nsString &aText); + NS_IMETHOD SetLabel(nsString &aText); + NS_IMETHOD SetEnabled(PRBool aIsEnabled); + NS_IMETHOD GetEnabled(PRBool *aIsEnabled); + NS_IMETHOD SetChecked(PRBool aIsEnabled); + NS_IMETHOD GetChecked(PRBool *aIsEnabled); + NS_IMETHOD GetCommand(PRUint32 & aCommand); + NS_IMETHOD GetTarget(nsIWidget *& aTarget); + NS_IMETHOD GetNativeData(void*& aData); + NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener); + NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener); + NS_IMETHOD IsSeparator(PRBool & aIsSep); + + NS_IMETHOD SetCommand(const nsString & aStrCmd); + NS_IMETHOD DoCommand(); + NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMElement); + NS_IMETHOD GetDOMElement(nsIDOMElement ** aDOMElement); + NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + + // nsIMenuListener interface + nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent); + nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell); + nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent); + +protected: + void Create(nsIWidget * aMBParent, BMenu *aParent, + const nsString &aLabel, PRUint32 aCommand); + nsIWidget * GetMenuBarParent(nsISupports * aParent); + BMenu *nsMenuItem::GetNativeParent(); + + BMenuItem *mMenuItem; + + nsString mLabel; + PRUint32 mCommand; + nsIMenu *mMenuParent; + nsIPopUpMenu *mPopUpParent; + nsIWidget * mTarget; + nsIMenu * mMenu; + nsIMenuListener * mListener; + PRBool mIsSeparator; + nsIWebShell * mWebShell; + nsIDOMElement * mDOMElement; +}; + +#endif // nsMenuItem_h__ diff --git a/widget/src/beos/nsObject.cpp b/widget/src/beos/nsObject.cpp new file mode 100644 index 000000000000..7565eb5be32d --- /dev/null +++ b/widget/src/beos/nsObject.cpp @@ -0,0 +1,84 @@ +/* -*- 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 "nsObject.h" + + +CList nsObject::s_liveChain; +PRMonitor *nsObject::s_liveChainMutex = PR_NewMonitor(); + +#ifdef _DEBUG +int32 nsObject::s_nObjects = 0; +#endif + +/** + * constructor + */ +nsObject::nsObject() +{ + // + // Add the new object the chain of allocated nsObjects + // + PR_EnterMonitor(s_liveChainMutex); + s_liveChain.Append(m_link); + PR_ExitMonitor(s_liveChainMutex); +#ifdef _DEBUG + s_nObjects++; +#endif +} + + +/** + * destructor + */ +nsObject::~nsObject() +{ +#ifdef _DEBUG + s_nObjects--; +#endif + // + // Remove from the chain of allocated nsObjects + // + PR_EnterMonitor(s_liveChainMutex); + m_link.Remove(); + PR_ExitMonitor(s_liveChainMutex); +} + + +/** + * static utility. Delete all live objects + */ + +void nsObject::DeleteAllObjects(void) +{ + PR_EnterMonitor(s_liveChainMutex); + + while (!s_liveChain.IsEmpty()) { + nsObject *pnsObject; + + pnsObject = (nsObject*)OBJECT_PTR_FROM_CLIST(nsObject, s_liveChain.next); + + // Remove the event from the chain... + pnsObject->m_link.Remove(); + delete pnsObject; + } + + PR_ExitMonitor(s_liveChainMutex); +} + diff --git a/widget/src/beos/nsObject.h b/widget/src/beos/nsObject.h new file mode 100644 index 000000000000..f0e3b1478480 --- /dev/null +++ b/widget/src/beos/nsObject.h @@ -0,0 +1,63 @@ +/* -*- 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 nsObject_h__ +#define nsObject_h__ + +#include "nsdefs.h" +#include "nsCList.h" +#include "nsISupports.h" +#include "prmon.h" + +/** + * nsObject is the base class for all native widgets + */ + +class nsObject +{ + +public: + nsObject(); + virtual ~nsObject(); + +protected: + // + // Data members: + // + CList m_link; + +public: + + // + // The following data members are used to maintain a chain of all + // allocated nsObject instances. This chain is traversed at + // shutdown to clean up any dangling instances... + // + static CList s_liveChain; + static PRMonitor *s_liveChainMutex; + +#ifdef _DEBUG + static int32 s_nObjects; +#endif + + static void DeleteAllObjects(void); + +}; + + +#endif // nsObject_h__ diff --git a/widget/src/beos/nsPopUpMenu.cpp b/widget/src/beos/nsPopUpMenu.cpp new file mode 100644 index 000000000000..5281b52596b1 --- /dev/null +++ b/widget/src/beos/nsPopUpMenu.cpp @@ -0,0 +1,236 @@ +/* -*- 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 "nsPopUpMenu.h" +#include "nsIPopUpMenu.h" +#include "nsIMenu.h" + +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsIAppShell.h" +#include "nsGUIEvent.h" +#include "nsIDeviceContext.h" +#include "nsRect.h" +#include "nsGfxCIID.h" + +static NS_DEFINE_IID(kPopUpMenuIID, NS_IPOPUPMENU_IID); +NS_IMPL_ISUPPORTS(nsPopUpMenu, kPopUpMenuIID) + + +//------------------------------------------------------------------------- +// +// nsPopUpMenu constructor +// +//------------------------------------------------------------------------- +nsPopUpMenu::nsPopUpMenu() : nsIPopUpMenu() +{ + NS_INIT_REFCNT(); + mNumMenuItems = 0; + mParent = nsnull; + mMenu = nsnull; +} + +//------------------------------------------------------------------------- +// +// nsPopUpMenu destructor +// +//------------------------------------------------------------------------- +nsPopUpMenu::~nsPopUpMenu() +{ + NS_IF_RELEASE(mParent); +} + + + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::Create(nsIWidget *aParent) +{ +printf("nsPopUpMenu::Create - FIXME: not implemented\n"); + + mParent = aParent; + NS_ADDREF(mParent); + +// mMenu = CreatePopupMenu(); + + return NS_OK; + +} + + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddItem(const nsString &aText) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddItem(nsIMenuItem * aMenuItem) +{ +#if 0 + PRUint32 command; + nsString name; + + aMenuItem->GetCommand(command); + aMenuItem->GetLabel(name); + char * nameStr = name.ToNewCString(); + + MENUITEMINFO menuInfo; + menuInfo.cbSize = sizeof(menuInfo); + menuInfo.fMask = MIIM_TYPE | MIIM_ID; + menuInfo.fType = MFT_STRING; + menuInfo.dwTypeData = nameStr; + menuInfo.wID = (DWORD)command; + menuInfo.cch = strlen(nameStr); + + BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo); + + delete[] nameStr; +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddMenu(nsIMenu * aMenu) +{ +#if 0 + nsString name; + aMenu->GetLabel(name); + char * nameStr = name.ToNewCString(); + + HMENU nativeMenuHandle; + void * voidData; + aMenu->GetNativeData(voidData); + nativeMenuHandle = (HMENU)voidData; + + MENUITEMINFO menuInfo; + + menuInfo.cbSize = sizeof(menuInfo); + menuInfo.fMask = MIIM_SUBMENU | MIIM_TYPE; + menuInfo.hSubMenu = nativeMenuHandle; + menuInfo.fType = MFT_STRING; + menuInfo.dwTypeData = nameStr; + + BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo); + + delete[] nameStr; +#endif + return NS_OK; + +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddSeparator() +{ +#if 0 + MENUITEMINFO menuInfo; + + menuInfo.cbSize = sizeof(menuInfo); + menuInfo.fMask = MIIM_TYPE; + menuInfo.fType = MFT_SEPARATOR; + + BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo); +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetItemCount(PRUint32 &aCount) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::InsertItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::InsertItemAt(const PRUint32 aCount, const nsString & aMenuItemName) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::InsertSeparator(const PRUint32 aCount) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::RemoveItem(const PRUint32 aCount) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::RemoveAll() +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::ShowMenu(PRInt32 aX, PRInt32 aY) +{ +printf("nsPopUpMenu::ShowMenu - FIXME: not implemented\n"); +#if 0 + if (nsnull != mParent) { + HWND pWnd = (HWND)mParent->GetNativeData(NS_NATIVE_WIDGET); + if (nsnull != pWnd) { + nsRect rect; + POINT point; + mParent->GetBounds(rect); + point.x = 0; + point.y = 0; + ClientToScreen (pWnd, &point) ; + point.x += aX; + point.y += aY; + BOOL status = TrackPopupMenu(mMenu, TPM_LEFTALIGN | TPM_TOPALIGN, point.x, point.y, 0, pWnd, NULL); + } + } +#endif + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetNativeData(void *& aData) +{ + aData = (void *)((BMenu *)mMenu); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetParent(nsIWidget *& aParent) +{ + aParent = mParent; + return NS_OK; +} diff --git a/widget/src/beos/nsPopUpMenu.h b/widget/src/beos/nsPopUpMenu.h new file mode 100644 index 000000000000..c4535dd544d5 --- /dev/null +++ b/widget/src/beos/nsPopUpMenu.h @@ -0,0 +1,69 @@ +/* -*- 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 nsPopUpMenu_h__ +#define nsPopUpMenu_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsIPopUpMenu.h" + +#include + +/** + * Native Win32 button wrapper + */ + +class nsPopUpMenu : public nsIPopUpMenu +{ + +public: + nsPopUpMenu(); + virtual ~nsPopUpMenu(); + + NS_DECL_ISUPPORTS + + NS_IMETHOD Create(nsIWidget * aParent); + + // nsIPopUpMenu Methods + NS_IMETHOD AddItem(const nsString &aText); + NS_IMETHOD AddItem(nsIMenuItem * aMenuItem); + NS_IMETHOD AddMenu(nsIMenu * aMenu); + NS_IMETHOD AddSeparator(); + NS_IMETHOD GetItemCount(PRUint32 &aCount); + NS_IMETHOD GetItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem); + NS_IMETHOD InsertItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem); + NS_IMETHOD InsertItemAt(const PRUint32 aCount, const nsString & aMenuItemName); + NS_IMETHOD InsertSeparator(const PRUint32 aCount); + NS_IMETHOD RemoveItem(const PRUint32 aCount); + NS_IMETHOD RemoveAll(); + NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY); + NS_IMETHOD GetNativeData(void*& aData); + NS_IMETHOD GetParent(nsIWidget*& aParent); + +protected: + + PRUint32 mNumMenuItems; + + nsIWidget * mParent; + BPopUpMenu *mMenu; +}; + +#endif // nsPopUpMenu_h__ diff --git a/widget/src/beos/nsRadioButton.cpp b/widget/src/beos/nsRadioButton.cpp new file mode 100644 index 000000000000..4aa396c7693b --- /dev/null +++ b/widget/src/beos/nsRadioButton.cpp @@ -0,0 +1,244 @@ +/* -*- 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 "nsRadioButton.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsStringUtil.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" + +NS_IMPL_ADDREF(nsRadioButton) +NS_IMPL_RELEASE(nsRadioButton) + +//------------------------------------------------------------------------- +// +// nsRadioButton constructor +// +//------------------------------------------------------------------------- +nsRadioButton::nsRadioButton() : nsWindow(), nsIRadioButton() +{ + NS_INIT_REFCNT(); +} + + +//------------------------------------------------------------------------- +// +// nsRadioButton destructor +// +//------------------------------------------------------------------------- +nsRadioButton::~nsRadioButton() +{ +} + + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsRadioButton::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kIRadioButtonIID)) { + *aInstancePtr = (void*) ((nsIRadioButton*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + return result; + } + +//------------------------------------------------------------------------- +// +// Sets the state of the nsRadioButton +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::SetState(const PRBool aState) +{ + fState = aState; + if(mRadioButton && mRadioButton->LockLooper()) + { + mRadioButton->SetValue(aState ? 1 : 0); + mRadioButton->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::GetState(PRBool& aState) +{ + aState = fState; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::SetLabel(const nsString& aText) +{ + char label[256]; + aText.ToCString(label, 256); + label[255] = '\0'; + if(mRadioButton && mRadioButton->LockLooper()) + { + mRadioButton->SetLabel(label); + mRadioButton->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::GetLabel(nsString& aBuffer) +{ + if(mRadioButton && mRadioButton->LockLooper()) + { + aBuffer.SetLength(0); + aBuffer.Append(mRadioButton->Label()); + mRadioButton->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsRadioButton::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsRadioButton::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsRadioButton::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +/** + * Renders the RadioButton for Printing + * + **/ +NS_METHOD nsRadioButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + float appUnits; + float scale; + nsIDeviceContext * context; + aRenderingContext.GetDeviceContext(context); + + context->GetCanonicalPixelScale(scale); + context->GetDevUnitsToAppUnits(appUnits); + nsRect rect; + GetBounds(rect); + + rect.x++; + rect.y++; + rect.width -= 2; + rect.height -= 2; + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscoord one = nscoord(PRFloat64(rect.width) * 1.0/12.0); + + rect.x = nscoord((PRFloat64)rect.x * appUnits); + rect.y = nscoord((PRFloat64)rect.y * appUnits); + rect.width = nscoord((PRFloat64)rect.width * appUnits); + rect.height = nscoord((PRFloat64)rect.height * appUnits); + rect.x += one; + rect.width = nscoord(PRFloat64(rect.width) * 11.0/12.0); + rect.height = nscoord(PRFloat64(rect.height) * 11.0/12.0); + + for (nscoord i=0;i + +/** + * Native Win32 Radio button wrapper + */ + +class nsRadioButton : public nsWindow, + public nsIRadioButton +{ + +public: + nsRadioButton(); + virtual ~nsRadioButton(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIRadioButton part + NS_IMETHOD SetLabel(const nsString& aText); + NS_IMETHOD GetLabel(nsString& aBuffer); + NS_IMETHOD SetState(const PRBool aState); + NS_IMETHOD GetState(PRBool& aState); + + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + + +protected: + PRBool fState; + virtual BView *CreateBeOSView(); + BRadioButton *mRadioButton; +}; + +// +// A BRadioButton subclass +// +class nsRadioButtonBeOS : public BRadioButton, public nsIWidgetStore { + public: + nsRadioButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + const char *aLabel, BMessage *aMessage, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, + uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE ); +}; + +#endif // nsRadioButton_h__ diff --git a/widget/src/beos/nsScrollbar.cpp b/widget/src/beos/nsScrollbar.cpp new file mode 100644 index 000000000000..d0ce025ef680 --- /dev/null +++ b/widget/src/beos/nsScrollbar.cpp @@ -0,0 +1,341 @@ +/* -*- 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 "nsScrollbar.h" +#include "nsToolkit.h" +#include "nsGUIEvent.h" +#include "nsUnitConversion.h" + + +NS_IMPL_ADDREF(nsScrollbar) +NS_IMPL_RELEASE(nsScrollbar) + +//------------------------------------------------------------------------- +// +// nsScrollbar constructor +// +//------------------------------------------------------------------------- +nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWindow(), nsIScrollbar() +{ + NS_INIT_REFCNT(); + mOrientation = (aIsVertical) ? B_VERTICAL : B_HORIZONTAL; + mLineIncrement = 0; + thumb = 0; +} + + +//------------------------------------------------------------------------- +// +// nsScrollbar destructor +// +//------------------------------------------------------------------------- +nsScrollbar::~nsScrollbar() +{ +} + + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsScrollbarIID, NS_ISCROLLBAR_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsScrollbarIID)) { + *aInstancePtr = (void*) ((nsIScrollbar*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// Define the range settings +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange) +{ + float min, max; + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->GetRange(&min, &max); + mScrollbar->SetRange(min, float(aEndRange - thumb)); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Return the range settings +// +//------------------------------------------------------------------------- +PRUint32 nsScrollbar::GetMaxRange(PRUint32& aRange) +{ + float startRange, endRange; + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->GetRange(&startRange, &endRange); + aRange = endRange + thumb; + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the thumb position +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos) +{ + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->SetValue(aPos); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the current thumb position. +// +//------------------------------------------------------------------------- +PRUint32 nsScrollbar::GetPosition(PRUint32& aPosition) +{ + if(mScrollbar && mScrollbar->LockLooper()) + { + aPosition = mScrollbar->Value(); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the thumb size +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize) +{ + float min, max, smallStep, bigStep; + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->GetRange(&min, &max); + max = max + thumb - aSize; +// thumb = aSize; + mScrollbar->SetRange(min, max); + mScrollbar->SetProportion(max == min ? 1 : (aSize / (max > min ? max - min : min - max))); + mScrollbar->GetSteps(&smallStep, &bigStep); + mScrollbar->SetSteps(smallStep, aSize); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the thumb size +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetThumbSize(PRUint32& aSize) +{ + aSize = thumb; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the line increment for this scrollbar +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aSize) +{ + float smallStep, bigStep; + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->GetSteps(&smallStep, &bigStep); + mScrollbar->SetSteps(aSize, bigStep); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get the line increment for this scrollbar +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetLineIncrement(PRUint32& aSize) +{ + float smallStep, bigStep; + aSize = 0; + if(mScrollbar && mScrollbar->LockLooper()) + { + mScrollbar->GetSteps(&smallStep, &bigStep); + aSize = uint32(smallStep); + mScrollbar->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set all scrolling parameters +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, + PRUint32 aPosition, PRUint32 aLineIncrement) +{ + SetMaxRange(aMaxRange); + SetThumbSize(aThumbSize); + SetPosition(aPosition); + SetLineIncrement(aLineIncrement); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsScrollbar::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + + +PRBool nsScrollbar::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + + +//------------------------------------------------------------------------- +// +// Deal with scrollbar messages (actually implemented only in nsScrollbar) +// +//------------------------------------------------------------------------- +PRBool nsScrollbar::OnScroll() +{ + PRBool result = PR_TRUE; + int32 newpos; + if(mEventCallback) + { + if(mScrollbar->LockLooper()) + { + if(mScrollbar->GetPosition(newpos)) + { + nsScrollbarEvent event; + InitEvent(event, NS_SCROLLBAR_POS); + event.widget = (nsWindow *)this; + event.position = newpos; + result = ConvertStatus((*mEventCallback)(&event)); + +// if(newpos != event.position) +// SetPosition(newpos = event.position); + } + mScrollbar->UnlockLooper(); + } + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsScrollbar::GetBounds(nsRect &aRect) +{ + return nsWindow::GetBounds(aRect); +} + +BView *nsScrollbar::CreateBeOSView() +{ + BRect temp; + + // work around stupit BeOS bug + if(mOrientation == B_VERTICAL) + temp.Set(0, 0, B_V_SCROLL_BAR_WIDTH, B_H_SCROLL_BAR_HEIGHT * 2); + else + temp.Set(0, 0, B_V_SCROLL_BAR_WIDTH * 2, B_H_SCROLL_BAR_HEIGHT); + + mScrollbar = new nsScrollbarBeOS(this, temp, "", NULL, 0, 0, mOrientation); + + return mScrollbar; +} + +//------------------------------------------------------------------------- +// Sub-class of BeOS Scrollbar +//------------------------------------------------------------------------- +nsScrollbarBeOS::nsScrollbarBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, BView *aTarget, float aMin, float aMax, + orientation aOrientation ) + : BScrollBar( aFrame, aName, aTarget, aMin, aMax, aOrientation ), + nsIWidgetStore( aWidgetWindow ), first(true), sbposchanged(false) +{ +} + +void nsScrollbarBeOS::ValueChanged(float newValue) +{ + if(first) + { + first = false; + return; + } + + sbpos = newValue; + sbposchanged = true; + + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONSCROLL); + t->CallMethodAsync(info); + NS_RELEASE(t); + } +} + +bool nsScrollbarBeOS::GetPosition(int32 &p) +{ + if(! sbposchanged) + return false; + p = (int32)sbpos; + sbposchanged = false; + return true; +} diff --git a/widget/src/beos/nsScrollbar.h b/widget/src/beos/nsScrollbar.h new file mode 100644 index 000000000000..56ca6abe6626 --- /dev/null +++ b/widget/src/beos/nsScrollbar.h @@ -0,0 +1,88 @@ +/* -*- 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 nsScrollbar_h__ +#define nsScrollbar_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsIScrollbar.h" + +#include + +class nsScrollbarBeOS; + +/** + * Native WIN32 scrollbar wrapper. + */ + +class nsScrollbar : public nsWindow, + public nsIScrollbar +{ + +public: + nsScrollbar(PRBool aIsVertical); + virtual ~nsScrollbar(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIScrollBar implementation + NS_IMETHOD SetMaxRange(PRUint32 aEndRange); + NS_IMETHOD GetMaxRange(PRUint32& aMaxRange); + NS_IMETHOD SetPosition(PRUint32 aPos); + NS_IMETHOD GetPosition(PRUint32& aPos); + NS_IMETHOD SetThumbSize(PRUint32 aSize); + NS_IMETHOD GetThumbSize(PRUint32& aSize); + NS_IMETHOD SetLineIncrement(PRUint32 aSize); + NS_IMETHOD GetLineIncrement(PRUint32& aSize); + NS_IMETHOD SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize, + PRUint32 aPosition, PRUint32 aLineIncrement); + + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnScroll(); + virtual PRBool OnResize(nsRect &aWindowRect); + NS_IMETHOD GetBounds(nsRect &aRect); + +protected: + nsScrollbarBeOS *mScrollbar; + BView *CreateBeOSView(); + int mLineIncrement; + float mScaleFactor; + int32 thumb; + orientation mOrientation; +}; + +class nsScrollbarBeOS : public BScrollBar, public nsIWidgetStore +{ + bool first; + float sbpos; + bool sbposchanged; + + public: + nsScrollbarBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + BView *aTarget, float aMin, float aMax, orientation aOrientation ); + void ValueChanged(float newValue); + bool nsScrollbarBeOS::GetPosition(int32 &p); +}; + +#endif // nsButton_h__ diff --git a/widget/src/beos/nsSound.cpp b/widget/src/beos/nsSound.cpp new file mode 100644 index 000000000000..936c12bfdde5 --- /dev/null +++ b/widget/src/beos/nsSound.cpp @@ -0,0 +1,84 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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 "nscore.h" +#include "nsISound.h" +#include "nsIAllocator.h" +#include "plstr.h" +#include "stdio.h" + +#include + +class SoundImpl : public nsISound +{ +public: + SoundImpl(); + virtual ~SoundImpl(); + + // nsISupports interface + NS_DECL_ISUPPORTS + + // nsISound interface + + NS_IMETHOD Beep(); + +}; + +//////////////////////////////////////////////////////////////////////// + +nsresult +NS_NewSound(nsISound** aSound) +{ + NS_PRECONDITION(aSound != nsnull, "null ptr"); + if (! aSound) + return NS_ERROR_NULL_POINTER; + + *aSound = new SoundImpl(); + if (! *aSound) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aSound); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////// + + +SoundImpl::SoundImpl() +{ + NS_INIT_REFCNT(); +} + + +SoundImpl::~SoundImpl() +{ +} + + + +NS_IMPL_ISUPPORTS(SoundImpl, nsISound::GetIID()); + + +NS_IMETHODIMP +SoundImpl::Beep() +{ + beep(); + + return NS_OK; +} diff --git a/widget/src/beos/nsStringUtil.h b/widget/src/beos/nsStringUtil.h new file mode 100644 index 000000000000..4925500ba780 --- /dev/null +++ b/widget/src/beos/nsStringUtil.h @@ -0,0 +1,79 @@ +/* -*- 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. + */ + +// Convience macros for converting nsString's to chars + +// creating temporary char[] bufs. + +#ifndef NS_STR_UTIL_H +#define NS_STR_UTIL_H + +// nsString to temporary char[] macro + +// Convience MACROS to convert an nsString to a char * which use a +// static char array if possible to reduce memory fragmentation, +// otherwise they allocate a char[] which must be freed. +// REMEMBER to always use the NS_FREE_STR_BUF after using the +// NS_ALLOC_STR_BUF. You can not nest NS_ALLOC_STR_BUF's. + +#define NS_ALLOC_STR_BUF(varName, strName, tempSize) \ + static const int _ns_kSmallBufferSize = tempSize; \ + char* varName = 0; \ + int _ns_smallBufUsed = 0; \ + char _ns_smallBuffer[_ns_kSmallBufferSize]; \ + if (strName.Length() < (_ns_kSmallBufferSize - 1)) { \ + strName.ToCString(_ns_smallBuffer, _ns_kSmallBufferSize); \ + _ns_smallBuffer[_ns_kSmallBufferSize - 1] = '\0'; \ + _ns_smallBufUsed = 1; \ + varName = _ns_smallBuffer; \ + } \ + else { \ + varName = strName.ToNewCString(); \ + } + +#define NS_FREE_STR_BUF(varName) \ + if (! _ns_smallBufUsed) \ + delete varName; + +// Create temporary char[] macro +// +// Create a temporary buffer for storing chars. +// If the actual size is > size then the buffer +// is allocated from the heap, otherwise the buffer +// is a stack variable. REMEMBER: use NS_FREE_BUF +// when finished with the buffer allocated, and do +// NOT nest INSERT_BUF'S. + +#define NS_ALLOC_CHAR_BUF(aBuf, aSize, aActualSize) \ + char *aBuf; \ + int _ns_smallBufUsed = 0; \ + static const int _ns_kSmallBufferSize = aSize; \ + if (aActualSize < _ns_kSmallBufferSize) { \ + char _ns_smallBuffer[_ns_kSmallBufferSize]; \ + aBuf = _ns_smallBuffer; \ + _ns_smallBufUsed = 1; \ + } \ + else { \ + aBuf = new char[aActualSize]; \ + } + +#define NS_FREE_CHAR_BUF(aBuf) \ +if (! _ns_smallBufUsed) \ + delete aBuf; + + +#endif // NSStringUtil \ No newline at end of file diff --git a/widget/src/beos/nsSwitchToUIThread.h b/widget/src/beos/nsSwitchToUIThread.h new file mode 100644 index 000000000000..dfdb8e17cfe2 --- /dev/null +++ b/widget/src/beos/nsSwitchToUIThread.h @@ -0,0 +1,70 @@ +/* -*- 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 SWITCHTOUITHREAD_H +#define SWITCHTOUITHREAD_H + +#include "nsISupports.h" + +// foreward declaration +struct MethodInfo; + +/** + * Switch thread to match the thread the widget was created in so messages will be dispatched. + */ + +class nsSwitchToUIThread { + +public: + virtual bool CallMethod(MethodInfo *info) = 0; + +}; + +// +// Structure used for passing the information necessary for synchronously +// invoking a method on the GUI thread... +// +struct MethodInfo { + nsISupports *widget; + nsSwitchToUIThread *target; + uint32 methodId; + int nArgs; + uint32 *args; + + MethodInfo(nsISupports *ref, nsSwitchToUIThread *obj, uint32 id, int numArgs = 0, uint32 *arguments = 0) + { + widget = ref; + NS_ADDREF(ref); + target = obj; + methodId = id; + nArgs = numArgs; + args = new uint32 [numArgs]; + memcpy(args, arguments, sizeof(uint32) * numArgs); + } + + ~MethodInfo() + { + delete [] args; + NS_RELEASE(widget); + } + + bool Invoke() { return target->CallMethod(this); } +}; + +#endif // TOUITHRD_H + diff --git a/widget/src/beos/nsTabWidget.cpp b/widget/src/beos/nsTabWidget.cpp new file mode 100644 index 000000000000..3bd02abc4088 --- /dev/null +++ b/widget/src/beos/nsTabWidget.cpp @@ -0,0 +1,134 @@ +/* -*- 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 "nsTabWidget.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + + +NS_IMPL_ADDREF(nsTabWidget) +NS_IMPL_RELEASE(nsTabWidget) + +//------------------------------------------------------------------------- +// +// nsTabWidget constructor +// +//------------------------------------------------------------------------- +nsTabWidget::nsTabWidget() : nsWindow() +{ + NS_INIT_REFCNT(); + // Ensure that common controls dll is loaded +#if 0 + InitCommonControls(); +#endif +} + +//------------------------------------------------------------------------- +// +// nsTabWidget destructor +// +//------------------------------------------------------------------------- +nsTabWidget::~nsTabWidget() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTabWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsTabWidgetIID, NS_ITABWIDGET_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsTabWidgetIID)) { + *aInstancePtr = (void*) ((nsITabWidget*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// Set the tab labels +// +//------------------------------------------------------------------------- + +NS_METHOD nsTabWidget::SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[]) +{ +#if 0 + TC_ITEM tie; + char labelTemp[256]; + + for (PRUint32 i = 0; i < aNumberOfTabs; i++) { + tie.mask = TCIF_TEXT; + aTabLabels[i].ToCString(labelTemp, 256); + tie.pszText = labelTemp; + TabCtrl_InsertItem(mWnd, i, &tie); + } +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get the currently selected tab +// +//------------------------------------------------------------------------- + + +PRUint32 nsTabWidget::GetSelectedTab(PRUint32& aTabNumber) +{ +#if 0 + aTabNumber = TabCtrl_GetCurSel(mWnd); +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsTabWidget::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsTabWidget::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsTabWidget::GetBounds(nsRect &aRect) +{ + return nsWindow::GetBounds(aRect); +} + diff --git a/widget/src/beos/nsTabWidget.h b/widget/src/beos/nsTabWidget.h new file mode 100644 index 000000000000..f7432d3fb1ab --- /dev/null +++ b/widget/src/beos/nsTabWidget.h @@ -0,0 +1,55 @@ +/* -*- 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 nsTabWidget_h__ +#define nsTabWidget_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsITabWidget.h" + +/** + * Native Win32 tab control wrapper + */ + +class nsTabWidget : public nsWindow, + public nsITabWidget +{ + +public: + nsTabWidget(); + virtual ~nsTabWidget(); + + // nsISupports + NS_IMETHOD_(nsrefcnt) Release(void); + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + + // nsITabWidget part + NS_IMETHOD SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[]); + NS_IMETHOD GetSelectedTab(PRUint32& aTabNumber); + + // nsIWidget overrides + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + NS_IMETHOD GetBounds(nsRect &aRect); +}; + +#endif // nsTabWidget_h__ diff --git a/widget/src/beos/nsTextAreaWidget.cpp b/widget/src/beos/nsTextAreaWidget.cpp new file mode 100644 index 000000000000..860bf5b68db7 --- /dev/null +++ b/widget/src/beos/nsTextAreaWidget.cpp @@ -0,0 +1,244 @@ +/* -*- 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 "nsTextAreaWidget.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); + + + +/*NS_IMPL_ADDREF(nsTextAreaWidget) +//NS_IMPL_RELEASE(nsTextAreaWidget) +nsrefcnt nsTextAreaWidget::Release(void) +{ +// NS_PRECONDITION(0 != cnt, "dup release"); + if (--mRefCnt == 0) { + delete this; + return 0; + } + return mRefCnt; +}*/ + +NS_IMPL_ADDREF(nsTextAreaWidget) +NS_IMPL_RELEASE(nsTextAreaWidget) + +//------------------------------------------------------------------------- +// +// nsTextAreaWidget constructor +// +//------------------------------------------------------------------------- +nsTextAreaWidget::nsTextAreaWidget() +{ + NS_INIT_REFCNT(); + nsTextHelper::mBackground = NS_RGB(124, 124, 124); +} + +//------------------------------------------------------------------------- +// +// nsTextAreaWidget destructor +// +//------------------------------------------------------------------------- +nsTextAreaWidget::~nsTextAreaWidget() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID); + static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); + + + if (aIID.Equals(kITextAreaWidgetIID)) { + nsITextAreaWidget* textArea = this; + *aInstancePtr = (void*) (textArea); + NS_ADDREF_THIS(); + return NS_OK; + } + else if (aIID.Equals(kIWidgetIID)) + { + nsIWidget* widget = this; + *aInstancePtr = (void*) (widget); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWindow::QueryInterface(aIID, aInstancePtr); +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsTextAreaWidget::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsTextAreaWidget::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsTextAreaWidget::GetBounds(nsRect &aRect) +{ +#if 0 + nsWindow::GetNonClientBounds(aRect); +#endif +printf("nsTextAreaWidget::GetBounds not wrong\n"); // the following is just a placeholder + nsWindow::GetClientBounds(aRect); + return NS_OK; +} + + +/** + * Renders the TextWidget for Printing + * + **/ +NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + nsRect rect; + float appUnits; + float scale; + nsIDeviceContext * context; + aRenderingContext.GetDeviceContext(context); + + context->GetCanonicalPixelScale(scale); + context->GetDevUnitsToAppUnits(appUnits); + + GetBoundsAppUnits(rect, appUnits); + + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscolor bgColor = NS_RGB(255,255,255); + nscolor fgColor = NS_RGB(0,0,0); + nscolor hltColor = NS_RGB(240,240,240); + nscolor sdwColor = NS_RGB(128,128,128); + nscolor txtBGColor = NS_RGB(255,255,255); + nscolor txtFGColor = NS_RGB(0,0,0); + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor); + } + + aRenderingContext.SetColor(txtBGColor); + aRenderingContext.FillRect(rect); + + // Paint Black border + //nsBaseWidget::Paint(aRenderingContext, aDirtyRect); + + nscoord onePixel = nscoord(scale); + nscoord twoPixels = nscoord(scale*2); + + rect.x += onePixel; + rect.y += onePixel; + rect.width -= twoPixels+onePixel; + rect.height -= twoPixels+onePixel; + + nscoord right = rect.x+rect.width; + nscoord bottom = rect.y+rect.height; + + + // Draw Left & Top + aRenderingContext.SetColor(NS_RGB(128,128,128)); + DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top + DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left + + //DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1 + //DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1 + + // Draw Right & Bottom + aRenderingContext.SetColor(NS_RGB(192,192,192)); + DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right + DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom + + //DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1 + //DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1 + + + aRenderingContext.SetFont(*mFont); + + nscoord textWidth; + nscoord textHeight; + aRenderingContext.GetWidth(mText, textWidth); + + nsIFontMetrics* metrics; + context->GetMetricsFor(*mFont, metrics); + metrics->GetMaxAscent(textHeight); + + nscoord x = (twoPixels * 2) + rect.x; + nscoord y = ((rect.height - textHeight) / 2) + rect.y; + aRenderingContext.SetColor(txtFGColor); + aRenderingContext.DrawString(mText, x, y); + + NS_RELEASE(context); + + return NS_OK; +} + +BView *nsTextAreaWidget::CreateBeOSView() +{ + mTextView = new nsTextAreaBeOS(this, BRect(0, 0, 0, 0), B_EMPTY_STRING, BRect(0, 0, 0, 0), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW); + return new TextFrameBeOS(mTextView, BRect(0, 0, 0, 0), B_EMPTY_STRING, 0, 0); +} + +//---------------------------------------------------- +// BeOS Sub-Class TextView +//---------------------------------------------------- + +nsTextAreaBeOS::nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame, + const char *aName, BRect aTextRect, uint32 aResizingMode, + uint32 aFlags ) + : BTextView( aFrame, aName, aTextRect, aResizingMode, aFlags ), + nsIWidgetStore( aWidgetWindow ) +{ +} diff --git a/widget/src/beos/nsTextAreaWidget.h b/widget/src/beos/nsTextAreaWidget.h new file mode 100644 index 000000000000..c73e4a3f5ff3 --- /dev/null +++ b/widget/src/beos/nsTextAreaWidget.h @@ -0,0 +1,67 @@ +/* -*- 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 nsTextAreaWidget_h__ +#define nsTextAreaWidget_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" +#include "nsTextHelper.h" + +#include "nsITextAreaWidget.h" + +#include + +/** + * Native WIN32 multi-line edit control wrapper. + */ + +class nsTextAreaWidget : public nsTextHelper +{ + +public: + nsTextAreaWidget(); + virtual ~nsTextAreaWidget(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + // nsIWidget Overrides + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + NS_IMETHOD GetBounds(nsRect &aRect); + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); +protected: + BView *CreateBeOSView(); +}; + +// +// A BTextView subclass +// +class nsTextAreaBeOS : public BTextView, public nsIWidgetStore { + public: + nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + BRect aTextRect, uint32 aResizingMode, uint32 aFlags ); +}; + +#endif // nsTextAreaWidget_h__ diff --git a/widget/src/beos/nsTextHelper.cpp b/widget/src/beos/nsTextHelper.cpp new file mode 100644 index 000000000000..1fd35fd4d790 --- /dev/null +++ b/widget/src/beos/nsTextHelper.cpp @@ -0,0 +1,226 @@ +/* -*- 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 "nsTextHelper.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + + +NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData; + mIsPassword = data->mIsPassword; + mIsReadOnly = data->mIsReadOnly; + } + return NS_OK; +} + +NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars) +{ + if(mTextView && mTextView->LockLooper()) + { + mTextView->SetMaxBytes(aChars); + mTextView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize) +{ + if(mTextView && mTextView->LockLooper()) + { + aTextBuffer.SetLength(0); + aTextBuffer.Append(mTextView->Text()); + aActualSize = strlen(mTextView->Text()); + mTextView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize) +{ + mText = aText; + + const char *text; + text = aText.ToNewCString(); + if(mTextView && mTextView->LockLooper()) + { + mTextView->SetText(text); + mTextView->UnlockLooper(); + } + delete [] text; + + aActualSize = aText.Length(); + return NS_OK; +} + +NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize) +{ + const char *text; + text = aText.ToNewCString(); + if(mTextView) + { + if(mTextView->LockLooper()) + { + mTextView->Insert(aStartPos, text, aActualSize); + mTextView->UnlockLooper(); + } + else + mTextView->Insert(aStartPos, text, aActualSize); + } + delete [] text; + mText.Insert(aText, aStartPos, aText.Length()); + return NS_OK; +} + +NS_METHOD nsTextHelper::RemoveText() +{ + if(mTextView && mTextView->LockLooper()) + { + mTextView->Delete(0, mTextView->TextLength() - 1); + mTextView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword) +{ + mIsPassword = aIsPassword; +if(mIsPassword) printf("nsTextHelper::SetPassword not implemented\n"); + return NS_OK; +} + +NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag) +{ + aOldFlag = mIsReadOnly; + mIsReadOnly = aReadOnlyFlag; + + // Update the widget + if(mTextView && mTextView->LockLooper()) + { + mTextView->MakeEditable(false); + mTextView->UnlockLooper(); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SelectAll() +{ + if(mTextView && mTextView->LockLooper()) + { + mTextView->SelectAll(); + mTextView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel) +{ + if(mTextView && mTextView->LockLooper()) + { + mTextView->Select(aStartSel, aEndSel); + mTextView->UnlockLooper(); + } + return NS_OK; +} + + +NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel) +{ + if(mTextView && mTextView->LockLooper()) + { + mTextView->GetSelection((int32 *)aStartSel, (int32 *)aEndSel); + mTextView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition) +{ + SetSelection(aPosition, aPosition); + return NS_OK; +} + +NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos) +{ + PRUint32 start; + PRUint32 end; + GetSelection(&start, &end); + if (start == end) { + aPos = start; + } + else { + aPos = PRUint32(-1);/* XXX is this right??? scary cast! */ + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsTextHelper constructor +// +//------------------------------------------------------------------------- + +nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget() +{ + mIsReadOnly = PR_FALSE; + mIsPassword = PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// nsTextHelper destructor +// +//------------------------------------------------------------------------- +nsTextHelper::~nsTextHelper() +{ +} + +//------------------------------------------------------------------------- +// +// Clear window before paint +// +//------------------------------------------------------------------------- + +PRBool nsTextHelper::AutoErase() +{ + return(PR_TRUE); +} + + +TextFrameBeOS::TextFrameBeOS(BTextView *child, BRect frame, const char *name, uint32 resizingmode, uint32 flags) + : BView(frame, name, resizingmode, flags | B_FRAME_EVENTS), tv(child) +{ + SetViewColor(0, 0, 0); + AddChild(tv); +} + +void TextFrameBeOS::FrameResized(float width, float height) +{ + tv->MoveTo(1, 1); + tv->ResizeTo(width - 2, height - 2); + BRect r = Bounds(); + r.InsetBy(1, 1); + tv->SetTextRect(r); + BView::FrameResized(width, height); +} diff --git a/widget/src/beos/nsTextHelper.h b/widget/src/beos/nsTextHelper.h new file mode 100644 index 000000000000..6bac01d2772b --- /dev/null +++ b/widget/src/beos/nsTextHelper.h @@ -0,0 +1,73 @@ +/* -*- 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 nsTextHelper_h__ +#define nsTextHelper_h__ + +#include "nsdefs.h" +#include "nsITextWidget.h" +#include "nsITextAreaWidget.h" +#include "nsWindow.h" + +#include + +/** + * Base class for nsTextAreaWidget and nsTextWidget + */ + +class nsTextHelper : public nsWindow, + public nsITextAreaWidget, + public nsITextWidget +{ + +public: + nsTextHelper(); + virtual ~nsTextHelper(); + + NS_IMETHOD SelectAll(); + NS_IMETHOD SetMaxTextLength(PRUint32 aChars); + NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize); + NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize); + NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize); + NS_IMETHOD RemoveText(); + NS_IMETHOD SetPassword(PRBool aIsPassword); + NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag); + NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel); + NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel); + NS_IMETHOD SetCaretPosition(PRUint32 aPosition); + NS_IMETHOD GetCaretPosition(PRUint32& aPosition); + + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + + virtual PRBool AutoErase(); + +protected: + nsString mText; + PRBool mIsPassword; + PRBool mIsReadOnly; + BTextView *mTextView; +}; + +class TextFrameBeOS : public BView +{ + BTextView *tv; +public: + TextFrameBeOS(BTextView *child, BRect frame, const char *name, uint32 resizingmode, uint32 flags); + void FrameResized(float width, float height); +}; + +#endif // nsTextHelper_h__ diff --git a/widget/src/beos/nsTextWidget.cpp b/widget/src/beos/nsTextWidget.cpp new file mode 100644 index 000000000000..b4f0e131135b --- /dev/null +++ b/widget/src/beos/nsTextWidget.cpp @@ -0,0 +1,289 @@ +/* -*- 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 "nsTextWidget.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); + + +NS_IMPL_ADDREF(nsTextWidget) +NS_IMPL_RELEASE(nsTextWidget) + + +//------------------------------------------------------------------------- +// +// nsTextWidget constructor +// +//------------------------------------------------------------------------- +nsTextWidget::nsTextWidget() : nsTextHelper() +{ + NS_INIT_REFCNT(); + mBackground = NS_RGB(124, 124, 124); +} + +//------------------------------------------------------------------------- +// +// nsTextWidget destructor +// +//------------------------------------------------------------------------- +nsTextWidget::~nsTextWidget() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsTextWidgetIID, NS_ITEXTWIDGET_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsTextWidgetIID)) { + *aInstancePtr = (void*) ((nsITextWidget*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsTextWidget::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsTextWidget::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + + +PRBool nsTextWidget::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsTextWidget::GetBounds(nsRect &aRect) +{ +#if 0 + nsWindow::GetNonClientBounds(aRect); +#endif +printf("nsTextWidget::GetBounds not wrong\n"); // the following is just a placeholder + nsWindow::GetClientBounds(aRect); + return NS_OK; +} + +/** + * Renders the TextWidget for Printing + * + **/ +NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + nsRect rect; + float appUnits; + float scale; + nsIDeviceContext * context; + aRenderingContext.GetDeviceContext(context); + + context->GetCanonicalPixelScale(scale); + context->GetDevUnitsToAppUnits(appUnits); + + GetBoundsAppUnits(rect, appUnits); + + aRenderingContext.SetColor(NS_RGB(0,0,0)); + + nscolor bgColor = NS_RGB(255,255,255); + nscolor fgColor = NS_RGB(0,0,0); + nscolor hltColor = NS_RGB(240,240,240); + nscolor sdwColor = NS_RGB(128,128,128); + nscolor txtBGColor = NS_RGB(255,255,255); + nscolor txtFGColor = NS_RGB(0,0,0); + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor); + lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor); + } + + aRenderingContext.SetColor(txtBGColor); + aRenderingContext.FillRect(rect); + + // Paint Black border + //nsBaseWidget::Paint(aRenderingContext, aDirtyRect); + + nscoord onePixel = nscoord(scale); + nscoord twoPixels = nscoord(scale*2); + + rect.x += onePixel; + rect.y += onePixel; + rect.width -= twoPixels+onePixel; + rect.height -= twoPixels+onePixel; + + nscoord right = rect.x+rect.width; + nscoord bottom = rect.y+rect.height; + + + // Draw Left & Top + aRenderingContext.SetColor(NS_RGB(128,128,128)); + DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top + DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left + + //DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1 + //DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1 + + // Draw Right & Bottom + aRenderingContext.SetColor(NS_RGB(192,192,192)); + DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right + DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom + + //DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1 + //DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1 + + + aRenderingContext.SetFont(*mFont); + + nscoord textWidth; + nscoord textHeight; + aRenderingContext.GetWidth(mText, textWidth); + + nsIFontMetrics* metrics; + context->GetMetricsFor(*mFont, metrics); + metrics->GetMaxAscent(textHeight); + + nscoord x = (twoPixels * 2) + rect.x; + nscoord y = ((rect.height - textHeight) / 2) + rect.y; + aRenderingContext.SetColor(txtFGColor); + if (!mIsPassword) { + aRenderingContext.DrawString(mText, x, y); + } else { + nsString astricks; + PRInt32 i; + for (i=0;iGetToolkit()) != 0) + { + uint32 bytebuf = 0; + uint8 *byteptr = (uint8 *)&bytebuf; + for(int32 i = 0; i < numBytes; i++) + byteptr[i] = bytes[i]; + + uint32 args[4]; + args[0] = NS_KEY_DOWN; + args[1] = bytebuf; + args[2] = numBytes; + args[3] = modifiers(); + + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args); + t->CallMethodAsync(info); + } +} + +void nsTextViewBeOS::KeyUp(const char *bytes, int32 numBytes) +{ + // call back if not enter/return + if(numBytes != 1 || (bytes[0] != 10 && bytes[0] != 13)) + BTextView::KeyUp(bytes, numBytes); + + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 bytebuf = 0; + uint8 *byteptr = (uint8 *)&bytebuf; + for(int32 i = 0; i < numBytes; i++) + byteptr[i] = bytes[i]; + + uint32 args[4]; + args[0] = NS_KEY_UP; + args[1] = (int32)bytebuf; + args[2] = numBytes; + args[3] = modifiers(); + + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args); + t->CallMethodAsync(info); + } +} diff --git a/widget/src/beos/nsTextWidget.h b/widget/src/beos/nsTextWidget.h new file mode 100644 index 000000000000..ba4b1568a7db --- /dev/null +++ b/widget/src/beos/nsTextWidget.h @@ -0,0 +1,70 @@ +/* -*- 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 nsTextWidget_h__ +#define nsTextWidget_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" +#include "nsTextHelper.h" + +#include "nsITextWidget.h" + +#include + +/** + * Native WIN32 single line edit control wrapper. + */ + +class nsTextWidget : public nsTextHelper +{ + +public: + nsTextWidget(); + virtual ~nsTextWidget(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnResize(nsRect &aWindowRect); + NS_IMETHOD GetBounds(nsRect &aRect); + + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); +protected: + BView *CreateBeOSView(); +}; + +// +// A BTextView subclass +// +class nsTextViewBeOS : public BTextView, public nsIWidgetStore +{ + public: + nsTextViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + BRect aTextRect, uint32 aResizingMode, uint32 aFlags ); + void KeyDown(const char *bytes, int32 numbytes); + void KeyUp(const char *bytes, int32 numbytes); +}; + +#endif // nsTextWidget_h__ diff --git a/widget/src/beos/nsToolkit.cpp b/widget/src/beos/nsToolkit.cpp new file mode 100644 index 000000000000..854f0a024152 --- /dev/null +++ b/widget/src/beos/nsToolkit.cpp @@ -0,0 +1,271 @@ +/* -*- 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 "nsToolkit.h" +#include "nsWindow.h" +#include "prmon.h" +#include "prtime.h" +#include "nsITimer.h" +#include "nsTimer.h" +#include "nsGUIEvent.h" +#include "nsSwitchToUIThread.h" +#include "plevent.h" + +//NS_IMPL_ISUPPORTS(nsToolkit, NS_ITOOLKIT_IID) +//------------------------------------------------------------------------- +// +// nsISupports implementation macro +// +//------------------------------------------------------------------------- +NS_DEFINE_IID(kIToolkitIID, NS_ITOOLKIT_IID); +NS_IMPL_ISUPPORTS(nsToolkit,kIToolkitIID); + +struct ThreadInterfaceData +{ + void *data; + int32 sync; +}; + +// +// main for the message pump thread +// +PRBool gThreadState = PR_FALSE; + +static sem_id my_find_sem(const char *name) +{ + sem_id ret = B_ERROR; + + /* Get the sem_info for every sempahore in this team. */ + sem_info info; + int32 cookie = 0; + + while(get_next_sem_info(0, &cookie, &info) == B_OK) + if(strcmp(name, info.name) == 0) + { + ret = info.sem; + break; + } + + return ret; +} + +struct ThreadInitInfo { + PRMonitor *monitor; + nsToolkit *toolkit; +}; + +void nsToolkit::RunPump(void* arg) +{ + int32 code; + char portname[64]; + char semname[64]; + ThreadInterfaceData id; + + ThreadInitInfo *info = (ThreadInitInfo*)arg; + ::PR_EnterMonitor(info->monitor); + + gThreadState = PR_TRUE; + + ::PR_Notify(info->monitor); + ::PR_ExitMonitor(info->monitor); + + delete info; + + // system wide unique names + sprintf(portname, "event%lx", PR_GetCurrentThread()); + sprintf(semname, "sync%lx", PR_GetCurrentThread()); + + port_id event = create_port(100, portname); + sem_id sync = create_sem(0, semname); + + while(read_port(event, &code, &id, sizeof(id)) >= 0) + { + switch(code) + { + case WM_TIMER : + { + TimerImpl *tobj = (TimerImpl *)id.data; + tobj->FireTimeout(); + if(! id.sync) + NS_RELEASE(tobj); + } + break; + + case WM_CALLMETHOD : + { + MethodInfo *mInfo = (MethodInfo *)id.data; + mInfo->Invoke(); + if(! id.sync) + delete mInfo; + } + break; + + case 'natv' : // native queue PLEvent + { + PREventQueue *queue = (PREventQueue *)id.data; + PR_ProcessPendingEvents(queue); + } + break; + + default : + printf("nsToolkit::RunPump - UNKNOWN EVENT\n"); + break; + } + + if(id.sync) + release_sem(sync); + } +} + +//------------------------------------------------------------------------- +// +// constructor +// +//------------------------------------------------------------------------- +nsToolkit::nsToolkit() +{ + localthread = false; + NS_INIT_REFCNT(); + mGuiThread = NULL; +} + + +//------------------------------------------------------------------------- +// +// destructor +// +//------------------------------------------------------------------------- +nsToolkit::~nsToolkit() +{ + Kill(); +} + +void nsToolkit::Kill() +{ + if(localthread) + { + GetInterface(); + + // interrupt message flow + close_port(eventport); + } +} + +//------------------------------------------------------------------------- +// +// Create a new thread and run the message pump in there +// +//------------------------------------------------------------------------- +void nsToolkit::CreateUIThread() +{ + PRMonitor *monitor = ::PR_NewMonitor(); + + ::PR_EnterMonitor(monitor); + + ThreadInitInfo *ti = new ThreadInitInfo(); + ti->monitor = monitor; + ti->toolkit = this; + + // create a gui thread + mGuiThread = ::PR_CreateThread(PR_SYSTEM_THREAD, + RunPump, + (void*)ti, + PR_PRIORITY_NORMAL, + PR_LOCAL_THREAD, + PR_UNJOINABLE_THREAD, + 0); + + // wait for the gui thread to start + while(gThreadState == PR_FALSE) + ::PR_Wait(monitor, PR_INTERVAL_NO_TIMEOUT); + + // at this point the thread is running + ::PR_ExitMonitor(monitor); + ::PR_DestroyMonitor(monitor); +} + + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +NS_METHOD nsToolkit::Init(PRThread *aThread) +{ + Kill(); + + // Store the thread ID of the thread containing the message pump. + // If no thread is provided create one + if (NULL != aThread) { + mGuiThread = aThread; + localthread = false; + } else { + localthread = true; + + // create a thread where the message pump will run + CreateUIThread(); + } + + cached = false; + + return NS_OK; +} + +void nsToolkit::GetInterface() +{ + if(! cached) + { + char portname[64]; + char semname[64]; + + sprintf(portname, "event%lx", mGuiThread); + sprintf(semname, "sync%lx", mGuiThread); + + eventport = find_port(portname); + syncsem = my_find_sem(semname); + + cached = true; + } +} + +void nsToolkit::CallMethod(MethodInfo *info) +{ + ThreadInterfaceData id; + + GetInterface(); + + id.data = info; + id.sync = true; + if(write_port(eventport, WM_CALLMETHOD, &id, sizeof(id)) == B_OK) + { + // semantics for CallMethod are that it should be synchronous + while(acquire_sem(syncsem) == B_INTERRUPTED) + ; + } +} + +// to be used only from a BView or BWindow +void nsToolkit::CallMethodAsync(MethodInfo *info) +{ + ThreadInterfaceData id; + + GetInterface(); + + id.data = info; + id.sync = false; + write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0); +} diff --git a/widget/src/beos/nsToolkit.h b/widget/src/beos/nsToolkit.h new file mode 100644 index 000000000000..9716763e4e63 --- /dev/null +++ b/widget/src/beos/nsToolkit.h @@ -0,0 +1,68 @@ +/* -*- 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 TOOLKIT_H +#define TOOLKIT_H + +#include "nsdefs.h" +#include "nsIToolkit.h" + +#include + +struct MethodInfo; + +/** + * Wrapper around the thread running the message pump. + * The toolkit abstraction is necessary because the message pump must + * execute within the same thread that created the widget under Win32. + */ + +class nsToolkit : public nsIToolkit +{ +public: + NS_DECL_ISUPPORTS + + nsToolkit(); + NS_IMETHOD Init(PRThread *aThread); + void CallMethod(MethodInfo *info); + void CallMethodAsync(MethodInfo *info); + // Return whether the current thread is the application's Gui thread. + PRBool IsGuiThread(void) { return (PRBool)(mGuiThread == PR_GetCurrentThread());} + PRThread* GetGuiThread(void) { return mGuiThread; } + void Kill(); + +private: + virtual ~nsToolkit(); + void CreateUIThread(void); + +protected: + // Thread Id of the "main" Gui thread. + PRThread *mGuiThread; + static void RunPump(void* arg); + void GetInterface(); + bool cached; + bool localthread; + port_id eventport; + sem_id syncsem; +}; + +#define WM_CALLMETHOD 'CAme' + +class nsWindow; + +#endif // TOOLKIT_H diff --git a/widget/src/beos/nsTooltipWidget.cpp b/widget/src/beos/nsTooltipWidget.cpp new file mode 100644 index 000000000000..d7fdee7d33bb --- /dev/null +++ b/widget/src/beos/nsTooltipWidget.cpp @@ -0,0 +1,107 @@ +/* -*- 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 "nsTooltipWidget.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + + +NS_IMPL_ADDREF(nsTooltipWidget) +NS_IMPL_RELEASE(nsTooltipWidget) + +//------------------------------------------------------------------------- +// +// nsTooltipWidget constructor +// +//------------------------------------------------------------------------- +nsTooltipWidget::nsTooltipWidget() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// nsTooltipWidget destructor +// +//------------------------------------------------------------------------- +nsTooltipWidget::~nsTooltipWidget() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTooltipWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsTooltipWidgetIID, NS_ITOOLTIPWIDGET_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsTooltipWidgetIID)) { + *aInstancePtr = (void*) ((nsITooltipWidget*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsTooltipWidget::OnPaint(nsRect &r) +{ + return PR_FALSE; +} + +PRBool nsTooltipWidget::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Clear window before paint +// +//------------------------------------------------------------------------- + +PRBool nsTooltipWidget::AutoErase() +{ + return(PR_TRUE); +} + + +//------------------------------------------------------------------------- +// +// get position/dimensions +// +//------------------------------------------------------------------------- + +NS_METHOD nsTooltipWidget::GetBounds(nsRect &aRect) +{ + return nsWindow::GetBounds(aRect); +} + + + diff --git a/widget/src/beos/nsTooltipWidget.h b/widget/src/beos/nsTooltipWidget.h new file mode 100644 index 000000000000..f4a08b48d360 --- /dev/null +++ b/widget/src/beos/nsTooltipWidget.h @@ -0,0 +1,51 @@ +/* -*- 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 nsTooltipWidget_h__ +#define nsTooltipWidget_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsITooltipWidget.h" + +/** + * Native Win32 tooltip window wrapper + */ + +class nsTooltipWidget : public nsWindow, + public nsITooltipWidget +{ + +public: + nsTooltipWidget(); + virtual ~nsTooltipWidget(); + + // nsISupports + NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); + NS_IMETHOD_(nsrefcnt) AddRef(void); + NS_IMETHOD_(nsrefcnt) Release(void); + + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + virtual PRBool AutoErase(); + NS_IMETHOD GetBounds(nsRect &aRect); +}; + +#endif // nsTooltipWidget_h__ diff --git a/widget/src/beos/nsWidgetFactory.cpp b/widget/src/beos/nsWidgetFactory.cpp new file mode 100644 index 000000000000..71f09c26de33 --- /dev/null +++ b/widget/src/beos/nsWidgetFactory.cpp @@ -0,0 +1,267 @@ +/* -*- Mode: C++; tab-width: 4; 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 "nsIFactory.h" +#include "nsISupports.h" +#include "nsdefs.h" +#include "nsWidgetsCID.h" + +#include "nsButton.h" +#include "nsCheckButton.h" +#include "nsComboBox.h" +#include "nsFileWidget.h" +#include "nsListBox.h" +#include "nsLookAndFeel.h" +#include "nsRadioButton.h" +#include "nsScrollbar.h" +#include "nsTextAreaWidget.h" +#include "nsTextHelper.h" +#include "nsTextWidget.h" +#include "nsToolkit.h" +#include "nsTabWidget.h" +#include "nsTooltipWidget.h" +#include "nsWindow.h" +#include "nsDialog.h" +#include "nsLabel.h" +#include "nsMenuBar.h" +#include "nsMenu.h" +#include "nsMenuItem.h" +#include "nsPopUpMenu.h" +#include "nsImageButton.h" +#include "nsMenuButton.h" +#include "nsAppShell.h" + +static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); +static NS_DEFINE_IID(kCChild, NS_CHILD_CID); +static NS_DEFINE_IID(kCButton, NS_BUTTON_CID); +static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID); +static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID); +static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID); +static NS_DEFINE_IID(kCRadioButton, NS_RADIOBUTTON_CID); +static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID); +static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID); +static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID); +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(kCToolkit, NS_TOOLKIT_CID); +static NS_DEFINE_IID(kCLookAndFeel, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kCDialog, NS_DIALOG_CID); +static NS_DEFINE_IID(kCLabel, NS_LABEL_CID); +static NS_DEFINE_IID(kCMenuBar, NS_MENUBAR_CID); +static NS_DEFINE_IID(kCMenu, NS_MENU_CID); +static NS_DEFINE_IID(kCMenuItem, NS_MENUITEM_CID); +static NS_DEFINE_IID(kCImageButton, NS_IMAGEBUTTON_CID); +static NS_DEFINE_IID(kCPopUpMenu, NS_POPUPMENU_CID); +static NS_DEFINE_IID(kCMenuButton, NS_MENUBUTTON_CID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +class nsWidgetFactory : public nsIFactory +{ +public: + // nsISupports methods + NS_DECL_ISUPPORTS + + // nsIFactory methods + NS_IMETHOD CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock); + + nsWidgetFactory(const nsCID &aClass); + ~nsWidgetFactory(); + +private: + nsCID mClassID; +}; + +NS_IMPL_ADDREF(nsWidgetFactory) +NS_IMPL_RELEASE(nsWidgetFactory) + + +nsWidgetFactory::nsWidgetFactory(const nsCID &aClass) +{ + NS_INIT_REFCNT(); + mClassID = aClass; +} + +nsWidgetFactory::~nsWidgetFactory() +{ + NS_ASSERTION(mRefCnt == 0, "Reference count not zero in destructor"); +} + +nsresult nsWidgetFactory::QueryInterface(const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + + // Always NULL result, in case of failure + *aResult = NULL; + + if (aIID.Equals(kISupportsIID)) { + *aResult = (void *)(nsISupports*)this; + } else if (aIID.Equals(kIFactoryIID)) { + *aResult = (void *)(nsIFactory*)this; + } + + if (*aResult == NULL) { + return NS_NOINTERFACE; + } + + NS_ADDREF_THIS(); // Increase reference count for caller + return NS_OK; +} + + +nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter, + const nsIID &aIID, + void **aResult) +{ + if (aResult == NULL) { + return NS_ERROR_NULL_POINTER; + } + *aResult = NULL; + if (nsnull != aOuter) { + return NS_ERROR_NO_AGGREGATION; + } + + nsISupports *inst = nsnull; + if (mClassID.Equals(kCWindow) || + mClassID.Equals(kCChild)) { + inst = (nsISupports*)new nsWindow(); + } + else if (mClassID.Equals(kCButton)) { + inst = (nsISupports*)(nsWindow*)new nsButton(); + } + else if (mClassID.Equals(kCCheckButton)) { + inst = (nsISupports*)(nsWindow*)new nsCheckButton(); + } + else if (mClassID.Equals(kCCombobox)) { + inst = (nsISupports*)(nsWindow*)new nsComboBox(); + } + else if (mClassID.Equals(kCRadioButton)) { + inst = (nsISupports*)(nsWindow*)new nsRadioButton(); + } + else if (mClassID.Equals(kCFileOpen)) { + inst = (nsISupports*)new nsFileWidget(); + } + else if (mClassID.Equals(kCListbox)) { + inst = (nsISupports*)(nsWindow*)new nsListBox(); + } + else if (mClassID.Equals(kCHorzScrollbar)) { + inst = (nsISupports*)(nsWindow*)new nsScrollbar(PR_FALSE); + } + else if (mClassID.Equals(kCVertScrollbar)) { + inst = (nsISupports*)(nsWindow*)new nsScrollbar(PR_TRUE); + } + else if (mClassID.Equals(kCTextArea)) { + inst = (nsISupports*)(nsWindow*)new nsTextAreaWidget(); + } + else if (mClassID.Equals(kCTextField)) { + inst = (nsISupports*)(nsWindow*)new nsTextWidget(); + } + else if (mClassID.Equals(kCTabWidget)) { + inst = (nsISupports*)(nsWindow*)new nsTabWidget(); + } + else if (mClassID.Equals(kCTooltipWidget)) { + inst = (nsISupports*)(nsWindow*)new nsTooltipWidget(); + } + else if (mClassID.Equals(kCAppShell)) { + inst = (nsISupports*)new nsAppShell(); + } + else if (mClassID.Equals(kCToolkit)) { + inst = (nsISupports*)new nsToolkit(); + } + else if (mClassID.Equals(kCLookAndFeel)) { + inst = (nsISupports*)new nsLookAndFeel(); + } + else if (mClassID.Equals(kCDialog)) { + inst = (nsISupports*)(nsWindow*)new nsDialog(); + } + else if (mClassID.Equals(kCLabel)) { + inst = (nsISupports*)(nsWindow*)new nsLabel(); + } + else if (mClassID.Equals(kCMenuBar)) { + inst = (nsISupports*)(nsIMenuBar*) new nsMenuBar(); + } + else if (mClassID.Equals(kCMenu)) { + inst = (nsISupports*)(nsIMenu*) new nsMenu(); + } + else if (mClassID.Equals(kCMenuItem)) { + inst = (nsISupports*)(nsIMenuItem*) new nsMenuItem(); + } + else if (mClassID.Equals(kCImageButton)) { + inst = (nsISupports*)(nsWindow*)new nsImageButton(); + } + else if (mClassID.Equals(kCMenuButton)) { + inst = (nsISupports*)(nsWindow*)new nsMenuButton(); + } + else if (mClassID.Equals(kCPopUpMenu)) { + inst = (nsISupports*)new nsPopUpMenu(); + } + /* */ + + if (inst == NULL) { + return NS_ERROR_OUT_OF_MEMORY; + } + + nsresult res = inst->QueryInterface(aIID, aResult); + + if (res != NS_OK) { + // We didn't get the right interface, so clean up + delete inst; + } + + return res; +} + +nsresult nsWidgetFactory::LockFactory(PRBool aLock) +{ + // Not implemented in simplest case. + return NS_OK; +} + +// return the proper factory to the caller +extern "C" NS_WIDGET nsresult +NSGetFactory(nsISupports* serviceMgr, + const nsCID &aClass, + const char *aClassName, + const char *aProgID, + nsIFactory **aFactory) +{ + if (nsnull == aFactory) { + return NS_ERROR_NULL_POINTER; + } + + *aFactory = new nsWidgetFactory(aClass); + + if (nsnull == aFactory) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory); +} + + diff --git a/widget/src/beos/nsWidgetSupport.cpp b/widget/src/beos/nsWidgetSupport.cpp new file mode 100644 index 000000000000..d4ba278a8d50 --- /dev/null +++ b/widget/src/beos/nsWidgetSupport.cpp @@ -0,0 +1,467 @@ +/* -*- 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 "nsWidgetSupport.h" +#include "nsRect.h" +#include "nsITextAreaWidget.h" +#include "nsIFileWidget.h" +#include "nsIAppShell.h" +#include "nsIButton.h" +#include "nsIComboBox.h" +#include "nsIEventListener.h" +#include "nsILabel.h" +#include "nsIListBox.h" +#include "nsIListWidget.h" +#include "nsILookAndFeel.h" +#include "nsIMouseListener.h" +#include "nsITabWidget.h" +#include "nsIToolkit.h" +#include "nsIWidget.h" +#include "nsIDialog.h" +#include "nsICheckButton.h" +#include "nsIScrollbar.h" +#include "nsIRadioButton.h" +#include "nsITooltipWidget.h" +#include "nsITextWidget.h" + + + + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID); +static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); +static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID); +static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID); +static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID); +static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID); +static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); +static NS_DEFINE_IID(kIScrollBarIID, NS_ISCROLLBAR_IID); + +NS_WIDGET nsresult +NS_CreateDialog(nsISupports* aParent, + nsIDialog* aDialog, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aDialog->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + + +NS_WIDGET nsresult +NS_CreateButton(nsISupports* aParent, + nsIButton* aButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + +NS_WIDGET nsresult +NS_CreateCheckButton(nsISupports* aParent, + nsICheckButton* aCheckButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + + + + +NS_WIDGET nsresult +NS_CreateRadioButton( nsISupports* aParent, + nsIRadioButton* aRadioButton, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget; + if (NS_OK == aRadioButton->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + if (aParent != nsnull) + NS_IF_RELEASE(parent); + return NS_OK; +} + + +NS_WIDGET nsresult +NS_CreateLabel( nsISupports* aParent, + nsILabel* aLabel, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent)) + { + nsIWidget* widget; + if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + NS_IF_RELEASE(parent); + } + return NS_OK; +} + + + +NS_WIDGET nsresult +NS_CreateTextAreaWidget(nsISupports* aParent, + nsITextAreaWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + +NS_WIDGET nsresult +NS_CreateTextWidget(nsISupports* aParent, + nsITextWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + + + +NS_WIDGET nsresult +NS_CreateScrollBar(nsISupports* aParent, + nsIScrollbar* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + +NS_WIDGET nsresult +NS_CreateListBox(nsISupports* aParent, + nsIListBox* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + + +NS_WIDGET nsresult +NS_CreateComboBox(nsISupports* aParent, + nsIComboBox* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + + +NS_WIDGET nsresult +NS_CreateTabWidget(nsISupports* aParent, + nsITabWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + + + + + +extern NS_WIDGET nsresult +NS_CreateTooltipWidget(nsISupports* aParent, + nsITooltipWidget* aWidget, + const nsRect& aRect, + EVENT_CALLBACK aHandleEventFunction, + const nsFont* aFont) +{ + nsIWidget* parent = nsnull; + if (aParent != nsnull) + aParent->QueryInterface(kIWidgetIID,(void**)&parent); + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Create(parent, aRect, aHandleEventFunction, NULL); + widget->Show(PR_TRUE); + if (aFont != nsnull) + widget->SetFont(*aFont); + NS_IF_RELEASE(widget); + } + else + { + NS_ERROR("Call QueryInterface on a non kIWidgetIID supported object"); + } + + if (aParent) + NS_IF_RELEASE(parent); + + return NS_OK; +} + +extern NS_WIDGET nsresult +NS_ShowWidget(nsISupports* aWidget, PRBool aShow) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Show(aShow); + NS_IF_RELEASE(widget); + } + + return NS_OK; +} + +extern NS_WIDGET nsresult +NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->Move(aX,aY); + NS_IF_RELEASE(widget); + } + return NS_OK; +} + +extern NS_WIDGET nsresult +NS_EnableWidget(nsISupports* aWidget, PRBool aEnable) +{ +#if 0 // YK990522 was unused + void* result = nsnull; +#endif + nsIWidget* widget; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) + { + widget->Enable(aEnable); + NS_RELEASE(widget); + } + return NS_OK; +} + + +extern NS_WIDGET nsresult +NS_SetFocusToWidget(nsISupports* aWidget) +{ + + nsIWidget* widget = nsnull; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { + widget->SetFocus(); + NS_IF_RELEASE(widget); + } + return NS_OK; +} + + +extern NS_WIDGET nsresult +NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData) +{ + void* result = nsnull; + nsIWidget* widget; + if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) + { + result = widget->GetNativeData(NS_NATIVE_WIDGET); + NS_RELEASE(widget); + } + *aNativeData = result; + return NS_OK; + +} diff --git a/widget/src/beos/nsWindow.cpp b/widget/src/beos/nsWindow.cpp new file mode 100644 index 000000000000..1f0db647a8b8 --- /dev/null +++ b/widget/src/beos/nsWindow.cpp @@ -0,0 +1,2736 @@ +/* -*- 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 "nsWindow.h" +#include "nsIAppShell.h" +#include "nsIFontMetrics.h" +#include "nsFont.h" +#include "nsGUIEvent.h" +#include "nsIRenderingContext.h" +#include "nsIDeviceContext.h" +#include "nsRect.h" +#include "nsTransform2D.h" +#include "nsStringUtil.h" +//#include "sysmets.h" +#include "nsGfxCIID.h" +#include "resource.h" +#include "prtime.h" + +#include "nsIMenu.h" +#include "nsMenu.h" +#include "nsIMenuItem.h" +#include "nsIMenuListener.h" +#include "nsMenuItem.h" + +#include +#include +#include +#include + +#ifdef DRAG_DROP +//#include "nsDropTarget.h" +#include "DragDrop.h" +#include "DropTar.h" +#include "DropSrc.h" +#endif + +static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +//static NS_DEFINE_IID(kIMenuListenerIID, NS_IMENULISTENER_IID); + +//------------------------------------------------------------------------- +// +// nsWindow constructor +// +//------------------------------------------------------------------------- +nsWindow::nsWindow() : nsBaseWidget() +{ + rgb_color back = ui_color(B_PANEL_BACKGROUND_COLOR); + + NS_INIT_REFCNT(); + mView = 0; + mBackground = NS_RGB(back.red, back.green, back.blue); + mForeground = NS_RGB(0x00,0x00,0x00); + mIsDestroying = PR_FALSE; + mOnDestroyCalled = PR_FALSE; +// mTooltip = NULL; + mPreferredWidth = 0; + mPreferredHeight = 0; + mFont = nsnull; + mIsVisible = PR_FALSE; + mMenuBar = nsnull; + mMenuCmdId = 0; + + mHitMenu = nsnull; + mHitSubMenus = new nsVoidArray(); + mVScrollbar = nsnull; + +#ifdef DRAG_DROP + mDragDrop = nsnull; + mDropTarget = nsnull; + mDropSource = nsnull; +#endif +} + + +//------------------------------------------------------------------------- +// +// nsWindow destructor +// +//------------------------------------------------------------------------- +nsWindow::~nsWindow() +{ + mIsDestroying = PR_TRUE; + + // If the widget was released without calling Destroy() then the native + // window still exists, and we need to destroy it + if (NULL != mView) { + Destroy(); + } + + NS_IF_RELEASE(mHitMenu); // this should always have already been freed by the deselect +#ifdef DRAG_DROP + NS_IF_RELEASE(mDropTarget); + NS_IF_RELEASE(mDropSource); + if (mDragDrop) + delete mDragDrop; + //NS_IF_RELEASE(mDragDrop); +#endif + + //XXX Temporary: Should not be caching the font + delete mFont; +} + + +//------------------------------------------------------------------------- +// +// Default for height modification is to do nothing +// +//------------------------------------------------------------------------- + +PRInt32 nsWindow::GetHeight(PRInt32 aProposedHeight) +{ + return(aProposedHeight); +} + +NS_METHOD nsWindow::BeginResizingChildren(void) +{ + if(mView && mView->LockLooper()) + { + mView->Window()->BeginViewTransaction(); + mView->UnlockLooper(); + } + return NS_OK; +} + +NS_METHOD nsWindow::EndResizingChildren(void) +{ + if(mView && mView->LockLooper()) + { + mView->Window()->EndViewTransaction(); + mView->UnlockLooper(); + } + return NS_OK; +} + +// DoCreateTooltip - creates a tooltip control and adds some tools +// to it. +// Returns the handle of the tooltip control if successful or NULL +// otherwise. +// hwndOwner - handle of the owner window +// + +void nsWindow::AddTooltip(BView * hwndOwner,nsRect* aRect, int aId) +{ +#if 0 + TOOLINFO ti; // tool information + memset(&ti, 0, sizeof(TOOLINFO)); + + // Make sure the common control DLL is loaded + InitCommonControls(); + + // Create a tooltip control for the window if needed + if (mTooltip == (BWindow *) NULL) { + mTooltip = CreateWindow(TOOLTIPS_CLASS, (LPSTR) NULL, TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + NULL, (HMENU) NULL, + nsToolkit::mDllInstance, + NULL); + } + + if (mTooltip == (BWindow *) NULL) + return; + + ti.cbSize = sizeof(TOOLINFO); + ti.uFlags = TTF_SUBCLASS; + ti.hwnd = hwndOwner; + ti.hinst = nsToolkit::mDllInstance; + ti.uId = aId; + ti.lpszText = (LPSTR)" "; // must set text to + // something for tooltip to give events; + ti.rect.left = aRect->x; + ti.rect.top = aRect->y; + ti.rect.right = aRect->x + aRect->width; + ti.rect.bottom = aRect->y + aRect->height; + + if (!SendMessage(mTooltip, TTM_ADDTOOL, 0, + (LPARAM) (LPTOOLINFO) &ti)) + return; +#endif +} + +NS_METHOD nsWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) +{ + BPoint point; + point.x = aOldRect.x; + point.y = aOldRect.y; + if(mView && mView->LockLooper()) + { + mView->ConvertToScreen(&point); + mView->UnlockLooper(); + } + aNewRect.x = nscoord(point.x); + aNewRect.y = nscoord(point.y); + aNewRect.width = aOldRect.width; + aNewRect.height = aOldRect.height; + return NS_OK; +} + +NS_METHOD nsWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) +{ + BPoint point; + point.x = aOldRect.x; + point.y = aOldRect.y; + if(mView && mView->LockLooper()) + { + mView->ConvertFromScreen(&point); + mView->UnlockLooper(); + } + aNewRect.x = nscoord(point.x); + aNewRect.y = nscoord(point.y); + aNewRect.width = aOldRect.width; + aNewRect.height = aOldRect.height; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Setup initial tooltip rectangles +// +//------------------------------------------------------------------------- + +NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) +{ + RemoveTooltips(); + for (int i = 0; i < (int)aNumberOfTips; i++) { + AddTooltip(mView, aTooltipAreas[i], i); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Update all tooltip rectangles +// +//------------------------------------------------------------------------- + +NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[]) +{ +#if 0 + TOOLINFO ti; + memset(&ti, 0, sizeof(TOOLINFO)); + ti.cbSize = sizeof(TOOLINFO); + ti.hwnd = mView; + // Get the number of tooltips + UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, 0); + NS_ASSERTION(count > 0, "Called UpdateTooltips before calling SetTooltips"); + + for (UINT i = 0; i < count; i++) { + ti.uId = i; + int result =::SendMessage(mTooltip, TTM_ENUMTOOLS, i, (LPARAM) (LPTOOLINFO)&ti); + + nsRect* newTip = aNewTips[i]; + ti.rect.left = newTip->x; + ti.rect.top = newTip->y; + ti.rect.right = newTip->x + newTip->width; + ti.rect.bottom = newTip->y + newTip->height; + ::SendMessage(mTooltip, TTM_NEWTOOLRECT, 0, (LPARAM) (LPTOOLINFO)&ti); + + } +#endif + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Remove all tooltip rectangles +// +//------------------------------------------------------------------------- + +NS_METHOD nsWindow::RemoveTooltips() +{ +#if 0 + TOOLINFO ti; + memset(&ti, 0, sizeof(TOOLINFO)); + ti.cbSize = sizeof(TOOLINFO); + long val; + + if (mTooltip == NULL) + return NS_ERROR_FAILURE; + + // Get the number of tooltips + UINT count = ::SendMessage(mTooltip, TTM_GETTOOLCOUNT, 0, (LPARAM)&val); + for (UINT i = 0; i < count; i++) { + ti.uId = i; + ti.hwnd = mView; + ::SendMessage(mTooltip, TTM_DELTOOL, 0, (LPARAM) (LPTOOLINFO)&ti); + } +#endif + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Convert nsEventStatus value to a windows boolean +// +//------------------------------------------------------------------------- + +PRBool nsWindow::ConvertStatus(nsEventStatus aStatus) +{ + switch(aStatus) { + case nsEventStatus_eIgnore: + return PR_FALSE; + case nsEventStatus_eConsumeNoDefault: + return PR_TRUE; + case nsEventStatus_eConsumeDoDefault: + return PR_FALSE; + default: + NS_ASSERTION(0, "Illegal nsEventStatus enumeration value"); + break; + } + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Initialize an event to dispatch +// +//------------------------------------------------------------------------- + +void nsWindow::InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint) +{ + event.widget = this; + NS_ADDREF(event.widget); + + if (nsnull == aPoint) { // use the point from the event + // get the message position in client coordinates and in twips + event.point.x = 0; + event.point.y = 0; +#if 0 + DWORD pos = ::GetMessagePos(); + POINT cpos; + + cpos.x = LOWORD(pos); + cpos.y = HIWORD(pos); + + if (mView != NULL) { + ::ScreenToClient(mView, &cpos); + event.point.x = cpos.x; + event.point.y = cpos.y; + } else { + event.point.x = 0; + event.point.y = 0; + } +#endif + } + else { // use the point override if provided + event.point.x = aPoint->x; + event.point.y = aPoint->y; + } + event.time = system_time() / 1000; + event.message = aEventType; +} + +//------------------------------------------------------------------------- +// +// Invokes callback and ProcessEvent method on Event Listener object +// +//------------------------------------------------------------------------- + +NS_IMETHODIMP nsWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) +{ + aStatus = nsEventStatus_eIgnore; + + //if (nsnull != mMenuListener) + // aStatus = mMenuListener->MenuSelected(*event); + if (nsnull != mEventCallback) { + aStatus = (*mEventCallback)(event); + } + + // Dispatch to event listener if event was not consumed + if ((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) { + aStatus = mEventListener->ProcessEvent(*event); + } +// YK990522 was unused +// nsWindow * thisPtr = this; + return NS_OK; +} + +//------------------------------------------------------------------------- +PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event) +{ + nsEventStatus status; + DispatchEvent(event, status); + return ConvertStatus(status); +} + +//------------------------------------------------------------------------- +// +// Dispatch standard event +// +//------------------------------------------------------------------------- + +PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) +{ + nsGUIEvent event; + event.eventStructType = NS_GUI_EVENT; + InitEvent(event, aMsg); + + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + return result; +} + +//WINOLEAPI oleStatus; +//------------------------------------------------------------------------- +// +// Utility method for implementing both Create(nsIWidget ...) and +// Create(nsNativeWidget...) +//------------------------------------------------------------------------- +#ifdef DRAG_DROP +BOOL gOLEInited = FALSE; +#endif + +nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData, + nsNativeWidget aNativeParent) +{ + BaseCreate(aParent, aRect, aHandleEventFunction, aContext, + aAppShell, aToolkit, aInitData); + + // Switch to the "main gui thread" if necessary... This method must + // be executed on the "gui thread"... + // + + nsToolkit* toolkit = (nsToolkit *)mToolkit; + if (toolkit) { + if (!toolkit->IsGuiThread()) { + uint32 args[7]; + args[0] = (uint32)aParent; + args[1] = (uint32)&aRect; + args[2] = (uint32)aHandleEventFunction; + args[3] = (uint32)aContext; + args[4] = (uint32)aAppShell; + args[5] = (uint32)aToolkit; + args[6] = (uint32)aInitData; + + if (nsnull != aParent) { + // nsIWidget parent dispatch + MethodInfo info(this, this, nsWindow::CREATE, 7, args); + toolkit->CallMethod(&info); + return NS_OK; + } + else { + // Native parent dispatch + MethodInfo info(this, this, nsWindow::CREATE_NATIVE, 5, args); + toolkit->CallMethod(&info); + return NS_OK; + } + } + } + + BView *parent; + if (nsnull != aParent) { // has a nsIWidget parent + parent = ((aParent) ? (BView *)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull); + } else { // has a nsNative parent + parent = (BView *)aNativeParent; + } + + mView = CreateBeOSView(); + mView->Hide(); + if(parent) + { + bool mustunlock; + + if(parent->LockLooper()) + mustunlock = true; + + parent->AddChild(mView); + mView->MoveTo(aRect.x, aRect.y); + mView->ResizeTo(aRect.width, GetHeight(aRect.height)); + + if(mustunlock) + parent->UnlockLooper(); + } + else + { + // create window + BRect winrect = BRect(aRect.x, aRect.y, aRect.x + aRect.width - 1, aRect.y + aRect.height - 1); + winrect.OffsetBy( 10, 30 ); + nsWindowBeOS *w = new nsWindowBeOS(this, + winrect, + "Gecko", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS); + w->AddChild(mView); + mView->MoveTo(0, 0); + mView->ResizeTo(aRect.width, GetHeight(aRect.height)); + mView->SetResizingMode(B_FOLLOW_ALL); + w->Run(); + } + +#if 0 + // Initial Drag & Drop Work +#ifdef DRAG_DROP + if (!gOLEInited) { + DWORD dwVer = ::OleBuildVersion(); + + if (FAILED(::OleInitialize(NULL))){ + printf("***** OLE has been initialized!\n"); + } + gOLEInited = TRUE; + } + + mDragDrop = new CfDragDrop(); + //mDragDrop->AddRef(); + mDragDrop->Initialize(this); + + /*mDropTarget = new CfDropTarget(*mDragDrop); + mDropTarget->AddRef(); + + mDropSource = new CfDropSource(*mDragDrop); + mDropSource->AddRef();*/ + + /*mDropTarget = new nsDropTarget(this); + mDropTarget->AddRef(); + if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mDropTarget,TRUE,FALSE)) { + if (S_OK == ::RegisterDragDrop(mView, (LPDROPTARGET)mDropTarget)) { + + } + }*/ +#endif +#endif + + // call the event callback to notify about creation + DispatchStandardEvent(NS_CREATE); + return(NS_OK); +} + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return(StandardWindowCreate(aParent, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, aInitData, + nsnull)); +} + + +//------------------------------------------------------------------------- +// +// create with a native parent +// +//------------------------------------------------------------------------- + +NS_METHOD nsWindow::Create(nsNativeWidget aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return(StandardWindowCreate(nsnull, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, aInitData, + aParent)); +} + +BView *nsWindow::CreateBeOSView() +{ + return new nsViewBeOS(this, BRect(0, 0, 0, 0), "", 0, B_WILL_DRAW | B_FRAME_EVENTS); +} + +//------------------------------------------------------------------------- +// +// Close this nsWindow +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Destroy() +{ + // Switch to the "main gui thread" if necessary... This method must + // be executed on the "gui thread"... + nsToolkit* toolkit = (nsToolkit *)mToolkit; + if (toolkit != nsnull && !toolkit->IsGuiThread()) { + MethodInfo info(this, this, nsWindow::DESTROY); + toolkit->CallMethod(&info); + return NS_ERROR_FAILURE; + } + + // disconnect from the parent + if (!mIsDestroying) { + nsBaseWidget::Destroy(); + } + + // destroy the BView + if (mView) + { + // prevent the widget from causing additional events + mEventCallback = nsnull; + + if(mView->LockLooper()) + { + // destroy from inside + BWindow *w = mView->Window(); + if(mView->Parent()) + { + mView->Parent()->RemoveChild(mView); + w->Unlock(); + } + else + { + w->RemoveChild(mView); + w->Quit(); + } + } + + // window is already gone + while(mView->ChildAt(0)) + mView->RemoveChild(mView->ChildAt(0)); + delete mView; + mView = NULL; + + //our windows can be subclassed by + //others and these namless, faceless others + //may not let us know about WM_DESTROY. so, + //if OnDestroy() didn't get called, just call + //it now. MMP + if (PR_FALSE == mOnDestroyCalled) + OnDestroy(); + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get this nsWindow parent +// +//------------------------------------------------------------------------- +nsIWidget* nsWindow::GetParent(void) +{ + nsIWidget *widget = 0; + BView *parent; + if(mView && (parent = mView->Parent()) != 0) + { + nsIWidgetStore *ws = dynamic_cast(parent); + NS_ASSERTION(ws != 0, "view must be derived from nsIWidgetStore"); + if((widget = ws->GetMozillaWidget()) != 0) + { + // If the widget is in the process of being destroyed then + // do NOT return it + if(((nsWindow *)widget)->mIsDestroying) + widget = 0; + else + NS_ADDREF(widget); + } + } + + return widget; +} + + +//------------------------------------------------------------------------- +// +// Hide or show this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Show(PRBool bState) +{ + bool mustunlock = false; + bool havewindow = false; + + if(mView) + { + if(mView->LockLooper()) + mustunlock = true; + + if(mustunlock && mView->Parent() == 0) + havewindow = true; + + if(PR_FALSE == bState) + { + mView->Hide(); + if(havewindow) + mView->Window()->Hide(); + } + else + { + mView->Show(); + if(havewindow) + mView->Window()->Show(); + } + + if(mustunlock) + mView->UnlockLooper(); + } + + mIsVisible = bState; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Return PR_TRUE if the whether the component is visible, PR_FALSE otherwise +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::IsVisible(PRBool & bState) +{ + bState = mIsVisible; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Move this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Move(PRUint32 aX, PRUint32 aY) +{ + bool mustunlock = false; + bool havewindow = false; + + mBounds.x = aX; + mBounds.y = aY; + + if(mView) + { + if(mView->LockLooper()) + mustunlock = true; + + if(mustunlock && mView->Parent() == 0) + havewindow = true; + + if(mView->Parent() || ! havewindow) + mView->MoveTo(aX, aY); + else + mView->Window()->MoveTo(aX, aY); + + if(mustunlock) + mView->UnlockLooper(); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Resize this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) +{ + bool mustunlock = false; + bool havewindow = false; + + if(aWidth < 0 || aHeight < 0) + return NS_OK; + + // Set cached value for lightweight and printing + mBounds.width = aWidth; + mBounds.height = aHeight; + + if(mView) + { + if(mView->LockLooper()) + mustunlock = true; + + if(mustunlock && mView->Parent() == 0) + havewindow = true; + + if(! aRepaint) + printf("nsWindow::Resize FIXME: no repaint not implemented\n"); + + if(mView->Parent() || ! havewindow) + mView->ResizeTo(aWidth, GetHeight(aHeight)); + else + mView->Window()->ResizeTo(aWidth, GetHeight(aHeight)); + + if(mustunlock) + mView->UnlockLooper(); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Resize this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Resize(PRUint32 aX, + PRUint32 aY, + PRUint32 aWidth, + PRUint32 aHeight, + PRBool aRepaint) +{ + bool mustunlock = false; + bool havewindow = false; + + if(aWidth < 0 || aHeight < 0) + return NS_OK; + + // Set cached value for lightweight and printing + mBounds.x = aX; + mBounds.y = aY; + mBounds.width = aWidth; + mBounds.height = aHeight; + + if(mView) + { + if(mView->LockLooper()) + mustunlock = true; + + if(mustunlock && mView->Parent() == 0) + havewindow = true; + + if(! aRepaint) + printf("nsWindow::Resize FIXME: no repaint not implemented\n"); + + if(mView->Parent() || ! havewindow) + { + mView->MoveTo(aX, aY); + mView->ResizeTo(aWidth, GetHeight(aHeight)); + } + else + { + mView->Window()->MoveTo(aX, aY); + mView->Window()->ResizeTo(aWidth, GetHeight(aHeight)); + } + + if(mustunlock) + mView->UnlockLooper(); + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Enable/disable this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Enable(PRBool bState) +{ +printf("nsWindow::Enable - FIXME: not implemented\n"); + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Give the focus to this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::SetFocus(void) +{ + // + // Switch to the "main gui thread" if necessary... This method must + // be executed on the "gui thread"... + // + nsToolkit* toolkit = (nsToolkit *)mToolkit; + if (!toolkit->IsGuiThread()) { + MethodInfo info(this, this, nsWindow::SET_FOCUS); + toolkit->CallMethod(&info); + return NS_ERROR_FAILURE; + } + + if(mView && mView->LockLooper()) + { + mView->MakeFocus(true); + mView->UnlockLooper(); + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get this component dimension +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::GetBounds(nsRect &aRect) +{ + if(mView && mView->LockLooper()) + { + BRect r = mView->Frame(); + aRect.x = nscoord(r.left); + aRect.y = nscoord(r.top); + aRect.width = r.IntegerWidth() + 1; + aRect.height = r.IntegerHeight() + 1; + mView->UnlockLooper(); + } else { + aRect = mBounds; + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this component dimension +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::GetClientBounds(nsRect &aRect) +{ + if(mView && mView->LockLooper()) + { + BRect r = mView->Bounds(); + aRect.x = nscoord(r.left); + aRect.y = nscoord(r.top); + aRect.width = r.IntegerWidth() + 1; + aRect.height = r.IntegerHeight() + 1; + mView->UnlockLooper(); + } else { + aRect.SetRect(0,0,0,0); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set the background color +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::SetBackgroundColor(const nscolor &aColor) +{ + nsBaseWidget::SetBackgroundColor(aColor); + + if(mView && mView->LockLooper()) + { + mView->SetViewColor(NS_GET_R(aColor), NS_GET_G(aColor), NS_GET_B(aColor), NS_GET_A(aColor)); + mView->UnlockLooper(); + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Get this component font +// +//------------------------------------------------------------------------- +nsIFontMetrics* nsWindow::GetFont(void) +{ + NS_NOTYETIMPLEMENTED("GetFont not yet implemented"); // to be implemented + return NULL; +} + + +//------------------------------------------------------------------------- +// +// Set this component font +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::SetFont(const nsFont &aFont) +{ + // Cache Font for owner draw + if (mFont == nsnull) { + mFont = new nsFont(aFont); + } else { + *mFont = aFont; + } + + // Bail out if there is no context + if (nsnull == mContext) { + return NS_ERROR_FAILURE; + } + + nsIFontMetrics* metrics; + mContext->GetMetricsFor(aFont, metrics); + nsFontHandle fontHandle; + metrics->GetFontHandle(fontHandle); + BFont *font = (BFont*)fontHandle; + if(font && mView && mView->LockLooper()) + { + mView->SetFont(font, B_FONT_ALL); + mView->UnlockLooper(); + } + NS_RELEASE(metrics); + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set this component cursor +// +//------------------------------------------------------------------------- + +NS_METHOD nsWindow::SetCursor(nsCursor aCursor) +{ + + // Only change cursor if it's changing + + //XXX mCursor isn't always right. Scrollbars and others change it, too. + //XXX If we want this optimization we need a better way to do it. + //if (aCursor != mCursor) { +// HCURSOR newCursor = NULL; + + switch(aCursor) { + case eCursor_select: +// newCursor = ::LoadCursor(NULL, IDC_IBEAM); + break; + + case eCursor_wait: +// newCursor = ::LoadCursor(NULL, IDC_WAIT); + break; + + case eCursor_hyperlink: { +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_SELECTANCHOR)); + break; + } + + case eCursor_standard: +// newCursor = ::LoadCursor(NULL, IDC_ARROW); + break; + + case eCursor_sizeWE: +// newCursor = ::LoadCursor(NULL, IDC_SIZEWE); + break; + + case eCursor_sizeNS: +// newCursor = ::LoadCursor(NULL, IDC_SIZENS); + break; + + case eCursor_arrow_north: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWNORTH)); + break; + + case eCursor_arrow_north_plus: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWNORTHPLUS)); + break; + + case eCursor_arrow_south: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWSOUTH)); + break; + + case eCursor_arrow_south_plus: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWSOUTHPLUS)); + break; + + case eCursor_arrow_east: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWEAST)); + break; + + case eCursor_arrow_east_plus: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWEASTPLUS)); + break; + + case eCursor_arrow_west: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWWEST)); + break; + + case eCursor_arrow_west_plus: +// newCursor = ::LoadCursor(nsToolkit::mDllInstance, MAKEINTRESOURCE(IDC_ARROWWESTPLUS)); + break; + + default: + NS_ASSERTION(0, "Invalid cursor type"); + break; + } + +#if 0 + if (NULL != newCursor) { + mCursor = aCursor; + HCURSOR oldCursor = ::SetCursor(newCursor); + } +#endif + //} + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Invalidate this component visible area +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Invalidate(PRBool aIsSynchronous) +{ + if(mView && mView->LockLooper()) + { + if(PR_TRUE == aIsSynchronous) + mView->Draw(mView->Bounds()); + else + mView->Invalidate(); + mView->UnlockLooper(); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Invalidate this component visible area +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) +{ + if(mView && mView->LockLooper()) + { + BRect r(aRect.x, aRect.y, aRect.x + aRect.width - 1, aRect.y + aRect.height - 1); + if(PR_TRUE == aIsSynchronous) + mView->Draw(r); + else + mView->Invalidate(r); + mView->UnlockLooper(); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Force a synchronous repaint of the window +// +//------------------------------------------------------------------------- +NS_IMETHODIMP nsWindow::Update() +{ + if(mView && mView->LockLooper()) + { + mView->Window()->UpdateIfNeeded(); + mView->UnlockLooper(); + } + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Return some native data according to aDataType +// +//------------------------------------------------------------------------- +void* nsWindow::GetNativeData(PRUint32 aDataType) +{ + switch(aDataType) { + case NS_NATIVE_WIDGET: + case NS_NATIVE_WINDOW: + case NS_NATIVE_PLUGIN_PORT: + case NS_NATIVE_GRAPHIC: + return (void *)((BView *)mView); + case NS_NATIVE_COLORMAP: + default: + break; + } + + return NULL; +} + +//------------------------------------------------------------------------- +// +// Set the colormap of the window +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap) +{ +printf("nsWindow::SetColorMap - not implemented\n"); + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Scroll the bits of a window +// +//------------------------------------------------------------------------- +NS_METHOD nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) +{ + BRect src; + BRect dest; + + if(mView && mView->LockLooper()) + { + BRect b = mView->Bounds(); + if(aClipRect) + { + src.left = aClipRect->x; + src.top = aClipRect->y; + src.right = aClipRect->XMost(); + src.bottom = aClipRect->YMost(); + } + else + src = b; + + BRegion invalid; + invalid.Include(src); + + // make sure we only reference visible bits + // so we don't trigger a BView invalidate + if(src.left + aDx < 0) + src.left = -aDx; + if(src.right + aDy > b.right) + src.right = b.right - aDy; + if(src.top + aDy < 0) + src.top = -aDy; + if(src.bottom + aDy > b.bottom) + src.bottom = b.bottom - aDy; + + dest = src; + dest.left += aDx; + dest.right += aDx; + dest.top += aDy; + dest.bottom += aDy; + + mView->ConstrainClippingRegion(0); + if(src.IsValid() && dest.IsValid()) + mView->CopyBits(src, dest); + + invalid.Exclude(dest); + + for(BView *child = mView->ChildAt(0); child; child = child->NextSibling()) + child->MoveBy(aDx, aDy); + + // scan through rects and paint them directly + // so we avoid going through the callback stuff + int32 rects = invalid.CountRects(); + for(int32 i = 0; i < rects; i++) + { + BRect curr = invalid.RectAt(i); + nsRect r; + r.x = (nscoord)curr.left; + r.y = (nscoord)curr.top; + r.width = (nscoord)curr.Width() + 1; + r.height = (nscoord)curr.Height() + 1; + OnPaint(r); + } + + mView->UnlockLooper(); + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Every function that needs a thread switch goes through this function +// by calling SendMessage (..WM_CALLMETHOD..) in nsToolkit::CallMethod. +// +//------------------------------------------------------------------------- +bool nsWindow::CallMethod(MethodInfo *info) +{ + bool bRet = TRUE; + + switch (info->methodId) { + case nsWindow::CREATE: + 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]), + (nsIAppShell *)(info->args[4]), + (nsIToolkit*)(info->args[5]), + (nsWidgetInitData*)(info->args[6])); + break; + + case nsWindow::CREATE_NATIVE: + 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]), + (nsIAppShell *)(info->args[4]), + (nsIToolkit*)(info->args[5]), + (nsWidgetInitData*)(info->args[6])); + return TRUE; + + case nsWindow::DESTROY: + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + Destroy(); + break; + + case nsWindow::CLOSEWINDOW : + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + DispatchStandardEvent(NS_DESTROY); + break; + + case nsWindow::SET_FOCUS: + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + SetFocus(); + break; + + case nsWindow::ONMOUSE : + NS_ASSERTION(info->nArgs == 5, "Wrong number of arguments to CallMethod"); + DispatchMouseEvent(((int32 *)info->args)[0], + nsPoint(((int32 *)info->args)[1], ((int32 *)info->args)[2]), + ((int32 *)info->args)[3], + ((int32 *)info->args)[4]); + break; + + case nsWindow::ONKEY : + NS_ASSERTION(info->nArgs == 4, "Wrong number of arguments to CallMethod"); + OnKey(((int32 *)info->args)[0], + (const char *)(&((uint32 *)info->args)[1]), ((int32 *)info->args)[2], + ((uint32 *)info->args)[3]); + break; + + case nsWindow::ONPAINT : + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + if(mView && mView->LockLooper()) + { + nsRect r; + nsViewBeOS *bv = dynamic_cast(mView); + if(bv && bv->GetPaintRect(r)) + OnPaint(r); + mView->UnlockLooper(); + } + break; + + case nsWindow::ONRESIZE : + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + if(mView && mView->LockLooper()) + { + nsRect r; + nsViewBeOS *bv = dynamic_cast(mView); + if(bv && bv->GetSizeRect(r)) + { + // have to disable frame events otherwise we'll be notified + // of the mozilla internals forced resize + mView->SetFlags(mView->Flags() & ~B_FRAME_EVENTS); + OnResize(r); + mView->SetFlags(mView->Flags() | B_FRAME_EVENTS); + } + mView->UnlockLooper(); + } + break; + + case nsWindow::ONSCROLL: + NS_ASSERTION(info->nArgs == 0, "Wrong number of arguments to CallMethod"); + OnScroll(); + break; + + case nsWindow::BTNCLICK : + NS_ASSERTION(info->nArgs == 5, "Wrong number of arguments to CallMethod"); + DispatchMouseEvent(((int32 *)info->args)[0], + nsPoint(((int32 *)info->args)[1], ((int32 *)info->args)[2]), + ((int32 *)info->args)[3], + ((int32 *)info->args)[4]); + break; + + case nsWindow::MENU : + NS_ASSERTION(info->nArgs == 1, "Wrong number of arguments to CallMethod"); + { + nsIMenuListener *menuListener = nsnull; + nsIMenuItem *menuItem = (nsIMenuItem *)(info->args[0]); + + nsMenuEvent mevent; + mevent.message = NS_MENU_SELECTED; + mevent.eventStructType = NS_MENU_EVENT; + mevent.point.x = 0; + mevent.point.y = 0; + menuItem->GetTarget(mevent.widget); + menuItem->GetCommand(mevent.mCommand); + + mevent.mMenuItem = menuItem; + mevent.time = PR_IntervalNow(); + + //nsEventStatus status; + // FIXME - THIS SHOULD WORK. FIX EVENTS FOR XP CODE!!!!! (pav) + // mevent.widget->DispatchEvent((nsGUIEvent *)&mevent, status); + + menuItem->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if(menuListener) + { + menuListener->MenuSelected(mevent); + NS_IF_RELEASE(menuListener); + } + } + break; + + default: + bRet = FALSE; + break; + } + + return bRet; +} + +//------------------------------------------------------------------------- +// +// OnKey +// +//------------------------------------------------------------------------- +PRBool nsWindow::OnKey(PRUint32 aEventType, const char *bytes, int32 numBytes, PRUint32 mod) +{ + if(numBytes == 1) + { + nsKeyEvent event; + InitEvent(event, aEventType); + +printf("nsWindow::OnKey - FIXME: keycode translation incomplete\n"); + event.charCode = bytes[0]; + + char c = bytes[0]; + if(numBytes == 1 && (c == 10 || c == 13)) + c = NS_VK_RETURN; + + event.keyCode = c; + event.isShift = mod & B_SHIFT_KEY; + event.isControl = mod & B_CONTROL_KEY; + event.isAlt = mod & B_COMMAND_KEY; + event.eventStructType = NS_KEY_EVENT; + + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + return result; + } + else + { + printf("nsWindow::OnKey - FIXME: handle non ASCII chars\n"); + return NS_OK; + } +} + +#if 0 +//------------------------------------------------------------------------- +// +// OnKey +// +//------------------------------------------------------------------------- + +PRBool nsWindow::OnKey(PRUint32 aEventType, uint32 nChar, uint32 nRepCnt, uint32 nFlags) +{ + if (nChar == NS_VK_CAPS_LOCK || + nChar == NS_VK_ALT || + nChar == NS_VK_SHIFT || + nChar == NS_VK_CONTROL) { + return FALSE; + } + + nsKeyEvent event; + nsPoint point; + + point.x = 0; + point.y = 0; + + InitEvent(event, aEventType, &point); + + // Now let windows do the conversion to the ascii code + WORD asciiChar = 0; + BYTE kbstate[256]; + ::GetKeyboardState(kbstate); + ToAscii(nChar, nFlags & 0xff, kbstate, &asciiChar, 0); + + event.keyCode = nChar; + event.charCode = (char)asciiChar; + + event.isShift = mIsShiftDown; + event.isControl = mIsControlDown; + event.isAlt = mIsAltDown; + event.eventStructType = NS_KEY_EVENT; + + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + return result; +} +#endif + +#if 0 +//------------------------------------------------------------------------- +nsIMenuItem * nsWindow::FindMenuItem(nsIMenu * aMenu, PRUint32 aId) +{ + PRUint32 i, count; + aMenu->GetItemCount(count); + for (i=0;iGetItemAt(i, item); + if (NS_OK == item->QueryInterface(kIMenuItemIID, (void **)&menuItem)) { + if (((nsMenuItem *)menuItem)->GetCmdId() == (PRInt32)aId) { + NS_RELEASE(item); + return menuItem; + } + } else if (NS_OK == item->QueryInterface(kIMenuIID, (void **)&menu)) { + nsIMenuItem * fndItem = FindMenuItem(menu, aId); + NS_RELEASE(menu); + if (nsnull != fndItem) { + NS_RELEASE(item); + return fndItem; + } + } + NS_RELEASE(item); + } + return nsnull; +} + +//------------------------------------------------------------------------- +static nsIMenuItem * FindMenuChild(nsIMenu * aMenu, PRInt32 aId) +{ + PRUint32 i, count; + aMenu->GetItemCount(count); + for (i=0;iGetItemAt(i, item); + nsIMenuItem * menuItem; + if (NS_OK == item->QueryInterface(kIMenuItemIID, (void **)&menuItem)) { + if (((nsMenuItem *)menuItem)->GetCmdId() == (PRInt32)aId) { + NS_RELEASE(item); + return menuItem; + } + } + NS_RELEASE(item); + } + return nsnull; +} + + +//------------------------------------------------------------------------- +nsIMenu * nsWindow::FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth) +{ + if (aNativeMenu == ((nsMenu *)aMenu)->GetNativeMenu()) { + NS_ADDREF(aMenu); + return aMenu; + } + + aDepth++; + PRUint32 i, count; + aMenu->GetItemCount(count); + for (i=0;iGetItemAt(i, item); + nsIMenu * menu; + if (NS_OK == item->QueryInterface(kIMenuIID, (void **)&menu)) { + HMENU nativeMenu = ((nsMenu *)menu)->GetNativeMenu(); + if (nativeMenu == aNativeMenu) { + return menu; + } else { + nsIMenu * fndMenu = FindMenu(menu, aNativeMenu, aDepth); + if (fndMenu) { + NS_RELEASE(item); + NS_RELEASE(menu); + return fndMenu; + } + } + NS_RELEASE(menu); + } + NS_RELEASE(item); + } + return nsnull; +} + +//------------------------------------------------------------------------- +static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent) +{ + if (nsnull != aCurrentMenu) { + nsIMenuListener * listener; + if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) { + listener->MenuDeselected(aEvent); + NS_RELEASE(listener); + } + } + + if (nsnull != aNewMenu) { + nsIMenuListener * listener; + if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) { + listener->MenuSelected(aEvent); + NS_RELEASE(listener); + } + } +} + + +//------------------------------------------------------------------------- +nsresult nsWindow::MenuHasBeenSelected(HMENU aNativeMenu, UINT aItemNum, UINT aFlags, UINT aCommand) +{ + nsMenuEvent event; + event.mCommand = aCommand; + event.eventStructType = NS_MENU_EVENT; + InitEvent(event, NS_MENU_SELECTED); + + // The MF_POPUP flag tells us if we are a menu item or a menu + // the aItemNum is either the command ID of the menu item or + // the position of the menu as a child pf its parent + PRBool isMenuItem = !(aFlags & MF_POPUP); + + // uItem is the position of the item that was clicked + // aNativeMenu is a handle to the menu that was clicked + + // if aNativeMenu is NULL then the menu is being deselected + if (!aNativeMenu) { + printf("///////////// Menu is NULL!\n"); + // check to make sure something had been selected + AdjustMenus(mHitMenu, nsnull, event); + NS_IF_RELEASE(mHitMenu); + // Clear All SubMenu items + while (mHitSubMenus->Count() > 0) { + PRUint32 inx = mHitSubMenus->Count()-1; + nsIMenu * menu = (nsIMenu *)mHitSubMenus->ElementAt(inx); + AdjustMenus(menu, nsnull, event); + NS_RELEASE(menu); + mHitSubMenus->RemoveElementAt(inx); + } + return NS_OK; + } else { // The menu is being selected + void * voidData; + mMenuBar->GetNativeData(voidData); + HMENU nativeMenuBar = (HMENU)voidData; + + // first check to see if it is a member of the menubar + nsIMenu * hitMenu = nsnull; + if (aNativeMenu == nativeMenuBar) { + mMenuBar->GetMenuAt(aItemNum, hitMenu); + if (mHitMenu != hitMenu) { + AdjustMenus(mHitMenu, hitMenu, event); + NS_IF_RELEASE(mHitMenu); + mHitMenu = hitMenu; + } else { + NS_IF_RELEASE(hitMenu); + } + } else { + // At this point we know we are inside a menu + + // Find the menu we are in (the parent menu) + nsIMenu * parentMenu = nsnull; + PRInt32 fndDepth = 0; + PRUint32 i, count; + mMenuBar->GetMenuCount(count); + for (i=0;iGetMenuAt(i, menu); + PRInt32 depth = 0; + parentMenu = FindMenu(menu, aNativeMenu, depth); + if (parentMenu) { + fndDepth = depth; + break; + } + NS_RELEASE(menu); + } + + if (nsnull != parentMenu) { + + // Sometimes an event comes through for a menu that is being popup down + // So it its depth is great then the current hit list count it already gone. + if (fndDepth > mHitSubMenus->Count()) { + NS_RELEASE(parentMenu); + return NS_OK; + } + + nsIMenu * newMenu = nsnull; + + // Skip if it is a menu item, otherwise, we get the menu by position + if (!isMenuItem) { + printf("Getting submenu by position %d from parentMenu\n", aItemNum); + nsISupports * item; + parentMenu->GetItemAt((PRUint32)aItemNum, item); + if (NS_OK != item->QueryInterface(kIMenuIID, (void **)&newMenu)) { + printf("Item was not a menu! What are we doing here? Return early....\n"); + return NS_ERROR_FAILURE; + } + } + + // Figure out if this new menu is in the list of popup'ed menus + PRBool newFound = PR_FALSE; + PRInt32 newLevel = 0; + for (newLevel=0;newLevelCount();newLevel++) { + if (newMenu == (nsIMenu *)mHitSubMenus->ElementAt(newLevel)) { + newFound = PR_TRUE; + break; + } + } + + // Figure out if the parent menu is in the list of popup'ed menus + PRBool found = PR_FALSE; + PRInt32 level = 0; + for (level=0;levelCount();level++) { + if (parentMenu == (nsIMenu *)mHitSubMenus->ElementAt(level)) { + found = PR_TRUE; + break; + } + } + + // So now figure out were we are compared to the hit list depth + // we figure out how many items are open below + // + // If the parent was found then we use it + // if the parent was NOT found this means we are at the very first level (menu from the menubar) + // Windows will send an event for a parent AND child that is already in the hit list + // and we think we should be popping it down. So we check to see if the + // new menu is already in the tree so it doesn't get removed and then added. + PRInt32 numToRemove = 0; + if (found) { + numToRemove = mHitSubMenus->Count() - level - 1; + } else { + // This means we got a menu event for a menubar menu + if (newFound) { // newFound checks to see if the new menu to be added is already in the hit list + numToRemove = mHitSubMenus->Count() - newLevel - 1; + } else { + numToRemove = mHitSubMenus->Count(); + } + } + + // If we are to remove 1 item && the new menu to be added is the + // same as the one we would be removing, then don't remove it. + if (numToRemove == 1 && newMenu == (nsIMenu *)mHitSubMenus->ElementAt(mHitSubMenus->Count()-1)) { + numToRemove = 0; + } + + // Now loop thru and removing the menu from thre list + PRInt32 ii; + for (ii=0;iiElementAt(mHitSubMenus->Count()-1 ); + AdjustMenus(m, nsnull, event); + nsString name; + m->GetLabel(name); + NS_RELEASE(m); + mHitSubMenus->RemoveElementAt(mHitSubMenus->Count()-1); + } + + // At this point we bail if we are a menu item + if (isMenuItem) { + return NS_OK; + } + + // Here we know we have a menu, check one last time to see + // if the new one is the last one in the list + // Add it if it isn't or skip adding it + nsString name; + newMenu->GetLabel(name); + if (newMenu != (nsIMenu *)mHitSubMenus->ElementAt(mHitSubMenus->Count()-1)) { + mHitSubMenus->AppendElement(newMenu); + NS_ADDREF(newMenu); + AdjustMenus(nsnull, newMenu, event); + } + + NS_RELEASE(parentMenu); + } else { + printf("no menu was found. This is bad.\n"); + // XXX need to assert here! + } + } + } + return NS_OK; +} +#endif + +//--------------------------------------------------------- +NS_METHOD nsWindow::EnableFileDrop(PRBool aEnable) +{ +#if 0 + ::DragAcceptFiles(mView, (aEnable?TRUE:FALSE)); +#endif + return NS_OK; +} + +#if 0 +//------------------------------------------------------------------------- +// +// Process all nsWindows messages +// +//------------------------------------------------------------------------- +PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue) +{ + static BOOL firstTime = TRUE; // for mouse wheel logic + static int iDeltaPerLine, iAccumDelta ; // for mouse wheel logic + ULONG ulScrollLines ; // for mouse wheel logic + + PRBool result = PR_FALSE; // call the default nsWindow proc + nsPaletteInfo palInfo; + *aRetValue = 0; + + switch (msg) { + + case WM_COMMAND: { + WORD wNotifyCode = HIWORD(wParam); // notification code + if (wNotifyCode == 0) { // Menu selection + nsMenuEvent event; + event.mCommand = LOWORD(wParam); + event.eventStructType = NS_MENU_EVENT; + InitEvent(event, NS_MENU_SELECTED); + result = DispatchWindowEvent(&event); + if (mMenuBar) { + PRUint32 i, count; + mMenuBar->GetMenuCount(count); + for (i=0;iGetMenuAt(i, menu); + nsIMenuItem * menuItem = FindMenuItem(menu, event.mCommand); + if (menuItem) { + nsIMenuListener * listener; + if (NS_OK == menuItem->QueryInterface(kIMenuListenerIID, (void **)&listener)) { + listener->MenuSelected(event); + NS_RELEASE(listener); + } + NS_RELEASE(menuItem); + } + NS_RELEASE(menu); + } + } + NS_RELEASE(event.widget); + } + } + break; + + + case WM_NOTIFY: + // TAB change + { + LPNMHDR pnmh = (LPNMHDR) lParam; + + switch (pnmh->code) { + case TCN_SELCHANGE: { + DispatchStandardEvent(NS_TABCHANGE); + result = PR_TRUE; + } + break; + + case TTN_SHOW: { + nsTooltipEvent event; + InitEvent(event, NS_SHOW_TOOLTIP); + event.tipIndex = (PRUint32)wParam; + event.eventStructType = NS_TOOLTIP_EVENT; + result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + } + break; + + case TTN_POP: + result = DispatchStandardEvent(NS_HIDE_TOOLTIP); + break; + } + } + break; + + case WM_MOVE: // Window moved + { + PRInt32 x = (PRInt32)LOWORD(lParam); // horizontal position in screen coordinates + PRInt32 y = (PRInt32)HIWORD(lParam); // vertical position in screen coordinates + result = OnMove(x, y); + } + break; + + case WM_DESTROY: + // clean up. + OnDestroy(); + result = PR_TRUE; + break; + + case WM_PAINT: + result = OnPaint(); + break; + + case WM_KEYUP: + + mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT); + mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL); + mIsAltDown = IS_VK_DOWN(NS_VK_ALT); + { + LONG data = (LONG)lParam; + LONG newdata = (data & 0x00FF00); + //LONG newdata2 = (data & 0xFFFF00F); + int x = 0; + } + result = OnKey(NS_KEY_UP, wParam, LOWORD(lParam), HIWORD(lParam)); + break; + + case WM_KEYDOWN: + + mIsShiftDown = IS_VK_DOWN(NS_VK_SHIFT); + mIsControlDown = IS_VK_DOWN(NS_VK_CONTROL); + mIsAltDown = IS_VK_DOWN(NS_VK_ALT); + + result = OnKey(NS_KEY_DOWN, wParam, LOWORD(lParam), HIWORD(lParam)); + break; + + // say we've dealt with erase background if widget does + // not need auto-erasing + case WM_ERASEBKGND: + if (! AutoErase()) { + *aRetValue = 1; + result = PR_TRUE; + } + break; + + case WM_MOUSEMOVE: + //RelayMouseEvent(msg,wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_MOVE); + break; + + case WM_LBUTTONDOWN: + //RelayMouseEvent(msg,wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_DOWN); + break; + + case WM_LBUTTONUP: + //RelayMouseEvent(msg,wParam, lParam); + result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_UP); + break; + + case WM_LBUTTONDBLCLK: + result = DispatchMouseEvent(NS_MOUSE_LEFT_BUTTON_DOWN); + if (result == PR_FALSE) + result = DispatchMouseEvent(NS_MOUSE_LEFT_DOUBLECLICK); + break; + + case WM_MBUTTONDOWN: + result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN); + break; + + case WM_MBUTTONUP: + result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_UP); + break; + + case WM_MBUTTONDBLCLK: + result = DispatchMouseEvent(NS_MOUSE_MIDDLE_BUTTON_DOWN); + break; + + case WM_RBUTTONDOWN: + result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN); + break; + + case WM_RBUTTONUP: + result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_UP); + break; + + case WM_RBUTTONDBLCLK: + result = DispatchMouseEvent(NS_MOUSE_RIGHT_BUTTON_DOWN); + if (result == PR_FALSE) + result = DispatchMouseEvent(NS_MOUSE_RIGHT_DOUBLECLICK); + break; + + case WM_HSCROLL: + case WM_VSCROLL: + // check for the incoming nsWindow handle to be null in which case + // we assume the message is coming from a horizontal scrollbar inside + // a listbox and we don't bother processing it (well, we don't have to) + if (lParam) { + nsWindow* scrollbar = (nsWindow*)::GetWindowLong((BWindow *)lParam, GWL_USERDATA); + + if (scrollbar) { + result = scrollbar->OnScroll(LOWORD(wParam), (short)HIWORD(wParam)); + } + } + break; + + case WM_CTLCOLORLISTBOX: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORBTN: + //case WM_CTLCOLORSCROLLBAR: //XXX causes a the scrollbar to be drawn incorrectly + case WM_CTLCOLORSTATIC: + if (lParam) { + nsWindow* control = (nsWindow*)::GetWindowLong((BWindow *)lParam, GWL_USERDATA); + if (control) { + control->SetUpForPaint((HDC)wParam); + *aRetValue = (LPARAM)control->OnControlColor(); + } + } + + result = PR_TRUE; + break; + + case WM_SETFOCUS: + result = DispatchFocus(NS_GOTFOCUS); + break; + + case WM_KILLFOCUS: + result = DispatchFocus(NS_LOSTFOCUS); + break; + + case WM_WINDOWPOSCHANGED: + { + WINDOWPOS *wp = (LPWINDOWPOS)lParam; + + // We only care about a resize, so filter out things like z-order + // changes. Note: there's a WM_MOVE handler above which is why we're + // not handling them here... + if (0 == (wp->flags & SWP_NOSIZE)) { + // XXX Why are we using the client size area? If the size notification + // is for the client area then the origin should be (0,0) and not + // the window origin in screen coordinates... + RECT r; + ::GetWindowRect(mView, &r); + PRInt32 newWidth, newHeight; + newWidth = PRInt32(r.right - r.left); + newHeight = PRInt32(r.bottom - r.top); + nsRect rect(wp->x, wp->y, newWidth, newHeight); + //if (newWidth != mBounds.width) + { + RECT drect; + + //getting wider + + drect.left = wp->x + mBounds.width; + drect.top = wp->y; + drect.right = drect.left + (newWidth - mBounds.width); + drect.bottom = drect.top + newHeight; + +// ::InvalidateRect(mView, NULL, FALSE); +// ::InvalidateRect(mView, &drect, FALSE); + ::RedrawWindow(mView, &drect, NULL, + RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN); + } + //if (newHeight != mBounds.height) + { + RECT drect; + + //getting taller + + drect.left = wp->x; + drect.top = wp->y + mBounds.height; + drect.right = drect.left + newWidth; + drect.bottom = drect.top + (newHeight - mBounds.height); + +// ::InvalidateRect(mView, NULL, FALSE); +// ::InvalidateRect(mView, &drect, FALSE); + ::RedrawWindow(mView, &drect, NULL, + RDW_INVALIDATE | RDW_NOERASE | RDW_NOINTERNALPAINT | RDW_ERASENOW | RDW_ALLCHILDREN); + } + mBounds.width = newWidth; + mBounds.height = newHeight; + ///nsRect rect(wp->x, wp->y, wp->cx, wp->cy); + + // recalculate the width and height + // this time based on the client area + if (::GetClientRect(mView, &r)) { + rect.width = PRInt32(r.right - r.left); + rect.height = PRInt32(r.bottom - r.top); + } + result = OnResize(rect); + } + break; + } +#if 0 // these are needed for now + case WM_INITMENU: { + printf("WM_INITMENU\n"); + } break; + + case WM_INITMENUPOPUP: { + printf("WM_INITMENUPOPUP\n"); + } break; +#endif + +#if 0 + case WM_MENUSELECT: + if (mMenuBar) { + MenuHasBeenSelected((HMENU)lParam, (UINT)LOWORD(wParam), (UINT)HIWORD(wParam), (UINT) LOWORD(wParam)); + } + break; +#endif + + case WM_SETTINGCHANGE: + firstTime = TRUE; + // Fall through + case WM_MOUSEWHEEL: { + if (firstTime) { + firstTime = FALSE; + //printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ WM_SETTINGCHANGE\n"); + SystemParametersInfo (104, 0, &ulScrollLines, 0) ; + //SystemParametersInfo (SPI_GETWHEELSCROLLLINES, 0, &ulScrollLines, 0) ; + + // ulScrollLines usually equals 3 or 0 (for no scrolling) + // WHEEL_DELTA equals 120, so iDeltaPerLine will be 40 + + if (ulScrollLines) + iDeltaPerLine = WHEEL_DELTA / ulScrollLines ; + else + iDeltaPerLine = 0 ; + //printf("ulScrollLines %d iDeltaPerLine %d\n", ulScrollLines, iDeltaPerLine); + + if (msg == WM_SETTINGCHANGE) { + return 0; + } + } + BWindow * scrollbar = NULL; + if (nsnull != mVScrollbar) { + scrollbar = (BWindow *)mVScrollbar->GetNativeData(NS_NATIVE_WINDOW); + } + if (scrollbar) { + if (iDeltaPerLine == 0) + break ; + + iAccumDelta += (short) HIWORD (wParam) ; // 120 or -120 + + while (iAccumDelta >= iDeltaPerLine) { + //printf("iAccumDelta %d\n", iAccumDelta); + SendMessage (mView, WM_VSCROLL, SB_LINEUP, (LONG)scrollbar) ; + iAccumDelta -= iDeltaPerLine ; + } + + while (iAccumDelta <= -iDeltaPerLine) { + //printf("iAccumDelta %d\n", iAccumDelta); + SendMessage (mView, WM_VSCROLL, SB_LINEDOWN, (LONG)scrollbar) ; + iAccumDelta += iDeltaPerLine ; + } + } + return 0 ; + } break; + + +#if 0 + case WM_PALETTECHANGED: + if ((BWindow *)wParam == mView) { + // We caused the WM_PALETTECHANGED message so avoid realizing + // another foreground palette + result = PR_TRUE; + break; + } + // fall thru... + + case WM_QUERYNEWPALETTE: + mContext->GetPaletteInfo(palInfo); + if (palInfo.isPaletteDevice && palInfo.palette) { + HDC hDC = ::GetDC(mView); + HPALETTE hOldPal = ::SelectPalette(hDC, (HPALETTE)palInfo.palette, FALSE); + + // Realize the drawing palette + int i = ::RealizePalette(hDC); + + // Did any of our colors change? + if (i > 0) { + // Yes, so repaint + ::InvalidateRect(mView, (LPRECT)NULL, TRUE); + } + + ::SelectPalette(hDC, hOldPal, TRUE); + ::RealizePalette(hDC); + ::ReleaseDC(mView, hDC); + *aRetValue = TRUE; + } + result = PR_TRUE; + break; + + case WM_DROPFILES: { + HDROP hDropInfo = (HDROP) wParam; + UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0); + + for (UINT iFile = 0; iFile < nFiles; iFile++) { + TCHAR szFileName[_MAX_PATH]; + ::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH); + printf("szFileName [%s]\n", szFileName); + nsAutoString fileStr(szFileName); + nsEventStatus status; + nsDragDropEvent event; + InitEvent(event, NS_DRAGDROP_EVENT); + event.mType = nsDragDropEventStatus_eDrop; + event.mIsFileURL = PR_FALSE; + event.mURL = (PRUnichar *)fileStr.GetUnicode(); + DispatchEvent(&event, status); + } + } break; +#endif + } + + return result; +} +#endif + + +//------------------------------------------------------------------------- +// +// WM_DESTROY has been called +// +//------------------------------------------------------------------------- +void nsWindow::OnDestroy() +{ + mOnDestroyCalled = PR_TRUE; + +#if 0 + // free tooltip window + if (mTooltip) { + VERIFY(::DestroyWindow(mTooltip)); + mTooltip = NULL; + } +#endif + + // release references to children, device context, toolkit, and app shell + nsBaseWidget::OnDestroy(); + + // dispatch the event + if (!mIsDestroying) { + // dispatching of the event may cause the reference count to drop to 0 + // and result in this object being destroyed. To avoid that, add a reference + // and then release it after dispatching the event + AddRef(); + DispatchStandardEvent(NS_DESTROY); + Release(); + } +} + +//------------------------------------------------------------------------- +// +// Move +// +//------------------------------------------------------------------------- +PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY) +{ + nsGUIEvent event; + InitEvent(event, NS_MOVE); + event.point.x = aX; + event.point.y = aY; + event.eventStructType = NS_GUI_EVENT; + + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + return result; +} + +//------------------------------------------------------------------------- +// +// Paint +// +//------------------------------------------------------------------------- +PRBool nsWindow::OnPaint(nsRect &r) +{ + PRBool result = PR_TRUE; + + if((r.width || r.height) && mEventCallback) + { + if(mView && mView->LockLooper()) + { + // set clipping + BRegion invalid; + invalid.Include(BRect(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1)); + mView->ConstrainClippingRegion(&invalid); + + nsPaintEvent event; + + InitEvent(event, NS_PAINT); + event.rect = &r; + event.eventStructType = NS_PAINT_EVENT; + + static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); + static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID); + + if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID, nsnull, kRenderingContextIID, (void **)&event.renderingContext)) + { + event.renderingContext->Init(mContext, this); + result = DispatchWindowEvent(&event); + + NS_RELEASE(event.renderingContext); + } + else + result = PR_FALSE; + + NS_RELEASE(event.widget); + + mView->UnlockLooper(); + } + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// Send a resize message to the listener +// +//------------------------------------------------------------------------- +PRBool nsWindow::OnResize(nsRect &aWindowRect) +{ + // call the event callback + if (mEventCallback) + { + nsSizeEvent event; + InitEvent(event, NS_SIZE); + event.windowSize = &aWindowRect; + event.eventStructType = NS_SIZE_EVENT; + if(mView && mView->LockLooper()) + { + BRect r = mView->Bounds(); + event.mWinWidth = PRInt32(r.right - r.left); + event.mWinHeight = PRInt32(r.bottom - r.top); + mView->UnlockLooper(); + } else { + event.mWinWidth = 0; + event.mWinHeight = 0; + } + PRBool result = DispatchWindowEvent(&event); + NS_RELEASE(event.widget); + return result; + } + + return PR_FALSE; +} + + + +//------------------------------------------------------------------------- +// +// Deal with all sort of mouse event +// +//------------------------------------------------------------------------- +PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod) +{ + if(nsnull != mEventCallback || nsnull != mMouseListener) + { + nsMouseEvent event; + InitEvent(event, aEventType, &aPoint); + event.isShift = mod & B_SHIFT_KEY; + event.isControl = mod & B_CONTROL_KEY; + event.isAlt = mod & B_COMMAND_KEY; + event.clickCount = clicks; + event.eventStructType = NS_MOUSE_EVENT; + + // call the event callback + if(nsnull != mEventCallback) + return DispatchWindowEvent(&event); + else + { + switch(aEventType) + { + case NS_MOUSE_MOVE : + mMouseListener->MouseMoved(event); + break; + + case NS_MOUSE_LEFT_BUTTON_DOWN : + case NS_MOUSE_MIDDLE_BUTTON_DOWN : + case NS_MOUSE_RIGHT_BUTTON_DOWN : + mMouseListener->MousePressed(event); + break; + + case NS_MOUSE_LEFT_BUTTON_UP : + case NS_MOUSE_MIDDLE_BUTTON_UP : + case NS_MOUSE_RIGHT_BUTTON_UP : + mMouseListener->MouseReleased(event); + mMouseListener->MouseClicked(event); + break; + } + } + NS_RELEASE(event.widget); + } + + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Deal with focus messages +// +//------------------------------------------------------------------------- +PRBool nsWindow::DispatchFocus(PRUint32 aEventType) +{ + // call the event callback + if (mEventCallback) { + return(DispatchStandardEvent(aEventType)); + } + + return PR_FALSE; +} + + +//------------------------------------------------------------------------- +// +// Deal with scrollbar messages (actually implemented only in nsScrollbar) +// +//------------------------------------------------------------------------- +PRBool nsWindow::OnScroll() +{ + return PR_FALSE; +} + +NS_METHOD nsWindow::SetTitle(const nsString& aTitle) +{ + const char *text = aTitle.ToNewCString(); + if(text && mView->LockLooper()) + { + mView->Window()->SetTitle(text); + mView->UnlockLooper(); + } + delete [] text; + return NS_OK; +} + + +PRBool nsWindow::AutoErase() +{ + return(PR_FALSE); +} + +NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) +{ + BMenuBar *menubar; + void *data; + aMenuBar->GetNativeData(data); + menubar = (BMenuBar *)data; + + if(mView && mView->LockLooper()) + { + mView->Window()->AddChild(menubar); + float sz = menubar->Bounds().Height() + 1; + + // FIXME: this is probably not correct, but seems to work ok; + // I think only the first view should be moved/resized... + for(BView *v = mView->Window()->ChildAt(0); v; v = v->NextSibling()) + if(v != menubar) + { + v->ResizeBy(0, -sz); + v->MoveBy(0, sz); + } + mView->UnlockLooper(); + } + + return NS_OK; +} + +NS_METHOD nsWindow::ShowMenuBar(PRBool aShow) +{ +printf("nsWindow::ShowMenuBar - FIXME: not implemented!\n"); +// if (!mMenuBar) +// // return NS_ERROR_FAILURE; +// return NS_OK; +// +// GtkWidget *menubar; +// void *voidData; +// mMenuBar->GetNativeData(voidData); +// menubar = GTK_WIDGET(voidData); +// +// if (aShow == PR_TRUE) +// gtk_widget_show(menubar); +// else +// gtk_widget_hide(menubar); +// +// return NS_OK; +} + +NS_METHOD nsWindow::IsMenuBarVisible(PRBool *aVisible) +{ + *aVisible = PR_TRUE; + return NS_ERROR_FAILURE; // todo: (maybe. method isn't actually used yet.) +} + +NS_METHOD nsWindow::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) +{ + aWidth = mPreferredWidth; + aHeight = mPreferredHeight; + return NS_ERROR_FAILURE; +} + +NS_METHOD nsWindow::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) +{ + mPreferredWidth = aWidth; + mPreferredHeight = aHeight; + return NS_OK; +} + +//---------------------------------------------------- +// Special Sub-Class +//---------------------------------------------------- +nsIWidgetStore::nsIWidgetStore( nsIWidget *aWidget ) + : mWidget( aWidget ) +{ + NS_ADDREF(mWidget); +} + +nsIWidgetStore::~nsIWidgetStore() +{ + NS_RELEASE(mWidget); +} + +nsIWidget *nsIWidgetStore::GetMozillaWidget(void) +{ + return mWidget; +} + +//---------------------------------------------------- +// BeOS Sub-Class Window +//---------------------------------------------------- + +nsWindowBeOS::nsWindowBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, window_look aLook, + window_feel aFeel, int32 aFlags, int32 aWorkspace ) + : BWindow( aFrame, aName, aLook, aFeel, aFlags, aWorkspace ), + nsIWidgetStore( aWidgetWindow ) +{ +} + +bool nsWindowBeOS::QuitRequested( void ) +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + if(ChildAt(0)) + RemoveChild(ChildAt(0)); + MethodInfo *info = new MethodInfo(w, w, nsWindow::CLOSEWINDOW); + t->CallMethodAsync(info); + NS_RELEASE(t); + } + return true; +} + +void nsWindowBeOS::MessageReceived(BMessage *msg) +{ + switch(msg->what) + { + case 'menu' : + { + nsIMenuItem *menuItem; + if(msg->FindPointer("nsMenuItem", (void **)&menuItem) == B_OK && + menuItem != NULL) + { + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 args[1]; + args[0] = (uint32)menuItem; + MethodInfo *info = new MethodInfo(w, w, nsWindow::MENU, 1, args); + t->CallMethodAsync(info); + NS_RELEASE(t); + } + } + } + break; + + default : + BWindow::MessageReceived(msg); + break; + } +} + +//---------------------------------------------------- +// BeOS Sub-Class View +//---------------------------------------------------- + +nsViewBeOS::nsViewBeOS(nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, uint32 aResizingMode, uint32 aFlags) + : BView(aFrame, aName, aResizingMode, aFlags), nsIWidgetStore(aWidgetWindow), buttons(0), currsizechanged(false) +{ +} + +void nsViewBeOS::AttachedToWindow() +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + SetHighColor(255, 255, 255); + FillRect(Bounds()); + if(! w->AutoErase()) + // view shouldn't erase + SetViewColor(B_TRANSPARENT_32_BIT); +} + +void nsViewBeOS::Draw(BRect updateRect) +{ + paintregion.Include(updateRect); + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONPAINT); + t->CallMethodAsync(info); + NS_RELEASE(t); + } +} + +bool nsViewBeOS::GetPaintRect(nsRect &r) +{ + if(paintregion.CountRects() == 0) + return false; + BRect paint = paintregion.Frame(); + r.x = (nscoord)paint.left; + r.y = (nscoord)paint.top; + r.width = (nscoord)(paint.Width() + 1); + r.height = (nscoord)(paint.Height() + 1); + paintregion.MakeEmpty(); + return true; +} + +void nsViewBeOS::FrameResized(float width, float height) +{ + currsizerect.x = (nscoord)Bounds().left; + currsizerect.y = (nscoord)Bounds().top; + currsizerect.width = (nscoord)width; + currsizerect.height = (nscoord)height; + currsizechanged = true; + + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONRESIZE); + t->CallMethodAsync(info); + NS_RELEASE(t); + } +} + +bool nsViewBeOS::GetSizeRect(nsRect &r) +{ + if(! currsizechanged) + return false; + r = currsizerect; + currsizechanged = false; + return true; +} + +void nsViewBeOS::MouseDown(BPoint point) +{ + SetMouseEventMask(B_POINTER_EVENTS | B_KEYBOARD_EVENTS); + + uint32 clicks = 0; + Window()->CurrentMessage()->FindInt32("buttons", (int32 *)&buttons); + Window()->CurrentMessage()->FindInt32("clicks", (int32 *)&clicks); + + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + if(buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) + { + int32 ev = (buttons & B_PRIMARY_MOUSE_BUTTON) ? NS_MOUSE_LEFT_BUTTON_DOWN : + ((buttons & B_SECONDARY_MOUSE_BUTTON) ? NS_MOUSE_RIGHT_BUTTON_DOWN : + NS_MOUSE_MIDDLE_BUTTON_DOWN); + uint32 args[5]; + args[0] = ev; + args[1] = (uint32)point.x; + args[2] = (uint32)point.y; + args[3] = clicks; + args[4] = modifiers(); + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOUSE, 5, args); + t->CallMethodAsync(info); + } + NS_RELEASE(t); + } +} + +void nsViewBeOS::MouseMoved(BPoint point, uint32 transit, const BMessage *message) +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 args[5]; + args[1] = (uint32)point.x; + args[2] = (uint32)point.y; + args[3] = 0; + args[4] = modifiers(); + + if(transit == B_ENTERED_VIEW) + { + args[0] = NS_MOUSE_ENTER; + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOUSE, 5, args); + t->CallMethodAsync(info); + } + + args[0] = NS_MOUSE_MOVE; + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOUSE, 5, args); + t->CallMethodAsync(info); + + if(transit == B_EXITED_VIEW) + { + args[0] = NS_MOUSE_EXIT; + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOUSE, 5, args); + t->CallMethodAsync(info); + } + NS_RELEASE(t); + } +} + +void nsViewBeOS::MouseUp(BPoint point) +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + if(buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON | B_TERTIARY_MOUSE_BUTTON)) + { + int32 ev = (buttons & B_PRIMARY_MOUSE_BUTTON) ? NS_MOUSE_LEFT_BUTTON_UP : + ((buttons & B_SECONDARY_MOUSE_BUTTON) ? NS_MOUSE_RIGHT_BUTTON_UP : + NS_MOUSE_MIDDLE_BUTTON_UP); + uint32 args[5]; + args[0] = ev; + args[1] = (uint32)point.x; + args[2] = (int32)point.y; + args[3] = 0; + args[4] = modifiers(); + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONMOUSE, 5, args); + t->CallMethodAsync(info); + } + NS_RELEASE(t); + } + buttons = 0; +} + +void nsViewBeOS::KeyDown(const char *bytes, int32 numBytes) +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 bytebuf = 0; + uint8 *byteptr = (uint8 *)&bytebuf; + for(int32 i = 0; i < numBytes; i++) + byteptr[i] = bytes[i]; + + uint32 args[4]; + args[0] = NS_KEY_DOWN; + args[1] = bytebuf; + args[2] = numBytes; + args[3] = modifiers(); + + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args); + t->CallMethodAsync(info); + } +} + +void nsViewBeOS::KeyUp(const char *bytes, int32 numBytes) +{ + nsWindow *w = (nsWindow *)GetMozillaWidget(); + nsToolkit *t; + if(w && (t = w->GetToolkit()) != 0) + { + uint32 bytebuf = 0; + uint8 *byteptr = (uint8 *)&bytebuf; + for(int32 i = 0; i < numBytes; i++) + byteptr[i] = bytes[i]; + + uint32 args[4]; + args[0] = NS_KEY_UP; + args[1] = (int32)bytebuf; + args[2] = numBytes; + args[3] = modifiers(); + + MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args); + t->CallMethodAsync(info); + } +} diff --git a/widget/src/beos/nsWindow.h b/widget/src/beos/nsWindow.h new file mode 100644 index 000000000000..0f177d8220f0 --- /dev/null +++ b/widget/src/beos/nsWindow.h @@ -0,0 +1,297 @@ +/* -*- 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 Window_h__ +#define Window_h__ + +#include "nsBaseWidget.h" +#include "nsdefs.h" +#include "nsObject.h" +#include "nsSwitchToUIThread.h" +#include "nsToolkit.h" + +#include "nsIWidget.h" + +#include "nsIMenuBar.h" + +#include "nsIMouseListener.h" +#include "nsIEventListener.h" +#include "nsStringUtil.h" +#include "nsString.h" + +#include "nsVoidArray.h" + +#include +#include +#include + +#define NSRGB_2_COLOREF(color) \ + RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color)) + +//#define DRAG_DROP + +// forward declaration +class nsViewBeOS; + +/** + * Native BeOS window wrapper. + */ + +class nsWindow : public nsObject, + public nsSwitchToUIThread, + public nsBaseWidget +{ + +public: + nsWindow(); + virtual ~nsWindow(); + + // nsIWidget interface + NS_IMETHOD Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell = nsnull, + nsIToolkit *aToolkit = nsnull, + nsWidgetInitData *aInitData = nsnull); + NS_IMETHOD Create(nsNativeWidget aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell = nsnull, + nsIToolkit *aToolkit = nsnull, + nsWidgetInitData *aInitData = nsnull); + + // Utility method for implementing both Create(nsIWidget ...) and + // Create(nsNativeWidget...) + + virtual nsresult StandardWindowCreate(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData, + nsNativeWidget aNativeParent = nsnull); + + NS_IMETHOD Destroy(); + virtual nsIWidget* GetParent(void); + NS_IMETHOD Show(PRBool bState); + NS_IMETHOD IsVisible(PRBool & aState); + + NS_IMETHOD Move(PRUint32 aX, PRUint32 aY); + NS_IMETHOD Resize(PRUint32 aWidth, + PRUint32 aHeight, + PRBool aRepaint); + NS_IMETHOD Resize(PRUint32 aX, + PRUint32 aY, + PRUint32 aWidth, + PRUint32 aHeight, + PRBool aRepaint); + NS_IMETHOD Enable(PRBool bState); + NS_IMETHOD SetFocus(void); + NS_IMETHOD GetBounds(nsRect &aRect); + NS_IMETHOD GetClientBounds(nsRect &aRect); + NS_IMETHOD SetBackgroundColor(const nscolor &aColor); + virtual nsIFontMetrics* GetFont(void); + NS_IMETHOD SetFont(const nsFont &aFont); + NS_IMETHOD SetCursor(nsCursor aCursor); + NS_IMETHOD Invalidate(PRBool aIsSynchronous); + NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); + NS_IMETHOD Update(); + virtual void* GetNativeData(PRUint32 aDataType); + NS_IMETHOD SetColorMap(nsColorMap *aColorMap); + NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); + NS_IMETHOD SetTitle(const nsString& aTitle); + NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); + NS_IMETHOD ShowMenuBar(PRBool aShow); + NS_IMETHOD IsMenuBarVisible(PRBool *aVisible); + NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); + NS_IMETHOD RemoveTooltips(); + NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); + NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect); + NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect); + NS_IMETHOD BeginResizingChildren(void); + NS_IMETHOD EndResizingChildren(void); + NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight); + NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight); + NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); + NS_IMETHOD EnableFileDrop(PRBool aEnable); + + virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {} + + + // nsSwitchToUIThread interface + virtual bool CallMethod(MethodInfo *info); + virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod); + virtual PRBool AutoErase(); + +// PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;} + + void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull); + +protected: + + // Allow Derived classes to modify the height that is passed + // when the window is created or resized. + virtual PRInt32 GetHeight(PRInt32 aProposedHeight); + virtual void OnDestroy(); + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsRect &r); + virtual PRBool OnResize(nsRect &aWindowRect); + virtual PRBool OnKey(PRUint32 aEventType, const char *bytes, int32 numBytes, PRUint32 mod); + + virtual PRBool DispatchFocus(PRUint32 aEventType); + virtual PRBool OnScroll(); + static PRBool ConvertStatus(nsEventStatus aStatus); + PRBool DispatchStandardEvent(PRUint32 aMsg); + void AddTooltip(BView *hwndOwner, nsRect* aRect, int aId); + + virtual PRBool DispatchWindowEvent(nsGUIEvent* event); + virtual BView *CreateBeOSView(); + +#if 0 + virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue); + nsIMenuItem * FindMenuItem(nsIMenu * aMenu, PRUint32 aId); + nsIMenu * FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth); + nsresult MenuHasBeenSelected(HMENU aNativeMenu, UINT aItemNum, UINT aFlags, UINT aCommand); + + virtual LPCTSTR WindowClass(); + virtual DWORD WindowStyle(); + virtual DWORD WindowExStyle(); + + static LRESULT CALLBACK WindowProc(BWindow * hWnd, + UINT msg, + WPARAM wParam, + LPARAM lParam); + + void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam); + + BWindow *mTooltip; +#endif + + BView *mView; + + PRBool mIsDestroying; + PRBool mOnDestroyCalled; + PRBool mIsVisible; + // XXX Temporary, should not be caching the font + nsFont * mFont; + + PRInt32 mPreferredWidth; + PRInt32 mPreferredHeight; + + nsIMenuBar * mMenuBar; + PRInt32 mMenuCmdId; + nsIMenu * mHitMenu; + nsVoidArray * mHitSubMenus; + +#if 0 + // Drag & Drop + +#ifdef DRAG_DROP + //nsDropTarget * mDropTarget; + CfDropSource * mDropSource; + CfDropTarget * mDropTarget; + CfDragDrop * mDragDrop; +#endif +#endif + +public: // public on BeOS to allow BViews to access it + // Enumeration of the methods which are accessable on the "main GUI thread" + // via the CallMethod(...) mechanism... + // see nsSwitchToUIThread + enum { + CREATE = 0x0101, + CREATE_NATIVE, + DESTROY, + SET_FOCUS, + SET_CURSOR, + CREATE_HACK, + ONMOUSE, + ONPAINT, + ONSCROLL, + ONRESIZE, + CLOSEWINDOW, + MENU, + ONKEY, + BTNCLICK + }; + nsToolkit *GetToolkit() { return (nsToolkit *)nsBaseWidget::GetToolkit(); } +}; + +// +// Each class need to subclass this as part of the subclass +// +class nsIWidgetStore { + public: + nsIWidgetStore(nsIWidget *aWindow); + virtual ~nsIWidgetStore(); + + virtual nsIWidget *GetMozillaWidget(void); + + private: + nsIWidget *mWidget; +}; + +// +// A BWindow subclass +// +class nsWindowBeOS : public BWindow, public nsIWidgetStore { + public: + nsWindowBeOS(nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, window_look aLook, + window_feel aFeel, int32 aFlags, int32 aWorkspace = B_CURRENT_WORKSPACE); + + virtual bool QuitRequested( void ); + virtual void MessageReceived(BMessage *msg); +}; + +// +// A BView subclass +// +class nsViewBeOS : public BView, public nsIWidgetStore { + BRegion paintregion; + uint32 buttons; + nsRect currsizerect; + bool currsizechanged; + +public: + nsViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, + uint32 aResizingMode, uint32 aFlags ); + + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + virtual void FrameResized(float width, float height); + virtual void MouseDown(BPoint point); + virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message); + virtual void MouseUp(BPoint point); + bool GetPaintRect(nsRect &r); + bool GetSizeRect(nsRect &r); + void KeyDown(const char *bytes, int32 numBytes); + void KeyUp(const char *bytes, int32 numBytes); +}; + +// +// A child window is a window with different style +// +class ChildWindow : public nsWindow { + public: + ChildWindow() {}; + virtual PRBool IsChild() { return(PR_TRUE); }; +}; + +#endif // Window_h__ diff --git a/widget/src/beos/nsdefs.h b/widget/src/beos/nsdefs.h new file mode 100644 index 000000000000..ad1878bf3b74 --- /dev/null +++ b/widget/src/beos/nsdefs.h @@ -0,0 +1,36 @@ +/* -*- 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 NSDEFS_H +#define NSDEFS_H + +#ifdef _DEBUG + #define BREAK_TO_DEBUGGER DebugBreak() +#else + #define BREAK_TO_DEBUGGER +#endif + +#ifdef _DEBUG + #define VERIFY(exp) ((exp) ? 0: (GetLastError(), BREAK_TO_DEBUGGER)) +#else // !_DEBUG + #define VERIFY(exp) (exp) +#endif // !_DEBUG + +#endif // NSDEFS_H + + diff --git a/widget/src/beos/resource.h b/widget/src/beos/resource.h new file mode 100644 index 000000000000..169c4ddfed0c --- /dev/null +++ b/widget/src/beos/resource.h @@ -0,0 +1,27 @@ +/* -*- 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. + */ +#define IDC_SELECTANCHOR 4100 +#define IDC_ARROWSOUTH 4101 +#define IDC_ARROWNORTH 4102 +#define IDC_ARROWEAST 4103 +#define IDC_ARROWWEST 4104 +#define IDC_ARROWSOUTHPLUS 4105 +#define IDC_ARROWNORTHPLUS 4106 +#define IDC_ARROWEASTPLUS 4107 +#define IDC_ARROWWESTPLUS 4108 +