]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/window.h
wxDropTarget starts to work
[wxWidgets.git] / include / wx / msw / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindow class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WINDOW_H_
13 #define _WX_WINDOW_H_
14
15 #ifdef __GNUG__
16 #pragma interface "window.h"
17 #endif
18
19 #include "wx/gdicmn.h"
20 #include "wx/icon.h"
21 #include "wx/cursor.h"
22 #include "wx/pen.h"
23 #include "wx/font.h"
24 #include "wx/validate.h"
25 #include "wx/event.h"
26 #include "wx/string.h"
27 #include "wx/list.h"
28 #include "wx/region.h"
29 #include "wx/msw/accel.h"
30 #include "wx/intl.h"
31
32 #define wxKEY_SHIFT 1
33 #define wxKEY_CTRL 2
34
35 /*
36 * Base class for frame, panel, canvas, panel items, dialog box.
37 *
38 */
39
40 /*
41 * Event handler: windows have themselves as their event handlers
42 * by default, but their event handlers could be set to another
43 * object entirely. This separation can reduce the amount of
44 * derivation required, and allow alteration of a window's functionality
45 * (e.g. by a resource editor that temporarily switches event handlers).
46 */
47
48 class WXDLLEXPORT wxWindow;
49 class WXDLLEXPORT wxEvent;
50 class WXDLLEXPORT wxCommandEvent;
51 class WXDLLEXPORT wxKeyEvent;
52 class WXDLLEXPORT wxControl;
53 class WXDLLEXPORT wxCursor;
54 class WXDLLEXPORT wxColourMap;
55 class WXDLLEXPORT wxFont;
56 class WXDLLEXPORT wxMenu;
57 class WXDLLEXPORT wxRect;
58 class WXDLLEXPORT wxBitmap;
59 class WXDLLEXPORT wxSizer;
60 class WXDLLEXPORT wxList;
61 class WXDLLEXPORT wxLayoutConstraints;
62 class WXDLLEXPORT wxMouseEvent;
63 class WXDLLEXPORT wxButton;
64 class WXDLLEXPORT wxColour;
65 class WXDLLEXPORT wxBrush;
66 class WXDLLEXPORT wxPen;
67 class WXDLLEXPORT wxIcon;
68 class WXDLLEXPORT wxDC;
69 class WXDLLEXPORT wxValidator;
70 class WXDLLEXPORT wxToolTip;
71
72 #if wxUSE_DRAG_AND_DROP
73 class WXDLLEXPORT wxDropTarget;
74 #endif
75
76 #if wxUSE_WX_RESOURCES
77 class WXDLLEXPORT wxResourceTable;
78 class WXDLLEXPORT wxItemResource;
79 #endif
80
81 WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr;
82
83 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
84 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
85
86 //-----------------------------------------------------------------------------
87 // wxClientData
88 //-----------------------------------------------------------------------------
89
90 class wxClientData
91 {
92 public:
93 wxClientData() { }
94 virtual ~wxClientData() { }
95 };
96
97 //-----------------------------------------------------------------------------
98 // wxStringClientData
99 //-----------------------------------------------------------------------------
100
101 class wxStringClientData: public wxClientData
102 {
103 public:
104 wxStringClientData() { }
105 wxStringClientData( wxString &data ) { m_data = data; }
106 void SetData( wxString &data ) { m_data = data; }
107 wxString GetData() const { return m_data; }
108
109 private:
110 wxString m_data;
111 };
112
113 // Clash with Windows headers
114 #ifdef GetCharWidth
115 #undef GetCharWidth
116 #endif
117
118 #ifdef FindWindow
119 #undef FindWindow
120 #endif
121
122 class WXDLLEXPORT wxWindow : public wxEvtHandler
123 {
124 DECLARE_ABSTRACT_CLASS(wxWindow)
125
126 friend class wxDC;
127 friend class wxPaintDC;
128
129 public:
130 wxWindow();
131 wxWindow(wxWindow *parent, wxWindowID id,
132 const wxPoint& pos = wxDefaultPosition,
133 const wxSize& size = wxDefaultSize,
134 long style = 0,
135 const wxString& name = wxPanelNameStr)
136 {
137 Init();
138 Create(parent, id, pos, size, style, name);
139 }
140
141 virtual ~wxWindow();
142
143 bool Create(wxWindow *parent, wxWindowID id,
144 const wxPoint& pos = wxDefaultPosition,
145 const wxSize& size = wxDefaultSize,
146 long style = 0,
147 const wxString& name = wxPanelNameStr);
148
149 // Fit the window around the items
150 virtual void Fit();
151
152 // Show or hide the window
153 virtual bool Show(bool show);
154
155 // Is the window shown?
156 virtual bool IsShown() const;
157
158 // Raise the window to the top of the Z order
159 virtual void Raise();
160
161 // Lower the window to the bottom of the Z order
162 virtual void Lower();
163
164 // Is the window enabled?
165 virtual bool IsEnabled() const;
166
167 // For compatibility
168 inline bool Enabled() const { return IsEnabled(); }
169
170 // Dialog support: override these and call
171 // base class members to add functionality
172 // that can't be done using validators.
173
174 // Transfer values to controls. If returns FALSE,
175 // it's an application error (pops up a dialog)
176 virtual bool TransferDataToWindow();
177
178 // Transfer values from controls. If returns FALSE,
179 // transfer failed: don't quit
180 virtual bool TransferDataFromWindow();
181
182 // Validate controls. If returns FALSE,
183 // validation failed: don't quit
184 virtual bool Validate();
185
186 // Return code for dialogs
187 inline void SetReturnCode(int retCode);
188 inline int GetReturnCode();
189
190 // Set the cursor
191 virtual void SetCursor(const wxCursor& cursor);
192 inline virtual wxCursor& GetCursor() const { return (wxCursor& ) m_windowCursor; };
193
194 // Get the window with the focus
195 static wxWindow *FindFocus();
196
197 // Get character size
198 virtual int GetCharHeight() const;
199 virtual int GetCharWidth() const;
200
201 // moving/resizing
202 // ---------------
203
204 // set the window size and/or position
205 void SetSize( int x, int y, int width, int height,
206 int sizeFlags = wxSIZE_AUTO )
207 { DoSetSize(x, y, width, height, sizeFlags); }
208
209 void SetSize( int width, int height )
210 { DoSetSize(-1, -1, width, height, wxSIZE_USE_EXISTING); }
211
212 void SetSize( const wxSize& size )
213 { SetSize(size.x, size.y); }
214
215 void SetSize(const wxRect& rect, int sizeFlags = wxSIZE_AUTO)
216 { DoSetSize(rect.x, rect.y, rect.width, rect.height, sizeFlags); }
217
218 void Move( int x, int y )
219 { DoSetSize( x, y, -1, -1, wxSIZE_USE_EXISTING ); }
220
221 void Move(const wxPoint& pt)
222 { Move(pt.x, pt.y); }
223
224 // client size is the size of area available for subwindows
225 void SetClientSize( int width, int height )
226 { DoSetClientSize(width, height); }
227
228 void SetClientSize( const wxSize& size )
229 { DoSetClientSize(size.x, size.y); }
230
231 void SetClientSize(const wxRect& rect)
232 { SetClientSize( rect.width, rect.height ); }
233
234 // get the window position and/or size
235 virtual void GetPosition( int *x, int *y ) const;
236 wxPoint GetPosition() const
237 {
238 int w, h;
239 GetPosition(& w, & h);
240
241 return wxPoint(w, h);
242 }
243
244 virtual void GetSize( int *width, int *height ) const;
245
246 wxSize GetSize() const
247 {
248 int w, h;
249 GetSize(& w, & h);
250 return wxSize(w, h);
251 }
252
253 wxRect GetRect() const
254 {
255 int x, y, w, h;
256 GetPosition(& x, & y);
257 GetSize(& w, & h);
258
259 return wxRect(x, y, w, h);
260 }
261
262 virtual void GetClientSize( int *width, int *height ) const;
263 wxSize GetClientSize() const
264 {
265 int w, h;
266 GetClientSize(& w, & h);
267 return wxSize(w, h);
268 }
269
270 wxRect GetClientRect() const
271 {
272 int w, h;
273 GetSize(& w, & h);
274
275 return wxRect(0, 0, w, h);
276 }
277
278 // Convert client to screen coordinates
279 virtual void ClientToScreen(int *x, int *y) const;
280 wxPoint ClientToScreen(const wxPoint& pt) const
281 { int x = pt.x; int y = pt.y; ClientToScreen(& x, & y); return wxPoint(x, y); }
282
283 // Convert screen to client coordinates
284 virtual void ScreenToClient(int *x, int *y) const;
285 wxPoint ScreenToClient(const wxPoint& pt) const
286 { int x = pt.x; int y = pt.y; ScreenToClient(& x, & y); return wxPoint(x, y); }
287
288 // Set the focus to this window
289 virtual void SetFocus();
290
291 // Capture/release mouse
292 virtual void CaptureMouse();
293 virtual void ReleaseMouse();
294
295 // Enable or disable the window
296 virtual void Enable(bool enable);
297
298 #if wxUSE_DRAG_AND_DROP
299 // Associate a drop target with this window (if the window already had a drop
300 // target, it's deleted!) and return the current drop target (may be NULL).
301 void SetDropTarget(wxDropTarget *pDropTarget);
302 wxDropTarget *GetDropTarget() const { return m_pDropTarget; }
303 #endif
304
305 #if wxUSE_TOOLTIPS
306 // tooltips
307 // create a tooltip with this text
308 void SetToolTip(const wxString &tip);
309 // pointer may be NULL to remove the tooltip
310 void SetToolTip(wxToolTip *tooltip);
311 // get the current tooltip (may return NULL if none)
312 wxToolTip* GetToolTip() const { return m_tooltip; }
313
314 #endif // wxUSE_TOOLTIPS
315
316 // Accept files for dragging
317 virtual void DragAcceptFiles(bool accept);
318
319 // Update region access
320 virtual wxRegion GetUpdateRegion() const;
321 virtual bool IsExposed(int x, int y, int w, int h) const;
322 virtual bool IsExposed(const wxPoint& pt) const;
323 virtual bool IsExposed(const wxRect& rect) const;
324
325 // Set/get the window title
326 virtual inline void SetTitle(const wxString& WXUNUSED(title)) {};
327 inline virtual wxString GetTitle() const { return wxString(""); };
328 // Most windows have the concept of a label; for frames, this is the
329 // title; for items, this is the label or button text.
330 inline virtual wxString GetLabel() const { return GetTitle(); }
331
332 // Set/get the window name (used for resource setting in X)
333 inline virtual wxString GetName() const;
334 inline virtual void SetName(const wxString& name);
335
336 // Centre the window
337 virtual void Centre(int direction) ;
338 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
339
340 // Popup a menu
341 virtual bool PopupMenu(wxMenu *menu, int x, int y);
342
343 // Send the window a refresh event
344 virtual void Refresh(bool eraseBack = TRUE, const wxRect *rect = NULL);
345
346 #if WXWIN_COMPATIBILITY
347 // Set/get scroll attributes
348 virtual void SetScrollRange(int orient, int range, bool refresh = TRUE);
349 virtual void SetScrollPage(int orient, int page, bool refresh = TRUE);
350 virtual int OldGetScrollRange(int orient) const;
351 virtual int GetScrollPage(int orient) const;
352 #endif
353
354 // New functions that will replace the above.
355 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
356 int range, bool refresh = TRUE);
357
358 virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE);
359 virtual int GetScrollPos(int orient) const;
360 virtual int GetScrollRange(int orient) const;
361 virtual int GetScrollThumb(int orient) const;
362
363 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
364
365 // Caret manipulation
366 virtual void CreateCaret(int w, int h);
367 virtual void CreateCaret(const wxBitmap *bitmap);
368 virtual void DestroyCaret();
369 virtual void ShowCaret(bool show);
370 virtual void SetCaretPos(int x, int y);
371 virtual void GetCaretPos(int *x, int *y) const;
372
373 // Tell window how much it can be sized
374 virtual void SetSizeHints(int minW = -1, int minH = -1, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1);
375
376 // Set/get the window's identifier
377 inline int GetId() const;
378 inline void SetId(int id);
379
380 // Make the window modal (all other windows unresponsive)
381 virtual void MakeModal(bool modal);
382
383 // Get the private handle (platform-dependent)
384 inline void *GetHandle() const;
385
386 // Set/get the window's relatives
387 inline wxWindow *GetParent() const;
388 inline void SetParent(wxWindow *p) ;
389 inline wxWindow *GetGrandParent() const;
390 inline wxList& GetChildren() const;
391 // Set this window to be the child of 'parent'.
392 // Returns FALSE it's not possible (some systems
393 // won't allow it)
394 virtual bool Reparent(wxWindow *parent);
395
396 // Set/get the window's font
397 virtual void SetFont(const wxFont& f);
398 inline virtual wxFont& GetFont() const;
399
400 // Set/get the window's validator
401 void SetValidator(const wxValidator& validator);
402 inline wxValidator *GetValidator() const;
403
404 // Set/get the window's style
405 inline void SetWindowStyleFlag(long flag);
406 inline long GetWindowStyleFlag() const;
407
408 // Set/get double-clickability
409 // TODO: we probably wish to get rid of this, and
410 // always allow double clicks.
411 inline void SetDoubleClick(bool flag);
412 inline bool GetDoubleClick() const;
413 inline void AllowDoubleClick(bool value) { SetDoubleClick(value); }
414
415 // Handle a control command
416 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
417
418 // Set/get event handler
419 inline void SetEventHandler(wxEvtHandler *handler);
420 inline wxEvtHandler *GetEventHandler() const;
421
422 // Push/pop event handler (i.e. allow a chain of event handlers
423 // be searched)
424 void PushEventHandler(wxEvtHandler *handler) ;
425 wxEvtHandler *PopEventHandler(bool deleteHandler = FALSE) ;
426
427 // Close the window by calling OnClose, posting a deletion
428 virtual bool Close(bool force = FALSE);
429
430 // Destroy the window (delayed, if a managed window)
431 virtual bool Destroy() ;
432
433 // Mode for telling default OnSize members to
434 // call Layout(), if not using Sizers, just top-down constraints
435 inline void SetAutoLayout(bool a);
436 inline bool GetAutoLayout() const;
437
438 // Set/get constraints
439 inline wxLayoutConstraints *GetConstraints() const;
440 void SetConstraints(wxLayoutConstraints *c);
441
442 // Set/get window background colour
443 inline virtual void SetBackgroundColour(const wxColour& col);
444 inline virtual wxColour GetBackgroundColour() const;
445
446 // Set/get window foreground colour
447 inline virtual void SetForegroundColour(const wxColour& col);
448 inline virtual wxColour GetForegroundColour() const;
449
450 // For backward compatibility
451 inline virtual void SetButtonFont(const wxFont& font) { SetFont(font); }
452 inline virtual void SetLabelFont(const wxFont& font) { SetFont(font); }
453 inline virtual wxFont& GetLabelFont() const { return GetFont(); };
454 inline virtual wxFont& GetButtonFont() const { return GetFont(); };
455
456 // Get the default button, if there is one
457 inline virtual wxButton *GetDefaultItem() const;
458 inline virtual void SetDefaultItem(wxButton *but);
459
460 virtual void SetAcceleratorTable(const wxAcceleratorTable& accel);
461 inline virtual wxAcceleratorTable& GetAcceleratorTable() const { return (wxAcceleratorTable&) m_acceleratorTable; }
462
463 // Override to define new behaviour for default action (e.g. double clicking
464 // on a listbox)
465 virtual void OnDefaultAction(wxControl *initiatingItem);
466
467 // Resource loading
468 #if wxUSE_WX_RESOURCES
469 virtual bool LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table = NULL);
470 virtual wxControl *CreateItem(const wxItemResource* childResource, const wxItemResource* parentResource, const wxResourceTable *table = NULL);
471 #endif
472
473 // Native resource loading
474 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
475 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
476 virtual wxWindow* GetWindowChild1(wxWindowID& id);
477 virtual wxWindow* GetWindowChild(wxWindowID& id);
478
479 virtual void GetTextExtent(const wxString& string, int *x, int *y,
480 int *descent = NULL,
481 int *externalLeading = NULL,
482 const wxFont *theFont = NULL, bool use16 = FALSE) const;
483
484 // Is the window retained?
485 inline bool IsRetained() const;
486
487 // Warp the pointer the given position
488 virtual void WarpPointer(int x_pos, int y_pos) ;
489
490 // Clear the window
491 virtual void Clear();
492
493 // Find a window by id or name
494 virtual wxWindow *FindWindow(long id);
495 virtual wxWindow *FindWindow(const wxString& name);
496
497 // Constraint operations
498 bool Layout();
499 void SetSizer(wxSizer *sizer); // Adds sizer child to this window
500 inline wxSizer *GetSizer() const ;
501 inline wxWindow *GetSizerParent() const ;
502 inline void SetSizerParent(wxWindow *win);
503
504 // Do Update UI processing for controls
505 void UpdateWindowUI();
506
507 void OnEraseBackground(wxEraseEvent& event);
508 void OnKeyDown(wxKeyEvent& event);
509 void OnKeyUp(wxKeyEvent& event);
510 void OnPaint(wxPaintEvent& event);
511 void OnChar(wxKeyEvent& event);
512 void OnIdle(wxIdleEvent& event);
513
514 // Does this window want to accept keyboard focus?
515 virtual bool AcceptsFocus() const;
516
517 virtual void PrepareDC( wxDC& WXUNUSED(dc) ) {};
518 public:
519 ////////////////////////////////////////////////////////////////////////
520 //// IMPLEMENTATION
521
522 // For implementation purposes - sometimes decorations make the client area
523 // smaller
524 virtual wxPoint GetClientAreaOrigin() const;
525
526 // Makes an adjustment to the window position (for example, a frame that has
527 // a toolbar that it manages itself).
528 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
529
530 // Windows subclassing
531 void SubclassWin(WXHWND hWnd);
532 void UnsubclassWin();
533 virtual long Default();
534 virtual bool MSWCommand(WXUINT param, WXWORD id);
535
536 // returns TRUE if the event was processed
537 virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result);
538
539 virtual wxWindow *FindItem(int id) const;
540 virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ;
541 virtual void PreDelete(WXHDC dc); // Allows system cleanup
542 // TO DO: how many of these need to be virtual?
543 virtual WXHWND GetHWND() const ;
544 virtual void SetHWND(WXHWND hWnd);
545
546 // Make a Windows extended style from the given wxWindows window style
547 virtual WXDWORD MakeExtendedStyle(long style, bool eliminateBorders = TRUE);
548 // Determine whether 3D effects are wanted
549 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
550
551 virtual void AddChild(wxWindow *child); // Adds reference to the child object
552 virtual void RemoveChild(wxWindow *child); // Removes reference to child
553 // (but doesn't delete the child object)
554 virtual void DestroyChildren(); // Removes and destroys all children
555
556 inline bool IsBeingDeleted();
557
558 // MSW only: TRUE if this control is part of the main control
559 virtual bool ContainsHWND(WXHWND WXUNUSED(hWnd)) const { return FALSE; };
560
561 // Constraint implementation
562 void UnsetConstraints(wxLayoutConstraints *c);
563 inline wxList *GetConstraintsInvolvedIn() const ;
564 // Back-pointer to other windows we're involved with, so if we delete
565 // this window, we must delete any constraints we're involved with.
566 void AddConstraintReference(wxWindow *otherWin);
567 void RemoveConstraintReference(wxWindow *otherWin);
568 void DeleteRelatedConstraints();
569
570 virtual void ResetConstraints();
571 virtual void SetConstraintSizes(bool recurse = TRUE);
572 virtual bool LayoutPhase1(int *noChanges);
573 virtual bool LayoutPhase2(int *noChanges);
574 virtual bool DoPhase(int);
575 // Transforms from sizer coordinate space to actual
576 // parent coordinate space
577 virtual void TransformSizerToActual(int *x, int *y) const ;
578
579 // Set size with transformation to actual coordinates if nec.
580 virtual void SizerSetSize(int x, int y, int w, int h);
581 virtual void SizerMove(int x, int y);
582
583 // Only set/get the size/position of the constraint (if any)
584 virtual void SetSizeConstraint(int x, int y, int w, int h);
585 virtual void MoveConstraint(int x, int y);
586 virtual void GetSizeConstraint(int *w, int *h) const ;
587 virtual void GetClientSizeConstraint(int *w, int *h) const ;
588 virtual void GetPositionConstraint(int *x, int *y) const ;
589
590 // Dialog units translations. Implemented in wincmn.cpp.
591 wxPoint ConvertPixelsToDialog(const wxPoint& pt) ;
592 wxPoint ConvertDialogToPixels(const wxPoint& pt) ;
593 inline wxSize ConvertPixelsToDialog(const wxSize& sz)
594 { wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
595 inline wxSize ConvertDialogToPixels(const wxSize& sz)
596 { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
597
598 wxObject *GetChild(int number) const ;
599
600 void MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title,
601 int x, int y, int width, int height,
602 WXDWORD style, const char *dialog_template = NULL,
603 WXDWORD exendedStyle = 0);
604
605 // Actually defined in wx_canvs.cc since requires wxCanvas declaration
606 virtual void MSWDeviceToLogical(float *x, float *y) const ;
607
608 // Create an appropriate wxWindow from a HWND
609 virtual wxWindow* CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd);
610
611 // Make sure the window style reflects the HWND style (roughly)
612 virtual void AdoptAttributesFromHWND();
613
614 // Setup background and foreground colours correctly
615 virtual void SetupColours();
616
617 // Saves the last message information before calling base version
618 virtual bool ProcessEvent(wxEvent& event);
619
620 // Handlers
621 virtual void MSWOnCreate(WXLPCREATESTRUCT cs);
622 virtual bool MSWOnPaint();
623 virtual WXHICON MSWOnQueryDragIcon() { return 0; }
624 virtual void MSWOnSize(int x, int y, WXUINT flag);
625 virtual void MSWOnWindowPosChanging(void *lpPos);
626 virtual void MSWOnHScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
627 virtual void MSWOnVScroll(WXWORD nSBCode, WXWORD pos, WXHWND control);
628 virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control);
629 virtual long MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam);
630 virtual long MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam);
631 virtual WXHBRUSH MSWOnCtlColor(WXHDC dc, WXHWND pWnd, WXUINT nCtlColor,
632 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
633 virtual bool MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
634 virtual long MSWOnPaletteChanged(WXHWND hWndPalChange);
635 virtual long MSWOnQueryNewPalette();
636 virtual bool MSWOnEraseBkgnd(WXHDC pDC);
637 virtual void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu);
638 virtual void MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem);
639 virtual bool MSWOnClose();
640 // Return TRUE to end session, FALSE to veto end session.
641 virtual bool MSWOnQueryEndSession(long logOff);
642 virtual bool MSWOnEndSession(bool endSession, long logOff);
643 virtual bool MSWOnDestroy();
644 virtual bool MSWOnSetFocus(WXHWND wnd);
645 virtual bool MSWOnKillFocus(WXHWND wnd);
646 virtual void MSWOnDropFiles(WXWPARAM wParam);
647 virtual bool MSWOnInitDialog(WXHWND hWndFocus);
648 virtual void MSWOnShow(bool show, int status);
649
650 // TODO: rationalise these functions into 1 or 2 which take the
651 // event type as argument.
652 virtual void MSWOnLButtonDown(int x, int y, WXUINT flags);
653 virtual void MSWOnLButtonUp(int x, int y, WXUINT flags);
654 virtual void MSWOnLButtonDClick(int x, int y, WXUINT flags);
655
656 virtual void MSWOnMButtonDown(int x, int y, WXUINT flags);
657 virtual void MSWOnMButtonUp(int x, int y, WXUINT flags);
658 virtual void MSWOnMButtonDClick(int x, int y, WXUINT flags);
659
660 virtual void MSWOnRButtonDown(int x, int y, WXUINT flags);
661 virtual void MSWOnRButtonUp(int x, int y, WXUINT flags);
662 virtual void MSWOnRButtonDClick(int x, int y, WXUINT flags);
663
664 virtual void MSWOnMouseMove(int x, int y, WXUINT flags);
665 virtual void MSWOnMouseEnter(int x, int y, WXUINT flags);
666 virtual void MSWOnMouseLeave(int x, int y, WXUINT flags);
667
668 // These return TRUE if an event handler was found, FALSE otherwise (not processed)
669 virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE);
670 virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam);
671 virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam);
672
673 virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate);
674 virtual long MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate);
675
676 virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item);
677 virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item);
678
679 virtual void MSWOnJoyDown(int joystick, int x, int y, WXUINT flags);
680 virtual void MSWOnJoyUp(int joystick, int x, int y, WXUINT flags);
681 virtual void MSWOnJoyMove(int joystick, int x, int y, WXUINT flags);
682 virtual void MSWOnJoyZMove(int joystick, int z, WXUINT flags);
683
684 virtual long MSWGetDlgCode();
685
686 // Window procedure
687 virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
688
689 // Calls an appropriate default window procedure
690 virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam);
691 virtual bool MSWProcessMessage(WXMSG* pMsg);
692 virtual bool MSWTranslateMessage(WXMSG* pMsg);
693 virtual void MSWDestroyWindow();
694
695 // Detach "Window" menu from menu bar so it doesn't get deleted
696 void MSWDetachWindowMenu();
697
698 inline WXFARPROC MSWGetOldWndProc() const;
699 inline void MSWSetOldWndProc(WXFARPROC proc);
700
701 // Define for each class of dialog and control
702 virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor,
703 WXUINT message, WXWPARAM wParam, WXLPARAM lParam);
704
705 inline void SetShowing(bool show);
706 inline bool IsUserEnabled() const;
707 inline bool GetUseCtl3D() const ;
708 inline bool GetTransparentBackground() const ;
709
710 // Responds to colour changes: passes event on to children.
711 void OnSysColourChanged(wxSysColourChangedEvent& event);
712
713 // Transfers data to any child controls
714 void OnInitDialog(wxInitDialogEvent& event);
715
716 // Sends an OnInitDialog event, which in turns transfers data to
717 // to the window via validators.
718 virtual void InitDialog();
719
720 ////////////////////////////////////////////////////////////////////////
721 //// PROTECTED DATA
722 protected:
723 wxAcceleratorTable m_acceleratorTable;
724 int m_windowId;
725 long m_windowStyle; // Store the window's style
726 wxEvtHandler * m_windowEventHandler; // Usually is 'this'
727 wxLayoutConstraints * m_constraints; // Constraints for this window
728 wxList * m_constraintsInvolvedIn; // List of constraints we're involved in
729 wxSizer * m_windowSizer; // Window's top-level sizer (if any)
730 wxWindow * m_sizerParent; // Window's parent sizer (if any)
731 bool m_autoLayout; // Whether to call Layout() in OnSize
732 wxWindow * m_windowParent; // Each window always knows its parent
733 wxValidator * m_windowValidator;
734 // Old window proc, for subclassed controls
735 WXFARPROC m_oldWndProc;
736 bool m_useCtl3D; // Using CTL3D for this control
737
738 bool m_inOnSize; // Protection against OnSize reentry
739 #ifndef _WX_WIN32__
740 // Pointer to global memory, for EDIT controls that need
741 // special treatment to reduce USER area consumption.
742 WXHGLOBAL m_globalHandle;
743 #endif
744
745 bool m_winEnabled;
746 int m_minSizeX;
747 int m_minSizeY;
748 int m_maxSizeX;
749 int m_maxSizeY;
750
751 // Caret data
752 int m_caretWidth;
753 int m_caretHeight;
754 bool m_caretEnabled;
755 bool m_caretShown;
756 wxFont m_windowFont; // Window's font
757 bool m_isShown;
758 bool m_doubleClickAllowed ;
759 wxCursor m_windowCursor; // Window's cursor
760 bool m_winCaptured;
761 wxString m_windowName; // Window name
762
763 #if wxUSE_EXTENDED_STATICS
764 wxList m_staticItems;
765 #endif
766
767 wxButton * m_defaultItem;
768 wxColour m_backgroundColour ;
769 wxColour m_foregroundColour ;
770 bool m_backgroundTransparent;
771
772 int m_xThumbSize;
773 int m_yThumbSize;
774
775 float m_lastXPos;
776 float m_lastYPos;
777 int m_lastEvent;
778
779 bool m_mouseInWindow;
780
781 #if wxUSE_DRAG_AND_DROP
782 wxDropTarget *m_pDropTarget; // the current drop target or NULL
783 #endif //USE_DRAG_AND_DROP
784
785 public:
786 WXHWND m_hWnd; // MS Windows window handle
787 WXUINT m_lastMsg;
788 WXWPARAM m_lastWParam;
789 WXLPARAM m_lastLParam;
790
791 wxRegion m_updateRegion;
792 /*
793 wxRect m_updateRect; // Bounding box for screen damage area
794 #ifdef __WIN32__
795 WXHRGN m_updateRgn; // NT allows access to the rectangle list
796 #endif
797 */
798
799 // WXHANDLE m_acceleratorTable;
800 WXHMENU m_hMenu; // Menu, if any
801 wxList * m_children; // Window's children
802 int m_returnCode;
803 bool m_isBeingDeleted; // Fudge because can't access parent
804 // when being deleted
805
806 // this is the virtual function to be overriden in any derived class which
807 // wants to change how SetSize() or Move() works - it is called by all
808 // versions of these functions in the base class
809 virtual void DoSetSize(int x, int y,
810 int width, int height,
811 int sizeFlags = wxSIZE_AUTO);
812
813 // same as DoSetSize() for the client size
814 virtual void DoSetClientSize(int width, int height);
815
816 private:
817 // common part of all ctors
818 void Init();
819
820 // the associated tooltip (may be NULL if none)
821 #if wxUSE_TOOLTIPS
822 wxToolTip *m_tooltip;
823 #endif // tooltips
824
825 DECLARE_EVENT_TABLE()
826 };
827
828 ////////////////////////////////////////////////////////////////////////
829 //// INLINES
830
831 inline void *wxWindow::GetHandle() const { return (void *)GetHWND(); }
832 inline int wxWindow::GetId() const { return m_windowId; }
833 inline void wxWindow::SetId(int id) { m_windowId = id; }
834 inline wxWindow *wxWindow::GetParent() const { return m_windowParent; }
835 inline void wxWindow::SetParent(wxWindow *p) { m_windowParent = p; }
836 inline wxWindow *wxWindow::GetGrandParent() const { return (m_windowParent ? m_windowParent->m_windowParent : (wxWindow*) NULL); }
837 inline wxList& wxWindow::GetChildren() const { return (wxList&) *m_children; }
838 inline wxFont& wxWindow::GetFont() const { return (wxFont&) m_windowFont; }
839 inline wxString wxWindow::GetName() const { return m_windowName; }
840 inline void wxWindow::SetName(const wxString& name) { m_windowName = name; }
841 inline long wxWindow::GetWindowStyleFlag() const { return m_windowStyle; }
842 inline void wxWindow::SetWindowStyleFlag(long flag) { m_windowStyle = flag; }
843 inline void wxWindow::SetDoubleClick(bool flag) { m_doubleClickAllowed = flag; }
844 inline bool wxWindow::GetDoubleClick() const { return m_doubleClickAllowed; }
845 inline void wxWindow::SetEventHandler(wxEvtHandler *handler) { m_windowEventHandler = handler; }
846 inline wxEvtHandler *wxWindow::GetEventHandler() const { return m_windowEventHandler; }
847 inline void wxWindow::SetAutoLayout(bool a) { m_autoLayout = a; }
848 inline bool wxWindow::GetAutoLayout() const { return m_autoLayout; }
849 inline wxLayoutConstraints *wxWindow::GetConstraints() const { return m_constraints; }
850 inline void wxWindow::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; };
851 inline wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; };
852 inline void wxWindow::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; };
853 inline wxColour wxWindow::GetForegroundColour() const { return m_foregroundColour; };
854
855 inline wxButton *wxWindow::GetDefaultItem() const { return m_defaultItem; }
856 inline void wxWindow::SetDefaultItem(wxButton *but) { m_defaultItem = but; }
857 inline bool wxWindow::IsRetained() const { return ((m_windowStyle & wxRETAINED) == wxRETAINED); }
858
859 inline void wxWindow::SetShowing(bool show) { m_isShown = show; }
860 inline wxList *wxWindow::GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
861 inline wxSizer *wxWindow::GetSizer() const { return m_windowSizer; }
862 inline wxWindow *wxWindow::GetSizerParent() const { return m_sizerParent; }
863 inline void wxWindow::SetSizerParent(wxWindow *win) { m_sizerParent = win; }
864 inline WXFARPROC wxWindow::MSWGetOldWndProc() const { return m_oldWndProc; }
865 inline void wxWindow::MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; }
866 inline wxValidator *wxWindow::GetValidator() const { return m_windowValidator; }
867 inline bool wxWindow::IsUserEnabled() const { return m_winEnabled; }
868 inline bool wxWindow::GetUseCtl3D() const { return m_useCtl3D; }
869 inline bool wxWindow::GetTransparentBackground() const { return m_backgroundTransparent; }
870 inline void wxWindow::SetReturnCode(int retCode) { m_returnCode = retCode; }
871 inline int wxWindow::GetReturnCode() { return m_returnCode; }
872 inline bool wxWindow::IsBeingDeleted() { return m_isBeingDeleted; }
873
874 // Window specific (so far)
875 WXDLLEXPORT wxWindow* wxGetActiveWindow();
876
877 WXDLLEXPORT_DATA(extern wxWindowList) wxTopLevelWindows;
878
879 WXDLLEXPORT int wxCharCodeMSWToWX(int keySym);
880 WXDLLEXPORT int wxCharCodeWXToMSW(int id, bool *IsVirtual);
881
882 // Allocates control ids
883 WXDLLEXPORT int NewControlId();
884
885 #endif
886 // _WX_WINDOW_H_