Back to index

lightning-sunbird  0.9+nobinonly
Minimo.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *   Doug Turner <dougt@meer.net>  Branched from TestGtkEmbed.cpp
00024  *
00025  *   The 10LE Team (in alphabetical order)
00026  *   -------------------------------------
00027  *
00028  *    Ilias Biris       <ext-ilias.biris@indt.org.br> - Coordinator
00029  *    Afonso Costa      <afonso.costa@indt.org.br>
00030  *    Antonio Gomes     <antonio.gomes@indt.org.br>
00031  *    Diego Gonzalez    <diego.gonzalez@indt.org.br>
00032  *    Raoni Novellino   <raoni.novellino@indt.org.br>
00033  *    Andre Pedralho    <andre.pedralho@indt.org.br>
00034  *
00035  *
00036  * Alternatively, the contents of this file may be used under the terms of
00037  * either the GNU General Public License Version 2 or later (the "GPL"), or
00038  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00039  * in which case the provisions of the GPL or the LGPL are applicable instead
00040  * of those above. If you wish to allow use of your version of this file only
00041  * under the terms of either the GPL or the LGPL, and not to allow others to
00042  * use your version of this file under the terms of the MPL, indicate your
00043  * decision by deleting the provisions above and replace them with the notice
00044  * and other provisions required by the GPL or the LGPL. If you do not delete
00045  * the provisions above, a recipient may use your version of this file under
00046  * the terms of any one of the MPL, the GPL or the LGPL.
00047  *
00048  * ***** END LICENSE BLOCK ***** */
00049 
00050 
00051 /* Minimo's global types */
00052 #include "minimo_types.h"
00053 /* History */
00054 #include "minimo_history.h"
00055 /* Minimo's callbacks */
00056 #include "minimo_callbacks.h"
00057 
00058 /* Global variables */
00059 
00060 MinimoBrowser *gMinimoBrowser;            /* Global Minimo Variable */
00061 
00062 gchar *gMinimoProfilePath = NULL;         /* Minimo's PATH - probably "~/home/current_user/.Minimo" */
00063 
00064 GList *gMinimoBrowserList = g_list_alloc();      /* the list of browser windows currently open */
00065 
00066 gint  gMinimoNumBrowsers = 0;                    /* Number of browsers */
00067 
00068 gchar *gMinimoLastFind = NULL;            /* store the last expression on find dialog */
00069 
00070 gchar *gMinimoLinkMessageURL;             /* Last clicked URL */
00071 
00072 GList *gAutoCompleteList = g_list_alloc(); /* Auto Complete List */
00073 
00074 gchar *gMinimoUserHomePath;
00075 
00076 /* Data Struct for make possible the real autocomplete */
00077 GtkEntryCompletion *gMinimoEntryCompletion;
00078 GtkListStore  *gMinimoAutoCompleteListStore;
00079 GtkTreeIter gMinimoAutoCompleteIter;
00080 
00081 extern ConfigData gPreferenceConfigStruct;
00082 extern PrefWindow *prefWindow;
00083 
00084 /* METHODS HEADERS  */
00085 
00086 /*callbacks from the menuToolButton */
00087 static void show_hide_tabs_cb (GtkMenuItem *button, MinimoBrowser *browser);
00088 static void open_history_window (GtkButton *button, MinimoBrowser* browser);
00089 static void switch_page_cb (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, MinimoBrowser *browser);
00090 static void create_find_dialog (GtkWidget *w, MinimoBrowser *browser);
00091 static void create_open_document_from_file (GtkMenuItem *button, MinimoBrowser *browser);
00092 static void increase_font_size_cb (GtkMenuItem *button, MinimoBrowser *browser);
00093 static void decrease_font_size_cb (GtkMenuItem *button, MinimoBrowser *browser);
00094 static void full_screen_cb (GtkMenuItem *button, MinimoBrowser* browser);
00095 static void unfull_screen_cb (GtkMenuItem *button, MinimoBrowser* browser);
00096 
00097 static GtkWidget *populate_menu_button(MinimoBrowser* browser);
00098 
00099 /* Building the Minimo Browser */
00100 static MinimoBrowser *new_gtk_browser(guint32 chromeMask);
00101 //static void new_window_cb(GtkMozEmbed *embed, GtkMozEmbed **retval, guint chromemask, MinimoBrowser *browser);
00102 static void setup_toolbar(MinimoBrowser* browser);
00103 static void build_entry_completion (MinimoBrowser* browser);
00104 static void setup_escape_key_handler(GtkWidget *window);
00105 static gint escape_key_handler(GtkWidget *window, GdkEventKey *ev);
00106 
00107 /* callbacks from the widget */
00108 static void info_clicked_cb(GtkButton *button, MinimoBrowser *browser);
00109 static void open_clicked_cb(GtkButton *button, MinimoBrowser *browser);
00110 static void create_info_dialog (MinimoBrowser* browser);
00111 static void create_open_dialog(MinimoBrowser* browser);
00112 static void find_dialog_ok_cb (GtkWidget *w, GtkWidget *window);
00113 static void on_open_ok_cb(GtkWidget *button, GtkWidget *fs);
00114 static GtkWidget *get_active_tab (MinimoBrowser *browser);
00115 static void update_ui (MinimoBrowser *browser);
00116 static void destroy_cb(GtkWidget *widget, MinimoBrowser *browser);
00117 /* callbacks from the singleton object */
00118 static void new_window_orphan_cb(GtkMozEmbedSingle *embed, GtkMozEmbed **retval, guint chromemask, gpointer data);
00119 
00120 /* body */
00121 static void handle_remote(int sig)
00122 {
00123   FILE *fp;
00124   char url[256];
00125   
00126   sprintf(url, "/tmp/Mosaic.%d", getpid());
00127   if ((fp = fopen(url, "r"))) {
00128     if (fgets(url, sizeof(url) - 1, fp)) {
00129       MinimoBrowser *bw = NULL;
00130       if (strncmp(url, "goto", 4) == 0 && fgets(url, sizeof(url) - 1, fp)) {
00131         GList *tmp_list = gMinimoBrowserList;
00132         bw =(MinimoBrowser *)tmp_list->data;
00133         if(!bw) return;
00134         
00135       } else if (strncmp(url, "newwin", 6) == 0 && fgets(url, sizeof(url) - 1, fp)) { 
00136         
00137         bw = new_gtk_browser(GTK_MOZ_EMBED_FLAG_DEFAULTCHROME);
00138         gtk_widget_set_usize(bw->mozEmbed, 240, 320);
00139         set_browser_visibility(bw, TRUE);
00140       }
00141       
00142       if (bw)
00143         gtk_moz_embed_load_url(GTK_MOZ_EMBED(bw->mozEmbed), url);
00144       fclose(fp);
00145     }
00146   }
00147   return;
00148 }
00149 
00150 static void init_remote() {
00151   gchar *file;
00152   FILE *fp;
00153   
00154   signal(SIGUSR1, SIG_IGN);
00155   
00156   /* Write the pidfile : would be useful for automation process*/
00157   file = g_strconcat(g_get_home_dir(), "/", ".mosaicpid", NULL);
00158   if((fp = fopen(file, "w"))) {
00159     fprintf (fp, "%d\n", getpid());
00160     fclose (fp);
00161     signal(SIGUSR1, handle_remote);
00162   }
00163   g_free(file);
00164 }
00165 
00166 static void cleanup_remote() {
00167   
00168   gchar *file;
00169   
00170   signal(SIGUSR1, SIG_IGN);
00171   
00172   file = g_strconcat(g_get_home_dir(), "/", ".mosaicpid", NULL);
00173   unlink(file);
00174   g_free(file);
00175 }
00176 
00177 static void autocomplete_populate(gpointer data, gpointer combobox) {
00178   
00179   if (!data || !combobox)
00180        return;
00181   
00182   gtk_combo_set_popdown_strings (GTK_COMBO (combobox), gAutoCompleteList);
00183 }
00184 
00185 static void populate_autocomplete(GtkCombo *comboBox) {
00186   
00187   g_list_foreach(gAutoCompleteList, autocomplete_populate, comboBox);
00188 }
00189 
00190 static gint autocomplete_list_cmp(gconstpointer a, gconstpointer b) {
00191   
00192   if (!a)
00193     return -1;
00194   if (!b)
00195     return 1;
00196   
00197   return strcmp((char*)a, (char*)b);
00198 }
00199 
00200 static void init_autocomplete() {
00201   if (!gAutoCompleteList)
00202     return;
00203   
00204   char* full_path = g_strdup_printf("%s/%s", gMinimoProfilePath, "autocomplete.txt");
00205   
00206   FILE *fp;
00207   char url[255];
00208   
00209   gMinimoAutoCompleteListStore = gtk_list_store_new (1, G_TYPE_STRING);
00210   
00211   if((fp = fopen(full_path, "r+"))) {
00212     while(fgets(url, sizeof(url) - 1, fp)) {
00213       int length = strlen(url);
00214       if (url[length-1] == '\n')
00215         url[length-1] = '\0'; 
00216       gAutoCompleteList = g_list_append(gAutoCompleteList, g_strdup(url));
00217       /* Append url's to autocompletion feature */
00218       gtk_list_store_append (gMinimoAutoCompleteListStore, &gMinimoAutoCompleteIter);
00219       gtk_list_store_set (gMinimoAutoCompleteListStore, &gMinimoAutoCompleteIter, 0, url, -1);
00220     }
00221     fclose(fp);
00222   }
00223   
00224   gAutoCompleteList =   g_list_sort(gAutoCompleteList, autocomplete_list_cmp);
00225 }
00226 
00227 static void autocomplete_writer(gpointer data, gpointer fp) {
00228   FILE* file = (FILE*) fp;
00229   char* url  = (char*) data;
00230   
00231   if (!url || !fp)
00232     return;
00233   
00234   fwrite(url, strlen(url), 1, file);
00235   fputc('\n', file);  
00236 }
00237 
00238 static void autocomplete_destroy(gpointer data, gpointer dummy) {
00239   
00240   g_free(data);
00241 }
00242 
00243 static void cleanup_autocomplete() {
00244   char* full_path = g_strdup_printf("%s/%s", gMinimoProfilePath, "autocomplete.txt");
00245   FILE *fp;
00246   
00247   if((fp = fopen(full_path, "w"))) {
00248     g_list_foreach(gAutoCompleteList, autocomplete_writer, fp);
00249     fclose(fp);
00250   }
00251   
00252   g_free(full_path);
00253   g_list_foreach(gAutoCompleteList, autocomplete_destroy, NULL);
00254 }
00255 
00256 static void add_autocomplete(const char* value, OpenDialogParams* params) {
00257   
00258   GList* found = g_list_find_custom(gAutoCompleteList, value, autocomplete_list_cmp);
00259   
00260   if (!found) {
00261     gAutoCompleteList = g_list_insert_sorted(gAutoCompleteList, g_strdup(value), autocomplete_list_cmp);    
00262     /* Append url's to autocompletion*/
00263     gtk_list_store_append (gMinimoAutoCompleteListStore, &gMinimoAutoCompleteIter);
00264     gtk_list_store_set (gMinimoAutoCompleteListStore, &gMinimoAutoCompleteIter, 0, value, -1);
00265   }
00266   gtk_combo_set_popdown_strings (GTK_COMBO (params->dialog_combo), gAutoCompleteList);
00267 }
00268 
00269 int
00270 main(int argc, char **argv) {
00271   
00272 #ifdef NS_TRACE_MALLOC
00273   argc = NS_TraceMallocStartupArgs(argc, argv);
00274 #endif
00275   
00276   gtk_set_locale();
00277   gtk_init(&argc, &argv);
00278   
00279   gMinimoUserHomePath = PR_GetEnv("HOME");
00280   if (!gMinimoUserHomePath) {
00281     fprintf(stderr, "Failed to get HOME\n");
00282     exit(1);
00283   }
00284   
00285   gchar *dir = g_strconcat(gMinimoUserHomePath,"/.Minimo",NULL);
00286   /* this is fine, as it will silently error if it already exists*/
00287   mkdir(dir,0755);
00288   g_free(dir);   
00289   
00290   /* Minimo's config folder - hidden */  
00291   gMinimoProfilePath = g_strdup_printf("%s/%s", gMinimoUserHomePath, ".Minimo");
00292   gtk_moz_embed_set_profile_path(gMinimoProfilePath, "Minimo");
00293   
00294   gMinimoBrowser = new_gtk_browser(GTK_MOZ_EMBED_FLAG_DEFAULTCHROME);
00295   
00296   /* set our minimum size */
00297   gtk_widget_set_usize(gMinimoBrowser->mozEmbed, 250, 320);
00298   
00299   /* Load the configuration files */
00300   read_minimo_config();
00301   
00302   set_browser_visibility(gMinimoBrowser, TRUE);
00303   
00304   initialize_bookmark(gMinimoBrowser->mozEmbed);
00305   
00306   init_remote();
00307   init_autocomplete();
00308   
00309   if (argc > 1)
00310     gtk_moz_embed_load_url(GTK_MOZ_EMBED(gMinimoBrowser->mozEmbed), argv[1]);
00311   
00312   // get the singleton object and hook up to its new window callback
00313   // so we can create orphaned windows.
00314   GtkMozEmbedSingle *single;
00315   
00316   single = gtk_moz_embed_single_get();
00317   if (!single) {
00318     fprintf(stderr, "Failed to get singleton embed object!\n");
00319     exit(1);
00320   }
00321   
00322   g_signal_connect(GTK_OBJECT(single), "new_window_orphan", G_CALLBACK(new_window_orphan_cb), NULL);
00323   
00324   gtk_main();
00325   
00326   cleanup_remote();
00327   cleanup_autocomplete();
00328 }
00329 
00330 /* Build the Minimo Window */
00331 static MinimoBrowser *
00332 new_gtk_browser(guint32 chromeMask) {
00333   
00334   //MinimoBrowser *browser = 0;
00335   
00336   gMinimoNumBrowsers++;
00337   
00338   gMinimoBrowser = g_new0(MinimoBrowser, 1);
00339   
00340   gMinimoBrowserList = g_list_prepend(gMinimoBrowserList, gMinimoBrowser);
00341   
00342   // create our new toplevel window
00343   gMinimoBrowser->topLevelWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
00344   gtk_window_set_resizable (GTK_WINDOW(gMinimoBrowser->topLevelWindow),TRUE);
00345   gtk_window_set_title (GTK_WINDOW (gMinimoBrowser->topLevelWindow), "MINIMO - Embedded Mozilla");
00346   
00347   // new vbox
00348   gMinimoBrowser->topLevelVBox = gtk_vbox_new(FALSE, 0);
00349   gtk_widget_show (gMinimoBrowser->topLevelVBox);
00350   
00351   // add it to the toplevel window
00352   gtk_container_add(GTK_CONTAINER(gMinimoBrowser->topLevelWindow), gMinimoBrowser->topLevelVBox);
00353   
00354   setup_toolbar(gMinimoBrowser);
00355   
00356   gtk_box_pack_start(GTK_BOX(gMinimoBrowser->topLevelVBox), 
00357                      gMinimoBrowser->toolbar.toolbar,
00358                      FALSE, // expand
00359                      FALSE, // fill
00360                      0);    // padding
00361   
00362   gMinimoBrowser->notebook = gtk_notebook_new ();
00363   gtk_box_pack_start (GTK_BOX (gMinimoBrowser->topLevelVBox), gMinimoBrowser->notebook, TRUE, TRUE, 0);
00364   gMinimoBrowser->show_tabs = FALSE;
00365   gtk_notebook_set_show_tabs (GTK_NOTEBOOK(gMinimoBrowser->notebook), gMinimoBrowser->show_tabs);
00366   gtk_notebook_set_tab_pos (GTK_NOTEBOOK (gMinimoBrowser->notebook), GTK_POS_LEFT);
00367   gtk_widget_show (gMinimoBrowser->notebook);
00368   
00369   open_new_tab_cb (NULL, gMinimoBrowser);
00370   
00371   // catch the destruction of the toplevel window
00372   g_signal_connect(GTK_OBJECT(gMinimoBrowser->topLevelWindow), "delete_event", 
00373                    G_CALLBACK(delete_cb), gMinimoBrowser);
00374   
00375   // hookup to when the window is destroyed
00376   g_signal_connect(GTK_OBJECT(gMinimoBrowser->topLevelWindow), "destroy", G_CALLBACK(destroy_cb), gMinimoBrowser);
00377   
00378   g_signal_connect (GTK_OBJECT (gMinimoBrowser->notebook), "switch_page", 
00379                     G_CALLBACK (switch_page_cb), gMinimoBrowser);
00380   
00381   // set the chrome type so it's stored in the object
00382   // commented for scrollbars fixing
00383   //gtk_moz_embed_set_chrome_mask(GTK_MOZ_EMBED(gMinimoBrowser->mozEmbed), chromeMask);
00384   
00385   gMinimoBrowser->active_page = get_active_tab (gMinimoBrowser);
00386   
00387   return gMinimoBrowser;
00388 }
00389 
00390 void setup_toolbar(MinimoBrowser* browser)
00391 {
00392   MinimoToolbar* toolbar = &browser->toolbar;
00393   GtkWidget *menu;
00394   
00395 #ifdef MOZ_WIDGET_GTK
00396   toolbar->toolbar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
00397 #endif
00398   
00399 #ifdef MOZ_WIDGET_GTK2
00400   toolbar->toolbar = gtk_toolbar_new();
00401   gtk_toolbar_set_orientation(GTK_TOOLBAR(toolbar->toolbar),GTK_ORIENTATION_HORIZONTAL);
00402   gtk_toolbar_set_style(GTK_TOOLBAR(toolbar->toolbar),GTK_TOOLBAR_ICONS);
00403 #endif /* MOZ_WIDGET_GTK2 */
00404   
00405   gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar->toolbar), GTK_ICON_SIZE_SMALL_TOOLBAR);
00406   
00407   gtk_widget_show(toolbar->toolbar);
00408   
00409   toolbar->OpenButton =(GtkWidget*) gtk_tool_button_new_from_stock ("gtk-open");
00410   gtk_widget_show(toolbar->OpenButton);
00411   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->OpenButton);
00412   g_signal_connect(GTK_OBJECT(toolbar->OpenButton), "clicked", G_CALLBACK(open_clicked_cb), browser);
00413   
00414   toolbar->BackButton = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-go-back");
00415   gtk_widget_show(toolbar->BackButton);
00416   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->BackButton);
00417   g_signal_connect(GTK_OBJECT(toolbar->BackButton), "clicked", G_CALLBACK(back_clicked_cb), browser);
00418   
00419   toolbar->ReloadButton = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-refresh");
00420   gtk_widget_show(toolbar->ReloadButton);
00421   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->ReloadButton);
00422   g_signal_connect(GTK_OBJECT(toolbar->ReloadButton), "clicked", G_CALLBACK(reload_clicked_cb), browser);
00423   
00424   toolbar->ForwardButton = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-go-forward");
00425   gtk_widget_show(toolbar->ForwardButton);
00426   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->ForwardButton);
00427   g_signal_connect(GTK_OBJECT(toolbar->ForwardButton), "clicked", G_CALLBACK(forward_clicked_cb), browser);
00428   
00429   toolbar->StopButton =(GtkWidget*) gtk_tool_button_new_from_stock ("gtk-stop");
00430   gtk_widget_show (toolbar->StopButton);
00431   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->StopButton);
00432   g_signal_connect(GTK_OBJECT(toolbar->StopButton), "clicked", G_CALLBACK(stop_clicked_cb), browser);
00433   
00434   toolbar->PrefsButton = (GtkWidget*) gtk_menu_tool_button_new_from_stock("gtk-preferences");
00435   gtk_widget_show (toolbar->PrefsButton);
00436   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->PrefsButton);
00437   g_signal_connect(GTK_OBJECT(toolbar->PrefsButton), "clicked", G_CALLBACK(pref_clicked_cb), browser);
00438   menu = populate_menu_button (browser);
00439   gtk_menu_tool_button_set_menu ((GtkMenuToolButton *) toolbar->PrefsButton, menu);
00440   
00441   toolbar->InfoButton = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-dialog-info");
00442   gtk_widget_show(toolbar->InfoButton);
00443   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->InfoButton);
00444   g_signal_connect(GTK_OBJECT(toolbar->InfoButton), "clicked", G_CALLBACK(info_clicked_cb), browser);
00445   
00446   toolbar->QuitButton = (GtkWidget*) gtk_tool_button_new_from_stock ("gtk-quit");
00447   gtk_widget_show(toolbar->QuitButton);
00448   gtk_container_add(GTK_CONTAINER (toolbar->toolbar), toolbar->QuitButton);  
00449   g_signal_connect(GTK_OBJECT(toolbar->QuitButton), "clicked", G_CALLBACK(destroy_cb), browser);
00450 }
00451 
00452 static GtkWidget *populate_menu_button(MinimoBrowser* browser){
00453   
00454   GtkWidget *menu, *menu_item;
00455   GtkWidget *image;
00456   
00457   menu = gtk_menu_new();
00458   
00459   menu_item = gtk_image_menu_item_new_with_label ("Show/Hide Tabs");
00460   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00461   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(show_hide_tabs_cb), browser);
00462   image = gtk_image_new_from_stock(GTK_STOCK_DND_MULTIPLE, GTK_ICON_SIZE_SMALL_TOOLBAR);
00463   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00464   
00465   menu_item = gtk_image_menu_item_new_with_label ("Add Tab");
00466   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00467   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(open_new_tab_cb), browser);
00468   image = gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_SMALL_TOOLBAR);
00469   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00470   
00471   menu_item = gtk_image_menu_item_new_with_label ("Close Tab");
00472   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00473   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(close_current_tab_cb), browser);
00474   image = gtk_image_new_from_stock(GTK_STOCK_REMOVE, GTK_ICON_SIZE_SMALL_TOOLBAR);
00475   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00476   
00477   menu_item = gtk_image_menu_item_new_with_label ("Open Bookmark Window");
00478   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00479   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(open_bookmark_window_cb), browser);
00480   image = gtk_image_new_from_stock(GTK_STOCK_HARDDISK, GTK_ICON_SIZE_SMALL_TOOLBAR);
00481   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00482   
00483   menu_item = gtk_image_menu_item_new_with_label ("Add Bookmark");
00484   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00485   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(add_bookmark_cb), browser);
00486   image = gtk_image_new_from_stock(GTK_STOCK_YES, GTK_ICON_SIZE_SMALL_TOOLBAR);
00487   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00488   
00489   menu_item = gtk_image_menu_item_new_with_label ("Find");
00490   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00491   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(create_find_dialog), browser);
00492   image = gtk_image_new_from_stock(GTK_STOCK_FIND, GTK_ICON_SIZE_SMALL_TOOLBAR);
00493   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00494   
00495   menu_item = gtk_image_menu_item_new_with_label ("Save As");
00496   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00497   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(create_save_document), browser);
00498   image = gtk_image_new_from_stock(GTK_STOCK_SAVE_AS, GTK_ICON_SIZE_SMALL_TOOLBAR);
00499   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00500   
00501   menu_item = gtk_image_menu_item_new_with_label ("Open From File");
00502   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00503   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(create_open_document_from_file), browser);
00504   image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_SMALL_TOOLBAR);
00505   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00506   
00507   menu_item = gtk_image_menu_item_new_with_label ("Increase Font Size");
00508   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00509   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(increase_font_size_cb), browser);
00510   image = gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_SMALL_TOOLBAR);
00511   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00512   
00513   menu_item = gtk_image_menu_item_new_with_label ("Decrease Font Size");
00514   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00515   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(decrease_font_size_cb), browser);
00516   image = gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_SMALL_TOOLBAR);
00517   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00518   
00519   menu_item = gtk_image_menu_item_new_with_label ("Full Screen");
00520   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00521   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(full_screen_cb), browser);
00522   image = gtk_image_new_from_stock(GTK_STOCK_ZOOM_FIT, GTK_ICON_SIZE_SMALL_TOOLBAR);
00523   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), image);
00524   
00525   menu_item = gtk_image_menu_item_new_with_label ("History");
00526   gtk_menu_shell_append  ((GtkMenuShell *)(menu),menu_item);
00527   g_signal_connect(GTK_OBJECT(menu_item), "activate", G_CALLBACK(open_history_window), browser);
00528   
00529   gtk_widget_show_all(menu);
00530   
00531   return (menu);
00532 }
00533 
00534 static void destroy_dialog_params_cb(GtkWidget *widget, OpenDialogParams* params)
00535 {
00536   free(params);
00537 }
00538 
00539 static void
00540 info_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00541 {
00542   create_info_dialog(browser);
00543 }
00544 
00545 static void
00546 open_clicked_cb(GtkButton *button, MinimoBrowser *browser)
00547 {
00548   create_open_dialog(browser);
00549 }
00550 
00551 static void open_dialog_ok_cb(GtkButton *button, OpenDialogParams* params)
00552 {
00553   const gchar *url = 
00554     gtk_editable_get_chars (GTK_EDITABLE (GTK_COMBO(params->dialog_combo)->entry), 0, -1);
00555   
00556   gtk_moz_embed_load_url(GTK_MOZ_EMBED(((MinimoBrowser *)(params->main_combo))->mozEmbed), url);
00557   
00558   add_autocomplete(url, params);
00559 }
00560 
00561 static void new_window_orphan_cb(GtkMozEmbedSingle *embed,
00562                                  GtkMozEmbed **retval, guint chromemask,
00563                                  gpointer data)
00564 {
00565   MinimoBrowser *newBrowser = new_gtk_browser(chromemask);
00566   *retval = GTK_MOZ_EMBED(newBrowser->mozEmbed);
00567 }
00568 
00569 /* METHODS THAT CREATE DIALOG FOR SPECIFICS TASK */
00570 static void create_open_dialog(MinimoBrowser* browser)
00571 {
00572   if (!browser) {
00573     quick_message("Creating the open dialog failed.");
00574     return;
00575   }
00576   
00577   GtkWidget *dialog;
00578   GtkWidget *dialog_vbox;
00579   GtkWidget *dialog_vbox2;
00580   GtkWidget *dialog_label;
00581   GtkWidget *dialog_comboentry;
00582   GtkWidget *dialog_area;
00583   GtkWidget *cancelbutton;
00584   GtkWidget *okbutton;
00585   GtkWidget *dialog_combo;
00586   GtkEntry *dialog_entry;
00587   
00588   dialog = gtk_dialog_new();
00589   
00590   gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(browser->topLevelWindow));
00591   
00592   /* set the position of this dialog immeditate below the toolbar */
00593   
00594   gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT);
00595   gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
00596   gtk_window_set_default_size(GTK_WINDOW(dialog), 320, 100);
00597   gtk_window_set_decorated (GTK_WINDOW (dialog), TRUE);
00598   gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE);
00599   gtk_window_set_skip_taskbar_hint(GTK_WINDOW(dialog), TRUE);
00600   gtk_window_set_skip_pager_hint(GTK_WINDOW(dialog), TRUE);
00601   gtk_window_set_type_hint(GTK_WINDOW(dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00602   
00603   gtk_window_set_title(GTK_WINDOW (dialog), "Open Dialog");
00604   
00605   dialog_vbox = GTK_DIALOG(dialog)->vbox;
00606   gtk_widget_show(dialog_vbox);
00607   
00608   dialog_vbox2 = gtk_vbox_new(FALSE, 0);
00609   gtk_widget_show(dialog_vbox2);
00610   gtk_box_pack_start(GTK_BOX (dialog_vbox), dialog_vbox2, TRUE, TRUE, 0);
00611   
00612   dialog_label = gtk_label_new("Enter a url:");
00613   gtk_widget_modify_font(dialog_label, getOrCreateDefaultMinimoFont());
00614   gtk_widget_show(dialog_label);
00615   gtk_box_pack_start(GTK_BOX (dialog_vbox2), dialog_label, FALSE, FALSE, 0);
00616   
00617   dialog_comboentry = gtk_combo_box_entry_new_text ();
00618   
00619   dialog_combo = gtk_combo_new ();
00620   dialog_entry = GTK_ENTRY (GTK_COMBO (dialog_combo)->entry);
00621   gtk_widget_modify_font(GTK_COMBO (dialog_combo)->entry, getOrCreateDefaultMinimoFont());
00622   gtk_widget_show(dialog_combo);
00623   gtk_box_pack_start(GTK_BOX (dialog_vbox2), dialog_combo, TRUE, TRUE, 0);
00624   
00625   populate_autocomplete((GtkCombo*) dialog_combo);
00626   
00627   /* setting up entry completion */
00628   build_entry_completion (browser);
00629   gtk_entry_set_completion (dialog_entry, gMinimoEntryCompletion);
00630   g_object_unref (gMinimoEntryCompletion);
00631   
00632   dialog_area = GTK_DIALOG(dialog)->action_area;
00633   gtk_widget_show(dialog_area);
00634   gtk_button_box_set_layout(GTK_BUTTON_BOX (dialog_area), GTK_BUTTONBOX_END);
00635   
00636   cancelbutton = gtk_button_new_with_label("Cancel");
00637   gtk_widget_modify_font(GTK_BIN(cancelbutton)->child, getOrCreateDefaultMinimoFont());
00638   gtk_widget_show(cancelbutton);
00639   gtk_dialog_add_action_widget(GTK_DIALOG (dialog), cancelbutton, GTK_RESPONSE_CANCEL);
00640   GTK_WIDGET_SET_FLAGS(cancelbutton, GTK_CAN_DEFAULT);
00641   
00642   okbutton = gtk_button_new_with_label("OK");
00643   gtk_widget_modify_font(GTK_BIN(okbutton)->child, getOrCreateDefaultMinimoFont());
00644   gtk_widget_show(okbutton);
00645   gtk_dialog_add_action_widget(GTK_DIALOG (dialog), okbutton, GTK_RESPONSE_OK);
00646   GTK_WIDGET_SET_FLAGS(okbutton, GTK_CAN_DEFAULT);
00647   
00648   OpenDialogParams* dialogParams = (OpenDialogParams*) malloc(sizeof(OpenDialogParams));
00649   
00650   dialogParams->dialog_combo = dialog_combo;
00651   (MinimoBrowser *)(dialogParams->main_combo) = browser;
00652   
00653   g_signal_connect (GTK_OBJECT (okbutton), "clicked", G_CALLBACK (open_dialog_ok_cb), dialogParams);
00654   g_signal_connect (GTK_OBJECT (GTK_COMBO (dialog_combo)->entry), "activate",G_CALLBACK (open_dialog_ok_cb), dialogParams);
00655   g_signal_connect_swapped(GTK_OBJECT(okbutton), "clicked", G_CALLBACK(gtk_widget_destroy), dialog);
00656   g_signal_connect_swapped(GTK_OBJECT(GTK_COMBO (dialog_combo)->entry), "activate", G_CALLBACK(gtk_widget_destroy), dialog);
00657   
00658   g_signal_connect_swapped(GTK_OBJECT(cancelbutton), "clicked", G_CALLBACK(gtk_widget_destroy), dialog);
00659   g_signal_connect(GTK_OBJECT(dialog), "destroy", G_CALLBACK(destroy_dialog_params_cb), dialogParams);
00660   
00661   gtk_widget_show_all(dialog);
00662 }
00663 
00664 
00665 void create_info_dialog (MinimoBrowser* browser)
00666 {
00667   if (!browser) {
00668     quick_message("Creating the info dialog failed.");
00669     return;
00670   }
00671   
00672   char* titleString    = gtk_moz_embed_get_title((GtkMozEmbed*)browser->mozEmbed);
00673   char* locationString = gtk_moz_embed_get_location((GtkMozEmbed*)browser->mozEmbed);
00674   
00675   // first extract all of the interesting info out of the browser
00676   // object.  
00677   GtkWidget *InfoDialog;
00678   GtkWidget *dialog_vbox5;
00679   GtkWidget *vbox4;
00680   GtkWidget *frame1;
00681   GtkWidget *table2;
00682   GtkWidget *URL;
00683   GtkWidget *Type;
00684   GtkWidget *RenderMode;
00685   GtkWidget *Encoding;
00686   GtkWidget *Size;
00687   GtkWidget *TypeEntry;
00688   GtkWidget *URLEntry;
00689   GtkWidget *ModeEntry;
00690   GtkWidget *SizeEntry;
00691   GtkWidget *PageTitle;
00692   GtkWidget *frame2;
00693   GtkWidget *SecurityText;
00694   GtkWidget *label10;
00695   GtkWidget *dialog_action_area5;
00696   GtkWidget *closebutton1;
00697   
00698   InfoDialog = gtk_dialog_new ();
00699   gtk_widget_set_size_request (InfoDialog, 240, 320);
00700   gtk_window_set_title (GTK_WINDOW (InfoDialog), ("Page Info"));
00701   gtk_window_set_position (GTK_WINDOW (InfoDialog), GTK_WIN_POS_CENTER_ON_PARENT);
00702   gtk_window_set_modal (GTK_WINDOW (InfoDialog), TRUE);
00703   gtk_window_set_default_size (GTK_WINDOW (InfoDialog), 240, 320);
00704   gtk_window_set_resizable (GTK_WINDOW (InfoDialog), FALSE);
00705   gtk_window_set_decorated (GTK_WINDOW (InfoDialog), TRUE);
00706   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (InfoDialog), TRUE);
00707   gtk_window_set_skip_pager_hint (GTK_WINDOW (InfoDialog), TRUE);
00708   gtk_window_set_type_hint (GTK_WINDOW (InfoDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00709   gtk_window_set_gravity (GTK_WINDOW (InfoDialog), GDK_GRAVITY_NORTH_EAST);
00710   gtk_window_set_transient_for(GTK_WINDOW(InfoDialog), GTK_WINDOW(browser->topLevelWindow));
00711   
00712   dialog_vbox5 = GTK_DIALOG (InfoDialog)->vbox;
00713   gtk_widget_show (dialog_vbox5);
00714   
00715   vbox4 = gtk_vbox_new (FALSE, 0);
00716   gtk_widget_show (vbox4);
00717   gtk_box_pack_start (GTK_BOX (dialog_vbox5), vbox4, TRUE, TRUE, 0);
00718   
00719   frame1 = gtk_frame_new (NULL);
00720   gtk_widget_show (frame1);
00721   gtk_box_pack_start (GTK_BOX (vbox4), frame1, TRUE, TRUE, 0);
00722   
00723   table2 = gtk_table_new (5, 2, FALSE);
00724   gtk_widget_show (table2);
00725   gtk_container_add (GTK_CONTAINER (frame1), table2);
00726   gtk_widget_set_size_request (table2, 240, -1);
00727   gtk_container_set_border_width (GTK_CONTAINER (table2), 2);
00728   gtk_table_set_row_spacings (GTK_TABLE (table2), 1);
00729   gtk_table_set_col_spacings (GTK_TABLE (table2), 10);
00730   
00731   URL = gtk_label_new (("URL:"));
00732   gtk_widget_modify_font(URL, getOrCreateDefaultMinimoFont());
00733   gtk_widget_show (URL);
00734   gtk_table_attach (GTK_TABLE (table2), URL, 0, 1, 0, 1,
00735                     (GtkAttachOptions) (GTK_FILL),
00736                     (GtkAttachOptions) (0), 0, 0);
00737   gtk_misc_set_alignment (GTK_MISC (URL), 0, 0.5);
00738   
00739   Type = gtk_label_new (("Type:"));
00740   gtk_widget_modify_font(Type, getOrCreateDefaultMinimoFont());
00741   gtk_widget_show (Type);
00742   gtk_table_attach (GTK_TABLE (table2), Type, 0, 1, 1, 2,
00743                     (GtkAttachOptions) (GTK_FILL),
00744                     (GtkAttachOptions) (0), 0, 0);
00745   gtk_misc_set_alignment (GTK_MISC (Type), 0, 0.5);
00746   
00747   RenderMode = gtk_label_new (("Mode:"));
00748   gtk_widget_modify_font(RenderMode, getOrCreateDefaultMinimoFont());
00749   gtk_widget_show (RenderMode);
00750   gtk_table_attach (GTK_TABLE (table2), RenderMode, 0, 1, 2, 3,
00751                     (GtkAttachOptions) (GTK_FILL),
00752                     (GtkAttachOptions) (0), 0, 0);
00753   gtk_misc_set_alignment (GTK_MISC (RenderMode), 0, 0.5);
00754   
00755   Encoding = gtk_label_new (("Encoding:"));
00756   gtk_widget_modify_font(Encoding, getOrCreateDefaultMinimoFont());
00757   gtk_widget_show (Encoding);
00758   gtk_table_attach (GTK_TABLE (table2), Encoding, 0, 1, 3, 4,
00759                     (GtkAttachOptions) (GTK_FILL),
00760                     (GtkAttachOptions) (0), 0, 0);
00761   gtk_misc_set_alignment (GTK_MISC (Encoding), 0, 0.5);
00762   
00763   Size = gtk_label_new (("Size:"));
00764   gtk_widget_modify_font(Size, getOrCreateDefaultMinimoFont());
00765   gtk_widget_show (Size);
00766   gtk_table_attach (GTK_TABLE (table2), Size, 0, 1, 4, 5,
00767                     (GtkAttachOptions) (GTK_FILL),
00768                     (GtkAttachOptions) (0), 0, 0);
00769   gtk_misc_set_alignment (GTK_MISC (Size), 0, 0.5);
00770   
00771   TypeEntry = gtk_entry_new ();
00772   gtk_widget_modify_font(TypeEntry, getOrCreateDefaultMinimoFont());
00773   gtk_widget_show (TypeEntry);
00774   gtk_table_attach (GTK_TABLE (table2), TypeEntry, 1, 2, 1, 2,
00775                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
00776                     (GtkAttachOptions) (0), 0, 0);
00777   gtk_editable_set_editable (GTK_EDITABLE (TypeEntry), FALSE);
00778   gtk_entry_set_has_frame (GTK_ENTRY (TypeEntry), FALSE);
00779   
00780   URLEntry = gtk_entry_new ();
00781   gtk_widget_modify_font(URLEntry, getOrCreateDefaultMinimoFont());
00782   
00783   gtk_entry_set_text(GTK_ENTRY(URLEntry), locationString);
00784   
00785   gtk_widget_show (URLEntry);
00786   gtk_table_attach (GTK_TABLE (table2), URLEntry, 1, 2, 0, 1,
00787                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
00788                     (GtkAttachOptions) (0), 0, 0);
00789   gtk_editable_set_editable (GTK_EDITABLE (URLEntry), FALSE);
00790   gtk_entry_set_has_frame (GTK_ENTRY (URLEntry), FALSE);
00791   
00792   ModeEntry = gtk_entry_new ();
00793   gtk_widget_modify_font(ModeEntry, getOrCreateDefaultMinimoFont());
00794   gtk_widget_show (ModeEntry);
00795   gtk_table_attach (GTK_TABLE (table2), ModeEntry, 1, 2, 2, 3,
00796                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
00797                     (GtkAttachOptions) (0), 0, 0);
00798   gtk_editable_set_editable (GTK_EDITABLE (ModeEntry), FALSE);
00799   gtk_entry_set_has_frame (GTK_ENTRY (ModeEntry), FALSE);
00800   
00801   Encoding = gtk_entry_new ();
00802   gtk_widget_modify_font(Encoding, getOrCreateDefaultMinimoFont());
00803   gtk_widget_show (Encoding);
00804   gtk_table_attach (GTK_TABLE (table2), Encoding, 1, 2, 3, 4,
00805                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
00806                     (GtkAttachOptions) (0), 0, 0);
00807   gtk_editable_set_editable (GTK_EDITABLE (Encoding), FALSE);
00808   gtk_entry_set_has_frame (GTK_ENTRY (Encoding), FALSE);
00809   
00810   SizeEntry = gtk_entry_new ();
00811   gtk_widget_modify_font(SizeEntry, getOrCreateDefaultMinimoFont());
00812   gtk_widget_show (SizeEntry);
00813   gtk_table_attach (GTK_TABLE (table2), SizeEntry, 1, 2, 4, 5,
00814                     (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
00815                     (GtkAttachOptions) (0), 0, 0);
00816   gtk_editable_set_editable (GTK_EDITABLE (SizeEntry), FALSE);
00817   gtk_entry_set_has_frame (GTK_ENTRY (SizeEntry), FALSE);
00818   
00819   
00820   char buffer[50];
00821   sprintf(buffer, "%d bytes", browser->totalBytes);
00822   gtk_entry_set_text(GTK_ENTRY(SizeEntry), buffer);
00823   
00824   PageTitle = gtk_label_new ("");
00825   gtk_widget_modify_font(PageTitle, getOrCreateDefaultMinimoFont());
00826   
00827   if (titleString)
00828        gtk_label_set_text(GTK_LABEL(PageTitle), titleString);
00829   else
00830        gtk_label_set_text(GTK_LABEL(PageTitle), "Untitled Page");
00831   
00832   gtk_widget_show (PageTitle);
00833   gtk_frame_set_label_widget (GTK_FRAME (frame1), PageTitle);
00834   
00835   frame2 = gtk_frame_new (NULL);
00836   gtk_widget_show (frame2);
00837   gtk_box_pack_start (GTK_BOX (vbox4), frame2, TRUE, TRUE, 0);
00838   
00839   SecurityText = gtk_label_new ("");
00840   gtk_widget_modify_font(SecurityText, getOrCreateDefaultMinimoFont());
00841   gtk_widget_show (SecurityText);
00842   gtk_container_add (GTK_CONTAINER (frame2), SecurityText);
00843   
00844   label10 = gtk_label_new (("Security Information"));
00845   gtk_widget_modify_font(label10, getOrCreateDefaultMinimoFont());
00846   gtk_widget_show (label10);
00847   gtk_frame_set_label_widget (GTK_FRAME (frame2), label10);
00848   
00849   dialog_action_area5 = GTK_DIALOG (InfoDialog)->action_area;
00850   gtk_widget_show (dialog_action_area5);
00851   gtk_button_box_set_layout (GTK_BUTTON_BOX (dialog_action_area5), GTK_BUTTONBOX_END);
00852   
00853   closebutton1 = gtk_button_new_with_label("Close");
00854   gtk_widget_modify_font(GTK_BIN(closebutton1)->child, getOrCreateDefaultMinimoFont());
00855   gtk_widget_show (closebutton1);
00856   gtk_dialog_add_action_widget (GTK_DIALOG (InfoDialog), closebutton1, GTK_RESPONSE_CLOSE);
00857   GTK_WIDGET_SET_FLAGS (closebutton1, GTK_CAN_DEFAULT);
00858   
00859   g_signal_connect_swapped(GTK_OBJECT(closebutton1), "clicked", G_CALLBACK(gtk_widget_destroy), InfoDialog);
00860   
00861   gtk_widget_show_all(InfoDialog);
00862   
00863   free(titleString);
00864   free(locationString);
00865 }
00866 
00867 /* method to enable find a substring in the embed */
00868 void
00869 create_find_dialog (GtkWidget *w, MinimoBrowser *browser) {
00870   
00871   GtkWidget *window, *hbox, *entry, *label, *button, *ignore_case, *vbox_l, *hbox_tog;
00872   GList *glist = NULL;
00873   
00874   if (gMinimoLastFind) 
00875     glist = g_list_append(glist, gMinimoLastFind);
00876   
00877   window = gtk_dialog_new();
00878   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ON_PARENT);
00879   gtk_window_set_modal (GTK_WINDOW (window), TRUE);
00880   gtk_window_set_keep_above(GTK_WINDOW (window), TRUE);
00881   gtk_widget_set_size_request (window, 230, 110);
00882   gtk_window_set_resizable(GTK_WINDOW (window),FALSE);
00883   gtk_window_set_title (GTK_WINDOW(window), "Find");
00884   setup_escape_key_handler(window);
00885   
00886   g_object_set_data(G_OBJECT(window), "Minimo", browser);
00887   g_object_set_data(G_OBJECT(window), "Embed", browser->mozEmbed);
00888   
00889   hbox = gtk_hbox_new (FALSE, 0);
00890   hbox_tog = gtk_hbox_new(FALSE, 0);
00891   vbox_l = gtk_vbox_new(FALSE, 0);
00892   gtk_container_set_border_width (GTK_CONTAINER(hbox), 4);
00893   
00894   label = gtk_label_new ("Find: ");
00895   gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
00896   
00897   entry = gtk_combo_new ();
00898   gtk_combo_disable_activate(GTK_COMBO(entry));
00899   gtk_combo_set_case_sensitive(GTK_COMBO(entry), TRUE);
00900   if (gMinimoLastFind) 
00901     gtk_combo_set_popdown_strings(GTK_COMBO(entry),glist);
00902   gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(entry)->entry), "");
00903   g_object_set_data(G_OBJECT(window), "entry", entry);
00904   g_signal_connect(G_OBJECT(GTK_COMBO(entry)->entry), "activate", G_CALLBACK(find_dialog_ok_cb), window);
00905   gtk_box_pack_start (GTK_BOX(hbox), entry, FALSE, FALSE, 0);
00906   
00907   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), hbox, FALSE, FALSE, 0);
00908   
00909   ignore_case = gtk_check_button_new_with_label ("Ignore case");
00910   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ignore_case), TRUE);
00911   g_object_set_data(G_OBJECT(window), "ignore_case", ignore_case);
00912   gtk_box_pack_start(GTK_BOX(vbox_l), ignore_case, FALSE, FALSE, 0);
00913   
00914   gtk_box_pack_start(GTK_BOX(hbox_tog), vbox_l, FALSE, FALSE, 0);
00915   
00916   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), hbox_tog, FALSE, FALSE, 0);
00917   
00918   button = gtk_button_new_from_stock (GTK_STOCK_FIND);
00919   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(window)->action_area), button, FALSE, FALSE, 0);
00920   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(find_dialog_ok_cb), window);
00921   
00922   button = gtk_button_new_from_stock (GTK_STOCK_CLOSE);
00923   gtk_box_pack_start (GTK_BOX(GTK_DIALOG(window)->action_area), button, FALSE, FALSE, 0);
00924   g_signal_connect_swapped(G_OBJECT(button), "clicked", G_CALLBACK(gtk_widget_destroy),
00925                            (gpointer)window);
00926   
00927   gtk_widget_show_all (window);
00928   gtk_widget_grab_focus (entry);
00929 }
00930 
00931 /* Method that create the "Open From File .." Dialog */
00932 static void
00933 create_open_document_from_file (GtkMenuItem *button, MinimoBrowser *browser) {
00934   
00935   GtkWidget *fs, *ok_button, *cancel_button, *hbox;
00936   GtkWidget *OpenFromFileDialog, *scrolled_window;
00937   
00938   G_CONST_RETURN gchar *location = NULL, *file_name = NULL;
00939   
00940   g_return_if_fail(browser->mozEmbed != NULL);
00941   
00942   location = gtk_moz_embed_get_location(GTK_MOZ_EMBED (browser->mozEmbed));
00943   if (location) 
00944     file_name = g_basename(location);
00945   
00946   fs = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
00947   
00948   OpenFromFileDialog = gtk_dialog_new ();
00949   gtk_widget_set_size_request (OpenFromFileDialog, 240, 320);
00950   gtk_window_set_title (GTK_WINDOW (OpenFromFileDialog), ("Open URL From File"));
00951   gtk_window_set_position (GTK_WINDOW (OpenFromFileDialog), GTK_WIN_POS_CENTER_ON_PARENT);
00952   gtk_window_set_modal (GTK_WINDOW (OpenFromFileDialog), TRUE);
00953   gtk_window_set_default_size (GTK_WINDOW (OpenFromFileDialog), 240, 320);
00954   gtk_window_set_resizable (GTK_WINDOW (OpenFromFileDialog), FALSE);
00955   gtk_window_set_decorated (GTK_WINDOW (OpenFromFileDialog), TRUE);
00956   gtk_window_set_skip_taskbar_hint (GTK_WINDOW (OpenFromFileDialog), TRUE);
00957   gtk_window_set_skip_pager_hint (GTK_WINDOW (OpenFromFileDialog), TRUE);
00958   gtk_window_set_type_hint (GTK_WINDOW (OpenFromFileDialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00959   gtk_window_set_gravity (GTK_WINDOW (OpenFromFileDialog), GDK_GRAVITY_NORTH_EAST);
00960   gtk_window_set_transient_for(GTK_WINDOW(OpenFromFileDialog), GTK_WINDOW(browser->topLevelWindow));
00961   
00962   scrolled_window = gtk_scrolled_window_new(NULL,NULL);
00963   gtk_widget_show(scrolled_window);
00964   gtk_box_pack_start(GTK_BOX(GTK_DIALOG (OpenFromFileDialog)->vbox),scrolled_window,TRUE,TRUE,0);
00965   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),GTK_POLICY_AUTOMATIC,GTK_POLICY_AUTOMATIC);
00966   
00967   gtk_scrolled_window_add_with_viewport ( GTK_SCROLLED_WINDOW (scrolled_window) ,fs);
00968   
00969   g_object_set_data(G_OBJECT(fs), "minimo", browser);
00970   g_object_set_data(G_OBJECT(fs), "open_dialog", OpenFromFileDialog);
00971   
00972   /* adding extra button into the widget -> 'Ok and Cancel' Button */
00973   ok_button = gtk_button_new_with_label ("Ok");
00974   gtk_widget_modify_font(GTK_BIN(ok_button)->child, getOrCreateDefaultMinimoFont());
00975   
00976   cancel_button = gtk_button_new_with_label ("Cancel");
00977   gtk_widget_modify_font(GTK_BIN(cancel_button)->child, getOrCreateDefaultMinimoFont());
00978   
00979   hbox = gtk_hbox_new(FALSE, 10);
00980   gtk_box_pack_start(GTK_BOX (hbox), ok_button, FALSE, TRUE, 10);
00981   gtk_box_pack_start(GTK_BOX (hbox), cancel_button, FALSE, TRUE, 10);
00982   gtk_widget_show_all (hbox);
00983   
00984   gtk_file_chooser_set_extra_widget ( GTK_FILE_CHOOSER (fs), GTK_WIDGET (hbox));
00985   
00986   /* connecting callbacks into the extra buttons */
00987   g_signal_connect(G_OBJECT(ok_button), "clicked", G_CALLBACK(on_open_ok_cb), fs);
00988   g_signal_connect_swapped(G_OBJECT(cancel_button), "clicked", G_CALLBACK(gtk_widget_destroy), (gpointer) OpenFromFileDialog         );
00989   
00990   gtk_widget_show(fs);
00991   gtk_widget_show_all(OpenFromFileDialog);
00992   
00993   return;
00994 }
00995 
00996 void increase_font_size_cb (GtkMenuItem *button, MinimoBrowser *browser) {   
00997   
00998   char tmpstr[128];
00999   
01000   gPreferenceConfigStruct.current_font_size += 3;
01001   
01002   g_snprintf (tmpstr, 1024, "font.size.variable.%s", lang_font_item[0]);
01003   mozilla_preference_set_int(tmpstr,gPreferenceConfigStruct.current_font_size);
01004   g_snprintf(tmpstr, 1024, "font.min-size.variable.%s", lang_font_item[0]);
01005   mozilla_preference_set_int(tmpstr, gPreferenceConfigStruct.current_font_size);
01006   
01007   fprintf(stderr, "increasing %d\n", gPreferenceConfigStruct.current_font_size);
01008 }
01009 
01010 /* Method that decrease the Minimo's font size */
01011 static 
01012 void decrease_font_size_cb (GtkMenuItem *button, MinimoBrowser *browser) {
01013   
01014   char tmpstr[128];
01015   
01016   gPreferenceConfigStruct.current_font_size -= 3;
01017   
01018   g_snprintf (tmpstr, 1024, "font.size.variable.%s", lang_font_item[0]);
01019   mozilla_preference_set_int(tmpstr,gPreferenceConfigStruct.current_font_size);
01020   g_snprintf(tmpstr, 1024, "font.min-size.variable.%s", lang_font_item[0]);
01021   mozilla_preference_set_int(tmpstr, gPreferenceConfigStruct.current_font_size);
01022   
01023   fprintf(stderr, "decreasing %d\n", gPreferenceConfigStruct.current_font_size);
01024 }
01025 
01026 /* Method that show the "Full Screen" Minimo's Mode */
01027 static void full_screen_cb (GtkMenuItem *button, MinimoBrowser* browser) {
01028   
01029   gtk_window_fullscreen (GTK_WINDOW (browser->topLevelWindow));
01030   g_signal_connect (GTK_OBJECT (button), "activate", G_CALLBACK(unfull_screen_cb), browser);
01031   gtk_tooltips_set_tip (gtk_tooltips_new (), GTK_WIDGET (button), "UnFull Screen", NULL);
01032 }
01033 
01034 /* Method that show the "Normal Screen" Minimo's Mode */
01035 static void unfull_screen_cb (GtkMenuItem *button, MinimoBrowser* browser) {
01036   
01037   gtk_window_unfullscreen (GTK_WINDOW (browser->topLevelWindow));
01038   g_signal_connect (GTK_OBJECT (button), "activate", G_CALLBACK(full_screen_cb), browser);  
01039   gtk_tooltips_set_tip (gtk_tooltips_new (), GTK_WIDGET (button), "Full Screen", NULL);
01040 }
01041 
01042 /* Method that show History Window */
01043 static void open_history_window (GtkButton *button, MinimoBrowser* browser){
01044   view_history(browser->mozEmbed);
01045 }
01046 
01047 /* METHODS TO MANIPULATE TABS */
01048 static GtkWidget *get_active_tab (MinimoBrowser *browser)
01049 {
01050   GtkWidget *active_page;
01051   gint current_page;
01052   
01053   current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (browser->notebook));
01054   active_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), current_page);
01055   
01056   return active_page;
01057 }
01058 
01059 static void switch_page_cb (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, MinimoBrowser *browser)
01060 {
01061   browser->active_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (browser->notebook), page_num);
01062   browser->mozEmbed = browser->active_page;
01063   update_ui (browser);
01064   initialize_bookmark(browser->mozEmbed);
01065 }
01066 
01067 static void show_hide_tabs_cb (GtkMenuItem *button, MinimoBrowser *browser)
01068 {
01069   if (browser->show_tabs) {
01070     gtk_notebook_set_show_tabs (GTK_NOTEBOOK(browser->notebook), FALSE);
01071     browser->show_tabs = FALSE;
01072   }
01073   else {
01074     gtk_notebook_set_show_tabs (GTK_NOTEBOOK(browser->notebook), TRUE);
01075     browser->show_tabs = TRUE;
01076   }
01077 }
01078 
01079 /* CALLBACKS METHODS ... */
01080 
01081 static void on_open_ok_cb (GtkWidget *button, GtkWidget *fs) {
01082   MinimoBrowser *browser = NULL;
01083   G_CONST_RETURN gchar *filename;
01084   gchar *converted;
01085   
01086   filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fs));
01087   
01088   if (!filename || !strcmp(filename,"")) {
01089        
01090     return ;
01091   } else {
01092        
01093     converted = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
01094     
01095     browser = (MinimoBrowser *) g_object_get_data(G_OBJECT(fs), "minimo");
01096        
01097     if (converted != NULL) {
01098       
01099       gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser->mozEmbed), converted);
01100       gtk_widget_grab_focus (GTK_WIDGET(browser->mozEmbed));
01101     }
01102     
01103     g_free (converted);
01104     g_free ((void *) filename);
01105     gtk_widget_destroy((GtkWidget *) g_object_get_data(G_OBJECT(fs), "open_dialog"));
01106   }
01107   return ;
01108 }
01109 
01110 static void find_dialog_ok_cb (GtkWidget *w, GtkWidget *window)
01111 {
01112   
01113   GtkWidget *entry = (GtkWidget *)g_object_get_data(G_OBJECT(window), "entry");
01114   
01115 #define       GET_FIND_OPTION(window, name)      \
01116               gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g_object_get_data(G_OBJECT(window), name)))
01117   
01118   gMinimoBrowser->didFind = mozilla_find( GTK_MOZ_EMBED (gMinimoBrowser->mozEmbed),
01119                                           gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(entry)->entry)),
01120                                           !GET_FIND_OPTION(window, "ignore_case"),
01121                                           FALSE, //GET_FIND_OPTION(window, "backwards"),
01122                                           TRUE, //GET_FIND_OPTION(window, "auto_wrap"),
01123                                           FALSE, //GET_FIND_OPTION(window, "entire_word"),
01124                                           TRUE, //GET_FIND_OPTION(window, "in_frame"),
01125                                           FALSE);
01126   
01127   //if (!browser->didFind) create_dialog("Find Results", "Expression was not found!", 0, 1);
01128   if (gMinimoLastFind) g_free(gMinimoLastFind);
01129   gMinimoLastFind = g_strdup(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(entry)->entry)));
01130 }
01131 
01132 void
01133 destroy_cb(GtkWidget *widget, MinimoBrowser *browser)
01134 {
01135   GList *tmp_list;
01136   gMinimoNumBrowsers--;
01137   tmp_list = g_list_find(gMinimoBrowserList, browser);
01138   gMinimoBrowserList = g_list_remove_link(gMinimoBrowserList, tmp_list);
01139   
01140   if (gMinimoNumBrowsers == 0)  
01141     gtk_main_quit();
01142 }
01143 
01144 /* OTHERS METHODS */
01145 
01146 static void update_ui (MinimoBrowser *browser)
01147 {
01148   gchar *tmp;
01149   int x=0;
01150   char *url;
01151   
01152   tmp = gtk_moz_embed_get_title (GTK_MOZ_EMBED (browser->active_page));
01153   
01154   if (tmp)
01155     x = strlen (tmp);
01156   if (x == 0)
01157     tmp = "Minimo";
01158   gtk_window_set_title (GTK_WINDOW(browser->topLevelWindow), tmp);
01159   url = gtk_moz_embed_get_location (GTK_MOZ_EMBED (browser->active_page));
01160   
01161   browser->progressPopup = create_minimo_progress(browser);
01162   
01163 }
01164 
01165 /* Method that build the entry completion */
01166 void build_entry_completion (MinimoBrowser* browser) 
01167 {  
01168   /* Minimo entry completion */
01169   gMinimoEntryCompletion = gtk_entry_completion_new ();
01170   
01171   gtk_entry_completion_set_model (gMinimoEntryCompletion, GTK_TREE_MODEL (gMinimoAutoCompleteListStore));
01172   gtk_entry_completion_set_text_column (gMinimoEntryCompletion, 0);
01173 }
01174 
01175 /* Method to sep up the escape key handler */
01176 void setup_escape_key_handler(GtkWidget *window) 
01177 {
01178   g_signal_connect(G_OBJECT(window), "key_press_event",
01179                    G_CALLBACK(escape_key_handler), NULL);
01180 }
01181 
01182 /* Method to handler the escape key */
01183 gint escape_key_handler(GtkWidget *window, GdkEventKey *ev) 
01184 {
01185   g_return_val_if_fail(window != NULL, FALSE);
01186   if (ev->keyval == GDK_Escape) {
01187     gtk_widget_destroy(window);
01188     return (1);
01189   }
01190   return (0);
01191 }