]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: toolbar.cpp | |
3 | // Purpose: wxToolBar | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "toolbar.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/wx.h" | |
17 | ||
18 | #if wxUSE_TOOLBAR | |
19 | ||
20 | #include "wx/toolbar.h" | |
21 | ||
22 | #if !USE_SHARED_LIBRARY | |
23 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarBase) | |
24 | ||
25 | BEGIN_EVENT_TABLE(wxToolBar, wxToolBarBase) | |
26 | END_EVENT_TABLE() | |
27 | #endif | |
28 | ||
29 | #include <wx/mac/uma.h> | |
30 | ||
31 | wxToolBar::wxToolBar() | |
32 | { | |
33 | m_maxWidth = -1; | |
34 | m_maxHeight = -1; | |
35 | m_defaultWidth = 24; | |
36 | m_defaultHeight = 22; | |
37 | // TODO | |
38 | } | |
39 | ||
40 | bool wxToolBar::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, | |
41 | long style, const wxString& name) | |
42 | { | |
43 | m_maxWidth = -1; | |
44 | m_maxHeight = -1; | |
45 | ||
46 | m_defaultWidth = 24; | |
47 | m_defaultHeight = 22; | |
48 | ||
49 | int x = pos.x; | |
50 | int y = pos.y; | |
51 | int width = size.x; | |
52 | int height = size.y; | |
53 | ||
54 | if (width <= 0) | |
55 | width = 100; | |
56 | if (height <= 0) | |
57 | height = 30; | |
58 | if (x < 0) | |
59 | x = 0; | |
60 | if (y < 0) | |
61 | y = 0; | |
62 | ||
63 | Rect bounds ; | |
64 | Str255 title ; | |
65 | ||
66 | MacPreControlCreate( parent , id , "" , wxPoint( x , y ) , wxSize( width , height ) ,style, *((wxValidator*)NULL) , name , &bounds , title ) ; | |
67 | ||
68 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , "\p" , true , 0 , 0 , 1, | |
69 | kControlPlacardProc , (long) this ) ; | |
70 | MacPostControlCreate() ; | |
71 | ||
72 | return TRUE; | |
73 | } | |
74 | ||
75 | wxToolBar::~wxToolBar() | |
76 | { | |
77 | // TODO | |
78 | } | |
79 | ||
80 | PicHandle MakePict(GWorldPtr wp) | |
81 | { | |
82 | CGrafPtr origPort ; | |
83 | GDHandle origDev ; | |
84 | ||
85 | PicHandle pict; // this is the Picture we give back | |
86 | ||
87 | RGBColor gray = { 0xCCCC ,0xCCCC , 0xCCCC } ; | |
88 | ||
89 | GetGWorld( &origPort , &origDev ) ; | |
90 | SetGWorld( wp , NULL ) ; | |
91 | ||
92 | pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing | |
93 | if(!pict) | |
94 | return NULL; | |
95 | ||
96 | RGBBackColor( &gray ) ; | |
97 | EraseRect(&wp->portRect) ; | |
98 | CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - | |
99 | (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - | |
100 | &wp->portRect, // srcRect - it will be recorded and compressed - | |
101 | &wp->portRect, // dstRect - into the picture that is open - | |
102 | srcCopy,NULL); // copyMode and no clip region | |
103 | ||
104 | ClosePicture(); // We are done recording the picture | |
105 | SetGWorld( origPort , origDev ) ; | |
106 | return pict; // return our groovy pict handle | |
107 | } | |
108 | ||
109 | PicHandle MakePictWhite(GWorldPtr wp) | |
110 | { | |
111 | CGrafPtr origPort ; | |
112 | GDHandle origDev ; | |
113 | ||
114 | PicHandle pict; // this is the Picture we give back | |
115 | ||
116 | RGBColor white = { 0xFFFF ,0xFFFF , 0xFFFF } ; | |
117 | ||
118 | GetGWorld( &origPort , &origDev ) ; | |
119 | SetGWorld( wp , NULL ) ; | |
120 | ||
121 | pict = OpenPicture(&wp->portRect); // open a picture, this disables drawing | |
122 | if(!pict) | |
123 | return NULL; | |
124 | ||
125 | RGBBackColor( &white ) ; | |
126 | EraseRect(&wp->portRect) ; | |
127 | CopyBits((BitMap*)*wp->portPixMap, // src PixMap - we copy image over itself - | |
128 | (BitMap*)*wp->portPixMap, // dst PixMap - no drawing occurs - | |
129 | &wp->portRect, // srcRect - it will be recorded and compressed - | |
130 | &wp->portRect, // dstRect - into the picture that is open - | |
131 | srcCopy,NULL); // copyMode and no clip region | |
132 | ||
133 | ClosePicture(); // We are done recording the picture | |
134 | SetGWorld( origPort , origDev ) ; | |
135 | return pict; // return our groovy pict handle | |
136 | } | |
137 | ||
138 | const short kwxMacToolBarTopMargin = 2 ; | |
139 | const short kwxMacToolBarLeftMargin = 2 ; | |
140 | ||
141 | bool wxToolBar::CreateTools() | |
142 | { | |
143 | if (m_tools.Number() == 0) | |
144 | return FALSE; | |
145 | ||
146 | Rect toolbarrect = { m_y , m_x , m_y + m_height , m_x + m_width } ; | |
147 | ControlFontStyleRec controlstyle ; | |
148 | WindowPtr window = GetMacRootWindow() ; | |
149 | controlstyle.flags = kControlUseFontMask ; | |
150 | controlstyle.font = kControlFontSmallSystemFont ; | |
151 | ||
152 | wxNode *node = m_tools.First(); | |
153 | int noButtons = 0; | |
154 | int x = 0 ; | |
155 | ||
156 | while (node) | |
157 | { | |
158 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
159 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( tool->m_bitmap1.GetRefData()) ; | |
160 | ||
161 | if( tool->m_toolStyle != wxTOOL_STYLE_SEPARATOR ) | |
162 | { | |
163 | Rect toolrect = { toolbarrect.top + kwxMacToolBarTopMargin , toolbarrect.left + x + kwxMacToolBarLeftMargin , 0 , 0 } ; | |
164 | toolrect.right = toolrect.left + m_defaultWidth ; | |
165 | toolrect.bottom = toolrect.top + m_defaultHeight ; | |
166 | ||
167 | PicHandle icon = NULL ; | |
168 | if ( bmap ) | |
169 | { | |
170 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) | |
171 | icon = bmap->m_hPict ; | |
172 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) | |
173 | { | |
174 | icon = MakePict( bmap->m_hBitmap ) ; | |
175 | } | |
176 | } | |
177 | ||
178 | ControlHandle m_macToolHandle ; | |
179 | ||
180 | if ( icon ) | |
181 | { | |
182 | m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 , | |
183 | kControlBehaviorOffsetContents + kControlContentPictHandle , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
184 | ControlButtonContentInfo info ; | |
185 | ||
186 | info.contentType = kControlContentPictHandle ; | |
187 | info.u.picture = icon ; | |
188 | ||
189 | UMASetControlData( m_macToolHandle , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
190 | } | |
191 | else | |
192 | { | |
193 | m_macToolHandle = UMANewControl( window , &toolrect , "\p" , true , 0 , | |
194 | kControlBehaviorOffsetContents , 0 , kControlBevelButtonNormalBevelProc , (long) this ) ; | |
195 | } | |
196 | m_macToolHandles.Add( m_macToolHandle ) ; | |
197 | UMASetControlFontStyle( m_macToolHandle , &controlstyle ) ; | |
198 | UMAEmbedControl( m_macToolHandle , m_macControl ) ; | |
199 | ||
200 | x += (int)m_defaultWidth; | |
201 | noButtons ++; | |
202 | } | |
203 | else | |
204 | { | |
205 | m_macToolHandles.Add( NULL ) ; | |
206 | x += (int)m_defaultWidth / 4; | |
207 | } | |
208 | node = node->Next(); | |
209 | } | |
210 | ||
211 | return TRUE; | |
212 | } | |
213 | ||
214 | void wxToolBar::SetToolBitmapSize(const wxSize& size) | |
215 | { | |
216 | m_defaultWidth = size.x; m_defaultHeight = size.y; | |
217 | } | |
218 | ||
219 | wxSize wxToolBar::GetMaxSize() const | |
220 | { | |
221 | // TODO | |
222 | return wxSize(0, 0); | |
223 | } | |
224 | ||
225 | // The button size is bigger than the bitmap size | |
226 | wxSize wxToolBar::GetToolSize() const | |
227 | { | |
228 | return wxSize(m_defaultWidth + 8, m_defaultHeight + 7); | |
229 | } | |
230 | ||
231 | void wxToolBar::MacHandleControlClick( ControlHandle control , SInt16 controlpart ) | |
232 | { | |
233 | int index = 0 ; | |
234 | for ( index = 0 ; index < m_macToolHandles.Count() ; ++index ) | |
235 | { | |
236 | if ( m_macToolHandles[index] == (void*) control ) | |
237 | { | |
238 | OnLeftClick( ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_index , ( (wxToolBarTool*) (m_tools.Nth( index )->Data() ) ) ->m_toggleState ) ; | |
239 | } | |
240 | } | |
241 | } | |
242 | ||
243 | void wxToolBar::EnableTool(int toolIndex, bool enable) | |
244 | { | |
245 | wxNode *node = m_tools.Find((long)toolIndex); | |
246 | if (node) | |
247 | { | |
248 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
249 | tool->m_enabled = enable; | |
250 | // TODO enable button | |
251 | } | |
252 | } | |
253 | ||
254 | void wxToolBar::ToggleTool(int toolIndex, bool toggle) | |
255 | { | |
256 | wxNode *node = m_tools.Find((long)toolIndex); | |
257 | if (node) | |
258 | { | |
259 | wxToolBarTool *tool = (wxToolBarTool *)node->Data(); | |
260 | if (tool->m_isToggle) | |
261 | { | |
262 | tool->m_toggleState = toggle; | |
263 | // TODO: set toggle state | |
264 | } | |
265 | } | |
266 | } | |
267 | ||
268 | void wxToolBar::ClearTools() | |
269 | { | |
270 | // TODO | |
271 | wxToolBarBase::ClearTools(); | |
272 | } | |
273 | ||
274 | // If pushedBitmap is NULL, a reversed version of bitmap is | |
275 | // created and used as the pushed/toggled image. | |
276 | // If toggle is TRUE, the button toggles between the two states. | |
277 | ||
278 | wxToolBarTool *wxToolBar::AddTool(int index, const wxBitmap& bitmap, const wxBitmap& pushedBitmap, | |
279 | bool toggle, long xPos, long yPos, wxObject *clientData, const wxString& helpString1, const wxString& helpString2) | |
280 | { | |
281 | wxToolBarTool *tool = new wxToolBarTool(index, bitmap, wxNullBitmap, toggle, xPos, yPos, helpString1, helpString2); | |
282 | tool->m_clientData = clientData; | |
283 | ||
284 | if (xPos > -1) | |
285 | tool->m_x = xPos; | |
286 | else | |
287 | tool->m_x = m_xMargin; | |
288 | ||
289 | if (yPos > -1) | |
290 | tool->m_y = yPos; | |
291 | else | |
292 | tool->m_y = m_yMargin; | |
293 | ||
294 | tool->SetSize(m_defaultWidth, m_defaultHeight); | |
295 | ||
296 | m_tools.Append((long)index, tool); | |
297 | return tool; | |
298 | } | |
299 | ||
300 | #endif // wxUSE_TOOLBAR | |
301 |