w_scrollarea.c

Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Sun May 16 2010
00003     copyright   : (C) 2010 by Martin Preuss
00004     email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 
00011 
00012 
00013 
00014 static GWENHYWFAR_CB
00015 int Gtk2Gui_WScrollArea_SetIntProperty(GWEN_WIDGET *w,
00016                                        GWEN_DIALOG_PROPERTY prop,
00017                                        int index,
00018                                        int value,
00019                                        int doSignal) {
00020   GtkWidget *g;  /* text view */
00021   GtkWidget *gs; /* scrollable window */
00022 
00023   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00024   assert(g);
00025   gs=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00026   assert(gs);
00027 
00028   switch(prop) {
00029   case GWEN_DialogProperty_Enabled:
00030     gtk_widget_set_sensitive(GTK_WIDGET(gs), (value==0)?FALSE:TRUE);
00031     return 0;
00032   
00033   case GWEN_DialogProperty_Focus:
00034     gtk_widget_grab_focus(GTK_WIDGET(gs));
00035     return 0;
00036 
00037   case GWEN_DialogProperty_Width:
00038   case GWEN_DialogProperty_Height:
00039     /* just ignore these for now */
00040     return 0;
00041 
00042   default:
00043     break;
00044   }
00045 
00046   DBG_WARN(GWEN_LOGDOMAIN,
00047            "Function is not appropriate for this type of widget (%s)",
00048            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00049   return GWEN_ERROR_INVALID;
00050 }
00051 
00052 
00053 
00054 
00055 static GWENHYWFAR_CB
00056 int Gtk2Gui_WScrollArea_GetIntProperty(GWEN_WIDGET *w,
00057                                        GWEN_DIALOG_PROPERTY prop,
00058                                        int index,
00059                                        int defaultValue) {
00060   GtkWidget *g;  /* text view */
00061   GtkWidget *gs; /* scrollable window */
00062 
00063   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00064   assert(g);
00065   gs=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00066   assert(gs);
00067 
00068   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00069   assert(g);
00070 
00071   switch(prop) {
00072   case GWEN_DialogProperty_Enabled:
00073     return (gtk_widget_get_sensitive(GTK_WIDGET(gs))==TRUE)?1:0;
00074 
00075   case GWEN_DialogProperty_Focus:
00076     return (gtk_widget_has_focus(GTK_WIDGET(gs))==TRUE)?1:0;
00077     return 0;
00078 
00079   case GWEN_DialogProperty_Width:
00080   case GWEN_DialogProperty_Height:
00081     /* just ignore these for now */
00082     return 0;
00083 
00084   default:
00085     break;
00086   }
00087 
00088   DBG_WARN(GWEN_LOGDOMAIN,
00089            "Function is not appropriate for this type of widget (%s)",
00090            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00091   return defaultValue;
00092 }
00093 
00094 
00095 
00096 static GWENHYWFAR_CB
00097 int Gtk2Gui_WScrollArea_SetCharProperty(GWEN_WIDGET *w,
00098                                          GWEN_DIALOG_PROPERTY prop,
00099                                          int index,
00100                                          const char *value,
00101                                          int doSignal) {
00102   GtkWidget *g;         /* scrollable window */
00103   GtkWidget *gContent;  /* vbox */
00104 
00105   gContent=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00106   assert(gContent);
00107   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00108   assert(g);
00109 
00110   DBG_WARN(GWEN_LOGDOMAIN,
00111            "Function is not appropriate for this type of widget (%s)",
00112            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00113   return GWEN_ERROR_INVALID;
00114 }
00115 
00116 
00117 
00118 static GWENHYWFAR_CB
00119 const char* Gtk2Gui_WScrollArea_GetCharProperty(GWEN_WIDGET *w,
00120                                                  GWEN_DIALOG_PROPERTY prop,
00121                                                  int index,
00122                                                  const char *defaultValue) {
00123   GtkWidget *gs; /* scrollable window */
00124   GtkWidget *g;  /* vbox */
00125 
00126   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00127   assert(g);
00128   gs=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00129   assert(gs);
00130 
00131   DBG_WARN(GWEN_LOGDOMAIN,
00132            "Function is not appropriate for this type of widget (%s)",
00133            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00134   return defaultValue;
00135 }
00136 
00137 
00138 
00139 static GWENHYWFAR_CB
00140 int Gtk2Gui_WScrollArea_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) {
00141   GtkWidget *g;
00142   GtkWidget *gChild;
00143   uint32_t cflags;
00144 
00145   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00146   assert(g);
00147 
00148   gChild=GTK_WIDGET(GWEN_Widget_GetImplData(wChild, GTK2_DIALOG_WIDGET_REAL));
00149   assert(gChild);
00150 
00151   cflags=GWEN_Widget_GetFlags(wChild);
00152 
00153   gtk_box_pack_start(GTK_BOX(g), gChild,
00154                      (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE,
00155                      (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE,
00156                      0);
00157 
00158   return 0;
00159 }
00160 
00161 
00162 
00163 int Gtk2Gui_WScrollArea_Setup(GWEN_WIDGET *w) {
00164   GtkWidget *g;
00165   GtkWidget *gContent;
00166   uint32_t flags;
00167   GWEN_WIDGET *wParent;
00168 
00169   flags=GWEN_Widget_GetFlags(w);
00170   wParent=GWEN_Widget_Tree_GetParent(w);
00171 
00172   /* create widget */
00173   g=gtk_scrolled_window_new(NULL, NULL);
00174   gContent=gtk_vbox_new(TRUE, GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING);
00175   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(g), gContent);
00176 
00177   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g);
00178   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) gContent);
00179 
00180   GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WScrollArea_SetIntProperty);
00181   GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WScrollArea_GetIntProperty);
00182   GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WScrollArea_SetCharProperty);
00183   GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WScrollArea_GetCharProperty);
00184   GWEN_Widget_SetAddChildGuiWidgetFn(w, Gtk2Gui_WScrollArea_AddChildGuiWidget);
00185 
00186   if (wParent)
00187     GWEN_Widget_AddChildGuiWidget(wParent, w);
00188 
00189   return 0;
00190 }
00191 
00192