diff --git a/mozilla/widget/public/Makefile b/mozilla/widget/public/Makefile index 7ab6900911f..73f8458b652 100644 --- a/mozilla/widget/public/Makefile +++ b/mozilla/widget/public/Makefile @@ -40,6 +40,7 @@ EXPORTS = \ nsIEventListener.h \ nsIToolkit.h \ nsWidgetsCID.h \ + nsITooltipWidget.h \ $(NULL) MODULE = raptor diff --git a/mozilla/widget/public/makefile.win b/mozilla/widget/public/makefile.win index 24843a6592f..f5159f37566 100644 --- a/mozilla/widget/public/makefile.win +++ b/mozilla/widget/public/makefile.win @@ -25,7 +25,7 @@ EXPORTS=nsui.h nsIWidget.h nsIButton.h nsICheckButton.h nsIListWidget.h \ nsIComboBox.h nsITextWidget.h nsITextAreaWidget.h nsIComboBox.h \ nsIListBox.h nsIFileWidget.h nsIScrollbar.h nsGUIEvent.h \ nsIRadioButton.h nsIRadioGroup.h nsIMouseListener.h \ - nsIEventListener.h nsIToolkit.h nsWidgetsCID.h nsITabWidget.h + nsIEventListener.h nsIToolkit.h nsWidgetsCID.h nsITabWidget.h nsITooltipWidget.h include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/widget/public/nsIListBox.h b/mozilla/widget/public/nsIListBox.h index 39f83dde113..9944e6a5468 100644 --- a/mozilla/widget/public/nsIListBox.h +++ b/mozilla/widget/public/nsIListBox.h @@ -28,6 +28,10 @@ /** * Single or multi selection list of items. + * Unlike a nsIWidget, The the list widget must automatically clear + * itself to the background color when paint messages are generated. + * The listbox always has a vertical scrollbar. It never has a + * horizontal scrollbar. */ class nsIListBox : public nsIListWidget { diff --git a/mozilla/widget/public/nsITextAreaWidget.h b/mozilla/widget/public/nsITextAreaWidget.h index 7a80b75749b..3a4309b76e2 100644 --- a/mozilla/widget/public/nsITextAreaWidget.h +++ b/mozilla/widget/public/nsITextAreaWidget.h @@ -32,6 +32,8 @@ * See nsITextWidget for capabilities. * Displays a scrollbar when the text content exceeds the number of lines * displayed. + * Unlike a nsIWidget, The textarea must automatically clear + * itself to the background color when paint messages are generated. */ class nsITextAreaWidget : public nsITextWidget diff --git a/mozilla/widget/public/nsITextWidget.h b/mozilla/widget/public/nsITextWidget.h index 283dfcfeca2..1b9af67d375 100644 --- a/mozilla/widget/public/nsITextWidget.h +++ b/mozilla/widget/public/nsITextWidget.h @@ -28,6 +28,8 @@ /** * * Single line text editor. + * Unlike a nsIWidget, The text editor must automatically clear + * itself to the background color when paint messages are generated. * */ diff --git a/mozilla/widget/public/nsITooltipWidget.h b/mozilla/widget/public/nsITooltipWidget.h new file mode 100644 index 00000000000..fb5f08cdf27 --- /dev/null +++ b/mozilla/widget/public/nsITooltipWidget.h @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ +#ifndef nsITooltipWidget_h__ +#define nsITooltipWidget_h__ + +#include "nsIWidget.h" +#include "nsString.h" + +#define NS_ITOOLTIPWIDGET_IID \ +{ 0x2910c191, 0xe38a, 0x11d1, { 0x9e, 0xc1, 0x0, 0xaa, 0x0, 0x2f, 0xb8, 0x21 } }; + +/** + * + * Tool tip display widget + * + */ + +class nsITooltipWidget : public nsIWidget +{ + public: + +}; + +#endif // nsITooltipWidget_h__ + diff --git a/mozilla/widget/public/nsIWidget.h b/mozilla/widget/public/nsIWidget.h index 17c42960df2..2a7b5b097d0 100644 --- a/mozilla/widget/public/nsIWidget.h +++ b/mozilla/widget/public/nsIWidget.h @@ -112,12 +112,15 @@ class nsIWidget : public nsISupports { * hook called synchronously. The return value determines whether * the event goes to the default window procedure or it is hidden * to the os. The assumption is that if the event handler returns - * false the widget does not see the event. + * false the widget does not see the event. The widget should not + * automatically clear the window to the background color. The + * calling code must handle paint messages and clear the background + * itself. * - * @param parent or null if it's a top level window + * @param parent or null if it's a top level window * @param aRect the widget dimension * @param aHandleEventFunction the event handler callback function - * @param aInitData data that is used for widget initialization + * @param aInitData data that is used for widget initialization * */ virtual void Create(nsIWidget *aParent, diff --git a/mozilla/widget/public/nsWidgetsCID.h b/mozilla/widget/public/nsWidgetsCID.h index db1ca47c145..a0c1d000067 100644 --- a/mozilla/widget/public/nsWidgetsCID.h +++ b/mozilla/widget/public/nsWidgetsCID.h @@ -81,8 +81,13 @@ { 0x2d96b3dc, 0xc051, 0x11d1, \ {0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} } -/* 2d96b3dc-c051-11d1-a827-0040959a28c9 */ +/* 2d96b3dd-c051-11d1-a827-0040959a28c9 */ #define NS_TABWIDGET_CID \ { 0x2d96b3dd, 0xc051, 0x11d1, \ {0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} } +/* 2d96b3de-c051-11d1-a827-0040959a28c9 */ +#define NS_TOOLTIPWIDGET_CID \ +{ 0x2d96b3de, 0xc051, 0x11d1, \ + {0xa8, 0x27, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9} } + diff --git a/mozilla/widget/src/windows/makefile.win b/mozilla/widget/src/windows/makefile.win index 168e5f602a4..9ba7da61cfa 100644 --- a/mozilla/widget/src/windows/makefile.win +++ b/mozilla/widget/src/windows/makefile.win @@ -49,6 +49,7 @@ OBJS = \ .\$(OBJDIR)\nsFileWidget.obj \ .\$(OBJDIR)\nsScrollbar.obj \ .\$(OBJDIR)\nsTabWidget.obj \ + .\$(OBJDIR)\nsTooltipWidget.obj \ $(NULL) LINCS= \ diff --git a/mozilla/widget/src/windows/nsTooltipWidget.cpp b/mozilla/widget/src/windows/nsTooltipWidget.cpp new file mode 100644 index 00000000000..40636b156c1 --- /dev/null +++ b/mozilla/widget/src/windows/nsTooltipWidget.cpp @@ -0,0 +1,144 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#include "nsTooltipWidget.h" +#include "nsToolkit.h" +#include "nsColor.h" +#include "nsGUIEvent.h" +#include "nsString.h" +#include "nsStringUtil.h" +#include +#include + +BOOL nsTooltipWidget::sTooltipWidgetIsRegistered = FALSE; + +//------------------------------------------------------------------------- +// +// nsTooltipWidget constructor +// +//------------------------------------------------------------------------- +nsTooltipWidget::nsTooltipWidget(nsISupports *aOuter) : nsWindow(aOuter) +{ +} + +//------------------------------------------------------------------------- +// +// nsTooltipWidget destructor +// +//------------------------------------------------------------------------- +nsTooltipWidget::~nsTooltipWidget() +{ +} + +//------------------------------------------------------------------------- +// +// Query interface implementation +// +//------------------------------------------------------------------------- +nsresult nsTooltipWidget::QueryObject(const nsIID& aIID, void** aInstancePtr) +{ + nsresult result = nsWindow::QueryObject(aIID, aInstancePtr); + + static NS_DEFINE_IID(kInsTooltipWidgetIID, NS_ITOOLTIPWIDGET_IID); + if (result == NS_NOINTERFACE && aIID.Equals(kInsTooltipWidgetIID)) { + *aInstancePtr = (void*) ((nsITooltipWidget*)this); + AddRef(); + result = NS_OK; + } + + return result; +} + +//------------------------------------------------------------------------- +// +// paint message. Don't send the paint out +// +//------------------------------------------------------------------------- +PRBool nsTooltipWidget::OnPaint() +{ + return PR_FALSE; +} + +PRBool nsTooltipWidget::OnResize(nsRect &aWindowRect) +{ + return PR_FALSE; +} + +//------------------------------------------------------------------------- +// +// return the window class name and initialize the class if needed +// +//------------------------------------------------------------------------- + +LPCTSTR nsTooltipWidget::WindowClass() +{ + const LPCTSTR className = "NetscapeTooltipWidgetClass"; + + if (!nsTooltipWidget::sTooltipWidgetIsRegistered) { + WNDCLASS wc; + + wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS; + wc.lpfnWndProc = ::DefWindowProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = nsToolkit::mDllInstance; + wc.hIcon = 0; + wc.hCursor = NULL; + wc.hbrBackground = ::CreateSolidBrush(NSRGB_2_COLOREF(NS_RGB(255,255,225))); + wc.lpszMenuName = NULL; + wc.lpszClassName = className; + + nsTooltipWidget::sTooltipWidgetIsRegistered = ::RegisterClass(&wc); + } + + return className; +} + +//------------------------------------------------------------------------- +// +// return window styles +// +//------------------------------------------------------------------------- +DWORD nsTooltipWidget::WindowStyle() +{ + return WS_POPUP; +} + +//------------------------------------------------------------------------- +// +// return window extended styles +// +//------------------------------------------------------------------------- +DWORD nsTooltipWidget::WindowExStyle() +{ + return 0; //WS_EX_TOPMOST; +} + +//------------------------------------------------------------------------- +// +// Clear window before paint +// +//------------------------------------------------------------------------- + +PRBool nsTooltipWidget::AutoErase() +{ + return(PR_TRUE); +} + + + diff --git a/mozilla/widget/src/windows/nsTooltipWidget.h b/mozilla/widget/src/windows/nsTooltipWidget.h new file mode 100644 index 00000000000..3060cd252d9 --- /dev/null +++ b/mozilla/widget/src/windows/nsTooltipWidget.h @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef nsTooltipWidget_h__ +#define nsTooltipWidget_h__ + +#include "nsdefs.h" +#include "nsWindow.h" +#include "nsSwitchToUIThread.h" + +#include "nsITooltipWidget.h" + +/** + * Native Win32 tooltip window wrapper + */ + +class nsTooltipWidget : public nsWindow, + public nsITooltipWidget +{ + +public: + nsTooltipWidget(nsISupports *aOuter); + virtual ~nsTooltipWidget(); + + // nsISupports. Forward to the nsObject base class + BASE_SUPPORT + + virtual nsresult QueryObject(const nsIID& aIID, void** aInstancePtr); + + // nsIWidget interface + BASE_IWIDGET_IMPL + + virtual PRBool OnPaint(); + virtual PRBool OnResize(nsRect &aWindowRect); + virtual PRBool AutoErase(); + +protected: + virtual LPCTSTR WindowClass(); + virtual DWORD WindowStyle(); + virtual DWORD WindowExStyle(); + +private: + static BOOL sTooltipWidgetIsRegistered; + +}; + +#endif // nsTooltipWidget_h__ diff --git a/mozilla/widget/src/windows/nsWidgetFactory.cpp b/mozilla/widget/src/windows/nsWidgetFactory.cpp index c47fedb7dcd..3814be8bc25 100644 --- a/mozilla/widget/src/windows/nsWidgetFactory.cpp +++ b/mozilla/widget/src/windows/nsWidgetFactory.cpp @@ -34,25 +34,28 @@ #include "nsTextWidget.h" #include "nsToolkit.h" #include "nsTabWidget.h" +#include "nsTooltipWidget.h" #include "nsWindow.h" -static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); -static NS_DEFINE_IID(kCChild, NS_CHILD_CID); -static NS_DEFINE_IID(kCButton, NS_BUTTON_CID); -static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID); -static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID); -static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID); -static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID); -static NS_DEFINE_IID(kCRadioButton, NS_RADIOBUTTON_CID); -static NS_DEFINE_IID(kCRadioGroup, NS_RADIOGROUP_CID); +static NS_DEFINE_IID(kCWindow, NS_WINDOW_CID); +static NS_DEFINE_IID(kCChild, NS_CHILD_CID); +static NS_DEFINE_IID(kCButton, NS_BUTTON_CID); +static NS_DEFINE_IID(kCCheckButton, NS_CHECKBUTTON_CID); +static NS_DEFINE_IID(kCCombobox, NS_COMBOBOX_CID); +static NS_DEFINE_IID(kCFileOpen, NS_FILEWIDGET_CID); +static NS_DEFINE_IID(kCListbox, NS_LISTBOX_CID); +static NS_DEFINE_IID(kCRadioButton, NS_RADIOBUTTON_CID); +static NS_DEFINE_IID(kCRadioGroup, NS_RADIOGROUP_CID); static NS_DEFINE_IID(kCHorzScrollbar, NS_HORZSCROLLBAR_CID); static NS_DEFINE_IID(kCVertScrollbar, NS_VERTSCROLLBAR_CID); -static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID); -static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID); -static NS_DEFINE_IID(kCTabWidget, NS_TABWIDGET_CID); +static NS_DEFINE_IID(kCTextArea, NS_TEXTAREA_CID); +static NS_DEFINE_IID(kCTextField, NS_TEXTFIELD_CID); +static NS_DEFINE_IID(kCTabWidget, NS_TABWIDGET_CID); +static NS_DEFINE_IID(kCTooltipWidget, NS_TOOLTIPWIDGET_CID); -static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); + +static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); +static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); class nsWidgetFactory : public nsIFactory { @@ -187,6 +190,9 @@ nsresult nsWidgetFactory::CreateInstance(nsISupports *aOuter, else if (mClassID.Equals(kCTabWidget)) { inst = (nsObject*)new nsTabWidget(aOuter); } + else if (mClassID.Equals(kCTooltipWidget)) { + inst = (nsObject*)new nsTooltipWidget(aOuter); + } if (inst == NULL) { return NS_ERROR_OUT_OF_MEMORY; diff --git a/mozilla/widget/src/windows/nsWindow.cpp b/mozilla/widget/src/windows/nsWindow.cpp index 631d271e5c1..df1b0f373a5 100644 --- a/mozilla/widget/src/windows/nsWindow.cpp +++ b/mozilla/widget/src/windows/nsWindow.cpp @@ -85,7 +85,6 @@ void nsWindow::AddTooltip(HWND hwndOwner,nsRect& aRect) (LPARAM) (LPTOOLINFO) &ti)) return; - // return hwndTT; } //------------------------------------------------------------------------- @@ -1209,7 +1208,7 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT // say we've dealt with erase background if widget does // not need auto-erasing case WM_ERASEBKGND: - if (! AutoErase()) { + if (! AutoErase()) { *aRetValue = 1; result = PR_TRUE; } @@ -1366,6 +1365,8 @@ PRBool nsWindow::ProcessMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT //------------------------------------------------------------------------- LPCTSTR nsWindow::WindowClass() { + const LPCTSTR className = "NetscapeWindowClass"; + if (!nsWindow::sIsRegistered) { WNDCLASS wc; @@ -1378,12 +1379,12 @@ LPCTSTR nsWindow::WindowClass() wc.hCursor = NULL; wc.hbrBackground = NULL; wc.lpszMenuName = NULL; - wc.lpszClassName = "NetscapeWindowClass"; + wc.lpszClassName = className; nsWindow::sIsRegistered = ::RegisterClass(&wc); } - return "NetscapeWindowClass"; + return className; } diff --git a/mozilla/widget/tests/windows/winmain.cpp b/mozilla/widget/tests/windows/winmain.cpp index 31ef584656c..4181fd38be4 100644 --- a/mozilla/widget/tests/windows/winmain.cpp +++ b/mozilla/widget/tests/windows/winmain.cpp @@ -48,6 +48,7 @@ #include "nsRepository.h" #include "nsWidgetsCID.h" #include "nsITabWidget.h" +#include "nsITooltipWidget.h" #include @@ -71,7 +72,7 @@ nsITabWidget *tabWidget = NULL; nsIButton *toolTipButton1 = NULL; nsIButton *toolTipButton2 = NULL; -nsIButton *tooltipWindow = NULL; +nsITooltipWidget *tooltipWindow = NULL; char * gFailedMsg = NULL; @@ -120,6 +121,7 @@ static NS_DEFINE_IID(kCTextAreaCID, NS_TEXTAREA_CID); static NS_DEFINE_IID(kCTextFieldCID, NS_TEXTFIELD_CID); static NS_DEFINE_IID(kCTabWidgetCID, NS_TABWIDGET_CID); +static NS_DEFINE_IID(kCTooltipWidgetCID, NS_TOOLTIPWIDGET_CID); // interface ids @@ -135,6 +137,7 @@ static NS_DEFINE_IID(kIListBoxIID, NS_ILISTBOX_IID); static NS_DEFINE_IID(kIComboBoxIID, NS_ICOMBOBOX_IID); static NS_DEFINE_IID(kIFileWidgetIID, NS_IFILEWIDGET_IID); static NS_DEFINE_IID(kITabWidgetIID, NS_ITABWIDGET_IID); +static NS_DEFINE_IID(kITooltipWidgetIID, NS_ITOOLTIPWIDGET_IID); char * eval(PRInt32 aVal) { @@ -371,7 +374,7 @@ nsIButton* createSimpleButton(nsIWidget * aWin, nsIButton *button; nsRect rect(aX, aY, aWidth, 25); NSRepository::CreateInstance(kCButtonCID, nsnull, kIButtonIID, (LPVOID*)&button); - button->Create(window, rect, aHandleEventFunction, NULL); + button->Create(aWin, rect, aHandleEventFunction, NULL); nsString label(aTitle); button->SetLabel(label); button->Show(PR_TRUE); @@ -380,6 +383,26 @@ nsIButton* createSimpleButton(nsIWidget * aWin, } +/**-------------------------------------------------------------------------------- + * + */ +nsITooltipWidget* createTooltipWindow(nsIWidget * aWin, + char * aTitle, + int aX, + int aY, + int aWidth, + EVENT_CALLBACK aHandleEventFunction) { + nsITooltipWidget *tooltip; + nsRect rect(aX, aY, aWidth, 40); + NSRepository::CreateInstance(kCTooltipWidgetCID, nsnull, kITooltipWidgetIID, (LPVOID*)&tooltip); + tooltip->Create((nsIWidget*)NULL, rect, aHandleEventFunction, NULL); + nsIButton *toolTipButton = createSimpleButton(tooltip, "tooltip",5, 5, 80, 0); + tooltip->Show(PR_TRUE); + return tooltip; +} + + + /**-------------------------------------------------------------------------------- * List Test Handler *-------------------------------------------------------------------------------- @@ -988,6 +1011,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd NSRepository::RegisterFactory(kCTextAreaCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); NSRepository::RegisterFactory(kCTextFieldCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); NSRepository::RegisterFactory(kCTabWidgetCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); + NSRepository::RegisterFactory(kCTooltipWidgetCID, "raptorwidget.dll", PR_FALSE, PR_FALSE); static NS_DEFINE_IID(kCRenderingContextIID, NS_RENDERING_CONTEXT_CID); static NS_DEFINE_IID(kCDeviceContextIID, NS_DEVICE_CONTEXT_CID); @@ -1027,7 +1051,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmd window->Create((nsIWidget*)NULL, rect, HandleEvent, NULL); window->SetTitle("TOP-LEVEL window"); - tooltipWindow = createSimpleButton(window, "INSERT here", 0, 0, 150, 0); + tooltipWindow = createTooltipWindow(window, "INSERT here", 0, 0, 150, 0); tooltipWindow->Show(PR_FALSE); toolTipButton1 = createSimpleButton(window, "Tooltip \\/\\/",400, 100, 100, 0); toolTipButton2 = createSimpleButton(window, "Tooltip /\\/\\",500, 200, 100, 0);