TSP: The Transport Sample Protocol



Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

gdisp_graphics.c

Go to the documentation of this file.
00001 
00043 /*
00044  * System includes.
00045  */
00046 #include <stdio.h>
00047 #include <stdlib.h>
00048 #include <assert.h>
00049 #include <string.h>
00050 
00051 
00052 /*
00053  * GDISP+ includes.
00054  */
00055 #include "gdisp_kernel.h"
00056 #include "gdisp_prototypes.h"
00057 
00058 
00059 /*
00060  --------------------------------------------------------------------
00061                              STATIC ROUTINES
00062  --------------------------------------------------------------------
00063 */
00064 
00065 #define GD_TABLE_SPACING 20
00066 
00067 
00068 /*
00069  * This callback is called whenever a "press button" is pressed.
00070  * The argument "data" is the kernel itself.
00071  */
00072 static void
00073 gdisp_changePlotTypeCallback(GtkWidget *buttonWidget,
00074                              gpointer   data )
00075 {
00076 
00077   Kernel_T         *kernel        =     (Kernel_T*)data;
00078   PlotSystem_T     *plotSystem    = (PlotSystem_T*)NULL;
00079   GString          *messageString = (GString*)NULL;
00080   PlotSystemInfo_T  plotInformation;
00081 
00082 
00083   /*
00084    * Store new current plot type.
00085    */
00086   kernel->currentPlotType =
00087     (PlotType_T)gtk_object_get_user_data(GTK_OBJECT(buttonWidget));
00088 
00089   /*
00090    * The callback has been called. So the corresponding plot type
00091    * is fully supported. Otherwise, the "press button" would not have
00092    * been created.
00093    */
00094   plotSystem = &kernel->plotSystems[kernel->currentPlotType];
00095   (*plotSystem->psGetInformation)(kernel,
00096                                   &plotInformation);
00097 
00098   /*
00099    * Write into the output window.
00100    * Keep in mind that the GString is released into the
00101    * 'gdispOutputWrite' function.
00102    * Do not 'g_string_free' it.
00103    */
00104   messageString = g_string_new((gchar*)NULL);
00105   g_string_sprintf(messageString,
00106                    "%s is now selected.",
00107                    plotInformation.psName);
00108   kernel->outputFunc(kernel,messageString,GD_MESSAGE);
00109 
00110 }
00111 
00112 
00113 /*
00114  --------------------------------------------------------------------
00115                              PUBLIC ROUTINES
00116  --------------------------------------------------------------------
00117 */
00118 
00119 
00120 /*
00121  * Create GDISP+ graphic plot list.
00122  */
00123 void
00124 gdisp_createGraphicList ( Kernel_T  *kernel,
00125                           GtkWidget *parent )
00126 {
00127 
00128   PlotType_T        plotType       = GD_PLOT_DEFAULT;
00129   PlotSystem_T     *plotSystem     = (PlotSystem_T*)NULL;
00130   PlotSystemInfo_T  plotInformation;
00131   GtkWidget        *frame          = (GtkWidget*)NULL;
00132   GtkWidget        *scrolledWindow = (GtkWidget*)NULL;
00133   GtkWidget        *box            = (GtkWidget*)NULL;
00134   GtkWidget        *table          = (GtkWidget*)NULL;
00135   GtkWidget        *pressButton    = (GtkWidget*)NULL;
00136   GtkTooltips      *toolTipGroup   = (GtkTooltips*)NULL;
00137   guint             line           = 0;
00138   guint             lineNumber     = 0;
00139   guint             column         = 0;
00140   guint             columnNumber   = 0;
00141 
00142   GtkWidget        *pixmapWidget   = (GtkWidget*)NULL;
00143   Pixmap_T         *pixmap         =  (Pixmap_T*)NULL;
00144 
00145 
00146   /* ------------------------ TOOLTIP GROUP ------------------------ */
00147 
00148   /*
00149    * Create the group of tooltips.
00150    * Look downwards for the association of tooltips and widgets.
00151    */
00152   toolTipGroup = gtk_tooltips_new();
00153 
00154 
00155   /* ------------------------ FRAME WITH LABEL ------------------------ */
00156 
00157   /*
00158    * Create a Frame that will contain a scrolled window for graphic logos.
00159    * Align the label at the left of the frame.
00160    * Set the style of the frame.
00161    */
00162   frame = gtk_frame_new(" Available Graphic Plots ");
00163   gtk_frame_set_label_align(GTK_FRAME(frame),0.1,0.0);
00164   gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_ETCHED_IN);
00165 
00166   gtk_container_add(GTK_CONTAINER(parent),frame);
00167   gtk_widget_show(frame);
00168 
00169 
00170   /* -------- SCROLLED WINDOW FOR THE LIST OF GRAPHIC PLOTS  -------- */
00171 
00172   /*
00173    * This is the scrolled window to put the List widget inside.
00174    */
00175   scrolledWindow = gtk_scrolled_window_new(NULL /* H Adjustment */,
00176                                            NULL /* V Adjustment */);
00177   gtk_container_border_width(GTK_CONTAINER(scrolledWindow),5);
00178   gtk_container_add(GTK_CONTAINER(frame),scrolledWindow); 
00179   gtk_widget_show(scrolledWindow);
00180 
00181 
00182   /* --------- BOX FOR ADDING SPACE INTO THE SCROLLED WINDOW ---------- */
00183 
00184   /*
00185    * We need a vertical packing box for managing the table.
00186    */
00187   box = gtk_vbox_new(FALSE, /* homogeneous */
00188                      0      /* spacing     */ );
00189   gtk_container_border_width(GTK_CONTAINER(box),
00190                              GD_TABLE_SPACING);
00191 
00192   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolledWindow),
00193                                         box);
00194 
00195   gtk_widget_show(box);
00196 
00197 
00198   /* ------------ TABLE CONTAINER FOR GRAPHIC PLOTS  ------------ */
00199 
00200   /*
00201    * Create a table with the correct dimensions.
00202    * 2 columns x (GD_MAX_PLOT / 2) lines.
00203    */
00204   lineNumber   = GD_MAX_PLOT / 2;
00205   columnNumber = 2;
00206 
00207   table = gtk_table_new(lineNumber,
00208                         columnNumber,
00209                         TRUE /* homogeneous */);
00210   gtk_table_set_row_spacings(GTK_TABLE(table),
00211                              GD_TABLE_SPACING);
00212   gtk_table_set_col_spacings(GTK_TABLE(table),
00213                              GD_TABLE_SPACING);
00214 
00215   gtk_box_pack_start(GTK_BOX(box),
00216                      table,
00217                      FALSE /* expand  */,
00218                      FALSE /* fill    */,
00219                      0     /* padding */);
00220 
00221   gtk_widget_show(table);
00222 
00223 
00224   /* ---------------- INSERT GRAPHIC PLOT TYPES  ---------------- */
00225 
00226   /* Do not start with default plot */
00227   plotType++;
00228 
00229   for (line=0; line<lineNumber; line++) {
00230 
00231     for (column=0; column<columnNumber; column++) {
00232 
00233       if (plotType < GD_MAX_PLOT) {
00234 
00235         plotSystem = &kernel->plotSystems[plotType];
00236 
00237         if (plotSystem->psIsSupported == TRUE) {
00238 
00239           /*
00240            * Get back information from graphic plot.
00241            */
00242           memset(&plotInformation,0,sizeof(PlotSystemInfo_T));
00243           (*plotSystem->psGetInformation)(kernel,
00244                                           &plotInformation);
00245 
00246           /*
00247            * Instanciate a press button.
00248            */
00249           pressButton = gtk_button_new();
00250 
00251           /*
00252            * Associate the press button with the plot type it represents.
00253            * Attach a "clicked" callback.
00254            */
00255           gtk_object_set_user_data(GTK_OBJECT(pressButton),
00256                                    (gpointer)plotType);
00257 
00258           gtk_signal_connect(GTK_OBJECT(pressButton),
00259                              "clicked",
00260                              GTK_SIGNAL_FUNC(gdisp_changePlotTypeCallback),
00261                              (gpointer)kernel);
00262 
00263           /**********************************************************/
00264 
00265           /*
00266            * Use GDK services to create GDISP+ Logo (XPM format).
00267            */
00268           if (plotInformation.psLogo == (gchar**)NULL) {
00269 
00270             pixmap = gdisp_getPixmapById(
00271                                       kernel,
00272                                       GD_PIX_gdispLogo,
00273                                       kernel->widgets.dataBookWindow);
00274 
00275           }
00276           else {
00277 
00278             pixmap = gdisp_getPixmapByAddr(
00279                                       kernel,
00280                                       (gchar**)plotInformation.psLogo,
00281                                       kernel->widgets.dataBookWindow);
00282 
00283           }
00284 
00285           /*
00286            * Create a pixmap widget to contain the pixmap.
00287            */
00288           pixmapWidget = gtk_pixmap_new(pixmap->pixmap,
00289                                         pixmap->mask);
00290 
00291           gtk_container_add(GTK_CONTAINER(pressButton),
00292                             pixmapWidget);
00293 
00294           gtk_widget_show(pixmapWidget);
00295 
00296           /**********************************************************/
00297 
00298           /*
00299            * Set up a requested size for the press button.
00300            */
00301           gtk_widget_set_usize(pressButton,
00302                                150,
00303                                150);
00304 
00305           /*
00306            * Associate a tooltip information to the press button.
00307            */
00308           gtk_tooltips_set_tip(GTK_TOOLTIPS(toolTipGroup),
00309                                pressButton,
00310                                plotInformation.psDescription,
00311                                "");
00312 
00313           /*
00314            * Attach the press button to its parent widget.
00315            */
00316           gtk_table_attach_defaults(GTK_TABLE(table),
00317                                     pressButton,
00318                                     column,
00319                                     column + 1,
00320                                     line,
00321                                     line   + 1);
00322 
00323           /*
00324            * Show the press button.
00325            */
00326           gtk_widget_show(pressButton);
00327 
00328         } /* graphic plot is supported */
00329 
00330       } /* do not exceed GD_MAX_PLOT */
00331 
00332       plotType++;
00333 
00334     } /* columns */
00335 
00336   } /* lines */
00337 
00338 }
00339 
00340 
00341 /*
00342  * Destroy GDISP+ graphic plot list.
00343  */
00344 void
00345 gdisp_destroyGraphicList ( Kernel_T *kernel )
00346 {
00347 
00348   /*
00349    * Nothing by now.
00350    */
00351 
00352 }
Framework Home Page.

Beware !! TSP wave is coming...