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
)
36 m_toggleState
= FALSE
;
37 m_shortHelpString
= shortHelpString
;
38 m_longHelpString
= longHelpString
;
39 m_isMenuCommand
= TRUE
;
40 m_clientData
= clientData
;
41 m_deleteSecondBitmap
= FALSE
;
44 wxToolBarTool::~wxToolBarTool()
48 //-----------------------------------------------------------------------------
50 //-----------------------------------------------------------------------------
52 static void gtk_toolbar_callback( GtkWidget
*WXUNUSED(widget
), wxToolBarTool
*tool
)
54 if (!tool
->m_enabled
) return;
56 if (tool
->m_isToggle
) tool
->m_toggleState
= !tool
->m_toggleState
;
58 tool
->m_owner
->OnLeftClick( tool
->m_index
, tool
->m_toggleState
);
61 //-----------------------------------------------------------------------------
63 IMPLEMENT_DYNAMIC_CLASS(wxToolBar
,wxControl
)
65 BEGIN_EVENT_TABLE(wxToolBar
, wxControl
)
68 wxToolBar::wxToolBar()
72 wxToolBar::wxToolBar( wxWindow
*parent
, wxWindowID id
,
73 const wxPoint
& pos
, const wxSize
& size
,
74 long style
, const wxString
& name
)
76 Create( parent
, id
, pos
, size
, style
, name
);
79 wxToolBar::~wxToolBar()
83 bool wxToolBar::Create( wxWindow
*parent
, wxWindowID id
,
84 const wxPoint
& pos
, const wxSize
& size
,
85 long style
, const wxString
& name
)
89 PreCreation( parent
, id
, pos
, size
, style
, name
);
91 m_tools
.DeleteContents( TRUE
);
93 m_widget
= gtk_handle_box_new();
95 m_toolbar
= GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL
, GTK_TOOLBAR_ICONS
) );
97 gtk_container_add( GTK_CONTAINER(m_widget
), GTK_WIDGET(m_toolbar
) );
99 gtk_widget_show( GTK_WIDGET(m_toolbar
) );
108 bool wxToolBar::OnLeftClick( int toolIndex
, bool toggleDown
)
110 wxCommandEvent
event( wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
111 event
.SetEventObject(this);
112 event
.SetInt( toolIndex
);
113 event
.SetExtraLong((long) toggleDown
);
115 GetEventHandler()->ProcessEvent(event
);
120 void wxToolBar::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
122 wxCommandEvent
event( wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
123 event
.SetEventObject( this );
124 event
.SetInt( toolIndex
);
126 GetEventHandler()->ProcessEvent(event
);
129 void wxToolBar::OnMouseEnter( int toolIndex
)
131 wxCommandEvent
event( wxEVT_COMMAND_TOOL_ENTER
, toolIndex
);
132 event
.SetEventObject(this);
133 event
.SetInt( toolIndex
);
135 GetEventHandler()->ProcessEvent(event
);
138 wxToolBarTool
*wxToolBar::AddTool( int toolIndex
, const wxBitmap
& bitmap
,
139 const wxBitmap
& pushedBitmap
, bool toggle
,
140 float WXUNUSED(xPos
), float WXUNUSED(yPos
), wxObject
*clientData
,
141 const wxString
& helpString1
, const wxString
& helpString2
)
143 if (!bitmap
.Ok()) return NULL
;
145 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
, toggle
,
146 clientData
, helpString1
, helpString2
);
148 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
150 GdkBitmap
*mask
= NULL
;
151 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
153 GtkWidget
*tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
154 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
156 GtkToolbarChildType ctype
= GTK_TOOLBAR_CHILD_BUTTON
;
157 if (toggle
) ctype
= GTK_TOOLBAR_CHILD_TOGGLEBUTTON
;
159 gtk_toolbar_append_element( m_toolbar
,
160 ctype
, NULL
, NULL
, helpString1
, "", tool_pixmap
, (GtkSignalFunc
)gtk_toolbar_callback
, (gpointer
)tool
);
162 m_tools
.Append( tool
);
167 void wxToolBar::AddSeparator(void)
169 gtk_toolbar_append_space( m_toolbar
);
172 void wxToolBar::ClearTools(void)
174 wxFAIL_MSG(_("wxToolBar::ClearTools not implemented"));
177 void wxToolBar::Realize(void)
184 wxNode
*node
= m_tools
.First();
187 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
188 if (tool
->m_bitmap1
.Ok())
190 int tool_height
= tool
->m_bitmap1
.GetHeight();
191 if (tool_height
> m_height
) m_height
= tool_height
;
200 void wxToolBar::EnableTool(int toolIndex
, bool enable
)
202 wxNode
*node
= m_tools
.First();
205 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
206 if (tool
->m_index
== toolIndex
)
208 tool
->m_enabled
= enable
;
215 void wxToolBar::ToggleTool(int WXUNUSED(toolIndex
), bool WXUNUSED(toggle
) )
217 wxFAIL_MSG(_("wxToolBar::ToggleTool not implemented"));
220 wxObject
*wxToolBar::GetToolClientData(int index
) const
222 wxNode
*node
= m_tools
.First();
225 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
226 if (tool
->m_index
== index
) return tool
->m_clientData
;;
229 return (wxObject
*)NULL
;
232 bool wxToolBar::GetToolState(int toolIndex
) const
234 wxNode
*node
= m_tools
.First();
237 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
238 if (tool
->m_index
== toolIndex
) return tool
->m_toggleState
;
244 bool wxToolBar::GetToolEnabled(int toolIndex
) const
246 wxNode
*node
= m_tools
.First();
249 wxToolBarTool
*tool
= (wxToolBarTool
*)node
->Data();
250 if (tool
->m_index
== toolIndex
) return tool
->m_enabled
;
256 void wxToolBar::SetMargins( int WXUNUSED(x
), int WXUNUSED(y
) )
260 void wxToolBar::SetToolPacking( int WXUNUSED(packing
) )
264 void wxToolBar::SetToolSeparation( int separation
)
266 gtk_toolbar_set_space_size( m_toolbar
, separation
);