From 3a19e16d18542ec645271612d3e0170831cbf0eb Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 31 Jan 1999 23:38:10 +0000 Subject: [PATCH] wxToolTip for MSW implementation (it has several problems right now, but it still works) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/frame.h | 329 +++++++++++++++++++++------------------ include/wx/msw/tooltip.h | 52 +++++++ src/msw/tooltip.cpp | 196 +++++++++++++++++++++++ src/msw/window.cpp | 171 ++++++++++++-------- 4 files changed, 530 insertions(+), 218 deletions(-) create mode 100644 include/wx/msw/tooltip.h create mode 100644 src/msw/tooltip.cpp diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 9038a6e60b..d039be9de4 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -27,164 +27,187 @@ WXDLLEXPORT_DATA(extern const char*) wxStatusLineNameStr; class WXDLLEXPORT wxMenuBar; class WXDLLEXPORT wxStatusBar; -class WXDLLEXPORT wxFrame: public wxWindow { - - DECLARE_DYNAMIC_CLASS(wxFrame) +class WXDLLEXPORT wxFrame : public wxWindow +{ +DECLARE_DYNAMIC_CLASS(wxFrame) public: - wxFrame(void); - inline wxFrame(wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - { - Create(parent, id, title, pos, size, style, name); - } - - ~wxFrame(void); - - bool Create(wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); - - virtual bool Destroy(void); - - void SetClientSize(int width, int height); - void SetClientSize(const wxSize& sz) { wxWindow::SetClientSize(sz); } - - void GetClientSize(int *width, int *height) const; - wxSize GetClientSize() const { return wxWindow::GetClientSize(); } - - void GetSize(int *width, int *height) const ; - wxSize GetSize() const { return wxWindow::GetSize(); } - - void GetPosition(int *x, int *y) const ; - wxPoint GetPosition() const { return wxWindow::GetPosition(); } - - virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); - - virtual void ClientToScreen(int *x, int *y) const; - - virtual void ScreenToClient(int *x, int *y) const; - - virtual bool OnClose(void); - - void OnSize(wxSizeEvent& event); - void OnMenuHighlight(wxMenuEvent& event); - void OnActivate(wxActivateEvent& event); - void OnIdle(wxIdleEvent& event); - void OnCloseWindow(wxCloseEvent& event); - - bool Show(bool show); - - // Set menu bar - void SetMenuBar(wxMenuBar *menu_bar); - virtual wxMenuBar *GetMenuBar(void) const ; - - // Set title - void SetTitle(const wxString& title); - wxString GetTitle(void) const ; - - void Centre(int direction = wxBOTH); - - // Call this to simulate a menu command - virtual void Command(int id); - virtual void ProcessCommand(int id); - - // Set icon - virtual void SetIcon(const wxIcon& icon); - - // Create status line - virtual wxStatusBar* CreateStatusBar(int number=1, long style = wxST_SIZEGRIP, wxWindowID id = 0, - const wxString& name = wxStatusLineNameStr); - inline wxStatusBar *GetStatusBar() const { return m_frameStatusBar; } - inline void SetStatusBar(wxStatusBar *statusBar) { m_frameStatusBar = statusBar; } - virtual void PositionStatusBar(void); - virtual wxStatusBar *OnCreateStatusBar(int number, long style, wxWindowID id, - const wxString& name); - - // Create toolbar - virtual wxToolBar* CreateToolBar(long style = wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT, - wxWindowID id = -1, - const wxString& name = wxToolBarNameStr); - virtual wxToolBar *OnCreateToolBar(long style, wxWindowID id, const wxString& name); - // If made known to the frame, the frame will manage it automatically. - virtual inline void SetToolBar(wxToolBar *toolbar) { m_frameToolBar = toolbar; } - virtual inline wxToolBar *GetToolBar(void) const { return m_frameToolBar; } - virtual void PositionToolBar(void); - - // Set status line text - virtual void SetStatusText(const wxString& text, int number = 0); - - // Set status line widths - virtual void SetStatusWidths(int n, const int widths_field[]); - - // Hint to tell framework which status bar to use - // TODO: should this go into a wxFrameworkSettings class perhaps? - static void UseNativeStatusBar(bool useNative) { m_useNativeStatusBar = useNative; }; - static bool UsesNativeStatusBar(void) { return m_useNativeStatusBar; }; - - // Fit frame around subwindows - virtual void Fit(void); - - // Iconize - virtual void Iconize(bool iconize); - - virtual bool IsIconized(void) const ; - - // Is it maximized? - virtual bool IsMaximized(void) const ; - - // Compatibility - inline bool Iconized(void) const { return IsIconized(); } - - virtual void Maximize(bool maximize); -// virtual bool LoadAccelerators(const wxString& table); - - // Responds to colour changes - void OnSysColourChanged(wxSysColourChangedEvent& event); - - // Query app for menu item updates (called from OnIdle) - void DoMenuUpdates(void); - void DoMenuUpdates(wxMenu* menu); - - WXHMENU GetWinMenu(void) const ; - - // Checks if there is a toolbar, and returns the first free client position - virtual wxPoint GetClientAreaOrigin() const; - - // Handlers - bool MSWOnPaint(void); - WXHICON MSWOnQueryDragIcon(void); - void MSWOnSize(int x, int y, WXUINT flag); - bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); - bool MSWOnClose(void); - void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); - bool MSWProcessMessage(WXMSG *msg); - bool MSWTranslateMessage(WXMSG *msg); - void MSWCreate(int id, wxWindow *parent, const char *WXUNUSED(wclass), wxWindow *wx_win, const char *title, + wxFrame(); + wxFrame(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr) + { + Create(parent, id, title, pos, size, style, name); + } + + ~wxFrame(); + + bool Create(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr); + + virtual bool Destroy(); + + void SetClientSize(int width, int height); + void SetClientSize(const wxSize& sz) { wxWindow::SetClientSize(sz); } + + void GetClientSize(int *width, int *height) const; + wxSize GetClientSize() const { return wxWindow::GetClientSize(); } + + void GetSize(int *width, int *height) const ; + wxSize GetSize() const { return wxWindow::GetSize(); } + + void GetPosition(int *x, int *y) const ; + wxPoint GetPosition() const { return wxWindow::GetPosition(); } + + virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO); + + virtual void ClientToScreen(int *x, int *y) const; + + virtual void ScreenToClient(int *x, int *y) const; + + virtual bool OnClose(); + + void OnSize(wxSizeEvent& event); + void OnMenuHighlight(wxMenuEvent& event); + void OnActivate(wxActivateEvent& event); + void OnIdle(wxIdleEvent& event); + void OnCloseWindow(wxCloseEvent& event); + + bool Show(bool show); + + // Set menu bar + void SetMenuBar(wxMenuBar *menu_bar); + virtual wxMenuBar *GetMenuBar() const ; + + // Set title + void SetTitle(const wxString& title); + wxString GetTitle() const ; + + void Centre(int direction = wxBOTH); + + // Call this to simulate a menu command + virtual void Command(int id); + virtual void ProcessCommand(int id); + + // Set icon + virtual void SetIcon(const wxIcon& icon); + + // Toolbar + virtual wxToolBar* CreateToolBar(long style = wxNO_BORDER | wxTB_HORIZONTAL | wxTB_FLAT, + wxWindowID id = -1, + const wxString& name = wxToolBarNameStr); + + virtual wxToolBar *OnCreateToolBar(long style, wxWindowID id, const wxString& name); + + virtual void SetToolBar(wxToolBar *toolbar) { m_frameToolBar = toolbar; } + virtual wxToolBar *GetToolBar() const { return m_frameToolBar; } + + virtual void PositionToolBar(); + + // Status bar + virtual wxStatusBar* CreateStatusBar(int number = 1, + long style = wxST_SIZEGRIP, + wxWindowID id = 0, + const wxString& name = wxStatusLineNameStr); + + wxStatusBar *GetStatusBar() const { return m_frameStatusBar; } + void SetStatusBar(wxStatusBar *statusBar) { m_frameStatusBar = statusBar; } + + virtual void PositionStatusBar(); + virtual wxStatusBar *OnCreateStatusBar(int number, + long style, + wxWindowID id, + const wxString& name); + + // Set status line text + virtual void SetStatusText(const wxString& text, int number = 0); + + // Set status line widths + virtual void SetStatusWidths(int n, const int widths_field[]); + + // Hint to tell framework which status bar to use + // TODO: should this go into a wxFrameworkSettings class perhaps? + static void UseNativeStatusBar(bool useNative) { m_useNativeStatusBar = useNative; }; + static bool UsesNativeStatusBar() { return m_useNativeStatusBar; }; + + // Fit frame around subwindows + virtual void Fit(); + + // Iconize + virtual void Iconize(bool iconize); + + virtual bool IsIconized() const ; + + // Is it maximized? + virtual bool IsMaximized() const ; + + // Compatibility + bool Iconized() const { return IsIconized(); } + + virtual void Maximize(bool maximize); + // virtual bool LoadAccelerators(const wxString& table); + + // Responds to colour changes + void OnSysColourChanged(wxSysColourChangedEvent& event); + + // Query app for menu item updates (called from OnIdle) + void DoMenuUpdates(); + void DoMenuUpdates(wxMenu* menu); + + WXHMENU GetWinMenu() const ; + + // Returns the origin of client area (may be different from (0,0) if the + // frame has a toolbar) + virtual wxPoint GetClientAreaOrigin() const; + + // Implementation only from here + // event handlers + bool MSWOnPaint(); + WXHICON MSWOnQueryDragIcon(); + void MSWOnSize(int x, int y, WXUINT flag); + bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); + bool MSWOnClose(); + void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); + bool MSWProcessMessage(WXMSG *msg); + bool MSWTranslateMessage(WXMSG *msg); + void MSWCreate(int id, wxWindow *parent, const char *wclass, + wxWindow *wx_win, const char *title, int x, int y, int width, int height, long style); + // tooltip management +#if wxUSE_TOOLTIPS + WXHWND GetToolTipCtrl() const { return m_hwndToolTip; } + void SetToolTipCtrl(WXHWND hwndTT) { m_hwndToolTip = hwndTT; } +#endif // tooltips + protected: - // propagate our state change to all child frames - void IconizeChildFrames(bool bIconize); - - wxMenuBar * m_frameMenuBar; - wxStatusBar * m_frameStatusBar; - wxIcon m_icon; - bool m_iconized; - WXHICON m_defaultIcon; - static bool m_useNativeStatusBar; - wxToolBar * m_frameToolBar ; - - DECLARE_EVENT_TABLE() + // propagate our state change to all child frames + void IconizeChildFrames(bool bIconize); + + wxMenuBar * m_frameMenuBar; + wxStatusBar * m_frameStatusBar; + wxIcon m_icon; + bool m_iconized; + WXHICON m_defaultIcon; + wxToolBar * m_frameToolBar ; + + static bool m_useNativeStatusBar; + +#if wxUSE_TOOLTIPS + WXHWND m_hwndToolTip; +#endif // tooltips + +private: + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/wx/msw/tooltip.h b/include/wx/msw/tooltip.h new file mode 100644 index 0000000000..d2ece32c85 --- /dev/null +++ b/include/wx/msw/tooltip.h @@ -0,0 +1,52 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: msw/tooltip.h +// Purpose: wxToolTip class - tooltip control +// Author: Vadim Zeitlin +// Modified by: +// Created: 31.01.99 +// RCS-ID: $Id$ +// Copyright: (c) 1999 Robert Roebling, Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +class wxToolTip : public wxObject +{ +public: + // ctor & dtor + wxToolTip(const wxString &tip); + virtual ~wxToolTip(); + + // accessors + // tip text + void SetTip(const wxString& tip); + const wxString& GetTip() const { return m_text; } + + // the window we're associated with + void SetWindow(wxWindow *win); + wxWindow *GetWindow() const { return m_window; } + + // controlling tooltip behaviour: under MSW, these functions change the + // behaviour of the tooltips for all controls in the same frame as this + // one (it is an implementation limitation). Also, these functions won't + // do anything before the tooltip control is associated with a window, so + // SetWindow() should be called first + // enable or disable the tooltips globally + void Enable(bool flag); + // set the delay after which the tooltip appears + void SetDelay(long milliseconds); + + // implementation + void RelayEvent(WXMSG *msg); + +private: + // create the tooltip ctrl for our parent frame if it doesn't exist yet + // and return its window handle + WXHWND GetToolTipCtrl(); + + // remove this tooltip from the tooltip control + void Remove(); + + wxString m_text; // tooltip text + wxWindow *m_window; // window we're associated with +}; + diff --git a/src/msw/tooltip.cpp b/src/msw/tooltip.cpp new file mode 100644 index 0000000000..73c0165697 --- /dev/null +++ b/src/msw/tooltip.cpp @@ -0,0 +1,196 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: msw/tooltip.cpp +// Purpose: wxToolTip class implementation for MSW +// Author: Vadim Zeitlin +// Modified by: +// Created: 31.01.99 +// RCS-ID: $Id$ +// Copyright: (c) 1999 Vadim Zeitlin +// Licence: wxWindows license +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#ifndef WX_PRECOMP + #include "wx/wx.h" +#endif + +#include "wx/tooltip.h" +#include "wx/msw/private.h" + +#include + +// ---------------------------------------------------------------------------- +// private classes +// ---------------------------------------------------------------------------- + +// a simple wrapper around TOOLINFO Win32 structure +class wxToolInfo : public TOOLINFO +{ +public: + wxToolInfo(wxWindow *win) + { + // initialize all members + ::ZeroMemory(this, sizeof(TOOLINFO)); + + cbSize = sizeof(TOOLINFO); + uFlags = TTF_IDISHWND; + uId = (UINT)win->GetHWND(); + } +}; + +// ---------------------------------------------------------------------------- +// private functions +// ---------------------------------------------------------------------------- + +// send a message to the tooltip control +inline LRESULT SendTooltipMessage(WXHWND hwnd, + UINT msg, + WPARAM wParam, + void *lParam) +{ + return hwnd ? ::SendMessage((HWND)hwnd, msg, wParam, (LPARAM)lParam) + : 0; +} + +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// "semiglobal" functions - these methods work with the tooltip control which +// is shared among all the wxToolTips of the same frame +// ---------------------------------------------------------------------------- + +// create the tooltip ctrl for our parent frame if it doesn't exist yet +WXHWND wxToolTip::GetToolTipCtrl() +{ + wxWindow *parent = m_window; + while ( parent && !parent->IsKindOf(CLASSINFO(wxFrame)) ) + { + parent = parent->GetParent(); + } + + wxCHECK_MSG( parent, 0, "can't create tooltip control outside a frame" ); + + wxFrame *frame = (wxFrame *)parent; + HWND hwndTT = (HWND)frame->GetToolTipCtrl(); + if ( !hwndTT ) + { + hwndTT = ::CreateWindow(TOOLTIPS_CLASS, + (LPSTR)NULL, + TTS_ALWAYSTIP, + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + (HWND)frame->GetHWND(), (HMENU)NULL, + wxGetInstance(), NULL); + + if ( hwndTT ) + { + frame->SetToolTipCtrl((WXHWND)hwndTT); + } + else + { + wxLogSysError(_("Can not create tooltip control")); + } + } + + return (WXHWND)hwndTT; +} + +void wxToolTip::Enable(bool flag) +{ + (void)SendTooltipMessage(GetToolTipCtrl(), TTM_ACTIVATE, flag, 0); +} + +void wxToolTip::RelayEvent(WXMSG *msg) +{ + (void)SendTooltipMessage(GetToolTipCtrl(), TTM_RELAYEVENT, 0, msg); +} + +void wxToolTip::SetDelay(long milliseconds) +{ + (void)SendTooltipMessage(GetToolTipCtrl(), TTM_SETDELAYTIME, + TTDT_INITIAL, (void *)milliseconds); +} + +// ---------------------------------------------------------------------------- +// ctor & dtor +// ---------------------------------------------------------------------------- + +wxToolTip::wxToolTip(const wxString &tip) + : m_text(tip) +{ + m_window = NULL; +} + +wxToolTip::~wxToolTip() +{ + // there is no need to Remove() this tool - it will be done automatically + // anyhow +} + +// ---------------------------------------------------------------------------- +// others +// ---------------------------------------------------------------------------- + +void wxToolTip::Remove() +{ + // remove this tool from the tooltip control + if ( m_window ) + { + wxToolInfo ti(m_window); + (void)SendTooltipMessage(GetToolTipCtrl(), TTM_DELTOOL, 0, &ti); + } +} + +void wxToolTip::SetWindow(wxWindow *win) +{ + Remove(); + + m_window = win; + + if ( m_window ) + { + wxToolInfo ti(m_window); + + // as we store our text anyhow, it seems useless to waste system memory + // by asking the tooltip ctrl to remember it too - instead it will send + // us TTN_NEEDTEXT (via WM_NOTIFY) when it is about to be shown + ti.hwnd = (HWND)m_window->GetHWND(); + ti.lpszText = LPSTR_TEXTCALLBACK; + // instead of: ti.lpszText = (char *)m_text.c_str(); + + if ( !SendTooltipMessage(GetToolTipCtrl(), TTM_ADDTOOL, 0, &ti) ) + { + wxLogSysError(_("Failed to create the tooltip '%s'"), + m_text.c_str()); + } + } +} + +void wxToolTip::SetTip(const wxString& tip) +{ + m_text = tip; + + if ( m_window ) + { + // update it immediately + wxToolInfo ti(m_window); + ti.lpszText = (char *)m_text.c_str(); + + (void)SendTooltipMessage(GetToolTipCtrl(), TTM_UPDATETIPTEXT, 0, &ti); + } +} diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 7df1986533..78eb269cf5 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -21,21 +21,21 @@ #endif #ifndef WX_PRECOMP -#include -#include "wx/setup.h" -#include "wx/menu.h" -#include "wx/dc.h" -#include "wx/dcclient.h" -#include "wx/utils.h" -#include "wx/app.h" -#include "wx/panel.h" -#include "wx/layout.h" -#include "wx/dialog.h" -#include "wx/frame.h" -#include "wx/listbox.h" -#include "wx/button.h" -#include "wx/settings.h" -#include "wx/msgdlg.h" + #include + #include "wx/setup.h" + #include "wx/menu.h" + #include "wx/dc.h" + #include "wx/dcclient.h" + #include "wx/utils.h" + #include "wx/app.h" + #include "wx/panel.h" + #include "wx/layout.h" + #include "wx/dialog.h" + #include "wx/frame.h" + #include "wx/listbox.h" + #include "wx/button.h" + #include "wx/settings.h" + #include "wx/msgdlg.h" #endif #if wxUSE_OWNER_DRAWN @@ -48,25 +48,30 @@ #include "wx/menuitem.h" #include "wx/log.h" +#include "wx/tooltip.h" + #include "wx/msw/private.h" #include #ifndef __GNUWIN32__ -#include -#include + #include + #include #endif #ifdef __WIN32__ -#include + #include #endif +#include + #ifndef __TWIN32__ -#ifdef __GNUWIN32__ -#include -#endif + #ifdef __GNUWIN32__ + #include + #endif #endif +// all these are defined in #ifdef GetCharWidth #undef GetCharWidth #endif @@ -97,13 +102,11 @@ void wxAssociateWinWithHandle(HWND hWnd, wxWindow *win); wxWindow *wxFindWinFromHandle(WXHWND hWnd); #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) + IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxEvtHandler) #endif BEGIN_EVENT_TABLE(wxWindow, wxEvtHandler) EVT_CHAR(wxWindow::OnChar) - EVT_KEY_DOWN(wxWindow::OnKeyDown) - EVT_KEY_UP(wxWindow::OnKeyUp) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) @@ -179,9 +182,19 @@ bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) } bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam), - WXLPARAM WXUNUSED(lParam), + WXLPARAM lParam, WXLPARAM* WXUNUSED(result)) { + NMHDR* hdr = (NMHDR *)lParam; + if ( hdr->code == TTN_NEEDTEXT && m_tooltip ) + { + TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; + ttt->lpszText = (char *)m_tooltip->GetTip().c_str(); + + // processed + return TRUE; + } + return FALSE; } @@ -268,6 +281,8 @@ void wxWindow::Init() #if wxUSE_DRAG_AND_DROP m_pDropTarget = NULL; #endif + + m_tooltip = NULL; } wxWindow::wxWindow() @@ -280,6 +295,10 @@ wxWindow::~wxWindow() { m_isBeingDeleted = TRUE; + // first of all, delete the things on which nothing else depends + + wxDELETE(m_tooltip); + // JACS - if behaviour is odd, restore this // to the start of ~wxWindow. Vadim has changed // it to nearer the end. Unsure of side-effects @@ -292,6 +311,7 @@ wxWindow::~wxWindow() // delete themselves. #if wxUSE_CONSTRAINTS DeleteRelatedConstraints(); + if (m_constraints) { // This removes any dangling pointers to this window @@ -300,11 +320,9 @@ wxWindow::~wxWindow() delete m_constraints; m_constraints = NULL; } - if (m_windowSizer) - { - delete m_windowSizer; - m_windowSizer = NULL; - } + + wxDELETE(m_windowSizer); + // If this is a child of a sizer, remove self from parent if (m_sizerParent) m_sizerParent->RemoveChild((wxWindow *)this); @@ -501,7 +519,8 @@ void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) m_pDropTarget->Register(m_hWnd); } -#endif +#endif // wxUSE_DRAG_AND_DROP + //old style file-manager drag&drop support // I think we should retain the old-style @@ -514,6 +533,24 @@ void wxWindow::DragAcceptFiles(bool accept) ::DragAcceptFiles(hWnd, (BOOL)accept); } +// ---------------------------------------------------------------------------- +// tooltips +// ---------------------------------------------------------------------------- + +void wxWindow::SetToolTip(const wxString &tip) +{ + SetToolTip(new wxToolTip(tip)); +} + +void wxWindow::SetToolTip(wxToolTip *tooltip) +{ + if ( m_tooltip ) + delete m_tooltip; + + m_tooltip = tooltip; + m_tooltip->SetWindow(this); +} + // Get total size void wxWindow::GetSize(int *x, int *y) const { @@ -882,7 +919,7 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) #ifdef __WXDEBUG__ wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)", - wxGetMessageName(message), wParam, lParam); + wxGetMessageName(message), wParam, lParam); #endif // __WXDEBUG__ HWND hWnd = (HWND)m_hWnd; @@ -1164,10 +1201,10 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) break; } +#if 0 case WM_KEYDOWN: { MSWOnKeyDown((WORD) wParam, lParam); -#if 0 // we consider these message "not interesting" if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) return Default(); @@ -1185,9 +1222,9 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) MSWOnChar((WORD)wParam, lParam); else return Default(); -#endif break; } +#endif case WM_KEYUP: { @@ -1902,14 +1939,19 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) lDlgCode = ::SendMessage(msg->hwnd, WM_GETDLGCODE, 0, 0); } - bool bForward = TRUE; + bool bForward = TRUE, + bWindowChange = FALSE; if ( bProcess ) { switch ( msg->wParam ) { case VK_TAB: - if ( lDlgCode & DLGC_WANTTAB ) // FALSE for Ctrl-Tab + if ( lDlgCode & DLGC_WANTTAB ) { bProcess = FALSE; - else + } + else { + // Ctrl-Tab cycles thru notebook pages + bWindowChange = bCtrlDown; bForward = !(::GetKeyState(VK_SHIFT) & 0x100); + } break; case VK_UP: @@ -1926,6 +1968,18 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) bProcess = FALSE; break; + case VK_RETURN: + // if there is a default button, Enter should press it + if ( !GetDefaultItem() ) { + // but if there is not it makes sense to make it work + // like a TAB + + // nothing to do - all variables are already set + + break; + } + //else: fall through and don't process the message + default: bProcess = FALSE; } @@ -1934,7 +1988,7 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) if ( bProcess ) { wxNavigationKeyEvent event; event.SetDirection(bForward); - event.SetWindowChange(bCtrlDown); + event.SetWindowChange(bWindowChange); event.SetEventObject(this); if ( GetEventHandler()->ProcessEvent(event) ) @@ -1943,6 +1997,14 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) return ::IsDialogMessage((HWND)GetHWND(), msg) != 0; } +#if wxUSE_TOOLTIPS + else if ( m_tooltip ) { + // relay mouse move events to the tooltip control + MSG *msg = (MSG *)pMsg; + if ( msg->message == WM_MOUSEMOVE ) + m_tooltip->RelayEvent(pMsg); + } +#endif // wxUSE_TOOLTIPS return FALSE; } @@ -3049,13 +3111,6 @@ void wxWindow::Centre(int direction) } -/* TODO (maybe) -void wxWindow::OnPaint() -{ -PaintSelectionHandles(); -} -*/ - void wxWindow::WarpPointer (int x_pos, int y_pos) { // Move the pointer to (x_pos,y_pos) coordinates. They are expressed in @@ -3550,17 +3605,17 @@ WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) void wxWindow::OnChar(wxKeyEvent& event) { -/* I'm commenting this out because otherwise, we lose tabs in e.g. a text window (see MDI sample) - * (JACS, 14/01/99) +#if 0 if ( event.KeyCode() == WXK_TAB ) { // propagate the TABs to the parent - it's up to it to decide what // to do with it - if ( GetParent() ) { - if ( GetParent()->GetEventHandler()->ProcessEvent(event) ) + wxWindow *parent = GetParent(); + if ( parent ) { + if ( parent->GetEventHandler()->ProcessEvent(event) ) return; } } -*/ +#endif // 0 bool isVirtual; int id = wxCharCodeWXToMSW((int)event.KeyCode(), &isVirtual); @@ -3572,21 +3627,6 @@ void wxWindow::OnChar(wxKeyEvent& event) (void) MSWDefWindowProc(m_lastMsg, (WPARAM) id, m_lastLParam); } -void wxWindow::OnKeyDown(wxKeyEvent& event) -{ - Default(); -} - -void wxWindow::OnKeyUp(wxKeyEvent& event) -{ - Default(); -} - -void wxWindow::OnPaint(wxPaintEvent& event) -{ - Default(); -} - bool wxWindow::IsEnabled(void) const { return (::IsWindowEnabled((HWND) GetHWND()) != 0); @@ -4427,6 +4467,7 @@ long wxWindow::MSWGetDlgCode() bool wxWindow::AcceptsFocus() const { + // invisible and disabled controls don't need focus return IsShown() && IsEnabled(); } -- 2.45.2