зеркало из https://github.com/mozilla/gecko-dev.git
- These files bring the Photon UI uptodate.
- They still include lots of debug that will be cleaned out later - once everything works.
This commit is contained in:
Родитель
19f3511bbb
Коммит
06cf38bb8b
|
@ -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)
|
||||
|
|
|
@ -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 ) );
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/* PtRawDrawContainer.h - widget header file */
|
||||
|
||||
#include <Pt.h>
|
||||
|
||||
/* 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;
|
||||
|
|
@ -17,12 +17,54 @@
|
|||
*/
|
||||
|
||||
#include "nsAppShell.h"
|
||||
#include "nsIAppShell.h"
|
||||
|
||||
#include "plevent.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
||||
|
||||
#include "nsIWidget.h"
|
||||
|
||||
#include <Pt.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
||||
NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID);
|
||||
|
||||
PRBool nsAppShell::mPtInited = PR_FALSE;
|
||||
|
||||
#include <prlog.h>
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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__
|
||||
|
|
|
@ -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 <Pt.h>
|
||||
|
||||
#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
|
||||
|
|
@ -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 <Pt.h>
|
||||
|
||||
/**
|
||||
* 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__
|
|
@ -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 <Pt.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
@ -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 <Pt.h>
|
||||
|
||||
/**
|
||||
* 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__
|
|
@ -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 <Pt.h>
|
||||
#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;
|
||||
}
|
|
@ -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__
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -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 <Pt.h>
|
||||
#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<aNumberOfFilters; i++)
|
||||
{
|
||||
char *str1 = aTitles[i].ToNewCString();
|
||||
char *str2 = aFilters[i].ToNewCString();
|
||||
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsFileWidget::SetFilterList %d Title=<%s> 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;
|
||||
}
|
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
#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<aSize;i++)
|
||||
{
|
||||
SelectItem(aIndices[i]);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Deselect
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsListBox::Deselect()
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::Deselect\n"));
|
||||
|
||||
nsresult res = NS_ERROR_FAILURE;
|
||||
|
||||
if (mWidget)
|
||||
{
|
||||
const int theSelectedCount = GetSelectedCount();
|
||||
int theList[theSelectedCount];
|
||||
int i;
|
||||
|
||||
GetSelectedIndices(theList, theSelectedCount);
|
||||
for(i=0;i<theSelectedCount;i++)
|
||||
{
|
||||
PR_LOG(PhWidLog, PR_LOG_DEBUG, ("nsListBox::Deselect Unselecting <%d>\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);
|
||||
}
|
|
@ -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__
|
|
@ -19,6 +19,7 @@
|
|||
#include "nsLookAndFeel.h"
|
||||
#include <Pt.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
#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<nsIMenuListener> menuListener;
|
||||
pnsMenuBar->QueryInterface(kIMenuListenerIID, getter_AddRefs(menuListener));
|
||||
aParentWindow->AddMenuListener(menuListener);
|
||||
|
||||
nsCOMPtr<nsIDOMNode> menuNode;
|
||||
((nsIDOMNode*)menubarNode)->GetFirstChild(getter_AddRefs(menuNode));
|
||||
while (menuNode) {
|
||||
nsCOMPtr<nsIDOMElement> 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<nsIDOMNode> 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;
|
||||
}
|
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
|
||||
#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<nsIContentViewerContainer> contentViewerContainer;
|
||||
contentViewerContainer = do_QueryInterface(mWebShell);
|
||||
if (!contentViewerContainer) {
|
||||
NS_ERROR("Webshell doesn't support the content viewer container interface");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) {
|
||||
NS_ERROR("Unable to retrieve content viewer.");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer;
|
||||
docViewer = do_QueryInterface(contentViewer);
|
||||
if (!docViewer) {
|
||||
NS_ERROR("Document viewer interface not supported by the content viewer.");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPresContext> 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<nsIContent> 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;
|
||||
}
|
|
@ -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__
|
|
@ -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 <prlog.h>
|
||||
#include <signal.h>
|
||||
|
||||
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
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
@ -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 <Pt.h>
|
||||
|
||||
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__
|
||||
|
|
@ -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 <Pt.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
@ -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 <Pt.h>
|
||||
|
||||
/**
|
||||
* 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__
|
|
@ -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 <Pt.h>
|
||||
#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);
|
||||
}
|
|
@ -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_
|
|
@ -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 <Pt.h>
|
||||
#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
|
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
#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"));
|
||||
}
|
|
@ -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__
|
|
@ -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 <Pt.h>
|
||||
#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);
|
||||
}
|
|
@ -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__
|
|
@ -22,6 +22,7 @@
|
|||
#include "prtime.h"
|
||||
#include "nsGUIEvent.h"
|
||||
#include <Pt.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifndef TOOLKIT_H
|
||||
#define TOOLKIT_H
|
||||
|
||||
#include <Pt.h>
|
||||
#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:
|
||||
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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 <Pt.h>
|
||||
|
||||
|
||||
/**
|
||||
* 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__ */
|
|
@ -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))
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -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);
|
||||
// nsIsupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef();
|
||||
NS_IMETHOD_(nsrefcnt) Release();
|
||||
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
|
||||
|
||||
// Utility method for implementing both Create(nsIWidget ...) and
|
||||
// Create(nsNativeWidget...)
|
||||
virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
|
||||
|
||||
virtual nsresult StandardWindowCreate(nsIWidget *aParent,
|
||||
const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction,
|
||||
nsIDeviceContext *aContext,
|
||||
nsIAppShell *aAppShell,
|
||||
nsIToolkit *aToolkit,
|
||||
nsWidgetInitData *aInitData,
|
||||
nsNativeWidget aNativeParent = nsnull);
|
||||
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aWidgetInitData);
|
||||
|
||||
NS_IMETHOD Destroy();
|
||||
virtual nsIWidget* GetParent(void);
|
||||
NS_IMETHOD Show(PRBool bState);
|
||||
NS_IMETHOD IsVisible(PRBool & aState);
|
||||
virtual void* GetNativeData(PRUint32 aDataType);
|
||||
|
||||
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);
|
||||
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
|
||||
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
|
||||
|
||||
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
||||
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();
|
||||
|
||||
virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint* aPoint = nsnull);
|
||||
virtual PRBool AutoErase();
|
||||
nsPoint* GetLastPoint() { return &mLastPoint; }
|
||||
|
||||
PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;}
|
||||
// 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);
|
||||
|
||||
static int RawEventHandler( PtWidget_t *, void *, PtCallbackInfo_t * );
|
||||
PRBool HandleEvent( PtCallbackInfo_t* );
|
||||
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 );
|
||||
|
||||
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
|
||||
PtWidget_t *mClientWidget;
|
||||
PtWidget_t *mRawDraw;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
PRBool mVisible;
|
||||
PRBool mDisplayed;
|
||||
PRBool mIsDestroying;
|
||||
|
||||
// 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);
|
||||
// GtkWindowType mBorderStyle;
|
||||
|
||||
virtual PRBool DispatchFocus(PRUint32 aEventType);
|
||||
// XXX Temporary, should not be caching the font
|
||||
nsFont * mFont;
|
||||
|
||||
static PRBool ConvertStatus(nsEventStatus aStatus);
|
||||
// Resize event management
|
||||
nsRect mResizeRect;
|
||||
int mResized;
|
||||
PRBool mLowerLeft;
|
||||
|
||||
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
||||
|
||||
void GetNonClientBounds(nsRect &aRect);
|
||||
|
||||
protected:
|
||||
static nsWindow* gCurrentWindow;
|
||||
nsPoint mLastPoint;
|
||||
PtWidget_t* mWidget;
|
||||
|
||||
PRBool mHas3DBorder;
|
||||
PRBool mIsShiftDown;
|
||||
PRBool mIsControlDown;
|
||||
PRBool mIsAltDown;
|
||||
PRBool mIsDestroying;
|
||||
PRBool mOnDestroyCalled;
|
||||
PRBool mIsVisible;
|
||||
// XXX Temporary, should not be caching the font
|
||||
nsFont * mFont;
|
||||
|
||||
PRInt32 mPreferredWidth;
|
||||
PRInt32 mPreferredHeight;
|
||||
|
||||
nsIMenuBar * mMenuBar;
|
||||
PRInt32 mMenuCmdId;
|
||||
nsIMenu * mHitMenu;
|
||||
nsVoidArray * mHitSubMenus;
|
||||
|
||||
// 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
|
||||
};
|
||||
// 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); };
|
||||
};
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче