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