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