]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stubs/window.h
added AppendText method, now used by operator <<
[wxWidgets.git] / include / wx / stubs / 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
193 // Get window position, relative to parent (or screen if no parent)
194 virtual void GetPosition(int *x, int *y) const;
195
196 // Get client (application-useable) size
197 virtual void GetClientSize(int *width, int *height) const;
198
199 // Set overall size and position
200 virtual void SetSize(int x, int y, int width, int height, int sizeFlags = wxSIZE_AUTO);
201 inline virtual void SetSize(int width, int height) { SetSize(-1, -1, width, height, wxSIZE_USE_EXISTING); }
202 inline virtual void Move(int x, int y) { SetSize(x, y, -1, -1, wxSIZE_USE_EXISTING); }
203
204 // Set client size
205 virtual void SetClientSize(int width, int size);
206
207 // Convert client to screen coordinates
208 virtual void ClientToScreen(int *x, int *y) const;
209
210 // Convert screen to client coordinates
211 virtual void ScreenToClient(int *x, int *y) const;
212
213 // Set the focus to this window
214 virtual void SetFocus();
215
216 // Capture/release mouse
217 virtual void CaptureMouse();
218 virtual void ReleaseMouse();
219
220 // Enable or disable the window
221 virtual void Enable(bool enable);
222
223 #if wxUSE_DRAG_AND_DROP
224 // Associate a drop target with this window (if the window already had a drop
225 // target, it's deleted!) and return the current drop target (may be NULL).
226 void SetDropTarget(wxDropTarget *pDropTarget);
227 wxDropTarget *GetDropTarget() const { return m_pDropTarget; }
228 #endif
229
230 // Accept files for dragging
231 virtual void DragAcceptFiles(bool accept);
232
233 // tooltips
234 // create a tooltip with this text
235 void SetToolTip(const wxString& tip);
236
237 // TODO
238 #if 0
239 // pointer may be NULL to remove the tooltip
240 void SetToolTip(wxToolTip *tooltip);
241 // get the current tooltip (may return NULL if none)
242 wxToolTip* GetToolTip() const { return m_tooltip; }
243 #endif
244
245 // Update region access
246 virtual wxRegion GetUpdateRegion() const;
247 virtual bool IsExposed(int x, int y, int w, int h) const;
248 virtual bool IsExposed(const wxPoint& pt) const;
249 virtual bool IsExposed(const wxRect& rect) const;
250
251 // Set/get the window title
252 virtual inline void SetTitle(const wxString& WXUNUSED(title)) {};
253 inline virtual wxString GetTitle() const { return wxString(""); };
254 // Most windows have the concept of a label; for frames, this is the
255 // title; for items, this is the label or button text.
256 inline virtual wxString GetLabel() const { return GetTitle(); }
257
258 // Set/get the window name (used for resource setting in X)
259 inline virtual wxString GetName() const;
260 inline virtual void SetName(const wxString& name);
261
262 // Centre the window
263 virtual void Centre(int direction) ;
264 inline void Center(int direction = wxHORIZONTAL) { Centre(direction); }
265
266 // Popup a menu
267 virtual bool PopupMenu(wxMenu *menu, int x, int y);
268
269 // Send the window a refresh event
270 virtual void Refresh(bool eraseBack = TRUE, const wxRect *rect = NULL);
271
272 // New functions that will replace the above.
273 virtual void SetScrollbar(int orient, int pos, int thumbVisible,
274 int range, bool refresh = TRUE);
275
276 virtual void SetScrollPos(int orient, int pos, bool refresh = TRUE);
277 virtual int GetScrollPos(int orient) const;
278 virtual int GetScrollRange(int orient) const;
279 virtual int GetScrollThumb(int orient) const;
280
281 virtual void ScrollWindow(int dx, int dy, const wxRect *rect = NULL);
282
283 // Caret manipulation
284 virtual void CreateCaret(int w, int h);
285 virtual void CreateCaret(const wxBitmap *bitmap);
286 virtual void DestroyCaret();
287 virtual void ShowCaret(bool show);
288 virtual void SetCaretPos(int x, int y);
289 virtual void GetCaretPos(int *x, int *y) const;
290
291 // Tell window how much it can be sized
292 virtual void SetSizeHints(int minW = -1, int minH = -1, int maxW = -1, int maxH = -1, int incW = -1, int incH = -1);
293
294 // Set/get the window's identifier
295 inline int GetId() const;
296 inline void SetId(int id);
297
298 virtual void SetAcceleratorTable(const wxAcceleratorTable& accel);
299 inline virtual wxAcceleratorTable& GetAcceleratorTable() const { return (wxAcceleratorTable&) m_acceleratorTable; }
300
301 // Make the window modal (all other windows unresponsive)
302 virtual void MakeModal(bool modal);
303
304 // Get the private handle (platform-dependent)
305 inline void *GetHandle() const;
306
307 // Set/get the window's relatives
308 inline wxWindow *GetParent() const;
309 inline void SetParent(wxWindow *p) ;
310 inline wxWindow *GetGrandParent() const;
311 inline wxList& GetChildren() const;
312
313 // Set/get the window's font
314 virtual void SetFont(const wxFont& f);
315 inline virtual wxFont& GetFont() const;
316
317 // Set/get the window's validator
318 void SetValidator(const wxValidator& validator);
319 inline wxValidator *GetValidator() const;
320
321 // Set/get the window's style
322 inline void SetWindowStyleFlag(long flag);
323 inline long GetWindowStyleFlag() const;
324
325 // Handle a control command
326 virtual void OnCommand(wxWindow& win, wxCommandEvent& event);
327
328 // Set/get event handler
329 inline void SetEventHandler(wxEvtHandler *handler);
330 inline wxEvtHandler *GetEventHandler() const;
331
332 // Push/pop event handler (i.e. allow a chain of event handlers
333 // be searched)
334 void PushEventHandler(wxEvtHandler *handler) ;
335 wxEvtHandler *PopEventHandler(bool deleteHandler = FALSE) ;
336
337 // Close the window by calling OnClose, posting a deletion
338 virtual bool Close(bool force = FALSE);
339
340 // Destroy the window (delayed, if a managed window)
341 virtual bool Destroy() ;
342
343 // Mode for telling default OnSize members to
344 // call Layout(), if not using Sizers, just top-down constraints
345 inline void SetAutoLayout(bool a);
346 inline bool GetAutoLayout() const;
347
348 // Set/get constraints
349 inline wxLayoutConstraints *GetConstraints() const;
350 void SetConstraints(wxLayoutConstraints *c);
351
352 // Set/get window background colour
353 inline virtual void SetBackgroundColour(const wxColour& col);
354 inline virtual wxColour GetBackgroundColour() const;
355
356 // Set/get window foreground colour
357 inline virtual void SetForegroundColour(const wxColour& col);
358 inline virtual wxColour GetForegroundColour() const;
359
360 // Get the default button, if there is one
361 inline virtual wxButton *GetDefaultItem() const;
362 inline virtual void SetDefaultItem(wxButton *but);
363
364 // Override to define new behaviour for default action (e.g. double clicking
365 // on a listbox)
366 virtual void OnDefaultAction(wxControl *initiatingItem);
367
368 // Resource loading
369 #if wxUSE_WX_RESOURCES
370 virtual bool LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table = NULL);
371 virtual wxControl *CreateItem(const wxItemResource* childResource, const wxItemResource* parentResource,
372 const wxResourceTable *table = (const wxResourceTable *) NULL);
373 #endif
374
375 virtual void GetTextExtent(const wxString& string, int *x, int *y,
376 int *descent = NULL,
377 int *externalLeading = NULL,
378 const wxFont *theFont = NULL, bool use16 = FALSE) const;
379
380 // Is the window retained?
381 inline bool IsRetained() const;
382
383 // Warp the pointer the given position
384 virtual void WarpPointer(int x_pos, int y_pos) ;
385
386 // Clear the window
387 virtual void Clear();
388
389 // Find a window by id or name
390 virtual wxWindow *FindWindow(long id);
391 virtual wxWindow *FindWindow(const wxString& name);
392
393 // Constraint operations
394 bool Layout();
395 void SetSizer(wxSizer *sizer); // Adds sizer child to this window
396 inline wxSizer *GetSizer() const ;
397 inline wxWindow *GetSizerParent() const ;
398 inline void SetSizerParent(wxWindow *win);
399
400 // Do Update UI processing for controls
401 void UpdateWindowUI();
402
403 void OnEraseBackground(wxEraseEvent& event);
404 void OnChar(wxKeyEvent& event);
405 void OnKeyDown(wxKeyEvent& event);
406 void OnKeyUp(wxKeyEvent& event);
407 void OnPaint(wxPaintEvent& event);
408 void OnIdle(wxIdleEvent& event);
409
410 // Does this window want to accept keyboard focus?
411 virtual bool AcceptsFocus() const;
412
413 virtual void PrepareDC( wxDC &dc ) {};
414
415
416 public:
417 ////////////////////////////////////////////////////////////////////////
418 //// IMPLEMENTATION
419
420 // For implementation purposes - sometimes decorations make the client area
421 // smaller
422 virtual wxPoint GetClientAreaOrigin() const;
423
424 // Makes an adjustment to the window position (for example, a frame that has
425 // a toolbar that it manages itself).
426 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
427
428 // Executes the default message
429 virtual long Default();
430
431 /* TODO: you may need something like this
432 // Determine whether 3D effects are wanted
433 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
434 */
435
436 virtual void AddChild(wxWindow *child); // Adds reference to the child object
437 virtual void RemoveChild(wxWindow *child); // Removes reference to child
438 // (but doesn't delete the child object)
439 virtual void DestroyChildren(); // Removes and destroys all children
440
441 inline bool IsBeingDeleted() const { return FALSE; } // TODO: Should probably eliminate this
442
443 // Constraint implementation
444 void UnsetConstraints(wxLayoutConstraints *c);
445 inline wxList *GetConstraintsInvolvedIn() const ;
446 // Back-pointer to other windows we're involved with, so if we delete
447 // this window, we must delete any constraints we're involved with.
448 void AddConstraintReference(wxWindow *otherWin);
449 void RemoveConstraintReference(wxWindow *otherWin);
450 void DeleteRelatedConstraints();
451
452 virtual void ResetConstraints();
453 virtual void SetConstraintSizes(bool recurse = TRUE);
454 virtual bool LayoutPhase1(int *noChanges);
455 virtual bool LayoutPhase2(int *noChanges);
456 virtual bool DoPhase(int);
457 // Transforms from sizer coordinate space to actual
458 // parent coordinate space
459 virtual void TransformSizerToActual(int *x, int *y) const ;
460
461 // Set size with transformation to actual coordinates if nec.
462 virtual void SizerSetSize(int x, int y, int w, int h);
463 virtual void SizerMove(int x, int y);
464
465 // Only set/get the size/position of the constraint (if any)
466 virtual void SetSizeConstraint(int x, int y, int w, int h);
467 virtual void MoveConstraint(int x, int y);
468 virtual void GetSizeConstraint(int *w, int *h) const ;
469 virtual void GetClientSizeConstraint(int *w, int *h) const ;
470 virtual void GetPositionConstraint(int *x, int *y) const ;
471
472 // Dialog units translations. Implemented in wincmn.cpp.
473 wxPoint ConvertPixelsToDialog(const wxPoint& pt) ;
474 wxPoint ConvertDialogToPixels(const wxPoint& pt) ;
475 inline wxSize ConvertPixelsToDialog(const wxSize& sz)
476 { wxPoint pt(ConvertPixelsToDialog(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
477 inline wxSize ConvertDialogToPixels(const wxSize& sz)
478 { wxPoint pt(ConvertDialogToPixels(wxPoint(sz.x, sz.y))); return wxSize(pt.x, pt.y); }
479
480 wxObject *GetChild(int number) const ;
481
482 // Generates a new id for controls
483 static int NewControlId();
484
485 // Responds to colour changes: passes event on to children.
486 void OnSysColourChanged(wxSysColourChangedEvent& event);
487
488 // Transfers data to any child controls
489 void OnInitDialog(wxInitDialogEvent& event);
490
491 // Sends an OnInitDialog event, which in turns transfers data to
492 // to the window via validators.
493 virtual void InitDialog();
494
495 ////////////////////////////////////////////////////////////////////////
496 //// PROTECTED DATA
497 protected:
498 int m_windowId;
499 long m_windowStyle; // Store the window's style
500 wxEvtHandler * m_windowEventHandler; // Usually is 'this'
501 wxLayoutConstraints * m_constraints; // Constraints for this window
502 wxList * m_constraintsInvolvedIn; // List of constraints we're involved in
503 wxSizer * m_windowSizer; // Window's top-level sizer (if any)
504 wxWindow * m_sizerParent; // Window's parent sizer (if any)
505 bool m_autoLayout; // Whether to call Layout() in OnSize
506 wxWindow * m_windowParent; // Each window always knows its parent
507 wxValidator * m_windowValidator;
508 int m_minSizeX;
509 int m_minSizeY;
510 int m_maxSizeX;
511 int m_maxSizeY;
512
513 // Caret data
514 int m_caretWidth;
515 int m_caretHeight;
516 bool m_caretEnabled;
517 bool m_caretShown;
518 wxFont m_windowFont; // Window's font
519 wxCursor m_windowCursor; // Window's cursor
520 wxString m_windowName; // Window name
521
522 wxButton * m_defaultItem;
523
524 wxColour m_backgroundColour ;
525 wxColour m_foregroundColour ;
526 wxAcceleratorTable m_acceleratorTable;
527
528 #if wxUSE_DRAG_AND_DROP
529 wxDropTarget *m_pDropTarget; // the current drop target or NULL
530 #endif //USE_DRAG_AND_DROP
531
532 public:
533 wxRegion m_updateRegion;
534 wxList * m_children; // Window's children
535 int m_returnCode;
536
537 DECLARE_EVENT_TABLE()
538 };
539
540 ////////////////////////////////////////////////////////////////////////
541 //// INLINES
542
543 inline void *wxWindow::GetHandle() const { return (void *)NULL; }
544 inline int wxWindow::GetId() const { return m_windowId; }
545 inline void wxWindow::SetId(int id) { m_windowId = id; }
546 inline wxWindow *wxWindow::GetParent() const { return m_windowParent; }
547 inline void wxWindow::SetParent(wxWindow *p) { m_windowParent = p; }
548 inline wxWindow *wxWindow::GetGrandParent() const { return (m_windowParent ? m_windowParent->m_windowParent : (wxWindow*) NULL); }
549 inline wxList& wxWindow::GetChildren() const { return (wxList&) * m_children; }
550 inline wxFont& wxWindow::GetFont() const { return (wxFont&) m_windowFont; }
551 inline wxString wxWindow::GetName() const { return m_windowName; }
552 inline void wxWindow::SetName(const wxString& name) { m_windowName = name; }
553 inline long wxWindow::GetWindowStyleFlag() const { return m_windowStyle; }
554 inline void wxWindow::SetWindowStyleFlag(long flag) { m_windowStyle = flag; }
555 inline void wxWindow::SetEventHandler(wxEvtHandler *handler) { m_windowEventHandler = handler; }
556 inline wxEvtHandler *wxWindow::GetEventHandler() const { return m_windowEventHandler; }
557 inline void wxWindow::SetAutoLayout(bool a) { m_autoLayout = a; }
558 inline bool wxWindow::GetAutoLayout() const { return m_autoLayout; }
559 inline wxLayoutConstraints *wxWindow::GetConstraints() const { return m_constraints; }
560 inline void wxWindow::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; };
561 inline wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; };
562 inline void wxWindow::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; };
563 inline wxColour wxWindow::GetForegroundColour() const { return m_foregroundColour; };
564
565 inline wxButton *wxWindow::GetDefaultItem() const { return m_defaultItem; }
566 inline void wxWindow::SetDefaultItem(wxButton *but) { m_defaultItem = but; }
567 inline bool wxWindow::IsRetained() const { return ((m_windowStyle & wxRETAINED) == wxRETAINED); }
568
569 inline wxList *wxWindow::GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
570 inline wxSizer *wxWindow::GetSizer() const { return m_windowSizer; }
571 inline wxWindow *wxWindow::GetSizerParent() const { return m_sizerParent; }
572 inline void wxWindow::SetSizerParent(wxWindow *win) { m_sizerParent = win; }
573 inline wxValidator *wxWindow::GetValidator() const { return m_windowValidator; }
574 inline void wxWindow::SetReturnCode(int retCode) { m_returnCode = retCode; }
575 inline int wxWindow::GetReturnCode() { return m_returnCode; }
576
577 // Get the active window.
578 wxWindow* WXDLLEXPORT wxGetActiveWindow();
579
580 WXDLLEXPORT_DATA(extern wxList) wxTopLevelWindows;
581
582 #endif
583 // _WX_WINDOW_H_