]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/gallery.cpp
440455e16f75ec9aba7cd5fa7cc5407dfd8da41c
[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 #include "wx/ribbon/gallery.h"
19
20 #if wxUSE_RIBBON
21
22 #include "wx/ribbon/art.h"
23 #include "wx/ribbon/bar.h"
24 #include "wx/dcbuffer.h"
25 #include "wx/clntdata.h"
26
27 #ifndef WX_PRECOMP
28 #endif
29
30 #ifdef __WXMSW__
31 #include "wx/msw/private.h"
32 #endif
33
34 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED, wxRibbonGalleryEvent);
35 wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, 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 }
362 m_mouse_active_rect = NULL;
363 m_active_item = NULL;
364 Refresh(false);
365 }
366 }
367
368 void wxRibbonGallery::SetItemClientObject(wxRibbonGalleryItem* itm,
369 wxClientData* data)
370 {
371 itm->SetClientObject(data);
372 }
373
374 wxClientData* wxRibbonGallery::GetItemClientObject(const wxRibbonGalleryItem* itm) const
375 {
376 return itm->GetClientObject();
377 }
378
379 void wxRibbonGallery::SetItemClientData(wxRibbonGalleryItem* itm, void* data)
380 {
381 itm->SetClientData(data);
382 }
383
384 void* wxRibbonGallery::GetItemClientData(const wxRibbonGalleryItem* itm) const
385 {
386 return itm->GetClientData();
387 }
388
389 bool wxRibbonGallery::ScrollLines(int lines)
390 {
391 if(m_scroll_limit == 0 || m_art == NULL)
392 return false;
393
394 int line_size = m_bitmap_padded_size.GetHeight();
395 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
396 line_size = m_bitmap_padded_size.GetWidth();
397 if(lines < 0)
398 {
399 if(m_scroll_amount > 0)
400 {
401 m_scroll_amount += lines * line_size;
402 if(m_scroll_amount <= 0)
403 {
404 m_scroll_amount = 0;
405 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
406 }
407 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
408 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
409 if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
410 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
411 return true;
412 }
413 }
414 else if(lines > 0)
415 {
416 if(m_scroll_amount < m_scroll_limit)
417 {
418 m_scroll_amount += lines * line_size;
419 if(m_scroll_amount >= m_scroll_limit)
420 {
421 m_scroll_amount = m_scroll_limit;
422 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
423 }
424 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
425 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
426 if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
427 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
428 return true;
429 }
430 }
431 return false;
432 }
433
434 void wxRibbonGallery::EnsureVisible(const wxRibbonGalleryItem* item)
435 {
436 if(item == NULL || !item->IsVisible() || IsEmpty())
437 return;
438
439 int y = item->GetPosition().GetTop();
440 int base_y = m_items.Item(0)->GetPosition().GetTop();
441 int delta = y - base_y - m_scroll_amount;
442 ScrollLines(delta / m_bitmap_padded_size.GetHeight());
443 }
444
445 bool wxRibbonGallery::IsHovered() const
446 {
447 return m_hovered;
448 }
449
450 void wxRibbonGallery::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
451 {
452 // All painting done in main paint handler to minimise flicker
453 }
454
455 void wxRibbonGallery::OnPaint(wxPaintEvent& WXUNUSED(evt))
456 {
457 wxAutoBufferedPaintDC dc(this);
458 if(m_art == NULL)
459 return;
460
461 wxSize cur_size = GetSize();
462 wxSize min_size = GetMinSize();
463
464 m_art->DrawGalleryBackground(dc, this, GetSize());
465
466 int padding_top = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE);
467 int padding_left = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE);
468
469 dc.SetClippingRegion(m_client_rect);
470
471 bool offset_vertical = true;
472 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
473 offset_vertical = false;
474 size_t item_count = m_items.Count();
475 size_t item_i;
476 for(item_i = 0; item_i < item_count; ++item_i)
477 {
478 wxRibbonGalleryItem *item = m_items.Item(item_i);
479 if(!item->IsVisible())
480 continue;
481
482 const wxRect& pos = item->GetPosition();
483 wxRect offset_pos(pos);
484 if(offset_vertical)
485 offset_pos.SetTop(offset_pos.GetTop() - m_scroll_amount);
486 else
487 offset_pos.SetLeft(offset_pos.GetLeft() - m_scroll_amount);
488 m_art->DrawGalleryItemBackground(dc, this, offset_pos, item);
489 dc.DrawBitmap(item->GetBitmap(), offset_pos.GetLeft() + padding_left,
490 offset_pos.GetTop() + padding_top);
491 }
492 }
493
494 void wxRibbonGallery::OnSize(wxSizeEvent& WXUNUSED(evt))
495 {
496 Layout();
497 }
498
499 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id)
500 {
501 wxASSERT(bitmap.IsOk());
502 if(m_items.IsEmpty())
503 {
504 m_bitmap_size = bitmap.GetSize();
505 CalculateMinSize();
506 }
507 else
508 {
509 wxASSERT(bitmap.GetSize() == m_bitmap_size);
510 }
511
512 wxRibbonGalleryItem *item = new wxRibbonGalleryItem;
513 item->SetId(id);
514 item->SetBitmap(bitmap);
515 m_items.Add(item);
516 return item;
517 }
518
519 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
520 void* clientData)
521 {
522 wxRibbonGalleryItem *item = Append(bitmap, id);
523 item->SetClientData(clientData);
524 return item;
525 }
526
527 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
528 wxClientData* clientData)
529 {
530 wxRibbonGalleryItem *item = Append(bitmap, id);
531 item->SetClientObject(clientData);
532 return item;
533 }
534
535 void wxRibbonGallery::Clear()
536 {
537 size_t item_count = m_items.Count();
538 size_t item_i;
539 for(item_i = 0; item_i < item_count; ++item_i)
540 {
541 wxRibbonGalleryItem *item = m_items.Item(item_i);
542 delete item;
543 }
544 m_items.Clear();
545 }
546
547 bool wxRibbonGallery::IsSizingContinuous() const
548 {
549 return false;
550 }
551
552 void wxRibbonGallery::CalculateMinSize()
553 {
554 if(m_art == NULL || !m_bitmap_size.IsFullySpecified())
555 {
556 SetMinSize(wxSize(20, 20));
557 }
558 else
559 {
560 m_bitmap_padded_size = m_bitmap_size;
561 m_bitmap_padded_size.IncBy(
562 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE) +
563 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE),
564 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE) +
565 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE));
566
567 wxMemoryDC dc;
568 SetMinSize(m_art->GetGallerySize(dc, this, m_bitmap_padded_size));
569
570 // The best size is displaying several items
571 m_best_size = m_bitmap_padded_size;
572 m_best_size.x *= 3;
573 m_best_size = m_art->GetGallerySize(dc, this, m_best_size);
574 }
575 }
576
577 bool wxRibbonGallery::Realize()
578 {
579 CalculateMinSize();
580 return Layout();
581 }
582
583 bool wxRibbonGallery::Layout()
584 {
585 if(m_art == NULL)
586 return false;
587
588 wxMemoryDC dc;
589 wxPoint origin;
590 wxSize client_size = m_art->GetGalleryClientSize(dc, this, GetSize(),
591 &origin, &m_scroll_up_button_rect, &m_scroll_down_button_rect,
592 &m_extension_button_rect);
593 m_client_rect = wxRect(origin, client_size);
594
595 int x_cursor = 0;
596 int y_cursor = 0;
597
598 size_t item_count = m_items.Count();
599 size_t item_i;
600 long art_flags = m_art->GetFlags();
601 for(item_i = 0; item_i < item_count; ++item_i)
602 {
603 wxRibbonGalleryItem *item = m_items.Item(item_i);
604 item->SetIsVisible(true);
605 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
606 {
607 if(y_cursor + m_bitmap_padded_size.y > client_size.GetHeight())
608 {
609 if(y_cursor == 0)
610 break;
611 y_cursor = 0;
612 x_cursor += m_bitmap_padded_size.x;
613 }
614 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
615 m_bitmap_padded_size);
616 y_cursor += m_bitmap_padded_size.y;
617 }
618 else
619 {
620 if(x_cursor + m_bitmap_padded_size.x > client_size.GetWidth())
621 {
622 if(x_cursor == 0)
623 break;
624 x_cursor = 0;
625 y_cursor += m_bitmap_padded_size.y;
626 }
627 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
628 m_bitmap_padded_size);
629 x_cursor += m_bitmap_padded_size.x;
630 }
631 }
632 for(; item_i < item_count; ++item_i)
633 {
634 wxRibbonGalleryItem *item = m_items.Item(item_i);
635 item->SetIsVisible(false);
636 }
637 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
638 m_scroll_limit = x_cursor;
639 else
640 m_scroll_limit = y_cursor;
641 if(m_scroll_amount >= m_scroll_limit)
642 {
643 m_scroll_amount = m_scroll_limit;
644 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
645 }
646 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
647 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
648
649 if(m_scroll_amount <= 0)
650 {
651 m_scroll_amount = 0;
652 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
653 }
654 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
655 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
656
657 return true;
658 }
659
660 wxSize wxRibbonGallery::DoGetBestSize() const
661 {
662 return m_best_size;
663 }
664
665 wxSize wxRibbonGallery::DoGetNextSmallerSize(wxOrientation direction,
666 wxSize relative_to) const
667 {
668 if(m_art == NULL)
669 return relative_to;
670
671 wxMemoryDC dc;
672
673 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
674 NULL, NULL, NULL);
675 switch(direction)
676 {
677 case wxHORIZONTAL:
678 client.DecBy(1, 0);
679 break;
680 case wxVERTICAL:
681 client.DecBy(0, 1);
682 break;
683 case wxBOTH:
684 client.DecBy(1, 1);
685 break;
686 }
687 if(client.GetWidth() < 0 || client.GetHeight() < 0)
688 return relative_to;
689
690 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
691 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
692
693 wxSize size = m_art->GetGallerySize(dc, this, client);
694 wxSize minimum = GetMinSize();
695
696 if(size.GetWidth() < minimum.GetWidth() ||
697 size.GetHeight() < minimum.GetHeight())
698 {
699 return relative_to;
700 }
701
702 switch(direction)
703 {
704 case wxHORIZONTAL:
705 size.SetHeight(relative_to.GetHeight());
706 break;
707 case wxVERTICAL:
708 size.SetWidth(relative_to.GetWidth());
709 break;
710 default:
711 break;
712 }
713
714 return size;
715 }
716
717 wxSize wxRibbonGallery::DoGetNextLargerSize(wxOrientation direction,
718 wxSize relative_to) const
719 {
720 if(m_art == NULL)
721 return relative_to;
722
723 wxMemoryDC dc;
724
725 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
726 NULL, NULL, NULL);
727
728 // No need to grow if the given size can already display every item
729 int nitems = (client.GetWidth() / m_bitmap_padded_size.x) *
730 (client.GetHeight() / m_bitmap_padded_size.y);
731 if(nitems >= (int)m_items.GetCount())
732 return relative_to;
733
734 switch(direction)
735 {
736 case wxHORIZONTAL:
737 client.IncBy(m_bitmap_padded_size.x, 0);
738 break;
739 case wxVERTICAL:
740 client.IncBy(0, m_bitmap_padded_size.y);
741 break;
742 case wxBOTH:
743 client.IncBy(m_bitmap_padded_size);
744 break;
745 }
746
747 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
748 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
749
750 wxSize size = m_art->GetGallerySize(dc, this, client);
751 wxSize minimum = GetMinSize();
752
753 if(size.GetWidth() < minimum.GetWidth() ||
754 size.GetHeight() < minimum.GetHeight())
755 {
756 return relative_to;
757 }
758
759 switch(direction)
760 {
761 case wxHORIZONTAL:
762 size.SetHeight(relative_to.GetHeight());
763 break;
764 case wxVERTICAL:
765 size.SetWidth(relative_to.GetWidth());
766 break;
767 default:
768 break;
769 }
770
771 return size;
772 }
773
774 bool wxRibbonGallery::IsEmpty() const
775 {
776 return m_items.IsEmpty();
777 }
778
779 unsigned int wxRibbonGallery::GetCount() const
780 {
781 return (unsigned int)m_items.GetCount();
782 }
783
784 wxRibbonGalleryItem* wxRibbonGallery::GetItem(unsigned int n)
785 {
786 if(n >= GetCount())
787 return NULL;
788 return m_items.Item(n);
789 }
790
791 void wxRibbonGallery::SetSelection(wxRibbonGalleryItem* item)
792 {
793 if(item != m_selected_item)
794 {
795 m_selected_item = item;
796 Refresh(false);
797 }
798 }
799
800 wxRibbonGalleryItem* wxRibbonGallery::GetSelection() const
801 {
802 return m_selected_item;
803 }
804
805 wxRibbonGalleryItem* wxRibbonGallery::GetHoveredItem() const
806 {
807 return m_hovered_item;
808 }
809
810 wxRibbonGalleryItem* wxRibbonGallery::GetActiveItem() const
811 {
812 return m_active_item;
813 }
814
815 wxRibbonGalleryButtonState wxRibbonGallery::GetUpButtonState() const
816 {
817 return m_up_button_state;
818 }
819
820 wxRibbonGalleryButtonState wxRibbonGallery::GetDownButtonState() const
821 {
822 return m_down_button_state;
823 }
824
825 wxRibbonGalleryButtonState wxRibbonGallery::GetExtensionButtonState() const
826 {
827 return m_extension_button_state;
828 }
829
830 #endif // wxUSE_RIBBON