]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
3 | // Purpose: GTK toolbar | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
a3622daa | 7 | // RCS-ID: |
c801d85f | 8 | // Copyright: (c) Robert Roebling |
a3622daa | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tbargtk.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/toolbar.h" | |
1a5a8367 | 17 | #include <wx/intl.h> |
c801d85f KB |
18 | |
19 | //----------------------------------------------------------------------------- | |
20 | // wxToolBarTool | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject) | |
a3622daa VZ |
24 | |
25 | wxToolBarTool::wxToolBarTool( wxToolBar *owner, int theIndex, | |
debe6624 JS |
26 | const wxBitmap& bitmap1, const wxBitmap& bitmap2, |
27 | bool toggle, wxObject *clientData, | |
fc008f25 RR |
28 | const wxString& shortHelpString, const wxString& longHelpString, |
29 | GtkWidget *item ) | |
c801d85f KB |
30 | { |
31 | m_owner = owner; | |
32 | m_index = theIndex; | |
33 | m_bitmap1 = bitmap1; | |
34 | m_bitmap2 = bitmap2; | |
35 | m_isToggle = toggle; | |
36 | m_enabled = TRUE; | |
37 | m_toggleState = FALSE; | |
38 | m_shortHelpString = shortHelpString; | |
39 | m_longHelpString = longHelpString; | |
40 | m_isMenuCommand = TRUE; | |
41 | m_clientData = clientData; | |
42 | m_deleteSecondBitmap = FALSE; | |
fc008f25 RR |
43 | m_item = item; |
44 | } | |
c801d85f | 45 | |
a3622daa | 46 | wxToolBarTool::~wxToolBarTool() |
c801d85f | 47 | { |
fc008f25 | 48 | } |
c801d85f KB |
49 | |
50 | //----------------------------------------------------------------------------- | |
716b7364 | 51 | // wxToolBar |
c801d85f KB |
52 | //----------------------------------------------------------------------------- |
53 | ||
54 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) | |
55 | { | |
56 | if (!tool->m_enabled) return; | |
a3622daa | 57 | |
c801d85f | 58 | if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState; |
a3622daa | 59 | |
c801d85f | 60 | tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState ); |
fc008f25 | 61 | } |
c801d85f KB |
62 | |
63 | //----------------------------------------------------------------------------- | |
64 | ||
716b7364 | 65 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl) |
c801d85f | 66 | |
716b7364 | 67 | BEGIN_EVENT_TABLE(wxToolBar, wxControl) |
c801d85f KB |
68 | END_EVENT_TABLE() |
69 | ||
a3622daa | 70 | wxToolBar::wxToolBar() |
c801d85f | 71 | { |
fc008f25 | 72 | } |
c801d85f | 73 | |
a3622daa | 74 | wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id, |
c801d85f | 75 | const wxPoint& pos, const wxSize& size, |
debe6624 | 76 | long style, const wxString& name ) |
c801d85f KB |
77 | { |
78 | Create( parent, id, pos, size, style, name ); | |
fc008f25 | 79 | } |
c801d85f | 80 | |
a3622daa | 81 | wxToolBar::~wxToolBar() |
c801d85f | 82 | { |
fc008f25 | 83 | } |
c801d85f | 84 | |
a3622daa | 85 | bool wxToolBar::Create( wxWindow *parent, wxWindowID id, |
c801d85f | 86 | const wxPoint& pos, const wxSize& size, |
debe6624 | 87 | long style, const wxString& name ) |
c801d85f KB |
88 | { |
89 | m_needParent = TRUE; | |
a3622daa | 90 | |
c801d85f KB |
91 | PreCreation( parent, id, pos, size, style, name ); |
92 | ||
93 | m_tools.DeleteContents( TRUE ); | |
a3622daa | 94 | |
c801d85f | 95 | m_widget = gtk_handle_box_new(); |
a3622daa | 96 | |
c801d85f | 97 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) ); |
a3622daa | 98 | |
c801d85f | 99 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
a3622daa | 100 | |
c801d85f | 101 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); |
a3622daa | 102 | |
c801d85f | 103 | PostCreation(); |
a3622daa | 104 | |
c801d85f | 105 | Show( TRUE ); |
a3622daa | 106 | |
c801d85f | 107 | return TRUE; |
fc008f25 | 108 | } |
c801d85f | 109 | |
716b7364 | 110 | bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown ) |
c801d85f | 111 | { |
cf4219e7 | 112 | wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex ); |
c801d85f | 113 | event.SetEventObject(this); |
46dc76ba | 114 | event.SetInt( toolIndex ); |
c801d85f KB |
115 | event.SetExtraLong((long) toggleDown); |
116 | ||
117 | GetEventHandler()->ProcessEvent(event); | |
118 | ||
119 | return TRUE; | |
fc008f25 | 120 | } |
c801d85f | 121 | |
716b7364 | 122 | void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) ) |
c801d85f | 123 | { |
cf4219e7 | 124 | wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex ); |
46dc76ba RR |
125 | event.SetEventObject( this ); |
126 | event.SetInt( toolIndex ); | |
c801d85f KB |
127 | |
128 | GetEventHandler()->ProcessEvent(event); | |
fc008f25 | 129 | } |
c801d85f | 130 | |
716b7364 | 131 | void wxToolBar::OnMouseEnter( int toolIndex ) |
c801d85f | 132 | { |
cf4219e7 | 133 | wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, toolIndex ); |
c801d85f | 134 | event.SetEventObject(this); |
46dc76ba | 135 | event.SetInt( toolIndex ); |
c801d85f KB |
136 | |
137 | GetEventHandler()->ProcessEvent(event); | |
fc008f25 | 138 | } |
c801d85f | 139 | |
a3622daa | 140 | wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, |
debe6624 JS |
141 | const wxBitmap& pushedBitmap, bool toggle, |
142 | float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData, | |
c801d85f KB |
143 | const wxString& helpString1, const wxString& helpString2 ) |
144 | { | |
145 | if (!bitmap.Ok()) return NULL; | |
a3622daa VZ |
146 | |
147 | wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, toggle, | |
fc008f25 | 148 | clientData, helpString1, helpString2 ); |
a3622daa | 149 | |
903f689b RR |
150 | GtkWidget *tool_pixmap = NULL; |
151 | ||
152 | wxCHECK_MSG( bitmap.GetBitmap() == NULL, (wxToolBarTool *)NULL, "wxToolBar doesn't support GdkBitmap" ) | |
153 | ||
154 | wxCHECK_MSG( bitmap.GetPixmap() != NULL, (wxToolBarTool *)NULL, "wxToolBar::Add needs a wxBitmap" ) | |
155 | ||
156 | if (TRUE) | |
157 | { | |
158 | GdkPixmap *pixmap = bitmap.GetPixmap(); | |
a3622daa | 159 | |
903f689b RR |
160 | GdkBitmap *mask = NULL; |
161 | if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap(); | |
162 | ||
163 | tool_pixmap = gtk_pixmap_new( pixmap, mask ); | |
164 | } | |
165 | ||
c801d85f | 166 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); |
a3622daa | 167 | |
c801d85f KB |
168 | GtkToolbarChildType ctype = GTK_TOOLBAR_CHILD_BUTTON; |
169 | if (toggle) ctype = GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
a3622daa | 170 | |
fc008f25 RR |
171 | tool->m_item = gtk_toolbar_append_element( m_toolbar, ctype, NULL, NULL, helpString1, "", tool_pixmap, |
172 | (GtkSignalFunc)gtk_toolbar_callback, (gpointer)tool ); | |
a3622daa VZ |
173 | |
174 | m_tools.Append( tool ); | |
175 | ||
c801d85f | 176 | return tool; |
fc008f25 | 177 | } |
c801d85f | 178 | |
716b7364 | 179 | void wxToolBar::AddSeparator(void) |
c801d85f KB |
180 | { |
181 | gtk_toolbar_append_space( m_toolbar ); | |
fc008f25 | 182 | } |
c801d85f | 183 | |
716b7364 | 184 | void wxToolBar::ClearTools(void) |
c801d85f | 185 | { |
fc008f25 RR |
186 | wxFAIL_MSG( "wxToolBar::ClearTools not implemented" ); |
187 | } | |
c801d85f | 188 | |
e3e65dac | 189 | void wxToolBar::Realize(void) |
46dc76ba RR |
190 | { |
191 | m_x = 0; | |
192 | m_y = 0; | |
193 | m_width = 100; | |
194 | m_height = 0; | |
195 | ||
196 | wxNode *node = m_tools.First(); | |
197 | while (node) | |
198 | { | |
199 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
200 | if (tool->m_bitmap1.Ok()) | |
201 | { | |
202 | int tool_height = tool->m_bitmap1.GetHeight(); | |
203 | if (tool_height > m_height) m_height = tool_height; | |
fc008f25 | 204 | } |
46dc76ba RR |
205 | |
206 | node = node->Next(); | |
fc008f25 | 207 | } |
46dc76ba RR |
208 | |
209 | m_height += 10; | |
fc008f25 | 210 | } |
46dc76ba | 211 | |
716b7364 | 212 | void wxToolBar::EnableTool(int toolIndex, bool enable) |
c801d85f | 213 | { |
cf4219e7 RR |
214 | wxNode *node = m_tools.First(); |
215 | while (node) | |
216 | { | |
217 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
218 | if (tool->m_index == toolIndex) | |
219 | { | |
220 | tool->m_enabled = enable; | |
221 | return; | |
222 | } | |
223 | node = node->Next(); | |
fc008f25 RR |
224 | } |
225 | ||
226 | wxFAIL_MSG( "wrong toolbar index" ); | |
227 | } | |
c801d85f | 228 | |
fc008f25 | 229 | void wxToolBar::ToggleTool( int toolIndex, bool toggle ) |
c801d85f | 230 | { |
fc008f25 RR |
231 | wxNode *node = m_tools.First(); |
232 | while (node) | |
233 | { | |
234 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
235 | if (tool->m_index == toolIndex) | |
236 | { | |
237 | tool->m_toggleState = toggle; | |
238 | if ((tool->m_item) && (GTK_IS_TOGGLE_BUTTON(tool->m_item))) | |
239 | gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool->m_item), toggle ); | |
240 | return; | |
241 | } | |
242 | node = node->Next(); | |
243 | } | |
244 | ||
245 | wxFAIL_MSG( "wrong toolbar index" ); | |
246 | } | |
c801d85f | 247 | |
fc008f25 | 248 | wxObject *wxToolBar::GetToolClientData( int index ) const |
c801d85f | 249 | { |
cf4219e7 RR |
250 | wxNode *node = m_tools.First(); |
251 | while (node) | |
252 | { | |
253 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
254 | if (tool->m_index == index) return tool->m_clientData;; | |
255 | node = node->Next(); | |
fc008f25 RR |
256 | } |
257 | ||
258 | wxFAIL_MSG( "wrong toolbar index" ); | |
259 | ||
cf4219e7 | 260 | return (wxObject*)NULL; |
fc008f25 | 261 | } |
c801d85f | 262 | |
716b7364 | 263 | bool wxToolBar::GetToolState(int toolIndex) const |
c801d85f | 264 | { |
cf4219e7 RR |
265 | wxNode *node = m_tools.First(); |
266 | while (node) | |
267 | { | |
268 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
269 | if (tool->m_index == toolIndex) return tool->m_toggleState; | |
270 | node = node->Next(); | |
fc008f25 RR |
271 | } |
272 | ||
273 | wxFAIL_MSG( "wrong toolbar index" ); | |
274 | ||
cf4219e7 | 275 | return FALSE; |
fc008f25 | 276 | } |
c801d85f | 277 | |
716b7364 | 278 | bool wxToolBar::GetToolEnabled(int toolIndex) const |
c801d85f | 279 | { |
cf4219e7 RR |
280 | wxNode *node = m_tools.First(); |
281 | while (node) | |
282 | { | |
283 | wxToolBarTool *tool = (wxToolBarTool*)node->Data(); | |
284 | if (tool->m_index == toolIndex) return tool->m_enabled; | |
285 | node = node->Next(); | |
fc008f25 RR |
286 | } |
287 | ||
288 | wxFAIL_MSG( "wrong toolbar index" ); | |
289 | ||
cf4219e7 | 290 | return FALSE; |
fc008f25 | 291 | } |
c801d85f | 292 | |
cf4219e7 | 293 | void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) ) |
c801d85f | 294 | { |
fc008f25 | 295 | } |
c801d85f | 296 | |
cf4219e7 | 297 | void wxToolBar::SetToolPacking( int WXUNUSED(packing) ) |
c801d85f | 298 | { |
fc008f25 | 299 | } |
c801d85f | 300 | |
cf4219e7 | 301 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 302 | { |
cf4219e7 | 303 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
fc008f25 | 304 | } |
c801d85f | 305 |