]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/frame.cpp
Added GSocket_Init and GSocket_Cleanup
[wxWidgets.git] / src / motif / frame.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: frame.cpp
3// Purpose: wxFrame
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "frame.h"
14#endif
15
16#include "wx/frame.h"
17#include "wx/statusbr.h"
18#include "wx/toolbar.h"
19#include "wx/menuitem.h"
20#include "wx/menu.h"
21#include "wx/dcclient.h"
22#include "wx/dialog.h"
23#include "wx/settings.h"
24#include "wx/app.h"
25#include "wx/utils.h"
26
27#if defined(__ultrix) || defined(__sgi)
28#include <Xm/Frame.h>
29#endif
30
31#include <Xm/Xm.h>
32#include <X11/Shell.h>
33#if XmVersion >= 1002
34#include <Xm/XmAll.h>
35#else
36#include <Xm/Frame.h>
37#endif
38#include <Xm/MwmUtil.h>
39#include <Xm/BulletinB.h>
40#include <Xm/Form.h>
41#include <Xm/MainW.h>
42#include <Xm/RowColumn.h>
43#include <Xm/Label.h>
44#include <Xm/AtomMgr.h>
45#include <Xm/LabelG.h>
46#include <Xm/Frame.h>
47#if XmVersion > 1000
48#include <Xm/Protocols.h>
49#endif
50
51#include "wx/motif/private.h"
52
53void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs);
54void wxFrameFocusProc(Widget workArea, XtPointer clientData,
55 XmAnyCallbackStruct *cbs);
56static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
57 XCrossingEvent * event);
58
59extern wxList wxModelessWindows;
60extern wxList wxPendingDelete;
61
62// TODO: this should be tidied so that any frame can be the
63// top frame
64static bool wxTopLevelUsed = FALSE;
65
66#if !USE_SHARED_LIBRARY
67BEGIN_EVENT_TABLE(wxFrame, wxWindow)
68EVT_SIZE(wxFrame::OnSize)
69EVT_ACTIVATE(wxFrame::OnActivate)
70EVT_MENU_HIGHLIGHT_ALL(wxFrame::OnMenuHighlight)
71EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
72EVT_IDLE(wxFrame::OnIdle)
73EVT_CLOSE(wxFrame::OnCloseWindow)
74END_EVENT_TABLE()
75
76IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
77#endif
78
79#if wxUSE_NATIVE_STATUSBAR
80bool wxFrame::m_useNativeStatusBar = TRUE;
81#else
82bool wxFrame::m_useNativeStatusBar = FALSE;
83#endif
84
85wxFrame::wxFrame()
86{
87#if wxUSE_TOOLBAR
88 m_frameToolBar = NULL ;
89#endif // wxUSE_TOOLBAR
90
91 m_frameMenuBar = NULL;
92 m_frameStatusBar = NULL;
93
94 m_parent = NULL;
95 m_iconized = FALSE;
96
97 //// Motif-specific
98 m_frameShell = (WXWidget) NULL;
99 m_frameWidget = (WXWidget) NULL;;
100 m_workArea = (WXWidget) NULL;;
101 m_clientArea = (WXWidget) NULL;;
102 m_visibleStatus = TRUE;
103 m_title = "";
104}
105
106bool wxFrame::Create(wxWindow *parent,
107 wxWindowID id,
108 const wxString& title,
109 const wxPoint& pos,
110 const wxSize& size,
111 long style,
112 const wxString& name)
113{
114 if (!parent)
115 wxTopLevelWindows.Append(this);
116
117 SetName(name);
118
119 m_windowStyle = style;
120 m_frameMenuBar = NULL;
121#if wxUSE_TOOLBAR
122 m_frameToolBar = NULL ;
123#endif // wxUSE_TOOLBAR
124 m_frameStatusBar = NULL;
125
126 //// Motif-specific
127 m_frameShell = (WXWidget) NULL;
128 m_frameWidget = (WXWidget) NULL;;
129 m_workArea = (WXWidget) NULL;;
130 m_clientArea = (WXWidget) NULL;;
131 m_visibleStatus = TRUE;
132 m_title = "";
133
134 m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
135 m_foregroundColour = *wxBLACK;
136 m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
137
138 if ( id > -1 )
139 m_windowId = id;
140 else
141 m_windowId = (int)NewControlId();
142
143 if (parent) parent->AddChild(this);
144
145 wxModelessWindows.Append(this);
146
147 int x = pos.x; int y = pos.y;
148 int width = size.x; int height = size.y;
149
150 if (wxTopLevelUsed)
151 {
152 // Change suggested by Matthew Flatt
153 m_frameShell = (WXWidget)XtAppCreateShell
154 (
155 name,
156 wxTheApp->GetClassName(),
157 topLevelShellWidgetClass,
158 (Display*) wxGetDisplay(),
159 NULL,
160 0
161 );
162 }
163 else
164 {
165 m_frameShell = wxTheApp->GetTopLevelWidget();
166 wxTopLevelUsed = TRUE;
167 }
168
169 XtVaSetValues((Widget) m_frameShell,
170 // Allows menu to resize
171 XmNallowShellResize, True,
172 XmNdeleteResponse, XmDO_NOTHING,
173 XmNmappedWhenManaged, False,
174 XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
175 NULL);
176
177 if (!title.IsNull())
178 XtVaSetValues((Widget) m_frameShell,
179 XmNtitle, (const char*) title,
180 NULL);
181
182 m_frameWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
183 xmMainWindowWidgetClass, (Widget) m_frameShell,
184 XmNresizePolicy, XmRESIZE_NONE,
185 NULL);
186
187 m_workArea = (WXWidget) XtVaCreateWidget("form",
188 xmFormWidgetClass, (Widget) m_frameWidget,
189 XmNresizePolicy, XmRESIZE_NONE,
190 NULL);
191
192 m_clientArea = (WXWidget) XtVaCreateWidget("client",
193 xmBulletinBoardWidgetClass, (Widget) m_workArea,
194 XmNmarginWidth, 0,
195 XmNmarginHeight, 0,
196 XmNrightAttachment, XmATTACH_FORM,
197 XmNleftAttachment, XmATTACH_FORM,
198 XmNtopAttachment, XmATTACH_FORM,
199 XmNbottomAttachment, XmATTACH_FORM,
200 // XmNresizePolicy, XmRESIZE_ANY,
201 NULL);
202
203 wxLogDebug("Created frame (0x%08x) with work area 0x%08x and client "
204 "area 0x%08x", m_frameWidget, m_workArea, m_clientArea);
205
206 XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE,
207 wxUniversalRepaintProc, (XtPointer) this);
208
209 XtVaSetValues((Widget) m_frameWidget,
210 XmNworkWindow, (Widget) m_workArea,
211 NULL);
212
213 XtManageChild((Widget) m_clientArea);
214 XtManageChild((Widget) m_workArea);
215
216 wxAddWindowToTable((Widget) m_workArea, this);
217
218 XtTranslations ptr ;
219
220 XtOverrideTranslations((Widget) m_workArea,
221 ptr = XtParseTranslationTable("<Configure>: resize()"));
222
223 XtFree((char *)ptr);
224
225 XtAddCallback((Widget) m_workArea, XmNfocusCallback,
226 (XtCallbackProc)wxFrameFocusProc, (XtPointer)this);
227
228 /* Part of show-&-hide fix */
229 XtAddEventHandler((Widget) m_frameShell, StructureNotifyMask,
230 False, (XtEventHandler)wxFrameMapProc,
231 (XtPointer)m_workArea);
232
233 if (x > -1)
234 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
235 if (y > -1)
236 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
237 if (width > -1)
238 XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL);
239 if (height > -1)
240 XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
241
242 m_mainWidget = m_frameWidget;
243
244 ChangeFont(FALSE);
245
246 // This patch comes from Torsten Liermann lier@lier1.muc.de
247 if (XmIsMotifWMRunning( (Widget) m_frameShell ))
248 {
249 int decor = 0 ;
250 if (style & wxRESIZE_BORDER)
251 decor |= MWM_DECOR_RESIZEH ;
252 if (style & wxSYSTEM_MENU)
253 decor |= MWM_DECOR_MENU;
254 if ((style & wxCAPTION) ||
255 (style & wxTINY_CAPTION_HORIZ) ||
256 (style & wxTINY_CAPTION_VERT))
257 decor |= MWM_DECOR_TITLE;
258 if (style & wxTHICK_FRAME)
259 decor |= MWM_DECOR_BORDER;
260 if (style & wxTHICK_FRAME)
261 decor |= MWM_DECOR_BORDER;
262 if (style & wxMINIMIZE_BOX)
263 decor |= MWM_DECOR_MINIMIZE;
264 if (style & wxMAXIMIZE_BOX)
265 decor |= MWM_DECOR_MAXIMIZE;
266 XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL) ;
267 }
268 // This allows non-Motif window managers to support at least the
269 // no-decorations case.
270 else
271 {
272 if (style == 0)
273 XtVaSetValues((Widget) m_frameShell,XmNoverrideRedirect,TRUE,NULL);
274 }
275 XtRealizeWidget((Widget) m_frameShell);
276
277 // Intercept CLOSE messages from the window manager
278 Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay((Widget) m_frameShell), "WM_DELETE_WINDOW", False);
279#if (XmREVISION > 1 || XmVERSION > 1)
280 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (XtPointer)this);
281#else
282#if XmREVISION == 1
283 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (caddr_t)this);
284#else
285 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (void (*)())wxCloseFrameCallback, (caddr_t)this);
286#endif
287#endif
288
289 ChangeBackgroundColour();
290
291 PreResize();
292
293 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
294 sizeEvent.SetEventObject(this);
295
296 GetEventHandler()->ProcessEvent(sizeEvent);
297
298 return TRUE;
299}
300
301wxFrame::~wxFrame()
302{
303 if (m_clientArea)
304 XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, FALSE,
305 wxUniversalRepaintProc, (XtPointer) this);
306
307 if (GetMainWidget())
308 Show(FALSE);
309
310 if (m_frameMenuBar)
311 {
312 m_frameMenuBar->DestroyMenuBar();
313
314 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
315#if MOTIF_MENUBAR_DELETE_FIX
316 GetMenuBar()->SetMainWidget((WXWidget) NULL);
317#endif
318 delete m_frameMenuBar;
319 m_frameMenuBar = NULL;
320 }
321
322 wxTopLevelWindows.DeleteObject(this);
323 wxModelessWindows.DeleteObject(this);
324
325 if (m_frameStatusBar)
326 delete m_frameStatusBar;
327
328 DestroyChildren();
329
330 /*
331 int i;
332 for (i = 0; i < wxMAX_STATUS; i++)
333 if (statusTextWidget[i])
334 XtDestroyWidget (statusTextWidget[i]);
335
336 if (statusLineForm)
337 XtDestroyWidget (statusLineForm);
338
339 if (statusLineWidget)
340 XtDestroyWidget (statusLineWidget);
341 */
342
343 if (m_workArea)
344 {
345 wxDeleteWindowFromTable((Widget) m_workArea);
346
347 XtDestroyWidget ((Widget) m_workArea);
348 }
349
350 if (m_frameWidget)
351 {
352 wxDeleteWindowFromTable((Widget) m_frameWidget);
353 XtDestroyWidget ((Widget) m_frameWidget);
354 }
355
356 if (m_frameShell)
357 XtDestroyWidget ((Widget) m_frameShell);
358
359 SetMainWidget((WXWidget) NULL);
360
361 /* Check if it's the last top-level window */
362
363 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
364 {
365 wxTheApp->SetTopWindow(NULL);
366
367 if (wxTheApp->GetExitOnFrameDelete())
368 {
369 // Signal to the app that we're going to close
370 wxTheApp->ExitMainLoop();
371 }
372 }
373
374}
375
376// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
377void wxFrame::GetClientSize(int *x, int *y) const
378{
379 Dimension xx, yy;
380 XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL);
381
382 if (m_frameStatusBar)
383 {
384 int sbw, sbh;
385 m_frameStatusBar->GetSize(& sbw, & sbh);
386 yy -= sbh;
387 }
388#if wxUSE_TOOLBAR
389 if (m_frameToolBar)
390 {
391 int tbw, tbh;
392 m_frameToolBar->GetSize(& tbw, & tbh);
393 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
394 xx -= tbw;
395 else
396 yy -= tbh;
397 }
398#endif // wxUSE_TOOLBAR
399 /*
400 if (GetMenuBar() != (wxMenuBar*) NULL)
401 {
402 // it seems that if a frame holds a panel, the menu bar size
403 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
404 bool hasSubPanel = FALSE;
405 for(wxNode* node = GetChildren().First(); node; node = node->Next())
406 {
407 wxWindow *win = (wxWindow *)node->Data();
408 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
409
410 if (hasSubPanel)
411 break;
412 }
413 if (! hasSubPanel) {
414 Dimension ys;
415 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
416 yy -= ys;
417 }
418 }
419 */
420
421 *x = xx; *y = yy;
422}
423
424// Set the client size (i.e. leave the calculation of borders etc.
425// to wxWindows)
426void wxFrame::DoSetClientSize(int width, int height)
427{
428 // Calculate how large the new main window should be
429 // by finding the difference between the client area and the
430 // main window area, and adding on to the new client area
431 if (width > -1)
432 XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL);
433
434 if (height > -1)
435 {
436 if (m_frameStatusBar)
437 {
438 int sbw, sbh;
439 m_frameStatusBar->GetSize(& sbw, & sbh);
440 height += sbh;
441 }
442#if wxUSE_TOOLBAR
443 if (m_frameToolBar)
444 {
445 int tbw, tbh;
446 m_frameToolBar->GetSize(& tbw, & tbh);
447 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
448 width += tbw;
449 else
450 height += tbh;
451 }
452#endif // wxUSE_TOOLBAR
453
454 XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL);
455 }
456 PreResize();
457
458 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
459 sizeEvent.SetEventObject(this);
460
461 GetEventHandler()->ProcessEvent(sizeEvent);
462
463}
464
465void wxFrame::GetSize(int *width, int *height) const
466{
467 Dimension xx, yy;
468 XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
469 *width = xx; *height = yy;
470}
471
472void wxFrame::GetPosition(int *x, int *y) const
473{
474 Window parent_window = XtWindow((Widget) m_frameShell),
475 next_parent = XtWindow((Widget) m_frameShell),
476 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
477
478 // search for the parent that is child of ROOT, because the WM may
479 // reparent twice and notify only the next parent (like FVWM)
480 while (next_parent != root) {
481 Window *theChildren; unsigned int n;
482 parent_window = next_parent;
483 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
484 &next_parent, &theChildren, &n);
485 XFree(theChildren); // not needed
486 }
487 int xx, yy; unsigned int dummy;
488 XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root,
489 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
490 if (x) *x = xx;
491 if (y) *y = yy;
492}
493
494void wxFrame::DoSetSize(int x, int y, int width, int height, int sizeFlags)
495{
496 if (x > -1)
497 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
498 if (y > -1)
499 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
500 if (width > -1)
501 XtVaSetValues((Widget) m_frameWidget, XmNwidth, width, NULL);
502 if (height > -1)
503 XtVaSetValues((Widget) m_frameWidget, XmNheight, height, NULL);
504
505 if (!(height == -1 && width == -1))
506 {
507 PreResize();
508
509 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
510 sizeEvent.SetEventObject(this);
511
512 GetEventHandler()->ProcessEvent(sizeEvent);
513 }
514}
515
516bool wxFrame::Show(bool show)
517{
518 if (!m_frameShell)
519 return wxWindow::Show(show);
520
521 m_visibleStatus = show; /* show-&-hide fix */
522
523 m_isShown = show;
524 if (show) {
525 XtMapWidget((Widget) m_frameShell);
526 XRaiseWindow(XtDisplay((Widget) m_frameShell), XtWindow((Widget) m_frameShell));
527 } else {
528 XtUnmapWidget((Widget) m_frameShell);
529 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
530 }
531 return TRUE;
532}
533
534void wxFrame::Iconize(bool iconize)
535{
536 if (!iconize)
537 Show(TRUE);
538
539 if (m_frameShell)
540 XtVaSetValues((Widget) m_frameShell, XmNiconic, (Boolean)iconize, NULL);
541}
542
543// Equivalent to maximize/restore in Windows
544void wxFrame::Maximize(bool maximize)
545{
546 Show(TRUE);
547
548 if (maximize && m_frameShell)
549 XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL);
550}
551
552bool wxFrame::IsIconized() const
553{
554 if (!m_frameShell)
555 return FALSE;
556
557 Boolean iconic;
558 XtVaGetValues((Widget) m_frameShell, XmNiconic, &iconic, NULL);
559 return iconic;
560}
561
562// Is it maximized?
563bool wxFrame::IsMaximized(void) const
564{
565 // No maximizing in Motif (?)
566 return FALSE;
567}
568
569void wxFrame::SetTitle(const wxString& title)
570{
571 if (title == m_title)
572 return;
573
574 m_title = title;
575
576 if (!title.IsNull())
577 XtVaSetValues((Widget) m_frameShell,
578 XmNtitle, (const char*) title,
579 XmNiconName, (const char*) title,
580 NULL);
581}
582
583void wxFrame::SetIcon(const wxIcon& icon)
584{
585 m_icon = icon;
586
587 if (!m_frameShell)
588 return;
589
590 if (!icon.Ok() || !icon.GetPixmap())
591 return;
592
593 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL);
594}
595
596wxStatusBar *wxFrame::OnCreateStatusBar(int number, long style, wxWindowID id,
597 const wxString& name)
598{
599 wxStatusBar *statusBar = NULL;
600
601 statusBar = new wxStatusBar(this, id, wxPoint(0, 0), wxSize(100, 20),
602 style, name);
603
604 // Set the height according to the font and the border size
605 wxClientDC dc(statusBar);
606 dc.SetFont(statusBar->GetFont());
607
608 long x, y;
609 dc.GetTextExtent("X", &x, &y);
610
611 int height = (int)( (y * 1.1) + 2* statusBar->GetBorderY());
612
613 statusBar->SetSize(-1, -1, 100, height);
614
615 statusBar->SetFieldsCount(number);
616 return statusBar;
617}
618
619wxStatusBar* wxFrame::CreateStatusBar(int number, long style, wxWindowID id,
620 const wxString& name)
621{
622 // Calling CreateStatusBar twice is an error.
623 wxCHECK_MSG( m_frameStatusBar == NULL, FALSE,
624 "recreating status bar in wxFrame" );
625
626 m_frameStatusBar = OnCreateStatusBar(number, style, id,
627 name);
628 if ( m_frameStatusBar )
629 {
630 PositionStatusBar();
631 return m_frameStatusBar;
632 }
633 else
634 return NULL;
635}
636
637void wxFrame::SetStatusText(const wxString& text, int number)
638{
639 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set text for" );
640
641 m_frameStatusBar->SetStatusText(text, number);
642}
643
644void wxFrame::SetStatusWidths(int n, const int widths_field[])
645{
646 wxCHECK_RET( m_frameStatusBar != NULL, "no statusbar to set widths for" );
647
648 m_frameStatusBar->SetStatusWidths(n, widths_field);
649 PositionStatusBar();
650}
651
652void wxFrame::PositionStatusBar()
653{
654 if (!m_frameStatusBar)
655 return;
656
657 int w, h;
658 GetClientSize(&w, &h);
659 int sw, sh;
660 m_frameStatusBar->GetSize(&sw, &sh);
661
662 // Since we wish the status bar to be directly under the client area,
663 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
664 m_frameStatusBar->SetSize(0, h, w, sh);
665}
666
667WXWidget wxFrame::GetMenuBarWidget() const
668{
669 if (GetMenuBar())
670 return GetMenuBar()->GetMainWidget();
671 else
672 return (WXWidget) NULL;
673}
674
675void wxFrame::SetMenuBar(wxMenuBar *menuBar)
676{
677 if (!menuBar)
678 {
679 m_frameMenuBar = NULL;
680 return;
681 }
682
683 // Currently can't set it twice
684 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
685
686 if (m_frameMenuBar)
687 {
688 m_frameMenuBar->DestroyMenuBar();
689 delete m_frameMenuBar;
690 }
691
692 m_frameMenuBar = menuBar;
693 m_frameMenuBar->CreateMenuBar(this);
694}
695
696void wxFrame::Fit()
697{
698 // Work out max. size
699 wxNode *node = GetChildren().First();
700 int max_width = 0;
701 int max_height = 0;
702 while (node)
703 {
704 // Find a child that's a subwindow, but not a dialog box.
705 wxWindow *win = (wxWindow *)node->Data();
706
707 if (!win->IsKindOf(CLASSINFO(wxFrame)) &&
708 !win->IsKindOf(CLASSINFO(wxDialog)))
709 {
710 int width, height;
711 int x, y;
712 win->GetSize(&width, &height);
713 win->GetPosition(&x, &y);
714
715 if ((x + width) > max_width)
716 max_width = x + width;
717 if ((y + height) > max_height)
718 max_height = y + height;
719 }
720 node = node->Next();
721 }
722 SetClientSize(max_width, max_height);
723}
724
725// Responds to colour changes, and passes event on to children.
726void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
727{
728 SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE));
729 Refresh();
730
731 if ( m_frameStatusBar )
732 {
733 wxSysColourChangedEvent event2;
734 event2.SetEventObject( m_frameStatusBar );
735 m_frameStatusBar->ProcessEvent(event2);
736 }
737
738 // Propagate the event to the non-top-level children
739 wxWindow::OnSysColourChanged(event);
740}
741
742// Default resizing behaviour - if only ONE subwindow,
743// resize to client rectangle size
744void wxFrame::OnSize(wxSizeEvent& event)
745{
746 // if we're using constraints - do use them
747#if wxUSE_CONSTRAINTS
748 if ( GetAutoLayout() ) {
749 Layout();
750 return;
751 }
752#endif
753
754 // do we have _exactly_ one child?
755 wxWindow *child = NULL;
756 for ( wxNode *node = GetChildren().First(); node; node = node->Next() )
757 {
758 wxWindow *win = (wxWindow *)node->Data();
759 if ( !win->IsKindOf(CLASSINFO(wxFrame)) &&
760 !win->IsKindOf(CLASSINFO(wxDialog)) &&
761 (win != GetStatusBar())
762#if wxUSE_TOOLBAR
763 && (win != GetToolBar())
764#endif // wxUSE_TOOLBAR
765 )
766 {
767 if ( child )
768 return; // it's our second subwindow - nothing to do
769 child = win;
770 }
771 }
772
773 if ( child ) {
774 // we have exactly one child - set it's size to fill the whole frame
775 int clientW, clientH;
776 GetClientSize(&clientW, &clientH);
777
778 int x = 0;
779 int y = 0;
780
781 child->SetSize(x, y, clientW, clientH);
782 }
783}
784
785// Default activation behaviour - set the focus for the first child
786// subwindow found.
787void wxFrame::OnActivate(wxActivateEvent& event)
788{
789 for(wxNode *node = GetChildren().First(); node; node = node->Next())
790 {
791 // Find a child that's a subwindow, but not a dialog box.
792 wxWindow *child = (wxWindow *)node->Data();
793 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
794 !child->IsKindOf(CLASSINFO(wxDialog)))
795 {
796 child->SetFocus();
797 return;
798 }
799 }
800}
801
802// The default implementation for the close window event.
803// OnClose for backward compatibility.
804
805void wxFrame::OnCloseWindow(wxCloseEvent& event)
806{
807 this->Destroy();
808}
809
810// Destroy the window (delayed, if a managed window)
811bool wxFrame::Destroy()
812{
813 if (!wxPendingDelete.Member(this))
814 wxPendingDelete.Append(this);
815 return TRUE;
816}
817
818// Default menu selection behaviour - display a help string
819void wxFrame::OnMenuHighlight(wxMenuEvent& event)
820{
821 if (GetStatusBar())
822 {
823 if (event.GetMenuId() == -1)
824 SetStatusText("");
825 else
826 {
827 wxMenuBar *menuBar = GetMenuBar();
828 if (menuBar)
829 {
830 wxString helpString(menuBar->GetHelpString(event.GetMenuId()));
831 if (helpString != "")
832 SetStatusText(helpString);
833 }
834 }
835 }
836}
837
838wxMenuBar *wxFrame::GetMenuBar() const
839{
840 return m_frameMenuBar;
841}
842
843void wxFrame::Centre(int direction)
844{
845 int display_width, display_height, width, height, x, y;
846 wxDisplaySize(&display_width, &display_height);
847
848 GetSize(&width, &height);
849 GetPosition(&x, &y);
850
851 if (direction & wxHORIZONTAL)
852 x = (int)((display_width - width)/2);
853 if (direction & wxVERTICAL)
854 y = (int)((display_height - height)/2);
855
856 SetSize(x, y, width, height);
857}
858
859// Call this to simulate a menu command
860void wxFrame::Command(int id)
861{
862 ProcessCommand(id);
863}
864
865void wxFrame::ProcessCommand(int id)
866{
867 wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, id);
868 commandEvent.SetInt( id );
869 commandEvent.SetEventObject( this );
870
871 wxMenuBar *bar = GetMenuBar() ;
872 if (!bar)
873 return;
874
875/* TODO: check the menu item if required
876 wxMenuItem *item = bar->FindItemForId(id) ;
877 if (item && item->IsCheckable())
878 {
879 bar->Check(id,!bar->Checked(id)) ;
880 }
881*/
882
883 wxEvtHandler* evtHandler = GetEventHandler();
884
885 evtHandler->ProcessEvent(commandEvent);
886}
887
888// Checks if there is a toolbar, and returns the first free client position
889wxPoint wxFrame::GetClientAreaOrigin() const
890{
891 wxPoint pt(0, 0);
892#if wxUSE_TOOLBAR
893 if (GetToolBar())
894 {
895 int w, h;
896 GetToolBar()->GetSize(& w, & h);
897
898 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
899 {
900 pt.x += w;
901 }
902 else
903 {
904 pt.y += h;
905 }
906 }
907#endif // wxUSE_TOOLBAR
908
909 return pt;
910}
911
912void wxFrame::ScreenToClient(int *x, int *y) const
913{
914 wxWindow::ScreenToClient(x, y);
915
916 // We may be faking the client origin.
917 // So a window that's really at (0, 30) may appear
918 // (to wxWin apps) to be at (0, 0).
919 wxPoint pt(GetClientAreaOrigin());
920 *x -= pt.x;
921 *y -= pt.y;
922}
923
924void wxFrame::ClientToScreen(int *x, int *y) const
925{
926 // We may be faking the client origin.
927 // So a window that's really at (0, 30) may appear
928 // (to wxWin apps) to be at (0, 0).
929 wxPoint pt1(GetClientAreaOrigin());
930 *x += pt1.x;
931 *y += pt1.y;
932
933 wxWindow::ClientToScreen(x, y);
934}
935
936#if wxUSE_TOOLBAR
937wxToolBar* wxFrame::CreateToolBar(long style, wxWindowID id, const wxString& name)
938{
939 wxCHECK_MSG( m_frameToolBar == NULL, FALSE,
940 "recreating toolbar in wxFrame" );
941
942 wxToolBar* toolBar = OnCreateToolBar(style, id, name);
943 if (toolBar)
944 {
945 SetToolBar(toolBar);
946 PositionToolBar();
947 return toolBar;
948 }
949 else
950 {
951 return NULL;
952 }
953}
954
955wxToolBar* wxFrame::OnCreateToolBar(long style, wxWindowID id, const wxString& name)
956{
957 return new wxToolBar(this, id, wxPoint(0, 0), wxSize(100, 24), style, name);
958}
959
960void wxFrame::SetToolBar(wxToolBar *toolbar)
961{
962 m_frameToolBar = toolbar;
963}
964
965wxToolBar *wxFrame::GetToolBar() const
966{
967 return m_frameToolBar;
968}
969
970void wxFrame::PositionToolBar()
971{
972 int cw, ch;
973
974 GetClientSize(& cw, &ch);
975
976 if (GetToolBar())
977 {
978 int tw, th;
979 GetToolBar()->GetSize(& tw, & th);
980
981 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
982 {
983 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
984 // means, pretend we don't have toolbar/status bar, so we
985 // have the original client size.
986 GetToolBar()->SetSize(0, 0, tw, ch + th, wxSIZE_NO_ADJUSTMENTS);
987 }
988 else
989 {
990 // Use the 'real' position
991 GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS);
992 }
993 }
994}
995#endif // wxUSE_TOOLBAR
996
997void wxFrame::CaptureMouse()
998{
999 if (m_winCaptured)
1000 return;
1001
1002 if (GetMainWidget())
1003 XtAddGrab((Widget) m_frameShell, TRUE, FALSE);
1004 m_winCaptured = TRUE;
1005}
1006
1007void wxFrame::ReleaseMouse()
1008{
1009 if (!m_winCaptured)
1010 return;
1011
1012 if (GetMainWidget())
1013 XtRemoveGrab((Widget) m_frameShell);
1014 m_winCaptured = FALSE;
1015}
1016
1017void wxFrame::Raise(void)
1018{
1019 Window parent_window = XtWindow((Widget) m_frameShell),
1020 next_parent = XtWindow((Widget) m_frameShell),
1021 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
1022 // search for the parent that is child of ROOT, because the WM may
1023 // reparent twice and notify only the next parent (like FVWM)
1024 while (next_parent != root) {
1025 Window *theChildren; unsigned int n;
1026 parent_window = next_parent;
1027 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
1028 &next_parent, &theChildren, &n);
1029 XFree(theChildren); // not needed
1030 }
1031 XRaiseWindow(XtDisplay((Widget) m_frameShell), parent_window);
1032}
1033
1034void wxFrame::Lower(void)
1035{
1036 Window parent_window = XtWindow((Widget) m_frameShell),
1037 next_parent = XtWindow((Widget) m_frameShell),
1038 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
1039 // search for the parent that is child of ROOT, because the WM may
1040 // reparent twice and notify only the next parent (like FVWM)
1041 while (next_parent != root) {
1042 Window *theChildren; unsigned int n;
1043 parent_window = next_parent;
1044 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
1045 &next_parent, &theChildren, &n);
1046 XFree(theChildren); // not needed
1047 }
1048 XLowerWindow(XtDisplay((Widget) m_frameShell), parent_window);
1049}
1050
1051void wxFrameFocusProc(Widget workArea, XtPointer clientData,
1052 XmAnyCallbackStruct *cbs)
1053{
1054 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
1055 // TODO
1056 // wxFrame *frame = (wxFrame *)clientData;
1057 // frame->GetEventHandler()->OnSetFocus();
1058}
1059
1060/* MATTEW: Used to insure that hide-&-show within an event cycle works */
1061static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
1062 XCrossingEvent * event)
1063{
1064 wxFrame *frame = (wxFrame *)wxGetWindowFromTable((Widget)clientData);
1065
1066 if (frame) {
1067 XEvent *e = (XEvent *)event;
1068
1069 if (e->xany.type == MapNotify)
1070 {
1071 // Iconize fix
1072 XtVaSetValues(frameShell, XmNiconic, (Boolean)False, NULL);
1073 if (!frame->GetVisibleStatus())
1074 {
1075 /* We really wanted this to be hidden! */
1076 XtUnmapWidget((Widget) frame->GetShellWidget());
1077 }
1078 }
1079 else if (e->xany.type == UnmapNotify)
1080 // Iconize fix
1081 XtVaSetValues(frameShell, XmNiconic, (Boolean)True, NULL);
1082 }
1083}
1084
1085//// Motif-specific
1086bool wxFrame::PreResize()
1087{
1088#if wxUSE_TOOLBAR
1089 PositionToolBar();
1090#endif // wxUSE_TOOLBAR
1091 PositionStatusBar();
1092 return TRUE;
1093}
1094
1095WXWidget wxFrame::GetClientWidget() const
1096{
1097 return m_clientArea;
1098}
1099
1100void wxFrame::ChangeFont(bool keepOriginalSize)
1101{
1102 // TODO
1103}
1104
1105void wxFrame::ChangeBackgroundColour()
1106{
1107 if (GetClientWidget())
1108 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
1109}
1110
1111void wxFrame::ChangeForegroundColour()
1112{
1113 if (GetClientWidget())
1114 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
1115}
1116
1117void wxCloseFrameCallback(Widget widget, XtPointer client_data, XmAnyCallbackStruct *cbs)
1118{
1119 wxFrame *frame = (wxFrame *)client_data;
1120
1121 wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, frame->GetId());
1122 closeEvent.SetEventObject(frame);
1123
1124 // May delete the frame (with delayed deletion)
1125 frame->GetEventHandler()->ProcessEvent(closeEvent);
1126}
1127