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 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool
,wxObject
)
24 wxToolBarTool::wxToolBarTool( wxToolBar
*owner
, int theIndex
,
25 const wxBitmap
& bitmap1
, const wxBitmap
& bitmap2
,
26 bool toggle
, wxObject
*clientData
,
27 const wxString
& shortHelpString
, const wxString
& longHelpString
)
35 m_toggleState
= FALSE
;
36 m_shortHelpString
= shortHelpString
;
37 m_longHelpString
= longHelpString
;
38 m_isMenuCommand
= TRUE
;
39 m_clientData
= clientData
;
40 m_deleteSecondBitmap
= FALSE
;
43 wxToolBarTool::~wxToolBarTool()
47 //-----------------------------------------------------------------------------
49 //-----------------------------------------------------------------------------
51 static void gtk_toolbar_callback( GtkWidget
*WXUNUSED(widget
), wxToolBarTool
*tool
)
53 if (!tool
->m_enabled
) return;
55 if (tool
->m_isToggle
) tool
->m_toggleState
= !tool
->m_toggleState
;
57 tool
->m_owner
->OnLeftClick( tool
->m_index
, tool
->m_toggleState
);
60 //-----------------------------------------------------------------------------
62 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
,wxControl
)
64 BEGIN_EVENT_TABLE(wxToolBar
, wxControl
)
67 wxToolBar::wxToolBar()
71 wxToolBar::wxToolBar( wxWindow
*parent
, wxWindowID id
,
72 const wxPoint
& pos
, const wxSize
& size
,
73 long style
, const wxString
& name
)
75 Create( parent
, id
, pos
, size
, style
, name
);
78 wxToolBar::~wxToolBar()
82 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
83 const wxPoint
& pos
, const wxSize
& size
,
84 long style
, const wxString
& name
)
88 PreCreation( parent
, id
, pos
, size
, style
, name
);
90 m_tools
.DeleteContents( TRUE
);
92 m_widget
= gtk_handle_box_new();
94 m_toolbar
= GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL
, GTK_TOOLBAR_ICONS
) );
96 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_toolbar
) );
98 gtk_widget_show( GTK_WIDGET(m_toolbar
) );
107 bool wxToolBar::OnLeftClick( int toolIndex
, bool toggleDown
)
109 wxCommandEvent
event( wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
110 event
.SetEventObject(this);
111 event
.SetInt( toolIndex
);
112 event
.SetExtraLong((long) toggleDown
);
114 GetEventHandler()->ProcessEvent(event
);
119 void wxToolBar::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
121 wxCommandEvent
event( wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
122 event
.SetEventObject( this );
123 event
.SetInt( toolIndex
);
125 GetEventHandler()->ProcessEvent(event
);
128 void wxToolBar::OnMouseEnter( int toolIndex
)
130 wxCommandEvent
event( wxEVT_COMMAND_TOOL_ENTER
, toolIndex
);
131 event
.SetEventObject(this);
132 event
.SetInt( toolIndex
);
134 GetEventHandler()->ProcessEvent(event
);
137 wxToolBarTool
*wxToolBar::AddTool( int toolIndex
, const wxBitmap
& bitmap
,
138 const wxBitmap
& pushedBitmap
, bool toggle
,
139 float WXUNUSED(xPos
), float WXUNUSED(yPos
), wxObject
*clientData
,
140 const wxString
& helpString1
, const wxString
& helpString2
)
142 if (!bitmap
.Ok()) return NULL
;
144 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
, toggle
,
145 clientData
, helpString1
, helpString2
);
147 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
149 GdkBitmap
*mask
= NULL
;
150 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
152 GtkWidget
*tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
153 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
155 GtkToolbarChildType ctype
= GTK_TOOLBAR_CHILD_BUTTON
;
156 if (toggle
) ctype
= GTK_TOOLBAR_CHILD_TOGGLEBUTTON
;
158 gtk_toolbar_append_element( m_toolbar
,
159 ctype
, NULL
, NULL
, helpString1
, "", tool_pixmap
, (GtkSignalFunc
)gtk_toolbar_callback
, (gpointer
)tool
);
161 m_tools
.Append( tool
);
166 void wxToolBar::AddSeparator(void)
168 gtk_toolbar_append_space( m_toolbar
);
171 void wxToolBar::ClearTools(void)
173 wxFAIL_MSG("wxToolBar::ClearTools not implemented");
176 void wxToolBar::Realize(void)
183 wxNode
*node
= m_tools
.First();
186 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
187 if (tool
->m_bitmap1
.Ok())
189 int tool_height
= tool
->m_bitmap1
.GetHeight();
190 if (tool_height
> m_height
) m_height
= tool_height
;
199 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
201 wxNode
*node
= m_tools
.First();
204 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
205 if (tool
->m_index
== toolIndex
)
207 tool
->m_enabled
= enable
;
214 void wxToolBar::ToggleTool(int WXUNUSED(toolIndex
), bool WXUNUSED(toggle
) )
216 wxFAIL_MSG("wxToolBar::ToggleTool not implemented");
219 wxObject
*wxToolBar::GetToolClientData(int index
) const
221 wxNode
*node
= m_tools
.First();
224 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
225 if (tool
->m_index
== index
) return tool
->m_clientData
;;
228 return (wxObject
*)NULL
;
231 bool wxToolBar::GetToolState(int toolIndex
) const
233 wxNode
*node
= m_tools
.First();
236 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
237 if (tool
->m_index
== toolIndex
) return tool
->m_toggleState
;
243 bool wxToolBar::GetToolEnabled(int toolIndex
) const
245 wxNode
*node
= m_tools
.First();
248 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
249 if (tool
->m_index
== toolIndex
) return tool
->m_enabled
;
255 void wxToolBar::SetMargins( int WXUNUSED(x
), int WXUNUSED(y
) )
259 void wxToolBar::SetToolPacking( int WXUNUSED(packing
) )
263 void wxToolBar::SetToolSeparation( int separation
)
265 gtk_toolbar_set_space_size( m_toolbar
, separation
);