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