]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/gallery.cpp
Use window position in screen coordinates in wxDisplay::GetFromWindow().
[wxWidgets.git] / src / ribbon / gallery.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/ribbon/gallery.cpp
3 // Purpose: Ribbon control which displays a gallery of items to choose from
4 // Author: Peter Cawley
5 // Modified by:
6 // Created: 2009-07-22
7 // RCS-ID: $Id$
8 // Copyright: (C) Peter Cawley
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_RIBBON
19
20 #include "wx/ribbon/gallery.h"
21 #include "wx/ribbon/art.h"
22 #include "wx/ribbon/bar.h"
23 #include "wx/dcbuffer.h"
24 #include "wx/clntdata.h"
25
26 #ifndef WX_PRECOMP
27 #endif
28
29 #ifdef __WXMSW__
30 #include "wx/msw/private.h"
31 #endif
32
33 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED, wxRibbonGalleryEvent);
34 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, wxRibbonGalleryEvent);
35 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_CLICKED, wxRibbonGalleryEvent);
36
37 IMPLEMENT_DYNAMIC_CLASS(wxRibbonGalleryEvent, wxCommandEvent)
38 IMPLEMENT_CLASS(wxRibbonGallery, wxRibbonControl)
39
40 class wxRibbonGalleryItem
41 {
42 public:
43 wxRibbonGalleryItem()
44 {
45 m_id = 0;
46 m_is_visible = false;
47 }
48
49 void SetId(int id) {m_id = id;}
50 void SetBitmap(const wxBitmap& bitmap) {m_bitmap = bitmap;}
51 const wxBitmap& GetBitmap() const {return m_bitmap;}
52 void SetIsVisible(bool visible) {m_is_visible = visible;}
53 void SetPosition(int x, int y, const wxSize& size)
54 {
55 m_position = wxRect(wxPoint(x, y), size);
56 }
57 bool IsVisible() const {return m_is_visible;}
58 const wxRect& GetPosition() const {return m_position;}
59
60 void SetClientObject(wxClientData *data) {m_client_data.SetClientObject(data);}
61 wxClientData *GetClientObject() const {return m_client_data.GetClientObject();}
62 void SetClientData(void *data) {m_client_data.SetClientData(data);}
63 void *GetClientData() const {return m_client_data.GetClientData();}
64
65 protected:
66 wxBitmap m_bitmap;
67 wxClientDataContainer m_client_data;
68 wxRect m_position;
69 int m_id;
70 bool m_is_visible;
71 };
72
73 BEGIN_EVENT_TABLE(wxRibbonGallery, wxRibbonControl)
74 EVT_ENTER_WINDOW(wxRibbonGallery::OnMouseEnter)
75 EVT_ERASE_BACKGROUND(wxRibbonGallery::OnEraseBackground)
76 EVT_LEAVE_WINDOW(wxRibbonGallery::OnMouseLeave)
77 EVT_LEFT_DOWN(wxRibbonGallery::OnMouseDown)
78 EVT_LEFT_UP(wxRibbonGallery::OnMouseUp)
79 EVT_MOTION(wxRibbonGallery::OnMouseMove)
80 EVT_PAINT(wxRibbonGallery::OnPaint)
81 EVT_SIZE(wxRibbonGallery::OnSize)
82 END_EVENT_TABLE()
83
84 wxRibbonGallery::wxRibbonGallery()
85 {
86 }
87
88 wxRibbonGallery::wxRibbonGallery(wxWindow* parent,
89 wxWindowID id,
90 const wxPoint& pos,
91 const wxSize& size,
92 long style)
93 : wxRibbonControl(parent, id, pos, size, wxBORDER_NONE)
94 {
95 CommonInit(style);
96 }
97
98 wxRibbonGallery::~wxRibbonGallery()
99 {
100 Clear();
101 }
102
103 bool wxRibbonGallery::Create(wxWindow* parent,
104 wxWindowID id,
105 const wxPoint& pos,
106 const wxSize& size,
107 long style)
108 {
109 if(!wxRibbonControl::Create(parent, id, pos, size, wxBORDER_NONE))
110 {
111 return false;
112 }
113
114 CommonInit(style);
115 return true;
116 }
117
118 void wxRibbonGallery::CommonInit(long WXUNUSED(style))
119 {
120 m_selected_item = NULL;
121 m_hovered_item = NULL;
122 m_active_item = NULL;
123 m_scroll_up_button_rect = wxRect(0, 0, 0, 0);
124 m_scroll_down_button_rect = wxRect(0, 0, 0, 0);
125 m_extension_button_rect = wxRect(0, 0, 0, 0);
126 m_mouse_active_rect = NULL;
127 m_bitmap_size = wxSize(64, 32);
128 m_bitmap_padded_size = m_bitmap_size;
129 m_item_separation_x = 0;
130 m_item_separation_y = 0;
131 m_scroll_amount = 0;
132 m_scroll_limit = 0;
133 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
134 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
135 m_extension_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
136 m_hovered = false;
137
138 SetBackgroundStyle(wxBG_STYLE_CUSTOM);
139 }
140
141 void wxRibbonGallery::OnMouseEnter(wxMouseEvent& evt)
142 {
143 m_hovered = true;
144 if(m_mouse_active_rect != NULL && !evt.LeftIsDown())
145 {
146 m_mouse_active_rect = NULL;
147 m_active_item = NULL;
148 }
149 Refresh(false);
150 }
151
152 void wxRibbonGallery::OnMouseMove(wxMouseEvent& evt)
153 {
154 bool refresh = false;
155 wxPoint pos = evt.GetPosition();
156
157 if(TestButtonHover(m_scroll_up_button_rect, pos, &m_up_button_state))
158 refresh = true;
159 if(TestButtonHover(m_scroll_down_button_rect, pos, &m_down_button_state))
160 refresh = true;
161 if(TestButtonHover(m_extension_button_rect, pos, &m_extension_button_state))
162 refresh = true;
163
164 wxRibbonGalleryItem *hovered_item = NULL;
165 wxRibbonGalleryItem *active_item = NULL;
166 if(m_client_rect.Contains(pos))
167 {
168 if(m_art && m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
169 pos.x += m_scroll_amount;
170 else
171 pos.y += m_scroll_amount;
172
173 size_t item_count = m_items.Count();
174 size_t item_i;
175 for(item_i = 0; item_i < item_count; ++item_i)
176 {
177 wxRibbonGalleryItem *item = m_items.Item(item_i);
178 if(!item->IsVisible())
179 continue;
180
181 if(item->GetPosition().Contains(pos))
182 {
183 if(m_mouse_active_rect == &item->GetPosition())
184 active_item = item;
185 hovered_item = item;
186 break;
187 }
188 }
189 }
190 if(active_item != m_active_item)
191 {
192 m_active_item = active_item;
193 refresh = true;
194 }
195 if(hovered_item != m_hovered_item)
196 {
197 m_hovered_item = hovered_item;
198 wxRibbonGalleryEvent notification(
199 wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED, GetId());
200 notification.SetEventObject(this);
201 notification.SetGallery(this);
202 notification.SetGalleryItem(hovered_item);
203 ProcessWindowEvent(notification);
204 refresh = true;
205 }
206
207 if(refresh)
208 Refresh(false);
209 }
210
211 bool wxRibbonGallery::TestButtonHover(const wxRect& rect, wxPoint pos,
212 wxRibbonGalleryButtonState* state)
213 {
214 if(*state == wxRIBBON_GALLERY_BUTTON_DISABLED)
215 return false;
216
217 wxRibbonGalleryButtonState new_state;
218 if(rect.Contains(pos))
219 {
220 if(m_mouse_active_rect == &rect)
221 new_state = wxRIBBON_GALLERY_BUTTON_ACTIVE;
222 else
223 new_state = wxRIBBON_GALLERY_BUTTON_HOVERED;
224 }
225 else
226 new_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
227
228 if(new_state != *state)
229 {
230 *state = new_state;
231 return true;
232 }
233 else
234 {
235 return false;
236 }
237 }
238
239 void wxRibbonGallery::OnMouseLeave(wxMouseEvent& WXUNUSED(evt))
240 {
241 m_hovered = false;
242 m_active_item = NULL;
243 if(m_up_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
244 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
245 if(m_down_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
246 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
247 if(m_extension_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
248 m_extension_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
249 if(m_hovered_item != NULL)
250 {
251 m_hovered_item = NULL;
252 wxRibbonGalleryEvent notification(
253 wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED, GetId());
254 notification.SetEventObject(this);
255 notification.SetGallery(this);
256 ProcessWindowEvent(notification);
257 }
258 Refresh(false);
259 }
260
261 void wxRibbonGallery::OnMouseDown(wxMouseEvent& evt)
262 {
263 wxPoint pos = evt.GetPosition();
264 m_mouse_active_rect = NULL;
265 if(m_client_rect.Contains(pos))
266 {
267 if(m_art && m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
268 pos.x += m_scroll_amount;
269 else
270 pos.y += m_scroll_amount;
271 size_t item_count = m_items.Count();
272 size_t item_i;
273 for(item_i = 0; item_i < item_count; ++item_i)
274 {
275 wxRibbonGalleryItem *item = m_items.Item(item_i);
276 if(!item->IsVisible())
277 continue;
278
279 const wxRect& rect = item->GetPosition();
280 if(rect.Contains(pos))
281 {
282 m_active_item = item;
283 m_mouse_active_rect = &rect;
284 break;
285 }
286 }
287 }
288 else if(m_scroll_up_button_rect.Contains(pos))
289 {
290 if(m_up_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
291 {
292 m_mouse_active_rect = &m_scroll_up_button_rect;
293 m_up_button_state = wxRIBBON_GALLERY_BUTTON_ACTIVE;
294 }
295 }
296 else if(m_scroll_down_button_rect.Contains(pos))
297 {
298 if(m_down_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
299 {
300 m_mouse_active_rect = &m_scroll_down_button_rect;
301 m_down_button_state = wxRIBBON_GALLERY_BUTTON_ACTIVE;
302 }
303 }
304 else if(m_extension_button_rect.Contains(pos))
305 {
306 if(m_extension_button_state != wxRIBBON_GALLERY_BUTTON_DISABLED)
307 {
308 m_mouse_active_rect = &m_extension_button_rect;
309 m_extension_button_state = wxRIBBON_GALLERY_BUTTON_ACTIVE;
310 }
311 }
312 if(m_mouse_active_rect != NULL)
313 Refresh(false);
314 }
315
316 void wxRibbonGallery::OnMouseUp(wxMouseEvent& evt)
317 {
318 if(m_mouse_active_rect != NULL)
319 {
320 wxPoint pos = evt.GetPosition();
321 if(m_active_item)
322 {
323 if(m_art && m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
324 pos.x += m_scroll_amount;
325 else
326 pos.y += m_scroll_amount;
327 }
328 if(m_mouse_active_rect->Contains(pos))
329 {
330 if(m_mouse_active_rect == &m_scroll_up_button_rect)
331 {
332 m_up_button_state = wxRIBBON_GALLERY_BUTTON_HOVERED;
333 ScrollLines(-1);
334 }
335 else if(m_mouse_active_rect == &m_scroll_down_button_rect)
336 {
337 m_down_button_state = wxRIBBON_GALLERY_BUTTON_HOVERED;
338 ScrollLines(1);
339 }
340 else if(m_mouse_active_rect == &m_extension_button_rect)
341 {
342 m_extension_button_state = wxRIBBON_GALLERY_BUTTON_HOVERED;
343 wxCommandEvent notification(wxEVT_COMMAND_BUTTON_CLICKED,
344 GetId());
345 notification.SetEventObject(this);
346 ProcessWindowEvent(notification);
347 }
348 else if(m_active_item != NULL)
349 {
350 if(m_selected_item != m_active_item)
351 {
352 m_selected_item = m_active_item;
353 wxRibbonGalleryEvent notification(
354 wxEVT_COMMAND_RIBBONGALLERY_SELECTED, GetId());
355 notification.SetEventObject(this);
356 notification.SetGallery(this);
357 notification.SetGalleryItem(m_selected_item);
358 ProcessWindowEvent(notification);
359 }
360
361 wxRibbonGalleryEvent notification(
362 wxEVT_COMMAND_RIBBONGALLERY_CLICKED, GetId());
363 notification.SetEventObject(this);
364 notification.SetGallery(this);
365 notification.SetGalleryItem(m_selected_item);
366 ProcessWindowEvent(notification);
367 }
368 }
369 m_mouse_active_rect = NULL;
370 m_active_item = NULL;
371 Refresh(false);
372 }
373 }
374
375 void wxRibbonGallery::SetItemClientObject(wxRibbonGalleryItem* itm,
376 wxClientData* data)
377 {
378 itm->SetClientObject(data);
379 }
380
381 wxClientData* wxRibbonGallery::GetItemClientObject(const wxRibbonGalleryItem* itm) const
382 {
383 return itm->GetClientObject();
384 }
385
386 void wxRibbonGallery::SetItemClientData(wxRibbonGalleryItem* itm, void* data)
387 {
388 itm->SetClientData(data);
389 }
390
391 void* wxRibbonGallery::GetItemClientData(const wxRibbonGalleryItem* itm) const
392 {
393 return itm->GetClientData();
394 }
395
396 bool wxRibbonGallery::ScrollLines(int lines)
397 {
398 if(m_scroll_limit == 0 || m_art == NULL)
399 return false;
400
401 int line_size = m_bitmap_padded_size.GetHeight();
402 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
403 line_size = m_bitmap_padded_size.GetWidth();
404 if(lines < 0)
405 {
406 if(m_scroll_amount > 0)
407 {
408 m_scroll_amount += lines * line_size;
409 if(m_scroll_amount <= 0)
410 {
411 m_scroll_amount = 0;
412 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
413 }
414 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
415 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
416 if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
417 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
418 return true;
419 }
420 }
421 else if(lines > 0)
422 {
423 if(m_scroll_amount < m_scroll_limit)
424 {
425 m_scroll_amount += lines * line_size;
426 if(m_scroll_amount >= m_scroll_limit)
427 {
428 m_scroll_amount = m_scroll_limit;
429 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
430 }
431 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
432 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
433 if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
434 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
435 return true;
436 }
437 }
438 return false;
439 }
440
441 void wxRibbonGallery::EnsureVisible(const wxRibbonGalleryItem* item)
442 {
443 if(item == NULL || !item->IsVisible() || IsEmpty())
444 return;
445
446 int y = item->GetPosition().GetTop();
447 int base_y = m_items.Item(0)->GetPosition().GetTop();
448 int delta = y - base_y - m_scroll_amount;
449 ScrollLines(delta / m_bitmap_padded_size.GetHeight());
450 }
451
452 bool wxRibbonGallery::IsHovered() const
453 {
454 return m_hovered;
455 }
456
457 void wxRibbonGallery::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
458 {
459 // All painting done in main paint handler to minimise flicker
460 }
461
462 void wxRibbonGallery::OnPaint(wxPaintEvent& WXUNUSED(evt))
463 {
464 wxAutoBufferedPaintDC dc(this);
465 if(m_art == NULL)
466 return;
467
468 m_art->DrawGalleryBackground(dc, this, GetSize());
469
470 int padding_top = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE);
471 int padding_left = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE);
472
473 dc.SetClippingRegion(m_client_rect);
474
475 bool offset_vertical = true;
476 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
477 offset_vertical = false;
478 size_t item_count = m_items.Count();
479 size_t item_i;
480 for(item_i = 0; item_i < item_count; ++item_i)
481 {
482 wxRibbonGalleryItem *item = m_items.Item(item_i);
483 if(!item->IsVisible())
484 continue;
485
486 const wxRect& pos = item->GetPosition();
487 wxRect offset_pos(pos);
488 if(offset_vertical)
489 offset_pos.SetTop(offset_pos.GetTop() - m_scroll_amount);
490 else
491 offset_pos.SetLeft(offset_pos.GetLeft() - m_scroll_amount);
492 m_art->DrawGalleryItemBackground(dc, this, offset_pos, item);
493 dc.DrawBitmap(item->GetBitmap(), offset_pos.GetLeft() + padding_left,
494 offset_pos.GetTop() + padding_top);
495 }
496 }
497
498 void wxRibbonGallery::OnSize(wxSizeEvent& WXUNUSED(evt))
499 {
500 Layout();
501 }
502
503 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id)
504 {
505 wxASSERT(bitmap.IsOk());
506 if(m_items.IsEmpty())
507 {
508 m_bitmap_size = bitmap.GetSize();
509 CalculateMinSize();
510 }
511 else
512 {
513 wxASSERT(bitmap.GetSize() == m_bitmap_size);
514 }
515
516 wxRibbonGalleryItem *item = new wxRibbonGalleryItem;
517 item->SetId(id);
518 item->SetBitmap(bitmap);
519 m_items.Add(item);
520 return item;
521 }
522
523 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
524 void* clientData)
525 {
526 wxRibbonGalleryItem *item = Append(bitmap, id);
527 item->SetClientData(clientData);
528 return item;
529 }
530
531 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
532 wxClientData* clientData)
533 {
534 wxRibbonGalleryItem *item = Append(bitmap, id);
535 item->SetClientObject(clientData);
536 return item;
537 }
538
539 void wxRibbonGallery::Clear()
540 {
541 size_t item_count = m_items.Count();
542 size_t item_i;
543 for(item_i = 0; item_i < item_count; ++item_i)
544 {
545 wxRibbonGalleryItem *item = m_items.Item(item_i);
546 delete item;
547 }
548 m_items.Clear();
549 }
550
551 bool wxRibbonGallery::IsSizingContinuous() const
552 {
553 return false;
554 }
555
556 void wxRibbonGallery::CalculateMinSize()
557 {
558 if(m_art == NULL || !m_bitmap_size.IsFullySpecified())
559 {
560 SetMinSize(wxSize(20, 20));
561 }
562 else
563 {
564 m_bitmap_padded_size = m_bitmap_size;
565 m_bitmap_padded_size.IncBy(
566 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE) +
567 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE),
568 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE) +
569 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE));
570
571 wxMemoryDC dc;
572 SetMinSize(m_art->GetGallerySize(dc, this, m_bitmap_padded_size));
573
574 // The best size is displaying several items
575 m_best_size = m_bitmap_padded_size;
576 m_best_size.x *= 3;
577 m_best_size = m_art->GetGallerySize(dc, this, m_best_size);
578 }
579 }
580
581 bool wxRibbonGallery::Realize()
582 {
583 CalculateMinSize();
584 return Layout();
585 }
586
587 bool wxRibbonGallery::Layout()
588 {
589 if(m_art == NULL)
590 return false;
591
592 wxMemoryDC dc;
593 wxPoint origin;
594 wxSize client_size = m_art->GetGalleryClientSize(dc, this, GetSize(),
595 &origin, &m_scroll_up_button_rect, &m_scroll_down_button_rect,
596 &m_extension_button_rect);
597 m_client_rect = wxRect(origin, client_size);
598
599 int x_cursor = 0;
600 int y_cursor = 0;
601
602 size_t item_count = m_items.Count();
603 size_t item_i;
604 long art_flags = m_art->GetFlags();
605 for(item_i = 0; item_i < item_count; ++item_i)
606 {
607 wxRibbonGalleryItem *item = m_items.Item(item_i);
608 item->SetIsVisible(true);
609 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
610 {
611 if(y_cursor + m_bitmap_padded_size.y > client_size.GetHeight())
612 {
613 if(y_cursor == 0)
614 break;
615 y_cursor = 0;
616 x_cursor += m_bitmap_padded_size.x;
617 }
618 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
619 m_bitmap_padded_size);
620 y_cursor += m_bitmap_padded_size.y;
621 }
622 else
623 {
624 if(x_cursor + m_bitmap_padded_size.x > client_size.GetWidth())
625 {
626 if(x_cursor == 0)
627 break;
628 x_cursor = 0;
629 y_cursor += m_bitmap_padded_size.y;
630 }
631 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
632 m_bitmap_padded_size);
633 x_cursor += m_bitmap_padded_size.x;
634 }
635 }
636 for(; item_i < item_count; ++item_i)
637 {
638 wxRibbonGalleryItem *item = m_items.Item(item_i);
639 item->SetIsVisible(false);
640 }
641 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
642 m_scroll_limit = x_cursor;
643 else
644 m_scroll_limit = y_cursor;
645 if(m_scroll_amount >= m_scroll_limit)
646 {
647 m_scroll_amount = m_scroll_limit;
648 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
649 }
650 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
651 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
652
653 if(m_scroll_amount <= 0)
654 {
655 m_scroll_amount = 0;
656 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
657 }
658 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
659 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
660
661 return true;
662 }
663
664 wxSize wxRibbonGallery::DoGetBestSize() const
665 {
666 return m_best_size;
667 }
668
669 wxSize wxRibbonGallery::DoGetNextSmallerSize(wxOrientation direction,
670 wxSize relative_to) const
671 {
672 if(m_art == NULL)
673 return relative_to;
674
675 wxMemoryDC dc;
676
677 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
678 NULL, NULL, NULL);
679 switch(direction)
680 {
681 case wxHORIZONTAL:
682 client.DecBy(1, 0);
683 break;
684 case wxVERTICAL:
685 client.DecBy(0, 1);
686 break;
687 case wxBOTH:
688 client.DecBy(1, 1);
689 break;
690 }
691 if(client.GetWidth() < 0 || client.GetHeight() < 0)
692 return relative_to;
693
694 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
695 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
696
697 wxSize size = m_art->GetGallerySize(dc, this, client);
698 wxSize minimum = GetMinSize();
699
700 if(size.GetWidth() < minimum.GetWidth() ||
701 size.GetHeight() < minimum.GetHeight())
702 {
703 return relative_to;
704 }
705
706 switch(direction)
707 {
708 case wxHORIZONTAL:
709 size.SetHeight(relative_to.GetHeight());
710 break;
711 case wxVERTICAL:
712 size.SetWidth(relative_to.GetWidth());
713 break;
714 default:
715 break;
716 }
717
718 return size;
719 }
720
721 wxSize wxRibbonGallery::DoGetNextLargerSize(wxOrientation direction,
722 wxSize relative_to) const
723 {
724 if(m_art == NULL)
725 return relative_to;
726
727 wxMemoryDC dc;
728
729 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
730 NULL, NULL, NULL);
731
732 // No need to grow if the given size can already display every item
733 int nitems = (client.GetWidth() / m_bitmap_padded_size.x) *
734 (client.GetHeight() / m_bitmap_padded_size.y);
735 if(nitems >= (int)m_items.GetCount())
736 return relative_to;
737
738 switch(direction)
739 {
740 case wxHORIZONTAL:
741 client.IncBy(m_bitmap_padded_size.x, 0);
742 break;
743 case wxVERTICAL:
744 client.IncBy(0, m_bitmap_padded_size.y);
745 break;
746 case wxBOTH:
747 client.IncBy(m_bitmap_padded_size);
748 break;
749 }
750
751 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
752 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
753
754 wxSize size = m_art->GetGallerySize(dc, this, client);
755 wxSize minimum = GetMinSize();
756
757 if(size.GetWidth() < minimum.GetWidth() ||
758 size.GetHeight() < minimum.GetHeight())
759 {
760 return relative_to;
761 }
762
763 switch(direction)
764 {
765 case wxHORIZONTAL:
766 size.SetHeight(relative_to.GetHeight());
767 break;
768 case wxVERTICAL:
769 size.SetWidth(relative_to.GetWidth());
770 break;
771 default:
772 break;
773 }
774
775 return size;
776 }
777
778 bool wxRibbonGallery::IsEmpty() const
779 {
780 return m_items.IsEmpty();
781 }
782
783 unsigned int wxRibbonGallery::GetCount() const
784 {
785 return (unsigned int)m_items.GetCount();
786 }
787
788 wxRibbonGalleryItem* wxRibbonGallery::GetItem(unsigned int n)
789 {
790 if(n >= GetCount())
791 return NULL;
792 return m_items.Item(n);
793 }
794
795 void wxRibbonGallery::SetSelection(wxRibbonGalleryItem* item)
796 {
797 if(item != m_selected_item)
798 {
799 m_selected_item = item;
800 Refresh(false);
801 }
802 }
803
804 wxRibbonGalleryItem* wxRibbonGallery::GetSelection() const
805 {
806 return m_selected_item;
807 }
808
809 wxRibbonGalleryItem* wxRibbonGallery::GetHoveredItem() const
810 {
811 return m_hovered_item;
812 }
813
814 wxRibbonGalleryItem* wxRibbonGallery::GetActiveItem() const
815 {
816 return m_active_item;
817 }
818
819 wxRibbonGalleryButtonState wxRibbonGallery::GetUpButtonState() const
820 {
821 return m_up_button_state;
822 }
823
824 wxRibbonGalleryButtonState wxRibbonGallery::GetDownButtonState() const
825 {
826 return m_down_button_state;
827 }
828
829 wxRibbonGalleryButtonState wxRibbonGallery::GetExtensionButtonState() const
830 {
831 return m_extension_button_state;
832 }
833
834 #endif // wxUSE_RIBBON