]> git.saurik.com Git - wxWidgets.git/blob - utils/framelayout/src/dyntbar.h
Cleaned up paint DC cache in ~wxPaintDC to avoid spurious memory warning
[wxWidgets.git] / utils / framelayout / src / dyntbar.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: No names yet.
3 // Purpose: Contrib. demo
4 // Author: Aleksandras Gluchovas
5 // Modified by:
6 // Created: ??/10/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleksandras Gluchovas
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __DYNTBAR_G__
13 #define __DYNTBAR_G__
14
15 #include "wx/tbarbase.h"
16 #include "wx/dynarray.h"
17
18 // layout item
19
20 class wxToolLayoutItem : public wxObject
21 {
22 public:
23 wxRect mRect;
24 bool mIsSeparator;
25 };
26
27 class wxDynToolInfo;
28
29 typedef wxToolLayoutItem* wxToolLayoutItemPtrT;
30 typedef wxDynToolInfo* wxDynToolInfoPtrT;
31
32
33 WX_DEFINE_ARRAY( wxToolLayoutItemPtrT, wxLayoutItemArrayT );
34 WX_DEFINE_ARRAY( wxDynToolInfoPtrT, wxDynToolInfoArrayT );
35
36 // base class for layouting algorithm implementations
37
38 class LayoutManagerBase
39 {
40 public:
41 virtual void Layout( const wxSize& parentDim,
42 wxSize& resultingDim,
43 wxLayoutItemArrayT& items,
44 int horizGap,
45 int vertGap ) = 0;
46
47 virtual ~LayoutManagerBase() {}
48 };
49
50 // layouts items in left-to-right order from
51 // top towards bottom
52
53 class BagLayout : public LayoutManagerBase
54 {
55 public:
56 virtual void Layout( const wxSize& parentDim,
57 wxSize& resultingDim,
58 wxLayoutItemArrayT& items,
59 int horizGap,
60 int vertGap );
61 };
62
63 class wxDynToolInfo : public wxToolLayoutItem
64 {
65 DECLARE_DYNAMIC_CLASS(wxDynToolInfo)
66
67 public:
68 wxWindow* mpToolWnd;
69 int mIndex;
70 wxSize mRealSize;
71 };
72
73 // layouting orientations for tools
74
75 #define LO_HORIZONTAL 0
76 #define LO_VERTICAL 1
77 #define LO_FIT_TO_WINDOW 2
78
79 // class manages containment and layouting of tool-windows
80
81 class wxDynamicToolBar : public wxToolBarBase
82 {
83 DECLARE_DYNAMIC_CLASS(wxDynamicToolBar)
84 protected:
85
86 friend class wxDynamicToolBarSerializer;
87
88 wxDynToolInfoArrayT mTools;
89 LayoutManagerBase* mpLayoutMan;
90
91 protected:
92 virtual void SizeToolWindows();
93
94 public: /* public properties */
95
96 int mSepartorSize; // default: 8
97 int mVertGap; // default: 0
98 int mHorizGap; // default: 0
99
100 public:
101 wxDynamicToolBar();
102
103 wxDynamicToolBar(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
104 const long style = wxNO_BORDER, const int orientation = wxVERTICAL,
105 const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr);
106
107 ~wxDynamicToolBar(void);
108
109 bool Create(wxWindow *parent, const wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
110 const long style = wxNO_BORDER, const int orientation = wxVERTICAL, const int RowsOrColumns = 1, const wxString& name = wxToolBarNameStr);
111
112 // overridables
113
114 virtual void AddTool( int toolIndex,
115 wxWindow* pToolWindow,
116 const wxSize& size = wxDefaultSize );
117
118 virtual void AddTool( int toolIndex,
119 const wxString& imageFileName,
120 int imageFileType = wxBITMAP_TYPE_BMP,
121 const wxString& labelText = "", bool alignTextRight = FALSE,
122 bool isFlat = TRUE );
123 virtual void AddTool( int toolIndex, wxBitmap labelBmp,
124 const wxString& labelText = "", bool alignTextRight = FALSE,
125 bool isFlat = TRUE );
126
127 // method from wxToolBarBase (for compatibility), only
128 // first two arguments are valid
129
130 virtual wxToolBarTool *AddTool(const int toolIndex, const wxBitmap& bitmap, const wxBitmap& pushedBitmap = wxNullBitmap,
131 const bool toggle = FALSE, const long xPos = -1, const long yPos = -1, wxObject *clientData = NULL,
132 const wxString& helpString1 = "", const wxString& helpString2 = "");
133
134 virtual void AddSeparator( wxWindow* pSepartorWnd = NULL );
135
136 wxDynToolInfo* GetToolInfo( int toolIndex );
137
138 void RemveTool( int toolIndex );
139
140 // the default implementation draws shaded line
141 virtual void DrawSeparator( wxDynToolInfo& info, wxDC& dc );
142
143 // see definitions of orientation types
144 virtual bool Layout();
145
146 virtual void GetPreferredDim( const wxSize& givenDim, wxSize& prefDim );
147
148 virtual LayoutManagerBase* CreateDefaulLayout() { return new BagLayout(); }
149
150 virtual void SetLayout( LayoutManagerBase* pLayout );
151
152 virtual void EnableTool(const int toolIndex, const bool enable = TRUE);
153
154 // event handlers
155
156 void OnSize( wxSizeEvent& event );
157 void OnPaint( wxPaintEvent& event );
158 void OnEraseBackground( wxEraseEvent& event );
159
160 // overriden from wxToolBarBase
161
162 virtual bool Realize(void);
163
164 DECLARE_EVENT_TABLE()
165 };
166
167 #endif