]> git.saurik.com Git - wxWidgets.git/blame - src/ribbon/gallery.cpp
Improve support for ribbon panel sizers: panels with sizers should now automatically...
[wxWidgets.git] / src / ribbon / gallery.cpp
CommitLineData
3c3ead1d
PC
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
3c3ead1d
PC
18#if wxUSE_RIBBON
19
4cf018e1 20#include "wx/ribbon/gallery.h"
3c3ead1d
PC
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
33wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_HOVER_CHANGED, wxRibbonGalleryEvent);
34wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_SELECTED, wxRibbonGalleryEvent);
1aff4201 35wxDEFINE_EVENT(wxEVT_COMMAND_RIBBONGALLERY_CLICKED, wxRibbonGalleryEvent);
3c3ead1d
PC
36
37IMPLEMENT_DYNAMIC_CLASS(wxRibbonGalleryEvent, wxCommandEvent)
38IMPLEMENT_CLASS(wxRibbonGallery, wxRibbonControl)
39
40class wxRibbonGalleryItem
41{
42public:
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
65protected:
66 wxBitmap m_bitmap;
67 wxClientDataContainer m_client_data;
68 wxRect m_position;
69 int m_id;
70 bool m_is_visible;
71};
72
73BEGIN_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)
82END_EVENT_TABLE()
83
84wxRibbonGallery::wxRibbonGallery()
85{
86}
87
88wxRibbonGallery::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
98wxRibbonGallery::~wxRibbonGallery()
99{
100 Clear();
101}
102
103bool 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
118void 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
141void 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
152void 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
211bool 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
239void 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
261void 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
316void 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 }
1aff4201
VZ
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);
3c3ead1d
PC
367 }
368 }
369 m_mouse_active_rect = NULL;
370 m_active_item = NULL;
371 Refresh(false);
372 }
373}
374
375void wxRibbonGallery::SetItemClientObject(wxRibbonGalleryItem* itm,
376 wxClientData* data)
377{
378 itm->SetClientObject(data);
379}
380
381wxClientData* wxRibbonGallery::GetItemClientObject(const wxRibbonGalleryItem* itm) const
382{
383 return itm->GetClientObject();
384}
385
386void wxRibbonGallery::SetItemClientData(wxRibbonGalleryItem* itm, void* data)
387{
388 itm->SetClientData(data);
389}
390
391void* wxRibbonGallery::GetItemClientData(const wxRibbonGalleryItem* itm) const
392{
393 return itm->GetClientData();
394}
395
396bool 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
441void wxRibbonGallery::EnsureVisible(const wxRibbonGalleryItem* item)
442{
443 if(item == NULL || !item->IsVisible() || IsEmpty())
444 return;
445
6f7e96d8
PC
446 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
447 {
448 int x = item->GetPosition().GetLeft();
449 int base_x = m_items.Item(0)->GetPosition().GetLeft();
450 int delta = x - base_x - m_scroll_amount;
451 ScrollLines(delta / m_bitmap_padded_size.GetWidth());
452 }
453 else
454 {
455 int y = item->GetPosition().GetTop();
456 int base_y = m_items.Item(0)->GetPosition().GetTop();
457 int delta = y - base_y - m_scroll_amount;
458 ScrollLines(delta / m_bitmap_padded_size.GetHeight());
459 }
3c3ead1d
PC
460}
461
462bool wxRibbonGallery::IsHovered() const
463{
464 return m_hovered;
465}
466
467void wxRibbonGallery::OnEraseBackground(wxEraseEvent& WXUNUSED(evt))
468{
469 // All painting done in main paint handler to minimise flicker
470}
471
472void wxRibbonGallery::OnPaint(wxPaintEvent& WXUNUSED(evt))
473{
474 wxAutoBufferedPaintDC dc(this);
475 if(m_art == NULL)
476 return;
477
3c3ead1d
PC
478 m_art->DrawGalleryBackground(dc, this, GetSize());
479
480 int padding_top = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE);
481 int padding_left = m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE);
482
483 dc.SetClippingRegion(m_client_rect);
484
485 bool offset_vertical = true;
486 if(m_art->GetFlags() & wxRIBBON_BAR_FLOW_VERTICAL)
487 offset_vertical = false;
488 size_t item_count = m_items.Count();
489 size_t item_i;
490 for(item_i = 0; item_i < item_count; ++item_i)
491 {
492 wxRibbonGalleryItem *item = m_items.Item(item_i);
493 if(!item->IsVisible())
494 continue;
495
496 const wxRect& pos = item->GetPosition();
497 wxRect offset_pos(pos);
498 if(offset_vertical)
499 offset_pos.SetTop(offset_pos.GetTop() - m_scroll_amount);
500 else
501 offset_pos.SetLeft(offset_pos.GetLeft() - m_scroll_amount);
502 m_art->DrawGalleryItemBackground(dc, this, offset_pos, item);
503 dc.DrawBitmap(item->GetBitmap(), offset_pos.GetLeft() + padding_left,
504 offset_pos.GetTop() + padding_top);
505 }
506}
507
508void wxRibbonGallery::OnSize(wxSizeEvent& WXUNUSED(evt))
509{
510 Layout();
511}
512
513wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id)
514{
515 wxASSERT(bitmap.IsOk());
516 if(m_items.IsEmpty())
517 {
518 m_bitmap_size = bitmap.GetSize();
519 CalculateMinSize();
520 }
521 else
522 {
523 wxASSERT(bitmap.GetSize() == m_bitmap_size);
524 }
525
526 wxRibbonGalleryItem *item = new wxRibbonGalleryItem;
527 item->SetId(id);
528 item->SetBitmap(bitmap);
529 m_items.Add(item);
530 return item;
531}
532
533wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
534 void* clientData)
535{
536 wxRibbonGalleryItem *item = Append(bitmap, id);
537 item->SetClientData(clientData);
538 return item;
539}
540
541wxRibbonGalleryItem* wxRibbonGallery::Append(const wxBitmap& bitmap, int id,
542 wxClientData* clientData)
543{
544 wxRibbonGalleryItem *item = Append(bitmap, id);
545 item->SetClientObject(clientData);
546 return item;
547}
548
549void wxRibbonGallery::Clear()
550{
551 size_t item_count = m_items.Count();
552 size_t item_i;
553 for(item_i = 0; item_i < item_count; ++item_i)
554 {
555 wxRibbonGalleryItem *item = m_items.Item(item_i);
556 delete item;
557 }
558 m_items.Clear();
559}
560
561bool wxRibbonGallery::IsSizingContinuous() const
562{
563 return false;
564}
565
566void wxRibbonGallery::CalculateMinSize()
567{
568 if(m_art == NULL || !m_bitmap_size.IsFullySpecified())
569 {
570 SetMinSize(wxSize(20, 20));
571 }
572 else
573 {
574 m_bitmap_padded_size = m_bitmap_size;
575 m_bitmap_padded_size.IncBy(
576 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_LEFT_SIZE) +
577 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_RIGHT_SIZE),
578 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_TOP_SIZE) +
579 m_art->GetMetric(wxRIBBON_ART_GALLERY_BITMAP_PADDING_BOTTOM_SIZE));
580
581 wxMemoryDC dc;
582 SetMinSize(m_art->GetGallerySize(dc, this, m_bitmap_padded_size));
583
584 // The best size is displaying several items
585 m_best_size = m_bitmap_padded_size;
586 m_best_size.x *= 3;
587 m_best_size = m_art->GetGallerySize(dc, this, m_best_size);
588 }
589}
590
591bool wxRibbonGallery::Realize()
592{
593 CalculateMinSize();
594 return Layout();
595}
596
597bool wxRibbonGallery::Layout()
598{
599 if(m_art == NULL)
600 return false;
601
602 wxMemoryDC dc;
603 wxPoint origin;
604 wxSize client_size = m_art->GetGalleryClientSize(dc, this, GetSize(),
605 &origin, &m_scroll_up_button_rect, &m_scroll_down_button_rect,
606 &m_extension_button_rect);
607 m_client_rect = wxRect(origin, client_size);
608
609 int x_cursor = 0;
610 int y_cursor = 0;
611
612 size_t item_count = m_items.Count();
613 size_t item_i;
614 long art_flags = m_art->GetFlags();
615 for(item_i = 0; item_i < item_count; ++item_i)
616 {
617 wxRibbonGalleryItem *item = m_items.Item(item_i);
618 item->SetIsVisible(true);
619 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
620 {
621 if(y_cursor + m_bitmap_padded_size.y > client_size.GetHeight())
622 {
623 if(y_cursor == 0)
624 break;
625 y_cursor = 0;
626 x_cursor += m_bitmap_padded_size.x;
627 }
628 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
629 m_bitmap_padded_size);
630 y_cursor += m_bitmap_padded_size.y;
631 }
632 else
633 {
634 if(x_cursor + m_bitmap_padded_size.x > client_size.GetWidth())
635 {
636 if(x_cursor == 0)
637 break;
638 x_cursor = 0;
639 y_cursor += m_bitmap_padded_size.y;
640 }
641 item->SetPosition(origin.x + x_cursor, origin.y + y_cursor,
642 m_bitmap_padded_size);
643 x_cursor += m_bitmap_padded_size.x;
644 }
645 }
646 for(; item_i < item_count; ++item_i)
647 {
648 wxRibbonGalleryItem *item = m_items.Item(item_i);
649 item->SetIsVisible(false);
650 }
651 if(art_flags & wxRIBBON_BAR_FLOW_VERTICAL)
652 m_scroll_limit = x_cursor;
653 else
654 m_scroll_limit = y_cursor;
655 if(m_scroll_amount >= m_scroll_limit)
656 {
657 m_scroll_amount = m_scroll_limit;
658 m_down_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
659 }
660 else if(m_down_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
661 m_down_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
662
663 if(m_scroll_amount <= 0)
664 {
665 m_scroll_amount = 0;
666 m_up_button_state = wxRIBBON_GALLERY_BUTTON_DISABLED;
667 }
668 else if(m_up_button_state == wxRIBBON_GALLERY_BUTTON_DISABLED)
669 m_up_button_state = wxRIBBON_GALLERY_BUTTON_NORMAL;
670
671 return true;
672}
673
674wxSize wxRibbonGallery::DoGetBestSize() const
675{
676 return m_best_size;
677}
678
679wxSize wxRibbonGallery::DoGetNextSmallerSize(wxOrientation direction,
680 wxSize relative_to) const
681{
682 if(m_art == NULL)
683 return relative_to;
684
685 wxMemoryDC dc;
686
687 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
688 NULL, NULL, NULL);
689 switch(direction)
690 {
691 case wxHORIZONTAL:
692 client.DecBy(1, 0);
693 break;
694 case wxVERTICAL:
695 client.DecBy(0, 1);
696 break;
697 case wxBOTH:
698 client.DecBy(1, 1);
699 break;
700 }
701 if(client.GetWidth() < 0 || client.GetHeight() < 0)
702 return relative_to;
703
704 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
705 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
706
707 wxSize size = m_art->GetGallerySize(dc, this, client);
708 wxSize minimum = GetMinSize();
709
710 if(size.GetWidth() < minimum.GetWidth() ||
711 size.GetHeight() < minimum.GetHeight())
712 {
713 return relative_to;
714 }
715
716 switch(direction)
717 {
718 case wxHORIZONTAL:
719 size.SetHeight(relative_to.GetHeight());
720 break;
721 case wxVERTICAL:
722 size.SetWidth(relative_to.GetWidth());
723 break;
724 default:
725 break;
726 }
727
728 return size;
729}
730
731wxSize wxRibbonGallery::DoGetNextLargerSize(wxOrientation direction,
732 wxSize relative_to) const
733{
734 if(m_art == NULL)
735 return relative_to;
736
737 wxMemoryDC dc;
738
739 wxSize client = m_art->GetGalleryClientSize(dc, this, relative_to, NULL,
740 NULL, NULL, NULL);
741
742 // No need to grow if the given size can already display every item
743 int nitems = (client.GetWidth() / m_bitmap_padded_size.x) *
744 (client.GetHeight() / m_bitmap_padded_size.y);
745 if(nitems >= (int)m_items.GetCount())
746 return relative_to;
747
748 switch(direction)
749 {
750 case wxHORIZONTAL:
751 client.IncBy(m_bitmap_padded_size.x, 0);
752 break;
753 case wxVERTICAL:
754 client.IncBy(0, m_bitmap_padded_size.y);
755 break;
756 case wxBOTH:
757 client.IncBy(m_bitmap_padded_size);
758 break;
759 }
760
761 client.x = (client.x / m_bitmap_padded_size.x) * m_bitmap_padded_size.x;
762 client.y = (client.y / m_bitmap_padded_size.y) * m_bitmap_padded_size.y;
763
764 wxSize size = m_art->GetGallerySize(dc, this, client);
765 wxSize minimum = GetMinSize();
766
767 if(size.GetWidth() < minimum.GetWidth() ||
768 size.GetHeight() < minimum.GetHeight())
769 {
770 return relative_to;
771 }
772
773 switch(direction)
774 {
775 case wxHORIZONTAL:
776 size.SetHeight(relative_to.GetHeight());
777 break;
778 case wxVERTICAL:
779 size.SetWidth(relative_to.GetWidth());
780 break;
781 default:
782 break;
783 }
784
785 return size;
786}
787
788bool wxRibbonGallery::IsEmpty() const
789{
790 return m_items.IsEmpty();
791}
792
793unsigned int wxRibbonGallery::GetCount() const
794{
795 return (unsigned int)m_items.GetCount();
796}
797
798wxRibbonGalleryItem* wxRibbonGallery::GetItem(unsigned int n)
799{
800 if(n >= GetCount())
801 return NULL;
802 return m_items.Item(n);
803}
804
805void wxRibbonGallery::SetSelection(wxRibbonGalleryItem* item)
806{
807 if(item != m_selected_item)
808 {
809 m_selected_item = item;
810 Refresh(false);
811 }
812}
813
814wxRibbonGalleryItem* wxRibbonGallery::GetSelection() const
815{
816 return m_selected_item;
817}
818
819wxRibbonGalleryItem* wxRibbonGallery::GetHoveredItem() const
820{
821 return m_hovered_item;
822}
823
824wxRibbonGalleryItem* wxRibbonGallery::GetActiveItem() const
825{
826 return m_active_item;
827}
828
829wxRibbonGalleryButtonState wxRibbonGallery::GetUpButtonState() const
830{
831 return m_up_button_state;
832}
833
834wxRibbonGalleryButtonState wxRibbonGallery::GetDownButtonState() const
835{
836 return m_down_button_state;
837}
838
839wxRibbonGalleryButtonState wxRibbonGallery::GetExtensionButtonState() const
840{
841 return m_extension_button_state;
842}
843
844#endif // wxUSE_RIBBON