]> git.saurik.com Git - wxWidgets.git/blob - interface/wx/toplevel.h
4cfa892bb7030ca31b9b669328351d25fadad8dd
[wxWidgets.git] / interface / wx / toplevel.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: toplevel.h
3 // Purpose: interface of wxTopLevelWindow
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 Styles used with wxTopLevelWindow::RequestUserAttention().
11 */
12 enum
13 {
14 wxUSER_ATTENTION_INFO = 1, ///< Requests user attention,
15 wxUSER_ATTENTION_ERROR = 2 ///< Results in a more drastic action.
16 };
17
18 /**
19 Styles used with wxTopLevelWindow::ShowFullScreen().
20 */
21 enum
22 {
23 wxFULLSCREEN_NOMENUBAR = 0x0001, ///< Don't display the menu bar.
24 wxFULLSCREEN_NOTOOLBAR = 0x0002, ///< Don't display toolbar bars.
25 wxFULLSCREEN_NOSTATUSBAR = 0x0004, ///< Don't display the status bar.
26 wxFULLSCREEN_NOBORDER = 0x0008, ///< Don't display any border.
27 wxFULLSCREEN_NOCAPTION = 0x0010, ///< Don't display a caption.
28
29 /**
30 Combination of all above, will display the least possible.
31 */
32 wxFULLSCREEN_ALL = wxFULLSCREEN_NOMENUBAR | wxFULLSCREEN_NOTOOLBAR |
33 wxFULLSCREEN_NOSTATUSBAR | wxFULLSCREEN_NOBORDER |
34 wxFULLSCREEN_NOCAPTION
35 };
36
37 #define wxDEFAULT_FRAME_STYLE (wxSYSTEM_MENU | \
38 wxRESIZE_BORDER | \
39 wxMINIMIZE_BOX | \
40 wxMAXIMIZE_BOX | \
41 wxCLOSE_BOX | \
42 wxCAPTION | \
43 wxCLIP_CHILDREN)
44
45 /**
46 @class wxTopLevelWindow
47
48 wxTopLevelWindow is a common base class for wxDialog and wxFrame. It is an
49 abstract base class meaning that you never work with objects of this class
50 directly, but all of its methods are also applicable for the two classes
51 above.
52
53 Note that the instances of wxTopLevelWindow are managed by wxWidgets in the
54 internal top level window list.
55
56 @beginEventEmissionTable
57 @event{EVT_MAXIMIZE(id, func)}
58 Process a @c wxEVT_MAXIMIZE event. See wxMaximizeEvent.
59 @event{EVT_MOVE(func)}
60 Process a @c wxEVT_MOVE event, which is generated when a window is moved.
61 See wxMoveEvent.
62 @event{EVT_MOVE_START(func)}
63 Process a @c wxEVT_MOVE_START event, which is generated when the user starts
64 to move or size a window. wxMSW only.
65 See wxMoveEvent.
66 @event{EVT_MOVE_END(func)}
67 Process a @c wxEVT_MOVE_END event, which is generated when the user stops
68 moving or sizing a window. wxMSW only.
69 See wxMoveEvent.
70 @event{EVT_SHOW(func)}
71 Process a @c wxEVT_SHOW event. See wxShowEvent.
72 @endEventTable
73
74 @library{wxcore}
75 @category{managedwnd}
76
77 @see wxDialog, wxFrame
78 */
79 class wxTopLevelWindow : public wxNonOwnedWindow
80 {
81 public:
82 /**
83 Default ctor.
84 */
85 wxTopLevelWindow();
86
87 /**
88 Constructor creating the top level window.
89 */
90 wxTopLevelWindow(wxWindow *parent,
91 wxWindowID id,
92 const wxString& title,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = wxDEFAULT_FRAME_STYLE,
96 const wxString& name = wxFrameNameStr);
97
98 /**
99 Destructor. Remember that wxTopLevelWindows do not get immediately
100 destroyed when the user (or the app) closes them; they have a
101 @b delayed destruction.
102
103 See @ref overview_windowdeletion for more info.
104 */
105 virtual ~wxTopLevelWindow();
106
107 /**
108 Creates the top level window.
109 */
110 bool Create(wxWindow *parent,
111 wxWindowID id,
112 const wxString& title,
113 const wxPoint& pos = wxDefaultPosition,
114 const wxSize& size = wxDefaultSize,
115 long style = wxDEFAULT_FRAME_STYLE,
116 const wxString& name = wxFrameNameStr);
117
118 /**
119 Returns @true if the platform supports making the window translucent.
120
121 @see SetTransparent()
122 */
123 virtual bool CanSetTransparent();
124
125 /**
126 A synonym for CentreOnScreen().
127 */
128 void CenterOnScreen(int direction = wxBOTH);
129
130 /**
131 Centres the window on screen.
132
133 @param direction
134 Specifies the direction for the centering. May be @c wxHORIZONTAL,
135 @c wxVERTICAL or @c wxBOTH.
136
137 @see wxWindow::CentreOnParent()
138 */
139 void CentreOnScreen(int direction = wxBOTH);
140
141 /**
142 Enables or disables the Close button (most often in the right upper
143 corner of a dialog) and the Close entry of the system menu (most often
144 in the left upper corner of the dialog).
145
146 Currently only implemented for wxMSW and wxGTK.
147
148 Returns @true if operation was successful. This may be wrong on X11
149 (including GTK+) where the window manager may not support this operation
150 and there is no way to find out.
151 */
152 virtual bool EnableCloseButton(bool enable = true);
153
154 /**
155 Returns a pointer to the button which is the default for this window, or
156 @c @NULL. The default button is the one activated by pressing the Enter
157 key.
158 */
159 wxWindow* GetDefaultItem() const;
160
161 /**
162 Get the default size for a new top level window.
163
164 This is used internally by wxWidgets on some platforms to determine the
165 default size for a window created using ::wxDefaultSize so it is not
166 necessary to use it when creating a wxTopLevelWindow, however it may be
167 useful if a rough estimation of the window size is needed for some
168 other reason.
169
170 @since 2.9.2
171 */
172 static wxSize GetDefaultSize();
173
174 /**
175 Returns the standard icon of the window. The icon will be invalid if it
176 hadn't been previously set by SetIcon().
177
178 @see GetIcons()
179 */
180 wxIcon GetIcon() const;
181
182 /**
183 Returns all icons associated with the window, there will be none of them
184 if neither SetIcon() nor SetIcons() had been called before. Use
185 GetIcon() to get the main icon of the window.
186
187 @see wxIconBundle
188 */
189 const wxIconBundle& GetIcons() const;
190
191 /**
192 Gets a string containing the window title.
193
194 @see SetTitle()
195 */
196 virtual wxString GetTitle() const;
197
198 /**
199 Unique to the wxWinCE port. Responds to showing/hiding SIP (soft input
200 panel) area and resize window accordingly. Override this if you want to
201 avoid resizing or do additional operations.
202 */
203 virtual bool HandleSettingChange(WXWPARAM wParam,
204 WXLPARAM lParam);
205
206 /**
207 Iconizes or restores the window.
208
209 @param iconize
210 If @true, iconizes the window; if @false, shows and restores it.
211
212 @see IsIconized(), Maximize(), wxIconizeEvent.
213 */
214 virtual void Iconize(bool iconize = true);
215
216 /**
217 Returns @true if this window is currently active, i.e.\ if the user is
218 currently working with it.
219 */
220 virtual bool IsActive();
221
222 /**
223 Returns @true if this window is expected to be always maximized, either
224 due to platform policy or due to local policy regarding particular
225 class.
226 */
227 virtual bool IsAlwaysMaximized() const;
228
229 /**
230 Returns @true if the window is in fullscreen mode.
231
232 @see ShowFullScreen()
233 */
234 virtual bool IsFullScreen() const;
235
236 /**
237 Returns @true if the window is iconized.
238 */
239 virtual bool IsIconized() const;
240
241 /**
242 Returns @true if the window is maximized.
243 */
244 virtual bool IsMaximized() const;
245
246 /**
247 This method is specific to wxUniversal port.
248
249 Returns @true if this window is using native decorations, @false if we
250 draw them ourselves.
251
252 @see UseNativeDecorations(),
253 UseNativeDecorationsByDefault()
254 */
255 bool IsUsingNativeDecorations() const;
256
257 /**
258 See wxWindow::SetAutoLayout(): when auto layout is on, this function gets
259 called automatically when the window is resized.
260 */
261 virtual bool Layout();
262
263 /**
264 Maximizes or restores the window.
265
266 @param maximize
267 If @true, maximizes the window, otherwise it restores it.
268
269 @see Iconize()
270 */
271 virtual void Maximize(bool maximize = true);
272
273 /**
274 MSW-specific function for accessing the system menu.
275
276 Returns a wxMenu pointer representing the system menu of the window
277 under MSW. The returned wxMenu may be used, if non-@c NULL, to add
278 extra items to the system menu. The usual @c wxEVT_COMMAND_MENU_SELECTED
279 events (that can be processed using @c EVT_MENU event table macro) will
280 then be generated for them. All the other wxMenu methods may be used as
281 well but notice that they won't allow you to access any standard system
282 menu items (e.g. they can't be deleted or modified in any way
283 currently).
284
285 Notice that because of the native system limitations the identifiers of
286 the items added to the system menu must be multiples of 16, otherwise
287 no events will be generated for them.
288
289 The returned pointer must @em not be deleted, it is owned by the window
290 and will be only deleted when the window itself is destroyed.
291
292 This function is not available in the other ports by design, any
293 occurrences of it in the portable code must be guarded by
294 @code #ifdef __WXMSW__ @endcode preprocessor guards.
295
296 @since 2.9.3
297 */
298 wxMenu *MSWGetSystemMenu() const;
299
300 /**
301 Use a system-dependent way to attract users attention to the window when
302 it is in background.
303
304 @a flags may have the value of either @c ::wxUSER_ATTENTION_INFO
305 (default) or @c ::wxUSER_ATTENTION_ERROR which results in a more drastic
306 action. When in doubt, use the default value.
307
308
309 @note This function should normally be only used when the application
310 is not already in foreground.
311
312 This function is currently implemented for Win32 where it flashes
313 the window icon in the taskbar, and for wxGTK with task bars
314 supporting it.
315
316 */
317 virtual void RequestUserAttention(int flags = wxUSER_ATTENTION_INFO);
318
319 /**
320 Changes the default item for the panel, usually @a win is a button.
321
322 @see GetDefaultItem()
323 */
324 wxWindow* SetDefaultItem(wxWindow* win);
325
326
327 wxWindow* SetTmpDefaultItem(wxWindow * win);
328 wxWindow* GetTmpDefaultItem() const;
329
330
331 /**
332 Sets the icon for this window.
333
334 @param icon
335 The wxIcon to associate with this window.
336
337 @remarks The window takes a 'copy' of @a icon, but since it uses
338 reference counting, the copy is very quick. It is safe to
339 delete @a icon after calling this function.
340
341 @note In wxMSW, @a icon must be either 16x16 or 32x32 icon.
342
343 @see wxIcon, SetIcons()
344 */
345 void SetIcon(const wxIcon& icon);
346
347 /**
348 Sets several icons of different sizes for this window: this allows to
349 use different icons for different situations (e.g. task switching bar,
350 taskbar, window title bar) instead of scaling, with possibly bad looking
351 results, the only icon set by SetIcon().
352
353 @param icons
354 The icons to associate with this window.
355
356 @note In wxMSW, @a icons must contain a 16x16 or 32x32 icon,
357 preferably both.
358
359 @see wxIconBundle
360 */
361 virtual void SetIcons(const wxIconBundle& icons);
362
363 /**
364 Sets action or menu activated by pressing left hardware button on the
365 smart phones. Unavailable on full keyboard machines.
366
367 @param id
368 Identifier for this button.
369 @param label
370 Text to be displayed on the screen area dedicated to this hardware
371 button.
372 @param subMenu
373 The menu to be opened after pressing this hardware button.
374
375 @see SetRightMenu().
376 */
377 void SetLeftMenu(int id = wxID_ANY,
378 const wxString& label = wxEmptyString,
379 wxMenu* subMenu = NULL);
380
381 /**
382 A simpler interface for setting the size hints than SetSizeHints().
383 */
384 virtual void SetMaxSize(const wxSize& size);
385
386 /**
387 A simpler interface for setting the size hints than SetSizeHints().
388 */
389 virtual void SetMinSize(const wxSize& size);
390
391 /**
392 Sets action or menu activated by pressing right hardware button on the
393 smart phones. Unavailable on full keyboard machines.
394
395 @param id
396 Identifier for this button.
397 @param label
398 Text to be displayed on the screen area dedicated to this hardware
399 button.
400 @param subMenu
401 The menu to be opened after pressing this hardware button.
402
403 @see SetLeftMenu().
404 */
405 void SetRightMenu(int id = wxID_ANY,
406 const wxString& label = wxEmptyString,
407 wxMenu* subMenu = NULL);
408
409 /**
410 Allows specification of minimum and maximum window sizes, and window
411 size increments. If a pair of values is not set (or set to -1), no
412 constraints will be used.
413
414 @param minW
415 The minimum width.
416 @param minH
417 The minimum height.
418 @param maxW
419 The maximum width.
420 @param maxH
421 The maximum height.
422 @param incW
423 Specifies the increment for sizing the width (GTK/Motif/Xt only).
424 @param incH
425 Specifies the increment for sizing the height (GTK/Motif/Xt only).
426
427 @remarks Notice that this function not only prevents the user from
428 resizing the window outside the given bounds but it also
429 prevents the program itself from doing it using
430 wxWindow::SetSize().
431
432 */
433 virtual void SetSizeHints(int minW, int minH,
434 int maxW = -1, int maxH = -1,
435 int incW = -1, int incH = -1);
436
437 /**
438 Allows specification of minimum and maximum window sizes, and window
439 size increments. If a pair of values is not set (or set to -1), no
440 constraints will be used.
441
442 @param minSize
443 The minimum size of the window.
444 @param maxSize
445 The maximum size of the window.
446 @param incSize
447 Increment size (only taken into account under X11-based ports such
448 as wxGTK/wxMotif/wxX11).
449
450 @remarks Notice that this function not only prevents the user from
451 resizing the window outside the given bounds but it also
452 prevents the program itself from doing it using
453 wxWindow::SetSize().
454 */
455 void SetSizeHints(const wxSize& minSize,
456 const wxSize& maxSize = wxDefaultSize,
457 const wxSize& incSize = wxDefaultSize);
458
459 /**
460 Sets the window title.
461
462 @param title
463 The window title.
464
465 @see GetTitle()
466 */
467 virtual void SetTitle(const wxString& title);
468
469 /**
470 If the platform supports it will set the window to be translucent.
471
472 @param alpha
473 Determines how opaque or transparent the window will be, if the
474 platform supports the operation. A value of 0 sets the window to be
475 fully transparent, and a value of 255 sets the window to be fully
476 opaque.
477 */
478 virtual bool SetTransparent(wxByte alpha);
479
480 /**
481 This virtual function is not meant to be called directly but can be
482 overridden to return @false (it returns @true by default) to allow the
483 application to close even if this, presumably not very important, window
484 is still opened. By default, the application stays alive as long as
485 there are any open top level windows.
486 */
487 virtual bool ShouldPreventAppExit() const;
488
489 /**
490 This function sets the wxTopLevelWindow's modified state on OS X,
491 which currently draws a black dot in the wxTopLevelWindow's close button.
492 On other platforms, this method does nothing.
493
494 @see OSXIsModified()
495 */
496 virtual void OSXSetModified(bool modified);
497
498 /**
499 Returns the current modified state of the wxTopLevelWindow on OS X.
500 On other platforms, this method does nothing.
501
502 @see OSXSetModified()
503 */
504 virtual bool OSXIsModified() const;
505
506 /**
507 Sets the file name represented by this wxTopLevelWindow.
508
509 Under OS X, this file name is used to set the "proxy icon", which
510 appears in the window title bar near its title, corresponding to this
511 file name. Under other platforms it currently doesn't do anything but
512 it is harmless to call it now and it might be implemented to do
513 something useful in the future so you're encouraged to use it for any
514 window representing a file-based document.
515
516 @since 2.9.4
517 */
518 virtual void SetRepresentedFilename(const wxString& filename);
519
520 /**
521 Show the wxTopLevelWindow, but do not give it keyboard focus. This can be
522 used for pop up or notification windows that should not steal the current
523 focus.
524 */
525 virtual void ShowWithoutActivating();
526
527 /**
528 Depending on the value of @a show parameter the window is either shown
529 full screen or restored to its normal state. @a style is a bit list
530 containing some or all of the following values, which indicate what
531 elements of the window to hide in full-screen mode:
532
533 - @c ::wxFULLSCREEN_NOMENUBAR
534 - @c ::wxFULLSCREEN_NOTOOLBAR
535 - @c ::wxFULLSCREEN_NOSTATUSBAR
536 - @c ::wxFULLSCREEN_NOBORDER
537 - @c ::wxFULLSCREEN_NOCAPTION
538 - @c ::wxFULLSCREEN_ALL (all of the above)
539
540 This function has not been tested with MDI frames.
541
542 @note Showing a window full screen also actually @ref wxWindow::Show()
543 "Show()"s the window if it isn't shown.
544
545 @see IsFullScreen()
546 */
547 virtual bool ShowFullScreen(bool show, long style = wxFULLSCREEN_ALL);
548
549 /**
550 This method is specific to wxUniversal port.
551
552 Use native or custom-drawn decorations for this window only. Notice that
553 to have any effect this method must be called before really creating the
554 window, i.e. two step creation must be used:
555
556 @code
557 MyFrame *frame = new MyFrame; // use default ctor
558 frame->UseNativeDecorations(false); // change from default "true"
559 frame->Create(parent, title, ...); // really create the frame
560 @endcode
561
562 @see UseNativeDecorationsByDefault(),
563 IsUsingNativeDecorations()
564 */
565 void UseNativeDecorations(bool native = true);
566
567 /**
568 This method is specific to wxUniversal port.
569
570 Top level windows in wxUniversal port can use either system-provided
571 window decorations (i.e. title bar and various icons, buttons and menus
572 in it) or draw the decorations themselves. By default the system
573 decorations are used if they are available, but this method can be
574 called with @a native set to @false to change this for all windows
575 created after this point.
576
577 Also note that if @c WXDECOR environment variable is set, then custom
578 decorations are used by default and so it may make sense to call this
579 method with default argument if the application can't use custom
580 decorations at all for some reason.
581
582 @see UseNativeDecorations()
583 */
584 void UseNativeDecorationsByDefault(bool native = true);
585 };
586