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