From 06cf38bb8b2018dcef2e3829dc63129ef0995b26 Mon Sep 17 00:00:00 2001 From: "Jerry.Kirk%Nexwarecorp.com" Date: Thu, 3 Jun 1999 01:13:06 +0000 Subject: [PATCH] - These files bring the Photon UI uptodate. - They still include lots of debug that will be cleaned out later - once everything works. --- widget/src/photon/Makefile.in | 26 +- widget/src/photon/PtRawDrawContainer.cpp | 74 + widget/src/photon/PtRawDrawContainer.h | 17 + widget/src/photon/nsAppShell.cpp | 197 ++- widget/src/photon/nsAppShell.h | 13 + widget/src/photon/nsButton.cpp | 233 +++ widget/src/photon/nsButton.h | 63 + widget/src/photon/nsCheckButton.cpp | 264 ++++ widget/src/photon/nsCheckButton.h | 66 + widget/src/photon/nsComboBox.cpp | 418 +++++ widget/src/photon/nsComboBox.h | 66 + widget/src/photon/nsDialog.cpp | 104 +- widget/src/photon/nsDialog.h | 33 +- widget/src/photon/nsFileWidget.cpp | 265 ++++ widget/src/photon/nsFileWidget.h | 97 ++ widget/src/photon/nsLabel.cpp | 211 +++ widget/src/photon/nsLabel.h | 61 + widget/src/photon/nsListBox.cpp | 517 ++++++ widget/src/photon/nsListBox.h | 72 + widget/src/photon/nsLookAndFeel.cpp | 132 +- widget/src/photon/nsMenu.cpp | 1010 ++++++++++++ widget/src/photon/nsMenu.h | 129 ++ widget/src/photon/nsMenuBar.cpp | 387 +++++ widget/src/photon/nsMenuBar.h | 80 + widget/src/photon/nsMenuItem.cpp | 654 ++++++++ widget/src/photon/nsMenuItem.h | 110 ++ widget/src/photon/nsPhWidgetLog.h | 65 + widget/src/photon/nsPopUpMenu.cpp | 212 +++ widget/src/photon/nsPopUpMenu.h | 68 + widget/src/photon/nsRadioButton.cpp | 255 +++ widget/src/photon/nsRadioButton.h | 65 + widget/src/photon/nsScrollbar.cpp | 448 ++++++ widget/src/photon/nsScrollbar.h | 68 + widget/src/photon/nsTextAreaWidget.cpp | 164 ++ widget/src/photon/nsTextAreaWidget.h | 51 + widget/src/photon/nsTextHelper.cpp | 290 ++++ widget/src/photon/nsTextHelper.h | 62 + widget/src/photon/nsTextWidget.cpp | 162 ++ widget/src/photon/nsTextWidget.h | 51 + widget/src/photon/nsToolkit.cpp | 30 + widget/src/photon/nsToolkit.h | 8 +- widget/src/photon/nsWidget.cpp | 1345 ++++++++++++++++ widget/src/photon/nsWidget.h | 158 ++ widget/src/photon/nsWidgetSupport.cpp | 53 +- widget/src/photon/nsWindow.cpp | 1843 +++++++++++----------- widget/src/photon/nsWindow.h | 225 +-- 46 files changed, 9717 insertions(+), 1205 deletions(-) create mode 100644 widget/src/photon/PtRawDrawContainer.cpp create mode 100644 widget/src/photon/PtRawDrawContainer.h create mode 100644 widget/src/photon/nsButton.cpp create mode 100644 widget/src/photon/nsButton.h create mode 100644 widget/src/photon/nsCheckButton.cpp create mode 100644 widget/src/photon/nsCheckButton.h create mode 100644 widget/src/photon/nsComboBox.cpp create mode 100644 widget/src/photon/nsComboBox.h create mode 100644 widget/src/photon/nsFileWidget.cpp create mode 100644 widget/src/photon/nsFileWidget.h create mode 100644 widget/src/photon/nsLabel.cpp create mode 100644 widget/src/photon/nsLabel.h create mode 100644 widget/src/photon/nsListBox.cpp create mode 100644 widget/src/photon/nsListBox.h create mode 100644 widget/src/photon/nsMenu.cpp create mode 100644 widget/src/photon/nsMenu.h create mode 100644 widget/src/photon/nsMenuBar.cpp create mode 100644 widget/src/photon/nsMenuBar.h create mode 100644 widget/src/photon/nsMenuItem.cpp create mode 100644 widget/src/photon/nsMenuItem.h create mode 100644 widget/src/photon/nsPhWidgetLog.h create mode 100644 widget/src/photon/nsPopUpMenu.cpp create mode 100644 widget/src/photon/nsPopUpMenu.h create mode 100644 widget/src/photon/nsRadioButton.cpp create mode 100644 widget/src/photon/nsRadioButton.h create mode 100644 widget/src/photon/nsScrollbar.cpp create mode 100644 widget/src/photon/nsScrollbar.h create mode 100644 widget/src/photon/nsTextAreaWidget.cpp create mode 100644 widget/src/photon/nsTextAreaWidget.h create mode 100644 widget/src/photon/nsTextHelper.cpp create mode 100644 widget/src/photon/nsTextHelper.h create mode 100644 widget/src/photon/nsTextWidget.cpp create mode 100644 widget/src/photon/nsTextWidget.h create mode 100644 widget/src/photon/nsWidget.cpp create mode 100644 widget/src/photon/nsWidget.h diff --git a/widget/src/photon/Makefile.in b/widget/src/photon/Makefile.in index cc92421efb84..f98eba842004 100644 --- a/widget/src/photon/Makefile.in +++ b/widget/src/photon/Makefile.in @@ -25,25 +25,43 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk -LIBRARY_NAME = raptorwidgetph_s +LIBRARY_NAME = raptorwidgetphoton_s MODULE=widget REQUIRES=util img xpcom raptor netlib -#DEFINES += -D_IMPL_NS_WIDGET +DEFINES += -D_IMPL_NS_WIDGET INCLUDES+= -I$(srcdir)/../xpwidgets -I$(srcdir)/. INCLUDES += $(TK_CFLAGS) +# nsWidgetFactory.cpp \ +# nsWidgetSupport.cpp \ + CPPSRCS= \ + PtRawDrawContainer.cpp \ nsAppShell.cpp \ + nsButton.cpp \ + nsLabel.cpp \ + nsCheckButton.cpp \ + nsRadioButton.cpp \ nsDialog.cpp \ nsLookAndFeel.cpp \ nsToolkit.cpp \ - nsWidgetFactory.cpp \ - nsWidgetSupport.cpp \ + nsMenuBar.cpp \ + nsMenuItem.cpp \ + nsMenu.cpp \ + nsPopUpMenu.cpp \ + nsWidget.cpp \ + nsScrollbar.cpp \ + nsTextHelper.cpp \ + nsTextWidget.cpp \ + nsTextAreaWidget.cpp \ + nsListBox.cpp \ + nsFileWidget.cpp \ + nsComboBox.cpp \ nsWindow.cpp TARGETS = $(LIBRARY) diff --git a/widget/src/photon/PtRawDrawContainer.cpp b/widget/src/photon/PtRawDrawContainer.cpp new file mode 100644 index 000000000000..71e0688da215 --- /dev/null +++ b/widget/src/photon/PtRawDrawContainer.cpp @@ -0,0 +1,74 @@ +/* PtRawDrawContainer.c - widget source file */ + +#include "PtRawDrawContainer.h" + +/* prototype declarations */ +PtWidgetClass_t *CreateRawDrawContainerClass( void ); + +/* widget class pointer - class structure, create function */ +PtWidgetClassRef_t WRawDrawContainer = { NULL, CreateRawDrawContainerClass }; +PtWidgetClassRef_t *PtRawDrawContainer = &WRawDrawContainer; + +// +// Defaults function +// +static void raw_draw_container_dflts( PtWidget_t *widget ) +{ + RawDrawContainerWidget *rdc = ( RawDrawContainerWidget * ) widget; + PtContainerWidget_t *container = ( PtContainerWidget_t * ) widget; + PtBasicWidget_t *basic = ( PtBasicWidget_t * ) widget; +// basic->flags |= Pt_OPAQUE; + widget->flags |= Pt_OPAQUE; + rdc->draw_f = NULL; +} + +// +// Draw function +// +static void raw_draw_container_draw( PtWidget_t *widget, PhTile_t *damage ) +{ + RawDrawContainerWidget *rdc = ( RawDrawContainerWidget * ) widget; + PtContainerWidget_t *container = ( PtContainerWidget_t * ) widget; + PhRect_t rect; + + // we don't want to draw outside our canvas! So we clip. +// PtBasicWidgetCanvas( widget, &rect ); +// PgSetTranslation( &rect.ul, Pg_RELATIVE ); +// PtClipAdd( widget, &rect ); + + if( rdc->draw_f ) + rdc->draw_f( widget, damage ); + + /* remove the clipping and translation */ +// PtClipRemove(); +// rect.ul.x *= -1; +// rect.ul.y *= -1; +// PgSetTranslation( &rect.ul, Pg_RELATIVE ); +} + +// +// Class creation function +// +PtWidgetClass_t *CreateRawDrawContainerClass( void ) +{ + // define our resources + static PtResourceRec_t resources[] = { + RDC_DRAW_FUNC, Pt_CHANGE_INVISIBLE, 0, + Pt_ARG_IS_POINTER( RawDrawContainerWidget, draw_f ), 0, + }; + + // set up our class member values + static PtArg_t args[] = { + { Pt_SET_VERSION, 110}, + { Pt_SET_STATE_LEN, sizeof( RawDrawContainerWidget ) }, + { Pt_SET_DFLTS_F, (long)raw_draw_container_dflts }, + { Pt_SET_DRAW_F, (long)raw_draw_container_draw }, + { Pt_SET_FLAGS, 0, Pt_RECTANGULAR }, + { Pt_SET_NUM_RESOURCES, sizeof( resources ) / sizeof( resources[0] ) }, + { Pt_SET_RESOURCES, (long)resources, sizeof( resources ) / sizeof( resources[0] ) }, + }; + + // create the widget class + return( PtRawDrawContainer->wclass = PtCreateWidgetClass( + PtContainer, 0, sizeof( args )/sizeof( args[0] ), args ) ); +} diff --git a/widget/src/photon/PtRawDrawContainer.h b/widget/src/photon/PtRawDrawContainer.h new file mode 100644 index 000000000000..5150bb75ae67 --- /dev/null +++ b/widget/src/photon/PtRawDrawContainer.h @@ -0,0 +1,17 @@ +/* PtRawDrawContainer.h - widget header file */ + +#include + +/* widget resources */ +#define RDC_DRAW_FUNC Pt_RESOURCE( Pt_USER( 0 ), 0 ) + +/* widget instance structure */ +typedef struct raw_draw_container_widget +{ + PtContainerWidget_t container; + void (*draw_f)( PtWidget_t *, PhTile_t * ); +} RawDrawContainerWidget; + +/* widget class pointer */ +extern PtWidgetClassRef_t *PtRawDrawContainer; + diff --git a/widget/src/photon/nsAppShell.cpp b/widget/src/photon/nsAppShell.cpp index a8c3d3ed3a01..cb7d3dbc3794 100644 --- a/widget/src/photon/nsAppShell.cpp +++ b/widget/src/photon/nsAppShell.cpp @@ -17,12 +17,54 @@ */ #include "nsAppShell.h" +#include "nsIAppShell.h" + +#include "plevent.h" +#include "nsIServiceManager.h" +#include "nsIEventQueueService.h" +#include + + +static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID); +static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID); + #include "nsIWidget.h" + #include +#include + NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID); NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID); +PRBool nsAppShell::mPtInited = PR_FALSE; + +#include +PRLogModuleInfo *PhWidLog = NULL; +unsigned char PhWidLogState = 0; /* 0= Not Enabled */ +#include "nsPhWidgetLog.h" + +#if 1 +void SigUsr1Handler(int signo) +{ + printf("SigUsr1Handler: PhWidLogState=<%d>\n", PhWidLogState); + + if (PhWidLogState) + PhWidLogState=0; + else + PhWidLogState=1; + +#if 1 + /* Should do this in a function in GFX */ + extern unsigned char PhGfxLogState; + if (PhGfxLogState) + PhGfxLogState=0; + else + PhGfxLogState=1; +#endif +} +#endif + //------------------------------------------------------------------------- // // nsAppShell constructor @@ -31,13 +73,66 @@ NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID); nsAppShell::nsAppShell() { NS_INIT_REFCNT(); - mDispatchListener = 0; + mDispatchListener = nsnull; mEventBufferSz = sizeof( PhEvent_t ) + 1000; mEvent = (PhEvent_t*) malloc( mEventBufferSz ); NS_ASSERTION( mEvent, "Out of memory" ); + + /* Run this only once per application startup */ + if( !mPtInited ) + { + PtInit( NULL ); + PtChannelCreate(); // Force use of pulses + mPtInited = PR_TRUE; + +#if 1 +extern int double_buffer; +//extern int raw_container_color; + + if (getenv("DOUBLE_BUFFER")!=0) + { + double_buffer = atoi(getenv("DOUBLE_BUFFER")); + } + printf ("double_buffer: %d\n",double_buffer); + +/* if (getenv("RAW_CONTAINER_COLOR")!=0) + { + raw_container_color = atoi(getenv("RAW_CONTAINER_COLOR")); + } + printf ("raw_container_color: %d\n",raw_container_color); +*/ +#endif + } } +NS_METHOD nsAppShell::Spinup() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spinup - Not Implemented.\n")); + return NS_OK; +} + + +NS_METHOD nsAppShell::Spindown() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Spindown - Not Implemented.\n")); + return NS_OK; +} + + +NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetNativeEvent - Not Implemented.\n")); + return NS_OK; +} + + +NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void * aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::DispatchNativeEvent - Not Implemented.\n")); + return NS_OK; +} + //------------------------------------------------------------------------- // @@ -47,12 +142,15 @@ nsAppShell::nsAppShell() NS_METHOD nsAppShell::Create(int* argc, char ** argv) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Create - Not Implemented.\n")); return NS_OK; } //------------------------------------------------------------------------- NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::SetDispatchListener.\n")); + mDispatchListener = aDispatchListener; return NS_OK; } @@ -62,15 +160,72 @@ NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener) // Enter a message handler loop // //------------------------------------------------------------------------- +//struct PLEventQueue; +nsIEventQueue * kedlEQueue = nsnull; + +int event_processor_callback(int fd, void *data, unsigned mode) +{ +// printf ("kedl: event processor callback!\n"); fflush (stdout); +// printf ("kedl: to pr process events!\n"); fflush(stdout); +// PR_ProcessPendingEvents(kedlEQueue); +// printf ("kedl: back from pr process events!\n"); fflush(stdout); + +nsIEventQueue * eventQueue = (nsIEventQueue *) data; +eventQueue->ProcessPendingEvents(); +} nsresult nsAppShell::Run() { + nsresult rv = NS_OK; + nsIEventQueue * EQueue = nsnull; + + // Get the event queue service + rv = nsServiceManager::GetService(kEventQueueServiceCID, + kIEventQueueServiceIID, + (nsISupports **) &mEventQService); + + if (NS_OK != rv) { + NS_ASSERTION(0,"Could not obtain event queue service"); + return rv; + } + + printf("Got thew event queue from the service\n"); + //Get the event queue for the thread. + rv = mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &EQueue); + + // If a queue already present use it. + if (nsnull != EQueue) + goto done; + + // Create the event queue for the thread + rv = mEventQService->CreateThreadEventQueue(); + if (NS_OK != rv) { + NS_ASSERTION(0,"Could not create the thread event queue"); + return rv; + } + //Get the event queue for the thread + rv = mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &EQueue); + if (NS_OK != rv) { + NS_ASSERTION(0,"Could not obtain the thread event queue"); + return rv; + } + +done: + kedlEQueue=EQueue; +// printf("setting up input with event queue\n"); + PtAppAddFd(NULL,EQueue->GetEventQueueSelectFD(),Pt_FD_READ,event_processor_callback,EQueue); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Run.\n")); + NS_ADDREF_THIS(); nsresult result = NS_OK; - PhEvent_t *event; - unsigned short locEventBufferSz = sizeof( PhEvent_t ) + 1000; /* initially */ +// PhEvent_t *event; +// unsigned long locEventBufferSz = sizeof( PhEvent_t ) + 4000; /* initially */ + PtMainLoop(); + +#if 0 if( nsnull != ( event = (PhEvent_t*) malloc( locEventBufferSz ))) { PRBool done = PR_FALSE; @@ -87,8 +242,10 @@ nsresult nsAppShell::Run() case Ph_RESIZE_MSG: locEventBufferSz = PhGetMsgSize( event ); + printf( "nsAppShell::Run got resize msg (%lu).\n", locEventBufferSz ); if(( event = (PhEvent_t*) realloc( event, locEventBufferSz )) == nsnull ) { + printf( "realloc barfed.\n" ); result = 0; // Meaningful error code? done = PR_TRUE; } @@ -99,12 +256,16 @@ nsresult nsAppShell::Run() } } + printf( "nsAppShell::Run exiting event loop.\n" ); + free( event ); } - +#endif Release(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Run - done.\n")); + return result; } @@ -116,6 +277,12 @@ nsresult nsAppShell::GetNativeEvent(void *& aEvent, nsIWidget* aWidget, PRBool & aIsInWindow = PR_FALSE; +//kedl +// printf ("kedl: to pr process events!\n"); fflush(stdout); +// PR_ProcessPendingEvents(kedlEQueue); +kedlEQueue->ProcessPendingEvents(); +// printf ("kedl: back from pr process events!\n"); fflush(stdout); + while(!done) { // This method uses the class event buffer, m_Event, and the class event @@ -190,9 +357,14 @@ nsresult nsAppShell::DispatchNativeEvent(void * aEvent) NS_METHOD nsAppShell::Exit() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::Exit - Not Implemented.\n")); + // REVISIT - How do we do this under Photon??? // PtSendEventToWidget( m_window, quit_event ); + /* kirk: Hack until we figure out what to do here */ + exit ( EXIT_SUCCESS ); + return NS_OK; } @@ -203,6 +375,7 @@ NS_METHOD nsAppShell::Exit() //------------------------------------------------------------------------- nsAppShell::~nsAppShell() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::~nsAppShell - Not Implemented.\n")); } //------------------------------------------------------------------------- @@ -212,6 +385,8 @@ nsAppShell::~nsAppShell() //------------------------------------------------------------------------- void* nsAppShell::GetNativeData(PRUint32 aDataType) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetNativeShell - Not Implemented.\n")); + if( aDataType == NS_NATIVE_SHELL ) { return nsnull; @@ -219,4 +394,18 @@ void* nsAppShell::GetNativeData(PRUint32 aDataType) return nsnull; } +#if 0 +NS_METHOD nsAppShell::GetSelectionMgr(nsISelectionMgr** aSelectionMgr) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::GetSelectionMgr - Not Implemented.\n")); + return NS_OK; +} +#endif + +NS_METHOD nsAppShell::EventIsForModalWindow(PRBool aRealEvent, void *aEvent, nsIWidget *aWidget, PRBool *aForWindow) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsAppShell::EventIsForModalWindow - Not Implemented.\n")); + + return NS_OK; +} diff --git a/widget/src/photon/nsAppShell.h b/widget/src/photon/nsAppShell.h index 4f4109cb1c66..7d8b250a2c32 100644 --- a/widget/src/photon/nsAppShell.h +++ b/widget/src/photon/nsAppShell.h @@ -25,6 +25,7 @@ /** * Native Photon Application shell wrapper */ +class nsIEventQueueService; class nsAppShell : public nsIAppShell { @@ -40,20 +41,32 @@ class nsAppShell : public nsIAppShell 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 SetDispatchListener(nsDispatchListener* aDispatchListener); NS_IMETHOD Exit(); virtual void* GetNativeData(PRUint32 aDataType); +// NS_IMETHOD GetSelectionMgr(nsISelectionMgr** aSelectionMgr); // XXX temporary for Dialog investigation NS_IMETHOD GetNativeEvent(void *& aEvent, nsIWidget* aWidget, PRBool &aIsInWindow, PRBool &aIsMouseEvent); NS_IMETHOD DispatchNativeEvent(void * aEvent); + NS_IMETHOD EventIsForModalWindow(PRBool aRealEvent, void *aEvent, nsIWidget *aWidget, + PRBool *aForWindow); private: nsDispatchListener *mDispatchListener; +// nsISelectionMgr *mSelectionMgr; unsigned long mEventBufferSz; PhEvent_t *mEvent; + static PRBool mPtInited; + + protected: + nsIEventQueueService * mEventQService; }; #endif // nsAppShell_h__ diff --git a/widget/src/photon/nsButton.cpp b/widget/src/photon/nsButton.cpp new file mode 100644 index 000000000000..95c115bea4f2 --- /dev/null +++ b/widget/src/photon/nsButton.cpp @@ -0,0 +1,233 @@ +/* -*- 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 + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +#include "nsPhWidgetLog.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() : nsWidget(), nsIButton() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// nsButton destructor +// +//------------------------------------------------------------------------- +nsButton::~nsButton() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::~nsButton - Not Implemented!\n")); +} + +/** + * 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) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton:QueryInterface, mWidget=%p\n", mWidget)); + + 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 nsWidget::QueryInterface(aIID,aInstancePtr); +} + + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsButton::SetLabel(const nsString& aText) +{ + nsresult res = NS_ERROR_FAILURE; + + mLabel = aText; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsButton:SetLabel, mWidget=%p\n", mWidget)); + if( mWidget ) + { + PtArg_t arg; + + NS_ALLOC_STR_BUF(label, aText, 256); + + PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + + NS_FREE_STR_BUF(label); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsButton::GetLabel(nsString& aBuffer) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::GetLabel\n")); + + aBuffer = mLabel; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsButton::OnMove(PRInt32, PRInt32) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::OnMove - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsButton::OnPaint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::OnPaint - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsButton::OnResize(nsRect &aWindowRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::OnResize - Not Implemented\n")); + return PR_FALSE; +} + + +/** + * Renders the Button for Printing + * + **/ +NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsButton::Paint - Not Implemented\n")); + return NS_OK; +} + + +NS_METHOD nsButton::CreateNative( PtWidget_t* aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + const unsigned short BorderWidth = 2; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsButton::CreateNative at (%d,%d) for (%d,%d)\n",mBounds.x,mBounds.y, mBounds.width, mBounds.height)); + + NS_PRECONDITION(aParent, "nsButton::CreateNative aParent is NULL"); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width - (2*BorderWidth); // Correct for border width + dim.h = mBounds.height - (2*BorderWidth); + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, BorderWidth, 0 ); + + mWidget = PtCreateWidget( PtButton, aParent, 3, arg ); + if( mWidget ) + { + PtAddEventHandler( mWidget, + Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY, + RawEventHandler, this ); + + res = NS_OK; + + /* Add an Activate Callback */ +// PtAddCallback(mWidget, Pt_CB_ACTIVATE, handle_activate_event, this); + } + + NS_POSTCONDITION(mWidget, "nsButton::CreateNative Failed to create Native Button"); + + return res; +} + +#if 0 +int nsButton::handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ) +{ + nsButton *me = (nsButton *) aData; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsButton::handle_activate_event widget=<%p>\n",me)); + + if (me) + { + nsGUIEvent event; + + event.widget = me; + NS_IF_ADDREF(event.widget); + event.time = 0; //gdk_event_get_time((GdkEvent*)ge); + event.message = NS_MOUSE_LEFT_BUTTON_UP; + + event.point.x = 0; + event.point.y = 0; + event.eventStructType = NS_GUI_EVENT; + + PRBool result = me->DispatchWindowEvent(&event); + } + + return (Pt_CONTINUE); +} +#endif + \ No newline at end of file diff --git a/widget/src/photon/nsButton.h b/widget/src/photon/nsButton.h new file mode 100644 index 000000000000..c9012cd245d5 --- /dev/null +++ b/widget/src/photon/nsButton.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 nsButton_h__ +#define nsButton_h__ + +#include "nsWindow.h" +#include "nsIButton.h" +#include + +/** + * Native Photon button wrapper + */ + +class nsButton : public nsWidget, 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(); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + + NS_IMETHOD CreateNative( PtWidget_t* aParent ); + static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); + + nsString mLabel; + +}; + +#endif // nsButton_h__ diff --git a/widget/src/photon/nsCheckButton.cpp b/widget/src/photon/nsCheckButton.cpp new file mode 100644 index 000000000000..ff2a2d5e777a --- /dev/null +++ b/widget/src/photon/nsCheckButton.cpp @@ -0,0 +1,264 @@ +/* -*- 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 + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +#include "nsPhWidgetLog.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); + + +NS_IMPL_ADDREF(nsCheckButton) +NS_IMPL_RELEASE(nsCheckButton) + +//------------------------------------------------------------------------- +// +// nsCheckButton constructor +// +//------------------------------------------------------------------------- +nsCheckButton::nsCheckButton() : nsWidget(), nsICheckButton(), + mState(PR_FALSE) +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// nsCheckButton destructor +// +//------------------------------------------------------------------------- +nsCheckButton::~nsCheckButton() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::~nsCheckButton - Not Implemented!\n")); +} + +/** + * 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) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton:QueryInterface, mWidget=%p\n", mWidget)); + + if (NULL == aInstancePtr) + { + return NS_ERROR_NULL_POINTER; + } + + static NS_DEFINE_IID(kICheckButton, NS_ICHECKBUTTON_IID); + if (aIID.Equals(kICheckButton)) { + *aInstancePtr = (void*) ((nsICheckButton*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWidget::QueryInterface(aIID,aInstancePtr); +} + +//------------------------------------------------------------------------- +// +// Set the CheckButton State +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::SetState(const PRBool aState) +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsCheckButton:SetState, mWidget=%p new state is <%d>\n", mWidget, aState)); + nsresult res = NS_ERROR_FAILURE; + + mState = aState; + if (mWidget) + { + PtArg_t arg; + + if (mState) + PtSetArg( &arg, Pt_ARG_FLAGS, Pt_SET, Pt_SET ); + else + PtSetArg( &arg, Pt_ARG_FLAGS, 0, Pt_SET ); + + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get the CheckButton State +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::GetState(PRBool & aState) +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsCheckButton:GetState, mWidget=%p\n", mWidget)); + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + PtArg_t arg; + long *flags; + + PtSetArg( &arg, Pt_ARG_FLAGS, &flags, 0); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if( *flags & Pt_SET ) + mState = PR_TRUE; + else + mState = PR_FALSE; + res = NS_OK; + } + } + + aState = mState; + + return res; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::SetLabel(const nsString& aText) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsCheckButton:SetLabel, mWidget=%p\n", mWidget)); + if( mWidget ) + { + PtArg_t arg; + + NS_ALLOC_STR_BUF(label, aText, 256); + + PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + + NS_FREE_STR_BUF(label); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::GetLabel\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsCheckButton::OnMove(PRInt32, PRInt32) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::OnMove - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsCheckButton::OnPaint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::OnPaint - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsCheckButton::OnResize(nsRect &aWindowRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::OnResize - Not Implemented\n")); + return PR_FALSE; +} + + +/** + * Renders the CheckButton for Printing + * + **/ +NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsCheckButton::Paint - Not Implemented\n")); + return NS_OK; +} + + +NS_METHOD nsCheckButton::CreateNative( PtWidget_t* aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[15]; + PhPoint_t pos; + PhDim_t dim; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsCheckButton::CreateNative this=<%p>\n", this)); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width; // Correct for border width + dim.h = mBounds.height; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 0, 0 ); + PtSetArg( &arg[3], Pt_ARG_INDICATOR_TYPE, Pt_CHECK, 0 ); + PtSetArg( &arg[4], Pt_ARG_INDICATOR_COLOR, Pg_BLACK, 0 ); + PtSetArg( &arg[5], Pt_ARG_SPACING, 0, 0 ); + PtSetArg( &arg[6], Pt_ARG_MARGIN_TOP, 0, 0 ); + PtSetArg( &arg[7], Pt_ARG_MARGIN_LEFT, 0, 0 ); + PtSetArg( &arg[8], Pt_ARG_MARGIN_BOTTOM, 0, 0 ); + PtSetArg( &arg[9], Pt_ARG_MARGIN_RIGHT, 0, 0 ); + PtSetArg( &arg[10], Pt_ARG_MARGIN_WIDTH, 0, 0 ); + PtSetArg( &arg[11], Pt_ARG_MARGIN_HEIGHT, 0, 0 ); + PtSetArg( &arg[12], Pt_ARG_VERTICAL_ALIGNMENT, Pt_TOP, 0 ); + PtSetArg( &arg[13], Pt_ARG_FLAGS, 0, Pt_SELECTABLE ); + + mWidget = PtCreateWidget( PtToggleButton, aParent, 14, arg ); + if( mWidget ) + { + PtAddEventHandler( mWidget, + Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY, + RawEventHandler, this ); + + res = NS_OK; + } + + return res; +} + + \ No newline at end of file diff --git a/widget/src/photon/nsCheckButton.h b/widget/src/photon/nsCheckButton.h new file mode 100644 index 000000000000..c8a991d35413 --- /dev/null +++ b/widget/src/photon/nsCheckButton.h @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsCheckButton_h__ +#define nsCheckButton_h__ + +#include "nsWindow.h" +#include "nsICheckButton.h" +#include + +/** + * Native Photon Check Button wrapper + */ + +class nsCheckButton : public nsWidget, 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); + + // nsBaseWidget + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + + NS_IMETHOD CreateNative( PtWidget_t* aParent ); + +// static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); + + PRBool mState; + +}; + +#endif // nsCheckButton_h__ diff --git a/widget/src/photon/nsComboBox.cpp b/widget/src/photon/nsComboBox.cpp new file mode 100644 index 000000000000..e4c9a774fb35 --- /dev/null +++ b/widget/src/photon/nsComboBox.cpp @@ -0,0 +1,418 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsComboBox.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" +#include "nsIDeviceContext.h" + +#include +#include "nsPhWidgetLog.h" + +#define DBG 0 + +#define INITIAL_MAX_ITEMS 128 +#define ITEMS_GROWSIZE 128 + +NS_IMPL_ADDREF(nsComboBox) +NS_IMPL_RELEASE(nsComboBox) + +//------------------------------------------------------------------------- +// +// nsComboBox constructor +// +//------------------------------------------------------------------------- +nsComboBox::nsComboBox() : nsWidget(), nsIListWidget(), nsIComboBox() +{ + NS_INIT_REFCNT(); + mMultiSelect = PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// nsComboBox:: destructor +// +//------------------------------------------------------------------------- +nsComboBox::~nsComboBox() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::~nsComboBox - Destructor called\n")); +} + +//------------------------------------------------------------------------- +// +// initializer +// +//------------------------------------------------------------------------- + +NS_METHOD nsComboBox::SetMultipleSelection(PRBool aMultipleSelections) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::SetMultipleSelection - aMultipleSelections=<%d>\n", aMultipleSelections)); + + PtArg_t arg; + nsresult res = NS_ERROR_FAILURE; + + mMultiSelect = aMultipleSelections; + + if (mWidget) + { + if (mMultiSelect) + PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_EXTENDED_MODE), 0); + else + PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_SINGLE_MODE), 0); + + if ( PtSetResources(mWidget, 1, &arg ) == 0) + res = NS_OK; + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// AddItemAt +// +//------------------------------------------------------------------------- + +NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition) +{ + char *str = aItem.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::AddItemAt - aItem=<%s> aPos=<%d>\n",str,aPosition)); + + PtArg_t arg; + nsresult res = NS_ERROR_FAILURE; + int err; + + if (mWidget) + { + err = PtListAddItems(mWidget, (const char **) &str, 1, (unsigned int) (aPosition+1)); + if (err == 0) + res = NS_OK; + } + + delete [] str; + return res; +} + +//------------------------------------------------------------------------- +// +// Finds an item at a postion +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos) +{ + char *str = aItem.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::FindItem - aItem=<%s> aStartPos=<%d>\n",str, aStartPos)); + + PRInt32 index = -1; + + if (mWidget) + { + index = PtListItemPos(mWidget, str); + if (index == 0) + index = -1; /* item wasn't found */ + } + + delete [] str; + return index; +} + +//------------------------------------------------------------------------- +// +// CountItems - Get Item Count +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::GetItemCount() +{ + PtArg_t arg; + short *theCount = nsnull; + PRInt32 total = 0; + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_LIST_ITEM_COUNT, &theCount, 0); + PtGetResources(mWidget, 1, &arg ); + + total = *theCount; + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetItemCount - mNumItems=<%d>\n", total)); + return (PRInt32) total; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::RemoveItemAt - aPos=<%d>\n", aPosition)); + + int err; + PRBool res = PR_FALSE; + + if (mWidget) + { + if (PtListDeleteItemPos(mWidget, 1, aPosition) == 0) + res = PR_TRUE; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition) +{ + PRBool result = PR_FALSE; + short *num; + char **items; + PtArg_t arg; + + /* Clear the nsString */ + anItem.SetLength(0); + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_ITEMS, &items, &num); + PtGetResources(mWidget, 1, &arg ); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetItemAt aPosition=<%d> aItem=<%s>\n", aPosition, items[aPosition+1])); + + anItem.Append(items[aPosition+1]); + result = PR_TRUE; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// Gets the selected of selected item +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem) +{ + nsresult res = NS_ERROR_FAILURE; + int theFirstSelectedItem = GetSelectedIndex(); + + if (mWidget) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedItem theFirstSelectedItem is <%d>\n", theFirstSelectedItem)); + GetItemAt(aItem, theFirstSelectedItem); + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Gets the list of selected items +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::GetSelectedIndex() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndex\n")); + + PRInt32 index=-1; + int theFirstSelectedItem[1]; + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + GetSelectedIndices(theFirstSelectedItem, 1); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndex theFirstSelectedItem is <%d>\n", theFirstSelectedItem[0])); + + index = theFirstSelectedItem[0]; + res = NS_OK; + } + + return index; +} + +//------------------------------------------------------------------------- +// +// SelectItem +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::SelectItem at %d\n", aPosition)); + + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + PtListSelectPos(mWidget, (aPosition+1)); /* Photon is 1 based */ + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// GetSelectedCount +// +//------------------------------------------------------------------------- +PRInt32 nsComboBox::GetSelectedCount() +{ + PtArg_t arg; + short *theCount; + PRInt32 total = 0; + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_LIST_SEL_COUNT, &theCount, 0); + PtGetResources(mWidget, 1, &arg ); + + total = *theCount; + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedCount theCount=<%d>\n", total)); + return total; +} + +//------------------------------------------------------------------------- +// +// GetSelectedIndices +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::GetSelectedIndices - Not Implemented\n")); + + return NS_ERROR_FAILURE; +} + +//------------------------------------------------------------------------- +// +// Deselect +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::Deselect() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::DeSelect - Not Implemented\n")); + + if (mMultiSelect) { + return NS_ERROR_FAILURE; + } + + return NS_ERROR_FAILURE; +} + +//------------------------------------------------------------------------- +// +// 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); + AddRef(); + return NS_OK; + } + else if (aIID.Equals(kInsListWidgetIID)) { + *aInstancePtr = (void*) ((nsIListWidget*)this); + AddRef(); + return NS_OK; + } + + return nsWidget::QueryInterface(aIID,aInstancePtr); +} + + +//------------------------------------------------------------------------- +// +// Create the native GtkCombo widget +// +//------------------------------------------------------------------------- +NS_METHOD nsComboBox::CreateNative(PtWidget_t *parentWindow) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width - 4; // Correct for border width + dim.h = mBounds.height - 4; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::CreateNative pos=(%d,%d) dim=(%d,%d)\n", + pos.x, pos.y, dim.w, dim.h)); + + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 ); + + mWidget = PtCreateWidget( PtComboBox, parentWindow, 3, arg ); + if( mWidget ) + { + res = NS_OK; + + /* Mozilla calls this first before we have a widget so re-call this */ + SetMultipleSelection(mMultiSelect); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsComboBox::OnMove(PRInt32, PRInt32) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnMove - Not Implemented\n")); + + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsComboBox::OnPaint(nsPaintEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnPaint - Not Implemented\n")); + + return PR_FALSE; +} + +PRBool nsComboBox::OnResize(nsSizeEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsComboBox::OnResize - Not Implemented\n")); + + return PR_FALSE; +} diff --git a/widget/src/photon/nsComboBox.h b/widget/src/photon/nsComboBox.h new file mode 100644 index 000000000000..0d6b2b2ed59e --- /dev/null +++ b/widget/src/photon/nsComboBox.h @@ -0,0 +1,66 @@ +/* -*- 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 "nsWidget.h" +#include "nsIComboBox.h" + +/** + * Native Photon Listbox wrapper + */ + +class nsComboBox : public nsWidget, + public nsIListWidget, + public nsIComboBox +{ +public: + nsComboBox(); + ~nsComboBox(); + + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + + // nsIComboBox interface + 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(); + NS_IMETHOD SelectItem(PRInt32 aPosition); + NS_IMETHOD Deselect() ; + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsPaintEvent & aEvent); + virtual PRBool OnResize(nsSizeEvent &aEvent); + + // nsIComboBox interface + NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections); + PRInt32 GetSelectedCount(); + NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize); + +protected: + NS_IMETHOD CreateNative(PtWidget_t *parentWindow); + PRBool mMultiSelect; +}; + +#endif // nsComboBox_h__ diff --git a/widget/src/photon/nsDialog.cpp b/widget/src/photon/nsDialog.cpp index d5b5b208a98c..c66326f96ccf 100644 --- a/widget/src/photon/nsDialog.cpp +++ b/widget/src/photon/nsDialog.cpp @@ -16,6 +16,7 @@ * Reserved. */ +#include "nsPhWidgetLog.h" #include "nsDialog.h" #include "nsToolkit.h" #include "nsColor.h" @@ -35,6 +36,7 @@ #include "nsGfxCIID.h" //#include "resource.h" + NS_IMPL_ADDREF(nsDialog) NS_IMPL_RELEASE(nsDialog) @@ -48,25 +50,6 @@ 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 @@ -74,44 +57,21 @@ NS_METHOD nsDialog::Create(nsIWidget *aParent, //------------------------------------------------------------------------- nsDialog::~nsDialog() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsDialog::~nsDialog - Not Implemented.\n")); } //------------------------------------------------------------------------- // -// Set this button label +// Create the native Photon Dialog widget (just a window) // //------------------------------------------------------------------------- -NS_METHOD nsDialog::SetLabel(const nsString& aText) -{ - nsresult result = NS_OK; - - if( mWidget ) - { - PtArg_t arg; - NS_ALLOC_STR_BUF(label, aText, 256); - - PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); - if( PtSetResources( mWidget, 1, &arg ) != 0 ) - result = NS_ERROR_FAILURE; - - NS_FREE_STR_BUF(label); - } - - return result; -} - -//------------------------------------------------------------------------- -// -// Get this button label -// -//------------------------------------------------------------------------- -NS_METHOD nsDialog::GetLabel(nsString& aBuffer) + +NS_METHOD nsDialog::CreateNative( PtWidget_t *parentWindow ) { + nsWindow::CreateNative( parentWindow ); return NS_OK; } - - //------------------------------------------------------------------------- // // Query interface implementation @@ -119,12 +79,12 @@ NS_METHOD nsDialog::GetLabel(nsString& aBuffer) //------------------------------------------------------------------------- nsresult nsDialog::QueryInterface(const nsIID& aIID, void** aInstancePtr) { - nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr); + nsresult result = nsWidget::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(); + AddRef(); result = NS_OK; } @@ -134,33 +94,39 @@ nsresult nsDialog::QueryInterface(const nsIID& aIID, void** aInstancePtr) //------------------------------------------------------------------------- // -// move, paint, resizes message - ignore +// Set this button label // //------------------------------------------------------------------------- -PRBool nsDialog::OnMove(PRInt32, PRInt32) +NS_METHOD nsDialog::SetLabel(const nsString& aText) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsDialog::SetLabel - Not Implemented.\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsDialog::GetLabel(nsString& aBuffer) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsDialog::GetLabel - Not Implemented.\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsDialog::OnPaint(nsPaintEvent &aEvent) { return PR_FALSE; } -PRBool nsDialog::OnPaint() +PRBool nsDialog::OnResize(nsSizeEvent &aEvent) { - return nsWindow::OnPaint(); -} - -PRBool nsDialog::OnResize(nsRect &aWindowRect) -{ - return nsWindow::OnResize(aWindowRect); + return PR_FALSE; } -//------------------------------------------------------------------------- -// -// get position/dimensions -// -//------------------------------------------------------------------------- - -NS_METHOD nsDialog::GetBounds(nsRect &aRect) -{ - return nsWindow::GetBounds(aRect); -} - diff --git a/widget/src/photon/nsDialog.h b/widget/src/photon/nsDialog.h index 5eeea192595a..8579c62eef5e 100644 --- a/widget/src/photon/nsDialog.h +++ b/widget/src/photon/nsDialog.h @@ -31,35 +31,26 @@ class nsDialog : public nsWindow, { public: + nsDialog(); virtual ~nsDialog(); - NS_IMETHOD Create(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - nsWidgetInitData *aInitData = nsnull); + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); - // nsISupports - NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr); - NS_IMETHOD_(nsrefcnt) AddRef(void); - NS_IMETHOD_(nsrefcnt) Release(void); - - // nsIDialog part + // nsIButton part NS_IMETHOD SetLabel(const nsString& aText); NS_IMETHOD GetLabel(nsString& aBuffer); - - virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); - virtual PRBool OnPaint(); - virtual PRBool OnResize(nsRect &aWindowRect); - NS_IMETHOD GetBounds(nsRect &aRect); + + virtual PRBool OnPaint(nsPaintEvent & aEvent); + virtual PRBool OnResize(nsSizeEvent &aEvent); + + //virtual void PreCreateWidget(nsWidgetInitData *aInitData); protected: - -// static BOOL CALLBACK NSDialogProc (HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam); - + NS_IMETHOD CreateNative(PtWidget_t *parentWindow); }; diff --git a/widget/src/photon/nsFileWidget.cpp b/widget/src/photon/nsFileWidget.cpp new file mode 100644 index 000000000000..abcfd64f8890 --- /dev/null +++ b/widget/src/photon/nsFileWidget.cpp @@ -0,0 +1,265 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsFileWidget.h" + +#include +#include "nsPhWidgetLog.h" + +NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); +NS_IMPL_ISUPPORTS(nsFileWidget, kIFileWidgetIID); + +//------------------------------------------------------------------------- +// +// nsFileWidget constructor +// +//------------------------------------------------------------------------- +nsFileWidget::nsFileWidget() : nsIFileWidget() +{ + NS_INIT_REFCNT(); + mWidget = nsnull; + mNumberOfFilters = 0; +} + +//------------------------------------------------------------------------- +// +// nsFileWidget destructor +// +//------------------------------------------------------------------------- +nsFileWidget::~nsFileWidget() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::~nsFileWidget - Destructor Called\n")); + + if (mWidget) + PtDestroyWidget(mWidget); +} + +//------------------------------------------------------------------------- +// +// Show - Display the file dialog +// +//------------------------------------------------------------------------- +PRBool nsFileWidget::Show() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::Show - Not Implemented\n")); + + int err; + PRBool res = PR_FALSE; + char *title = mTitle.ToNewCString(); + + PtWidget_t *myParent = (PtWidget_t *) mParent->GetNativeData(NS_NATIVE_WIDGET); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::Show myParent=<%p> - Not Implemented\n", myParent)); + + PhPoint_t *thePos=nsnull; + char *root_dir = mDefault.ToNewCString(); + char *file_spec = nsnull; + char *btn1 = nsnull; + char *btn2 = nsnull; + char format[] = "100n50d"; /* 100 Pix for Name, 50 Pix for Date */ + PtFileSelectionInfo_t info; + int flags = 0; + + if (mMode == eMode_load) + { + /* Load a File or directory */ + } + else + { + /* Save a File or directory */ + flags = flags | Pt_FSDIALOG_NO_FCHECK; + } + + int i; + nsString mFilterList; + for(i=0; i<(mNumberOfFilters-1); i++) + { + mFilterList.Append(mFilters[i]); + mFilterList.Append(","); + } + + mFilterList.Append(mFilters[i]); /* Add the last one */ + + file_spec = mFilterList.ToNewCString(); /* convert it into a string */ + + myParent = nsnull; /* HACK! */ + + err = PtFileSelection(myParent, thePos, title, root_dir, file_spec, btn1, btn2, format, &info, flags); + if (err == 0) + { + /* Successfully selected a file or directory */ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::Create Success from PtFileSelection\n")); + if (info.ret == Pt_FSDIALOG_BTN1) + { + mSelectedFile.SetLength(0); + mSelectedFile.Append(info.path); + } + else + { + /* User pressed cancel */ + } + } + + delete [] title; + delete [] root_dir; + delete [] file_spec; + + return res; +} + +//------------------------------------------------------------------------- +// +// Set the list of filters +// +//------------------------------------------------------------------------- + +NS_METHOD nsFileWidget::SetFilterList(PRUint32 aNumberOfFilters, + const nsString aTitles[], + const nsString aFilters[]) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::SetFilterList numFilters=<%d>\n", aNumberOfFilters)); +#if 1 +{ + int i; + for(i=0; i Filter=<%s>\n", i, str1, str2)); + + delete [] str1; + delete [] str2; + } + +} +#endif + + mNumberOfFilters = aNumberOfFilters; + mTitles = aTitles; + mFilters = aFilters; + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the file + path +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDefaultString(const nsString& aString) +{ + char *str = aString.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::SetDefaultString new string=<%s> - Not Implemented\n", str)); + delete [] str; + + mDefault = aString; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::SetDisplayDirectory(const nsFileSpec & aDirectory) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::SetDisplayDirectory - Not Implemented\n")); + + mDisplayDirectory = aDirectory; + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get the display directory +// +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetDisplayDirectory(nsFileSpec& aDirectory) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::GetDisplayDirectory - Not Implemented\n")); + + aDirectory = mDisplayDirectory; + return NS_OK; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::Create(nsIWidget *aParent, + const nsString& aTitle, + nsFileDlgMode aMode, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + void *aInitData) +{ + mMode = aMode; + mTitle.SetLength(0); + mTitle.Append(aTitle); + mParent = aParent; + + return NS_OK; +} + + + +NS_METHOD nsFileWidget::GetFile(nsFileSpec& aFile) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::GetFile with nsFileSpec - Not Implemented\n")); + + nsresult res = NS_ERROR_FAILURE; + return res; +} + +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +NS_METHOD nsFileWidget::GetSelectedType(PRInt16& theType) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::GetSelectedType - Not Implemented\n")); + + theType = mSelectedType; + return NS_OK; +} + + +nsFileDlgResults nsFileWidget::GetFile( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec) // Populate with initial path for file dialog +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::GetFile with nsIWidget - Not Implemented\n")); + return nsFileDlgResults_OK; +} + +nsFileDlgResults nsFileWidget::GetFolder( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec) // Populate with initial path for file dialog +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::GetFolder with nsIWidget - Not Implemented\n")); + return nsFileDlgResults_OK; +} +nsFileDlgResults nsFileWidget::PutFile( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec) // Populate with initial path for file dialog +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::PutFile with nsIWidget - Not Implemented\n")); + return nsFileDlgResults_OK; +} \ No newline at end of file diff --git a/widget/src/photon/nsFileWidget.h b/widget/src/photon/nsFileWidget.h new file mode 100644 index 000000000000..28ee4b315df4 --- /dev/null +++ b/widget/src/photon/nsFileWidget.h @@ -0,0 +1,97 @@ +/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsFileWidget_h__ +#define nsFileWidget_h__ + +#include "nsToolkit.h" +#include "nsWidgetsCID.h" +#include "nsIWidget.h" +#include "nsIFileWidget.h" + +/** + * Native Photon FileSelector wrapper + */ + +class nsFileWidget : public nsIFileWidget +{ + public: + nsFileWidget(); + virtual ~nsFileWidget(); + + NS_DECL_ISUPPORTS + + PRBool OnPaint(); + + // 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(nsString& aFile); + NS_IMETHOD GetFile(nsFileSpec& aFile); + NS_IMETHOD SetDefaultString(const nsString& aFile); + NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters, + const nsString aTitles[], + const nsString aFilters[]); + + NS_IMETHOD SetDisplayDirectory(const nsFileSpec & aDirectory); + NS_IMETHOD GetDisplayDirectory(nsFileSpec & aDirectory); + + virtual nsFileDlgResults GetFile( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec); // Populate with initial path for file dialog + + virtual nsFileDlgResults GetFolder( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec); // Populate with initial path for file dialog + + virtual nsFileDlgResults PutFile( + nsIWidget * aParent, + const nsString & promptString, // Window title for the dialog + nsFileSpec & theFileSpec); // Populate with initial path for file dialog + + + NS_IMETHOD GetSelectedType(PRInt16& theType); + + protected: + PtWidget_t *mWidget; + nsIWidget *mParent; + nsString mTitle; + nsFileDlgMode mMode; + + PRUint32 mNumberOfFilters; + const nsString *mTitles; + const nsString *mFilters; + + nsString mDefault; + nsString mSelectedFile; + nsString mDisplayDirectory; + PRInt16 mSelectedType; +}; + +#endif // nsFileWidget_h__ diff --git a/widget/src/photon/nsLabel.cpp b/widget/src/photon/nsLabel.cpp new file mode 100644 index 000000000000..49cee819e662 --- /dev/null +++ b/widget/src/photon/nsLabel.cpp @@ -0,0 +1,211 @@ +/* -*- 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 "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" +#include + +#include "nsPhWidgetLog.h" + +NS_IMPL_ADDREF_INHERITED(nsLabel, nsWidget) +NS_IMPL_RELEASE_INHERITED(nsLabel, nsWidget) + +//------------------------------------------------------------------------- +// +// nsLabel constructor +// +//------------------------------------------------------------------------- +nsLabel::nsLabel() : nsWidget(), nsILabel() +{ + NS_INIT_REFCNT(); + mAlignment = eAlign_Left; +} + +//------------------------------------------------------------------------- +// +// nsLabel destructor +// +//------------------------------------------------------------------------- +nsLabel::~nsLabel() +{ +} + + +//------------------------------------------------------------------------- +// +// Create the nativeLabel widget +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::CreateNative( PtWidget_t *aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsLabel::CreateNative at (%d,%d) for (%d,%d)\n",mBounds.x,mBounds.y, mBounds.width, mBounds.height)); + NS_PRECONDITION(aParent, "nsLabel::CreateNative aParent is NULL"); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width; + dim.h = mBounds.height; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 0, 0 ); + + mWidget = PtCreateWidget( PtButton, aParent, 3, arg ); + if( mWidget ) + { + res = NS_OK; + } + + NS_POSTCONDITION(mWidget, "nsLabel::CreateNative Failed to create native label"); + + return res; +} + + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData) +{ + if (nsnull != aInitData) { + nsLabelInitData* data = (nsLabelInitData *) aInitData; + mAlignment = data->mAlignment; + } + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Set alignment +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment) +{ + mAlignment = aAlignment; + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsLabel::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + + nsresult result = nsWidget::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kILabelIID)) { + *aInstancePtr = (void*) ((nsILabel*)this); + AddRef(); + result = NS_OK; + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::SetLabel(const nsString& aText) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsLabel:SetLabel\n")); + + if( mWidget ) + { + PtArg_t arg; + + NS_ALLOC_STR_BUF(label, aText, 256); + + PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + + NS_FREE_STR_BUF(label); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsLabel::GetLabel(nsString& aBuffer) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsLabel:GetLabel\n")); + + aBuffer.SetLength(0); + + if( mWidget ) + { + PtArg_t arg; + char *label; + + PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + aBuffer.Append( label ); + res = NS_OK; + } + } + + return res; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsLabel::OnMove(PRInt32, PRInt32) +{ + return PR_FALSE; +} + +PRBool nsLabel::OnPaint(nsPaintEvent &aEvent) +{ + //printf("** nsLabel::OnPaint **\n"); + return PR_FALSE; +} + +PRBool nsLabel::OnResize(nsSizeEvent &aEvent) +{ + return PR_FALSE; +} diff --git a/widget/src/photon/nsLabel.h b/widget/src/photon/nsLabel.h new file mode 100644 index 000000000000..cfb867c6d77c --- /dev/null +++ b/widget/src/photon/nsLabel.h @@ -0,0 +1,61 @@ +/* -*- 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 "nsWidget.h" +#include "nsIAppShell.h" +#include "nsILabel.h" + +/** + * Native Photon Label wrapper + */ +class nsLabel : public nsWidget, + public nsILabel +{ + +public: + + nsLabel(); + virtual ~nsLabel(); + + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + + // nsILabel part + NS_IMETHOD SetLabel(const nsString &aText); + NS_IMETHOD GetLabel(nsString &aBuffer); + NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment); + + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsPaintEvent &aEvent); + virtual PRBool OnResize(nsSizeEvent &aEvent); + +protected: + NS_METHOD CreateNative( PtWidget_t *aParent ); + + nsLabelAlignment mAlignment; + +}; + +#endif // nsLabel_h__ diff --git a/widget/src/photon/nsListBox.cpp b/widget/src/photon/nsListBox.cpp new file mode 100644 index 000000000000..5a01b4ced060 --- /dev/null +++ b/widget/src/photon/nsListBox.cpp @@ -0,0 +1,517 @@ +/* -*- 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 "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" + +#include +#include "nsPhWidgetLog.h" + + +NS_IMPL_ADDREF(nsListBox) +NS_IMPL_RELEASE(nsListBox) + +//------------------------------------------------------------------------- +// +// nsListBox constructor +// +//------------------------------------------------------------------------- +nsListBox::nsListBox() : nsWidget(), nsIListWidget(), nsIListBox() +{ + NS_INIT_REFCNT(); + mMultiSelect = PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// nsListBox:: destructor +// +//------------------------------------------------------------------------- +nsListBox::~nsListBox() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::~nsListBox - Destructor Called\n")); +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWidget::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); + AddRef(); + result = NS_OK; + } + else if (aIID.Equals(kInsListWidgetIID)) { + *aInstancePtr = (void*) ((nsIListWidget*)this); + AddRef(); + result = NS_OK; + } + } + + return result; +} + + +//------------------------------------------------------------------------- +// +// initializer +// +//------------------------------------------------------------------------- + +NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SetMultipleSelection aMultipleSelections=<%d>\n", aMultipleSelections)); + + PtArg_t arg; + nsresult res = NS_ERROR_FAILURE; + + mMultiSelect = aMultipleSelections; + + if (mWidget) + { + if (mMultiSelect) + PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_EXTENDED_MODE), 0); + else + PtSetArg( &arg, Pt_ARG_SELECTION_MODE, (Pt_SINGLE_MODE), 0); + + if ( PtSetResources(mWidget, 1, &arg ) == 0) + res = NS_OK; + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// AddItemAt +// +//------------------------------------------------------------------------- + +NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition) +{ + char *str = aItem.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::AddItemAt aItem=<%s> aPosition=<%d>\n", str, aPosition)); + + PtArg_t arg; + nsresult res = NS_ERROR_FAILURE; + int err; + + if (mWidget) + { + err = PtListAddItems(mWidget, (const char **) &str, 1, (unsigned int) (aPosition+1)); + if (err == 0) + res = NS_OK; + } + + delete [] str; + return res; +} + +//------------------------------------------------------------------------- +// +// Finds an item at a postion +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos) +{ + char *str = aItem.ToNewCString(); + int index = -1; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::AddItemAt aItem=<%s> aStartPos=<%d>\n", str, aStartPos)); + + if (mWidget) + { + index = PtListItemPos(mWidget, str); + if (index == 0) + index = -1; /* item wasn't found */ + } + + + delete [] str; + return index; +} + +//------------------------------------------------------------------------- +// +// CountItems - Get Item Count +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetItemCount() +{ + PtArg_t arg; + short *theCount; + PRInt32 total = 0; + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_LIST_ITEM_COUNT, &theCount, 0); + PtGetResources(mWidget, 1, &arg ); + + total = *theCount; + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetItemCount is <%d>\n", total)); + return total; +} + +//------------------------------------------------------------------------- +// +// Removes an Item at a specified location +// +//------------------------------------------------------------------------- +PRBool nsListBox::RemoveItemAt(PRInt32 aPosition) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::RemoveItemAt %d\n", aPosition)); + + int err; + PRBool res = PR_FALSE; + + if (mWidget) + { + if (PtListDeleteItemPos(mWidget, 1, (aPosition+1)) == 0) + res = PR_TRUE; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// +// +//------------------------------------------------------------------------- +PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition) +{ + PRBool result = PR_FALSE; + short *num; + char **items; + PtArg_t arg; + + /* Clear the nsString */ + anItem.SetLength(0); + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_ITEMS, &items, &num); + PtGetResources(mWidget, 1, &arg ); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetItemAt aPosition=<%d> aItem=<%s>\n", aPosition, items[aPosition])); + + anItem.Append(items[aPosition]); + result = PR_TRUE; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// Gets the text from the first selected Item +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::GetSelectedItem(nsString& aItem) +{ + int theFirstSelectedItem = GetSelectedIndex(); + nsresult res = NS_ERROR_FAILURE; + + + if (mWidget) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedItem theFirstSelectedItem is <%d>\n", theFirstSelectedItem)); + + GetItemAt(aItem, theFirstSelectedItem); + + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Gets the list of selected items +// Gets the Position of the first selected Item or -1 if no items. +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetSelectedIndex() +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndex - Not Implemented\n")); + + PRInt32 index=-1; + int theFirstSelectedItem[1]; + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + GetSelectedIndices(theFirstSelectedItem, 1); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndex theFirstSelectedItem is <%d>\n", theFirstSelectedItem[0])); + + index = theFirstSelectedItem[0]; + res = NS_OK; + } + + return index; +} + +//------------------------------------------------------------------------- +// +// SelectItem +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::SelectItem(PRInt32 aPosition) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SelectItem %d\n", aPosition)); + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + PtListSelectPos(mWidget, (aPosition+1)); /* Photon is 1 based */ + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// GetSelectedCount +// +//------------------------------------------------------------------------- +PRInt32 nsListBox::GetSelectedCount() +{ + PtArg_t arg; + short *theCount; + PRInt32 total = 0; + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_LIST_SEL_COUNT, &theCount, 0); + PtGetResources(mWidget, 1, &arg ); + + total = *theCount; + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedCount theCount=<%d>\n", total)); + return total; +} + +//------------------------------------------------------------------------- +// +// GetSelectedIndices +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices aSize=<%d>\n", aSize)); + + PRInt32 i=0, num = 0; + short *theSelectedIndices, *theSelectedCount; + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg; + + if (mWidget) + { + PtSetArg( &arg, Pt_ARG_SELECTION_INDEXES, &theSelectedIndices, &theSelectedCount); + PtGetResources(mWidget, 1, &arg ); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices Found %d Selected Items\n", *theSelectedCount)); + + for (i=0; i < *theSelectedCount && i < aSize; i++) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::GetSelectedIndices %d is Selected.\n", theSelectedIndices[i])); + + aIndices[i] = (theSelectedIndices[i]-1) ; /* photon is 1 based, mozilla appears to be 0 based */ + } + + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// SetSelectedIndices +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::SetSelectedIndices\n")); + + /* De-Select Everything ... */ + Deselect(); + + int i; + for (i=0;i\n", theList[i])); + PtListUnselectPos(mWidget, theList[i]); + } + + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Set initial parameters +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::PreCreateWidget - Not Implemented\n")); + + if (nsnull != aInitData) { + nsListBoxInitData* data = (nsListBoxInitData *) aInitData; + mMultiSelect = data->mMultiSelect; + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Create the native widget +// +//------------------------------------------------------------------------- +NS_METHOD nsListBox::CreateNative(PtWidget_t *parentWindow) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::CreateNative\n")); + + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width - 4; // Correct for border width + dim.h = mBounds.height - 4; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 ); + + mWidget = PtCreateWidget( PtList, parentWindow, 3, arg ); + if( mWidget ) + { + res = NS_OK; + + /* Mozilla calls this first before we have a widget so re-call this */ + SetMultipleSelection(mMultiSelect); + + /* Add a Callback so I can keep track of whats selected or not */ +// PtAddCallback(mWidget, Pt_CB_SELECTION, handle_selection_event, this); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsListBox::OnMove(PRInt32, PRInt32) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnMove - Not Implemented\n")); + + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsListBox::OnPaint(nsPaintEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnPaint - Not Implemented\n")); + + return PR_FALSE; +} + +PRBool nsListBox::OnResize(nsSizeEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::OnResize - Not Implemented\n")); + + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Callback when user selects or deselects an item +// +//------------------------------------------------------------------------- +int nsListBox::handle_selection_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ) +{ + nsListBox *me = (nsListBox *) aData; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsListBox::handle_select_event widget=<%p>\n",me)); + + if ((me) && (aCbinfo->reason == Pt_CB_SELECTION) && + (aCbinfo->reason_subtype == Pt_LIST_SELECTION_FINAL)) + { + PtListCallback_t *ListCallback = (PtListCallback_t *) aCbinfo->cbdata; + +// PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsListBox::handle_select_event mode=<%d>\n",ListCal)); + + } + + return (Pt_CONTINUE); +} \ No newline at end of file diff --git a/widget/src/photon/nsListBox.h b/widget/src/photon/nsListBox.h new file mode 100644 index 000000000000..78b9e36cb866 --- /dev/null +++ b/widget/src/photon/nsListBox.h @@ -0,0 +1,72 @@ +/* -*- 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 "nsWidget.h" +#include "nsIListBox.h" + +/** + * Native Photon Listbox wrapper + */ + +class nsListBox : public nsWidget, + public nsIListWidget, + public nsIListBox +{ + +public: + nsListBox(); + virtual ~nsListBox(); + + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(nsPaintEvent & aEvent); + virtual PRBool OnResize(nsSizeEvent &aEvent); + + + // nsIListBox interface + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData); + 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() ; + +protected: + NS_IMETHOD CreateNative(PtWidget_t *parentWindow); + static int handle_selection_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); + + PRBool mMultiSelect; +}; + +#endif // nsListBox_h__ diff --git a/widget/src/photon/nsLookAndFeel.cpp b/widget/src/photon/nsLookAndFeel.cpp index 7196db1c71ca..e1a540760427 100644 --- a/widget/src/photon/nsLookAndFeel.cpp +++ b/widget/src/photon/nsLookAndFeel.cpp @@ -19,6 +19,7 @@ #include "nsLookAndFeel.h" #include #include "nsFont.h" +#include "nsPhWidgetLog.h" NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); NS_IMPL_ISUPPORTS(nsLookAndFeel,kILookAndFeelIID); @@ -36,37 +37,63 @@ NS_IMETHODIMP nsLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor) { nsresult res = NS_OK; -#if 0 +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - Not Implemented!\n")); + switch( aID ) { case eColor_WindowBackground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WindowBackground\n")); + aColor = NS_RGB(255,255,255); /* White */ break; case eColor_WindowForeground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WindowForeground\n")); + aColor = NS_RGB(0,0,0); /* Black */ break; case eColor_WidgetBackground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WidgetBackground\n")); + aColor = NS_RGB(128,128,128); /* Gray */ break; case eColor_WidgetForeground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WidgetForeground\n")); + aColor = NS_RGB(0,0,0); /* Black */ break; case eColor_WidgetSelectBackground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WidgetSelectBackground\n")); + aColor = NS_RGB(200,200,200); /* Dark Gray */ break; case eColor_WidgetSelectForeground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - WidgetSelectForeground\n")); + aColor = NS_RGB(0,0,0); /* Black */ break; case eColor_Widget3DHighlight: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - Widget3DHighlight\n")); + aColor = NS_RGB(255,255,255); /* White */ break; case eColor_Widget3DShadow: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - Widget3DHighlight\n")); + aColor = NS_RGB(200,200,200); /* Dark Gray */ break; case eColor_TextBackground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - TextBackground\n")); + aColor = NS_RGB(255,255,255); /* White */ break; case eColor_TextForeground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - TextForeground\n")); + aColor = NS_RGB(0,0,0); /* Black */ break; case eColor_TextSelectBackground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - TextSelectBackground\n")); + aColor = NS_RGB(0,0,255); /* Blue */ break; case eColor_TextSelectForeground: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - TextSelectForeground\n")); + aColor = NS_RGB(255,255,255); /* White */ break; default: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetColor - Unknown Request!\n")); + res = NS_ERROR_FAILURE; break; } -#endif return res; } @@ -75,47 +102,67 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric) { nsresult res = NS_OK; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric\n")); + switch( aID ) { - case eMetric_WindowTitleHeight: - break; - case eMetric_WindowBorderWidth: - break; - case eMetric_WindowBorderHeight: - break; - case eMetric_Widget3DBorder: - break; - case eMetric_TextFieldHeight: - break; - case eMetric_ButtonHorizontalInsidePaddingNavQuirks: - break; - case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: - break; - case eMetric_CheckboxSize: - break; - case eMetric_RadioboxSize: - break; - case eMetric_TextHorizontalInsideMinimumPadding: - break; - case eMetric_TextVerticalInsidePadding: - break; - case eMetric_TextShouldUseVerticalInsidePadding: - break; - case eMetric_TextShouldUseHorizontalInsideMinimumPadding: - break; - case eMetric_ListShouldUseHorizontalInsideMinimumPadding: - break; - case eMetric_ListHorizontalInsideMinimumPadding: - break; - case eMetric_ListShouldUseVerticalInsidePadding: - break; - case eMetric_ListVerticalInsidePadding: - break; - default: - aMetric = -1; - res = NS_ERROR_FAILURE; - break; - } + case eMetric_WindowTitleHeight: + aMetric = 20; // REVISIT - HACK! + break; + case eMetric_WindowBorderWidth: + aMetric = 8; // REVISIT - HACK! + break; + case eMetric_WindowBorderHeight: + aMetric = 8; // REVISIT - HACK! + break; + case eMetric_Widget3DBorder: + aMetric = 2; + break; + case eMetric_TextFieldHeight: + aMetric = 23; + break; + case eMetric_ButtonHorizontalInsidePaddingNavQuirks: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_CheckboxSize: + aMetric = 10; // REVISIT - HACK! + break; + case eMetric_RadioboxSize: + aMetric = 10; // REVISIT - HACK! + break; + case eMetric_TextHorizontalInsideMinimumPadding: + aMetric = 1; // REVISIT - HACK! + break; + case eMetric_TextVerticalInsidePadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_TextShouldUseVerticalInsidePadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_TextShouldUseHorizontalInsideMinimumPadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_ListShouldUseHorizontalInsideMinimumPadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_ListHorizontalInsideMinimumPadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_ListShouldUseVerticalInsidePadding: + aMetric = 0; // REVISIT - HACK! + break; + case eMetric_ListVerticalInsidePadding: + aMetric = 0; // REVISIT - HACK! + break; + default: + aMetric = -1; + res = NS_ERROR_FAILURE; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric - Unknown ID!\n")); + break; + } return res; } @@ -124,6 +171,8 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetri { nsresult res = NS_OK; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric with float aID=<%d>\n", aID)); + switch( aID ) { case eMetricFloat_TextFieldVerticalInsidePadding: @@ -152,6 +201,7 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetri break; default: aMetric = -1.0; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsLookAndFeel::GetMetric (float) - Unknown ID!\n")); res = NS_ERROR_FAILURE; } diff --git a/widget/src/photon/nsMenu.cpp b/widget/src/photon/nsMenu.cpp new file mode 100644 index 000000000000..2462a2c9184e --- /dev/null +++ b/widget/src/photon/nsMenu.cpp @@ -0,0 +1,1010 @@ +/* -*- 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 +#include "nsPhWidgetLog.h" + +#include "nsMenu.h" +#include "nsIMenu.h" +#include "nsIMenuBar.h" +#include "nsIMenuItem.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" +#include "nsMenuItem.h" +#include "nsCOMPtr.h" +#include "nsIMenuListener.h" +#include "nsIComponentManager.h" + + +#include "nsWidgetsCID.h" +static NS_DEFINE_IID(kMenuBarCID, NS_MENUBAR_CID); +static NS_DEFINE_IID(kMenuCID, NS_MENU_CID); +static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); + +nsresult nsMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + *aInstancePtr = NULL; + + if (aIID.Equals(kIMenuIID)) + { + *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(kIMenuListenerIID)) + { + *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; + mMenuButton = nsnull; + mMenuParent = nsnull; + mMenuBarParent = nsnull; + mListener = nsnull; + mConstruct = PR_FALSE; + mIsSubMenu = PR_FALSE; + mParentWindow = nsnull; + mDOMNode = nsnull; + mDOMElement = nsnull; + mWebShell = nsnull; + + nsresult result = NS_NewISupportsArray(&mItems); +} + +//------------------------------------------------------------------------- +// +// nsMenu destructor +// +//------------------------------------------------------------------------- +nsMenu::~nsMenu() +{ + char *str=mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::~nsMenu Destructor called for <%s>\n", str)); + delete [] str; + + NS_IF_RELEASE(mListener); + + // Remove all references to the items + mItems->Clear(); + + /* Destroy my Photon Objects */ + if (mMenuButton) + PtDestroyWidget(mMenuButton); + if (mMenu) + PtDestroyWidget(mMenu); +} + +//------------------------------------------------------------------------- +// +// Create the proper widget +//------------------------------------------------------------------------- +NS_METHOD nsMenu::Create(nsISupports * aParent, const nsString &aLabel) +{ +#ifdef DEBUG + char *str=aLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::Create with nsISupports aLabel=<%s> this=<%p>\n", str, this)); + delete [] str; +#endif + + PtArg_t arg[5]; + void *voidData = nsnull; + PtWidget_t *myParent = nsnull; + void *me = (void *) this; + + /* Store the label in a local variable */ + mLabel = aLabel; + + /* Create a Char * string from a nsString */ + char *labelStr = mLabel.ToNewCString(); + + if(aParent) + { + nsIMenuBar * menubar = nsnull; + aParent->QueryInterface(kIMenuBarIID, (void**) &menubar); + if(menubar) + { + mMenuBarParent = menubar; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::Create with nsISupports menu on a menubar\n")); + + /* Get Photon Pointer that I will attach this menu to */ + mMenuBarParent->GetNativeData(voidData); + myParent = (PtWidget_t *) voidData; + + PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_DOWN, 0); + PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, labelStr, 0); + PtSetArg(&arg[2], Pt_ARG_USER_DATA, &me, sizeof(void *)); + mMenuButton = PtCreateWidget(PtMenuButton, myParent, 3, arg); + if (!mMenuButton) + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenu::Create failed to create menubuton for menu\n")); + return NS_ERROR_FAILURE; + } + + /* Set the Call back on this top level menu button */ + PtAddCallback(mMenuButton, Pt_CB_ARM, TopLevelMenuItemArmCb, this); + + /* Now Create the Photon Menu that is attached to the mMenuButton */ + PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_AUTO, 0xFFFFFFFF); + PtSetArg(&arg[1], Pt_ARG_USER_DATA, &me, sizeof(void *) ); + mMenu = PtCreateWidget (PtMenu, mMenuButton, 2, arg); + if (!mMenu) + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenu::Create failed to create menu for menubutton\n")); + return NS_ERROR_FAILURE; + } + + NS_RELEASE(menubar); + } + else + { + nsIMenu * menu = nsnull; + aParent->QueryInterface(kIMenuIID, (void**) &menu); + if(menu) + { + mMenuParent = menu; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::Create with nsISupports menu on a menu\n")); + + /* Get Photon Pointer that I will attach this menu to */ + mMenuParent->GetNativeData(&voidData); + myParent = (PtWidget_t *) voidData; + + PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0); + PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, labelStr, 0); + PtSetArg(&arg[2], Pt_ARG_USER_DATA, &me, sizeof(void *)); + mMenuButton = PtCreateWidget(PtMenuButton, myParent, 3, arg); + if (!mMenuButton) + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenu::Create failed to create menubuton for menu\n")); + return NS_ERROR_FAILURE; + } + + /* Set the Call back on this top level menu button */ + PtAddCallback(mMenuButton, Pt_CB_MENU, SubMenuMenuItemMenuCb, this); + PtAddCallback(mMenuButton, Pt_CB_ARM, SubMenuMenuItemArmCb, this); + + mIsSubMenu = PR_TRUE; +#if 0 + /* Now Create the Photon Menu that is attached to the mMenuButton */ + PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_CHILD | Pt_MENU_AUTO, 0xFFFFFFFF); + PtSetArg(&arg[1], Pt_ARG_USER_DATA, &me, sizeof(void *) ); + PtSetArg(&arg[2], Pt_ARG_FLAGS, Pt_DELAY_REALIZE, Pt_DELAY_REALIZE); + mMenu = PtCreateWidget (PtMenu, mMenuButton, 3, arg); + if (!mMenu) + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenu::Create failed to create menu for menubutton\n")); + return NS_ERROR_FAILURE; + } +#endif + NS_RELEASE(menu); + } + } + } + if (mMenu) + { + /* Set the Call back on each menu */ +// PtAddCallback(mMenu, Pt_CB_REALIZED, MenuRealizedCb, this); + PtAddCallback(mMenu, Pt_CB_UNREALIZED, MenuUnRealizedCb, this); + } + + PtRealizeWidget(mMenuButton); + delete[] labelStr; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::Create with nsIMenuBar PtMenuButton=<%p> PtMenu=<%p>\n", mMenuButton, mMenu)); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetParent(nsISupports*& aParent) +{ + aParent = nsnull; + if (nsnull != mMenuParent) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetParent is menu=<%p>\n", aParent)); + return mMenuParent->QueryInterface(kISupportsIID,(void**)&aParent); + } + else if (nsnull != mMenuBarParent) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetParent is menubar=<%p>\n", aParent)); + return mMenuBarParent->QueryInterface(kISupportsIID,(void**)&aParent); + } + + return NS_ERROR_FAILURE; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetLabel(nsString &aText) +{ +#ifdef DEBUG + char *str = mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetLabel mLabel=<%s>\n", str)); + delete [] str; +#endif + + aText = mLabel; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::SetLabel(const nsString &aText) +{ + mLabel = aText; + +#ifdef DEBUG + char * labelStr = mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SetLabel to this=<%p> <%s>\n", this, labelStr)); + delete [] labelStr; +#endif + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddItem(nsISupports* aItem) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::AddItem with nsISupports - not implemented this=<%p> aIten=<%p>.\n", this, aItem)); + + if(aItem) + { + nsIMenuItem * menuitem = nsnull; + aItem->QueryInterface(kIMenuItemIID, (void**) &menuitem); + if(menuitem) + { + AddMenuItem(menuitem); // nsMenu now owns this + NS_RELEASE(menuitem); + } + else + { + nsIMenu * menu = nsnull; + aItem->QueryInterface(kIMenuIID, (void**) &menu); + if(menu) + { + AddMenu(menu); // nsMenu now owns this + NS_RELEASE(menu); + } + } + } + + return NS_OK; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenuItem(nsIMenuItem * aMenuItem) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::AddItem nsIMenuItem this=<%p> aMenuItem=<%p> - not implemented.\n", this, aMenuItem)); + + return mItems->AppendElement((nsISupports *) aMenuItem); +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenu(nsIMenu * aMenu) +{ + nsString Label; + PtWidget_t *item = nsnull, *newmenu=nsnull; + char *labelStr; + void *voidData = nsnull; + + aMenu->GetLabel(Label); + + labelStr = Label.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::AddMenu this=<%p> aMenu=<%p> label=<%s> - not implemented.\n", this, aMenu, labelStr)); + +#if 1 + mItems->AppendElement((nsISupports *) aMenu); +#else + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem); + if (NS_OK == rv) + { + pnsMenuItem->Create(this, labelStr, PR_FALSE); //PR_TRUE); + nsISupports * supports = nsnull; + pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports); + AddItem(supports); // Parent should now own menu item + NS_RELEASE(supports); + + void * menuitem = nsnull; + pnsMenuItem->GetNativeData(menuitem); + + voidData = NULL; + aMenu->GetNativeData(&voidData); + newmenu = (PtWidget_t *) voidData; + +// gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), newmenu); + NS_RELEASE(pnsMenuItem); + } +#endif + + delete[] labelStr; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddSeparator() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::AddSeparater this=<%p>\n", this)); + +/* REVISIT this could be broken in regard to ref count */ + + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem); + if (NS_OK == rv) + { +// nsString tmp = "separator"; +// nsString tmp; +// pnsMenuItem->Create((nsISupports *) this, tmp, PR_TRUE); + + nsISupports * supports = nsnull; + QueryInterface(kISupportsIID, (void**) &supports); + pnsMenuItem->Create(supports, "", 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; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetItemCount(PRUint32 &aCount) +{ + mItems->Count(&aCount); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetItemCount: %d\n", aCount)); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetItemAt(const PRUint32 aPos, nsISupports *& aMenuItem) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetItemAt aPos=<%d>\n", aPos)); + aMenuItem = (nsISupports *)mItems->ElementAt(aPos); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::InsertItemAt(const PRUint32 aPos, nsISupports * aMenuItem) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::InsertItemAt - Not Implemented\n")); + + mItems->InsertElementAt(aMenuItem, (PRInt32) aPos); + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::InsertSeparator(const PRUint32 aPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::InsertSeparator - Not Implemented\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveItem(const PRUint32 aPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::RemoveItem at %d\n", aPos)); + mItems->RemoveElementAt(aPos); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveAll() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::RemoveAll - Not Implemented\n")); + + while (PR_TRUE) + { + PRUint32 cnt; + mItems->Count(&cnt); + if (cnt == 0) + break; + mItems->RemoveElementAt(0); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::GetNativeData(void **aData) +{ + *aData = (void *)mMenu; + return NS_OK; +} + +PtWidget_t *nsMenu::GetNativeParent() +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetNativeParent\n")); + + void * voidData; + if (nsnull != mMenuParent) + { + mMenuParent->GetNativeData(&voidData); + } + else if (nsnull != mMenuBarParent) + { + mMenuBarParent->GetNativeData(voidData); + } + else + { + voidData = nsnull; + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::GetNativeParent parent=<%p>\n", voidData)); + + return (PtWidget_t *) voidData; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::AddMenuListener(nsIMenuListener * aMenuListener) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::AddMenuListener\n")); + + NS_IF_RELEASE(mListener); + mListener = aMenuListener; + NS_ADDREF(mListener); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenu::RemoveMenuListener(nsIMenuListener * aMenuListener) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::RemoveMenuListener\n")); + + if (aMenuListener == mListener) + { + NS_IF_RELEASE(mListener); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// nsIMenuListener interface +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + char *labelStr = mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuItemSelected mLabel=<%s>\n", labelStr)); + delete [] labelStr; + + if (nsnull != mListener) + { + NS_ASSERTION(false, "nsMenu::MenuItemSelected - get debugger"); + mListener->MenuSelected(aMenuEvent); + } + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenu::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + char *labelStr = mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuSelected mLabel=<%s>\n", labelStr)); + delete [] labelStr; + + if(mConstruct) + { + MenuDestruct(aMenuEvent); + mConstruct = false; + } + + if(!mConstruct) + { + MenuConstruct(aMenuEvent, mParentWindow, mDOMNode, mWebShell); + mConstruct = true; + } + + if (nsnull != mListener) + { + NS_ASSERTION(false, "nsMenu::MenuSelected - get debugger"); + mListener->MenuSelected(aMenuEvent); + } + + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuDeselected(const nsMenuEvent & aMenuEvent) +{ + char *str=mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuDeSelected for <%s> - Not Implemented\n", str)); + delete [] str; + + if (nsnull != mListener) + { + NS_ASSERTION(false, "nsMenu::MenuDeselected - get debugger"); + mListener->MenuDeselected(aMenuEvent); + } + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell) +{ + char *str=mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuConstruct for <%s>\n", str)); +// delete [] str; + + if(menuNode) + { + SetDOMNode((nsIDOMNode*) menuNode); + } + + if(!aWebShell) + { + aWebShell = mWebShell; + } + + // 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); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuConstruct menuitem for <%s> mRefCnt=<%d>\n", str, mRefCnt)); + + } + else if (menuitemNodeType.Equals("separator")) + { + AddSeparator(); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuConstruct seperator for <%s> mRefCnt=<%d>\n", str, mRefCnt)); + } + else if (menuitemNodeType.Equals("menu")) + { + // Load a submenu + LoadSubMenu(this, menuitemElement, menuitemNode); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuConstruct menu for <%s> mRefCnt=<%d>\n", str, mRefCnt)); + + } + } + + ++menuIndex; + + nsCOMPtr oldmenuitemNode(menuitemNode); + oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode)); + } // end menu item innner loop + + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent) +{ + char *str=mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuDestruct called for <%s> mRefCnt=<%d>\n", str, this->mRefCnt)); + delete [] str; + + // We cannot call RemoveAll() yet because menu item selection may need it + //RemoveAll(); + + while (PR_TRUE) + { + PRUint32 cnt; + mItems->Count(&cnt); + if (cnt == 0) + break; + + mItems->RemoveElementAt(0); + } + + /* Only destroy submenus */ + if ((mIsSubMenu) && (mMenu)) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuDestruct called for SubMenu\n")); + PtDestroyWidget(mMenu); + mMenu = nsnull; + } + + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +/** +* Set DOMNode +* +*/ +NS_METHOD nsMenu::SetDOMNode(nsIDOMNode * aMenuNode) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SetDOMNode\n")); + mDOMNode = aMenuNode; + return NS_OK; +} + +//------------------------------------------------------------------------- +/** +* Set DOMElement +* +*/ +NS_METHOD nsMenu::SetDOMElement(nsIDOMElement * aMenuElement) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SetDOMElement\n")); + mDOMElement = aMenuElement; + return NS_OK; +} + +//------------------------------------------------------------------------- +/** +* Set WebShell +* +*/ +NS_METHOD nsMenu::SetWebShell(nsIWebShell * aWebShell) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SetWebShell\n")); + 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); + + char *str = menuitemName.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -1- Label=<%s> mRefCnt=<%d> this=<%p>\n",str, mRefCnt, this)); + delete [] str; + + // Create nsMenuItem + nsIMenuItem * pnsMenuItem = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID, nsnull, kIMenuItemIID, (void**)&pnsMenuItem); + +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -2- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + if (NS_OK == rv) + { + pnsMenuItem->Create(pParentMenu, menuitemName, PR_FALSE); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -3- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + nsISupports * supports = nsnull; + pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -4- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + pParentMenu->AddItem(supports); // Parent should now own menu item +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -5- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + NS_RELEASE(supports); + + if (disabled == NS_STRING_TRUE ) + { + pnsMenuItem->SetEnabled(PR_FALSE); + } +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -6- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + // 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)); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -7- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + if (!domElement) + { + return; + } + + nsAutoString cmdAtom("onclick"); + nsString cmdName; +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -8- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + domElement->GetAttribute(cmdAtom, cmdName); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -9- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + pnsMenuItem->SetCommand(cmdName); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -10- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + // DO NOT use passed in webshell because of messed up windows dynamic loading + // code. + pnsMenuItem->SetWebShell(mWebShell); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -11- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + pnsMenuItem->SetDOMElement(domElement); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -12- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + NS_RELEASE(pnsMenuItem); +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadMenuItem -13- Label=<%s> mRefCnt=<%d>\n",str, mRefCnt)); + + } + return; +} + +//---------------------------------------- +void nsMenu::LoadSubMenu( + nsIMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode) +{ + nsString menuName; + menuElement->GetAttribute(nsAutoString("name"), menuName); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::LoadSubMenu <%s>\n", menuName.ToNewCString())); + + // Create nsMenu + nsIMenu * pnsMenu = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuCID, nsnull, kIMenuIID, (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); + pnsMenu->SetDOMElement(menuElement); + + NS_RELEASE(pnsMenu); + } +} + + +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +//------------------------------------------------------------------------- +int nsMenu::TopLevelMenuItemArmCb (PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo) +{ + nsMenu *aMenu = (nsMenu *) aNSMenu; + + if ((aMenu) && aMenu->mMenu) + { + char *labelStr = aMenu->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::TopLevelMenuItemArmCb - mLabel=<%s>\n", labelStr)); + delete [] labelStr; + } + + if ( (aMenu) && (aMenu->mMenu)) + { + nsIMenuListener *menuListener = nsnull; + nsIMenu *menu = (nsIMenu *)aNSMenu; + + if (menu != nsnull) + { + nsMenuEvent mevent; + mevent.message = NS_MENU_SELECTED; + mevent.eventStructType = NS_MENU_EVENT; + mevent.point.x = 0; + mevent.point.y = 0; + mevent.widget = nsnull; + mevent.time = PR_IntervalNow(); + menu->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if (menuListener) + { + menuListener->MenuConstruct(mevent,nsnull, // parent window + nsnull, // menuNode + nsnull); // webshell + NS_IF_RELEASE(menuListener); + } + } + } + + if ((aMenu) && aMenu->mMenu) + { + PtPositionMenu ( aMenu->mMenu, NULL); + PtRealizeWidget( aMenu->mMenu); + } + return( Pt_CONTINUE ); +} + +//------------------------------------------------------------------------- +int nsMenu::SubMenuMenuItemArmCb (PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo) +{ + PtArg_t arg[5]; + nsMenu *aMenu = (nsMenu *) aNSMenu; + + char *labelStr = aMenu->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SubMenuMenuItemArmCb - mLabel=<%s> mRefCnt=<%d>\n", labelStr, aMenu->mRefCnt)); + delete [] labelStr; + + if (aMenu->mMenu == nsnull) + { + /* Now Create the Photon Menu that is attached to the mMenuButton */ + PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_CHILD | Pt_MENU_AUTO, 0xFFFFFFFF); + PtSetArg(&arg[1], Pt_ARG_USER_DATA, &aNSMenu, sizeof(void *) ); + aMenu->mMenu = PtCreateWidget (PtMenu, aMenu->mMenuButton, 2, arg); + + /* Set the Call back on each menu */ +// PtAddCallback(aMenu->mMenu, Pt_CB_REALIZED, MenuRealizedCb, aMenu); + PtAddCallback(aMenu->mMenu, Pt_CB_UNREALIZED, MenuUnRealizedCb, aMenu); + } + + if ((aMenu) && (aMenu->mMenu)) + { + nsIMenuListener *menuListener = nsnull; + nsIMenu *menu = (nsIMenu *)aNSMenu; + + if (menu != nsnull) + { + nsMenuEvent mevent; + mevent.message = NS_MENU_SELECTED; + mevent.eventStructType = NS_MENU_EVENT; + mevent.point.x = 0; + mevent.point.y = 0; + mevent.widget = nsnull; + mevent.time = PR_IntervalNow(); + menu->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if (menuListener) + { + menuListener->MenuConstruct(mevent,nsnull, // parent window + nsnull, // menuNode + nsnull); // webshell + NS_IF_RELEASE(menuListener); + } + else + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SubMenuMenuItemArmCb - Error no menuListener defined!\n")); + } + } + } + + if ((aMenu) && aMenu->mMenu) + { + PtPositionMenu ( aMenu->mMenu, NULL); + PtRealizeWidget( aMenu->mMenu); + } + + return( Pt_CONTINUE ); +} +//------------------------------------------------------------------------- +int nsMenu::MenuRealizedCb (PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo) +{ + nsMenu *aMenu = (nsMenu *) aNSMenu; + + + if ((aMenu) && aMenu->mMenu) + { + char *labelStr = aMenu->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuRealizedCb - mLabel=<%s>\n", labelStr)); + delete [] labelStr; + } + + return( Pt_CONTINUE ); +} + +//------------------------------------------------------------------------- +int nsMenu::MenuUnRealizedCb (PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo) +{ + nsMenu *aMenu = (nsMenu *) aNSMenu; + if ((aMenu) && aMenu->mMenu) + { + char *labelStr = aMenu->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::MenuUnRealizedCb - mLabel=<%s>\n", labelStr)); + delete [] labelStr; + } + + + if ((aMenu) && aMenu->mMenu) + { + nsIMenuListener *menuListener = nsnull; + nsIMenu *menu = (nsIMenu *) aNSMenu; + if (menu != nsnull) + { + nsMenuEvent mevent; + mevent.message = NS_MENU_SELECTED; + mevent.eventStructType = NS_MENU_EVENT; + mevent.point.x = 0; + mevent.point.y = 0; + mevent.widget = nsnull; + mevent.time = PR_IntervalNow(); + menu->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if (menuListener) + { + menuListener->MenuDestruct(mevent); + NS_IF_RELEASE(menuListener); + } + } + } + return( Pt_CONTINUE ); +} + +//------------------------------------------------------------------------- +int nsMenu::SubMenuMenuItemMenuCb (PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo) +{ + nsMenu *aMenu = (nsMenu *) aNSMenu; + if ((aMenu) && aMenu->mMenu) + { + char *labelStr = aMenu->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenu::SubMenuMenuItemMenuCb - mLabel=<%s>\n", labelStr)); + delete [] labelStr; + } + + return( Pt_CONTINUE ); +} \ No newline at end of file diff --git a/widget/src/photon/nsMenu.h b/widget/src/photon/nsMenu.h new file mode 100644 index 000000000000..cbd5a0174502 --- /dev/null +++ b/widget/src/photon/nsMenu.h @@ -0,0 +1,129 @@ +/* -*- 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 "Pt.h" +#include "nsIMenu.h" +#include "nsISupportsArray.h" +#include "nsIMenuListener.h" + +class nsIMenuBar; +class nsIMenuListener; + +/** + * Native Photon Menu wrapper + */ + +class nsMenu : public nsIMenu, public nsIMenuListener +{ + +public: + nsMenu(); + virtual ~nsMenu(); + + NS_DECL_ISUPPORTS + + // nsIMenuListener methods + 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); + + + // nsIMenu Methods + NS_IMETHOD Create(nsISupports * aParent, const nsString &aLabel); + NS_IMETHOD GetParent(nsISupports *&aParent); + NS_IMETHOD GetLabel(nsString &aText); + NS_IMETHOD SetLabel(const nsString &aText); + + NS_IMETHOD AddItem(nsISupports * aItem); + + 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 AddMenuItem(nsIMenuItem * aMenuItem); + NS_IMETHOD AddMenu(nsIMenu * aMenu); + NS_IMETHOD InsertSeparator(const PRUint32 aPos); + + NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode); + NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement); + NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + + // Native Photon Support Methods + static int TopLevelMenuItemArmCb ( + PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo); + static int SubMenuMenuItemArmCb ( + PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo); + static int SubMenuMenuItemMenuCb ( + PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo); + static int MenuRealizedCb ( + PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo); + static int MenuUnRealizedCb ( + PtWidget_t *widget, void *aNSMenu, PtCallbackInfo_t *cbinfo); + +protected: + void LoadMenuItem( + nsIMenu * pParentMenu, + nsIDOMElement * menuitemElement, + nsIDOMNode * menuitemNode, + unsigned short menuitemIndex, + nsIWebShell * aWebShell); + + void LoadSubMenu( + nsIMenu * pParentMenu, + nsIDOMElement * menuElement, + nsIDOMNode * menuNode); + + void Create(PtWidget_t *aParent, const nsString &aLabel); + PtWidget_t *GetNativeParent(); + + nsString mLabel; + PtWidget_t *mMenu; + PtWidget_t *mMenuButton; + + nsISupportsArray *mItems; + nsIMenuListener *mListener; + + nsIMenu *mMenuParent; + nsIMenuBar *mMenuBarParent; + + nsIWidget * mParentWindow; + nsIDOMNode * mDOMNode; + nsIDOMElement * mDOMElement; + nsIWebShell * mWebShell; + PRBool mConstruct; + PRBool mIsSubMenu; +}; + +#endif // nsMenu_h__ diff --git a/widget/src/photon/nsMenuBar.cpp b/widget/src/photon/nsMenuBar.cpp new file mode 100644 index 000000000000..aca70892f57e --- /dev/null +++ b/widget/src/photon/nsMenuBar.cpp @@ -0,0 +1,387 @@ +/* -*- 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 +#include "nsPhWidgetLog.h" + +#include "nsMenuBar.h" +#include "nsIMenu.h" +#include "nsIMenuItem.h" +#include "nsIWidget.h" + +#include "nsString.h" +#include "nsStringUtil.h" + +#include "nsIComponentManager.h" +#include "nsCOMPtr.h" + +// CIDS +#include "nsWidgetsCID.h" +static NS_DEFINE_IID(kMenuBarCID, NS_MENUBAR_CID); +static NS_DEFINE_IID(kMenuCID, NS_MENU_CID); +static NS_DEFINE_IID(kMenuItemCID, NS_MENUITEM_CID); + +// IIDS +static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID); +static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID); +static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID); +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(kIMenuBarIID)) + { + *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(kIMenuListenerIID)) + { + *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(); + mMenuBar = nsnull; + mParent = nsnull; + mIsMenuBarAdded = PR_FALSE; + mConstructed = PR_FALSE; + mWebShell = nsnull; + mDOMNode = nsnull; + mDOMElement = nsnull; + + mItems = new nsVoidArray(); +} + +//------------------------------------------------------------------------- +// +// nsMenuBar destructor +// +//------------------------------------------------------------------------- +nsMenuBar::~nsMenuBar() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::~nsMenuBar Destructor Called - Not Implmenented\n")); + + // Remove all references to menus on this menubar + mItems->Clear(); + + if (mMenuBar) + PtDestroyWidget(mMenuBar); +} + +//------------------------------------------------------------------------- +// +// Create the proper widget +// +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::Create(nsIWidget *aParent) +{ + void *voidData; + PtWidget_t *parent; + void *me = (void *) this; + PtArg_t arg[1]; + + voidData = aParent->GetNativeData(NS_NATIVE_WINDOW); + parent = (PtWidget_t *) voidData; + + PtSetArg(&arg[0], Pt_ARG_USER_DATA, &me, sizeof(void *) ); + mMenuBar = PtCreateWidget( PtMenuBar, parent, 1, arg); + if (!mMenuBar) + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuBar::Create Failed to create the PtMenuBar\n")); + return NS_ERROR_FAILURE; + } + else + { + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuBar::Create with nsIWidget parent=%p, this=%p Photon menuBar=<%p>\n", aParent, this, mMenuBar)); + + SetParent(aParent); + PtRealizeWidget(mMenuBar); + return NS_OK; + } +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::GetParent mParent=<%p>\n", mParent)); + + aParent = mParent; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::SetParent(nsIWidget *aParent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::SetParent aParent=<%p>\n", aParent)); + + mParent = aParent; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu) +{ + NS_ASSERTION(aMenu, "NULL Pointer in nsMenuBar::AddMenu"); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::AddMenu aMenu=<%p>\n", aMenu)); + + /* Add the nsMenu to our list */ + mItems->AppendElement(aMenu); + NS_ADDREF(aMenu); // Not sure about this but windows did it + +#ifdef DEBUG + nsString Label; + aMenu->GetLabel(Label); + char *labelStr = Label.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::AddMenu Label is <%s>\n", labelStr)); + delete[] labelStr; +#endif + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetMenuCount(PRUint32 &aCount) +{ + aCount = mItems->Count();; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::GetMenuCount aCount=<%d>\n", aCount)); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetMenuAt(const PRUint32 aPos, nsIMenu *& aMenu) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::GetMenuAt %d\n", aPos)); + aMenu = (nsIMenu *) mItems->ElementAt(aPos); + NS_ADDREF(aMenu); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::InsertMenuAt(const PRUint32 aPos, nsIMenu *& aMenu) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::InsertMenuAt aPos=<%d> - Not Implemented\n", aPos)); + + mItems->InsertElementAt(aMenu, aPos); + NS_ADDREF(aMenu); + + if (!mIsMenuBarAdded) + { + if (mParent) + { + mParent->SetMenuBar(this); + } + mIsMenuBarAdded = PR_TRUE; + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::RemoveMenu(const PRUint32 aPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::RemoveMenu aPos=<%d>\n", aPos)); + + nsIMenu * menu = (nsIMenu *) mItems->ElementAt(aPos); + NS_RELEASE(menu); + mItems->RemoveElementAt(aPos); + + return NS_OK; +} +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::RemoveAll() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::RemoveAll\n")); + + while (mItems->Count()) + { + nsISupports * supports = (nsISupports *)mItems->ElementAt(0); + NS_RELEASE(supports); + mItems->RemoveElementAt(0); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::GetNativeData(void *& aData) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::GetNativeData this=<%p> mMenuBar=<%p>\n", this, mMenuBar)); + aData = (void *)mMenuBar; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::SetNativeData(void * aData) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::SetNativeData to <%p> - Not Implemented\n", aData)); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuBar::Paint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::Paint - Not Implemented\n")); + mParent->Invalidate(PR_TRUE); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsMenuListener interface +// +//------------------------------------------------------------------------- +nsEventStatus nsMenuBar::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::MenuItemSelected - Not Implemented\n")); + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + // I should determine which menu was selected and call MenuConstruct + // on it.. + // Not really sure what to do here, will have to wait until someone + // calls it! + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::MenuSelected aMenuEvent->nativeMsg=<%p> - Not Implemented\n", aMenuEvent.nativeMsg)); + + /* I have no idea what this really is... */ +// PtWidget_t *PhMenu = (PtWidget_t *) aMenuEvent.nativeMsg; + + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuDeselected(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::MenuDeSelected - Not Implemented\n")); + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuBar::MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menubarNode, + void * aWebShell) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::MenuConstruct\n")); + + mWebShell = (nsIWebShell*) aWebShell; + mDOMNode = (nsIDOMNode*)menubarNode; + + nsIMenuBar * pnsMenuBar = nsnull; + nsresult rv = nsComponentManager::CreateInstance(kMenuBarCID, nsnull, kIMenuBarIID, (void**)&pnsMenuBar); + if (NS_OK == rv) { + if (nsnull != pnsMenuBar) { + pnsMenuBar->Create(aParentWindow); + + // set pnsMenuBar as a nsMenuListener on aParentWindow + nsCOMPtr menuListener; + pnsMenuBar->QueryInterface(kIMenuListenerIID, 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, kIMenuIID, (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; +} + +nsEventStatus nsMenuBar::MenuDestruct(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuBar::MenuDeconstruct - Not Implemented\n")); + return nsEventStatus_eIgnore; +} diff --git a/widget/src/photon/nsMenuBar.h b/widget/src/photon/nsMenuBar.h new file mode 100644 index 000000000000..046d8ef0b0e0 --- /dev/null +++ b/widget/src/photon/nsMenuBar.h @@ -0,0 +1,80 @@ +/* -*- 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 "nsIMenuBar.h" +#include "nsIMenuListener.h" +#include "nsVoidArray.h" + +class nsIWidget; + +/** + * Native Photon MenuBar 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 + + // nsIMenuBar Methods + NS_IMETHOD Create(nsIWidget * aParent); + 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 aCount, nsIMenu *& aMenu); + NS_IMETHOD InsertMenuAt(const PRUint32 aCount, nsIMenu *& aMenu); + NS_IMETHOD RemoveMenu(const PRUint32 aCount); + NS_IMETHOD RemoveAll(); + NS_IMETHOD GetNativeData(void*& aData); + NS_IMETHOD Paint(); + NS_IMETHOD SetNativeData(void* aData); + +protected: + PtWidget_t *mMenuBar; + nsIWidget *mParent; + + PRBool mIsMenuBarAdded; + + nsVoidArray * mItems; /* Items on my menubar */ + + nsIDOMNode *mDOMNode; + nsIDOMElement *mDOMElement; + nsIWebShell *mWebShell; + PRBool mConstructed; +}; + +#endif // nsMenuBar_h__ diff --git a/widget/src/photon/nsMenuItem.cpp b/widget/src/photon/nsMenuItem.cpp new file mode 100644 index 000000000000..5bcd4c9d478c --- /dev/null +++ b/widget/src/photon/nsMenuItem.cpp @@ -0,0 +1,654 @@ +/* -*- 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 + +#include "nsMenuItem.h" +#include "nsIMenu.h" +#include "nsIMenuBar.h" +#include "nsIWidget.h" + +#include "nsStringUtil.h" + +#include "nsIPopUpMenu.h" + +#include "nsCOMPtr.h" +#include "nsIContentViewerContainer.h" +#include "nsIContentViewer.h" +#include "nsIDocumentViewer.h" +#include "nsIPresContext.h" +#include "nsIContent.h" +#include "nsIWebShell.h" + +#include "nsPhWidgetLog.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); + +/* Attach this Data structure to each PtMenuButton */ +/* because by the time we get into the menuitem callback the */ +/* nsMenuItem has already been destroyed. */ + +struct PhMenuData { + PRUint32 theCommand; + nsIMenuListener * theMenuListener; +}; + +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(kISupportsIID)) + { + *aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this; + NS_ADDREF_THIS(); + return NS_OK; + } + + if (aIID.Equals(kIMenuListenerIID)) + { + *aInstancePtr = (void*)(nsIMenuListener*)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; + mIsSubMenu = PR_FALSE; + mWebShell = nsnull; + mDOMElement = nsnull; +} + +//------------------------------------------------------------------------- +// +// nsMenuItem destructor +// +//------------------------------------------------------------------------- +nsMenuItem::~nsMenuItem() +{ + char *str=mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::~nsMenuItem Destructor called for <%s>\n", str)); + delete [] str; + + NS_IF_RELEASE(mListener); + + /* Destroy my Photon Objects */ + if (mMenuItem) + PtDestroyWidget (mMenuItem); +} + +//------------------------------------------------------------------------- +void nsMenuItem::Create(nsIWidget *aMBParent, + PtWidget_t *aParent, + const nsString &aLabel, + PRBool aIsSeparator) +{ + PtArg_t arg[3]; + void *me = (void *) this; + + + mTarget = aMBParent; + mLabel = aLabel; + + if (NULL == aParent || nsnull == aMBParent) + { + return; + } + + char * nameStr = mLabel.ToNewCString(); + +PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::nsMenuItem Create with MenuBar parent this=<%p> aMBParent=<%p> aParent=<%p> label=<%s>\n", this, aMBParent,aParent, nameStr)); + + PtSetArg ( &arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_TEXT, 0); + PtSetArg ( &arg[1], Pt_ARG_USER_DATA, &me, sizeof(void *) ); + + if (aIsSeparator) + { + mIsSeparator = PR_TRUE; + PtSetArg ( &arg[2], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0); + mMenuItem = PtCreateWidget (PtSeparator, aParent, 3, arg); + } + else + { + mIsSeparator = PR_FALSE; + PtSetArg ( &arg[2], Pt_ARG_TEXT_STRING, nameStr, 0); + mMenuItem = PtCreateWidget (PtMenuButton, aParent, 3, arg); + } + + + NS_ASSERTION(mMenuItem, "Null Photon PtMenuItem"); + + PtAddCallback(mMenuItem, Pt_CB_ACTIVATE, MenuItemActivateCb ,this); + + PtAddCallback(mMenuItem, Pt_CB_GOT_FOCUS, MenuItemArmCb ,this); + PtAddCallback(mMenuItem, Pt_CB_LOST_FOCUS, MenuItemDisarmCb ,this); + + delete[] nameStr; +} + +//------------------------------------------------------------------------- +/* Create a Menu Separator */ +NS_METHOD nsMenuItem::Create(nsIMenu * aParent) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::Create Separator with nsIMenu\n")); + + /* New M5 Way */ + mMenuParent = aParent; + mIsSeparator = PR_TRUE; + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::Create(nsIPopUpMenu * aParent) +{ + + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::Create with nsIPopUpMenu %p - Not Implemented\n", aParent)); + mIsSeparator = PR_TRUE; + return NS_OK; +} + + +//------------------------------------------------------------------------- +PtWidget_t *nsMenuItem::GetNativeParent() +{ + void * voidData; + + if (nsnull != mMenuParent) + { + mMenuParent->GetNativeData(&voidData); + } + else if (nsnull != mPopUpParent) + { + mPopUpParent->GetNativeData(voidData); + } + else + { + return nsnull; + } + + return (PtWidget_t *) voidData; +} + + +//------------------------------------------------------------------------- +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(popup); + NS_RELEASE(parent); + return widget; + + } else if (NS_OK == parent->QueryInterface(kIMenuBarIID,(void**)&menuBar)) { + if (NS_OK != menuBar->GetParent(widget)) { + widget = nsnull; + } + NS_RELEASE(menuBar); + NS_RELEASE(parent); + return widget; + } else { + NS_RELEASE(parent); + return nsnull; + } + } + return nsnull; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::Create(nsISupports *aParent, + const nsString &aLabel, + PRBool aIsSeparator) +{ + char *str=aLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::Create with nsIMenu this=<%p>, aParent=<%p> aLabel=<%s> aIsSep=<%d>\n",this, aParent, str, aIsSeparator)); + delete [] str; + + if (nsnull == aParent) + { + return NS_ERROR_FAILURE; + } + + mMenuParent = (nsIMenu *) aParent; /* HACK */ + + nsIWidget * widget = nsnull; // MenuBar's Parent + nsISupports * sups; + if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) + { + widget = GetMenuBarParent(sups); + NS_RELEASE(sups); // Balance the Query Interface + } + + Create(widget, GetNativeParent(), aLabel, aIsSeparator); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::Create(nsIPopUpMenu *aParent, + const nsString &aLabel, + PRUint32 aCommand) +{ + + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::Create with nsIPopUpMenu, Never Tested\n")); + + mPopUpParent = aParent; + + nsIWidget * widget = nsnull; + if (NS_OK != aParent->GetParent(widget)) + { + widget = nsnull; + } + + Create(widget, GetNativeParent(), aLabel, aCommand); + return NS_OK; +} + +//------------------------------------------------------------------------- +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::SetEnabled(PRBool aIsEnabled) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuItem::SetEnabled - Not Implmented\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetEnabled(PRBool *aIsEnabled) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuItem::GetEnabled - Not Implmented\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetChecked(PRBool aIsEnabled) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuItem::SetChecked - Not Implmented\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsMenuItem::GetChecked - Not Implmented\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand) +{ + aCommand = mCommand; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget) +{ + aTarget = mTarget; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetNativeData(void *& aData) +{ + aData = (void *)mMenuItem; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::AddMenuListener new mListener=<%p>\n", aMenuListener)); + + NS_IF_RELEASE(mListener); + mListener = aMenuListener; + NS_ADDREF(mListener); + +#if 1 + struct PhMenuData data; + PtArg_t arg; + + data.theCommand = mCommand; + data.theMenuListener = mListener; + + PtSetArg ( &arg, Pt_ARG_USER_DATA, &data, sizeof(struct PhMenuData)); + PtSetResources(mMenuItem, 1, &arg); +#endif + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::RemoveMenuListener(nsIMenuListener * aMenuListener) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::RemoveMenuListener\n")); + + if (mListener == aMenuListener) + { + NS_IF_RELEASE(mListener); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep) +{ + aIsSep = mIsSeparator; + return NS_OK; +} + +//------------------------------------------------------------------------- +// nsIMenuListener interface +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuItemSelected(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::MenuItemSelected\n")); + + if(!mIsSeparator) + { + DoCommand(); + } + + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::MenuSelected - Not Implemented\n")); + + if(mListener) + return mListener->MenuSelected(aMenuEvent); + + return nsEventStatus_eIgnore; +} + +nsEventStatus nsMenuItem::MenuDeselected(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::MenuDeSelected - Not Implemented\n")); + if(mListener) + return mListener->MenuDeselected(aMenuEvent); + + return nsEventStatus_eIgnore; +} + +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuConstruct( + const nsMenuEvent & aMenuEvent, + nsIWidget * aParentWindow, + void * menuNode, + void * aWebShell) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::MenuConstruct - Not Implemented\n")); + if (mListener) + { + mListener->MenuSelected(aMenuEvent); + } + + return nsEventStatus_eIgnore; +} +//------------------------------------------------------------------------- +nsEventStatus nsMenuItem::MenuDestruct(const nsMenuEvent & aMenuEvent) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::MenuDestruct - Not Implemented\n")); + if (mListener) + { + mListener->MenuDeselected(aMenuEvent); + } + + 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) +{ + char *str = aStrCmd.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::SetCommand mCommandStr=<%s>\n", str)); + delete [] str; + + mCommandStr = 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; + + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::DoCommand\n")); + + if(!mWebShell || !mDOMElement) + return rv; + + nsCOMPtr contentViewerContainer; + contentViewerContainer = do_QueryInterface(mWebShell); + if (!contentViewerContainer) { + NS_ERROR("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."); + return rv; + } + + nsCOMPtr docViewer; + docViewer = do_QueryInterface(contentViewer); + if (!docViewer) { + NS_ERROR("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."); + 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."); + return rv; + } + + rv = contentNode->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status); + return rv; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetDOMElement(nsIDOMElement * aDOMElement) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::SetDOMElement\n")); + mDOMElement = aDOMElement; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::GetDOMElement(nsIDOMElement ** aDOMElement) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::GetDOMElement\n")); + *aDOMElement = mDOMElement; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsMenuItem::SetWebShell(nsIWebShell * aWebShell) +{ + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsMenuItem::SetWebShell - Not Implemented\n")); + mWebShell = aWebShell; + return NS_OK; +} + + + + + + + +int nsMenuItem::MenuItemActivateCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo) +{ + nsMenuEvent event; + nsEventStatus status; + struct PhMenuData **theMenuData = NULL; + PtArg_t arg; + + /* Get the Data stored on the PtMenuButton */ + PtSetArg(&arg, Pt_ARG_USER_DATA, &theMenuData, 0); + PtGetResources(widget, 1, &arg); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::MenuItemActivate Callback theMenuData=<%p>\n", theMenuData)); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::MenuItemActivate Callback command=<%d> Listeneer=<%p>\n", (*theMenuData)->theCommand,(*theMenuData)->theMenuListener)); + + nsMenuItem *aMenuItem = (nsMenuItem *) nsClassPtr; + + if (aMenuItem != nsnull) + { + /* Fill out the event structure */ + event.message = NS_MENU_SELECTED; + event.eventStructType = NS_MENU_EVENT; + event.point = nsPoint (0,0); + event.time = PR_IntervalNow(); + event.widget = nsnull; + event.nativeMsg = NULL; + + aMenuItem->GetCommand(aMenuItem->mCommand); //event.mCommand = aMenuItem->mCommand; + event.mMenuItem = aMenuItem; + + nsIMenuListener *menuListener = nsnull; + aMenuItem->QueryInterface(kIMenuListenerIID, (void**)&menuListener); + if (menuListener) + { + menuListener->MenuItemSelected(event); + NS_IF_RELEASE(menuListener); + } + } + + return Pt_CONTINUE; +} + +int nsMenuItem::MenuItemArmCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo) +{ + nsMenuEvent event; + nsEventStatus status; + nsMenuItem *aMenuItem = (nsMenuItem *) nsClassPtr; + + char *str = aMenuItem->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::MenuItemArmCB Callback for <%s>\n", str)); + delete [] str; + + return Pt_CONTINUE; +} + +int nsMenuItem::MenuItemDisarmCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo) +{ + nsMenuEvent event; + nsEventStatus status; + nsMenuItem *aMenuItem = (nsMenuItem *) nsClassPtr; + + char *str = aMenuItem->mLabel.ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsMenuItem::MenuItemDisarmCB Callback for <%s>\n", str)); + delete [] str; + + return Pt_CONTINUE; +} \ No newline at end of file diff --git a/widget/src/photon/nsMenuItem.h b/widget/src/photon/nsMenuItem.h new file mode 100644 index 000000000000..7a660ee6d95c --- /dev/null +++ b/widget/src/photon/nsMenuItem.h @@ -0,0 +1,110 @@ +/* -*- 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 "nsIMenuItem.h" +#include "nsString.h" +#include "nsIMenuListener.h" + +class nsIMenu; +class nsIPopUpMenu; +class nsIWidget; + +/** + * Native Photon 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 SetDOMElement(nsIDOMElement * aDOMElement); + NS_IMETHOD GetDOMElement(nsIDOMElement ** aDOMElement); + NS_IMETHOD SetWebShell(nsIWebShell * aWebShell); + NS_IMETHOD SetCommand(const nsString & aStrCmd); + NS_IMETHOD DoCommand(); + + 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); + + // 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); + + // Photon Support Methods + static int MenuItemActivateCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo); + static int MenuItemArmCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo); + static int MenuItemDisarmCb (PtWidget_t *widget, void *nsClassPtr, PtCallbackInfo_t *cbinfo); + +protected: + NS_IMETHOD Create(nsIPopUpMenu *aParent, const nsString &aLabel, PRUint32 aCommand) ; + NS_IMETHOD Create(nsIMenu * aParent); + NS_IMETHOD Create(nsIPopUpMenu * aParent); + void Create(nsIWidget * aMBParent, PtWidget_t *aParent, + const nsString &aLabel, PRBool aIsSeparator); + nsIWidget *GetMenuBarParent(nsISupports * aParentSupports); + PtWidget_t *GetNativeParent(); + + + nsString mLabel; + PRUint32 mCommand; + nsIMenu *mMenuParent; + nsIPopUpMenu *mPopUpParent; + nsIWidget *mTarget; + + PtWidget_t *mMenuItem; + nsIMenuListener *mListener; + PRBool mIsSeparator; + PRBool mIsSubMenu; + + nsString mCommandStr; + nsIWebShell *mWebShell; + nsIDOMElement *mDOMElement; +}; + +#endif // nsMenuItem_h__ diff --git a/widget/src/photon/nsPhWidgetLog.h b/widget/src/photon/nsPhWidgetLog.h new file mode 100644 index 000000000000..e85944576c5f --- /dev/null +++ b/widget/src/photon/nsPhWidgetLog.h @@ -0,0 +1,65 @@ +/* -*- 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. + */ + +/* + * Used for Logging in the widget/src/photon directory. + */ + +#include +#include + +extern PRLogModuleInfo *PhWidLog; +extern unsigned char PhWidLogState; +#undef PR_LOG + +#define PR_LOG(_module,_level,_args) \ +PR_BEGIN_MACRO \ + if (_module == nsnull) { \ + extern void SigUsr1Handler(int); \ + struct sigaction act; \ + sigset_t set; \ + sigemptyset(&set); \ + sigaddset(&set, SIGUSR1); \ + act.sa_flags=0; \ + act.sa_mask=set; \ + act.sa_handler=&SigUsr1Handler; \ + sigaction( SIGUSR1, &act, NULL); \ + printf("nsPhWidgetLog: defining PhWidLog\n"); \ + PhWidLog = PR_NewLogModule("PhWidLog"); \ + PR_SetLogFile("logfile.txt"); \ + } \ + if ((_module)->level >= (_level)) \ + PR_LogPrint _args ;\ + else if (PhWidLogState) \ + PR_LogPrint _args ;\ +PR_END_MACRO + + +#if 0 + + extern void SigUsr1Handler(int); \ + struct sigaction act; \ + sigset_t set; \ + sigemptyset(&set); \ + sigaddset(&set, SIGUSR1); \ + act.sa_flags=0; \ + act.sa_mask=set; \ + act.sa_handler=&SigUsr1Handler; \ + sigaction( SIGUSR1, &act, NULL); \ + +#endif diff --git a/widget/src/photon/nsPopUpMenu.cpp b/widget/src/photon/nsPopUpMenu.cpp new file mode 100644 index 000000000000..f3b849b1387e --- /dev/null +++ b/widget/src/photon/nsPopUpMenu.cpp @@ -0,0 +1,212 @@ +/* -*- 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 "nsIWidget.h" + +#include "nsString.h" +#include "nsStringUtil.h" +#include "nsPhWidgetLog.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) +{ + + mParent = aParent; + NS_ADDREF(mParent); + + return NS_OK; +} + + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddItem(const nsString &aText) +{ + char * labelStr = mLabel.ToNewCString(); + delete[] labelStr; + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddItem(nsIMenuItem * aMenuItem) +{ + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddMenu(nsIMenu * aMenu) +{ + nsString Label; +// GtkWidget *item=NULL, *parentmenu=NULL, *newmenu=NULL; + char *labelStr; + void *voidData=NULL; + + aMenu->GetLabel(Label); + + labelStr = Label.ToNewCString(); + + GetNativeData(voidData); +// parentmenu = GTK_WIDGET(voidData); + +// item = gtk_menu_item_new_with_label (labelStr); +// gtk_widget_show(item); +// gtk_menu_shell_append (GTK_MENU_SHELL (parentmenu), item); + + delete[] labelStr; + + voidData = NULL; + +// aMenu->GetNativeData(voidData); +// newmenu = GTK_WIDGET(voidData); + +// gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), newmenu); + + // XXX add aMenu to internal data structor list + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::AddSeparator() +{ +// GtkWidget *widget; + +// widget = gtk_menu_item_new (); +// gtk_widget_show(widget); +// gtk_menu_shell_append (GTK_MENU_SHELL (mMenu), widget); + + 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; +} + +#if 0 +//------------------------------------------------------------------------- +void nsPopUpMenu::GetXY(GtkMenu *menu, gint *x, gint *y, gpointer user_data) +{ +// *x = ((nsPopUpMenu *)(user_data))->mX; +// *y = ((nsPopUpMenu *)(user_data))->mY; +} +#endif + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::ShowMenu(PRInt32 aX, PRInt32 aY) +{ +#if 0 + mX = aX; + mY = aY; + + gtk_menu_popup (GTK_MENU(mMenu), + NULL, + NULL, + GetXY, + this, + 0, + GDK_CURRENT_TIME); +#endif + + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetNativeData(void *& aData) +{ + aData = (void *)mMenu; + return NS_OK; +} + +//------------------------------------------------------------------------- +NS_METHOD nsPopUpMenu::GetParent(nsIWidget *& aParent) +{ + aParent = mParent; + return NS_OK; +} + + diff --git a/widget/src/photon/nsPopUpMenu.h b/widget/src/photon/nsPopUpMenu.h new file mode 100644 index 000000000000..d082d20fdfb6 --- /dev/null +++ b/widget/src/photon/nsPopUpMenu.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 nsPopUpMenu_h__ +#define nsPopUpMenu_h__ + +#include "nsIPopUpMenu.h" +#include + +class nsIWidget; + +/** + * Native Photon PopUpMenu 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(); +// static void GetXY(PtWidget_t *menu, int *x, int *y, gpointer user_data); + NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY); + NS_IMETHOD GetNativeData(void*& aData); + NS_IMETHOD GetParent(nsIWidget*& aParent); + +protected: + + nsString mLabel; + PRUint32 mNumMenuItems; + nsIWidget *mParent; + PtWidget_t *mMenu; +}; + +#endif // nsPopUpMenu_h__ + diff --git a/widget/src/photon/nsRadioButton.cpp b/widget/src/photon/nsRadioButton.cpp new file mode 100644 index 000000000000..dd213d90fd26 --- /dev/null +++ b/widget/src/photon/nsRadioButton.cpp @@ -0,0 +1,255 @@ +/* -*- 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 "nsString.h" +#include "nsStringUtil.h" +#include + +#include "nsILookAndFeel.h" +#include "nsWidgetsCID.h" +#include "nsIComponentManager.h" + +#include "nsIDeviceContext.h" +#include "nsIFontMetrics.h" + +#include "nsPhWidgetLog.h" + +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); + + +NS_IMPL_ADDREF(nsRadioButton) +NS_IMPL_RELEASE(nsRadioButton) + +//------------------------------------------------------------------------- +// +// nsRadioButton constructor +// +//------------------------------------------------------------------------- +nsRadioButton::nsRadioButton() : nsWidget(), nsIRadioButton() +{ + NS_INIT_REFCNT(); +} + +//------------------------------------------------------------------------- +// +// nsRadioButton destructor +// +//------------------------------------------------------------------------- +nsRadioButton::~nsRadioButton() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::~nsRadioButton - Not Implemented!\n")); +} + +nsresult nsRadioButton::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton:QueryInterface, mWidget=%p\n", mWidget)); + + if (NULL == aInstancePtr) + { + return NS_ERROR_NULL_POINTER; + } + + static NS_DEFINE_IID(kIRadioButton, NS_IRADIOBUTTON_IID); + if (aIID.Equals(kIRadioButton)) { + *aInstancePtr = (void*) ((nsIRadioButton*)this); + NS_ADDREF_THIS(); + return NS_OK; + } + + return nsWidget::QueryInterface(aIID,aInstancePtr); +} + +//------------------------------------------------------------------------- +// +// Set the RadioButton State +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::SetState(const PRBool aState) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsRadioButton:SetState, mWidget=%p new state is <%d>\n", mWidget, aState)); + nsresult res = NS_ERROR_FAILURE; + + mState = aState; + if (mWidget) + { + PtArg_t arg; + + if (mState) + PtSetArg( &arg, Pt_ARG_FLAGS, Pt_SET, Pt_SET ); + else + PtSetArg( &arg, Pt_ARG_FLAGS, 0, Pt_SET ); + + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get the RadioButton State +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::GetState(PRBool & aState) +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsRadioButton:GetState, mWidget=%p\n", mWidget)); + nsresult res = NS_ERROR_FAILURE; + + if (mWidget) + { + PtArg_t arg; + long *flags; + + PtSetArg( &arg, Pt_ARG_FLAGS, &flags, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if( *flags & Pt_SET ) + mState = PR_TRUE; + else + mState = PR_FALSE; + + res = NS_OK; + } + } + + aState = mState; + + return res; +} + +//------------------------------------------------------------------------- +// +// Set this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::SetLabel(const nsString& aText) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsRadioButton:SetLabel, mWidget=%p\n", mWidget)); + if( mWidget ) + { + PtArg_t arg; + + NS_ALLOC_STR_BUF(label, aText, 256); + + PtSetArg( &arg, Pt_ARG_TEXT_STRING, label, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + + NS_FREE_STR_BUF(label); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Get this button label +// +//------------------------------------------------------------------------- +NS_METHOD nsRadioButton::GetLabel(nsString& aBuffer) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::GetLabel\n")); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// move, paint, resizes message - ignore +// +//------------------------------------------------------------------------- +PRBool nsRadioButton::OnMove(PRInt32, PRInt32) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::OnMove - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsRadioButton::OnPaint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::OnPaint - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsRadioButton::OnResize(nsRect &aWindowRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::OnResize - Not Implemented\n")); + return PR_FALSE; +} + + +/** + * Renders the RadioButton for Printing + * + **/ +NS_METHOD nsRadioButton::Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsRadioButton::Paint - Not Implemented\n")); + return NS_OK; +} + + +NS_METHOD nsRadioButton::CreateNative( PtWidget_t* aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[15]; + PhPoint_t pos; + PhDim_t dim; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsRadioButton::CreateNative\n")); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width; + dim.h = mBounds.height; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 0, 0 ); + PtSetArg( &arg[3], Pt_ARG_INDICATOR_TYPE, Pt_RADIO, 0 ); + PtSetArg( &arg[4], Pt_ARG_INDICATOR_COLOR, Pg_BLACK, 0 ); + PtSetArg( &arg[5], Pt_ARG_SPACING, 0, 0 ); + PtSetArg( &arg[6], Pt_ARG_MARGIN_TOP, 0, 0 ); + PtSetArg( &arg[7], Pt_ARG_MARGIN_LEFT, 0, 0 ); + PtSetArg( &arg[8], Pt_ARG_MARGIN_BOTTOM, 0, 0 ); + PtSetArg( &arg[9], Pt_ARG_MARGIN_RIGHT, 0, 0 ); + PtSetArg( &arg[10], Pt_ARG_MARGIN_WIDTH, 0, 0 ); + PtSetArg( &arg[11], Pt_ARG_MARGIN_HEIGHT, 0, 0 ); + PtSetArg( &arg[12], Pt_ARG_VERTICAL_ALIGNMENT, Pt_TOP, 0 ); +// PtSetArg( &arg[13], Pt_ARG_TEXT_FONT, "helv08", 0 ); + + mWidget = PtCreateWidget( PtToggleButton, aParent, 13, arg ); + if( mWidget ) + { + PtAddEventHandler( mWidget, + Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY, + RawEventHandler, this ); + + res = NS_OK; + } + + return res; +} + diff --git a/widget/src/photon/nsRadioButton.h b/widget/src/photon/nsRadioButton.h new file mode 100644 index 000000000000..e2e6b6969af0 --- /dev/null +++ b/widget/src/photon/nsRadioButton.h @@ -0,0 +1,65 @@ +/* -*- 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 nsRadioButton_h__ +#define nsRadioButton_h__ + +#include "nsWindow.h" +#include "nsIRadioButton.h" +#include + +/** + * Native Photon Radio Button wrapper + */ + +class nsRadioButton : public nsWidget, 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); + + // nsBaseWidget + NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext, + const nsRect& aDirtyRect); + + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + virtual PRBool OnPaint(); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + + NS_IMETHOD CreateNative( PtWidget_t* aParent ); + static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); + + PRBool mState; + +}; + +#endif // nsRadioButton_h__ diff --git a/widget/src/photon/nsScrollbar.cpp b/widget/src/photon/nsScrollbar.cpp new file mode 100644 index 000000000000..16ba583f4c7e --- /dev/null +++ b/widget/src/photon/nsScrollbar.cpp @@ -0,0 +1,448 @@ +/* -*- 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 +#include "nsPhWidgetLog.h" + +#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):nsWidget (), nsIScrollbar () +{ + NS_INIT_REFCNT (); + + mOrientation = (aIsVertical) ? Pt_VERTICAL : Pt_HORIZONTAL; +} + +//------------------------------------------------------------------------- +// +// nsScrollbar destructor +// +//------------------------------------------------------------------------- +nsScrollbar::~nsScrollbar () +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::~nsScrollbar - Not Implemented.\n")); +} + +//------------------------------------------------------------------------- +// +// Create the native scrollbar widget +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::CreateNative (PtWidget_t * parentWindow) +{ + nsresult res = NS_ERROR_FAILURE; + PhPoint_t pos; + PhDim_t dim; + PtArg_t arg[5]; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::CreateNative\n")); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width; + dim.h = mBounds.height; + + PtSetArg( &arg[0], Pt_ARG_ORIENTATION, mOrientation, 0 ); + PtSetArg( &arg[1], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[2], Pt_ARG_DIM, &dim, 0 ); + mWidget = PtCreateWidget( PtScrollbar, parentWindow, 3, arg ); + if( mWidget ) + { + res = NS_OK; + + /* Add an Activate Callback */ + PtAddCallback(mWidget, Pt_CB_SCROLL_MOVE, handle_scroll_move_event, this); + } + + return res; +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsScrollbar::QueryInterface (const nsIID & aIID, void **aInstancePtr) +{ + nsresult result = nsWidget::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) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::SetMaxRange to %d\n", aEndRange)); + + if( mWidget ) + { + PtArg_t arg; + PtSetArg( &arg, Pt_ARG_MAXIMUM, aEndRange, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Return the range settings +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetMaxRange (PRUint32 & aMaxRange) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::GetMaxRange\n")); + + if( mWidget ) + { + PtArg_t arg; + int *max; + + PtSetArg( &arg, Pt_ARG_MAXIMUM, &max, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + aMaxRange = *max; + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Set the thumb position +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetPosition (PRUint32 aPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::SetPosition\n")); + + nsresult res = NS_ERROR_FAILURE; + + if( mWidget ) + { + PtArg_t arg; + + PtSetArg( &arg, Pt_ARG_SCROLL_POSITION, aPos, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + { + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Get the current thumb position. +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetPosition (PRUint32 & aPos) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::GetPosition\n")); + + if( mWidget ) + { + PtArg_t arg; + int *pos; + + PtSetArg( &arg, Pt_ARG_SCROLL_POSITION, &pos, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + aPos = *pos; + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Set the thumb size +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetThumbSize (PRUint32 aSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::SetThumbSize\n")); + nsresult res = NS_ERROR_FAILURE; + + if( mWidget ) + { + PtArg_t arg; + + PtSetArg( &arg, Pt_ARG_SLIDER_SIZE, aSize, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + { + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Get the thumb size +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetThumbSize (PRUint32 & aThumbSize) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::GetThumbSize\n")); + + if( mWidget ) + { + PtArg_t arg; + int *size; + + PtSetArg( &arg, Pt_ARG_SLIDER_SIZE, &size, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + aThumbSize = *size; + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Set the line increment for this scrollbar +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetLineIncrement (PRUint32 aLineIncrement) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::SetLineIncrement to %d \n", aLineIncrement)); + + nsresult res = NS_ERROR_FAILURE; + + if( mWidget ) + { + PtArg_t arg; + + PtSetArg( &arg, Pt_ARG_INCREMENT, aLineIncrement, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + { + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Get the line increment for this scrollbar +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::GetLineIncrement (PRUint32 & aLineInc) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::GetLineIncrement\n")); + + nsresult res = NS_ERROR_FAILURE; + + if( mWidget ) + { + PtArg_t arg; + int *incr; + + PtSetArg( &arg, Pt_ARG_INCREMENT, &incr, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + aLineInc = *incr; + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// Set all scrolling parameters +// +//------------------------------------------------------------------------- +NS_METHOD nsScrollbar::SetParameters (PRUint32 aMaxRange, PRUint32 aThumbSize, + PRUint32 aPosition, PRUint32 aLineIncrement) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::SetParameters\n")); + + nsresult res = NS_ERROR_FAILURE; + + if( mWidget ) + { + PtArg_t arg[5]; + + PtSetArg( &arg[0], Pt_ARG_MAXIMUM , aMaxRange, 0 ); + PtSetArg( &arg[1], Pt_ARG_SLIDER_SIZE , aThumbSize, 0 ); + PtSetArg( &arg[2], Pt_ARG_SCROLL_POSITION , aPosition, 0 ); + PtSetArg( &arg[3], Pt_ARG_INCREMENT, aLineIncrement, 0 ); + + if( PtSetResources( mWidget, 4, arg ) == 0 ) + { + res = NS_OK; + } + } + + return res; +} + + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsScrollbar::OnPaint (nsPaintEvent & aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::OnPaint - Not Implemented\n")); + + return PR_FALSE; +} + + +PRBool nsScrollbar::OnResize(nsSizeEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::OnResize - Not Implemented\n")); + + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// Deal with scrollbar messages (actually implemented only in nsScrollbar) +// --- This funciton is not necessary ---- +//------------------------------------------------------------------------- +PRBool nsScrollbar::OnScroll (nsScrollbarEvent & aEvent, PRUint32 cPos) +{ + PRBool result = PR_TRUE; + float newPosition; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::OnScroll cPos=<%d>\n", cPos)); + +#if 0 + /* I should look at the theScrollbarCallback->action and do something */ + switch (aEvent.message) + { + default: + break; + } +#endif + + if (mEventCallback) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsScrollbar::OnScroll Inside mEventCallback porotion\n", cPos)); + + aEvent.position = cPos; + result = ConvertStatus((*mEventCallback)(&aEvent)); + newPosition = aEvent.position; + } + else + PR_LOG(PhWidLog, PR_LOG_ERROR, ("nsScrollbar::OnScroll Error no mEventCallback defined\n")); + + return result; +} + +//------------------------------------------------------------------------- +// +// +// +//------------------------------------------------------------------------- +int nsScrollbar::handle_scroll_move_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ) +{ + nsScrollbar *me = (nsScrollbar *) aData; + nsScrollbarEvent scroll_event; + PRUint32 thePos = 0; + PtScrollbarCallback_t *theScrollbarCallback = (PtScrollbarCallback_t *) aCbinfo->cbdata; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsScrollbar::handle_activate_event me=<%p> new position=<%d>\n",me, theScrollbarCallback->position)); + + scroll_event.message = NS_SCROLLBAR_POS; + scroll_event.widget = (nsWidget *) me; + scroll_event.eventStructType = NS_SCROLLBAR_EVENT; + thePos = theScrollbarCallback->position; + + switch (theScrollbarCallback->action) + { + case Pt_SCROLL_DECREMENT: + scroll_event.message = NS_SCROLLBAR_LINE_PREV; + break; + case Pt_SCROLL_INCREMENT: + scroll_event.message = NS_SCROLLBAR_LINE_NEXT; + break; + case Pt_SCROLL_PAGE_INCREMENT: + scroll_event.message = NS_SCROLLBAR_PAGE_NEXT; + break; + case Pt_SCROLL_PAGE_DECREMENT: + scroll_event.message = NS_SCROLLBAR_PAGE_PREV; + break; + case NS_SCROLLBAR_POS: + scroll_event.message = NS_SCROLLBAR_POS; + break; + default: + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsScrollbar::handle_activate_event Invalid Scroll Type!\n")); + break; + } + + me->OnScroll(scroll_event, thePos); + + return (Pt_CONTINUE); +} \ No newline at end of file diff --git a/widget/src/photon/nsScrollbar.h b/widget/src/photon/nsScrollbar.h new file mode 100644 index 000000000000..2cb61f24991e --- /dev/null +++ b/widget/src/photon/nsScrollbar.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 nsScrollbar_h__ +#define nsScrollbar_h__ + +#include "nsWidget.h" +#include "nsIScrollbar.h" + +/** + * Native Photon scrollbar wrapper. + */ + +class nsScrollbar : public nsWidget, + public nsIScrollbar +{ + +public: + nsScrollbar(PRBool aIsVertical); + virtual ~nsScrollbar(); + + // nsISupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); + + // 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(nsPaintEvent & aEvent); + virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); + virtual PRBool OnResize(nsSizeEvent &aEvent); + +protected: + NS_IMETHOD CreateNative(PtWidget_t *parentWindow); + static int handle_scroll_move_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); + +private: + int mOrientation; + +}; + +#endif // nsScrollbar_ diff --git a/widget/src/photon/nsTextAreaWidget.cpp b/widget/src/photon/nsTextAreaWidget.cpp new file mode 100644 index 000000000000..9e3d82a4a0d9 --- /dev/null +++ b/widget/src/photon/nsTextAreaWidget.cpp @@ -0,0 +1,164 @@ +/* -*- 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" + +#include +#include "nsPhWidgetLog.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) + + +//------------------------------------------------------------------------- +// +// nsTextAreaWidget constructor +// +//------------------------------------------------------------------------- +nsTextAreaWidget::nsTextAreaWidget() : nsTextHelper() +{ + NS_INIT_REFCNT(); + mBackground = NS_RGB(124, 124, 124); +} + +//------------------------------------------------------------------------- +// +// nsTextAreaWidget destructor +// +//------------------------------------------------------------------------- +nsTextAreaWidget::~nsTextAreaWidget() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::~nsTextAreaWidget Destructor called.\n")); +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWidget::QueryInterface(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsTextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsTextAreaWidgetIID)) { + *aInstancePtr = (void*) ((nsITextAreaWidget*)this); + NS_ADDREF_THIS(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +PRBool nsTextAreaWidget::OnPaint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::OnPaint - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::OnResize - Not Implemented\n")); + return PR_FALSE; +} + +NS_METHOD nsTextAreaWidget::CreateNative( PtWidget_t* aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::CreateNative")); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width - 4; // Correct for border width + dim.h = mBounds.height - 4; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 ); + mWidget = PtCreateWidget( PtMultiText, aParent, 3, arg ); + if( mWidget ) + { + res = NS_OK; + PtAddEventHandler(mWidget, Ph_EV_KEY, RawEventHandler, this); + + /* Add an Activate Callback */ +// PtAddCallback(mWidget, Pt_CB_ACTIVATE, handle_activate_event, this); + } + + return res; +} + +int nsTextAreaWidget::RawEventHandler(PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbInfo ) +{ + nsTextAreaWidget *me = (nsTextAreaWidget *) aData; /* Mozilla object that created the event */ + +//PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::RawEventHandler\n")); + + if( aCbInfo->reason == Pt_CB_RAW ) + { + PhEvent_t* event = aCbInfo->event; + + switch( event->type ) + { + case Ph_EV_KEY: + { + PhKeyEvent_t* keyev = (PhKeyEvent_t*) PhGetData( event ); + me->DispatchKeyEvent(keyev); + break; + } + default: + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::RawEventHandler Unknown event\n")); + break; + } + } + + return (Pt_CONTINUE); +} + +#if 0 +int nsTextAreaWidget::handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ) +{ + nsTextAreaWidget *me = (nsTextAreaWidget *) aData; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextAreaWidget::handle_activate_event me=<%p> - Not Implemented\n",me)); + + return (Pt_CONTINUE); +} +#endif diff --git a/widget/src/photon/nsTextAreaWidget.h b/widget/src/photon/nsTextAreaWidget.h new file mode 100644 index 000000000000..43eb2759b8d3 --- /dev/null +++ b/widget/src/photon/nsTextAreaWidget.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 nsTextAreaWidget_h__ +#define nsTextAreaWidget_h__ + +#include "nsWindow.h" +#include "nsTextHelper.h" +#include "nsITextAreaWidget.h" + +/** + * Native Photon single 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); + + virtual PRBool OnPaint(); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + NS_IMETHOD CreateNative(PtWidget_t *aParentWindow); + static int RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ); +// static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); +}; + +#endif // nsTextAreaWidget_h__ diff --git a/widget/src/photon/nsTextHelper.cpp b/widget/src/photon/nsTextHelper.cpp new file mode 100644 index 000000000000..57a9fa974134 --- /dev/null +++ b/widget/src/photon/nsTextHelper.cpp @@ -0,0 +1,290 @@ +/* -*- 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" + +#include +#include "nsPhWidgetLog.h" + +NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::PreCreateWidget\n")); + + if (nsnull != aInitData) + { + nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData; + mIsPassword = data->mIsPassword; + mIsReadOnly = data->mIsReadOnly; + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars) +{ + PtArg_t arg[2]; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetMaxLength to %d\n", aChars)); + + if (mWidget) + { + PtSetArg(&arg[0], Pt_ARG_MAX_LENGTH, aChars, 0); + PtSetResources(mWidget, 1, arg); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::GetText\n")); + + PtArg_t arg[2]; + int length; + char *string; + + + if (mWidget) + { + PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, &string, 0); + PtGetResources(mWidget, 1, arg); + + aTextBuffer.SetLength(0); + aTextBuffer.Append(string); + aActualSize = aTextBuffer.Length(); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize) +{ + PtArg_t arg[2]; + + mText = aText; + + if (mWidget) + { + NS_ALLOC_STR_BUF(buf, aText, 512); + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetText to <%s>\n", buf)); + + PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, buf, 0); + PtSetResources(mWidget, 1, arg); + + NS_FREE_STR_BUF(buf); + } + + aActualSize = aText.Length(); + return NS_OK; +} + +NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::InsertText from %d to %d\n", aStartPos, aEndPos)); + + PtArg_t arg[2]; + int ret; + nsString currentText; + PRUint32 currentTextLength; + if (mWidget) + { + NS_ALLOC_STR_BUF(buf, aText, 512); + ret=PtTextModifyText(mWidget,0,0,aStartPos,buf,aText.Length()); + if (!ret) + { + PR_LOG(PhWidLog, PR_LOG_ERROR,("nsTextHelper::InsertText failed in call to PtTextModifyText\n")); + } + + NS_FREE_STR_BUF(buf); + } + aActualSize = aText.Length(); + + /* Re-get the text and store in the local variable mText */ + GetText(currentText, 0, currentTextLength); + mText = currentText; + + return NS_OK; +} + +NS_METHOD nsTextHelper::RemoveText() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::RemoveText\n")); + PtArg_t arg[2]; + + mText.SetLength(0); + + if (mWidget) + { + PtSetArg(&arg[0], Pt_ARG_TEXT_STRING, "", 0); + PtSetResources(mWidget, 1, arg); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword) +{ + mIsPassword = aIsPassword; + return NS_OK; +} + +NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetReadOnnly %d %d\n", aReadOnlyFlag, mIsReadOnly)); + + PtArg_t arg[2]; + int temp; + + aOldFlag = mIsReadOnly; + mIsReadOnly = aReadOnlyFlag; + + // Update the widget + if (mWidget) + { + if (mIsReadOnly) + temp = 0; + else + temp = 1; + + PtSetArg(&arg[0], Pt_ARG_TEXT_FLAGS, temp, Pt_EDITABLE); + PtSetResources(mWidget, 1, arg); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SelectAll() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SelectAll\n")); + + int start, end; + + if (mWidget) + { + start = 0; + end = SHRT_MAX; + PtTextSetSelection(mWidget, &start, &end); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetSelection %d to %d\n", aStartSel, aEndSel)); + +/* The text widget is 0 based! */ + + if (mWidget) + { + int start, end, err=0; + start = aStartSel; + end = aEndSel; + + err=PtTextSetSelection(mWidget, &start, &end); + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetSelection after err=%d start=%d end=%d\n", err, start, end)); + } + + return NS_OK; +} + + +NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel) +{ +/*revisit not sure if this is 1 or 0 based! */ + + if (mWidget) + { + int start, end; + + PtTextGetSelection(mWidget, &start, &end); + + *aStartSel = start; + *aEndSel = end; + + } + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::GetSelection aStartSel=<%d> aEndSel=<%d>\n", *aStartSel, *aEndSel)); + + return NS_OK; +} + +NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::SetCaretPosition at %d", aPosition)); + + PtArg_t arg[2]; + + if (mWidget) + { + short CursPos = aPosition; + + PtSetArg(&arg[0], Pt_ARG_CURSOR_POSITION, CursPos, 0); + PtSetResources(mWidget, 1, arg); + } + + return NS_OK; +} + +NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::GetCaretPosition\n")); + + PtArg_t arg[2]; + short *CaretPosition; + + if (mWidget) + { + PtSetArg(&arg[0], Pt_ARG_CURSOR_POSITION, &CaretPosition, 0); + PtGetResources(mWidget, 1, arg); + } + + aPos = PRUint32(*CaretPosition); + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::GetCaretPosition aPos=<%d>\n", aPos)); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// nsTextHelper constructor +// +//------------------------------------------------------------------------- + +nsTextHelper::nsTextHelper() : nsWidget(), nsITextAreaWidget(), nsITextWidget() +{ + mIsReadOnly = PR_FALSE; + mIsPassword = PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// nsTextHelper destructor +// +//------------------------------------------------------------------------- +nsTextHelper::~nsTextHelper() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextHelper::~nsTextHelper Destructor called\n")); +} diff --git a/widget/src/photon/nsTextHelper.h b/widget/src/photon/nsTextHelper.h new file mode 100644 index 000000000000..1d6a5d575205 --- /dev/null +++ b/widget/src/photon/nsTextHelper.h @@ -0,0 +1,62 @@ +/* -*- 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 "nsITextWidget.h" +#include "nsITextAreaWidget.h" +#include "nsWindow.h" + +/** + * Base class for nsTextAreaWidget and nsTextWidget + */ + +class nsTextHelper : public nsWidget, + 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); + +protected: + nsString mText; + PRBool mIsPassword; + PRBool mIsReadOnly; + +// virtual DWORD WindowExStyle(); + +}; + +#endif // nsTextHelper_h__ diff --git a/widget/src/photon/nsTextWidget.cpp b/widget/src/photon/nsTextWidget.cpp new file mode 100644 index 000000000000..484df47764cd --- /dev/null +++ b/widget/src/photon/nsTextWidget.cpp @@ -0,0 +1,162 @@ +/* -*- 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" + +#include +#include "nsPhWidgetLog.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() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::~nsTextWidget Destructor called.\n")); +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWidget::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; +} + +//------------------------------------------------------------------------- +// +// +//------------------------------------------------------------------------- +PRBool nsTextWidget::OnPaint() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::OnPaint - Not Implemented\n")); + return PR_FALSE; +} + +PRBool nsTextWidget::OnResize(nsRect &aWindowRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::OnResize - Not Implemented\n")); + return PR_FALSE; +} + +NS_METHOD nsTextWidget::CreateNative( PtWidget_t* aParent ) +{ + nsresult res = NS_ERROR_FAILURE; + PtArg_t arg[5]; + PhPoint_t pos; + PhDim_t dim; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::CreateNative")); + + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width - 4; // Correct for border width + dim.h = mBounds.height - 4; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 2, 0 ); + mWidget = PtCreateWidget( PtText, aParent, 3, arg ); + if( mWidget ) + { + res = NS_OK; + PtAddEventHandler(mWidget, Ph_EV_KEY, RawEventHandler, this); + + /* Add an Activate Callback */ + PtAddCallback(mWidget, Pt_CB_ACTIVATE, handle_activate_event, this); + } + + return res; +} + +int nsTextWidget::RawEventHandler(PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbInfo ) +{ + nsTextWidget *me = (nsTextWidget *) aData; /* Mozilla object that created the event */ + +//PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::RawEventHandler\n")); + + if( aCbInfo->reason == Pt_CB_RAW ) + { + PhEvent_t* event = aCbInfo->event; + + switch( event->type ) + { + case Ph_EV_KEY: + { + PhKeyEvent_t* keyev = (PhKeyEvent_t*) PhGetData( event ); + me->DispatchKeyEvent(keyev); + break; + } + default: + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::RawEventHandler Unknown event\n")); + break; + } + } + + return (Pt_CONTINUE); +} + +int nsTextWidget::handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ) +{ + nsTextWidget *me = (nsTextWidget *) aData; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsTextWidget::handle_activate_event me=<%p> - Not Implemented\n",me)); + + return (Pt_CONTINUE); +} \ No newline at end of file diff --git a/widget/src/photon/nsTextWidget.h b/widget/src/photon/nsTextWidget.h new file mode 100644 index 000000000000..bba52abb0aae --- /dev/null +++ b/widget/src/photon/nsTextWidget.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 nsTextWidget_h__ +#define nsTextWidget_h__ + +#include "nsWindow.h" +#include "nsTextHelper.h" +#include "nsITextWidget.h" + +/** + * Native Photon 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(); + virtual PRBool OnResize(nsRect &aWindowRect); + +protected: + NS_IMETHOD CreateNative(PtWidget_t *aParentWindow); + static int RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ); + static int handle_activate_event (PtWidget_t *aWidget, void *aData, PtCallbackInfo_t *aCbinfo ); +}; + +#endif // nsTextWidget_h__ diff --git a/widget/src/photon/nsToolkit.cpp b/widget/src/photon/nsToolkit.cpp index 40e0dbb22f86..580546938088 100644 --- a/widget/src/photon/nsToolkit.cpp +++ b/widget/src/photon/nsToolkit.cpp @@ -22,6 +22,7 @@ #include "prtime.h" #include "nsGUIEvent.h" #include +#include "nsPhWidgetLog.h" NS_DEFINE_IID(kIToolkitIID, NS_ITOOLKIT_IID); @@ -35,6 +36,8 @@ NS_IMPL_ISUPPORTS(nsToolkit,kIToolkitIID); nsToolkit::nsToolkit() { NS_INIT_REFCNT(); + + mWidget = NULL; } @@ -45,6 +48,7 @@ nsToolkit::nsToolkit() //------------------------------------------------------------------------- nsToolkit::~nsToolkit() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::~nsToolkit - Not Implemented.\n")); } @@ -54,6 +58,32 @@ nsToolkit::~nsToolkit() //------------------------------------------------------------------------- NS_METHOD nsToolkit::Init(PRThread *aThread) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::Init this=<%p> aThread=<%p>\n", this, aThread)); + if( aThread ) + { +/* + PtArg_t arg[5]; + PhPoint_t pos={-1000,-1000}; + PhDim_t dim={50,50}; + + printf( " Creating the hidden parent window.\n" ); + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_WINDOW_RENDER_FLAGS, Ph_WM_RENDER_TITLE | Ph_WM_RENDER_CLOSE, 0xFFFFFFFF ); + mWidget = PtCreateWidget( PtWindow, NULL, 3, arg ); + if( mWidget ) + { + PtRealizeWidget( mWidget ); + printf( "nsToolkit->mWidget = %p\n", mWidget ); + } +*/ + } + else + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsToolkit::Init - ERROR: Wants to create a thread!\n")); + } + return NS_OK; } diff --git a/widget/src/photon/nsToolkit.h b/widget/src/photon/nsToolkit.h index 6b4c5512c764..34b210079276 100644 --- a/widget/src/photon/nsToolkit.h +++ b/widget/src/photon/nsToolkit.h @@ -19,6 +19,7 @@ #ifndef TOOLKIT_H #define TOOLKIT_H +#include #include "nsIToolkit.h" class nsToolkit : public nsIToolkit @@ -28,11 +29,12 @@ public: NS_DECL_ISUPPORTS - nsToolkit(); - NS_IMETHOD Init( PRThread *aThread ); + nsToolkit(); + NS_IMETHOD Init( PRThread *aThread ); private: - ~nsToolkit(); + ~nsToolkit(); + PtWidget_t* mWidget; protected: diff --git a/widget/src/photon/nsWidget.cpp b/widget/src/photon/nsWidget.cpp new file mode 100644 index 000000000000..79f50dee466d --- /dev/null +++ b/widget/src/photon/nsWidget.cpp @@ -0,0 +1,1345 @@ +/* -*- 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 "nsPhWidgetLog.h" +#include "nsWidget.h" +#include "nsWindow.h" +#include "nsIDeviceContext.h" +#include "nsIAppShell.h" +#include "nsGfxCIID.h" +#include "nsIComponentManager.h" +#include "nsIFontMetrics.h" +#include + +// BGR, not RGB - REVISIT +#define NSCOLOR_TO_PHCOLOR(g,n) \ + g.red=NS_GET_B(n); \ + g.green=NS_GET_G(n); \ + g.blue=NS_GET_R(n); + +static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID); +static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID); + +//#define DBG 1 + +nsWidget::nsWidget() +{ + // XXX Shouldn't this be done in nsBaseWidget? + NS_INIT_REFCNT(); + + // get the proper color from the look and feel code + nsILookAndFeel * lookAndFeel; + if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) { + lookAndFeel->GetColor(nsILookAndFeel::eColor_WindowBackground, mBackground); + } + NS_RELEASE(lookAndFeel); + mWidget = nsnull; + mParent = nsnull; + mClient = nsnull; + mPreferredWidth = 0; + mPreferredHeight = 0; + mShown = PR_FALSE; + mBounds.x = 0; + mBounds.y = 0; + mBounds.width = 0; + mBounds.height = 0; + mIsDestroying = PR_FALSE; + mOnDestroyCalled = PR_FALSE; + mIsToplevel = PR_FALSE; + mUpdateArea.SetRect(0, 0, 0, 0); + mMenuBar = nsnull; +} + + +nsWidget::~nsWidget() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::~nsWidget (%p).\n", this )); + + mIsDestroying = PR_TRUE; + if (nsnull != mWidget) { + Destroy(); + } +} + + +NS_METHOD nsWidget::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::WidgetToScreen - Not Implemented.\n" )); + return NS_OK; +} + +NS_METHOD nsWidget::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::ScreenToWidget - Not Implemented.\n" )); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Close this nsWidget +// +//------------------------------------------------------------------------- + +NS_IMETHODIMP nsWidget::Destroy(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Destroy (%p).\n", this )); + + if( !mIsDestroying ) + { + nsBaseWidget::Destroy(); + NS_IF_RELEASE( mParent ); + } + + if( mWidget ) + { + mEventCallback = nsnull; + PtDestroyWidget( mWidget ); + mWidget = nsnull; + + if( PR_FALSE == mOnDestroyCalled ) + OnDestroy(); + } + + return NS_OK; +} + +// make sure that we clean up here + +void nsWidget::OnDestroy() +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::OnDestroy.\n" )); + + mOnDestroyCalled = PR_TRUE; + // release references to children, device context, toolkit + 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(); + } +} + +//------------------------------------------------------------------------- +// +// Get this nsWidget parent +// +//------------------------------------------------------------------------- + +nsIWidget *nsWidget::GetParent(void) +{ + if( mParent ) + { + NS_ADDREF( mParent ); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetParent - mParent is NULL!\n" )); + + return mParent; +} + + +//------------------------------------------------------------------------- +// +// Hide or show this component +// +//------------------------------------------------------------------------- + +NS_METHOD nsWidget::Show(PRBool bState) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Show." )); + + if (!mWidget) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Show - mWidget is NULL!\n" )); + return NS_OK; // Will be null durring printing + } + + if (bState) + { + if( !PtWidgetIsRealized( mWidget )) + PtRealizeWidget(mWidget); + } + else + { + if( PtWidgetIsRealized( mWidget )) + PtUnrealizeWidget(mWidget); + } + + mShown = bState; + + return NS_OK; +} + +NS_METHOD nsWidget::IsVisible(PRBool &aState) +{ + if( mWidget ) + { + if( PtWidgetIsRealized( mWidget )) + mShown = PR_TRUE; + else + mShown = PR_FALSE; + + aState = mShown; + } + else + aState = PR_FALSE; + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Move this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::Move(PRUint32 aX, PRUint32 aY) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Move (%p) to (%ld,%ld)\n", this, aX, aY )); + + mBounds.x = aX; + mBounds.y = aY; + + if (mWidget) + { + PtArg_t arg; + PhPoint_t *oldpos; + PhPoint_t pos = {aX, aY}; + + PtSetArg( &arg, Pt_ARG_POS, &oldpos, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if(( oldpos->x != pos.x ) || ( oldpos->y != pos.y )) + { + PtSetArg( &arg, Pt_ARG_POS, &pos, 0 ); + PtSetResources( mWidget, 1, &arg ); + } + } + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Move - mWidget is NULL!\n" )); + + return NS_OK; +} + + +NS_METHOD nsWidget::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Resize (%p)\n", this )); + + mBounds.width = aWidth; + mBounds.height = aHeight; + + if( mWidget ) + { + PtArg_t arg; + int *border; + PhDim_t *olddim; + PhDim_t dim = {aWidth, aHeight}; + + PtSetArg( &arg, Pt_ARG_BORDER_WIDTH, &border, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + dim.w -= 2*(*border); + dim.h -= 2*(*border); + } + + PtSetArg( &arg, Pt_ARG_DIM, &olddim, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if(( olddim->w != dim.w ) || ( olddim->h != dim.h )) + { + PtSetArg( &arg, Pt_ARG_DIM, &dim, 0 ); + PtSetResources( mWidget, 1, &arg ); + + if (aRepaint) + { + // REVISIT - photon doesnt like being told to redraw... + } + } + } + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Resize - mWidget is NULL!\n" )); + +// OnResize( mBounds ); + + return NS_OK; +} + + +NS_METHOD nsWidget::Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, + PRUint32 aHeight, PRBool aRepaint) +{ + Resize(aWidth,aHeight,aRepaint); + Move(aX,aY); + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Send a resize message to the listener +// +//------------------------------------------------------------------------- +PRBool nsWidget::OnResize(nsRect &aRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::OnResize.\n" )); + + // call the event callback + + if (mEventCallback) + { + nsSizeEvent event; + InitEvent(event, NS_SIZE); + event.windowSize = &aRect; + event.eventStructType = NS_SIZE_EVENT; + event.mWinWidth = 0; + event.mWinHeight = 0; + event.point.x = 0; //mWidget->allocation.x; + event.point.y = 0; //mWidget->allocation.y; + event.time = 0; + + if (mWidget) + { + PhArea_t *area; + PtArg_t arg; + PtSetArg( &arg, Pt_ARG_AREA, &area, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + event.mWinWidth = area->size.w; + event.mWinHeight = area->size.h; + event.point.x = area->pos.x; + event.point.y = area->pos.y; + } + } + + PRBool result = DispatchWindowEvent(&event); + + // XXX why does this always crash? maybe we need to add + // a ref in the dispatch code? check the windows + // code for a reference + //NS_RELEASE(event.widget); + + return result; + } +return PR_FALSE; +} + +//------ +// Move +//------ +PRBool nsWidget::OnMove(PRInt32 aX, PRInt32 aY) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::OnMove.\n" )); + + 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; +} + +//------------------------------------------------------------------------- +// +// Enable/disable this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::Enable(PRBool bState) +{ + if (mWidget) + { + PtArg_t arg; + if( bState ) + PtSetArg( &arg, Pt_ARG_FLAGS, 0, Pt_BLOCKED ); + else + PtSetArg( &arg, Pt_ARG_FLAGS, Pt_BLOCKED, Pt_BLOCKED ); + PtSetResources( mWidget, 1, &arg ); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Enable - mWidget is NULL!\n" )); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Give the focus to this component +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::SetFocus(void) +{ + if (mWidget) + PtContainerGiveFocus( mWidget, NULL ); + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFocus - mWidget is NULL!\n" )); + + return NS_OK; +} + + +NS_METHOD nsWidget::GetBounds(nsRect &aRect) +{ + /////////////////////////////////////////////////////////// + // NOTE: The nsWidget::GetBounds() function does not work + // for nsWindow objects. nsWindow MUST provide its own + // GetBounds method. + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetBounds.\n" )); + + if( mWidget ) + { + PtArg_t arg[2]; +// PhDim_t *dim; + PhArea_t *area; + int *border; + +// PtSetArg( &arg[0], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[0], Pt_ARG_AREA, &area, 0 ); + PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, &border, 0 ); + if( PtGetResources( mWidget, 2, arg ) == 0 ) + { + mBounds.x = area->pos.x - *border; + mBounds.y = area->pos.y - *border; + mBounds.width = area->size.w + 2*(*border); + mBounds.height = area->size.h + 2*(*border); +/* + mBounds.width = dim->w + 2*(*border); + mBounds.height = dim->h + 2*(*border); + + short x,y,ox,oy; + + PtGetAbsPosition( mWidget, &x, &y ); + PtGetAbsPosition( mClient, &ox, &oy ); + mBounds.x = x - ox; + mBounds.y = y - oy; +*/ + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetBounds - GetResources FAILED!\n" )); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetBounds - mWidget is NULL!\n" )); + + aRect = mBounds; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetBounds - bounds = (%ld,%ld,%ld,%ld)\n", aRect.x, aRect.y, aRect.width, aRect.height )); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Get this component font +// +//------------------------------------------------------------------------- +nsIFontMetrics *nsWidget::GetFont(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetFont - Not Implemented.\n" )); + + return nsnull; +} + +//------------------------------------------------------------------------- +// +// Set this component font +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::SetFont(const nsFont &aFont) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFont\n" )); +#if 1 +{ + char *str = nsnull; + str = aFont.name.ToNewCString(); + if (str) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFont aFont.name=<%s>\n",str)); + delete [] str; + } + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFont aFont.size=<%d>\n",aFont.size)); + +} +#endif + + nsIFontMetrics* mFontMetrics; + mContext->GetMetricsFor(aFont, mFontMetrics); + + if (mFontMetrics) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFont Get a FontMetrics\n" )); + PtArg_t arg; + + nsFontHandle aFontHandle; + mFontMetrics->GetFontHandle(aFontHandle); + nsString *aString; + aString = (nsString *) aFontHandle; + char *str = aString->ToNewCString(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetFont Get a FontMetrics font name=<%s>\n",str )); + + PtSetArg( &arg, Pt_ARG_TEXT_FONT, str, 0 ); + PtSetResources( mWidget, 1, &arg ); + + delete [] str; + NS_RELEASE(mFontMetrics); + } + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Set this component cursor +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::SetCursor(nsCursor aCursor) +{ + unsigned short curs; + + switch( aCursor ) + { + case eCursor_select: + curs = Ph_CURSOR_INSERT; + break; + + case eCursor_wait: + curs = Ph_CURSOR_LONG_WAIT; + break; + + case eCursor_hyperlink: + curs = Ph_CURSOR_FINGER; + break; + + case eCursor_standard: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_sizeWE: + curs = Ph_CURSOR_DRAG_HORIZONTAL; + break; + + case eCursor_sizeNS: + curs = Ph_CURSOR_DRAG_VERTICAL; + break; + + // REVISIT - Photon does not have the following cursor types... + + case eCursor_arrow_north: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_north_plus: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_south: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_south_plus: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_east: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_east_plus: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_west: + curs = Ph_CURSOR_POINTER; + break; + + case eCursor_arrow_west_plus: + curs = Ph_CURSOR_POINTER; + break; + + default: + NS_ASSERTION(0, "Invalid cursor type"); + break; + } + + if( mWidget ) + { + PtArg_t arg; + + PtSetArg( &arg, Pt_ARG_CURSOR_TYPE, curs, 0 ); + PtSetResources( mWidget, 1, &arg ); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetCursor - mWidget is NULL!\n" )); + + mCursor = aCursor; + + return NS_OK; +} + + +NS_METHOD nsWidget::Invalidate(PRBool aIsSynchronous) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Invalidate %p\n", this )); + + if( mWidget ) + { + PtArg_t arg; + int *flags; + + PtSetArg( &arg, Pt_ARG_FLAGS, &flags, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if( *flags & Pt_DAMAGED ) + return NS_OK; + } + + PtDamageWidget( mWidget ); + + // REVISIT - PtFlush may be unstable & cause crashes... + if( aIsSynchronous ) + PtFlush(); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Invalidate - mWidget is NULL!\n" )); + + return NS_OK; +} + + +NS_METHOD nsWidget::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Invalidate %p (%ld,%ld,%ld,%ld)\n", this, aRect.x, aRect.y, aRect.width, aRect.height )); + + if( mWidget ) + { + PtArg_t arg; + int *flags; + + PtSetArg( &arg, Pt_ARG_FLAGS, &flags, 0 ); + if( PtGetResources( mWidget, 1, &arg ) == 0 ) + { + if( *flags & Pt_DAMAGED ) + return NS_OK; + } + + PhRect_t extent; + PhArea_t area; + + PtWidgetArea( mWidget, &area ); + + extent.ul.x = aRect.x + area.pos.x; + extent.ul.y = aRect.y + area.pos.y; + extent.lr.x = extent.ul.x + aRect.width - 1; + extent.lr.y = extent.ul.y + aRect.height - 1; + + PtDamageExtent( mWidget, &extent ); + + // REVISIT - PtFlush may be unstable & cause crashes... + if( aIsSynchronous ) + PtFlush(); + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Invalidate(2) - mWidget is NULL!\n" )); + + return NS_OK; +} + + +NS_METHOD nsWidget::Update(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Update\n" )); + + PtFlush(); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Return some native data according to aDataType +// +//------------------------------------------------------------------------- +void *nsWidget::GetNativeData(PRUint32 aDataType) +{ + switch(aDataType) + { + case NS_NATIVE_WINDOW: + case NS_NATIVE_WIDGET: + if( !mWidget ) + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetNativeData(mWidget) - mWidget is NULL!\n" )); + return (void *)mWidget; + case NS_NATIVE_DISPLAY: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetNativeData(NS_NATIVE_DISPLAY) - Not Implemented.\n" )); + return nsnull; + case NS_NATIVE_GRAPHIC: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetNativeData(NS_NATIVE_GRAPHIC) - Not Implemented.\n" )); + return nsnull; + default: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::GetNativeData() - ERROR Bad ID.\n" )); + break; + } + return nsnull; +} + +//------------------------------------------------------------------------- +// +// Set the colormap of the window +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::SetColorMap(nsColorMap *aColorMap) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetColorMap - Not Implemented.\n" )); + return NS_OK; +} + +NS_METHOD nsWidget::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::Scroll - Not Implemented.\n" )); + return NS_OK; +} + +NS_METHOD nsWidget::BeginResizingChildren(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::BeginResizingChildren - Not Implemented.\n" )); + return NS_OK; +} + +NS_METHOD nsWidget::EndResizingChildren(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::EndResizingChildren - Not Implemented.\n" )); + return NS_OK; +} + +NS_METHOD nsWidget::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight) +{ + aWidth = mPreferredWidth; + aHeight = mPreferredHeight; + return (mPreferredWidth != 0 && mPreferredHeight != 0)?NS_OK:NS_ERROR_FAILURE; +} + +NS_METHOD nsWidget::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight) +{ + mPreferredWidth = aWidth; + mPreferredHeight = aHeight; + return NS_OK; +} + + +NS_METHOD nsWidget::SetMenuBar(nsIMenuBar * aMenuBar) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::SetMenuBar - Not Implemented.\n" )); + return NS_OK; +} + + +nsresult nsWidget::CreateWidget(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData, + nsNativeWidget aNativeParent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::CreateWidget (%p).\n", this )); + + PtWidget_t *parentWidget = nsnull; + + BaseCreate(aParent, aRect, aHandleEventFunction, aContext, + aAppShell, aToolkit, aInitData); + + mParent = aParent; + NS_IF_ADDREF( mParent ); + + if( aNativeParent ) + { + parentWidget = (PtWidget_t*)aNativeParent; + } + else if( aParent ) + { + parentWidget = (PtWidget_t*) (aParent->GetNativeData(NS_NATIVE_WIDGET)); + } + else + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::CreateWidget - No parent specified!\n" )); + } +// else if(aAppShell) { +// nsNativeWidget shellWidget = aAppShell->GetNativeData(NS_NATIVE_SHELL); +// if (shellWidget) +// parentWidget = GTK_WIDGET(shellWidget); +// } + + // Find the native client widget and store for ALL non-toplevel widgets + if( parentWidget ) + { + PtWidget_t *pTop = PtFindDisjoint( parentWidget ); + nsWindow * pWin = (nsWindow *) GetInstance( pTop ); + if( pWin ) + { + mClient = (PtWidget_t*) pWin->GetNativeData( NS_NATIVE_WIDGET ); + } + } + + mBounds = aRect; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::CreateWidget - bounds=(%i,%i,%i,%i)\n", mBounds.x, mBounds.y, mBounds.width, mBounds.height )); + + CreateNative (parentWidget); + + DispatchStandardEvent(NS_CREATE); + +// InitCallbacks(); + + return NS_OK; +} + + +//------------------------------------------------------------------------- +// +// create with nsIWidget parent +// +//------------------------------------------------------------------------- + +NS_METHOD nsWidget::Create(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return(CreateWidget(aParent, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, aInitData, + nsnull)); +} + +//------------------------------------------------------------------------- +// +// create with a native parent +// +//------------------------------------------------------------------------- +NS_METHOD nsWidget::Create(nsNativeWidget aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData) +{ + return(CreateWidget(nsnull, aRect, aHandleEventFunction, + aContext, aAppShell, aToolkit, aInitData, + aParent)); +} + + +void nsWidget::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::ConvertToDeviceCoordinates - Not Implemented.\n" )); +} + +void nsWidget::InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint) +{ + event.widget = this; + NS_IF_ADDREF(event.widget); + + if (aPoint == nsnull) { // use the point from the event + // get the message position in client coordinates and in twips + +// if (ge != nsnull) { +// event.point.x = PRInt32(ge->x); +// event.point.y = PRInt32(ge->y); +// } else { + event.point.x = 0; + event.point.y = 0; +// } + } + else { // use the point override if provided + event.point.x = aPoint->x; + event.point.y = aPoint->y; + } + + event.time = 0; //gdk_event_get_time((GdkEvent*)ge); + event.message = aEventType; + +// mLastPoint.x = event.point.x; +// mLastPoint.y = event.point.y; +} + +PRBool nsWidget::ConvertStatus(nsEventStatus aStatus) +{ +//PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWidget::ConvertStatus - aStatus=<%d>\n",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); +} + +PRBool nsWidget::DispatchWindowEvent(nsGUIEvent* event) +{ +// printf( ">>> nsWidget::DispatchWindowEvent\n" ); fflush( stdout ); + nsEventStatus status; + DispatchEvent(event, status); + return ConvertStatus(status); +} + +//------------------------------------------------------------------------- +// +// Dispatch standard event +// +//------------------------------------------------------------------------- + +PRBool nsWidget::DispatchStandardEvent(PRUint32 aMsg) +{ +// printf( ">>> nsWidget::DispatchStandardEvent\n" ); fflush( stdout ); + + nsGUIEvent event; + event.eventStructType = NS_GUI_EVENT; + InitEvent(event, aMsg); + + PRBool result = DispatchWindowEvent(&event); +// NS_IF_RELEASE(event.widget); + return result; +} + + +//------------------------------------------------------------------------- +// +// Invokes callback and ProcessEvent method on Event Listener object +// +//------------------------------------------------------------------------- + +NS_IMETHODIMP nsWidget::DispatchEvent(nsGUIEvent *event, + nsEventStatus &aStatus) +{ +// printf( ">>> nsWidget::DispatchEvent\n" ); fflush(stdout); + + if( !( event ) || !( event->widget )) + { + printf( " event or event->widget is NULL!\n" ); fflush(stdout); + return NS_ERROR_FAILURE; + } + + NS_ADDREF(event->widget); + + if( nsnull != mMenuListener ) + { + if( NS_MENU_EVENT == event->eventStructType ) + { + aStatus = mMenuListener->MenuSelected(NS_STATIC_CAST(nsMenuEvent&, *event)); + } + } + + aStatus = nsEventStatus_eIgnore; + if( nsnull != mEventCallback ) + { +//printf ("kedl: real callback....\n"); + aStatus = (*mEventCallback)(event); + } + + // Dispatch to event listener if event was not consumed + if(( aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) + { + aStatus = mEventListener->ProcessEvent(*event); + } + + NS_RELEASE(event->widget); + + return NS_OK; +} + +//------------------------------------------------------------------------- +// +// Deal with all sort of mouse event +// +//------------------------------------------------------------------------- +//PRBool nsWidget::DispatchMouseEvent(nsMouseEvent& aEvent) +PRBool nsWidget::DispatchMouseEvent( PhPoint_t &aPos, PRUint32 aEvent ) +{ +// printf( ">>> nsWidget::DispatchMouseEvent\n" ); fflush( stdout ); + + PRBool result = PR_FALSE; + if( nsnull == mEventCallback && nsnull == mMouseListener ) + { + return result; + } + + nsMouseEvent event; + + InitEvent( event, aEvent ); + event.eventStructType = NS_MOUSE_EVENT; + event.point.x = aPos.x; + event.point.y = aPos.y; + event.isShift = PR_FALSE; + event.isControl = PR_FALSE; + event.isAlt = PR_FALSE; + +//printf ("kedl: in dispatchmouse %lu\n",aEvent); + // call the event callback + if (nsnull != mEventCallback) { +// printf ("kedl: dispatchwindow!!!\n"); + result = DispatchWindowEvent( &event ); + + return result; + } + + if (nsnull != mMouseListener) + { + switch (aEvent) + { + case NS_MOUSE_MOVE: + result = ConvertStatus(mMouseListener->MouseMoved(event)); + break; + + case NS_MOUSE_LEFT_BUTTON_DOWN: + case NS_MOUSE_MIDDLE_BUTTON_DOWN: + case NS_MOUSE_RIGHT_BUTTON_DOWN: + result = ConvertStatus(mMouseListener->MousePressed(event)); + break; + + case NS_MOUSE_LEFT_BUTTON_UP: + case NS_MOUSE_MIDDLE_BUTTON_UP: + case NS_MOUSE_RIGHT_BUTTON_UP: + result = ConvertStatus(mMouseListener->MouseReleased(event)); + result = ConvertStatus(mMouseListener->MouseClicked(event)); + break; + } // switch + } + return result; +} + +void nsWidget::InitCallbacks( char * aName ) +{ +} + + +PRBool nsWidget::SetInstance( PtWidget_t * pWidget, nsWidget * inst ) +{ + PRBool res = PR_FALSE; + + if( pWidget ) + { + PtArg_t arg; + void *data = (void *)inst; + + PtSetArg(&arg, Pt_ARG_USER_DATA, &data, sizeof(void *) ); + if( PtSetResources( pWidget, 1, &arg) == 0 ) + res = PR_TRUE; + } + + return res; +} + + +nsWidget* nsWidget::GetInstance( PtWidget_t * pWidget ) +{ + if( pWidget ) + { + PtArg_t arg; + void **data; + + PtSetArg( &arg, Pt_ARG_USER_DATA, &data, 0 ); + if( PtGetResources( pWidget, 1, &arg ) == 0 ) + { + if( data ) + return (nsWidget *) *data; + } + } + + return NULL; +} + + +// Input keysym is in gtk format; output is in NS_VK format +PRUint32 nsWidget::nsConvertKey(unsigned long keysym) +{ + + struct nsKeyConverter { + PRUint32 vkCode; // Platform independent key code + unsigned long keysym; // Photon key_sym key code + }; + + struct nsKeyConverter nsKeycodes[] = { + { NS_VK_CANCEL, Pk_Cancel }, + { NS_VK_BACK, Pk_BackSpace }, + { NS_VK_TAB, Pk_Tab }, + { NS_VK_CLEAR, Pk_Clear }, + { NS_VK_RETURN, Pk_Return }, + { NS_VK_SHIFT, Pk_Shift_L }, + { NS_VK_SHIFT, Pk_Shift_R }, + { NS_VK_CONTROL, Pk_Control_L }, + { NS_VK_CONTROL, Pk_Control_R }, + { NS_VK_ALT, Pk_Alt_L }, + { NS_VK_ALT, Pk_Alt_R }, + { NS_VK_PAUSE, Pk_Pause }, + { NS_VK_CAPS_LOCK, Pk_Caps_Lock }, + { NS_VK_ESCAPE, Pk_Escape }, + { NS_VK_SPACE, Pk_space }, + { NS_VK_PAGE_UP, Pk_Pg_Up }, + { NS_VK_PAGE_DOWN, Pk_Pg_Down }, + { NS_VK_END, Pk_End }, + { NS_VK_HOME, Pk_Home }, + { NS_VK_LEFT, Pk_Left }, + { NS_VK_UP, Pk_Up }, + { NS_VK_RIGHT, Pk_Right }, + { NS_VK_DOWN, Pk_Down }, + { NS_VK_PRINTSCREEN, Pk_Print }, + { NS_VK_INSERT, Pk_Insert }, + { NS_VK_DELETE, Pk_Delete }, + { NS_VK_MULTIPLY, Pk_KP_Multiply }, + { NS_VK_ADD, Pk_KP_Add }, + { NS_VK_SEPARATOR, Pk_KP_Separator }, + { NS_VK_SUBTRACT, Pk_KP_Subtract }, + { NS_VK_DECIMAL, Pk_KP_Decimal }, + { NS_VK_DIVIDE, Pk_KP_Divide }, + { NS_VK_RETURN, Pk_KP_Enter }, + { NS_VK_COMMA, Pk_comma }, + { NS_VK_PERIOD, Pk_period }, + { NS_VK_SLASH, Pk_slash }, + { NS_VK_OPEN_BRACKET, Pk_bracketleft }, + { NS_VK_CLOSE_BRACKET, Pk_bracketright }, + { NS_VK_QUOTE, Pk_quotedbl } + }; + + const int length = sizeof(nsKeycodes) / sizeof(struct nsKeyConverter); + + for (int i = 0; i < length; i++) { + if (nsKeycodes[i].keysym == keysym) + { + return(nsKeycodes[i].vkCode); + } + } + + // First, try to handle alphanumeric input, not listed in nsKeycodes: + if (keysym >= Pk_a && keysym <= Pk_z) + return keysym - Pk_a + NS_VK_A; + + if (keysym >= Pk_A && keysym <= Pk_Z) + return keysym - Pk_A + NS_VK_A; + + if (keysym >= Pk_0 && keysym <= Pk_9) + return keysym - Pk_0 + NS_VK_0; + + if (keysym >= Pk_KP_0 && keysym <= Pk_KP_9) + return keysym - Pk_KP_0 + NS_VK_NUMPAD0; + + if (keysym >= Pk_F1 && keysym <= Pk_F24) + return keysym - Pk_F1 + NS_VK_F1; + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::nsConvertKey - Did not Find Key! - Not Implemented\n")); + + return(keysym & 0x00FF); +} + +PRBool nsWidget::DispatchKeyEvent(PhKeyEvent_t *aPhKeyEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::DispatchEvent Got a Key Event aPhEkyEvent->key_mods:<%x> aPhEkyEvent->key_flags:<%x> aPhEkyEvent->key_sym=<%x> aPhEkyEvent->key_caps=<%x>\n",aPhKeyEvent->key_mods, aPhKeyEvent->key_flags, aPhKeyEvent->key_sym, aPhKeyEvent->key_cap)); + + NS_ASSERTION(aPhKeyEvent, "nsWidget::DispatchKeyEvent a NULL PhKeyEvent was passed in"); + + nsKeyEvent keyEvent; + PRBool result = PR_FALSE; + + if (mEventCallback == NULL) + return PR_TRUE; + if ( ( aPhKeyEvent->key_cap == Pk_Shift_L ) || + ( aPhKeyEvent->key_cap == Pk_Shift_R ) || + ( aPhKeyEvent->key_cap == Pk_Control_L ) || + ( aPhKeyEvent->key_cap == Pk_Control_R ) || + ( aPhKeyEvent->key_cap == Pk_Alt_L ) || + ( aPhKeyEvent->key_cap == Pk_Alt_R ) + ) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::DispatchKeyEvent Ignoring SHIFT, CONTROL and ALT keypress\n")); + return PR_TRUE; + } + + //mIsShiftDown = ( aPhEkyEvent->key_mods & Pk_KM_Shift ) ? PR_TRUE : PR_FALSE; + //mIsControlDown = ( aPhEkyEvent->key_mods & Pk_KM_Ctrl ) ? PR_TRUE : PR_FALSE; + //mIsAltDown = ( aPhKeyEvent->key_mods & Pk_KM_Alt ) ? PR_TRUE : PR_FALSE; + + if (PkIsKeyDown(aPhKeyEvent->key_flags)) + { + keyEvent.message = NS_KEY_DOWN; + } + else + { + keyEvent.message = NS_KEY_UP; + } + + keyEvent.widget = this; + NS_ADDREF(keyEvent.widget); + keyEvent.eventStructType = NS_KEY_EVENT; + + + /* this should be keyCode = nsConvertKey(aPhKeyEvent->key_cap); */ + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::HandleEvent key_cap converted to NS_VK = <%x>\n", nsConvertKey(aPhKeyEvent->key_cap))); + + keyEvent.keyCode = nsConvertKey(aPhKeyEvent->key_cap); + keyEvent.charCode = (aPhKeyEvent->key_cap & 0x00FF); /* this should be UNICODE */ + keyEvent.time = 0; // event->timestamp; + + keyEvent.isShift = ( aPhKeyEvent->key_mods & Pk_KM_Shift ) ? PR_TRUE : PR_FALSE; + keyEvent.isControl = ( aPhKeyEvent->key_mods & Pk_KM_Ctrl ) ? PR_TRUE : PR_FALSE; + keyEvent.isAlt = ( aPhKeyEvent->key_mods & Pk_KM_Alt ) ? PR_TRUE : PR_FALSE; + keyEvent.point.x = 0; // aPhKeyEvent->pos.x; + keyEvent.point.y = 0; // aPhKeyEvent->pos.y; + + + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::HandleEvent Shift=<%d> Control=<%d> Alt=<%d>\n", keyEvent.isShift, keyEvent.isControl, keyEvent.isAlt)); + //PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::HandleEvent keyCode=<%d> charCode=<%d>\n", keyEvent.keyCode, keyEvent.charCode)); + + result = DispatchWindowEvent(&keyEvent); + PR_LOG(PhWidLog, PR_LOG_DEBUG,("nsWidget::HandleEvent result=<%d>\n", result)); + result = PR_TRUE; /* HACK! */ + + return result; +} + + +//------------------------------------------------------------------------- +// +// the nsWidget raw event callback for all nsWidgets in this toolkit +// +//------------------------------------------------------------------------- +int nsWidget::RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ) +{ + // Get the window which caused the event and ask it to process the message + nsWidget *someWidget = (nsWidget*) data; + + if( nsnull != someWidget ) + { + if( someWidget->HandleEvent( cbinfo )) + return( Pt_END ); // Event was consumed + } + + return( Pt_CONTINUE ); +} + + + +PRBool nsWidget::HandleEvent( PtCallbackInfo_t* aCbInfo ) +{ + PRBool result = PR_FALSE; // call the default nsWindow proc + PtWidget_t *parent = PtFindContainer( mWidget ); + nsWidget * parentWidget = (nsWidget *) GetInstance( parent ); + + // When we get menu selections, dispatch the menu command (event) AND IF there is + // a menu listener, call "listener->MenuSelected(event)" + + if( aCbInfo->reason == Pt_CB_RAW ) + { + PhEvent_t* event = aCbInfo->event; + + switch( event->type ) + { + case Ph_EV_BUT_PRESS: + { + PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); + + if( ptrev ) + { + ptrev->pos.x = 1; + ptrev->pos.y = 1; + if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button + { + if( ptrev->click_count == 2 ) + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_DOUBLECLICK ); + else + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_BUTTON_DOWN ); + } + else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button + { + if( ptrev->click_count == 2 ) + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_DOUBLECLICK ); + else + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_BUTTON_DOWN ); + } + else // middle button + { + if( ptrev->click_count == 2 ) + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_DOUBLECLICK ); + else + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_BUTTON_DOWN ); + } + } + } + break; + + case Ph_EV_BUT_RELEASE: + { + PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); + + if (event->subtype==Ph_EV_RELEASE_REAL) + if( ptrev ) + { + ptrev->pos.x = 1; + ptrev->pos.y = 1; + if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_BUTTON_UP ); + else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_BUTTON_UP ); + else // middle button + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_BUTTON_UP ); + } + } + break; + + case Ph_EV_BOUNDARY: + switch( event->subtype ) + { + case Ph_EV_PTR_ENTER: + result = DispatchStandardEvent( NS_MOUSE_ENTER ); + break; + case Ph_EV_PTR_LEAVE: + result = DispatchStandardEvent( NS_MOUSE_EXIT ); + break; + } + break; + } + } + +// return result; + return PR_TRUE; +} + + +void nsWidget::ScreenToWidget( PhPoint_t &pt ) +{ + // pt is in screen coordinates + // convert it to be relative to ~this~ widgets origin + short x=0,y=0; + + PtGetAbsPosition( mWidget, &x, &y ); + + pt.x -= x; + pt.y -= y; +} diff --git a/widget/src/photon/nsWidget.h b/widget/src/photon/nsWidget.h new file mode 100644 index 000000000000..8e8ba125bc7a --- /dev/null +++ b/widget/src/photon/nsWidget.h @@ -0,0 +1,158 @@ +/* -*- 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 nsWidget_h__ +#define nsWidget_h__ + +#include "nsBaseWidget.h" +#include "nsToolkit.h" +#include "nsIAppShell.h" +#include "nsWidgetsCID.h" + +#include "nsIMouseListener.h" +#include "nsIEventListener.h" + +#include "nsLookAndFeel.h" + +#include + + +/** + * Base of all Photon native widgets. + */ + +class nsWidget : public nsBaseWidget +{ + public: + nsWidget(); + virtual ~nsWidget(); + + 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); + + NS_IMETHOD Destroy(void); + nsIWidget* GetParent(void); + + NS_IMETHOD Show(PRBool state); + 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 aState); + NS_IMETHOD SetFocus(void); + + NS_IMETHOD GetBounds(nsRect &aRect); + + virtual PRBool OnResize(nsRect &aRect); + virtual PRBool OnMove(PRInt32 aX, PRInt32 aY); + + nsIFontMetrics *GetFont(void); + NS_IMETHOD SetFont(const nsFont &aFont); + + NS_IMETHOD SetCursor(nsCursor aCursor); + + NS_IMETHOD SetColorMap(nsColorMap *aColorMap); + + void* GetNativeData(PRUint32 aDataType); + + 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); + + virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY); + + // the following are nsWindow specific, and just stubbed here + + NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect); + NS_IMETHOD SetMenuBar(nsIMenuBar *aMenuBar); + NS_IMETHOD Invalidate(PRBool aIsSynchronous); + NS_IMETHOD Invalidate(const nsRect &aRect, PRBool aIsSynchronous); + NS_IMETHOD Update(void); + NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); + virtual void ScreenToWidget( PhPoint_t &pt ); + + void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull); + static int RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ); + virtual PRBool HandleEvent( PtCallbackInfo_t* aCbInfo ); + + // Utility functions + + PRBool ConvertStatus(nsEventStatus aStatus); + /* Convert Photon key codes to Mozilla key codes */ + PRUint32 nsConvertKey(unsigned long keysym); + PRBool DispatchMouseEvent(PhPoint_t &aPos, PRUint32 aEvent); + PRBool DispatchStandardEvent(PRUint32 aMsg); + PRBool DispatchKeyEvent(PhKeyEvent_t *aPhKeyEvent); + // are we a "top level" widget? + PRBool mIsToplevel; + + protected: + virtual void InitCallbacks(char * aName = nsnull); + virtual void OnDestroy(); + + NS_IMETHOD CreateNative(PtWidget_t *parentWindow) { return NS_OK; } + + nsresult CreateWidget(nsIWidget *aParent, + const nsRect &aRect, + EVENT_CALLBACK aHandleEventFunction, + nsIDeviceContext *aContext, + nsIAppShell *aAppShell, + nsIToolkit *aToolkit, + nsWidgetInitData *aInitData, + nsNativeWidget aNativeParent = nsnull); + + + PRBool DispatchWindowEvent(nsGUIEvent* event); + static PRBool SetInstance( PtWidget_t *pWidget, nsWidget * inst ); + static nsWidget* GetInstance( PtWidget_t *pWidget ); + + PtWidget_t *mWidget; + nsIWidget *mParent; + nsIMenuBar *mMenuBar; + PtWidget_t *mClient; + + // This is the composite update area (union of all the calls to + // Invalidate) + nsRect mUpdateArea; + + PRBool mShown; + + PRUint32 mPreferredWidth, mPreferredHeight; +}; + +#endif /* nsWidget_h__ */ diff --git a/widget/src/photon/nsWidgetSupport.cpp b/widget/src/photon/nsWidgetSupport.cpp index 17afffdb1e42..be61008fb78e 100644 --- a/widget/src/photon/nsWidgetSupport.cpp +++ b/widget/src/photon/nsWidgetSupport.cpp @@ -17,7 +17,7 @@ */ -#include "nsWidgetSupport.h" +//#include "nsWidgetSupport.h" #include "nsRect.h" #include "nsITextAreaWidget.h" #include "nsIFileWidget.h" @@ -41,12 +41,12 @@ #include "nsITextWidget.h" - +#include "nsPhWidgetLog.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(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); @@ -62,6 +62,8 @@ NS_CreateDialog(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateDialog\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -79,7 +81,7 @@ NS_CreateDialog(nsISupports* aParent, return NS_OK; } -#if 0 + NS_WIDGET nsresult NS_CreateButton(nsISupports* aParent, nsIButton* aButton, @@ -87,6 +89,8 @@ NS_CreateButton(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateButton\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -114,6 +118,8 @@ NS_CreateCheckButton(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateCheckButton\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -140,6 +146,8 @@ NS_CreateRadioButton( nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateRadioButton\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -165,6 +173,8 @@ NS_CreateLabel( nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateLabel\n")); + nsIWidget* parent = nsnull; if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent)) { @@ -190,6 +200,8 @@ NS_CreateTextAreaWidget(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateTextArea\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -220,6 +232,8 @@ NS_CreateTextWidget(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateTextWidget\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -251,6 +265,8 @@ NS_CreateScrollBar(nsISupports* aParent, const nsRect& aRect, EVENT_CALLBACK aHandleEventFunction) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateScrollBar\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -279,6 +295,8 @@ NS_CreateListBox(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateListBox\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -310,6 +328,8 @@ NS_CreateComboBox(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateComboBox\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -341,6 +361,8 @@ NS_CreateTabWidget(nsISupports* aParent, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateTabWidget\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -368,13 +390,15 @@ NS_CreateTabWidget(nsISupports* aParent, -extern NS_WIDGET nsresult +NS_WIDGET nsresult NS_CreateTooltipWidget(nsISupports* aParent, nsITooltipWidget* aWidget, const nsRect& aRect, EVENT_CALLBACK aHandleEventFunction, const nsFont* aFont) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_CreateTooltipWidget\n")); + nsIWidget* parent = nsnull; if (aParent != nsnull) aParent->QueryInterface(kIWidgetIID,(void**)&parent); @@ -397,11 +421,12 @@ NS_CreateTooltipWidget(nsISupports* aParent, return NS_OK; } -#endif -extern NS_WIDGET nsresult + +NS_WIDGET nsresult NS_ShowWidget(nsISupports* aWidget, PRBool aShow) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_ShowWidget\n")); nsIWidget* widget = nsnull; if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { @@ -412,9 +437,10 @@ NS_ShowWidget(nsISupports* aWidget, PRBool aShow) return NS_OK; } -extern NS_WIDGET nsresult +NS_WIDGET nsresult NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_MoveWidget\n")); nsIWidget* widget = nsnull; if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { @@ -424,9 +450,11 @@ NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY) return NS_OK; } -extern NS_WIDGET nsresult +NS_WIDGET nsresult NS_EnableWidget(nsISupports* aWidget, PRBool aEnable) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_EnableWidget\n")); + void* result = nsnull; nsIWidget* widget; if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) @@ -438,9 +466,10 @@ NS_EnableWidget(nsISupports* aWidget, PRBool aEnable) } -extern NS_WIDGET nsresult +NS_WIDGET nsresult NS_SetFocusToWidget(nsISupports* aWidget) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_SetFocusToWidget\n")); nsIWidget* widget = nsnull; if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) { @@ -451,9 +480,11 @@ NS_SetFocusToWidget(nsISupports* aWidget) } -extern NS_WIDGET nsresult +NS_WIDGET nsresult NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData) { +PR_LOG(PhWidLog, PR_LOG_DEBUG, "nsWidgetSupport::NS_GetWidgetNativeData\n")); + void* result = nsnull; nsIWidget* widget; if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) diff --git a/widget/src/photon/nsWindow.cpp b/widget/src/photon/nsWindow.cpp index b874d61f15c3..e71a7bf27857 100644 --- a/widget/src/photon/nsWindow.cpp +++ b/widget/src/photon/nsWindow.cpp @@ -16,64 +16,88 @@ * Reserved. */ +#include "nsPhWidgetLog.h" #include "nsWindow.h" #include "nsIAppShell.h" #include "nsIFontMetrics.h" #include "nsFont.h" #include "nsGUIEvent.h" #include "nsIRenderingContext.h" +#include "nsIRenderingContextPh.h" #include "nsIDeviceContext.h" #include "nsRect.h" #include "nsTransform2D.h" #include "nsStringUtil.h" #include +#include "PtRawDrawContainer.h" #include "nsGfxCIID.h" #include "prtime.h" +#include "nsIMenuBar.h" #include "nsIMenu.h" #include "nsIMenuItem.h" #include "nsIMenuListener.h" -nsWindow* nsWindow::gCurrentWindow = nsnull; +static NS_DEFINE_IID(kRenderingContextCID, NS_RENDERING_CONTEXT_CID); +static NS_DEFINE_IID(kRenderingContextIID, NS_IRENDERING_CONTEXT_IID); +static NS_DEFINE_IID(kRenderingContextPhIID, NS_IRENDERING_CONTEXT_PH_IID); + + +// for nsISupports +NS_IMPL_ADDREF(nsWindow) +NS_IMPL_RELEASE(nsWindow) + + +/** + * 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 nsWindow::QueryInterface(const nsIID& aIID, void** aInstancePtr) +{ + if (NULL == aInstancePtr) { + return NS_ERROR_NULL_POINTER; + } + + static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); + if (aIID.Equals(kCWindow)) { + *aInstancePtr = (void*) ((nsWindow*)this); + AddRef(); + return NS_OK; + } + return nsWidget::QueryInterface(aIID,aInstancePtr); +} -// Global variable -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() +nsWindow::nsWindow() { - NS_INIT_REFCNT(); - mWidget = 0; - mIsShiftDown = PR_FALSE; - mIsControlDown = PR_FALSE; - mIsAltDown = PR_FALSE; - mIsDestroying = PR_FALSE; - mOnDestroyCalled = PR_FALSE; - mLastPoint.x = 0; - mLastPoint.y = 0; - mPreferredWidth = 0; - mPreferredHeight = 0; - mFont = nsnull; - mIsVisible = PR_FALSE; - mHas3DBorder = PR_FALSE; - mMenuBar = nsnull; - mMenuCmdId = 0; - - mHitMenu = nsnull; - mHitSubMenus = new nsVoidArray(); - mVScrollbar = nsnull; + NS_INIT_REFCNT(); +// strcpy(gInstanceClassName, "nsWindow"); + mClientWidget = nsnull; + mRawDraw = nsnull; + mFontMetrics = nsnull; +// mShell = nsnull; +// mVBox = nsnull; + mResized = PR_FALSE; + mVisible = PR_FALSE; + mDisplayed = PR_FALSE; + mLowerLeft = PR_FALSE; +// mBorderStyle = GTK_WINDOW_TOPLEVEL; + mIsDestroying = PR_FALSE; + mOnDestroyCalled = PR_FALSE; + mFont = nsnull; } - //------------------------------------------------------------------------- // // nsWindow destructor @@ -81,79 +105,34 @@ nsWindow::nsWindow() : nsBaseWidget() //------------------------------------------------------------------------- nsWindow::~nsWindow() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::~nsWindow (%p) - Not Implemented.\n", this )); + mIsDestroying = PR_TRUE; - if( gCurrentWindow == this ) - { - gCurrentWindow = nsnull; - } - // If the widget was released without calling Destroy() then the native - // window still exists, and we need to destroy it - if( NULL != mWidget ) - { - Destroy(); - } +// if (mShell) +// { +// if (GTK_IS_WIDGET(mShell)) +// gtk_widget_destroy(mShell); +// mShell = nsnull; +// } - NS_IF_RELEASE(mHitMenu); // this should always have already been freed by the deselect - - //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); } //------------------------------------------------------------------------- -// -// Deferred Window positioning -// -//------------------------------------------------------------------------- - -NS_METHOD nsWindow::BeginResizingChildren(void) +void nsWindow::ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY) { - return NS_OK; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::ConvertToDeviceCoordinates - Not Implemented.\n")); } -NS_METHOD nsWindow::EndResizingChildren(void) -{ - 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 -// - - -NS_METHOD nsWindow::WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect) -{ - return NS_OK; -} - -NS_METHOD nsWindow::ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect) -{ - return NS_OK; -} - //------------------------------------------------------------------------- // // Setup initial tooltip rectangles // //------------------------------------------------------------------------- - NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetTooltips - Not Implemented.\n")); + return NS_OK; } @@ -165,6 +144,8 @@ NS_METHOD nsWindow::SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]) NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[]) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::UpdateTooltips - Not Implemented.\n")); + return NS_OK; } @@ -176,710 +157,286 @@ NS_METHOD nsWindow::UpdateTooltips(nsRect* aNewTips[]) NS_METHOD nsWindow::RemoveTooltips() { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::RemoveTooltips - Not Implemented.\n")); return NS_OK; } -//------------------------------------------------------------------------- -// -// Convert nsEventStatus value to a windows boolean -// -//------------------------------------------------------------------------- - -PRBool nsWindow::ConvertStatus(nsEventStatus aStatus) +#if 0 +NS_METHOD nsWindow::Destroy() { - 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; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Destroy\n")); + + // disconnect from the parent + + if( !mIsDestroying ) + nsBaseWidget::Destroy(); + + if( mWidget ) + { + mEventCallback = nsnull; + PtDestroyWidget( mWidget ); + mWidget = nsnull; + + if( PR_FALSE == mOnDestroyCalled ) + OnDestroy(); } - return PR_FALSE; + + return NS_OK; } +#endif - -//------------------------------------------------------------------------- -// -// Invokes callback and ProcessEvent method on Event Listener object -// -//------------------------------------------------------------------------- - -NS_IMETHODIMP nsWindow::DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus) +#if 0 +void nsWindow::OnDestroy() { - aStatus = nsEventStatus_eIgnore; - - //if (nsnull != mMenuListener) - // aStatus = mMenuListener->MenuSelected(*event); - if (nsnull != mEventCallback) { - aStatus = (*mEventCallback)(event); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::OnDestroy\n")); + + mOnDestroyCalled = PR_TRUE; + + // 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(); } +} +#endif - // Dispatch to event listener if event was not consumed - if((aStatus != nsEventStatus_eIgnore) && (nsnull != mEventListener)) { - aStatus = mEventListener->ProcessEvent(*event); + +NS_METHOD nsWindow::PreCreateWidget(nsWidgetInitData *aInitData) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::PreCreateWidget - Not Implemented.\n")); + +/* + if (nsnull != aInitData) { + switch(aInitData->mBorderStyle) + { + case eBorderStyle_none: + break; + case eBorderStyle_dialog: + mBorderStyle = GTK_WINDOW_DIALOG; + break; + case eBorderStyle_window: + mBorderStyle = GTK_WINDOW_TOPLEVEL; + break; + case eBorderStyle_3DChildWindow: + break; + } + return NS_OK; } - - nsWindow * thisPtr = this; - + return NS_ERROR_FAILURE; +*/ return NS_OK; } -//------------------------------------------------------------------------- -PRBool nsWindow::DispatchWindowEvent(nsGUIEvent* event) -{ - return PR_TRUE; -} - //------------------------------------------------------------------------- // -// Dispatch standard event +// Create the native widget // //------------------------------------------------------------------------- - -PRBool nsWindow::DispatchStandardEvent(PRUint32 aMsg) +NS_METHOD nsWindow::CreateNative(PtWidget_t *parentWidget) { - return PR_TRUE; -} + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::CreateNative (%p) - parent = %p.\n", this, parentWidget)); -//------------------------------------------------------------------------- -// -// the nsWindow raw event callback for all nsWindows in this toolkit -// -//------------------------------------------------------------------------- -int nsWindow::RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ) -{ - // Get the window which caused the event and ask it to process the message - PtArg_t arg; - nsWindow *someWindow = (nsWindow*) data; - - if( nsnull != someWindow ) - someWindow->HandleEvent( cbinfo ); - - return( Pt_CONTINUE ); -} - - - -nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent, - const nsRect &aRect, - EVENT_CALLBACK aHandleEventFunction, - nsIDeviceContext *aContext, - nsIAppShell *aAppShell, - nsIToolkit *aToolkit, - nsWidgetInitData *aInitData, - nsNativeWidget aNativeParent) -{ - PtArg_t arg[5]; + PtArg_t arg[20]; PhPoint_t pos; PhDim_t dim; unsigned long render_flags; nsresult result = NS_ERROR_FAILURE; - 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"... - // REVISIT - printf( "Must check thread here...\n" ); + //printf( "Must check thread here...\n" ); - PtWidget_t *parent; - if( nsnull != aParent ) // has a nsIWidget parent - parent = (PtWidget_t*) aParent->GetNativeData(NS_NATIVE_WINDOW); - else // has a nsNative parent - parent = (PtWidget_t*)aNativeParent; + pos.x = mBounds.x; + pos.y = mBounds.y; + dim.w = mBounds.width; + dim.h = mBounds.height; - render_flags = Ph_WM_RENDER_TITLE | Ph_WM_RENDER_CLOSE; - if( nsnull != aInitData ) + //PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::CreateNative - bounds = %lu,%lu.\n", mBounds.width, mBounds.height )); + +#define MY_FIELDS Ph_REGION_EV_SENSE |\ + Ph_REGION_FLAGS |\ + Ph_REGION_EV_OPAQUE + + if( IsChild() ) { - switch( aInitData->mBorderStyle ) + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_RESIZE_FLAGS, 0, Pt_RESIZE_XY_BITS ); + PtSetArg( &arg[3], Pt_ARG_FLAGS, 0 /*Pt_HIGHLIGHTED*/, Pt_HIGHLIGHTED ); + PtSetArg( &arg[4], Pt_ARG_BORDER_WIDTH, 0, 0 ); + PtSetArg( &arg[5], Pt_ARG_TOP_BORDER_COLOR, Pg_RED, 0 ); + PtSetArg( &arg[6], Pt_ARG_BOT_BORDER_COLOR, Pg_RED, 0 ); +//kedl, this is it!!! +// PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0 ); +// PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_BLUE, 0 ); +// PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_GREY, 0 ); +//extern int raw_container_color; +// PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, raw_container_color, 0 ); +//kedl, but falls thru to red..... +// mWidget = PtCreateWidget( PtContainer, parentWidget, 8, arg ); +// mWidget = PtCreateWidget( PtRaw, parentWidget, 8, arg ); + PtSetArg( &arg[7], RDC_DRAW_FUNC, RawDrawFunc, 0 ); + mWidget = PtCreateWidget( PtRawDrawContainer, parentWidget, 8, arg ); +//printf ("kedl: raw parent:%lu\n",mWidget); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::CreateNative - Is a Child\n" )); + +#if 0 + if( mWidget ) { - case eBorderStyle_dialog: - render_flags |= Ph_WM_RENDER_BORDER; - break; - - case eBorderStyle_window: - render_flags |= Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | - Ph_WM_RENDER_MAX | Ph_WM_RENDER_MIN | Ph_WM_RENDER_MENU; - - case eBorderStyle_3DChildWindow: - render_flags |= Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE; - break; - - case eBorderStyle_none: - default: - break; + PhDim_t rawDim = { 20, 20 }; + PtSetArg( &arg[0], Pt_ARG_DIM, &rawDim, 0 ); + PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, 0 , 0 ); + PtSetArg( &arg[2], Pt_ARG_MARGIN_WIDTH, 0 , 0 ); + PtSetArg( &arg[3], Pt_ARG_RAW_DRAW_F, RawDrawFunc, 0 ); + PtSetArg( &arg[4], Pt_ARG_TOP_BORDER_COLOR, Pg_GREEN, 0 ); + PtSetArg( &arg[5], Pt_ARG_BOT_BORDER_COLOR, Pg_GREEN, 0 ); + PtSetArg( &arg[6], Pt_ARG_FILL_COLOR, /*Pg_GRAY*/ Pg_GREEN, 0 ); + PtSetArg( &arg[7], Pt_ARG_FLAGS, 0 ,Pt_HIGHLIGHTED ); + mRawDraw = PtCreateWidget( PtRaw, mWidget, 8, arg ); +//printf ("kedl: raw widget: %lu\n",mRawDraw); } +#endif } - - mHas3DBorder = PR_FALSE; - - PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); - PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); - PtSetArg( &arg[2], Pt_ARG_WINDOW_RENDER_FLAGS, render_flags, 0 ); - mWidget = PtCreateWidget( PtWindow, parent, 3, arg ); - - if( mWidget ) + else { - // Attach event handler - PtAddEventHandler( mWidget, 0xFFFFFFFF, RawEventHandler, this ); + render_flags = Ph_WM_RENDER_TITLE | Ph_WM_RENDER_CLOSE | + Ph_WM_RENDER_BORDER | Ph_WM_RENDER_RESIZE | + Ph_WM_RENDER_MAX | Ph_WM_RENDER_MIN | Ph_WM_RENDER_MENU; + + PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); + PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[2], Pt_ARG_RESIZE_FLAGS, 0, Pt_RESIZE_XY_BITS ); + PtSetArg( &arg[3], Pt_ARG_WINDOW_RENDER_FLAGS, render_flags, 0xFFFFFFFF ); + mWidget = PtCreateWidget( PtWindow, parentWidget, 4, arg ); - // call the event callback to notify about creation - DispatchStandardEvent(NS_CREATE); - } - - return result; -} - -//------------------------------------------------------------------------- -// -// 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)); -} - - -//------------------------------------------------------------------------- -// -// Close this nsWindow -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Destroy() -{ - // Switch to the "main gui thread" if necessary... This method must - // be executed on the "gui thread"... - // REVISIT - printf( "Must check thread here...\n" ); - - // disconnect from the parent - if (!mIsDestroying) { - nsBaseWidget::Destroy(); - } - - // destroy the HWND - if( mWidget ) - { - // prevent the widget from causing additional events - mEventCallback = nsnull; - PtDestroyWidget( mWidget ); - mWidget = NULL; - } - - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Get this nsWindow parent -// -//------------------------------------------------------------------------- -nsIWidget* nsWindow::GetParent(void) -{ - nsWindow* widget = NULL; - - if( mWidget ) - { - PtWidget_t* parent = PtWidgetParent( mWidget ); - if( parent ) + // Must also create the client-area widget + if( mWidget ) { - PtArg_t arg; - - PtSetArg( &arg, Pt_ARG_USER_DATA, &widget, 0 ); - if(( PtGetResources( mWidget, 1, &arg ) == 0 ) && widget ) + PtSetArg( &arg[0], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[1], Pt_ARG_ANCHOR_FLAGS, Pt_LEFT_ANCHORED_LEFT | + Pt_RIGHT_ANCHORED_RIGHT | Pt_TOP_ANCHORED_TOP | Pt_BOTTOM_ANCHORED_BOTTOM, 0xFFFFFFFF ); + PtSetArg( &arg[2], Pt_ARG_BORDER_WIDTH, 0 , 0 ); + PtSetArg( &arg[3], Pt_ARG_MARGIN_WIDTH, 0 , 0 ); + PtSetArg( &arg[4], Pt_ARG_FLAGS, 0 , Pt_HIGHLIGHTED|Pt_OPAQUE ); + PtSetArg( &arg[5], Pt_ARG_TOP_BORDER_COLOR, Pg_BLUE, 0 ); + PtSetArg( &arg[6], Pt_ARG_BOT_BORDER_COLOR, Pg_BLUE, 0 ); +// kedl, falls thru to backdrop... + PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0 ); + PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_RED, 0 ); + PtSetArg( &arg[7], Pt_ARG_FILL_COLOR, Pg_GREY, 0 ); + PtSetArg( &arg[8], Pt_ARG_REGION_FIELDS, MY_FIELDS, MY_FIELDS); + PtSetArg( &arg[9], Pt_ARG_REGION_SENSE, Ph_EV_WIDGET_SENSE, Ph_EV_WIDGET_SENSE ); + PtSetArg( &arg[9], Pt_ARG_REGION_SENSE, Ph_EV_WIN_OPAQUE, Ph_EV_WIN_OPAQUE ); +// mClientWidget = PtCreateWidget( PtRegion, mWidget, 10, arg ); + mClientWidget = PtCreateWidget( PtContainer, mWidget, 8, arg ); + if( !mClientWidget ) { - // If the widget is in the process of being destroyed then - // do NOT return it - if( widget->mIsDestroying ) - widget = NULL; - else - NS_ADDREF( widget ); + PtDestroyWidget( mWidget ); + mWidget = nsnull; } } } - return (nsIWidget*)widget; -} - - -//------------------------------------------------------------------------- -// -// Hide or show this component -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Show( PRBool bState ) -{ if( mWidget ) { - if( bState ) - PtRealizeWidget( mWidget ); - else - PtUnrealizeWidget( mWidget ); - } - mIsVisible = bState; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::CreateNative - mWidget=%p, mClientWidget=%p\n", mWidget, mClientWidget )); - return NS_OK; -} + SetInstance( mWidget, this ); +// if( mRawDraw ) +// SetInstance( mRawDraw, this ); -//------------------------------------------------------------------------- -// -// Return PR_TRUE if the whether the component is visible, PR_FALSE otherwise -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::IsVisible(PRBool & bState) -{ - if( mWidget && PtWidgetIsRealized( mWidget )) - bState = PR_TRUE; - else - bState = PR_FALSE; + if( mClientWidget ) + SetInstance( mClientWidget, this ); - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Move this component -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Move(PRUint32 aX, PRUint32 aY) -{ - mBounds.x = aX; - mBounds.y = aY; - - if( mWidget ) - { - PtArg_t arg; - PhPoint_t pos = { aX, aY }; - - PtSetArg( &arg, Pt_ARG_POS, &pos, 0 ); - PtSetResources( mWidget, 1, &arg ); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - // Set cached value for lightweight and printing - mBounds.width = aWidth; - mBounds.height = aHeight; - - if( mWidget ) - { - PtArg_t arg; - PhDim_t dim = { aWidth, aHeight }; - - PtSetArg( &arg, Pt_ARG_DIM, &dim, 0 ); - PtSetResources( mWidget, 1, &arg ); - } - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Resize this component -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) -{ - // Set cached value for lightweight and printing - mBounds.x = aX; - mBounds.y = aY; - mBounds.width = aWidth; - mBounds.height = aHeight; - - if( mWidget ) - { - PtArg_t arg[2]; - PhPoint_t pos = { aX, aY }; - PhDim_t dim = { aWidth, aHeight }; - - PtSetArg( &arg[0], Pt_ARG_POS, &pos, 0 ); - PtSetArg( &arg[1], Pt_ARG_DIM, &dim, 0 ); - PtSetResources( mWidget, 2, arg ); - } - - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Enable/disable this component -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Enable(PRBool bState) -{ - if( mWidget ) - { - PtArg_t arg; - - if( PR_TRUE == bState ) - PtSetArg( &arg, Pt_ARG_FLAGS, 0, Pt_BLOCKED ); - else - PtSetArg( &arg, Pt_ARG_FLAGS, Pt_BLOCKED, Pt_BLOCKED ); - - PtSetResources( mWidget, 1, &arg ); - } - - 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"... - - // REVISIT - printf( "Must check thread here...\n" ); - - if( mWidget ) + // Attach event handler + if( IsChild()) { - PtContainerGiveFocus( mWidget, NULL ); - } - return NS_OK; -} + PhDim_t *dim; + dim = (PhDim_t *)malloc(sizeof(PhDim_t)); + PtAddCallback(mWidget, Pt_CB_RESIZE, ResizeHandler, dim); - -//------------------------------------------------------------------------- -// -// Get this component dimension -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::GetBounds(nsRect &aRect) -{ - nsresult res = NS_ERROR_FAILURE; - - if( mWidget ) - { - PhRect_t extent; - - PtWidgetExtent( mWidget, &extent ); - - aRect.x = 0; - aRect.y = 0; - aRect.width = extent.lr.x - extent.ul.x; - aRect.height = extent.lr.y - extent.ul.y; - - res = NS_OK; - } - else - aRect.SetRect(0,0,0,0); - - return res; -} - -//------------------------------------------------------------------------- -// -// Get this component dimension -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::GetClientBounds( nsRect &aRect ) -{ - nsresult res = NS_ERROR_FAILURE; - - if( mWidget ) - { - PhRect_t extent; - - PtBasicWidgetCanvas( mWidget, &extent ); - - aRect.x = 0; - aRect.y = 0; - aRect.width = extent.lr.x - extent.ul.x; - aRect.height = extent.lr.y - extent.ul.y; - - res = NS_OK; - } - else - aRect.SetRect(0,0,0,0); - - return res; -} - -//get the bounds, but don't take into account the client size - -void nsWindow::GetNonClientBounds(nsRect &aRect) -{ - if( mWidget ) - { - PhRect_t extent; - PtArg_t arg[2]; - int lf,rf,tf,bf; - unsigned long *render; - int *border; - - PtWidgetExtent( mWidget, &extent ); - - PtSetArg( &arg[0], Pt_ARG_WINDOW_RENDER_FLAGS, &render, 0 ); - PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, &border, 0 ); - if( PtGetResources( mWidget, 2, arg ) == 0 ) - { - PtFrameSize( *render, *border, &lf, &tf, &rf, &bf ); + PtAddEventHandler( mWidget, + Ph_EV_KEY | Ph_EV_PTR_MOTION_BUTTON | Ph_EV_PTR_MOTION_NOBUTTON | + Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE |Ph_EV_BOUNDARY, + RawEventHandler, this ); } else { - lf = rf = tf = bf = 0; + PhDim_t *dim; + dim = (PhDim_t *)malloc(sizeof(PhDim_t)); + PtAddCallback(mWidget, Pt_CB_RESIZE, ResizeHandler, dim); + +// PtAddEventHandler( mWidget, Ph_EV_WM, RawEventHandler, this ); +// PtAddEventHandler( mClientWidget, Ph_EV_PTR_ALL | Ph_EV_KEY, RawEventHandler, this ); } + + // call the event callback to notify about creation + DispatchStandardEvent(NS_CREATE); - aRect.x = extent.ul.x - lf; - aRect.y = extent.ul.y - tf; - aRect.width = extent.lr.x - extent.ul.x + lf + rf; - aRect.height = extent.lr.y - extent.ul.y + tf + bf; - - // REVISIT - What are these coords supposed to be - // relative to? Screen, Parent, Top-Level Window????? + result = NS_OK; } else - aRect.SetRect(0,0,0,0); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::CreateNative - FAILED TO CREATE WIDGET!\n" )); + mIsToplevel = PR_TRUE; + mCursor = eCursor_select; + SetCursor(eCursor_standard); + + return result; } - -//------------------------------------------------------------------------- -// -// Set the background color -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::SetBackgroundColor(const nscolor &aColor) -{ - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Get this component font -// -//------------------------------------------------------------------------- -nsIFontMetrics* nsWindow::GetFont(void) -{ - return NULL; -} - - -//------------------------------------------------------------------------- -// -// Set this component font -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::SetFont(const nsFont &aFont) -{ - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Set this component cursor -// -//------------------------------------------------------------------------- - -NS_METHOD nsWindow::SetCursor(nsCursor aCursor) -{ - unsigned short curs; - - switch( aCursor ) - { - case eCursor_select: - curs = Ph_CURSOR_INSERT; - break; - - case eCursor_wait: - curs = Ph_CURSOR_LONG_WAIT; - break; - - case eCursor_hyperlink: - curs = Ph_CURSOR_FINGER; - break; - - case eCursor_standard: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_sizeWE: - curs = Ph_CURSOR_DRAG_HORIZONTAL; - break; - - case eCursor_sizeNS: - curs = Ph_CURSOR_DRAG_VERTICAL; - break; - - // REVISIT - Photon does not have the following cursor types... - - case eCursor_arrow_north: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_north_plus: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_south: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_south_plus: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_east: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_east_plus: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_west: - curs = Ph_CURSOR_POINTER; - break; - - case eCursor_arrow_west_plus: - curs = Ph_CURSOR_POINTER; - break; - - default: - NS_ASSERTION(0, "Invalid cursor type"); - break; - } - - PtArg_t arg; - - PtSetArg( &arg, Pt_ARG_CURSOR_TYPE, curs, 0 ); - PtSetResources( mWidget, 1, &arg ); - mCursor = aCursor; - - return NS_OK; -} - - -//------------------------------------------------------------------------- -// -// Invalidate this component visible area -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Invalidate(PRBool aIsSynchronous) -{ - if( mWidget ) - { - PtDamageWidget( mWidget ); - - // REVISIT - PtFlush may be unstable & cause crashes... - if( aIsSynchronous ) - PtFlush(); - } - - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Invalidate this component visible area -// -//------------------------------------------------------------------------- -NS_METHOD nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) -{ - if( mWidget ) - { - PhRect_t extent; - - extent.ul.x = aRect.x; - extent.ul.y = aRect.y; - extent.lr.x = aRect.x + aRect.width; - extent.lr.y = aRect.y + aRect.height; - - PtDamageExtent( mWidget, &extent ); - - // REVISIT - PtFlush may be unstable & cause crashes... - if( aIsSynchronous ) - PtFlush(); - } - return NS_OK; -} - -//------------------------------------------------------------------------- -// -// Force a synchronous repaint of the window -// -//------------------------------------------------------------------------- -NS_IMETHODIMP nsWindow::Update() -{ - return NS_OK; -} //------------------------------------------------------------------------- // // Return some native data according to aDataType // //------------------------------------------------------------------------- -void* nsWindow::GetNativeData( PRUint32 aDataType ) +void *nsWindow::GetNativeData(PRUint32 aDataType) { - switch( aDataType ) + switch(aDataType) { - case NS_NATIVE_WIDGET: - case NS_NATIVE_WINDOW: - return (void*)mWidget; - case NS_NATIVE_GRAPHIC: -// return (void*)::GetDC(mWnd); - case NS_NATIVE_COLORMAP: - default: - break; - } + case NS_NATIVE_WINDOW: + if( !mWidget ) + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData( NS_NATIVE_WINDOW ) - mWidget is NULL!\n")); + return (void *)mWidget; + case NS_NATIVE_DISPLAY: +// return (void *)GDK_DISPLAY(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData( NS_NATIVE_DISPLAY ) - Not Implemented.\n")); + return nsnull; + case NS_NATIVE_WIDGET: + if( IsChild() ) + { + if( !mWidget ) + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData( NS_NATIVE_WIDGET ) this=%p IsChild=TRUE - mWidget is NULL!\n", this )); + return (void *)mWidget; + } + else + { + if( !mClientWidget ) + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData( NS_NATIVE_WIDGET ) this=%p IsChild=FALSE - mClientWidget is NULL!\n", this )); + return (void *)mClientWidget; + } - return NULL; + case NS_NATIVE_GRAPHIC: +// return (void *)((nsToolkit *)mToolkit)->GetSharedGC(); + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData( NS_NATIVE_GRAPHIC ) - Not Implemented.\n")); + return nsnull; + default: + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetNativeData - Wierd value.\n")); + break; + } + return nsnull; } //------------------------------------------------------------------------- @@ -889,10 +446,10 @@ void* nsWindow::GetNativeData( PRUint32 aDataType ) //------------------------------------------------------------------------- NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetColorMap - Not Implemented.\n")); return NS_OK; } - //------------------------------------------------------------------------- // // Scroll the bits of a window @@ -900,49 +457,418 @@ NS_METHOD nsWindow::SetColorMap(nsColorMap *aColorMap) //------------------------------------------------------------------------- NS_METHOD nsWindow::Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Scroll aDx=<%d aDy=<%d> aClipRect=<%p> - Not Implemented.\n", aDx, aDy, aClipRect)); + + PtWidget_t *widget; + PhRid_t rid; + + if( IsChild() ) + { +// widget = mRawDraw; + widget = mWidget; + rid = PtWidgetRid( mWidget ); + } + else + { + widget = mClientWidget; + rid = PtWidgetRid( mClientWidget ); + } + + if( widget ) + { + PhRect_t rect; + PhPoint_t offset = { aDx, aDy }; + PhArea_t area; + + PtWidgetArea( widget, &area ); + + // Ignore clipping for now... + + rect.ul.x = /*origin.x +*/ area.pos.x; + rect.ul.y = /*origin.y +*/ area.pos.y; + rect.lr.x = rect.ul.x + area.size.w - 1; + rect.lr.y = rect.ul.y + area.size.h - 1; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, (" blit rect = %ld,%ld,%ld,%ld\n", rect.ul.x, rect.ul.y, rect.lr.x, rect.lr.y )); + + if( aClipRect ) + PR_LOG(PhWidLog, PR_LOG_DEBUG, (" clip rect = %ld,%ld,%ld,%ld\n", aClipRect->x, aClipRect->y, aClipRect->width, aClipRect->height )); + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, (" no clip rect\n" )); + + PgFlush(); + PhBlit( rid, &rect, &offset ); + + // Invalidate exposed area... + + if( aDx > 0 ) + rect.lr.x = rect.ul.x + aDx; + else if( aDx < 0 ) + rect.ul.x = rect.lr.x + aDx; + + if( aDy > 0 ) + rect.lr.y = rect.ul.y + aDy; + else if( aDy < 0 ) + rect.ul.y = rect.lr.y + aDy; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, (" dmg rect = %ld,%ld,%ld,%ld\n", rect.ul.x, rect.ul.y, rect.lr.x, rect.lr.y )); + + PtDamageExtent( widget, &rect ); + + // move all the children +PtWidget_t *w; +PtArg_t arg; +PhPoint_t *pos; +PhPoint_t p; + + for( w = PtWidgetChildFront( mWidget ); + w; + w = PtWidgetBrotherBehind( w ) ) + { +// printf ("move: %lu\n",w); + PtSetArg( &arg, Pt_ARG_POS, &pos, 0 ); + PtGetResources( w, 1, &arg ) ; +// printf ("old pos: %d %d\n",pos->x,pos->y); + p = *pos; + p.x += aDx; + p.y += aDy; +// printf ("new pos: %d %d\n",p.x,p.y); + PtSetArg( &arg, Pt_ARG_POS, &p, 0 ); + PtSetResources( w, 1, &arg ) ; + PtDamageWidget(w); + } + } + + return NS_OK; +} + +NS_METHOD nsWindow::SetTitle(const nsString& aTitle) +{ + nsresult res = NS_ERROR_FAILURE; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetTitle.\n")); + + if( mWidget ) + { + PtArg_t arg; + char *title = aTitle.ToNewCString(); + + PtSetArg( &arg, Pt_ARG_WINDOW_TITLE, title, 0 ); + if( PtSetResources( mWidget, 1, &arg ) == 0 ) + res = NS_OK; + } + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetTitle - mWidget is NULL!\n")); + + return res; +} + + +/** + * Processes an Expose Event + * + **/ +PRBool nsWindow::OnPaint(nsPaintEvent &event) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::OnPaint - Not Implemented.\n")); return NS_OK; } - -//------------------------------------------------------------------------- -// -// OnKey -// -//------------------------------------------------------------------------- -PRBool nsWindow::OnKey( PRUint32 aEventType, PRUint32 aKeyCode ) +NS_METHOD nsWindow::BeginResizingChildren(void) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::BeginResizingChildren.\n")); + +// PtHold(); + + PtStartFlux( mWidget ); +#if 0 + if( IsChild() ) + PtContainerHold( mWidget ); + else + PtContainerHold( mClientWidget ); +#endif + return NS_OK; +} + +NS_METHOD nsWindow::EndResizingChildren(void) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::EndResizingChildren.\n")); + +// PtRelease(); + + PtEndFlux( mWidget ); +#if 0 + if( IsChild() ) + PtContainerRelease( mWidget ); + else + PtContainerRelease( mClientWidget ); +#endif + return NS_OK; +} + + +NS_METHOD nsWindow::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Resize (%p) from (%ld,%ld) to (%ld,%ld).\n", this, + mBounds.width, mBounds.height, aWidth, aHeight )); + + nsWidget::Resize( aWidth, aHeight, aRepaint ); + +#if 0 + if( IsChild() ) + { + PtArg_t arg[5]; + PhDim_t dim = { aWidth, aHeight }; + + PtSetArg( &arg[0], Pt_ARG_DIM, &dim, 0 ); + PtSetResources( mRawDraw, 1, arg ); + } +#endif + + return NS_OK; +} + + +NS_METHOD nsWindow::Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, + PRUint32 aHeight, PRBool aRepaint) +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Resize (cover).\n" )); + + Resize(aWidth,aHeight,aRepaint); + Move(aX,aY); + return NS_OK; +} + + +PRBool nsWindow::OnKey(nsKeyEvent &aEvent) +{ + if (mEventCallback) { + PR_LOG(PhWidLog, PR_LOG_DEBUG, (" nsWindow::OnKey - mEventCallback=<%p>\n", mEventCallback)); + return DispatchWindowEvent(&aEvent); + } return PR_FALSE; } +PRBool nsWindow::DispatchFocus(nsGUIEvent &aEvent) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::DispatchFocus - Not Implemented.\n")); + + if( mEventCallback ) + { +// return DispatchWindowEvent(&aEvent); +// return DispatchStandardEvent(&aEvent); + } + + return PR_FALSE; +} + +PRBool nsWindow::OnScroll(nsScrollbarEvent &aEvent, PRUint32 cPos) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::OnScroll - Not Implemented.\n")); + return PR_FALSE; +} + + +NS_METHOD nsWindow::GetBounds( nsRect &aRect ) +{ + nsresult res = NS_ERROR_FAILURE; + + if( IsChild() ) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetBounds for child window (%p).\n", this )); + + // A child window is just another widget, call base class GetBounds + res = nsWidget::GetBounds( aRect ); + } + else + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetBounds - not a child (%p).\n", this )); + + if( mWidget ) + { + PtArg_t arg[5]; + PhDim_t *dim; + int *border; + unsigned short *render; + + PtSetArg( &arg[0], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, &border, 0 ); + PtSetArg( &arg[2], Pt_ARG_WINDOW_RENDER_FLAGS, &render, 0 ); + + if( PtGetResources( mWidget, 3, arg ) == 0 ) + { + short x,y; + int l,r,t,b; + + // Get position + + PtGetAbsPosition( mWidget, &x, &y ); + + // Get Frame dimensions + + PtFrameSize( *render, 0, &l, &t, &r, &b ); + + aRect.x = x - l; + aRect.y = y - t; + aRect.width = dim->w + 2*(*border) + r; + aRect.height = dim->h + 2*(*border) + b; + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetBounds = %ld,%ld,%ld,%ld\n", aRect.x, aRect.y, aRect.width, aRect.height )); + } + } + } + + return res; +} + + +NS_METHOD nsWindow::GetClientBounds( nsRect &aRect ) +{ + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::GetClientBounds (%p).\n", this )); + + nsresult res = NS_ERROR_FAILURE; + + if( IsChild() ) + { + // A child window is just another widget, call base class GetBounds + res = nsWidget::GetBounds( aRect ); + } + else + { + // All we care about here are the dimensions of our mClientWidget. + // The origin is ALWAYS 0,0 + if( mClientWidget ) + { + PtArg_t arg[5]; + PhDim_t *dim; + int *border; + + PtSetArg( &arg[0], Pt_ARG_DIM, &dim, 0 ); + PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, &border, 0 ); + if( PtGetResources( mClientWidget, 2, arg ) == 0 ) + { + aRect.x = 0; + aRect.y = 0; + aRect.width = dim->w + 2*(*border); + aRect.height = dim->h + 2*(*border); + res = NS_OK; + } + } + } + + return res; +} + + +NS_METHOD nsWindow::SetMenuBar( nsIMenuBar * aMenuBar ) +{ +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetMenuBar\n")); + + nsresult res = NS_ERROR_FAILURE; + + if( IsChild() ) // Child windows can't have menus! + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetMenuBar - ERROR! Trying to set a menu for a ChildWindow!\n")); + return res; + } + + mMenuBar = aMenuBar; + + PtArg_t arg[5]; + int menu_h = GetMenuBarHeight(); + PhArea_t *win_area,new_area; + PhArea_t old_area; + + // Now, get the dimensions of the real window + + PtSetArg( &arg[0], Pt_ARG_AREA, &win_area, 0 ); + if( PtGetResources( mWidget, 1, arg ) == 0 ) + { + // Resize the window + old_area = *win_area; + new_area = *win_area; + new_area.size.h += menu_h; + + PtSetArg( &arg[0], Pt_ARG_AREA, &new_area, 0 ); + if( PtSetResources( mWidget, 1, arg ) == 0 ) + { + int *ca_border; + + // Get the client widgets current area + PtSetArg( &arg[0], Pt_ARG_BORDER_WIDTH, &ca_border, 0 ); + if( PtGetResources( mClientWidget, 1, arg ) == 0 ) + { + // Now move the client area below the menu bar + + // New position is just below the menubar + old_area.pos.x = 0; + old_area.pos.y = menu_h; + + // New size is the orig. window size minus border width + old_area.size.w -= 2*(*ca_border); + old_area.size.h -= 2*(*ca_border); + + PtSetArg( &arg[0], Pt_ARG_AREA, &old_area, 0 ); + if( PtSetResources( mClientWidget, 1, arg ) == 0 ) + { + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::SetMenuBar - client shifted down by %i\n", menu_h )); + res = NS_OK; + } + } + } + } + + return res; +} + +/////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////////////////////// + + +int nsWindow::ResizeHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ) +{ +PhRect_t *extents = (PhRect_t *)cbinfo->cbdata; +nsWindow *someWindow = (nsWindow *) GetInstance(widget); +nsRect rect; + + rect.x = extents->ul.x; + rect.y = extents->ul.y; + rect.width = extents->lr.x - rect.x; + rect.height = extents->lr.y - rect.y - someWindow->GetMenuBarHeight(); + +// printf ("doing resize %d %d %d %d\n",rect.x,rect.y,rect.width,rect.height); + someWindow->OnResize( rect ); + return( Pt_CONTINUE ); +} + + +#if 0 //------------------------------------------------------------------------- -static void AdjustMenus(nsIMenu * aCurrentMenu, nsIMenu * aNewMenu, nsMenuEvent & aEvent) +// +// the nsWindow raw event callback for all nsWindows in this toolkit +// +//------------------------------------------------------------------------- +int nsWindow::RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ) { - if (nsnull != aCurrentMenu) { - nsIMenuListener * listener; - if (NS_OK == aCurrentMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) { - listener->MenuDeselected(aEvent); - NS_RELEASE(listener); - } + // Get the window which caused the event and ask it to process the message + nsWindow *someWindow = (nsWindow*) data; + + if( nsnull != someWindow ) + { +//printf ("kedl: nswindow raweventhandler %x\n",someWindow); + if( someWindow->HandleEvent( cbinfo )) + return( Pt_END ); // Event was consumed } - if (nsnull != aNewMenu) { - nsIMenuListener * listener; - if (NS_OK == aNewMenu->QueryInterface(kIMenuListenerIID, (void **)&listener)) { - listener->MenuSelected(aEvent); - NS_RELEASE(listener); - } - } + return( Pt_CONTINUE ); } +#endif -//--------------------------------------------------------- -NS_METHOD nsWindow::EnableFileDrop(PRBool aEnable) -{ - return NS_OK; -} - //------------------------------------------------------------------------- // // Process all nsWindows messages @@ -955,6 +881,7 @@ PRBool nsWindow::HandleEvent( PtCallbackInfo_t* aCbInfo ) // When we get menu selections, dispatch the menu command (event) AND IF there is // a menu listener, call "listener->MenuSelected(event)" + if( aCbInfo->reason == Pt_CB_RAW ) { PhEvent_t* event = aCbInfo->event; @@ -963,49 +890,58 @@ PRBool nsWindow::HandleEvent( PtCallbackInfo_t* aCbInfo ) { case Ph_EV_KEY: { - PhKeyEvent_t* keyev = (PhKeyEvent_t*) PhGetData( event ); - - mIsShiftDown = ( keyev->key_mods & Pk_KM_Shift ) ? PR_TRUE : PR_FALSE; - mIsControlDown = ( keyev->key_mods & Pk_KM_Ctrl ) ? PR_TRUE : PR_FALSE; - mIsAltDown = ( keyev->key_mods & Pk_KM_Alt ) ? PR_TRUE : PR_FALSE; - if( keyev->key_flags & Pk_KF_Key_Down ) - result = OnKey( NS_KEY_DOWN, keyev->key_sym ); - else - result = OnKey( NS_KEY_UP, keyev->key_sym ); + PhKeyEvent_t* keyev = (PhKeyEvent_t*) PhGetData( event ); + result = DispatchKeyEvent(keyev); } break; case Ph_EV_PTR_MOTION_BUTTON: case Ph_EV_PTR_MOTION_NOBUTTON: - result = DispatchMouseEvent( NS_MOUSE_MOVE ); + { + PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); + +// printf( " Mouse move event.\n" ); + + if( ptrev ) + { +// ptrev->pos.y -= GetMenuBarHeight(); + ScreenToWidget( ptrev->pos ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MOVE ); + } + } break; case Ph_EV_BUT_PRESS: { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); +// printf( " Mouse button-press event.\n" ); + if( ptrev ) { +// ptrev->pos.y -= GetMenuBarHeight(); + ScreenToWidget( ptrev->pos ); if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button { + printf( "Window mouse click: (%ld,%ld)\n", ptrev->pos.x, ptrev->pos.y ); if( ptrev->click_count == 2 ) - result = DispatchMouseEvent( NS_MOUSE_LEFT_DOUBLECLICK ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_DOUBLECLICK ); else - result = DispatchMouseEvent( NS_MOUSE_LEFT_BUTTON_DOWN ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_BUTTON_DOWN ); } else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button { if( ptrev->click_count == 2 ) - result = DispatchMouseEvent( NS_MOUSE_RIGHT_DOUBLECLICK ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_DOUBLECLICK ); else - result = DispatchMouseEvent( NS_MOUSE_RIGHT_BUTTON_DOWN ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_BUTTON_DOWN ); } else // middle button { if( ptrev->click_count == 2 ) - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_DOUBLECLICK ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_DOUBLECLICK ); else - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_BUTTON_DOWN ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_BUTTON_DOWN ); } } } @@ -1015,28 +951,66 @@ PRBool nsWindow::HandleEvent( PtCallbackInfo_t* aCbInfo ) { PhPointerEvent_t* ptrev = (PhPointerEvent_t*) PhGetData( event ); +// printf( " Mouse button-release event.\n" ); + + if (event->subtype==Ph_EV_RELEASE_REAL) if( ptrev ) { +// ptrev->pos.y -= GetMenuBarHeight(); + ScreenToWidget( ptrev->pos ); if( ptrev->buttons & Ph_BUTTON_SELECT ) // Normally the left mouse button - result = DispatchMouseEvent( NS_MOUSE_LEFT_BUTTON_UP ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_LEFT_BUTTON_UP ); else if( ptrev->buttons & Ph_BUTTON_MENU ) // the right button - result = DispatchMouseEvent( NS_MOUSE_RIGHT_BUTTON_UP ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_RIGHT_BUTTON_UP ); else // middle button - result = DispatchMouseEvent( NS_MOUSE_MIDDLE_BUTTON_UP ); + result = DispatchMouseEvent( ptrev->pos, NS_MOUSE_MIDDLE_BUTTON_UP ); } } break; + case Ph_EV_BOUNDARY: + switch( event->subtype ) + { + case Ph_EV_PTR_ENTER: + result = DispatchStandardEvent( NS_MOUSE_ENTER ); + break; + case Ph_EV_PTR_LEAVE: + result = DispatchStandardEvent( NS_MOUSE_EXIT ); + break; + } + break; + case Ph_EV_WM: { PhWindowEvent_t* wmev = (PhWindowEvent_t*) PhGetData( event ); + +// printf( " WM event.\n" ); + switch( wmev->event_f ) { case Ph_WM_FOCUS: + { if( wmev->event_state == Ph_WM_EVSTATE_FOCUS ) - result = DispatchFocus(NS_GOTFOCUS); + result = DispatchStandardEvent(NS_GOTFOCUS); else - result = DispatchFocus(NS_LOSTFOCUS); + result = DispatchStandardEvent(NS_LOSTFOCUS); + } + break; + + case Ph_WM_RESIZE: + { + nsRect rect; + PtArg_t arg[5]; + + rect.x = wmev->pos.x; + rect.y = wmev->pos.y; + rect.width = wmev->size.w; + rect.height = wmev->size.h - GetMenuBarHeight(); + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow (%p) Resize Event\n", this )); + + OnResize( rect ); + } break; } } @@ -1048,176 +1022,227 @@ PRBool nsWindow::HandleEvent( PtCallbackInfo_t* aCbInfo ) } - -//------------------------------------------------------------------------- -// -// WM_DESTROY has been called -// -//------------------------------------------------------------------------- -void nsWindow::OnDestroy() +void nsWindow::RawDrawFunc( PtWidget_t * pWidget, PhTile_t * damage ) { - mOnDestroyCalled = PR_TRUE; + nsWindow * pWin = (nsWindow*) GetInstance( pWidget ); - mWidget = NULL; + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::RawDrawFunc for %p\n", pWin )); - // 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(); - } -} + if( !pWin ) + return; -//------------------------------------------------------------------------- -// -// Move -// -//------------------------------------------------------------------------- -PRBool nsWindow::OnMove(PRInt32 aX, PRInt32 aY) -{ - return PR_TRUE; -} - - -//------------------------------------------------------------------------- -// -// Paint -// -//------------------------------------------------------------------------- -PRBool nsWindow::OnPaint() -{ - return PR_TRUE; -} - - -//------------------------------------------------------------------------- -// -// Send a resize message to the listener -// -//------------------------------------------------------------------------- -PRBool nsWindow::OnResize(nsRect &aWindowRect) -{ - // call the event callback - if( mEventCallback ) + if( pWin->mEventCallback ) { - } + PhRect_t rect; + PhArea_t area; + PhPoint_t offset; + nsRect nsDmg; - return PR_FALSE; -} + // Ok... I ~think~ the damage rect is in window coordinates and is not neccessarily clipped to + // the widgets canvas. Mozilla wants the paint coords relative to the parent widget, not the window. + PtWidgetArea( pWidget, &area ); + PtWidgetOffset( pWidget, &offset ); + offset.x += area.pos.x; + offset.y += area.pos.y; + // Convert damage rect to widget's coordinates... + rect = damage->rect; + rect.ul.x -= offset.x; + rect.ul.y -= offset.y; + rect.lr.x -= offset.x; + rect.lr.y -= offset.y; -//------------------------------------------------------------------------- -// -// Deal with all sort of mouse event -// -//------------------------------------------------------------------------- -PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint) -{ - return PR_TRUE; -} + // If the damage tile is not within our bounds, do nothing + if(( rect.ul.x >= area.size.w ) || ( rect.ul.y >= area.size.h ) || ( rect.lr.x < 0 ) || ( rect.lr.y < 0 )) + return; -//------------------------------------------------------------------------- -// -// Deal with focus messages -// -//------------------------------------------------------------------------- -PRBool nsWindow::DispatchFocus(PRUint32 aEventType) -{ - // call the event callback - if (mEventCallback) { - if ((nsnull != gCurrentWindow) && (!gCurrentWindow->mIsDestroying)) { - return(DispatchStandardEvent(aEventType)); + // clip damage to widgets bounds... + if( rect.ul.x < 0 ) rect.ul.x = 0; + if( rect.ul.y < 0 ) rect.ul.y = 0; + if( rect.lr.x >= area.size.w ) rect.lr.x = area.size.w - 1; + if( rect.lr.y >= area.size.h ) rect.lr.y = area.size.h - 1; + + // Make damage relative to widgets parent + nsDmg.x = rect.ul.x + area.pos.x; + nsDmg.y = rect.ul.y + area.pos.y; + + // Get the position of the child window instead of pWidgets pos since it's always 0,0. + +// PtWidget_t * parent = PtWidgetParent( pWidget ); +// if( parent ) +// { +// PtWidgetArea( parent, &area ); +// nsDmg.x = area.pos.x + rect.ul.x; +// nsDmg.y = area.pos.y + rect.ul.y; +// } +// else +// PR_LOG(PhWidLog, PR_LOG_DEBUG, (" No parent!\n" )); + + nsDmg.width = rect.lr.x - rect.ul.x + 1; + nsDmg.height = rect.lr.y - rect.ul.y + 1; + + if( !nsDmg.width || !nsDmg.height ) + return; + + nsPaintEvent pev; + pWin->InitEvent(pev, NS_PAINT); + + pev.rect = &nsDmg; + pev.eventStructType = NS_PAINT_EVENT; + + PtHold(); + + if (NS_OK == nsComponentManager::CreateInstance(kRenderingContextCID, nsnull, kRenderingContextIID, (void **)&pev.renderingContext)) + { + PhRect_t *rects; + int rect_count; + int i; + + pev.renderingContext->Init( pWin->mContext, pWin ); + + rects = PhTilesToRects( damage->next, &rect_count ); + + for(i=0;iDispatchWindowEvent(&pev); + NS_RELEASE(pev.renderingContext); } - return PR_FALSE; + PtRelease(); + +// NS_RELEASE(pev.widget); +// PR_LOG(PhWidLog, PR_LOG_DEBUG, ("* widget released (not really)\n")); + + } } - -//------------------------------------------------------------------------- -// -// Deal with all sort of mouse event -// -//------------------------------------------------------------------------- -PRBool ChildWindow::DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint) +int nsWindow::GetMenuBarHeight() { - PRBool result = PR_FALSE; + int h = 0; - if (nsnull == mEventCallback && nsnull == mMouseListener) { - return result; + if( mMenuBar ) + { + void * menubar; +// PtWidget_t * menubar; + + mMenuBar->GetNativeData( menubar ); + + if( menubar ) + { + PtArg_t arg[2]; + PhDim_t *mb_dim; + int *mb_border; + + // Resize the window to accomodate the menubar + // First, get the menubars dimensions and border size + + PtSetArg( &arg[0], Pt_ARG_DIM, &mb_dim, 0 ); + PtSetArg( &arg[1], Pt_ARG_BORDER_WIDTH, &mb_border, 0 ); + if( PtGetResources(( PtWidget_t* ) menubar, 2, arg ) == 0 ) + { + h = mb_dim->h + 2*(*mb_border); + } + } } - switch (aEventType) { - case NS_MOUSE_LEFT_BUTTON_DOWN: - case NS_MOUSE_MIDDLE_BUTTON_DOWN: - case NS_MOUSE_RIGHT_BUTTON_DOWN: -// SetCapture(mWnd); - // Photon doesn't allow mouse events to be captures outside of the - // apps regions... - break; - - case NS_MOUSE_LEFT_BUTTON_UP: - case NS_MOUSE_MIDDLE_BUTTON_UP: - case NS_MOUSE_RIGHT_BUTTON_UP: -// ReleaseCapture(); - break; - - default: - break; - - } // switch - - return nsWindow::DispatchMouseEvent(aEventType, aPoint); + return h; } - -NS_METHOD nsWindow::SetTitle(const nsString& aTitle) +void nsWindow::ScreenToWidget( PhPoint_t &pt ) { + // pt is in screen coordinates + // convert it to be relative to ~this~ widgets origin + short x=0,y=0; + + if( IsChild()) + { + PtGetAbsPosition( mWidget, &x, &y ); + } + else + { + PtGetAbsPosition( mClientWidget, &x, &y ); + } + + pt.x -= x; + pt.y -= y; +} + +#if 0 + +NS_METHOD nsWindow::Invalidate(PRBool aIsSynchronous) +{ + return nsWidget::Invalidate( aIsSynchronous ); +} + + +NS_METHOD nsWindow::Invalidate(const nsRect & aRect, PRBool aIsSynchronous) +{ + + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Invalidate %p (%ld,%ld,%ld,%ld)\n", this, aRect.x, aRect.y, aRect.width, aRect.height )); + if( mWidget ) { - PtArg_t arg; - - NS_ALLOC_STR_BUF(buf, aTitle, 256); - PtSetArg( &arg, Pt_ARG_WINDOW_TITLE, buf, 0 ); - PtSetResources( mWidget, 1, &arg ); - NS_FREE_STR_BUF(buf); + PhRect_t extent; + PhArea_t area; + + PtWidgetArea( mWidget, &area ); + + extent.ul.x = aRect.x + area.pos.x; + extent.ul.y = aRect.y + area.pos.y; + extent.lr.x = extent.ul.x + aRect.width - 1; + extent.lr.y = extent.ul.y + aRect.height - 1; + + + PtDamageExtent( mWidget, &extent ); + +/* +if (PtWidgetChildFront(mWidget)) + PtDamageExtent( PtWidgetChildFront(mWidget), &extent ); +else + PtDamageExtent( mWidget, &extent ); +*/ + +#if 0 + PtWidget_t *w; + + for( w = PtWidgetChildFront( mWidget ); + w; + w = PtWidgetBrotherBehind( w ) ) + { +// printf ("damage: %lu\n",w); + PtDamageExtent(w,&extent); + } +#endif + + // REVISIT - PtFlush may be unstable & cause crashes... + if( aIsSynchronous ) + PtFlush(); } - return NS_OK; -} + else + PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsWindow::Invalidate - mWidget is NULL!\n" )); -PRBool nsWindow::AutoErase() -{ - return(PR_FALSE); -} - -NS_METHOD nsWindow::SetMenuBar(nsIMenuBar * aMenuBar) -{ - return NS_OK; -} - -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; } - - +#endif diff --git a/widget/src/photon/nsWindow.h b/widget/src/photon/nsWindow.h index 4b84248f4af9..a0f3ca3f56fd 100644 --- a/widget/src/photon/nsWindow.h +++ b/widget/src/photon/nsWindow.h @@ -20,7 +20,7 @@ #include "nsBaseWidget.h" #include "nsToolkit.h" -#include "nsIWidget.h" +#include "nsWidget.h" #include "nsIMenuBar.h" #include "nsIMouseListener.h" #include "nsIEventListener.h" @@ -36,153 +36,94 @@ * Native Photon window wrapper. */ -class nsWindow : public nsBaseWidget +class nsWindow : public nsWidget { public: + // nsIWidget interface + 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 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) {} - - - - virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint = nsnull); - virtual PRBool AutoErase(); - nsPoint* GetLastPoint() { return &mLastPoint; } - - PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;} - - -protected: - - static int RawEventHandler( PtWidget_t *, void *, PtCallbackInfo_t * ); - PRBool HandleEvent( PtCallbackInfo_t* ); - - virtual PRBool DispatchWindowEvent(nsGUIEvent* event); - - // 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(); - virtual PRBool OnResize(nsRect &aWindowRect); - virtual PRBool OnKey(PRUint32 aEventType, PRUint32 aKeyCode); - - virtual PRBool DispatchFocus(PRUint32 aEventType); - - static PRBool ConvertStatus(nsEventStatus aStatus); - - PRBool DispatchStandardEvent(PRUint32 aMsg); - - void GetNonClientBounds(nsRect &aRect); - -protected: - static nsWindow* gCurrentWindow; - nsPoint mLastPoint; - PtWidget_t* mWidget; + // nsIsupports + NS_IMETHOD_(nsrefcnt) AddRef(); + NS_IMETHOD_(nsrefcnt) Release(); + NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr); - PRBool mHas3DBorder; - PRBool mIsShiftDown; - PRBool mIsControlDown; - PRBool mIsAltDown; - PRBool mIsDestroying; - PRBool mOnDestroyCalled; - PRBool mIsVisible; - // XXX Temporary, should not be caching the font - nsFont * mFont; + virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY); - PRInt32 mPreferredWidth; - PRInt32 mPreferredHeight; + NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData); - nsIMenuBar * mMenuBar; - PRInt32 mMenuCmdId; - nsIMenu * mHitMenu; - nsVoidArray * mHitSubMenus; + virtual void* GetNativeData(PRUint32 aDataType); - // 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 - }; + 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 GetBounds( nsRect &aRect ); + NS_IMETHOD GetClientBounds( nsRect &aRect ); + + NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]); + NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]); + NS_IMETHOD RemoveTooltips(); + + NS_IMETHOD BeginResizingChildren(void); + NS_IMETHOD EndResizingChildren(void); +// NS_IMETHOD Destroy(void); + NS_IMETHOD Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint); + NS_IMETHOD Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, + PRUint32 aHeight, PRBool aRepaint); +// NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous); +// NS_IMETHOD Invalidate(PRBool aIsSynchronous); + + + virtual PRBool IsChild() { return(PR_FALSE); }; + virtual void SetIsDestroying( PRBool val) { mIsDestroying = val; }; + virtual int GetMenuBarHeight(); + + // Utility methods + virtual PRBool OnPaint(nsPaintEvent &event); + PRBool OnKey(nsKeyEvent &aEvent); + PRBool DispatchFocus(nsGUIEvent &aEvent); + virtual PRBool OnScroll(nsScrollbarEvent & aEvent, PRUint32 cPos); + // in nsWidget now + //PRBool OnResize( nsRect &rect ); + +// char gInstanceClassName[256]; + +protected: +// virtual void OnDestroy(); + static void RawDrawFunc( PtWidget_t *pWidget, PhTile_t *damage ); +// virtual void InitCallbacks(char * aName = nsnull); + + NS_IMETHOD CreateNative(PtWidget_t *parentWidget); + static int ResizeHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ); +// static int RawEventHandler( PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo ); + PRBool HandleEvent( PtCallbackInfo_t* aCbInfo ); + void ScreenToWidget( PhPoint_t &pt ); + + PtWidget_t *mClientWidget; + PtWidget_t *mRawDraw; + nsIFontMetrics *mFontMetrics; + PRBool mVisible; + PRBool mDisplayed; + PRBool mIsDestroying; + + +// GtkWindowType mBorderStyle; + + // XXX Temporary, should not be caching the font + nsFont * mFont; + + // Resize event management + nsRect mResizeRect; + int mResized; + PRBool mLowerLeft; + +// GtkWidget *mShell; /* used for toplevel windows */ +// GtkWidget *mVBox; }; @@ -190,11 +131,9 @@ protected: // A child window is a window with different style // class ChildWindow : public nsWindow { - -public: - ChildWindow(){} - PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint = nsnull); - + public: + ChildWindow() {}; + virtual PRBool IsChild() { return(PR_TRUE); }; };