]>
Commit | Line | Data |
---|---|---|
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 | ||
4dff3400 JJ |
23 | #ifdef __VMS |
24 | #define XtDisplay XTDISPLAY | |
25 | #endif | |
26 | ||
670f9935 WS |
27 | #include "wx/toolbar.h" |
28 | ||
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/app.h" | |
76b49cf4 | 31 | #include "wx/frame.h" |
c0badb70 | 32 | #include "wx/timer.h" |
9eddec69 | 33 | #include "wx/settings.h" |
670f9935 WS |
34 | #endif |
35 | ||
338dd992 JJ |
36 | #ifdef __VMS__ |
37 | #pragma message disable nosimpint | |
38 | #endif | |
0d57be45 JS |
39 | #include <Xm/Xm.h> |
40 | #include <Xm/PushBG.h> | |
41 | #include <Xm/PushB.h> | |
1a3ac83f | 42 | #include <Xm/Label.h> |
0d57be45 JS |
43 | #include <Xm/ToggleB.h> |
44 | #include <Xm/ToggleBG.h> | |
45 | #include <Xm/Form.h> | |
338dd992 JJ |
46 | #ifdef __VMS__ |
47 | #pragma message enable nosimpint | |
48 | #endif | |
0d57be45 JS |
49 | |
50 | #include "wx/motif/private.h" | |
aae91497 | 51 | #include "wx/motif/bmpmotif.h" |
4bb6408c | 52 | |
8a0681f9 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
2eb10e2a | 57 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxControl) |
4bb6408c | 58 | |
8a0681f9 VZ |
59 | // ---------------------------------------------------------------------------- |
60 | // private functions | |
61 | // ---------------------------------------------------------------------------- | |
4bb6408c | 62 | |
1a3ac83f | 63 | static void wxToolButtonCallback (Widget w, XtPointer clientData, |
bf6c2b35 | 64 | XtPointer ptr); |
1a3ac83f JS |
65 | static void wxToolButtonPopupCallback (Widget w, XtPointer client_data, |
66 | XEvent *event, Boolean *continue_to_dispatch); | |
67 | ||
8a0681f9 VZ |
68 | // ---------------------------------------------------------------------------- |
69 | // private classes | |
70 | // ---------------------------------------------------------------------------- | |
71 | ||
72 | class wxToolBarTimer : public wxTimer | |
1a3ac83f JS |
73 | { |
74 | public: | |
8a0681f9 | 75 | virtual void Notify(); |
1a3ac83f | 76 | |
8a0681f9 VZ |
77 | static Widget help_popup; |
78 | static Widget buttonWidget; | |
79 | static wxString helpString; | |
1a3ac83f JS |
80 | }; |
81 | ||
8a0681f9 VZ |
82 | class wxToolBarTool : public wxToolBarToolBase |
83 | { | |
84 | public: | |
85 | wxToolBarTool(wxToolBar *tbar, | |
86 | int id, | |
fcb35b5f VZ |
87 | const wxString& label, |
88 | const wxBitmap& bmpNormal, | |
89 | const wxBitmap& bmpToggled, | |
90 | wxItemKind kind, | |
8a0681f9 | 91 | wxObject *clientData, |
fcb35b5f VZ |
92 | const wxString& shortHelp, |
93 | const wxString& longHelp) | |
94 | : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpToggled, kind, | |
95 | clientData, shortHelp, longHelp) | |
8a0681f9 VZ |
96 | { |
97 | Init(); | |
98 | } | |
99 | ||
07d02e9e VZ |
100 | wxToolBarTool(wxToolBar *tbar, wxControl *control, const wxString& label) |
101 | : wxToolBarToolBase(tbar, control, label) | |
8a0681f9 VZ |
102 | { |
103 | Init(); | |
104 | } | |
105 | ||
106 | virtual ~wxToolBarTool(); | |
107 | ||
108 | // accessors | |
109 | void SetWidget(Widget widget) { m_widget = widget; } | |
110 | Widget GetButtonWidget() const { return m_widget; } | |
111 | ||
aae91497 MB |
112 | Pixmap GetArmPixmap() |
113 | { | |
114 | m_bitmapCache.SetBitmap( GetNormalBitmap() ); | |
115 | return (Pixmap)m_bitmapCache.GetArmPixmap( (WXWidget)m_widget ); | |
116 | } | |
8a0681f9 | 117 | |
aae91497 MB |
118 | Pixmap GetInsensPixmap() |
119 | { | |
120 | m_bitmapCache.SetBitmap( GetNormalBitmap() ); | |
121 | return (Pixmap)m_bitmapCache.GetInsensPixmap( (WXWidget)m_widget ); | |
122 | } | |
8a0681f9 VZ |
123 | protected: |
124 | void Init(); | |
125 | ||
126 | Widget m_widget; | |
aae91497 | 127 | wxBitmapCache m_bitmapCache; |
8a0681f9 VZ |
128 | }; |
129 | ||
130 | // ---------------------------------------------------------------------------- | |
131 | // globals | |
132 | // ---------------------------------------------------------------------------- | |
133 | ||
1a3ac83f JS |
134 | static wxToolBarTimer* wxTheToolBarTimer = (wxToolBarTimer*) NULL; |
135 | ||
136 | Widget wxToolBarTimer::help_popup = (Widget) 0; | |
137 | Widget wxToolBarTimer::buttonWidget = (Widget) 0; | |
8a0681f9 VZ |
138 | wxString wxToolBarTimer::helpString; |
139 | ||
140 | // ============================================================================ | |
141 | // implementation | |
142 | // ============================================================================ | |
143 | ||
144 | // ---------------------------------------------------------------------------- | |
145 | // wxToolBarTool | |
146 | // ---------------------------------------------------------------------------- | |
147 | ||
982b2cfc | 148 | wxToolBarToolBase *wxToolBar::CreateTool(int id, |
fcb35b5f VZ |
149 | const wxString& label, |
150 | const wxBitmap& bmpNormal, | |
151 | const wxBitmap& bmpToggled, | |
152 | wxItemKind kind, | |
982b2cfc | 153 | wxObject *clientData, |
fcb35b5f VZ |
154 | const wxString& shortHelp, |
155 | const wxString& longHelp) | |
8a0681f9 | 156 | { |
fcb35b5f VZ |
157 | return new wxToolBarTool(this, id, label, bmpNormal, bmpToggled, kind, |
158 | clientData, shortHelp, longHelp); | |
8a0681f9 | 159 | } |
1a3ac83f | 160 | |
fcb35b5f | 161 | |
07d02e9e VZ |
162 | wxToolBarToolBase * |
163 | wxToolBar::CreateTool(wxControl *control, const wxString& label) | |
4bb6408c | 164 | { |
07d02e9e | 165 | return new wxToolBarTool(this, control, label); |
4bb6408c JS |
166 | } |
167 | ||
8a0681f9 VZ |
168 | void wxToolBarTool::Init() |
169 | { | |
170 | m_widget = (Widget)0; | |
8a0681f9 VZ |
171 | } |
172 | ||
173 | wxToolBarTool::~wxToolBarTool() | |
174 | { | |
982b2cfc VZ |
175 | if ( m_widget ) |
176 | XtDestroyWidget(m_widget); | |
8a0681f9 VZ |
177 | } |
178 | ||
179 | // ---------------------------------------------------------------------------- | |
180 | // wxToolBar construction | |
181 | // ---------------------------------------------------------------------------- | |
182 | ||
183 | void 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 | ||
197 | bool 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 | |
d408730c VZ |
208 | FixupStyle(); |
209 | ||
a756f210 | 210 | m_backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE); |
4bb6408c | 211 | |
0d57be45 JS |
212 | Widget parentWidget = (Widget) parent->GetClientWidget(); |
213 | ||
214 | Widget toolbar = XtVaCreateManagedWidget("toolbar", | |
7fe7d506 JS |
215 | xmBulletinBoardWidgetClass, (Widget) parentWidget, |
216 | XmNmarginWidth, 0, | |
217 | XmNmarginHeight, 0, | |
218 | XmNresizePolicy, XmRESIZE_NONE, | |
219 | NULL); | |
220 | /* | |
221 | Widget toolbar = XtVaCreateManagedWidget("toolbar", | |
222 | xmFormWidgetClass, (Widget) m_clientWidget, | |
0d57be45 JS |
223 | XmNtraversalOn, False, |
224 | XmNhorizontalSpacing, 0, | |
225 | XmNverticalSpacing, 0, | |
1a3ac83f JS |
226 | XmNleftOffset, 0, |
227 | XmNrightOffset, 0, | |
228 | XmNmarginWidth, 0, | |
229 | XmNmarginHeight, 0, | |
0d57be45 | 230 | NULL); |
7fe7d506 | 231 | */ |
0d57be45 JS |
232 | |
233 | m_mainWidget = (WXWidget) toolbar; | |
234 | ||
96be256b | 235 | ChangeFont(false); |
4b5f3fe6 | 236 | |
46675b46 MB |
237 | wxPoint rPos = pos; |
238 | wxSize rSize = size; | |
239 | ||
240 | if( rPos.x == -1 ) rPos.x = 0; | |
241 | if( rPos.y == -1 ) rPos.y = 0; | |
242 | if( rSize.x == -1 && GetParent() ) | |
243 | rSize.x = GetParent()->GetSize().x; | |
244 | ||
46675b46 MB |
245 | AttachWidget (parent, m_mainWidget, (WXWidget) NULL, |
246 | rPos.x, rPos.y, rSize.x, rSize.y); | |
0d57be45 | 247 | |
0d57be45 | 248 | ChangeBackgroundColour(); |
bf6c2b35 | 249 | |
96be256b | 250 | return true; |
4bb6408c JS |
251 | } |
252 | ||
253 | wxToolBar::~wxToolBar() | |
254 | { | |
1a3ac83f JS |
255 | delete wxTheToolBarTimer; |
256 | wxTheToolBarTimer = NULL; | |
4bb6408c JS |
257 | } |
258 | ||
8a0681f9 | 259 | bool wxToolBar::Realize() |
7fe7d506 | 260 | { |
8a0681f9 VZ |
261 | if ( m_tools.GetCount() == 0 ) |
262 | { | |
263 | // nothing to do | |
96be256b | 264 | return true; |
8a0681f9 | 265 | } |
7fe7d506 | 266 | |
46675b46 MB |
267 | bool isVertical = GetWindowStyle() & wxTB_VERTICAL; |
268 | ||
7fe7d506 JS |
269 | // Separator spacing |
270 | const int separatorSize = GetToolSeparation(); // 8; | |
271 | wxSize margins = GetToolMargins(); | |
f3979fcc | 272 | int packing = GetToolPacking(); |
7fe7d506 JS |
273 | int marginX = margins.x; |
274 | int marginY = margins.y; | |
275 | ||
276 | int currentX = marginX; | |
277 | int currentY = marginY; | |
278 | ||
46675b46 | 279 | int buttonHeight = 0, buttonWidth = 0; |
7fe7d506 | 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 | { |
3e0071d9 | 385 | WXPixel backgroundPixel; |
8a0681f9 | 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) | |
3e0071d9 | 408 | WXPixel backgroundPixel; |
8a0681f9 VZ |
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 | } | |
355b4d3d | 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 | ||
8a0681f9 | 473 | break; |
7fe7d506 | 474 | } |
8a0681f9 VZ |
475 | |
476 | node = node->GetNext(); | |
7fe7d506 JS |
477 | } |
478 | ||
46675b46 | 479 | SetSize( -1, -1, |
aae91497 MB |
480 | isVertical ? buttonWidth + 2 * marginX : -1, |
481 | isVertical ? -1 : buttonHeight + 2*marginY ); | |
7fe7d506 | 482 | |
96be256b | 483 | return true; |
7fe7d506 JS |
484 | } |
485 | ||
982b2cfc VZ |
486 | wxToolBarToolBase *wxToolBar::FindToolForPosition(wxCoord WXUNUSED(x), |
487 | wxCoord WXUNUSED(y)) const | |
4bb6408c | 488 | { |
8a0681f9 | 489 | wxFAIL_MSG( _T("TODO") ); |
4b5f3fe6 | 490 | |
982b2cfc | 491 | return (wxToolBarToolBase *)NULL; |
4bb6408c JS |
492 | } |
493 | ||
982b2cfc | 494 | bool wxToolBar::DoInsertTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
4bb6408c | 495 | { |
8a0681f9 | 496 | tool->Attach(this); |
4bb6408c | 497 | |
96be256b | 498 | return true; |
4bb6408c JS |
499 | } |
500 | ||
355b4d3d | 501 | bool wxToolBar::DoDeleteTool(size_t WXUNUSED(pos), wxToolBarToolBase *tool) |
4bb6408c | 502 | { |
8a0681f9 | 503 | tool->Detach(); |
0d57be45 | 504 | |
aae91497 MB |
505 | bool isVertical = GetWindowStyle() & wxTB_VERTICAL; |
506 | const int separatorSize = GetToolSeparation(); // 8; | |
507 | int packing = GetToolPacking(); | |
508 | int offset = 0; | |
509 | ||
ac32ba44 | 510 | for( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
aae91497 MB |
511 | node; node = node->GetNext() ) |
512 | { | |
513 | wxToolBarTool *t = (wxToolBarTool*)node->GetData(); | |
514 | ||
515 | if( t == tool ) | |
516 | { | |
517 | switch ( t->GetStyle() ) | |
518 | { | |
519 | case wxTOOL_STYLE_CONTROL: | |
520 | { | |
521 | wxSize size = t->GetControl()->GetSize(); | |
522 | offset = isVertical ? size.y : size.x; | |
523 | offset += packing; | |
524 | break; | |
355b4d3d | 525 | } |
aae91497 MB |
526 | case wxTOOL_STYLE_SEPARATOR: |
527 | offset = isVertical ? 0 : separatorSize; | |
528 | break; | |
529 | case wxTOOL_STYLE_BUTTON: | |
530 | { | |
531 | Widget w = t->GetButtonWidget(); | |
532 | Dimension width, height; | |
533 | ||
534 | XtVaGetValues( w, | |
535 | XmNwidth, &width, | |
536 | XmNheight, &height, | |
537 | NULL ); | |
538 | ||
539 | offset = isVertical ? height : width; | |
540 | offset += packing; | |
541 | break; | |
542 | } | |
543 | } | |
544 | } | |
545 | else if( offset ) | |
546 | { | |
547 | switch ( t->GetStyle() ) | |
548 | { | |
549 | case wxTOOL_STYLE_CONTROL: | |
550 | { | |
355b4d3d | 551 | wxPoint location = t->GetControl()->GetPosition(); |
aae91497 MB |
552 | |
553 | if( isVertical ) | |
355b4d3d | 554 | location.y -= offset; |
aae91497 | 555 | else |
355b4d3d | 556 | location.x -= offset; |
aae91497 | 557 | |
355b4d3d | 558 | t->GetControl()->Move( location ); |
aae91497 MB |
559 | break; |
560 | } | |
561 | case wxTOOL_STYLE_SEPARATOR: | |
562 | break; | |
563 | case wxTOOL_STYLE_BUTTON: | |
564 | { | |
565 | Dimension x, y; | |
566 | XtVaGetValues( t->GetButtonWidget(), | |
567 | XmNx, &x, | |
568 | XmNy, &y, | |
569 | NULL ); | |
570 | ||
571 | if( isVertical ) | |
355b4d3d | 572 | y = (Dimension)(y - offset); |
aae91497 | 573 | else |
355b4d3d | 574 | x = (Dimension)(x - offset); |
aae91497 MB |
575 | |
576 | XtVaSetValues( t->GetButtonWidget(), | |
577 | XmNx, x, | |
578 | XmNy, y, | |
579 | NULL ); | |
580 | break; | |
581 | } | |
582 | } | |
583 | } | |
584 | } | |
585 | ||
96be256b | 586 | return true; |
4bb6408c JS |
587 | } |
588 | ||
982b2cfc | 589 | void wxToolBar::DoEnableTool(wxToolBarToolBase *toolBase, bool enable) |
1a3ac83f | 590 | { |
982b2cfc | 591 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
6707bb94 MB |
592 | if (tool->GetButtonWidget()){ |
593 | XtSetSensitive(tool->GetButtonWidget(), (Boolean) enable); | |
594 | } else if (wxTOOL_STYLE_CONTROL == tool->GetStyle()){ | |
595 | // Controls (such as wxChoice) do not have button widgets | |
596 | tool->GetControl()->Enable(enable); | |
597 | } | |
1a3ac83f JS |
598 | } |
599 | ||
982b2cfc | 600 | void wxToolBar::DoToggleTool(wxToolBarToolBase *toolBase, bool toggle) |
4bb6408c | 601 | { |
982b2cfc VZ |
602 | wxToolBarTool *tool = (wxToolBarTool *)toolBase; |
603 | ||
8a0681f9 | 604 | XmToggleButtonSetState(tool->GetButtonWidget(), (Boolean) toggle, False); |
4bb6408c JS |
605 | } |
606 | ||
982b2cfc VZ |
607 | void wxToolBar::DoSetToggle(wxToolBarToolBase * WXUNUSED(tool), |
608 | bool WXUNUSED(toggle)) | |
1a3ac83f | 609 | { |
982b2cfc | 610 | // nothing to do |
1a3ac83f JS |
611 | } |
612 | ||
46675b46 MB |
613 | void wxToolBar::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
614 | { | |
615 | int old_width, old_height; | |
616 | GetSize(&old_width, &old_height); | |
617 | ||
46675b46 MB |
618 | // Correct width and height if needed. |
619 | if ( width == -1 || height == -1 ) | |
620 | { | |
aae91497 | 621 | wxSize defaultSize = GetSize(); |
46675b46 MB |
622 | |
623 | if ( width == -1 ) | |
aae91497 | 624 | width = defaultSize.x; |
46675b46 | 625 | if ( height == -1 ) |
aae91497 | 626 | height = defaultSize.y; |
46675b46 | 627 | } |
aae91497 MB |
628 | |
629 | wxToolBarBase::DoSetSize(x, y, width, height, sizeFlags); | |
355b4d3d | 630 | |
46675b46 MB |
631 | // We must refresh the frame size when the toolbar changes size |
632 | // otherwise the toolbar can be shown incorrectly | |
633 | if ( old_width != width || old_height != height ) | |
634 | { | |
355b4d3d | 635 | // But before we send the size event check it |
46675b46 MB |
636 | // we have a frame that is not being deleted. |
637 | wxFrame *frame = wxDynamicCast(GetParent(), wxFrame); | |
638 | if ( frame && !frame->IsBeingDeleted() ) | |
639 | { | |
640 | frame->SendSizeEvent(); | |
641 | } | |
642 | } | |
643 | } | |
644 | ||
8a0681f9 VZ |
645 | // ---------------------------------------------------------------------------- |
646 | // Motif callbacks | |
647 | // ---------------------------------------------------------------------------- | |
1a3ac83f | 648 | |
982b2cfc | 649 | wxToolBarToolBase *wxToolBar::FindToolByWidget(WXWidget w) const |
7fe7d506 | 650 | { |
ac32ba44 | 651 | wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst(); |
8a0681f9 VZ |
652 | while ( node ) |
653 | { | |
654 | wxToolBarTool *tool = (wxToolBarTool *)node->GetData(); | |
655 | if ( tool->GetButtonWidget() == w) | |
656 | { | |
657 | return tool; | |
658 | } | |
7fe7d506 | 659 | |
8a0681f9 VZ |
660 | node = node->GetNext(); |
661 | } | |
7fe7d506 | 662 | |
982b2cfc | 663 | return (wxToolBarToolBase *)NULL; |
7fe7d506 JS |
664 | } |
665 | ||
8a0681f9 VZ |
666 | static void wxToolButtonCallback(Widget w, |
667 | XtPointer clientData, | |
668 | XtPointer WXUNUSED(ptr)) | |
1a3ac83f JS |
669 | { |
670 | wxToolBar *toolBar = (wxToolBar *) clientData; | |
982b2cfc | 671 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
8a0681f9 VZ |
672 | if ( !tool ) |
673 | return; | |
1a3ac83f | 674 | |
8a0681f9 VZ |
675 | if ( tool->CanBeToggled() ) |
676 | tool->Toggle(); | |
677 | ||
678 | if ( !toolBar->OnLeftClick(tool->GetId(), tool->IsToggled()) ) | |
1a3ac83f | 679 | { |
8a0681f9 VZ |
680 | // revert |
681 | tool->Toggle(); | |
1a3ac83f | 682 | } |
1a3ac83f JS |
683 | } |
684 | ||
1a3ac83f | 685 | |
8a0681f9 VZ |
686 | static void wxToolButtonPopupCallback(Widget w, |
687 | XtPointer client_data, | |
688 | XEvent *event, | |
689 | Boolean *WXUNUSED(continue_to_dispatch)) | |
1a3ac83f JS |
690 | { |
691 | // TODO: retrieve delay before popping up tooltip from wxSystemSettings. | |
8a0681f9 | 692 | static const int delayMilli = 800; |
1a3ac83f | 693 | |
8a0681f9 | 694 | wxToolBar* toolBar = (wxToolBar*) client_data; |
982b2cfc | 695 | wxToolBarToolBase *tool = toolBar->FindToolByWidget((WXWidget) w); |
1a3ac83f | 696 | |
8a0681f9 VZ |
697 | if ( !tool ) |
698 | return; | |
1a3ac83f | 699 | |
8a0681f9 VZ |
700 | wxString tooltip = tool->GetShortHelp(); |
701 | if ( !tooltip ) | |
702 | return; | |
1a3ac83f | 703 | |
8a0681f9 VZ |
704 | if (!wxTheToolBarTimer) |
705 | wxTheToolBarTimer = new wxToolBarTimer; | |
1a3ac83f | 706 | |
8a0681f9 VZ |
707 | wxToolBarTimer::buttonWidget = w; |
708 | wxToolBarTimer::helpString = tooltip; | |
1a3ac83f JS |
709 | |
710 | /************************************************************/ | |
711 | /* Popup help label */ | |
712 | /************************************************************/ | |
713 | if (event->type == EnterNotify) | |
714 | { | |
715 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
716 | { | |
717 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
718 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 719 | } |
1a3ac83f JS |
720 | wxToolBarTimer::help_popup = (Widget) 0; |
721 | ||
722 | // One shot | |
96be256b | 723 | wxTheToolBarTimer->Start(delayMilli, true); |
1a3ac83f JS |
724 | |
725 | } | |
726 | /************************************************************/ | |
727 | /* Popdown help label */ | |
728 | /************************************************************/ | |
729 | else if (event->type == LeaveNotify) | |
730 | { | |
731 | if (wxTheToolBarTimer) | |
732 | wxTheToolBarTimer->Stop(); | |
733 | if (wxToolBarTimer::help_popup != (Widget) 0) | |
734 | { | |
735 | XtDestroyWidget (wxToolBarTimer::help_popup); | |
736 | XtPopdown (wxToolBarTimer::help_popup); | |
bf6c2b35 | 737 | } |
1a3ac83f JS |
738 | wxToolBarTimer::help_popup = (Widget) 0; |
739 | } | |
1a3ac83f JS |
740 | } |
741 | ||
742 | void wxToolBarTimer::Notify() | |
743 | { | |
744 | Position x, y; | |
745 | ||
746 | /************************************************************/ | |
747 | /* Create shell without window decorations */ | |
748 | /************************************************************/ | |
bf6c2b35 VZ |
749 | help_popup = XtVaCreatePopupShell ("shell", |
750 | overrideShellWidgetClass, (Widget) wxTheApp->GetTopLevelWidget(), | |
1a3ac83f JS |
751 | NULL); |
752 | ||
753 | /************************************************************/ | |
754 | /* Get absolute position on display of toolbar button */ | |
755 | /************************************************************/ | |
756 | XtTranslateCoords (buttonWidget, | |
bf6c2b35 VZ |
757 | (Position) 0, |
758 | (Position) 0, | |
1a3ac83f JS |
759 | &x, &y); |
760 | ||
761 | // Move the tooltip more or less above the button | |
762 | int yOffset = 20; // TODO: What should be really? | |
355b4d3d | 763 | y = (Position)(y - yOffset); |
1a3ac83f JS |
764 | if (y < yOffset) y = 0; |
765 | ||
766 | /************************************************************/ | |
767 | /* Set the position of the help popup */ | |
768 | /************************************************************/ | |
bf6c2b35 VZ |
769 | XtVaSetValues (help_popup, |
770 | XmNx, (Position) x, | |
771 | XmNy, (Position) y, | |
1a3ac83f | 772 | NULL); |
bf6c2b35 | 773 | |
1a3ac83f JS |
774 | /************************************************************/ |
775 | /* Create help label */ | |
776 | /************************************************************/ | |
777 | XmString text = XmStringCreateSimple ((char*) (const char*) helpString); | |
bf6c2b35 VZ |
778 | XtVaCreateManagedWidget ("help_label", |
779 | xmLabelWidgetClass, help_popup, | |
1a3ac83f | 780 | XmNlabelString, text, |
bf6c2b35 VZ |
781 | XtVaTypedArg, |
782 | XmNforeground, XtRString, "black", | |
783 | strlen("black")+1, | |
784 | XtVaTypedArg, | |
785 | XmNbackground, XtRString, "LightGoldenrod", | |
786 | strlen("LightGoldenrod")+1, | |
1a3ac83f JS |
787 | NULL); |
788 | XmStringFree (text); | |
789 | ||
790 | /************************************************************/ | |
791 | /* Popup help label */ | |
792 | /************************************************************/ | |
793 | XtPopup (help_popup, XtGrabNone); | |
794 | } |