r=mkaply, a=brendan
Remove unused widget files
This commit is contained in:
mkaply%us.ibm.com 2000-08-07 21:40:45 +00:00
parent c245821651
commit 22fb378e7d
36 changed files with 0 additions and 4579 deletions

View File

@ -35,8 +35,6 @@ ifdef ENABLE_TESTS
DIRS += tests
endif
CSRCS = tabctrl.c
CPPSRCS = \
nsAppShell.cpp \
nsCanvas.cpp \
@ -66,18 +64,6 @@ CPPSRCS = \
# nsDataObj.cpp \
# nsDataObjCollection.cpp \
# OBSOLETE FILES
# nsBaseList.cpp \
# nsCheckbutton.cpp \
# nsCombobox.cpp \
# nsEntryField.cpp \
# nsLabel.cpp \
# nsListbox.cpp \
# nsPushbutton.cpp \
# nsRadiobutton.cpp \
# nsTextArea.cpp \
# nsTabWidget.cpp \
SHARED_LIBRARY_LIBS = $(DIST)/lib/libxpwidgets_s.$(LIB_SUFFIX)
EXTRA_DSO_LDOPTS = \

View File

@ -1,148 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#include "nsWidgetDefs.h"
#include "nsBaseList.h"
#include "nsStringUtil.h"
// Basic things for talking to listboxen.
// Code shared by listbox & combobox controls.
//
// Very straight-forward; potential DBCS/Unicode problems as ever.
// return false if index is silly
PRBool nsBaseList::CheckIndex( PRInt32 &index)
{
short sItems = GetItemCount();
if( index == -1)
index = sItems - 1;
return index >= sItems ? PR_FALSE : PR_TRUE;
}
nsresult nsBaseList::AddItemAt( nsString &aItem, PRInt32 aPosition)
{
NS_ALLOC_STR_BUF(buf, aItem, 256);
short iPos = aPosition;
if( iPos == -1)
iPos = LIT_END;
SendMsg( LM_INSERTITEM, MPFROMSHORT(iPos), MPFROMP(buf));
NS_FREE_STR_BUF(buf);
return NS_OK;
}
// Despite what the comment says, return the found index.
PRInt32 nsBaseList::FindItem( nsString &aItem, PRInt32 aStartPos)
{
PRInt32 ret = -1;
if( PR_TRUE == CheckIndex( aStartPos))
{
NS_ALLOC_STR_BUF(buf, aItem, 256);
short sStart = aStartPos;
if( sStart == 0)
sStart = LIT_FIRST;
MRESULT rc = SendMsg( LM_SEARCHSTRING,
MPFROM2SHORT(LSS_CASESENSITIVE,sStart),
MPFROMP(buf));
ret = SHORT1FROMMR(rc);
if( ret == LIT_NONE)
ret = -1;
NS_FREE_STR_BUF(buf);
}
return ret;
}
PRInt32 nsBaseList::GetItemCount()
{
return SHORT1FROMMR( SendMsg( LM_QUERYITEMCOUNT));
}
PRBool nsBaseList::RemoveItemAt( PRInt32 aPosition)
{
PRBool rc = CheckIndex( aPosition);
if( rc == PR_TRUE)
SendMsg( LM_DELETEITEM, MPFROMSHORT(aPosition));
return rc;
}
PRBool nsBaseList::GetItemAt( nsString& anItem, PRInt32 aPosition)
{
PRBool rc = CheckIndex( aPosition);
if( rc == PR_TRUE)
{
// first get text length
short len = SHORT1FROMMR( SendMsg( LM_QUERYITEMTEXTLENGTH,
MPFROMSHORT(aPosition)));
NS_ALLOC_CHAR_BUF(buf,256,len+1);
// now get text & fill in string
SendMsg( LM_QUERYITEMTEXT, MPFROM2SHORT(aPosition,len+1), MPFROMP(buf));
anItem.AssignWithConversion(buf);
NS_FREE_CHAR_BUF(buf);
}
return rc;
}
nsresult nsBaseList::GetSelectedItem( nsString &aItem)
{
PRInt32 sel = GetSelectedIndex();
if( sel != -1)
GetItemAt( aItem, sel);
return NS_OK;
}
PRInt32 nsBaseList::GetSelectedIndex()
{
short sel = SHORT1FROMMR( SendMsg( LM_QUERYSELECTION,
MPFROMSHORT(LIT_FIRST)));
if( sel == LIT_NONE)
sel = -1;
return sel;
}
nsresult nsBaseList::SelectItem( PRInt32 aPosition)
{
if( PR_TRUE == CheckIndex( aPosition))
SendMsg( LM_SELECTITEM, MPFROMSHORT(aPosition), MPFROMLONG(TRUE));
return NS_OK;
}
nsresult nsBaseList::Deselect()
{
SendMsg( LM_SELECTITEM, MPFROMSHORT(LIT_NONE));
return NS_OK;
}

View File

@ -1,73 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsbaselist_h
#define _nsbaselist_h
// Share code between listbox & combobox controls.
// Avoid inheriting one from the other.
#include "nsstring.h"
#include "nsISupports.h"
class nsBaseList
{
public:
// nsIListWidget implementation
NS_IMETHOD AddItemAt( nsString &aItem, PRInt32 aPosition);
virtual PRInt32 FindItem( nsString &aItem, PRInt32 aStartPos);
virtual PRInt32 GetItemCount();
virtual PRBool RemoveItemAt( PRInt32 aPosition);
virtual PRBool GetItemAt( nsString& anItem, PRInt32 aPosition);
NS_IMETHOD GetSelectedItem( nsString &aItem);
virtual PRInt32 GetSelectedIndex();
NS_IMETHOD SelectItem( PRInt32 aPosition);
NS_IMETHOD Deselect();
// helper
virtual MRESULT SendMsg( ULONG msg, MPARAM mp1=0, MPARAM mp2=0) = 0;
protected:
PRBool CheckIndex( PRInt32 &index);
};
#define DECL_BASE_LIST_METHODS virtual nsresult AddItemAt( nsString &aItem, PRInt32 aPosition) \
{ return nsBaseList::AddItemAt( aItem,aPosition); } \
virtual PRInt32 FindItem( nsString &aItem, PRInt32 aStartPos) \
{ return nsBaseList::FindItem( aItem, aStartPos); } \
virtual PRInt32 GetItemCount() \
{ return nsBaseList::GetItemCount(); } \
virtual PRBool RemoveItemAt( PRInt32 aPosition) \
{ return nsBaseList::RemoveItemAt( aPosition); } \
virtual PRBool GetItemAt( nsString& anItem, PRInt32 aPosition) \
{ return nsBaseList::GetItemAt( anItem, aPosition); } \
NS_IMETHOD GetSelectedItem( nsString &aItem) \
{ return nsBaseList::GetSelectedItem( aItem); } \
virtual PRInt32 GetSelectedIndex() \
{ return nsBaseList::GetSelectedIndex(); } \
NS_IMETHOD SelectItem( PRInt32 aPosition) \
{ return nsBaseList::SelectItem( aPosition); } \
NS_IMETHOD Deselect() \
{ return nsBaseList::Deselect(); } \
virtual MRESULT SendMsg( ULONG msg, MPARAM mp1=0, MPARAM mp2=0) \
{ return mOS2Toolkit->SendMsg( mWnd, msg, mp1, mp2); }
#endif

View File

