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