]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/tbargtk.cpp
wxDocManager gets the only view if none other specified as the current view;
[wxWidgets.git] / src / gtk1 / 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
18 //-----------------------------------------------------------------------------
19 // wxToolBarTool
20 //-----------------------------------------------------------------------------
21
22 IMPLEMENT_DYNAMIC_CLASS(wxToolBarTool,wxObject)
23
24 wxToolBarTool::wxToolBarTool( wxToolBarGTK *owner, int theIndex,
25 const wxBitmap& bitmap1, const wxBitmap& bitmap2,
26 bool toggle, wxObject *clientData,
27 const wxString& shortHelpString, const wxString& longHelpString )
28 {
29 m_owner = owner;
30 m_index = theIndex;
31 m_bitmap1 = bitmap1;
32 m_bitmap2 = bitmap2;
33 m_isToggle = toggle;
34 m_enabled = TRUE;
35 m_toggleState = FALSE;
36 m_shortHelpString = shortHelpString;
37 m_longHelpString = longHelpString;
38 m_isMenuCommand = TRUE;
39 m_clientData = clientData;
40 m_deleteSecondBitmap = FALSE;
41 };
42
43 wxToolBarTool::~wxToolBarTool(void)
44 {
45 };
46
47 //-----------------------------------------------------------------------------
48 // wxToolBarGTK
49 //-----------------------------------------------------------------------------
50
51 static void gtk_toolbar_callback( GtkWidget *WXUNUSED(widget), wxToolBarTool *tool )
52 {
53 if (!tool->m_enabled) return;
54
55 if (tool->m_isToggle) tool->m_toggleState = !tool->m_toggleState;
56
57 tool->m_owner->OnLeftClick( tool->m_index, tool->m_toggleState );
58 };
59
60 //-----------------------------------------------------------------------------
61
62 IMPLEMENT_DYNAMIC_CLASS(wxToolBarGTK,wxControl)
63
64 BEGIN_EVENT_TABLE(wxToolBarGTK, wxControl)
65 END_EVENT_TABLE()
66
67 wxToolBarGTK::wxToolBarGTK(void)
68 {
69 };
70
71 wxToolBarGTK::wxToolBarGTK( wxWindow *parent, wxWindowID id,
72 const wxPoint& pos, const wxSize& size,
73 long style, const wxString& name )
74 {
75 Create( parent, id, pos, size, style, name );
76 };
77
78 wxToolBarGTK::~wxToolBarGTK(void)
79 {
80 };
81
82 bool wxToolBarGTK::Create( wxWindow *parent, wxWindowID id,
83 const wxPoint& pos, const wxSize& size,
84 long style, const wxString& name )
85 {
86 m_needParent = TRUE;
87
88 PreCreation( parent, id, pos, size, style, name );
89
90 m_tools.DeleteContents( TRUE );
91
92 m_widget = gtk_handle_box_new();
93
94 m_toolbar = GTK_TOOLBAR( gtk_toolbar_new( GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS ) );
95
96 gtk_container_add( GTK_CONTAINER(m_widget), GTK_WIDGET(m_toolbar) );
97
98 gtk_widget_show( GTK_WIDGET(m_toolbar) );
99
100 PostCreation();
101
102 Show( TRUE );
103
104 return TRUE;
105 };
106
107 bool wxToolBarGTK::OnLeftClick( int toolIndex, bool toggleDown )
108 {
109 wxCommandEvent event(wxEVT_COMMAND_TOOL_CLICKED, toolIndex);
110 event.SetEventObject(this);
111 event.SetExtraLong((long) toggleDown);
112
113 GetEventHandler()->ProcessEvent(event);
114
115 return TRUE;
116 };
117
118 void wxToolBarGTK::OnRightClick( int toolIndex, float WXUNUSED(x), float WXUNUSED(y) )
119 {
120 wxCommandEvent event(wxEVT_COMMAND_TOOL_RCLICKED, toolIndex);
121 event.SetEventObject(this);
122
123 GetEventHandler()->ProcessEvent(event);
124 };
125
126 void wxToolBarGTK::OnMouseEnter( int toolIndex )
127 {
128 wxCommandEvent event(wxEVT_COMMAND_TOOL_ENTER, toolIndex);
129 event.SetEventObject(this);
130
131 GetEventHandler()->ProcessEvent(event);
132 };
133
134 wxToolBarTool *wxToolBarGTK::AddTool( int toolIndex, const wxBitmap& bitmap,
135 const wxBitmap& pushedBitmap, bool toggle,
136 float WXUNUSED(xPos), float WXUNUSED(yPos), wxObject *clientData,
137 const wxString& helpString1, const wxString& helpString2 )
138 {
139 if (!bitmap.Ok()) return NULL;
140
141 wxToolBarTool *tool = new wxToolBarTool( this, toolIndex, bitmap, pushedBitmap, toggle,
142 clientData, helpString1, helpString2 );
143
144 GdkPixmap *pixmap = bitmap.GetPixmap();
145
146 GdkBitmap *mask = NULL;
147 if (bitmap.GetMask()) mask = bitmap.GetMask()->GetBitmap();
148
149 GtkWidget *tool_pixmap = gtk_pixmap_new( pixmap, mask );
150 gtk_misc_set_alignment( GTK_MISC(tool_pixmap), 0.5, 0.5 );
151
152 GtkToolbarChildType ctype = GTK_TOOLBAR_CHILD_BUTTON;
153 if (toggle) ctype = GTK_TOOLBAR_CHILD_TOGGLEBUTTON;
154
155 gtk_toolbar_append_element( m_toolbar,
156 ctype, NULL, NULL, helpString1, "", tool_pixmap, (GtkSignalFunc)gtk_toolbar_callback, (gpointer)tool );
157
158 m_tools.Append( tool );
159
160 return tool;
161 };
162
163 void wxToolBarGTK::AddSeparator(void)
164 {
165 gtk_toolbar_append_space( m_toolbar );
166 };
167
168 void wxToolBarGTK::ClearTools(void)
169 {
170 };
171
172 void wxToolBarGTK::EnableTool(int toolIndex, bool enable)
173 {
174 };
175
176 void wxToolBarGTK::ToggleTool(int toolIndex, bool toggle)
177 {
178 };
179
180 void wxToolBarGTK::SetToggle(int toolIndex, bool toggle)
181 {
182 };
183
184 wxObject *wxToolBarGTK::GetToolClientData(int index) const
185 {
186 };
187
188 bool wxToolBarGTK::GetToolState(int toolIndex) const
189 {
190 };
191
192 bool wxToolBarGTK::GetToolEnabled(int toolIndex) const
193 {
194 };
195
196 void wxToolBarGTK::SetMargins(int x, int y)
197 {
198 };
199
200 void wxToolBarGTK::SetToolPacking(int packing)
201 {
202 };
203
204 void wxToolBarGTK::SetToolSeparation(int separation)
205 {
206 };
207