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