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"
19 //-----------------------------------------------------------------------------
21 //-----------------------------------------------------------------------------
23 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool
,wxObject
)
25 wxToolBarTool::wxToolBarTool( wxToolBar
*owner
, int theIndex
,
26 const wxBitmap
& bitmap1
, const wxBitmap
& bitmap2
,
27 bool toggle
, wxObject
*clientData
,
28 const wxString
& shortHelpString
, const wxString
& longHelpString
,
37 m_toggleState
= FALSE
;
38 m_shortHelpString
= shortHelpString
;
39 m_longHelpString
= longHelpString
;
40 m_isMenuCommand
= TRUE
;
41 m_clientData
= clientData
;
42 m_deleteSecondBitmap
= FALSE
;
46 wxToolBarTool::~wxToolBarTool()
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
54 static void gtk_toolbar_callback( GtkWidget
*WXUNUSED(widget
), wxToolBarTool
*tool
)
56 if (!tool
->m_enabled
) return;
58 if (tool
->m_isToggle
) tool
->m_toggleState
= !tool
->m_toggleState
;
60 tool
->m_owner
->OnLeftClick( tool
->m_index
, tool
->m_toggleState
);
63 //-----------------------------------------------------------------------------
65 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
,wxControl
)
67 BEGIN_EVENT_TABLE(wxToolBar
, wxControl
)
70 wxToolBar::wxToolBar()
74 wxToolBar::wxToolBar( wxWindow
*parent
, wxWindowID id
,
75 const wxPoint
& pos
, const wxSize
& size
,
76 long style
, const wxString
& name
)
78 Create( parent
, id
, pos
, size
, style
, name
);
81 wxToolBar::~wxToolBar()
85 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
86 const wxPoint
& pos
, const wxSize
& size
,
87 long style
, const wxString
& name
)
91 PreCreation( parent
, id
, pos
, size
, style
, name
);
93 m_tools
.DeleteContents( TRUE
);
95 m_widget
= gtk_handle_box_new();
97 m_toolbar
= GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL
, GTK_TOOLBAR_ICONS
) );
99 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_toolbar
) );
101 gtk_widget_show( GTK_WIDGET(m_toolbar
) );
110 bool wxToolBar::OnLeftClick( int toolIndex
, bool toggleDown
)
112 wxCommandEvent
event( wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
113 event
.SetEventObject(this);
114 event
.SetInt( toolIndex
);
115 event
.SetExtraLong((long) toggleDown
);
117 GetEventHandler()->ProcessEvent(event
);
122 void wxToolBar::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
124 wxCommandEvent
event( wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
125 event
.SetEventObject( this );
126 event
.SetInt( toolIndex
);
128 GetEventHandler()->ProcessEvent(event
);
131 void wxToolBar::OnMouseEnter( int toolIndex
)
133 wxCommandEvent
event( wxEVT_COMMAND_TOOL_ENTER
, toolIndex
);
134 event
.SetEventObject(this);
135 event
.SetInt( toolIndex
);
137 GetEventHandler()->ProcessEvent(event
);
140 wxToolBarTool
*wxToolBar::AddTool( int toolIndex
, const wxBitmap
& bitmap
,
141 const wxBitmap
& pushedBitmap
, bool toggle
,
142 float WXUNUSED(xPos
), float WXUNUSED(yPos
), wxObject
*clientData
,
143 const wxString
& helpString1
, const wxString
& helpString2
)
145 if (!bitmap
.Ok()) return NULL
;
147 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
, toggle
,
148 clientData
, helpString1
, helpString2
);
150 GtkWidget
*tool_pixmap
= NULL
;
152 wxCHECK_MSG( bitmap
.GetBitmap() == NULL
, (wxToolBarTool
*)NULL
, "wxToolBar doesn't support GdkBitmap" )
154 wxCHECK_MSG( bitmap
.GetPixmap() != NULL
, (wxToolBarTool
*)NULL
, "wxToolBar::Add needs a wxBitmap" )
158 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
160 GdkBitmap
*mask
= NULL
;
161 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
163 tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
166 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
168 GtkToolbarChildType ctype
= GTK_TOOLBAR_CHILD_BUTTON
;
169 if (toggle
) ctype
= GTK_TOOLBAR_CHILD_TOGGLEBUTTON
;
171 tool
->m_item
= gtk_toolbar_append_element( m_toolbar
, ctype
, NULL
, NULL
, helpString1
, "", tool_pixmap
,
172 (GtkSignalFunc
)gtk_toolbar_callback
, (gpointer
)tool
);
174 m_tools
.Append( tool
);
179 void wxToolBar::AddSeparator(void)
181 gtk_toolbar_append_space( m_toolbar
);
184 void wxToolBar::ClearTools(void)
186 wxFAIL_MSG( "wxToolBar::ClearTools not implemented" );
189 void wxToolBar::Realize(void)
196 wxNode
*node
= m_tools
.First();
199 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
200 if (tool
->m_bitmap1
.Ok())
202 int tool_height
= tool
->m_bitmap1
.GetHeight();
203 if (tool_height
> m_height
) m_height
= tool_height
;
212 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
214 wxNode
*node
= m_tools
.First();
217 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
218 if (tool
->m_index
== toolIndex
)
220 tool
->m_enabled
= enable
;
226 wxFAIL_MSG( "wrong toolbar index" );
229 void wxToolBar::ToggleTool( int toolIndex
, bool toggle
)
231 wxNode
*node
= m_tools
.First();
234 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
235 if (tool
->m_index
== toolIndex
)
237 tool
->m_toggleState
= toggle
;
238 if ((tool
->m_item
) && (GTK_IS_TOGGLE_BUTTON(tool
->m_item
)))
239 gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(tool
->m_item
), toggle
);
245 wxFAIL_MSG( "wrong toolbar index" );
248 wxObject
*wxToolBar::GetToolClientData( int index
) const
250 wxNode
*node
= m_tools
.First();
253 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
254 if (tool
->m_index
== index
) return tool
->m_clientData
;;
258 wxFAIL_MSG( "wrong toolbar index" );
260 return (wxObject
*)NULL
;
263 bool wxToolBar::GetToolState(int toolIndex
) const
265 wxNode
*node
= m_tools
.First();
268 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
269 if (tool
->m_index
== toolIndex
) return tool
->m_toggleState
;
273 wxFAIL_MSG( "wrong toolbar index" );
278 bool wxToolBar::GetToolEnabled(int toolIndex
) const
280 wxNode
*node
= m_tools
.First();
283 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
284 if (tool
->m_index
== toolIndex
) return tool
->m_enabled
;
288 wxFAIL_MSG( "wrong toolbar index" );
293 void wxToolBar::SetMargins( int WXUNUSED(x
), int WXUNUSED(y
) )
297 void wxToolBar::SetToolPacking( int WXUNUSED(packing
) )
301 void wxToolBar::SetToolSeparation( int separation
)
303 gtk_toolbar_set_space_size( m_toolbar
, separation
);