@ -1,69 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// Check button control
#include "nsCheckButton.h"
// XP-com
NS_IMPL_ADDREF(nsCheckButton)
NS_IMPL_RELEASE(nsCheckButton)
nsresult nsCheckButton::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsICheckButton)))
{
*aInstancePtr = (void*) ((nsICheckButton*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
NS_IMPL_LABEL(nsCheckButton)
// checked-ness
nsresult nsCheckButton::GetState( PRBool &aState)
{
MRESULT rc = mOS2Toolkit->SendMsg( mWnd, BM_QUERYCHECK);
aState = SHORT1FROMMR(rc);
return NS_OK;
}
nsresult nsCheckButton::SetState( const PRBool aState)
{
mOS2Toolkit->SendMsg( mWnd, BM_SETCHECK, MPFROMLONG(aState));
return NS_OK;
}
// Creation hooks
PCSZ nsCheckButton::WindowClass()
{
return WC_BUTTON;
}
ULONG nsCheckButton::WindowStyle()
{
return BASE_CONTROL_STYLE | BS_CHECKBOX;
}

View File

@ -1,59 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsCheckButton_h
#define _nsCheckButton_h
#include "nsWindow.h"
#include "nsICheckButton.h"
// WC_BUTTON, BS_CHECKBUTTON wrapper for NS_CHECKBUTTON_CID
//
// !! Really want to share code with (at least) nsRadioButton, but there's
// !! so little of it a `nsBaseSelectionButton' seems like overkill.
// !! Maybe if this 'GetPreferredSize' thing get's going it would be better.
class nsCheckButton : public nsWindow, public nsICheckButton
{
public:
nsCheckButton() {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsICheckButton
NS_DECL_LABEL
NS_IMETHOD GetState( PRBool &aState);
NS_IMETHOD SetState( const PRBool aState);
protected:
// message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// Creation hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
};
#endif

View File

@ -1,112 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*
*/
#include "nscombobox.h"
// WC_COMBOBOX wrapper. Hackery present in nsWindow to enable user to just
// talk about the height of the entryfield portion. This may well not work
// because the combobox will size it on its own. Oh well, can be worked on.
NS_IMPL_ADDREF(nsComboBox)
NS_IMPL_RELEASE(nsComboBox)
nsresult nsComboBox::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
if( aIID.Equals( NS_GET_IID(nsIComboBox)))
{
*aInstancePtr = (void*) ((nsIComboBox*)this);
NS_ADDREF_THIS();
return NS_OK;
}
else if( aIID.Equals( NS_GET_IID(nsIListWidget)))
{
*aInstancePtr = (void*) ((nsIListWidget*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return nsWindow::QueryInterface( aIID,aInstancePtr);
}
nsComboBox::nsComboBox() : mDropdown(60), mEntry(gModuleData.lHtEntryfield)
{}
nsresult nsComboBox::PreCreateWidget( nsWidgetInitData *aInitData)
{
if( aInitData != nsnull)
{
// remember the dropdown height
nsComboBoxInitData *comboData = (nsComboBoxInitData*) aInitData;
mDropdown = comboData->mDropDownHeight;
}
return NS_OK;
}
PRBool nsComboBox::OnPresParamChanged( MPARAM mp1, MPARAM mp2)
{
if( LONGFROMMP(mp1) == PP_FONTNAMESIZE)
{
// reget height of entryfield
SWP swp;
WinQueryWindowPos( WinWindowFromID( mWnd, CBID_EDIT), &swp);
mEntry = swp.cy + 6; // another magic number...
}
return PR_FALSE;
}
PRInt32 nsComboBox::GetHeight( PRInt32 aProposedHeight)
{
// See layout/html/forms/src/nsSelectControlFrame.cpp
// return aProposedHeight + mDropdown;
return mDropdown + mEntry;
}
nsresult nsComboBox::GetBounds( nsRect &aRect)
{
aRect.x = mBounds.x;
aRect.y = mBounds.y;
aRect.width = mBounds.width;
aRect.height = mEntry;
return NS_OK;
}
nsresult nsComboBox::GetClientBounds( nsRect &aRect)
{
aRect.x = 0;
aRect.y = 0;
aRect.width = mBounds.width;
aRect.height = mEntry;
return NS_OK;
}
PCSZ nsComboBox::WindowClass()
{
return WC_COMBOBOX;
}
ULONG nsComboBox::WindowStyle()
{
return CBS_DROPDOWNLIST | BASE_CONTROL_STYLE;
}

View File

@ -1,65 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nscombobox_h
#define _nscombobox_h
#include "nsWindow.h"
#include "nsBaseList.h"
#include "nsIComboBox.h"
// WC_COMBOBOX wrapper for NS_COMBOBOX_CID
class nsComboBox : public nsWindow, public nsIComboBox,
public nsBaseList, public nsIListWidget
{
public:
nsComboBox();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// baselist
DECL_BASE_LIST_METHODS
// platform hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
virtual PRInt32 GetHeight( PRInt32 aHeight);
NS_IMETHOD PreCreateWidget( nsWidgetInitData *aInitData);
// Message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// Hacks to pretend we're the size of our entryfield part
NS_IMETHOD GetBounds( nsRect &aRect);
NS_IMETHOD GetClientBounds( nsRect &aRect);
virtual PRBool OnPresParamChanged( MPARAM mp1, MPARAM mp2);
protected:
PRInt32 mDropdown;
PRInt32 mEntry;
};
#endif

View File

@ -1,218 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// popup context menu
#include "nsContextMenu.h"
#include "nsWindow.h"
#include "nsCOMPtr.h"
// Can't WinQueryWindowRect() on menu before popping up...
static void CalcMenuSize( HWND hwnd, PSIZEL szl);
NS_IMPL_ADDREF(nsContextMenu)
NS_IMPL_RELEASE(nsContextMenu)
nsresult nsContextMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if( aIID.Equals(NS_GET_IID(nsIContextMenu)))
{
*aInstancePtr = (void*) ((nsIContextMenu*) this);
NS_ADDREF_THIS();
return NS_OK;
}
if( aIID.Equals(NS_GET_IID(nsIMenuListener)))
{
*aInstancePtr = (void*) ((nsIMenuListener*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if( aIID.Equals(((nsIContextMenu*)this)->GetIID()))
{
*aInstancePtr = (void*) ((nsIContextMenu*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsContextMenu::nsContextMenu() : mOwner(nsnull), mX(0), mY(0), mShowing(PR_FALSE)
{
NS_INIT_REFCNT();
}
nsContextMenu::~nsContextMenu()
{
}
NS_METHOD nsContextMenu::Create(nsISupports *aParent, const nsString& anAlignment,
const nsString& anAnchorAlignment)
{
if(aParent)
{
nsIWidget * parent = nsnull;
aParent->QueryInterface(nsCOMTypeInfo<nsIWidget>::GetIID(), (void**) &parent); // This does the addref
if(parent)
{
mParentWindow = parent;
}
}
mAlignment = anAlignment;
mAnchorAlignment = anAnchorAlignment;
// mMenu = CreatePopupMenu();
return NS_OK;
}
nsresult nsContextMenu::GetParent( nsISupports *&aParent)
{
aParent = nsnull;
if (nsnull != mParentWindow) {
return mParentWindow->QueryInterface(nsCOMTypeInfo<nsISupports>::GetIID(),(void**)&aParent);
}
return NS_ERROR_FAILURE;
}
nsresult nsContextMenu::SetLocation( PRInt32 aX, PRInt32 aY)
{
mX = aX;
mY = aY;
return NS_OK;
}
// nsIMenuListener specialization for
// Called to display the menu: update the DOM tree & then pop up the menu
nsEventStatus nsContextMenu::MenuSelected( const nsMenuEvent &aMenuEvent)
{
// Bail if we're already up. This happens for complicated reasons.
if( mShowing) return nsEventStatus_eIgnore;
// Call superclass method to build the menu
nsDynamicMenu::MenuSelected( aMenuEvent);
// The coords we have are relative to the desktop. Convert to PM.
POINTL ptl = { mX, mY };
ptl.y = gModuleData.szScreen.cy - ptl.y - 1;
// Now look at the "popupalign" attribute to see what corner of the popup
// should go at this location.
// (see http://www.mozilla.org/xpfe/xptoolkit/popups.html)
SIZEL szMenu;
CalcMenuSize( mWnd, &szMenu);
if( mAlignment.EqualsWithConversion("topleft")) // most common case
ptl.y -= szMenu.cy;
else if( mAlignment.EqualsWithConversion("bottomright"))
ptl.x -= szMenu.cx;
else if( mAlignment.EqualsWithConversion("topright"))
{
ptl.x -= szMenu.cx;
ptl.y -= szMenu.cy;
}
mShowing = TRUE;
// Tell owner we're up so it can dispatch our commands.
mOwner->SetContextMenu( this);
WinPopupMenu( HWND_DESKTOP,
(HWND) mOwner->GetNativeData( NS_NATIVE_WIDGET),
mWnd,
ptl.x, ptl.y,
0,
PU_HCONSTRAIN | PU_VCONSTRAIN | PU_NONE |
PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2);
// Because XPFE is Really Great, this is meant to be synchronous. Oh yes.
//
// XXX this loop is WRONG if there is a ``modal dialog'' showing.
#if 0
nsIAppShell *pAppShell;
NS_CreateAppShell( &pAppShell);
#endif
// Guess we ought to get appshell in on the act -- we can get
// the current appshell using NS_GetAppShell() or something, and it
// knows if there's a modal loop 'cos it's smart :-).
// Add a method to the appshell to 'process contextmenu' or something.
//
QMSG qmsg;
BOOL rc;
while( mShowing)
{
rc = WinGetMsg( 0, &qmsg, 0, 0, 0);
if( qmsg.msg == WM_USER) break; // menu is done, leave loop.
WinDispatchMsg( 0, &qmsg);
}
mOwner->SetContextMenu(0);
mShowing = PR_FALSE;
return nsEventStatus_eIgnore;
}
nsEventStatus nsContextMenu::MenuDeselected( const nsMenuEvent &aMenuEvent)
{
// terminate modal loop from popup method
if( mShowing)
{
WinPostQueueMsg( HMQ_CURRENT, WM_USER, 0, 0);
}
return nsEventStatus_eIgnore;
}
// Can't WinQueryWindowRect() on menu before popping up...
void CalcMenuSize( HWND hwnd, PSIZEL szl)
{
#ifndef XP_OS2_VACPP // XXXXX "SHORT too small for MRESULT"
SHORT sItems = (SHORT) WinSendMsg( hwnd, MM_QUERYITEMCOUNT, 0, 0);
memset( szl, 0, sizeof(SIZEL));
for( SHORT i = 0; i < sItems; i++)
{
SHORT sID = (SHORT) WinSendMsg( hwnd, MM_ITEMIDFROMPOSITION,
MPFROMSHORT(i), 0);
RECTL rclItem;
WinSendMsg( hwnd, MM_QUERYITEMRECT, MPFROM2SHORT(sID,0), MPFROMP(&rclItem));
LONG lWidth = rclItem.xRight - rclItem.xLeft;
if( lWidth > szl->cx) szl->cx = lWidth;
szl->cy += (rclItem.yTop - rclItem.yBottom);
}
// Fudge-factor
szl->cy += WinQuerySysValue( HWND_DESKTOP, SV_CYSIZEBORDER);
#endif
}

View File

@ -1,64 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nscontextmenu_h
#define _nscontextmenu_h
#include "nsIContextMenu.h"
#include "nsMenuBase.h"
class nsWindow;
// Pop-up menu
class nsContextMenu : public nsIContextMenu, public nsDynamicMenu
{
public:
nsContextMenu();
virtual ~nsContextMenu();
// nsISupports
NS_DECL_ISUPPORTS
// nsIContextMenu extras
NS_IMETHOD Create( nsISupports *aParent,
const nsString &str1, const nsString &str2);
NS_IMETHOD GetParent( nsISupports *&aParent);
NS_IMETHOD SetLocation( PRInt32 aX, PRInt32 aY);
// nsIMenuListener overrides
nsEventStatus MenuSelected( const nsMenuEvent &aMenuEvent);
nsEventStatus MenuDeselected( const nsMenuEvent &aMenuEvent);
// Common methods
DECL_DYNAMIC_MENU_METHODS
protected:
nsWindow *mOwner;
PRInt32 mX, mY;
PRBool mShowing;
nsString mAnchor;
nsString mAlignment;
nsString mAnchorAlignment;
nsIWidget* mParentWindow;
};
#endif

View File

@ -1,203 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsEntryField.h"
NS_IMPL_ADDREF(nsEntryField)
NS_IMPL_RELEASE(nsEntryField)
nsresult nsEntryField::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsITextWidget)))
{
*aInstancePtr = (void*) ((nsITextWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// Textfield messages; all very straight-forward to translate into PM.
nsresult nsEntryField::GetText( nsString &aTextBuffer, PRUint32 aBufferSize, PRUint32 &size)
{
nsWindow::GetWindowText( aTextBuffer, &size);
return NS_OK;
}
nsresult nsEntryField::SetText( const nsString &aText, PRUint32 &len)
{
SetTitle( aText);
mText = aText;
len = aText.Length();
return NS_OK;
}
nsresult nsEntryField::InsertText( const nsString &aText, PRUint32 aStartPos,
PRUint32 aEndPos, PRUint32& aActualSize)
{
PRUint32 actualSize;
nsString currentText;
GetText( currentText, 256, actualSize);
nsString newText( aText);
currentText.Insert( newText, aStartPos);
SetText( currentText, actualSize);
aActualSize = aText.Length();
mText = currentText;
return NS_OK;
}
nsresult nsEntryField::RemoveText()
{
PRUint32 dummy;
SetText( nsString(), dummy);
return NS_OK;
}
nsresult nsEntryField::SetPassword( PRBool aIsPassword)
{
if( mWnd)
{
if( aIsPassword)
AddToStyle( ES_UNREADABLE);
else
RemoveFromStyle( ES_UNREADABLE);
}
else
{
if( aIsPassword)
mStyle |= ES_UNREADABLE;
else
mStyle &= ~ES_UNREADABLE;
}
return NS_OK;
}
nsresult nsEntryField::SetMaxTextLength( PRUint32 aChars)
{
short sLength = aChars ? (short) aChars : 500; // !! hmm
mOS2Toolkit->SendMsg( mWnd, EM_SETTEXTLIMIT, MPFROMSHORT(sLength));
return NS_OK;
}
nsresult nsEntryField::SetReadOnly( PRBool aReadOnlyFlag, PRBool &old)
{
BOOL bOldState;
if( mWnd)
{
bOldState = (BOOL) mOS2Toolkit->SendMsg( mWnd, EM_QUERYREADONLY);
mOS2Toolkit->SendMsg( mWnd, EM_SETREADONLY, MPFROMLONG(aReadOnlyFlag));
}
else
{
bOldState = mStyle & ES_READONLY;
if( aReadOnlyFlag)
mStyle |= ES_READONLY;
else
mStyle &= ~ES_READONLY;
}
old = bOldState ? PR_TRUE : PR_FALSE;
return NS_OK;
}
nsresult nsEntryField::SelectAll()
{
SetSelection( 0, 32000);
return NS_OK;
}
// Maybe off-by-one errors here, test & see
nsresult nsEntryField::SetSelection( PRUint32 aStartSel, PRUint32 aEndSel)
{
mOS2Toolkit->SendMsg( mWnd, EM_SETSEL,
MPFROM2SHORT( (short)aStartSel, (short)aEndSel));
return NS_OK;
}
nsresult nsEntryField::GetSelection( PRUint32 *aStartSel, PRUint32 *aEndSel)
{
MRESULT rc = mOS2Toolkit->SendMsg( mWnd, EM_QUERYSEL);
if( aStartSel)
*aStartSel = SHORT1FROMMR( rc);
if( aEndSel)
*aEndSel = SHORT2FROMMR( rc);
return NS_OK;
}
nsresult nsEntryField::SetCaretPosition( PRUint32 aPosition)
{
SetSelection( aPosition, aPosition);
return NS_OK;
}
// We're in a bit of trouble here 'cos we can't find out where the cursor
// is if there's a selection. Oh well, do what windows does...
nsresult nsEntryField::GetCaretPosition( PRUint32 &rc)
{
PRUint32 selStart, selEnd;
GetSelection( &selStart, &selEnd);
if( selStart == selEnd)
rc = selStart;
else
rc = (PRUint32) -1;
return NS_OK;
}
// platform hooks
PCSZ nsEntryField::WindowClass()
{
return WC_ENTRYFIELD;
}
ULONG nsEntryField::WindowStyle()
{
return mStyle | ES_MARGIN | ES_LEFT | ES_AUTOSCROLL | BASE_CONTROL_STYLE;
}
nsresult nsEntryField::PreCreateWidget( nsWidgetInitData *aInitData)
{
if( nsnull != aInitData)
{
nsTextWidgetInitData *data = (nsTextWidgetInitData *) aInitData;
if( data->mIsPassword)
mStyle |= ES_UNREADABLE;
if( data->mIsReadOnly)
mStyle |= ES_READONLY;
}
return NS_OK;
}
ULONG nsEntryField::GetSWPFlags( ULONG flags)
{
// add SWP_NOADJUST to stop ever-increasing entryfields
return flags | SWP_NOADJUST;
}
void nsEntryField::PostCreateWidget()
{
SetMaxTextLength( 0);
}

View File

@ -1,66 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nstextwidget_h
#define _nstextwidget_h
#include "nswindow.h"
#include "nsITextWidget.h"
// WC_ENTRYFIELD wrapper, for NS_TEXTFIELD_CID
class nsEntryField : public nsWindow, public nsITextWidget
{
public:
nsEntryField() : nsWindow(), mStyle( 0) {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsITextWidget
NS_IMETHOD GetText( nsString &aTextBuffer, PRUint32 aBufferSize, PRUint32 &);
NS_IMETHOD SetText( const nsString &aText, PRUint32 &);
NS_IMETHOD InsertText( const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32 &);
NS_IMETHOD RemoveText();
NS_IMETHOD SetPassword( PRBool aIsPassword);
NS_IMETHOD SetMaxTextLength( PRUint32 aChars);
NS_IMETHOD SetReadOnly( PRBool aReadOnlyFlag, PRBool &);
NS_IMETHOD SelectAll();
NS_IMETHOD SetSelection( PRUint32 aStartSel, PRUint32 aEndSel);
NS_IMETHOD GetSelection( PRUint32 *aStartSel, PRUint32 *aEndSel);
NS_IMETHOD SetCaretPosition( PRUint32 aPosition);
NS_IMETHOD GetCaretPosition( PRUint32 &pos);
// platform hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
NS_IMETHOD PreCreateWidget( nsWidgetInitData *aInitData);
virtual ULONG GetSWPFlags( ULONG flags);
virtual void PostCreateWidget();
protected:
ULONG mStyle;
nsString mText;
};
#endif

View File

@ -1,99 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsLabel.h"
// XP-com
NS_IMPL_ADDREF(nsLabel)
NS_IMPL_RELEASE(nsLabel)
nsresult nsLabel::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsILabel)))
{
*aInstancePtr = (void*) ((nsILabel*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// nsLabel constructor
nsLabel::nsLabel()
{
mAlignment = eAlign_Left;
}
// Creation hook to create with correct aligment
nsresult nsLabel::PreCreateWidget( nsWidgetInitData *aInitData)
{
if( nsnull != aInitData)
{
nsLabelInitData* data = (nsLabelInitData *) aInitData;
mAlignment = data->mAlignment;
}
return NS_OK;
}
ULONG nsLabel::GetPMStyle( nsLabelAlignment aAlignment)
{
ULONG rc = 0;
switch( aAlignment)
{
case eAlign_Right : rc = DT_RIGHT; break;
case eAlign_Left : rc = DT_LEFT; break;
case eAlign_Center: rc = DT_CENTER; break;
}
return rc;
}
// Label style
nsresult nsLabel::SetAlignment( nsLabelAlignment aAlignment)
{
if( mWnd && aAlignment != mAlignment)
{
// already created a PM window; remove current aligment & add new
RemoveFromStyle( GetPMStyle( mAlignment));
AddToStyle( GetPMStyle( aAlignment));
}
mAlignment = aAlignment;
return NS_OK;
}
// Label text
NS_IMPL_LABEL(nsLabel)
// Creation hooks
PCSZ nsLabel::WindowClass()
{
return WC_STATIC;
}
ULONG nsLabel::WindowStyle()
{
return BASE_CONTROL_STYLE | SS_TEXT | GetPMStyle( mAlignment);
}

View File

@ -1,61 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsLabel_h
#define _nsLabel_h
#include "nsWindow.h"
#include "nsILabel.h"
// WC_STATIC, SS_TEXT wrapper for NS_LABEL_CID
class nsLabel : public nsWindow, public nsILabel
{
public:
nsLabel();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsILabel part
NS_DECL_LABEL
NS_IMETHOD SetAlignment( nsLabelAlignment aAlignment);
// message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// platform hooks
NS_IMETHOD PreCreateWidget( nsWidgetInitData *aInitData);
protected:
nsLabelAlignment mAlignment;
// utility to get the pm style bit from the alignment enumeration value
ULONG GetPMStyle( nsLabelAlignment aAlignment);
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
};
#endif

View File

@ -1,136 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsListBox.h"
// listbox; need more code here to allow multiple selections.
NS_IMPL_ADDREF(nsListBox)
NS_IMPL_RELEASE(nsListBox)
nsresult nsListBox::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE)
{
if( aIID.Equals( NS_GET_IID(nsIListBox)))
{
*aInstancePtr = (void*) ((nsIListBox*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
else if( aIID.Equals( NS_GET_IID(nsIListWidget)))
{
*aInstancePtr = (void*) ((nsIListWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
}
return result;
}
#define LS_U_MULTISEL (LS_MULTIPLESEL | LS_EXTENDEDSEL)
nsresult nsListBox::SetMultipleSelection( PRBool aMultipleSelections)
{
if( mWnd)
{
if( aMultipleSelections)
AddToStyle( LS_U_MULTISEL);
else
RemoveFromStyle( LS_U_MULTISEL);
}
else
{
if( aMultipleSelections)
mStyle |= LS_U_MULTISEL;
else
mStyle &= ~LS_U_MULTISEL;
}
return NS_OK;
}
// Helper
PRInt32 nsListBox::GetSelections( PRInt32 *aIndices, PRInt32 aSize)
{
PRInt32 cItems = 0;
short sItemStart = LIT_FIRST;
for(;;)
{
sItemStart = SHORT1FROMMR( SendMsg( LM_QUERYSELECTION,
MPFROMSHORT(sItemStart)));
if( sItemStart == LIT_NONE)
break;
if( aIndices && cItems < aSize)
aIndices[cItems] = sItemStart;
cItems++;
}
return cItems;
}
PRInt32 nsListBox::GetSelectedCount()
{
return GetSelections( 0, 0);
}
nsresult nsListBox::GetSelectedIndices( PRInt32 aIndices[], PRInt32 aSize)
{
GetSelections( aIndices, aSize);
return NS_OK;
}
nsresult nsListBox::SetSelectedIndices( PRInt32 aIndices[], PRInt32 aSize)
{
// clear selection
Deselect();
for( int i = 0; i < aSize; i++)
SendMsg( LM_SELECTITEM, MPFROMSHORT( aIndices[i]), MPFROMLONG( TRUE));
return NS_OK;
}
// Platform hooks
nsresult nsListBox::PreCreateWidget( nsWidgetInitData *aInitData)
{
if( nsnull != aInitData)
{
nsListBoxInitData *data = (nsListBoxInitData *) aInitData;
if( data->mMultiSelect)
mStyle |= LS_U_MULTISEL;
}
return NS_OK;
}
PCSZ nsListBox::WindowClass()
{
return WC_LISTBOX;
}
ULONG nsListBox::WindowStyle()
{
return mStyle | LS_NOADJUSTPOS | BASE_CONTROL_STYLE;
}

View File

@ -1,65 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nslistbox_h
#define _nslistbox_h
#include "nsWindow.h"
#include "nsBaseList.h"
#include "nsIListBox.h"
// WC_LISTBOX wrapper for NS_LISTBOX_CID
class nsListBox : public nsWindow, public nsIListBox,
public nsBaseList, public nsIListWidget
{
public:
nsListBox() : mStyle(0) {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// baselist
DECL_BASE_LIST_METHODS
// nsIListbox
NS_IMETHOD SetMultipleSelection( PRBool aMultipleSelections);
virtual PRInt32 GetSelectedCount();
NS_IMETHOD GetSelectedIndices( PRInt32 aIndices[], PRInt32 aSize);
NS_IMETHOD SetSelectedIndices( PRInt32 aIndices[], PRInt32 aSize);
// platform hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
NS_IMETHOD PreCreateWidget( nsWidgetInitData *aInitData);
// Message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
protected:
PRInt32 GetSelections( PRInt32 *aIndices, PRInt32 aSize);
ULONG mStyle;
};
#endif

View File

@ -1,174 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// normal menu
#include "nsMenu.h"
#include "nsIMenuBar.h"
#include "nsMenuItem.h"
#include "nsIContextMenu.h"
#include "nsIWebShell.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
#include "nsCOMPtr.h"
NS_IMPL_ADDREF(nsMenu)
NS_IMPL_RELEASE(nsMenu)
nsresult nsMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if( aIID.Equals(NS_GET_IID(nsIMenu)))
{
*aInstancePtr = (void*) ((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;
}
if( aIID.Equals(((nsIMenu*)this)->GetIID()))
{
*aInstancePtr = (void*) ((nsIMenu*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsMenu::nsMenu() : mParent(nsnull)
{
NS_INIT_REFCNT();
}
nsMenu::~nsMenu()
{
}
nsresult nsMenu::Create( nsISupports *aThing, const nsString &aLabel)
{
if( !aThing)
return NS_ERROR_NULL_POINTER;
void *pvHwnd = 0;
nsIMenu *aMenu = nsnull;
nsIContextMenu *aPopup = nsnull;
nsIMenuBar *aBar = nsnull;
if( NS_SUCCEEDED( aThing->QueryInterface( NS_GET_IID(nsIMenuBar),
(void**) &aBar)))
{
aBar->GetNativeData( pvHwnd);
NS_RELEASE(aBar);
}
else if( NS_SUCCEEDED( aThing->QueryInterface( NS_GET_IID(nsIMenu),
(void**) &aMenu)))
{
aMenu->GetNativeData( &pvHwnd);
NS_RELEASE(aMenu);
}
else if( NS_SUCCEEDED( aThing->QueryInterface( NS_GET_IID(nsIContextMenu),
(void**) &aPopup)))
{
aPopup->GetNativeData( &pvHwnd);
NS_RELEASE(aPopup);
}
// This is a bit dubious, as there's no guarantee that this menu
// is being created in the same thread as the parent was. But this
// is probably moot...
nsMenuBase *pPBase = (nsMenuBase*) WinQueryWindowPtr( (HWND) pvHwnd, QWL_USER);
nsMenuBase::Create( HWND_DESKTOP, pPBase->GetTK());
// Connect up to parent menu component
WinSetOwner( mWnd, (HWND) pvHwnd);
mParent = aThing;
// record text
mLabel = aLabel;
return NS_OK;
}
nsresult nsMenu::GetParent( nsISupports * &aParent)
{
NS_IF_RELEASE(aParent);
aParent = mParent;
NS_IF_ADDREF(aParent);
return NS_OK;
}
nsresult nsMenu::GetLabel( nsString &aText)
{
aText = mLabel;
return NS_OK;
}
nsresult nsMenu::SetLabel( const nsString &aText)
{
mLabel = aText;
return NS_OK;
}
NS_METHOD nsMenu::SetEnabled(PRBool aIsEnabled)
{
return NS_OK;
}
NS_METHOD nsMenu::GetEnabled(PRBool* aIsEnabled)
{
return NS_OK;
}
NS_METHOD nsMenu::GetAccessKey(nsString &aText)
{
aText = mAccessKey;
return NS_OK;
}
NS_METHOD nsMenu::SetAccessKey(const nsString &aText)
{
mAccessKey = aText;
return NS_OK;
}
NS_METHOD nsMenu::IsHelpMenu(PRBool* aIsHelpMenu)
{
return NS_OK;
}
NS_METHOD nsMenu::SetNativeData(void * aData)
{
return NS_OK;
}

View File

@ -1,61 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsMenu_h
#define _nsMenu_h
// A submenu which reflects a DOM content model
#include "nsIMenu.h"
#include "nsMenuBase.h"
class nsMenu : public nsIMenu, public nsDynamicMenu
{
public:
nsMenu();
~nsMenu();
// nsISupports
NS_DECL_ISUPPORTS
// nsIMenu extras
NS_IMETHOD Create( nsISupports *aParent, const nsString &aLabel);
NS_IMETHOD GetParent( nsISupports *&aParent);
NS_IMETHOD GetLabel( nsString &aText);
NS_IMETHOD SetLabel( const nsString &aText);
NS_IMETHOD GetEnabled(PRBool* aIsEnabled);
NS_IMETHOD SetEnabled(PRBool aIsEnabled);
NS_IMETHOD GetAccessKey(nsString &aText);
NS_IMETHOD SetAccessKey(const nsString &aText);
NS_IMETHOD IsHelpMenu(PRBool* aIsHelp);
NS_IMETHOD SetNativeData(void* aData);
// Common methods
DECL_DYNAMIC_MENU_METHODS
protected:
nsString mLabel;
nsISupports *mParent;
nsString mAccessKey;
};
#endif

View File

@ -1,242 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// menu bar
#include "nsWindow.h"
#include "nsMenuBar.h"
#include "nsMenu.h"
#include "nsIWebShell.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
// XPCom
NS_IMPL_ADDREF(nsMenuBar)
NS_IMPL_RELEASE(nsMenuBar)
nsresult nsMenuBar::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if( aIID.Equals(NS_GET_IID(nsIMenuBar)))
{
*aInstancePtr = (void*) ((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;
}
if( aIID.Equals(((nsIMenuBar*)this)->GetIID()))
{
*aInstancePtr = (void*) ((nsIMenuBar*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsMenuBar::nsMenuBar() : mWndFrame(nsnull), mParent(nsnull)
{
NS_INIT_REFCNT();
}
nsMenuBar::~nsMenuBar()
{
}
// Creation
nsresult nsMenuBar::Create( nsIWidget *aParent)
{
NS_ASSERTION(aParent,"Menu must have a parent");
nsToolkit *aToolkit = (nsToolkit*) aParent->GetToolkit();
mWndFrame = (HWND) aParent->GetNativeData( NS_NATIVE_WINDOW);
//
// Who knows what kind of window the client's given to us here.
// Search up the window hierarchy until we find a frame.
//
while( !((ULONG)aToolkit->SendMsg( mWndFrame, WM_QUERYFRAMEINFO) & FI_FRAME))
mWndFrame = WinQueryWindow( mWndFrame, QW_PARENT);
nsMenuBase::Create( mWndFrame, aToolkit);
NS_RELEASE(aToolkit); // add-ref'd by above call
// must have id FID_MENU
WinSetWindowUShort( mWnd, QWS_ID, FID_MENU);
// tell the frame about us
UpdateFrame();
// remember parent
mParent = aParent;
return NS_OK;
}
ULONG nsMenuBar::WindowStyle()
{
return MS_ACTIONBAR;
}
nsresult nsMenuBar::GetParent( nsIWidget *&aParent)
{
NS_IF_RELEASE(aParent);
aParent = mParent;
NS_ADDREF(aParent);
return NS_OK;
}
nsresult nsMenuBar::SetParent( nsIWidget *aParent)
{
// XXX oh dear. I don't really want to implement this.
// I guess we could work out what new frame window this
// is & then reparent ourselves, but ewwww.
printf( "nsMenuBar::SetParent() - tell someone\n");
return NS_OK;
}
void nsMenuBar::UpdateFrame()
{
if( mToolkit)
mToolkit->SendMsg( mWndFrame, WM_UPDATEFRAME, MPFROMLONG(FCF_MENU));
}
// Need to override these so we can tell the frame about the new entries
nsresult nsMenuBar::AddMenu( nsIMenu *aMenu)
{
nsresult rc = nsMenuBase::InsertItemAt( aMenu);
UpdateFrame();
return rc;
}
nsresult nsMenuBar::InsertMenuAt( const PRUint32 aCount, nsIMenu *&aMenu)
{
nsresult rc = nsMenuBase::InsertItemAt( aMenu, aCount);
UpdateFrame();
return rc;
}
nsresult nsMenuBar::RemoveMenu( const PRUint32 aCount)
{
nsresult rc = nsMenuBase::RemoveItemAt( aCount);
UpdateFrame();
return rc;
}
nsresult nsMenuBar::RemoveAll()
{
nsresult rc = nsMenuBase::RemoveAll();
UpdateFrame();
return rc;
}
// accessor
nsresult nsMenuBar::GetMenuAt( const PRUint32 aCount, nsIMenu *&aMenu)
{
nsresult rc = NS_ERROR_FAILURE;
NS_IF_RELEASE(aMenu);
if( VerifyIndex( aCount))
{
MENUITEM mI;
nsMenuBase::GetItemAt( aCount, &mI);
nsISupports *aThing = (nsISupports*) mI.hItem;
rc = aThing->QueryInterface( NS_GET_IID(nsIMenu), (void**) &aMenu);
}
return rc;
}
// hmm
nsresult nsMenuBar::Paint()
{
UpdateFrame();
mParent->Invalidate( PR_TRUE);
return NS_OK;
}
// nsIMenuListener interface - used to update menu dynamically and build it
// from a dom content model
// nsWebShellWindow currently fakes a call into here to kick us off
nsEventStatus nsMenuBar::MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *aMenubarNode,
void *aWebShell)
{
nsIWebShell *pWebShell = (nsIWebShell*) aWebShell;
nsIDOMNode *pMenubarNode = (nsIDOMNode*) aMenubarNode;
// Create the menubar, register for notifications with the window
Create( aParentWindow);
aParentWindow->AddMenuListener( this);
aParentWindow->SetMenuBar( this);
// Now iterate through the DOM children creating submenus.
nsCOMPtr<nsIDOMNode> pMenuNode;
pMenubarNode->GetFirstChild( getter_AddRefs(pMenuNode));
while( pMenuNode)
{
nsCOMPtr<nsIDOMElement> pMenuElement( do_QueryInterface(pMenuNode));
if( pMenuElement)
{
nsString nodeType, menuName;
pMenuElement->GetNodeName( nodeType);
if( nodeType.EqualsWithConversion( "menu"))
{
// new submenu
nsString val;
val.AssignWithConversion("value");
pMenuElement->GetAttribute( val, menuName);
nsIMenu *pMenu = new nsMenu;
NS_ADDREF(pMenu);
pMenu->Create( (nsIMenuBar*)this, menuName);
pMenu->SetDOMNode( pMenuNode);
pMenu->SetDOMElement( pMenuElement);
pMenu->SetWebShell( pWebShell);
// insert into menubar; nsMenuBase takes ownership
AddMenu( pMenu);
NS_RELEASE(pMenu);
}
}
nsCOMPtr<nsIDOMNode> pOldNode( pMenuNode);
pOldNode->GetNextSibling( getter_AddRefs(pMenuNode));
}
// Hackish -- nsWebShellWindow doesn't cut its ref, so leave the frame
// window with ownership.
Release(); // can't call NS_RELEASE 'cos |this| is not an lvalue...
return nsEventStatus_eIgnore;
}

View File

@ -1,70 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsMenubar_h
#define _nsMenubar_h
// menubar; WC_MENU with MS_ACTIONBAR
#include "nsMenuBase.h"
#include "nsIMenuBar.h"
class nsMenuBar : public nsIMenuBar, public nsMenuBase
{
public:
nsMenuBar();
~nsMenuBar();
// nsISupports
NS_DECL_ISUPPORTS
// nsIMenuBar
NS_IMETHOD Create( nsIWidget *aParent);
NS_IMETHOD GetParent( nsIWidget *&aParent);
NS_IMETHOD SetParent( nsIWidget *aParent);
NS_IMETHOD AddMenu( nsIMenu *aMenu);
NS_IMETHOD InsertMenuAt( const PRUint32 aCount, nsIMenu *&aMenu);
NS_IMETHOD GetMenuCount( PRUint32 &aCount)
{ return nsMenuBase::GetItemCount( aCount); }
NS_IMETHOD GetMenuAt( const PRUint32 aCount, nsIMenu *&aMenu);
NS_IMETHOD RemoveMenu( const PRUint32 aCount);
NS_IMETHOD RemoveAll();
NS_IMETHOD GetNativeData( void *&aData)
{ return nsMenuBase::GetNativeData( &aData); }
NS_IMETHOD Paint();
// strange mac method
NS_IMETHOD SetNativeData( void *aData) { return NS_OK; }
// nsIMenuListener interface
nsEventStatus MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *menubarNode,
void *aWebShell);
protected:
ULONG WindowStyle();
void UpdateFrame();
HWND mWndFrame; // hang on to the frame hwnd so we can update it
nsIWidget *mParent; // nsIWidget for the frame/client window
};
#endif

View File

@ -1,448 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsMenuBase.h"
#include "nsMenuItem.h"
#include "nsMenu.h"
#include "nsToolkit.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
#include "nsIDOMNode.h"
#include "nsIDOMElement.h"
// Common code used by menu classes
nsMenuBase::nsMenuBase() : mToolkit(0), mWnd(0), mElements(nsnull)
{}
void nsMenuBase::Create( HWND hwndParent, nsToolkit *aToolkit)
{
NS_ASSERTION( aToolkit, "Missing toolkit in menucreation");
mToolkit = aToolkit;
NS_ADDREF(mToolkit);
// thread-switch if necessary
if( !mToolkit->IsPMThread())
{
NS_NOTYETIMPLEMENTED( "Threaded menus");
}
else
{
mWnd = WinCreateWindow( hwndParent,
WC_MENU,
0, // text
WindowStyle(),
0, 0, 0, 0, // pos/size
hwndParent, // owner
HWND_TOP,
0, // window ID
0, 0); // ctldata, presparams
NS_ASSERTION( mWnd, "No menu window");
// store nsMenuBase * in QWL_USER
WinSetWindowPtr( mWnd, QWL_USER, this);
// nice font (hmm)
WinSetPresParam( mWnd, PP_FONTNAMESIZE,
strlen( gModuleData.pszFontNameSize) + 1,
gModuleData.pszFontNameSize);
NS_NewISupportsArray( &mElements);
}
}
ULONG nsMenuBase::WindowStyle()
{
return 0;
}
void nsMenuBase::Destroy()
{
if( mToolkit)
if( !mToolkit->IsPMThread())
{
NS_NOTYETIMPLEMENTED( "Threaded menus");
}
else
{
// XXX Not sure about this -- need to think more.
// Shouldn't it be dealt with by the normal parent-death process?
WinDestroyWindow( mWnd);
mWnd = 0;
}
}
// dumb helper
MRESULT nsMenuBase::SendMsg( ULONG m, MPARAM mp1, MPARAM mp2)
{
MRESULT mrc = 0;
if( mToolkit)
mrc = mToolkit->SendMsg( mWnd, m, mp1, mp2);
return mrc;
}
nsMenuBase::~nsMenuBase()
{
if( mWnd) Destroy();
NS_IF_RELEASE(mToolkit);
NS_IF_RELEASE(mElements);
}
nsresult nsMenuBase::GetItemCount( PRUint32 &aCount)
{
MRESULT rc = SendMsg( MM_QUERYITEMCOUNT);
aCount = SHORT1FROMMP( rc);
return NS_OK;
}
nsresult nsMenuBase::GetNativeData( void **aNative)
{
*aNative = (void*) mWnd;
return NS_OK;
}
// New all-singing, all-dancing insert routine.
//
// The 'aThing' may be an nsIMenu or an nsIMenuItem, joy.
// If it is null, then we're talking about a separator, though this ought
// not to be used.
nsresult nsMenuBase::InsertItemAt( nsISupports *aThing, PRUint32 aPos)
{
nsIMenu *pMenu = nsnull;
nsIMenuItem *pItem = nsnull;
MENUITEM mI = { aPos, 0, 0, 0, 0, (ULONG) aThing };
nsString pStr;
// XXX needs to use unicode converter to get right text
// This is very much an issue now that menus are constructed
// from XUL and so can have an arbitrary encoding.
//
// Whether PM will know what to do with non-western characters
// is another issue! Probably okay if it's in the process'
// codepage (font set via presparams, which take that cp)
// set up menitem depending on what we have...
if( nsnull == aThing)
{
mI.afStyle |= MIS_SEPARATOR;
}
else if( NS_SUCCEEDED( aThing->QueryInterface( NS_GET_IID(nsIMenu),
(void**) &pMenu)))
{
void *hwnd = nsnull;
nsString aString;
pMenu->GetLabel( aString);
pStr.AssignWithConversion( gModuleData.ConvertFromUcs( aString));
mI.afStyle |= MIS_SUBMENU | MIS_TEXT;
pMenu->GetNativeData( &hwnd);
mI.hwndSubMenu = (HWND) hwnd;
NS_RELEASE(pMenu);
}
else if( NS_SUCCEEDED( aThing->QueryInterface( NS_GET_IID(nsIMenuItem),
(void**) &pItem)))
{
nsMenuItem *pPMItem = (nsMenuItem*) pItem; // XXX
nsString aString;
PRBool bIsSep = PR_FALSE;
mI.id = pPMItem->GetPMID();
pPMItem->IsSeparator( bIsSep);
if( bIsSep)
{
mI.afStyle |= MIS_SEPARATOR;
}
else
{
mI.afStyle |= MIS_TEXT;
pPMItem->GetLabel( aString);
pStr.AssignWithConversion( gModuleData.ConvertFromUcs( aString));
}
NS_RELEASE(pItem);
}
else
{
#ifdef DEBUG
printf( "Erk, strange menu thing being added\n");
#endif
return NS_ERROR_FAILURE;
}
// add menu item to gui
SendMsg( MM_INSERTITEM, MPFROMP(&mI), MPFROMP(&pStr));
// ..and take ownership of it (separators don't have it)
if( aThing)
mElements->InsertElementAt( aThing, 0);
return NS_OK;
}
// Pull items off of a menu
nsresult nsMenuBase::GetItemID( USHORT usID, PMENUITEM pItem)
{
SendMsg( MM_QUERYITEM, MPFROM2SHORT(usID, FALSE), MPFROMP(pItem));
return NS_OK;
}
nsresult nsMenuBase::GetItemAt( const PRUint32 &pos, PMENUITEM pItem)
{
nsresult rc = NS_ERROR_ILLEGAL_VALUE;
if( VerifyIndex( pos))
{
// find the ID
MRESULT mrc = SendMsg( MM_ITEMIDFROMPOSITION, MPFROMLONG(pos));
rc = GetItemID( SHORT1FROMMR(mrc), pItem);
rc = NS_OK;
}
return rc;
}
nsresult nsMenuBase::GetItemAt( const PRUint32 &aPos, nsISupports *&aThing)
{
MENUITEM mI = { 0 };
nsresult rc = GetItemAt( aPos, &mI);
if( NS_SUCCEEDED(rc))
{
NS_IF_RELEASE(aThing); // XP-COM correct, but probably bad, sigh.
// This is either an nsIMenu or an nsIMenuItem
aThing = (nsISupports*) mI.hItem;
NS_ADDREF(aThing);
}
return rc;
}
// Update an item (grey, tick)
nsresult nsMenuBase::UpdateItem( PMENUITEM aItem)
{
SendMsg( MM_SETITEM, 0, MPFROMP(aItem));
return NS_OK;
}
nsresult nsMenuBase::RemoveItemAt( const PRUint32 index)
{
MENUITEM mI = { 0 };
nsresult rc = GetItemAt( index, &mI);
if( NS_SUCCEEDED(rc))
{
// remove item from gui
SendMsg( MM_REMOVEITEM, MPFROM2SHORT( mI.id, FALSE));
// remove item from our list if we have it (& hence delete the window)
nsISupports *pThing = (nsISupports*) mI.hItem;
PRInt32 lIndex = 0;
if( pThing && NS_SUCCEEDED( mElements->GetIndexOf( pThing, &lIndex)))
rc = mElements->DeleteElementAt( lIndex);
}
return rc;
}
nsresult nsMenuBase::RemoveAll()
{
PRUint32 count;
GetItemCount( count);
for( PRUint32 i = 0; i < count; i++)
RemoveItemAt( 0);
return NS_OK;
}
BOOL nsMenuBase::VerifyIndex( PRUint32 index)
{
PRUint32 count;
GetItemCount( count);
return index == NS_MIT_END || index < count;
}
// Dummy nsIMenuListener implementation
nsEventStatus nsMenuBase::MenuItemSelected( const nsMenuEvent &aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuBase::MenuSelected(const nsMenuEvent & aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuBase::MenuDeselected(const nsMenuEvent & aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuBase::MenuDestruct( const nsMenuEvent &aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuBase::MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *menubarNode,
void *aWebShell)
{
return nsEventStatus_eIgnore;
}
// nsDynamicMenu, common base class for context & 'normal' menus
//
nsDynamicMenu::nsDynamicMenu() : mListener(0), mWebShell(0),
mDOMNode(0), mDOMElement(0)
{}
nsDynamicMenu::~nsDynamicMenu()
{
NS_IF_RELEASE(mListener);
}
nsresult nsDynamicMenu::AddMenuListener( nsIMenuListener *aMenuListener)
{
if( !aMenuListener)
return NS_ERROR_NULL_POINTER;
NS_IF_RELEASE(mListener);
mListener = aMenuListener;
NS_ADDREF(mListener);
return NS_OK;
}
nsresult nsDynamicMenu::RemoveMenuListener( nsIMenuListener *aMenuListener)
{
if( aMenuListener == mListener)
NS_IF_RELEASE(mListener);
return NS_OK;
}
nsresult nsDynamicMenu::SetDOMNode( nsIDOMNode *aMenuNode)
{
mDOMNode = aMenuNode;
return NS_OK;
}
nsresult nsDynamicMenu::SetDOMElement( nsIDOMElement *aMenuElement)
{
mDOMElement = aMenuElement;
return NS_OK;
}
nsresult nsDynamicMenu::SetWebShell( nsIWebShell *aWebShell)
{
mWebShell = aWebShell;
return NS_OK;
}
// build the menu from the DOM content model.
//
// Note that the tear-down from the previous display is done in the init for
// the next menu so that the MENUITEMs are valid for WM_COMMAND dispatching
//
nsEventStatus nsDynamicMenu::MenuSelected( const nsMenuEvent &aMenuEvent)
{
RemoveAll();
// Go through children of menu node and populate menu
nsCOMPtr<nsIDOMNode> pItemNode;
mDOMNode->GetFirstChild( getter_AddRefs(pItemNode));
while( pItemNode)
{
nsCOMPtr<nsIDOMElement> pItemElement( do_QueryInterface(pItemNode));
if( pItemElement)
{
nsString nodeType;
pItemElement->GetNodeName( nodeType);
if( nodeType.EqualsWithConversion( "menuitem"))
{
// find attributes of menu item & create gui peer
nsString itemName;
nsIMenuItem *pItem = new nsMenuItem;
NS_ADDREF(pItem);
nsString val;
val.AssignWithConversion("value");
pItemElement->GetAttribute( val, itemName);
pItem->Create( (nsIMenu*)this, itemName, PR_FALSE);
InsertItemAt( pItem);
nsString itemCmd, disabled, checked;
val.AssignWithConversion("oncommand");
pItemElement->GetAttribute( val, itemCmd);
val.AssignWithConversion("disabled");
pItemElement->GetAttribute( val, disabled);
val.AssignWithConversion("checked");
pItemElement->GetAttribute( val, checked);
pItem->SetCommand( itemCmd);
pItem->SetWebShell( mWebShell);
pItem->SetDOMElement( pItemElement);
val.AssignWithConversion("true");
pItem->SetEnabled( !disabled.Equals( val));
pItem->SetChecked( checked.Equals( val));
NS_RELEASE(pItem); // ownership of the item has passed to nsMenuBase
}
else if( nodeType.EqualsWithConversion( "menuseparator"))
InsertItemAt( 0);
else if( nodeType.EqualsWithConversion( "menu"))
{
// new submenu
nsString menuName;
nsIMenu *pMenu = new nsMenu;
NS_ADDREF(pMenu);
nsString val;
val.AssignWithConversion("value");
pItemElement->GetAttribute( val, menuName);
pMenu->Create( (nsIMenu*)this, menuName);
pMenu->SetDOMNode( pItemNode);
pMenu->SetDOMElement( pItemElement);
pMenu->SetWebShell( mWebShell);
// insert into menubar
InsertItemAt( pMenu);
NS_RELEASE(pMenu); // owned in nsMenuBase
}
}
nsCOMPtr<nsIDOMNode> pOldNode( pItemNode);
pOldNode->GetNextSibling( getter_AddRefs(pItemNode));
}
return nsEventStatus_eIgnore;
}
nsresult nsDynamicMenu::GetDOMNode(nsIDOMNode ** menuNode)
{
if(menuNode) {
*menuNode = mDOMNode;
// NS_IF_ADDREF(menuNode);
}
return NS_OK;
}

View File

@ -1,144 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsmenubase_h
#define _nsmenubase_h
#include "nsWidgetDefs.h"
#include "nsIMenuListener.h"
class nsString;
class nsIWebShell;
class nsIDOMElement;
class nsIDOMNode;
class nsISupportsArray;
// Base class for the various menu widgets to share code.
class nsToolkit;
class nsMenuBase : public nsIMenuListener
{
public:
nsMenuBase();
virtual ~nsMenuBase();
// common menu methods
NS_IMETHOD GetItemCount( PRUint32 &aCount);
NS_IMETHOD InsertItemAt( nsISupports *aThing, PRUint32 aPos = NS_MIT_END);
NS_IMETHOD GetItemID( USHORT usID, PMENUITEM pItem);
NS_IMETHOD GetItemAt( const PRUint32 &pos, PMENUITEM pItem);
NS_IMETHOD GetItemAt( const PRUint32 &pos, nsISupports *&aThing);
NS_IMETHOD UpdateItem( PMENUITEM pItem);
NS_IMETHOD RemoveItemAt( const PRUint32 index);
NS_IMETHOD RemoveAll();
NS_IMETHOD GetNativeData( void **aNative);
// dummy nsIMenuListener implementation
virtual nsEventStatus MenuSelected( const nsMenuEvent &aMenuEvent);
virtual nsEventStatus MenuItemSelected( const nsMenuEvent &aMenuEvent);
virtual nsEventStatus MenuDeselected( const nsMenuEvent &aMenuEvent);
virtual nsEventStatus MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *menubarNode,
void *aWebShell);
virtual nsEventStatus MenuDestruct( const nsMenuEvent &aMenuEvent);
// helpers
MRESULT SendMsg( ULONG m, MPARAM mp1=0, MPARAM mp2=0);
nsToolkit *GetTK() { return mToolkit; }
protected:
virtual BOOL VerifyIndex( PRUint32 index);
void Create( HWND hwndParent, nsToolkit *aToolkit);
void Destroy();
// Subclasses should supply extra style bits here if required.
virtual ULONG WindowStyle();
nsToolkit *mToolkit;
HWND mWnd;
nsISupportsArray *mElements; // we now own the menu elements
};
#define DECL_MENU_BASE_METHODS \
NS_IMETHOD AddItem( nsISupports *aThing) \
{ return nsMenuBase::InsertItemAt( aThing); } \
NS_IMETHOD AddSeparator() \
{ return nsMenuBase::InsertItemAt( nsnull); } \
NS_IMETHOD GetItemCount( PRUint32 &aCount) \
{ return nsMenuBase::GetItemCount( aCount); } \
NS_IMETHOD GetItemAt( const PRUint32 aCount, nsISupports *&aThing) \
{ return nsMenuBase::GetItemAt( aCount, aThing); } \
NS_IMETHOD InsertItemAt( const PRUint32 aCount, nsISupports *aThing) \
{ return nsMenuBase::InsertItemAt( aThing, aCount); } \
NS_IMETHOD InsertSeparator( const PRUint32 aCount) \
{ return nsMenuBase::InsertItemAt( nsnull, aCount); } \
NS_IMETHOD RemoveItem( const PRUint32 aCount) \
{ return nsMenuBase::RemoveItemAt( aCount); } \
NS_IMETHOD RemoveAll() \
{ return nsMenuBase::RemoveAll(); } \
NS_IMETHOD GetNativeData( void **aNative) \
{ return nsMenuBase::GetNativeData( aNative); }
// Base class for nsMenu & nsContextMenu, menus whose contents are build afresh
// from the DOM content model on each activation.
class nsDynamicMenu : public nsMenuBase
{
public:
nsDynamicMenu();
virtual ~nsDynamicMenu();
// Common methods
NS_IMETHOD AddMenuListener( nsIMenuListener *aMenuListener);
NS_IMETHOD RemoveMenuListener( nsIMenuListener *aMenuListener);
NS_IMETHOD GetDOMNode( nsIDOMNode ** aMenuNode);
NS_IMETHOD SetDOMNode( nsIDOMNode *aMenuNode);
NS_IMETHOD SetDOMElement( nsIDOMElement *aMenuElement);
NS_IMETHOD SetWebShell( nsIWebShell *aWebShell);
// nsIMenuListener override to build/tear down the menu
virtual nsEventStatus MenuSelected( const nsMenuEvent &aMenuEvent);
protected:
nsIMenuListener *mListener;
nsIWebShell *mWebShell;
nsIDOMNode *mDOMNode;
nsIDOMElement *mDOMElement;
};
#define DECL_DYNAMIC_MENU_METHODS \
DECL_MENU_BASE_METHODS \
NS_IMETHOD AddMenuListener( nsIMenuListener *aMenuListener) \
{ return nsDynamicMenu::AddMenuListener( aMenuListener); } \
NS_IMETHOD RemoveMenuListener( nsIMenuListener *aMenuListener) \
{ return nsDynamicMenu::RemoveMenuListener( aMenuListener); } \
NS_IMETHOD GetDOMNode( nsIDOMNode **aMenuNode) \
{ return nsDynamicMenu::GetDOMNode( aMenuNode); } \
NS_IMETHOD SetDOMNode( nsIDOMNode *aMenuNode) \
{ return nsDynamicMenu::SetDOMNode( aMenuNode); } \
NS_IMETHOD SetDOMElement( nsIDOMElement *aMenuElement) \
{ return nsDynamicMenu::SetDOMElement( aMenuElement); } \
NS_IMETHOD SetWebShell( nsIWebShell *aWebShell) \
{ return nsDynamicMenu::SetWebShell( aWebShell); }
#endif

View File

@ -1,441 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// menu item
#include "nsWidgetDefs.h"
#include "nsMenuItem.h"
#include "nsMenuBase.h"
#include "nsIMenu.h"
#include "nsIContextMenu.h"
#include "nsIMenuBar.h"
#include "nsWindow.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
#include "nsIPresContext.h"
#include "nsIWebShell.h"
#include "nsIDOMElement.h"
// XP-Com
NS_IMPL_ADDREF(nsMenuItem)
NS_IMPL_RELEASE(nsMenuItem)
nsresult nsMenuItem::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if( nsnull == aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = nsnull;
if( aIID.Equals(NS_GET_IID(nsIMenuItem)))
{
*aInstancePtr = (void*) ((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;
}
if( aIID.Equals(((nsIMenuItem*)this)->GetIID()))
{
*aInstancePtr = (void*) ((nsIMenuItem*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
// Constructor
nsMenuItem::nsMenuItem() : mMenuBase(nsnull), mIsSeparator(PR_FALSE),
mTarget(nsnull), mPMID(0), mMenuListener(nsnull),
mDOMElement(nsnull), mWebShell(nsnull)
{
NS_INIT_REFCNT();
}
nsMenuItem::~nsMenuItem()
{
NS_IF_RELEASE(mMenuListener);
}
// Helper function to find the widget at the root of the menu tree.
//
// This may have to traverse an arbitrary number of cascaded menus.
static nsIWidget *FindWidget( nsISupports *aParent)
{
nsIWidget *widget = nsnull;
nsIMenu *menu = nsnull;
nsIMenuBar *menuBar = nsnull;
nsIContextMenu *popup = nsnull;
nsISupports *parent = aParent;
// Bump the ref count on the parent, since it gets released unconditionally..
NS_ADDREF(parent);
for( ;;)
{
if( NS_OK == parent->QueryInterface( NS_GET_IID(nsIMenu), (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( NS_GET_IID(nsIContextMenu),
(void**) &popup))
{
nsISupports *pThing = 0;
if( NS_OK != popup->GetParent( pThing))
{
widget = nsnull;
}
pThing->QueryInterface( NS_GET_IID(nsIWidget), (void**) &widget);
NS_RELEASE(parent);
NS_RELEASE(popup);
return widget;
}
else if( NS_OK == parent->QueryInterface( NS_GET_IID(nsIMenuBar),
(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;
}
nsresult nsMenuItem::Create( nsISupports *aParent, const nsString &aLabel,
PRBool aIsSeparator)
{
nsIContextMenu *pPopup = nsnull;
nsIMenu *pMenu = nsnull;
void *pvWnd = 0;
if( NS_SUCCEEDED( aParent->QueryInterface( NS_GET_IID(nsIMenu),
(void**) &pMenu)))
{
pMenu->GetNativeData( &pvWnd);
NS_RELEASE(pMenu);
}
else if( NS_SUCCEEDED( aParent->QueryInterface( NS_GET_IID(nsIContextMenu),
(void**) &pPopup)))
{
pPopup->GetNativeData( &pvWnd);
NS_RELEASE(pPopup);
}
mMenuBase = (nsMenuBase*) WinQueryWindowPtr( (HWND) pvWnd, QWL_USER);
mLabel = aLabel;
mTarget = FindWidget( aParent);
NS_ASSERTION(mTarget,"Can't find window to target menuitem to");
if( mTarget)
{
mIsSeparator = aIsSeparator;
HWND hwnd = (HWND) mTarget->GetNativeData( NS_NATIVE_WINDOW);
nsWindow *wnd = NS_HWNDToWindow( hwnd); // doesn't addref
mPMID = wnd->GetNextCmdID();
mTarget->Release(); // don't want to hold a ref to the window
}
return NS_OK;
}
nsresult nsMenuItem::GetLabel( nsString &aText)
{
aText = mLabel;
return NS_OK;
}
nsresult nsMenuItem::SetLabel( nsString &aText)
{
mLabel = aText;
return NS_OK;
}
// menuitem style
nsresult nsMenuItem::SetEnabled( PRBool aIsEnabled)
{
MENUITEM mI;
mMenuBase->GetItemID( mPMID, &mI);
if( PR_TRUE == aIsEnabled)
mI.afAttribute &= ~MIA_DISABLED;
else
mI.afAttribute |= MIA_DISABLED;
mMenuBase->UpdateItem( &mI);
return NS_OK;
}
nsresult nsMenuItem::GetEnabled( PRBool *aIsEnabled)
{
if( nsnull == aIsEnabled)
return NS_ERROR_NULL_POINTER;
MENUITEM mI;
mMenuBase->GetItemID( mPMID, &mI);
*aIsEnabled = ((mI.afAttribute & MIA_DISABLED) ? PR_FALSE : PR_TRUE);
return NS_OK;
}
nsresult nsMenuItem::SetChecked( PRBool aIsChecked)
{
MENUITEM mI;
mMenuBase->GetItemID( mPMID, &mI);
if( PR_TRUE == aIsChecked)
mI.afAttribute |= MIA_CHECKED;
else
mI.afAttribute &= ~MIA_CHECKED;
mMenuBase->UpdateItem( &mI);
return NS_OK;
}
nsresult nsMenuItem::GetChecked( PRBool *aIsChecked)
{
if( nsnull == aIsChecked)
return NS_ERROR_NULL_POINTER;
MENUITEM mI;
mMenuBase->GetItemID( mPMID, &mI);
*aIsChecked = ((mI.afAttribute & MIA_CHECKED) ? PR_TRUE : PR_FALSE);
return NS_OK;
}
nsresult nsMenuItem::GetCommand( PRUint32 &aCommand)
{
return NS_ERROR_FAILURE;
}
nsresult nsMenuItem::GetTarget( nsIWidget *&aTarget)
{
NS_IF_RELEASE(aTarget);
aTarget = mTarget;
NS_IF_ADDREF(aTarget);
return NS_OK;
}
nsresult nsMenuItem::GetNativeData( void *&aData)
{
return mMenuBase->GetNativeData( &aData);
}
NS_METHOD nsMenuItem::AddMenuListener( nsIMenuListener *aMenuListener)
{
NS_IF_RELEASE(mMenuListener);
mMenuListener = aMenuListener;
NS_ADDREF(mMenuListener);
return NS_OK;
}
NS_METHOD nsMenuItem::RemoveMenuListener( nsIMenuListener *aMenuListener)
{
if( mMenuListener == aMenuListener)
NS_IF_RELEASE(mMenuListener);
return NS_OK;
}
nsresult nsMenuItem::IsSeparator( PRBool &aIsSep)
{
aIsSep = mIsSeparator;
return NS_OK;
}
nsresult nsMenuItem::SetCommand( const nsString &aStrCmd)
{
mCmdString = aStrCmd;
return NS_OK;
}
nsresult nsMenuItem::DoCommand()
{
// code copied from windows
nsresult rv = NS_ERROR_FAILURE;
#if 0 // XXXXX FIXME no longer works due to WebShell changes
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.");
return rv;
}
nsCOMPtr<nsIPresContext> presContext;
if (NS_FAILED(rv = docViewer->GetPresContext(*getter_AddRefs(presContext)))) {
NS_ERROR("Unable to retrieve the doc viewer's presentation context.");
return rv;
}
nsEventStatus status = nsEventStatus_eIgnore;
nsMouseEvent event;
event.eventStructType = NS_MOUSE_EVENT;
event.message = NS_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.");
return rv;
}
rv = contentNode->HandleDOMEvent(presContext, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
#endif
return rv;
}
nsresult nsMenuItem::SetDOMElement( nsIDOMElement *aDOMElement)
{
mDOMElement = aDOMElement;
return NS_OK;
}
nsresult nsMenuItem::GetDOMElement( nsIDOMElement **aDOMElement)
{
if( !aDOMElement)
return NS_ERROR_NULL_POINTER;
NS_IF_RELEASE(*aDOMElement);
*aDOMElement = mDOMElement;
NS_IF_ADDREF(mDOMElement);
return NS_OK;
}
nsresult nsMenuItem::GetDOMNode(nsIDOMNode ** menuNode)
{
if(menuNode) {
*menuNode = mDOMNode;
// NS_IF_ADDREF(menuNode);
}
return NS_OK;
}
nsresult nsMenuItem::SetDOMNode(nsIDOMNode * menuNode)
{
mDOMNode = menuNode;
return NS_OK;
}
nsresult nsMenuItem::SetWebShell( nsIWebShell *aWebShell)
{
mWebShell = aWebShell;
return NS_OK;
}
// nsIMenuListener interface
nsEventStatus nsMenuItem::MenuItemSelected( const nsMenuEvent &aMenuEvent)
{
DoCommand();
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuItem::MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *menubarNode,
void *aWebShell)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuItem::MenuSelected( const nsMenuEvent &aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuItem::MenuDeselected(const nsMenuEvent & aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsEventStatus nsMenuItem::MenuDestruct( const nsMenuEvent &aMenuEvent)
{
return nsEventStatus_eIgnore;
}
nsresult nsMenuItem::SetShortcutChar(const nsString &aText)
{
mKeyEquivalent = aText;
return NS_OK;
}
nsresult nsMenuItem::GetShortcutChar(nsString &aText)
{
aText = mKeyEquivalent;
return NS_OK;
}
nsresult nsMenuItem::SetModifiers(PRUint8 aModifiers)
{
mModifiers = aModifiers;
return NS_OK;
}
nsresult nsMenuItem::GetModifiers(PRUint8 * aModifiers)
{
*aModifiers = mModifiers;
return NS_OK;
}
nsresult nsMenuItem::SetCheckboxType(PRBool aIsCheckbox)
{
return NS_OK;
}
nsresult nsMenuItem::GetCheckboxType(PRBool *aIsCheckbox)
{
return NS_OK;
}
nsresult nsMenuItem::SetMenuItemType(EMenuItemType aType)
{
mMenuType = aType;
return NS_OK;
}
nsresult nsMenuItem::GetMenuItemType(EMenuItemType *aType)
{
*aType = mMenuType;
return NS_OK;
}

View File

@ -1,106 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
// nsMenuItem - interface to things which live in menus.
//
// This is rather complicated, not least because it contains about 2 1/2
// versions of the API rolled up into 1.
#ifndef _nsmenuitem_h
#define _nsmenuitem_h
#include "nsString.h"
#include "nsIMenuItem.h"
#include "nsIMenuListener.h"
class nsMenuBase;
class nsIDOMElement;
class nsIWebShell;
class nsMenuItem : public nsIMenuItem, public nsIMenuListener
{
public:
nsMenuItem();
virtual ~nsMenuItem();
// nsISupports
NS_DECL_ISUPPORTS
// nsIMenuItem
NS_IMETHOD Create( nsISupports *aParent, const nsString &aLabel, PRBool isSep);
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 SetCheckboxType(PRBool aIsCheckbox);
NS_IMETHOD GetCheckboxType(PRBool *aIsCheckbox);
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);
NS_IMETHOD SetMenuItemType(EMenuItemType aIsCheckbox);
NS_IMETHOD GetMenuItemType(EMenuItemType *aIsCheckbox);
// nsIMenuListener interface
nsEventStatus MenuSelected( const nsMenuEvent &aMenuEvent);
nsEventStatus MenuItemSelected( const nsMenuEvent &aMenuEvent);
nsEventStatus MenuDeselected( const nsMenuEvent &aMenuEvent);
nsEventStatus MenuConstruct( const nsMenuEvent &aMenuEvent,
nsIWidget *aParentWindow,
void *menubarNode,
void *aWebShell);
nsEventStatus MenuDestruct( const nsMenuEvent &aMenuEvent);
// nsMenuItem
USHORT GetPMID() { return mPMID; }
protected:
nsMenuBase *mMenuBase; // Menu we are attached to
nsString mLabel;
PRBool mIsSeparator;
nsString mKeyEquivalent;
PRUint8 mModifiers;
nsIWidget *mTarget; // window we dispatch to
USHORT mPMID; // PM command ID
nsIMenuListener *mMenuListener;
nsString mCmdString; // JS command
nsIDOMElement *mDOMElement; // dom element for item
nsIDOMNode *mDOMNode;
nsIWebShell *mWebShell;
EMenuItemType mMenuType;
};
#endif

View File

@ -1,113 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// popup menu
#include "nsPopupMenu.h"
#include "nsWindow.h"
// XPCom
NS_IMPL_ADDREF(nsPopupMenu)
NS_IMPL_RELEASE(nsPopupMenu)
nsresult nsPopupMenu::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
if( !aInstancePtr)
return NS_ERROR_NULL_POINTER;
*aInstancePtr = 0;
if( aIID.Equals(NS_GET_IID(nsIPopupMenu)))
{
*aInstancePtr = (void*) ((nsIPopUpMenu*) this);
NS_ADDREF_THIS();
return NS_OK;
}
if( aIID.Equals(((nsISupports*)(nsIPopUpMenu*)this)->GetIID()))
{
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
nsPopupMenu::nsPopupMenu() : mParent(0), nsMenuBase()
{
NS_INIT_REFCNT();
}
nsPopupMenu::~nsPopupMenu()
{
NS_IF_RELEASE(mParent);
}
// Creation: parent to the desktop, owner to the `parent'
nsresult nsPopupMenu::Create( nsIWidget *aParent)
{
// find the owner hwnd & nsWindow (for the toolkit)
HWND hwndOwner = (HWND) aParent->GetNativeData( NS_NATIVE_WINDOW);
mParent = NS_HWNDToWindow( hwndOwner);
NS_ADDREF(mParent);
nsIToolkit *aToolkit = mParent->GetToolkit();
nsMenuBase::Create( HWND_DESKTOP, (nsToolkit*) aToolkit);
NS_RELEASE(aToolkit);
WinSetOwner( mWnd, hwndOwner);
return NS_OK;
}
nsresult nsPopupMenu::GetParent( nsIWidget *&aParent)
{
NS_IF_RELEASE(aParent);
aParent = mParent;
NS_IF_ADDREF(aParent);
return NS_OK;
}
ULONG nsPopupMenu::WindowStyle()
{
return 0;
}
nsresult nsPopupMenu::ShowMenu( PRInt32 aX, PRInt32 aY)
{
POINTL pos = { aX, aY };
mParent->NS2PM(pos);
WinPopupMenu( HWND_DESKTOP,
(HWND) mParent->GetNativeData( NS_NATIVE_WIDGET),
mWnd, pos.x, pos.y, 0,
PU_HCONSTRAIN | PU_VCONSTRAIN | PU_NONE |
PU_KEYBOARD | PU_MOUSEBUTTON1 | PU_MOUSEBUTTON2);
return NS_OK;
}
NS_METHOD nsPopUpMenu::AddMenu(nsIMenu * aMenu)
{
return NS_OK;
}

View File

@ -1,72 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsPopupMenu_h
#define _nsPopupMenu_h
// A menu for popping up.
#include "nsIPopupMenu.h"
#include "nsMenuBase.h"
class nsWindow;
class nsIMenuItem;
class nsPopupMenu : public nsIPopUpMenu, public nsMenuBase
{
public:
nsPopupMenu();
~nsPopupMenu();
// nsISupports
NS_DECL_ISUPPORTS
// nsIPopupMenu
NS_IMETHOD Create( nsIWidget *aParent);
NS_IMETHOD GetParent( nsIWidget *&aParent);
NS_IMETHOD ShowMenu( PRInt32 aX, PRInt32 aY);
NS_IMETHOD AddMenu(nsIMenu * aMenu);
// Common methods with nsMenu
DECL_MENU_BASE_METHODS
// nsIPopUpMenu hasn't been revamped along with the other menu classes
// in the `dynamic menu' effort, so don't try too hard getting these
// old-style methods implemented -- it'll change soon. (ask saari if
// concerned).
NS_IMETHOD AddItem( nsIMenuItem *aMenuItem)
{ return nsMenuBase::InsertItemAt( aMenuItem); }
NS_IMETHOD GetItemAt( const PRUint32 aCount, nsIMenuItem *&aThing)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD InsertItemAt( const PRUint32 aCount, nsIMenuItem *&aMenuItem)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD InsertItemAt( const PRUint32 aCount, const nsString &aMenuItemName)
{ return NS_ERROR_NOT_IMPLEMENTED; }
NS_IMETHOD GetNativeData( void *&aData)
{ return nsMenuBase::GetNativeData( &aData); }
protected:
ULONG WindowStyle();
nsWindow *mParent;
};
#endif

View File

@ -1,56 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// Push button control; don't really come any simpler than this...
#include "nsPushButton.h"
// XP-com
NS_IMPL_ADDREF(nsPushButton)
NS_IMPL_RELEASE(nsPushButton)
nsresult nsPushButton::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsIButton)))
{
*aInstancePtr = (void*) ((nsIButton*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// Text
NS_IMPL_LABEL(nsPushButton)
// Creation hooks
PCSZ nsPushButton::WindowClass()
{
return WC_BUTTON;
}
ULONG nsPushButton::WindowStyle()
{
return BASE_CONTROL_STYLE | BS_PUSHBUTTON;
}

View File

@ -1,53 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsPushButton_h
#define _nsPushButton_h
#include "nsWindow.h"
#include "nsIButton.h"
// WC_BUTTON, BS_PUSHBUTTON wrapper for NS_BUTTON_CID
class nsPushButton : public nsWindow, public nsIButton
{
public:
nsPushButton() {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIButton
NS_DECL_LABEL
protected:
// message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// Creation hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
};
#endif

View File

@ -1,70 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// Radio button control
#include "nsRadioButton.h"
// XP-com
NS_IMPL_ADDREF(nsRadioButton)
NS_IMPL_RELEASE(nsRadioButton)
nsresult nsRadioButton::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsIRadioButton)))
{
*aInstancePtr = (void*) ((nsIRadioButton*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// Text
NS_IMPL_LABEL(nsRadioButton)
// checked-ness
nsresult nsRadioButton::GetState( PRBool &aState)
{
MRESULT rc = mOS2Toolkit->SendMsg( mWnd, BM_QUERYCHECK);
aState = SHORT1FROMMR(rc);
return NS_OK;
}
nsresult nsRadioButton::SetState( const PRBool aState)
{
mOS2Toolkit->SendMsg( mWnd, BM_SETCHECK, MPFROMLONG(aState));
return NS_OK;
}
// Creation hooks
PCSZ nsRadioButton::WindowClass()
{
return WC_BUTTON;
}
ULONG nsRadioButton::WindowStyle()
{
return BASE_CONTROL_STYLE | BS_RADIOBUTTON;
}

View File

@ -1,59 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsRadioButton_h
#define _nsRadioButton_h
#include "nsWindow.h"
#include "nsIRadioButton.h"
// WC_BUTTON, BS_RADIOBUTTON wrapper for NS_RADIOBUTTON_CID
//
// !! Really want to share code with (at least) nsCheckButton, but there's
// !! so little of it a `nsBaseSelectionButton' seems like overkill.
// !! Maybe if this 'GetPreferredSize' thing get's going it would be better.
class nsRadioButton : public nsWindow, public nsIRadioButton
{
public:
nsRadioButton() {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsIRadioButton
NS_DECL_LABEL
NS_IMETHOD GetState( PRBool &aState);
NS_IMETHOD SetState( const PRBool aState);
protected:
// message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// Creation hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
};
#endif

View File

@ -1,118 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
// C++ interface
#include "nsTabWidget.h"
// C interface
#include "tabapi.h" // !! TAB-FIX
#include <stdlib.h>
// XP-com
NS_IMPL_ADDREF(nsTabWidget)
NS_IMPL_RELEASE(nsTabWidget)
nsresult nsTabWidget::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsITabWidget)))
{
*aInstancePtr = (void*) ((nsITabWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// tab methods
nsresult nsTabWidget::SetTabs( PRUint32 aNumberOfTabs,
const nsString aTabLabels[])
{
nsresult rc = NS_ERROR_FAILURE;
if( mToolkit && mWnd)
{
// first remove current tabs...
// !! oops, can't do this yet :-) // !! TAB-FIX
// mOS2Toolkit->SendMsg( mWnd, TABM_REMOVEALLTABS);
PRUint32 i;
char **strings = new char * [aNumberOfTabs];
for( i = 0; i < aNumberOfTabs; i++)
strings[i] = strdup( gModuleData.ConvertFromUcs( aTabLabels[i]));
BOOL bOk = (BOOL) mOS2Toolkit->SendMsg( mWnd, TABM_INSERTMULTTABS,
MPFROMSHORT(aNumberOfTabs),
MPFROMP(strings));
for( i = 0; i < aNumberOfTabs; i++)
free( strings[i]);
delete [] strings;
if( bOk)
rc = NS_OK;
}
return rc;
}
nsresult nsTabWidget::GetSelectedTab( PRUint32 &aTab)
{
nsresult rc = NS_ERROR_FAILURE;
if( mWnd && mToolkit)
{
MRESULT mrc = mOS2Toolkit->SendMsg( mWnd, TABM_QUERYHILITTAB);
aTab = SHORT1FROMMR( mrc);
if( aTab != TABC_FAILURE)
rc = NS_OK;
aTab--; // !! TAB-INDEX
}
return rc;
}
// Generate mozilla events when appropriate...
PRBool nsTabWidget::OnControl( MPARAM mp1, MPARAM mp2)
{
switch( SHORT2FROMMP(mp1))
{
case TTN_TABCHANGE:
DispatchStandardEvent( NS_TABCHANGE);
break;
}
return PR_TRUE;
}
// Creation hooks...
PCSZ nsTabWidget::WindowClass()
{
return (PCSZ) TabGetTabControlName();
}
ULONG nsTabWidget::WindowStyle()
{
return BASE_CONTROL_STYLE;
}

View File

@ -1,56 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nsTabWidget_h
#define _nsTabWidget_h
#include "nsWindow.h"
#include "nsITabWidget.h"
// C++ wrapper for tab control
class nsTabWidget : public nsWindow, public nsITabWidget
{
public:
nsTabWidget() {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsITabWidget
NS_IMETHOD SetTabs( PRUint32 aNumberOfTabs,
const nsString aTabLabels[]);
NS_IMETHOD GetSelectedTab( PRUint32 &aTab);
// message stopping..
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
// ..and starting
virtual PRBool OnControl( MPARAM mp1, MPARAM mp2);
protected:
// creation hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
};
#endif

View File

@ -1,241 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsTextArea.h"
NS_IMPL_ADDREF(nsTextArea)
NS_IMPL_RELEASE(nsTextArea)
nsresult nsTextArea::QueryInterface( const nsIID &aIID, void **aInstancePtr)
{
nsresult result = nsWindow::QueryInterface( aIID, aInstancePtr);
if( result == NS_NOINTERFACE && aIID.Equals( NS_GET_IID(nsITextAreaWidget)))
{
*aInstancePtr = (void*) ((nsITextAreaWidget*)this);
NS_ADDREF_THIS();
result = NS_OK;
}
return result;
}
// MLE notes: in Warp 4 (and I guess Warp3 fp 28-ish) MLE's *do* respond
// correctly to colour-changes via presparams.
//
// Should really add code to deal with text lengths > 64k.
//
// No DBCS support.
//
// Format is currently left as MLFIE_CFTEXT; need to wait & see what it
// should be. MLFIE_WINFMT could well be the right thing to do; set this
// using the PostCreateWidget() hook.
//
// May also need strategic MLM_DISABLEREFRESH
nsresult nsTextArea::GetText( nsString &aTextBuffer, PRUint32 aBufferSize, PRUint32 &len)
{
if( mToolkit != nsnull)
{
IPT clength = (IPT) mOS2Toolkit->SendMsg( mWnd, MLM_QUERYTEXTLENGTH);
// now get bytes
long length = (long) mOS2Toolkit->SendMsg( mWnd, MLM_QUERYFORMATTEXTLENGTH,
0, MPFROMLONG(length));
// ..buffer..
NS_ALLOC_CHAR_BUF(buf,256,length+1)
mOS2Toolkit->SendMsg( mWnd, MLM_SETIMPORTEXPORT,
MPFROMP(buf), MPFROMLONG(length+1));
IPT start = 0;
mOS2Toolkit->SendMsg( mWnd, MLM_EXPORT, MPFROMP(&start), MPFROMP(&length));
aTextBuffer.SetLength(0);
aTextBuffer.AppendWithConversion(buf);
NS_FREE_CHAR_BUF(buf)
len = clength;
}
else
{
aTextBuffer = mText;
len = aTextBuffer.Length();
}
return NS_OK;
}
nsresult nsTextArea::SetText( const nsString &aText, PRUint32 &len)
{
if( mOS2Toolkit != nsnull)
{
RemoveText();
NS_ALLOC_STR_BUF(buf,aText,512)
mOS2Toolkit->SendMsg( mWnd, MLM_SETIMPORTEXPORT,
MPFROMP(buf), MPFROMLONG(aText.Length() + 1));
IPT ipt = 0;
mOS2Toolkit->SendMsg( mWnd, MLM_IMPORT,
MPFROMP(&ipt), MPFROMLONG(aText.Length()));
NS_FREE_STR_BUF(buf)
}
len = aText.Length();
mText = aText;
return NS_OK;
}
nsresult nsTextArea::InsertText( const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32 &len)
{
PRUint32 dummy;
nsString currentText;
GetText( currentText, 256, dummy);
nsString newText( aText);
currentText.Insert( newText, aStartPos);
SetText( currentText, dummy);
len = aText.Length();
return NS_OK;
}
nsresult nsTextArea::RemoveText()
{
if( mOS2Toolkit != nsnull)
{
IPT length = (IPT) mOS2Toolkit->SendMsg( mWnd, MLM_QUERYTEXTLENGTH);
mOS2Toolkit->SendMsg( mWnd, MLM_DELETE, MPFROMLONG(0), MPFROMLONG(length));
}
return NS_OK;
}
nsresult nsTextArea::SetPassword( PRBool aIsPassword)
{
// no...
return NS_OK;
}
nsresult nsTextArea::SetMaxTextLength( PRUint32 aChars)
{
if( mToolkit != nsnull)
{
long lSize = aChars ? (long)aChars : -1;
mOS2Toolkit->SendMsg( mWnd, MLM_SETTEXTLIMIT, MPFROMLONG(lSize));
}
return NS_OK;
}
nsresult nsTextArea::SetReadOnly( PRBool aReadOnlyFlag, PRBool &bOld)
{
BOOL bOldState;
if( mWnd)
{
bOldState = (BOOL) mOS2Toolkit->SendMsg( mWnd, MLM_QUERYREADONLY);
mOS2Toolkit->SendMsg( mWnd, MLM_SETREADONLY, MPFROMSHORT(aReadOnlyFlag));
}
else
{
bOldState = mStyle & MLS_READONLY;
if( aReadOnlyFlag)
mStyle |= MLS_READONLY;
else
mStyle &= ~MLS_READONLY;
}
bOld = bOldState ? PR_TRUE : PR_FALSE;
return NS_OK;
}
nsresult nsTextArea::SelectAll()
{
if( mToolkit != nsnull)
{
IPT length = (IPT) mOS2Toolkit->SendMsg( mWnd, MLM_QUERYTEXTLENGTH);
SetSelection( 0, length);
}
return NS_OK;
}
nsresult nsTextArea::SetSelection( PRUint32 aStartSel, PRUint32 aEndSel)
{
if( mToolkit != nsnull)
mOS2Toolkit->SendMsg( mWnd, MLM_SETSEL,
MPFROMLONG(aStartSel), MPFROMLONG(aEndSel));
return NS_OK;
}
nsresult nsTextArea::GetSelection( PRUint32 *aStartSel, PRUint32 *aEndSel)
{
if( mToolkit != nsnull)
{
MRESULT rc = mOS2Toolkit->SendMsg( mWnd, MLM_QUERYSEL,
MPFROMLONG(MLFQS_MINMAXSEL));
if( aStartSel)
*aStartSel = SHORT1FROMMR(rc);
if( aEndSel)
*aEndSel = SHORT2FROMMR(rc);
}
return NS_OK;
}
nsresult nsTextArea::SetCaretPosition( PRUint32 aPosition)
{
if( mToolkit != nsnull)
mOS2Toolkit->SendMsg( mWnd, MLM_SETSEL,
MPFROMLONG(aPosition), MPFROMLONG(aPosition));
return NS_OK;
}
nsresult nsTextArea::GetCaretPosition( PRUint32 &ret)
{
if( mToolkit != nsnull)
{
MRESULT rc = mOS2Toolkit->SendMsg( mWnd, MLM_QUERYSEL,
MPFROMLONG(MLFQS_CURSORSEL));
ret = (PRUint32) rc;
}
return NS_OK;
}
// platform hooks
PCSZ nsTextArea::WindowClass()
{
return WC_MLE;
}
ULONG nsTextArea::WindowStyle()
{ // no wordwrap, intentional; should be in interface...
return mStyle | MLS_BORDER | MLS_HSCROLL | MLS_VSCROLL | BASE_CONTROL_STYLE;
}
nsresult nsTextArea::PreCreateWidget( nsWidgetInitData *aInitData)
{
if( nsnull != aInitData)
{
nsTextWidgetInitData *data = (nsTextWidgetInitData *) aInitData;
if( data->mIsReadOnly)
mStyle |= MLS_READONLY;
}
return NS_OK;
}

View File

@ -1,68 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _nstextarea_h
#define _nstextarea_h
#include "nswindow.h"
#include "nsITextAreaWidget.h"
// WC_MLE wrapper, for NS_TEXTAREAWIDGET_CID
class nsTextArea : public nsWindow, public nsITextAreaWidget
{
public:
// scaffolding
nsTextArea() : nsWindow(), mStyle( 0) {}
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// nsITextAreaWidget
NS_IMETHOD GetText( nsString &aTextBuffer, PRUint32 aBufferSize, PRUint32 &);
NS_IMETHOD SetText( const nsString &aText, PRUint32 &);
NS_IMETHOD InsertText( const nsString &aText, PRUint32 aStartPos, PRUint32 aEndPos, PRUint32 &);
NS_IMETHOD RemoveText();
NS_IMETHOD SetPassword( PRBool aIsPassword);
NS_IMETHOD SetMaxTextLength( PRUint32 aChars);
NS_IMETHOD SetReadOnly( PRBool aReadOnlyFlag, PRBool &old);
NS_IMETHOD SelectAll();
NS_IMETHOD SetSelection( PRUint32 aStartSel, PRUint32 aEndSel);
NS_IMETHOD GetSelection( PRUint32 *aStartSel, PRUint32 *aEndSel);
NS_IMETHOD SetCaretPosition( PRUint32 aPosition);
NS_IMETHOD GetCaretPosition( PRUint32 &);
// platform hooks
virtual PCSZ WindowClass();
virtual ULONG WindowStyle();
NS_IMETHOD PreCreateWidget( nsWidgetInitData *aInitData);
// Message stopping
virtual PRBool OnMove( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
virtual PRBool OnResize( PRInt32 aX, PRInt32 aY) { return PR_FALSE; }
protected:
ULONG mStyle;
nsString mText;
};
#endif

View File

@ -64,8 +64,6 @@
//~~~ windowless plugin support
#include "nsplugindefs.h"
#include "tabapi.h" // !! TAB-FIX
#include <stdlib.h>
#include <ctype.h>
#include <unikbd.h>

View File

@ -1,121 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s):
*
*/
#ifndef _tabapi_h
#define _tabapi_h
#ifdef __cplusplus
extern "C" {
#endif
/* Call to get the class name; will register the class on first call */
PSZ TabGetTabControlName(void);
/* messages that can be sent to the tab control */
#define TABM_BASE (WM_USER + 50)
#define TABC_END ((USHORT)-1)
#define TABC_FAILURE ((USHORT)-1)
/* TABM_INSERTMULTTABS - append several tabs to the control */
/* */
/* param1 USHORT usTabs, number of tabs to insert. */
/* param2 PSZ *apszLabels, array of tab labels */
/* */
/* returns BOOL bSuccess */
#define TABM_INSERTMULTTABS (TABM_BASE + 0)
/* TABM_INSERTTAB - add a new tab to the control. If this is the first */
/* tab in the control, it will be the hilighted tab. */
/* */
/* param1 USHORT usIndex, index to insert. May be TABC_END. */
/* param2 PSZ pszStr, label for new tab */
/* */
/* returns USHORT usIndex, index of new tab or TABC_FAILURE */
#define TABM_INSERTTAB (TABM_BASE + 1)
/* TABM_QUERYHILITTAB - get the index of the hilighted tab */
/* */
/* param1 ULONG ulReserved, reserved */
/* param2 ULONG ulReserved, reserved */
/* */
/* returns USHORT usIndex, index of active tab or TABC_FAILURE */
#define TABM_QUERYHILITTAB (TABM_BASE + 2)
/* TABM_QUERYTABCOUNT - how many tabs are there? */
/* */
/* param1 ULONG ulReserved, reserved */
/* param2 ULONG ulReserved, reserved */
/* */
/* returns USHORT usTabs, number of tabs */
#define TABM_QUERYTABCOUNT (TABM_BASE + 3)
/* TABM_QUERYTABTEXT - get a tab's label */
/* */
/* param1 USHORT usIndex, index of tab to query text for */
/* USHORT usLength, length of buffer */
/* param2 PSZ pszBuffer, buffer to get text into */
/* */
/* returns USHORT usChars, chars not copied or TABC_FAILURE */
#define TABM_QUERYTABTEXT (TABM_BASE + 4)
/* TABM_QUERYTABTEXTLENGTH - get the length of a tab's label */
/* */
/* param1 USHORT usIndex, index of tab to query text length for */
/* param2 ULONG ulReserved, reserved */
/* */
/* returns ULONG ulLength, length of text not including null terminator */
#define TABM_QUERYTABTEXTLENGTH (TABM_BASE + 5)
/* TABM_REMOVETAB - remove a tab from the control */
/* */
/* param1 USHORT usIndex, index of tab to remove */
/* param2 ULONG ulReserved, reserved */
/* */
/* returns BOOL bSuccess */
#define TABM_REMOVETAB (TABM_BASE + 6)
/* TABM_SETHILITTAB - set the index of the hilighted tab */
/* */
/* param1 USHORT usIndex, index of requested tab */
/* param2 ULONG ulReserved, reserved */
/* */
/* returns BOOL bSuccess */
#define TABM_SETHILITTAB (TABM_BASE + 7)
/* TABM_SETCAPTION - Change the caption of an existing tab */
/* */
/* param1 USHORT usIndex, index to change. */
/* param2 PSZ pszStr, label for new tab */
/* */
/* returns TRUE or TABC_FAILURE */
#define TABM_SETCAPTION (TABM_BASE + 8)
#define TABM_LASTPUBLIC TABM_SETCAPTION
/* WM_CONTROL id sent to owner; mp2 is the index of the newly selected tab */
#define TTN_TABCHANGE 1
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,412 +0,0 @@
/*
* The contents of this file are subject to the Mozilla 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/MPL/
*
* 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 the Mozilla OS/2 libraries.
*
* The Initial Developer of the Original Code is John Fairhurst,
* <john_fairhurst@iname.com>. Portions created by John Fairhurst are
* Copyright (C) 1999 John Fairhurst. All Rights Reserved.
*
* Contributor(s): Dan Holmes <dholmes@trellis.net>
*
*
* TabCtrl.c - Warpzilla tab control
*
*/
#define INCL_WIN
#define INCL_GPI
#include <os2.h>
#include <stdlib.h>
#include <string.h>
#include "tabapi.h"
/* prototype of window procedure */
MRESULT EXPENTRY fnwpTabCtrl( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
void DrawLine (HPS hps, int x1,int x2, int y1, int y2);
/* Convenience method to get classname & register class */
static BOOL bRegistered;
#define UWC_TABCONTROL "WarpzillaTabControl"
PSZ TabGetTabControlName(void)
{
static PSZ pszClassname;
if(!pszClassname)
{
BOOL rc = WinRegisterClass( 0, /* don't actually need a hab */
UWC_TABCONTROL,
fnwpTabCtrl,
0, /* maybe want CS_SIZEREDRAW here? */
8); /* 4 bytes spare for user, 4 for us */
if(rc)
pszClassname = UWC_TABCONTROL;
}
return pszClassname;
}
/***************************************************************************/
/* */
/* TABDATA */
/* */
/***************************************************************************/
typedef struct _PERTABDATA
{
ULONG ulLength;
PSZ pszTabCaption;
struct _PERTABDATA *nextPerTabdata;
} PERTABDATA,*PPERTABDATA;
typedef struct _TABDATA
{
RECTL rclTabctl;
USHORT usTabCount;
USHORT usCurrentTab;
USHORT usMouseX;
USHORT usMouseY;
PPERTABDATA perTabData;
} TABDATA, *PTABDATA;
/***************************************************************************/
/* */
/* Window procedure - add whatever messages you need */
/* */
/* When you want to define new messages to send to yourself, start at */
/* TABM_LASTPUBLIC + 1 */
/* */
/***************************************************************************/
MRESULT EXPENTRY fnwpTabCtrl( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
{
PTABDATA pData = (PTABDATA) WinQueryWindowPtr( hwnd, 4);
switch( msg)
{
case WM_CREATE:
/* allocate and set up default TABDATA structure */
pData = (PTABDATA) calloc( sizeof(TABDATA), 1);
pData->usTabCount=0;
pData->usCurrentTab=0;
pData->usMouseX=0;
pData->usMouseY=0;
pData->rclTabctl.yTop=0;
pData->rclTabctl.yBottom=0;
pData->rclTabctl.xLeft=0;
pData->rclTabctl.xRight=0;
WinSetWindowPtr( hwnd, 4, pData);
break;
case WM_DESTROY:
{
/* free up contents of TABDATA structure */
/* then free the structure itself */
PPERTABDATA pPTD, pPTD1;
pPTD=pData->perTabData;
while (pPTD) {
if (pPTD->pszTabCaption)
free(pPTD->pszTabCaption);
pPTD1=pPTD->nextPerTabdata;
free(pPTD);
pPTD=pPTD1;
} /* endwhile */
free( pData);
break;
}
case WM_PAINT:
{
PPERTABDATA pPTD, pPTD1;
int x1,i,j,k,numChars;
POINTL ptl;
RECTL rcl,rcl1;
HPS hps = WinBeginPaint( hwnd, NULLHANDLE, &rcl);
WinQueryWindowRect(hwnd,&rcl);
pData->rclTabctl=rcl;
WinFillRect( hps, &rcl, CLR_PALEGRAY);
WinDrawBorder(hps,&rcl,1,1,0L,0L,DB_AREAATTRS);
GpiSetColor (hps,CLR_BLACK);
if (pData->usTabCount>0) {
if (pData->usCurrentTab==0)
pData->usCurrentTab=1;
if (pData->usCurrentTab>0) {
x1=(rcl.xRight-rcl.xLeft) / pData->usTabCount;
rcl1.xLeft=rcl.xLeft+(x1*(pData->usCurrentTab-1));
rcl1.xRight=rcl1.xLeft+x1;
rcl1.yTop=rcl.yTop;
rcl1.yBottom=rcl.yBottom;
// WinFillRect( hps, &rcl1, CLR_DARKGRAY);
} /* endif */
j=(rcl.xRight-rcl.xLeft) / pData->usTabCount;
i=k=0;
/* draw left white line */
if (pData->usCurrentTab==1) {
GpiSetColor (hps,CLR_DARKGRAY);
} else {
GpiSetColor (hps,CLR_WHITE);
} /* endif */
DrawLine(hps,i+1,i+1,rcl.yBottom+1,rcl.yTop-2);
DrawLine(hps,i+2,i+2,rcl.yBottom+1,rcl.yTop-2);
/* draw top white line */
DrawLine(hps,i+1,rcl.xRight-2,rcl.yTop-2,rcl.yTop-2);
DrawLine(hps,i+1,rcl.xRight-2,rcl.yTop-3,rcl.yTop-3);
GpiSetColor (hps,CLR_BLACK);
/* draw left dark gray line */
if (pData->usCurrentTab!=1) {
GpiSetColor (hps,CLR_DARKGRAY);
} else {
GpiSetColor (hps,CLR_WHITE);
} /* endif */
DrawLine(hps,rcl1.xRight-2,rcl1.xRight-2,rcl1.yBottom+1,rcl1.yTop-2);
DrawLine(hps,rcl1.xRight-3,rcl1.xRight-3,rcl1.yBottom+1,rcl1.yTop-2);
/* draw bottom dark gray line */
DrawLine(hps,rcl1.xLeft+1,rcl1.xRight-2,rcl1.yBottom+1,rcl1.yBottom+1);
DrawLine(hps,rcl1.xLeft+1,rcl1.xRight-2,rcl1.yBottom+2,rcl1.yBottom+2);
GpiSetColor (hps,CLR_BLACK);
rcl1.xLeft=rcl.xLeft+i;
rcl1.xRight=rcl1.xLeft+j-2;
rcl1.yTop=rcl.yTop-3;
rcl1.yBottom=rcl.yBottom;
pPTD=pData->perTabData;
numChars=WinDrawText(hps,(LONG)strlen(pPTD->pszTabCaption),pPTD->pszTabCaption,&rcl1,0,0,DT_CENTER|DT_TEXTATTRS|DT_WORDBREAK|DT_VCENTER);
for (i=j;i<rcl.xRight ;i+=(rcl.xRight-rcl.xLeft) / pData->usTabCount) {
GpiSetColor (hps,CLR_BLACK);
k++;
rcl1.xLeft=rcl.xLeft+i;
rcl1.xRight=rcl1.xLeft+j-2;
rcl1.yTop=rcl.yTop-3;
rcl1.yBottom=rcl.yBottom;
if (!pPTD->nextPerTabdata) break;
pPTD=pPTD->nextPerTabdata;
numChars=WinDrawText(hps,(LONG)strlen(pPTD->pszTabCaption),pPTD->pszTabCaption,&rcl1,0,0,DT_CENTER|DT_TEXTATTRS|DT_WORDBREAK|DT_VCENTER);
DrawLine(hps,i,i,rcl.yBottom,rcl.yTop);
/* draw highlites */
if (pData->usCurrentTab==(k+1)) {
GpiSetColor (hps,CLR_DARKGRAY);
} else {
GpiSetColor (hps,CLR_WHITE);
} /* endif */
/* draw left white line */
DrawLine(hps,i+1,i+1,rcl.yBottom+1,rcl.yTop-2);
DrawLine(hps,i+2,i+2,rcl.yBottom+1,rcl.yTop-2);
/* draw top white line */
DrawLine(hps,i+1,rcl.xRight-2,rcl.yTop-2,rcl.yTop-2);
DrawLine(hps,i+1,rcl.xRight-2,rcl.yTop-3,rcl.yTop-3);
if (pData->usCurrentTab!=(k+1)) {
GpiSetColor (hps,CLR_DARKGRAY);
} else {
GpiSetColor (hps,CLR_WHITE);
} /* endif */
/* draw right dark gray line */
DrawLine(hps,rcl1.xRight,rcl1.xRight,rcl1.yBottom+1,rcl1.yTop-2);
DrawLine(hps,rcl1.xRight-1,rcl1.xRight-1,rcl1.yBottom+1,rcl1.yTop-2);
/* draw bottom dark gray line */
DrawLine(hps,rcl1.xLeft+1,rcl1.xRight-2,rcl1.yBottom+1,rcl1.yBottom+1);
DrawLine(hps,rcl1.xLeft+1,rcl1.xRight-2,rcl1.yBottom+2,rcl1.yBottom+2);
GpiSetColor (hps,CLR_BLACK);
} /* endfor */
} /* endif */
WinEndPaint( hps);
return 0;
}
case WM_BUTTON1DOWN:
{
int x1;
RECTL rcl;
if (pData->usTabCount>0) {
WinQueryWindowRect(hwnd,&rcl);
pData->usMouseX=SHORT1FROMMP(mp1);
pData->usMouseY=SHORT2FROMMP(mp1);
x1=pData->usMouseX / (rcl.xRight / pData->usTabCount)+1;
if (x1!=pData->usCurrentTab) {
pData->usCurrentTab=x1;
WinSendMsg(WinQueryWindow(hwnd,QW_OWNER),
WM_CONTROL,
MPFROM2SHORT(WinQueryWindowUShort(hwnd,QWS_ID),TTN_TABCHANGE),
MPFROMSHORT(x1));
WinInvalidateRect( hwnd, 0, TRUE);
} /* endif */
} /* endif */
break;
}
case TABM_INSERTMULTTABS:
{
PPERTABDATA pFirstTabData=0, pPrevious=0;
int k;
/* create new tabs */
for (k=1;k<=SHORT1FROMMP(mp1);k++) {
PPERTABDATA pTabData = calloc( sizeof(PERTABDATA), 1);
if( pPrevious != 0)
{
pPrevious->nextPerTabdata = pTabData;
pPrevious = pTabData;
}
if( pFirstTabData == 0)
{
pFirstTabData = pTabData;
pPrevious = pTabData;
}
pTabData->pszTabCaption=strdup(((char **)mp2)[k-1]);
pTabData->ulLength=strlen(pTabData->pszTabCaption);
pData->usTabCount++;
} /* end for */
if (pData->usTabCount==SHORT1FROMMP(mp1))
pData->perTabData=pFirstTabData;
else
{
PPERTABDATA pPTD=0;
pPTD=pData->perTabData;
while (pPTD->nextPerTabdata)
pPTD=pPTD->nextPerTabdata;
pPTD->nextPerTabdata=pFirstTabData;
}
WinInvalidateRect( hwnd, 0, TRUE);
return (MRESULT)TRUE;
}
case TABM_INSERTTAB:
{
int i,j;
PPERTABDATA pTempTabData, pTabData = calloc(sizeof(PERTABDATA),1);
pTabData->ulLength=strlen((char *)mp2);
pTabData->pszTabCaption=calloc(pTabData->ulLength+1,1);
strcpy(pTabData->pszTabCaption,(char *)mp2);
if (SHORT1FROMMP(mp1)==1) {
pData->perTabData=pTabData;
pData->usTabCount=1;
WinInvalidateRect( hwnd, 0, TRUE);
return (MRESULT)1;
} else {
j=SHORT1FROMMP(mp1);
if (j<=pData->usTabCount+1) {
pTempTabData=pData->perTabData;
for (i=2;i<j;i++)
pTempTabData=pTempTabData->nextPerTabdata;
pTempTabData->nextPerTabdata=pTabData;
if (pData->usTabCount<SHORT1FROMMP(mp1)) {
pData->usTabCount++;
} /* endif */
WinInvalidateRect( hwnd, 0, TRUE);
return mp1;
} else {
free(pTabData);
return (MRESULT)TABC_FAILURE;
} /* endif */
} /* endif */
} /* end case */
case TABM_QUERYHILITTAB:
return MRFROMSHORT((pData->usTabCount?pData->usCurrentTab:TABC_FAILURE));
case TABM_QUERYTABCOUNT:
return MRFROMSHORT(pData->usTabCount);
case TABM_QUERYTABTEXT:
{
int i;
PPERTABDATA pTabData=pData->perTabData;
if (pData->usTabCount>0) {
for (i=1;i<SHORT1FROMMP(mp1);i++) {
pTabData=pTabData->nextPerTabdata;
} /* endfor */
strncpy((char *)mp2,pTabData->pszTabCaption,SHORT1FROMMP(mp2));
return MRFROMSHORT(((SHORT2FROMMP(mp1)<strlen(pTabData->pszTabCaption))?strlen(pTabData->pszTabCaption)-SHORT2FROMMP(mp1):0));
} else {
return MRFROMSHORT(TABC_FAILURE);
} /* endif */
}
case TABM_QUERYTABTEXTLENGTH:
{
int i;
PPERTABDATA pTabData=pData->perTabData;
if (pData->usTabCount>0) {
for (i=1;i<SHORT1FROMMP(mp1);i++) {
pTabData=pTabData->nextPerTabdata;
} /* endfor */
return (MRESULT)(strlen(pTabData->pszTabCaption));
} else {
return (MRESULT)TABC_FAILURE;
} /* endif */
}
case TABM_REMOVETAB:
{
int i;
PPERTABDATA pPTD, pPTD1;
if (SHORT1FROMMP(mp1)>pData->usTabCount)
return (MRESULT)TABC_FAILURE;
if (SHORT1FROMMP(mp1)==1) {
pPTD=pData->perTabData->nextPerTabdata;
free(pData->perTabData->pszTabCaption);
free(pData->perTabData);
pData->perTabData=pPTD;
} else if (SHORT1FROMMP(mp1)==pData->usTabCount) {
pPTD=pData->perTabData;
for (i=1;i<SHORT1FROMMP(mp1)-1;i++)
pPTD=pPTD->nextPerTabdata;
free(pPTD->nextPerTabdata->pszTabCaption);
free(pPTD->nextPerTabdata);
pPTD->nextPerTabdata='\0';
if (SHORT1FROMMP(mp1)==pData->usCurrentTab)
pData->usCurrentTab--;
} else {
pPTD=pData->perTabData; /* first tab */
for (i=1;i<SHORT1FROMMP(mp1)-1;i++)
pPTD=pPTD->nextPerTabdata; /* at end of loop tab before the one to delete */
pPTD1=pPTD->nextPerTabdata; /* the tab to remove */
if (pPTD1->pszTabCaption)
free(pPTD1->pszTabCaption);
pPTD->nextPerTabdata=pPTD1->nextPerTabdata;
free(pPTD1);
}
pData->usTabCount--;
WinSendMsg(WinQueryWindow(hwnd,QW_OWNER),
WM_CONTROL,
MPFROM2SHORT(WinQueryWindowUShort(hwnd,QWS_ID),TTN_TABCHANGE),
MPFROMSHORT(pData->usCurrentTab));
WinInvalidateRect( hwnd, 0, TRUE);
return (MRESULT) TABC_END;
}
case TABM_SETHILITTAB:
{
if (pData->usCurrentTab!=SHORT1FROMMP(mp1)) {
pData->usCurrentTab=SHORT1FROMMP(mp1);
WinInvalidateRect( hwnd, 0, TRUE);
}
return (MRESULT) TABC_END;
}
case TABM_SETCAPTION:
{
int i;
PPERTABDATA pTabData=pData->perTabData;
if (LONGFROMMP(mp1)<=pData->usTabCount) {
for (i=1;i<LONGFROMMP(mp1);i++)
pTabData=pTabData->nextPerTabdata;
free(pTabData->pszTabCaption);
pTabData->pszTabCaption=calloc(LONGFROMMP(mp1),1);
strcpy(pTabData->pszTabCaption,(char *)mp2);
WinInvalidateRect( hwnd, 0, TRUE);
return (MRESULT)1;
} else {
return (MRESULT)TABC_FAILURE;
} /* endif */
}
}
/* call the default window procedure so normal things still work */
return WinDefWindowProc( hwnd, msg, mp1, mp2);
}
void DrawLine (HPS hps, int x1,int x2, int y1, int y2)
{
POINTL ptl;
ptl.x=x1;
ptl.y=y1;
GpiMove(hps,&ptl);
ptl.x=x2;
ptl.y=y2;
GpiLine(hps,&ptl);
}