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( wxToolBarGTK
*owner
, const int theIndex
,
25 const wxBitmap
& bitmap1
, const wxBitmap
& bitmap2
,
26 const 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(void)
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(wxToolBarGTK
,wxControl
)
64 BEGIN_EVENT_TABLE(wxToolBarGTK
, wxControl
)
67 wxToolBarGTK::wxToolBarGTK(void)
71 wxToolBarGTK::wxToolBarGTK( wxWindow
*parent
, const wxWindowID id
,
72 const wxPoint
& pos
, const wxSize
& size
,
73 const long style
, const wxString
& name
)
75 Create( parent
, id
, pos
, size
, style
, name
);
78 wxToolBarGTK::~wxToolBarGTK(void)
82 bool wxToolBarGTK::Create( wxWindow
*parent
, const wxWindowID id
,
83 const wxPoint
& pos
, const wxSize
& size
,
84 const 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 wxToolBarGTK::OnLeftClick( int toolIndex
, bool toggleDown
)
109 wxCommandEvent
event(wxEVT_COMMAND_TOOL_CLICKED
, toolIndex
);
110 event
.SetEventObject(this);
111 event
.SetExtraLong((long) toggleDown
);
113 GetEventHandler()->ProcessEvent(event
);
118 void wxToolBarGTK::OnRightClick( int toolIndex
, float WXUNUSED(x
), float WXUNUSED(y
) )
120 wxCommandEvent
event(wxEVT_COMMAND_TOOL_RCLICKED
, toolIndex
);
121 event
.SetEventObject(this);
123 GetEventHandler()->ProcessEvent(event
);
126 void wxToolBarGTK::OnMouseEnter( int toolIndex
)
128 wxCommandEvent
event(wxEVT_COMMAND_TOOL_ENTER
, toolIndex
);
129 event
.SetEventObject(this);
131 GetEventHandler()->ProcessEvent(event
);
134 wxToolBarTool
*wxToolBarGTK::AddTool( const int toolIndex
, const wxBitmap
& bitmap
,
135 const wxBitmap
& pushedBitmap
, const bool toggle
,
136 const float WXUNUSED(xPos
), const float WXUNUSED(yPos
), wxObject
*clientData
,
137 const wxString
& helpString1
, const wxString
& helpString2
)
139 if (!bitmap
.Ok()) return NULL
;
141 wxToolBarTool
*tool
= new wxToolBarTool( this, toolIndex
, bitmap
, pushedBitmap
, toggle
,
142 clientData
, helpString1
, helpString2
);
144 GdkPixmap
*pixmap
= bitmap
.GetPixmap();
146 GdkBitmap
*mask
= NULL
;
147 if (bitmap
.GetMask()) mask
= bitmap
.GetMask()->GetBitmap();
149 GtkWidget
*tool_pixmap
= gtk_pixmap_new( pixmap
, mask
);
150 gtk_misc_set_alignment( GTK_MISC(tool_pixmap
), 0.5, 0.5 );
152 GtkToolbarChildType ctype
= GTK_TOOLBAR_CHILD_BUTTON
;
153 if (toggle
) ctype
= GTK_TOOLBAR_CHILD_TOGGLEBUTTON
;
155 gtk_toolbar_append_element( m_toolbar
,
156 ctype
, NULL
, NULL
, helpString1
, "", tool_pixmap
, (GtkSignalFunc
)gtk_toolbar_callback
, (gpointer
)tool
);
158 m_tools
.Append( tool
);
163 void wxToolBarGTK::AddSeparator(void)
165 gtk_toolbar_append_space( m_toolbar
);
168 void wxToolBarGTK::ClearTools(void)
172 void wxToolBarGTK::EnableTool(const int toolIndex
, const bool enable
)
176 void wxToolBarGTK::ToggleTool(const int toolIndex
, const bool toggle
)
180 void wxToolBarGTK::SetToggle(const int toolIndex
, const bool toggle
)
184 wxObject
*wxToolBarGTK::GetToolClientData(const int index
) const
188 bool wxToolBarGTK::GetToolState(const int toolIndex
) const
192 bool wxToolBarGTK::GetToolEnabled(const int toolIndex
) const
196 void wxToolBarGTK::SetMargins(const int x
, const int y
)
200 void wxToolBarGTK::SetToolPacking(const int packing
)
204 void wxToolBarGTK::SetToolSeparation(const int separation
)