зеркало из https://github.com/mozilla/gecko-dev.git
Removing unused files under BeOS. Part of Bug 9863.
BeOS only code.
This commit is contained in:
Родитель
441998fa74
Коммит
1cb87c4af8
|
@ -39,26 +39,27 @@ static int gBAppCount = 0;
|
|||
|
||||
struct ThreadInterfaceData
|
||||
{
|
||||
void *data;
|
||||
int32 sync;
|
||||
void *data;
|
||||
int32 sync;
|
||||
};
|
||||
|
||||
static sem_id my_find_sem(const char *name)
|
||||
{
|
||||
sem_id ret = B_ERROR;
|
||||
sem_id ret = B_ERROR;
|
||||
|
||||
/* Get the sem_info for every sempahore in this team. */
|
||||
sem_info info;
|
||||
int32 cookie = 0;
|
||||
/* 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;
|
||||
while(get_next_sem_info(0, &cookie, &info) == B_OK)
|
||||
{
|
||||
if(strcmp(name, info.name) == 0)
|
||||
{
|
||||
ret = info.sem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -72,24 +73,26 @@ 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;
|
||||
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);
|
||||
public:
|
||||
sem_id init;
|
||||
|
||||
nsBeOSApp(const char *signature, sem_id initsem);
|
||||
virtual void ReadyToRun(void);
|
||||
};
|
||||
|
||||
nsBeOSApp::nsBeOSApp(const char *signature, sem_id initsem)
|
||||
|
@ -99,17 +102,27 @@ nsBeOSApp::nsBeOSApp(const char *signature, sem_id initsem)
|
|||
|
||||
void nsBeOSApp::ReadyToRun(void)
|
||||
{
|
||||
release_sem(init);
|
||||
release_sem(init);
|
||||
}
|
||||
|
||||
// Return B_OK for success, anything else error!
|
||||
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;
|
||||
// create and start BApplication
|
||||
char sig[B_MIME_TYPE_LENGTH + 1];
|
||||
int32 error = B_OK;
|
||||
|
||||
GetAppSig(sig);
|
||||
nsBeOSApp *app = new nsBeOSApp(sig, (sem_id)arg);
|
||||
if(app)
|
||||
{
|
||||
app->Run();
|
||||
}
|
||||
else
|
||||
{
|
||||
error = B_NO_MEMORY;
|
||||
}
|
||||
return error;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -122,13 +135,13 @@ nsAppShell::nsAppShell()
|
|||
NS_INIT_REFCNT();
|
||||
mDispatchListener = 0;
|
||||
|
||||
if(gBAppCount++ == 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);
|
||||
}
|
||||
if(gBAppCount++ == 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -140,26 +153,26 @@ nsAppShell::nsAppShell()
|
|||
|
||||
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];
|
||||
PR_snprintf(portname, sizeof(portname), "event%lx",
|
||||
(long unsigned) PR_GetCurrentThread());
|
||||
PR_snprintf(semname, sizeof(semname), "sync%lx",
|
||||
(long unsigned) PR_GetCurrentThread());
|
||||
// system wide unique names
|
||||
// NOTE: this needs to be run from within the main application thread
|
||||
char portname[64];
|
||||
char semname[64];
|
||||
PR_snprintf(portname, sizeof(portname), "event%lx",
|
||||
(long unsigned) PR_GetCurrentThread());
|
||||
PR_snprintf(semname, sizeof(semname), "sync%lx",
|
||||
(long unsigned) 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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
@ -179,56 +192,62 @@ NS_METHOD nsAppShell::SetDispatchListener(nsDispatchListener* aDispatchListener)
|
|||
|
||||
nsresult nsAppShell::Run()
|
||||
{
|
||||
int32 code;
|
||||
ThreadInterfaceData id;
|
||||
int32 code;
|
||||
ThreadInterfaceData id;
|
||||
|
||||
NS_ADDREF_THIS();
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
while(read_port(eventport, &code, &id, sizeof(id)) >= 0)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
while(read_port(eventport, &code, &id, sizeof(id)) >= 0)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CALLMETHOD :
|
||||
{
|
||||
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||
mInfo->Invoke();
|
||||
if(! id.sync)
|
||||
delete mInfo;
|
||||
}
|
||||
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;
|
||||
case 'natv' : // native queue PLEvent
|
||||
{
|
||||
PREventQueue *queue = (PREventQueue *)id.data;
|
||||
PR_ProcessPendingEvents(queue);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
default :
|
||||
#ifdef DEBUG
|
||||
printf("nsAppShell::Run - UNKNOWN EVENT\n");
|
||||
printf("nsAppShell::Run - UNKNOWN EVENT\n");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(mDispatchListener)
|
||||
mDispatchListener->AfterDispatch();
|
||||
if(mDispatchListener)
|
||||
{
|
||||
mDispatchListener->AfterDispatch();
|
||||
}
|
||||
|
||||
if(id.sync)
|
||||
{
|
||||
release_sem(syncsem);
|
||||
}
|
||||
}
|
||||
|
||||
if(id.sync)
|
||||
release_sem(syncsem);
|
||||
}
|
||||
Release();
|
||||
|
||||
Release();
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -239,10 +258,10 @@ nsresult nsAppShell::Run()
|
|||
|
||||
NS_METHOD nsAppShell::Exit()
|
||||
{
|
||||
// interrupt message flow
|
||||
close_port(eventport);
|
||||
// interrupt message flow
|
||||
close_port(eventport);
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -252,11 +271,13 @@ NS_METHOD nsAppShell::Exit()
|
|||
//-------------------------------------------------------------------------
|
||||
nsAppShell::~nsAppShell()
|
||||
{
|
||||
if(--gBAppCount == 0)
|
||||
{
|
||||
if(be_app->Lock())
|
||||
be_app->Quit();
|
||||
}
|
||||
if(--gBAppCount == 0)
|
||||
{
|
||||
if(be_app->Lock())
|
||||
{
|
||||
be_app->Quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -266,9 +287,7 @@ nsAppShell::~nsAppShell()
|
|||
//-------------------------------------------------------------------------
|
||||
void* nsAppShell::GetNativeData(PRUint32 aDataType)
|
||||
{
|
||||
if (aDataType == NS_NATIVE_SHELL) {
|
||||
return NULL;
|
||||
}
|
||||
// To be implemented.
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
@ -305,9 +324,10 @@ NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
|
|||
// should we check for eventport initialization ?
|
||||
char portname[64];
|
||||
PR_snprintf(portname, sizeof(portname), "event%lx",
|
||||
(long unsigned) PR_GetCurrentThread());
|
||||
(long unsigned) PR_GetCurrentThread());
|
||||
|
||||
if((eventport = find_port(portname)) < 0) {
|
||||
if((eventport = find_port(portname)) < 0)
|
||||
{
|
||||
// not initialized
|
||||
#ifdef DEBUG
|
||||
printf("nsAppShell::DispatchNativeEvent() was called before init\n");
|
||||
|
@ -322,43 +342,54 @@ NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
|
|||
id.sync = 0;
|
||||
bool gotMessage = false;
|
||||
|
||||
do {
|
||||
if (read_port(eventport, &code, &id, sizeof(id)) >= 0) {
|
||||
switch(code) {
|
||||
case 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
case WM_CALLMETHOD :
|
||||
{
|
||||
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||
mInfo->Invoke();
|
||||
if(! id.sync)
|
||||
delete mInfo;
|
||||
gotMessage = PR_TRUE;
|
||||
}
|
||||
break;
|
||||
case 'natv' : // native queue PLEvent
|
||||
{
|
||||
PREventQueue *queue = (PREventQueue *)id.data;
|
||||
PR_ProcessPendingEvents(queue);
|
||||
gotMessage = PR_TRUE;
|
||||
}
|
||||
break;
|
||||
default :
|
||||
do
|
||||
{
|
||||
if (read_port(eventport, &code, &id, sizeof(id)) >= 0)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CALLMETHOD :
|
||||
{
|
||||
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||
mInfo->Invoke();
|
||||
if(! id.sync)
|
||||
{
|
||||
delete mInfo;
|
||||
}
|
||||
gotMessage = PR_TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'natv' : // native queue PLEvent
|
||||
{
|
||||
PREventQueue *queue = (PREventQueue *)id.data;
|
||||
PR_ProcessPendingEvents(queue);
|
||||
gotMessage = PR_TRUE;
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
#ifdef DEBUG
|
||||
printf("nsAppShell::Run - UNKNOWN EVENT\n");
|
||||
printf("nsAppShell::Run - UNKNOWN EVENT\n");
|
||||
#endif
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
if(id.sync)
|
||||
{
|
||||
release_sem(syncsem);
|
||||
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// read_port failure
|
||||
#ifdef DEBUG
|
||||
printf("nsAppShell::GetNativeEvent() read_port failed.\n");
|
||||
|
@ -369,8 +400,10 @@ NS_METHOD nsAppShell::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
|
|||
|
||||
// no need to do this?
|
||||
//if(mDispatchListener)
|
||||
//{
|
||||
// mDispatchListener->AfterDispatch();
|
||||
|
||||
//}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,255 +0,0 @@
|
|||
/* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*-
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
//#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;
|
||||
}
|
|
@ -47,10 +47,13 @@ nsFontRetrieverService::nsFontRetrieverService()
|
|||
//----------------------------------------------------------
|
||||
nsFontRetrieverService::~nsFontRetrieverService()
|
||||
{
|
||||
if (nsnull != mFontList) {
|
||||
for (PRInt32 i=0;i<mFontList->Count();i++) {
|
||||
if (nsnull != mFontList)
|
||||
{
|
||||
for (PRInt32 i=0;i<mFontList->Count();i++)
|
||||
{
|
||||
FontInfo * font = (FontInfo *)mFontList->ElementAt(i);
|
||||
if (font->mSizes) {
|
||||
if (font->mSizes)
|
||||
{
|
||||
delete font->mSizes;
|
||||
}
|
||||
delete font;
|
||||
|
@ -69,19 +72,22 @@ nsFontRetrieverService::~nsFontRetrieverService()
|
|||
nsresult nsFontRetrieverService::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
{
|
||||
|
||||
if (NULL == aInstancePtr) {
|
||||
if (NULL == aInstancePtr)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsresult rv = NS_NOINTERFACE;
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIFontRetrieverService))) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIFontRetrieverService)))
|
||||
{
|
||||
*aInstancePtr = (void*) ((nsIFontRetrieverService*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(NS_GET_IID(nsIFontNameIterator))) {
|
||||
if (aIID.Equals(NS_GET_IID(nsIFontNameIterator)))
|
||||
{
|
||||
*aInstancePtr = (void*) ((nsIFontNameIterator*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
|
@ -96,11 +102,13 @@ nsresult nsFontRetrieverService::QueryInterface(const nsIID& aIID, void** aInsta
|
|||
//----------------------------------------------------------
|
||||
NS_IMETHODIMP nsFontRetrieverService::CreateFontNameIterator( nsIFontNameIterator** aIterator )
|
||||
{
|
||||
if (nsnull == aIterator) {
|
||||
if (nsnull == aIterator)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (nsnull == mFontList) {
|
||||
if (nsnull == mFontList)
|
||||
{
|
||||
LoadFontList();
|
||||
}
|
||||
*aIterator = this;
|
||||
|
@ -117,17 +125,21 @@ NS_IMETHODIMP nsFontRetrieverService::CreateFontSizeIterator( const nsString & a
|
|||
|
||||
PRBool found = PR_FALSE;
|
||||
Reset();
|
||||
do {
|
||||
do
|
||||
{
|
||||
nsAutoString name;
|
||||
Get(&name);
|
||||
if (name.Equals(aFontName)) {
|
||||
if (name.Equals(aFontName))
|
||||
{
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
} while (Advance() == NS_OK);
|
||||
|
||||
if (found) {
|
||||
if (nsnull == mSizeIter) {
|
||||
if (found)
|
||||
{
|
||||
if (nsnull == mSizeIter)
|
||||
{
|
||||
mSizeIter = new nsFontSizeIterator();
|
||||
}
|
||||
NS_ASSERTION( nsnull != mSizeIter, "nsFontSizeIterator instance pointer is null");
|
||||
|
@ -156,7 +168,8 @@ NS_IMETHODIMP nsFontRetrieverService::Reset()
|
|||
//----------------------------------------------------------
|
||||
NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName )
|
||||
{
|
||||
if (mNameIterInx < mFontList->Count()) {
|
||||
if (mNameIterInx < mFontList->Count())
|
||||
{
|
||||
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
|
||||
*aFontName = fontInfo->mName;
|
||||
return NS_OK;
|
||||
|
@ -167,7 +180,8 @@ NS_IMETHODIMP nsFontRetrieverService::Get( nsString* aFontName )
|
|||
//----------------------------------------------------------
|
||||
NS_IMETHODIMP nsFontRetrieverService::Advance()
|
||||
{
|
||||
if (mNameIterInx < mFontList->Count()-1) {
|
||||
if (mNameIterInx < mFontList->Count()-1)
|
||||
{
|
||||
mNameIterInx++;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -180,37 +194,51 @@ static FontInfo * GetFontInfo(nsVoidArray * aFontList, char * aName)
|
|||
nsAutoString name; name.AssignWithConversion(aName);
|
||||
PRInt32 i;
|
||||
PRInt32 cnt = aFontList->Count();
|
||||
for (i=0;i<cnt;i++) {
|
||||
for (i=0;i<cnt;i++)
|
||||
{
|
||||
FontInfo * fontInfo = (FontInfo *)aFontList->ElementAt(i);
|
||||
if (fontInfo->mName.Equals(name)) {
|
||||
return fontInfo;
|
||||
if (fontInfo) // I don't think ElementAt can return null pointer... See Bug 8827
|
||||
{
|
||||
if (fontInfo->mName.Equals(name))
|
||||
{
|
||||
return fontInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FontInfo * fontInfo = new FontInfo();
|
||||
fontInfo->mName.AssignWithConversion(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;
|
||||
if (fontInfo)
|
||||
{
|
||||
fontInfo->mName.AssignWithConversion(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;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
//------------------------------
|
||||
static void AddSizeToFontInfo(FontInfo * aFontInfo, PRInt32 aSize)
|
||||
{
|
||||
nsVoidArray * sizes;
|
||||
if (nsnull == aFontInfo->mSizes) {
|
||||
if (nsnull == aFontInfo->mSizes)
|
||||
{
|
||||
sizes = new nsVoidArray();
|
||||
aFontInfo->mSizes = sizes;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
sizes = aFontInfo->mSizes;
|
||||
}
|
||||
PRInt32 i;
|
||||
PRInt32 cnt = sizes->Count();
|
||||
for (i=0;i<cnt;i++) {
|
||||
for (i=0;i<cnt;i++)
|
||||
{
|
||||
PRInt32 size = (int)sizes->ElementAt(i);
|
||||
if (size == aSize) {
|
||||
if (size == aSize)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -402,16 +430,19 @@ NS_IMETHODIMP nsFontRetrieverService::IsFontScalable(const nsString & aFontName,
|
|||
|
||||
PRBool found = PR_FALSE;
|
||||
Reset();
|
||||
do {
|
||||
do
|
||||
{
|
||||
nsAutoString name;
|
||||
Get(&name);
|
||||
if (name.Equals(aFontName)) {
|
||||
if (name.Equals(aFontName))
|
||||
{
|
||||
found = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
} while (Advance() == NS_OK);
|
||||
|
||||
if (found) {
|
||||
if (found)
|
||||
{
|
||||
FontInfo * fontInfo = (FontInfo *)mFontList->ElementAt(mNameIterInx);
|
||||
*aResult = fontInfo->mIsScalable;
|
||||
mNameIterInx = saveIterInx;
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "nsFont.h"
|
||||
|
||||
#include "nsXPLookAndFeel.h"
|
||||
|
||||
#include <InterfaceDefs.h>
|
||||
|
||||
//static NS_DEFINE_IID(kILookAndFeelIID, NS_ILOOKANDFEEL_IID);
|
||||
//NS_IMPL_ISUPPORTS(nsLookAndFeel, NS_ILOOKANDFEEL_IID)
|
||||
|
@ -201,73 +203,96 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(const nsMetricID aID, PRInt32 & aMetric)
|
|||
res = NS_OK;
|
||||
}
|
||||
|
||||
switch (aID) {
|
||||
switch (aID)
|
||||
{
|
||||
case eMetric_WindowTitleHeight:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_WindowBorderWidth:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_WindowBorderHeight:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_Widget3DBorder:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_TextFieldBorder:
|
||||
aMetric = 3;
|
||||
break;
|
||||
aMetric = 3;
|
||||
break;
|
||||
case eMetric_TextFieldHeight:
|
||||
aMetric = 24;
|
||||
break;
|
||||
aMetric = 24;
|
||||
break;
|
||||
case eMetric_ButtonHorizontalInsidePaddingNavQuirks:
|
||||
aMetric = 10;
|
||||
break;
|
||||
aMetric = 10;
|
||||
break;
|
||||
case eMetric_ButtonHorizontalInsidePaddingOffsetNavQuirks:
|
||||
aMetric = 8;
|
||||
break;
|
||||
aMetric = 8;
|
||||
break;
|
||||
case eMetric_CheckboxSize:
|
||||
aMetric = 12;
|
||||
break;
|
||||
aMetric = 12;
|
||||
break;
|
||||
case eMetric_RadioboxSize:
|
||||
aMetric = 12;
|
||||
break;
|
||||
aMetric = 12;
|
||||
break;
|
||||
case eMetric_TextHorizontalInsideMinimumPadding:
|
||||
aMetric = 3;
|
||||
break;
|
||||
aMetric = 3;
|
||||
break;
|
||||
case eMetric_TextVerticalInsidePadding:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_TextShouldUseVerticalInsidePadding:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_TextShouldUseHorizontalInsideMinimumPadding:
|
||||
aMetric = 1;
|
||||
break;
|
||||
aMetric = 1;
|
||||
break;
|
||||
case eMetric_ListShouldUseHorizontalInsideMinimumPadding:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_ListHorizontalInsideMinimumPadding:
|
||||
aMetric = 3;
|
||||
break;
|
||||
aMetric = 3;
|
||||
break;
|
||||
case eMetric_ListShouldUseVerticalInsidePadding:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_ListVerticalInsidePadding:
|
||||
aMetric = 0;
|
||||
break;
|
||||
aMetric = 0;
|
||||
break;
|
||||
case eMetric_CaretBlinkTime:
|
||||
aMetric = 500;
|
||||
break;
|
||||
aMetric = 500;
|
||||
break;
|
||||
case eMetric_SingleLineCaretWidth:
|
||||
aMetric = 1;
|
||||
break;
|
||||
aMetric = 1;
|
||||
break;
|
||||
case eMetric_MultiLineCaretWidth:
|
||||
aMetric = 2;
|
||||
break;
|
||||
aMetric = 2;
|
||||
break;
|
||||
case eMetric_SubmenuDelay:
|
||||
aMetric = 200;
|
||||
break;
|
||||
aMetric = 200;
|
||||
break;
|
||||
case eMetric_ScrollArrowStyle:
|
||||
{
|
||||
aMetric = eMetric_ScrollArrowStyleBothAtEachEnd; // BeOS default
|
||||
|
||||
scroll_bar_info info;
|
||||
if(B_OK == get_scroll_bar_info(&info) && !info.double_arrows)
|
||||
{
|
||||
aMetric = eMetric_ScrollArrowStyleSingle;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case eMetric_ScrollSliderStyle:
|
||||
{
|
||||
aMetric = eMetric_ScrollThumbStyleProportional; // BeOS default
|
||||
|
||||
scroll_bar_info info;
|
||||
if(B_OK == get_scroll_bar_info(&info) && !info.proportional)
|
||||
{
|
||||
aMetric = eMetric_ScrollThumbStyleNormal;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
aMetric = -1;
|
||||
res = NS_ERROR_FAILURE;
|
||||
|
|
|
@ -1,671 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#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(NS_GET_IID(nsIMenu))) {
|
||||
*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(NS_GET_IID(nsIMenuListener))) {
|
||||
*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(NS_GET_IID(nsIMenuBar), (void**) &menubar);
|
||||
if(menubar)
|
||||
{
|
||||
mMenuBarParent = menubar;
|
||||
NS_RELEASE(menubar);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIMenu * menu = nsnull;
|
||||
aParent->QueryInterface(NS_GET_IID(nsIMenu), (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::GetAccessKey(nsString &aText)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::SetAccessKey(const nsString &aText)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
/**
|
||||
* Set enabled state
|
||||
*
|
||||
*/
|
||||
NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenu::AddItem(nsISupports * aItem)
|
||||
{
|
||||
if(aItem)
|
||||
{
|
||||
nsIMenuItem * menuitem = nsnull;
|
||||
aItem->QueryInterface(NS_GET_IID(nsIMenuItem),
|
||||
(void**)&menuitem);
|
||||
if(menuitem)
|
||||
{
|
||||
AddMenuItem(menuitem); // nsMenu now owns this
|
||||
NS_RELEASE(menuitem);
|
||||
}
|
||||
else
|
||||
{
|
||||
nsIMenu * menu = nsnull;
|
||||
aItem->QueryInterface(NS_GET_IID(nsIMenu),
|
||||
(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, NS_GET_IID(nsIMenuItem), (void**)&pnsMenuItem);
|
||||
if (NS_OK == rv) {
|
||||
nsString tmp; tmp.AssignWithConversion("menuseparator");
|
||||
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::SetNativeData(void * aData)
|
||||
{
|
||||
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(NS_ConvertASCIItoUCS2("open"), NS_ConvertASCIItoUCS2("true"));
|
||||
|
||||
|
||||
/// Now get the kids. Retrieve our menupopup child.
|
||||
nsCOMPtr<nsIDOMNode> menuPopupNode;
|
||||
mDOMNode->GetFirstChild(getter_AddRefs(menuPopupNode));
|
||||
while (menuPopupNode) {
|
||||
nsCOMPtr<nsIDOMElement> menuPopupElement(do_QueryInterface(menuPopupNode));
|
||||
if (menuPopupElement) {
|
||||
nsString menuPopupNodeType;
|
||||
menuPopupElement->GetNodeName(menuPopupNodeType);
|
||||
if (menuPopupNodeType.EqualsWithConversion("menupopup"))
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIDOMNode> oldMenuPopupNode(menuPopupNode);
|
||||
oldMenuPopupNode->GetNextSibling(getter_AddRefs(menuPopupNode));
|
||||
}
|
||||
|
||||
if (!menuPopupNode)
|
||||
return nsEventStatus_eIgnore;
|
||||
|
||||
nsCOMPtr<nsIDOMNode> menuitemNode;
|
||||
menuPopupNode->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.EqualsWithConversion("menuitem")) {
|
||||
// LoadMenuItem
|
||||
LoadMenuItem(this,
|
||||
menuitemElement,
|
||||
menuitemNode,
|
||||
menuIndex,
|
||||
(nsIWebShell*)aWebShell);
|
||||
} else if (menuitemNodeType.EqualsWithConversion("menuseparator")) {
|
||||
AddSeparator();
|
||||
} else if (menuitemNodeType.EqualsWithConversion("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(NS_ConvertASCIItoUCS2("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(NS_ConvertASCIItoUCS2("disabled")), disabled);
|
||||
menuitemElement->GetAttribute(nsAutoString(NS_ConvertASCIItoUCS2("value")), menuitemName);
|
||||
menuitemElement->GetAttribute(nsAutoString(NS_ConvertASCIItoUCS2("cmd")), menuitemCmd);
|
||||
|
||||
// Create nsMenuItem
|
||||
nsIMenuItem * pnsMenuItem = nsnull;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kMenuItemCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIMenuItem),
|
||||
(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.EqualsWithConversion(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; cmdAtom.AssignWithConversion("oncommand");
|
||||
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(NS_ConvertASCIItoUCS2("value"), menuName);
|
||||
//printf("Creating Menu [%s] \n", menuName.ToNewCString()); // this leaks
|
||||
|
||||
// Create nsMenu
|
||||
nsIMenu * pnsMenu = nsnull;
|
||||
nsresult rv = nsComponentManager::CreateInstance(kMenuCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIMenu),
|
||||
(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("menuseparator"));
|
||||
#endif
|
||||
|
||||
if (menuitemNodeType.Equals("menuitem")) {
|
||||
// Load a menuitem
|
||||
LoadMenuItem(pnsMenu, menuitemElement, menuitemNode, menuIndex, mWebShell);
|
||||
} else if (menuitemNodeType.Equals("menuseparator")) {
|
||||
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
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,123 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#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 GetAccessKey(nsString &aText);
|
||||
NS_IMETHOD SetAccessKey(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 SetNativeData(void * aData);
|
||||
NS_IMETHOD AddMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD RemoveMenuListener(nsIMenuListener * aMenuListener);
|
||||
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
|
||||
|
||||
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__
|
|
@ -1,324 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#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(NS_GET_IID(nsIMenuBar))) {
|
||||
*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(NS_GET_IID(nsIMenuListener))) {
|
||||
*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,
|
||||
NS_GET_IID(nsIMenuBar),
|
||||
(void**)&pnsMenuBar);
|
||||
if (NS_OK == rv) {
|
||||
if (nsnull != pnsMenuBar) {
|
||||
pnsMenuBar->Create(aParentWindow);
|
||||
|
||||
// set pnsMenuBar as a nsMenuListener on aParentWindow
|
||||
nsCOMPtr<nsIMenuListener> menuListener =
|
||||
do_QueryInterface(pnsMenuBar);
|
||||
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.EqualsWithConversion("menu")) {
|
||||
menuElement->GetAttribute(NS_ConvertASCIItoUCS2("value"), menuName);
|
||||
// Don't create the menu yet, just add in the top level names
|
||||
|
||||
// Create nsMenu
|
||||
nsIMenu * pnsMenu = nsnull;
|
||||
rv = nsComponentManager::CreateInstance(kMenuCID, nsnull, NS_GET_IID(nsIMenu), (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;
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#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__
|
|
@ -1,472 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Pierre Phaneuf <pp@ludusdesign.com>
|
||||
*/
|
||||
|
||||
#include "nsMenuItem.h"
|
||||
#include "nsIMenu.h"
|
||||
#include "nsIMenuBar.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
#include "nsIPopUpMenu.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIContent.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(NS_GET_IID(nsIMenuItem))) {
|
||||
*aInstancePtr = (void*)(nsIMenuItem*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)(nsIMenuItem*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIMenuListener))) {
|
||||
*aInstancePtr = (void*)(nsIMenuListener*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsMenuItem)
|
||||
NS_IMPL_RELEASE(nsMenuItem)
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// nsMenuItem constructor
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
nsMenuItem::nsMenuItem() : nsIMenuItem()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mMenuItem = nsnull;
|
||||
mMenuParent = nsnull;
|
||||
mPopUpParent = nsnull;
|
||||
mTarget = nsnull;
|
||||
mListener = nsnull;
|
||||
mIsSeparator = PR_FALSE;
|
||||
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(NS_GET_IID(nsIMenu), (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<nsIContentViewer> contentViewer;
|
||||
NS_ENSURE_SUCCESS(mWebShell->GetContentViewer(getter_AddRefs(contentViewer)),
|
||||
NS_ERROR_FAILURE);
|
||||
|
||||
|
||||
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_MENU_ACTION;
|
||||
|
||||
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::SetDOMNode(nsIDOMNode * aDOMNode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsMenuItem::GetDOMNode(nsIDOMNode ** aDOMNode)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMenuItem::SetShortcutChar(const nsString &aText)
|
||||
{
|
||||
mKeyEquivalent = aText;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMenuItem::GetShortcutChar(nsString &aText)
|
||||
{
|
||||
aText = mKeyEquivalent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMenuItem::SetModifiers(PRUint8 aModifiers)
|
||||
{
|
||||
mModifiers = aModifiers;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
NS_IMETHODIMP nsMenuItem::GetModifiers(PRUint8 * aModifiers)
|
||||
{
|
||||
*aModifiers = mModifiers;
|
||||
return NS_OK;
|
||||
}
|
|
@ -1,117 +0,0 @@
|
|||
/* -*- 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.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#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 SetDOMNode(nsIDOMNode * aDOMNode);
|
||||
NS_IMETHOD GetDOMNode(nsIDOMNode ** aDOMNode);
|
||||
NS_IMETHOD SetDOMElement(nsIDOMElement * aDOMElement);
|
||||
NS_IMETHOD GetDOMElement(nsIDOMElement ** aDOMElement);
|
||||
NS_IMETHOD SetWebShell(nsIWebShell * aWebShell);
|
||||
|
||||
NS_IMETHOD SetShortcutChar(const nsString &aText);
|
||||
NS_IMETHOD GetShortcutChar(nsString &aText);
|
||||
NS_IMETHOD SetModifiers(PRUint8 aModifiers);
|
||||
NS_IMETHOD GetModifiers(PRUint8 * aModifiers);
|
||||
|
||||
// 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 *GetNativeParent();
|
||||
|
||||
BMenuItem *mMenuItem;
|
||||
|
||||
nsString mLabel;
|
||||
nsString mKeyEquivalent;
|
||||
PRUint8 mModifiers;
|
||||
PRUint32 mCommand;
|
||||
nsIMenu *mMenuParent;
|
||||
nsIPopUpMenu *mPopUpParent;
|
||||
nsIWidget * mTarget;
|
||||
nsIMenu * mMenu;
|
||||
nsIMenuListener * mListener;
|
||||
PRBool mIsSeparator;
|
||||
nsIWebShell * mWebShell;
|
||||
nsIDOMElement * mDOMElement;
|
||||
};
|
||||
|
||||
#endif // nsMenuItem_h__
|
|
@ -46,8 +46,8 @@ NS_IMPL_ISUPPORTS(nsToolkit,kIToolkitIID);
|
|||
|
||||
struct ThreadInterfaceData
|
||||
{
|
||||
void *data;
|
||||
int32 sync;
|
||||
void *data;
|
||||
int32 sync;
|
||||
};
|
||||
|
||||
//
|
||||
|
@ -57,87 +57,92 @@ PRBool gThreadState = PR_FALSE;
|
|||
|
||||
static sem_id my_find_sem(const char *name)
|
||||
{
|
||||
sem_id ret = B_ERROR;
|
||||
sem_id ret = B_ERROR;
|
||||
|
||||
/* Get the sem_info for every sempahore in this team. */
|
||||
sem_info info;
|
||||
int32 cookie = 0;
|
||||
/* 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;
|
||||
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;
|
||||
PRMonitor *monitor;
|
||||
nsToolkit *toolkit;
|
||||
};
|
||||
|
||||
void nsToolkit::RunPump(void* arg)
|
||||
{
|
||||
int32 code;
|
||||
char portname[64];
|
||||
char semname[64];
|
||||
ThreadInterfaceData id;
|
||||
int32 code;
|
||||
char portname[64];
|
||||
char semname[64];
|
||||
ThreadInterfaceData id;
|
||||
|
||||
ThreadInitInfo *info = (ThreadInitInfo*)arg;
|
||||
::PR_EnterMonitor(info->monitor);
|
||||
ThreadInitInfo *info = (ThreadInitInfo*)arg;
|
||||
::PR_EnterMonitor(info->monitor);
|
||||
|
||||
gThreadState = PR_TRUE;
|
||||
gThreadState = PR_TRUE;
|
||||
|
||||
::PR_Notify(info->monitor);
|
||||
::PR_ExitMonitor(info->monitor);
|
||||
::PR_Notify(info->monitor);
|
||||
::PR_ExitMonitor(info->monitor);
|
||||
|
||||
delete info;
|
||||
delete info;
|
||||
|
||||
// system wide unique names
|
||||
sprintf(portname, "event%lx", PR_GetCurrentThread());
|
||||
sprintf(semname, "sync%lx", PR_GetCurrentThread());
|
||||
// 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);
|
||||
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 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
while(read_port(event, &code, &id, sizeof(id)) >= 0)
|
||||
{
|
||||
switch(code)
|
||||
{
|
||||
case 'WMti' :
|
||||
{
|
||||
// Hack
|
||||
nsCOMPtr<nsTimerBeOS> timer = (nsTimerBeOS *)id.data;
|
||||
timer->FireTimeout();
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_CALLMETHOD :
|
||||
{
|
||||
MethodInfo *mInfo = (MethodInfo *)id.data;
|
||||
mInfo->Invoke();
|
||||
if(! id.sync)
|
||||
delete mInfo;
|
||||
}
|
||||
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;
|
||||
case 'natv' : // native queue PLEvent
|
||||
{
|
||||
PREventQueue *queue = (PREventQueue *)id.data;
|
||||
PR_ProcessPendingEvents(queue);
|
||||
}
|
||||
break;
|
||||
|
||||
default :
|
||||
printf("nsToolkit::RunPump - UNKNOWN EVENT\n");
|
||||
break;
|
||||
}
|
||||
default :
|
||||
printf("nsToolkit::RunPump - UNKNOWN EVENT\n");
|
||||
break;
|
||||
}
|
||||
|
||||
if(id.sync)
|
||||
release_sem(sync);
|
||||
}
|
||||
if(id.sync)
|
||||
{
|
||||
release_sem(sync);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -147,9 +152,9 @@ void nsToolkit::RunPump(void* arg)
|
|||
//-------------------------------------------------------------------------
|
||||
nsToolkit::nsToolkit()
|
||||
{
|
||||
localthread = false;
|
||||
NS_INIT_REFCNT();
|
||||
mGuiThread = NULL;
|
||||
localthread = false;
|
||||
NS_INIT_REFCNT();
|
||||
mGuiThread = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,19 +165,19 @@ nsToolkit::nsToolkit()
|
|||
//-------------------------------------------------------------------------
|
||||
nsToolkit::~nsToolkit()
|
||||
{
|
||||
Kill();
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
|
||||
Kill();
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
|
||||
}
|
||||
|
||||
void nsToolkit::Kill()
|
||||
{
|
||||
if(localthread)
|
||||
{
|
||||
GetInterface();
|
||||
if(localthread)
|
||||
{
|
||||
GetInterface();
|
||||
|
||||
// interrupt message flow
|
||||
close_port(eventport);
|
||||
}
|
||||
// interrupt message flow
|
||||
close_port(eventport);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -182,30 +187,35 @@ void nsToolkit::Kill()
|
|||
//-------------------------------------------------------------------------
|
||||
void nsToolkit::CreateUIThread()
|
||||
{
|
||||
PRMonitor *monitor = ::PR_NewMonitor();
|
||||
PRMonitor *monitor = ::PR_NewMonitor();
|
||||
|
||||
::PR_EnterMonitor(monitor);
|
||||
::PR_EnterMonitor(monitor);
|
||||
|
||||
ThreadInitInfo *ti = new ThreadInitInfo();
|
||||
ti->monitor = monitor;
|
||||
ti->toolkit = this;
|
||||
ThreadInitInfo *ti = new ThreadInitInfo();
|
||||
if (ti)
|
||||
{
|
||||
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);
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -215,77 +225,84 @@ void nsToolkit::CreateUIThread()
|
|||
//-------------------------------------------------------------------------
|
||||
NS_METHOD nsToolkit::Init(PRThread *aThread)
|
||||
{
|
||||
Kill();
|
||||
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;
|
||||
// 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();
|
||||
}
|
||||
// create a thread where the message pump will run
|
||||
CreateUIThread();
|
||||
}
|
||||
|
||||
cached = false;
|
||||
cached = false;
|
||||
|
||||
return NS_OK;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsToolkit::GetInterface()
|
||||
{
|
||||
if(! cached)
|
||||
{
|
||||
char portname[64];
|
||||
char semname[64];
|
||||
if(! cached)
|
||||
{
|
||||
char portname[64];
|
||||
char semname[64];
|
||||
|
||||
sprintf(portname, "event%lx", mGuiThread);
|
||||
sprintf(semname, "sync%lx", mGuiThread);
|
||||
sprintf(portname, "event%lx", mGuiThread);
|
||||
sprintf(semname, "sync%lx", mGuiThread);
|
||||
|
||||
eventport = find_port(portname);
|
||||
syncsem = my_find_sem(semname);
|
||||
eventport = find_port(portname);
|
||||
syncsem = my_find_sem(semname);
|
||||
|
||||
cached = true;
|
||||
}
|
||||
cached = true;
|
||||
}
|
||||
}
|
||||
|
||||
void nsToolkit::CallMethod(MethodInfo *info)
|
||||
{
|
||||
ThreadInterfaceData id;
|
||||
ThreadInterfaceData id;
|
||||
|
||||
GetInterface();
|
||||
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)
|
||||
;
|
||||
}
|
||||
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;
|
||||
ThreadInterfaceData id;
|
||||
|
||||
GetInterface();
|
||||
GetInterface();
|
||||
|
||||
id.data = info;
|
||||
id.sync = false;
|
||||
id.data = info;
|
||||
id.sync = false;
|
||||
|
||||
// Check message count to not exceed the port's capacity.
|
||||
// There seems to be a BeOS bug that allows more
|
||||
// messages on a port than its capacity.
|
||||
port_info portinfo;
|
||||
if (get_port_info(eventport, &portinfo) != B_OK)
|
||||
return;
|
||||
|
||||
if (port_count(eventport) < portinfo.capacity - 20)
|
||||
write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0);
|
||||
// Check message count to not exceed the port's capacity.
|
||||
// There seems to be a BeOS bug that allows more
|
||||
// messages on a port than its capacity.
|
||||
port_info portinfo;
|
||||
if (get_port_info(eventport, &portinfo) != B_OK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (port_count(eventport) < portinfo.capacity - 20)
|
||||
{
|
||||
write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
@ -301,25 +318,32 @@ NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
|||
PRStatus status;
|
||||
|
||||
// Create the TLS index the first time through...
|
||||
if (0 == gToolkitTLSIndex) {
|
||||
if (0 == gToolkitTLSIndex)
|
||||
{
|
||||
status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
|
||||
if (PR_FAILURE == status) {
|
||||
if (PR_FAILURE == status)
|
||||
{
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
|
||||
|
||||
//
|
||||
// Create a new toolkit for this thread...
|
||||
//
|
||||
if (!toolkit) {
|
||||
if (!toolkit)
|
||||
{
|
||||
toolkit = new nsToolkit();
|
||||
|
||||
if (!toolkit) {
|
||||
if (!toolkit)
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ADDREF(toolkit);
|
||||
toolkit->Init(PR_GetCurrentThread());
|
||||
//
|
||||
|
@ -328,7 +352,9 @@ NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
|||
//
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
NS_ADDREF(toolkit);
|
||||
}
|
||||
*aResult = toolkit;
|
||||
|
|
|
@ -439,194 +439,231 @@ nsresult nsWindow::StandardWindowCreate(nsIWidget *aParent,
|
|||
nsWidgetInitData *aInitData,
|
||||
nsNativeWidget aNativeParent)
|
||||
{
|
||||
nsIWidget *baseParent = aInitData &&
|
||||
(aInitData->mWindowType == eWindowType_dialog ||
|
||||
aInitData->mWindowType == eWindowType_toplevel) ?
|
||||
nsnull : aParent;
|
||||
nsIWidget *baseParent = aInitData &&
|
||||
(aInitData->mWindowType == eWindowType_dialog ||
|
||||
aInitData->mWindowType == eWindowType_toplevel) ?
|
||||
nsnull : aParent;
|
||||
|
||||
mIsTopWidgetWindow = (nsnull == baseParent);
|
||||
mIsTopWidgetWindow = (nsnull == baseParent);
|
||||
|
||||
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
|
||||
aAppShell, aToolkit, aInitData);
|
||||
BaseCreate(baseParent, aRect, aHandleEventFunction, aContext,
|
||||
aAppShell, aToolkit, aInitData);
|
||||
|
||||
// Switch to the "main gui thread" if necessary... This method must
|
||||
// be executed on the "gui thread"...
|
||||
//
|
||||
// Switch to the "main gui thread" if necessary... This method must
|
||||
// be executed on the "gui thread"...
|
||||
//
|
||||
|
||||
nsToolkit* toolkit = (nsToolkit *)mToolkit;
|
||||
if (toolkit) {
|
||||
if (!toolkit->IsGuiThread()) {
|
||||
uint32 args[7];
|
||||
args[0] = (uint32)aParent;
|
||||
args[1] = (uint32)&aRect;
|
||||
args[2] = (uint32)aHandleEventFunction;
|
||||
args[3] = (uint32)aContext;
|
||||
args[4] = (uint32)aAppShell;
|
||||
args[5] = (uint32)aToolkit;
|
||||
args[6] = (uint32)aInitData;
|
||||
nsToolkit* toolkit = (nsToolkit *)mToolkit;
|
||||
if (toolkit)
|
||||
{
|
||||
if (!toolkit->IsGuiThread())
|
||||
{
|
||||
uint32 args[7];
|
||||
args[0] = (uint32)aParent;
|
||||
args[1] = (uint32)&aRect;
|
||||
args[2] = (uint32)aHandleEventFunction;
|
||||
args[3] = (uint32)aContext;
|
||||
args[4] = (uint32)aAppShell;
|
||||
args[5] = (uint32)aToolkit;
|
||||
args[6] = (uint32)aInitData;
|
||||
|
||||
if (nsnull != aParent) {
|
||||
// nsIWidget parent dispatch
|
||||
MethodInfo info(this, this, nsWindow::CREATE, 7, args);
|
||||
toolkit->CallMethod(&info);
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
// Native parent dispatch
|
||||
MethodInfo info(this, this, nsWindow::CREATE_NATIVE, 5, args);
|
||||
toolkit->CallMethod(&info);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if (nsnull != aParent)
|
||||
{
|
||||
// nsIWidget parent dispatch
|
||||
MethodInfo info(this, this, nsWindow::CREATE, 7, args);
|
||||
toolkit->CallMethod(&info);
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Native parent dispatch
|
||||
MethodInfo info(this, this, nsWindow::CREATE_NATIVE, 5, args);
|
||||
toolkit->CallMethod(&info);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BView *parent;
|
||||
if (nsnull != aParent) { // has a nsIWidget parent
|
||||
parent = ((aParent) ? (BView *)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull);
|
||||
} else { // has a nsNative parent
|
||||
parent = (BView *)aNativeParent;
|
||||
}
|
||||
BView *parent;
|
||||
if (nsnull != aParent) // has a nsIWidget parent
|
||||
{
|
||||
parent = ((aParent) ? (BView *)aParent->GetNativeData(NS_NATIVE_WINDOW) : nsnull);
|
||||
}
|
||||
else // has a nsNative parent
|
||||
{
|
||||
parent = (BView *)aNativeParent;
|
||||
}
|
||||
|
||||
if (nsnull != aInitData) {
|
||||
SetWindowType(aInitData->mWindowType);
|
||||
SetBorderStyle(aInitData->mBorderStyle);
|
||||
}
|
||||
if (nsnull != aInitData)
|
||||
{
|
||||
SetWindowType(aInitData->mWindowType);
|
||||
SetBorderStyle(aInitData->mBorderStyle);
|
||||
}
|
||||
|
||||
// NEED INPLEMENT
|
||||
// DWORD style = WindowStyle();
|
||||
// NEED INPLEMENT
|
||||
// DWORD extendedStyle = WindowExStyle();
|
||||
// NEED INPLEMENT
|
||||
// DWORD style = WindowStyle();
|
||||
// NEED INPLEMENT
|
||||
// DWORD extendedStyle = WindowExStyle();
|
||||
|
||||
mBorderlessParent = NULL;
|
||||
if (mWindowType == eWindowType_popup) {
|
||||
mBorderlessParent = parent;
|
||||
// Don't set the parent of a popup window.
|
||||
parent = NULL;
|
||||
} else if (nsnull != aInitData) {
|
||||
// See if the caller wants to explictly set clip children and clip siblings
|
||||
if (aInitData->clipChildren) {
|
||||
// NEED INPLEMENT
|
||||
// style |= WS_CLIPCHILDREN;
|
||||
} else {
|
||||
mBorderlessParent = NULL;
|
||||
if (mWindowType == eWindowType_popup)
|
||||
{
|
||||
mBorderlessParent = parent;
|
||||
// Don't set the parent of a popup window.
|
||||
parent = NULL;
|
||||
}
|
||||
else if (nsnull != aInitData)
|
||||
{
|
||||
// See if the caller wants to explictly set clip children and clip siblings
|
||||
if (aInitData->clipChildren)
|
||||
{
|
||||
// NEED INPLEMENT
|
||||
// style |= WS_CLIPCHILDREN;
|
||||
}
|
||||
else
|
||||
{
|
||||
// NEED INPLEMENT
|
||||
// style &= ~WS_CLIPCHILDREN;
|
||||
}
|
||||
if (aInitData->clipSiblings) {
|
||||
}
|
||||
|
||||
if (aInitData->clipSiblings)
|
||||
{
|
||||
// NEED INPLEMENT
|
||||
// style |= WS_CLIPSIBLINGS;
|
||||
}
|
||||
}
|
||||
|
||||
mView = CreateBeOSView();
|
||||
if(mView)
|
||||
{
|
||||
if (mWindowType == eWindowType_dialog)
|
||||
{
|
||||
// create window (dialog)
|
||||
bool is_subset = (parent)? true : false;
|
||||
window_feel feel = (is_subset) ? B_MODAL_SUBSET_WINDOW_FEEL : B_MODAL_APP_WINDOW_FEEL;
|
||||
BRect winrect = BRect(aRect.x, aRect.y, aRect.x + aRect.width - 1, aRect.y + aRect.height - 1);
|
||||
|
||||
winrect.OffsetBy( 10, 30 );
|
||||
|
||||
nsWindowBeOS *w = new nsWindowBeOS(this, winrect, "", B_TITLED_WINDOW_LOOK, feel,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
if(w)
|
||||
{
|
||||
w->AddChild(mView);
|
||||
if (is_subset)
|
||||
{
|
||||
w->AddToSubset(parent->Window());
|
||||
}
|
||||
|
||||
// FIXME: we have to use the window size because
|
||||
// the window might not like sizes less then 30x30 or something like that
|
||||
mView->MoveTo(0, 0);
|
||||
mView->ResizeTo(w->Bounds().Width(), w->Bounds().Height());
|
||||
mView->SetResizingMode(B_FOLLOW_ALL);
|
||||
}
|
||||
}
|
||||
else if (mWindowType == eWindowType_child)
|
||||
{
|
||||
// create view only
|
||||
bool mustunlock=false;
|
||||
|
||||
mView = CreateBeOSView();
|
||||
if(parent->LockLooper())
|
||||
{
|
||||
mustunlock = true;
|
||||
}
|
||||
|
||||
parent->AddChild(mView);
|
||||
mView->MoveTo(aRect.x, aRect.y);
|
||||
mView->ResizeTo(aRect.width-1, GetHeight(aRect.height)-1);
|
||||
|
||||
if (mWindowType == eWindowType_dialog) {
|
||||
// create window (dialog)
|
||||
bool is_subset = (parent)? true : false;
|
||||
window_feel feel = (is_subset)?
|
||||
B_MODAL_SUBSET_WINDOW_FEEL :
|
||||
B_MODAL_APP_WINDOW_FEEL;
|
||||
BRect winrect = BRect(aRect.x, aRect.y, aRect.x + aRect.width - 1, aRect.y + aRect.height - 1);
|
||||
winrect.OffsetBy( 10, 30 );
|
||||
nsWindowBeOS *w = new nsWindowBeOS(this,
|
||||
winrect,
|
||||
"", B_TITLED_WINDOW_LOOK, feel,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
w->AddChild(mView);
|
||||
if (is_subset) {
|
||||
w->AddToSubset(parent->Window());
|
||||
}
|
||||
if(mustunlock)
|
||||
{
|
||||
parent->UnlockLooper();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// create window (normal or popup)
|
||||
BRect winrect = BRect(aRect.x, aRect.y,
|
||||
aRect.x + aRect.width - 1, aRect.y + aRect.height - 1);
|
||||
nsWindowBeOS *w;
|
||||
|
||||
// FIXME: we have to use the window size because
|
||||
// the window might not like sizes less then 30x30 or something like that
|
||||
mView->MoveTo(0, 0);
|
||||
mView->ResizeTo(w->Bounds().Width(), w->Bounds().Height());
|
||||
mView->SetResizingMode(B_FOLLOW_ALL);
|
||||
} else
|
||||
if (mWindowType == eWindowType_child) {
|
||||
// create view only
|
||||
bool mustunlock=false;
|
||||
if (mWindowType == eWindowType_popup)
|
||||
{
|
||||
bool is_subset = (mBorderlessParent)? true : false;
|
||||
window_feel feel = (is_subset) ? B_FLOATING_SUBSET_WINDOW_FEEL : B_FLOATING_APP_WINDOW_FEEL;
|
||||
|
||||
w = new nsWindowBeOS(this, winrect, "", B_NO_BORDER_WINDOW_LOOK, feel,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
if (w)
|
||||
{
|
||||
// popup window : no border
|
||||
if (is_subset)
|
||||
{
|
||||
w->AddToSubset(mBorderlessParent->Window());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// normal window :normal look & feel
|
||||
winrect.OffsetBy( 10, 30 );
|
||||
w = new nsWindowBeOS(this, winrect, "", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
}
|
||||
|
||||
if(parent->LockLooper())
|
||||
mustunlock = true;
|
||||
if(w)
|
||||
{
|
||||
w->AddChild(mView);
|
||||
|
||||
parent->AddChild(mView);
|
||||
mView->MoveTo(aRect.x, aRect.y);
|
||||
mView->ResizeTo(aRect.width-1, GetHeight(aRect.height)-1);
|
||||
|
||||
if(mustunlock)
|
||||
parent->UnlockLooper();
|
||||
} else {
|
||||
// create window (normal or popup)
|
||||
BRect winrect = BRect(aRect.x, aRect.y,
|
||||
aRect.x + aRect.width - 1, aRect.y + aRect.height - 1);
|
||||
nsWindowBeOS *w;
|
||||
|
||||
if (mWindowType == eWindowType_popup) {
|
||||
bool is_subset = (mBorderlessParent)? true : false;
|
||||
window_feel feel = (is_subset) ?
|
||||
B_FLOATING_SUBSET_WINDOW_FEEL :
|
||||
B_FLOATING_APP_WINDOW_FEEL;
|
||||
w = new nsWindowBeOS(this,
|
||||
winrect,
|
||||
"", B_NO_BORDER_WINDOW_LOOK, feel,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
// popup window : no border
|
||||
if (is_subset) {
|
||||
w->AddToSubset(mBorderlessParent->Window());
|
||||
}
|
||||
} else {
|
||||
// normal window :normal look & feel
|
||||
winrect.OffsetBy( 10, 30 );
|
||||
w = new nsWindowBeOS(this,
|
||||
winrect,
|
||||
"", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
|
||||
B_WILL_ACCEPT_FIRST_CLICK | B_ASYNCHRONOUS_CONTROLS);
|
||||
}
|
||||
|
||||
w->AddChild(mView);
|
||||
|
||||
// FIXME: we have to use the window size because
|
||||
// the window might not like sizes less then 30x30 or something like that
|
||||
mView->MoveTo(0, 0);
|
||||
mView->ResizeTo(w->Bounds().Width(), w->Bounds().Height());
|
||||
mView->SetResizingMode(B_FOLLOW_ALL);
|
||||
}
|
||||
// FIXME: we have to use the window size because
|
||||
// the window might not like sizes less then 30x30 or something like that
|
||||
mView->MoveTo(0, 0);
|
||||
mView->ResizeTo(w->Bounds().Width(), w->Bounds().Height());
|
||||
mView->SetResizingMode(B_FOLLOW_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Initial Drag & Drop Work
|
||||
#ifdef DRAG_DROP
|
||||
if (!gOLEInited) {
|
||||
DWORD dwVer = ::OleBuildVersion();
|
||||
if (!gOLEInited)
|
||||
{
|
||||
DWORD dwVer = ::OleBuildVersion();
|
||||
|
||||
if (FAILED(::OleInitialize(NULL))){
|
||||
printf("***** OLE has been initialized!\n");
|
||||
}
|
||||
gOLEInited = TRUE;
|
||||
}
|
||||
if (FAILED(::OleInitialize(NULL)))
|
||||
{
|
||||
printf("***** OLE has been initialized!\n");
|
||||
}
|
||||
gOLEInited = TRUE;
|
||||
}
|
||||
|
||||
mDragDrop = new CfDragDrop();
|
||||
//mDragDrop->AddRef();
|
||||
mDragDrop->Initialize(this);
|
||||
mDragDrop = new CfDragDrop();
|
||||
//mDragDrop->AddRef();
|
||||
mDragDrop->Initialize(this);
|
||||
|
||||
/*mDropTarget = new CfDropTarget(*mDragDrop);
|
||||
mDropTarget->AddRef();
|
||||
/*mDropTarget = new CfDropTarget(*mDragDrop);
|
||||
mDropTarget->AddRef();
|
||||
|
||||
mDropSource = new CfDropSource(*mDragDrop);
|
||||
mDropSource->AddRef();*/
|
||||
mDropSource = new CfDropSource(*mDragDrop);
|
||||
mDropSource->AddRef();*/
|
||||
|
||||
/*mDropTarget = new nsDropTarget(this);
|
||||
mDropTarget->AddRef();
|
||||
if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mDropTarget,TRUE,FALSE)) {
|
||||
if (S_OK == ::RegisterDragDrop(mView, (LPDROPTARGET)mDropTarget)) {
|
||||
|
||||
}
|
||||
}*/
|
||||
/*mDropTarget = new nsDropTarget(this);
|
||||
mDropTarget->AddRef();
|
||||
if (S_OK == ::CoLockObjectExternal((LPUNKNOWN)mDropTarget,TRUE,FALSE)) {
|
||||
if (S_OK == ::RegisterDragDrop(mView, (LPDROPTARGET)mDropTarget)) {
|
||||
|
||||
}
|
||||
}*/
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// call the event callback to notify about creation
|
||||
DispatchStandardEvent(NS_CREATE);
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче