]> git.saurik.com Git - wxWidgets.git/blob - include/wx/stubs/window.h
some minor changes in wxLogWindow
[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
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 USE_DRAG_AND_DROP
70 class wxDropTarget;
71 #endif
72
73 #if USE_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 USE_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 // Get the default button, if there is one
315 inline virtual wxButton *GetDefaultItem() const;
316 inline virtual void SetDefaultItem(wxButton *but);
317
318 // Override to define new behaviour for default action (e.g. double clicking
319 // on a listbox)
320 virtual void OnDefaultAction(wxControl *initiatingItem);
321
322 // Resource loading
323 #if USE_WX_RESOURCES
324 virtual bool LoadFromResource(wxWindow *parent, const wxString& resourceName, const wxResourceTable *table = NULL);
325 virtual wxControl *CreateItem(const wxItemResource *childResource, const wxResourceTable *table = NULL);
326 #endif
327
328 // Native resource loading
329 virtual bool LoadNativeDialog(wxWindow* parent, wxWindowID& id);
330 virtual bool LoadNativeDialog(wxWindow* parent, const wxString& name);
331 virtual wxWindow* GetWindowChild1(wxWindowID& id);
332 virtual wxWindow* GetWindowChild(wxWindowID& id);
333
334 virtual void GetTextExtent(const wxString& string, int *x, int *y,
335 int *descent = NULL,
336 int *externalLeading = NULL,
337 const wxFont *theFont = NULL, bool use16 = FALSE) const;
338
339 // Is the window retained?
340 inline bool IsRetained() const;
341
342 // Warp the pointer the given position
343 virtual void WarpPointer(int x_pos, int y_pos) ;
344
345 // Clear the window
346 virtual void Clear();
347
348 // Find a window by id or name
349 virtual wxWindow *FindWindow(long id);
350 virtual wxWindow *FindWindow(const wxString& name);
351
352 // Constraint operations
353 bool Layout();
354 void SetSizer(wxSizer *sizer); // Adds sizer child to this window
355 inline wxSizer *GetSizer() const ;
356 inline wxWindow *GetSizerParent() const ;
357 inline void SetSizerParent(wxWindow *win);
358
359 // Do Update UI processing for controls
360 void UpdateWindowUI();
361
362 void OnEraseBackground(wxEraseEvent& event);
363 void OnChar(wxKeyEvent& event);
364 void OnPaint(wxPaintEvent& event);
365 void OnIdle(wxIdleEvent& event);
366
367 // Does this window want to accept keyboard focus?
368 virtual bool AcceptsFocus() const;
369
370 public:
371 ////////////////////////////////////////////////////////////////////////
372 //// IMPLEMENTATION
373
374 // For implementation purposes - sometimes decorations make the client area
375 // smaller
376 virtual wxPoint GetClientAreaOrigin() const;
377
378 // Makes an adjustment to the window position (for example, a frame that has
379 // a toolbar that it manages itself).
380 virtual void AdjustForParentClientOrigin(int& x, int& y, int sizeFlags);
381
382 // Executes the default message
383 virtual long Default();
384
385 /* TODO: implement your own data access
386 virtual WXHWND GetHWND() const ;
387 virtual void SetHWND(WXHWND hWnd);
388 */
389
390 /* TODO: you may need something like this
391 // Determine whether 3D effects are wanted
392 virtual WXDWORD Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D);
393 */
394
395 virtual void AddChild(wxWindow *child); // Adds reference to the child object
396 virtual void RemoveChild(wxWindow *child); // Removes reference to child
397 // (but doesn't delete the child object)
398 virtual void DestroyChildren(); // Removes and destroys all children
399
400 // Constraint implementation
401 void UnsetConstraints(wxLayoutConstraints *c);
402 inline wxList *GetConstraintsInvolvedIn() const ;
403 // Back-pointer to other windows we're involved with, so if we delete
404 // this window, we must delete any constraints we're involved with.
405 void AddConstraintReference(wxWindow *otherWin);
406 void RemoveConstraintReference(wxWindow *otherWin);
407 void DeleteRelatedConstraints();
408
409 virtual void ResetConstraints();
410 virtual void SetConstraintSizes(bool recurse = TRUE);
411 virtual bool LayoutPhase1(int *noChanges);
412 virtual bool LayoutPhase2(int *noChanges);
413 virtual bool DoPhase(int);
414 // Transforms from sizer coordinate space to actual
415 // parent coordinate space
416 virtual void TransformSizerToActual(int *x, int *y) const ;
417
418 // Set size with transformation to actual coordinates if nec.
419 virtual void SizerSetSize(int x, int y, int w, int h);
420 virtual void SizerMove(int x, int y);
421
422 // Only set/get the size/position of the constraint (if any)
423 virtual void SetSizeConstraint(int x, int y, int w, int h);
424 virtual void MoveConstraint(int x, int y);
425 virtual void GetSizeConstraint(int *w, int *h) const ;
426 virtual void GetClientSizeConstraint(int *w, int *h) const ;
427 virtual void GetPositionConstraint(int *x, int *y) const ;
428
429 wxObject *GetChild(int number) const ;
430
431 inline void SetShowing(bool show);
432 inline bool IsUserEnabled() const;
433 inline bool GetTransparentBackground() const ;
434
435 // Responds to colour changes: passes event on to children.
436 void OnSysColourChanged(wxSysColourChangedEvent& event);
437
438 // Transfers data to any child controls
439 void OnInitDialog(wxInitDialogEvent& event);
440
441 // Sends an OnInitDialog event, which in turns transfers data to
442 // to the window via validators.
443 virtual void InitDialog();
444
445 ////////////////////////////////////////////////////////////////////////
446 //// PROTECTED DATA
447 protected:
448 int m_windowId;
449 long m_windowStyle; // Store the window's style
450 wxEvtHandler * m_windowEventHandler; // Usually is 'this'
451 wxLayoutConstraints * m_constraints; // Constraints for this window
452 wxList * m_constraintsInvolvedIn; // List of constraints we're involved in
453 wxSizer * m_windowSizer; // Window's top-level sizer (if any)
454 wxWindow * m_sizerParent; // Window's parent sizer (if any)
455 bool m_autoLayout; // Whether to call Layout() in OnSize
456 wxWindow * m_windowParent; // Each window always knows its parent
457 wxValidator * m_windowValidator;
458 bool m_inOnSize; // Protection against OnSize reentry
459 bool m_winEnabled;
460 int m_minSizeX;
461 int m_minSizeY;
462 int m_maxSizeX;
463 int m_maxSizeY;
464
465 // Caret data
466 int m_caretWidth;
467 int m_caretHeight;
468 bool m_caretEnabled;
469 bool m_caretShown;
470 wxFont m_windowFont; // Window's font
471 bool m_isShown;
472 wxCursor m_windowCursor; // Window's cursor
473 wxString m_windowName; // Window name
474
475 wxButton * m_defaultItem;
476
477 wxColour m_backgroundColour ;
478 wxColour m_foregroundColour ;
479 bool m_backgroundTransparent;
480
481 int m_xThumbSize;
482 int m_yThumbSize;
483
484 float m_lastXPos;
485 float m_lastYPos;
486 int m_lastEvent;
487
488 bool m_mouseInWindow;
489
490 #if USE_DRAG_AND_DROP
491 wxDropTarget *m_pDropTarget; // the current drop target or NULL
492 #endif //USE_DRAG_AND_DROP
493
494 public:
495 /* TODO: implementation of window handle, note of last message, etc.
496 WXHWND m_hWnd; // MS Windows window handle
497 WXUINT m_lastMsg;
498 WXWPARAM m_lastWParam;
499 WXLPARAM m_lastLParam;
500 WXHMENU m_hMenu; // Menu, if any
501
502 */
503
504 wxRegion m_updateRegion;
505 wxList * m_children; // Window's children
506 int m_returnCode;
507
508 DECLARE_EVENT_TABLE()
509 };
510
511 ////////////////////////////////////////////////////////////////////////
512 //// INLINES
513
514 inline void *wxWindow::GetHandle() const { return (void *)NULL; }
515 inline int wxWindow::GetId() const { return m_windowId; }
516 inline void wxWindow::SetId(int id) { m_windowId = id; }
517 inline wxWindow *wxWindow::GetParent() const { return m_windowParent; }
518 inline void wxWindow::SetParent(wxWindow *p) { m_windowParent = p; }
519 inline wxWindow *wxWindow::GetGrandParent() const { return (m_windowParent ? m_windowParent->m_windowParent : NULL); }
520 inline wxList *wxWindow::GetChildren() const { return m_children; }
521 inline wxFont *wxWindow::GetFont() const { return (wxFont *) & m_windowFont; }
522 inline wxString wxWindow::GetName() const { return m_windowName; }
523 inline void wxWindow::SetName(const wxString& name) { m_windowName = name; }
524 inline long wxWindow::GetWindowStyleFlag() const { return m_windowStyle; }
525 inline void wxWindow::SetWindowStyleFlag(long flag) { m_windowStyle = flag; }
526 inline void wxWindow::SetDoubleClick(bool flag) { m_doubleClickAllowed = flag; }
527 inline bool wxWindow::GetDoubleClick() const { return m_doubleClickAllowed; }
528 inline void wxWindow::SetEventHandler(wxEvtHandler *handler) { m_windowEventHandler = handler; }
529 inline wxEvtHandler *wxWindow::GetEventHandler() const { return m_windowEventHandler; }
530 inline void wxWindow::SetAutoLayout(bool a) { m_autoLayout = a; }
531 inline bool wxWindow::GetAutoLayout() const { return m_autoLayout; }
532 inline wxLayoutConstraints *wxWindow::GetConstraints() const { return m_constraints; }
533 inline void wxWindow::SetBackgroundColour(const wxColour& col) { m_backgroundColour = col; };
534 inline wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; };
535 inline void wxWindow::SetForegroundColour(const wxColour& col) { m_foregroundColour = col; };
536 inline wxColour wxWindow::GetForegroundColour() const { return m_foregroundColour; };
537
538 inline wxButton *wxWindow::GetDefaultItem() const { return m_defaultItem; }
539 inline void wxWindow::SetDefaultItem(wxButton *but) { m_defaultItem = but; }
540 inline bool wxWindow::IsRetained() const { return ((m_windowStyle & wxRETAINED) == wxRETAINED); }
541
542 inline void wxWindow::SetShowing(bool show) { m_isShown = show; }
543 inline wxList *wxWindow::GetConstraintsInvolvedIn() const { return m_constraintsInvolvedIn; }
544 inline wxSizer *wxWindow::GetSizer() const { return m_windowSizer; }
545 inline wxWindow *wxWindow::GetSizerParent() const { return m_sizerParent; }
546 inline void wxWindow::SetSizerParent(wxWindow *win) { m_sizerParent = win; }
547 inline wxValidator *wxWindow::GetValidator() const { return m_windowValidator; }
548 inline bool wxWindow::IsUserEnabled() const { return m_winEnabled; }
549 inline bool wxWindow::GetTransparentBackground() const { return m_backgroundTransparent; }
550 inline void wxWindow::SetReturnCode(int retCode) { m_returnCode = retCode; }
551 inline int wxWindow::GetReturnCode() { return m_returnCode; }
552
553 // Get the active window.
554 wxWindow* WXDLLEXPORT wxGetActiveWindow();
555
556 WXDLLEXPORT_DATA(extern wxList) wxTopLevelWindows;
557
558 #endif
559 // _WX_WINDOW_H_