TSP: The Transport Sample Protocol



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

gdisp_pixmaps.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 
00050 
00051 /*
00052  * GDISP+ includes.
00053  */
00054 #include "gdisp_kernel.h"
00055 #include "gdisp_prototypes.h"
00056 
00057 
00058 /*
00059  --------------------------------------------------------------------
00060                              PIXMAP INCLUSION
00061  --------------------------------------------------------------------
00062 */
00063 
00064 #include "pixmaps/gdisp_gdispLogo.xpm"
00065 #include "pixmaps/gdisp_okButton.xpm"
00066 #include "pixmaps/gdisp_okButton2.xpm"
00067 #include "pixmaps/gdisp_stopButton.xpm"
00068 #include "pixmaps/gdisp_timeDigits.xpm"
00069 #include "pixmaps/gdisp_2dLogo.xpm"
00070 #include "pixmaps/gdisp_textLogo.xpm"
00071 #include "pixmaps/gdisp_stubLogo.xpm"
00072 #include "pixmaps/gdisp_resLogo.xpm"
00073 #include "pixmaps/gdisp_collapsedNode.xpm"
00074 #include "pixmaps/gdisp_expandedNode.xpm"
00075 #include "pixmaps/gdisp_applyLogo.xpm"
00076 #include "pixmaps/gdisp_doneLogo.xpm"
00077 #include "pixmaps/gdisp_warningLogo.xpm"
00078 #include "pixmaps/gdisp_errorLogo.xpm"
00079 #include "pixmaps/gdisp_infoLogo.xpm"
00080 #include "pixmaps/gdisp_magentaBall.xpm"
00081 #include "pixmaps/gdisp_cyanBall.xpm"
00082 #include "pixmaps/gdisp_yellowBall.xpm"
00083 #include "pixmaps/gdisp_blueBall.xpm"
00084 #include "pixmaps/gdisp_greenBall.xpm"
00085 #include "pixmaps/gdisp_redBall.xpm"
00086 
00087 
00088 
00089 /*
00090  --------------------------------------------------------------------
00091                              STATIC ROUTINES
00092  --------------------------------------------------------------------
00093 */
00094 
00095 static gint
00096 gdisp_checkPixmapById ( gconstpointer listItemData,
00097                         gconstpointer pixmapIdAddr )
00098 {
00099 
00100   Pixmap_T  *pixmap   =  (Pixmap_T*)listItemData;
00101   Pixmap_ID *pixmapId = (Pixmap_ID*)pixmapIdAddr;
00102 
00103   return (pixmap->id == (*pixmapId) ? 0 : 1);
00104 
00105 }
00106 
00107 
00108 static gint
00109 gdisp_checkPixmapByAddr ( gconstpointer listItemData,
00110                           gconstpointer pixmapAddr )
00111 {
00112 
00113   Pixmap_T  *pixmap     = (Pixmap_T*)listItemData;
00114   gchar    **pixmapData = (gchar**)pixmapAddr;
00115 
00116   return (pixmap->data == pixmapData ? 0 : 1);
00117 
00118 }
00119 
00120 
00121 static Pixmap_T*
00122 gdisp_createPixmap ( Kernel_T   *kernel,
00123                      Pixmap_ID   pixmapId,
00124                      gchar     **pixmapAddr,
00125                      GtkWidget  *pixmapParent )
00126 {
00127 
00128   Pixmap_T *requestedPixmap = (Pixmap_T*)NULL;
00129   GtkStyle *style           = (GtkStyle*)NULL;
00130 
00131   /*
00132    * All available pixmaps.
00133    */
00134   gchar **gdisp_pixmapAddrs[GD_PIX_NbPixmaps] = { gdisp_gdispLogo,
00135                                                   gdisp_okButton,
00136                                                   gdisp_okButton2,
00137                                                   gdisp_stopButton,
00138                                                   gdisp_timeDigits,
00139                                                   gdisp_2dLogo,
00140                                                   gdisp_textLogo,
00141                                                   gdisp_stubLogo,
00142                                                   gdisp_resLogo,
00143                                                   gdisp_collapsedNode,
00144                                                   gdisp_expandedNode,
00145                                                   gdisp_applyLogo,
00146                                                   gdisp_doneLogo,
00147                                                   gdisp_warningLogo,
00148                                                   gdisp_errorLogo,
00149                                                   gdisp_infoLogo,
00150                                                   gdisp_magentaBall,
00151                                                   gdisp_cyanBall,
00152                                                   gdisp_yellowBall,
00153                                                   gdisp_blueBall,
00154                                                   gdisp_greenBall,
00155                                                   gdisp_redBall };
00156 
00157 
00158   /*
00159    * Allocate memory for this new pixmap.
00160    */
00161   requestedPixmap = (Pixmap_T*)g_malloc0(sizeof(Pixmap_T));
00162   assert(requestedPixmap);
00163 
00164   if (pixmapId == GD_PIX_NbPixmaps) {
00165 
00166     requestedPixmap->id   = pixmapId;
00167     requestedPixmap->data = pixmapAddr;
00168 
00169   }
00170   else {
00171 
00172     requestedPixmap->id   = pixmapId;
00173     requestedPixmap->data = gdisp_pixmapAddrs[pixmapId];
00174 
00175   }
00176 
00177   /*
00178    * Deduce width and height from pixmap data.
00179    */
00180   if (sscanf(requestedPixmap->data[0],
00181              "%d %d",
00182              &requestedPixmap->width,
00183              &requestedPixmap->height) != 2) {
00184 
00185     requestedPixmap->width  = 1;
00186     requestedPixmap->height = 1; /* fallback */
00187 
00188   }
00189 
00190   /*
00191    * Tke into account the parent style for transparency purpose.
00192    */
00193   style = gtk_widget_get_style(pixmapParent);
00194 
00195   /*
00196    * Now, create the pixmap according to specified data.
00197    */
00198   requestedPixmap->pixmap =
00199     gdk_pixmap_create_from_xpm_d(pixmapParent->window,
00200                                  &requestedPixmap->mask,
00201                                  &style->bg[GTK_STATE_NORMAL],
00202                                  requestedPixmap->data);
00203 
00204   /*
00205    * Store it into the list.
00206    */
00207   kernel->widgets.pixmapTable = g_list_prepend(kernel->widgets.pixmapTable,
00208                                                (gpointer)requestedPixmap);
00209 
00210   return requestedPixmap;
00211 
00212 }
00213 
00214 /*
00215  --------------------------------------------------------------------
00216                              PUBLIC ROUTINES
00217  --------------------------------------------------------------------
00218 */
00219 
00220 
00221 Pixmap_T*
00222 gdisp_getPixmapById ( Kernel_T  *kernel,
00223                       Pixmap_ID  pixmapId,
00224                       GtkWidget *pixmapParent )
00225 {
00226 
00227   GList     *requestedPixmapListItem =    (GList*)NULL;
00228   Pixmap_T  *requestedPixmap         = (Pixmap_T*)NULL;
00229   gchar    **pixmapAddr              =   (gchar**)NULL;
00230   GtkStyle  *style                   = (GtkStyle*)NULL;
00231 
00232 
00233   /*
00234    * Retreive requested pixmap.
00235    */
00236   if (kernel->widgets.pixmapTable != (GList*)NULL) {
00237 
00238     requestedPixmapListItem = g_list_find_custom(kernel->widgets.pixmapTable,
00239                                                  (gpointer)&pixmapId,
00240                                                  gdisp_checkPixmapById);
00241 
00242   }
00243 
00244   if (requestedPixmapListItem == (GList*)NULL) {
00245 
00246     requestedPixmap = gdisp_createPixmap(kernel,
00247                                          pixmapId,
00248                                          pixmapAddr,
00249                                          pixmapParent);
00250   }
00251   else {
00252 
00253     requestedPixmap = (Pixmap_T*)requestedPixmapListItem->data;
00254 
00255   }
00256 
00257   return requestedPixmap;
00258 
00259 }
00260 
00261 
00262 Pixmap_T*
00263 gdisp_getPixmapByAddr ( Kernel_T   *kernel,
00264                         gchar     **pixmapAddr,
00265                         GtkWidget  *pixmapParent )
00266 {
00267 
00268   GList     *requestedPixmapListItem = (GList*)NULL;
00269   Pixmap_T  *requestedPixmap         = (Pixmap_T*)NULL;
00270   Pixmap_ID  pixmapId                = GD_PIX_NbPixmaps;
00271   GtkStyle  *style                   = (GtkStyle*)NULL;
00272 
00273 
00274   /*
00275    * Retreive requested pixmap.
00276    */
00277   if (kernel->widgets.pixmapTable != (GList*)NULL) {
00278 
00279     requestedPixmapListItem = g_list_find_custom(kernel->widgets.pixmapTable,
00280                                                  (gpointer)pixmapAddr,
00281                                                  gdisp_checkPixmapByAddr);
00282 
00283   }
00284 
00285   if (requestedPixmapListItem == (GList*)NULL) {
00286 
00287     requestedPixmap = gdisp_createPixmap(kernel,
00288                                          pixmapId,
00289                                          pixmapAddr,
00290                                          pixmapParent);
00291   }
00292   else {
00293 
00294     requestedPixmap = (Pixmap_T*)requestedPixmapListItem->data;
00295 
00296   }
00297 
00298   return requestedPixmap;
00299 
00300 }
00301 
00302 
00303 void
00304 gdisp_destroyPixmaps ( Kernel_T *kernel )
00305 {
00306 
00307   GList    *pixmapItem =    (GList*)NULL;
00308   Pixmap_T *pixmap     = (Pixmap_T*)NULL;
00309 
00310 
00311   /*
00312    * Loop over all created pixmaps, destroy them.
00313    */
00314   pixmapItem = g_list_first(kernel->widgets.pixmapTable);
00315 
00316   while (pixmapItem != (GList*)NULL) {
00317 
00318     pixmap = (Pixmap_T*)pixmapItem->data;
00319 
00320     gdk_pixmap_unref(pixmap->pixmap);
00321     gdk_bitmap_unref(pixmap->mask  );
00322 
00323     pixmapItem = g_list_next(pixmapItem);
00324 
00325   }
00326 
00327 }
Framework Home Page.

Beware !! TSP wave is coming...