]> git.saurik.com Git - wxWidgets.git/blob - src/ribbon/gallery.cpp
Added wxMSW wxChoice::GetClassDefaultAttributes(), initially used in wxComboCtrl
[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 m_art->DrawGalleryBackground(dc, this, GetSize());
462
463 int padding_top = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE);
464 int padding_left = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE);
465
466 dc.SetClippingRegion(m_client_rect);
467
468 bool offset_vertical = true;
469 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
470 offset_vertical = false;
471 size_t item_count = m_items.Count();
472 size_t item_i;
473 for(item_i = 0; item_i < item_count; ++item_i)
474 {
475 wxRibbonGalleryItem *item = m_items.Item(item_i);
476 if(!item->IsVisible())
477 continue;
478
479 const wxRect& pos = item->GetPosition();
480 wxRect offset_pos(pos);
481 if(offset_vertical)
482 offset_pos.SetTop(offset_pos.GetTop() - m_scroll_amount);
483 else
484 offset_pos.SetLeft(offset_pos.GetLeft() - m_scroll_amount);
485 m_art->DrawGalleryItemBackground(dc, this, offset_pos, item);
486 dc.DrawBitmap(item->GetBitmap(), offset_pos.GetLeft() + padding_left,
487 offset_pos.GetTop() + padding_top);
488 }
489 }
490
491 void wxRibbonGallery::OnSize(wxSizeEvent& WXUNUSED(evt))
492 {
493 Layout();
494 }
495
496 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id)
497 {
498 wxASSERT(bitmap.IsOk());
499 if(m_items.IsEmpty())
500 {
501 m_bitmap_size = bitmap.GetSize();
502 CalculateMinSize();
503 }
504 else
505 {
506 wxASSERT(bitmap.GetSize() == m_bitmap_size);
507 }
508
509 wxRibbonGalleryItem *item = new wxRibbonGalleryItem;
510 item->SetId(id);
511 item->SetBitmap(bitmap);
512 m_items.Add(item);
513 return item;
514 }
515
516 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
517 void* clientData)
518 {
519 wxRibbonGalleryItem *item = Append(bitmap, id);
520 item->SetClientData(clientData);
521 return item;
522 }
523
524 wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
525 wxClientData* clientData)
526 {
527 wxRibbonGalleryItem *item = Append(bitmap, id);
528 item->SetClientObject(clientData);
529 return item;
530 }
531
532 void wxRibbonGallery::Clear()
533 {
534 size_t item_count = m_items.Count();
535 size_t item_i;
536 for(item_i = 0; item_i < item_count; ++item_i)
537 {
538 wxRibbonGalleryItem *item = m_items.Item(item_i);
539 delete item;
540 }
541 m_items.Clear();
542 }
543
544 bool wxRibbonGallery::IsSizingContinuous() const
545 {
546 return false;
547 }
548
549 void wxRibbonGallery::CalculateMinSize()
550 {
551 if(m_art == NULL || !m_bitmap_size.IsFullySpecified())
552 {
553 SetMinSize(wxSize(20, 20));
554 }
555 else
556 {
557 m_bitmap_padded_size = m_bitmap_size;
558 m_bitmap_padded_size.IncBy(
559 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE) +
560 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE),
561 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE) +
562 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE));
563
564 wxMemoryDC dc;
565 SetMinSize(m_art->GetGallerySize(dc, this, m_bitmap_padded_size));
566
567 // The best size is displaying several items
568 m_best_size = m_bitmap_padded_size;
569 m_best_size.x *= 3;
570 m_best_size = m_art->GetGallerySize(dc, this, m_best_size);
571 }
572 }
573
574 bool wxRibbonGallery::Realize()
575 {
576 CalculateMinSize();
577 return Layout();
578 }
579
580 bool wxRibbonGallery::Layout()
581 {
582 if(m_art == NULL)
583 return false;
584
585 wxMemoryDC dc;
586 wxPoint origin;
587 wxSize client_size = m_art->GetGalleryClientSize(dc, this, GetSize(),
588 &origin, &m_scroll_up_button_rect, &m_scroll_down_button_rect,
589 &m_extension_button_rect);
590 m_client_rect = wxRect(origin, client_size);
591
592 int x_cursor = 0;
593 int y_cursor = 0;
594
595 size_t item_count = m_items.Count();
596 size_t item_i;
597 long art_flags = m_art->GetFlags();
598 for(item_i = 0; item_i < item_count; ++item_i)
599 {
600 wxRibbonGalleryItem *item = m_items.Item(item_i);
601 item->SetIsVisible(true);
602 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
603 {
604 if(y_cursor + m_bitmap_padded_size.y > client_size.GetHeight())
605 {
606 if(y_cursor == 0)
607 break;
608 y_cursor = 0;
609 x_cursor += m_bitmap_padded_size.x;
610 }
611 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
612 m_bitmap_padded_size);
613 y_cursor += m_bitmap_padded_size.y;
614 }
615 else
616 {
617 if(x_cursor + m_bitmap_padded_size.x > client_size.GetWidth())
618 {
619 if(x_cursor == 0)
620 break;
621 x_cursor = 0;
622 y_cursor += m_bitmap_padded_size.y;
623 }
624 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
625 m_bitmap_padded_size);
626 x_cursor += m_bitmap_padded_size.x;
627 }
628 }
629 for(; item_i < item_count; ++item_i)
630 {
631 wxRibbonGalleryItem *item = m_items.Item(item_i);
632 item->SetIsVisible(false);
633 }
634 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
635 m_scroll_limit = x_cursor;
636 else
637 m_scroll_limit = y_cursor;
638 if(m_scroll_amount >= m_scroll_limit)
639 {
640 m_scroll_amount = m_scroll_limit;
641 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
642 }
643 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
644 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
645
646 if(m_scroll_amount <= 0)
647 {
648 m_scroll_amount = 0;
649 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
650 }
651 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
652 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
653
654 return true;
655 }
656
657 wxSize wxRibbonGallery::DoGetBestSize() const
658 {
659 return m_best_size;
660 }
661
662 wxSize wxRibbonGallery::DoGetNextSmallerSize(wxOrientation direction,
663 wxSize relative_to) const
664 {
665 if(m_art == NULL)
666 return relative_to;
667
668 wxMemoryDC dc;
669
670 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
671 NULL, NULL, NULL);
672 switch(direction)
673 {
674 case wxHORIZONTAL:
675 client.DecBy(1, 0);
676 break;
677 case wxVERTICAL:
678 client.DecBy(0, 1);
679 break;
680 case wxBOTH:
681 client.DecBy(1, 1);
682 break;
683 }
684 if(client.GetWidth() < 0 || client.GetHeight() < 0)
685 return relative_to;
686
687 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
688 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
689
690 wxSize size = m_art->GetGallerySize(dc, this, client);
691 wxSize minimum = GetMinSize();
692
693 if(size.GetWidth() < minimum.GetWidth() ||
694 size.GetHeight() < minimum.GetHeight())
695 {
696 return relative_to;
697 }
698
699 switch(direction)
700 {
701 case wxHORIZONTAL:
702 size.SetHeight(relative_to.GetHeight());
703 break;
704 case wxVERTICAL:
705 size.SetWidth(relative_to.GetWidth());
706 break;
707 default:
708 break;
709 }
710
711 return size;
712 }
713
714 wxSize wxRibbonGallery::DoGetNextLargerSize(wxOrientation direction,
715 wxSize relative_to) const
716 {
717 if(m_art == NULL)
718 return relative_to;
719
720 wxMemoryDC dc;
721
722 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
723 NULL, NULL, NULL);
724
725 // No need to grow if the given size can already display every item
726 int nitems = (client.GetWidth() / m_bitmap_padded_size.x) *
727 (client.GetHeight() / m_bitmap_padded_size.y);
728 if(nitems >= (int)m_items.GetCount())
729 return relative_to;
730
731 switch(direction)
732 {
733 case wxHORIZONTAL:
734 client.IncBy(m_bitmap_padded_size.x, 0);
735 break;
736 case wxVERTICAL:
737 client.IncBy(0, m_bitmap_padded_size.y);
738 break;
739 case wxBOTH:
740 client.IncBy(m_bitmap_padded_size);
741 break;
742 }
743
744 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
745 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
746
747 wxSize size = m_art->GetGallerySize(dc, this, client);
748 wxSize minimum = GetMinSize();
749
750 if(size.GetWidth() < minimum.GetWidth() ||
751 size.GetHeight() < minimum.GetHeight())
752 {
753 return relative_to;
754 }
755
756 switch(direction)
757 {
758 case wxHORIZONTAL:
759 size.SetHeight(relative_to.GetHeight());
760 break;
761 case wxVERTICAL:
762 size.SetWidth(relative_to.GetWidth());
763 break;
764 default:
765 break;
766 }
767
768 return size;
769 }
770
771 bool wxRibbonGallery::IsEmpty() const
772 {
773 return m_items.IsEmpty();
774 }
775
776 unsigned int wxRibbonGallery::GetCount() const
777 {
778 return (unsigned int)m_items.GetCount();
779 }
780
781 wxRibbonGalleryItem* wxRibbonGallery::GetItem(unsigned int n)
782 {
783 if(n >= GetCount())
784 return NULL;
785 return m_items.Item(n);
786 }
787
788 void wxRibbonGallery::SetSelection(wxRibbonGalleryItem* item)
789 {
790 if(item != m_selected_item)
791 {
792 m_selected_item = item;
793 Refresh(false);
794 }
795 }
796
797 wxRibbonGalleryItem* wxRibbonGallery::GetSelection() const
798 {
799 return m_selected_item;
800 }
801
802 wxRibbonGalleryItem* wxRibbonGallery::GetHoveredItem() const
803 {
804 return m_hovered_item;
805 }
806
807 wxRibbonGalleryItem* wxRibbonGallery::GetActiveItem() const
808 {
809 return m_active_item;
810 }
811
812 wxRibbonGalleryButtonState wxRibbonGallery::GetUpButtonState() const
813 {
814 return m_up_button_state;
815 }
816
817 wxRibbonGalleryButtonState wxRibbonGallery::GetDownButtonState() const
818 {
819 return m_down_button_state;
820 }
821
822 wxRibbonGalleryButtonState wxRibbonGallery::GetExtensionButtonState() const
823 {
824 return m_extension_button_state;
825 }
826
827 #endif // wxUSE_RIBBON