Diff of /trunk/src/html.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by harbaum, Sat Jun 20 11:08:47 2009 UTC revision 229 by harbaum, Fri Dec 4 19:58:26 2009 UTC
# Line 18  Line 18 
18   */   */
19    
20  #include "gpxview.h"  #include "gpxview.h"
21    #include <hildon/hildon-banner.h>
22    
23  typedef struct load_context {  typedef struct load_context {
24    int active;    int active;
# Line 178  static void on_request_url(GtkHTML *html Line 179  static void on_request_url(GtkHTML *html
179        fclose(f);        fclose(f);
180    
181      } else {      } else {
182        if(context->appdata->load_images) {        printf("image file doesn't exist, starting extra thread!\n");
         printf("image file doesn't exist, starting extra thread!\n");  
183    
184          checkdir(path);        checkdir(path);
185    
186          /* walk to end of list */        /* walk to end of list */
187          load_context_t **load_context = &(context->load_context);        load_context_t **load_context = &(context->load_context);
188          while(*load_context)        while(*load_context)
189            load_context = &(*load_context)->next;          load_context = &(*load_context)->next;
190    
191          *load_context = g_new0(load_context_t, 1);        *load_context = g_new0(load_context_t, 1);
192    
193          (*load_context)->url = strdup(url);        (*load_context)->url = strdup(url);
194          (*load_context)->path = strdup(path);        (*load_context)->path = strdup(path);
195          (*load_context)->view = context->view;        (*load_context)->view = context->view;
196          (*load_context)->stream = stream;        (*load_context)->stream = stream;
197          (*load_context)->next = NULL;        (*load_context)->next = NULL;
198          (*load_context)->active = TRUE;        (*load_context)->active = TRUE;
199          (*load_context)->mutex = g_mutex_new();        (*load_context)->mutex = g_mutex_new();
200    
201          g_thread_create(loader_thread, *load_context, TRUE, NULL);        g_thread_create(loader_thread, *load_context, TRUE, NULL);
202          return;        return;
       } else  
         g_print("Image loading disabled\n");  
203      }      }
204    } else {    } else {
205      /* not a cache, maybe help, so load images from icon directory */      /* not a cache, maybe help, so load images from icon directory */
# Line 247  void html_zoom(appdata_t *appdata, gbool Line 245  void html_zoom(appdata_t *appdata, gbool
245    }    }
246  }  }
247    
248    #ifndef NO_COPY_N_PASTE
249  static void on_destroy_textview(GtkWidget *widget, gpointer data) {  static void on_destroy_textview(GtkWidget *widget, gpointer data) {
250    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
251    int destroy_active = FALSE;    int destroy_active = FALSE;
# Line 284  static void on_destroy_textview(GtkWidge Line 283  static void on_destroy_textview(GtkWidge
283      gtk_widget_set_sensitive(appdata->menu_paste, FALSE);      gtk_widget_set_sensitive(appdata->menu_paste, FALSE);
284    }    }
285  }  }
286    #endif
287    
288  static void on_destroy_htmlview(GtkWidget *widget, gpointer data) {  static void on_destroy_htmlview(GtkWidget *widget, gpointer data) {
289    http_context_t *context = (http_context_t*)data;    http_context_t *context = (http_context_t*)data;
# Line 312  static void on_destroy_htmlview(GtkWidge Line 312  static void on_destroy_htmlview(GtkWidge
312      load_context = tmp_context;      load_context = tmp_context;
313    }    }
314    
315    #ifndef NO_COPY_N_PASTE
316    on_destroy_textview(widget, context->appdata);    on_destroy_textview(widget, context->appdata);
317    #endif
318    
319    /* destroy context */    /* destroy context */
320    free(data);    free(data);
321  }  }
322    
323    #ifndef NO_COPY_N_PASTE
324  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,  static gboolean focus_in(GtkWidget *widget, GdkEventFocus *event,
325                           gpointer data) {                           gpointer data) {
326    appdata_t *appdata = (appdata_t*)data;    appdata_t *appdata = (appdata_t*)data;
# Line 343  static gboolean focus_in(GtkWidget *widg Line 346  static gboolean focus_in(GtkWidget *widg
346  void html_copy_to_clipboard(appdata_t *appdata) {  void html_copy_to_clipboard(appdata_t *appdata) {
347    gtk_html_copy(GTK_HTML(appdata->active_buffer));    gtk_html_copy(GTK_HTML(appdata->active_buffer));
348  }  }
349    #endif
 /* panning a gtkhtml view currently doesn't work well */  
 #undef PANNABLE_HTML  
350    
351  #ifdef PANNABLE_HTML  #ifdef PANNABLE_HTML
352  /* eat the button events */  static void
353  static gboolean on_button_press(GtkWidget *widget, GdkEventButton *event,  tap_and_hold_cb (GtkWidget *widget, gpointer user_data) {
354                                  gpointer user_data) {    appdata_t *appdata = (appdata_t*)user_data;
355    return TRUE;  
356      printf("Tap n hold\n");
357      hildon_banner_show_information(GTK_WIDGET(appdata->window), NULL, "Tap n hold");
358  }  }
359  #endif  #endif
360    
# Line 362  static const char *html_start = "<html>< Line 365  static const char *html_start = "<html><
365  static const char *html_end = "</body></html>";  static const char *html_end = "</body></html>";
366    
367  GtkWidget *html_view(appdata_t *appdata, char *text,  GtkWidget *html_view(appdata_t *appdata, char *text,
368                       gboolean is_html, gboolean scrollwin,                       html_mode_t mode, gboolean scrollwin,
369                       cache_t *cache, char *anchor) {                       cache_t *cache, char *anchor) {
370    GtkWidget *view;    GtkWidget *view;
371    
372    if(is_html) {    if(mode == HTML_HTML) {
373      http_context_t *context = g_new0(http_context_t, 1);      http_context_t *context = g_new0(http_context_t, 1);
374      context->appdata = appdata;      context->appdata = appdata;
375      context->cache = cache;      context->cache = cache;
# Line 399  GtkWidget *html_view(appdata_t *appdata, Line 402  GtkWidget *html_view(appdata_t *appdata,
402      (*h)->view = view;      (*h)->view = view;
403    
404  #ifdef PANNABLE_HTML  #ifdef PANNABLE_HTML
405      /* this causes finger scrolling to work nicely but also prevents */      gtk_widget_tap_and_hold_setup(GTK_WIDGET(view), NULL, NULL, 0);
406      /* copy'n paste from working correctly */      g_signal_connect(G_OBJECT(view), "tap-and-hold", G_CALLBACK(tap_and_hold_cb), appdata);
     gtk_widget_set_sensitive(GTK_WIDGET(view), FALSE);  
   
     g_signal_connect(G_OBJECT(view), "button-press-event",  
                      G_CALLBACK(on_button_press), NULL);  
407  #endif  #endif
408    
409      g_signal_connect(G_OBJECT(view), "destroy",      g_signal_connect(G_OBJECT(view), "destroy",
# Line 413  GtkWidget *html_view(appdata_t *appdata, Line 412  GtkWidget *html_view(appdata_t *appdata,
412      GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);      GtkTextBuffer *buffer = gtk_text_buffer_new(NULL);
413      gtk_text_buffer_set_text(buffer, text, strlen(text));      gtk_text_buffer_set_text(buffer, text, strlen(text));
414    
415  #ifndef USE_MAEMO  #ifndef USE_HILDON_TEXT_VIEW
416      view = gtk_text_view_new_with_buffer(buffer);      view = gtk_text_view_new_with_buffer(buffer);
417  #else  #else
418      view = hildon_text_view_new();      view = hildon_text_view_new();
419      hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), buffer);      hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), buffer);
420    
421        gtk_widget_tap_and_hold_setup(GTK_WIDGET(view), NULL, NULL, 0);
422        g_signal_connect(G_OBJECT(view), "tap-and-hold", G_CALLBACK(tap_and_hold_cb), appdata);
423  #endif  #endif
424    
425      gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);      gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD);
426      gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);      gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE);
427      gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE);      gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE);
428    
429        /* make this look nicer in fremantle and not just black-on-white */
430        /* just use the default style */
431    #ifdef USE_STACKABLE_WINDOW
432        /* in fremantle this is really tricky and we need to inherit the */
433        /* style from the topmost window in the stack */
434        HildonWindowStack *stack = hildon_window_stack_get_default();
435        GList *list = hildon_window_stack_get_windows(stack);
436        gtk_widget_set_style(view, GTK_WIDGET(list->data)->style);
437        g_list_free(list);
438    #else
439        gtk_widget_set_style(view, GTK_WIDGET(appdata->window)->style);
440    #endif
441    
442    #ifndef NO_COPY_N_PASTE
443      g_signal_connect(G_OBJECT(view), "destroy",      g_signal_connect(G_OBJECT(view), "destroy",
444                       G_CALLBACK(on_destroy_textview), appdata);                       G_CALLBACK(on_destroy_textview), appdata);
445    #endif
446    }    }
447    
448    #ifndef NO_COPY_N_PASTE
449    g_signal_connect(G_OBJECT(view), "focus-in-event",    g_signal_connect(G_OBJECT(view), "focus-in-event",
450                     G_CALLBACK(focus_in), appdata);                     G_CALLBACK(focus_in), appdata);
451    #endif
452    
453    if(scrollwin) {    if(scrollwin) {
454  #ifndef USE_PANNABLE_AREA  #ifndef USE_PANNABLE_AREA
# Line 449  GtkWidget *html_view(appdata_t *appdata, Line 468  GtkWidget *html_view(appdata_t *appdata,
468  #endif  #endif
469  #else  #else
470  #ifndef PANNABLE_HTML  #ifndef PANNABLE_HTML
471    if(is_html) {    if(mode == HTML_HTML) {
472        GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);        GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL);
473        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window),        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled_window),
474                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

Legend:
Removed from v.1  
changed lines
  Added in v.229