]> git.saurik.com Git - wxWidgets.git/blame - src/motif/toolbar.cpp
Rebake after recguard.h added to bakefiles
[wxWidgets.git] / src / motif / toolbar.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
8a0681f9 2// Name: motif/toolbar.cpp
4bb6408c
JS
3// Purpose: wxToolBar
4// Author: Julian Smart
8a0681f9 5// Modified by: 13.12.99 by VZ during toolbar classes reorganization
4bb6408c
JS
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
4bb6408c
JS
10/////////////////////////////////////////////////////////////////////////////
11
8a0681f9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
8a0681f9 21 #pragma implementation "toolbar.h"
4bb6408c
JS
22#endif
23
1248b41f
MB
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
4dff3400
JJ
27#ifdef __VMS
28#define XtDisplay XTDISPLAY
29#endif
30
00dd3b18 31#include "wx/settings.h"
1a3ac83f
JS
32#include "wx/app.h"
33#include "wx/timer.h"
1ccbb61a 34#include "wx/toolbar.h"
46675b46 35#include "wx/frame.h"
0d57be45 36
338dd992
JJ
37#ifdef __VMS__
38#pragma message disable nosimpint
39#endif
0d57be45
JS
40#include <Xm/Xm.h>
41#include <Xm/PushBG.h>
42#include <Xm/PushB.h>
1a3ac83f 43#include <Xm/Label.h>
0d57be45
JS
44#include <Xm/ToggleB.h>
45#include <Xm/ToggleBG.h>
46#include <Xm/Form.h>
338dd992
JJ
47#ifdef __VMS__
48#pragma message enable nosimpint
49#endif
0d57be45
JS
50
51#include "wx/motif/private.h"
aae91497 52#include "wx/motif/bmpmotif.h"
4bb6408c 53
8a0681f9
VZ
54// ----------------------------------------------------------------------------
55// wxWin macros
56// ----------------------------------------------------------------------------
57
2eb10e2a 58IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl)
4bb6408c 59
8a0681f9
VZ
60// ----------------------------------------------------------------------------
61// private functions
62// ----------------------------------------------------------------------------
4bb6408c 63
1a3ac83f 64static void wxToolButtonCallback (Widget w, XtPointer clientData,
bf6c2b35 65 XtPointer ptr);
1a3ac83f
JS
66static void wxToolButtonPopupCallback (Widget w, XtPointer client_data,
67 XEvent *event, Boolean *continue_to_dispatch);
68
8a0681f9
VZ
69// ----------------------------------------------------------------------------
70// private classes
71// ----------------------------------------------------------------------------
72
73class wxToolBarTimer : public wxTimer
1a3ac83f
JS
74{
75public:
8a0681f9 76 virtual void Notify();
1a3ac83f 77
8a0681f9
VZ
78 static Widget help_popup;
79 static Widget buttonWidget;
80 static wxString helpString;
1a3ac83f
JS
81};
82
8a0681f9
VZ
83class wxToolBarTool : public wxToolBarToolBase
84{
85public:
86 wxToolBarTool(wxToolBar *tbar,
87 int id,
fcb35b5f
VZ
88 const wxString& label,
89 const wxBitmap& bmpNormal,
90 const wxBitmap& bmpToggled,
91 wxItemKind kind,
8a0681f9 92 wxObject *clientData,
fcb35b5f
VZ
93 const wxString& shortHelp,
94 const wxString& longHelp)
95 : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpToggled, kind,
96 clientData, shortHelp, longHelp)
8a0681f9
VZ
97 {
98 Init();
99 }
100
101 wxToolBarTool(wxToolBar *tbar, wxControl *control)
102 : wxToolBarToolBase(tbar, control)
103 {
104 Init();
105 }
106
107 virtual ~wxToolBarTool();
108
109 // accessors
110 void SetWidget(Widget widget) { m_widget = widget; }
111 Widget GetButtonWidget() const { return m_widget; }
112
aae91497
MB
113 Pixmap GetArmPixmap()
114 {
115 m_bitmapCache.SetBitmap( GetNormalBitmap() );
116 return (Pixmap)m_bitmapCache.GetArmPixmap( (WXWidget)m_widget );
117 }
8a0681f9 118
aae91497
MB
119 Pixmap GetInsensPixmap()
120 {
121 m_bitmapCache.SetBitmap( GetNormalBitmap() );
122 return (Pixmap)m_bitmapCache.GetInsensPixmap( (WXWidget)m_widget );
123 }
8a0681f9
VZ
124protected:
125 void Init();
126
127 Widget m_widget;
aae91497 128 wxBitmapCache m_bitmapCache;
8a0681f9
VZ
129};
130
131// ----------------------------------------------------------------------------
132// globals
133// ----------------------------------------------------------------------------
134
1a3ac83f
JS
135static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL;
136
137Widget wxToolBarTimer::help_popup = (Widget) 0;
138Widget wxToolBarTimer::buttonWidget = (Widget) 0;
8a0681f9
VZ
139wxString wxToolBarTimer::helpString;
140
141// ============================================================================
142// implementation
143// ============================================================================
144
145// ----------------------------------------------------------------------------
146// wxToolBarTool
147// ----------------------------------------------------------------------------
148
982b2cfc 149wxToolBarToolBase *wxToolBar::CreateTool(int id,
fcb35b5f
VZ
150 const wxString& label,
151 const wxBitmap& bmpNormal,
152 const wxBitmap& bmpToggled,
153 wxItemKind kind,
982b2cfc 154 wxObject *clientData,
fcb35b5f
VZ
155 const wxString& shortHelp,
156 const wxString& longHelp)
8a0681f9 157{
fcb35b5f
VZ
158 return new wxToolBarTool(this, id, label, bmpNormal, bmpToggled, kind,
159 clientData, shortHelp, longHelp);
8a0681f9 160}
1a3ac83f 161
fcb35b5f 162
982b2cfc 163wxToolBarToolBase *wxToolBar::CreateTool(wxControl *control)
4bb6408c 164{
982b2cfc 165 return new wxToolBarTool(this, control);
4bb6408c
JS
166}
167
8a0681f9
VZ
168void wxToolBarTool::Init()
169{
170 m_widget = (Widget)0;
8a0681f9
VZ
171}
172
173wxToolBarTool::~wxToolBarTool()
174{
982b2cfc
VZ
175 if ( m_widget )
176 XtDestroyWidget(m_widget);
8a0681f9
VZ
177}
178
179// ----------------------------------------------------------------------------
180// wxToolBar construction
181// ----------------------------------------------------------------------------
182
183void wxToolBar::Init()
4bb6408c
JS
184{
185 m_maxWidth = -1;
186 m_maxHeight = -1;
4bb6408c
JS
187 m_defaultWidth = 24;
188 m_defaultHeight = 22;
7b28757f
JS
189 m_toolPacking = 2;
190 m_toolSeparation = 8;
191 m_xMargin = 2;
192 m_yMargin = 2;
193 m_maxRows = 100;
194 m_maxCols = 100;
8a0681f9
VZ
195}
196
197bool wxToolBar::Create(wxWindow *parent,
198 wxWindowID id,
199 const wxPoint& pos,
200 const wxSize& size,
201 long style,
202 const wxString& name)
203{
46675b46
MB
204 if( !wxControl::CreateControl( parent, id, pos, size, style,
205 wxDefaultValidator, name ) )
96be256b 206 return false;
8a0681f9 207
a756f210 208 m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
4bb6408c 209
0d57be45
JS
210 Widget parentWidget = (Widget) parent->GetClientWidget();
211
212 Widget toolbar = XtVaCreateManagedWidget("toolbar",
7fe7d506
JS
213 xmBulletinBoardWidgetClass, (Widget) parentWidget,
214 XmNmarginWidth, 0,
215 XmNmarginHeight, 0,
216 XmNresizePolicy, XmRESIZE_NONE,
217 NULL);
218/*
219 Widget toolbar = XtVaCreateManagedWidget("toolbar",
220 xmFormWidgetClass, (Widget) m_clientWidget,
0d57be45
JS
221 XmNtraversalOn, False,
222 XmNhorizontalSpacing, 0,
223 XmNverticalSpacing, 0,
1a3ac83f
JS
224 XmNleftOffset, 0,
225 XmNrightOffset, 0,
226 XmNmarginWidth, 0,
227 XmNmarginHeight, 0,
0d57be45 228 NULL);
7fe7d506 229*/
0d57be45
JS
230
231 m_mainWidget = (WXWidget) toolbar;
232
96be256b 233 ChangeFont(false);
4b5f3fe6 234
46675b46
MB
235 wxPoint rPos = pos;
236 wxSize rSize = size;
237
238 if( rPos.x == -1 ) rPos.x = 0;
239 if( rPos.y == -1 ) rPos.y = 0;
240 if( rSize.x == -1 && GetParent() )
241 rSize.x = GetParent()->GetSize().x;
242
46675b46
MB
243 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
244 rPos.x, rPos.y, rSize.x, rSize.y);
0d57be45 245
0d57be45 246 ChangeBackgroundColour();
bf6c2b35 247
96be256b 248 return true;
4bb6408c
JS
249}
250
251wxToolBar::~wxToolBar()
252{
1a3ac83f
JS
253 delete wxTheToolBarTimer;
254 wxTheToolBarTimer = NULL;
4bb6408c
JS
255}
256
8a0681f9 257bool wxToolBar::Realize()
7fe7d506 258{
8a0681f9
VZ
259 if ( m_tools.GetCount() == 0 )
260 {
261 // nothing to do
96be256b 262 return true;
8a0681f9 263 }
7fe7d506 264
46675b46
MB
265 bool isVertical = GetWindowStyle() & wxTB_VERTICAL;
266
7fe7d506
JS
267 // Separator spacing
268 const int separatorSize = GetToolSeparation(); // 8;
269 wxSize margins = GetToolMargins();
f3979fcc 270 int packing = GetToolPacking();
7fe7d506
JS
271 int marginX = margins.x;
272 int marginY = margins.y;
273
274 int currentX = marginX;
275 int currentY = marginY;
276
46675b46 277 int buttonHeight = 0, buttonWidth = 0;
7fe7d506
JS
278
279 int currentSpacing = 0;
280
8a0681f9
VZ
281 Widget button;
282 Pixmap pixmap, insensPixmap;
aae91497 283 wxBitmap bmp, insensBmp;
8a0681f9 284
ac32ba44 285 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9 286 while ( node )
7fe7d506 287 {
8a0681f9 288 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
7fe7d506 289
8a0681f9 290 switch ( tool->GetStyle() )
7fe7d506 291 {
8a0681f9 292 case wxTOOL_STYLE_CONTROL:
f3979fcc 293 {
66f55ec6
JS
294 wxControl* control = tool->GetControl();
295 wxSize sz = control->GetSize();
f3979fcc 296 wxPoint pos = control->GetPosition();
46675b46
MB
297 // Allow a control to specify a y[x]-offset by setting
298 // its initial position, but still don't allow it to
299 // position itself above the top[left] margin.
aae91497
MB
300 int controlY = (pos.y > 0) ? pos.y : currentY;
301 int controlX = (pos.x > 0) ? pos.x : currentX;
46675b46
MB
302 control->Move( isVertical ? controlX : currentX,
303 isVertical ? currentY : controlY );
304 if ( isVertical )
305 currentY += sz.y + packing;
306 else
307 currentX += sz.x + packing;
66f55ec6 308
8a0681f9 309 break;
f3979fcc 310 }
8a0681f9 311 case wxTOOL_STYLE_SEPARATOR:
aae91497
MB
312 // skip separators for vertical toolbars
313 if( !isVertical )
314 {
315 currentX += separatorSize;
316 }
8a0681f9 317 break;
7fe7d506 318
8a0681f9
VZ
319 case wxTOOL_STYLE_BUTTON:
320 button = (Widget) 0;
bf6c2b35 321
aae91497 322 if ( tool->CanBeToggled() && !tool->GetButtonWidget() )
7fe7d506 323 {
8a0681f9
VZ
324 button = XtVaCreateWidget("toggleButton",
325 xmToggleButtonWidgetClass, (Widget) m_mainWidget,
326 XmNx, currentX, XmNy, currentY,
e838cc14
VZ
327 XmNindicatorOn, False,
328 XmNshadowThickness, 2,
329 XmNborderWidth, 0,
330 XmNspacing, 0,
331 XmNmarginWidth, 0,
332 XmNmarginHeight, 0,
8a0681f9
VZ
333 XmNmultiClick, XmMULTICLICK_KEEP,
334 XmNlabelType, XmPIXMAP,
335 NULL);
aae91497
MB
336 XtAddCallback ((Widget) button,
337 XmNvalueChangedCallback,
338 (XtCallbackProc) wxToolButtonCallback,
339 (XtPointer) this);
8a0681f9
VZ
340
341 XtVaSetValues ((Widget) button,
aae91497
MB
342 XmNselectColor,
343 m_backgroundColour.AllocColour
344 (XtDisplay((Widget) button)),
345 NULL);
bf6c2b35 346 }
aae91497 347 else if( !tool->GetButtonWidget() )
8a0681f9
VZ
348 {
349 button = XtVaCreateWidget("button",
350 xmPushButtonWidgetClass, (Widget) m_mainWidget,
351 XmNx, currentX, XmNy, currentY,
352 XmNpushButtonEnabled, True,
353 XmNmultiClick, XmMULTICLICK_KEEP,
354 XmNlabelType, XmPIXMAP,
355 NULL);
356 XtAddCallback (button,
aae91497
MB
357 XmNactivateCallback,
358 (XtCallbackProc) wxToolButtonCallback,
359 (XtPointer) this);
8a0681f9 360 }
7fe7d506 361
aae91497
MB
362 if( !tool->GetButtonWidget() )
363 {
a8680e3e 364 wxDoChangeBackgroundColour((WXWidget) button,
96be256b 365 m_backgroundColour, true);
7fe7d506 366
aae91497
MB
367 tool->SetWidget(button);
368 }
369 else
370 {
371 button = (Widget)tool->GetButtonWidget();
372 XtVaSetValues( button,
373 XmNx, currentX, XmNy, currentY,
374 NULL );
375 }
7fe7d506 376
8a0681f9
VZ
377 // For each button, if there is a mask, we must create
378 // a new wxBitmap that has the correct background colour
379 // for the button. Otherwise the background will just be
380 // e.g. black if a transparent XPM has been loaded.
fcb35b5f 381 bmp = tool->GetNormalBitmap();
aae91497
MB
382 insensBmp = tool->GetDisabledBitmap();
383 if ( bmp.GetMask() || insensBmp.GetMask() )
7fe7d506 384 {
8a0681f9
VZ
385 int backgroundPixel;
386 XtVaGetValues(button, XmNbackground, &backgroundPixel,
aae91497 387 NULL);
8a0681f9
VZ
388
389 wxColour col;
390 col.SetPixel(backgroundPixel);
8a0681f9 391
aae0472b 392 if( bmp.Ok() && bmp.GetMask() )
aae91497
MB
393 {
394 bmp = wxCreateMaskedBitmap(bmp, col);
395 tool->SetNormalBitmap(bmp);
396 }
397
aae0472b 398 if( insensBmp.Ok() && insensBmp.GetMask() )
aae91497
MB
399 {
400 insensBmp = wxCreateMaskedBitmap(insensBmp, col);
401 tool->SetDisabledBitmap(insensBmp);
402 }
7fe7d506 403 }
8a0681f9
VZ
404
405 // Create a selected/toggled bitmap. If there isn't a 2nd
406 // bitmap, we need to create it (with a darker, selected
407 // background)
408 int backgroundPixel;
409 if ( tool->CanBeToggled() )
410 XtVaGetValues(button, XmNselectColor, &backgroundPixel,
aae91497 411 NULL);
7fe7d506 412 else
8a0681f9 413 XtVaGetValues(button, XmNarmColor, &backgroundPixel,
aae91497 414 NULL);
8a0681f9
VZ
415 wxColour col;
416 col.SetPixel(backgroundPixel);
417
aae0472b 418 pixmap = (Pixmap) bmp.GetDrawable();
aae91497
MB
419 {
420 wxBitmap tmp = tool->GetDisabledBitmap();
8a0681f9 421
aae91497 422 insensPixmap = tmp.Ok() ?
aae0472b 423 (Pixmap)tmp.GetDrawable() :
aae91497
MB
424 tool->GetInsensPixmap();
425 }
426
8a0681f9
VZ
427 if (tool->CanBeToggled())
428 {
429 // Toggle button
aae91497
MB
430 Pixmap pixmap2 = tool->GetArmPixmap();
431 Pixmap insensPixmap2 = tool->GetInsensPixmap();
982b2cfc 432
8a0681f9 433 XtVaSetValues (button,
8a0681f9
VZ
434 XmNfillOnSelect, True,
435 XmNlabelPixmap, pixmap,
436 XmNselectPixmap, pixmap2,
437 XmNlabelInsensitivePixmap, insensPixmap,
438 XmNselectInsensitivePixmap, insensPixmap2,
439 XmNlabelType, XmPIXMAP,
440 NULL);
7fe7d506
JS
441 }
442 else
443 {
aae91497 444 Pixmap pixmap2 = tool->GetArmPixmap();
982b2cfc 445
8a0681f9
VZ
446 // Normal button
447 XtVaSetValues(button,
448 XmNlabelPixmap, pixmap,
449 XmNlabelInsensitivePixmap, insensPixmap,
450 XmNarmPixmap, pixmap2,
451 NULL);
452 }
982b2cfc 453
8a0681f9 454 XtManageChild(button);
7fe7d506 455
8a0681f9
VZ
456 {
457 Dimension width, height;
458 XtVaGetValues(button,
459 XmNwidth, &width,
460 XmNheight, & height,
461 NULL);
46675b46
MB
462 if ( isVertical )
463 currentY += height + packing;
464 else
465 currentX += width + packing;
8a0681f9 466 buttonHeight = wxMax(buttonHeight, height);
46675b46 467 buttonWidth = wxMax(buttonWidth, width);
7fe7d506 468 }
8a0681f9
VZ
469
470 XtAddEventHandler (button, EnterWindowMask | LeaveWindowMask,
471 False, wxToolButtonPopupCallback, (XtPointer) this);
472
473 currentSpacing = 0;
474 break;
7fe7d506 475 }
8a0681f9
VZ
476
477 node = node->GetNext();
7fe7d506
JS
478 }
479
46675b46 480 SetSize( -1, -1,
aae91497
MB
481 isVertical ? buttonWidth + 2 * marginX : -1,
482 isVertical ? -1 : buttonHeight + 2*marginY );
7fe7d506 483
96be256b 484 return true;
7fe7d506
JS
485}
486
982b2cfc
VZ
487wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x),
488 wxCoord WXUNUSED(y)) const
4bb6408c 489{
8a0681f9 490 wxFAIL_MSG( _T("TODO") );
4b5f3fe6 491
982b2cfc 492 return (wxToolBarToolBase *)NULL;
4bb6408c
JS
493}
494
982b2cfc 495bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool)
4bb6408c 496{
8a0681f9 497 tool->Attach(this);
4bb6408c 498
96be256b 499 return true;
4bb6408c
JS
500}
501
aae91497 502bool wxToolBar::DoDeleteTool(size_t pos, wxToolBarToolBase *tool)
4bb6408c 503{
8a0681f9 504 tool->Detach();
0d57be45 505
aae91497
MB
506 bool isVertical = GetWindowStyle() & wxTB_VERTICAL;
507 const int separatorSize = GetToolSeparation(); // 8;
508 int packing = GetToolPacking();
509 int offset = 0;
510
ac32ba44 511 for( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
aae91497
MB
512 node; node = node->GetNext() )
513 {
514 wxToolBarTool *t = (wxToolBarTool*)node->GetData();
515
516 if( t == tool )
517 {
518 switch ( t->GetStyle() )
519 {
520 case wxTOOL_STYLE_CONTROL:
521 {
522 wxSize size = t->GetControl()->GetSize();
523 offset = isVertical ? size.y : size.x;
524 offset += packing;
525 break;
526 }
527 case wxTOOL_STYLE_SEPARATOR:
528 offset = isVertical ? 0 : separatorSize;
529 break;
530 case wxTOOL_STYLE_BUTTON:
531 {
532 Widget w = t->GetButtonWidget();
533 Dimension width, height;
534
535 XtVaGetValues( w,
536 XmNwidth, &width,
537 XmNheight, &height,
538 NULL );
539
540 offset = isVertical ? height : width;
541 offset += packing;
542 break;
543 }
544 }
545 }
546 else if( offset )
547 {
548 switch ( t->GetStyle() )
549 {
550 case wxTOOL_STYLE_CONTROL:
551 {
552 wxPoint pos = t->GetControl()->GetPosition();
553
554 if( isVertical )
555 pos.y -= offset;
556 else
557 pos.x -= offset;
558
559 t->GetControl()->Move( pos );
560 break;
561 }
562 case wxTOOL_STYLE_SEPARATOR:
563 break;
564 case wxTOOL_STYLE_BUTTON:
565 {
566 Dimension x, y;
567 XtVaGetValues( t->GetButtonWidget(),
568 XmNx, &x,
569 XmNy, &y,
570 NULL );
571
572 if( isVertical )
573 y -= offset;
574 else
575 x -= offset;
576
577 XtVaSetValues( t->GetButtonWidget(),
578 XmNx, x,
579 XmNy, y,
580 NULL );
581 break;
582 }
583 }
584 }
585 }
586
96be256b 587 return true;
4bb6408c
JS
588}
589
982b2cfc 590void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable)
1a3ac83f 591{
982b2cfc 592 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
6707bb94
MB
593 if (tool->GetButtonWidget()){
594 XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable);
595 } else if (wxTOOL_STYLE_CONTROL == tool->GetStyle()){
596 // Controls (such as wxChoice) do not have button widgets
597 tool->GetControl()->Enable(enable);
598 }
1a3ac83f
JS
599}
600
982b2cfc 601void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle)
4bb6408c 602{
982b2cfc
VZ
603 wxToolBarTool *tool = (wxToolBarTool *)toolBase;
604
8a0681f9 605 XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False);
4bb6408c
JS
606}
607
982b2cfc
VZ
608void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool),
609 bool WXUNUSED(toggle))
1a3ac83f 610{
982b2cfc 611 // nothing to do
1a3ac83f
JS
612}
613
46675b46
MB
614void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags)
615{
616 int old_width, old_height;
617 GetSize(&old_width, &old_height);
618
46675b46
MB
619 // Correct width and height if needed.
620 if ( width == -1 || height == -1 )
621 {
aae91497 622 wxSize defaultSize = GetSize();
46675b46
MB
623
624 if ( width == -1 )
aae91497 625 width = defaultSize.x;
46675b46 626 if ( height == -1 )
aae91497 627 height = defaultSize.y;
46675b46 628 }
aae91497
MB
629
630 wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags);
46675b46
MB
631
632 // We must refresh the frame size when the toolbar changes size
633 // otherwise the toolbar can be shown incorrectly
634 if ( old_width != width || old_height != height )
635 {
636 // But before we send the size event check it
637 // we have a frame that is not being deleted.
638 wxFrame *frame = wxDynamicCast(GetParent(), wxFrame);
639 if ( frame && !frame->IsBeingDeleted() )
640 {
641 frame->SendSizeEvent();
642 }
643 }
644}
645
8a0681f9
VZ
646// ----------------------------------------------------------------------------
647// Motif callbacks
648// ----------------------------------------------------------------------------
1a3ac83f 649
982b2cfc 650wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const
7fe7d506 651{
ac32ba44 652 wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();
8a0681f9
VZ
653 while ( node )
654 {
655 wxToolBarTool *tool = (wxToolBarTool *)node->GetData();
656 if ( tool->GetButtonWidget() == w)
657 {
658 return tool;
659 }
7fe7d506 660
8a0681f9
VZ
661 node = node->GetNext();
662 }
7fe7d506 663
982b2cfc 664 return (wxToolBarToolBase *)NULL;
7fe7d506
JS
665}
666
8a0681f9
VZ
667static void wxToolButtonCallback(Widget w,
668 XtPointer clientData,
669 XtPointer WXUNUSED(ptr))
1a3ac83f
JS
670{
671 wxToolBar *toolBar = (wxToolBar *) clientData;
982b2cfc 672 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
8a0681f9
VZ
673 if ( !tool )
674 return;
1a3ac83f 675
8a0681f9
VZ
676 if ( tool->CanBeToggled() )
677 tool->Toggle();
678
679 if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) )
1a3ac83f 680 {
8a0681f9
VZ
681 // revert
682 tool->Toggle();
1a3ac83f 683 }
1a3ac83f
JS
684}
685
1a3ac83f 686
8a0681f9
VZ
687static void wxToolButtonPopupCallback(Widget w,
688 XtPointer client_data,
689 XEvent *event,
690 Boolean *WXUNUSED(continue_to_dispatch))
1a3ac83f
JS
691{
692 // TODO: retrieve delay before popping up tooltip from wxSystemSettings.
8a0681f9 693 static const int delayMilli = 800;
1a3ac83f 694
8a0681f9 695 wxToolBar* toolBar = (wxToolBar*) client_data;
982b2cfc 696 wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w);
1a3ac83f 697
8a0681f9
VZ
698 if ( !tool )
699 return;
1a3ac83f 700
8a0681f9
VZ
701 wxString tooltip = tool->GetShortHelp();
702 if ( !tooltip )
703 return;
1a3ac83f 704
8a0681f9
VZ
705 if (!wxTheToolBarTimer)
706 wxTheToolBarTimer = new wxToolBarTimer;
1a3ac83f 707
8a0681f9
VZ
708 wxToolBarTimer::buttonWidget = w;
709 wxToolBarTimer::helpString = tooltip;
1a3ac83f
JS
710
711 /************************************************************/
712 /* Popup help label */
713 /************************************************************/
714 if (event->type == EnterNotify)
715 {
716 if (wxToolBarTimer::help_popup != (Widget) 0)
717 {
718 XtDestroyWidget (wxToolBarTimer::help_popup);
719 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 720 }
1a3ac83f
JS
721 wxToolBarTimer::help_popup = (Widget) 0;
722
723 // One shot
96be256b 724 wxTheToolBarTimer->Start(delayMilli, true);
1a3ac83f
JS
725
726 }
727 /************************************************************/
728 /* Popdown help label */
729 /************************************************************/
730 else if (event->type == LeaveNotify)
731 {
732 if (wxTheToolBarTimer)
733 wxTheToolBarTimer->Stop();
734 if (wxToolBarTimer::help_popup != (Widget) 0)
735 {
736 XtDestroyWidget (wxToolBarTimer::help_popup);
737 XtPopdown (wxToolBarTimer::help_popup);
bf6c2b35 738 }
1a3ac83f
JS
739 wxToolBarTimer::help_popup = (Widget) 0;
740 }
1a3ac83f
JS
741}
742
743void wxToolBarTimer::Notify()
744{
745 Position x, y;
746
747 /************************************************************/
748 /* Create shell without window decorations */
749 /************************************************************/
bf6c2b35
VZ
750 help_popup = XtVaCreatePopupShell ("shell",
751 overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(),
1a3ac83f
JS
752 NULL);
753
754 /************************************************************/
755 /* Get absolute position on display of toolbar button */
756 /************************************************************/
757 XtTranslateCoords (buttonWidget,
bf6c2b35
VZ
758 (Position) 0,
759 (Position) 0,
1a3ac83f
JS
760 &x, &y);
761
762 // Move the tooltip more or less above the button
763 int yOffset = 20; // TODO: What should be really?
764 y -= yOffset;
765 if (y < yOffset) y = 0;
766
767 /************************************************************/
768 /* Set the position of the help popup */
769 /************************************************************/
bf6c2b35
VZ
770 XtVaSetValues (help_popup,
771 XmNx, (Position) x,
772 XmNy, (Position) y,
1a3ac83f 773 NULL);
bf6c2b35 774
1a3ac83f
JS
775 /************************************************************/
776 /* Create help label */
777 /************************************************************/
778 XmString text = XmStringCreateSimple ((char*) (const char*) helpString);
bf6c2b35
VZ
779 XtVaCreateManagedWidget ("help_label",
780 xmLabelWidgetClass, help_popup,
1a3ac83f 781 XmNlabelString, text,
bf6c2b35
VZ
782 XtVaTypedArg,
783 XmNforeground, XtRString, "black",
784 strlen("black")+1,
785 XtVaTypedArg,
786 XmNbackground, XtRString, "LightGoldenrod",
787 strlen("LightGoldenrod")+1,
1a3ac83f
JS
788 NULL);
789 XmStringFree (text);
790
791 /************************************************************/
792 /* Popup help label */
793 /************************************************************/
794 XtPopup (help_popup, XtGrabNone);
795}
796