File: figure_common.cpp

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (804 lines) | stat: -rw-r--r-- 21,302 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
/* 
 * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "figure_common.h"
#include "base/string_utilities.h"

using namespace wbfig;
using namespace base;

Titlebar::Titlebar(mdc::Layer *layer, FigureEventHub *hub, BaseFigure *owner, bool expander)
  : mdc::Box(layer, mdc::Box::Horizontal), _hub(hub), _owner(owner), _icon_text(layer)
{
  set_padding(6, 4);
  set_spacing(6);

  _corners= mdc::CNone;
  _back_color= Color(1, 1, 1);
  _border_color= Color(0.7, 0.7, 0.7);

  _icon_text.set_allow_shrinking(true);
  //_icon_text.set_auto_sizing(false);

  add(&_icon_text, true, true);
  
  if (expander)
  {
    _expander= new mdc::Button(layer, mdc::ExpanderButton);
    scoped_connect(_expander->signal_activate(),boost::bind(&Titlebar::expand_toggled, this));
    _expander->set_pen_color(Color(0.4, 0.4, 0.4));
    
    add(_expander, false, false);
  }
  else
    _expander= 0;
}



Titlebar::~Titlebar()
{
  delete _expander;
}


bool Titlebar::on_button_press(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub || !_hub->figure_button_press(_owner->represented_object(), target, point, button, state))
    return super::on_button_press(target, point, button, state);
  return false;
}


bool Titlebar::on_button_release(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub || !_hub->figure_button_release(_owner->represented_object(), target, point, button, state))
    return super::on_button_release(target, point, button, state);
  return false;
}


bool Titlebar::on_enter(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub || !_hub->figure_enter(_owner->represented_object(), target, point))
    return super::on_enter(target, point);
  return false;
}


bool Titlebar::on_leave(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub || !_hub->figure_leave(_owner->represented_object(), target, point))
    return super::on_leave(target, point);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool Titlebar::on_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub || !_hub->figure_click(_owner->represented_object(), target, point, button, state))
    return super::on_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool Titlebar::on_double_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub || !_hub->figure_double_click(_owner->represented_object(), target, point, button, state))
    return super::on_double_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

void Titlebar::set_icon(cairo_surface_t *icon)
{
  _icon_text.set_icon(icon);
}


void Titlebar::set_title(const std::string &text)
{
  _icon_text.set_text(text);
}


void Titlebar::set_expanded(bool flag)
{
  if (_expander && _expander->get_active() != flag)
    _expander->set_active(flag);
}


bool Titlebar::get_expanded()
{
  return _expander->get_active();
}


void Titlebar::expand_toggled()
{
  _signal_expand_toggle(_expander->get_active());
}


void Titlebar::set_color(const Color &color)
{
  _back_color= color;
  set_needs_render();
}


void Titlebar::set_text_color(const Color &color)
{
  _icon_text.set_pen_color(color);
}


void Titlebar::set_border_color(const Color &color)
{
  _border_color= color;
}


void Titlebar::set_font(const mdc::FontSpec &font)
{
  _icon_text.set_font(font);
}


void Titlebar::set_rounded(mdc::CornerMask corners)
{
  _corners= corners;
}


void Titlebar::render(mdc::CairoCtx *cr)
{
  cr->save();

  mdc::stroke_rounded_rectangle(cr, get_bounds(), _corners, 8);

  cr->set_color(_back_color);
  cr->set_line_width(1);

  cr->fill_preserve();
  cr->set_color(_border_color);
  cr->stroke();
  cr->restore();

  mdc::Box::render(cr);
}


void Titlebar::set_auto_sizing(bool flag)
{
  mdc::Box::set_auto_sizing(flag);
  _icon_text.set_auto_sizing(flag);
}


//-------------------------------------------------------------------------------------------------------------


FigureItem::FigureItem(mdc::Layer *layer, FigureEventHub *hub, BaseFigure *owner)
: mdc::IconTextFigure(layer), _hub(hub), _owner(owner), _dirty(true) 
{
  set_font(get_view()->get_default_font());
}


bool FigureItem::on_button_press(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_button_press(_owner->represented_object(), target, point, button, state))
    return super::on_button_press(target, point, button, state);
  return false;
}


bool FigureItem::on_button_release(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_button_release(_owner->represented_object(), target, point, button, state))
    return super::on_button_release(target, point, button, state);
  return false;
}


bool FigureItem::on_enter(mdc::CanvasItem *target, const Point &point)
{
  if (target!= this || !_hub->figure_enter(_owner->represented_object(), target, point))
    return super::on_enter(target, point);
  return false;
}


bool FigureItem::on_leave(mdc::CanvasItem *target, const Point &point)
{
  if (target!= this || !_hub->figure_leave(_owner->represented_object(), target, point))
    return super::on_leave(target, point);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool FigureItem::on_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_click(_owner->represented_object(), target, point, button, state))
    return super::on_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool FigureItem::on_double_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_double_click(_owner->represented_object(), target, point, button, state))
    return super::on_double_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

Point FigureItem::get_intersection_with_line_to(const Point &p)
{
  Point point(mdc::CanvasItem::get_intersection_with_line_to(p));
  Rect bounds(get_root_bounds());

  if (point.x-bounds.left() < bounds.width()/2)
    point.x= bounds.left();
  else
    point.x= bounds.right();

  point.y= (bounds.bottom()+bounds.top())/2;
  
  return point;
}


Rect FigureItem::get_root_bounds() const
{
  if (!get_visible() || !get_parents_visible())
    return get_toplevel()->get_root_bounds();
  return super::get_root_bounds();
}


void FigureItem::draw_state(mdc::CairoCtx *cr)
{
  switch (get_state())
  {
  case Hovering:
    cr->save();
    cr->set_color(get_view()->get_hover_color(), 0.5);
    stroke_outline(cr, 0);
    cr->fill();
    cr->restore();
    break;
  case Highlighted:
    cr->save();
    cr->set_color(_highlight_color ? *_highlight_color : get_view()->get_highlight_color(), 0.3);
    stroke_outline(cr, 0);
    cr->fill();
    cr->restore();
    break;
  default:
    mdc::IconTextFigure::draw_state(cr);
  }
}


//-------------------------------------------------------------------------------------------------------------

BaseFigure::BaseFigure(mdc::Layer *layer, FigureEventHub *hub, const model_ObjectRef &object)
: mdc::Box(layer, mdc::Box::Vertical), _hub(hub)
{
  _represented_object= &object.content();

#ifndef __APPLE__ // disabling caching allows for hidpi correctness
  set_cache_toplevel_contents(true);
#endif
  set_draggable(true);
  _manual_resizing= false;
  _resizing= false;
}


bool BaseFigure::on_button_press(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_button_press(represented_object(), target, point, button, state))
    return super::on_button_press(target, point, button, state);
  return false;
}


bool BaseFigure::on_button_release(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_button_release(represented_object(), target, point, button, state))
    return super::on_button_release(target, point, button, state);
  return false;
}


bool BaseFigure::on_enter(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub->figure_enter(represented_object(), target, point))
    return super::on_enter(target, point);
  return false;
}


bool BaseFigure::on_leave(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub->figure_leave(represented_object(), target, point))
    return super::on_leave(target, point);
  return false;
}


bool BaseFigure::on_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_click(represented_object(), target, point, button, state))
    return super::on_click(target, point, button, state);
  return false;
}

bool BaseFigure::on_double_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (target!= this || !_hub->figure_double_click(represented_object(), target, point, button, state))
    return super::on_double_click(target, point, button, state);
  return false;
}

void BaseFigure::unset_color()
{
  set_draw_background(false);
}


void BaseFigure::set_color(const Color &color)
{
  set_background_color(color);
  set_draw_background(true);
}


void BaseFigure::highlight(const Color *color)
{
  set_highlight_color(color);
  set_highlighted(true);
}


void BaseFigure::unhighlight()
{
  set_highlight_color(0);
  set_highlighted(false);
}



void BaseFigure::set_allow_manual_resizing(bool flag)
{
  _manual_resizing= flag;
  invalidate_min_sizes();
  if (!flag)
    set_fixed_size(Size(-1,-1));
}


void BaseFigure::invalidate_min_sizes(mdc::CanvasItem *item)
{
  item->set_needs_relayout();
  if (dynamic_cast<mdc::Layouter*>(item))
    dynamic_cast<mdc::Layouter*>(item)->foreach(std::ptr_fun(&BaseFigure::invalidate_min_sizes));
}


void BaseFigure::invalidate_min_sizes()
{
  invalidate_min_sizes(this);
}


bool BaseFigure::on_drag_handle(mdc::ItemHandle *handle, const Point &pos, bool dragging)
{
  if (!_manual_resizing)
    set_allow_manual_resizing(true); // TODO: what about undo record?

  if (dragging)
  {
    if (!_resizing)
      _initial_bounds= get_bounds();
    _resizing= true;
  }

  bool flag= super::on_drag_handle(handle, pos, dragging);

  if (!dragging)
  {
    _resizing = false;
    _signal_interactive_resize(_initial_bounds);
  }
  if (flag)
    set_fixed_size(get_size());

  return flag;
}


void BaseFigure::set_content_font(const mdc::FontSpec &font)
{
  _content_font= font;
  if (font.family == "Arial")
    _content_font=font;
}


void BaseFigure::set_state_drawing(bool flag)
{
  _disable_state_drawing= !flag;
}


static BaseFigure::ItemList::iterator find_item(BaseFigure::ItemList &list,
                                           const std::string &id)
{
  for (BaseFigure::ItemList::iterator i= list.begin(); i != list.end(); ++i)
  {
    if ((*i)->get_id() == id)
      return i;
  }
  return list.end();
}



BaseFigure::ItemList::iterator BaseFigure::begin_sync(mdc::Box &box, ItemList &list)
{
  get_layer()->get_view()->lock();
  get_layer()->get_view()->lock_redraw();
  return list.begin();
}


BaseFigure::ItemList::iterator BaseFigure::sync_next(mdc::Box &box, ItemList &list,
                                                     ItemList::iterator iter,
                                                     const std::string &id,
                                                     cairo_surface_t *icon,
                                                     const std::string &text,
                                                     const CreateItemSlot &create_item,
                                                     const UpdateItemSlot &update_item)

{
  ItemList::iterator i= find_item(list, id);
  
  if (i == list.end()) // item is new, insert it
  {
    FigureItem *item;

    if (create_item)
      item= create_item(get_layer(), _hub);
    else
      item= new FigureItem(get_layer(), _hub, this);

    if (update_item)
      update_item(item);

    if (_manual_resizing)
      item->set_auto_sizing(false);
    item->set_allow_shrinking(true);
    item->set_spacing(2);
    item->set_padding(4, 4);
    
    item->set_font(_content_font);

    item->set_icon(icon);
    item->set_text(text);
    item->set_id(id);

    list.insert(iter, item); // insert before

    _signal_item_added(item);

    return iter; // return same
  }
  else if (i == iter) // item is in the same position, just update
  {
    if ((*i)->get_icon() != icon || (*i)->get_text() != text)
    {
      (*i)->set_icon(icon);
      (*i)->set_text(text);
      (*i)->set_dirty();
    }

    if (update_item)
      update_item(*i);

    ++iter; // go to next
    return iter;
  }
  else // item has moved, update and move up
  {
    FigureItem *item= *i;

    (*i)->set_icon(icon);
    (*i)->set_text(text);
    (*i)->set_dirty();
    if (update_item)
      update_item(*i);

    list.erase(i);
    list.insert(iter, item);

    return iter;
  }
}


void BaseFigure::end_sync(mdc::Box &box, ItemList &list, ItemList::iterator iter)
{
  // everything after iter is outdated, so just delete everything
  while (iter != list.end())
  {
    ItemList::iterator next= iter;

    ++next;
    
    delete *iter;
    list.erase(iter);

    iter= next;
  }

  bool dirty= false;

  // first check if anything changed
  for (ItemList::const_iterator i= list.begin(); i!=list.end(); ++i)
  {
    if ((*i)->get_dirty())
      dirty= true;
    (*i)->set_dirty(false);
  }

  // resync box
  if (dirty)
  {
    box.remove_all();
    for (ItemList::const_iterator i= list.begin(); i!=list.end(); ++i)
    {
      box.add(*i, false, true, true);
    }
    box.set_needs_relayout();

    if (_manual_resizing)
    {
      Size size= get_min_size();
      Size fsize= get_fixed_size();

      if (size.height > fsize.height)
        set_fixed_size(Size(fsize.width, size.height));
    }
  }
  get_layer()->get_view()->unlock_redraw();
  get_layer()->get_view()->unlock();
}


//---------------------------------------------------------------------------------------------------

CaptionFigure::CaptionFigure(mdc::Layer *layer, FigureEventHub *hub, model_Object *owner)
: mdc::TextFigure(layer), _hub(hub), _owner_object(owner)
{
  set_draw_outline(true);
}


bool CaptionFigure::on_button_press(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub->figure_button_press(_owner_object, target, point, button, state))
    return super::on_button_press(target, point, button, state);
  return false;
}


bool CaptionFigure::on_button_release(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub->figure_button_release(_owner_object, target, point, button, state))
    return super::on_button_release(target, point, button, state);
  return false;
}


bool CaptionFigure::on_enter(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub->figure_enter(_owner_object, target, point))
    return super::on_enter(target, point);
  return false;
}


bool CaptionFigure::on_leave(mdc::CanvasItem *target, const Point &point)
{
  if (!_hub->figure_leave(_owner_object, target, point))
    return super::on_leave(target, point);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool CaptionFigure::on_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub->figure_click(_owner_object, target, point, button, state))
    return super::on_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

bool CaptionFigure::on_double_click(mdc::CanvasItem *target, const Point &point, mdc::MouseButton button, mdc::EventState state)
{
  if (!_hub->figure_double_click(_owner_object, target, point, button, state))
    return super::on_double_click(target, point, button, state);
  return false;
}

//--------------------------------------------------------------------------------------------------

ShrinkableBox::ShrinkableBox(mdc::Layer *layer, mdc::Box::Orientation orientation)
: mdc::Box(layer, orientation), _manual_resizing(false)
{
  _hidden_item_count= 0;
  _limit_item_count= 0;
}

Size ShrinkableBox::calc_min_size()
{
  if (_manual_resizing)
  {
    if (_children.empty())
      return Size(0,0);//Box::calc_min_size();
    else
    {
      Size min_size= Box::calc_min_size();
      min_size.height= _children.front().item->get_min_size().height;
      
      return min_size;
    }
  }
  else if (_limit_item_count > 0 && _limit_item_count+1 < (int) _children.size())
  {
    Size min_item_size= _children.front().item->get_min_size();
    Size min_size= Box::calc_min_size();

    min_size.height= min_item_size.height * (_limit_item_count+1) + _spacing * (_limit_item_count);
    
    return min_size;
  }
  else
  {
    return Box::calc_min_size();
  }
}

#define EXTRA_LABEL_SIZE 10
#define EXTRA_LABEL_PADDING 2

void ShrinkableBox::resize_to(const Size &size)
{  
  if (!_children.empty() && (_manual_resizing || (_limit_item_count > 0 && _limit_item_count < (int) _children.size())))
  {
    Size used_size;
    int number_of_items_that_fit= 0;
    int i;
    // hide items that won't fit
    Size min_item_size= _children.front().item->get_min_size();
    
    if (_orientation == mdc::Box::Horizontal)
    {
      number_of_items_that_fit= (int) floor((size.width - 2 * _xpadding + _spacing) / (min_item_size.width + _spacing));
    }
    else
    {
      number_of_items_that_fit= (int) floor((size.height - 2 * _ypadding + _spacing) / (min_item_size.height + _spacing));
    }
        
    _hidden_item_count = (int)_children.size() - number_of_items_that_fit;
    if (_hidden_item_count > 0)
    {  
      // add space needed by "X items more..." label
      number_of_items_that_fit= (int) floor((size.height - EXTRA_LABEL_SIZE + _spacing) / (min_item_size.height + _spacing));
      _hidden_item_count = (int)_children.size() - number_of_items_that_fit;
    }
    
    if (number_of_items_that_fit > 0)
    {
      if (_orientation == mdc::Box::Horizontal)
        _visible_part_size= (float) (number_of_items_that_fit * (min_item_size.width + _spacing));
      else
        _visible_part_size= (float) (number_of_items_that_fit * (min_item_size.height + _spacing));
    }
    else
      _visible_part_size= 0;

    i= 0;
    for (ItemList::iterator iter= _children.begin(); iter != _children.end(); ++iter, ++i)
    {
      if (i < number_of_items_that_fit)
        iter->item->set_visible(true);
      else
        iter->item->set_visible(false);
    }
  }
  super::resize_to(size);
}


void ShrinkableBox::set_item_count_limit(int limit)
{
  _limit_item_count= limit;
  
  resize_to(calc_min_size());
}


void ShrinkableBox::set_allow_manual_resizing(bool flag)
{
  if (_manual_resizing != flag)
  {
    _manual_resizing= flag;
    if (!flag)
    {
      for (ItemList::iterator iter= _children.begin(); iter != _children.end(); ++iter)
        iter->item->set_visible(true);
      _hidden_item_count= 0;
    }
    set_needs_relayout();
  }
}


void ShrinkableBox::render(mdc::CairoCtx *cr)
{
  super::render(cr);
  if (_hidden_item_count > 0)
  {
    char text[100];
    sprintf(text, "%i more...", _hidden_item_count);
    Point pos= get_position();
    
    cr->save();
    
    cairo_text_extents_t extents;
    mdc::FontSpec font("Helvetica", mdc::SNormal, mdc::WNormal, EXTRA_LABEL_SIZE);
    
    cr->get_text_extents(font, text, extents);
    cr->set_font(font);
    pos.y+= _visible_part_size + (get_size().height - 2*_ypadding - _visible_part_size - extents.height) / 2 - extents.y_bearing;
    pos.x+= (get_size().width - extents.width) / 2;
    
    cr->move_to(pos);
    cr->show_text(text);
    cr->stroke();
    
    cr->restore();
  }
}