1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: GTK toolbar
4 // Author: Robert Roebling
6 // Copyright: (c) Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "tbargtk.h"
14 #include "wx/toolbar.h"
16 //-----------------------------------------------------------------------------
18 //-----------------------------------------------------------------------------
20 extern bool g_blockEventsOnDrag
;
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
26 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool
,wxObject
)
28 wxToolBarTool::wxToolBarTool( wxToolBar
*owner
, int theIndex
,
29 const wxBitmap
& bitmap1
, const wxBitmap
& bitmap2
,
32 const wxString
& shortHelpString
,
33 const wxString
& longHelpString
,
42 m_toggleState
= FALSE
;
43 m_shortHelpString
= shortHelpString
;
44 m_longHelpString
= longHelpString
;
45 m_isMenuCommand
= TRUE
;
46 m_clientData
= clientData
;
47 m_deleteSecondBitmap
= FALSE
;
51 wxToolBarTool::~wxToolBarTool()
55 //-----------------------------------------------------------------------------
56 // "clicked" (internal from gtk_toolbar)
57 //-----------------------------------------------------------------------------
59 static void gtk_toolbar_callback( GtkWidget
*WXUNUSED(widget
), wxToolBarTool
*tool
)
61 if (g_blockEventsOnDrag
) return;
62 if (!tool
->m_enabled
) return;
64 if (tool
->m_isToggle
) tool
->m_toggleState
= !tool
->m_toggleState
;
66 tool
->m_owner
->OnLeftClick( tool
->m_index
, tool
->m_toggleState
);
69 //-----------------------------------------------------------------------------
70 // "enter_notify_event"
71 //-----------------------------------------------------------------------------
73 static gint
gtk_toolbar_enter_callback( GtkWidget
*WXUNUSED(widget
),
74 GdkEventCrossing
*WXUNUSED(gdk_event
), wxToolBarTool
*tool
)
76 if (g_blockEventsOnDrag
) return TRUE
;
78 tool
->m_owner
->OnMouseEnter( tool
->m_index
);
83 //-----------------------------------------------------------------------------
85 //-----------------------------------------------------------------------------
87 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
,wxControl
)
89 wxToolBar::wxToolBar()
93 wxToolBar::wxToolBar( wxWindow
*parent
, wxWindowID id
,
94 const wxPoint
& pos
, const wxSize
& size
,
95 long style
, const wxString
& name
)
97 Create( parent
, id
, pos
, size
, style
, name
);
100 wxToolBar::~wxToolBar()
104 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
105 const wxPoint
& pos
, const wxSize
& size
,
106 long style
, const wxString
& name
)
110 PreCreation( parent
, id
, pos
, size
, style
, name
);
112 m_tools
.DeleteContents( TRUE
);
114 m_toolbar
= GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL
,
115 GTK_TOOLBAR_ICONS
) );
117 m_widget
= GTK_WIDGET(m_toolbar
);
119 gtk_toolbar_set_tooltips( GTK_TOOLBAR(m_toolbar
), TRUE
);
128 bool wxToolBar::OnLeftClick( int toolIndex
, bool toggleDown
)
130 wxCommandEvent
event( wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
131 event
.SetEventObject(this);
132 event
.SetInt( toolIndex
);
133 event
.SetExtraLong((long) toggleDown
);
135 GetEventHandler()->ProcessEvent(event
);
140 void wxToolBar::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
142 wxCommandEvent
event( wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
143 event
.SetEventObject( this );
144 event
.SetInt( toolIndex
);
146 GetEventHandler()->ProcessEvent(event
);
149 void wxToolBar::OnMouseEnter( int toolIndex
)
151 wxCommandEvent
event( wxEVT_COMMAND_TOOL_ENTER
, GetId() );
152 event
.SetEventObject(this);
153 event
.SetInt( toolIndex
);
155 GetEventHandler()->ProcessEvent(event
);
158 wxToolBarTool
*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
)
163 wxCHECK_MSG( bitmap
.Ok(), (wxToolBarTool
*)NULL
,
164 "invalid bitmap for wxToolBar icon" );
166 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
,
168 helpString1
, helpString2
);
170 wxCHECK_MSG( bitmap
.GetBitmap() == NULL
, (wxToolBarTool
*)NULL
,
171 "wxToolBar doesn't support GdkBitmap" );
173 wxCHECK_MSG( bitmap
.GetPixmap() != NULL
, (wxToolBarTool
*)NULL
,
174 "wxToolBar::Add needs a wxBitmap" );
176 GtkWidget
*tool_pixmap
= (GtkWidget
*)NULL
;
178 if (TRUE
) // FIXME huh?
180 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
182 GdkBitmap
*mask
= (GdkBitmap
*)NULL
;
183 if ( bitmap
.GetMask() )
184 mask
= bitmap
.GetMask()->GetBitmap();
186 tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
189 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
191 GtkToolbarChildType ctype
= toggle
? GTK_TOOLBAR_CHILD_TOGGLEBUTTON
192 : GTK_TOOLBAR_CHILD_BUTTON
;
194 GtkWidget
*item
= gtk_toolbar_append_element
196 GTK_TOOLBAR(m_toolbar
),
203 (GtkSignalFunc
)gtk_toolbar_callback
,
209 gtk_signal_connect( GTK_OBJECT(tool
->m_item
),
210 "enter_notify_event",
211 GTK_SIGNAL_FUNC(gtk_toolbar_enter_callback
),
214 m_tools
.Append( tool
);
219 void wxToolBar::AddSeparator()
221 gtk_toolbar_append_space( m_toolbar
);
224 void wxToolBar::ClearTools()
226 wxFAIL_MSG( "wxToolBar::ClearTools not implemented" );
229 void wxToolBar::Realize()
236 wxNode
*node
= m_tools
.First();
239 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
240 if (tool
->m_bitmap1
.Ok())
242 int tool_height
= tool
->m_bitmap1
.GetHeight();
243 if (tool_height
> m_height
) m_height
= tool_height
;
252 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
254 wxNode
*node
= m_tools
.First();
257 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
258 if (tool
->m_index
== toolIndex
)
260 tool
->m_enabled
= enable
;
266 wxFAIL_MSG( "wrong toolbar index" );
269 void wxToolBar::ToggleTool( int toolIndex
, bool toggle
)
271 wxNode
*node
= m_tools
.First();
274 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
275 if (tool
->m_index
== toolIndex
)
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
);
285 wxFAIL_MSG( "wrong toolbar index" );
288 wxObject
*wxToolBar::GetToolClientData( int index
) const
290 wxNode
*node
= m_tools
.First();
293 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
294 if (tool
->m_index
== index
) return tool
->m_clientData
;;
298 wxFAIL_MSG( "wrong toolbar index" );
300 return (wxObject
*)NULL
;
303 bool wxToolBar::GetToolState(int toolIndex
) const
305 wxNode
*node
= m_tools
.First();
308 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
309 if (tool
->m_index
== toolIndex
) return tool
->m_toggleState
;
313 wxFAIL_MSG( "wrong toolbar index" );
318 bool wxToolBar::GetToolEnabled(int toolIndex
) const
320 wxNode
*node
= m_tools
.First();
323 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
324 if (tool
->m_index
== toolIndex
) return tool
->m_enabled
;
328 wxFAIL_MSG( "wrong toolbar index" );
333 void wxToolBar::SetMargins( int WXUNUSED(x
), int WXUNUSED(y
) )
335 wxFAIL_MSG( "wxToolBar::SetMargins not implemented" );
338 void wxToolBar::SetToolPacking( int WXUNUSED(packing
) )
340 wxFAIL_MSG( "wxToolBar::SetToolPacking not implemented" );
343 void wxToolBar::SetToolSeparation( int separation
)
345 gtk_toolbar_set_space_size( m_toolbar
, separation
);