1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: GTK toolbar
4 // Author: Robert Roebling
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "tbargtk.h"
16 #include "wx/toolbar.h"
18 //-----------------------------------------------------------------------------
20 //-----------------------------------------------------------------------------
22 extern bool g_blockEventsOnDrag
;
24 //-----------------------------------------------------------------------------
26 //-----------------------------------------------------------------------------
28 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool
,wxObject
)
30 wxToolBarTool::wxToolBarTool( wxToolBar
*owner
, int theIndex
,
31 const wxBitmap
& bitmap1
, const wxBitmap
& bitmap2
,
34 const wxString
& shortHelpString
,
35 const wxString
& longHelpString
,
44 m_toggleState
= FALSE
;
45 m_shortHelpString
= shortHelpString
;
46 m_longHelpString
= longHelpString
;
47 m_isMenuCommand
= TRUE
;
48 m_clientData
= clientData
;
49 m_deleteSecondBitmap
= FALSE
;
53 wxToolBarTool::~wxToolBarTool()
57 //-----------------------------------------------------------------------------
58 // "clicked" (internal from gtk_toolbar)
59 //-----------------------------------------------------------------------------
61 static void gtk_toolbar_callback( GtkWidget
*WXUNUSED(widget
), wxToolBarTool
*tool
)
63 if (g_blockEventsOnDrag
) return;
64 if (!tool
->m_enabled
) return;
66 if (tool
->m_isToggle
) tool
->m_toggleState
= !tool
->m_toggleState
;
68 tool
->m_owner
->OnLeftClick( tool
->m_index
, tool
->m_toggleState
);
71 //-----------------------------------------------------------------------------
72 // "enter_notify_event"
73 //-----------------------------------------------------------------------------
75 static gint
gtk_toolbar_enter_callback( GtkWidget
*WXUNUSED(widget
),
76 GdkEventCrossing
*WXUNUSED(gdk_event
), wxToolBarTool
*tool
)
78 if (g_blockEventsOnDrag
) return TRUE
;
80 tool
->m_owner
->OnMouseEnter( tool
->m_index
);
85 //-----------------------------------------------------------------------------
87 //-----------------------------------------------------------------------------
89 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
,wxControl
)
91 wxToolBar::wxToolBar()
95 wxToolBar::wxToolBar( wxWindow
*parent
, wxWindowID id
,
96 const wxPoint
& pos
, const wxSize
& size
,
97 long style
, const wxString
& name
)
99 Create( parent
, id
, pos
, size
, style
, name
);
102 wxToolBar::~wxToolBar()
106 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
107 const wxPoint
& pos
, const wxSize
& size
,
108 long style
, const wxString
& name
)
112 PreCreation( parent
, id
, pos
, size
, style
, name
);
114 m_tools
.DeleteContents( TRUE
);
116 m_widget
= gtk_handle_box_new();
118 m_toolbar
= GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL
, GTK_TOOLBAR_ICONS
) );
119 gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar
), TRUE
);
121 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_toolbar
) );
123 gtk_widget_show( GTK_WIDGET(m_toolbar
) );
132 bool wxToolBar::OnLeftClick( int toolIndex
, bool toggleDown
)
134 wxCommandEvent
event( wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
135 event
.SetEventObject(this);
136 event
.SetInt( toolIndex
);
137 event
.SetExtraLong((long) toggleDown
);
139 GetEventHandler()->ProcessEvent(event
);
144 void wxToolBar::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
146 wxCommandEvent
event( wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
147 event
.SetEventObject( this );
148 event
.SetInt( toolIndex
);
150 GetEventHandler()->ProcessEvent(event
);
153 void wxToolBar::OnMouseEnter( int toolIndex
)
155 wxCommandEvent
event( wxEVT_COMMAND_TOOL_ENTER
, GetId() );
156 event
.SetEventObject(this);
157 event
.SetInt( toolIndex
);
159 GetEventHandler()->ProcessEvent(event
);
162 wxToolBarTool
*wxToolBar::AddTool( int toolIndex
, const wxBitmap
& bitmap
,
163 const wxBitmap
& pushedBitmap
, bool toggle
,
164 float WXUNUSED(xPos
), float WXUNUSED(yPos
), wxObject
*clientData
,
165 const wxString
& helpString1
, const wxString
& helpString2
)
167 wxCHECK_MSG( bitmap
.Ok(), (wxToolBarTool
*)NULL
,
168 "invalid bitmap for wxToolBar icon" );
170 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
,
172 helpString1
, helpString2
);
174 wxCHECK_MSG( bitmap
.GetBitmap() == NULL
, (wxToolBarTool
*)NULL
,
175 "wxToolBar doesn't support GdkBitmap" );
177 wxCHECK_MSG( bitmap
.GetPixmap() != NULL
, (wxToolBarTool
*)NULL
,
178 "wxToolBar::Add needs a wxBitmap" );
180 GtkWidget
*tool_pixmap
= (GtkWidget
*) NULL
;
182 if (TRUE
) // FIXME huh?
184 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
186 GdkBitmap
*mask
= (GdkBitmap
*) NULL
;
187 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
189 tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
192 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
195 GtkToolbarChildType ctype
= toggle
? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
196 : GTK_TOOLBAR_CHILD_BUTTON
;
198 tool
->m_item
= gtk_toolbar_append_element
200 GTK_TOOLBAR(m_toolbar
),
207 (GtkSignalFunc
)gtk_toolbar_callback
,
211 gtk_signal_connect( GTK_OBJECT(tool
->m_item
),
212 "enter_notify_event",
213 GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback
),
216 tool
->m_item
= gtk_toolbar_append_item
218 GTK_TOOLBAR(m_toolbar
),
223 (GtkSignalFunc
)gtk_toolbar_callback
,
228 m_tools
.Append( tool
);
233 void wxToolBar::AddSeparator()
235 gtk_toolbar_append_space( m_toolbar
);
238 void wxToolBar::ClearTools()
240 wxFAIL_MSG( "wxToolBar::ClearTools not implemented" );
243 void wxToolBar::Realize()
250 wxNode
*node
= m_tools
.First();
253 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
254 if (tool
->m_bitmap1
.Ok())
256 int tool_height
= tool
->m_bitmap1
.GetHeight();
257 if (tool_height
> m_height
) m_height
= tool_height
;
266 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
268 wxNode
*node
= m_tools
.First();
271 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
272 if (tool
->m_index
== toolIndex
)
274 tool
->m_enabled
= enable
;
280 wxFAIL_MSG( "wrong toolbar index" );
283 void wxToolBar::ToggleTool( int toolIndex
, bool toggle
)
285 wxNode
*node
= m_tools
.First();
288 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
289 if (tool
->m_index
== toolIndex
)
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
);
299 wxFAIL_MSG( "wrong toolbar index" );
302 wxObject
*wxToolBar::GetToolClientData( int index
) const
304 wxNode
*node
= m_tools
.First();
307 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
308 if (tool
->m_index
== index
) return tool
->m_clientData
;;
312 wxFAIL_MSG( "wrong toolbar index" );
314 return (wxObject
*)NULL
;
317 bool wxToolBar::GetToolState(int toolIndex
) const
319 wxNode
*node
= m_tools
.First();
322 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
323 if (tool
->m_index
== toolIndex
) return tool
->m_toggleState
;
327 wxFAIL_MSG( "wrong toolbar index" );
332 bool wxToolBar::GetToolEnabled(int toolIndex
) const
334 wxNode
*node
= m_tools
.First();
337 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
338 if (tool
->m_index
== toolIndex
) return tool
->m_enabled
;
342 wxFAIL_MSG( "wrong toolbar index" );
347 void wxToolBar::SetMargins( int WXUNUSED(x
), int WXUNUSED(y
) )
349 wxFAIL_MSG( "wxToolBar::SetMargins not implemented" );
352 void wxToolBar::SetToolPacking( int WXUNUSED(packing
) )
354 wxFAIL_MSG( "wxToolBar::SetToolPacking not implemented" );
357 void wxToolBar::SetToolSeparation( int separation
)
359 gtk_toolbar_set_space_size( m_toolbar
, separation
);