]> git.saurik.com Git - wxWidgets.git/blame - src/motif/frame.cpp
Applied patch from Ian Brown to make menus look better in wxMotif (#586347)
[wxWidgets.git] / src / motif / frame.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
1c4f8f8d 2// Name: motif/frame.cpp
4bb6408c
JS
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
1c4f8f8d
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
4bb6408c 20#ifdef __GNUG__
1c4f8f8d 21 #pragma implementation "frame.h"
4bb6408c
JS
22#endif
23
4dff3400
JJ
24
25#ifdef __VMS
26#define XtDisplay XTDISPLAY
27#define XtWindow XTWINDOW
28#define XtScreen XTSCREEN
29#endif
30
31# include "wx/frame.h"
4bb6408c
JS
32#include "wx/statusbr.h"
33#include "wx/toolbar.h"
34#include "wx/menuitem.h"
35#include "wx/menu.h"
36#include "wx/dcclient.h"
37#include "wx/dialog.h"
38#include "wx/settings.h"
39#include "wx/app.h"
40#include "wx/utils.h"
176513eb 41#include "wx/log.h"
4bb6408c 42
338dd992 43#ifdef __VMS__
1c4f8f8d 44 #pragma message disable nosimpint
338dd992 45#endif
1c4f8f8d 46
4bb6408c 47#if defined(__ultrix) || defined(__sgi)
1c4f8f8d 48 #include <Xm/Frame.h>
4bb6408c
JS
49#endif
50
51#include <Xm/Xm.h>
52#include <X11/Shell.h>
f618020a 53#include <X11/Core.h>
4bb6408c 54#if XmVersion >= 1002
1c4f8f8d 55 #include <Xm/XmAll.h>
4bb6408c 56#else
1c4f8f8d 57 #include <Xm/Frame.h>
4bb6408c
JS
58#endif
59#include <Xm/MwmUtil.h>
60#include <Xm/BulletinB.h>
61#include <Xm/Form.h>
62#include <Xm/MainW.h>
63#include <Xm/RowColumn.h>
64#include <Xm/Label.h>
65#include <Xm/AtomMgr.h>
66#include <Xm/LabelG.h>
67#include <Xm/Frame.h>
68#if XmVersion > 1000
1c4f8f8d 69 #include <Xm/Protocols.h>
4bb6408c 70#endif
1c4f8f8d 71
338dd992 72#ifdef __VMS__
1c4f8f8d 73 #pragma message enable nosimpint
338dd992 74#endif
4bb6408c
JS
75
76#include "wx/motif/private.h"
f618020a 77#include "wx/unix/utilsx11.h"
4bb6408c 78
1c4f8f8d
VZ
79// ----------------------------------------------------------------------------
80// private functions
81// ----------------------------------------------------------------------------
82
dc1efb1d
JS
83static void wxFrameEventHandler(Widget wid,
84 XtPointer WXUNUSED(client_data),
85 XEvent* event,
86 Boolean* continueToDispatch);
1c4f8f8d
VZ
87static void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs);
88static void wxFrameFocusProc(Widget workArea, XtPointer clientData,
89 XmAnyCallbackStruct *cbs);
dfe1eee3 90static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
2d120f83 91 XCrossingEvent * event);
4bb6408c 92
1c4f8f8d
VZ
93// ----------------------------------------------------------------------------
94// globals
95// ----------------------------------------------------------------------------
96
4bb6408c
JS
97extern wxList wxModelessWindows;
98extern wxList wxPendingDelete;
99
100// TODO: this should be tidied so that any frame can be the
101// top frame
102static bool wxTopLevelUsed = FALSE;
103
1c4f8f8d
VZ
104// ----------------------------------------------------------------------------
105// wxWin macros
106// ----------------------------------------------------------------------------
107
1c4f8f8d
VZ
108BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
109 EVT_ACTIVATE(wxFrame::OnActivate)
110 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
4bb6408c
JS
111END_EVENT_TABLE()
112
c0854a08 113IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxWindow)
4bb6408c 114
1c4f8f8d
VZ
115// ============================================================================
116// implementation
117// ============================================================================
1ccbb61a 118
1c4f8f8d
VZ
119// ----------------------------------------------------------------------------
120// frame construction
121// ----------------------------------------------------------------------------
dfe1eee3 122
1c4f8f8d
VZ
123void wxFrame::Init()
124{
4bb6408c 125 m_iconized = FALSE;
dfe1eee3 126
4bb6408c
JS
127 //// Motif-specific
128 m_frameShell = (WXWidget) NULL;
129 m_frameWidget = (WXWidget) NULL;;
130 m_workArea = (WXWidget) NULL;;
131 m_clientArea = (WXWidget) NULL;;
132 m_visibleStatus = TRUE;
4bb6408c
JS
133}
134
135bool wxFrame::Create(wxWindow *parent,
2d120f83
JS
136 wxWindowID id,
137 const wxString& title,
138 const wxPoint& pos,
139 const wxSize& size,
140 long style,
141 const wxString& name)
4bb6408c 142{
1c4f8f8d 143 if ( parent )
cf58a48f 144 parent->AddChild(this);
1c4f8f8d 145 else
2d120f83 146 wxTopLevelWindows.Append(this);
dfe1eee3 147
1c4f8f8d
VZ
148 wxModelessWindows.Append(this);
149
2d120f83 150 SetName(name);
dfe1eee3 151
2d120f83 152 m_windowStyle = style;
dfe1eee3 153
a756f210 154 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
2d120f83 155 m_foregroundColour = *wxBLACK;
a756f210 156 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
dfe1eee3 157
2d120f83
JS
158 if ( id > -1 )
159 m_windowId = id;
160 else
161 m_windowId = (int)NewControlId();
dfe1eee3 162
447a039f
MB
163 int x = pos.x, y = pos.y;
164 int width = size.x, height = size.y;
da8bed9b
VZ
165
166 // Set reasonable values for position and size if defaults have been
167 // requested
447a039f 168 //
da8bed9b
VZ
169 // MB TODO: something better than these arbitrary values ?
170 // VZ should use X resources for this...
171 if ( width == -1 )
172 width = 400;
173 if ( height == -1 )
174 height = 400;
447a039f
MB
175
176 int displayW, displayH;
177 wxDisplaySize( &displayW, &displayH );
178
179 if ( x == -1 )
180 {
181 x = (displayW - width) / 2;
182 if (x < 10) x = 10;
183 }
184 if ( y == -1 )
185 {
186 y = (displayH - height) / 2;
da8bed9b 187 if (y < 10) y = 10;
447a039f 188 }
da8bed9b 189
1c4f8f8d 190 // VZ: what does this do??
2d120f83 191 if (wxTopLevelUsed)
31528cd3 192 {
2d120f83 193 // Change suggested by Matthew Flatt
31528cd3
VZ
194 m_frameShell = (WXWidget)XtAppCreateShell
195 (
196 name,
197 wxTheApp->GetClassName(),
198 topLevelShellWidgetClass,
199 (Display*) wxGetDisplay(),
200 NULL,
201 0
202 );
203 }
2d120f83
JS
204 else
205 {
206 m_frameShell = wxTheApp->GetTopLevelWidget();
207 wxTopLevelUsed = TRUE;
208 }
dfe1eee3
VZ
209
210 XtVaSetValues((Widget) m_frameShell,
2d120f83
JS
211 // Allows menu to resize
212 XmNallowShellResize, True,
213 XmNdeleteResponse, XmDO_NOTHING,
214 XmNmappedWhenManaged, False,
215 XmNiconic, (style & wxICONIZE) ? TRUE : FALSE,
216 NULL);
dfe1eee3 217
1c4f8f8d 218 if (!title.IsEmpty())
dfe1eee3 219 XtVaSetValues((Widget) m_frameShell,
1c4f8f8d 220 XmNtitle, title.c_str(),
2d120f83 221 NULL);
dfe1eee3 222
2d120f83
JS
223 m_frameWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
224 xmMainWindowWidgetClass, (Widget) m_frameShell,
225 XmNresizePolicy, XmRESIZE_NONE,
226 NULL);
dfe1eee3 227
2d120f83
JS
228 m_workArea = (WXWidget) XtVaCreateWidget("form",
229 xmFormWidgetClass, (Widget) m_frameWidget,
230 XmNresizePolicy, XmRESIZE_NONE,
231 NULL);
dfe1eee3 232
2d120f83
JS
233 m_clientArea = (WXWidget) XtVaCreateWidget("client",
234 xmBulletinBoardWidgetClass, (Widget) m_workArea,
235 XmNmarginWidth, 0,
236 XmNmarginHeight, 0,
237 XmNrightAttachment, XmATTACH_FORM,
238 XmNleftAttachment, XmATTACH_FORM,
239 XmNtopAttachment, XmATTACH_FORM,
240 XmNbottomAttachment, XmATTACH_FORM,
241 // XmNresizePolicy, XmRESIZE_ANY,
242 NULL);
0492c5a0 243
1c4f8f8d
VZ
244 wxLogTrace(wxTRACE_Messages,
245 "Created frame (0x%08x) with work area 0x%08x and client "
31528cd3
VZ
246 "area 0x%08x", m_frameWidget, m_workArea, m_clientArea);
247
2e35f56f
JS
248 XtAddEventHandler((Widget) m_clientArea, ExposureMask,FALSE,
249 wxUniversalRepaintProc, (XtPointer) this);
dfe1eee3 250
dc1efb1d
JS
251 XtAddEventHandler((Widget) m_clientArea,
252 ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask,
253 FALSE,
254 wxFrameEventHandler,
255 (XtPointer)this);
256
2d120f83
JS
257 XtVaSetValues((Widget) m_frameWidget,
258 XmNworkWindow, (Widget) m_workArea,
259 NULL);
dfe1eee3 260
2d120f83
JS
261 XtManageChild((Widget) m_clientArea);
262 XtManageChild((Widget) m_workArea);
dfe1eee3 263
2d120f83 264 wxAddWindowToTable((Widget) m_workArea, this);
dc1efb1d 265 wxAddWindowToTable((Widget) m_clientArea, this);
dfe1eee3 266
1c4f8f8d 267 XtTranslations ptr;
dfe1eee3 268
2d120f83
JS
269 XtOverrideTranslations((Widget) m_workArea,
270 ptr = XtParseTranslationTable("<Configure>: resize()"));
dfe1eee3 271
2d120f83 272 XtFree((char *)ptr);
dfe1eee3
VZ
273
274 XtAddCallback((Widget) m_workArea, XmNfocusCallback,
2d120f83 275 (XtCallbackProc)wxFrameFocusProc, (XtPointer)this);
dfe1eee3 276
2d120f83
JS
277 /* Part of show-&-hide fix */
278 XtAddEventHandler((Widget) m_frameShell, StructureNotifyMask,
279 False, (XtEventHandler)wxFrameMapProc,
280 (XtPointer)m_workArea);
dfe1eee3 281
2d120f83
JS
282 if (x > -1)
283 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
284 if (y > -1)
285 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
286 if (width > -1)
287 XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL);
288 if (height > -1)
289 XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
dfe1eee3 290
2d120f83 291 m_mainWidget = m_frameWidget;
dfe1eee3 292
2d120f83 293 ChangeFont(FALSE);
dfe1eee3 294
2d120f83
JS
295 // This patch comes from Torsten Liermann lier@lier1.muc.de
296 if (XmIsMotifWMRunning( (Widget) m_frameShell ))
297 {
1c4f8f8d 298 int decor = 0;
2d120f83 299 if (style & wxRESIZE_BORDER)
1c4f8f8d 300 decor |= MWM_DECOR_RESIZEH;
2d120f83
JS
301 if (style & wxSYSTEM_MENU)
302 decor |= MWM_DECOR_MENU;
303 if ((style & wxCAPTION) ||
304 (style & wxTINY_CAPTION_HORIZ) ||
305 (style & wxTINY_CAPTION_VERT))
306 decor |= MWM_DECOR_TITLE;
307 if (style & wxTHICK_FRAME)
308 decor |= MWM_DECOR_BORDER;
2d120f83
JS
309 if (style & wxMINIMIZE_BOX)
310 decor |= MWM_DECOR_MINIMIZE;
311 if (style & wxMAXIMIZE_BOX)
312 decor |= MWM_DECOR_MAXIMIZE;
1c4f8f8d 313 XtVaSetValues((Widget) m_frameShell,XmNmwmDecorations,decor,NULL);
2d120f83
JS
314 }
315 // This allows non-Motif window managers to support at least the
316 // no-decorations case.
317 else
318 {
319 if (style == 0)
320 XtVaSetValues((Widget) m_frameShell,XmNoverrideRedirect,TRUE,NULL);
321 }
322 XtRealizeWidget((Widget) m_frameShell);
dfe1eee3 323
2d120f83
JS
324 // Intercept CLOSE messages from the window manager
325 Atom WM_DELETE_WINDOW = XmInternAtom(XtDisplay((Widget) m_frameShell), "WM_DELETE_WINDOW", False);
4bb6408c 326#if (XmREVISION > 1 || XmVERSION > 1)
2d120f83 327 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (XtPointer)this);
4bb6408c
JS
328#else
329#if XmREVISION == 1
2d120f83 330 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (XtCallbackProc) wxCloseFrameCallback, (caddr_t)this);
4bb6408c 331#else
2d120f83 332 XmAddWMProtocolCallback((Widget) m_frameShell, WM_DELETE_WINDOW, (void (*)())wxCloseFrameCallback, (caddr_t)this);
4bb6408c
JS
333#endif
334#endif
dfe1eee3 335
2d120f83 336 ChangeBackgroundColour();
dfe1eee3 337
2d120f83 338 PreResize();
dfe1eee3 339
2d120f83
JS
340 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
341 sizeEvent.SetEventObject(this);
dfe1eee3 342
2d120f83 343 GetEventHandler()->ProcessEvent(sizeEvent);
dfe1eee3 344
2d120f83 345 return TRUE;
4bb6408c
JS
346}
347
348wxFrame::~wxFrame()
349{
3ab377bd 350 m_isBeingDeleted = TRUE;
da8bed9b 351
2e35f56f 352 if (m_clientArea)
dc1efb1d 353 {
2e35f56f
JS
354 XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, FALSE,
355 wxUniversalRepaintProc, (XtPointer) this);
dc1efb1d
JS
356 XtRemoveEventHandler((Widget) m_clientArea, ButtonPressMask | ButtonReleaseMask | PointerMotionMask | KeyPressMask,
357 FALSE,
358 wxFrameEventHandler, (XtPointer) this);
359 wxDeleteWindowFromTable((Widget) m_clientArea);
360 }
2e35f56f 361
2d120f83
JS
362 if (GetMainWidget())
363 Show(FALSE);
0492c5a0 364
2d120f83
JS
365 if (m_frameMenuBar)
366 {
367 m_frameMenuBar->DestroyMenuBar();
dfe1eee3 368
2d120f83 369 // Hack to stop core dump on Ultrix, OSF, for some strange reason.
4bb6408c 370#if MOTIF_MENUBAR_DELETE_FIX
2d120f83 371 GetMenuBar()->SetMainWidget((WXWidget) NULL);
4bb6408c 372#endif
2d120f83
JS
373 delete m_frameMenuBar;
374 m_frameMenuBar = NULL;
375 }
dfe1eee3 376
2d120f83
JS
377 wxTopLevelWindows.DeleteObject(this);
378 wxModelessWindows.DeleteObject(this);
dfe1eee3 379
2d120f83 380 if (m_frameStatusBar)
1c4f8f8d 381 {
2d120f83 382 delete m_frameStatusBar;
1c4f8f8d
VZ
383 m_frameStatusBar = NULL;
384 }
dfe1eee3 385
2d120f83 386 DestroyChildren();
dfe1eee3 387
2d120f83 388 if (m_workArea)
4bb6408c 389 {
2d120f83 390 wxDeleteWindowFromTable((Widget) m_workArea);
dfe1eee3 391
2d120f83 392 XtDestroyWidget ((Widget) m_workArea);
4bb6408c 393 }
dfe1eee3 394
2d120f83
JS
395 if (m_frameWidget)
396 {
397 wxDeleteWindowFromTable((Widget) m_frameWidget);
398 XtDestroyWidget ((Widget) m_frameWidget);
399 }
dfe1eee3 400
2d120f83
JS
401 if (m_frameShell)
402 XtDestroyWidget ((Widget) m_frameShell);
dfe1eee3 403
2d120f83 404 SetMainWidget((WXWidget) NULL);
dfe1eee3 405
2d120f83 406 /* Check if it's the last top-level window */
dfe1eee3 407
2d120f83
JS
408 if (wxTheApp && (wxTopLevelWindows.Number() == 0))
409 {
410 wxTheApp->SetTopWindow(NULL);
dfe1eee3 411
2d120f83
JS
412 if (wxTheApp->GetExitOnFrameDelete())
413 {
414 // Signal to the app that we're going to close
415 wxTheApp->ExitMainLoop();
416 }
417 }
4bb6408c
JS
418}
419
420// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
449f38b5 421void wxFrame::DoGetClientSize(int *x, int *y) const
4bb6408c 422{
2d120f83
JS
423 Dimension xx, yy;
424 XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL);
dfe1eee3 425
2d120f83
JS
426 if (m_frameStatusBar)
427 {
428 int sbw, sbh;
429 m_frameStatusBar->GetSize(& sbw, & sbh);
430 yy -= sbh;
431 }
1ccbb61a 432#if wxUSE_TOOLBAR
2d120f83
JS
433 if (m_frameToolBar)
434 {
435 int tbw, tbh;
436 m_frameToolBar->GetSize(& tbw, & tbh);
437 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
438 xx -= tbw;
439 else
440 yy -= tbh;
441 }
1ccbb61a 442#endif // wxUSE_TOOLBAR
2d120f83
JS
443 /*
444 if (GetMenuBar() != (wxMenuBar*) NULL)
445 {
4bb6408c
JS
446 // it seems that if a frame holds a panel, the menu bar size
447 // gets automatically taken care of --- grano@cs.helsinki.fi 4.4.95
448 bool hasSubPanel = FALSE;
c0ed460c 449 for(wxNode* node = GetChildren().First(); node; node = node->Next())
4bb6408c 450 {
2d120f83
JS
451 wxWindow *win = (wxWindow *)node->Data();
452 hasSubPanel = (win->IsKindOf(CLASSINFO(wxPanel)) && !win->IsKindOf(CLASSINFO(wxDialog)));
dfe1eee3 453
4bb6408c 454 if (hasSubPanel)
2d120f83
JS
455 break;
456 }
457 if (! hasSubPanel) {
4bb6408c
JS
458 Dimension ys;
459 XtVaGetValues((Widget) GetMenuBarWidget(), XmNheight, &ys, NULL);
460 yy -= ys;
2d120f83
JS
461 }
462 }
463 */
dfe1eee3 464
2d120f83 465 *x = xx; *y = yy;
4bb6408c
JS
466}
467
468// Set the client size (i.e. leave the calculation of borders etc.
469// to wxWindows)
bfc6fde4 470void wxFrame::DoSetClientSize(int width, int height)
4bb6408c 471{
2d120f83
JS
472 // Calculate how large the new main window should be
473 // by finding the difference between the client area and the
474 // main window area, and adding on to the new client area
475 if (width > -1)
476 XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL);
dfe1eee3 477
2d120f83 478 if (height > -1)
a4294b78 479 {
2d120f83
JS
480 if (m_frameStatusBar)
481 {
482 int sbw, sbh;
483 m_frameStatusBar->GetSize(& sbw, & sbh);
484 height += sbh;
485 }
1ccbb61a 486#if wxUSE_TOOLBAR
2d120f83
JS
487 if (m_frameToolBar)
488 {
489 int tbw, tbh;
490 m_frameToolBar->GetSize(& tbw, & tbh);
491 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
492 width += tbw;
493 else
494 height += tbh;
495 }
1ccbb61a 496#endif // wxUSE_TOOLBAR
dfe1eee3 497
2d120f83 498 XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL);
a4294b78 499 }
2d120f83 500 PreResize();
dfe1eee3 501
2d120f83
JS
502 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
503 sizeEvent.SetEventObject(this);
dfe1eee3 504
2d120f83 505 GetEventHandler()->ProcessEvent(sizeEvent);
dfe1eee3 506
4bb6408c
JS
507}
508
449f38b5 509void wxFrame::DoGetSize(int *width, int *height) const
4bb6408c 510{
2d120f83
JS
511 Dimension xx, yy;
512 XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
513 *width = xx; *height = yy;
4bb6408c
JS
514}
515
449f38b5 516void wxFrame::DoGetPosition(int *x, int *y) const
4bb6408c
JS
517{
518 Window parent_window = XtWindow((Widget) m_frameShell),
2d120f83
JS
519 next_parent = XtWindow((Widget) m_frameShell),
520 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
dfe1eee3 521
4bb6408c
JS
522 // search for the parent that is child of ROOT, because the WM may
523 // reparent twice and notify only the next parent (like FVWM)
524 while (next_parent != root) {
2d120f83
JS
525 Window *theChildren; unsigned int n;
526 parent_window = next_parent;
527 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
528 &next_parent, &theChildren, &n);
529 XFree(theChildren); // not needed
4bb6408c
JS
530 }
531 int xx, yy; unsigned int dummy;
532 XGetGeometry(XtDisplay((Widget) m_frameShell), parent_window, &root,
2d120f83 533 &xx, &yy, &dummy, &dummy, &dummy, &dummy);
4bb6408c
JS
534 if (x) *x = xx;
535 if (y) *y = yy;
536}
537
af111fc3 538void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags))
4bb6408c 539{
2d120f83
JS
540 if (x > -1)
541 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
542 if (y > -1)
543 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
544 if (width > -1)
545 XtVaSetValues((Widget) m_frameWidget, XmNwidth, width, NULL);
546 if (height > -1)
547 XtVaSetValues((Widget) m_frameWidget, XmNheight, height, NULL);
dfe1eee3 548
2d120f83
JS
549 if (!(height == -1 && width == -1))
550 {
551 PreResize();
dfe1eee3 552
2d120f83
JS
553 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
554 sizeEvent.SetEventObject(this);
dfe1eee3 555
2d120f83
JS
556 GetEventHandler()->ProcessEvent(sizeEvent);
557 }
4bb6408c
JS
558}
559
560bool wxFrame::Show(bool show)
561{
2d120f83
JS
562 if (!m_frameShell)
563 return wxWindow::Show(show);
dfe1eee3 564
2d120f83 565 m_visibleStatus = show; /* show-&-hide fix */
dfe1eee3 566
2d120f83
JS
567 m_isShown = show;
568 if (show) {
569 XtMapWidget((Widget) m_frameShell);
570 XRaiseWindow(XtDisplay((Widget) m_frameShell), XtWindow((Widget) m_frameShell));
571 } else {
572 XtUnmapWidget((Widget) m_frameShell);
573 // XmUpdateDisplay(wxTheApp->topLevel); // Experimental: may be responsible for crashes
574 }
575 return TRUE;
4bb6408c
JS
576}
577
578void wxFrame::Iconize(bool iconize)
579{
2d120f83
JS
580 if (!iconize)
581 Show(TRUE);
dfe1eee3 582
2d120f83
JS
583 if (m_frameShell)
584 XtVaSetValues((Widget) m_frameShell, XmNiconic, (Boolean)iconize, NULL);
4bb6408c
JS
585}
586
1c4f8f8d
VZ
587void wxFrame::Restore()
588{
589 if ( m_frameShell )
590 XtVaSetValues((Widget) m_frameShell, XmNiconic, FALSE, NULL);
591}
592
4bb6408c
JS
593void wxFrame::Maximize(bool maximize)
594{
2d120f83 595 Show(TRUE);
dfe1eee3 596
1c4f8f8d
VZ
597 if ( maximize )
598 Restore();
4bb6408c
JS
599}
600
601bool wxFrame::IsIconized() const
602{
2d120f83
JS
603 if (!m_frameShell)
604 return FALSE;
dfe1eee3 605
2d120f83
JS
606 Boolean iconic;
607 XtVaGetValues((Widget) m_frameShell, XmNiconic, &iconic, NULL);
608 return iconic;
4bb6408c
JS
609}
610
6f63ec3f 611// Is it maximized?
1c4f8f8d 612bool wxFrame::IsMaximized() const
6f63ec3f
JS
613{
614 // No maximizing in Motif (?)
615 return FALSE;
616}
617
4bb6408c
JS
618void wxFrame::SetTitle(const wxString& title)
619{
2d120f83
JS
620 if (title == m_title)
621 return;
dfe1eee3 622
2d120f83 623 m_title = title;
dfe1eee3 624
2d120f83 625 if (!title.IsNull())
dfe1eee3 626 XtVaSetValues((Widget) m_frameShell,
1c4f8f8d
VZ
627 XmNtitle, title.c_str(),
628 XmNiconName, title.c_str(),
2d120f83 629 NULL);
4bb6408c
JS
630}
631
f618020a 632void wxFrame::DoSetIcon(const wxIcon& icon)
4bb6408c 633{
2d120f83
JS
634 if (!m_frameShell)
635 return;
dfe1eee3 636
2d120f83
JS
637 if (!icon.Ok() || !icon.GetPixmap())
638 return;
dfe1eee3 639
2d120f83 640 XtVaSetValues((Widget) m_frameShell, XtNiconPixmap, icon.GetPixmap(), NULL);
4bb6408c
JS
641}
642
f618020a
MB
643void wxFrame::SetIcon(const wxIcon& icon)
644{
645 SetIcons( wxIconBundle( icon ) );
646}
647
648void wxFrame::SetIcons(const wxIconBundle& icons)
649{
650 wxFrameBase::SetIcons( icons );
651
652 if (!m_frameShell)
653 return;
654
655 DoSetIcon( m_icons.GetIcon( -1 ) );
656 wxSetIconsX11(GetXDisplay(),
657 (WXWindow) XtWindow( (Widget) m_frameShell ), icons);
658}
659
4bb6408c
JS
660void wxFrame::PositionStatusBar()
661{
50414e24 662 if (!m_frameStatusBar)
2d120f83 663 return;
dfe1eee3 664
4bb6408c
JS
665 int w, h;
666 GetClientSize(&w, &h);
667 int sw, sh;
668 m_frameStatusBar->GetSize(&sw, &sh);
dfe1eee3 669
4bb6408c
JS
670 // Since we wish the status bar to be directly under the client area,
671 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
89c7e962 672 m_frameStatusBar->SetSize(0, h, w, sh);
4bb6408c
JS
673}
674
675WXWidget wxFrame::GetMenuBarWidget() const
676{
2d120f83
JS
677 if (GetMenuBar())
678 return GetMenuBar()->GetMainWidget();
679 else
680 return (WXWidget) NULL;
4bb6408c
JS
681}
682
683void wxFrame::SetMenuBar(wxMenuBar *menuBar)
684{
685 if (!menuBar)
686 {
687 m_frameMenuBar = NULL;
688 return;
689 }
dfe1eee3 690
4bb6408c 691 // Currently can't set it twice
2d120f83 692 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
dfe1eee3 693
621793f4 694 if (m_frameMenuBar)
4bb6408c 695 {
621793f4
JS
696 m_frameMenuBar->DestroyMenuBar();
697 delete m_frameMenuBar;
4bb6408c 698 }
dfe1eee3 699
621793f4
JS
700 m_frameMenuBar = menuBar;
701 m_frameMenuBar->CreateMenuBar(this);
4bb6408c
JS
702}
703
4bb6408c
JS
704// Responds to colour changes, and passes event on to children.
705void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
706{
a756f210 707 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
4bb6408c 708 Refresh();
dfe1eee3 709
4bb6408c
JS
710 if ( m_frameStatusBar )
711 {
712 wxSysColourChangedEvent event2;
713 event2.SetEventObject( m_frameStatusBar );
714 m_frameStatusBar->ProcessEvent(event2);
715 }
dfe1eee3 716
4bb6408c
JS
717 // Propagate the event to the non-top-level children
718 wxWindow::OnSysColourChanged(event);
719}
720
4bb6408c
JS
721// Default activation behaviour - set the focus for the first child
722// subwindow found.
723void wxFrame::OnActivate(wxActivateEvent& event)
724{
af111fc3
JS
725 if (!event.GetActive())
726 return;
727
2d120f83 728 for(wxNode *node = GetChildren().First(); node; node = node->Next())
4bb6408c 729 {
2d120f83
JS
730 // Find a child that's a subwindow, but not a dialog box.
731 wxWindow *child = (wxWindow *)node->Data();
732 if (!child->IsKindOf(CLASSINFO(wxFrame)) &&
733 !child->IsKindOf(CLASSINFO(wxDialog)))
734 {
735 child->SetFocus();
736 return;
737 }
4bb6408c 738 }
4bb6408c
JS
739}
740
1ccbb61a 741#if wxUSE_TOOLBAR
dfe1eee3 742
1c4f8f8d
VZ
743wxToolBar* wxFrame::CreateToolBar(long style,
744 wxWindowID id,
745 const wxString& name)
4bb6408c 746{
1c4f8f8d 747 if ( wxFrameBase::CreateToolBar(style, id, name) )
4bb6408c 748 {
4bb6408c 749 PositionToolBar();
4bb6408c 750 }
4bb6408c 751
1ccbb61a
VZ
752 return m_frameToolBar;
753}
754
4bb6408c
JS
755void wxFrame::PositionToolBar()
756{
4bb6408c
JS
757 if (GetToolBar())
758 {
1c4f8f8d
VZ
759 int cw, ch;
760 GetClientSize(& cw, &ch);
761
4bb6408c
JS
762 int tw, th;
763 GetToolBar()->GetSize(& tw, & th);
dfe1eee3 764
4bb6408c
JS
765 if (GetToolBar()->GetWindowStyleFlag() & wxTB_VERTICAL)
766 {
767 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
768 // means, pretend we don't have toolbar/status bar, so we
769 // have the original client size.
a4294b78 770 GetToolBar()->SetSize(0, 0, tw, ch + th, wxSIZE_NO_ADJUSTMENTS);
4bb6408c
JS
771 }
772 else
773 {
774 // Use the 'real' position
775 GetToolBar()->SetSize(0, 0, cw, th, wxSIZE_NO_ADJUSTMENTS);
776 }
777 }
778}
1ccbb61a 779#endif // wxUSE_TOOLBAR
4bb6408c 780
1c4f8f8d 781void wxFrame::Raise()
4bb6408c
JS
782{
783 Window parent_window = XtWindow((Widget) m_frameShell),
2d120f83
JS
784 next_parent = XtWindow((Widget) m_frameShell),
785 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
4bb6408c
JS
786 // search for the parent that is child of ROOT, because the WM may
787 // reparent twice and notify only the next parent (like FVWM)
788 while (next_parent != root) {
2d120f83
JS
789 Window *theChildren; unsigned int n;
790 parent_window = next_parent;
791 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
792 &next_parent, &theChildren, &n);
793 XFree(theChildren); // not needed
4bb6408c
JS
794 }
795 XRaiseWindow(XtDisplay((Widget) m_frameShell), parent_window);
796}
797
1c4f8f8d 798void wxFrame::Lower()
4bb6408c
JS
799{
800 Window parent_window = XtWindow((Widget) m_frameShell),
2d120f83
JS
801 next_parent = XtWindow((Widget) m_frameShell),
802 root = RootWindowOfScreen(XtScreen((Widget) m_frameShell));
4bb6408c
JS
803 // search for the parent that is child of ROOT, because the WM may
804 // reparent twice and notify only the next parent (like FVWM)
805 while (next_parent != root) {
2d120f83
JS
806 Window *theChildren; unsigned int n;
807 parent_window = next_parent;
808 XQueryTree(XtDisplay((Widget) m_frameShell), parent_window, &root,
809 &next_parent, &theChildren, &n);
810 XFree(theChildren); // not needed
4bb6408c
JS
811 }
812 XLowerWindow(XtDisplay((Widget) m_frameShell), parent_window);
813}
814
af111fc3
JS
815void wxFrameFocusProc(Widget WXUNUSED(workArea), XtPointer WXUNUSED(clientData),
816 XmAnyCallbackStruct *WXUNUSED(cbs))
4bb6408c 817{
2d120f83
JS
818 // wxDebugMsg("focus proc from frame %ld\n",(long)frame);
819 // TODO
dfe1eee3
VZ
820 // wxFrame *frame = (wxFrame *)clientData;
821 // frame->GetEventHandler()->OnSetFocus();
4bb6408c
JS
822}
823
824/* MATTEW: Used to insure that hide-&-show within an event cycle works */
dfe1eee3 825static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
2d120f83 826 XCrossingEvent * event)
4bb6408c 827{
dfe1eee3
VZ
828 wxFrame *frame = (wxFrame *)wxGetWindowFromTable((Widget)clientData);
829
2d120f83
JS
830 if (frame) {
831 XEvent *e = (XEvent *)event;
dfe1eee3 832
2d120f83
JS
833 if (e->xany.type == MapNotify)
834 {
835 // Iconize fix
836 XtVaSetValues(frameShell, XmNiconic, (Boolean)False, NULL);
837 if (!frame->GetVisibleStatus())
838 {
839 /* We really wanted this to be hidden! */
840 XtUnmapWidget((Widget) frame->GetShellWidget());
841 }
842 }
843 else if (e->xany.type == UnmapNotify)
844 // Iconize fix
845 XtVaSetValues(frameShell, XmNiconic, (Boolean)True, NULL);
4bb6408c 846 }
4bb6408c
JS
847}
848
849//// Motif-specific
850bool wxFrame::PreResize()
851{
1ccbb61a 852#if wxUSE_TOOLBAR
2d120f83 853 PositionToolBar();
1ccbb61a 854#endif // wxUSE_TOOLBAR
1c4f8f8d
VZ
855
856#if wxUSE_STATUSBAR
2d120f83 857 PositionStatusBar();
1c4f8f8d
VZ
858#endif // wxUSE_STATUSBAR
859
2d120f83 860 return TRUE;
4bb6408c
JS
861}
862
50414e24
JS
863WXWidget wxFrame::GetClientWidget() const
864{
2d120f83 865 return m_clientArea;
50414e24
JS
866}
867
af111fc3 868void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize))
0d57be45
JS
869{
870 // TODO
871}
872
873void wxFrame::ChangeBackgroundColour()
874{
621793f4
JS
875 if (GetClientWidget())
876 DoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
0d57be45
JS
877}
878
879void wxFrame::ChangeForegroundColour()
880{
621793f4
JS
881 if (GetClientWidget())
882 DoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
0d57be45
JS
883}
884
af111fc3 885void wxCloseFrameCallback(Widget WXUNUSED(widget), XtPointer client_data, XmAnyCallbackStruct *WXUNUSED(cbs))
4bb6408c 886{
2d120f83 887 wxFrame *frame = (wxFrame *)client_data;
dfe1eee3 888
2d120f83
JS
889 wxCloseEvent closeEvent(wxEVT_CLOSE_WINDOW, frame->GetId());
890 closeEvent.SetEventObject(frame);
dfe1eee3 891
2d120f83
JS
892 // May delete the frame (with delayed deletion)
893 frame->GetEventHandler()->ProcessEvent(closeEvent);
4bb6408c 894}
0d57be45 895
dc1efb1d
JS
896static void wxFrameEventHandler(Widget wid,
897 XtPointer WXUNUSED(client_data),
898 XEvent* event,
899 Boolean* continueToDispatch)
900{
901 wxFrame *frame = (wxFrame *)wxGetWindowFromTable(wid);
902 if (frame)
903 {
904 wxMouseEvent wxevent(wxEVT_NULL);
905 if (wxTranslateMouseEvent(wxevent, frame, wid, event))
906 {
907 wxevent.SetEventObject(frame);
908 wxevent.SetId(frame->GetId());
909 frame->GetEventHandler()->ProcessEvent(wxevent);
910 }
911 else
912 {
913 // An attempt to implement OnCharHook by calling OnCharHook first;
914 // if this returns TRUE, set continueToDispatch to False
915 // (don't continue processing).
916 // Otherwise set it to True and call OnChar.
917 wxKeyEvent keyEvent(wxEVT_CHAR);
918 if (wxTranslateKeyEvent(keyEvent, frame, wid, event))
919 {
920 keyEvent.SetEventObject(frame);
921 keyEvent.SetId(frame->GetId());
922 keyEvent.SetEventType(wxEVT_CHAR_HOOK);
923 if (frame->GetEventHandler()->ProcessEvent(keyEvent))
924 {
925 *continueToDispatch = False;
926 return;
927 }
928 else
929 {
930 // For simplicity, OnKeyDown is the same as OnChar
931 // TODO: filter modifier key presses from OnChar
932 keyEvent.SetEventType(wxEVT_KEY_DOWN);
933
934 // Only process OnChar if OnKeyDown didn't swallow it
935 if (!frame->GetEventHandler()->ProcessEvent (keyEvent))
936 {
937 keyEvent.SetEventType(wxEVT_CHAR);
938 frame->GetEventHandler()->ProcessEvent(keyEvent);
939 }
940 }
941 }
942 }
943 }
944 *continueToDispatch = True;
945}