utils.cpp
00001 00002 /*************************************************************************** 00003 * utils.cpp - General purpose GUI utility functions 00004 * 00005 * Created: Tue Sep 23 13:41:30 2008 00006 * Copyright 2008 Daniel Beck 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <gui_utils/utils.h> 00025 00026 /** Obtain a widget from a Glade XML file by its name. 00027 * Use a dynamic cast to cast it to the expected widget-type. 00028 * @param ref_xml Glade XML file 00029 * @param widget_name name of the widget 00030 */ 00031 Gtk::Widget* 00032 fawkes::get_widget( Glib::RefPtr<Gnome::Glade::Xml> ref_xml, 00033 const char* widget_name ) 00034 { 00035 Gtk::Widget* widget; 00036 ref_xml->get_widget(widget_name, widget); 00037 if ( !widget ) 00038 { 00039 std::string err_str = "Couldn't find widget "; 00040 err_str += std::string(widget_name); 00041 err_str += "."; 00042 throw std::runtime_error(err_str); 00043 } 00044 00045 return widget; 00046 }

