00001 #ifndef FRAMEDWIDGET_H_ 00002 #define FRAMEDWIDGET_H_ 00003 00004 #include <gtk/gtkframe.h> 00005 #include <gtk/gtkwidget.h> 00006 #include <string> 00007 00008 #include "LeftAlignedLabel.h" 00009 00010 namespace gtkutil 00011 { 00017 class FramedWidget 00018 { 00019 protected: 00020 // The contained widget 00021 GtkWidget* _containedWidget; 00022 00023 std::string _title; 00024 00025 public: 00026 00027 // Constructor 00028 FramedWidget (GtkWidget* containedWidget) : 00029 _containedWidget(containedWidget), _title("") 00030 { 00031 } 00032 00033 // Constructor with frame label 00034 FramedWidget (GtkWidget* containedWidget, std::string& title) : 00035 _containedWidget(containedWidget), _title(title) 00036 { 00037 } 00038 00039 // Constructor with frame label 00040 FramedWidget (GtkWidget* containedWidget, const char* title) : 00041 _containedWidget(containedWidget), _title(title) 00042 { 00043 } 00044 00045 virtual ~FramedWidget () 00046 { 00047 } 00048 00049 // Operator cast to GtkWindow* (use this to create and retrieve the GtkWidget* pointer) 00050 virtual operator GtkWidget* () 00051 { 00052 // Create a new frame and set its properties 00053 GtkFrame* frame; 00054 00055 if (!_title.empty()) 00056 frame = GTK_FRAME(gtk_frame_new(_title.c_str())); 00057 else 00058 frame = GTK_FRAME(gtk_frame_new(0)); 00059 gtk_widget_show(GTK_WIDGET(frame)); 00060 gtk_frame_set_shadow_type(frame, GTK_SHADOW_IN); 00061 00062 // Add the contained widget as children to the frame 00063 gtk_container_add(GTK_CONTAINER(frame), _containedWidget); 00064 gtk_widget_show(_containedWidget); 00065 00066 // Now show the whole widget tree 00067 gtk_widget_show_all(GTK_WIDGET(frame)); 00068 00069 // Return the readily fabricated widget 00070 return GTK_WIDGET(frame); 00071 } 00072 }; 00073 00074 } // namespace gtkutil 00075 00076 #endif /*FRAMEDWIDGET_H_*/