]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: tbargtk.cpp | |
3 | // Purpose: GTK toolbar | |
4 | // Author: Robert Roebling | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
a3622daa | 7 | // RCS-ID: |
c801d85f | 8 | // Copyright: (c) Robert Roebling |
a3622daa | 9 | // Licence: wxWindows licence |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "tbargtk.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/toolbar.h" | |
1a5a8367 | 17 | #include <wx/intl.h> |
c801d85f KB |
18 | |
19 | //----------------------------------------------------------------------------- | |
20 | // wxToolBarTool | |
21 | //----------------------------------------------------------------------------- | |
22 | ||
23 | IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject) | |
a3622daa VZ |
24 | |
25 | wxToolBarTool::wxToolBarTool( wxToolBar *owner, int theIndex, | |
debe6624 JS |
26 | const wxBitmap& bitmap1, const wxBitmap& bitmap2, |
27 | bool toggle, wxObject *clientData, | |
c801d85f KB |
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 | ||
a3622daa | 44 | wxToolBarTool::~wxToolBarTool() |
c801d85f KB |
45 | { |
46 | }; | |
47 | ||
48 | //----------------------------------------------------------------------------- | |
716b7364 | 49 | // wxToolBar |
c801d85f KB |
50 | //----------------------------------------------------------------------------- |
51 | ||
52 | static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool ) | |
53 | { | |
54 | if (!tool->m_enabled) return; | |
a3622daa | 55 | |
c801d85f | 56 | if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState; |
a3622daa | 57 | |
c801d85f KB |
58 | tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState ); |
59 | }; | |
60 | ||
61 | //----------------------------------------------------------------------------- | |
62 | ||
716b7364 | 63 | IMPLEMENT_DYNAMIC_CLASS(wxToolBar,wxControl) |
c801d85f | 64 | |
716b7364 | 65 | BEGIN_EVENT_TABLE(wxToolBar, wxControl) |
c801d85f KB |
66 | END_EVENT_TABLE() |
67 | ||
a3622daa | 68 | wxToolBar::wxToolBar() |
c801d85f KB |
69 | { |
70 | }; | |
71 | ||
a3622daa | 72 | wxToolBar::wxToolBar( wxWindow *parent, wxWindowID id, |
c801d85f | 73 | const wxPoint& pos, const wxSize& size, |
debe6624 | 74 | long style, const wxString& name ) |
c801d85f KB |
75 | { |
76 | Create( parent, id, pos, size, style, name ); | |
77 | }; | |
78 | ||
a3622daa | 79 | wxToolBar::~wxToolBar() |
c801d85f KB |
80 | { |
81 | }; | |
82 | ||
a3622daa | 83 | bool wxToolBar::Create( wxWindow *parent, wxWindowID id, |
c801d85f | 84 | const wxPoint& pos, const wxSize& size, |
debe6624 | 85 | long style, const wxString& name ) |
c801d85f KB |
86 | { |
87 | m_needParent = TRUE; | |
a3622daa | 88 | |
c801d85f KB |
89 | PreCreation( parent, id, pos, size, style, name ); |
90 | ||
91 | m_tools.DeleteContents( TRUE ); | |
a3622daa | 92 | |
c801d85f | 93 | m_widget = gtk_handle_box_new(); |
a3622daa | 94 | |
c801d85f | 95 | m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) ); |
a3622daa | 96 | |
c801d85f | 97 | gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) ); |
a3622daa | 98 | |
c801d85f | 99 | gtk_widget_show( GTK_WIDGET(m_toolbar) ); |
a3622daa | 100 | |
c801d85f | 101 | PostCreation(); |
a3622daa | 102 | |
c801d85f | 103 | Show( TRUE ); |
a3622daa | 104 | |
c801d85f KB |
105 | return TRUE; |
106 | }; | |
107 | ||
716b7364 | 108 | bool wxToolBar::OnLeftClick( int toolIndex, bool toggleDown ) |
c801d85f | 109 | { |
cf4219e7 | 110 | wxCommandEvent event( wxEVT_COMMAND_TOOL_CLICKED, toolIndex ); |
c801d85f | 111 | event.SetEventObject(this); |
46dc76ba | 112 | event.SetInt( toolIndex ); |
c801d85f KB |
113 | event.SetExtraLong((long) toggleDown); |
114 | ||
115 | GetEventHandler()->ProcessEvent(event); | |
116 | ||
117 | return TRUE; | |
118 | }; | |
119 | ||
716b7364 | 120 | void wxToolBar::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) ) |
c801d85f | 121 | { |
cf4219e7 | 122 | wxCommandEvent event( wxEVT_COMMAND_TOOL_RCLICKED, toolIndex ); |
46dc76ba RR |
123 | event.SetEventObject( this ); |
124 | event.SetInt( toolIndex ); | |
c801d85f KB |
125 | |
126 | GetEventHandler()->ProcessEvent(event); | |
127 | }; | |
128 | ||
716b7364 | 129 | void wxToolBar::OnMouseEnter( int toolIndex ) |
c801d85f | 130 | { |
cf4219e7 | 131 | wxCommandEvent event( wxEVT_COMMAND_TOOL_ENTER, toolIndex ); |
c801d85f | 132 | event.SetEventObject(this); |
46dc76ba | 133 | event.SetInt( toolIndex ); |
c801d85f KB |
134 | |
135 | GetEventHandler()->ProcessEvent(event); | |
136 | }; | |
137 | ||
a3622daa | 138 | wxToolBarTool *wxToolBar::AddTool( int toolIndex, const wxBitmap& bitmap, |
debe6624 JS |
139 | const wxBitmap& pushedBitmap, bool toggle, |
140 | float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData, | |
c801d85f KB |
141 | const wxString& helpString1, const wxString& helpString2 ) |
142 | { | |
143 | if (!bitmap.Ok()) return NULL; | |
a3622daa VZ |
144 | |
145 | wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, toggle, | |
c801d85f | 146 | clientData, helpString1, helpString2 ); |
a3622daa | 147 | |
c801d85f | 148 | GdkPixmap *pixmap = bitmap.GetPixmap(); |
a3622daa | 149 | |
c801d85f KB |
150 | GdkBitmap *mask = NULL; |
151 | if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap(); | |
a3622daa | 152 | |
c801d85f KB |
153 | GtkWidget *tool_pixmap = gtk_pixmap_new( pixmap, mask ); |
154 | gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 ); | |
a3622daa | 155 | |
c801d85f KB |
156 | GtkToolbarChildType ctype = GTK_TOOLBAR_CHILD_BUTTON; |
157 | if (toggle) ctype = GTK_TOOLBAR_CHILD_TOGGLEBUTTON; | |
a3622daa VZ |
158 | |
159 | gtk_toolbar_append_element( m_toolbar, | |
c801d85f | 160 | ctype, NULL, NULL, helpString1, "", tool_pixmap, (GtkSignalFunc)gtk_toolbar_callback, (gpointer)tool ); |
a3622daa VZ |
161 | |
162 | m_tools.Append( tool ); | |
163 | ||
c801d85f KB |
164 | return tool; |
165 | }; | |
166 | ||
716b7364 | 167 | void wxToolBar::AddSeparator(void) |
c801d85f KB |
168 | { |
169 | gtk_toolbar_append_space( m_toolbar ); | |
170 | }; | |
171 | ||
716b7364 | 172 | void wxToolBar::ClearTools(void) |
c801d85f | 173 | { |
1a5a8367 | 174 | wxFAIL_MSG(_("wxToolBar::ClearTools not implemented")); |
c801d85f KB |
175 | }; |
176 | ||
e3e65dac | 177 | void wxToolBar::Realize(void) |
46dc76ba RR |
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 | ||
716b7364 | 200 | void wxToolBar::EnableTool(int toolIndex, bool enable) |
c801d85f | 201 | { |
cf4219e7 RR |
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 | }; | |
c801d85f KB |
213 | }; |
214 | ||
cf4219e7 | 215 | void wxToolBar::ToggleTool(int WXUNUSED(toolIndex), bool WXUNUSED(toggle) ) |
c801d85f | 216 | { |
1a5a8367 | 217 | wxFAIL_MSG(_("wxToolBar::ToggleTool not implemented")); |
c801d85f KB |
218 | }; |
219 | ||
716b7364 | 220 | wxObject *wxToolBar::GetToolClientData(int index) const |
c801d85f | 221 | { |
cf4219e7 RR |
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; | |
c801d85f KB |
230 | }; |
231 | ||
716b7364 | 232 | bool wxToolBar::GetToolState(int toolIndex) const |
c801d85f | 233 | { |
cf4219e7 RR |
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; | |
c801d85f KB |
242 | }; |
243 | ||
716b7364 | 244 | bool wxToolBar::GetToolEnabled(int toolIndex) const |
c801d85f | 245 | { |
cf4219e7 RR |
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; | |
c801d85f KB |
254 | }; |
255 | ||
cf4219e7 | 256 | void wxToolBar::SetMargins( int WXUNUSED(x), int WXUNUSED(y) ) |
c801d85f KB |
257 | { |
258 | }; | |
259 | ||
cf4219e7 | 260 | void wxToolBar::SetToolPacking( int WXUNUSED(packing) ) |
c801d85f KB |
261 | { |
262 | }; | |
263 | ||
cf4219e7 | 264 | void wxToolBar::SetToolSeparation( int separation ) |
c801d85f | 265 | { |
cf4219e7 | 266 | gtk_toolbar_set_space_size( m_toolbar, separation ); |
c801d85f KB |
267 | }; |
268 |