| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: wx/msw/window.h |
| 3 | // Purpose: wxWindowMSW class |
| 4 | // Author: Julian Smart |
| 5 | // Modified by: Vadim Zeitlin on 13.05.99: complete refont of message handling, |
| 6 | // elimination of Default(), ... |
| 7 | // Created: 01/02/97 |
| 8 | // RCS-ID: $Id$ |
| 9 | // Copyright: (c) Julian Smart |
| 10 | // Licence: wxWindows licence |
| 11 | ///////////////////////////////////////////////////////////////////////////// |
| 12 | |
| 13 | #ifndef _WX_WINDOW_H_ |
| 14 | #define _WX_WINDOW_H_ |
| 15 | |
| 16 | #include "wx/settings.h" // solely for wxSystemColour |
| 17 | |
| 18 | // if this is set to 1, we use deferred window sizing to reduce flicker when |
| 19 | // resizing complicated window hierarchies, but this can in theory result in |
| 20 | // different behaviour than the old code so we keep the possibility to use it |
| 21 | // by setting this to 0 (in the future this should be removed completely) |
| 22 | #ifdef __WXWINCE__ |
| 23 | #define wxUSE_DEFERRED_SIZING 0 |
| 24 | #else |
| 25 | #define wxUSE_DEFERRED_SIZING 1 |
| 26 | #endif |
| 27 | |
| 28 | // --------------------------------------------------------------------------- |
| 29 | // wxWindow declaration for MSW |
| 30 | // --------------------------------------------------------------------------- |
| 31 | |
| 32 | class WXDLLIMPEXP_CORE wxWindowMSW : public wxWindowBase |
| 33 | { |
| 34 | friend class wxSpinCtrl; |
| 35 | friend class wxSlider; |
| 36 | friend class wxRadioBox; |
| 37 | #if defined __VISUALC__ && __VISUALC__ <= 1200 |
| 38 | friend class wxWindowMSW; |
| 39 | #endif |
| 40 | public: |
| 41 | wxWindowMSW() { Init(); } |
| 42 | |
| 43 | wxWindowMSW(wxWindow *parent, |
| 44 | wxWindowID id, |
| 45 | const wxPoint& pos = wxDefaultPosition, |
| 46 | const wxSize& size = wxDefaultSize, |
| 47 | long style = 0, |
| 48 | const wxString& name = wxPanelNameStr) |
| 49 | { |
| 50 | Init(); |
| 51 | Create(parent, id, pos, size, style, name); |
| 52 | } |
| 53 | |
| 54 | virtual ~wxWindowMSW(); |
| 55 | |
| 56 | bool Create(wxWindow *parent, |
| 57 | wxWindowID id, |
| 58 | const wxPoint& pos = wxDefaultPosition, |
| 59 | const wxSize& size = wxDefaultSize, |
| 60 | long style = 0, |
| 61 | const wxString& name = wxPanelNameStr); |
| 62 | |
| 63 | // implement base class pure virtuals |
| 64 | virtual void SetLabel(const wxString& label); |
| 65 | virtual wxString GetLabel() const; |
| 66 | |
| 67 | virtual void Raise(); |
| 68 | virtual void Lower(); |
| 69 | |
| 70 | virtual bool Show(bool show = true); |
| 71 | virtual bool ShowWithEffect(wxShowEffect effect, |
| 72 | unsigned timeout = 0) |
| 73 | { |
| 74 | return MSWShowWithEffect(true, effect, timeout); |
| 75 | } |
| 76 | virtual bool HideWithEffect(wxShowEffect effect, |
| 77 | unsigned timeout = 0) |
| 78 | { |
| 79 | return MSWShowWithEffect(false, effect, timeout); |
| 80 | } |
| 81 | |
| 82 | virtual void SetFocus(); |
| 83 | virtual void SetFocusFromKbd(); |
| 84 | |
| 85 | virtual bool Reparent(wxWindowBase *newParent); |
| 86 | |
| 87 | virtual void WarpPointer(int x, int y); |
| 88 | |
| 89 | virtual void Refresh( bool eraseBackground = true, |
| 90 | const wxRect *rect = (const wxRect *) NULL ); |
| 91 | virtual void Update(); |
| 92 | |
| 93 | virtual void SetWindowStyleFlag(long style); |
| 94 | virtual void SetExtraStyle(long exStyle); |
| 95 | virtual bool SetCursor( const wxCursor &cursor ); |
| 96 | virtual bool SetFont( const wxFont &font ); |
| 97 | |
| 98 | virtual int GetCharHeight() const; |
| 99 | virtual int GetCharWidth() const; |
| 100 | |
| 101 | virtual void SetScrollbar( int orient, int pos, int thumbVisible, |
| 102 | int range, bool refresh = true ); |
| 103 | virtual void SetScrollPos( int orient, int pos, bool refresh = true ); |
| 104 | virtual int GetScrollPos( int orient ) const; |
| 105 | virtual int GetScrollThumb( int orient ) const; |
| 106 | virtual int GetScrollRange( int orient ) const; |
| 107 | virtual void ScrollWindow( int dx, int dy, |
| 108 | const wxRect* rect = NULL ); |
| 109 | |
| 110 | virtual bool ScrollLines(int lines); |
| 111 | virtual bool ScrollPages(int pages); |
| 112 | |
| 113 | virtual void SetLayoutDirection(wxLayoutDirection dir); |
| 114 | virtual wxLayoutDirection GetLayoutDirection() const; |
| 115 | virtual wxCoord AdjustForLayoutDirection(wxCoord x, |
| 116 | wxCoord width, |
| 117 | wxCoord widthTotal) const; |
| 118 | |
| 119 | #if wxUSE_DRAG_AND_DROP |
| 120 | virtual void SetDropTarget( wxDropTarget *dropTarget ); |
| 121 | #endif // wxUSE_DRAG_AND_DROP |
| 122 | |
| 123 | // Accept files for dragging |
| 124 | virtual void DragAcceptFiles(bool accept); |
| 125 | |
| 126 | #ifndef __WXUNIVERSAL__ |
| 127 | // Native resource loading (implemented in src/msw/nativdlg.cpp) |
| 128 | // FIXME: should they really be all virtual? |
| 129 | virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id); |
| 130 | virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name); |
| 131 | wxWindow* GetWindowChild1(wxWindowID id); |
| 132 | wxWindow* GetWindowChild(wxWindowID id); |
| 133 | #endif // __WXUNIVERSAL__ |
| 134 | |
| 135 | #if wxUSE_HOTKEY |
| 136 | // install and deinstall a system wide hotkey |
| 137 | virtual bool RegisterHotKey(int hotkeyId, int modifiers, int keycode); |
| 138 | virtual bool UnregisterHotKey(int hotkeyId); |
| 139 | #endif // wxUSE_HOTKEY |
| 140 | |
| 141 | #ifdef __POCKETPC__ |
| 142 | bool IsContextMenuEnabled() const { return m_contextMenuEnabled; } |
| 143 | void EnableContextMenu(bool enable = true) { m_contextMenuEnabled = enable; } |
| 144 | #endif |
| 145 | |
| 146 | // window handle stuff |
| 147 | // ------------------- |
| 148 | |
| 149 | WXHWND GetHWND() const { return m_hWnd; } |
| 150 | void SetHWND(WXHWND hWnd) { m_hWnd = hWnd; } |
| 151 | virtual WXWidget GetHandle() const { return GetHWND(); } |
| 152 | |
| 153 | void AssociateHandle(WXWidget handle); |
| 154 | void DissociateHandle(); |
| 155 | |
| 156 | // does this window have deferred position and/or size? |
| 157 | bool IsSizeDeferred() const; |
| 158 | |
| 159 | // these functions allow to register a global handler for the given Windows |
| 160 | // message: it will be called from MSWWindowProc() of any window which gets |
| 161 | // this event if it's not processed before (i.e. unlike a hook procedure it |
| 162 | // does not override the normal processing) |
| 163 | // |
| 164 | // notice that if you want to process a message for a given window only you |
| 165 | // should override its MSWWindowProc() instead |
| 166 | |
| 167 | // type of the handler: it is called with the message parameters (except |
| 168 | // that the window object is passed instead of window handle) and should |
| 169 | // return true if it handled the message or false if it should be passed to |
| 170 | // DefWindowProc() |
| 171 | typedef bool (*MSWMessageHandler)(wxWindowMSW *win, |
| 172 | WXUINT nMsg, |
| 173 | WXWPARAM wParam, |
| 174 | WXLPARAM lParam); |
| 175 | |
| 176 | // install a handler, shouldn't be called more than one for the same message |
| 177 | static bool MSWRegisterMessageHandler(int msg, MSWMessageHandler handler); |
| 178 | |
| 179 | // unregister a previously registered handler |
| 180 | static void MSWUnregisterMessageHandler(int msg, MSWMessageHandler handler); |
| 181 | |
| 182 | |
| 183 | // implementation from now on |
| 184 | // ========================== |
| 185 | |
| 186 | // event handlers |
| 187 | // -------------- |
| 188 | |
| 189 | void OnPaint(wxPaintEvent& event); |
| 190 | #ifdef __WXWINCE__ |
| 191 | void OnInitDialog(wxInitDialogEvent& event); |
| 192 | #endif |
| 193 | |
| 194 | public: |
| 195 | // Windows subclassing |
| 196 | void SubclassWin(WXHWND hWnd); |
| 197 | void UnsubclassWin(); |
| 198 | |
| 199 | WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; } |
| 200 | void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; } |
| 201 | |
| 202 | // return true if the window is of a standard (i.e. not wxWidgets') class |
| 203 | // |
| 204 | // to understand why does it work, look at SubclassWin() code and comments |
| 205 | bool IsOfStandardClass() const { return m_oldWndProc != NULL; } |
| 206 | |
| 207 | wxWindow *FindItem(long id) const; |
| 208 | wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = false) const; |
| 209 | |
| 210 | // MSW only: true if this control is part of the main control |
| 211 | virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return false; } |
| 212 | |
| 213 | #if wxUSE_TOOLTIPS |
| 214 | // MSW only: true if this window or any of its children have a tooltip |
| 215 | virtual bool HasToolTips() const { return GetToolTip() != NULL; } |
| 216 | #endif // wxUSE_TOOLTIPS |
| 217 | |
| 218 | // translate wxWidgets style flags for this control into the Windows style |
| 219 | // and optional extended style for the corresponding native control |
| 220 | // |
| 221 | // this is the function that should be overridden in the derived classes, |
| 222 | // but you will mostly use MSWGetCreateWindowFlags() below |
| 223 | virtual WXDWORD MSWGetStyle(long flags, WXDWORD *exstyle = NULL) const ; |
| 224 | |
| 225 | // get the MSW window flags corresponding to wxWidgets ones |
| 226 | // |
| 227 | // the functions returns the flags (WS_XXX) directly and puts the ext |
| 228 | // (WS_EX_XXX) flags into the provided pointer if not NULL |
| 229 | WXDWORD MSWGetCreateWindowFlags(WXDWORD *exflags = NULL) const |
| 230 | { return MSWGetStyle(GetWindowStyle(), exflags); } |
| 231 | |
| 232 | // update the real underlying window style flags to correspond to the |
| 233 | // current wxWindow object style (safe to call even if window isn't fully |
| 234 | // created yet) |
| 235 | void MSWUpdateStyle(long flagsOld, long exflagsOld); |
| 236 | |
| 237 | // translate wxWidgets coords into Windows ones suitable to be passed to |
| 238 | // ::CreateWindow() |
| 239 | // |
| 240 | // returns true if non default coords are returned, false otherwise |
| 241 | bool MSWGetCreateWindowCoords(const wxPoint& pos, |
| 242 | const wxSize& size, |
| 243 | int& x, int& y, |
| 244 | int& w, int& h) const; |
| 245 | |
| 246 | // get the HWND to be used as parent of this window with CreateWindow() |
| 247 | virtual WXHWND MSWGetParent() const; |
| 248 | |
| 249 | // get the Win32 window class name used by all wxWindow objects by default |
| 250 | static const wxChar *MSWGetRegisteredClassName(); |
| 251 | |
| 252 | // creates the window of specified Windows class with given style, extended |
| 253 | // style, title and geometry (default values |
| 254 | // |
| 255 | // returns true if the window has been created, false if creation failed |
| 256 | bool MSWCreate(const wxChar *wclass, |
| 257 | const wxChar *title = NULL, |
| 258 | const wxPoint& pos = wxDefaultPosition, |
| 259 | const wxSize& size = wxDefaultSize, |
| 260 | WXDWORD style = 0, |
| 261 | WXDWORD exendedStyle = 0); |
| 262 | |
| 263 | virtual bool MSWCommand(WXUINT param, WXWORD id); |
| 264 | |
| 265 | #ifndef __WXUNIVERSAL__ |
| 266 | // Create an appropriate wxWindow from a HWND |
| 267 | virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd); |
| 268 | |
| 269 | // Make sure the window style reflects the HWND style (roughly) |
| 270 | virtual void AdoptAttributesFromHWND(); |
| 271 | #endif // __WXUNIVERSAL__ |
| 272 | |
| 273 | // Setup background and foreground colours correctly |
| 274 | virtual void SetupColours(); |
| 275 | |
| 276 | // ------------------------------------------------------------------------ |
| 277 | // helpers for message handlers: these perform the same function as the |
| 278 | // message crackers from <windowsx.h> - they unpack WPARAM and LPARAM into |
| 279 | // the correct parameters |
| 280 | // ------------------------------------------------------------------------ |
| 281 | |
| 282 | void UnpackCommand(WXWPARAM wParam, WXLPARAM lParam, |
| 283 | WXWORD *id, WXHWND *hwnd, WXWORD *cmd); |
| 284 | void UnpackActivate(WXWPARAM wParam, WXLPARAM lParam, |
| 285 | WXWORD *state, WXWORD *minimized, WXHWND *hwnd); |
| 286 | void UnpackScroll(WXWPARAM wParam, WXLPARAM lParam, |
| 287 | WXWORD *code, WXWORD *pos, WXHWND *hwnd); |
| 288 | void UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam, |
| 289 | WXHDC *hdc, WXHWND *hwnd); |
| 290 | void UnpackMenuSelect(WXWPARAM wParam, WXLPARAM lParam, |
| 291 | WXWORD *item, WXWORD *flags, WXHMENU *hmenu); |
| 292 | |
| 293 | // ------------------------------------------------------------------------ |
| 294 | // internal handlers for MSW messages: all handlers return a boolean value: |
| 295 | // true means that the handler processed the event and false that it didn't |
| 296 | // ------------------------------------------------------------------------ |
| 297 | |
| 298 | // there are several cases where we have virtual functions for Windows |
| 299 | // message processing: this is because these messages often require to be |
| 300 | // processed in a different manner in the derived classes. For all other |
| 301 | // messages, however, we do *not* have corresponding MSWOnXXX() function |
| 302 | // and if the derived class wants to process them, it should override |
| 303 | // MSWWindowProc() directly. |
| 304 | |
| 305 | // scroll event (both horizontal and vertical) |
| 306 | virtual bool MSWOnScroll(int orientation, WXWORD nSBCode, |
| 307 | WXWORD pos, WXHWND control); |
| 308 | |
| 309 | // child control notifications |
| 310 | virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); |
| 311 | |
| 312 | // owner-drawn controls need to process these messages |
| 313 | virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item); |
| 314 | virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); |
| 315 | |
| 316 | // the rest are not virtual |
| 317 | bool HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate); |
| 318 | bool HandleInitDialog(WXHWND hWndFocus); |
| 319 | bool HandleDestroy(); |
| 320 | |
| 321 | bool HandlePaint(); |
| 322 | bool HandlePrintClient(WXHDC hDC); |
| 323 | bool HandleEraseBkgnd(WXHDC hDC); |
| 324 | |
| 325 | bool HandleMinimize(); |
| 326 | bool HandleMaximize(); |
| 327 | bool HandleSize(int x, int y, WXUINT flag); |
| 328 | bool HandleSizing(wxRect& rect); |
| 329 | bool HandleGetMinMaxInfo(void *mmInfo); |
| 330 | bool HandleEnterSizeMove(); |
| 331 | bool HandleExitSizeMove(); |
| 332 | |
| 333 | bool HandleShow(bool show, int status); |
| 334 | bool HandleActivate(int flag, bool minimized, WXHWND activate); |
| 335 | |
| 336 | bool HandleCommand(WXWORD id, WXWORD cmd, WXHWND control); |
| 337 | |
| 338 | bool HandleCtlColor(WXHBRUSH *hBrush, WXHDC hdc, WXHWND hWnd); |
| 339 | |
| 340 | bool HandlePaletteChanged(WXHWND hWndPalChange); |
| 341 | bool HandleQueryNewPalette(); |
| 342 | bool HandleSysColorChange(); |
| 343 | bool HandleDisplayChange(); |
| 344 | bool HandleCaptureChanged(WXHWND gainedCapture); |
| 345 | virtual bool HandleSettingChange(WXWPARAM wParam, WXLPARAM lParam); |
| 346 | |
| 347 | bool HandleQueryEndSession(long logOff, bool *mayEnd); |
| 348 | bool HandleEndSession(bool endSession, long logOff); |
| 349 | |
| 350 | bool HandleSetFocus(WXHWND wnd); |
| 351 | bool HandleKillFocus(WXHWND wnd); |
| 352 | |
| 353 | bool HandleDropFiles(WXWPARAM wParam); |
| 354 | |
| 355 | bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags); |
| 356 | bool HandleMouseMove(int x, int y, WXUINT flags); |
| 357 | bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam); |
| 358 | |
| 359 | bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false); |
| 360 | bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam); |
| 361 | bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam); |
| 362 | #if wxUSE_ACCEL |
| 363 | bool HandleHotKey(WXWPARAM wParam, WXLPARAM lParam); |
| 364 | #endif |
| 365 | #ifdef __WIN32__ |
| 366 | int HandleMenuChar(int chAccel, WXLPARAM lParam); |
| 367 | #endif |
| 368 | // Create and process a clipboard event specified by type. |
| 369 | bool HandleClipboardEvent( WXUINT nMsg ); |
| 370 | |
| 371 | bool HandleQueryDragIcon(WXHICON *hIcon); |
| 372 | |
| 373 | bool HandleSetCursor(WXHWND hWnd, short nHitTest, int mouseMsg); |
| 374 | |
| 375 | bool HandlePower(WXWPARAM wParam, WXLPARAM lParam, bool *vetoed); |
| 376 | |
| 377 | |
| 378 | // Window procedure |
| 379 | virtual WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); |
| 380 | |
| 381 | // Calls an appropriate default window procedure |
| 382 | virtual WXLRESULT MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); |
| 383 | |
| 384 | // message processing helpers |
| 385 | |
| 386 | // return false if the message shouldn't be translated/preprocessed but |
| 387 | // dispatched normally |
| 388 | virtual bool MSWShouldPreProcessMessage(WXMSG* pMsg); |
| 389 | |
| 390 | // return true if the message was preprocessed and shouldn't be dispatched |
| 391 | virtual bool MSWProcessMessage(WXMSG* pMsg); |
| 392 | |
| 393 | // return true if the message was translated and shouldn't be dispatched |
| 394 | virtual bool MSWTranslateMessage(WXMSG* pMsg); |
| 395 | |
| 396 | // called when the window is about to be destroyed |
| 397 | virtual void MSWDestroyWindow(); |
| 398 | |
| 399 | |
| 400 | // this function should return the brush to paint the children controls |
| 401 | // background or 0 if this window doesn't impose any particular background |
| 402 | // on its children |
| 403 | // |
| 404 | // the hDC parameter is the DC background will be drawn on, it can be used |
| 405 | // to call SetBrushOrgEx() on it if the returned brush is a bitmap one |
| 406 | // |
| 407 | // child parameter is never NULL |
| 408 | // |
| 409 | // the base class version returns a solid brush if we have a non default |
| 410 | // background colour or 0 otherwise |
| 411 | virtual WXHBRUSH MSWGetBgBrushForChild(WXHDC hDC, wxWindowMSW *child); |
| 412 | |
| 413 | // return the background brush to use for painting the given window by |
| 414 | // quering the parent windows via their MSWGetBgBrushForChild() recursively |
| 415 | WXHBRUSH MSWGetBgBrush(WXHDC hDC) { return MSWGetBgBrush(hDC, this); } |
| 416 | WXHBRUSH MSWGetBgBrush(WXHDC hDC, wxWindowMSW *child); |
| 417 | |
| 418 | enum MSWThemeColour |
| 419 | { |
| 420 | ThemeColourText = 0, |
| 421 | ThemeColourBackground, |
| 422 | ThemeColourBorder |
| 423 | }; |
| 424 | |
| 425 | // returns a specific theme colour, or if that is not possible then |
| 426 | // wxSystemSettings::GetColour(fallback) |
| 427 | wxColour MSWGetThemeColour(const wchar_t *themeName, |
| 428 | int themePart, |
| 429 | int themeState, |
| 430 | MSWThemeColour themeColour, |
| 431 | wxSystemColour fallback) const; |
| 432 | |
| 433 | // gives the parent the possibility to draw its children background, e.g. |
| 434 | // this is used by wxNotebook to do it using DrawThemeBackground() |
| 435 | // |
| 436 | // return true if background was drawn, false otherwise |
| 437 | virtual bool MSWPrintChild(WXHDC WXUNUSED(hDC), wxWindow * WXUNUSED(child)) |
| 438 | { |
| 439 | return false; |
| 440 | } |
| 441 | |
| 442 | // some controls (e.g. wxListBox) need to set the return value themselves |
| 443 | // |
| 444 | // return true to let parent handle it if we don't, false otherwise |
| 445 | virtual bool MSWShouldPropagatePrintChild() |
| 446 | { |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | #if !defined(__WXWINCE__) && !defined(__WXUNIVERSAL__) |
| 451 | #define wxHAS_MSW_BACKGROUND_ERASE_HOOK |
| 452 | #endif |
| 453 | |
| 454 | #ifdef wxHAS_MSW_BACKGROUND_ERASE_HOOK |
| 455 | // allows the child to hook into its parent WM_ERASEBKGND processing: call |
| 456 | // MSWSetEraseBgHook() with a non-NULL window to make parent call |
| 457 | // MSWEraseBgHook() on this window (don't forget to reset it to NULL |
| 458 | // afterwards) |
| 459 | // |
| 460 | // this hack is used by wxToolBar, see comments there |
| 461 | void MSWSetEraseBgHook(wxWindow *child); |
| 462 | |
| 463 | // return true if WM_ERASEBKGND is currently hooked |
| 464 | bool MSWHasEraseBgHook() const; |
| 465 | |
| 466 | // called when the window on which MSWSetEraseBgHook() had been called |
| 467 | // receives WM_ERASEBKGND |
| 468 | virtual bool MSWEraseBgHook(WXHDC WXUNUSED(hDC)) { return false; } |
| 469 | #endif // wxHAS_MSW_BACKGROUND_ERASE_HOOK |
| 470 | |
| 471 | // common part of Show/HideWithEffect() |
| 472 | bool MSWShowWithEffect(bool show, |
| 473 | wxShowEffect effect, |
| 474 | unsigned timeout); |
| 475 | |
| 476 | // Responds to colour changes: passes event on to children. |
| 477 | void OnSysColourChanged(wxSysColourChangedEvent& event); |
| 478 | |
| 479 | // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX) |
| 480 | void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags); |
| 481 | |
| 482 | // check if mouse is in the window |
| 483 | bool IsMouseInWindow() const; |
| 484 | |
| 485 | // check if a native double-buffering applies for this window |
| 486 | virtual bool IsDoubleBuffered() const; |
| 487 | |
| 488 | void SetDoubleBuffered(bool on); |
| 489 | |
| 490 | // synthesize a wxEVT_LEAVE_WINDOW event and set m_mouseInWindow to false |
| 491 | void GenerateMouseLeave(); |
| 492 | |
| 493 | // virtual function for implementing internal idle |
| 494 | // behaviour |
| 495 | virtual void OnInternalIdle(); |
| 496 | |
| 497 | protected: |
| 498 | // this allows you to implement standard control borders without |
| 499 | // repeating the code in different classes that are not derived from |
| 500 | // wxControl |
| 501 | virtual wxBorder GetDefaultBorderForControl() const; |
| 502 | |
| 503 | // choose the default border for this window |
| 504 | virtual wxBorder GetDefaultBorder() const; |
| 505 | |
| 506 | // Translate wxBORDER_THEME (and other border styles if necessary to the value |
| 507 | // that makes most sense for this Windows environment |
| 508 | virtual wxBorder TranslateBorder(wxBorder border) const; |
| 509 | |
| 510 | #if wxUSE_MENUS_NATIVE |
| 511 | virtual bool DoPopupMenu( wxMenu *menu, int x, int y ); |
| 512 | #endif // wxUSE_MENUS_NATIVE |
| 513 | |
| 514 | // the window handle |
| 515 | WXHWND m_hWnd; |
| 516 | |
| 517 | // the old window proc (we subclass all windows) |
| 518 | WXFARPROC m_oldWndProc; |
| 519 | |
| 520 | // additional (MSW specific) flags |
| 521 | bool m_mouseInWindow:1; |
| 522 | bool m_lastKeydownProcessed:1; |
| 523 | |
| 524 | // the size of one page for scrolling |
| 525 | int m_xThumbSize; |
| 526 | int m_yThumbSize; |
| 527 | |
| 528 | // implement the base class pure virtuals |
| 529 | virtual void DoGetTextExtent(const wxString& string, |
| 530 | int *x, int *y, |
| 531 | int *descent = NULL, |
| 532 | int *externalLeading = NULL, |
| 533 | const wxFont *font = NULL) const; |
| 534 | virtual void DoClientToScreen( int *x, int *y ) const; |
| 535 | virtual void DoScreenToClient( int *x, int *y ) const; |
| 536 | virtual void DoGetPosition( int *x, int *y ) const; |
| 537 | virtual void DoGetSize( int *width, int *height ) const; |
| 538 | virtual void DoGetClientSize( int *width, int *height ) const; |
| 539 | virtual void DoSetSize(int x, int y, |
| 540 | int width, int height, |
| 541 | int sizeFlags = wxSIZE_AUTO); |
| 542 | virtual void DoSetClientSize(int width, int height); |
| 543 | |
| 544 | virtual wxSize DoGetBorderSize() const; |
| 545 | |
| 546 | virtual void DoCaptureMouse(); |
| 547 | virtual void DoReleaseMouse(); |
| 548 | |
| 549 | virtual void DoEnable(bool enable); |
| 550 | |
| 551 | virtual void DoFreeze(); |
| 552 | virtual void DoThaw(); |
| 553 | |
| 554 | // this simply moves/resizes the given HWND which is supposed to be our |
| 555 | // sibling (this is useful for controls which are composite at MSW level |
| 556 | // and for which DoMoveWindow() is not enough) |
| 557 | // |
| 558 | // returns true if the window move was deferred, false if it was moved |
| 559 | // immediately (no error return) |
| 560 | bool DoMoveSibling(WXHWND hwnd, int x, int y, int width, int height); |
| 561 | |
| 562 | // move the window to the specified location and resize it: this is called |
| 563 | // from both DoSetSize() and DoSetClientSize() and would usually just call |
| 564 | // ::MoveWindow() except for composite controls which will want to arrange |
| 565 | // themselves inside the given rectangle |
| 566 | virtual void DoMoveWindow(int x, int y, int width, int height); |
| 567 | |
| 568 | #if wxUSE_TOOLTIPS |
| 569 | virtual void DoSetToolTip( wxToolTip *tip ); |
| 570 | |
| 571 | // process TTN_NEEDTEXT message properly (i.e. fixing the bugs in |
| 572 | // comctl32.dll in our code -- see the function body for more info) |
| 573 | bool HandleTooltipNotify(WXUINT code, |
| 574 | WXLPARAM lParam, |
| 575 | const wxString& ttip); |
| 576 | #endif // wxUSE_TOOLTIPS |
| 577 | |
| 578 | // the helper functions used by HandleChar/KeyXXX methods |
| 579 | wxKeyEvent CreateKeyEvent(wxEventType evType, int id, |
| 580 | WXLPARAM lParam = 0, WXWPARAM wParam = 0) const; |
| 581 | |
| 582 | |
| 583 | // default OnEraseBackground() implementation, return true if we did erase |
| 584 | // the background, false otherwise (i.e. the system should erase it) |
| 585 | bool DoEraseBackground(WXHDC hDC); |
| 586 | |
| 587 | // generate WM_CHANGEUISTATE if it's needed for the OS we're running under |
| 588 | // |
| 589 | // action should be one of the UIS_XXX constants |
| 590 | // state should be one or more of the UISF_XXX constants |
| 591 | // if action == UIS_INITIALIZE then it doesn't seem to matter what we use |
| 592 | // for state as the system will decide for us what needs to be set |
| 593 | void MSWUpdateUIState(int action, int state = 0); |
| 594 | |
| 595 | private: |
| 596 | // common part of all ctors |
| 597 | void Init(); |
| 598 | |
| 599 | // the (non-virtual) handlers for the events |
| 600 | bool HandleMove(int x, int y); |
| 601 | bool HandleMoving(wxRect& rect); |
| 602 | bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); |
| 603 | bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); |
| 604 | |
| 605 | #if wxUSE_DEFERRED_SIZING |
| 606 | protected: |
| 607 | // this function is called after the window was resized to its new size |
| 608 | virtual void MSWEndDeferWindowPos() |
| 609 | { |
| 610 | m_pendingPosition = wxDefaultPosition; |
| 611 | m_pendingSize = wxDefaultSize; |
| 612 | } |
| 613 | |
| 614 | // current defer window position operation handle (may be NULL) |
| 615 | WXHANDLE m_hDWP; |
| 616 | |
| 617 | // When deferred positioning is done these hold the pending changes, and |
| 618 | // are used for the default values if another size/pos changes is done on |
| 619 | // this window before the group of deferred changes is completed. |
| 620 | wxPoint m_pendingPosition; |
| 621 | wxSize m_pendingSize; |
| 622 | #endif // wxUSE_DEFERRED_SIZING |
| 623 | |
| 624 | private: |
| 625 | #ifdef __POCKETPC__ |
| 626 | bool m_contextMenuEnabled; |
| 627 | #endif |
| 628 | |
| 629 | DECLARE_DYNAMIC_CLASS(wxWindowMSW) |
| 630 | wxDECLARE_NO_COPY_CLASS(wxWindowMSW); |
| 631 | DECLARE_EVENT_TABLE() |
| 632 | }; |
| 633 | |
| 634 | // ---------------------------------------------------------------------------- |
| 635 | // inline functions |
| 636 | // ---------------------------------------------------------------------------- |
| 637 | |
| 638 | // --------------------------------------------------------------------------- |
| 639 | // global functions |
| 640 | // --------------------------------------------------------------------------- |
| 641 | |
| 642 | // kbd code translation |
| 643 | WXDLLIMPEXP_CORE int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0); |
| 644 | WXDLLIMPEXP_CORE WXWORD wxCharCodeWXToMSW(int id); |
| 645 | |
| 646 | // window creation helper class: before creating a new HWND, instantiate an |
| 647 | // object of this class on stack - this allows to process the messages sent to |
| 648 | // the window even before CreateWindow() returns |
| 649 | class wxWindowCreationHook |
| 650 | { |
| 651 | public: |
| 652 | wxWindowCreationHook(wxWindowMSW *winBeingCreated); |
| 653 | ~wxWindowCreationHook(); |
| 654 | }; |
| 655 | |
| 656 | #endif // _WX_WINDOW_H_ |