X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=radiant%2Fplugintoolbar.cpp;h=4312252719f35e2216669ae56c40e89fe4db6ded;hb=ab35d2859c400749e32f801ad8cc5284ac0a0078;hp=4612fbd465bcc3b0b5834024227274617b079f79;hpb=107765f0e4b543dfc346851ee5b4605cc17eb1c6;p=xonotic%2Fnetradiant.git diff --git a/radiant/plugintoolbar.cpp b/radiant/plugintoolbar.cpp index 4612fbd4..43122527 100644 --- a/radiant/plugintoolbar.cpp +++ b/radiant/plugintoolbar.cpp @@ -1,32 +1,31 @@ /* -Copyright (C) 2001-2006, William Joseph. -All Rights Reserved. + Copyright (C) 2001-2006, William Joseph. + All Rights Reserved. -This file is part of GtkRadiant. + This file is part of GtkRadiant. -GtkRadiant is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. + GtkRadiant is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. -GtkRadiant is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. + GtkRadiant is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. -You should have received a copy of the GNU General Public License -along with GtkRadiant; if not, write to the Free Software -Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ + You should have received a copy of the GNU General Public License + along with GtkRadiant; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "plugintoolbar.h" +#include #include "itoolbar.h" #include "modulesystem.h" -#include - #include "stream/stringstream.h" #include "gtkutil/image.h" #include "gtkutil/container.h" @@ -34,118 +33,113 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "mainframe.h" #include "plugin.h" -GtkImage* new_plugin_image(const char* filename) +ui::Image new_plugin_image(const char *filename) { - { - StringOutputStream fullpath(256); - fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask(fullpath.c_str()); - if(image != 0) { - return image; + StringOutputStream fullpath(256); + fullpath << GameToolsPath_get() << g_pluginsDir << "bitmaps/" << filename; + if (auto image = image_new_from_file_with_mask(fullpath.c_str())) { return image; } } - } - { - StringOutputStream fullpath(256); - fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask(fullpath.c_str()); - if(image != 0) { - return image; + StringOutputStream fullpath(256); + fullpath << AppPath_get() << g_pluginsDir << "bitmaps/" << filename; + if (auto image = image_new_from_file_with_mask(fullpath.c_str())) { return image; } } - } - { - StringOutputStream fullpath(256); - fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename; - GtkImage* image = image_new_from_file_with_mask(fullpath.c_str()); - if(image != 0) { - return image; + StringOutputStream fullpath(256); + fullpath << AppPath_get() << g_modulesDir << "bitmaps/" << filename; + if (auto image = image_new_from_file_with_mask(fullpath.c_str())) { return image; } } - } - - return image_new_missing(); -} -inline GtkToolbarChildType gtktoolbarchildtype_for_toolbarbuttontype(IToolbarButton::EType type) -{ - switch(type) - { - case IToolbarButton::eSpace: - return GTK_TOOLBAR_CHILD_SPACE; - case IToolbarButton::eButton: - return GTK_TOOLBAR_CHILD_BUTTON; - case IToolbarButton::eToggleButton: - return GTK_TOOLBAR_CHILD_TOGGLEBUTTON; - case IToolbarButton::eRadioButton: - return GTK_TOOLBAR_CHILD_RADIOBUTTON; - } - ERROR_MESSAGE("invalid toolbar button type"); - return (GtkToolbarChildType)0; + return image_new_missing(); } -void toolbar_insert(GtkToolbar *toolbar, const char* icon, const char* text, const char* tooltip, IToolbarButton::EType type, GtkSignalFunc handler, gpointer data) +void +toolbar_insert(ui::Toolbar toolbar, const char *icon, const char *text, const char *tooltip, IToolbarButton::EType type, + GCallback handler, gpointer data) { - gtk_toolbar_append_element(toolbar, gtktoolbarchildtype_for_toolbarbuttontype(type), 0, text, tooltip, "", GTK_WIDGET(new_plugin_image(icon)), handler, data); + if (type == IToolbarButton::eSpace) { + auto it = ui::ToolItem::from(gtk_separator_tool_item_new()); + it.show(); + toolbar.add(it); + return; + } + if (type == IToolbarButton::eButton) { + auto button = ui::ToolButton::from(gtk_tool_button_new(new_plugin_image(icon), text)); + gtk_widget_set_tooltip_text(button, tooltip); + gtk_widget_show_all(button); + button.connect("clicked", G_CALLBACK(handler), data); + toolbar.add(button); + return; + } + if (type == IToolbarButton::eToggleButton) { + auto button = ui::ToolButton::from(gtk_toggle_tool_button_new()); + gtk_tool_button_set_icon_widget(button, new_plugin_image(icon)); + gtk_tool_button_set_label(button, text); + gtk_widget_set_tooltip_text(button, tooltip); + gtk_widget_show_all(button); + button.connect("toggled", G_CALLBACK(handler), data); + toolbar.add(button); + return; + } + ERROR_MESSAGE("invalid toolbar button type"); } -void ActivateToolbarButton(GtkWidget *widget, gpointer data) +void ActivateToolbarButton(ui::ToolButton widget, gpointer data) { - const_cast(reinterpret_cast(data))->activate(); + (const_cast( reinterpret_cast( data )))->activate(); } -void PlugInToolbar_AddButton(GtkToolbar* toolbar, const IToolbarButton* button) +void PlugInToolbar_AddButton(ui::Toolbar toolbar, const IToolbarButton *button) { - toolbar_insert(toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), GTK_SIGNAL_FUNC(ActivateToolbarButton), reinterpret_cast(const_cast(button))); + toolbar_insert(toolbar, button->getImage(), button->getText(), button->getTooltip(), button->getType(), + G_CALLBACK(ActivateToolbarButton), + reinterpret_cast( const_cast( button ))); } -GtkToolbar* g_plugin_toolbar = 0; +ui::Toolbar g_plugin_toolbar{ui::null}; void PluginToolbar_populate() { - class AddToolbarItemVisitor : public ToolbarModules::Visitor - { - GtkToolbar* m_toolbar; - public: - AddToolbarItemVisitor(GtkToolbar* toolbar) - : m_toolbar(toolbar) - { - } - void visit(const char* name, const _QERPlugToolbarTable& table) const - { - const std::size_t count = table.m_pfnToolbarButtonCount(); - for(std::size_t i=0;i