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