]> git.saurik.com Git - wxWidgets.git/blob - include/wx/qt/window.h
GTK's dnd is broken, not mine
[wxWidgets.git] / include / wx / qt / window.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: window.h
3 // Purpose: wxWindow class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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
30 #define wxKEY_SHIFT 1
31 #define wxKEY_CTRL 2
32
33 /*
34 * Base class for frame, panel, canvas, panel items, dialog box.
35 *
36 */
37
38 /*
39 * Event handler: windows have themselves as their event handlers
40 * by default, but their event handlers could be set to another
41 * object entirely. This separation can reduce the amount of
42 * derivation required, and allow alteration of a window's functionality
43 * (e.g. by a resource editor that temporarily switches event handlers).
44 */
45
46 class WXDLLEXPORT wxWindow;
47 class WXDLLEXPORT wxEvent;
48 class WXDLLEXPORT wxCommandEvent;
49 class WXDLLEXPORT wxKeyEvent;
50 class WXDLLEXPORT wxControl;
51 class WXDLLEXPORT wxCursor;
52 class WXDLLEXPORT wxColourMap;
53 class WXDLLEXPORT wxFont;
54 class WXDLLEXPORT wxMenu;
55 class WXDLLEXPORT wxRectangle;
56 class WXDLLEXPORT wxBitmap;
57 class WXDLLEXPORT wxSizer;
58 class WXDLLEXPORT wxList;
59 class WXDLLEXPORT wxLayoutConstraints;
60 class WXDLLEXPORT wxMouseEvent;
61 class WXDLLEXPORT wxButton;
62 class WXDLLEXPORT wxColour;
63 class WXDLLEXPORT wxBrush;
64 class WXDLLEXPORT wxPen;
65 class WXDLLEXPORT wxIcon;
66 class WXDLLEXPORT wxDC;
67 class WXDLLEXPORT wxValidator;
68
69 #if wxUSE_DRAG_AND_DROP
70 class WXDLLEXPORT wxDropTarget;
71 #endif
72
73 #if wxUSE_WX_RESOURCES
74 class WXDLLEXPORT wxResourceTable;
75 class WXDLLEXPORT wxItemResource;
76 #endif
77
78 WXDLLEXPORT_DATA(extern const char*) wxPanelNameStr;
79
80 WXDLLEXPORT_DATA(extern const wxSize) wxDefaultSize;
81 WXDLLEXPORT_DATA(extern const wxPoint) wxDefaultPosition;
82
83 class WXDLLEXPORT wxWindow: public wxEvtHandler
84 {
85 DECLARE_ABSTRACT_CLASS(wxWindow)
86
87 friend class wxDC;
88 friend class wxPaintDC;
89
90 public:
91 wxWindow();
92 inline wxWindow(wxWindow *parent, wxWindowID id,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0,
96 const wxString& name = wxPanelNameStr)
97 {
98 m_children = new wxList;
99 Create(parent, id, pos, size, style, name);
100 }
101
102 virtual ~wxWindow();
103
104 bool Create(wxWindow *parent, wxWindowID id,
105 const wxPoint& pos = wxDefaultPosition,
106 const wxSize& size = wxDefaultSize,
107 long style = 0,
108 const wxString& name = wxPanelNameStr);
109
110 // Fit the window around the items
111 virtual void Fit();
112
113 // Show or hide the window
114 virtual bool Show(bool show);
115
116 // Is the window shown?
117 virtual bool IsShown() const;
118
119 // Raise the window to the top of the Z order
120 virtual void Raise();
121
122 // Lower the window to the bottom of the Z order
123 virtual void Lower();
124
125 // Is the window enabled?
126 virtual bool IsEnabled() const;
127
128 // For compatibility
129 inline bool Enabled() const { return IsEnabled(); }
130
131 // Dialog support: override these and call
132 // base class members to add functionality
133 // that can't be done using validators.
134
135 // Transfer values to controls. If returns FALSE,
136 // it's an application error (pops up a dialog)
137 virtual bool TransferDataToWindow();
138
139 // Transfer values from controls. If returns FALSE,
140 // transfer failed: don't quit
141 virtual bool TransferDataFromWindow();
142
143 // Validate controls. If returns FALSE,
144 // validation failed: don't quit
145 virtual bool Validate();
146
147 // Return code for dialogs
148 inline void SetReturnCode(int retCode);
149 inline int GetReturnCode();
150
151 // Set the cursor
152 virtual void SetCursor(const wxCursor& cursor);
153 inline virtual wxCursor *GetCursor() const { return (wxCursor *)& m_windowCursor; };
154
155 // Get the window with the focus
156 static wxWindow *FindFocus();
157
158 // Get character size
159 virtual int GetCharHeight() const;
160 virtual int GetCharWidth() const;
161
162 // Get overall window size
163 virtual void GetSize(int *width, int *height) const;
164
165 // Get window position, relative to parent (or screen if no parent)
166 virtual void GetPosition(int *x, int *y) const;
167
168 // Get client (application-useable) size
169 virtual void GetClientSize(int *width, int *height) const;
170
171 // Set overall size and position
172 virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
173 inline virtual void SetSize(int width, int height) { SetSize(-1, -1, width, height, wxSIZE_USE_EXISTING); }
174 inline virtual void Move(int x, int y) { SetSize(x, y, -1, -1, wxSIZE_USE_EXISTING); }
175
176 // Set client size
177 virtual void SetClientSize(int width, int size);
178
179 // Convert client to screen coordinates
180 virtual void ClientToScreen(int *x, int *y) const;
181
182 // Convert screen to client coordinates
183 virtual void ScreenToClient(int *x, int *y) const;
184
185 // Set the focus to this window
186 virtual void SetFocus();
187
188 // Capture/release mouse
189 virtual void CaptureMouse();
190 virtual void ReleaseMouse();
191
192 // Enable or disable the window
193 virtual void Enable(bool enable);
194
195 #if wxUSE_DRAG_AND_DROP
196 // Associate a drop target with this window (if the window already had a drop
197 // target, it's deleted!) and return the current drop target (may be NULL).
198 void SetDropTarget(wxDropTarget *pDropTarget);
199 wxDropTarget *GetDropTarget() const { return m_pDropTarget; }
200 #endif
201
202 // Accept files for dragging
203 virtual void DragAcceptFiles(bool accept);
204
205 // Update region access
206 virtual wxRegion GetUpdateRegion() const;
207 virtual bool IsExposed(int x, int y, int w, int h) const;
208 virtual bool IsExposed(const wxPoint& pt) const;
209 virtual bool IsExposed(const wxRect& rect) const;
210
211 // Set/get the window title
212 virtual inline void SetTitle(const wxString& WXUNUSED(title)) {};
213 inline virtual wxString GetTitle() const { return wxString(""); };
214 // Most windows have the concept of a label; for frames, this is the
215 // title; for items, this is the label or button text.
216 inline virtual wxString GetLabel() const { return GetTitle(); }
217
218 // Set/get the window name (used for resource setting in X)
219 inline virtual wxString GetName() const;
220 inline virtual void SetName(const wxString& name);
221
222 // Centre the window
223 virtual void Centre(int direction) ;
224 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
225
226 // Popup a menu
227 virtual bool PopupMenu(wxMenu *menu, int x, int y);
228
229 // Send the window a refresh event
230 virtual void Refresh(bool eraseBack = TRUE, const wxRectangle *rect = NULL);
231
232 // New functions that will replace the above.
233 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
234 int range, bool refresh = TRUE);
235
236 virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE);
237 virtual int GetScrollPos(int orient) const;
238 virtual int GetScrollRange(int orient) const;
239 virtual int GetScrollThumb(int orient) const;
240
241 virtual void ScrollWindow(int dx, int dy, const wxRectangle *rect = NULL);
242
243 // Caret manipulation
244 virtual void CreateCaret(int w, int h);
245 virtual void CreateCaret(const wxBitmap *bitmap);
246 virtual void DestroyCaret();
247 virtual void ShowCaret(bool show);
248 virtual void SetCaretPos(int x, int y);
249 virtual void GetCaretPos(int *x, int *y) const;
250
251 // Tell window how much it can be sized
252 virtual void SetSizeHints(int minW = -1, int minH = -1, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1);
253
254 // Set/get the window's identifier
255 inline int GetId() const;
256 inline void SetId(int id);
257
258 // Make the window modal (all other windows unresponsive)
259 virtual void MakeModal(bool modal);
260
261 // Get the private handle (platform-dependent)
262 inline void *GetHandle() const;
263
264 // Set/get the window's relatives
265 inline wxWindow *GetParent() const;
266 inline void SetParent(wxWindow *p) ;
267 inline wxWindow *GetGrandParent() const;
268 inline wxList *GetChildren() const;
269
270 // Set/get the window's font
271 virtual void SetFont(const wxFont& f);
272 inline virtual wxFont *GetFont() const;
273
274 // Set/get the window's validator
275 void SetValidator(const wxValidator& validator);
276 inline wxValidator *GetValidator() const;
277
278 // Set/get the window's style
279 inline void SetWindowStyleFlag(long flag);
280 inline long GetWindowStyleFlag() const;
281
282 // Set/get event handler
283 inline void SetEventHandler(wxEvtHandler *handler);
284 inline wxEvtHandler *GetEventHandler() const;
285
286 // Push/pop event handler (i.e. allow a chain of event handlers
287 // be searched)
288 void PushEventHandler(wxEvtHandler *handler) ;
289 wxEvtHandler *PopEventHandler(bool deleteHandler = FALSE) ;
290
291 // Close the window by calling OnClose, posting a deletion
292 virtual bool Close(bool force = FALSE);
293
294 // Destroy the window (delayed, if a managed window)
295 virtual bool Destroy() ;
296
297 // Mode for telling default OnSize members to
298 // call Layout(), if not using Sizers, just top-down constraints
299 inline void SetAutoLayout(bool a);
300 inline bool GetAutoLayout() const;
301
302 // Set/get constraints
303 inline wxLayoutConstraints *GetConstraints() const;
304 void SetConstraints(wxLayoutConstraints *c);
305
306 // Set/get window background colour
307 inline virtual void SetBackgroundColour(const wxColour& col);
308 inline virtual wxColour GetBackgroundColour() const;
309
310 // Set/get window foreground colour
311 inline virtual void SetForegroundColour(const wxColour& col);
312 inline virtual wxColour GetForegroundColour() const;
313
314 // Set/get window default background colour (for children to inherit).
315 // NOTE: these may be removed in later revisions.
316 inline virtual void SetDefaultBackgroundColour(const wxColour& col);
317 inline virtual wxColour GetDefaultBackgroundColour(void) const;
318
319 // Set/get window default foreground colour (for children to inherit)
320 inline virtual void SetDefaultForegroundColour(const wxColour& col);
321 inline virtual wxColour GetDefaultForegroundColour(void) const;
322
323 // Get the default button, if there is one
324 inline virtual wxButton *GetDefaultItem() const;
325 inline virtual void SetDefaultItem(wxButton *but);
326
327 // Override to define new behaviour for default action (e.g. double clicking
328 // on a listbox)
329 virtual void OnDefaultAction(wxControl *initiatingItem);
330
331 // Resource loading
332 #if wxUSE_WX_RESOURCES
333 virtual bool LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table = NULL);
334 virtual wxControl *CreateItem(const wxItemResource *childResource, const wxResourceTable *table = NULL);
335 #endif
336
337 // Native resource loading
338 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
339 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
340 virtual wxWindow* GetWindowChild1(wxWindowID& id);
341 virtual wxWindow* GetWindowChild(wxWindowID& id);
342
343 virtual void GetTextExtent(const wxString& string, int *x, int *y,
344 int *descent = NULL,
345 int *externalLeading = NULL,
346 const wxFont *theFont = NULL, bool use16 = FALSE) const;
347
348 // Is the window retained?
349 inline bool IsRetained() const;
350
351 // Warp the pointer the given position
352 virtual void WarpPointer(int x_pos, int y_pos) ;
353
354 // Clear the window
355 virtual void Clear();
356
357 // Find a window by id or name
358 virtual wxWindow *FindWindow(long id);
359 virtual wxWindow *FindWindow(const wxString& name);
360
361 // Constraint operations
362 bool Layout();
363 void SetSizer(wxSizer *sizer); // Adds sizer child to this window
364 inline wxSizer *GetSizer() const ;
365 inline wxWindow *GetSizerParent() const ;
366 inline void SetSizerParent(wxWindow *win);
367
368 // Do Update UI processing for controls
369 void UpdateWindowUI();
370
371 void OnEraseBackground(wxEraseEvent& event);
372 void OnChar(wxKeyEvent& event);
373 void OnPaint(wxPaintEvent& event);
374 void OnIdle(wxIdleEvent& event);
375
376 // Does this window want to accept keyboard focus?
377 virtual bool AcceptsFocus() const;
378
379 public:
380 ////////////////////////////////////////////////////////////////////////
381 //// IMPLEMENTATION
382
383 // For implementation purposes - sometimes decorations make the client area
384 // smaller
385 virtual wxPoint GetClientAreaOrigin() const;
386
387 // Makes an adjustment to the window position (for example, a frame that has
388 // a toolbar that it manages itself).
389 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
390
391 // Executes the default message
392 virtual long Default();
393
394 /* TODO: you may need something like this
395 // Determine whether 3D effects are wanted
396 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
397 */
398
399 virtual void AddChild(wxWindow *child); // Adds reference to the child object
400 virtual void RemoveChild(wxWindow *child); // Removes reference to child
401 // (but doesn't delete the child object)
402 virtual void DestroyChildren(); // Removes and destroys all children
403
404 // Constraint implementation
405 void UnsetConstraints(wxLayoutConstraints *c);
406 inline wxList *GetConstraintsInvolvedIn() const ;
407 // Back-pointer to other windows we're involved with, so if we delete
408 // this window, we must delete any constraints we're involved with.
409 void AddConstraintReference(wxWindow *otherWin);
410 void RemoveConstraintReference(wxWindow *otherWin);
411 void DeleteRelatedConstraints();
412
413 virtual void ResetConstraints();
414 virtual void SetConstraintSizes(bool recurse = TRUE);
415 virtual bool LayoutPhase1(int *noChanges);
416 virtual bool LayoutPhase2(int *noChanges);
417 virtual bool DoPhase(int);
418 // Transforms from sizer coordinate space to actual
419 // parent coordinate space
420 virtual void TransformSizerToActual(int *x, int *y) const ;
421
422 // Set size with transformation to actual coordinates if nec.
423 virtual void SizerSetSize(int x, int y, int w, int h);
424 virtual void SizerMove(int x, int y);
425
426 // Only set/get the size/position of the constraint (if any)
427 virtual void SetSizeConstraint(int x, int y, int w, int h);
428 virtual void MoveConstraint(int x, int y);
429 virtual void GetSizeConstraint(int *w, int *h) const ;
430 virtual void GetClientSizeConstraint(int *w, int *h) const ;
431 virtual void GetPositionConstraint(int *x, int *y) const ;
432
433 wxObject *GetChild(int number) const ;
434
435 inline void SetShowing(bool show);
436 inline bool IsUserEnabled() const;
437 inline bool GetTransparentBackground() const ;
438
439 // Responds to colour changes: passes event on to children.
440 void OnSysColourChanged(wxSysColourChangedEvent& event);
441
442 // Transfers data to any child controls
443 void OnInitDialog(wxInitDialogEvent& event);
444
445 // Sends an OnInitDialog event, which in turns transfers data to
446 // to the window via validators.
447 virtual void InitDialog();
448
449 ////////////////////////////////////////////////////////////////////////
450 //// PROTECTED DATA
451 protected:
452 int m_windowId;
453 long m_windowStyle; // Store the window's style
454 wxEvtHandler * m_windowEventHandler; // Usually is 'this'
455 wxLayoutConstraints * m_constraints; // Constraints for this window
456 wxList * m_constraintsInvolvedIn; // List of constraints we're involved in
457 wxSizer * m_windowSizer; // Window's top-level sizer (if any)
458 wxWindow * m_sizerParent; // Window's parent sizer (if any)
459 bool m_autoLayout; // Whether to call Layout() in OnSize
460 wxWindow * m_windowParent; // Each window always knows its parent
461 wxValidator * m_windowValidator;
462 int m_minSizeX;
463 int m_minSizeY;
464 int m_maxSizeX;
465 int m_maxSizeY;
466
467 // Caret data
468 int m_caretWidth;
469 int m_caretHeight;
470 bool m_caretEnabled;
471 bool m_caretShown;
472 wxFont m_windowFont; // Window's font
473 wxCursor m_windowCursor; // Window's cursor
474 wxString m_windowName; // Window name
475
476 wxButton * m_defaultItem;
477
478 wxColour m_backgroundColour ;
479 wxColour m_foregroundColour ;
480 wxColour m_defaultBackgroundColour;
481 wxColour m_defaultForegroundColour;
482
483 #if wxUSE_DRAG_AND_DROP
484 wxDropTarget *m_pDropTarget; // the current drop target or NULL
485 #endif //USE_DRAG_AND_DROP
486
487 public:
488 wxRegion m_updateRegion;
489 wxList * m_children; // Window's children
490 int m_returnCode;
491
492 DECLARE_EVENT_TABLE()
493 };
494
495 ////////////////////////////////////////////////////////////////////////
496 //// INLINES
497
498 inline void *wxWindow::GetHandle() const { return (void *)NULL; }
499 inline int wxWindow::GetId() const { return m_windowId; }
500 inline void wxWindow::SetId(int id) { m_windowId = id; }
501 inline wxWindow *wxWindow::GetParent() const { return m_windowParent; }
502 inline void wxWindow::SetParent(wxWindow *p) { m_windowParent = p; }
503 inline wxWindow *wxWindow::GetGrandParent() const { return (m_windowParent ? m_windowParent->m_windowParent : NULL); }
504 inline wxList *wxWindow::GetChildren() const { return m_children; }
505 inline wxFont *wxWindow::GetFont() const { return (wxFont *) & m_windowFont; }
506 inline wxString wxWindow::GetName() const { return m_windowName; }
507 inline void wxWindow::SetName(const wxString& name) { m_windowName = name; }
508 inline long wxWindow::GetWindowStyleFlag() const { return m_windowStyle; }
509 inline void wxWindow::SetWindowStyleFlag(long flag) { m_windowStyle = flag; }
510 inline void wxWindow::SetDoubleClick(bool flag) { m_doubleClickAllowed = flag; }
511 inline bool wxWindow::GetDoubleClick() const { return m_doubleClickAllowed; }
512 inline void wxWindow::SetEventHandler(wxEvtHandler *handler) { m_windowEventHandler = handler; }
513 inline wxEvtHandler *wxWindow::GetEventHandler() const { return m_windowEventHandler; }
514 inline void wxWindow::SetAutoLayout(bool a) { m_autoLayout = a; }
515 inline bool wxWindow::GetAutoLayout() const { return m_autoLayout; }
516 inline wxLayoutConstraints *wxWindow::GetConstraints() const { return m_constraints; }
517 inline void wxWindow::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; };
518 inline wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; };
519 inline void wxWindow::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; };
520 inline wxColour wxWindow::GetForegroundColour() const { return m_foregroundColour; };
521 inline void wxWindow::SetDefaultForegroundColour(const wxColour& col) { m_defaultForegroundColour = col; };
522 inline wxColour wxWindow::GetDefaultForegroundColour(void) const { return m_defaultForegroundColour; };
523 inline void wxWindow::SetDefaultBackgroundColour(const wxColour& col) { m_defaultBackgroundColour = col; };
524 inline wxColour wxWindow::GetDefaultBackgroundColour(void) const { return m_defaultBackgroundColour; };
525
526 inline wxButton *wxWindow::GetDefaultItem() const { return m_defaultItem; }
527 inline void wxWindow::SetDefaultItem(wxButton *but) { m_defaultItem = but; }
528 inline bool wxWindow::IsRetained() const { return ((m_windowStyle & wxRETAINED) == wxRETAINED); }
529
530 inline void wxWindow::SetShowing(bool show) { m_isShown = show; }
531 inline wxList *wxWindow::GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
532 inline wxSizer *wxWindow::GetSizer() const { return m_windowSizer; }
533 inline wxWindow *wxWindow::GetSizerParent() const { return m_sizerParent; }
534 inline void wxWindow::SetSizerParent(wxWindow *win) { m_sizerParent = win; }
535 inline wxValidator *wxWindow::GetValidator() const { return m_windowValidator; }
536 inline bool wxWindow::IsUserEnabled() const { return m_winEnabled; }
537 inline bool wxWindow::GetTransparentBackground() const { return m_backgroundTransparent; }
538 inline void wxWindow::SetReturnCode(int retCode) { m_returnCode = retCode; }
539 inline int wxWindow::GetReturnCode() { return m_returnCode; }
540
541 // Get the active window.
542 wxWindow* WXDLLEXPORT wxGetActiveWindow();
543
544 WXDLLEXPORT_DATA(extern wxList) wxTopLevelWindows;
545
546 #endif
547 // _WX_WINDOW_H_