зеркало из https://github.com/mozilla/gecko-dev.git
BeOS landing; thanks to Duncan Wilcox (duncan@be.com) for these changes.
This commit is contained in:
Родитель
8a84e0812a
Коммит
a85131e848
|
@ -0,0 +1,85 @@
|
||||||
|
#!gmake
|
||||||
|
#
|
||||||
|
# The contents of this file are subject to the Netscape Public License
|
||||||
|
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
# http://www.mozilla.org/NP\
|
||||||
|
#
|
||||||
|
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
# for the specific language governing rights and limitations under the
|
||||||
|
# NPL.
|
||||||
|
#
|
||||||
|
# The Initial Developer of this code under the NPL is Netscape
|
||||||
|
# Communications Corporation. Portions created by Netscape are
|
||||||
|
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
# Reserved.
|
||||||
|
|
||||||
|
|
||||||
|
DEPTH = ../../..
|
||||||
|
topsrcdir = @top_srcdir@
|
||||||
|
srcdir = @srcdir@
|
||||||
|
VPATH = @srcdir@
|
||||||
|
|
||||||
|
include $(DEPTH)/config/autoconf.mk
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/config.mk
|
||||||
|
|
||||||
|
LIBRARY_NAME = raptorwidgetbeos_s
|
||||||
|
|
||||||
|
MODULE=widget
|
||||||
|
|
||||||
|
REQUIRES=util img xpcom raptor netlib
|
||||||
|
|
||||||
|
DEFINES += -D_IMPL_NS_WIDGET
|
||||||
|
|
||||||
|
INCLUDES+= -I$(srcdir)/../xpwidgets -I$(srcdir)/. -I@top_srcdir@/gfx/src/beos
|
||||||
|
|
||||||
|
INCLUDES += $(TK_CFLAGS)
|
||||||
|
|
||||||
|
CPPSRCS = \
|
||||||
|
nsPopUpMenu.cpp \
|
||||||
|
nsMenuBar.cpp \
|
||||||
|
nsMenu.cpp \
|
||||||
|
nsMenuItem.cpp \
|
||||||
|
nsObject.cpp \
|
||||||
|
nsWindow.cpp \
|
||||||
|
nsButton.cpp \
|
||||||
|
nsCheckButton.cpp \
|
||||||
|
nsRadioButton.cpp \
|
||||||
|
nsDragService.cpp \
|
||||||
|
nsListBox.cpp \
|
||||||
|
nsComboBox.cpp \
|
||||||
|
nsTextWidget.cpp \
|
||||||
|
nsTextHelper.cpp \
|
||||||
|
nsTextAreaWidget.cpp\
|
||||||
|
nsFileWidget.cpp \
|
||||||
|
nsScrollbar.cpp \
|
||||||
|
nsTabWidget.cpp \
|
||||||
|
nsTooltipWidget.cpp \
|
||||||
|
nsAppShell.cpp \
|
||||||
|
nsLabel.cpp \
|
||||||
|
nsToolkit.cpp \
|
||||||
|
nsSound.cpp \
|
||||||
|
nsFontRetrieverService.cpp \
|
||||||
|
nsFontSizeIterator.cpp \
|
||||||
|
nsClipboard.cpp \
|
||||||
|
nsLookAndFeel.cpp \
|
||||||
|
$(NULL)
|
||||||
|
|
||||||
|
TARGETS = $(LIBRARY)
|
||||||
|
|
||||||
|
MKSHLIB :=
|
||||||
|
|
||||||
|
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||||
|
override NO_SHARED_LIB=1
|
||||||
|
override NO_STATIC_LIB=
|
||||||
|
|
||||||
|
include $(topsrcdir)/config/rules.mk
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,294 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsAppShell.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include "nsIAppShell.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsTimer.h"
|
||||||
|
#include "plevent.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <AppKit.h>
|
||||||
|
#include <AppFileInfo.h>
|
||||||
|
|
||||||
|
struct ThreadInterfaceData
|
||||||
|
{
|
||||||
|
void *data;
|
||||||
|
int32 sync;
|
||||||
|
};
|
||||||
|
|
||||||
|
static sem_id my_find_sem(const char *name)
|
||||||
|
{
|
||||||
|
sem_id ret = B_ERROR;
|
||||||
|
|
||||||
|
/* Get the sem_info for every sempahore in this team. */
|
||||||
|
sem_info info;
|
||||||
|
int32 cookie = 0;
|
||||||
|
|
||||||
|
while(get_next_sem_info(0, &cookie, &info) == B_OK)
|
||||||
|
if(strcmp(name, info.name) == 0)
|
||||||
|
{
|
||||||
|
ret = info.sem;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsISupports implementation macro
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsAppShell,kIAppShellIID);
|
||||||
|
|
||||||
|
static bool GetAppSig(char *sig)
|
||||||
|
{
|
||||||
|
app_info appInfo;
|
||||||
|
BFile file;
|
||||||
|
BAppFileInfo appFileInfo;
|
||||||
|
image_info info;
|
||||||
|
int32 cookie = 0;
|
||||||
|
*sig = 0;
|
||||||
|
return get_next_image_info(0, &cookie, &info) == B_OK &&
|
||||||
|
file.SetTo(info.name, B_READ_ONLY) == B_OK &&
|
||||||
|
appFileInfo.SetTo(&file) == B_OK &&
|
||||||
|
appFileInfo.GetSignature(sig) == B_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
class nsBeOSApp : public BApplication
|
||||||
|
{
|
||||||
|
sem_id init;
|
||||||
|
public:
|
||||||
|
nsBeOSApp(const char *signature, sem_id initsem);
|
||||||
|
virtual void ReadyToRun(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
nsBeOSApp::nsBeOSApp(const char *signature, sem_id initsem)
|
||||||
|
: BApplication(signature), init(initsem)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsBeOSApp::ReadyToRun(void)
|
||||||
|
{
|
||||||
|
release_sem(init);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 bapp_thread(void *arg)
|
||||||
|
{
|
||||||
|
// create and start BApplication
|
||||||
|
char sig[B_MIME_TYPE_LENGTH + 1];
|
||||||
|
GetAppSig(sig);
|
||||||
|
nsBeOSApp *app = new nsBeOSApp(sig, (sem_id)arg);
|
||||||
|
app->Run();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsAppShell constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsAppShell::nsAppShell()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mDispatchListener = 0;
|
||||||
|
|
||||||
|
sem_id initsem = create_sem(0, "bapp init");
|
||||||
|
resume_thread(spawn_thread(bapp_thread, "BApplication", B_NORMAL_PRIORITY, (void *)initsem));
|
||||||
|
acquire_sem(initsem);
|
||||||
|
delete_sem(initsem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create the application shell
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsAppShell::Create(int* argc, char ** argv)
|
||||||
|
{
|
||||||
|
// system wide unique names
|
||||||
|
// NOTE: this needs to be run from within the main application thread
|
||||||
|
char portname[64];
|
||||||
|
char semname[64];
|
||||||
|
sprintf(portname, "event%lx", PR_GetCurrentThread());
|
||||||
|
sprintf(semname, "sync%lx", PR_GetCurrentThread());
|
||||||
|
|
||||||
|
if((eventport = find_port(portname)) < 0)
|
||||||
|
{
|
||||||
|
// we're here first
|
||||||
|
eventport = create_port(100, portname);
|
||||||
|
syncsem = create_sem(0, semname);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// the PLEventQueue stuff (in plevent.c) created the queue before we started
|
||||||
|
syncsem = my_find_sem(semname);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
|
||||||
|
{
|
||||||
|
mDispatchListener = aDispatchListener;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Enter a message handler loop
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
nsresult nsAppShell::Run()
|
||||||
|
{
|
||||||
|
int32 code;
|
||||||
|
ThreadInterfaceData id;
|
||||||
|
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
|
||||||
|
while(read_port(eventport, &code, &id, sizeof(id)) >= 0)
|
||||||
|
{
|
||||||
|
switch(code)
|
||||||
|
{
|
||||||
|
case WM_TIMER :
|
||||||
|
{
|
||||||
|
TimerImpl *tobj = (TimerImpl *)id.data;
|
||||||
|
tobj->FireTimeout();
|
||||||
|
if(! id.sync)
|
||||||
|
NS_RELEASE(tobj);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_CALLMETHOD :
|
||||||
|
{
|
||||||
|
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||||
|
mInfo->Invoke();
|
||||||
|
if(! id.sync)
|
||||||
|
delete mInfo;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'natv' : // native queue PLEvent
|
||||||
|
{
|
||||||
|
PREventQueue *queue = (PREventQueue *)id.data;
|
||||||
|
PR_ProcessPendingEvents(queue);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
printf("nsAppShell::Run - UNKNOWN EVENT\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(mDispatchListener)
|
||||||
|
mDispatchListener->AfterDispatch();
|
||||||
|
|
||||||
|
if(id.sync)
|
||||||
|
release_sem(syncsem);
|
||||||
|
}
|
||||||
|
|
||||||
|
Release();
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Exit a message handler loop
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsAppShell::Exit()
|
||||||
|
{
|
||||||
|
// interrupt message flow
|
||||||
|
close_port(eventport);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsAppShell destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsAppShell::~nsAppShell()
|
||||||
|
{
|
||||||
|
if(be_app->Lock())
|
||||||
|
be_app->Quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// GetNativeData
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
void* nsAppShell::GetNativeData(PRUint32 aDataType)
|
||||||
|
{
|
||||||
|
if (aDataType == NS_NATIVE_SHELL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Spinup - do any preparation necessary for running a message loop
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsAppShell::Spinup()
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Spindown - do any cleanup necessary for finishing a message loop
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsAppShell::Spindown()
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsAppShell::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
|
||||||
|
{
|
||||||
|
printf("nsAppShell::GetNativeEvent - FIXME: not implemented\n");
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
|
||||||
|
{
|
||||||
|
printf("nsAppShell::DispatchNativeEvent - FIXME: not implemented\n");
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsAppShell::EventIsForModalWindow(PRBool aRealEvent, void *aEvent, nsIWidget *aWidget, PRBool *aForWindow)
|
||||||
|
{
|
||||||
|
printf("nsAppShell::EventIsForModalWindow - FIXME: not implemented\n");
|
||||||
|
*aForWindow = PR_FALSE;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,58 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsAppShell_h__
|
||||||
|
#define nsAppShell_h__
|
||||||
|
|
||||||
|
#include "nsObject.h"
|
||||||
|
#include "nsIAppShell.h"
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS Application shell wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsAppShell : public nsIAppShell
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsAppShell();
|
||||||
|
virtual ~nsAppShell();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIAppShellInterface
|
||||||
|
|
||||||
|
NS_IMETHOD Create(int* argc, char ** argv);
|
||||||
|
virtual nsresult Run();
|
||||||
|
NS_IMETHOD Spinup();
|
||||||
|
NS_IMETHOD Spindown();
|
||||||
|
NS_IMETHOD GetNativeEvent(PRBool &aRealEvent, void *&aEvent);
|
||||||
|
NS_IMETHOD DispatchNativeEvent(PRBool aRealEvent, void * aEvent);
|
||||||
|
NS_IMETHOD EventIsForModalWindow(PRBool aRealEvent, void *aEvent,
|
||||||
|
nsIWidget *aWidget, PRBool *aForWindow);
|
||||||
|
NS_IMETHOD Exit();
|
||||||
|
NS_IMETHOD SetDispatchListener(nsDispatchListener* aDispatchListener);
|
||||||
|
virtual void* GetNativeData(PRUint32 aDataType);
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsDispatchListener *mDispatchListener;
|
||||||
|
port_id eventport;
|
||||||
|
sem_id syncsem;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsAppShell_h__
|
|
@ -0,0 +1,282 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsButton.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsButton)
|
||||||
|
NS_IMPL_RELEASE(nsButton)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsButton constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsButton::nsButton() : nsWindow() , nsIButton()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsButton destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsButton::~nsButton()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
|
||||||
|
* @modify gpk 8/4/98
|
||||||
|
* @param aIID The name of the class implementing the method
|
||||||
|
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||||
|
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nsresult nsButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kIButton, NS_IBUTTON_IID);
|
||||||
|
if (aIID.Equals(kIButton)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIButton*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsWindow::QueryInterface(aIID,aInstancePtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsButton::SetLabel(const nsString& aText)
|
||||||
|
{
|
||||||
|
mLabel = aText;
|
||||||
|
if(NULL == mView) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
NS_ALLOC_STR_BUF(label, aText, 256);
|
||||||
|
if(mButton)
|
||||||
|
{
|
||||||
|
if(mButton->Looper())
|
||||||
|
mButton->LockLooper();
|
||||||
|
|
||||||
|
mButton->SetLabel(label);
|
||||||
|
|
||||||
|
if(mButton->Looper())
|
||||||
|
mButton->UnlockLooper();
|
||||||
|
}
|
||||||
|
NS_FREE_STR_BUF(label);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsButton::GetLabel(nsString& aBuffer)
|
||||||
|
{
|
||||||
|
aBuffer = mLabel;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsButton::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsButton::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
//printf("** nsButton::OnPaint **\n");
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsButton::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the Button for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
float appUnits;
|
||||||
|
float devUnits;
|
||||||
|
float scale;
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
|
||||||
|
context->GetCanonicalPixelScale(scale);
|
||||||
|
context->GetAppUnitsToDevUnits(devUnits);
|
||||||
|
context->GetDevUnitsToAppUnits(appUnits);
|
||||||
|
|
||||||
|
nsRect rect;
|
||||||
|
GetBoundsAppUnits(rect, appUnits);
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscolor bgColor = NS_RGB(255,255,255);
|
||||||
|
nscolor fgColor = NS_RGB(0,0,0);
|
||||||
|
nscolor hltColor = NS_RGB(240,240,240);
|
||||||
|
nscolor sdwColor = NS_RGB(128,128,128);
|
||||||
|
|
||||||
|
nsILookAndFeel * lookAndFeel;
|
||||||
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(bgColor);
|
||||||
|
aRenderingContext.FillRect(rect);
|
||||||
|
|
||||||
|
/*aRenderingContext.SetColor(bgColor);
|
||||||
|
for (int i=0;i<int(scale);i++) {
|
||||||
|
aRenderingContext.DrawRect(rect);
|
||||||
|
rect.x += 3;
|
||||||
|
rect.y += 3;
|
||||||
|
rect.width -= 6;
|
||||||
|
rect.height -= 6;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
nscoord onePixel = nscoord(scale);
|
||||||
|
nscoord twoPixels = nscoord(scale*2);
|
||||||
|
|
||||||
|
rect.x += onePixel;
|
||||||
|
rect.y += onePixel;
|
||||||
|
rect.width -= twoPixels;
|
||||||
|
rect.height -= twoPixels;
|
||||||
|
|
||||||
|
nscoord right = rect.x+rect.width;
|
||||||
|
nscoord bottom = rect.y+rect.height;
|
||||||
|
|
||||||
|
|
||||||
|
// Draw Left & Top
|
||||||
|
aRenderingContext.SetColor(NS_RGB(225,225,225));
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||||
|
|
||||||
|
// Draw Right & Bottom
|
||||||
|
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||||
|
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||||
|
|
||||||
|
aRenderingContext.SetFont(*mFont);
|
||||||
|
|
||||||
|
nscoord textWidth;
|
||||||
|
nscoord textHeight;
|
||||||
|
aRenderingContext.GetWidth(mLabel, textWidth);
|
||||||
|
|
||||||
|
nsIFontMetrics* metrics;
|
||||||
|
context->GetMetricsFor(*mFont, metrics);
|
||||||
|
metrics->GetMaxAscent(textHeight);
|
||||||
|
|
||||||
|
nscoord x = ((rect.width - textWidth) / 2) + rect.x;
|
||||||
|
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||||
|
aRenderingContext.DrawString(mLabel, x, y);
|
||||||
|
|
||||||
|
|
||||||
|
NS_RELEASE(context);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsButton::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mButton = new nsButtonBeOS(this, BRect(0, 0, 0, 0), "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS Button
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsButtonBeOS::nsButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, const char *aLabel, uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BButton( aFrame, aName, aLabel, new BMessage('clik'), aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsButtonBeOS::AttachedToWindow()
|
||||||
|
{
|
||||||
|
SetTarget(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsButtonBeOS::MessageReceived(BMessage *msg)
|
||||||
|
{
|
||||||
|
switch(msg->what)
|
||||||
|
{
|
||||||
|
case 'clik' :
|
||||||
|
{
|
||||||
|
nsWindow *w = (nsWindow *)GetMozillaWidget();
|
||||||
|
nsToolkit *t;
|
||||||
|
if(w && (t = w->GetToolkit()) != 0)
|
||||||
|
{
|
||||||
|
uint32 args[5];
|
||||||
|
args[0] = NS_MOUSE_LEFT_CLICK;
|
||||||
|
args[1] = (uint32)0;
|
||||||
|
args[2] = (uint32)0;
|
||||||
|
args[3] = 1;
|
||||||
|
args[4] = modifiers();
|
||||||
|
MethodInfo *info = new MethodInfo(w, w, nsWindow::BTNCLICK, 5, args);
|
||||||
|
t->CallMethodAsync(info);
|
||||||
|
NS_RELEASE(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
BButton::MessageReceived(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsButton_h__
|
||||||
|
#define nsButton_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIButton.h"
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 button wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsButton : public nsWindow,
|
||||||
|
public nsIButton
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsButton();
|
||||||
|
virtual ~nsButton();
|
||||||
|
|
||||||
|
//nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsIButton part
|
||||||
|
NS_IMETHOD SetLabel(const nsString& aText);
|
||||||
|
NS_IMETHOD GetLabel(nsString& aBuffer);
|
||||||
|
|
||||||
|
// nsBaseWidget
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsString mLabel;
|
||||||
|
virtual BView *CreateBeOSView();
|
||||||
|
BButton *mButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BButton subclass
|
||||||
|
//
|
||||||
|
class nsButtonBeOS : public BButton, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
const char *aLabel, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
void AttachedToWindow();
|
||||||
|
void MessageReceived(BMessage *msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsButton_h__
|
|
@ -0,0 +1,102 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CLIST_H
|
||||||
|
#define CLIST_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Simple circular linked-list implementation...
|
||||||
|
//
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Foreward declarations...
|
||||||
|
struct CList;
|
||||||
|
|
||||||
|
#define OBJECT_PTR_FROM_CLIST(className, listElement) \
|
||||||
|
((char*)listElement - offsetof(className, m_link))
|
||||||
|
|
||||||
|
|
||||||
|
struct CList {
|
||||||
|
CList *next;
|
||||||
|
CList *prev;
|
||||||
|
|
||||||
|
CList() {
|
||||||
|
next = prev = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
~CList() {
|
||||||
|
Remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Append an element to the end of this list
|
||||||
|
//
|
||||||
|
void Append(CList &element) {
|
||||||
|
element.next = this;
|
||||||
|
element.prev = prev;
|
||||||
|
prev->next = &element;
|
||||||
|
prev = &element;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add an element to the beginning of this list
|
||||||
|
//
|
||||||
|
void Add(CList &element) {
|
||||||
|
element.next = next;
|
||||||
|
element.prev = this;
|
||||||
|
next->prev = &element;
|
||||||
|
next = &element;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Append this element to the end of a list
|
||||||
|
//
|
||||||
|
void AppendToList(CList &list) {
|
||||||
|
list.Append(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Add this element to the beginning of a list
|
||||||
|
//
|
||||||
|
void AddToList(CList &list) {
|
||||||
|
list.Add(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Remove this element from the list and re-initialize
|
||||||
|
//
|
||||||
|
void Remove(void) {
|
||||||
|
prev->next = next;
|
||||||
|
next->prev = prev;
|
||||||
|
|
||||||
|
next = prev = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Is this list empty ?
|
||||||
|
//
|
||||||
|
bool IsEmpty(void) {
|
||||||
|
return (next == this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CLIST_H
|
||||||
|
|
|
@ -0,0 +1,237 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsCheckButton.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsCheckButton)
|
||||||
|
NS_IMPL_RELEASE(nsCheckButton)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsCheckButton constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsCheckButton::nsCheckButton() : nsWindow() , nsICheckButton(),
|
||||||
|
mState(PR_FALSE)
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsCheckButton destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsCheckButton::~nsCheckButton()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implement the standard QueryInterface for NS_IWIDGET_IID and NS_ISUPPORTS_IID
|
||||||
|
* @modify gpk 8/4/98
|
||||||
|
* @param aIID The name of the class implementing the method
|
||||||
|
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||||
|
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nsresult nsCheckButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
||||||
|
if (aIID.Equals(kICheckButtonIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsICheckButton*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return nsWindow::QueryInterface(aIID,aInstancePtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCheckButton::SetState(const PRBool aState)
|
||||||
|
{
|
||||||
|
mState = aState;
|
||||||
|
if(mCheckBox && mCheckBox->LockLooper())
|
||||||
|
{
|
||||||
|
mCheckBox->SetValue(aState ? 1 : 0);
|
||||||
|
mCheckBox->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCheckButton::GetState(PRBool& aState)
|
||||||
|
{
|
||||||
|
aState = mState;
|
||||||
|
if(mCheckBox && mCheckBox->LockLooper())
|
||||||
|
{
|
||||||
|
aState = mCheckBox->Value() ? PR_TRUE : PR_FALSE;
|
||||||
|
mCheckBox->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCheckButton::SetLabel(const nsString& aText)
|
||||||
|
{
|
||||||
|
char label[256];
|
||||||
|
aText.ToCString(label, 256);
|
||||||
|
label[255] = '\0';
|
||||||
|
if(mCheckBox && mCheckBox->LockLooper())
|
||||||
|
{
|
||||||
|
mCheckBox->SetLabel(label);
|
||||||
|
mCheckBox->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsCheckButton::GetLabel(nsString& aBuffer)
|
||||||
|
{
|
||||||
|
if(mCheckBox && mCheckBox->LockLooper())
|
||||||
|
{
|
||||||
|
aBuffer.SetLength(0);
|
||||||
|
aBuffer.Append(mCheckBox->Label());
|
||||||
|
mCheckBox->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsCheckButton::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsCheckButton::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsCheckButton::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the CheckButton for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsCheckButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
nsRect rect;
|
||||||
|
float appUnits;
|
||||||
|
float scale;
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
|
||||||
|
context->GetCanonicalPixelScale(scale);
|
||||||
|
context->GetDevUnitsToAppUnits(appUnits);
|
||||||
|
|
||||||
|
GetBoundsAppUnits(rect, appUnits);
|
||||||
|
|
||||||
|
nscoord one = nscoord(PRFloat64(rect.height) * 1.0/20.0);
|
||||||
|
nscoord three = nscoord(PRFloat64(rect.width) * 3.0/20.0);
|
||||||
|
nscoord five = nscoord(PRFloat64(rect.width) * 5.0/20.0);
|
||||||
|
nscoord six = nscoord(PRFloat64(rect.height) * 5.0/20.0);
|
||||||
|
nscoord eight = nscoord(PRFloat64(rect.height) * 7.0/20.0);
|
||||||
|
nscoord nine = nscoord(PRFloat64(rect.width) * 9.0/20.0);
|
||||||
|
nscoord ten = nscoord(PRFloat64(rect.height) * 9.0/20.0);
|
||||||
|
|
||||||
|
rect.x += three;
|
||||||
|
rect.y += nscoord(PRFloat64(rect.height) * 3.5 /20.0);
|
||||||
|
rect.width = nscoord(PRFloat64(rect.width) * 12.0/20.0);
|
||||||
|
rect.height = nscoord(PRFloat64(rect.height) * 12.0/20.0);
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscoord onePixel = nscoord((appUnits+0.6F));
|
||||||
|
DrawScaledRect(aRenderingContext, rect, scale, appUnits);
|
||||||
|
nscoord x = rect.x;
|
||||||
|
nscoord y = rect.y;
|
||||||
|
|
||||||
|
if (mState) {
|
||||||
|
nscoord inc = nscoord(PRFloat64(rect.height) * 0.75/20.0);
|
||||||
|
nscoord yy = 0;
|
||||||
|
for (nscoord i=0;i<4;i++) {
|
||||||
|
DrawScaledLine(aRenderingContext, x+three, y+eight+yy, x+five, y+ten+yy, scale, appUnits, PR_FALSE); // top
|
||||||
|
DrawScaledLine(aRenderingContext, x+five, y+ten+yy, x+nine, y+six+yy, scale, appUnits, PR_FALSE); // top
|
||||||
|
//aRenderingContext.DrawLine(x+three, y+eight+yy, x+five, y+ten+yy);
|
||||||
|
//aRenderingContext.DrawLine(x+five, y+ten+yy, x+nine, y+six+yy);
|
||||||
|
yy += nscoord(scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_RELEASE(context);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsCheckButton::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mCheckBox = new nsCheckBoxBeOS(this, BRect(0, 0, 0, 0), "", "", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS CheckBox
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsCheckBoxBeOS::nsCheckBoxBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, const char *aLabel, BMessage *aMessage,
|
||||||
|
uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BCheckBox( aFrame, aName, aLabel, aMessage, aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsCheckButton_h__
|
||||||
|
#define nsCheckButton_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsICheckButton.h"
|
||||||
|
|
||||||
|
#include <CheckBox.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 Checkbox wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsCheckButton : public nsWindow,
|
||||||
|
public nsICheckButton
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsCheckButton();
|
||||||
|
virtual ~nsCheckButton();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsICheckButton part
|
||||||
|
NS_IMETHOD SetLabel(const nsString &aText);
|
||||||
|
NS_IMETHOD GetLabel(nsString &aBuffer);
|
||||||
|
NS_IMETHOD SetState(const PRBool aState);
|
||||||
|
NS_IMETHOD GetState(PRBool& aState);
|
||||||
|
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PRBool mState;
|
||||||
|
virtual BView *CreateBeOSView();
|
||||||
|
BCheckBox *mCheckBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BCheckBox subclass
|
||||||
|
//
|
||||||
|
class nsCheckBoxBeOS : public BCheckBox, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsCheckBoxBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
const char *aLabel, BMessage *aMessage, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsCheckButton_h__
|
|
@ -0,0 +1,523 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsClipboard.h"
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
#include "nsIClipboardOwner.h"
|
||||||
|
#include "nsITransferable.h" // kTextMime
|
||||||
|
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
// The class statics:
|
||||||
|
BView *nsClipboard::sView = 0;
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF_INHERITED(nsClipboard, nsBaseClipboard)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(nsClipboard, nsBaseClipboard)
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kCClipboardCID, NS_CLIPBOARD_CID);
|
||||||
|
|
||||||
|
#if defined(DEBUG_akkana) || defined(DEBUG_mcafee)
|
||||||
|
#define DEBUG_CLIPBOARD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsClipboard constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsClipboard::nsClipboard() : nsBaseClipboard()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::nsClipboard()\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
//NS_INIT_REFCNT();
|
||||||
|
mIgnoreEmptyNotification = PR_FALSE;
|
||||||
|
mClipboardOwner = nsnull;
|
||||||
|
mTransferable = nsnull;
|
||||||
|
// mSelectionData.data = nsnull;
|
||||||
|
// mSelectionData.length = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsClipboard destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsClipboard::~nsClipboard()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::~nsClipboard()\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
// // Remove all our event handlers:
|
||||||
|
// if (sView &&
|
||||||
|
// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window)
|
||||||
|
// gtk_selection_remove_all(sWidget);
|
||||||
|
//
|
||||||
|
// // free the selection data, if any
|
||||||
|
// if (mSelectionData.data != nsnull)
|
||||||
|
// g_free(mSelectionData.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param aIID The name of the class implementing the method
|
||||||
|
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||||
|
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nsresult nsClipboard::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult rv = NS_NOINTERFACE;
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIClipboard::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIClipboard*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void nsClipboard::SetTopLevelView(BView *v)
|
||||||
|
{
|
||||||
|
// Don't set up any more event handlers if we're being called twice
|
||||||
|
// for the same toplevel widget
|
||||||
|
if (sView == v)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (sView != 0 && sView->Window() != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(v == 0 || v->Window() == 0)
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::SetTopLevelView: widget passed in is null or has no window!\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::SetTopLevelView\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
// // If we're changing from one widget to another
|
||||||
|
// // (shouldn't generally happen), clear the old event handlers:
|
||||||
|
// if (sView &&
|
||||||
|
// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window)
|
||||||
|
// gtk_selection_remove_all(sWidget);
|
||||||
|
//
|
||||||
|
// sWidget = w;
|
||||||
|
//
|
||||||
|
// // Get the clipboard from the service manager.
|
||||||
|
// nsresult rv;
|
||||||
|
// NS_WITH_SERVICE(nsIClipboard, clipboard, kCClipboardCID, &rv);
|
||||||
|
//
|
||||||
|
// if (!NS_SUCCEEDED(rv)) {
|
||||||
|
// printf("Couldn't get clipboard service!\n");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // Handle selection requests if we called gtk_selection_add_target:
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_get",
|
||||||
|
// GTK_SIGNAL_FUNC(nsClipboard::SelectionGetCB),
|
||||||
|
// clipboard);
|
||||||
|
//
|
||||||
|
// // When someone else takes the selection away:
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_clear_event",
|
||||||
|
// GTK_SIGNAL_FUNC(nsClipboard::SelectionClearCB),
|
||||||
|
// clipboard);
|
||||||
|
//
|
||||||
|
// // Set up the paste handler:
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_received",
|
||||||
|
// GTK_SIGNAL_FUNC(nsClipboard::SelectionReceivedCB),
|
||||||
|
// clipboard);
|
||||||
|
//
|
||||||
|
//#if 0
|
||||||
|
// // Handle selection requests if we called gtk_selection_add_targets:
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_request_event",
|
||||||
|
// GTK_SIGNAL_FUNC(nsClipboard::SelectionRequestCB),
|
||||||
|
// clipboard);
|
||||||
|
//
|
||||||
|
// // Watch this, experimenting with Gtk :-)
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(sWidget), "selection_notify_event",
|
||||||
|
// GTK_SIGNAL_FUNC(nsClipboard::SelectionNotifyCB),
|
||||||
|
// clipboard);
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
// // Hmm, sometimes we need this, sometimes not. I'm not clear why.
|
||||||
|
// // See also long comment above on why we don't register a whole target list.
|
||||||
|
//
|
||||||
|
// // Register all the target types we handle:
|
||||||
|
// gtk_selection_add_target(sWidget,
|
||||||
|
// GDK_SELECTION_PRIMARY,
|
||||||
|
// GDK_SELECTION_TYPE_STRING,
|
||||||
|
// GDK_SELECTION_TYPE_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NS_IMETHODIMP nsClipboard::SetNativeClipboardData()
|
||||||
|
{
|
||||||
|
mIgnoreEmptyNotification = PR_TRUE;
|
||||||
|
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::SetNativeClipboardData()\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
// make sure we have a good transferable
|
||||||
|
if (nsnull == mTransferable) {
|
||||||
|
printf(" SetNativeClipboardData: no transferable!\n");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// // If we're already the selection owner, don't need to do anything,
|
||||||
|
// // we'll already get the events:
|
||||||
|
// if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window)
|
||||||
|
// return NS_OK;
|
||||||
|
//
|
||||||
|
// // Clear the native clipboard
|
||||||
|
// if (sWidget &&
|
||||||
|
// gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window)
|
||||||
|
// gtk_selection_remove_all(sWidget);
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // register as the selection owner:
|
||||||
|
// gint have_selection =
|
||||||
|
// gtk_selection_owner_set(sWidget,
|
||||||
|
// GDK_SELECTION_PRIMARY,
|
||||||
|
// GDK_CURRENT_TIME);
|
||||||
|
// if (have_selection == 0)
|
||||||
|
// return NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
mIgnoreEmptyNotification = PR_FALSE;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// The blocking Paste routine
|
||||||
|
//
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsClipboard::GetNativeClipboardData(nsITransferable * aTransferable)
|
||||||
|
{
|
||||||
|
nsresult rv = NS_OK;
|
||||||
|
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::GetNativeClipboardData()\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
// make sure we have a good transferable
|
||||||
|
if (nsnull == aTransferable) {
|
||||||
|
printf(" GetNativeClipboardData: Transferable is null!\n");
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dunno why we need to do this, copying the win32 code ...
|
||||||
|
nsCOMPtr<nsITransferable> trans = do_QueryInterface(aTransferable);
|
||||||
|
if (!trans)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
// //
|
||||||
|
// // We can't call the copy callback when we're blocking on the paste callback;
|
||||||
|
// // so if this app is already the selection owner, we need to copy our own
|
||||||
|
// // data without going through the X server.
|
||||||
|
// //
|
||||||
|
// if (gdk_selection_owner_get (GDK_SELECTION_PRIMARY) == sWidget->window)
|
||||||
|
// {
|
||||||
|
// // XXX only support text/plain for now
|
||||||
|
// nsAutoString dataFlavor(kTextMime);
|
||||||
|
//
|
||||||
|
// // Get data out of our existing transferable.
|
||||||
|
// void *clipboardData;
|
||||||
|
// PRUint32 dataLength;
|
||||||
|
// rv = mTransferable->GetTransferData(&dataFlavor,
|
||||||
|
// &clipboardData,
|
||||||
|
// &dataLength);
|
||||||
|
// if (NS_SUCCEEDED(rv))
|
||||||
|
// rv = trans->SetTransferData(&dataFlavor,
|
||||||
|
// clipboardData, dataLength);
|
||||||
|
// return rv;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//#define ONLY_SUPPORT_PLAIN_TEXT 1
|
||||||
|
//#ifdef ONLY_SUPPORT_PLAIN_TEXT
|
||||||
|
// gtk_selection_convert(sWidget, GDK_SELECTION_PRIMARY,
|
||||||
|
// GDK_SELECTION_TYPE_STRING, GDK_CURRENT_TIME);
|
||||||
|
// // Tried to use straight Xlib call but this would need more work:
|
||||||
|
// //XConvertSelection(GDK_WINDOW_XDISPLAY(sWidget->window),
|
||||||
|
// // XA_PRIMARY, XA_STRING, gdk_selection_property,
|
||||||
|
// // GDK_WINDOW_XWINDOW(sWidget->window), GDK_CURRENT_TIME);
|
||||||
|
//
|
||||||
|
//#else /* ONLY_SUPPORT_PLAIN_TEXT */
|
||||||
|
// //
|
||||||
|
// // XXX This code isn't implemented for Unix yet!
|
||||||
|
// // Instead of SetTransferData it will have to call gtk_selection_convert.
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// // Get the transferable list of data flavors
|
||||||
|
// nsVoidArray * dfList;
|
||||||
|
// aTransferable->GetTransferDataFlavors(&dfList);
|
||||||
|
//
|
||||||
|
// // Walk through flavors and see which flavor matches the one being pasted:
|
||||||
|
// PRUint32 i;
|
||||||
|
// PRUint32 cnt = 0;
|
||||||
|
// nsresult rv = dfList->Count(&cnt);
|
||||||
|
// NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");
|
||||||
|
// for (i=0;i<cnt;i++) {
|
||||||
|
// nsString * df = (nsString *)dfList->ElementAt(i);
|
||||||
|
// if (nsnull != df) {
|
||||||
|
// UINT format = GetFormat(*df);
|
||||||
|
//
|
||||||
|
// void * data;
|
||||||
|
// PRUint32 dataLen;
|
||||||
|
//
|
||||||
|
// if (nsnull != aDataObject) {
|
||||||
|
// res = GetNativeDataOffClipboard(aDataObject, format, &data, &dataLen);
|
||||||
|
// if (NS_OK == res) {
|
||||||
|
// trans->SetTransferData(df, data, dataLen);
|
||||||
|
// }
|
||||||
|
// } else if (nsnull != aWindow) {
|
||||||
|
// res = GetNativeDataOffClipboard(aWindow, format, &data, &dataLen);
|
||||||
|
// if (NS_OK == res) {
|
||||||
|
// trans->SetTransferData(df, data, dataLen);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//#endif /* ONLY_SUPPORT_PLAIN_TEXT */
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // We've told X what type to send, and we just have to wait
|
||||||
|
// // for the callback saying that the data have been transferred.
|
||||||
|
// //
|
||||||
|
//
|
||||||
|
// // Set a flag saying that we're blocking waiting for the callback:
|
||||||
|
// mBlocking = PR_TRUE;
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf("Waiting for the callback\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//
|
||||||
|
// // Now we need to wait until the callback comes in ...
|
||||||
|
// // i is in case we get a runaway (yuck).
|
||||||
|
// for (int i=0; mBlocking == PR_TRUE && i < 10000; ++i)
|
||||||
|
// {
|
||||||
|
// gtk_main_iteration_do(PR_TRUE);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf("Got the callback: '%s', %d\n",
|
||||||
|
// mSelectionData.data, mSelectionData.length);
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//
|
||||||
|
// // We're back from the callback, no longer blocking:
|
||||||
|
// mBlocking = PR_FALSE;
|
||||||
|
//
|
||||||
|
// //
|
||||||
|
// // Now we have data in mSelectionData.data.
|
||||||
|
// // We just have to copy it to the transferable.
|
||||||
|
// //
|
||||||
|
// nsAutoString dataFlavor(kTextMime);
|
||||||
|
// trans->SetTransferData(&dataFlavor, mSelectionData.data, mSelectionData.length);
|
||||||
|
//
|
||||||
|
// // Can't free the selection data -- the transferable just saves a pointer.
|
||||||
|
// // But the transferable is responsible for freeing it, so we have to
|
||||||
|
// // consider it freed now:
|
||||||
|
// //g_free(mSelectionData.data);
|
||||||
|
// mSelectionData.data = nsnull;
|
||||||
|
// mSelectionData.length = 0;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Called when the data from a paste comes in:
|
||||||
|
//
|
||||||
|
//void
|
||||||
|
//nsClipboard::SelectionReceivedCB (GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData)
|
||||||
|
//{
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf(" nsClipboard::SelectionReceivedCB\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//
|
||||||
|
// // ARGHH! GTK doesn't pass the arg to the callback, so we can't
|
||||||
|
// // get "this" back! Until we solve this, get it from the service mgr:
|
||||||
|
// nsresult rv;
|
||||||
|
// NS_WITH_SERVICE(nsIClipboard, iclipboard, kCClipboardCID, &rv);
|
||||||
|
//
|
||||||
|
// if (NS_FAILED(rv)) {
|
||||||
|
// printf("Couldn't get clipboard service!\n");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// nsClipboard* clipboard = (nsClipboard*)iclipboard;
|
||||||
|
// if (!clipboard) {
|
||||||
|
// printf("couldn't convert nsIClipboard to nsClipboard\n");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// clipboard->SelectionReceiver(aWidget, aSelectionData);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void
|
||||||
|
//nsClipboard::SelectionReceiver (GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData)
|
||||||
|
//{
|
||||||
|
// mBlocking = PR_FALSE;
|
||||||
|
//
|
||||||
|
// if (aSelectionData->length < 0)
|
||||||
|
// {
|
||||||
|
// printf("Error retrieving selection: length was %d\n",
|
||||||
|
// aSelectionData->length);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// switch (aSelectionData->type)
|
||||||
|
// {
|
||||||
|
// case GDK_SELECTION_TYPE_STRING:
|
||||||
|
// mSelectionData = *aSelectionData;
|
||||||
|
// mSelectionData.data = g_new(guchar, aSelectionData->length + 1);
|
||||||
|
// memcpy(mSelectionData.data,
|
||||||
|
// aSelectionData->data, aSelectionData->length);
|
||||||
|
// // Null terminate in case anyone cares,
|
||||||
|
// // and so we can print the string for debugging:
|
||||||
|
// mSelectionData.data[aSelectionData->length] = '\0';
|
||||||
|
// mSelectionData.length = aSelectionData->length;
|
||||||
|
// return;
|
||||||
|
//
|
||||||
|
// default:
|
||||||
|
// printf("Can't convert type %s (%ld) to string\n",
|
||||||
|
// gdk_atom_name (aSelectionData->type), aSelectionData->type);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
/**
|
||||||
|
* No-op.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NS_IMETHODIMP nsClipboard::ForceDataToClipboard()
|
||||||
|
{
|
||||||
|
#ifdef DEBUG_CLIPBOARD
|
||||||
|
printf(" nsClipboard::ForceDataToClipboard()\n");
|
||||||
|
#endif /* DEBUG_CLIPBOARD */
|
||||||
|
|
||||||
|
// make sure we have a good transferable
|
||||||
|
if (nsnull == mTransferable) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//// This is the callback which is called when another app
|
||||||
|
//// requests the selection.
|
||||||
|
////
|
||||||
|
//void nsClipboard::SelectionGetCB(GtkWidget *widget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// guint /*info*/,
|
||||||
|
// guint /*time*/,
|
||||||
|
// gpointer aData)
|
||||||
|
//{
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf(" nsClipboard::SelectionGetCB\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//
|
||||||
|
// nsClipboard *clipboard = (nsClipboard *)aData;
|
||||||
|
//
|
||||||
|
// void *clipboardData;
|
||||||
|
// PRUint32 dataLength;
|
||||||
|
// nsresult rv;
|
||||||
|
//
|
||||||
|
// // Make sure we have a transferable:
|
||||||
|
// if (!clipboard->mTransferable) {
|
||||||
|
// printf("Clipboard has no transferable!\n");
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // XXX hack, string-only for now.
|
||||||
|
// // Create string data-flavor.
|
||||||
|
// nsString dataFlavor (kTextMime);
|
||||||
|
//
|
||||||
|
// // Get data out of transferable.
|
||||||
|
// rv = clipboard->mTransferable->GetTransferData(&dataFlavor,
|
||||||
|
// &clipboardData,
|
||||||
|
// &dataLength);
|
||||||
|
//
|
||||||
|
// // Currently we only offer the data in GDK_SELECTION_TYPE_STRING format.
|
||||||
|
// if (NS_SUCCEEDED(rv) && clipboardData && dataLength > 0) {
|
||||||
|
// gtk_selection_data_set(aSelectionData,
|
||||||
|
// GDK_SELECTION_TYPE_STRING, 8,
|
||||||
|
// (unsigned char *)clipboardData,
|
||||||
|
// dataLength);
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// printf("Transferable didn't support the data flavor\n");
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// Called when another app requests selection ownership:
|
||||||
|
//void nsClipboard::SelectionClearCB(GtkWidget *widget,
|
||||||
|
// GdkEventSelection *event,
|
||||||
|
// gpointer data)
|
||||||
|
//{
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf(" nsClipboard::SelectionClearCB\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//// The routine called when another app asks for the content of the selection
|
||||||
|
//void
|
||||||
|
//nsClipboard::SelectionRequestCB (GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData)
|
||||||
|
//{
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf(" nsClipboard::SelectionRequestCB\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//void
|
||||||
|
//nsClipboard::SelectionNotifyCB (GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData)
|
||||||
|
//{
|
||||||
|
//#ifdef DEBUG_CLIPBOARD
|
||||||
|
// printf(" nsClipboard::SelectionNotifyCB\n");
|
||||||
|
//#endif /* DEBUG_CLIPBOARD */
|
||||||
|
//}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsClipboard_h__
|
||||||
|
#define nsClipboard_h__
|
||||||
|
|
||||||
|
#include "nsBaseClipboard.h"
|
||||||
|
#include <Clipboard.h>
|
||||||
|
|
||||||
|
class nsITransferable;
|
||||||
|
class nsIClipboardOwner;
|
||||||
|
class nsIWidget;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS Clipboard wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsClipboard : public nsBaseClipboard
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsClipboard();
|
||||||
|
virtual ~nsClipboard();
|
||||||
|
|
||||||
|
//nsISupports
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
||||||
|
// nsIClipboard
|
||||||
|
NS_IMETHOD ForceDataToClipboard();
|
||||||
|
|
||||||
|
static void SetTopLevelView(BView *v);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NS_IMETHOD SetNativeClipboardData();
|
||||||
|
NS_IMETHOD GetNativeClipboardData(nsITransferable * aTransferable);
|
||||||
|
|
||||||
|
PRBool mIgnoreEmptyNotification;
|
||||||
|
|
||||||
|
static BView *sView;
|
||||||
|
|
||||||
|
// // Used for communicating pasted data
|
||||||
|
// // from the asynchronous X routines back to a blocking paste:
|
||||||
|
// GtkSelectionData mSelectionData;
|
||||||
|
// PRBool mBlocking;
|
||||||
|
//
|
||||||
|
// void SelectionReceiver(GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData);
|
||||||
|
//
|
||||||
|
// static void SelectionGetCB(GtkWidget *widget,
|
||||||
|
// GtkSelectionData *selection_data,
|
||||||
|
// guint /*info*/,
|
||||||
|
// guint /*time*/,
|
||||||
|
// gpointer data);
|
||||||
|
//
|
||||||
|
// static void SelectionClearCB(GtkWidget *widget,
|
||||||
|
// GdkEventSelection *event,
|
||||||
|
// gpointer data );
|
||||||
|
//
|
||||||
|
// static void SelectionRequestCB(GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData);
|
||||||
|
//
|
||||||
|
// static void SelectionReceivedCB(GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData);
|
||||||
|
//
|
||||||
|
// static void SelectionNotifyCB(GtkWidget *aWidget,
|
||||||
|
// GtkSelectionData *aSelectionData,
|
||||||
|
// gpointer aData);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsClipboard_h__
|
|
@ -0,0 +1,380 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsComboBox.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
NS_IMPL_ADDREF(nsComboBox)
|
||||||
|
NS_IMPL_RELEASE(nsComboBox)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsComboBox constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsComboBox::nsComboBox() : nsWindow(), nsIListWidget(), nsIComboBox()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mBackground = NS_RGB(124, 124, 124);
|
||||||
|
mDropDownHeight = 60; // Default to 60 pixels for drop-down list height
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsComboBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||||
|
mMenuField->Menu()->AddItem(new BMenuItem(val, 0), aPosition);
|
||||||
|
NS_FREE_STR_BUF(val);
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Finds an item at a postion
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsComboBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||||
|
int index = ::SendMessage(mWnd, CB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
|
||||||
|
NS_FREE_STR_BUF(val);
|
||||||
|
|
||||||
|
return index;
|
||||||
|
#endif
|
||||||
|
printf("nsListBox::FindItem not implemented\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CountItems - Get Item Count
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsComboBox::GetItemCount()
|
||||||
|
{
|
||||||
|
PRInt32 result = 0;
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
result = mMenuField->Menu()->CountItems();
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Removes an Item at a specified location
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsComboBox::RemoveItemAt(PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
BMenuItem *it = mMenuField->Menu()->RemoveItem(aPosition);
|
||||||
|
delete it;
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
return it ? PR_TRUE : PR_FALSE;
|
||||||
|
}
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Removes an Item at a specified location
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsComboBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
PRBool result = PR_FALSE;
|
||||||
|
anItem.SetLength(0);
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition);
|
||||||
|
anItem.Append(it->Label());
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
result = PR_TRUE;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Gets the selected of selected item
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsComboBox::GetSelectedItem(nsString& aItem)
|
||||||
|
{
|
||||||
|
GetItemAt(aItem, GetSelectedIndex());
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Gets the list of selected otems
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsComboBox::GetSelectedIndex()
|
||||||
|
{
|
||||||
|
PRInt32 index = -1;
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
BMenuItem *it = mMenuField->Menu()->FindMarked();
|
||||||
|
index = it ? mMenuField->Menu()->IndexOf(it) : -1;
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SelectItem
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsComboBox::SelectItem(PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
BMenuItem *it = mMenuField->Menu()->ItemAt(aPosition);
|
||||||
|
if(it)
|
||||||
|
it->SetMarked(true);
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Deselect
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsComboBox::Deselect()
|
||||||
|
{
|
||||||
|
if(mMenuField && mMenuField->LockLooper())
|
||||||
|
{
|
||||||
|
BMenuItem *it = mMenuField->Menu()->FindMarked();
|
||||||
|
if(it)
|
||||||
|
it->SetMarked(false);
|
||||||
|
mMenuField->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsComboBox::~nsComboBox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsComboBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
static NS_DEFINE_IID(kInsComboBoxIID, NS_ICOMBOBOX_IID);
|
||||||
|
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
|
||||||
|
|
||||||
|
if (aIID.Equals(kInsComboBoxIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIComboBox*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsWindow::QueryInterface(aIID,aInstancePtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsComboBox::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsComboBox::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsComboBox::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Cache the drop down list height in mDropDownHeight
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsComboBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||||
|
{
|
||||||
|
nsComboBoxInitData* comboData = (nsComboBoxInitData*)aInitData;
|
||||||
|
mDropDownHeight = comboData->mDropDownHeight;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Modify the height passed to create and resize to be
|
||||||
|
// the combo box drop down list height. (Note: Windows uses
|
||||||
|
// the height of the window to specify the drop-down list size,
|
||||||
|
// not the height of combobox text area.
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PRInt32 nsComboBox::GetHeight(PRInt32 aProposedHeight)
|
||||||
|
{
|
||||||
|
return(mDropDownHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsComboBox::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
nsWindow::GetNonClientBounds(aRect);
|
||||||
|
#endif
|
||||||
|
printf("nsListBox::GetBounds not wrong\n"); // the following is just a placeholder
|
||||||
|
nsWindow::GetClientBounds(aRect);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the TextWidget for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsComboBox::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||||
|
/*nsRect rect;
|
||||||
|
GetBoundsAppUnits(rect, aTwipsConversion);
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscolor bgColor = NS_RGB(255,255,255);
|
||||||
|
nscolor fgColor = NS_RGB(0,0,0);
|
||||||
|
nscolor hltColor = NS_RGB(240,240,240);
|
||||||
|
nscolor sdwColor = NS_RGB(128,128,128);
|
||||||
|
nsILookAndFeel * lookAndFeel;
|
||||||
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
//nsDrawingSurface surface;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
//context->GetDrawingSurface(aRenderingContext, surface);
|
||||||
|
|
||||||
|
//HDC the_hdc = ((nsDrawingSurfaceWin *)&surface)->mDC;
|
||||||
|
|
||||||
|
//::SendMessage(mWnd, WM_PAINT, (WPARAM)the_hdc, NULL);
|
||||||
|
|
||||||
|
|
||||||
|
// shrink by one pixel
|
||||||
|
|
||||||
|
nscoord onePixel = nscoord((aTwipsConversion+0.6F));
|
||||||
|
nscoord twoPixels = onePixel*2;
|
||||||
|
|
||||||
|
nsString text("(ComboBox)");
|
||||||
|
//GetSelectedItem(text);
|
||||||
|
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(bgColor);
|
||||||
|
aRenderingContext.FillRect(rect);
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
aRenderingContext.DrawRect(rect);
|
||||||
|
|
||||||
|
|
||||||
|
aRenderingContext.SetFont(*mFont);
|
||||||
|
|
||||||
|
nscoord textWidth;
|
||||||
|
nscoord textHeight;
|
||||||
|
aRenderingContext.GetWidth(text, textWidth);
|
||||||
|
|
||||||
|
nsIFontMetrics* metrics;
|
||||||
|
context->GetMetricsFor(*mFont, metrics);
|
||||||
|
metrics->GetMaxAscent(textHeight);
|
||||||
|
|
||||||
|
nscoord x = (twoPixels * 2) + rect.x;
|
||||||
|
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||||
|
//aRenderingContext.DrawString(text, x, y);
|
||||||
|
*/
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BView *nsComboBox::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mMenuField = new nsMenuFieldBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS MenuField
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenuFieldBeOS::nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BMenuField( aFrame, aName, "", new BPopUpMenu(""), aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
SetDivider(0);
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsComboBox_h__
|
||||||
|
#define nsComboBox_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsIComboBox.h"
|
||||||
|
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 Combobox wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsComboBox : public nsWindow,
|
||||||
|
public nsIListWidget,
|
||||||
|
public nsIComboBox
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsComboBox();
|
||||||
|
~nsComboBox();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsIWidget overrides
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
// nsIWidget
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
|
||||||
|
// nsIComboBox interface
|
||||||
|
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||||
|
virtual PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||||
|
virtual PRInt32 GetItemCount();
|
||||||
|
virtual PRBool RemoveItemAt(PRInt32 aPosition);
|
||||||
|
virtual PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||||
|
NS_IMETHOD GetSelectedItem(nsString& aItem);
|
||||||
|
virtual PRInt32 GetSelectedIndex();
|
||||||
|
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||||
|
NS_IMETHOD Deselect() ;
|
||||||
|
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
|
||||||
|
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Modify the height passed to create and resize to be
|
||||||
|
// the combo box drop down list height.
|
||||||
|
PRInt32 GetHeight(PRInt32 aProposedHeight);
|
||||||
|
PRInt32 mDropDownHeight;
|
||||||
|
BView *CreateBeOSView();
|
||||||
|
BMenuField *mMenuField;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BMenuField subclass
|
||||||
|
//
|
||||||
|
class nsMenuFieldBeOS : public BMenuField, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsMenuFieldBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsComboBox_h__
|
|
@ -0,0 +1,165 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsDialog.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsIAppShell.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsIRenderingContext.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsRect.h"
|
||||||
|
#include "nsTransform2D.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
#include "nsGfxCIID.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsDialog)
|
||||||
|
NS_IMPL_RELEASE(nsDialog)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsDialog constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsDialog::nsDialog() : nsWindow(), nsIDialog()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create the proper widget
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsDialog::Create(nsIWidget *aParent,
|
||||||
|
const nsRect &aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
nsIDeviceContext *aContext,
|
||||||
|
nsIAppShell *aAppShell,
|
||||||
|
nsIToolkit *aToolkit,
|
||||||
|
nsWidgetInitData *aInitData)
|
||||||
|
{
|
||||||
|
return nsWindow::Create(aParent,aRect,aHandleEventFunction,aContext,aAppShell,aToolkit,aInitData);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsDialog destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsDialog::~nsDialog()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsDialog::SetLabel(const nsString& aText)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
NS_ALLOC_STR_BUF(label, aText, 256);
|
||||||
|
VERIFY(::SetWindowText(mWnd, label));
|
||||||
|
NS_FREE_STR_BUF(label);
|
||||||
|
#endif
|
||||||
|
printf("nsDialog::SetLabel not implemented\n");
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsDialog::GetLabel(nsString& aBuffer)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
int actualSize = ::GetWindowTextLength(mWnd)+1;
|
||||||
|
NS_ALLOC_CHAR_BUF(label, 256, actualSize);
|
||||||
|
::GetWindowText(mWnd, label, actualSize);
|
||||||
|
aBuffer.SetLength(0);
|
||||||
|
aBuffer.Append(label);
|
||||||
|
NS_FREE_CHAR_BUF(label);
|
||||||
|
#endif
|
||||||
|
printf("nsDialog::SetLabel not implemented\n");
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsDialog::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsDialogIID, NS_IDIALOG_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kInsDialogIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIDialog*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsDialog::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsDialog::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return nsWindow::OnPaint(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsDialog::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return nsWindow::OnResize(aWindowRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsDialog::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
return nsWindow::GetBounds(aRect);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,230 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsDragService.h"
|
||||||
|
#include "nsITransferable.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kIDragServiceIID, NS_IDRAGSERVICE_IID);
|
||||||
|
static NS_DEFINE_CID(kCDragServiceCID, NS_DRAGSERVICE_CID);
|
||||||
|
|
||||||
|
// The class statics:
|
||||||
|
BView *nsDragService::sView = 0;
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF_INHERITED(nsDragService, nsBaseDragService)
|
||||||
|
NS_IMPL_RELEASE_INHERITED(nsDragService, nsBaseDragService)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// static variables
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//static PRBool gHaveDrag = PR_FALSE;
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// DragService constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsDragService::nsDragService()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// DragService destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsDragService::~nsDragService()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param aIID The name of the class implementing the method
|
||||||
|
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||||
|
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nsresult nsDragService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult rv = NS_NOINTERFACE;
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIDragService::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIDragService*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsDragService::StartDragSession (nsITransferable * aTransferable, PRUint32 aActionType)
|
||||||
|
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsDragService::GetData (nsITransferable * aTransferable,
|
||||||
|
PRUint32 aItemIndex)
|
||||||
|
{
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
void nsDragService::SetTopLevelView(BView *v)
|
||||||
|
{
|
||||||
|
printf(" nsDragService::SetTopLevelWidget\n");
|
||||||
|
|
||||||
|
// Don't set up any more event handlers if we're being called twice
|
||||||
|
// for the same toplevel widget
|
||||||
|
if (sView == v)
|
||||||
|
return;
|
||||||
|
|
||||||
|
sView = v;
|
||||||
|
|
||||||
|
// Get the DragService from the service manager.
|
||||||
|
nsresult rv;
|
||||||
|
NS_WITH_SERVICE(nsIDragService, dragService, kCDragServiceCID, &rv);
|
||||||
|
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave",
|
||||||
|
GTK_SIGNAL_FUNC (nsDragService::DragLeave), dragService);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion",
|
||||||
|
GTK_SIGNAL_FUNC (nsDragService::DragMotion), dragService);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop",
|
||||||
|
GTK_SIGNAL_FUNC (nsDragService::DragDrop), dragService);
|
||||||
|
|
||||||
|
gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received",
|
||||||
|
GTK_SIGNAL_FUNC (nsDragService::DragDataReceived), dragService);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//void
|
||||||
|
//nsDragService::DragLeave (GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// guint time)
|
||||||
|
//{
|
||||||
|
// g_print("leave\n");
|
||||||
|
// //gHaveDrag = PR_FALSE;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////-------------------------------------------------------------------------
|
||||||
|
//PRBool
|
||||||
|
//nsDragService::DragMotion(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// guint time)
|
||||||
|
//{
|
||||||
|
// g_print("drag motion\n");
|
||||||
|
// GtkWidget *source_widget;
|
||||||
|
//
|
||||||
|
//#if 0
|
||||||
|
// if (!gHaveDrag) {
|
||||||
|
// gHaveDrag = PR_TRUE;
|
||||||
|
// }
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
// source_widget = gtk_drag_get_source_widget (context);
|
||||||
|
// g_print("motion, source %s\n", source_widget ?
|
||||||
|
// gtk_type_name (GTK_OBJECT (source_widget)->klass->type) :
|
||||||
|
// "unknown");
|
||||||
|
//
|
||||||
|
// gdk_drag_status (context, context->suggested_action, time);
|
||||||
|
//
|
||||||
|
// return PR_TRUE;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////-------------------------------------------------------------------------
|
||||||
|
//PRBool
|
||||||
|
//nsDragService::DragDrop(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// guint time)
|
||||||
|
//{
|
||||||
|
// g_print("drop\n");
|
||||||
|
// //gHaveDrag = PR_FALSE;
|
||||||
|
//
|
||||||
|
// if (context->targets){
|
||||||
|
// gtk_drag_get_data (widget, context,
|
||||||
|
// GPOINTER_TO_INT (context->targets->data),
|
||||||
|
// time);
|
||||||
|
// return PR_TRUE;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return PR_FALSE;
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////-------------------------------------------------------------------------
|
||||||
|
//void
|
||||||
|
//nsDragService::DragDataReceived (GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// GtkSelectionData *data,
|
||||||
|
// guint info,
|
||||||
|
// guint time)
|
||||||
|
//{
|
||||||
|
// if ((data->length >= 0) && (data->format == 8)) {
|
||||||
|
// g_print ("Received \"%s\"\n", (gchar *)data->data);
|
||||||
|
// gtk_drag_finish (context, PR_TRUE, PR_FALSE, time);
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// gtk_drag_finish (context, PR_FALSE, PR_FALSE, time);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////-------------------------------------------------------------------------
|
||||||
|
//void
|
||||||
|
//nsDragService::DragDataGet(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// GtkSelectionData *selection_data,
|
||||||
|
// guint info,
|
||||||
|
// guint time,
|
||||||
|
// gpointer data)
|
||||||
|
//{
|
||||||
|
// gtk_selection_data_set (selection_data,
|
||||||
|
// selection_data->target,
|
||||||
|
// 8, (guchar *)"I'm Data!", 9);
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////-------------------------------------------------------------------------
|
||||||
|
//void
|
||||||
|
//nsDragService::DragDataDelete(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gpointer data)
|
||||||
|
//{
|
||||||
|
// g_print ("Delete the data!\n");
|
||||||
|
//}
|
|
@ -0,0 +1,91 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsDragService_h__
|
||||||
|
#define nsDragService_h__
|
||||||
|
|
||||||
|
#include "nsBaseDragService.h"
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS DragService wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsDragService : public nsBaseDragService
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsDragService();
|
||||||
|
virtual ~nsDragService();
|
||||||
|
|
||||||
|
//nsISupports
|
||||||
|
NS_DECL_ISUPPORTS_INHERITED
|
||||||
|
|
||||||
|
|
||||||
|
//nsIDragService
|
||||||
|
NS_IMETHOD StartDragSession (nsITransferable * aTransferable,
|
||||||
|
PRUint32 aActionType);
|
||||||
|
|
||||||
|
// Native Impl.
|
||||||
|
NS_IMETHOD GetData (nsITransferable * aTransferable, PRUint32 aItemIndex);
|
||||||
|
|
||||||
|
static void SetTopLevelView(BView *v);
|
||||||
|
|
||||||
|
static BView *sView;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static PRBool gHaveDrag;
|
||||||
|
|
||||||
|
// static void DragLeave(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// guint time);
|
||||||
|
//
|
||||||
|
// static PRBool DragMotion(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// guint time);
|
||||||
|
//
|
||||||
|
// static PRBool DragDrop(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// guint time);
|
||||||
|
//
|
||||||
|
// static void DragDataReceived(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gint x,
|
||||||
|
// gint y,
|
||||||
|
// GtkSelectionData *data,
|
||||||
|
// guint info,
|
||||||
|
// guint time);
|
||||||
|
//
|
||||||
|
// static void DragDataGet(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// GtkSelectionData *selection_data,
|
||||||
|
// guint info,
|
||||||
|
// guint time,
|
||||||
|
// gpointer data);
|
||||||
|
//
|
||||||
|
// static void DragDataDelete(GtkWidget *widget,
|
||||||
|
// GdkDragContext *context,
|
||||||
|
// gpointer data);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsDragService_h__
|
|
@ -0,0 +1,251 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*-
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
//#include "stdafx.h"
|
||||||
|
//#include "olebase.h"
|
||||||
|
//#include "idropsrc.h"
|
||||||
|
#include "nsDropTarget.h"
|
||||||
|
//#include "contndoc.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
|
||||||
|
#include "nsWindow.h"
|
||||||
|
//Don't forget to RegisterDragDrop and to
|
||||||
|
//CoLockObjectExternal.
|
||||||
|
//You must RevokeDragDrop before destroying this object
|
||||||
|
//
|
||||||
|
nsDropTarget::nsDropTarget(nsIWidget * aWindow)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::nsDropTarget\n");
|
||||||
|
m_refs = 0;
|
||||||
|
m_pWin = aWindow;
|
||||||
|
NS_ADDREF(aWindow);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Destructor for nsDropTarget
|
||||||
|
//Doesn't do a whole lot!
|
||||||
|
//
|
||||||
|
nsDropTarget::~nsDropTarget()
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::Drop\n");
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
//QueryInterface for IDropTarget
|
||||||
|
//Notice that this QueryInterface does not refer to another object's QueryInterface,
|
||||||
|
//this is a totally stand-alone separate object
|
||||||
|
//
|
||||||
|
STDMETHODIMP nsDropTarget::QueryInterface(REFIID riid, LPVOID FAR* ppv)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::QueryInterface\n");
|
||||||
|
if (riid == IID_IUnknown)
|
||||||
|
*ppv = this;
|
||||||
|
else if (riid == IID_IDropTarget)
|
||||||
|
*ppv = this;
|
||||||
|
else{
|
||||||
|
*ppv = NULL;
|
||||||
|
}
|
||||||
|
if (*ppv != NULL){
|
||||||
|
((LPUNKNOWN)(*ppv))->AddRef();
|
||||||
|
return NOERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//If for some reason our constructor did not create the requested interface
|
||||||
|
//don't pass the NULL interface without telling the caller that we don't support
|
||||||
|
//the requested interface.
|
||||||
|
return ResultFromScode(E_NOINTERFACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//A private AddRef for IDropTarget
|
||||||
|
//
|
||||||
|
STDMETHODIMP_(ULONG) nsDropTarget::AddRef(void)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::AddRef\n");
|
||||||
|
return ++m_refs;
|
||||||
|
}
|
||||||
|
|
||||||
|
//A private Release for IDropTarget
|
||||||
|
//
|
||||||
|
STDMETHODIMP_(ULONG) nsDropTarget::Release(void)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::Release\n");
|
||||||
|
if(--m_refs == 0){
|
||||||
|
//And now we can delete this object
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_refs;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//This helper function tells us what the drag/drop effect would be at
|
||||||
|
//the point pointl. Since our object accepts being a drop target anywhere
|
||||||
|
//in the window, we will ignore pointl
|
||||||
|
//
|
||||||
|
DWORD nsDropTarget::FindDragDropEffect(DWORD grfKeyState, POINTL /* pointl */)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::FindDragDropEffect\n");
|
||||||
|
DWORD dwRet;
|
||||||
|
|
||||||
|
// no modifier -- DROPEFFECT_MOVE or source default
|
||||||
|
// SHIFT -- DROPEFFECT_MOVE
|
||||||
|
// CTRL -- DROPEFFECT_COPY
|
||||||
|
// CTRL-SHIFT -- DROPEFFECT_LINK
|
||||||
|
|
||||||
|
dwRet = 0;//OleStdGetDropEffect(grfKeyState);
|
||||||
|
if (dwRet == 0)
|
||||||
|
dwRet = DROPEFFECT_COPY;
|
||||||
|
|
||||||
|
return dwRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Notification that a DropSource is over the current DropTarget
|
||||||
|
//
|
||||||
|
STDMETHODIMP nsDropTarget::DragEnter (LPDATAOBJECT pDataObj,
|
||||||
|
DWORD grfKeyState,
|
||||||
|
POINTL pointl,
|
||||||
|
LPDWORD pdwEffect)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::DragEnter\n");
|
||||||
|
*pdwEffect = FindDragDropEffect(grfKeyState, pointl);
|
||||||
|
return NOERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Provides user feedback when a DropSource is over a DropTarget
|
||||||
|
//
|
||||||
|
STDMETHODIMP nsDropTarget::DragOver (DWORD grfKeyState,
|
||||||
|
POINTL pointl,
|
||||||
|
LPDWORD pdwEffect)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::DragOver\n");
|
||||||
|
*pdwEffect = FindDragDropEffect(grfKeyState, pointl);
|
||||||
|
return NOERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//The DropSource is leaving our target window
|
||||||
|
//so its cleanup time!!!
|
||||||
|
//
|
||||||
|
STDMETHODIMP nsDropTarget::DragLeave (void)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::DragLeave\n");
|
||||||
|
return NOERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Drops the DropSource
|
||||||
|
//
|
||||||
|
STDMETHODIMP nsDropTarget::Drop (LPDATAOBJECT pIDataObject,
|
||||||
|
DWORD grfKeyState,
|
||||||
|
POINTL pointl,
|
||||||
|
LPDWORD pdwEffect)
|
||||||
|
{
|
||||||
|
printf("nsDropTarget::Drop\n");
|
||||||
|
printf("pIDataObject 0x%x\n", pIDataObject);
|
||||||
|
pIDataObject->AddRef();
|
||||||
|
if (nsnull != m_pWin) {
|
||||||
|
nsEventStatus status;
|
||||||
|
nsDragDropEvent event;
|
||||||
|
((nsWindow *)m_pWin)->InitEvent(event, NS_DRAGDROP_EVENT);
|
||||||
|
event.mType = nsDragDropEventStatus_eDrop;
|
||||||
|
event.mIsFileURL = PR_FALSE;
|
||||||
|
event.mURL = nsnull;
|
||||||
|
m_pWin->DispatchEvent(&event, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
//pdwEffect = FindDragDropEffect(grfKeyState, pointl);
|
||||||
|
|
||||||
|
|
||||||
|
if (pIDataObject != NULL) {
|
||||||
|
IDataObject * presistStorage;
|
||||||
|
//printf("QueryInterface for persist\n");
|
||||||
|
pIDataObject->QueryInterface(IID_IDataObject,(LPVOID *)&presistStorage);
|
||||||
|
//printf("Done QueryInterface for persist\n");
|
||||||
|
if (presistStorage != NULL) {
|
||||||
|
printf("$$$$$$$$$$$$$$$ Got it!\n");
|
||||||
|
FORMATETC pFE;
|
||||||
|
presistStorage->QueryGetData(&pFE);
|
||||||
|
|
||||||
|
pFE.tymed = TYMED_FILE;
|
||||||
|
|
||||||
|
STGMEDIUM pSTM;
|
||||||
|
HRESULT st = presistStorage->GetDataHere(&pFE, &pSTM);
|
||||||
|
printf("st 0x%X\n", st);
|
||||||
|
if (NOERROR != st) {
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
//TYMED_STORAGE, TYMED_STREAM, TYMED_HGLOBAL, or TYMED_FILE
|
||||||
|
//printf("%s\n", pSTM.lpszFileName);
|
||||||
|
{
|
||||||
|
|
||||||
|
//HRESULT hr = pIDataObject->GetData(&pFE, &pSTM);
|
||||||
|
//printf("hr 0x%X\n", hr);
|
||||||
|
//if (NOERROR != hr) {
|
||||||
|
// return FALSE;
|
||||||
|
//}
|
||||||
|
|
||||||
|
const CLIPFORMAT format = pFE.cfFormat;
|
||||||
|
switch(format) {
|
||||||
|
case CF_BITMAP:
|
||||||
|
//hr = SetBitmap(*pFE, stm);
|
||||||
|
break;
|
||||||
|
case CF_DIB:
|
||||||
|
//hr = SetDib(*pFE, stm);
|
||||||
|
break;
|
||||||
|
case CF_TEXT:
|
||||||
|
//hr = SetText(*pFE, stm);
|
||||||
|
break;
|
||||||
|
case CF_METAFILEPICT:
|
||||||
|
//hr = SetMetafilePict(*pFE, stm);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//if (format == GetRcfFormat()) {
|
||||||
|
// hr = SetRcf(*pFE, stm);
|
||||||
|
//}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
//return (SUCCEEDED(hr));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf("^^^^^^^^^^^^^^^^^ Didn't!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* if (m_pContainDoc->m_pOleSiteObject)
|
||||||
|
delete m_pContainDoc->m_pOleSiteObject;
|
||||||
|
m_pContainDoc->m_pOleSiteObject = new COleSiteObject(m_pContainDoc);
|
||||||
|
FORMATETC fmtetc;
|
||||||
|
fmtetc.cfFormat = NULL;
|
||||||
|
fmtetc.ptd = NULL;
|
||||||
|
fmtetc.lindex = -1;
|
||||||
|
fmtetc.dwAspect = DVASPECT_CONTENT;
|
||||||
|
fmtetc.tymed = TYMED_NULL;
|
||||||
|
m_pContainDoc->m_pOleSiteObject->AddSiteFromData(m_pContainDoc,
|
||||||
|
pIDataObject,
|
||||||
|
&fmtetc);
|
||||||
|
*/
|
||||||
|
pIDataObject->Release();
|
||||||
|
|
||||||
|
DragLeave();
|
||||||
|
|
||||||
|
return NOERROR;
|
||||||
|
}
|
|
@ -0,0 +1,277 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Define so header files for openfilename are included
|
||||||
|
#ifdef WIN32_LEAN_AND_MEAN
|
||||||
|
#undef WIN32_LEAN_AND_MEAN
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "nsFileWidget.h"
|
||||||
|
|
||||||
|
//NS_IMPL_ISUPPORTS(nsFileWidget, NS_IFILEWIDGET_IID)
|
||||||
|
NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsFileWidget, kIFileWidgetIID);
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsFileWidget constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsFileWidget::nsFileWidget() : nsIFileWidget()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
// mWnd = NULL;
|
||||||
|
mNumberOfFilters = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Show - Display the file dialog
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PRBool nsFileWidget::Show()
|
||||||
|
{
|
||||||
|
printf("nsFileWidget::Show not implemented\n");
|
||||||
|
#if 0
|
||||||
|
char fileBuffer[MAX_PATH+1] = "";
|
||||||
|
mDefault.ToCString(fileBuffer,MAX_PATH);
|
||||||
|
|
||||||
|
OPENFILENAME ofn;
|
||||||
|
memset(&ofn, 0, sizeof(ofn));
|
||||||
|
|
||||||
|
ofn.lStructSize = sizeof(ofn);
|
||||||
|
|
||||||
|
nsString filterList;
|
||||||
|
GetFilterListArray(filterList);
|
||||||
|
char *filterBuffer = filterList.ToNewCString();
|
||||||
|
char *title = mTitle.ToNewCString();
|
||||||
|
char *initialDir = mDisplayDirectory.ToNewCString();
|
||||||
|
if (mDisplayDirectory.Length() > 0) {
|
||||||
|
ofn.lpstrInitialDir = initialDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
ofn.lpstrTitle = title;
|
||||||
|
ofn.lpstrFilter = filterBuffer;
|
||||||
|
ofn.nFilterIndex = 1;
|
||||||
|
ofn.hwndOwner = mWnd;
|
||||||
|
ofn.lpstrFile = fileBuffer;
|
||||||
|
ofn.nMaxFile = MAX_PATH;
|
||||||
|
ofn.Flags = OFN_SHAREAWARE | OFN_LONGNAMES | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
|
||||||
|
|
||||||
|
PRBool result;
|
||||||
|
|
||||||
|
// Save current directory, so we can reset if it changes.
|
||||||
|
char* currentDirectory = new char[MAX_PATH+1];
|
||||||
|
VERIFY(::GetCurrentDirectory(MAX_PATH, currentDirectory) > 0);
|
||||||
|
|
||||||
|
if (mMode == eMode_load) {
|
||||||
|
result = GetOpenFileName(&ofn);
|
||||||
|
}
|
||||||
|
else if (mMode == eMode_save) {
|
||||||
|
result = GetSaveFileName(&ofn);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NS_ASSERTION(0, "Only load and save are supported modes");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store the current directory in mDisplayDirectory
|
||||||
|
char* newCurrentDirectory = new char[MAX_PATH+1];
|
||||||
|
VERIFY(::GetCurrentDirectory(MAX_PATH, newCurrentDirectory) > 0);
|
||||||
|
mDisplayDirectory.SetLength(0);
|
||||||
|
mDisplayDirectory.Append(newCurrentDirectory);
|
||||||
|
delete newCurrentDirectory;
|
||||||
|
|
||||||
|
|
||||||
|
VERIFY(::SetCurrentDirectory(currentDirectory));
|
||||||
|
delete currentDirectory;
|
||||||
|
|
||||||
|
// Clean up filter buffers
|
||||||
|
delete filterBuffer;
|
||||||
|
delete title;
|
||||||
|
delete initialDir;
|
||||||
|
|
||||||
|
// Set user-selected location of file or directory
|
||||||
|
mFile.SetLength(0);
|
||||||
|
if (result == PR_TRUE) {
|
||||||
|
mFile.Append(fileBuffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return((PRBool)result);
|
||||||
|
#endif
|
||||||
|
return PR_TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Convert filter titles + filters into a Windows filter string
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void nsFileWidget::GetFilterListArray(nsString& aFilterList)
|
||||||
|
{
|
||||||
|
aFilterList.SetLength(0);
|
||||||
|
for (PRUint32 i = 0; i < mNumberOfFilters; i++) {
|
||||||
|
const nsString& title = mTitles[i];
|
||||||
|
const nsString& filter = mFilters[i];
|
||||||
|
|
||||||
|
aFilterList.Append(title);
|
||||||
|
aFilterList.Append('\0');
|
||||||
|
aFilterList.Append(filter);
|
||||||
|
aFilterList.Append('\0');
|
||||||
|
}
|
||||||
|
aFilterList.Append('\0');
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the list of filters
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsFileWidget::SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[])
|
||||||
|
{
|
||||||
|
mNumberOfFilters = aNumberOfFilters;
|
||||||
|
mTitles = aTitles;
|
||||||
|
mFilters = aFilters;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the file + path
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsFileWidget::GetFile(nsFileSpec& aFile)
|
||||||
|
{
|
||||||
|
aFile = mFile;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the file + path
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsFileWidget::SetDefaultString(const nsString& aString)
|
||||||
|
{
|
||||||
|
mDefault = aString;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the display directory
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsFileWidget::SetDisplayDirectory(const nsFileSpec& aDirectory)
|
||||||
|
{
|
||||||
|
mDisplayDirectory = aDirectory;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the display directory
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsFileWidget::GetDisplayDirectory(nsFileSpec& aDirectory)
|
||||||
|
{
|
||||||
|
aDirectory = mDisplayDirectory;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsFileWidget::Create(nsIWidget *aParent,
|
||||||
|
const nsString& aTitle,
|
||||||
|
nsFileDlgMode aMode,
|
||||||
|
nsIDeviceContext *aContext = nsnull,
|
||||||
|
nsIAppShell *aAppShell = nsnull,
|
||||||
|
nsIToolkit *aToolkit = nsnull,
|
||||||
|
void *aInitData = nsnull)
|
||||||
|
{
|
||||||
|
// mWnd = (HWND) ((aParent) ? aParent->GetNativeData(NS_NATIVE_WINDOW) : 0);
|
||||||
|
mTitle.SetLength(0);
|
||||||
|
mTitle.Append(aTitle);
|
||||||
|
mMode = aMode;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsFileWidget destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsFileWidget::~nsFileWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nsFileDlgResults nsFileWidget::GetFile(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec)
|
||||||
|
{
|
||||||
|
Create(aParent, promptString, eMode_load, nsnull, nsnull);
|
||||||
|
if (Show() == PR_TRUE)
|
||||||
|
{
|
||||||
|
GetFile(theFileSpec);
|
||||||
|
return nsFileDlgResults_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsFileDlgResults_Cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsFileDlgResults nsFileWidget::GetFolder(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec)
|
||||||
|
{
|
||||||
|
Create(aParent, promptString, eMode_getfolder, nsnull, nsnull);
|
||||||
|
if (Show() == PR_TRUE)
|
||||||
|
{
|
||||||
|
GetFile(theFileSpec);
|
||||||
|
return nsFileDlgResults_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsFileDlgResults_Cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsFileDlgResults nsFileWidget::PutFile(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec)
|
||||||
|
{
|
||||||
|
Create(aParent, promptString, eMode_save, nsnull, nsnull);
|
||||||
|
if (Show() == PR_TRUE)
|
||||||
|
{
|
||||||
|
GetFile(theFileSpec);
|
||||||
|
return nsFileDlgResults_OK;
|
||||||
|
}
|
||||||
|
return nsFileDlgResults_Cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsFileWidget::GetSelectedType(PRInt16& theType)
|
||||||
|
{
|
||||||
|
theType = mSelectedType;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsFileWidget_h__
|
||||||
|
#define nsFileWidget_h__
|
||||||
|
|
||||||
|
#include "nsObject.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include "nsIFileWidget.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 FileSelector wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsFileWidget : public nsIFileWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsFileWidget();
|
||||||
|
virtual ~nsFileWidget();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
PRBool OnPaint(nsRect &r);
|
||||||
|
|
||||||
|
// nsIWidget interface
|
||||||
|
|
||||||
|
NS_IMETHOD Create(nsIWidget *aParent,
|
||||||
|
const nsString& aTitle,
|
||||||
|
nsFileDlgMode aMode,
|
||||||
|
nsIDeviceContext *aContext = nsnull,
|
||||||
|
nsIAppShell *aAppShell = nsnull,
|
||||||
|
nsIToolkit *aToolkit = nsnull,
|
||||||
|
void *aInitData = nsnull);
|
||||||
|
|
||||||
|
// nsIFileWidget part
|
||||||
|
virtual PRBool Show();
|
||||||
|
NS_IMETHOD GetFile(nsFileSpec& aFile);
|
||||||
|
NS_IMETHOD SetDefaultString(const nsString& aFile);
|
||||||
|
NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters,
|
||||||
|
const nsString aTitles[],
|
||||||
|
const nsString aFilters[]);
|
||||||
|
|
||||||
|
NS_IMETHOD GetDisplayDirectory(nsFileSpec& aDirectory);
|
||||||
|
NS_IMETHOD SetDisplayDirectory(const nsFileSpec& aDirectory);
|
||||||
|
|
||||||
|
virtual nsFileDlgResults GetFile(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec);
|
||||||
|
|
||||||
|
virtual nsFileDlgResults GetFolder(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec);
|
||||||
|
|
||||||
|
virtual nsFileDlgResults PutFile(nsIWidget *aParent,
|
||||||
|
const nsString &promptString,
|
||||||
|
nsFileSpec &theFileSpec);
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHOD GetSelectedType(PRInt16& theType);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// HWND mWnd;
|
||||||
|
nsString mTitle;
|
||||||
|
nsFileDlgMode mMode;
|
||||||
|
nsString mFile;
|
||||||
|
PRUint32 mNumberOfFilters;
|
||||||
|
const nsString* mTitles;
|
||||||
|
const nsString* mFilters;
|
||||||
|
nsString mDefault;
|
||||||
|
nsFileSpec mDisplayDirectory;
|
||||||
|
PRInt16 mSelectedType;
|
||||||
|
|
||||||
|
|
||||||
|
void GetFilterListArray(nsString& aFilterList);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsFileWidget_h__
|
|
@ -0,0 +1,418 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsFontRetrieverService.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
#include "nsFont.h"
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
#include "nsFontSizeIterator.h"
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsFontRetrieverService)
|
||||||
|
NS_IMPL_RELEASE(nsFontRetrieverService)
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
nsFontRetrieverService::nsFontRetrieverService()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
|
mFontList = nsnull;
|
||||||
|
mSizeIter = nsnull;
|
||||||
|
mNameIterInx = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
nsFontRetrieverService::~nsFontRetrieverService()
|
||||||
|
{
|
||||||
|
if (nsnull != mFontList) {
|
||||||
|
for (PRInt32 i=0;i<mFontList->Count();i++) {
|
||||||
|
FontInfo * font = (FontInfo *)mFontList->ElementAt(i);
|
||||||
|
if (font->mSizes) {
|
||||||
|
delete font->mSizes;
|
||||||
|
}
|
||||||
|
delete font;
|
||||||
|
}
|
||||||
|
delete mFontList;
|
||||||
|
}
|
||||||
|
NS_IF_RELEASE(mSizeIter);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param aIID The name of the class implementing the method
|
||||||
|
* @param _classiiddef The name of the #define symbol that defines the IID
|
||||||
|
* for the class (e.g. NS_ISUPPORTS_IID)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
nsresult nsFontRetrieverService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult rv = NS_NOINTERFACE;
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIFontRetrieverService::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIFontRetrieverService*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIFontNameIterator::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIFontNameIterator*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
//-- nsIFontRetrieverService
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::CreateFontNameIterator( nsIFontNameIterator** aIterator )
|
||||||
|
{
|
||||||
|
if (nsnull == aIterator) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nsnull == mFontList) {
|
||||||
|
LoadFontList();
|
||||||
|
}
|
||||||
|
*aIterator = this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::CreateFontSizeIterator( const nsString & aFontName,
|
||||||
|
nsIFontSizeIterator** aIterator )
|
||||||
|
{
|
||||||
|
// save value in case someone externally is using it
|
||||||
|
PRInt32 saveIterInx = mNameIterInx;
|
||||||
|
|
||||||
|
PRBool found = PR_FALSE;
|
||||||
|
Reset();
|
||||||
|
do {
|
||||||
|
nsAutoString name;
|
||||||
|
Get(&name);
|
||||||
|
if (name.Equals(aFontName)) {
|
||||||
|
found = PR_TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (Advance() == NS_OK);
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
if (nsnull == mSizeIter) {
|
||||||
|
mSizeIter = new nsFontSizeIterator();
|
||||||
|
}
|
||||||
|
NS_ASSERTION( nsnull != mSizeIter, "nsFontSizeIterator instance pointer is null");
|
||||||
|
|
||||||
|
*aIterator = (nsIFontSizeIterator *)mSizeIter;
|
||||||
|
NS_ADDREF(mSizeIter);
|
||||||
|
|
||||||
|
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
|
||||||
|
mSizeIter->SetFontInfo(fontInfo);
|
||||||
|
mNameIterInx = saveIterInx;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
mNameIterInx = saveIterInx;
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
//-- nsIFontNameIterator
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::Reset()
|
||||||
|
{
|
||||||
|
mNameIterInx = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName )
|
||||||
|
{
|
||||||
|
if (mNameIterInx < mFontList->Count()) {
|
||||||
|
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
|
||||||
|
*aFontName = fontInfo->mName;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::Advance()
|
||||||
|
{
|
||||||
|
if (mNameIterInx < mFontList->Count()-1) {
|
||||||
|
mNameIterInx++;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
static FontInfo * GetFontInfo(nsVoidArray * aFontList, char * aName)
|
||||||
|
{
|
||||||
|
nsAutoString name(aName);
|
||||||
|
PRInt32 i;
|
||||||
|
PRInt32 cnt = aFontList->Count();
|
||||||
|
for (i=0;i<cnt;i++) {
|
||||||
|
FontInfo * fontInfo = (FontInfo *)aFontList->ElementAt(i);
|
||||||
|
if (fontInfo->mName.Equals(name)) {
|
||||||
|
return fontInfo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FontInfo * fontInfo = new FontInfo();
|
||||||
|
fontInfo->mName = aName;
|
||||||
|
//printf("Adding [%s]\n", aName);fflush(stdout);
|
||||||
|
fontInfo->mIsScalable = PR_FALSE; // X fonts aren't scalable right??
|
||||||
|
fontInfo->mSizes = nsnull;
|
||||||
|
aFontList->AppendElement(fontInfo);
|
||||||
|
return fontInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------
|
||||||
|
static void AddSizeToFontInfo(FontInfo * aFontInfo, PRInt32 aSize)
|
||||||
|
{
|
||||||
|
nsVoidArray * sizes;
|
||||||
|
if (nsnull == aFontInfo->mSizes) {
|
||||||
|
sizes = new nsVoidArray();
|
||||||
|
aFontInfo->mSizes = sizes;
|
||||||
|
} else {
|
||||||
|
sizes = aFontInfo->mSizes;
|
||||||
|
}
|
||||||
|
PRInt32 i;
|
||||||
|
PRInt32 cnt = sizes->Count();
|
||||||
|
for (i=0;i<cnt;i++) {
|
||||||
|
PRInt32 size = (int)sizes->ElementAt(i);
|
||||||
|
if (size == aSize) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sizes->AppendElement((void *)aSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------
|
||||||
|
// XXX - Hack - Parts of this will need to be reworked
|
||||||
|
//
|
||||||
|
// This method does brute force parcing for 4 different formats:
|
||||||
|
//
|
||||||
|
// 1) The format -*-*-*-*-*-* etc.
|
||||||
|
// -misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-8
|
||||||
|
//
|
||||||
|
// 2) Name-size format
|
||||||
|
// lucidasans-10
|
||||||
|
//
|
||||||
|
// 3) Name-style-size
|
||||||
|
// lucidasans-bold-10
|
||||||
|
//
|
||||||
|
// 4) Name only (implicit size)
|
||||||
|
// 6x13
|
||||||
|
//
|
||||||
|
//--------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::LoadFontList()
|
||||||
|
{
|
||||||
|
// char * pattern = "*";
|
||||||
|
// int nnames = 1024;
|
||||||
|
//
|
||||||
|
// int available = nnames+1;
|
||||||
|
// int i;
|
||||||
|
// char **fonts;
|
||||||
|
// XFontStruct *info;
|
||||||
|
//
|
||||||
|
// if (nsnull == mFontList) {
|
||||||
|
// mFontList = new nsVoidArray();
|
||||||
|
// if (nsnull == mFontList) {
|
||||||
|
// return NS_ERROR_FAILURE;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// /* Get list of fonts matching pattern */
|
||||||
|
// for (;;) {
|
||||||
|
// // the following line is VERY slow to return
|
||||||
|
// fonts = XListFontsWithInfo(GDK_DISPLAY(), pattern, nnames,
|
||||||
|
// &available, &info);
|
||||||
|
// if (fonts == NULL || available < nnames)
|
||||||
|
// break;
|
||||||
|
//
|
||||||
|
// XFreeFontInfo(fonts, info, available);
|
||||||
|
// nnames = available * 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (fonts == NULL) {
|
||||||
|
// fprintf(stderr, "pattern \"%s\" unmatched\n", pattern);
|
||||||
|
// return NS_ERROR_FAILURE;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//#if 0 // debug
|
||||||
|
// // print out all the retrieved fonts
|
||||||
|
// printf("-----------------------------\n");
|
||||||
|
// for (i=0; i<available; i++) {
|
||||||
|
// printf("[%s]i\n", fonts[i]);
|
||||||
|
// }
|
||||||
|
// printf("-----------------------------\n");
|
||||||
|
//#endif
|
||||||
|
//
|
||||||
|
// // this code assumes all like fonts are grouped together
|
||||||
|
// // currentName is the current name of the font we are gathering
|
||||||
|
// // sizes for, when the name changes we create a new FontInfo object
|
||||||
|
// // but it also takes into account fonts of similar names when it
|
||||||
|
// // goes to add then and disregards duplicates
|
||||||
|
// char buffer[1024];
|
||||||
|
// char currentName[1024];
|
||||||
|
// FontInfo * font = nsnull;
|
||||||
|
//
|
||||||
|
// currentName[0] = 0;
|
||||||
|
// for (i=0; i<available; i++) {
|
||||||
|
//
|
||||||
|
// // This is kind of lame, but it will have to do for now
|
||||||
|
// strcpy(buffer, fonts[i]);
|
||||||
|
//
|
||||||
|
// // Start by checking to see if the name begins with a dash
|
||||||
|
// char * ptr = buffer;
|
||||||
|
// if (buffer[0] == '-') { //Format #1
|
||||||
|
//
|
||||||
|
// PRInt32 cnt = 0;
|
||||||
|
// // skip first two '-'
|
||||||
|
// do {
|
||||||
|
// if (*ptr == '-') cnt++;
|
||||||
|
// ptr++;
|
||||||
|
// } while (cnt < 2);
|
||||||
|
//
|
||||||
|
// // find the dash at the end of the name
|
||||||
|
// char * end = strchr(ptr, '-');
|
||||||
|
// if (end) {
|
||||||
|
// *end = 0;
|
||||||
|
//
|
||||||
|
// // Check to see if we need to create a new FontInfo obj
|
||||||
|
// // and set the currentName var to this guys font name
|
||||||
|
// if (strcmp(currentName, ptr) || NULL == font) {
|
||||||
|
// font = GetFontInfo(mFontList, ptr);
|
||||||
|
// strcpy(currentName, ptr);
|
||||||
|
// }
|
||||||
|
// if (nsnull == font->mSizes) {
|
||||||
|
// font->mSizes = new nsVoidArray();
|
||||||
|
// }
|
||||||
|
// ptr = end+1; // skip past the dash that was set to zero
|
||||||
|
//
|
||||||
|
// cnt = 0;
|
||||||
|
// // now skip ahead 4 dashes
|
||||||
|
// do {
|
||||||
|
// if (*ptr == '-') cnt++;
|
||||||
|
// ptr++;
|
||||||
|
// } while (cnt < 4);
|
||||||
|
//
|
||||||
|
// // find the dash after the size
|
||||||
|
// end = strchr(ptr, '-');
|
||||||
|
//
|
||||||
|
// if (end) {
|
||||||
|
// *end = 0;
|
||||||
|
// PRInt32 size;
|
||||||
|
// sscanf(ptr, "%d", &size);
|
||||||
|
// AddSizeToFontInfo(font, size);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } else { // formats 2,3,4
|
||||||
|
//
|
||||||
|
// // no leading dash means the start of the
|
||||||
|
// // buffer is the start of the name
|
||||||
|
// // this checks for a dash at the end of the font name
|
||||||
|
// // which means there is a size at the end
|
||||||
|
// char * end = strchr(buffer, '-');
|
||||||
|
// if (end) { // Format 2,3
|
||||||
|
// *end = 0;
|
||||||
|
// // Check to see if we need to create a new FontInfo obj
|
||||||
|
// // and set the currentName var to this guys font name
|
||||||
|
// if (strcmp(currentName, buffer) || NULL == font) {
|
||||||
|
// font = GetFontInfo(mFontList, buffer);
|
||||||
|
// strcpy(currentName, buffer);
|
||||||
|
// }
|
||||||
|
// end++; // advance past the dash
|
||||||
|
// // check to see if we have a number
|
||||||
|
// ptr = end;
|
||||||
|
// if (isalpha(*ptr)) { // Format 3
|
||||||
|
// // skip until next dash
|
||||||
|
// end = strchr(ptr, '-');
|
||||||
|
// if (end) {
|
||||||
|
// *end = 0;
|
||||||
|
// ptr = end+1;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// PRInt32 size;
|
||||||
|
// // yes, it has a dash at the end so it must have the size
|
||||||
|
// // check to see if the size is terminated by a dash
|
||||||
|
// // it shouldn't be
|
||||||
|
// char * end2 = strchr(ptr, '-');
|
||||||
|
// if (end2) *end2 = 0; // put terminator at the dash
|
||||||
|
// sscanf(end, "%d", &size);
|
||||||
|
// AddSizeToFontInfo(font, size);
|
||||||
|
//
|
||||||
|
// } else { // Format #4
|
||||||
|
// // The font has an implicit size,
|
||||||
|
// // so there is nothing to parse for size
|
||||||
|
// // so we can't really do much here
|
||||||
|
// // Check to see if we need to create a new FontInfo obj
|
||||||
|
// // and set the currentName var to this guys font name
|
||||||
|
// if (strcmp(currentName, buffer) || NULL == font) {
|
||||||
|
// font = GetFontInfo(mFontList, buffer);
|
||||||
|
// strcpy(currentName, buffer);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// XFreeFontInfo(fonts, info, available);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontRetrieverService::IsFontScalable(const nsString & aFontName,
|
||||||
|
PRBool* aResult )
|
||||||
|
{
|
||||||
|
// save value in case someone externally is using it
|
||||||
|
PRInt32 saveIterInx = mNameIterInx;
|
||||||
|
|
||||||
|
PRBool found = PR_FALSE;
|
||||||
|
Reset();
|
||||||
|
do {
|
||||||
|
nsAutoString name;
|
||||||
|
Get(&name);
|
||||||
|
if (name.Equals(aFontName)) {
|
||||||
|
found = PR_TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (Advance() == NS_OK);
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
|
||||||
|
*aResult = fontInfo->mIsScalable;
|
||||||
|
mNameIterInx = saveIterInx;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
mNameIterInx = saveIterInx;
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __nsFontRetrieverService
|
||||||
|
#define __nsFontRetrieverService
|
||||||
|
|
||||||
|
#include "nsIFontRetrieverService.h"
|
||||||
|
#include "nsIFontNameIterator.h"
|
||||||
|
|
||||||
|
class nsVoidArray;
|
||||||
|
class nsFontSizeIterator;
|
||||||
|
|
||||||
|
class nsFontRetrieverService: public nsIFontRetrieverService,
|
||||||
|
public nsIFontNameIterator {
|
||||||
|
public:
|
||||||
|
nsFontRetrieverService();
|
||||||
|
virtual ~nsFontRetrieverService();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIFontRetrieverService
|
||||||
|
NS_IMETHOD CreateFontNameIterator( nsIFontNameIterator** aIterator );
|
||||||
|
|
||||||
|
NS_IMETHOD CreateFontSizeIterator( const nsString & aFontName, nsIFontSizeIterator** aIterator );
|
||||||
|
NS_IMETHOD IsFontScalable( const nsString & aFontName, PRBool* aResult );
|
||||||
|
|
||||||
|
// nsIFontNameIterator
|
||||||
|
|
||||||
|
NS_IMETHOD Reset();
|
||||||
|
NS_IMETHOD Get( nsString* aFontName );
|
||||||
|
NS_IMETHOD Advance();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
NS_IMETHOD LoadFontList();
|
||||||
|
|
||||||
|
nsVoidArray * mFontList;
|
||||||
|
|
||||||
|
PRInt32 mNameIterInx;
|
||||||
|
|
||||||
|
nsFontSizeIterator * mSizeIter;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsFontSizeIterator.h"
|
||||||
|
|
||||||
|
#include "nsFont.h"
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsFontSizeIterator)
|
||||||
|
NS_IMPL_RELEASE(nsFontSizeIterator)
|
||||||
|
NS_IMPL_QUERY_INTERFACE(nsFontSizeIterator, nsIFontSizeIterator::GetIID())
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
nsFontSizeIterator::nsFontSizeIterator()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mFontInfo = nsnull;
|
||||||
|
mSizeIterInx = 0;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
nsFontSizeIterator::~nsFontSizeIterator()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
///----------------------------------------------------------
|
||||||
|
//-- nsIFontNameIterator
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontSizeIterator::Reset()
|
||||||
|
{
|
||||||
|
mSizeIterInx = 0;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontSizeIterator::Get( double* aFontSize )
|
||||||
|
{
|
||||||
|
if (nsnull != mFontInfo->mSizes &&
|
||||||
|
mFontInfo->mSizes->Count() > 0 &&
|
||||||
|
mSizeIterInx < mFontInfo->mSizes->Count()) {
|
||||||
|
PRUint32 size = (PRUint32)mFontInfo->mSizes->ElementAt(mSizeIterInx);
|
||||||
|
*aFontSize = (double)size;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontSizeIterator::Advance()
|
||||||
|
{
|
||||||
|
if (nsnull != mFontInfo->mSizes &&
|
||||||
|
mFontInfo->mSizes->Count() > 0 &&
|
||||||
|
mSizeIterInx < mFontInfo->mSizes->Count()-2) {
|
||||||
|
mSizeIterInx++;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------
|
||||||
|
NS_IMETHODIMP nsFontSizeIterator::SetFontInfo( FontInfo * aFontInfo )
|
||||||
|
{
|
||||||
|
mFontInfo = aFontInfo;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __nsFontSizeIterator
|
||||||
|
#define __nsFontSizeIterator
|
||||||
|
|
||||||
|
#include "nsIFontSizeIterator.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
class nsVoidArray;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
nsString mName;
|
||||||
|
PRBool mIsScalable;
|
||||||
|
nsVoidArray * mSizes;
|
||||||
|
} FontInfo;
|
||||||
|
|
||||||
|
|
||||||
|
class nsFontSizeIterator: public nsIFontSizeIterator {
|
||||||
|
public:
|
||||||
|
nsFontSizeIterator();
|
||||||
|
virtual ~nsFontSizeIterator();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIFontSizeIterator
|
||||||
|
NS_IMETHOD Reset();
|
||||||
|
NS_IMETHOD Get( double* aFontSize );
|
||||||
|
NS_IMETHOD Advance();
|
||||||
|
|
||||||
|
// Native impl
|
||||||
|
NS_IMETHOD SetFontInfo( FontInfo * aFontInfo );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
FontInfo * mFontInfo;
|
||||||
|
PRInt32 mSizeIterInx; // current index of iter
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,222 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsLabel.h"
|
||||||
|
#include "nsILabel.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsLabel)
|
||||||
|
NS_IMPL_RELEASE(nsLabel)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsLabel constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsLabel::nsLabel() : nsWindow(), nsILabel()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mAlignment = eAlign_Left;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||||
|
{
|
||||||
|
if (nsnull != aInitData) {
|
||||||
|
nsLabelInitData* data = (nsLabelInitData *) aInitData;
|
||||||
|
mAlignment = data->mAlignment;
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsLabel destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsLabel::~nsLabel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsLabel::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kILabelIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsILabel*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::SetAlignment(nsLabelAlignment aAlignment)
|
||||||
|
{
|
||||||
|
mAlignment = aAlignment;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::SetLabel(const nsString& aText)
|
||||||
|
{
|
||||||
|
char label[256];
|
||||||
|
aText.ToCString(label, 256);
|
||||||
|
label[255] = '\0';
|
||||||
|
if(mStringView && mStringView->LockLooper())
|
||||||
|
{
|
||||||
|
mStringView->SetText(label);
|
||||||
|
mStringView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::GetLabel(nsString& aBuffer)
|
||||||
|
{
|
||||||
|
if(mStringView && mStringView->LockLooper())
|
||||||
|
{
|
||||||
|
aBuffer.SetLength(0);
|
||||||
|
aBuffer.Append(mStringView->Text());
|
||||||
|
mStringView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsLabel::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsLabel::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
//printf("** nsLabel::OnPaint **\n");
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsLabel::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsLabel::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
return nsWindow::GetBounds(aRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight)
|
||||||
|
{
|
||||||
|
if (nsnull == mContext) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
//nsIFontMetrics * fm = GetFont();;
|
||||||
|
// mDeviceContext->GetMetricsFor(mFont, &fm);
|
||||||
|
|
||||||
|
nsIFontMetrics* metrics;
|
||||||
|
mContext->GetMetricsFor(*mFont, metrics);
|
||||||
|
|
||||||
|
nsString text;
|
||||||
|
GetLabel(text);
|
||||||
|
|
||||||
|
nsIRenderingContext *cx;
|
||||||
|
mContext->CreateRenderingContext(this, cx);
|
||||||
|
cx->SetFont(metrics);
|
||||||
|
nscoord string_height, string_width;
|
||||||
|
metrics->GetHeight(string_height);
|
||||||
|
cx->GetWidth(text, string_width);
|
||||||
|
NS_RELEASE(cx);
|
||||||
|
NS_RELEASE(metrics);
|
||||||
|
|
||||||
|
if (mPreferredWidth != 0) {
|
||||||
|
aWidth = mPreferredWidth;
|
||||||
|
} else {
|
||||||
|
aWidth = string_width+8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mPreferredHeight != 0) {
|
||||||
|
aHeight = mPreferredHeight;
|
||||||
|
} else {
|
||||||
|
aHeight = string_height+8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsLabel::SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight)
|
||||||
|
{
|
||||||
|
mPreferredWidth = aWidth;
|
||||||
|
mPreferredHeight = aHeight;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsLabel::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mStringView = new nsStringViewBeOS(this, BRect(0, 0, 0, 0), "", "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS StringView
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsStringViewBeOS::nsStringViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, const char *text, uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BStringView( aFrame, aName, text, aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsLabel_h__
|
||||||
|
#define nsLabel_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsILabel.h"
|
||||||
|
|
||||||
|
#include <StringView.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 Label wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsLabel : public nsWindow,
|
||||||
|
public nsILabel
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsLabel();
|
||||||
|
virtual ~nsLabel();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsILabel part
|
||||||
|
NS_IMETHOD SetLabel(const nsString &aText);
|
||||||
|
NS_IMETHOD GetLabel(nsString &aBuffer);
|
||||||
|
NS_IMETHOD SetAlignment(nsLabelAlignment aAlignment);
|
||||||
|
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||||
|
|
||||||
|
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
|
||||||
|
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsLabelAlignment mAlignment;
|
||||||
|
BStringView *mStringView;
|
||||||
|
BView *CreateBeOSView();
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BStringView subclass
|
||||||
|
//
|
||||||
|
class nsStringViewBeOS : public BStringView, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsStringViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
const char *text, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsLabel_h__
|
|
@ -0,0 +1,389 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsListBox.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsListBox)
|
||||||
|
NS_IMPL_RELEASE(nsListBox)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// initializer
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsListBox::SetMultipleSelection(PRBool aMultipleSelections)
|
||||||
|
{
|
||||||
|
mMultiSelect = aMultipleSelections;
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
mListView->SetListType(aMultipleSelections ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST);
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsListBox::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||||
|
{
|
||||||
|
if (nsnull != aInitData) {
|
||||||
|
nsListBoxInitData* data = (nsListBoxInitData *) aInitData;
|
||||||
|
mMultiSelect = data->mMultiSelect;
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsListBox::AddItemAt(nsString &aItem, PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||||
|
mListView->AddItem(new BStringItem(val), aPosition);
|
||||||
|
NS_FREE_STR_BUF(val);
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Finds an item at a postion
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsListBox::FindItem(nsString &aItem, PRInt32 aStartPos)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
NS_ALLOC_STR_BUF(val, aItem, 256);
|
||||||
|
int index = ::SendMessage(mWnd, LB_FINDSTRINGEXACT, (int)aStartPos, (LPARAM)(LPCTSTR)val);
|
||||||
|
NS_FREE_STR_BUF(val);
|
||||||
|
|
||||||
|
return index;
|
||||||
|
#endif
|
||||||
|
printf("nsListBox::FindItem not implemented\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// CountItems - Get Item Count
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsListBox::GetItemCount()
|
||||||
|
{
|
||||||
|
PRInt32 result = 0;
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
result = mListView->CountItems();
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Removes an Item at a specified location
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsListBox::RemoveItemAt(PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
BListItem *it = mListView->RemoveItem(aPosition);
|
||||||
|
delete it;
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
return it ? PR_TRUE : PR_FALSE;
|
||||||
|
}
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Removes an Item at a specified location
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsListBox::GetItemAt(nsString& anItem, PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
PRBool result = PR_FALSE;
|
||||||
|
anItem.SetLength(0);
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
BListItem *it = mListView->ItemAt(aPosition);
|
||||||
|
BStringItem *str;
|
||||||
|
if((str = dynamic_cast<BStringItem *>(it)) != 0)
|
||||||
|
{
|
||||||
|
anItem.Append(str->Text());
|
||||||
|
result = PR_TRUE;
|
||||||
|
}
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Gets the selected of selected item
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsListBox::GetSelectedItem(nsString& aItem)
|
||||||
|
{
|
||||||
|
if (!mMultiSelect) {
|
||||||
|
GetItemAt(aItem, GetSelectedIndex());
|
||||||
|
} else {
|
||||||
|
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedItem()");
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Gets the list of selected otems
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsListBox::GetSelectedIndex()
|
||||||
|
{
|
||||||
|
if (!mMultiSelect)
|
||||||
|
{
|
||||||
|
PRInt32 index = -1;
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
index = mListView->CurrentSelection();
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
} else {
|
||||||
|
NS_ASSERTION(0, "Multi selection list box does not support GetSelectedIndex()");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SelectItem
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsListBox::SelectItem(PRInt32 aPosition)
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
mListView->Select(aPosition);
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// GetSelectedCount
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRInt32 nsListBox::GetSelectedCount()
|
||||||
|
{
|
||||||
|
if (!mMultiSelect) {
|
||||||
|
PRInt32 inx = GetSelectedIndex();
|
||||||
|
return (inx == -1? 0 : 1);
|
||||||
|
} else {
|
||||||
|
PRInt32 count = 0;
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
while((index = mListView->CurrentSelection(index)) != -1)
|
||||||
|
count++;
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// GetSelectedIndices
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsListBox::GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
int index = 0;
|
||||||
|
for(int i = 0; i < aSize; i++)
|
||||||
|
{
|
||||||
|
if(index != -1)
|
||||||
|
index = mListView->CurrentSelection(index);
|
||||||
|
aIndices[i] = index;
|
||||||
|
}
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// SetSelectedIndices
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsListBox::SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize)
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
mListView->Select(aIndices[0], false);
|
||||||
|
for(int i = 1; i < aSize; i++)
|
||||||
|
mListView->Select(aIndices[i], true);
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Deselect
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsListBox::Deselect()
|
||||||
|
{
|
||||||
|
if(mListView && mListView->LockLooper())
|
||||||
|
{
|
||||||
|
mListView->DeselectAll();
|
||||||
|
mListView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsListBox constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsListBox::nsListBox() : nsWindow(), nsIListWidget(), nsIListBox()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mMultiSelect = PR_FALSE;
|
||||||
|
mBackground = NS_RGB(124, 124, 124);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsListBox:: destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsListBox::~nsListBox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsListBox::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsListBoxIID, NS_ILISTBOX_IID);
|
||||||
|
static NS_DEFINE_IID(kInsListWidgetIID, NS_ILISTWIDGET_IID);
|
||||||
|
if (result == NS_NOINTERFACE) {
|
||||||
|
if (aIID.Equals(kInsListBoxIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIListBox*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
else if (aIID.Equals(kInsListWidgetIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIListWidget*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsListBox::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsListBox::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsListBox::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Clear window before paint
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PRBool nsListBox::AutoErase()
|
||||||
|
{
|
||||||
|
return(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsListBox::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
nsWindow::GetNonClientBounds(aRect);
|
||||||
|
#endif
|
||||||
|
printf("nsListBox::GetBounds not wrong\n"); // the following is just a placeholder
|
||||||
|
nsWindow::GetClientBounds(aRect);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsListBox::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mListView = new nsListViewBeOS((nsIWidget *)this, BRect(0, 0, 0, 0), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS ListView
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsListViewBeOS::nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BListView( aFrame, aName,
|
||||||
|
((nsListBox *)aWidgetWindow)->mMultiSelect ? B_MULTIPLE_SELECTION_LIST : B_SINGLE_SELECTION_LIST,
|
||||||
|
aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,91 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsListBox_h__
|
||||||
|
#define nsListBox_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsIListBox.h"
|
||||||
|
|
||||||
|
#include <ListView.h>
|
||||||
|
#include <ListItem.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 Listbox wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsListBox : public nsWindow,
|
||||||
|
public nsIListWidget,
|
||||||
|
public nsIListBox
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsListBox();
|
||||||
|
virtual ~nsListBox();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
|
||||||
|
|
||||||
|
// nsIListBox interface
|
||||||
|
NS_IMETHOD SetMultipleSelection(PRBool aMultipleSelections);
|
||||||
|
NS_IMETHOD AddItemAt(nsString &aItem, PRInt32 aPosition);
|
||||||
|
PRInt32 FindItem(nsString &aItem, PRInt32 aStartPos);
|
||||||
|
PRInt32 GetItemCount();
|
||||||
|
PRBool RemoveItemAt(PRInt32 aPosition);
|
||||||
|
PRBool GetItemAt(nsString& anItem, PRInt32 aPosition);
|
||||||
|
NS_IMETHOD GetSelectedItem(nsString& aItem);
|
||||||
|
PRInt32 GetSelectedIndex();
|
||||||
|
PRInt32 GetSelectedCount();
|
||||||
|
NS_IMETHOD GetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||||
|
NS_IMETHOD SetSelectedIndices(PRInt32 aIndices[], PRInt32 aSize);
|
||||||
|
NS_IMETHOD SelectItem(PRInt32 aPosition);
|
||||||
|
NS_IMETHOD Deselect() ;
|
||||||
|
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||||
|
|
||||||
|
// nsWindow interface
|
||||||
|
virtual PRBool AutoErase();
|
||||||
|
protected:
|
||||||
|
PRBool mMultiSelect;
|
||||||
|
virtual BView *CreateBeOSView();
|
||||||
|
BListView *mListView;
|
||||||
|
|
||||||
|
friend class nsListViewBeOS;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BListView subclass
|
||||||
|
//
|
||||||
|
class nsListViewBeOS : public BListView, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsListViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *name, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsListBox_h__
|
|
@ -0,0 +1,184 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsLookAndFeel.h"
|
||||||
|
#include "nsFont.h"
|
||||||
|
|
||||||
|
//static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
//NS_IMPL_ISUPPORTS(nsLookAndFeel, NS_ILOOKANDFEEL_IID)
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsLookAndFeel, kILookAndFeelIID);
|
||||||
|
|
||||||
|
nsLookAndFeel::nsLookAndFeel() : nsILookAndFeel()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
nsLookAndFeel::~nsLookAndFeel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsLookAndFeel::GetColor(const nsColorID aID, nscolor &aColor)
|
||||||
|
{
|
||||||
|
nsresult res = NS_OK;
|
||||||
|
int idx;
|
||||||
|
switch (aID) {
|
||||||
|
case eColor_WindowBackground:
|
||||||
|
aColor = NS_RGB(0xff,0xff,0xff);
|
||||||
|
break;
|
||||||
|
case eColor_WindowForeground:
|
||||||
|
aColor = NS_RGB(0x00,0x00,0x00);
|
||||||
|
break;
|
||||||
|
case eColor_WidgetBackground:
|
||||||
|
aColor = NS_RGB(192, 192, 192);
|
||||||
|
break;
|
||||||
|
case eColor_WidgetForeground:
|
||||||
|
aColor = NS_RGB(0x00,0x00,0x00);
|
||||||
|
break;
|
||||||
|
case eColor_WidgetSelectBackground:
|
||||||
|
aColor = NS_RGB(0x80,0x80,0x80);
|
||||||
|
break;
|
||||||
|
case eColor_WidgetSelectForeground:
|
||||||
|
aColor = NS_RGB(0x00,0x00,0x80);
|
||||||
|
break;
|
||||||
|
case eColor_Widget3DHighlight:
|
||||||
|
aColor = NS_RGB(0xa0,0xa0,0xa0);
|
||||||
|
break;
|
||||||
|
case eColor_Widget3DShadow:
|
||||||
|
aColor = NS_RGB(0x40,0x40,0x40);
|
||||||
|
break;
|
||||||
|
case eColor_TextBackground:
|
||||||
|
aColor = NS_RGB(0xff,0xff,0xff);
|
||||||
|
break;
|
||||||
|
case eColor_TextForeground:
|
||||||
|
aColor = NS_RGB(0x00,0x00,0x00);
|
||||||
|
break;
|
||||||
|
case eColor_TextSelectBackground:
|
||||||
|
aColor = NS_RGB(0x00,0x00,0x80);
|
||||||
|
break;
|
||||||
|
case eColor_TextSelectForeground:
|
||||||
|
aColor = NS_RGB(0xff,0xff,0xff);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
aColor = NS_RGB(0xff,0xff,0xff);
|
||||||
|
res = NS_ERROR_FAILURE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
|
||||||
|
{
|
||||||
|
nsresult res = NS_OK;
|
||||||
|
switch (aID) {
|
||||||
|
case eMetric_WindowTitleHeight:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_WindowBorderWidth:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_WindowBorderHeight:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_Widget3DBorder:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_TextFieldHeight:
|
||||||
|
aMetric = 24;
|
||||||
|
break;
|
||||||
|
case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
|
||||||
|
aMetric = 10;
|
||||||
|
break;
|
||||||
|
case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
|
||||||
|
aMetric = 8;
|
||||||
|
break;
|
||||||
|
case eMetric_CheckboxSize:
|
||||||
|
aMetric = 12;
|
||||||
|
break;
|
||||||
|
case eMetric_RadioboxSize:
|
||||||
|
aMetric = 12;
|
||||||
|
break;
|
||||||
|
case eMetric_TextHorizontalInsideMinimumPadding:
|
||||||
|
aMetric = 3;
|
||||||
|
break;
|
||||||
|
case eMetric_TextVerticalInsidePadding:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_TextShouldUseVerticalInsidePadding:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
|
||||||
|
aMetric = 1;
|
||||||
|
break;
|
||||||
|
case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_ListHorizontalInsideMinimumPadding:
|
||||||
|
aMetric = 3;
|
||||||
|
break;
|
||||||
|
case eMetric_ListShouldUseVerticalInsidePadding:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
case eMetric_ListVerticalInsidePadding:
|
||||||
|
aMetric = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
aMetric = -1;
|
||||||
|
res = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricFloatID aID, float & aMetric)
|
||||||
|
{
|
||||||
|
nsresult res = NS_OK;
|
||||||
|
switch (aID) {
|
||||||
|
case eMetricFloat_TextFieldVerticalInsidePadding:
|
||||||
|
aMetric = 0.25f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_TextFieldHorizontalInsidePadding:
|
||||||
|
aMetric = 0.95f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_TextAreaVerticalInsidePadding:
|
||||||
|
aMetric = 0.40f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_TextAreaHorizontalInsidePadding:
|
||||||
|
aMetric = 0.40f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_ListVerticalInsidePadding:
|
||||||
|
aMetric = 0.10f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_ListHorizontalInsidePadding:
|
||||||
|
aMetric = 0.40f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_ButtonVerticalInsidePadding:
|
||||||
|
aMetric = 0.25f;
|
||||||
|
break;
|
||||||
|
case eMetricFloat_ButtonHorizontalInsidePadding:
|
||||||
|
aMetric = 0.25f;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
aMetric = -1.0;
|
||||||
|
res = NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __nsLookAndFeel
|
||||||
|
#define __nsLookAndFeel
|
||||||
|
#include "nsObject.h"
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
|
||||||
|
class nsLookAndFeel: public nsILookAndFeel {
|
||||||
|
public:
|
||||||
|
nsLookAndFeel();
|
||||||
|
virtual ~nsLookAndFeel();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD GetColor(const nsColorID aID, nscolor &aColor);
|
||||||
|
NS_IMETHOD GetMetric(const nsMetricID aID, PRInt32 & aMetric);
|
||||||
|
NS_IMETHOD GetMetric(const nsMetricFloatID aID, float & aMetric);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,620 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsMenu.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
#include "nsIDOMElement.h"
|
||||||
|
#include "nsIDOMNode.h"
|
||||||
|
#include "nsIMenuBar.h"
|
||||||
|
#include "nsIMenuItem.h"
|
||||||
|
#include "nsIMenuListener.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kMenuCID, NS_MENU_CID);
|
||||||
|
static NS_DEFINE_CID(kMenuItemCID, NS_MENUITEM_CID);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
|
||||||
|
nsresult nsMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aInstancePtr = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIMenu::GetIID())) {
|
||||||
|
*aInstancePtr = (void*)(nsIMenu*) this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsISupports*)(nsIMenu*)this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(nsIMenuListener::GetIID())) {
|
||||||
|
*aInstancePtr = (void*)(nsIMenuListener*)this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsMenu)
|
||||||
|
NS_IMPL_RELEASE(nsMenu)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenu constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenu::nsMenu() : nsIMenu()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mMenu = nsnull;
|
||||||
|
mMenuBarParent = nsnull;
|
||||||
|
mMenuParent = nsnull;
|
||||||
|
mListener = nsnull;
|
||||||
|
NS_NewISupportsArray(&mItems);
|
||||||
|
|
||||||
|
mDOMNode = nsnull;
|
||||||
|
mWebShell = nsnull;
|
||||||
|
mDOMElement = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenu destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenu::~nsMenu()
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mMenuBarParent);
|
||||||
|
NS_IF_RELEASE(mMenuParent);
|
||||||
|
NS_IF_RELEASE(mListener);
|
||||||
|
|
||||||
|
// Remove all references to the items
|
||||||
|
mItems->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create the proper widget
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::Create(nsISupports *aParent, const nsString &aLabel)
|
||||||
|
{
|
||||||
|
if(aParent)
|
||||||
|
{
|
||||||
|
nsIMenuBar * menubar = nsnull;
|
||||||
|
aParent->QueryInterface(nsIMenuBar::GetIID(), (void**) &menubar);
|
||||||
|
if(menubar)
|
||||||
|
{
|
||||||
|
mMenuBarParent = menubar;
|
||||||
|
NS_RELEASE(menubar);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nsIMenu * menu = nsnull;
|
||||||
|
aParent->QueryInterface(nsIMenu::GetIID(), (void**) &menu);
|
||||||
|
if(menu)
|
||||||
|
{
|
||||||
|
mMenuParent = menu;
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mLabel = aLabel;
|
||||||
|
char *str = mLabel.ToNewCString();
|
||||||
|
mMenu = new BMenu(str);
|
||||||
|
delete [] str;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetParent(nsISupports*& aParent)
|
||||||
|
{
|
||||||
|
|
||||||
|
aParent = nsnull;
|
||||||
|
if (nsnull != mMenuParent) {
|
||||||
|
return mMenuParent->QueryInterface(kISupportsIID,(void**)&aParent);
|
||||||
|
} else if (nsnull != mMenuBarParent) {
|
||||||
|
return mMenuBarParent->QueryInterface(kISupportsIID,(void**)&aParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetLabel(nsString &aText)
|
||||||
|
{
|
||||||
|
aText = mLabel;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::SetLabel(const nsString &aText)
|
||||||
|
{
|
||||||
|
mLabel = aText;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::AddItem(nsISupports * aItem)
|
||||||
|
{
|
||||||
|
if(aItem)
|
||||||
|
{
|
||||||
|
nsIMenuItem * menuitem = nsnull;
|
||||||
|
aItem->QueryInterface(nsIMenuItem::GetIID(),
|
||||||
|
(void**)&menuitem);
|
||||||
|
if(menuitem)
|
||||||
|
{
|
||||||
|
AddMenuItem(menuitem); // nsMenu now owns this
|
||||||
|
NS_RELEASE(menuitem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nsIMenu * menu = nsnull;
|
||||||
|
aItem->QueryInterface(nsIMenu::GetIID(),
|
||||||
|
(void**)&menu);
|
||||||
|
if(menu)
|
||||||
|
{
|
||||||
|
AddMenu(menu); // nsMenu now owns this
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::AddSeparator()
|
||||||
|
{
|
||||||
|
// Create nsMenuItem
|
||||||
|
nsIMenuItem * pnsMenuItem = nsnull;
|
||||||
|
nsresult rv = nsComponentManager::CreateInstance(
|
||||||
|
kMenuItemCID, nsnull, nsIMenuItem::GetIID(), (void**)&pnsMenuItem);
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
nsString tmp = "separator";
|
||||||
|
nsISupports * supports = nsnull;
|
||||||
|
QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
pnsMenuItem->Create(supports, tmp, PR_TRUE);
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
|
||||||
|
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
AddItem(supports); // Parent should now own menu item
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
|
||||||
|
NS_RELEASE(pnsMenuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// This does not return a ref counted object
|
||||||
|
// This is NOT an nsIMenu method
|
||||||
|
nsIMenuBar * nsMenu::GetMenuBar(nsIMenu * aMenu)
|
||||||
|
{
|
||||||
|
if (!aMenu) {
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsMenu * menu = (nsMenu *)aMenu;
|
||||||
|
|
||||||
|
if (menu->GetMenuBarParent()) {
|
||||||
|
return menu->GetMenuBarParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (menu->GetMenuParent()) {
|
||||||
|
return GetMenuBar(menu->GetMenuParent());
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// This does not return a ref counted object
|
||||||
|
// This is NOT an nsIMenu method
|
||||||
|
nsIWidget * nsMenu::GetParentWidget()
|
||||||
|
{
|
||||||
|
nsIWidget * parent = nsnull;
|
||||||
|
nsIMenuBar * menuBar = GetMenuBar(this);
|
||||||
|
if (menuBar) {
|
||||||
|
menuBar->GetParent(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::AddMenuItem(nsIMenuItem * aMenuItem)
|
||||||
|
{
|
||||||
|
PRUint32 cnt;
|
||||||
|
nsresult rv = mItems->Count(&cnt);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
return InsertItemAt(cnt, (nsISupports *)aMenuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::AddMenu(nsIMenu * aMenu)
|
||||||
|
{
|
||||||
|
PRUint32 cnt;
|
||||||
|
nsresult rv = mItems->Count(&cnt);
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
return InsertItemAt(cnt, (nsISupports *)aMenu);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetItemCount(PRUint32 &aCount)
|
||||||
|
{
|
||||||
|
return mItems->Count(&aCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetItemAt(const PRUint32 aCount, nsISupports *& aMenuItem)
|
||||||
|
{
|
||||||
|
aMenuItem = (nsISupports *)mItems->ElementAt(aCount);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::InsertItemAt(const PRUint32 aCount, nsISupports * aMenuItem)
|
||||||
|
{
|
||||||
|
bool status = false;
|
||||||
|
|
||||||
|
mItems->InsertElementAt(aMenuItem, (PRInt32)aCount);
|
||||||
|
|
||||||
|
nsCOMPtr<nsIMenuItem> menuItem(do_QueryInterface(aMenuItem));
|
||||||
|
if (menuItem) {
|
||||||
|
BMenuItem *it;
|
||||||
|
void *data;
|
||||||
|
menuItem->GetNativeData(data);
|
||||||
|
it = (BMenuItem *)data;
|
||||||
|
mMenu->AddItem(it, aCount);
|
||||||
|
status = true;
|
||||||
|
} else {
|
||||||
|
nsCOMPtr<nsIMenu> menu(do_QueryInterface(aMenuItem));
|
||||||
|
if (menu) {
|
||||||
|
BMenu *m;
|
||||||
|
void *data;
|
||||||
|
menu->GetNativeData(&data);
|
||||||
|
m = (BMenu *)data;
|
||||||
|
mMenu->AddItem(m, aCount);
|
||||||
|
status = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (status ? NS_OK : NS_ERROR_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::RemoveItem(const PRUint32 aCount)
|
||||||
|
{
|
||||||
|
printf("nsMenu::RemoveItem - FIXME: not implemented\n");
|
||||||
|
#if 0
|
||||||
|
//nsISupports * supports = (nsISupports *)mItems->ElementAt(aCount);
|
||||||
|
mItems->RemoveElementAt(aCount);
|
||||||
|
|
||||||
|
return (::RemoveMenu(mMenu, aCount, MF_BYPOSITION) ? NS_OK:NS_ERROR_FAILURE);
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::RemoveAll()
|
||||||
|
{
|
||||||
|
printf("nsMenu::RemoveAll - FIXME: not implemented\n");
|
||||||
|
#if 0
|
||||||
|
while (mItems->Count()) {
|
||||||
|
mItems->RemoveElementAt(0);
|
||||||
|
::RemoveMenu(mMenu, 0, MF_BYPOSITION);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::GetNativeData(void ** aData)
|
||||||
|
{
|
||||||
|
*aData = (void *)mMenu;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::AddMenuListener(nsIMenuListener * aMenuListener)
|
||||||
|
{
|
||||||
|
mListener = aMenuListener;
|
||||||
|
NS_ADDREF(mListener);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenu::RemoveMenuListener(nsIMenuListener * aMenuListener)
|
||||||
|
{
|
||||||
|
if (aMenuListener == mListener) {
|
||||||
|
NS_IF_RELEASE(mListener);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// nsIMenuListener interface
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenu::MenuItemSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
if (nsnull != mListener) {
|
||||||
|
mListener->MenuSelected(aMenuEvent);
|
||||||
|
}
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus nsMenu::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
if (nsnull != mListener) {
|
||||||
|
mListener->MenuSelected(aMenuEvent);
|
||||||
|
}
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenu::MenuDeselected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
if (nsnull != mListener) {
|
||||||
|
mListener->MenuDeselected(aMenuEvent);
|
||||||
|
}
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenu::MenuConstruct(const nsMenuEvent & aMenuEvent,
|
||||||
|
nsIWidget * aParentWindow,
|
||||||
|
void * menuNode,
|
||||||
|
void * aWebShell)
|
||||||
|
{
|
||||||
|
//g_print("nsMenu::MenuConstruct called \n");
|
||||||
|
if(menuNode){
|
||||||
|
SetDOMNode((nsIDOMNode*)menuNode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!aWebShell){
|
||||||
|
aWebShell = mWebShell;
|
||||||
|
}
|
||||||
|
|
||||||
|
// First open the menu.
|
||||||
|
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mDOMNode);
|
||||||
|
if (domElement)
|
||||||
|
domElement->SetAttribute("open", "true");
|
||||||
|
|
||||||
|
// Begin menuitem inner loop
|
||||||
|
nsCOMPtr<nsIDOMNode> menuitemNode;
|
||||||
|
((nsIDOMNode*)mDOMNode)->GetFirstChild(getter_AddRefs(menuitemNode));
|
||||||
|
|
||||||
|
unsigned short menuIndex = 0;
|
||||||
|
|
||||||
|
while (menuitemNode) {
|
||||||
|
nsCOMPtr<nsIDOMElement> menuitemElement(do_QueryInterface(menuitemNode));
|
||||||
|
if (menuitemElement) {
|
||||||
|
nsString menuitemNodeType;
|
||||||
|
nsString menuitemName;
|
||||||
|
menuitemElement->GetNodeName(menuitemNodeType);
|
||||||
|
if (menuitemNodeType.Equals("menuitem")) {
|
||||||
|
// LoadMenuItem
|
||||||
|
LoadMenuItem(this,
|
||||||
|
menuitemElement,
|
||||||
|
menuitemNode,
|
||||||
|
menuIndex,
|
||||||
|
(nsIWebShell*)aWebShell);
|
||||||
|
} else if (menuitemNodeType.Equals("separator")) {
|
||||||
|
AddSeparator();
|
||||||
|
} else if (menuitemNodeType.Equals("menu")) {
|
||||||
|
// Load a submenu
|
||||||
|
LoadSubMenu(this, menuitemElement, menuitemNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
++menuIndex;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMNode> oldmenuitemNode(menuitemNode);
|
||||||
|
oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode));
|
||||||
|
} // end menu item innner loop
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenu::MenuDestruct(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
// Close the node.
|
||||||
|
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(mDOMNode);
|
||||||
|
if (domElement)
|
||||||
|
domElement->RemoveAttribute("open");
|
||||||
|
|
||||||
|
//g_print("nsMenu::MenuDestruct called \n");
|
||||||
|
RemoveAll();
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Set DOMNode
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NS_METHOD nsMenu::SetDOMNode(nsIDOMNode * aMenuNode)
|
||||||
|
{
|
||||||
|
mDOMNode = aMenuNode;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Set DOMElement
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NS_METHOD nsMenu::SetDOMElement(nsIDOMElement * aMenuElement)
|
||||||
|
{
|
||||||
|
mDOMElement = aMenuElement;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Set WebShell
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
NS_METHOD nsMenu::SetWebShell(nsIWebShell * aWebShell)
|
||||||
|
{
|
||||||
|
mWebShell = aWebShell;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
void nsMenu::LoadMenuItem(nsIMenu * pParentMenu,
|
||||||
|
nsIDOMElement * menuitemElement,
|
||||||
|
nsIDOMNode * menuitemNode,
|
||||||
|
unsigned short menuitemIndex,
|
||||||
|
nsIWebShell * aWebShell)
|
||||||
|
{
|
||||||
|
static const char* NS_STRING_TRUE = "true";
|
||||||
|
nsString disabled;
|
||||||
|
nsString menuitemName;
|
||||||
|
nsString menuitemCmd;
|
||||||
|
|
||||||
|
menuitemElement->GetAttribute(nsAutoString("disabled"), disabled);
|
||||||
|
menuitemElement->GetAttribute(nsAutoString("name"), menuitemName);
|
||||||
|
menuitemElement->GetAttribute(nsAutoString("cmd"), menuitemCmd);
|
||||||
|
|
||||||
|
// Create nsMenuItem
|
||||||
|
nsIMenuItem * pnsMenuItem = nsnull;
|
||||||
|
nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID,
|
||||||
|
nsnull,
|
||||||
|
nsIMenuItem::GetIID(),
|
||||||
|
(void**)&pnsMenuItem);
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
pnsMenuItem->Create(pParentMenu, menuitemName, PR_FALSE);
|
||||||
|
|
||||||
|
nsISupports * supports = nsnull;
|
||||||
|
pnsMenuItem->QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
pParentMenu->AddItem(supports); // Parent should now own menu item
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
|
||||||
|
if(disabled == NS_STRING_TRUE ) {
|
||||||
|
pnsMenuItem->SetEnabled(PR_FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create MenuDelegate - this is the intermediator inbetween
|
||||||
|
// the DOM node and the nsIMenuItem
|
||||||
|
// The nsWebShellWindow wacthes for Document changes and then notifies the
|
||||||
|
// the appropriate nsMenuDelegate object
|
||||||
|
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(menuitemNode));
|
||||||
|
if (!domElement) {
|
||||||
|
//return NS_ERROR_FAILURE;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAutoString cmdAtom("onclick");
|
||||||
|
nsString cmdName;
|
||||||
|
|
||||||
|
domElement->GetAttribute(cmdAtom, cmdName);
|
||||||
|
|
||||||
|
pnsMenuItem->SetCommand(cmdName);
|
||||||
|
// DO NOT use passed in webshell because of messed up windows dynamic loading
|
||||||
|
// code.
|
||||||
|
pnsMenuItem->SetWebShell(mWebShell);
|
||||||
|
pnsMenuItem->SetDOMElement(domElement);
|
||||||
|
|
||||||
|
NS_RELEASE(pnsMenuItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
void nsMenu::LoadSubMenu(nsIMenu * pParentMenu,
|
||||||
|
nsIDOMElement * menuElement,
|
||||||
|
nsIDOMNode * menuNode)
|
||||||
|
{
|
||||||
|
nsString menuName;
|
||||||
|
menuElement->GetAttribute(nsAutoString("name"), menuName);
|
||||||
|
//printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks
|
||||||
|
|
||||||
|
// Create nsMenu
|
||||||
|
nsIMenu * pnsMenu = nsnull;
|
||||||
|
nsresult rv = nsComponentManager::CreateInstance(kMenuCID,
|
||||||
|
nsnull,
|
||||||
|
nsIMenu::GetIID(),
|
||||||
|
(void**)&pnsMenu);
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
// Call Create
|
||||||
|
nsISupports * supports = nsnull;
|
||||||
|
pParentMenu->QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
pnsMenu->Create(supports, menuName);
|
||||||
|
NS_RELEASE(supports); // Balance QI
|
||||||
|
|
||||||
|
// Set nsMenu Name
|
||||||
|
pnsMenu->SetLabel(menuName);
|
||||||
|
|
||||||
|
supports = nsnull;
|
||||||
|
pnsMenu->QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
pParentMenu->AddItem(supports); // parent takes ownership
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
|
||||||
|
pnsMenu->SetWebShell(mWebShell);
|
||||||
|
pnsMenu->SetDOMNode(menuNode);
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Begin menuitem inner loop
|
||||||
|
unsigned short menuIndex = 0;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDOMNode> menuitemNode;
|
||||||
|
menuNode->GetFirstChild(getter_AddRefs(menuitemNode));
|
||||||
|
while (menuitemNode) {
|
||||||
|
nsCOMPtr<nsIDOMElement> menuitemElement(do_QueryInterface(menuitemNode));
|
||||||
|
if (menuitemElement) {
|
||||||
|
nsString menuitemNodeType;
|
||||||
|
menuitemElement->GetNodeName(menuitemNodeType);
|
||||||
|
|
||||||
|
#ifdef DEBUG_saari
|
||||||
|
printf("Type [%s] %d\n", menuitemNodeType.ToNewCString(), menuitemNodeType.Equals("separator"));
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (menuitemNodeType.Equals("menuitem")) {
|
||||||
|
// Load a menuitem
|
||||||
|
LoadMenuItem(pnsMenu, menuitemElement, menuitemNode, menuIndex, mWebShell);
|
||||||
|
} else if (menuitemNodeType.Equals("separator")) {
|
||||||
|
pnsMenu->AddSeparator();
|
||||||
|
} else if (menuitemNodeType.Equals("menu")) {
|
||||||
|
// Add a submenu
|
||||||
|
LoadSubMenu(pnsMenu, menuitemElement, menuitemNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++menuIndex;
|
||||||
|
nsCOMPtr<nsIDOMNode> oldmenuitemNode(menuitemNode);
|
||||||
|
oldmenuitemNode->GetNextSibling(getter_AddRefs(menuitemNode));
|
||||||
|
} // end menu item innner loop
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,115 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsMenu_h__
|
||||||
|
#define nsMenu_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIMenu.h"
|
||||||
|
#include "nsISupportsArray.h"
|
||||||
|
|
||||||
|
#include <Menu.h>
|
||||||
|
class nsIMenuListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS Menu wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsMenu : public nsIMenu, public nsIMenuListener
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsMenu();
|
||||||
|
virtual ~nsMenu();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
//nsIMenuListener interface
|
||||||
|
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuConstruct(
|
||||||
|
const nsMenuEvent & aMenuEvent,
|
||||||
|
nsIWidget * aParentWindow,
|
||||||
|
void * menuNode,
|
||||||
|
void * aWebShell);
|
||||||
|
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||||
|
|
||||||
|
NS_IMETHOD Create(nsISupports * aParent, const nsString &aLabel);
|
||||||
|
|
||||||
|
// nsIMenu Methods
|
||||||
|
NS_IMETHOD GetParent(nsISupports *&aParent);
|
||||||
|
NS_IMETHOD GetLabel(nsString &aText);
|
||||||
|
NS_IMETHOD SetLabel(const nsString &aText);
|
||||||
|
NS_IMETHOD AddItem(nsISupports * aItem);
|
||||||
|
NS_IMETHOD AddMenuItem(nsIMenuItem * aMenuItem);
|
||||||
|
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||||
|
NS_IMETHOD AddSeparator();
|
||||||
|
NS_IMETHOD GetItemCount(PRUint32 &aCount);
|
||||||
|
NS_IMETHOD GetItemAt(const PRUint32 aPos, nsISupports *& aMenuItem);
|
||||||
|
NS_IMETHOD InsertItemAt(const PRUint32 aPos, nsISupports * aMenuItem);
|
||||||
|
NS_IMETHOD RemoveItem(const PRUint32 aPos);
|
||||||
|
NS_IMETHOD RemoveAll();
|
||||||
|
NS_IMETHOD GetNativeData(void** aData);
|
||||||
|
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
|
||||||
|
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
|
||||||
|
|
||||||
|
NS_IMETHOD SetDOMNode(nsIDOMNode * aMenuNode);
|
||||||
|
NS_IMETHOD SetDOMElement(nsIDOMElement * aMenuElement);
|
||||||
|
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);
|
||||||
|
|
||||||
|
// Native Impl Methods
|
||||||
|
// These are not ref counted
|
||||||
|
nsIMenu * GetMenuParent() { return mMenuParent; }
|
||||||
|
nsIMenuBar * GetMenuBarParent() { return mMenuBarParent; }
|
||||||
|
BMenu * GetNativeMenu() { return mMenu; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void LoadMenuItem(
|
||||||
|
nsIMenu * pParentMenu,
|
||||||
|
nsIDOMElement * menuitemElement,
|
||||||
|
nsIDOMNode * menuitemNode,
|
||||||
|
unsigned short menuitemIndex,
|
||||||
|
nsIWebShell * aWebShell);
|
||||||
|
|
||||||
|
void LoadSubMenu(
|
||||||
|
nsIMenu * pParentMenu,
|
||||||
|
nsIDOMElement * menuElement,
|
||||||
|
nsIDOMNode * menuNode);
|
||||||
|
|
||||||
|
nsIMenuBar * GetMenuBar(nsIMenu * aMenu);
|
||||||
|
nsIWidget * GetParentWidget();
|
||||||
|
|
||||||
|
nsString mLabel;
|
||||||
|
BMenu *mMenu;
|
||||||
|
|
||||||
|
nsIMenuBar * mMenuBarParent;
|
||||||
|
nsIMenu * mMenuParent;
|
||||||
|
|
||||||
|
nsISupportsArray * mItems;
|
||||||
|
nsIMenuListener * mListener;
|
||||||
|
|
||||||
|
nsIDOMNode * mDOMNode;
|
||||||
|
nsIWebShell * mWebShell;
|
||||||
|
nsIDOMElement * mDOMElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsMenu_h__
|
|
@ -0,0 +1,319 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsMenuBar.h"
|
||||||
|
#include "nsMenuItem.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
#include "nsIDOMNode.h"
|
||||||
|
#include "nsIMenu.h"
|
||||||
|
#include "nsIWebShell.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
|
||||||
|
#include <MenuItem.h>
|
||||||
|
|
||||||
|
static NS_DEFINE_CID(kMenuBarCID, NS_MENUBAR_CID);
|
||||||
|
static NS_DEFINE_CID(kMenuCID, NS_MENU_CID);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
|
||||||
|
nsresult nsMenuBar::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aInstancePtr = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIMenuBar::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIMenuBar*) this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsISupports*)(nsIMenuBar*) this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aIID.Equals(nsIMenuListener::GetIID())) {
|
||||||
|
*aInstancePtr = (void*) ((nsIMenuListener*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsMenuBar)
|
||||||
|
NS_IMPL_RELEASE(nsMenuBar)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenuBar constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenuBar::nsMenuBar() : nsIMenuBar(), nsIMenuListener()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mMenu = nsnull;
|
||||||
|
mParent = nsnull;
|
||||||
|
mItems = new nsVoidArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenuBar destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenuBar::~nsMenuBar()
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mParent);
|
||||||
|
|
||||||
|
// Remove all references to the menus
|
||||||
|
mItems->Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create the proper widget
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::Create(nsIWidget *aParent)
|
||||||
|
{
|
||||||
|
SetParent(aParent);
|
||||||
|
mMenu = new BMenuBar(BRect(0, 0, 0, 0), B_EMPTY_STRING);
|
||||||
|
// mParent->SetMenuBar(this);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::GetParent(nsIWidget *&aParent)
|
||||||
|
{
|
||||||
|
aParent = mParent;
|
||||||
|
NS_ADDREF(mParent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::SetParent(nsIWidget *aParent)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mParent);
|
||||||
|
mParent = aParent;
|
||||||
|
NS_IF_ADDREF(mParent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::AddMenu(nsIMenu * aMenu)
|
||||||
|
{
|
||||||
|
InsertMenuAt(mItems->Count(), aMenu);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::GetMenuCount(PRUint32 &aCount)
|
||||||
|
{
|
||||||
|
aCount = mItems->Count();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::GetMenuAt(const PRUint32 aPos, nsIMenu *& aMenu)
|
||||||
|
{
|
||||||
|
aMenu = (nsIMenu *)mItems->ElementAt(aPos);
|
||||||
|
NS_ADDREF(aMenu);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::InsertMenuAt(const PRUint32 aPos, nsIMenu *& aMenu)
|
||||||
|
{
|
||||||
|
nsString name;
|
||||||
|
aMenu->GetLabel(name);
|
||||||
|
char * nameStr = name.ToNewCString();
|
||||||
|
|
||||||
|
mItems->InsertElementAt(aMenu, (PRInt32)aPos);
|
||||||
|
NS_ADDREF(aMenu);
|
||||||
|
|
||||||
|
BMenu *nativeMenu;
|
||||||
|
void *data;
|
||||||
|
aMenu->GetNativeData(&data);
|
||||||
|
nativeMenu = (BMenu *)data;
|
||||||
|
mMenu->AddItem(nativeMenu, aPos);
|
||||||
|
delete[] nameStr;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::RemoveMenu(const PRUint32 aPos)
|
||||||
|
{
|
||||||
|
nsIMenu * menu = (nsIMenu *)mItems->ElementAt(aPos);
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
mItems->RemoveElementAt(aPos);
|
||||||
|
delete mMenu->RemoveItem(aPos);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::RemoveAll()
|
||||||
|
{
|
||||||
|
printf("nsMenuBar::RemoveAll - FIXME: not implemented\n");
|
||||||
|
#if 0
|
||||||
|
while (mItems->Count()) {
|
||||||
|
nsISupports * supports = (nsISupports *)mItems->ElementAt(0);
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
mItems->RemoveElementAt(0);
|
||||||
|
|
||||||
|
::RemoveMenu(mMenu, 0, MF_BYPOSITION);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::GetNativeData(void *& aData)
|
||||||
|
{
|
||||||
|
aData = (void *)mMenu;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::SetNativeData(void * aData)
|
||||||
|
{
|
||||||
|
// Temporary hack for MacOS. Will go away when nsMenuBar handles it's own
|
||||||
|
// construction
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuBar::Paint()
|
||||||
|
{
|
||||||
|
mParent->Invalidate(PR_TRUE);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenuListener interface
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuBar::MenuItemSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus nsMenuBar::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus nsMenuBar::MenuDeselected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus nsMenuBar::MenuConstruct(
|
||||||
|
const nsMenuEvent & aMenuEvent,
|
||||||
|
nsIWidget * aParentWindow,
|
||||||
|
void * menubarNode,
|
||||||
|
void * aWebShell)
|
||||||
|
{
|
||||||
|
mWebShell = (nsIWebShell*) aWebShell;
|
||||||
|
mDOMNode = (nsIDOMNode*)menubarNode;
|
||||||
|
|
||||||
|
nsIMenuBar * pnsMenuBar = nsnull;
|
||||||
|
nsresult rv = nsComponentManager::CreateInstance(kMenuBarCID,
|
||||||
|
nsnull,
|
||||||
|
nsIMenuBar::GetIID(),
|
||||||
|
(void**)&pnsMenuBar);
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
if (nsnull != pnsMenuBar) {
|
||||||
|
pnsMenuBar->Create(aParentWindow);
|
||||||
|
|
||||||
|
// set pnsMenuBar as a nsMenuListener on aParentWindow
|
||||||
|
nsCOMPtr<nsIMenuListener> menuListener;
|
||||||
|
pnsMenuBar->QueryInterface(nsIMenuListener::GetIID(), 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, nsIMenu::GetIID(), (void**)&pnsMenu);
|
||||||
|
if (NS_OK == rv) {
|
||||||
|
// Call Create
|
||||||
|
nsISupports * supports = nsnull;
|
||||||
|
pnsMenuBar->QueryInterface(kISupportsIID, (void**) &supports);
|
||||||
|
pnsMenu->Create(supports, menuName);
|
||||||
|
NS_RELEASE(supports);
|
||||||
|
|
||||||
|
pnsMenu->SetLabel(menuName);
|
||||||
|
pnsMenu->SetDOMNode(menuNode);
|
||||||
|
pnsMenu->SetDOMElement(menuElement);
|
||||||
|
pnsMenu->SetWebShell(mWebShell);
|
||||||
|
|
||||||
|
// Make nsMenu a child of nsMenuBar
|
||||||
|
// nsMenuBar takes ownership of the nsMenu
|
||||||
|
pnsMenuBar->AddMenu(pnsMenu);
|
||||||
|
|
||||||
|
// Release the menu now that the menubar owns it
|
||||||
|
NS_RELEASE(pnsMenu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
nsCOMPtr<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;
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus nsMenuBar::MenuDestruct(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsMenuBar_h__
|
||||||
|
#define nsMenuBar_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIMenuBar.h"
|
||||||
|
#include "nsIMenuListener.h"
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
|
||||||
|
|
||||||
|
class nsIDOMNode;
|
||||||
|
class nsIWebShell;
|
||||||
|
class nsIWidget;
|
||||||
|
|
||||||
|
#include <MenuBar.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 button wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsMenuBar : public nsIMenuBar, public nsIMenuListener
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsMenuBar();
|
||||||
|
virtual ~nsMenuBar();
|
||||||
|
|
||||||
|
// nsIMenuListener interface
|
||||||
|
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuConstruct(
|
||||||
|
const nsMenuEvent & aMenuEvent,
|
||||||
|
nsIWidget * aParentWindow,
|
||||||
|
void * menuNode,
|
||||||
|
void * aWebShell);
|
||||||
|
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHOD Create(nsIWidget * aParent);
|
||||||
|
|
||||||
|
// nsIMenuBar Methods
|
||||||
|
NS_IMETHOD GetParent(nsIWidget *&aParent);
|
||||||
|
NS_IMETHOD SetParent(nsIWidget * aParent);
|
||||||
|
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||||
|
NS_IMETHOD GetMenuCount(PRUint32 &aCount);
|
||||||
|
NS_IMETHOD GetMenuAt(const PRUint32 aPos, nsIMenu *& aMenu);
|
||||||
|
NS_IMETHOD InsertMenuAt(const PRUint32 aPos, nsIMenu *& aMenu);
|
||||||
|
NS_IMETHOD RemoveMenu(const PRUint32 aPos);
|
||||||
|
NS_IMETHOD RemoveAll();
|
||||||
|
NS_IMETHOD GetNativeData(void*& aData);
|
||||||
|
NS_IMETHOD Paint();
|
||||||
|
NS_IMETHOD SetNativeData(void* aData);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PRUint32 mNumMenus;
|
||||||
|
BMenuBar *mMenu;
|
||||||
|
nsIWidget * mParent;
|
||||||
|
|
||||||
|
nsIWebShell * mWebShell;
|
||||||
|
nsIDOMNode * mDOMNode;
|
||||||
|
|
||||||
|
nsVoidArray * mItems;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsMenuBar_h__
|
|
@ -0,0 +1,439 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsMenuItem.h"
|
||||||
|
#include "nsIMenu.h"
|
||||||
|
#include "nsIMenuBar.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
|
||||||
|
#include "nsIPopUpMenu.h"
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
#include "nsIContent.h"
|
||||||
|
#include "nsIContentViewerContainer.h"
|
||||||
|
#include "nsIContentViewer.h"
|
||||||
|
#include "nsIDOMElement.h"
|
||||||
|
#include "nsIDocumentViewer.h"
|
||||||
|
#include "nsIPresContext.h"
|
||||||
|
#include "nsIWebShell.h"
|
||||||
|
#include "nsICharsetConverterManager.h"
|
||||||
|
#include "nsIPlatformCharset.h"
|
||||||
|
#include "nsIServiceManager.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kIMenuIID, NS_IMENU_IID);
|
||||||
|
static NS_DEFINE_IID(kIMenuBarIID, NS_IMENUBAR_IID);
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIPopUpMenuIID, NS_IPOPUPMENU_IID);
|
||||||
|
static NS_DEFINE_IID(kIMenuItemIID, NS_IMENUITEM_IID);
|
||||||
|
//NS_IMPL_ISUPPORTS(nsMenuItem, kIMenuItemIID)
|
||||||
|
|
||||||
|
nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
if (NULL == aInstancePtr) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aInstancePtr = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(kIMenuItemIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsIMenuItem*)this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kIMenuListenerIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsIMenuListener*)this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this;
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsMenuItem)
|
||||||
|
NS_IMPL_RELEASE(nsMenuItem)
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenuItem constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenuItem::nsMenuItem() : nsIMenuItem()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mMenuItem = nsnull;
|
||||||
|
mMenuParent = nsnull;
|
||||||
|
mPopUpParent = nsnull;
|
||||||
|
mTarget = nsnull;
|
||||||
|
mListener = nsnull;
|
||||||
|
mIsSeparator = PR_FALSE;
|
||||||
|
mWebShell = nsnull;
|
||||||
|
mDOMElement = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsMenuItem destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsMenuItem::~nsMenuItem()
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mMenuParent);
|
||||||
|
NS_IF_RELEASE(mPopUpParent);
|
||||||
|
NS_IF_RELEASE(mTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsIWidget * nsMenuItem::GetMenuBarParent(nsISupports * aParent)
|
||||||
|
{
|
||||||
|
nsIWidget * widget = nsnull; // MenuBar's Parent
|
||||||
|
nsIMenu * menu = nsnull;
|
||||||
|
nsIMenuBar * menuBar = nsnull;
|
||||||
|
nsIPopUpMenu * popup = nsnull;
|
||||||
|
nsISupports * parent = aParent;
|
||||||
|
|
||||||
|
// Bump the ref count on the parent, since it gets released unconditionally..
|
||||||
|
NS_ADDREF(parent);
|
||||||
|
while (1) {
|
||||||
|
if (NS_OK == parent->QueryInterface(kIMenuIID,(void**)&menu)) {
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
if (NS_OK != menu->GetParent(parent)) {
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
|
||||||
|
} else if (NS_OK == parent->QueryInterface(kIPopUpMenuIID,(void**)&popup)) {
|
||||||
|
if (NS_OK != popup->GetParent(widget)) {
|
||||||
|
widget = nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
NS_RELEASE(popup);
|
||||||
|
return widget;
|
||||||
|
|
||||||
|
} else if (NS_OK == parent->QueryInterface(kIMenuBarIID,(void**)&menuBar)) {
|
||||||
|
if (NS_OK != menuBar->GetParent(widget)) {
|
||||||
|
widget = nsnull;
|
||||||
|
}
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
NS_RELEASE(menuBar);
|
||||||
|
return widget;
|
||||||
|
} else {
|
||||||
|
NS_RELEASE(parent);
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::Create(nsISupports *aParent,
|
||||||
|
const nsString &aLabel,
|
||||||
|
PRBool aIsSeparator)
|
||||||
|
{
|
||||||
|
if (nsnull == aParent) {
|
||||||
|
return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(aParent) {
|
||||||
|
nsIMenu * menu;
|
||||||
|
aParent->QueryInterface(nsIMenu::GetIID(), (void**) &menu);
|
||||||
|
mMenuParent = menu;
|
||||||
|
NS_RELEASE(menu);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsIWidget *widget = nsnull; // MenuBar's Parent
|
||||||
|
nsISupports *sups;
|
||||||
|
if (NS_OK == aParent->QueryInterface(kISupportsIID,(void**)&sups)) {
|
||||||
|
widget = GetMenuBarParent(sups);
|
||||||
|
// GetMenuBarParent will call release for us
|
||||||
|
// NS_RELEASE(sups);
|
||||||
|
mTarget = widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
mIsSeparator = aIsSeparator;
|
||||||
|
mLabel = aLabel;
|
||||||
|
|
||||||
|
// create the native menu item
|
||||||
|
|
||||||
|
if(mIsSeparator) {
|
||||||
|
mMenuItem = new BSeparatorItem();
|
||||||
|
} else {
|
||||||
|
char * nameStr = mLabel.ToNewCString();
|
||||||
|
BMessage *msg = new BMessage('menu');
|
||||||
|
msg->AddPointer("nsMenuItem", this);
|
||||||
|
mMenuItem = new BMenuItem(nameStr, msg);
|
||||||
|
delete[] nameStr;
|
||||||
|
// mMenuItem = CreateLocalized(aLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// gtk_widget_show(mMenuItem);
|
||||||
|
//
|
||||||
|
// gtk_signal_connect(GTK_OBJECT(mMenuItem), "activate",
|
||||||
|
// GTK_SIGNAL_FUNC(menu_item_activate_handler),
|
||||||
|
// this);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
BMenu *nsMenuItem::GetNativeParent()
|
||||||
|
{
|
||||||
|
void * voidData;
|
||||||
|
if (nsnull != mMenuParent) {
|
||||||
|
mMenuParent->GetNativeData(&voidData);
|
||||||
|
} else if (nsnull != mPopUpParent) {
|
||||||
|
mPopUpParent->GetNativeData(voidData);
|
||||||
|
} else {
|
||||||
|
return nsnull;
|
||||||
|
}
|
||||||
|
return (BMenu *)voidData;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetLabel(nsString &aText)
|
||||||
|
{
|
||||||
|
aText = mLabel;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::SetLabel(nsString &aText)
|
||||||
|
{
|
||||||
|
mLabel = aText;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetCommand(PRUint32 & aCommand)
|
||||||
|
{
|
||||||
|
aCommand = mCommand;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetTarget(nsIWidget *& aTarget)
|
||||||
|
{
|
||||||
|
aTarget = mTarget;
|
||||||
|
NS_ADDREF(mTarget);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetNativeData(void *& aData)
|
||||||
|
{
|
||||||
|
aData = (void *)mMenuItem;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::AddMenuListener(nsIMenuListener * aMenuListener)
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mListener);
|
||||||
|
mListener = aMenuListener;
|
||||||
|
NS_ADDREF(mListener);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::RemoveMenuListener(nsIMenuListener * aMenuListener)
|
||||||
|
{
|
||||||
|
if (mListener == aMenuListener) {
|
||||||
|
NS_IF_RELEASE(mListener);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::IsSeparator(PRBool & aIsSep)
|
||||||
|
{
|
||||||
|
aIsSep = mIsSeparator;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::SetEnabled(PRBool aIsEnabled)
|
||||||
|
{
|
||||||
|
mMenuItem->SetEnabled(aIsEnabled ? true : false);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetEnabled(PRBool *aIsEnabled)
|
||||||
|
{
|
||||||
|
*aIsEnabled = mMenuItem->IsEnabled();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::SetChecked(PRBool aIsEnabled)
|
||||||
|
{
|
||||||
|
mMenuItem->SetMarked(aIsEnabled ? true : false);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetChecked(PRBool *aIsEnabled)
|
||||||
|
{
|
||||||
|
*aIsEnabled = mMenuItem->IsMarked();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// nsIMenuListener interface
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuItem::MenuItemSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
if(!mIsSeparator) {
|
||||||
|
//g_print("nsMenuItem::MenuItemSelected\n");
|
||||||
|
DoCommand();
|
||||||
|
}else{
|
||||||
|
//g_print("nsMenuItem::MenuItemSelected is separator\n");
|
||||||
|
}
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuItem::MenuSelected(const nsMenuEvent & aMenuEvent)
|
||||||
|
{
|
||||||
|
if(mListener)
|
||||||
|
return mListener->MenuSelected(aMenuEvent);
|
||||||
|
|
||||||
|
//g_print("nsMenuItem::MenuSelected\n");
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuItem::MenuDeselected(const nsMenuEvent &aMenuEvent)
|
||||||
|
{
|
||||||
|
//g_print("nsMenuItem::MenuDeselected\n");
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuItem::MenuConstruct(const nsMenuEvent &aMenuEvent,
|
||||||
|
nsIWidget *aParentWindow,
|
||||||
|
void *menuNode,
|
||||||
|
void *aWebShell)
|
||||||
|
{
|
||||||
|
//g_print("nsMenuItem::MenuConstruct\n");
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsEventStatus nsMenuItem::MenuDestruct(const nsMenuEvent &aMenuEvent)
|
||||||
|
{
|
||||||
|
//g_print("nsMenuItem::MenuDestruct\n");
|
||||||
|
return nsEventStatus_eIgnore;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Sets the JavaScript Command to be invoked when a "gui" event
|
||||||
|
* occurs on a source widget
|
||||||
|
* @param aStrCmd the JS command to be cached for later execution
|
||||||
|
* @return NS_OK
|
||||||
|
*/
|
||||||
|
NS_METHOD nsMenuItem::SetCommand(const nsString &aStrCmd)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* Executes the "cached" JavaScript Command
|
||||||
|
* @return NS_OK if the command was executed properly, otherwise an error code
|
||||||
|
*/
|
||||||
|
NS_METHOD nsMenuItem::DoCommand()
|
||||||
|
{
|
||||||
|
nsresult rv = NS_ERROR_FAILURE;
|
||||||
|
|
||||||
|
if(!mWebShell || !mDOMElement)
|
||||||
|
return rv;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentViewerContainer> contentViewerContainer;
|
||||||
|
contentViewerContainer = do_QueryInterface(mWebShell);
|
||||||
|
if (!contentViewerContainer) {
|
||||||
|
NS_ERROR("Webshell doesn't support the content viewer container interface");
|
||||||
|
//g_print("Webshell doesn't support the content viewer container interface");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||||
|
if (NS_FAILED(rv = contentViewerContainer->GetContentViewer(getter_AddRefs(contentViewer)))) {
|
||||||
|
NS_ERROR("Unable to retrieve content viewer.");
|
||||||
|
//g_print("Unable to retrieve content viewer.");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIDocumentViewer> docViewer;
|
||||||
|
docViewer = do_QueryInterface(contentViewer);
|
||||||
|
if (!docViewer) {
|
||||||
|
NS_ERROR("Document viewer interface not supported by the content viewer.");
|
||||||
|
//g_print("Document viewer interface not supported by the content viewer.");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIPresContext> presContext;
|
||||||
|
if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) {
|
||||||
|
NS_ERROR("Unable to retrieve the doc viewer's presentation context.");
|
||||||
|
//g_print("Unable to retrieve the doc viewer's presentation context.");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsEventStatus status = nsEventStatus_eIgnore;
|
||||||
|
nsMouseEvent event;
|
||||||
|
event.eventStructType = NS_MOUSE_EVENT;
|
||||||
|
event.message = NS_MOUSE_LEFT_CLICK;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIContent> contentNode;
|
||||||
|
contentNode = do_QueryInterface(mDOMElement);
|
||||||
|
if (!contentNode) {
|
||||||
|
NS_ERROR("DOM Node doesn't support the nsIContent interface required to handle DOM events.");
|
||||||
|
//g_print("DOM Node doesn't support the nsIContent interface required to handle DOM events.");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
rv = contentNode->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);
|
||||||
|
//g_print("HandleDOMEvent called");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::SetDOMElement(nsIDOMElement * aDOMElement)
|
||||||
|
{
|
||||||
|
mDOMElement = aDOMElement;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::GetDOMElement(nsIDOMElement ** aDOMElement)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsMenuItem::SetWebShell(nsIWebShell * aWebShell)
|
||||||
|
{
|
||||||
|
mWebShell = aWebShell;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsMenuItem_h__
|
||||||
|
#define nsMenuItem_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIMenuItem.h"
|
||||||
|
#include "nsIMenuListener.h"
|
||||||
|
|
||||||
|
#include <MenuItem.h>
|
||||||
|
|
||||||
|
class nsIMenu;
|
||||||
|
class nsIPopUpMenu;
|
||||||
|
class nsIMenuListener;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS MenuItem wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsMenuItem : public nsIMenuItem, public nsIMenuListener
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsMenuItem();
|
||||||
|
virtual ~nsMenuItem();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Create(nsISupports *aParent,
|
||||||
|
const nsString &aLabel,
|
||||||
|
PRBool aIsSeparator);
|
||||||
|
|
||||||
|
// nsIMenuBar Methods
|
||||||
|
NS_IMETHOD GetLabel(nsString &aText);
|
||||||
|
NS_IMETHOD SetLabel(nsString &aText);
|
||||||
|
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
|
||||||
|
NS_IMETHOD GetEnabled(PRBool *aIsEnabled);
|
||||||
|
NS_IMETHOD SetChecked(PRBool aIsEnabled);
|
||||||
|
NS_IMETHOD GetChecked(PRBool *aIsEnabled);
|
||||||
|
NS_IMETHOD GetCommand(PRUint32 & aCommand);
|
||||||
|
NS_IMETHOD GetTarget(nsIWidget *& aTarget);
|
||||||
|
NS_IMETHOD GetNativeData(void*& aData);
|
||||||
|
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
|
||||||
|
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
|
||||||
|
NS_IMETHOD IsSeparator(PRBool & aIsSep);
|
||||||
|
|
||||||
|
NS_IMETHOD SetCommand(const nsString & aStrCmd);
|
||||||
|
NS_IMETHOD DoCommand();
|
||||||
|
NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMElement);
|
||||||
|
NS_IMETHOD GetDOMElement(nsIDOMElement ** aDOMElement);
|
||||||
|
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);
|
||||||
|
|
||||||
|
// nsIMenuListener interface
|
||||||
|
nsEventStatus MenuItemSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuSelected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuDeselected(const nsMenuEvent & aMenuEvent);
|
||||||
|
nsEventStatus MenuConstruct(const nsMenuEvent & aMenuEvent,
|
||||||
|
nsIWidget * aParentWindow,
|
||||||
|
void * menuNode,
|
||||||
|
void * aWebShell);
|
||||||
|
nsEventStatus MenuDestruct(const nsMenuEvent & aMenuEvent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void Create(nsIWidget * aMBParent, BMenu *aParent,
|
||||||
|
const nsString &aLabel, PRUint32 aCommand);
|
||||||
|
nsIWidget * GetMenuBarParent(nsISupports * aParent);
|
||||||
|
BMenu *nsMenuItem::GetNativeParent();
|
||||||
|
|
||||||
|
BMenuItem *mMenuItem;
|
||||||
|
|
||||||
|
nsString mLabel;
|
||||||
|
PRUint32 mCommand;
|
||||||
|
nsIMenu *mMenuParent;
|
||||||
|
nsIPopUpMenu *mPopUpParent;
|
||||||
|
nsIWidget * mTarget;
|
||||||
|
nsIMenu * mMenu;
|
||||||
|
nsIMenuListener * mListener;
|
||||||
|
PRBool mIsSeparator;
|
||||||
|
nsIWebShell * mWebShell;
|
||||||
|
nsIDOMElement * mDOMElement;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsMenuItem_h__
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "nsObject.h"
|
||||||
|
|
||||||
|
|
||||||
|
CList nsObject::s_liveChain;
|
||||||
|
PRMonitor *nsObject::s_liveChainMutex = PR_NewMonitor();
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
int32 nsObject::s_nObjects = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* constructor
|
||||||
|
*/
|
||||||
|
nsObject::nsObject()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Add the new object the chain of allocated nsObjects
|
||||||
|
//
|
||||||
|
PR_EnterMonitor(s_liveChainMutex);
|
||||||
|
s_liveChain.Append(m_link);
|
||||||
|
PR_ExitMonitor(s_liveChainMutex);
|
||||||
|
#ifdef _DEBUG
|
||||||
|
s_nObjects++;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* destructor
|
||||||
|
*/
|
||||||
|
nsObject::~nsObject()
|
||||||
|
{
|
||||||
|
#ifdef _DEBUG
|
||||||
|
s_nObjects--;
|
||||||
|
#endif
|
||||||
|
//
|
||||||
|
// Remove from the chain of allocated nsObjects
|
||||||
|
//
|
||||||
|
PR_EnterMonitor(s_liveChainMutex);
|
||||||
|
m_link.Remove();
|
||||||
|
PR_ExitMonitor(s_liveChainMutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* static utility. Delete all live objects
|
||||||
|
*/
|
||||||
|
|
||||||
|
void nsObject::DeleteAllObjects(void)
|
||||||
|
{
|
||||||
|
PR_EnterMonitor(s_liveChainMutex);
|
||||||
|
|
||||||
|
while (!s_liveChain.IsEmpty()) {
|
||||||
|
nsObject *pnsObject;
|
||||||
|
|
||||||
|
pnsObject = (nsObject*)OBJECT_PTR_FROM_CLIST(nsObject, s_liveChain.next);
|
||||||
|
|
||||||
|
// Remove the event from the chain...
|
||||||
|
pnsObject->m_link.Remove();
|
||||||
|
delete pnsObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
PR_ExitMonitor(s_liveChainMutex);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsObject_h__
|
||||||
|
#define nsObject_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsCList.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "prmon.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* nsObject is the base class for all native widgets
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsObject
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsObject();
|
||||||
|
virtual ~nsObject();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//
|
||||||
|
// Data members:
|
||||||
|
//
|
||||||
|
CList m_link;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
//
|
||||||
|
// The following data members are used to maintain a chain of all
|
||||||
|
// allocated nsObject instances. This chain is traversed at
|
||||||
|
// shutdown to clean up any dangling instances...
|
||||||
|
//
|
||||||
|
static CList s_liveChain;
|
||||||
|
static PRMonitor *s_liveChainMutex;
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
static int32 s_nObjects;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void DeleteAllObjects(void);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // nsObject_h__
|
|
@ -0,0 +1,236 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#include "nsPopUpMenu.h"
|
||||||
|
#include "nsIPopUpMenu.h"
|
||||||
|
#include "nsIMenu.h"
|
||||||
|
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsIAppShell.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsRect.h"
|
||||||
|
#include "nsGfxCIID.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kPopUpMenuIID, NS_IPOPUPMENU_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsPopUpMenu, kPopUpMenuIID)
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsPopUpMenu constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsPopUpMenu::nsPopUpMenu() : nsIPopUpMenu()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mNumMenuItems = 0;
|
||||||
|
mParent = nsnull;
|
||||||
|
mMenu = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsPopUpMenu destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsPopUpMenu::~nsPopUpMenu()
|
||||||
|
{
|
||||||
|
NS_IF_RELEASE(mParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create the proper widget
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::Create(nsIWidget *aParent)
|
||||||
|
{
|
||||||
|
printf("nsPopUpMenu::Create - FIXME: not implemented\n");
|
||||||
|
|
||||||
|
mParent = aParent;
|
||||||
|
NS_ADDREF(mParent);
|
||||||
|
|
||||||
|
// mMenu = CreatePopupMenu();
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::AddItem(const nsString &aText)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::AddItem(nsIMenuItem * aMenuItem)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
PRUint32 command;
|
||||||
|
nsString name;
|
||||||
|
|
||||||
|
aMenuItem->GetCommand(command);
|
||||||
|
aMenuItem->GetLabel(name);
|
||||||
|
char * nameStr = name.ToNewCString();
|
||||||
|
|
||||||
|
MENUITEMINFO menuInfo;
|
||||||
|
menuInfo.cbSize = sizeof(menuInfo);
|
||||||
|
menuInfo.fMask = MIIM_TYPE | MIIM_ID;
|
||||||
|
menuInfo.fType = MFT_STRING;
|
||||||
|
menuInfo.dwTypeData = nameStr;
|
||||||
|
menuInfo.wID = (DWORD)command;
|
||||||
|
menuInfo.cch = strlen(nameStr);
|
||||||
|
|
||||||
|
BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo);
|
||||||
|
|
||||||
|
delete[] nameStr;
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::AddMenu(nsIMenu * aMenu)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
nsString name;
|
||||||
|
aMenu->GetLabel(name);
|
||||||
|
char * nameStr = name.ToNewCString();
|
||||||
|
|
||||||
|
HMENU nativeMenuHandle;
|
||||||
|
void * voidData;
|
||||||
|
aMenu->GetNativeData(voidData);
|
||||||
|
nativeMenuHandle = (HMENU)voidData;
|
||||||
|
|
||||||
|
MENUITEMINFO menuInfo;
|
||||||
|
|
||||||
|
menuInfo.cbSize = sizeof(menuInfo);
|
||||||
|
menuInfo.fMask = MIIM_SUBMENU | MIIM_TYPE;
|
||||||
|
menuInfo.hSubMenu = nativeMenuHandle;
|
||||||
|
menuInfo.fType = MFT_STRING;
|
||||||
|
menuInfo.dwTypeData = nameStr;
|
||||||
|
|
||||||
|
BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo);
|
||||||
|
|
||||||
|
delete[] nameStr;
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::AddSeparator()
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
MENUITEMINFO menuInfo;
|
||||||
|
|
||||||
|
menuInfo.cbSize = sizeof(menuInfo);
|
||||||
|
menuInfo.fMask = MIIM_TYPE;
|
||||||
|
menuInfo.fType = MFT_SEPARATOR;
|
||||||
|
|
||||||
|
BOOL status = InsertMenuItem(mMenu, mNumMenuItems++, TRUE, &menuInfo);
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::GetItemCount(PRUint32 &aCount)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::GetItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::InsertItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::InsertItemAt(const PRUint32 aCount, const nsString & aMenuItemName)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::InsertSeparator(const PRUint32 aCount)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::RemoveItem(const PRUint32 aCount)
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::RemoveAll()
|
||||||
|
{
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::ShowMenu(PRInt32 aX, PRInt32 aY)
|
||||||
|
{
|
||||||
|
printf("nsPopUpMenu::ShowMenu - FIXME: not implemented\n");
|
||||||
|
#if 0
|
||||||
|
if (nsnull != mParent) {
|
||||||
|
HWND pWnd = (HWND)mParent->GetNativeData(NS_NATIVE_WIDGET);
|
||||||
|
if (nsnull != pWnd) {
|
||||||
|
nsRect rect;
|
||||||
|
POINT point;
|
||||||
|
mParent->GetBounds(rect);
|
||||||
|
point.x = 0;
|
||||||
|
point.y = 0;
|
||||||
|
ClientToScreen (pWnd, &point) ;
|
||||||
|
point.x += aX;
|
||||||
|
point.y += aY;
|
||||||
|
BOOL status = TrackPopupMenu(mMenu, TPM_LEFTALIGN | TPM_TOPALIGN, point.x, point.y, 0, pWnd, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::GetNativeData(void *& aData)
|
||||||
|
{
|
||||||
|
aData = (void *)((BMenu *)mMenu);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsPopUpMenu::GetParent(nsIWidget *& aParent)
|
||||||
|
{
|
||||||
|
aParent = mParent;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsPopUpMenu_h__
|
||||||
|
#define nsPopUpMenu_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIPopUpMenu.h"
|
||||||
|
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 button wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsPopUpMenu : public nsIPopUpMenu
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsPopUpMenu();
|
||||||
|
virtual ~nsPopUpMenu();
|
||||||
|
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
NS_IMETHOD Create(nsIWidget * aParent);
|
||||||
|
|
||||||
|
// nsIPopUpMenu Methods
|
||||||
|
NS_IMETHOD AddItem(const nsString &aText);
|
||||||
|
NS_IMETHOD AddItem(nsIMenuItem * aMenuItem);
|
||||||
|
NS_IMETHOD AddMenu(nsIMenu * aMenu);
|
||||||
|
NS_IMETHOD AddSeparator();
|
||||||
|
NS_IMETHOD GetItemCount(PRUint32 &aCount);
|
||||||
|
NS_IMETHOD GetItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem);
|
||||||
|
NS_IMETHOD InsertItemAt(const PRUint32 aCount, nsIMenuItem *& aMenuItem);
|
||||||
|
NS_IMETHOD InsertItemAt(const PRUint32 aCount, const nsString & aMenuItemName);
|
||||||
|
NS_IMETHOD InsertSeparator(const PRUint32 aCount);
|
||||||
|
NS_IMETHOD RemoveItem(const PRUint32 aCount);
|
||||||
|
NS_IMETHOD RemoveAll();
|
||||||
|
NS_IMETHOD ShowMenu(PRInt32 aX, PRInt32 aY);
|
||||||
|
NS_IMETHOD GetNativeData(void*& aData);
|
||||||
|
NS_IMETHOD GetParent(nsIWidget*& aParent);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
PRUint32 mNumMenuItems;
|
||||||
|
|
||||||
|
nsIWidget * mParent;
|
||||||
|
BPopUpMenu *mMenu;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsPopUpMenu_h__
|
|
@ -0,0 +1,244 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsRadioButton.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsRadioButton)
|
||||||
|
NS_IMPL_RELEASE(nsRadioButton)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsRadioButton constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsRadioButton::nsRadioButton() : nsWindow(), nsIRadioButton()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsRadioButton destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsRadioButton::~nsRadioButton()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsRadioButton::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kIRadioButtonIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIRadioButton*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Sets the state of the nsRadioButton
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsRadioButton::SetState(const PRBool aState)
|
||||||
|
{
|
||||||
|
fState = aState;
|
||||||
|
if(mRadioButton && mRadioButton->LockLooper())
|
||||||
|
{
|
||||||
|
mRadioButton->SetValue(aState ? 1 : 0);
|
||||||
|
mRadioButton->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsRadioButton::GetState(PRBool& aState)
|
||||||
|
{
|
||||||
|
aState = fState;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsRadioButton::SetLabel(const nsString& aText)
|
||||||
|
{
|
||||||
|
char label[256];
|
||||||
|
aText.ToCString(label, 256);
|
||||||
|
label[255] = '\0';
|
||||||
|
if(mRadioButton && mRadioButton->LockLooper())
|
||||||
|
{
|
||||||
|
mRadioButton->SetLabel(label);
|
||||||
|
mRadioButton->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get this button label
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsRadioButton::GetLabel(nsString& aBuffer)
|
||||||
|
{
|
||||||
|
if(mRadioButton && mRadioButton->LockLooper())
|
||||||
|
{
|
||||||
|
aBuffer.SetLength(0);
|
||||||
|
aBuffer.Append(mRadioButton->Label());
|
||||||
|
mRadioButton->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsRadioButton::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsRadioButton::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsRadioButton::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the RadioButton for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsRadioButton::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
float appUnits;
|
||||||
|
float scale;
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
|
||||||
|
context->GetCanonicalPixelScale(scale);
|
||||||
|
context->GetDevUnitsToAppUnits(appUnits);
|
||||||
|
nsRect rect;
|
||||||
|
GetBounds(rect);
|
||||||
|
|
||||||
|
rect.x++;
|
||||||
|
rect.y++;
|
||||||
|
rect.width -= 2;
|
||||||
|
rect.height -= 2;
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscoord one = nscoord(PRFloat64(rect.width) * 1.0/12.0);
|
||||||
|
|
||||||
|
rect.x = nscoord((PRFloat64)rect.x * appUnits);
|
||||||
|
rect.y = nscoord((PRFloat64)rect.y * appUnits);
|
||||||
|
rect.width = nscoord((PRFloat64)rect.width * appUnits);
|
||||||
|
rect.height = nscoord((PRFloat64)rect.height * appUnits);
|
||||||
|
rect.x += one;
|
||||||
|
rect.width = nscoord(PRFloat64(rect.width) * 11.0/12.0);
|
||||||
|
rect.height = nscoord(PRFloat64(rect.height) * 11.0/12.0);
|
||||||
|
|
||||||
|
for (nscoord i=0;i<nscoord(scale*1.25);i++) {
|
||||||
|
aRenderingContext.DrawArc(rect, 0, 180);
|
||||||
|
aRenderingContext.DrawArc(rect, 180, 360);
|
||||||
|
rect.x++;
|
||||||
|
rect.y++;
|
||||||
|
rect.width -= 2;
|
||||||
|
rect.height -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fState) {
|
||||||
|
GetBounds(rect);
|
||||||
|
nscoord xHalf = rect.width / 4;
|
||||||
|
nscoord yHalf = rect.height / 4;
|
||||||
|
rect.x += xHalf;
|
||||||
|
rect.y += yHalf;
|
||||||
|
rect.width -= xHalf*2;
|
||||||
|
rect.height -= yHalf*2;
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscoord one = nscoord(PRFloat64(rect.width) * 1.0/12.0);
|
||||||
|
|
||||||
|
rect.x = nscoord((PRFloat64)rect.x * appUnits);
|
||||||
|
rect.y = nscoord((PRFloat64)rect.y * appUnits);
|
||||||
|
rect.width = nscoord((PRFloat64)rect.width * appUnits);
|
||||||
|
rect.height = nscoord((PRFloat64)rect.height * appUnits);
|
||||||
|
rect.x += one;
|
||||||
|
rect.width = nscoord(PRFloat64(rect.width) * 11.0/12.0);
|
||||||
|
rect.height = nscoord(PRFloat64(rect.height) * 11.0/12.0);
|
||||||
|
|
||||||
|
aRenderingContext.FillArc(rect, 0, 180);
|
||||||
|
aRenderingContext.FillArc(rect, 180, 360);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_RELEASE(context);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsRadioButton::CreateBeOSView()
|
||||||
|
{
|
||||||
|
return mRadioButton = new nsRadioButtonBeOS(this, BRect(0, 0, 0, 0), "", "", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS RadioButton
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsRadioButtonBeOS::nsRadioButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, const char *aLabel, BMessage *aMessage,
|
||||||
|
uint32 aResizingMode, uint32 aFlags )
|
||||||
|
: BRadioButton( aFrame, aName, aLabel, aMessage, aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsRadioButton_h__
|
||||||
|
#define nsRadioButton_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#include "nsIRadioButton.h"
|
||||||
|
|
||||||
|
#include <RadioButton.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 Radio button wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsRadioButton : public nsWindow,
|
||||||
|
public nsIRadioButton
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsRadioButton();
|
||||||
|
virtual ~nsRadioButton();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsIRadioButton part
|
||||||
|
NS_IMETHOD SetLabel(const nsString& aText);
|
||||||
|
NS_IMETHOD GetLabel(nsString& aBuffer);
|
||||||
|
NS_IMETHOD SetState(const PRBool aState);
|
||||||
|
NS_IMETHOD GetState(PRBool& aState);
|
||||||
|
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
PRBool fState;
|
||||||
|
virtual BView *CreateBeOSView();
|
||||||
|
BRadioButton *mRadioButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BRadioButton subclass
|
||||||
|
//
|
||||||
|
class nsRadioButtonBeOS : public BRadioButton, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsRadioButtonBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
const char *aLabel, BMessage *aMessage, uint32 aResizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
|
uint32 aFlags = B_WILL_DRAW | B_NAVIGABLE );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsRadioButton_h__
|
|
@ -0,0 +1,341 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsScrollbar.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsUnitConversion.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsScrollbar)
|
||||||
|
NS_IMPL_RELEASE(nsScrollbar)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsScrollbar constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsScrollbar::nsScrollbar(PRBool aIsVertical) : nsWindow(), nsIScrollbar()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mOrientation = (aIsVertical) ? B_VERTICAL : B_HORIZONTAL;
|
||||||
|
mLineIncrement = 0;
|
||||||
|
thumb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsScrollbar destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsScrollbar::~nsScrollbar()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsScrollbar::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsScrollbarIID, NS_ISCROLLBAR_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kInsScrollbarIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsIScrollbar*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Define the range settings
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::SetMaxRange(PRUint32 aEndRange)
|
||||||
|
{
|
||||||
|
float min, max;
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->GetRange(&min, &max);
|
||||||
|
mScrollbar->SetRange(min, float(aEndRange - thumb));
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Return the range settings
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRUint32 nsScrollbar::GetMaxRange(PRUint32& aRange)
|
||||||
|
{
|
||||||
|
float startRange, endRange;
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->GetRange(&startRange, &endRange);
|
||||||
|
aRange = endRange + thumb;
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the thumb position
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::SetPosition(PRUint32 aPos)
|
||||||
|
{
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->SetValue(aPos);
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the current thumb position.
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRUint32 nsScrollbar::GetPosition(PRUint32& aPosition)
|
||||||
|
{
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
aPosition = mScrollbar->Value();
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the thumb size
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::SetThumbSize(PRUint32 aSize)
|
||||||
|
{
|
||||||
|
float min, max, smallStep, bigStep;
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->GetRange(&min, &max);
|
||||||
|
max = max + thumb - aSize;
|
||||||
|
// thumb = aSize;
|
||||||
|
mScrollbar->SetRange(min, max);
|
||||||
|
mScrollbar->SetProportion(max == min ? 1 : (aSize / (max > min ? max - min : min - max)));
|
||||||
|
mScrollbar->GetSteps(&smallStep, &bigStep);
|
||||||
|
mScrollbar->SetSteps(smallStep, aSize);
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the thumb size
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::GetThumbSize(PRUint32& aSize)
|
||||||
|
{
|
||||||
|
aSize = thumb;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the line increment for this scrollbar
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::SetLineIncrement(PRUint32 aSize)
|
||||||
|
{
|
||||||
|
float smallStep, bigStep;
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->GetSteps(&smallStep, &bigStep);
|
||||||
|
mScrollbar->SetSteps(aSize, bigStep);
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the line increment for this scrollbar
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::GetLineIncrement(PRUint32& aSize)
|
||||||
|
{
|
||||||
|
float smallStep, bigStep;
|
||||||
|
aSize = 0;
|
||||||
|
if(mScrollbar && mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
mScrollbar->GetSteps(&smallStep, &bigStep);
|
||||||
|
aSize = uint32(smallStep);
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set all scrolling parameters
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsScrollbar::SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||||
|
PRUint32 aPosition, PRUint32 aLineIncrement)
|
||||||
|
{
|
||||||
|
SetMaxRange(aMaxRange);
|
||||||
|
SetThumbSize(aThumbSize);
|
||||||
|
SetPosition(aPosition);
|
||||||
|
SetLineIncrement(aLineIncrement);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// paint message. Don't send the paint out
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsScrollbar::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PRBool nsScrollbar::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Deal with scrollbar messages (actually implemented only in nsScrollbar)
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsScrollbar::OnScroll()
|
||||||
|
{
|
||||||
|
PRBool result = PR_TRUE;
|
||||||
|
int32 newpos;
|
||||||
|
if(mEventCallback)
|
||||||
|
{
|
||||||
|
if(mScrollbar->LockLooper())
|
||||||
|
{
|
||||||
|
if(mScrollbar->GetPosition(newpos))
|
||||||
|
{
|
||||||
|
nsScrollbarEvent event;
|
||||||
|
InitEvent(event, NS_SCROLLBAR_POS);
|
||||||
|
event.widget = (nsWindow *)this;
|
||||||
|
event.position = newpos;
|
||||||
|
result = ConvertStatus((*mEventCallback)(&event));
|
||||||
|
|
||||||
|
// if(newpos != event.position)
|
||||||
|
// SetPosition(newpos = event.position);
|
||||||
|
}
|
||||||
|
mScrollbar->UnlockLooper();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsScrollbar::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
return nsWindow::GetBounds(aRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsScrollbar::CreateBeOSView()
|
||||||
|
{
|
||||||
|
BRect temp;
|
||||||
|
|
||||||
|
// work around stupit BeOS bug
|
||||||
|
if(mOrientation == B_VERTICAL)
|
||||||
|
temp.Set(0, 0, B_V_SCROLL_BAR_WIDTH, B_H_SCROLL_BAR_HEIGHT * 2);
|
||||||
|
else
|
||||||
|
temp.Set(0, 0, B_V_SCROLL_BAR_WIDTH * 2, B_H_SCROLL_BAR_HEIGHT);
|
||||||
|
|
||||||
|
mScrollbar = new nsScrollbarBeOS(this, temp, "", NULL, 0, 0, mOrientation);
|
||||||
|
|
||||||
|
return mScrollbar;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
// Sub-class of BeOS Scrollbar
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsScrollbarBeOS::nsScrollbarBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, BView *aTarget, float aMin, float aMax,
|
||||||
|
orientation aOrientation )
|
||||||
|
: BScrollBar( aFrame, aName, aTarget, aMin, aMax, aOrientation ),
|
||||||
|
nsIWidgetStore( aWidgetWindow ), first(true), sbposchanged(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsScrollbarBeOS::ValueChanged(float newValue)
|
||||||
|
{
|
||||||
|
if(first)
|
||||||
|
{
|
||||||
|
first = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sbpos = newValue;
|
||||||
|
sbposchanged = true;
|
||||||
|
|
||||||
|
nsWindow *w = (nsWindow *)GetMozillaWidget();
|
||||||
|
nsToolkit *t;
|
||||||
|
if(w && (t = w->GetToolkit()) != 0)
|
||||||
|
{
|
||||||
|
MethodInfo *info = new MethodInfo(w, w, nsWindow::ONSCROLL);
|
||||||
|
t->CallMethodAsync(info);
|
||||||
|
NS_RELEASE(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nsScrollbarBeOS::GetPosition(int32 &p)
|
||||||
|
{
|
||||||
|
if(! sbposchanged)
|
||||||
|
return false;
|
||||||
|
p = (int32)sbpos;
|
||||||
|
sbposchanged = false;
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,88 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsScrollbar_h__
|
||||||
|
#define nsScrollbar_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsIScrollbar.h"
|
||||||
|
|
||||||
|
#include <ScrollBar.h>
|
||||||
|
|
||||||
|
class nsScrollbarBeOS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native WIN32 scrollbar wrapper.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsScrollbar : public nsWindow,
|
||||||
|
public nsIScrollbar
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsScrollbar(PRBool aIsVertical);
|
||||||
|
virtual ~nsScrollbar();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsIScrollBar implementation
|
||||||
|
NS_IMETHOD SetMaxRange(PRUint32 aEndRange);
|
||||||
|
NS_IMETHOD GetMaxRange(PRUint32& aMaxRange);
|
||||||
|
NS_IMETHOD SetPosition(PRUint32 aPos);
|
||||||
|
NS_IMETHOD GetPosition(PRUint32& aPos);
|
||||||
|
NS_IMETHOD SetThumbSize(PRUint32 aSize);
|
||||||
|
NS_IMETHOD GetThumbSize(PRUint32& aSize);
|
||||||
|
NS_IMETHOD SetLineIncrement(PRUint32 aSize);
|
||||||
|
NS_IMETHOD GetLineIncrement(PRUint32& aSize);
|
||||||
|
NS_IMETHOD SetParameters(PRUint32 aMaxRange, PRUint32 aThumbSize,
|
||||||
|
PRUint32 aPosition, PRUint32 aLineIncrement);
|
||||||
|
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnScroll();
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsScrollbarBeOS *mScrollbar;
|
||||||
|
BView *CreateBeOSView();
|
||||||
|
int mLineIncrement;
|
||||||
|
float mScaleFactor;
|
||||||
|
int32 thumb;
|
||||||
|
orientation mOrientation;
|
||||||
|
};
|
||||||
|
|
||||||
|
class nsScrollbarBeOS : public BScrollBar, public nsIWidgetStore
|
||||||
|
{
|
||||||
|
bool first;
|
||||||
|
float sbpos;
|
||||||
|
bool sbposchanged;
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsScrollbarBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
BView *aTarget, float aMin, float aMax, orientation aOrientation );
|
||||||
|
void ValueChanged(float newValue);
|
||||||
|
bool nsScrollbarBeOS::GetPosition(int32 &p);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsButton_h__
|
|
@ -0,0 +1,84 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "nscore.h"
|
||||||
|
#include "nsISound.h"
|
||||||
|
#include "nsIAllocator.h"
|
||||||
|
#include "plstr.h"
|
||||||
|
#include "stdio.h"
|
||||||
|
|
||||||
|
#include <Beep.h>
|
||||||
|
|
||||||
|
class SoundImpl : public nsISound
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SoundImpl();
|
||||||
|
virtual ~SoundImpl();
|
||||||
|
|
||||||
|
// nsISupports interface
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsISound interface
|
||||||
|
|
||||||
|
NS_IMETHOD Beep();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
NS_NewSound(nsISound** aSound)
|
||||||
|
{
|
||||||
|
NS_PRECONDITION(aSound != nsnull, "null ptr");
|
||||||
|
if (! aSound)
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
||||||
|
*aSound = new SoundImpl();
|
||||||
|
if (! *aSound)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
NS_ADDREF(*aSound);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
SoundImpl::SoundImpl()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SoundImpl::~SoundImpl()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ISUPPORTS(SoundImpl, nsISound::GetIID());
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
SoundImpl::Beep()
|
||||||
|
{
|
||||||
|
beep();
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
|
||||||
|
/*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Convience macros for converting nsString's to chars +
|
||||||
|
// creating temporary char[] bufs.
|
||||||
|
|
||||||
|
#ifndef NS_STR_UTIL_H
|
||||||
|
#define NS_STR_UTIL_H
|
||||||
|
|
||||||
|
// nsString to temporary char[] macro
|
||||||
|
|
||||||
|
// Convience MACROS to convert an nsString to a char * which use a
|
||||||
|
// static char array if possible to reduce memory fragmentation,
|
||||||
|
// otherwise they allocate a char[] which must be freed.
|
||||||
|
// REMEMBER to always use the NS_FREE_STR_BUF after using the
|
||||||
|
// NS_ALLOC_STR_BUF. You can not nest NS_ALLOC_STR_BUF's.
|
||||||
|
|
||||||
|
#define NS_ALLOC_STR_BUF(varName, strName, tempSize) \
|
||||||
|
static const int _ns_kSmallBufferSize = tempSize; \
|
||||||
|
char* varName = 0; \
|
||||||
|
int _ns_smallBufUsed = 0; \
|
||||||
|
char _ns_smallBuffer[_ns_kSmallBufferSize]; \
|
||||||
|
if (strName.Length() < (_ns_kSmallBufferSize - 1)) { \
|
||||||
|
strName.ToCString(_ns_smallBuffer, _ns_kSmallBufferSize); \
|
||||||
|
_ns_smallBuffer[_ns_kSmallBufferSize - 1] = '\0'; \
|
||||||
|
_ns_smallBufUsed = 1; \
|
||||||
|
varName = _ns_smallBuffer; \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
varName = strName.ToNewCString(); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NS_FREE_STR_BUF(varName) \
|
||||||
|
if (! _ns_smallBufUsed) \
|
||||||
|
delete varName;
|
||||||
|
|
||||||
|
// Create temporary char[] macro
|
||||||
|
//
|
||||||
|
// Create a temporary buffer for storing chars.
|
||||||
|
// If the actual size is > size then the buffer
|
||||||
|
// is allocated from the heap, otherwise the buffer
|
||||||
|
// is a stack variable. REMEMBER: use NS_FREE_BUF
|
||||||
|
// when finished with the buffer allocated, and do
|
||||||
|
// NOT nest INSERT_BUF'S.
|
||||||
|
|
||||||
|
#define NS_ALLOC_CHAR_BUF(aBuf, aSize, aActualSize) \
|
||||||
|
char *aBuf; \
|
||||||
|
int _ns_smallBufUsed = 0; \
|
||||||
|
static const int _ns_kSmallBufferSize = aSize; \
|
||||||
|
if (aActualSize < _ns_kSmallBufferSize) { \
|
||||||
|
char _ns_smallBuffer[_ns_kSmallBufferSize]; \
|
||||||
|
aBuf = _ns_smallBuffer; \
|
||||||
|
_ns_smallBufUsed = 1; \
|
||||||
|
} \
|
||||||
|
else { \
|
||||||
|
aBuf = new char[aActualSize]; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NS_FREE_CHAR_BUF(aBuf) \
|
||||||
|
if (! _ns_smallBufUsed) \
|
||||||
|
delete aBuf;
|
||||||
|
|
||||||
|
|
||||||
|
#endif // NSStringUtil
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SWITCHTOUITHREAD_H
|
||||||
|
#define SWITCHTOUITHREAD_H
|
||||||
|
|
||||||
|
#include "nsISupports.h"
|
||||||
|
|
||||||
|
// foreward declaration
|
||||||
|
struct MethodInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Switch thread to match the thread the widget was created in so messages will be dispatched.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsSwitchToUIThread {
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual bool CallMethod(MethodInfo *info) = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Structure used for passing the information necessary for synchronously
|
||||||
|
// invoking a method on the GUI thread...
|
||||||
|
//
|
||||||
|
struct MethodInfo {
|
||||||
|
nsISupports *widget;
|
||||||
|
nsSwitchToUIThread *target;
|
||||||
|
uint32 methodId;
|
||||||
|
int nArgs;
|
||||||
|
uint32 *args;
|
||||||
|
|
||||||
|
MethodInfo(nsISupports *ref, nsSwitchToUIThread *obj, uint32 id, int numArgs = 0, uint32 *arguments = 0)
|
||||||
|
{
|
||||||
|
widget = ref;
|
||||||
|
NS_ADDREF(ref);
|
||||||
|
target = obj;
|
||||||
|
methodId = id;
|
||||||
|
nArgs = numArgs;
|
||||||
|
args = new uint32 [numArgs];
|
||||||
|
memcpy(args, arguments, sizeof(uint32) * numArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
~MethodInfo()
|
||||||
|
{
|
||||||
|
delete [] args;
|
||||||
|
NS_RELEASE(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Invoke() { return target->CallMethod(this); }
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TOUITHRD_H
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsTabWidget.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsTabWidget)
|
||||||
|
NS_IMPL_RELEASE(nsTabWidget)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTabWidget constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTabWidget::nsTabWidget() : nsWindow()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
// Ensure that common controls dll is loaded
|
||||||
|
#if 0
|
||||||
|
InitCommonControls();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTabWidget destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTabWidget::~nsTabWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsTabWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsTabWidgetIID, NS_ITABWIDGET_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kInsTabWidgetIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsITabWidget*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Set the tab labels
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsTabWidget::SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[])
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
TC_ITEM tie;
|
||||||
|
char labelTemp[256];
|
||||||
|
|
||||||
|
for (PRUint32 i = 0; i < aNumberOfTabs; i++) {
|
||||||
|
tie.mask = TCIF_TEXT;
|
||||||
|
aTabLabels[i].ToCString(labelTemp, 256);
|
||||||
|
tie.pszText = labelTemp;
|
||||||
|
TabCtrl_InsertItem(mWnd, i, &tie);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Get the currently selected tab
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
PRUint32 nsTabWidget::GetSelectedTab(PRUint32& aTabNumber)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
aTabNumber = TabCtrl_GetCurSel(mWnd);
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// paint message. Don't send the paint out
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsTabWidget::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsTabWidget::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsTabWidget::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
return nsWindow::GetBounds(aRect);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,55 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTabWidget_h__
|
||||||
|
#define nsTabWidget_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsITabWidget.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 tab control wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsTabWidget : public nsWindow,
|
||||||
|
public nsITabWidget
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsTabWidget();
|
||||||
|
virtual ~nsTabWidget();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
|
||||||
|
// nsITabWidget part
|
||||||
|
NS_IMETHOD SetTabs(PRUint32 aNumberOfTabs, const nsString aTabLabels[]);
|
||||||
|
NS_IMETHOD GetSelectedTab(PRUint32& aTabNumber);
|
||||||
|
|
||||||
|
// nsIWidget overrides
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsTabWidget_h__
|
|
@ -0,0 +1,244 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#include "nsTextAreaWidget.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*NS_IMPL_ADDREF(nsTextAreaWidget)
|
||||||
|
//NS_IMPL_RELEASE(nsTextAreaWidget)
|
||||||
|
nsrefcnt nsTextAreaWidget::Release(void)
|
||||||
|
{
|
||||||
|
// NS_PRECONDITION(0 != cnt, "dup release");
|
||||||
|
if (--mRefCnt == 0) {
|
||||||
|
delete this;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return mRefCnt;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsTextAreaWidget)
|
||||||
|
NS_IMPL_RELEASE(nsTextAreaWidget)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextAreaWidget constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTextAreaWidget::nsTextAreaWidget()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
nsTextHelper::mBackground = NS_RGB(124, 124, 124);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextAreaWidget destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTextAreaWidget::~nsTextAreaWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsTextAreaWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kITextAreaWidgetIID, NS_ITEXTAREAWIDGET_IID);
|
||||||
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||||
|
|
||||||
|
|
||||||
|
if (aIID.Equals(kITextAreaWidgetIID)) {
|
||||||
|
nsITextAreaWidget* textArea = this;
|
||||||
|
*aInstancePtr = (void*) (textArea);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
else if (aIID.Equals(kIWidgetIID))
|
||||||
|
{
|
||||||
|
nsIWidget* widget = this;
|
||||||
|
*aInstancePtr = (void*) (widget);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsTextAreaWidget::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsTextAreaWidget::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsTextAreaWidget::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsTextAreaWidget::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
nsWindow::GetNonClientBounds(aRect);
|
||||||
|
#endif
|
||||||
|
printf("nsTextAreaWidget::GetBounds not wrong\n"); // the following is just a placeholder
|
||||||
|
nsWindow::GetClientBounds(aRect);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the TextWidget for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsTextAreaWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
nsRect rect;
|
||||||
|
float appUnits;
|
||||||
|
float scale;
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
|
||||||
|
context->GetCanonicalPixelScale(scale);
|
||||||
|
context->GetDevUnitsToAppUnits(appUnits);
|
||||||
|
|
||||||
|
GetBoundsAppUnits(rect, appUnits);
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscolor bgColor = NS_RGB(255,255,255);
|
||||||
|
nscolor fgColor = NS_RGB(0,0,0);
|
||||||
|
nscolor hltColor = NS_RGB(240,240,240);
|
||||||
|
nscolor sdwColor = NS_RGB(128,128,128);
|
||||||
|
nscolor txtBGColor = NS_RGB(255,255,255);
|
||||||
|
nscolor txtFGColor = NS_RGB(0,0,0);
|
||||||
|
nsILookAndFeel * lookAndFeel;
|
||||||
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(txtBGColor);
|
||||||
|
aRenderingContext.FillRect(rect);
|
||||||
|
|
||||||
|
// Paint Black border
|
||||||
|
//nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||||
|
|
||||||
|
nscoord onePixel = nscoord(scale);
|
||||||
|
nscoord twoPixels = nscoord(scale*2);
|
||||||
|
|
||||||
|
rect.x += onePixel;
|
||||||
|
rect.y += onePixel;
|
||||||
|
rect.width -= twoPixels+onePixel;
|
||||||
|
rect.height -= twoPixels+onePixel;
|
||||||
|
|
||||||
|
nscoord right = rect.x+rect.width;
|
||||||
|
nscoord bottom = rect.y+rect.height;
|
||||||
|
|
||||||
|
|
||||||
|
// Draw Left & Top
|
||||||
|
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||||
|
|
||||||
|
// Draw Right & Bottom
|
||||||
|
aRenderingContext.SetColor(NS_RGB(192,192,192));
|
||||||
|
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||||
|
|
||||||
|
|
||||||
|
aRenderingContext.SetFont(*mFont);
|
||||||
|
|
||||||
|
nscoord textWidth;
|
||||||
|
nscoord textHeight;
|
||||||
|
aRenderingContext.GetWidth(mText, textWidth);
|
||||||
|
|
||||||
|
nsIFontMetrics* metrics;
|
||||||
|
context->GetMetricsFor(*mFont, metrics);
|
||||||
|
metrics->GetMaxAscent(textHeight);
|
||||||
|
|
||||||
|
nscoord x = (twoPixels * 2) + rect.x;
|
||||||
|
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||||
|
aRenderingContext.SetColor(txtFGColor);
|
||||||
|
aRenderingContext.DrawString(mText, x, y);
|
||||||
|
|
||||||
|
NS_RELEASE(context);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsTextAreaWidget::CreateBeOSView()
|
||||||
|
{
|
||||||
|
mTextView = new nsTextAreaBeOS(this, BRect(0, 0, 0, 0), B_EMPTY_STRING, BRect(0, 0, 0, 0), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
|
||||||
|
return new TextFrameBeOS(mTextView, BRect(0, 0, 0, 0), B_EMPTY_STRING, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
|
// BeOS Sub-Class TextView
|
||||||
|
//----------------------------------------------------
|
||||||
|
|
||||||
|
nsTextAreaBeOS::nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, BRect aTextRect, uint32 aResizingMode,
|
||||||
|
uint32 aFlags )
|
||||||
|
: BTextView( aFrame, aName, aTextRect, aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,67 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTextAreaWidget_h__
|
||||||
|
#define nsTextAreaWidget_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsTextHelper.h"
|
||||||
|
|
||||||
|
#include "nsITextAreaWidget.h"
|
||||||
|
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native WIN32 multi-line edit control wrapper.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsTextAreaWidget : public nsTextHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsTextAreaWidget();
|
||||||
|
virtual ~nsTextAreaWidget();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
// nsIWidget Overrides
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
protected:
|
||||||
|
BView *CreateBeOSView();
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BTextView subclass
|
||||||
|
//
|
||||||
|
class nsTextAreaBeOS : public BTextView, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsTextAreaBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
BRect aTextRect, uint32 aResizingMode, uint32 aFlags );
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsTextAreaWidget_h__
|
|
@ -0,0 +1,226 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsTextHelper.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::PreCreateWidget(nsWidgetInitData *aInitData)
|
||||||
|
{
|
||||||
|
if (nsnull != aInitData) {
|
||||||
|
nsTextWidgetInitData* data = (nsTextWidgetInitData *) aInitData;
|
||||||
|
mIsPassword = data->mIsPassword;
|
||||||
|
mIsReadOnly = data->mIsReadOnly;
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetMaxTextLength(PRUint32 aChars)
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->SetMaxBytes(aChars);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize)
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
aTextBuffer.SetLength(0);
|
||||||
|
aTextBuffer.Append(mTextView->Text());
|
||||||
|
aActualSize = strlen(mTextView->Text());
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetText(const nsString &aText, PRUint32& aActualSize)
|
||||||
|
{
|
||||||
|
mText = aText;
|
||||||
|
|
||||||
|
const char *text;
|
||||||
|
text = aText.ToNewCString();
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->SetText(text);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
delete [] text;
|
||||||
|
|
||||||
|
aActualSize = aText.Length();
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize)
|
||||||
|
{
|
||||||
|
const char *text;
|
||||||
|
text = aText.ToNewCString();
|
||||||
|
if(mTextView)
|
||||||
|
{
|
||||||
|
if(mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->Insert(aStartPos, text, aActualSize);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
mTextView->Insert(aStartPos, text, aActualSize);
|
||||||
|
}
|
||||||
|
delete [] text;
|
||||||
|
mText.Insert(aText, aStartPos, aText.Length());
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::RemoveText()
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->Delete(0, mTextView->TextLength() - 1);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetPassword(PRBool aIsPassword)
|
||||||
|
{
|
||||||
|
mIsPassword = aIsPassword;
|
||||||
|
if(mIsPassword) printf("nsTextHelper::SetPassword not implemented\n");
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetReadOnly(PRBool aReadOnlyFlag, PRBool& aOldFlag)
|
||||||
|
{
|
||||||
|
aOldFlag = mIsReadOnly;
|
||||||
|
mIsReadOnly = aReadOnlyFlag;
|
||||||
|
|
||||||
|
// Update the widget
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->MakeEditable(false);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SelectAll()
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->SelectAll();
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetSelection(PRUint32 aStartSel, PRUint32 aEndSel)
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->Select(aStartSel, aEndSel);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel)
|
||||||
|
{
|
||||||
|
if(mTextView && mTextView->LockLooper())
|
||||||
|
{
|
||||||
|
mTextView->GetSelection((int32 *)aStartSel, (int32 *)aEndSel);
|
||||||
|
mTextView->UnlockLooper();
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::SetCaretPosition(PRUint32 aPosition)
|
||||||
|
{
|
||||||
|
SetSelection(aPosition, aPosition);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_METHOD nsTextHelper::GetCaretPosition(PRUint32& aPos)
|
||||||
|
{
|
||||||
|
PRUint32 start;
|
||||||
|
PRUint32 end;
|
||||||
|
GetSelection(&start, &end);
|
||||||
|
if (start == end) {
|
||||||
|
aPos = start;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
aPos = PRUint32(-1);/* XXX is this right??? scary cast! */
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextHelper constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
nsTextHelper::nsTextHelper() : nsWindow(), nsITextAreaWidget(), nsITextWidget()
|
||||||
|
{
|
||||||
|
mIsReadOnly = PR_FALSE;
|
||||||
|
mIsPassword = PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextHelper destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTextHelper::~nsTextHelper()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Clear window before paint
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PRBool nsTextHelper::AutoErase()
|
||||||
|
{
|
||||||
|
return(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TextFrameBeOS::TextFrameBeOS(BTextView *child, BRect frame, const char *name, uint32 resizingmode, uint32 flags)
|
||||||
|
: BView(frame, name, resizingmode, flags | B_FRAME_EVENTS), tv(child)
|
||||||
|
{
|
||||||
|
SetViewColor(0, 0, 0);
|
||||||
|
AddChild(tv);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TextFrameBeOS::FrameResized(float width, float height)
|
||||||
|
{
|
||||||
|
tv->MoveTo(1, 1);
|
||||||
|
tv->ResizeTo(width - 2, height - 2);
|
||||||
|
BRect r = Bounds();
|
||||||
|
r.InsetBy(1, 1);
|
||||||
|
tv->SetTextRect(r);
|
||||||
|
BView::FrameResized(width, height);
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#ifndef nsTextHelper_h__
|
||||||
|
#define nsTextHelper_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsITextWidget.h"
|
||||||
|
#include "nsITextAreaWidget.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for nsTextAreaWidget and nsTextWidget
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsTextHelper : public nsWindow,
|
||||||
|
public nsITextAreaWidget,
|
||||||
|
public nsITextWidget
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsTextHelper();
|
||||||
|
virtual ~nsTextHelper();
|
||||||
|
|
||||||
|
NS_IMETHOD SelectAll();
|
||||||
|
NS_IMETHOD SetMaxTextLength(PRUint32 aChars);
|
||||||
|
NS_IMETHOD GetText(nsString& aTextBuffer, PRUint32 aBufferSize, PRUint32& aActualSize);
|
||||||
|
NS_IMETHOD SetText(const nsString &aText, PRUint32& aActualSize);
|
||||||
|
NS_IMETHOD InsertText(const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32& aActualSize);
|
||||||
|
NS_IMETHOD RemoveText();
|
||||||
|
NS_IMETHOD SetPassword(PRBool aIsPassword);
|
||||||
|
NS_IMETHOD SetReadOnly(PRBool aNewReadOnlyFlag, PRBool& aOldReadOnlyFlag);
|
||||||
|
NS_IMETHOD SetSelection(PRUint32 aStartSel, PRUint32 aEndSel);
|
||||||
|
NS_IMETHOD GetSelection(PRUint32 *aStartSel, PRUint32 *aEndSel);
|
||||||
|
NS_IMETHOD SetCaretPosition(PRUint32 aPosition);
|
||||||
|
NS_IMETHOD GetCaretPosition(PRUint32& aPosition);
|
||||||
|
|
||||||
|
NS_IMETHOD PreCreateWidget(nsWidgetInitData *aInitData);
|
||||||
|
|
||||||
|
virtual PRBool AutoErase();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
nsString mText;
|
||||||
|
PRBool mIsPassword;
|
||||||
|
PRBool mIsReadOnly;
|
||||||
|
BTextView *mTextView;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextFrameBeOS : public BView
|
||||||
|
{
|
||||||
|
BTextView *tv;
|
||||||
|
public:
|
||||||
|
TextFrameBeOS(BTextView *child, BRect frame, const char *name, uint32 resizingmode, uint32 flags);
|
||||||
|
void FrameResized(float width, float height);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsTextHelper_h__
|
|
@ -0,0 +1,289 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsTextWidget.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
|
#include "nsIDeviceContext.h"
|
||||||
|
#include "nsIFontMetrics.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kLookAndFeelCID, NS_LOOKANDFEEL_CID);
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsTextWidget)
|
||||||
|
NS_IMPL_RELEASE(nsTextWidget)
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextWidget constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTextWidget::nsTextWidget() : nsTextHelper()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mBackground = NS_RGB(124, 124, 124);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTextWidget destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTextWidget::~nsTextWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsTextWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsTextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kInsTextWidgetIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsITextWidget*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// move, paint, resizes message - ignore
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsTextWidget::OnMove(PRInt32, PRInt32)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsTextWidget::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PRBool nsTextWidget::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsTextWidget::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
#if 0
|
||||||
|
nsWindow::GetNonClientBounds(aRect);
|
||||||
|
#endif
|
||||||
|
printf("nsTextWidget::GetBounds not wrong\n"); // the following is just a placeholder
|
||||||
|
nsWindow::GetClientBounds(aRect);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the TextWidget for Printing
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
NS_METHOD nsTextWidget::Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect)
|
||||||
|
{
|
||||||
|
nsRect rect;
|
||||||
|
float appUnits;
|
||||||
|
float scale;
|
||||||
|
nsIDeviceContext * context;
|
||||||
|
aRenderingContext.GetDeviceContext(context);
|
||||||
|
|
||||||
|
context->GetCanonicalPixelScale(scale);
|
||||||
|
context->GetDevUnitsToAppUnits(appUnits);
|
||||||
|
|
||||||
|
GetBoundsAppUnits(rect, appUnits);
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(NS_RGB(0,0,0));
|
||||||
|
|
||||||
|
nscolor bgColor = NS_RGB(255,255,255);
|
||||||
|
nscolor fgColor = NS_RGB(0,0,0);
|
||||||
|
nscolor hltColor = NS_RGB(240,240,240);
|
||||||
|
nscolor sdwColor = NS_RGB(128,128,128);
|
||||||
|
nscolor txtBGColor = NS_RGB(255,255,255);
|
||||||
|
nscolor txtFGColor = NS_RGB(0,0,0);
|
||||||
|
nsILookAndFeel * lookAndFeel;
|
||||||
|
if (NS_OK == nsComponentManager::CreateInstance(kLookAndFeelCID, nsnull, kILookAndFeelIID, (void**)&lookAndFeel)) {
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetBackground, bgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_WidgetForeground, fgColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DShadow, sdwColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_Widget3DHighlight, hltColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextBackground, txtBGColor);
|
||||||
|
lookAndFeel->GetColor(nsILookAndFeel::eColor_TextForeground, txtFGColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
aRenderingContext.SetColor(txtBGColor);
|
||||||
|
aRenderingContext.FillRect(rect);
|
||||||
|
|
||||||
|
// Paint Black border
|
||||||
|
//nsBaseWidget::Paint(aRenderingContext, aDirtyRect);
|
||||||
|
|
||||||
|
nscoord onePixel = nscoord(scale);
|
||||||
|
nscoord twoPixels = nscoord(scale*2);
|
||||||
|
|
||||||
|
rect.x += onePixel;
|
||||||
|
rect.y += onePixel;
|
||||||
|
rect.width -= twoPixels+onePixel;
|
||||||
|
rect.height -= twoPixels+onePixel;
|
||||||
|
|
||||||
|
nscoord right = rect.x+rect.width;
|
||||||
|
nscoord bottom = rect.y+rect.height;
|
||||||
|
|
||||||
|
|
||||||
|
// Draw Left & Top
|
||||||
|
aRenderingContext.SetColor(NS_RGB(128,128,128));
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, right, rect.y, scale, appUnits, PR_TRUE); // top
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x, rect.y, rect.x, bottom, scale, appUnits, PR_FALSE); // left
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, right-onePixel, rect.y+onePixel, scale, appUnits, PR_TRUE); // top + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+onePixel, rect.y+onePixel, rect.x+onePixel, bottom-onePixel, scale, appUnits, PR_FALSE); // left + 1
|
||||||
|
|
||||||
|
// Draw Right & Bottom
|
||||||
|
aRenderingContext.SetColor(NS_RGB(192,192,192));
|
||||||
|
DrawScaledLine(aRenderingContext, right, rect.y+onePixel, right, bottom, scale, appUnits, PR_FALSE); // right
|
||||||
|
DrawScaledLine(aRenderingContext, rect.x+onePixel, bottom, right, bottom, scale, appUnits, PR_TRUE); // bottom
|
||||||
|
|
||||||
|
//DrawScaledLine(aRenderingContext, right-onePixel, rect.y+twoPixels, right-onePixel, bottom, scale, appUnits, PR_FALSE); // right + 1
|
||||||
|
//DrawScaledLine(aRenderingContext, rect.x+twoPixels, bottom-onePixel, right, bottom-onePixel, scale, appUnits, PR_TRUE); // bottom + 1
|
||||||
|
|
||||||
|
|
||||||
|
aRenderingContext.SetFont(*mFont);
|
||||||
|
|
||||||
|
nscoord textWidth;
|
||||||
|
nscoord textHeight;
|
||||||
|
aRenderingContext.GetWidth(mText, textWidth);
|
||||||
|
|
||||||
|
nsIFontMetrics* metrics;
|
||||||
|
context->GetMetricsFor(*mFont, metrics);
|
||||||
|
metrics->GetMaxAscent(textHeight);
|
||||||
|
|
||||||
|
nscoord x = (twoPixels * 2) + rect.x;
|
||||||
|
nscoord y = ((rect.height - textHeight) / 2) + rect.y;
|
||||||
|
aRenderingContext.SetColor(txtFGColor);
|
||||||
|
if (!mIsPassword) {
|
||||||
|
aRenderingContext.DrawString(mText, x, y);
|
||||||
|
} else {
|
||||||
|
nsString astricks;
|
||||||
|
PRInt32 i;
|
||||||
|
for (i=0;i<mText.Length();i++) {
|
||||||
|
astricks.Append("*");
|
||||||
|
}
|
||||||
|
aRenderingContext.DrawString(astricks, x, y);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_RELEASE(context);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
BView *nsTextWidget::CreateBeOSView()
|
||||||
|
{
|
||||||
|
mTextView = new nsTextViewBeOS(this, BRect(0, 0, 0, 0), B_EMPTY_STRING, BRect(0, 0, 0, 0), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
|
||||||
|
return new TextFrameBeOS(mTextView, BRect(0, 0, 0, 0), B_EMPTY_STRING, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------
|
||||||
|
// BeOS Sub-Class TextView
|
||||||
|
//----------------------------------------------------
|
||||||
|
|
||||||
|
nsTextViewBeOS::nsTextViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame,
|
||||||
|
const char *aName, BRect aTextRect, uint32 aResizingMode,
|
||||||
|
uint32 aFlags )
|
||||||
|
: BTextView( aFrame, aName, aTextRect, aResizingMode, aFlags ),
|
||||||
|
nsIWidgetStore( aWidgetWindow )
|
||||||
|
{
|
||||||
|
DisallowChar(10);
|
||||||
|
DisallowChar(13);
|
||||||
|
SetMaxBytes(256);
|
||||||
|
SetWordWrap(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsTextViewBeOS::KeyDown(const char *bytes, int32 numBytes)
|
||||||
|
{
|
||||||
|
// call back if not enter/return
|
||||||
|
if(numBytes != 1 || (bytes[0] != 10 && bytes[0] != 13))
|
||||||
|
BTextView::KeyDown(bytes, numBytes);
|
||||||
|
|
||||||
|
nsWindow *w = (nsWindow *)GetMozillaWidget();
|
||||||
|
nsToolkit *t;
|
||||||
|
if(w && (t = w->GetToolkit()) != 0)
|
||||||
|
{
|
||||||
|
uint32 bytebuf = 0;
|
||||||
|
uint8 *byteptr = (uint8 *)&bytebuf;
|
||||||
|
for(int32 i = 0; i < numBytes; i++)
|
||||||
|
byteptr[i] = bytes[i];
|
||||||
|
|
||||||
|
uint32 args[4];
|
||||||
|
args[0] = NS_KEY_DOWN;
|
||||||
|
args[1] = bytebuf;
|
||||||
|
args[2] = numBytes;
|
||||||
|
args[3] = modifiers();
|
||||||
|
|
||||||
|
MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args);
|
||||||
|
t->CallMethodAsync(info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsTextViewBeOS::KeyUp(const char *bytes, int32 numBytes)
|
||||||
|
{
|
||||||
|
// call back if not enter/return
|
||||||
|
if(numBytes != 1 || (bytes[0] != 10 && bytes[0] != 13))
|
||||||
|
BTextView::KeyUp(bytes, numBytes);
|
||||||
|
|
||||||
|
nsWindow *w = (nsWindow *)GetMozillaWidget();
|
||||||
|
nsToolkit *t;
|
||||||
|
if(w && (t = w->GetToolkit()) != 0)
|
||||||
|
{
|
||||||
|
uint32 bytebuf = 0;
|
||||||
|
uint8 *byteptr = (uint8 *)&bytebuf;
|
||||||
|
for(int32 i = 0; i < numBytes; i++)
|
||||||
|
byteptr[i] = bytes[i];
|
||||||
|
|
||||||
|
uint32 args[4];
|
||||||
|
args[0] = NS_KEY_UP;
|
||||||
|
args[1] = (int32)bytebuf;
|
||||||
|
args[2] = numBytes;
|
||||||
|
args[3] = modifiers();
|
||||||
|
|
||||||
|
MethodInfo *info = new MethodInfo(w, w, nsWindow::ONKEY, 4, args);
|
||||||
|
t->CallMethodAsync(info);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,70 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTextWidget_h__
|
||||||
|
#define nsTextWidget_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsTextHelper.h"
|
||||||
|
|
||||||
|
#include "nsITextWidget.h"
|
||||||
|
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native WIN32 single line edit control wrapper.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsTextWidget : public nsTextHelper
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsTextWidget();
|
||||||
|
virtual ~nsTextWidget();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
|
||||||
|
NS_IMETHOD Paint(nsIRenderingContext& aRenderingContext,
|
||||||
|
const nsRect& aDirtyRect);
|
||||||
|
protected:
|
||||||
|
BView *CreateBeOSView();
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BTextView subclass
|
||||||
|
//
|
||||||
|
class nsTextViewBeOS : public BTextView, public nsIWidgetStore
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
nsTextViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
BRect aTextRect, uint32 aResizingMode, uint32 aFlags );
|
||||||
|
void KeyDown(const char *bytes, int32 numbytes);
|
||||||
|
void KeyUp(const char *bytes, int32 numbytes);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsTextWidget_h__
|
|
@ -0,0 +1,271 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "prmon.h"
|
||||||
|
#include "prtime.h"
|
||||||
|
#include "nsITimer.h"
|
||||||
|
#include "nsTimer.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "plevent.h"
|
||||||
|
|
||||||
|
//NS_IMPL_ISUPPORTS(nsToolkit, NS_ITOOLKIT_IID)
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsISupports implementation macro
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_DEFINE_IID(kIToolkitIID, NS_ITOOLKIT_IID);
|
||||||
|
NS_IMPL_ISUPPORTS(nsToolkit,kIToolkitIID);
|
||||||
|
|
||||||
|
struct ThreadInterfaceData
|
||||||
|
{
|
||||||
|
void *data;
|
||||||
|
int32 sync;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// main for the message pump thread
|
||||||
|
//
|
||||||
|
PRBool gThreadState = PR_FALSE;
|
||||||
|
|
||||||
|
static sem_id my_find_sem(const char *name)
|
||||||
|
{
|
||||||
|
sem_id ret = B_ERROR;
|
||||||
|
|
||||||
|
/* Get the sem_info for every sempahore in this team. */
|
||||||
|
sem_info info;
|
||||||
|
int32 cookie = 0;
|
||||||
|
|
||||||
|
while(get_next_sem_info(0, &cookie, &info) == B_OK)
|
||||||
|
if(strcmp(name, info.name) == 0)
|
||||||
|
{
|
||||||
|
ret = info.sem;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ThreadInitInfo {
|
||||||
|
PRMonitor *monitor;
|
||||||
|
nsToolkit *toolkit;
|
||||||
|
};
|
||||||
|
|
||||||
|
void nsToolkit::RunPump(void* arg)
|
||||||
|
{
|
||||||
|
int32 code;
|
||||||
|
char portname[64];
|
||||||
|
char semname[64];
|
||||||
|
ThreadInterfaceData id;
|
||||||
|
|
||||||
|
ThreadInitInfo *info = (ThreadInitInfo*)arg;
|
||||||
|
::PR_EnterMonitor(info->monitor);
|
||||||
|
|
||||||
|
gThreadState = PR_TRUE;
|
||||||
|
|
||||||
|
::PR_Notify(info->monitor);
|
||||||
|
::PR_ExitMonitor(info->monitor);
|
||||||
|
|
||||||
|
delete info;
|
||||||
|
|
||||||
|
// system wide unique names
|
||||||
|
sprintf(portname, "event%lx", PR_GetCurrentThread());
|
||||||
|
sprintf(semname, "sync%lx", PR_GetCurrentThread());
|
||||||
|
|
||||||
|
port_id event = create_port(100, portname);
|
||||||
|
sem_id sync = create_sem(0, semname);
|
||||||
|
|
||||||
|
while(read_port(event, &code, &id, sizeof(id)) >= 0)
|
||||||
|
{
|
||||||
|
switch(code)
|
||||||
|
{
|
||||||
|
case WM_TIMER :
|
||||||
|
{
|
||||||
|
TimerImpl *tobj = (TimerImpl *)id.data;
|
||||||
|
tobj->FireTimeout();
|
||||||
|
if(! id.sync)
|
||||||
|
NS_RELEASE(tobj);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_CALLMETHOD :
|
||||||
|
{
|
||||||
|
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||||
|
mInfo->Invoke();
|
||||||
|
if(! id.sync)
|
||||||
|
delete mInfo;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'natv' : // native queue PLEvent
|
||||||
|
{
|
||||||
|
PREventQueue *queue = (PREventQueue *)id.data;
|
||||||
|
PR_ProcessPendingEvents(queue);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default :
|
||||||
|
printf("nsToolkit::RunPump - UNKNOWN EVENT\n");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(id.sync)
|
||||||
|
release_sem(sync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsToolkit::nsToolkit()
|
||||||
|
{
|
||||||
|
localthread = false;
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mGuiThread = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsToolkit::~nsToolkit()
|
||||||
|
{
|
||||||
|
Kill();
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsToolkit::Kill()
|
||||||
|
{
|
||||||
|
if(localthread)
|
||||||
|
{
|
||||||
|
GetInterface();
|
||||||
|
|
||||||
|
// interrupt message flow
|
||||||
|
close_port(eventport);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Create a new thread and run the message pump in there
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
void nsToolkit::CreateUIThread()
|
||||||
|
{
|
||||||
|
PRMonitor *monitor = ::PR_NewMonitor();
|
||||||
|
|
||||||
|
::PR_EnterMonitor(monitor);
|
||||||
|
|
||||||
|
ThreadInitInfo *ti = new ThreadInitInfo();
|
||||||
|
ti->monitor = monitor;
|
||||||
|
ti->toolkit = this;
|
||||||
|
|
||||||
|
// create a gui thread
|
||||||
|
mGuiThread = ::PR_CreateThread(PR_SYSTEM_THREAD,
|
||||||
|
RunPump,
|
||||||
|
(void*)ti,
|
||||||
|
PR_PRIORITY_NORMAL,
|
||||||
|
PR_LOCAL_THREAD,
|
||||||
|
PR_UNJOINABLE_THREAD,
|
||||||
|
0);
|
||||||
|
|
||||||
|
// wait for the gui thread to start
|
||||||
|
while(gThreadState == PR_FALSE)
|
||||||
|
::PR_Wait(monitor, PR_INTERVAL_NO_TIMEOUT);
|
||||||
|
|
||||||
|
// at this point the thread is running
|
||||||
|
::PR_ExitMonitor(monitor);
|
||||||
|
::PR_DestroyMonitor(monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
NS_METHOD nsToolkit::Init(PRThread *aThread)
|
||||||
|
{
|
||||||
|
Kill();
|
||||||
|
|
||||||
|
// Store the thread ID of the thread containing the message pump.
|
||||||
|
// If no thread is provided create one
|
||||||
|
if (NULL != aThread) {
|
||||||
|
mGuiThread = aThread;
|
||||||
|
localthread = false;
|
||||||
|
} else {
|
||||||
|
localthread = true;
|
||||||
|
|
||||||
|
// create a thread where the message pump will run
|
||||||
|
CreateUIThread();
|
||||||
|
}
|
||||||
|
|
||||||
|
cached = false;
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsToolkit::GetInterface()
|
||||||
|
{
|
||||||
|
if(! cached)
|
||||||
|
{
|
||||||
|
char portname[64];
|
||||||
|
char semname[64];
|
||||||
|
|
||||||
|
sprintf(portname, "event%lx", mGuiThread);
|
||||||
|
sprintf(semname, "sync%lx", mGuiThread);
|
||||||
|
|
||||||
|
eventport = find_port(portname);
|
||||||
|
syncsem = my_find_sem(semname);
|
||||||
|
|
||||||
|
cached = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nsToolkit::CallMethod(MethodInfo *info)
|
||||||
|
{
|
||||||
|
ThreadInterfaceData id;
|
||||||
|
|
||||||
|
GetInterface();
|
||||||
|
|
||||||
|
id.data = info;
|
||||||
|
id.sync = true;
|
||||||
|
if(write_port(eventport, WM_CALLMETHOD, &id, sizeof(id)) == B_OK)
|
||||||
|
{
|
||||||
|
// semantics for CallMethod are that it should be synchronous
|
||||||
|
while(acquire_sem(syncsem) == B_INTERRUPTED)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// to be used only from a BView or BWindow
|
||||||
|
void nsToolkit::CallMethodAsync(MethodInfo *info)
|
||||||
|
{
|
||||||
|
ThreadInterfaceData id;
|
||||||
|
|
||||||
|
GetInterface();
|
||||||
|
|
||||||
|
id.data = info;
|
||||||
|
id.sync = false;
|
||||||
|
write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0);
|
||||||
|
}
|
|
@ -0,0 +1,68 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TOOLKIT_H
|
||||||
|
#define TOOLKIT_H
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsIToolkit.h"
|
||||||
|
|
||||||
|
#include <OS.h>
|
||||||
|
|
||||||
|
struct MethodInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Wrapper around the thread running the message pump.
|
||||||
|
* The toolkit abstraction is necessary because the message pump must
|
||||||
|
* execute within the same thread that created the widget under Win32.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsToolkit : public nsIToolkit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
nsToolkit();
|
||||||
|
NS_IMETHOD Init(PRThread *aThread);
|
||||||
|
void CallMethod(MethodInfo *info);
|
||||||
|
void CallMethodAsync(MethodInfo *info);
|
||||||
|
// Return whether the current thread is the application's Gui thread.
|
||||||
|
PRBool IsGuiThread(void) { return (PRBool)(mGuiThread == PR_GetCurrentThread());}
|
||||||
|
PRThread* GetGuiThread(void) { return mGuiThread; }
|
||||||
|
void Kill();
|
||||||
|
|
||||||
|
private:
|
||||||
|
virtual ~nsToolkit();
|
||||||
|
void CreateUIThread(void);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Thread Id of the "main" Gui thread.
|
||||||
|
PRThread *mGuiThread;
|
||||||
|
static void RunPump(void* arg);
|
||||||
|
void GetInterface();
|
||||||
|
bool cached;
|
||||||
|
bool localthread;
|
||||||
|
port_id eventport;
|
||||||
|
sem_id syncsem;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define WM_CALLMETHOD 'CAme'
|
||||||
|
|
||||||
|
class nsWindow;
|
||||||
|
|
||||||
|
#endif // TOOLKIT_H
|
|
@ -0,0 +1,107 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsTooltipWidget.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsColor.h"
|
||||||
|
#include "nsGUIEvent.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsTooltipWidget)
|
||||||
|
NS_IMPL_RELEASE(nsTooltipWidget)
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTooltipWidget constructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTooltipWidget::nsTooltipWidget()
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// nsTooltipWidget destructor
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsTooltipWidget::~nsTooltipWidget()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Query interface implementation
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
nsresult nsTooltipWidget::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||||
|
{
|
||||||
|
nsresult result = nsWindow::QueryInterface(aIID, aInstancePtr);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kInsTooltipWidgetIID, NS_ITOOLTIPWIDGET_IID);
|
||||||
|
if (result == NS_NOINTERFACE && aIID.Equals(kInsTooltipWidgetIID)) {
|
||||||
|
*aInstancePtr = (void*) ((nsITooltipWidget*)this);
|
||||||
|
NS_ADDREF_THIS();
|
||||||
|
result = NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// paint message. Don't send the paint out
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
PRBool nsTooltipWidget::OnPaint(nsRect &r)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRBool nsTooltipWidget::OnResize(nsRect &aWindowRect)
|
||||||
|
{
|
||||||
|
return PR_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Clear window before paint
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
PRBool nsTooltipWidget::AutoErase()
|
||||||
|
{
|
||||||
|
return(PR_TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// get position/dimensions
|
||||||
|
//
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
NS_METHOD nsTooltipWidget::GetBounds(nsRect &aRect)
|
||||||
|
{
|
||||||
|
return nsWindow::GetBounds(aRect);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef nsTooltipWidget_h__
|
||||||
|
#define nsTooltipWidget_h__
|
||||||
|
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
|
||||||
|
#include "nsITooltipWidget.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native Win32 tooltip window wrapper
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsTooltipWidget : public nsWindow,
|
||||||
|
public nsITooltipWidget
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsTooltipWidget();
|
||||||
|
virtual ~nsTooltipWidget();
|
||||||
|
|
||||||
|
// nsISupports
|
||||||
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||||
|
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||||
|
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||||
|
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
virtual PRBool AutoErase();
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // nsTooltipWidget_h__
|
|
@ -0,0 +1,267 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "nsIFactory.h"
|
||||||
|
#include "nsISupports.h"
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsWidgetsCID.h"
|
||||||
|
|
||||||
|
#include "nsButton.h"
|
||||||
|
#include "nsCheckButton.h"
|
||||||
|
#include "nsComboBox.h"
|
||||||
|
#include "nsFileWidget.h"
|
||||||
|
#include "nsListBox.h"
|
||||||
|
#include "nsLookAndFeel.h"
|
||||||
|
#include "nsRadioButton.h"
|
||||||
|
#include "nsScrollbar.h"
|
||||||
|
#include "nsTextAreaWidget.h"
|
||||||
|
#include "nsTextHelper.h"
|
||||||
|
#include "nsTextWidget.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
#include "nsTabWidget.h"
|
||||||
|
#include "nsTooltipWidget.h"
|
||||||
|
#include "nsWindow.h"
|
||||||
|
#include "nsDialog.h"
|
||||||
|
#include "nsLabel.h"
|
||||||
|
#include "nsMenuBar.h"
|
||||||
|
#include "nsMenu.h"
|
||||||
|
#include "nsMenuItem.h"
|
||||||
|
#include "nsPopUpMenu.h"
|
||||||
|
#include "nsImageButton.h"
|
||||||
|
#include "nsMenuButton.h"
|
||||||
|
#include "nsAppShell.h"
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID);
|
||||||
|
static NS_DEFINE_IID(kCChild, NS_CHILD_CID);
|
||||||
|
static NS_DEFINE_IID(kCButton, NS_BUTTON_CID);
|
||||||
|
static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID);
|
||||||
|
static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID);
|
||||||
|
static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID);
|
||||||
|
static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID);
|
||||||
|
static NS_DEFINE_IID(kCRadioButton, NS_RADIOBUTTON_CID);
|
||||||
|
static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID);
|
||||||
|
static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID);
|
||||||
|
static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID);
|
||||||
|
static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID);
|
||||||
|
static NS_DEFINE_IID(kCTabWidget, NS_TABWIDGET_CID);
|
||||||
|
static NS_DEFINE_IID(kCTooltipWidget, NS_TOOLTIPWIDGET_CID);
|
||||||
|
static NS_DEFINE_IID(kCAppShell, NS_APPSHELL_CID);
|
||||||
|
static NS_DEFINE_IID(kCToolkit, NS_TOOLKIT_CID);
|
||||||
|
static NS_DEFINE_IID(kCLookAndFeel, NS_LOOKANDFEEL_CID);
|
||||||
|
static NS_DEFINE_IID(kCDialog, NS_DIALOG_CID);
|
||||||
|
static NS_DEFINE_IID(kCLabel, NS_LABEL_CID);
|
||||||
|
static NS_DEFINE_IID(kCMenuBar, NS_MENUBAR_CID);
|
||||||
|
static NS_DEFINE_IID(kCMenu, NS_MENU_CID);
|
||||||
|
static NS_DEFINE_IID(kCMenuItem, NS_MENUITEM_CID);
|
||||||
|
static NS_DEFINE_IID(kCImageButton, NS_IMAGEBUTTON_CID);
|
||||||
|
static NS_DEFINE_IID(kCPopUpMenu, NS_POPUPMENU_CID);
|
||||||
|
static NS_DEFINE_IID(kCMenuButton, NS_MENUBUTTON_CID);
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
|
|
||||||
|
class nsWidgetFactory : public nsIFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// nsISupports methods
|
||||||
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
// nsIFactory methods
|
||||||
|
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||||
|
const nsIID &aIID,
|
||||||
|
void **aResult);
|
||||||
|
|
||||||
|
NS_IMETHOD LockFactory(PRBool aLock);
|
||||||
|
|
||||||
|
nsWidgetFactory(const nsCID &aClass);
|
||||||
|
~nsWidgetFactory();
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsCID mClassID;
|
||||||
|
};
|
||||||
|
|
||||||
|
NS_IMPL_ADDREF(nsWidgetFactory)
|
||||||
|
NS_IMPL_RELEASE(nsWidgetFactory)
|
||||||
|
|
||||||
|
|
||||||
|
nsWidgetFactory::nsWidgetFactory(const nsCID &aClass)
|
||||||
|
{
|
||||||
|
NS_INIT_REFCNT();
|
||||||
|
mClassID = aClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsWidgetFactory::~nsWidgetFactory()
|
||||||
|
{
|
||||||
|
NS_ASSERTION(mRefCnt == 0, "Reference count not zero in destructor");
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsWidgetFactory::QueryInterface(const nsIID &aIID,
|
||||||
|
void **aResult)
|
||||||
|
{
|
||||||
|
if (aResult == NULL) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always NULL result, in case of failure
|
||||||
|
*aResult = NULL;
|
||||||
|
|
||||||
|
if (aIID.Equals(kISupportsIID)) {
|
||||||
|
*aResult = (void *)(nsISupports*)this;
|
||||||
|
} else if (aIID.Equals(kIFactoryIID)) {
|
||||||
|
*aResult = (void *)(nsIFactory*)this;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*aResult == NULL) {
|
||||||
|
return NS_NOINTERFACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ADDREF_THIS(); // Increase reference count for caller
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
nsresult nsWidgetFactory::CreateInstance( nsISupports* aOuter,
|
||||||
|
const nsIID &aIID,
|
||||||
|
void **aResult)
|
||||||
|
{
|
||||||
|
if (aResult == NULL) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
*aResult = NULL;
|
||||||
|
if (nsnull != aOuter) {
|
||||||
|
return NS_ERROR_NO_AGGREGATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsISupports *inst = nsnull;
|
||||||
|
if (mClassID.Equals(kCWindow) ||
|
||||||
|
mClassID.Equals(kCChild)) {
|
||||||
|
inst = (nsISupports*)new nsWindow();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCButton)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsButton();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCCheckButton)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsCheckButton();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCCombobox)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsComboBox();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCRadioButton)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsRadioButton();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCFileOpen)) {
|
||||||
|
inst = (nsISupports*)new nsFileWidget();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCListbox)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsListBox();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCHorzScrollbar)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsScrollbar(PR_FALSE);
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCVertScrollbar)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsScrollbar(PR_TRUE);
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCTextArea)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsTextAreaWidget();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCTextField)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsTextWidget();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCTabWidget)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsTabWidget();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCTooltipWidget)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsTooltipWidget();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCAppShell)) {
|
||||||
|
inst = (nsISupports*)new nsAppShell();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCToolkit)) {
|
||||||
|
inst = (nsISupports*)new nsToolkit();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCLookAndFeel)) {
|
||||||
|
inst = (nsISupports*)new nsLookAndFeel();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCDialog)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsDialog();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCLabel)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsLabel();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCMenuBar)) {
|
||||||
|
inst = (nsISupports*)(nsIMenuBar*) new nsMenuBar();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCMenu)) {
|
||||||
|
inst = (nsISupports*)(nsIMenu*) new nsMenu();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCMenuItem)) {
|
||||||
|
inst = (nsISupports*)(nsIMenuItem*) new nsMenuItem();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCImageButton)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsImageButton();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCMenuButton)) {
|
||||||
|
inst = (nsISupports*)(nsWindow*)new nsMenuButton();
|
||||||
|
}
|
||||||
|
else if (mClassID.Equals(kCPopUpMenu)) {
|
||||||
|
inst = (nsISupports*)new nsPopUpMenu();
|
||||||
|
}
|
||||||
|
/* */
|
||||||
|
|
||||||
|
if (inst == NULL) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||||
|
|
||||||
|
if (res != NS_OK) {
|
||||||
|
// We didn't get the right interface, so clean up
|
||||||
|
delete inst;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult nsWidgetFactory::LockFactory(PRBool aLock)
|
||||||
|
{
|
||||||
|
// Not implemented in simplest case.
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the proper factory to the caller
|
||||||
|
extern "C" NS_WIDGET nsresult
|
||||||
|
NSGetFactory(nsISupports* serviceMgr,
|
||||||
|
const nsCID &aClass,
|
||||||
|
const char *aClassName,
|
||||||
|
const char *aProgID,
|
||||||
|
nsIFactory **aFactory)
|
||||||
|
{
|
||||||
|
if (nsnull == aFactory) {
|
||||||
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
*aFactory = new nsWidgetFactory(aClass);
|
||||||
|
|
||||||
|
if (nsnull == aFactory) {
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,467 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "nsWidgetSupport.h"
|
||||||
|
#include "nsRect.h"
|
||||||
|
#include "nsITextAreaWidget.h"
|
||||||
|
#include "nsIFileWidget.h"
|
||||||
|
#include "nsIAppShell.h"
|
||||||
|
#include "nsIButton.h"
|
||||||
|
#include "nsIComboBox.h"
|
||||||
|
#include "nsIEventListener.h"
|
||||||
|
#include "nsILabel.h"
|
||||||
|
#include "nsIListBox.h"
|
||||||
|
#include "nsIListWidget.h"
|
||||||
|
#include "nsILookAndFeel.h"
|
||||||
|
#include "nsIMouseListener.h"
|
||||||
|
#include "nsITabWidget.h"
|
||||||
|
#include "nsIToolkit.h"
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
#include "nsIDialog.h"
|
||||||
|
#include "nsICheckButton.h"
|
||||||
|
#include "nsIScrollbar.h"
|
||||||
|
#include "nsIRadioButton.h"
|
||||||
|
#include "nsITooltipWidget.h"
|
||||||
|
#include "nsITextWidget.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
|
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||||
|
static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||||
|
static NS_DEFINE_IID(kIButtonIID, NS_IBUTTON_IID);
|
||||||
|
static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID);
|
||||||
|
static NS_DEFINE_IID(kITextWidgetIID, NS_ITEXTWIDGET_IID);
|
||||||
|
static NS_DEFINE_IID(kIDialogIID, NS_IDIALOG_IID);
|
||||||
|
static NS_DEFINE_IID(kICheckButtonIID, NS_ICHECKBUTTON_IID);
|
||||||
|
static NS_DEFINE_IID(kIRadioButtonIID, NS_IRADIOBUTTON_IID);
|
||||||
|
static NS_DEFINE_IID(kILabelIID, NS_ILABEL_IID);
|
||||||
|
static NS_DEFINE_IID(kIScrollBarIID, NS_ISCROLLBAR_IID);
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateDialog(nsISupports* aParent,
|
||||||
|
nsIDialog* aDialog,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aDialog->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
if (aParent != nsnull)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateButton(nsISupports* aParent,
|
||||||
|
nsIButton* aButton,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent != nsnull)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateCheckButton(nsISupports* aParent,
|
||||||
|
nsICheckButton* aCheckButton,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aCheckButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
if (aParent != nsnull)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateRadioButton( nsISupports* aParent,
|
||||||
|
nsIRadioButton* aRadioButton,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aRadioButton->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
if (aParent != nsnull)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateLabel( nsISupports* aParent,
|
||||||
|
nsILabel* aLabel,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (NS_OK == aParent->QueryInterface(kIWidgetIID,(void**)&parent))
|
||||||
|
{
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aLabel->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateTextAreaWidget(nsISupports* aParent,
|
||||||
|
nsITextAreaWidget* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateTextWidget(nsISupports* aParent,
|
||||||
|
nsITextWidget* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateScrollBar(nsISupports* aParent,
|
||||||
|
nsIScrollbar* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateListBox(nsISupports* aParent,
|
||||||
|
nsIListBox* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateComboBox(nsISupports* aParent,
|
||||||
|
nsIComboBox* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
NS_WIDGET nsresult
|
||||||
|
NS_CreateTabWidget(nsISupports* aParent,
|
||||||
|
nsITabWidget* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Called QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_CreateTooltipWidget(nsISupports* aParent,
|
||||||
|
nsITooltipWidget* aWidget,
|
||||||
|
const nsRect& aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
const nsFont* aFont)
|
||||||
|
{
|
||||||
|
nsIWidget* parent = nsnull;
|
||||||
|
if (aParent != nsnull)
|
||||||
|
aParent->QueryInterface(kIWidgetIID,(void**)&parent);
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Create(parent, aRect, aHandleEventFunction, NULL);
|
||||||
|
widget->Show(PR_TRUE);
|
||||||
|
if (aFont != nsnull)
|
||||||
|
widget->SetFont(*aFont);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NS_ERROR("Call QueryInterface on a non kIWidgetIID supported object");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (aParent)
|
||||||
|
NS_IF_RELEASE(parent);
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_ShowWidget(nsISupports* aWidget, PRBool aShow)
|
||||||
|
{
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Show(aShow);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_MoveWidget(nsISupports* aWidget, PRUint32 aX, PRUint32 aY)
|
||||||
|
{
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->Move(aX,aY);
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_EnableWidget(nsISupports* aWidget, PRBool aEnable)
|
||||||
|
{
|
||||||
|
#if 0 // YK990522 was unused
|
||||||
|
void* result = nsnull;
|
||||||
|
#endif
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
|
||||||
|
{
|
||||||
|
widget->Enable(aEnable);
|
||||||
|
NS_RELEASE(widget);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_SetFocusToWidget(nsISupports* aWidget)
|
||||||
|
{
|
||||||
|
|
||||||
|
nsIWidget* widget = nsnull;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget)) {
|
||||||
|
widget->SetFocus();
|
||||||
|
NS_IF_RELEASE(widget);
|
||||||
|
}
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
extern NS_WIDGET nsresult
|
||||||
|
NS_GetWidgetNativeData(nsISupports* aWidget, void** aNativeData)
|
||||||
|
{
|
||||||
|
void* result = nsnull;
|
||||||
|
nsIWidget* widget;
|
||||||
|
if (NS_OK == aWidget->QueryInterface(kIWidgetIID,(void**)&widget))
|
||||||
|
{
|
||||||
|
result = widget->GetNativeData(NS_NATIVE_WIDGET);
|
||||||
|
NS_RELEASE(widget);
|
||||||
|
}
|
||||||
|
*aNativeData = result;
|
||||||
|
return NS_OK;
|
||||||
|
|
||||||
|
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,297 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#ifndef Window_h__
|
||||||
|
#define Window_h__
|
||||||
|
|
||||||
|
#include "nsBaseWidget.h"
|
||||||
|
#include "nsdefs.h"
|
||||||
|
#include "nsObject.h"
|
||||||
|
#include "nsSwitchToUIThread.h"
|
||||||
|
#include "nsToolkit.h"
|
||||||
|
|
||||||
|
#include "nsIWidget.h"
|
||||||
|
|
||||||
|
#include "nsIMenuBar.h"
|
||||||
|
|
||||||
|
#include "nsIMouseListener.h"
|
||||||
|
#include "nsIEventListener.h"
|
||||||
|
#include "nsStringUtil.h"
|
||||||
|
#include "nsString.h"
|
||||||
|
|
||||||
|
#include "nsVoidArray.h"
|
||||||
|
|
||||||
|
#include <Window.h>
|
||||||
|
#include <View.h>
|
||||||
|
#include <Region.h>
|
||||||
|
|
||||||
|
#define NSRGB_2_COLOREF(color) \
|
||||||
|
RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
|
||||||
|
|
||||||
|
//#define DRAG_DROP
|
||||||
|
|
||||||
|
// forward declaration
|
||||||
|
class nsViewBeOS;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Native BeOS window wrapper.
|
||||||
|
*/
|
||||||
|
|
||||||
|
class nsWindow : public nsObject,
|
||||||
|
public nsSwitchToUIThread,
|
||||||
|
public nsBaseWidget
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsWindow();
|
||||||
|
virtual ~nsWindow();
|
||||||
|
|
||||||
|
// nsIWidget interface
|
||||||
|
NS_IMETHOD Create(nsIWidget *aParent,
|
||||||
|
const nsRect &aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
nsIDeviceContext *aContext,
|
||||||
|
nsIAppShell *aAppShell = nsnull,
|
||||||
|
nsIToolkit *aToolkit = nsnull,
|
||||||
|
nsWidgetInitData *aInitData = nsnull);
|
||||||
|
NS_IMETHOD Create(nsNativeWidget aParent,
|
||||||
|
const nsRect &aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
nsIDeviceContext *aContext,
|
||||||
|
nsIAppShell *aAppShell = nsnull,
|
||||||
|
nsIToolkit *aToolkit = nsnull,
|
||||||
|
nsWidgetInitData *aInitData = nsnull);
|
||||||
|
|
||||||
|
// Utility method for implementing both Create(nsIWidget ...) and
|
||||||
|
// Create(nsNativeWidget...)
|
||||||
|
|
||||||
|
virtual nsresult StandardWindowCreate(nsIWidget *aParent,
|
||||||
|
const nsRect &aRect,
|
||||||
|
EVENT_CALLBACK aHandleEventFunction,
|
||||||
|
nsIDeviceContext *aContext,
|
||||||
|
nsIAppShell *aAppShell,
|
||||||
|
nsIToolkit *aToolkit,
|
||||||
|
nsWidgetInitData *aInitData,
|
||||||
|
nsNativeWidget aNativeParent = nsnull);
|
||||||
|
|
||||||
|
NS_IMETHOD Destroy();
|
||||||
|
virtual nsIWidget* GetParent(void);
|
||||||
|
NS_IMETHOD Show(PRBool bState);
|
||||||
|
NS_IMETHOD IsVisible(PRBool & aState);
|
||||||
|
|
||||||
|
NS_IMETHOD Move(PRUint32 aX, PRUint32 aY);
|
||||||
|
NS_IMETHOD Resize(PRUint32 aWidth,
|
||||||
|
PRUint32 aHeight,
|
||||||
|
PRBool aRepaint);
|
||||||
|
NS_IMETHOD Resize(PRUint32 aX,
|
||||||
|
PRUint32 aY,
|
||||||
|
PRUint32 aWidth,
|
||||||
|
PRUint32 aHeight,
|
||||||
|
PRBool aRepaint);
|
||||||
|
NS_IMETHOD Enable(PRBool bState);
|
||||||
|
NS_IMETHOD SetFocus(void);
|
||||||
|
NS_IMETHOD GetBounds(nsRect &aRect);
|
||||||
|
NS_IMETHOD GetClientBounds(nsRect &aRect);
|
||||||
|
NS_IMETHOD SetBackgroundColor(const nscolor &aColor);
|
||||||
|
virtual nsIFontMetrics* GetFont(void);
|
||||||
|
NS_IMETHOD SetFont(const nsFont &aFont);
|
||||||
|
NS_IMETHOD SetCursor(nsCursor aCursor);
|
||||||
|
NS_IMETHOD Invalidate(PRBool aIsSynchronous);
|
||||||
|
NS_IMETHOD Invalidate(const nsRect & aRect, PRBool aIsSynchronous);
|
||||||
|
NS_IMETHOD Update();
|
||||||
|
virtual void* GetNativeData(PRUint32 aDataType);
|
||||||
|
NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
|
||||||
|
NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
|
||||||
|
NS_IMETHOD SetTitle(const nsString& aTitle);
|
||||||
|
NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar);
|
||||||
|
NS_IMETHOD ShowMenuBar(PRBool aShow);
|
||||||
|
NS_IMETHOD IsMenuBarVisible(PRBool *aVisible);
|
||||||
|
NS_IMETHOD SetTooltips(PRUint32 aNumberOfTips,nsRect* aTooltipAreas[]);
|
||||||
|
NS_IMETHOD RemoveTooltips();
|
||||||
|
NS_IMETHOD UpdateTooltips(nsRect* aNewTips[]);
|
||||||
|
NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
|
||||||
|
NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
|
||||||
|
NS_IMETHOD BeginResizingChildren(void);
|
||||||
|
NS_IMETHOD EndResizingChildren(void);
|
||||||
|
NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
|
||||||
|
NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
|
||||||
|
NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
|
||||||
|
NS_IMETHOD EnableFileDrop(PRBool aEnable);
|
||||||
|
|
||||||
|
virtual void ConvertToDeviceCoordinates(nscoord &aX,nscoord &aY) {}
|
||||||
|
|
||||||
|
|
||||||
|
// nsSwitchToUIThread interface
|
||||||
|
virtual bool CallMethod(MethodInfo *info);
|
||||||
|
virtual PRBool DispatchMouseEvent(PRUint32 aEventType, nsPoint aPoint, PRUint32 clicks, PRUint32 mod);
|
||||||
|
virtual PRBool AutoErase();
|
||||||
|
|
||||||
|
// PRInt32 GetNewCmdMenuId() { mMenuCmdId++; return mMenuCmdId;}
|
||||||
|
|
||||||
|
void InitEvent(nsGUIEvent& event, PRUint32 aEventType, nsPoint* aPoint = nsnull);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Allow Derived classes to modify the height that is passed
|
||||||
|
// when the window is created or resized.
|
||||||
|
virtual PRInt32 GetHeight(PRInt32 aProposedHeight);
|
||||||
|
virtual void OnDestroy();
|
||||||
|
virtual PRBool OnMove(PRInt32 aX, PRInt32 aY);
|
||||||
|
virtual PRBool OnPaint(nsRect &r);
|
||||||
|
virtual PRBool OnResize(nsRect &aWindowRect);
|
||||||
|
virtual PRBool OnKey(PRUint32 aEventType, const char *bytes, int32 numBytes, PRUint32 mod);
|
||||||
|
|
||||||
|
virtual PRBool DispatchFocus(PRUint32 aEventType);
|
||||||
|
virtual PRBool OnScroll();
|
||||||
|
static PRBool ConvertStatus(nsEventStatus aStatus);
|
||||||
|
PRBool DispatchStandardEvent(PRUint32 aMsg);
|
||||||
|
void AddTooltip(BView *hwndOwner, nsRect* aRect, int aId);
|
||||||
|
|
||||||
|
virtual PRBool DispatchWindowEvent(nsGUIEvent* event);
|
||||||
|
virtual BView *CreateBeOSView();
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
virtual PRBool ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *aRetValue);
|
||||||
|
nsIMenuItem * FindMenuItem(nsIMenu * aMenu, PRUint32 aId);
|
||||||
|
nsIMenu * FindMenu(nsIMenu * aMenu, HMENU aNativeMenu, PRInt32 &aDepth);
|
||||||
|
nsresult MenuHasBeenSelected(HMENU aNativeMenu, UINT aItemNum, UINT aFlags, UINT aCommand);
|
||||||
|
|
||||||
|
virtual LPCTSTR WindowClass();
|
||||||
|
virtual DWORD WindowStyle();
|
||||||
|
virtual DWORD WindowExStyle();
|
||||||
|
|
||||||
|
static LRESULT CALLBACK WindowProc(BWindow * hWnd,
|
||||||
|
UINT msg,
|
||||||
|
WPARAM wParam,
|
||||||
|
LPARAM lParam);
|
||||||
|
|
||||||
|
void RelayMouseEvent(UINT aMsg, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
|
BWindow *mTooltip;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
BView *mView;
|
||||||
|
|
||||||
|
PRBool mIsDestroying;
|
||||||
|
PRBool mOnDestroyCalled;
|
||||||
|
PRBool mIsVisible;
|
||||||
|
// XXX Temporary, should not be caching the font
|
||||||
|
nsFont * mFont;
|
||||||
|
|
||||||
|
PRInt32 mPreferredWidth;
|
||||||
|
PRInt32 mPreferredHeight;
|
||||||
|
|
||||||
|
nsIMenuBar * mMenuBar;
|
||||||
|
PRInt32 mMenuCmdId;
|
||||||
|
nsIMenu * mHitMenu;
|
||||||
|
nsVoidArray * mHitSubMenus;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// Drag & Drop
|
||||||
|
|
||||||
|
#ifdef DRAG_DROP
|
||||||
|
//nsDropTarget * mDropTarget;
|
||||||
|
CfDropSource * mDropSource;
|
||||||
|
CfDropTarget * mDropTarget;
|
||||||
|
CfDragDrop * mDragDrop;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public: // public on BeOS to allow BViews to access it
|
||||||
|
// Enumeration of the methods which are accessable on the "main GUI thread"
|
||||||
|
// via the CallMethod(...) mechanism...
|
||||||
|
// see nsSwitchToUIThread
|
||||||
|
enum {
|
||||||
|
CREATE = 0x0101,
|
||||||
|
CREATE_NATIVE,
|
||||||
|
DESTROY,
|
||||||
|
SET_FOCUS,
|
||||||
|
SET_CURSOR,
|
||||||
|
CREATE_HACK,
|
||||||
|
ONMOUSE,
|
||||||
|
ONPAINT,
|
||||||
|
ONSCROLL,
|
||||||
|
ONRESIZE,
|
||||||
|
CLOSEWINDOW,
|
||||||
|
MENU,
|
||||||
|
ONKEY,
|
||||||
|
BTNCLICK
|
||||||
|
};
|
||||||
|
nsToolkit *GetToolkit() { return (nsToolkit *)nsBaseWidget::GetToolkit(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// Each class need to subclass this as part of the subclass
|
||||||
|
//
|
||||||
|
class nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsIWidgetStore(nsIWidget *aWindow);
|
||||||
|
virtual ~nsIWidgetStore();
|
||||||
|
|
||||||
|
virtual nsIWidget *GetMozillaWidget(void);
|
||||||
|
|
||||||
|
private:
|
||||||
|
nsIWidget *mWidget;
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BWindow subclass
|
||||||
|
//
|
||||||
|
class nsWindowBeOS : public BWindow, public nsIWidgetStore {
|
||||||
|
public:
|
||||||
|
nsWindowBeOS(nsIWidget *aWidgetWindow, BRect aFrame, const char *aName, window_look aLook,
|
||||||
|
window_feel aFeel, int32 aFlags, int32 aWorkspace = B_CURRENT_WORKSPACE);
|
||||||
|
|
||||||
|
virtual bool QuitRequested( void );
|
||||||
|
virtual void MessageReceived(BMessage *msg);
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A BView subclass
|
||||||
|
//
|
||||||
|
class nsViewBeOS : public BView, public nsIWidgetStore {
|
||||||
|
BRegion paintregion;
|
||||||
|
uint32 buttons;
|
||||||
|
nsRect currsizerect;
|
||||||
|
bool currsizechanged;
|
||||||
|
|
||||||
|
public:
|
||||||
|
nsViewBeOS( nsIWidget *aWidgetWindow, BRect aFrame, const char *aName,
|
||||||
|
uint32 aResizingMode, uint32 aFlags );
|
||||||
|
|
||||||
|
virtual void AttachedToWindow();
|
||||||
|
virtual void Draw(BRect updateRect);
|
||||||
|
virtual void FrameResized(float width, float height);
|
||||||
|
virtual void MouseDown(BPoint point);
|
||||||
|
virtual void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
|
||||||
|
virtual void MouseUp(BPoint point);
|
||||||
|
bool GetPaintRect(nsRect &r);
|
||||||
|
bool GetSizeRect(nsRect &r);
|
||||||
|
void KeyDown(const char *bytes, int32 numBytes);
|
||||||
|
void KeyUp(const char *bytes, int32 numBytes);
|
||||||
|
};
|
||||||
|
|
||||||
|
//
|
||||||
|
// A child window is a window with different style
|
||||||
|
//
|
||||||
|
class ChildWindow : public nsWindow {
|
||||||
|
public:
|
||||||
|
ChildWindow() {};
|
||||||
|
virtual PRBool IsChild() { return(PR_TRUE); };
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // Window_h__
|
|
@ -0,0 +1,36 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NSDEFS_H
|
||||||
|
#define NSDEFS_H
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define BREAK_TO_DEBUGGER DebugBreak()
|
||||||
|
#else
|
||||||
|
#define BREAK_TO_DEBUGGER
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef _DEBUG
|
||||||
|
#define VERIFY(exp) ((exp) ? 0: (GetLastError(), BREAK_TO_DEBUGGER))
|
||||||
|
#else // !_DEBUG
|
||||||
|
#define VERIFY(exp) (exp)
|
||||||
|
#endif // !_DEBUG
|
||||||
|
|
||||||
|
#endif // NSDEFS_H
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||||
|
*
|
||||||
|
* The contents of this file are subject to the Netscape Public License
|
||||||
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||||
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||||
|
* http://www.mozilla.org/NPL/
|
||||||
|
*
|
||||||
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||||
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||||
|
* for the specific language governing rights and limitations under the
|
||||||
|
* NPL.
|
||||||
|
*
|
||||||
|
* The Initial Developer of this code under the NPL is Netscape
|
||||||
|
* Communications Corporation. Portions created by Netscape are
|
||||||
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||||
|
* Reserved.
|
||||||
|
*/
|
||||||
|
#define IDC_SELECTANCHOR 4100
|
||||||
|
#define IDC_ARROWSOUTH 4101
|
||||||
|
#define IDC_ARROWNORTH 4102
|
||||||
|
#define IDC_ARROWEAST 4103
|
||||||
|
#define IDC_ARROWWEST 4104
|
||||||
|
#define IDC_ARROWSOUTHPLUS 4105
|
||||||
|
#define IDC_ARROWNORTHPLUS 4106
|
||||||
|
#define IDC_ARROWEASTPLUS 4107
|
||||||
|
#define IDC_ARROWWESTPLUS 4108
|
||||||
|
|
Загрузка…
Ссылка в новой задаче