]>
Commit | Line | Data |
---|---|---|
10b959e3 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbarbase.cpp | |
3 | // Purpose: Toolbar base classes | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tbarbase.h" | |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
24 | #include "wx/wx.h" | |
25 | #endif | |
26 | ||
27 | // For ::UpdateWindow | |
2049ba38 | 28 | #ifdef __WXMSW__ |
10b959e3 JS |
29 | #include <windows.h> |
30 | #endif | |
31 | ||
47d67540 | 32 | #if wxUSE_TOOLBAR |
10b959e3 JS |
33 | |
34 | #include "wx/tbarbase.h" | |
35 | ||
36 | #if !USE_SHARED_LIBRARY | |
81d66cf3 | 37 | IMPLEMENT_ABSTRACT_CLASS(wxToolBarBase, wxControl) |
10b959e3 JS |
38 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool, wxObject) |
39 | ||
40 | BEGIN_EVENT_TABLE(wxToolBarBase, wxControl) | |
41 | EVT_SCROLL(wxToolBarBase::OnScroll) | |
42 | EVT_SIZE(wxToolBarBase::OnSize) | |
43 | EVT_IDLE(wxToolBarBase::OnIdle) | |
44 | END_EVENT_TABLE() | |
45 | #endif | |
46 | ||
47 | // Keep a list of all toolbars created, so you can tell whether a toolbar | |
48 | // is still valid: a tool may have quit the toolbar. | |
49 | static wxList gs_ToolBars; | |
50 | ||
4fcd73bd RR |
51 | #ifdef __WXGTK__ |
52 | wxToolBarTool::wxToolBarTool(wxToolBar *owner, int theIndex, | |
53 | const wxBitmap& theBitmap1, const wxBitmap& theBitmap2, | |
54 | bool toggle, wxObject *clientData, | |
55 | const wxString& helpS1, const wxString& helpS2, | |
56 | GtkWidget *item ) | |
57 | #else | |
debe6624 JS |
58 | wxToolBarTool::wxToolBarTool(int theIndex, |
59 | const wxBitmap& theBitmap1, const wxBitmap& theBitmap2, bool toggle, | |
60 | long xPos, long yPos, const wxString& helpS1, const wxString& helpS2) | |
4fcd73bd | 61 | #endif |
10b959e3 JS |
62 | { |
63 | m_toolStyle = wxTOOL_STYLE_BUTTON; | |
4fcd73bd RR |
64 | #ifdef __WXGTK__ |
65 | m_owner = owner; | |
66 | m_item = item; | |
67 | m_clientData = clientData; | |
68 | m_x = 0; | |
69 | m_y = 0; | |
70 | #else | |
10b959e3 | 71 | m_clientData = NULL; |
4fcd73bd RR |
72 | m_x = xPos; |
73 | m_y = yPos; | |
74 | #endif | |
10b959e3 JS |
75 | m_index = theIndex; |
76 | m_isToggle = toggle; | |
77 | m_toggleState = FALSE; | |
78 | m_enabled = TRUE; | |
79 | m_bitmap1 = theBitmap1; | |
80 | m_bitmap2 = theBitmap2; | |
10b959e3 JS |
81 | m_width = m_height = 0; |
82 | m_deleteSecondBitmap = FALSE; | |
83 | if (m_bitmap1.Ok()) | |
84 | { | |
85 | m_width = m_bitmap1.GetWidth()+2; | |
86 | m_height = m_bitmap1.GetHeight()+2; | |
87 | } | |
88 | m_shortHelpString = helpS1; | |
89 | m_longHelpString = helpS2; | |
90 | } | |
91 | ||
92 | wxToolBarTool::~wxToolBarTool(void) | |
93 | { | |
94 | /* | |
95 | if (m_deleteSecondBitmap && m_bitmap2) | |
96 | delete m_bitmap2; | |
97 | */ | |
98 | } | |
99 | ||
100 | ||
101 | // class wxToolBar | |
102 | ||
103 | wxToolBarBase::wxToolBarBase(void) : m_tools(wxKEY_INTEGER) | |
104 | { | |
105 | gs_ToolBars.Append(this); | |
106 | ||
81d66cf3 JS |
107 | m_maxRows = 1; |
108 | m_maxCols = 32000; | |
10b959e3 JS |
109 | m_maxWidth = 0; |
110 | m_maxHeight = 0; | |
111 | m_defaultWidth = 16; | |
112 | m_defaultHeight = 15; | |
113 | m_xMargin = 0; | |
114 | m_yMargin = 0; | |
115 | m_toolPacking = 1; | |
116 | m_toolSeparation = 5; | |
117 | m_currentTool = -1; | |
118 | ||
119 | m_xScrollPixelsPerLine = 0; | |
120 | m_yScrollPixelsPerLine = 0; | |
121 | m_xScrollingEnabled = TRUE; | |
122 | m_yScrollingEnabled = TRUE; | |
123 | m_xScrollPosition = 0; | |
124 | m_yScrollPosition = 0; | |
125 | m_calcScrolledOffset = TRUE; | |
126 | m_xScrollLines = 0; | |
127 | m_yScrollLines = 0; | |
128 | m_xScrollLinesPerPage = 0; | |
129 | m_yScrollLinesPerPage = 0; | |
130 | } | |
131 | ||
132 | wxToolBarBase::~wxToolBarBase () | |
133 | { | |
134 | gs_ToolBars.DeleteObject(this); | |
135 | ||
136 | for ( wxNode *node = m_tools.First(); node; node = node->Next() ) | |
137 | { | |
138 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
139 | delete tool; | |
140 | } | |
141 | } | |
142 | ||
143 | // Only allow toggle if returns TRUE | |
144 | bool wxToolBarBase::OnLeftClick(int toolIndex, bool toggleDown) | |
145 | { | |
146 | wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, toolIndex); | |
147 | event.SetEventObject(this); | |
148 | event.SetExtraLong((long) toggleDown); | |
149 | ||
150 | GetEventHandler()->ProcessEvent(event); | |
151 | ||
152 | return TRUE; | |
153 | } | |
154 | ||
155 | // Call when right button down. | |
156 | void wxToolBarBase::OnRightClick(int toolIndex, long x, long y) | |
157 | { | |
158 | wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, toolIndex); | |
159 | event.SetEventObject(this); | |
0f217db3 | 160 | event.SetInt(toolIndex); |
10b959e3 JS |
161 | |
162 | GetEventHandler()->ProcessEvent(event); | |
163 | } | |
164 | ||
165 | // Called when the mouse cursor enters a tool bitmap (no button pressed). | |
166 | // Argument is -1 if mouse is exiting the toolbar. | |
81d66cf3 JS |
167 | // Note that for this event, the id of the window is used, |
168 | // and the integer parameter of wxCommandEvent is used to retrieve | |
169 | // the tool id. | |
10b959e3 JS |
170 | void wxToolBarBase::OnMouseEnter ( int toolIndex ) |
171 | { | |
81d66cf3 | 172 | wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, GetId()); |
10b959e3 | 173 | event.SetEventObject(this); |
0f217db3 | 174 | event.SetInt(toolIndex); |
10b959e3 JS |
175 | |
176 | GetEventHandler()->ProcessEvent(event); | |
177 | } | |
178 | ||
179 | // If pushedBitmap is NULL, a reversed version of bitmap is | |
180 | // created and used as the pushed/toggled image. | |
181 | // If toggle is TRUE, the button toggles between the two states. | |
debe6624 JS |
182 | wxToolBarTool *wxToolBarBase::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap, |
183 | bool toggle, long xPos, long yPos, wxObject *clientData, | |
10b959e3 JS |
184 | const wxString& helpString1, const wxString& helpString2) |
185 | { | |
4fcd73bd RR |
186 | #ifdef __WXGTK__ |
187 | wxToolBarTool *tool = new wxToolBarTool( (wxToolBar*)this, index, bitmap, pushedBitmap, toggle, | |
188 | (wxObject*) NULL, helpString1, helpString2); | |
189 | #else | |
10b959e3 | 190 | wxToolBarTool *tool = new wxToolBarTool(index, bitmap, pushedBitmap, toggle, xPos, yPos, helpString1, helpString2); |
4fcd73bd | 191 | #endif |
10b959e3 JS |
192 | tool->m_clientData = clientData; |
193 | ||
194 | if (xPos > -1) | |
195 | tool->m_x = xPos; | |
196 | else | |
197 | tool->m_x = m_xMargin; | |
198 | ||
199 | if (yPos > -1) | |
200 | tool->m_y = yPos; | |
201 | else | |
202 | tool->m_y = m_yMargin; | |
203 | ||
204 | // Calculate reasonable max size in case Layout() not called | |
205 | if ((tool->m_x + bitmap.GetWidth() + m_xMargin) > m_maxWidth) | |
206 | m_maxWidth = (tool->m_x + bitmap.GetWidth() + m_xMargin); | |
207 | ||
208 | if ((tool->m_y + bitmap.GetHeight() + m_yMargin) > m_maxHeight) | |
209 | m_maxHeight = (tool->m_y + bitmap.GetHeight() + m_yMargin); | |
210 | ||
211 | m_tools.Append((long)index, tool); | |
212 | return tool; | |
213 | } | |
214 | ||
215 | void wxToolBarBase::AddSeparator () | |
216 | { | |
217 | wxToolBarTool *tool = new wxToolBarTool; | |
218 | tool->m_toolStyle = wxTOOL_STYLE_SEPARATOR; | |
fd3f686c | 219 | m_tools.Append(-1, tool); |
10b959e3 JS |
220 | } |
221 | ||
222 | void wxToolBarBase::ClearTools(void) | |
223 | { | |
224 | m_pressedTool = m_currentTool = -1; | |
225 | wxNode *node = m_tools.First(); | |
226 | while (node) | |
227 | { | |
228 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
229 | wxNode *nextNode = node->Next(); | |
230 | delete tool; | |
231 | delete node; | |
232 | node = nextNode; | |
233 | } | |
234 | } | |
235 | ||
debe6624 | 236 | void wxToolBarBase::EnableTool(int index, bool enable) |
10b959e3 JS |
237 | { |
238 | wxNode *node = m_tools.Find((long)index); | |
239 | if (node) | |
240 | { | |
241 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
242 | if (tool) | |
243 | tool->m_enabled = enable; | |
244 | } | |
245 | } | |
246 | ||
debe6624 | 247 | void wxToolBarBase::ToggleTool(int index, bool toggle) |
10b959e3 JS |
248 | { |
249 | } | |
250 | ||
debe6624 | 251 | void wxToolBarBase::SetToggle(int index, bool value) |
10b959e3 JS |
252 | { |
253 | wxNode *node=m_tools.Find((long)index); | |
254 | if (node){ | |
255 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
256 | tool->m_isToggle = value; | |
257 | } | |
258 | } | |
259 | ||
debe6624 | 260 | bool wxToolBarBase::GetToolState(int index) const |
10b959e3 JS |
261 | { |
262 | wxNode *node = m_tools.Find((long)index); | |
263 | if (node) | |
264 | { | |
265 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
266 | if (tool) | |
267 | { | |
268 | return tool->m_toggleState; | |
269 | } | |
270 | else return FALSE; | |
271 | } | |
272 | else return FALSE; | |
273 | } | |
274 | ||
debe6624 | 275 | bool wxToolBarBase::GetToolEnabled(int index) const |
10b959e3 JS |
276 | { |
277 | wxNode *node = m_tools.Find((long)index); | |
278 | if (node) | |
279 | { | |
280 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
281 | if (tool) | |
282 | { | |
283 | return tool->m_enabled; | |
284 | } | |
285 | else return FALSE; | |
286 | } | |
287 | else return FALSE; | |
288 | } | |
289 | ||
debe6624 | 290 | wxObject *wxToolBarBase::GetToolClientData(int index) const |
10b959e3 JS |
291 | { |
292 | wxNode *node = m_tools.Find((long)index); | |
293 | if (node) | |
294 | { | |
295 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
296 | if (tool) | |
297 | { | |
298 | return tool->m_clientData; | |
299 | } | |
300 | else return NULL; | |
301 | } | |
302 | else return NULL; | |
303 | } | |
304 | ||
debe6624 | 305 | void wxToolBarBase::SetToolShortHelp(int index, const wxString& helpString) |
10b959e3 JS |
306 | { |
307 | wxNode *node=m_tools.Find((long)index); | |
308 | if (node) | |
309 | { | |
310 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
311 | tool->m_shortHelpString = helpString; | |
312 | } | |
313 | } | |
314 | ||
debe6624 | 315 | wxString wxToolBarBase::GetToolShortHelp(int index) const |
10b959e3 JS |
316 | { |
317 | wxNode *node=m_tools.Find((long)index); | |
318 | if (node) | |
319 | { | |
320 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
321 | return tool->m_shortHelpString; | |
322 | } | |
323 | else | |
324 | return wxString(""); | |
325 | } | |
326 | ||
debe6624 | 327 | void wxToolBarBase::SetToolLongHelp(int index, const wxString& helpString) |
10b959e3 JS |
328 | { |
329 | wxNode *node=m_tools.Find((long)index); | |
330 | if (node) | |
331 | { | |
332 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
333 | tool->m_longHelpString = helpString; | |
334 | } | |
335 | } | |
336 | ||
debe6624 | 337 | wxString wxToolBarBase::GetToolLongHelp(int index) const |
10b959e3 JS |
338 | { |
339 | wxNode *node=m_tools.Find((long)index); | |
340 | if (node) | |
341 | { | |
342 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
343 | return tool->m_longHelpString; | |
344 | } | |
345 | else | |
346 | return wxString(""); | |
347 | } | |
348 | ||
debe6624 | 349 | wxToolBarTool *wxToolBarBase::FindToolForPosition(long x, long y) const |
10b959e3 JS |
350 | { |
351 | wxNode *node = m_tools.First(); | |
352 | while (node) | |
353 | { | |
354 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
355 | if ((x >= tool->m_x) && (y >= tool->m_y) && | |
356 | (x <= (tool->m_x + tool->GetWidth())) && | |
357 | (y <= (tool->m_y + tool->GetHeight()))) | |
358 | return tool; | |
359 | ||
360 | node = node->Next(); | |
361 | } | |
362 | return NULL; | |
363 | } | |
364 | ||
365 | wxSize wxToolBarBase::GetMaxSize ( void ) const | |
366 | { | |
367 | return wxSize(m_maxWidth, m_maxHeight); | |
368 | } | |
369 | ||
370 | // Okay, so we've left the tool we're in ... we must check if | |
371 | // the tool we're leaving was a 'sprung push button' and if so, | |
372 | // spring it back to the up state. | |
373 | // | |
debe6624 | 374 | void wxToolBarBase::SetMargins(int x, int y) |
10b959e3 JS |
375 | { |
376 | m_xMargin = x; | |
377 | m_yMargin = y; | |
378 | } | |
379 | ||
debe6624 | 380 | void wxToolBarBase::SetToolPacking(int packing) |
10b959e3 JS |
381 | { |
382 | m_toolPacking = packing; | |
383 | } | |
384 | ||
debe6624 | 385 | void wxToolBarBase::SetToolSeparation(int separation) |
10b959e3 JS |
386 | { |
387 | m_toolSeparation = separation; | |
388 | } | |
389 | ||
390 | void wxToolBarBase::Command(wxCommandEvent& event) | |
391 | { | |
392 | } | |
393 | ||
394 | void wxToolBarBase::Layout(void) | |
395 | { | |
10b959e3 JS |
396 | } |
397 | ||
398 | ||
399 | // SCROLLING IMPLEMENTATION | |
400 | ||
401 | /* | |
402 | * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line) | |
403 | * noUnitsX/noUnitsY: : no. units per scrollbar | |
404 | */ | |
debe6624 JS |
405 | void wxToolBarBase::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, |
406 | int noUnitsX, int noUnitsY, | |
407 | int xPos, int yPos) | |
10b959e3 JS |
408 | { |
409 | m_xScrollPixelsPerLine = pixelsPerUnitX; | |
410 | m_yScrollPixelsPerLine = pixelsPerUnitY; | |
411 | m_xScrollLines = noUnitsX; | |
412 | m_yScrollLines = noUnitsY; | |
413 | ||
414 | int w, h; | |
415 | GetSize(&w, &h); | |
416 | ||
417 | // Recalculate scroll bar range and position | |
418 | if (m_xScrollLines > 0) | |
419 | { | |
420 | m_xScrollPosition = xPos; | |
421 | SetScrollPos (wxHORIZONTAL, m_xScrollPosition, TRUE); | |
422 | } | |
423 | else | |
424 | { | |
425 | SetScrollbar(wxHORIZONTAL, 0, 0, 0, FALSE); | |
426 | m_xScrollPosition = 0; | |
427 | } | |
428 | ||
429 | if (m_yScrollLines > 0) | |
430 | { | |
431 | m_yScrollPosition = yPos; | |
432 | SetScrollPos (wxVERTICAL, m_yScrollPosition, TRUE); | |
433 | } | |
434 | else | |
435 | { | |
436 | SetScrollbar(wxVERTICAL, 0, 0, 0, FALSE); | |
437 | m_yScrollPosition = 0; | |
438 | } | |
439 | AdjustScrollbars(); | |
440 | Refresh(); | |
2049ba38 | 441 | #ifdef __WXMSW__ |
10b959e3 JS |
442 | ::UpdateWindow ((HWND) GetHWND()); |
443 | #endif | |
444 | } | |
445 | ||
446 | ||
447 | void wxToolBarBase::OnScroll(wxScrollEvent& event) | |
448 | { | |
449 | int orient = event.GetOrientation(); | |
450 | ||
451 | int nScrollInc = CalcScrollInc(event); | |
452 | if (nScrollInc == 0) | |
453 | return; | |
454 | ||
455 | if (orient == wxHORIZONTAL) | |
456 | { | |
457 | int newPos = m_xScrollPosition + nScrollInc; | |
458 | SetScrollPos(wxHORIZONTAL, newPos, TRUE ); | |
459 | } | |
460 | else | |
461 | { | |
462 | int newPos = m_yScrollPosition + nScrollInc; | |
463 | SetScrollPos(wxVERTICAL, newPos, TRUE ); | |
464 | } | |
465 | ||
466 | if (orient == wxHORIZONTAL) | |
467 | { | |
468 | if (m_xScrollingEnabled) | |
469 | ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, NULL); | |
470 | else | |
471 | Refresh(); | |
472 | } | |
473 | else | |
474 | { | |
475 | if (m_yScrollingEnabled) | |
476 | ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, NULL); | |
477 | else | |
478 | Refresh(); | |
479 | } | |
480 | ||
481 | if (orient == wxHORIZONTAL) | |
482 | { | |
483 | m_xScrollPosition += nScrollInc; | |
484 | } | |
485 | else | |
486 | { | |
487 | m_yScrollPosition += nScrollInc; | |
488 | } | |
489 | ||
490 | } | |
491 | ||
492 | int wxToolBarBase::CalcScrollInc(wxScrollEvent& event) | |
493 | { | |
494 | int pos = event.GetPosition(); | |
495 | int orient = event.GetOrientation(); | |
496 | ||
497 | int nScrollInc = 0; | |
498 | switch (event.GetEventType()) | |
499 | { | |
0757d27c | 500 | case wxEVT_SCROLL_TOP: |
10b959e3 JS |
501 | { |
502 | if (orient == wxHORIZONTAL) | |
503 | nScrollInc = - m_xScrollPosition; | |
504 | else | |
505 | nScrollInc = - m_yScrollPosition; | |
506 | break; | |
507 | } | |
0757d27c | 508 | case wxEVT_SCROLL_BOTTOM: |
10b959e3 JS |
509 | { |
510 | if (orient == wxHORIZONTAL) | |
511 | nScrollInc = m_xScrollLines - m_xScrollPosition; | |
512 | else | |
513 | nScrollInc = m_yScrollLines - m_yScrollPosition; | |
514 | break; | |
515 | } | |
0757d27c | 516 | case wxEVT_SCROLL_LINEUP: |
10b959e3 JS |
517 | { |
518 | nScrollInc = -1; | |
519 | break; | |
520 | } | |
0757d27c | 521 | case wxEVT_SCROLL_LINEDOWN: |
10b959e3 JS |
522 | { |
523 | nScrollInc = 1; | |
524 | break; | |
525 | } | |
0757d27c | 526 | case wxEVT_SCROLL_PAGEUP: |
10b959e3 JS |
527 | { |
528 | if (orient == wxHORIZONTAL) | |
529 | nScrollInc = -GetScrollPageSize(wxHORIZONTAL); | |
530 | else | |
531 | nScrollInc = -GetScrollPageSize(wxVERTICAL); | |
532 | break; | |
533 | } | |
0757d27c | 534 | case wxEVT_SCROLL_PAGEDOWN: |
10b959e3 JS |
535 | { |
536 | if (orient == wxHORIZONTAL) | |
537 | nScrollInc = GetScrollPageSize(wxHORIZONTAL); | |
538 | else | |
539 | nScrollInc = GetScrollPageSize(wxVERTICAL); | |
540 | break; | |
541 | } | |
0757d27c | 542 | case wxEVT_SCROLL_THUMBTRACK: |
10b959e3 JS |
543 | { |
544 | if (orient == wxHORIZONTAL) | |
545 | nScrollInc = pos - m_xScrollPosition; | |
546 | else | |
547 | nScrollInc = pos - m_yScrollPosition; | |
548 | break; | |
549 | } | |
550 | default: | |
551 | { | |
552 | break; | |
553 | } | |
554 | } | |
555 | if (orient == wxHORIZONTAL) | |
556 | { | |
557 | int w, h; | |
558 | GetClientSize(&w, &h); | |
559 | ||
560 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
561 | int noPositions = (int) ( ((nMaxWidth - w)/(float)m_xScrollPixelsPerLine) + 0.5 ); | |
562 | if (noPositions < 0) | |
563 | noPositions = 0; | |
564 | ||
565 | if ( (m_xScrollPosition + nScrollInc) < 0 ) | |
566 | nScrollInc = -m_xScrollPosition; // As -ve as we can go | |
567 | else if ( (m_xScrollPosition + nScrollInc) > noPositions ) | |
568 | nScrollInc = noPositions - m_xScrollPosition; // As +ve as we can go | |
569 | ||
570 | return nScrollInc; | |
571 | } | |
572 | else | |
573 | { | |
574 | int w, h; | |
575 | GetClientSize(&w, &h); | |
576 | ||
577 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; | |
578 | int noPositions = (int) ( ((nMaxHeight - h)/(float)m_yScrollPixelsPerLine) + 0.5 ); | |
579 | if (noPositions < 0) | |
580 | noPositions = 0; | |
581 | ||
582 | if ( (m_yScrollPosition + nScrollInc) < 0 ) | |
583 | nScrollInc = -m_yScrollPosition; // As -ve as we can go | |
584 | else if ( (m_yScrollPosition + nScrollInc) > noPositions ) | |
585 | nScrollInc = noPositions - m_yScrollPosition; // As +ve as we can go | |
586 | ||
587 | return nScrollInc; | |
588 | } | |
589 | } | |
590 | ||
591 | // Adjust the scrollbars - new version. | |
592 | void wxToolBarBase::AdjustScrollbars(void) | |
593 | { | |
594 | int w, h; | |
595 | GetClientSize(&w, &h); | |
596 | ||
597 | // Recalculate scroll bar range and position | |
598 | if (m_xScrollLines > 0) | |
599 | { | |
600 | int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine; | |
601 | int newRange = (int) ( ((nMaxWidth)/(float)m_xScrollPixelsPerLine) + 0.5 ); | |
602 | if (newRange < 0) | |
603 | newRange = 0; | |
604 | ||
605 | m_xScrollPosition = wxMin(newRange, m_xScrollPosition); | |
606 | ||
607 | // Calculate page size i.e. number of scroll units you get on the | |
608 | // current client window | |
609 | int noPagePositions = (int) ( (w/(float)m_xScrollPixelsPerLine) + 0.5 ); | |
610 | if (noPagePositions < 1) | |
611 | noPagePositions = 1; | |
612 | ||
613 | SetScrollbar(wxHORIZONTAL, m_xScrollPosition, noPagePositions, newRange); | |
614 | SetScrollPageSize(wxHORIZONTAL, noPagePositions); | |
615 | } | |
616 | if (m_yScrollLines > 0) | |
617 | { | |
618 | int nMaxHeight = m_yScrollLines*m_yScrollPixelsPerLine; | |
619 | int newRange = (int) ( ((nMaxHeight)/(float)m_yScrollPixelsPerLine) + 0.5 ); | |
620 | if (newRange < 0) | |
621 | newRange = 0; | |
622 | ||
623 | m_yScrollPosition = wxMin(newRange, m_yScrollPosition); | |
624 | ||
625 | // Calculate page size i.e. number of scroll units you get on the | |
626 | // current client window | |
627 | int noPagePositions = (int) ( (h/(float)m_yScrollPixelsPerLine) + 0.5 ); | |
628 | if (noPagePositions < 1) | |
629 | noPagePositions = 1; | |
630 | ||
631 | SetScrollbar(wxVERTICAL, m_yScrollPosition, noPagePositions, newRange); | |
632 | SetScrollPageSize(wxVERTICAL, noPagePositions); | |
633 | } | |
634 | } | |
635 | ||
636 | // Default OnSize resets scrollbars, if any | |
637 | void wxToolBarBase::OnSize(wxSizeEvent& event) | |
638 | { | |
47d67540 | 639 | #if wxUSE_CONSTRAINTS |
10b959e3 JS |
640 | if (GetAutoLayout()) |
641 | Layout(); | |
642 | #endif | |
643 | ||
644 | AdjustScrollbars(); | |
645 | } | |
646 | ||
647 | // Prepare the DC by translating it according to the current scroll position | |
648 | void wxToolBarBase::PrepareDC(wxDC& dc) | |
649 | { | |
650 | dc.SetDeviceOrigin(- m_xScrollPosition * m_xScrollPixelsPerLine, - m_yScrollPosition * m_yScrollPixelsPerLine); | |
651 | } | |
652 | ||
653 | void wxToolBarBase::GetScrollPixelsPerUnit (int *x_unit, int *y_unit) const | |
654 | { | |
655 | *x_unit = m_xScrollPixelsPerLine; | |
656 | *y_unit = m_yScrollPixelsPerLine; | |
657 | } | |
658 | ||
659 | int wxToolBarBase::GetScrollPageSize(int orient) const | |
660 | { | |
661 | if ( orient == wxHORIZONTAL ) | |
662 | return m_xScrollLinesPerPage; | |
663 | else | |
664 | return m_yScrollLinesPerPage; | |
665 | } | |
666 | ||
667 | void wxToolBarBase::SetScrollPageSize(int orient, int pageSize) | |
668 | { | |
669 | if ( orient == wxHORIZONTAL ) | |
670 | m_xScrollLinesPerPage = pageSize; | |
671 | else | |
672 | m_yScrollLinesPerPage = pageSize; | |
673 | } | |
674 | ||
675 | /* | |
676 | * Scroll to given position (scroll position, not pixel position) | |
677 | */ | |
debe6624 | 678 | void wxToolBarBase::Scroll (int x_pos, int y_pos) |
10b959e3 JS |
679 | { |
680 | int old_x, old_y; | |
681 | ViewStart (&old_x, &old_y); | |
682 | if (((x_pos == -1) || (x_pos == old_x)) && ((y_pos == -1) || (y_pos == old_y))) | |
683 | return; | |
684 | ||
685 | if (x_pos > -1) | |
686 | { | |
687 | m_xScrollPosition = x_pos; | |
688 | SetScrollPos (wxHORIZONTAL, x_pos, TRUE); | |
689 | } | |
690 | if (y_pos > -1) | |
691 | { | |
692 | m_yScrollPosition = y_pos; | |
693 | SetScrollPos (wxVERTICAL, y_pos, TRUE); | |
694 | } | |
695 | Refresh(); | |
2049ba38 | 696 | #ifdef __WXMSW__ |
10b959e3 JS |
697 | UpdateWindow ((HWND) GetHWND()); |
698 | #endif | |
699 | } | |
700 | ||
debe6624 | 701 | void wxToolBarBase::EnableScrolling (bool x_scroll, bool y_scroll) |
10b959e3 JS |
702 | { |
703 | m_xScrollingEnabled = x_scroll; | |
704 | m_yScrollingEnabled = y_scroll; | |
705 | } | |
706 | ||
707 | void wxToolBarBase::GetVirtualSize (int *x, int *y) const | |
708 | { | |
709 | *x = m_xScrollPixelsPerLine * m_xScrollLines; | |
710 | *y = m_yScrollPixelsPerLine * m_yScrollLines; | |
711 | } | |
712 | ||
713 | // Where the current view starts from | |
714 | void wxToolBarBase::ViewStart (int *x, int *y) const | |
715 | { | |
716 | *x = m_xScrollPosition; | |
717 | *y = m_yScrollPosition; | |
718 | } | |
719 | ||
10b959e3 JS |
720 | void wxToolBarBase::OnIdle(wxIdleEvent& event) |
721 | { | |
4fcd73bd | 722 | #ifndef __WXGTK__ |
43d811ea | 723 | wxWindow::OnIdle(event); |
4fcd73bd | 724 | #endif |
43d811ea | 725 | |
10b959e3 JS |
726 | DoToolbarUpdates(); |
727 | } | |
728 | ||
729 | // Do the toolbar button updates (check for EVT_UPDATE_UI handlers) | |
730 | void wxToolBarBase::DoToolbarUpdates(void) | |
731 | { | |
732 | wxNode* node = GetTools().First(); | |
733 | while (node) | |
734 | { | |
735 | wxToolBarTool* tool = (wxToolBarTool* ) node->Data(); | |
736 | ||
737 | wxUpdateUIEvent event(tool->m_index); | |
738 | event.SetEventObject(this); | |
739 | ||
740 | if (GetEventHandler()->ProcessEvent(event)) | |
741 | { | |
742 | if (event.GetSetEnabled()) | |
743 | EnableTool(tool->m_index, event.GetEnabled()); | |
744 | if (event.GetSetChecked()) | |
745 | ToggleTool(tool->m_index, event.GetChecked()); | |
746 | /* | |
747 | if (event.GetSetText()) | |
748 | // Set tooltip? | |
749 | */ | |
750 | } | |
751 | ||
752 | node = node->Next(); | |
753 | } | |
754 | } | |
755 | ||
2049ba38 | 756 | #ifdef __WXMSW__ |
10b959e3 | 757 | // Circumvent wxControl::MSWOnMouseMove which doesn't set the cursor. |
4d0c0756 | 758 | void wxToolBarBase::MSWOnMouseMove(int x, int y, WXUINT flags) |
10b959e3 JS |
759 | { |
760 | wxWindow::MSWOnMouseMove(x, y, flags); | |
761 | } | |
762 | #endif | |
763 | ||
764 | #endif |