]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/motif/frame.cpp
added pragmas to disable icc warning when va_arg is used with a pointer type
[wxWidgets.git] / src / motif / frame.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: motif/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// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __VMS
24#define XtDisplay XTDISPLAY
25#define XtWindow XTWINDOW
26#define XtScreen XTSCREEN
27#endif
28
29#include "wx/frame.h"
30#include "wx/statusbr.h"
31#include "wx/toolbar.h"
32#include "wx/menu.h"
33#include "wx/settings.h"
34#include "wx/utils.h"
35#include "wx/log.h"
36#include "wx/app.h"
37#include "wx/icon.h"
38
39#ifdef __VMS__
40 #pragma message disable nosimpint
41#endif
42
43#if defined(__ultrix) || defined(__sgi)
44 #include <Xm/Frame.h>
45#endif
46
47#include <Xm/Xm.h>
48#include <X11/Shell.h>
49#include <X11/Core.h>
50#if XmVersion >= 1002
51 #include <Xm/XmAll.h>
52#else
53 #include <Xm/Frame.h>
54#endif
55#include <Xm/MwmUtil.h>
56#include <Xm/BulletinB.h>
57#include <Xm/Form.h>
58#include <Xm/MainW.h>
59#include <Xm/RowColumn.h>
60#include <Xm/Label.h>
61#include <Xm/AtomMgr.h>
62#include <Xm/LabelG.h>
63#include <Xm/Frame.h>
64#if XmVersion > 1000
65 #include <Xm/Protocols.h>
66#endif
67
68#ifdef __VMS__
69 #pragma message enable nosimpint
70#endif
71
72#include "wx/motif/private.h"
73#include "wx/unix/utilsx11.h"
74
75// ----------------------------------------------------------------------------
76// private functions
77// ----------------------------------------------------------------------------
78
79static void wxFrameMapProc(Widget frameShell, XtPointer clientData,
80 XCrossingEvent* event);
81
82// ----------------------------------------------------------------------------
83// globals
84// ----------------------------------------------------------------------------
85
86extern wxList wxModelessWindows;
87extern wxList wxPendingDelete;
88
89// ----------------------------------------------------------------------------
90// wxWin macros
91// ----------------------------------------------------------------------------
92
93BEGIN_EVENT_TABLE(wxFrame, wxFrameBase)
94 EVT_ACTIVATE(wxFrame::OnActivate)
95 EVT_SYS_COLOUR_CHANGED(wxFrame::OnSysColourChanged)
96END_EVENT_TABLE()
97
98IMPLEMENT_DYNAMIC_CLASS(wxFrame, wxTopLevelWindow)
99
100// ============================================================================
101// implementation
102// ============================================================================
103
104// ----------------------------------------------------------------------------
105// frame construction
106// ----------------------------------------------------------------------------
107
108void wxFrame::Init()
109{
110 m_iconized = false;
111
112 //// Motif-specific
113 m_frameShell = (WXWidget) NULL;
114 m_mainWidget = (WXWidget) NULL;
115 m_workArea = (WXWidget) NULL;
116 m_clientArea = (WXWidget) NULL;
117}
118
119bool wxFrame::Create(wxWindow *parent,
120 wxWindowID id,
121 const wxString& title,
122 const wxPoint& pos,
123 const wxSize& size,
124 long style,
125 const wxString& name)
126{
127 if( !wxTopLevelWindow::Create( parent, id, title, pos, size, style,
128 name ) )
129 return false;
130
131 m_backgroundColour =
132 wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE);
133 m_foregroundColour = *wxBLACK;
134 m_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
135
136 int x = pos.x, y = pos.y;
137 int width = size.x, height = size.y;
138
139 // Set reasonable values for position and size if defaults have been
140 // requested
141 //
142 // MB TODO: something better than these arbitrary values ?
143 // VZ should use X resources for this...
144 if ( width == -1 )
145 width = 400;
146 if ( height == -1 )
147 height = 400;
148
149 int displayW, displayH;
150 wxDisplaySize( &displayW, &displayH );
151
152 if ( x == -1 )
153 {
154 x = (displayW - width) / 2;
155 if (x < 10) x = 10;
156 }
157 if ( y == -1 )
158 {
159 y = (displayH - height) / 2;
160 if (y < 10) y = 10;
161 }
162
163 SetTitle( title );
164
165 wxLogTrace(wxTRACE_Messages,
166 "Created frame (0x%p) with work area 0x%p and client "
167 "area 0x%p", m_mainWidget, m_workArea, m_clientArea);
168
169 XtAddEventHandler((Widget) m_clientArea, ExposureMask,False,
170 wxUniversalRepaintProc, (XtPointer) this);
171
172 if (x > -1)
173 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
174 if (y > -1)
175 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
176 if (width > -1)
177 XtVaSetValues((Widget) m_frameShell, XmNwidth, width, NULL);
178 if (height > -1)
179 XtVaSetValues((Widget) m_frameShell, XmNheight, height, NULL);
180
181 ChangeFont(false);
182
183 ChangeBackgroundColour();
184
185 PreResize();
186
187 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
188 sizeEvent.SetEventObject(this);
189
190 GetEventHandler()->ProcessEvent(sizeEvent);
191
192 return true;
193}
194
195bool wxFrame::XmDoCreateTLW(wxWindow* parent,
196 wxWindowID id,
197 const wxString& title,
198 const wxPoint& pos,
199 const wxSize& size,
200 long style,
201 const wxString& name)
202{
203 Widget frameShell;
204
205 frameShell = XtCreatePopupShell( name, topLevelShellWidgetClass,
206 (Widget)wxTheApp->GetTopLevelWidget(),
207 NULL, 0 );
208
209 XtVaSetValues(frameShell,
210 // Allows menu to resize
211 XmNallowShellResize, True,
212 XmNdeleteResponse, XmDO_NOTHING,
213 XmNmappedWhenManaged, False,
214 XmNiconic, (style & wxICONIZE) ? True : False,
215 NULL);
216
217 m_frameShell = (WXWidget)frameShell;
218
219 m_mainWidget = (WXWidget) XtVaCreateManagedWidget("main_window",
220 xmMainWindowWidgetClass, frameShell,
221 XmNresizePolicy, XmRESIZE_NONE,
222 NULL);
223
224 m_workArea = (WXWidget) XtVaCreateWidget("form",
225 xmFormWidgetClass, (Widget) m_mainWidget,
226 XmNresizePolicy, XmRESIZE_NONE,
227 NULL);
228
229 m_clientArea = (WXWidget) XtVaCreateWidget("client",
230 xmBulletinBoardWidgetClass, (Widget) m_workArea,
231 XmNmarginWidth, 0,
232 XmNmarginHeight, 0,
233 XmNrightAttachment, XmATTACH_FORM,
234 XmNleftAttachment, XmATTACH_FORM,
235 XmNtopAttachment, XmATTACH_FORM,
236 XmNbottomAttachment, XmATTACH_FORM,
237 NULL);
238
239 XtVaSetValues((Widget) m_mainWidget,
240 XmNworkWindow, (Widget) m_workArea,
241 NULL);
242
243 XtManageChild((Widget) m_clientArea);
244 XtManageChild((Widget) m_workArea);
245
246 XtTranslations ptr = XtParseTranslationTable( "<Configure>: resize()" );
247 XtOverrideTranslations( (Widget) m_workArea, ptr );
248 XtFree( (char *)ptr );
249
250 /* Part of show-&-hide fix */
251 XtAddEventHandler( frameShell, StructureNotifyMask,
252 False, (XtEventHandler)wxFrameMapProc,
253 (XtPointer)this );
254
255 XtRealizeWidget(frameShell);
256
257 wxAddWindowToTable( (Widget)m_workArea, this);
258 wxAddWindowToTable( (Widget)m_clientArea, this);
259
260 wxModelessWindows.Append( this );
261
262 return true;
263}
264
265wxFrame::~wxFrame()
266{
267 m_isBeingDeleted = true;
268
269 if (m_clientArea)
270 {
271 XtRemoveEventHandler((Widget) m_clientArea, ExposureMask, False,
272 wxUniversalRepaintProc, (XtPointer) this);
273 }
274
275 if (GetMainWidget())
276 Show(false);
277
278 if (m_frameMenuBar)
279 {
280 m_frameMenuBar->DestroyMenuBar();
281 delete m_frameMenuBar;
282 m_frameMenuBar = NULL;
283 }
284
285 if (m_frameStatusBar)
286 {
287 delete m_frameStatusBar;
288 m_frameStatusBar = NULL;
289 }
290
291 PreDestroy();
292
293 Widget frameShell = (Widget)GetShellWidget();
294
295 if( frameShell )
296 XtRemoveEventHandler( frameShell, StructureNotifyMask,
297 False, (XtEventHandler)wxFrameMapProc,
298 (XtPointer)this );
299
300 if( m_clientArea )
301 {
302 wxDeleteWindowFromTable( (Widget)m_clientArea );
303 XtDestroyWidget( (Widget)m_clientArea );
304 }
305
306 if( m_workArea )
307 {
308 XtVaSetValues( (Widget)m_mainWidget,
309 XmNworkWindow, (Widget)NULL,
310 NULL );
311
312 wxDeleteWindowFromTable( (Widget)m_workArea );
313 XtDestroyWidget( (Widget)m_workArea );
314 }
315
316 if( m_mainWidget )
317 XtDestroyWidget( (Widget)m_mainWidget );
318
319 if( frameShell )
320 XtDestroyWidget( frameShell );
321}
322
323// Get size *available for subwindows* i.e. excluding menu bar, toolbar etc.
324void wxFrame::DoGetClientSize(int *x, int *y) const
325{
326 Dimension xx, yy;
327 XtVaGetValues((Widget) m_workArea, XmNwidth, &xx, XmNheight, &yy, NULL);
328
329 if (m_frameStatusBar)
330 {
331 int sbw, sbh;
332 m_frameStatusBar->GetSize(& sbw, & sbh);
333 yy -= sbh;
334 }
335#if wxUSE_TOOLBAR
336 if (m_frameToolBar)
337 {
338 int tbw, tbh;
339 m_frameToolBar->GetSize(& tbw, & tbh);
340 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
341 xx -= tbw;
342 else
343 yy -= tbh;
344 }
345#endif // wxUSE_TOOLBAR
346
347//CE found a call here with NULL y pointer
348 if (x)
349 *x = xx;
350 if (y)
351 *y = yy;
352}
353
354// Set the client size (i.e. leave the calculation of borders etc.
355// to wxWidgets)
356void wxFrame::DoSetClientSize(int width, int height)
357{
358 // Calculate how large the new main window should be
359 // by finding the difference between the client area and the
360 // main window area, and adding on to the new client area
361 if (width > -1)
362 XtVaSetValues((Widget) m_workArea, XmNwidth, width, NULL);
363
364 if (height > -1)
365 {
366 if (m_frameStatusBar)
367 {
368 int sbw, sbh;
369 m_frameStatusBar->GetSize(& sbw, & sbh);
370 height += sbh;
371 }
372#if wxUSE_TOOLBAR
373 if (m_frameToolBar)
374 {
375 int tbw, tbh;
376 m_frameToolBar->GetSize(& tbw, & tbh);
377 if (m_frameToolBar->GetWindowStyleFlag() & wxTB_VERTICAL)
378 width += tbw;
379 else
380 height += tbh;
381 }
382#endif // wxUSE_TOOLBAR
383
384 XtVaSetValues((Widget) m_workArea, XmNheight, height, NULL);
385 }
386 PreResize();
387
388 wxSizeEvent sizeEvent(wxSize(width, height), GetId());
389 sizeEvent.SetEventObject(this);
390
391 GetEventHandler()->ProcessEvent(sizeEvent);
392
393}
394
395void wxFrame::DoGetSize(int *width, int *height) const
396{
397 Dimension xx, yy;
398 XtVaGetValues((Widget) m_frameShell, XmNwidth, &xx, XmNheight, &yy, NULL);
399 *width = xx; *height = yy;
400}
401
402void wxFrame::DoSetSize(int x, int y, int width, int height, int WXUNUSED(sizeFlags))
403{
404 if (x > -1)
405 XtVaSetValues((Widget) m_frameShell, XmNx, x, NULL);
406 if (y > -1)
407 XtVaSetValues((Widget) m_frameShell, XmNy, y, NULL);
408 if (width > -1)
409 XtVaSetValues((Widget) m_mainWidget, XmNwidth, width, NULL);
410 if (height > -1)
411 XtVaSetValues((Widget) m_mainWidget, XmNheight, height, NULL);
412
413 if (!(height == -1 && width == -1))
414 {
415 PreResize();
416 }
417}
418
419bool wxFrame::Show( bool show )
420{
421 if( !wxWindowBase::Show( show ) )
422 return false;
423
424 m_isShown = show;
425
426 Widget shell = (Widget)GetShellWidget();
427 if (!shell)
428 return wxWindow::Show(show);
429
430 SetVisibleStatus(show);
431 if (show)
432 {
433 XtPopup(shell, XtGrabNone);
434 }
435 else
436 {
437 XtPopdown(shell);
438 }
439
440 return true;
441}
442
443void wxFrame::SetTitle(const wxString& title)
444{
445 wxString oldTitle = GetTitle();
446 if( title == oldTitle )
447 return;
448
449 wxTopLevelWindow::SetTitle( title );
450
451 if( !title.empty() )
452 XtVaSetValues( (Widget)m_frameShell,
453 XmNtitle, title.c_str(),
454 XmNiconName, title.c_str(),
455 NULL );
456}
457
458void wxFrame::DoSetIcon(const wxIcon& icon)
459{
460 if (!m_frameShell)
461 return;
462
463 if (!icon.Ok() || !icon.GetDrawable())
464 return;
465
466 XtVaSetValues((Widget) m_frameShell,
467 XtNiconPixmap, icon.GetDrawable(),
468 NULL);
469}
470
471void wxFrame::SetIcon(const wxIcon& icon)
472{
473 SetIcons( wxIconBundle( icon ) );
474}
475
476void wxFrame::SetIcons(const wxIconBundle& icons)
477{
478 wxFrameBase::SetIcons( icons );
479
480 if (!m_frameShell)
481 return;
482
483 DoSetIcon( m_icons.GetIcon( -1 ) );
484 wxSetIconsX11(GetXDisplay(),
485 (WXWindow) XtWindow( (Widget) m_frameShell ), icons);
486}
487
488void wxFrame::PositionStatusBar()
489{
490 if (!m_frameStatusBar)
491 return;
492
493 int w, h;
494 GetClientSize(&w, &h);
495 int sw, sh;
496 m_frameStatusBar->GetSize(&sw, &sh);
497
498 // Since we wish the status bar to be directly under the client area,
499 // we use the adjusted sizes without using wxSIZE_NO_ADJUSTMENTS.
500 m_frameStatusBar->SetSize(0, h, w, sh);
501}
502
503WXWidget wxFrame::GetMenuBarWidget() const
504{
505 if (GetMenuBar())
506 return GetMenuBar()->GetMainWidget();
507 else
508 return (WXWidget) NULL;
509}
510
511void wxFrame::SetMenuBar(wxMenuBar *menuBar)
512{
513 if (!menuBar)
514 {
515 m_frameMenuBar = NULL;
516 return;
517 }
518
519 // Currently can't set it twice
520 // wxASSERT_MSG( (m_frameMenuBar == (wxMenuBar*) NULL), "Cannot set the menubar more than once");
521
522 if (m_frameMenuBar)
523 {
524 m_frameMenuBar->DestroyMenuBar();
525 delete m_frameMenuBar;
526 }
527
528 m_frameMenuBar = menuBar;
529 m_frameMenuBar->CreateMenuBar(this);
530}
531
532// Responds to colour changes, and passes event on to children.
533void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
534{
535 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_APPWORKSPACE));
536 Refresh();
537
538 if ( m_frameStatusBar )
539 {
540 wxSysColourChangedEvent event2;
541 event2.SetEventObject( m_frameStatusBar );
542 m_frameStatusBar->ProcessEvent(event2);
543 }
544
545 // Propagate the event to the non-top-level children
546 wxWindow::OnSysColourChanged(event);
547}
548
549// Default activation behaviour - set the focus for the first child
550// subwindow found.
551void wxFrame::OnActivate(wxActivateEvent& event)
552{
553 if (!event.GetActive())
554 return;
555
556 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); node;
557 node = node->GetNext())
558 {
559 // Find a child that's a subwindow, but not a dialog box.
560 wxWindow *child = node->GetData();
561 if (!child->IsTopLevel())
562 {
563 child->SetFocus();
564 return;
565 }
566 }
567}
568
569void wxFrame::SendSizeEvent()
570{
571 wxSizeEvent event(GetSize(), GetId());
572 event.SetEventObject(this);
573 GetEventHandler()->AddPendingEvent(event);
574}
575
576#if wxUSE_TOOLBAR
577
578wxToolBar* wxFrame::CreateToolBar(long style,
579 wxWindowID id,
580 const wxString& name)
581{
582 if ( wxFrameBase::CreateToolBar(style, id, name) )
583 {
584 PositionToolBar();
585 }
586
587 return m_frameToolBar;
588}
589
590void wxFrame::SetToolBar(wxToolBar *toolbar)
591{
592 wxFrameBase::SetToolBar(toolbar);
593 SendSizeEvent();
594}
595
596void wxFrame::PositionToolBar()
597{
598 wxToolBar* tb = GetToolBar();
599 if (tb)
600 {
601 int cw, ch;
602 GetClientSize(& cw, &ch);
603
604 int tw, th;
605 tb->GetSize(& tw, & th);
606
607 if (tb->GetWindowStyleFlag() & wxTB_VERTICAL)
608 {
609 // Use the 'real' position. wxSIZE_NO_ADJUSTMENTS
610 // means, pretend we don't have toolbar/status bar, so we
611 // have the original client size.
612 th = ch + th;
613 }
614 else
615 {
616 // Use the 'real' position
617 tw = cw;
618 }
619
620 tb->SetSize(0, 0, -1, -1, wxSIZE_NO_ADJUSTMENTS);
621 }
622}
623#endif // wxUSE_TOOLBAR
624
625//// Motif-specific
626bool wxFrame::PreResize()
627{
628#if wxUSE_TOOLBAR
629 PositionToolBar();
630#endif // wxUSE_TOOLBAR
631
632#if wxUSE_STATUSBAR
633 PositionStatusBar();
634#endif // wxUSE_STATUSBAR
635
636 return true;
637}
638
639WXWidget wxFrame::GetClientWidget() const
640{
641 return m_clientArea;
642}
643
644void wxFrame::ChangeFont(bool WXUNUSED(keepOriginalSize))
645{
646 // TODO
647}
648
649void wxFrame::ChangeBackgroundColour()
650{
651 if (GetClientWidget())
652 wxDoChangeBackgroundColour(GetClientWidget(), m_backgroundColour);
653}
654
655void wxFrame::ChangeForegroundColour()
656{
657 if (GetClientWidget())
658 wxDoChangeForegroundColour(GetClientWidget(), m_foregroundColour);
659}
660
661/* MATTEW: Used to insure that hide-&-show within an event cycle works */
662static void wxFrameMapProc( Widget frameShell, XtPointer clientData,
663 XCrossingEvent* event )
664{
665 wxFrame *tli = (wxFrame*)clientData;
666
667 XEvent *e = (XEvent *)event;
668
669 if( e->xany.type == MapNotify )
670 {
671 // Iconize fix
672 XtVaSetValues( frameShell, XmNiconic, (Boolean)False, NULL );
673 if( !tli->GetVisibleStatus() )
674 {
675 /* We really wanted this to be hidden! */
676 XtUnmapWidget( frameShell );
677 }
678 }
679 else if( e->xany.type == UnmapNotify )
680 // Iconize fix
681 XtVaSetValues( frameShell, XmNiconic, (Boolean)True, NULL );
682}