| 1 | /* |
| 2 | Copyright (C) 2001-2006, William Joseph. |
| 3 | All Rights Reserved. |
| 4 | |
| 5 | This file is part of GtkRadiant. |
| 6 | |
| 7 | GtkRadiant is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | GtkRadiant is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with GtkRadiant; if not, write to the Free Software |
| 19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include "toolbar.h" |
| 23 | |
| 24 | #include <uilib/uilib.h> |
| 25 | #include <gtk/gtk.h> |
| 26 | |
| 27 | #include "generic/callback.h" |
| 28 | |
| 29 | #include "accelerator.h" |
| 30 | #include "button.h" |
| 31 | #include "image.h" |
| 32 | |
| 33 | |
| 34 | void toolbar_append( ui::Toolbar toolbar, ui::ToolItem button, const char* description ){ |
| 35 | gtk_widget_show_all(button); |
| 36 | gtk_widget_set_tooltip_text(button, description); |
| 37 | toolbar.add(button); |
| 38 | } |
| 39 | |
| 40 | ui::ToolButton toolbar_append_button( ui::Toolbar toolbar, const char* description, const char* icon ){ |
| 41 | auto button = ui::ToolButton::from(gtk_tool_button_new(new_local_image(icon), nullptr)); |
| 42 | toolbar_append(toolbar, button, description); |
| 43 | return button; |
| 44 | } |
| 45 | |
| 46 | ui::ToolButton toolbar_append_button( ui::Toolbar toolbar, const char* description, const char* icon, const Callback<void()>& callback ){ |
| 47 | auto button = ui::ToolButton::from(gtk_tool_button_new(new_local_image(icon), nullptr)); |
| 48 | button_connect_callback(button, callback); |
| 49 | toolbar_append(toolbar, button, description); |
| 50 | return button; |
| 51 | } |
| 52 | |
| 53 | ui::ToggleToolButton toolbar_append_toggle_button( ui::Toolbar toolbar, const char* description, const char* icon, const Callback<void()>& callback ){ |
| 54 | auto button = ui::ToggleToolButton::from(gtk_toggle_tool_button_new()); |
| 55 | toggle_button_connect_callback(button, callback); |
| 56 | gtk_tool_button_set_icon_widget(GTK_TOOL_BUTTON(button), new_local_image(icon)); |
| 57 | gtk_tool_button_set_label(GTK_TOOL_BUTTON(button), description); |
| 58 | toolbar_append(toolbar, button, description); |
| 59 | return button; |
| 60 | } |
| 61 | |
| 62 | ui::ToolButton toolbar_append_button( ui::Toolbar toolbar, const char* description, const char* icon, const Command& command ){ |
| 63 | return toolbar_append_button( toolbar, description, icon, command.m_callback ); |
| 64 | } |
| 65 | |
| 66 | void toggle_button_set_active_callback(void *it, bool active ){ |
| 67 | auto button = ui::ToggleToolButton::from(it); |
| 68 | toggle_button_set_active_no_signal( button, active ); |
| 69 | } |
| 70 | |
| 71 | ui::ToggleToolButton toolbar_append_toggle_button( ui::Toolbar toolbar, const char* description, const char* icon, const Toggle& toggle ){ |
| 72 | auto button = toolbar_append_toggle_button( toolbar, description, icon, toggle.m_command.m_callback ); |
| 73 | toggle.m_exportCallback( PointerCaller<void, void(bool), toggle_button_set_active_callback>( button._handle ) ); |
| 74 | return button; |
| 75 | } |