Back to index

lightning-sunbird  0.9+nobinonly
minimo_context.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 #include "minimo_context.h"
00051 #include "minimo_callbacks.h"
00052 #include "minimo_bookmark.h"
00053 
00054 void on_menu_destroy(GtkWidget *menu, gchar *name)
00055 {
00056   gchar *free_href, *free_img, *free_linktext, *free_name;
00057   
00058   free_href = (gchar *) g_object_get_data(G_OBJECT(menu), "freehref");
00059   if (free_href) g_free(free_href);
00060   free_img = (gchar *) g_object_get_data(G_OBJECT(menu), "freeimg");
00061   if (free_img) g_free(free_img);
00062   free_linktext = (gchar *) g_object_get_data(G_OBJECT(menu), "freelinktext");
00063   if (free_linktext) g_free(free_linktext);
00064   free_name = (gchar *) g_object_get_data(G_OBJECT(menu), "freename");
00065   if (free_name) g_free(free_name);
00066   return;
00067 }
00068 
00069 GtkWidget * get_link_popup_menu (MinimoBrowser *browser, gchar *href, gchar *linktext)
00070 {
00071   GtkWidget *menu, *m1, *m2, *m3;
00072   
00073   if (browser->link_menu) gtk_widget_destroy(browser->link_menu);
00074   menu = gtk_menu_new();
00075   g_object_set_data(G_OBJECT(menu), "freehref", href);
00076   g_object_set_data(G_OBJECT(menu), "freelinktext", linktext);
00077   
00078   /* Open in this Window */
00079   m1 = gtk_image_menu_item_new_with_mnemonic("_Open link ...");
00080   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m1),
00081                                 gtk_image_new_from_stock(GTK_STOCK_OPEN,GTK_ICON_SIZE_MENU));
00082   g_signal_connect(G_OBJECT(m1), "activate", G_CALLBACK(browse_in_window_from_popup), browser);
00083   g_object_set_data(G_OBJECT(m1), "link", href);
00084   gtk_menu_append(GTK_MENU(menu), m1);
00085   
00086   /* Open in a new Tab */
00087   m2 = gtk_image_menu_item_new_with_mnemonic("Open in a new _tab");
00088   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m2),
00089                                 gtk_image_new_from_stock(GTK_STOCK_NEW,GTK_ICON_SIZE_MENU));
00090   gtk_menu_append(GTK_MENU(menu), m2);
00091   g_object_set_data(G_OBJECT(m2), "link", href);
00092   g_signal_connect(G_OBJECT(m2), "activate", G_CALLBACK(make_tab_from_popup), browser);           
00093   
00094   /* Download link */
00095   m3  = gtk_image_menu_item_new_with_mnemonic("_Save link as ...");
00096   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m3),
00097                                 gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
00098   g_signal_connect(G_OBJECT(m3), "activate", G_CALLBACK(download_link_from_popup), browser);
00099   g_object_set_data(G_OBJECT(m3), "link", href);
00100   gtk_menu_append(GTK_MENU(menu), m3);
00101   
00102   gtk_widget_show_all(menu);
00103   browser->link_menu = menu;
00104   return (menu);
00105   
00106 }
00107 
00108 GtkWidget * get_image_popup_menu(MinimoBrowser *browser, gchar *img)
00109 {
00110   GtkWidget *menu, *m1, *m2, *m3, *m4, *sep;
00111   gchar *lbl, *name, *aux_string;
00112   G_CONST_RETURN gchar *img_basename;
00113   
00114   if (browser->image_menu)
00115     gtk_widget_destroy(browser->image_menu);
00116   
00117   aux_string = (gchar *)g_malloc(1024);
00118   strcpy (aux_string, "");
00119   img_basename = g_basename(img);
00120   name = g_strdup(img_basename);
00121   menu = gtk_menu_new();
00122   g_object_set_data(G_OBJECT(menu), "freeimg", img);
00123   g_object_set_data(G_OBJECT(menu), "freename", name);
00124   
00125   /* View Image */
00126   m1 = gtk_image_menu_item_new_with_mnemonic ("_View image");
00127   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m1),
00128                                 gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
00129   g_signal_connect(G_OBJECT(m1), "activate", G_CALLBACK(browse_in_window_from_popup), browser);
00130   g_object_set_data(G_OBJECT(m1), "link", img);
00131   gtk_menu_append(GTK_MENU(menu), m1);
00132   
00133   /* Separator */
00134   sep = gtk_menu_item_new();
00135   gtk_menu_append(GTK_MENU(menu), sep);
00136   
00137   /* Save as */
00138   m2  = gtk_image_menu_item_new_with_mnemonic ("_Save image as ...");
00139   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m2),
00140                                 gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
00141   g_signal_connect(G_OBJECT(m2), "activate", G_CALLBACK(download_link_from_popup), browser);
00142   g_object_set_data(G_OBJECT(m2), "link", img);
00143   g_object_set_data(G_OBJECT(m2), "name", aux_string);
00144   gtk_menu_append(GTK_MENU(menu), m2);
00145   
00146   /* Save */
00147   lbl = g_strdup_printf("%s %s","Sa_ve image as ",img_basename);
00148   m3  = gtk_image_menu_item_new_with_mnemonic (lbl);
00149   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m3),
00150                                 gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
00151   g_signal_connect(G_OBJECT(m3), "activate", G_CALLBACK(save_image_from_popup), browser);
00152   g_object_set_data(G_OBJECT(m3), "link", img);
00153   g_object_set_data(G_OBJECT(m3), "name", name);
00154   gtk_menu_append(GTK_MENU(menu), m3);
00155   
00156   /* Separator */
00157   sep = gtk_menu_item_new();
00158   gtk_menu_append(GTK_MENU(menu), sep);
00159   
00160   /* Save page as */
00161   m4 = gtk_image_menu_item_new_with_mnemonic("Save page _as ... ");
00162   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m4),
00163                                 gtk_image_new_from_stock(GTK_STOCK_COPY, GTK_ICON_SIZE_MENU));    
00164   g_signal_connect(G_OBJECT(m4), "activate", G_CALLBACK(download_link_from_popup), browser);
00165   g_object_set_data(G_OBJECT(m4), "link", gtk_moz_embed_get_location(GTK_MOZ_EMBED (browser->mozEmbed)));
00166   gtk_menu_append(GTK_MENU(menu), m4);
00167   gtk_widget_show_all(menu);
00168   
00169   gtk_widget_show_all(menu);
00170   
00171   g_free(aux_string);       
00172   g_free(lbl);
00173   
00174   browser->image_menu = menu;
00175   return (menu);
00176 }
00177 
00178 GtkWidget * get_doc_popup_menu(MinimoBrowser *browser, gchar *href)
00179 {
00180   GtkWidget *menu, *m1,*m2,*m3, *m4, *m5, *m6, *sep;
00181   
00182   if (browser->doc_menu) gtk_widget_destroy(browser->doc_menu);
00183   menu = gtk_menu_new();
00184   g_object_set_data(G_OBJECT(menu), "freehref", href);
00185   
00186   m1 =  gtk_image_menu_item_new_from_stock(GTK_STOCK_GO_BACK,NULL);
00187   g_signal_connect(G_OBJECT(m1), "activate", G_CALLBACK(back_clicked_cb), browser);
00188   gtk_widget_set_sensitive(m1, gtk_moz_embed_can_go_back(GTK_MOZ_EMBED(browser->mozEmbed)));
00189   gtk_menu_append(GTK_MENU(menu), m1);
00190   
00191   m2 = gtk_image_menu_item_new_from_stock(GTK_STOCK_GO_FORWARD,NULL);
00192   gtk_menu_append(GTK_MENU(menu), m2);
00193   g_signal_connect(G_OBJECT(m2), "activate", G_CALLBACK(forward_clicked_cb), browser);
00194   gtk_widget_set_sensitive(m2, gtk_moz_embed_can_go_forward(GTK_MOZ_EMBED(browser->mozEmbed)));
00195   
00196   m3  = gtk_image_menu_item_new_from_stock(GTK_STOCK_REFRESH,NULL);     
00197   g_signal_connect(G_OBJECT(m3), "activate", G_CALLBACK(reload_clicked_cb), browser);
00198   gtk_menu_append(GTK_MENU(menu), m3);
00199   
00200   m4 = gtk_image_menu_item_new_from_stock(GTK_STOCK_STOP,NULL);
00201   g_signal_connect(G_OBJECT(m4), "activate", G_CALLBACK(stop_clicked_cb), browser);
00202   gtk_menu_append(GTK_MENU(menu), m4);
00203   
00204   /* Separator */
00205   sep = gtk_menu_item_new();
00206   gtk_menu_append(GTK_MENU(menu), sep);
00207   
00208   m5 = gtk_image_menu_item_new_with_mnemonic ("_Save page as ... ");
00209   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m5),
00210                                 gtk_image_new_from_stock(GTK_STOCK_SAVE, GTK_ICON_SIZE_MENU));
00211   g_signal_connect(G_OBJECT(m5), "activate", G_CALLBACK(download_link_from_popup), browser);
00212   g_object_set_data(G_OBJECT(m5), "link", gtk_moz_embed_get_location(GTK_MOZ_EMBED (browser->mozEmbed)));
00213   gtk_menu_append(GTK_MENU(menu), m5);
00214   
00215   m6 = gtk_image_menu_item_new_with_mnemonic ("_Bookmark this page");
00216   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m6),
00217                                 gtk_image_new_from_stock(GTK_STOCK_ADD, GTK_ICON_SIZE_MENU));
00218   g_signal_connect(G_OBJECT(m6), "activate", G_CALLBACK(add_bookmark_cb), browser);
00219   gtk_menu_append(GTK_MENU(menu), m6);
00220   
00221   gtk_widget_show_all(menu);
00222   browser->doc_menu = menu;
00223   
00224   return ( menu );   
00225 }
00226 
00227 GtkWidget * get_link_image_popup_menu(MinimoBrowser *browser, gchar *img, gchar *href)
00228 {
00229   GtkWidget *menu, *m1, *m2, *m3, *m4, *m5, *sep;
00230   gchar *lbl, *name, *aux_string;
00231   G_CONST_RETURN gchar *img_basename;
00232   
00233   if (browser->image_link_menu) 
00234     gtk_widget_destroy(browser->image_link_menu);
00235   
00236   aux_string= (gchar *)g_malloc(1024);
00237   strcpy (aux_string, "link image menu");
00238   
00239   img_basename = g_basename(img);
00240   menu = gtk_menu_new();
00241   name = g_strdup(img_basename);
00242   g_object_set_data(G_OBJECT(menu), "freehref", href);
00243   g_object_set_data(G_OBJECT(menu), "freeimg", img);
00244   g_object_set_data(G_OBJECT(menu), "freename", name);
00245   g_signal_connect(G_OBJECT(menu), "destroy", G_CALLBACK(on_menu_destroy), aux_string);
00246   
00247   /* Open Link in the current Window */
00248   m1 = gtk_image_menu_item_new_with_mnemonic ("_Open link ...");
00249   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(m1),gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
00250   g_signal_connect(G_OBJECT(m1), "activate", G_CALLBACK(browse_in_window_from_popup), browser);
00251   g_object_set_data(G_OBJECT(m1), "link", href);
00252   gtk_menu_append(GTK_MENU(menu), m1);
00253   
00254   /* Open Link in a new tab */            
00255   m2 = gtk_image_menu_item_new_with_mnemonic ("Open link in a new _Tab");
00256   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM(m2), 
00257                                  gtk_image_new_from_stock(GTK_STOCK_NEW, GTK_ICON_SIZE_MENU));
00258   gtk_menu_append(GTK_MENU(menu), m2);
00259   g_object_set_data(G_OBJECT(m2), "link", href);
00260   g_signal_connect(G_OBJECT(m2), "activate", G_CALLBACK(make_tab_from_popup), browser);
00261   
00262   /* Separator */
00263   sep = gtk_menu_item_new();
00264   gtk_menu_append(GTK_MENU(menu), sep);
00265   
00266   /* View Image */
00267   m3 = gtk_image_menu_item_new_with_mnemonic ("_View image");
00268   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m3),
00269                                 gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_MENU));
00270   g_signal_connect(G_OBJECT(m3), "activate", G_CALLBACK(browse_in_window_from_popup), browser);
00271   g_object_set_data(G_OBJECT(m3), "link", img);       
00272   gtk_menu_append(GTK_MENU(menu), m3);
00273   
00274   /* Separator */
00275   sep = gtk_menu_item_new();
00276   gtk_menu_append(GTK_MENU(menu), sep);
00277   
00278   m4 = gtk_image_menu_item_new_with_mnemonic ("_Save link as ...");
00279   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m4),gtk_image_new_from_stock(GTK_STOCK_SAVE,
00280                                                                                  GTK_ICON_SIZE_MENU));
00281   g_signal_connect(G_OBJECT(m4), "activate", G_CALLBACK(download_link_from_popup), browser);
00282   g_object_set_data(G_OBJECT(m4), "link", href);
00283   gtk_menu_append(GTK_MENU(menu), m4);
00284   
00285   lbl = g_strdup_printf("%s %s","Save image _as ",img_basename);
00286   m5  = gtk_image_menu_item_new_with_mnemonic (lbl);
00287   gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m5),gtk_image_new_from_stock(GTK_STOCK_SAVE,
00288                                                                                  GTK_ICON_SIZE_MENU));
00289   g_signal_connect(G_OBJECT(m5), "activate", G_CALLBACK(save_image_from_popup), browser);
00290   g_object_set_data(G_OBJECT(m5), "link", img);
00291   g_object_set_data(G_OBJECT(m5), "name", name);
00292   gtk_menu_append(GTK_MENU(menu), m5);
00293   
00294   gtk_widget_show_all(menu);
00295   browser->image_link_menu = menu;
00296   
00297   g_free(aux_string);
00298   
00299   return ( menu );
00300 }
00301