"Fossies" - the Fresh Open Source Software Archive

Member "gamgi0.17.5x/src/gtk/help/gamgi_gtk_help_dialog.c" (23 Feb 2022, 8673 Bytes) of package /linux/misc/gamgi-all-0.17.5x.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /***********************************************
    2  *
    3  * $GAMGI/src/gtk/help/gamgi_gtk_help_dialog.c
    4  *
    5  * Copyright (C) 2001, 2004 Carlos Pereira
    6  *
    7  * Distributed under the terms of the GNU
    8  * General Public License: $GAMGI/LICENSE
    9  *
   10  */
   11 
   12 #include <ctype.h>
   13 
   14 #include "gamgi_engine.h"
   15 #include "gamgi_gtk.h"
   16 #include "gamgi_io.h"
   17 #include "gamgi_expat.h"
   18 #include "gamgi_global.h"
   19 
   20 #include "gamgi_gtk_dialog.h"
   21 #include "gamgi_io_token.h"
   22 #include "gamgi_io_file.h"
   23 #include "gamgi_io_error.h"
   24 #include "gamgi_expat_import.h"
   25 
   26 static gamgi_bool static_browser (char *fullname, 
   27 char *shortname, gamgi_window *window)
   28 {
   29 char command[GAMGI_ENGINE_LINE];
   30 
   31 /******************************
   32  * check browser availability *
   33  ******************************/
   34 
   35 if (gamgi->help->browser == NULL)
   36   return gamgi_io_error_browser (window);
   37 
   38 /********************************************************
   39  * check command size: add 4 for 2 spaces, '&' and '\0' *
   40  ********************************************************/
   41 
   42 if (strlen (gamgi->help->browser) + strlen (fullname) + 4 > GAMGI_ENGINE_LINE)
   43   return gamgi_io_error_open (shortname, window);
   44 
   45 /********************************
   46  * array is larger than command *
   47  ********************************/
   48 
   49 sprintf (command, "%s %s &", gamgi->help->browser, fullname);
   50 system (command);
   51 
   52 return TRUE;
   53 }
   54 
   55 char *static_source (gamgi_window *window)
   56 {
   57 char *source;
   58 
   59 if (gamgi->help->source_in == TRUE)
   60   {
   61   /*********************************************
   62    * get help documentation from local address *
   63    *********************************************/
   64 
   65   source = gamgi->help->local;
   66   if (source == NULL) gamgi_io_error_local (window);
   67   }
   68 else
   69   {
   70   /**********************************************
   71    * get help documentation from remote address *
   72    **********************************************/
   73 
   74   source = gamgi->help->remote;
   75   if (source == NULL) gamgi_io_error_remote (window);
   76   }
   77 
   78 return source; 
   79 }
   80 
   81 GtkWidget *gamgi_gtk_help_dialog_text (GtkWidget *vbox)
   82 {
   83 GtkWidget *scrolled_window;
   84 GtkWidget *text;
   85 
   86 /**************************
   87  * create scrolled window *
   88  **************************/
   89 
   90 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
   91 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
   92 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
   93 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
   94 gtk_widget_show (scrolled_window);
   95 
   96 /******************************
   97  * create and initialize text *
   98  ******************************/
   99 
  100 text = gamgi_gtk_dialog_text_create ();
  101 gtk_container_add (GTK_CONTAINER (scrolled_window), text);
  102 gtk_widget_show (text);
  103 
  104 return text;
  105 }
  106 
  107 GtkWidget *gamgi_gtk_help_dialog_page (GtkWidget *notebook, char *name)
  108 {
  109 GtkWidget *label;
  110 GtkWidget *vbox_page;
  111 
  112 /********
  113  * page *
  114  ********/
  115 
  116 vbox_page = gtk_vbox_new (TRUE, 0);
  117 gtk_container_set_border_width (GTK_CONTAINER (vbox_page), 5);
  118 label = gtk_label_new (name);
  119 gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox_page, label);
  120 gtk_widget_show (vbox_page);
  121 
  122 return vbox_page;
  123 }
  124 
  125 GtkWidget *gamgi_gtk_help_dialog_notebook (GtkWidget *vbox_dialog)
  126 {
  127 GtkWidget *notebook;
  128 
  129 /************
  130  * notebook *
  131  ************/
  132 
  133 notebook = gtk_notebook_new ();
  134 gtk_box_pack_start (GTK_BOX (vbox_dialog), notebook, TRUE, TRUE, 0);
  135 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_TOP);
  136 gtk_widget_set_size_request (notebook,
  137 GAMGI_GTK_TEXT_WIDTH_MIN, GAMGI_GTK_TEXT_HEIGHT_MIN);
  138 gtk_widget_show (notebook);
  139 
  140 return notebook;
  141 }
  142 
  143 GtkWidget *gamgi_gtk_help_dialog_window (char *title, gamgi_window *window)
  144 {
  145 GtkWidget *dialog;
  146 GtkWidget *vbox_dialog;
  147 GtkWidget *hbox_center;
  148 GtkWidget *button;
  149 
  150 dialog = gamgi_gtk_dialog_help_create (title, window);
  151 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
  152 
  153 vbox_dialog = gtk_vbox_new (FALSE, 0);
  154 gtk_container_add (GTK_CONTAINER (dialog), vbox_dialog);
  155 gtk_widget_show (vbox_dialog);
  156 
  157 /*****************
  158  * Cancel button *
  159  *****************/
  160 
  161 hbox_center = gtk_hbox_new (TRUE, 0);
  162 gtk_box_pack_end (GTK_BOX (vbox_dialog), hbox_center, FALSE, FALSE, 5);
  163 gtk_widget_show (hbox_center);
  164 
  165 button = gamgi_gtk_dialog_button_create ("Cancel", "red");
  166 gtk_box_pack_start (GTK_BOX (hbox_center), button, FALSE, FALSE, 0);
  167 gtk_widget_set_size_request (button, GAMGI_GTK_BUTTON_WIDTH, -1);
  168 gtk_widget_grab_focus (button);
  169 g_signal_connect (button, "clicked",
  170 G_CALLBACK (gamgi_gtk_dialog_remove), &window->help);
  171 gtk_widget_show (button);
  172 
  173 return vbox_dialog;
  174 }
  175 
  176 gamgi_bool gamgi_gtk_help_dialog_import (char *title, 
  177 char *file, gamgi_window *window, int n_pages, int page, ...)
  178 {
  179 GtkWidget *notebook;
  180 GtkWidget *vbox_dialog, *vbox_page;
  181 GtkWidget *text;
  182 char fullname[GAMGI_IO_FULLNAME];
  183 char token[GAMGI_ENGINE_TOKEN];
  184 char *shortname;
  185 va_list list;
  186 char *source, *name;
  187 int i;
  188 
  189 /***********************************************
  190  * The allowed values are:                     *
  191  * if (n_pages == 0) page = 0;                 *
  192  * if (n_pages == N && N > 0) page = 1,..., N; *
  193  ***********************************************/
  194  
  195 if (page > n_pages) page = n_pages;
  196 if (page == 0 && n_pages > 0) page = 1;
  197 
  198 /****************************
  199  * get documentation source *
  200  ****************************/
  201 
  202 source = static_source (window);
  203 if (source == NULL) return FALSE;
  204 
  205 if (gamgi->help->agent_in == FALSE)
  206   {
  207   /*****************************
  208    * use a browser to see file *
  209    *****************************/
  210 
  211   if (page == 0)
  212     {
  213     /**********************************
  214      * check size, accounting for the *
  215      * extra characters: / .html '\0' *
  216      **********************************/
  217 
  218     if (strlen (source) + strlen (file) + 7 > GAMGI_IO_FULLNAME)
  219       return gamgi_io_error_open (file, window);
  220     sprintf (fullname, "%s/%s.html", source, file);
  221     }
  222   else
  223     {
  224     /***********************************
  225      * get file for notebook open page *
  226      ***********************************/
  227 
  228     name = NULL;
  229     va_start (list, page);
  230     for (i = 0; i < page; i++)
  231       name = va_arg (list, char *);
  232     va_end (list);
  233 
  234     /************************************
  235      * check size, accounting for the   *
  236      * extra characters: / _ .html '\0' *
  237      ************************************/
  238 
  239     if (strlen (source) + strlen (file) + strlen (name) + 8 > GAMGI_IO_FULLNAME)
  240       return gamgi_io_error_open (file, window);
  241     sprintf (fullname, "%s/%s_%s.html", source, file, name);
  242     }
  243 
  244   shortname = gamgi_io_file_shortname (fullname);
  245 
  246   return static_browser (fullname, shortname, window);
  247   }
  248 
  249 /*************************
  250  * use gamgi to see file *
  251  *************************/
  252 
  253 vbox_dialog = gamgi_gtk_help_dialog_window (title, window);
  254 notebook = gamgi_gtk_help_dialog_notebook (vbox_dialog);
  255 
  256 if (page == 0)
  257   {
  258   gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
  259   vbox_page = gamgi_gtk_help_dialog_page (notebook, "");
  260   text = gamgi_gtk_help_dialog_text (vbox_page);
  261   
  262   /**********************************
  263    * check size, accounting for the *
  264    * extra characters: / .html '\0' *
  265    **********************************/
  266 
  267   if (strlen (source) + strlen (file) + 7 > GAMGI_IO_FULLNAME)
  268     return gamgi_io_error_open (file, window);
  269   sprintf (fullname, "%s/%s.html", source, file);
  270 
  271   if (gamgi_expat_import_html (fullname, text, window) == FALSE)
  272     { gamgi_gtk_dialog_remove (NULL, &window->help); return FALSE; }
  273   }
  274 else
  275   {
  276   /***********************************
  277    * get file for notebook open page *
  278    ***********************************/
  279 
  280   va_start (list, page);
  281   for (i = 0; i < n_pages; i++)
  282     {
  283     name = va_arg (list, char *);
  284 
  285     sprintf (token, "%c%s", toupper (name[0]), name + 1);
  286     vbox_page = gamgi_gtk_help_dialog_page (notebook, token);
  287     text = gamgi_gtk_help_dialog_text (vbox_page);
  288 
  289     /************************************
  290      * check size, accounting for the   *
  291      * extra characters: / _ .html '\0' *
  292      ************************************/
  293 
  294     if (strlen (source) + strlen (file) + strlen (name) + 8 > GAMGI_IO_FULLNAME)
  295       { gamgi_io_error_open (file, window); 
  296         gamgi_gtk_dialog_remove (NULL, &window->help); 
  297         va_end (list); return FALSE; }
  298 
  299     sprintf (fullname, "%s/%s_%s.html", source, file, name);
  300 
  301     if (gamgi_expat_import_html (fullname, text, window) == FALSE)
  302       { gamgi_gtk_dialog_remove (NULL, &window->help); 
  303         va_end (list); return FALSE; }
  304     }
  305 
  306   gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), page - 1);
  307   va_end (list);
  308   }
  309 
  310 gtk_widget_show (window->help);
  311 
  312 return TRUE;
  313 }
  314 
  315 void gamgi_gtk_help_dialog_tips (GtkWidget *widget, void *data)
  316 {
  317 gamgi_gtk_help_dialog_import ("Help Tips",
  318 "tips", GAMGI_CAST_WINDOW data, 0, 0);
  319 }