2 /* $Id: optioncontext.ccg,v 1.4 2004/10/30 14:25:45 murrayc Exp $ */
4 /* Copyright (C) 2002 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <glibmm/utility.h>
22 #include <glibmm/exceptionhandler.h>
30 static const gchar* SignalProxy_translate_gtk_callback (const gchar* str, gpointer data)
32 Glib::ustring translated_str;
33 Glib::OptionContext::SlotTranslate* the_slot =
34 static_cast<Glib::OptionContext::SlotTranslate*>(data);
36 #ifdef GLIBMM_EXCEPTIONS_ENABLED
39 #endif //GLIBMM_EXCEPTIONS_ENABLED
40 translated_str = (*the_slot)(str);
41 #ifdef GLIBMM_EXCEPTIONS_ENABLED
45 Glib::exception_handlers_invoke();
47 #endif //GLIBMM_EXCEPTIONS_ENABLED
48 return translated_str.c_str ();
51 static void SignalProxy_translate_gtk_callback_destroy (gpointer data)
53 delete static_cast<Glib::OptionContext::SlotTranslate*>(data);
58 OptionContext::OptionContext(const Glib::ustring& parameter_string)
59 : gobject_( g_option_context_new(parameter_string.c_str()) ),
64 OptionContext::OptionContext(GOptionContext* castitem, bool take_ownership)
66 has_ownership_(take_ownership)
70 OptionContext::~OptionContext()
73 g_option_context_free(gobj());
78 void OptionContext::add_group(OptionGroup& group)
80 //Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
81 g_option_context_add_group(gobj(), (group).gobj_give_ownership());
84 void OptionContext::set_main_group(OptionGroup& group)
86 //Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
87 g_option_context_set_main_group(gobj(), (group).gobj_give_ownership());
92 OptionGroup OptionContext::get_main_group() const
94 const GOptionGroup* cobj = g_option_context_get_main_group(const_cast<GOptionContext*>( gobj()) );
95 OptionGroup cppObj(const_cast<GOptionGroup*>(cobj), true); // take_copy
101 void OptionContext::set_translate_func (const SlotTranslate& slot)
103 //Create a copy of the slot. A pointer to this will be passed through the callback's data parameter.
104 //It will be deleted when SignalProxy_translate_gtk_callback_destroy() is called.
105 SlotTranslate* slot_copy = new SlotTranslate(slot);
107 g_option_context_set_translate_func(
108 gobj(), &Private::SignalProxy_translate_gtk_callback, slot_copy,
109 &Private::SignalProxy_translate_gtk_callback_destroy);
112 Glib::ustring OptionContext::get_help(bool main_help) const
114 return Glib::convert_return_gchar_ptr_to_ustring(g_option_context_get_help(const_cast<GOptionContext*>(gobj()), static_cast<int>(main_help), NULL));