Style.h
1 /* Copyright (C) 2016 Laurentiu-Gheorghe Crisan
2  Copyright (C) 2016 Marc Boris Duerner
3  Copyright (C) 2017 Ilja Maier
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  As a special exception, you may use this file as part of a free
11  software library without restriction. Specifically, if other files
12  instantiate templates or use macros or inline functions from this
13  file, or you compile this file and link it with other files to
14  produce an executable, this file does not by itself cause the
15  resulting executable to be covered by the GNU General Public
16  License. This exception does not however invalidate any other
17  reasons why the executable file might be covered by the GNU Library
18  General Public License.
19 
20  This library is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23  Lesser General Public License for more details.
24 
25  You should have received a copy of the GNU Lesser General Public
26  License along with this library; if not, write to the Free Software
27  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28  MA 02110-1301 USA
29 */
30 
31 #ifndef Pt_Forms_Style_h
32 #define Pt_Forms_Style_h
33 
34 #include <Pt/Forms/Api.h>
35 #include <Pt/Forms/Spacing.h>
36 #include <Pt/Forms/PaintSurface.h>
37 #include <Pt/Gfx/Painter.h>
38 #include <Pt/Gfx/Color.h>
39 #include <Pt/Gfx/Brush.h>
40 #include <Pt/Gfx/Pen.h>
41 #include <Pt/Gfx/Rect.h>
42 #include <Pt/Gfx/Font.h>
43 #include <Pt/Gfx/TextMetrics.h>
44 #include <Pt/TypeInfo.h>
45 #include <Pt/NonCopyable.h>
46 
47 #include <map>
48 #include <cstddef>
49 
50 namespace Pt {
51 
52 namespace Forms {
53 
54 class Pixmap;
55 class StyleOptions;
56 class Panel;
57 class Label;
58 class LineEdit;
59 class PushButton;
60 class CheckBox;
61 class ComboBox;
62 class Menu;
63 class MenuItem;
64 class MenuBar;
65 class MenuBarItem;
66 class ScrollBar;
67 class Slider;
68 class SpinBox;
69 class SpinBoxButton;
70 class ProgressBar;
71 class ListBox;
72 class ListBoxItem;
73 class TabView;
74 class TabBar;
75 class TabItem;
76 
77 template <typename T>
78 class FacetPtr
79 {
80  public:
81  FacetPtr(T* facet = 0)
82  : _facet(facet)
83  {
84  if( _facet )
85  _facet->ref();
86  }
87 
88  FacetPtr(const FacetPtr& ptr)
89  : _facet(ptr._facet)
90  {
91  if( _facet )
92  _facet->ref();
93  }
94 
95  ~FacetPtr()
96  {
97  if(_facet)
98  {
99  if( 0 == _facet->unref() )
100  delete _facet;
101  }
102  }
103 
104  FacetPtr& operator=(const FacetPtr& ptr)
105  {
106  if(this == &ptr)
107  return *this;
108 
109  if(_facet)
110  {
111  if( 0 == _facet->unref() )
112  delete _facet;
113  }
114 
115  _facet = ptr._facet;
116  if( _facet )
117  _facet->ref();
118 
119  return *this;
120  }
121 
122  void reset(T* facet = 0)
123  {
124  if (_facet == facet)
125  return;
126 
127  if(_facet)
128  {
129  if( 0 == _facet->unref() )
130  delete _facet;
131  }
132 
133  _facet = facet;
134  if( _facet )
135  _facet->ref();
136  }
137 
138  T* operator->() const
139  { return _facet; }
140 
141  T& operator*() const
142  { return *_facet; }
143 
144  bool operator! () const
145  { return _facet == 0; }
146 
147  operator bool () const
148  { return _facet != 0; }
149 
150  T* get()
151  { return _facet; }
152 
153  const T* get() const
154  { return _facet; }
155 
156  private:
157  T* _facet;
158 };
159 
160 class PT_FORMS_API Style
161 {
162  public:
163  class Facet : private NonCopyable
164  {
165  public:
166  explicit Facet(const std::type_info& ti, std::size_t refs = 0)
167  : _typeId(&ti)
168  , _refs(refs)
169  {}
170 
171  virtual ~Facet()
172  {}
173 
174  const std::type_info& typeId() const
175  {
176  return *_typeId;
177  }
178 
179  void ref()
180  {
181  ++_refs;
182  }
183 
184  std::size_t unref()
185  {
186  return --_refs;
187  }
188 
189  private:
190  const std::type_info* _typeId;
191  std::size_t _refs;
192  };
193 
194  public:
195  Style();
196 
197  Style(const Style& style);
198 
199  virtual ~Style();
200 
201  Style& operator=(const Style& style);
202 
203  void assign(const Style& style);
204 
205  void combine(const Style& style);
206 
207  void set(Facet* facet);
208 
209  template <typename FacetT>
210  FacetT* get() const
211  {
212  Facet* facet = find( typeid(FacetT) );
213  return static_cast<FacetT*>(facet);
214  }
215 
216  private:
217  Facet* find(const std::type_info& ti) const;
218 
219  private:
220  typedef std::map<TypeInfo, Facet*> FacetMap;
221  FacetMap _facets;
222 };
223 
224 
225 class PT_FORMS_API ButtonRenderer : public Style::Facet
226 {
227  public:
228  ButtonRenderer(std::size_t refs = 0);
229 
230  virtual ~ButtonRenderer();
231 
232  void prepare(const PushButton& button,
233  const StyleOptions& options,
234  Gfx::Brush& brush,
235  Gfx::Pen& contour,
236  Gfx::Font& font,
237  Gfx::Pen& textPen) const;
238 
239  void prepareIcon(const PushButton& button,
240  const StyleOptions& options,
241  const Gfx::Image& icon,
242  Pixmap& picture) const;
243 
244  void renderBackground(const PushButton& button,
245  const StyleOptions& options,
246  Gfx::Painter& painter,
247  const Gfx::RectF& rect,
248  const Gfx::Brush& brush,
249  const Gfx::Pen& pen) const;
250 
251  void renderText(const PushButton& button,
252  const StyleOptions& options,
253  Gfx::Painter& painter,
254  const Gfx::RectF& rect,
255  const String& text,
256  const Gfx::PointF& textPos,
257  const Gfx::Font& font,
258  const Gfx::Pen& textPen,
259  const Gfx::RectF& mnemonic) const;
260 
261  protected:
262  virtual void onPrepare(const PushButton& button,
263  const StyleOptions& options,
264  Gfx::Brush& brush,
265  Gfx::Pen& contour,
266  Gfx::Font& font,
267  Gfx::Pen& textPen) const = 0;
268 
269  virtual void onPrepareIcon(const PushButton& button,
270  const StyleOptions& options,
271  const Gfx::Image& icon,
272  Pixmap& picture) const = 0;
273 
274  virtual void onRenderBackground(const PushButton& button,
275  const StyleOptions& options,
276  Gfx::Painter& painter,
277  const Gfx::RectF& rect,
278  const Gfx::Brush& brush,
279  const Gfx::Pen& pen) const = 0;
280 
281  virtual void onRenderText(const PushButton& button,
282  const StyleOptions& options,
283  Gfx::Painter& painter,
284  const Gfx::RectF& rect,
285  const String& text,
286  const Gfx::PointF& textPos,
287  const Gfx::Font& font,
288  const Gfx::Pen& textPen,
289  const Gfx::RectF& mnemonic) const = 0;
290 };
291 
292 
293 class PT_FORMS_API CheckBoxRenderer : public Style::Facet
294 {
295  public:
296  CheckBoxRenderer(std::size_t refs = 0);
297 
298  virtual ~CheckBoxRenderer();
299 
300  void prepare(const CheckBox& cb,
301  const StyleOptions& options,
302  Gfx::Brush& brush,
303  Gfx::Pen& contour,
304  Gfx::Font& font,
305  Gfx::Pen& textPen,
306  Gfx::SizeF& boxSize) const;
307 
308  void renderBox(const CheckBox& cb,
309  const StyleOptions& options,
310  Gfx::Painter& painter,
311  const Gfx::RectF& rect,
312  const Gfx::RectF& boxRect,
313  const Gfx::Brush& brush,
314  const Gfx::Pen& pen) const;
315 
316  void renderText(const CheckBox& cb,
317  const StyleOptions& options,
318  Gfx::Painter& painter,
319  const Gfx::RectF& rect,
320  const String& text,
321  const Gfx::PointF& textPos,
322  const Gfx::TextMetrics& textMetric,
323  const Gfx::Font& font,
324  const Gfx::Pen& textPen,
325  const Gfx::RectF& mnemonic) const;
326 
327  protected:
328  virtual void onPrepare(const CheckBox& cb,
329  const StyleOptions& options,
330  Gfx::Brush& brush,
331  Gfx::Pen& contour,
332  Gfx::Font& font,
333  Gfx::Pen& textPen,
334  Gfx::SizeF& boxSize) const = 0;
335 
336  virtual void onRenderBox(const CheckBox& cb,
337  const StyleOptions& options,
338  Gfx::Painter& painter,
339  const Gfx::RectF& rect,
340  const Gfx::RectF& boxRect,
341  const Gfx::Brush& brush,
342  const Gfx::Pen& pen) const = 0;
343 
344  virtual void onRenderText(const CheckBox& cb,
345  const StyleOptions& options,
346  Gfx::Painter& painter,
347  const Gfx::RectF& rect,
348  const String& text,
349  const Gfx::PointF& textPos,
350  const Gfx::TextMetrics& textMetric,
351  const Gfx::Font& font,
352  const Gfx::Pen& textPen,
353  const Gfx::RectF& mnemonic) const = 0;
354 };
355 
356 
357 class PT_FORMS_API PanelRenderer : public Style::Facet
358 {
359  public:
360  PanelRenderer(std::size_t refs = 0);
361 
362  virtual ~PanelRenderer();
363 
364  void renderBackground(const Panel& p,
365  const StyleOptions& options,
366  Gfx::Painter& painter,
367  const Gfx::RectF& rect,
368  const Gfx::Brush& brush) const;
369 
370  void renderFrame(const Panel& p,
371  const StyleOptions& options,
372  Gfx::Painter& painter,
373  const Gfx::RectF& rect,
374  const Gfx::Pen& pen) const;
375 
376  protected:
377  virtual void onRenderBackground(const Panel& p,
378  const StyleOptions& options,
379  Gfx::Painter& painter,
380  const Gfx::RectF& rect,
381  const Gfx::Brush& brush) const = 0;
382 
383  virtual void onRenderFrame(const Panel& p,
384  const StyleOptions& options,
385  Gfx::Painter& painter,
386  const Gfx::RectF& rect,
387  const Gfx::Pen& pen) const = 0;
388 };
389 
390 
391 class PT_FORMS_API LabelRenderer : public Style::Facet
392 {
393  public:
394  LabelRenderer(std::size_t refs = 0);
395 
396  virtual ~LabelRenderer();
397 
398  void prepare(const Label& l,
399  const StyleOptions& options,
400  Gfx::Font& font,
401  Gfx::Pen& contour,
402  Gfx::Pen& textPen) const;
403 
404  void renderBackground(const Label& l,
405  const StyleOptions& options,
406  Gfx::Painter& p,
407  const Gfx::RectF& rect,
408  const Gfx::Brush& brush) const;
409 
410  void renderFrame(const Label& l,
411  const StyleOptions& options,
412  Gfx::Painter& p,
413  const Gfx::RectF& rect,
414  const Gfx::Pen& contour) const;
415 
416  void renderText(const Label& l,
417  const StyleOptions& options,
418  Gfx::Painter& p,
419  const Gfx::RectF& rect,
420  const String& text,
421  const Gfx::PointF& textPos,
422  const Gfx::Font& font,
423  const Gfx::Pen& textPen) const;
424 
425  protected:
426  virtual void onPrepare(const Label& l,
427  const StyleOptions& options,
428  Gfx::Font& font,
429  Gfx::Pen& contour,
430  Gfx::Pen& textPen) const = 0;
431 
432  virtual void onRenderBackground(const Label& l,
433  const StyleOptions& options,
434  Gfx::Painter& p,
435  const Gfx::RectF& rect,
436  const Gfx::Brush& brush) const = 0;
437 
438  virtual void onRenderFrame(const Label& l,
439  const StyleOptions& options,
440  Gfx::Painter& p,
441  const Gfx::RectF& rect,
442  const Gfx::Pen& contour) const = 0;
443 
444  virtual void onRenderText(const Label& l,
445  const StyleOptions& options,
446  Gfx::Painter& p,
447  const Gfx::RectF& rect,
448  const String& text,
449  const Gfx::PointF& textPos,
450  const Gfx::Font& font,
451  const Gfx::Pen& textPen) const = 0;
452 };
453 
454 class PT_FORMS_API LineEditRenderer : public Style::Facet
455 {
456  public:
457  LineEditRenderer(std::size_t refs = 0);
458 
459  virtual ~LineEditRenderer();
460 
461  void prepare(const LineEdit& le,
462  const StyleOptions& options,
463  Gfx::Brush& brush,
464  Gfx::Pen& contour,
465  Gfx::Font& font,
466  Gfx::Pen& textPen) const;
467 
468  void renderBackground(const LineEdit& le,
469  const StyleOptions& options,
470  Gfx::Painter& painter,
471  const Gfx::RectF& rect,
472  const Gfx::Pen& contour,
473  const Gfx::Brush& brush) const;
474 
475  void renderText(const LineEdit& le,
476  const StyleOptions& options,
477  Gfx::Painter& painter,
478  const Gfx::RectF& rect,
479  const String& text,
480  const Gfx::PointF& textPos,
481  const Gfx::Font& font,
482  const Gfx::Pen& textPen) const;
483 
484  void renderCursor(const LineEdit& le,
485  const StyleOptions& options,
486  Gfx::Painter& painter,
487  const Gfx::RectF& rect,
488  const Gfx::RectF& cursorRect ) const;
489 
490  protected:
491  virtual void onPrepare(const LineEdit& le,
492  const StyleOptions& options,
493  Gfx::Brush& brush,
494  Gfx::Pen& contour,
495  Gfx::Font& font,
496  Gfx::Pen& textPen) const = 0;
497 
498  virtual void onRenderBackground(const LineEdit& le,
499  const StyleOptions& options,
500  Gfx::Painter& painter,
501  const Gfx::RectF& rect,
502  const Gfx::Pen& contour,
503  const Gfx::Brush& brush) const = 0;
504 
505  virtual void onRenderText(const LineEdit& le,
506  const StyleOptions& options,
507  Gfx::Painter& painter,
508  const Gfx::RectF& rect,
509  const String& text,
510  const Gfx::PointF& textPos,
511  const Gfx::Font& font,
512  const Gfx::Pen& textPen) const = 0;
513 
514  virtual void onRenderCursor(const LineEdit& le,
515  const StyleOptions& options,
516  Gfx::Painter& painter,
517  const Gfx::RectF& rect,
518  const Gfx::RectF& cursorRect ) const = 0;
519 };
520 
521 class PT_FORMS_API MenuRenderer : public Style::Facet
522 {
523  public:
524  MenuRenderer(std::size_t refs = 0);
525 
526  virtual ~MenuRenderer();
527 
528  void prepare(const Menu& m,
529  const StyleOptions& options,
530  Gfx::Brush& brush,
531  Gfx::Pen& contour) const;
532 
533  void prepareItem(const MenuItem& m,
534  const StyleOptions& options,
535  const Gfx::Image& icon,
536  Pixmap& picture,
537  Gfx::Brush& brush,
538  Gfx::Pen& contour,
539  Gfx::Font& font,
540  Gfx::Pen& textPen) const;
541 
542  void renderBackground(const Menu& m,
543  const StyleOptions& options,
544  Gfx::Painter& painter,
545  const Gfx::RectF& rect,
546  const Gfx::Brush& brush,
547  const Gfx::Pen& contour) const;
548 
549  void renderItem(const MenuItem& m,
550  const StyleOptions& options,
551  Gfx::Painter& painter,
552  const Gfx::RectF& rect,
553  Gfx::Brush& brush,
554  Gfx::Pen& contour) const;
555 
556  void renderIndicator(const MenuItem& m,
557  const StyleOptions& options,
558  Gfx::Painter& painter,
559  const Gfx::RectF& rect) const;
560 
561  protected:
562  virtual void onPrepare(const Menu& m,
563  const StyleOptions& options,
564  Gfx::Brush& brush,
565  Gfx::Pen& contour) const = 0;
566 
567  virtual void onPrepareItem(const MenuItem& m,
568  const StyleOptions& options,
569  const Gfx::Image& icon,
570  Pixmap& picture,
571  Gfx::Brush& brush,
572  Gfx::Pen& contour,
573  Gfx::Font& font,
574  Gfx::Pen& textPen) const = 0;
575 
576  virtual void onRenderBackground(const Menu& m,
577  const StyleOptions& options,
578  Gfx::Painter& painter,
579  const Gfx::RectF& rect,
580  const Gfx::Brush& brush,
581  const Gfx::Pen& contour) const = 0;
582 
583  virtual void onRenderItem(const MenuItem& m,
584  const StyleOptions& options,
585  Gfx::Painter& painter,
586  const Gfx::RectF& rect,
587  Gfx::Brush& brush,
588  Gfx::Pen& contour) const = 0;
589 
590  virtual void onRenderIndicator(const MenuItem& m,
591  const StyleOptions& options,
592  Gfx::Painter& painter,
593  const Gfx::RectF& rect) const = 0;
594 };
595 
596 class PT_FORMS_API MenuBarRenderer : public Style::Facet
597 {
598  public:
599  MenuBarRenderer(std::size_t refs = 0);
600 
601  virtual ~MenuBarRenderer();
602 
603  void prepare(const MenuBar& m,
604  const StyleOptions& options,
605  Gfx::Brush& brush,
606  Gfx::Pen& contour) const;
607 
608  void renderBackground(const MenuBar& m,
609  const StyleOptions& options,
610  Gfx::Painter& painter,
611  const Gfx::RectF& rect,
612  const Gfx::Brush& brush,
613  const Gfx::Pen& contour) const;
614 
615  void prepareItem(const MenuBarItem& m,
616  const StyleOptions& options,
617  Gfx::Brush& brush,
618  Gfx::Pen& contour,
619  Gfx::Font& font,
620  Gfx::Pen& textPen) const;
621 
622  void renderItem(const MenuBarItem& m,
623  const StyleOptions& options,
624  Gfx::Painter& painter,
625  const Gfx::RectF& rect,
626  const Gfx::Brush& brush,
627  const Gfx::Pen& contour) const;
628 
629  void renderItemText(const MenuBarItem& m,
630  const StyleOptions& options,
631  Gfx::Painter& painter,
632  const Gfx::RectF& rect,
633  const String& text,
634  const Gfx::PointF& textPos,
635  const Gfx::Font& font,
636  const Gfx::Pen& textPen,
637  const Gfx::RectF& mnemonic) const;
638 
639  protected:
640  virtual void onPrepare(const MenuBar& m,
641  const StyleOptions& options,
642  Gfx::Brush& brush,
643  Gfx::Pen& contour) const = 0;
644 
645  virtual void onRenderBackground(const MenuBar& m,
646  const StyleOptions& options,
647  Gfx::Painter& painter,
648  const Gfx::RectF& rect,
649  const Gfx::Brush& brush,
650  const Gfx::Pen& contour) const = 0;
651 
652  virtual void onPrepareItem(const MenuBarItem& m,
653  const StyleOptions& options,
654  Gfx::Brush& brush,
655  Gfx::Pen& contour,
656  Gfx::Font& font,
657  Gfx::Pen& textPen) const = 0;
658 
659  virtual void onRenderItem(const MenuBarItem& m,
660  const StyleOptions& options,
661  Gfx::Painter& painter,
662  const Gfx::RectF& rect,
663  const Gfx::Brush& brush,
664  const Gfx::Pen& contour) const = 0;
665 
666  virtual void onRenderItemText(const MenuBarItem& m,
667  const StyleOptions& options,
668  Gfx::Painter& painter,
669  const Gfx::RectF& rect,
670  const String& text,
671  const Gfx::PointF& textPos,
672  const Gfx::Font& font,
673  const Gfx::Pen& textPen,
674  const Gfx::RectF& mnemonic) const = 0;
675 };
676 
677 
678 class PT_FORMS_API ScrollBarRenderer : public Style::Facet
679 {
680  public:
681  ScrollBarRenderer(std::size_t refs = 0);
682 
683  virtual ~ScrollBarRenderer();
684 
685  void prepare(const ScrollBar& s,
686  const StyleOptions& options,
687  Gfx::Brush& background,
688  Gfx::Brush& foreground,
689  Gfx::Pen& contour) const;
690 
691  void render(const ScrollBar& s,
692  const StyleOptions& options,
693  Gfx::Painter& painter,
694  const Gfx::RectF& rect,
695  const Gfx::RectF& handleRect,
696  const Gfx::Brush& background,
697  const Gfx::Brush& foreground,
698  const Gfx::Pen& contour) const;
699 
700  protected:
701  virtual void onPrepare(const ScrollBar& s,
702  const StyleOptions& options,
703  Gfx::Brush& background,
704  Gfx::Brush& foreground,
705  Gfx::Pen& contour) const = 0;
706 
707  virtual void onRender(const ScrollBar& s,
708  const StyleOptions& options,
709  Gfx::Painter& painter,
710  const Gfx::RectF& rect,
711  const Gfx::RectF& handleRect,
712  const Gfx::Brush& background,
713  const Gfx::Brush& foreground,
714  const Gfx::Pen& contour) const = 0;
715 };
716 
717 
718 class PT_FORMS_API ProgressBarRenderer : public Style::Facet
719 {
720  public:
721  ProgressBarRenderer(std::size_t refs = 0);
722 
723  virtual ~ProgressBarRenderer();
724 
725  void prepare(const ProgressBar& p,
726  const StyleOptions& options,
727  Gfx::Brush& background,
728  Gfx::Brush& foreground,
729  Gfx::Pen& contour,
730  Gfx::Pen& textPen,
731  Gfx::Font& font
732  ) const;
733 
734  void render( const ProgressBar& p,
735  const StyleOptions& options,
736  Gfx::Painter& painter,
737  const Gfx::RectF& rect,
738  const Gfx::Brush& background,
739  const Gfx::Brush& foreground,
740  const Gfx::Pen& contour,
741  const Gfx::Pen& textPen,
742  const Gfx::Font& font
743  ) const;
744 
745  protected:
746  virtual void onPrepare(const ProgressBar& p,
747  const StyleOptions& options,
748  Gfx::Brush& background,
749  Gfx::Brush& foreground,
750  Gfx::Pen& contour,
751  Gfx::Pen& textPen,
752  Gfx::Font& font
753  ) const = 0;
754 
755  virtual void onRender( const ProgressBar& p,
756  const StyleOptions& options,
757  Gfx::Painter& painter,
758  const Gfx::RectF& rect,
759  const Gfx::Brush& background,
760  const Gfx::Brush& foreground,
761  const Gfx::Pen& contour,
762  const Gfx::Pen& textPen,
763  const Gfx::Font& font
764  ) const = 0;
765 };
766 
767 
768 class PT_FORMS_API SliderRenderer : public Style::Facet
769 {
770  public:
771  SliderRenderer(std::size_t refs = 0);
772 
773  virtual ~SliderRenderer();
774 
775  void prepare( const Slider& s,
776  const StyleOptions& options,
777  Gfx::Brush& background,
778  Gfx::Brush& foreground,
779  Gfx::Pen& contour,
780  Gfx::Pen& textPen,
781  Gfx::Font& font
782  ) const;
783 
784  void render( const Slider& s,
785  const StyleOptions& options,
786  Gfx::Painter& painter,
787  const Gfx::RectF& rect,
788  const Gfx::Brush& background,
789  const Gfx::Brush& foreground,
790  const Gfx::Pen& contour,
791  const Gfx::Pen& textPen,
792  const Gfx::Font& font
793  ) const;
794 
795  protected:
796  virtual void onPrepare( const Slider& s,
797  const StyleOptions& options,
798  Gfx::Brush& background,
799  Gfx::Brush& foreground,
800  Gfx::Pen& contour,
801  Gfx::Pen& textPen,
802  Gfx::Font& font
803  ) const = 0;
804 
805  virtual void onRender( const Slider& s,
806  const StyleOptions& options,
807  Gfx::Painter& painter,
808  const Gfx::RectF& rect,
809  const Gfx::Brush& background,
810  const Gfx::Brush& foreground,
811  const Gfx::Pen& contour,
812  const Gfx::Pen& textPen,
813  const Gfx::Font& font
814  ) const = 0;
815 };
816 
817 
818 class PT_FORMS_API ListBoxRenderer : public Style::Facet
819 {
820  public:
821  ListBoxRenderer(std::size_t refs = 0);
822 
823  virtual ~ListBoxRenderer();
824 
825  void prepareLayout(Spacing& frameSize);
826 
827  void renderBackground(const ListBox& lb,
828  const StyleOptions& options,
829  Gfx::Painter& painter,
830  const Gfx::RectF& rect,
831  const Gfx::Brush& brush) const;
832 
833  void renderFrame(const ListBox& lb,
834  const StyleOptions& options,
835  Gfx::Painter& painter,
836  const Gfx::RectF& rect,
837  const Gfx::Pen& pen) const;
838 
839  void prepareItem(const ListBoxItem& item,
840  const StyleOptions& options,
841  Gfx::Brush& brush,
842  Gfx::Pen& contour,
843  Gfx::Font& font,
844  Gfx::Pen& textPen) const;
845 
846  void renderItem(const ListBoxItem& item,
847  const StyleOptions& options,
848  Gfx::Painter& painter,
849  const Gfx::RectF& rect,
850  Gfx::Brush& brush,
851  Gfx::Pen& contour) const;
852 
853  protected:
854  virtual void onPrepareLayout(Spacing& frameSize) = 0;
855 
856  virtual void onRenderBackground(const ListBox& lb,
857  const StyleOptions& options,
858  Gfx::Painter& painter,
859  const Gfx::RectF& rect,
860  const Gfx::Brush& brush) const = 0;
861 
862  virtual void onRenderFrame(const ListBox& lb,
863  const StyleOptions& options,
864  Gfx::Painter& painter,
865  const Gfx::RectF& rect,
866  const Gfx::Pen& pen) const = 0;
867 
868  virtual void onPrepareItem(const ListBoxItem& item,
869  const StyleOptions& options,
870  Gfx::Brush& brush,
871  Gfx::Pen& contour,
872  Gfx::Font& font,
873  Gfx::Pen& textPen) const = 0;
874 
875  virtual void onRenderItem(const ListBoxItem& item,
876  const StyleOptions& options,
877  Gfx::Painter& painter,
878  const Gfx::RectF& rect,
879  Gfx::Brush& brush,
880  Gfx::Pen& contour) const = 0;
881 };
882 
883 
884 class PT_FORMS_API ComboBoxRenderer : public Style::Facet
885 {
886  public:
887  ComboBoxRenderer(std::size_t refs = 0);
888 
889  virtual ~ComboBoxRenderer();
890 
891  void prepare(const ComboBox& cb,
892  const StyleOptions& options,
893  Gfx::Brush& background,
894  Gfx::Brush& foreground,
895  Gfx::Pen& contour,
896  Gfx::Font& font,
897  Gfx::Pen& textPen) const;
898 
899  void prepareLayout(const ComboBox& cb,
900  Gfx::SizeF& buttonSize) const;
901 
902  void renderBackground(const ComboBox& cb,
903  const StyleOptions& options,
904  Gfx::Painter& painter,
905  const Gfx::RectF& rect,
906  const Gfx::Pen& contour,
907  const Gfx::Brush& brush) const;
908 
909  void renderButton(const ComboBox& cb,
910  const StyleOptions& options,
911  Gfx::Painter& painter,
912  const Gfx::RectF& rect,
913  const Gfx::Pen& contour,
914  const Gfx::Brush& foreground) const;
915 
916  void renderText(const ComboBox& cb,
917  const StyleOptions& options,
918  Gfx::Painter& painter,
919  const Gfx::RectF& rect,
920  const String& text,
921  const Gfx::PointF& textPos,
922  const Gfx::Font& font,
923  const Gfx::Pen& textPen,
924  const Gfx::RectF& cursor) const;
925 
926  protected:
927  virtual void onPrepare(const ComboBox& cb,
928  const StyleOptions& options,
929  Gfx::Brush& background,
930  Gfx::Brush& foreground,
931  Gfx::Pen& contour,
932  Gfx::Font& font,
933  Gfx::Pen& textPen) const = 0;
934 
935  virtual void onPrepareLayout(const ComboBox& cb,
936  Gfx::SizeF& buttonSize) const = 0;
937 
938  virtual void onRenderBackground(const ComboBox& cb,
939  const StyleOptions& options,
940  Gfx::Painter& painter,
941  const Gfx::RectF& rect,
942  const Gfx::Pen& contour,
943  const Gfx::Brush& brush) const = 0;
944 
945  virtual void onRenderButton(const ComboBox& cb,
946  const StyleOptions& options,
947  Gfx::Painter& painter,
948  const Gfx::RectF& rect,
949  const Gfx::Pen& contour,
950  const Gfx::Brush& foreground) const = 0;
951 
952  virtual void onRenderText(const ComboBox& cb,
953  const StyleOptions& options,
954  Gfx::Painter& painter,
955  const Gfx::RectF& rect,
956  const String& text,
957  const Gfx::PointF& textPos,
958  const Gfx::Font& font,
959  const Gfx::Pen& textPen,
960  const Gfx::RectF& cursor) const = 0;
961 };
962 
963 
964 class PT_FORMS_API SpinBoxRenderer : public Style::Facet
965 {
966  public:
967  SpinBoxRenderer(std::size_t refs = 0);
968 
969  virtual ~SpinBoxRenderer();
970 
971  void prepare(const SpinBox& sb,
972  const StyleOptions& options,
973  Gfx::Brush& background,
974  Gfx::Pen& contour,
975  Gfx::Font& font,
976  Gfx::Pen& textPen) const;
977 
978  void prepareButton(const SpinBoxButton& sb,
979  const StyleOptions& options,
980  Gfx::Brush& foreground,
981  Gfx::Pen& contour) const;
982 
983  void layout(const SpinBox& sb,
984  Gfx::RectF& downButton,
985  Gfx::RectF& upButton,
986  Gfx::RectF& textBox) const;
987 
988  void renderBackground(const SpinBox& sb,
989  const StyleOptions& options,
990  Gfx::Painter& painter,
991  const Gfx::RectF& rect,
992  const Gfx::Pen& contour,
993  const Gfx::Brush& brush) const;
994 
995  void renderButton(const SpinBoxButton& sb,
996  const StyleOptions& options,
997  Gfx::Painter& painter,
998  const Gfx::RectF& rect,
999  const Gfx::Brush& foreground,
1000  const Gfx::Pen& contour) const;
1001 
1002  void renderText(const SpinBox& sb,
1003  const StyleOptions& options,
1004  Gfx::Painter& painter,
1005  const Gfx::RectF& rect,
1006  const String& text,
1007  const Gfx::PointF& textPos,
1008  const Gfx::Font& font,
1009  const Gfx::Pen& textPen,
1010  const Gfx::RectF& cursor) const;
1011 
1012  protected:
1013  virtual void onPrepare(const SpinBox& sb,
1014  const StyleOptions& options,
1015  Gfx::Brush& background,
1016  Gfx::Pen& contour,
1017  Gfx::Font& font,
1018  Gfx::Pen& textPen) const = 0;
1019 
1020  virtual void onPrepareButton(const SpinBoxButton& sb,
1021  const StyleOptions& options,
1022  Gfx::Brush& foreground,
1023  Gfx::Pen& contour) const = 0;
1024 
1025  virtual void onLayout(const SpinBox& sb,
1026  Gfx::RectF& downButton,
1027  Gfx::RectF& upButton,
1028  Gfx::RectF& textBox) const = 0;
1029 
1030  virtual void onRenderBackground(const SpinBox& sb,
1031  const StyleOptions& options,
1032  Gfx::Painter& painter,
1033  const Gfx::RectF& rect,
1034  const Gfx::Pen& contour,
1035  const Gfx::Brush& brush) const = 0;
1036 
1037  virtual void onRenderButton(const SpinBoxButton& sb,
1038  const StyleOptions& options,
1039  Gfx::Painter& painter,
1040  const Gfx::RectF& rect,
1041  const Gfx::Brush& foreground,
1042  const Gfx::Pen& contour) const = 0;
1043 
1044  virtual void onRenderText(const SpinBox& sb,
1045  const StyleOptions& options,
1046  Gfx::Painter& painter,
1047  const Gfx::RectF& rect,
1048  const String& text,
1049  const Gfx::PointF& textPos,
1050  const Gfx::Font& font,
1051  const Gfx::Pen& textPen,
1052  const Gfx::RectF& cursor) const = 0;
1053 };
1054 
1055 
1056 class PT_FORMS_API TabViewRenderer : public Style::Facet
1057 {
1058  public:
1059  TabViewRenderer(std::size_t refs = 0);
1060 
1061  virtual ~TabViewRenderer();
1062 
1063  void prepare(const TabView& tv,
1064  const StyleOptions& options,
1065  Gfx::Brush& background,
1066  Gfx::Brush& foreground,
1067  Gfx::Pen& contour) const;
1068 
1069  void render(const TabView& tv,
1070  const StyleOptions& options,
1071  Gfx::Painter& painter,
1072  const Gfx::RectF& rect,
1073  const Gfx::Brush& background,
1074  const Gfx::Brush& foreground,
1075  const Gfx::Pen& contour) const;
1076 
1077  Gfx::SizeF measureTabs(PaintSurface& surface,
1078  const std::vector<TabItem>& tabs,
1079  const Gfx::Font& font) const;
1080 
1081  void layoutTabs(PaintSurface& surface,
1082  std::vector<TabItem>& tabs,
1083  const Gfx::RectF& rect,
1084  const Gfx::Font& font) const;
1085 
1086  void prepareTabs(const TabBar& tabs,
1087  const StyleOptions& options,
1088  const Gfx::Brush& background,
1089  const Gfx::Brush& foreground,
1090  const Gfx::Pen& contour,
1091  const Gfx::Font& font,
1092  const Gfx::Pen& textPen) const;
1093 
1094  void renderTabs(const std::vector<TabItem>& tabs,
1095  const StyleOptions& options,
1096  Gfx::Painter& painter,
1097  const Gfx::RectF& rect,
1098  const Gfx::Brush& background,
1099  const Gfx::Brush& foreground,
1100  const Gfx::Pen& contour,
1101  const Gfx::Font& font,
1102  const Gfx::Pen& textPen) const;
1103 
1104  protected:
1105  virtual void onPrepare(const TabView& tv,
1106  const StyleOptions& options,
1107  Gfx::Brush& background,
1108  Gfx::Brush& foreground,
1109  Gfx::Pen& contour) const = 0;
1110 
1111  virtual void onRender(const TabView& tv,
1112  const StyleOptions& options,
1113  Gfx::Painter& painter,
1114  const Gfx::RectF& rect,
1115  const Gfx::Brush& background,
1116  const Gfx::Brush& foreground,
1117  const Gfx::Pen& contour) const = 0;
1118 
1119  virtual Gfx::SizeF onMeasureTabs(PaintSurface& surface,
1120  const std::vector<TabItem>& tabs,
1121  const Gfx::Font& font) const = 0;
1122 
1123  virtual void onLayoutTabs(PaintSurface& surface,
1124  std::vector<TabItem>& tabs,
1125  const Gfx::RectF& rect,
1126  const Gfx::Font& font) const = 0;
1127 
1128  virtual void onPrepareTabs(const TabBar& tabs,
1129  const StyleOptions& options,
1130  const Gfx::Brush& background,
1131  const Gfx::Brush& foreground,
1132  const Gfx::Pen& contour,
1133  const Gfx::Font& font,
1134  const Gfx::Pen& textPen) const = 0;
1135 
1136  virtual void onRenderTabs(const std::vector<TabItem>& tabs,
1137  const StyleOptions& options,
1138  Gfx::Painter& painter,
1139  const Gfx::RectF& rect,
1140  const Gfx::Brush& background,
1141  const Gfx::Brush& foreground,
1142  const Gfx::Pen& contour,
1143  const Gfx::Font& font,
1144  const Gfx::Pen& textPen) const = 0;
1145 };
1146 
1147 } // namespace
1148 
1149 } // namespace
1150 
1151 #endif