]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/tbargtk.cpp
00a20b423654c4b2aa20995857ac299f022b2d35
[wxWidgets.git] / src / gtk / tbargtk.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: tbargtk.cpp
3 // Purpose: GTK toolbar
4 // Author: Robert Roebling
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID:
8 // Copyright: (c) Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "tbargtk.h"
14 #endif
15
16 #include "wx/toolbar.h"
17 #include <wx/intl.h>
18
19 //-----------------------------------------------------------------------------
20 // wxToolBarTool
21 //-----------------------------------------------------------------------------
22
23 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject)
24
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 )
29 {
30 m_owner = owner;
31 m_index = theIndex;
32 m_bitmap1 = bitmap1;
33 m_bitmap2 = bitmap2;
34 m_isToggle = toggle;
35 m_enabled = TRUE;
36 m_toggleState = FALSE;
37 m_shortHelpString = shortHelpString;
38 m_longHelpString = longHelpString;
39 m_isMenuCommand = TRUE;
40 m_clientData = clientData;
41 m_deleteSecondBitmap = FALSE;
42 };
43
44 wxToolBarTool::~wxToolBarTool()
45 {
46 };
47
48 //-----------------------------------------------------------------------------
49 // wxToolBar
50 //-----------------------------------------------------------------------------
51
52 static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
53 {
54 if (!tool->m_enabled) return;
55
56 if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState;
57
58 tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
59 };
60
61 //-----------------------------------------------------------------------------
62
63 IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl)
64
65 BEGIN_EVENT_TABLE(wxToolBar, wxControl)
66 END_EVENT_TABLE()
67
68 wxToolBar::wxToolBar()
69 {
70 };
71
72 wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id,
73 const wxPoint& pos, const wxSize& size,
74 long style, const wxString& name )
75 {
76 Create( parent, id, pos, size, style, name );
77 };
78
79 wxToolBar::~wxToolBar()
80 {
81 };
82
83 bool wxToolBar::Create( wxWindow *parent, wxWindowID id,
84 const wxPoint& pos, const wxSize& size,
85 long style, const wxString& name )
86 {
87 m_needParent = TRUE;
88
89 PreCreation( parent, id, pos, size, style, name );
90
91 m_tools.DeleteContents( TRUE );
92
93 m_widget = gtk_handle_box_new();
94
95 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) );
96
97 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
98
99 gtk_widget_show( GTK_WIDGET(m_toolbar) );
100
101 PostCreation();
102
103 Show( TRUE );
104
105 return TRUE;
106 };
107
108 bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown )
109 {
110 wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex );
111 event.SetEventObject(this);
112 event.SetInt( toolIndex );
113 event.SetExtraLong((long) toggleDown);
114
115 GetEventHandler()->ProcessEvent(event);
116
117 return TRUE;
118 };
119
120 void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
121 {
122 wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex );
123 event.SetEventObject( this );
124 event.SetInt( toolIndex );
125
126 GetEventHandler()->ProcessEvent(event);
127 };
128
129 void wxToolBar::OnMouseEnter( int toolIndex )
130 {
131 wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, toolIndex );
132 event.SetEventObject(this);
133 event.SetInt( toolIndex );
134
135 GetEventHandler()->ProcessEvent(event);
136 };
137
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 )
142 {
143 if (!bitmap.Ok()) return NULL;
144
145 wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, toggle,
146 clientData, helpString1, helpString2 );
147
148 GdkPixmap *pixmap = bitmap.GetPixmap();
149
150 GdkBitmap *mask = NULL;
151 if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
152
153 GtkWidget *tool_pixmap = gtk_pixmap_new( pixmap, mask );
154 gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
155
156 GtkToolbarChildType ctype = GTK_TOOLBAR_CHILD_BUTTON;
157 if (toggle) ctype = GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
158
159 gtk_toolbar_append_element( m_toolbar,
160 ctype, NULL, NULL, helpString1, "", tool_pixmap, (GtkSignalFunc)gtk_toolbar_callback, (gpointer)tool );
161
162 m_tools.Append( tool );
163
164 return tool;
165 };
166
167 void wxToolBar::AddSeparator(void)
168 {
169 gtk_toolbar_append_space( m_toolbar );
170 };
171
172 void wxToolBar::ClearTools(void)
173 {
174 wxFAIL_MSG(_("wxToolBar::ClearTools not implemented"));
175 };
176
177 void wxToolBar::Realize(void)
178 {
179 m_x = 0;
180 m_y = 0;
181 m_width = 100;
182 m_height = 0;
183
184 wxNode *node = m_tools.First();
185 while (node)
186 {
187 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
188 if (tool->m_bitmap1.Ok())
189 {
190 int tool_height = tool->m_bitmap1.GetHeight();
191 if (tool_height > m_height) m_height = tool_height;
192 };
193
194 node = node->Next();
195 };
196
197 m_height += 10;
198 };
199
200 void wxToolBar::EnableTool(int toolIndex, bool enable)
201 {
202 wxNode *node = m_tools.First();
203 while (node)
204 {
205 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
206 if (tool->m_index == toolIndex)
207 {
208 tool->m_enabled = enable;
209 return;
210 }
211 node = node->Next();
212 };
213 };
214
215 void wxToolBar::ToggleTool(int WXUNUSED(toolIndex), bool WXUNUSED(toggle) )
216 {
217 wxFAIL_MSG(_("wxToolBar::ToggleTool not implemented"));
218 };
219
220 wxObject *wxToolBar::GetToolClientData(int index) const
221 {
222 wxNode *node = m_tools.First();
223 while (node)
224 {
225 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
226 if (tool->m_index == index) return tool->m_clientData;;
227 node = node->Next();
228 };
229 return (wxObject*)NULL;
230 };
231
232 bool wxToolBar::GetToolState(int toolIndex) const
233 {
234 wxNode *node = m_tools.First();
235 while (node)
236 {
237 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
238 if (tool->m_index == toolIndex) return tool->m_toggleState;
239 node = node->Next();
240 };
241 return FALSE;
242 };
243
244 bool wxToolBar::GetToolEnabled(int toolIndex) const
245 {
246 wxNode *node = m_tools.First();
247 while (node)
248 {
249 wxToolBarTool *tool = (wxToolBarTool*)node->Data();
250 if (tool->m_index == toolIndex) return tool->m_enabled;
251 node = node->Next();
252 };
253 return FALSE;
254 };
255
256 void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) )
257 {
258 };
259
260 void wxToolBar::SetToolPacking( int WXUNUSED(packing) )
261 {
262 };
263
264 void wxToolBar::SetToolSeparation( int separation )
265 {
266 gtk_toolbar_set_space_size( m_toolbar, separation );
267 };
268