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