Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /cbrpager-maemo/branches/MAEMO_0_9_20/src/global.c [r11] .. [r12] Maximize Restore

  Switch to side-by-side view

--- a/cbrpager-maemo/branches/MAEMO_0_9_20/src/global.c
+++ b/cbrpager-maemo/branches/MAEMO_0_9_20/src/global.c
@@ -47,6 +47,7 @@
 #ifdef USE_HILDON
 #    include <hildon/hildon-program.h>
 #    include <hildon/hildon-note.h>
+#    include <hildon/hildon-banner.h>
 #endif
 
 enum FitSettings {
@@ -61,7 +62,7 @@
 int		 page_nr = 0,
                  timer_id = 0;
 #if USE_HILDON
-#define FIT_WIDTH_MARGIN 0
+#define FIT_WIDTH_MARGIN 40
 #else
 #define FIT_WIDTH_MARGIN 20
 #endif
@@ -108,6 +109,14 @@
   return i;
 }
 
+void
+info_dialog(char* msg)
+{
+  GtkWidget* dlg;
+  dlg = hildon_banner_show_information(GTK_WINDOW(MainWindow),
+				       NULL,
+				       msg);
+}
 #else
 int
 ok_dialog(char *ttl, char *msg)
@@ -126,6 +135,14 @@
   response = gtk_dialog_run(GTK_DIALOG(dlg));
   gtk_widget_destroy(dlg);
   return response;
+}
+
+int
+info_dialog(char* msg)
+{
+  /* nothing to do for now */
+  /* TODO: create a window normally hidden that will display the message
+     and disappear after some time */
 }
 #endif
 
@@ -361,7 +378,10 @@
       nr_pages = g_list_length(pagelist);
 
   if (by == 0) by = pref.nrpages;
-  if (page_nr == (nr_pages - by)) return;
+  if (page_nr == (nr_pages - by)) {
+    info_dialog(_("End of archive"));
+    return;
+  }
   page_nr += by;
 
   show_page(page_nr);
@@ -378,6 +398,11 @@
   int by = prv;
   
   if (by == 0) by = pref.nrpages;
+
+  if(page_nr == 0) {
+    info_dialog(_("Beginning of archive"));
+    return;
+  }
   
   page_nr -= by;
   if (page_nr < 0) {
@@ -741,16 +766,59 @@
 }
 
 
+static gint
+find_scrollbar_width(GtkWidget* scroller, GtkWidget* scrollbar, gint default_value)
+{
+  gint adj = default_value;
+  gint temp;
+
+  if(scrollbar) {
+    adj = 0;
+    temp = 0;
+    /* find the fit to width margin using scrollbar width */
+    gtk_widget_style_get(scrollbar, "slider-width", &temp, NULL);
+    adj += temp;
+    
+    temp = 0;
+    gtk_widget_style_get(scrollbar, "trough-border", &temp, NULL);
+    adj += temp * 2;
+    
+    temp = 0;
+    gtk_widget_style_get(scroller, "scrollbar-spacing", &temp, NULL);
+    adj += temp;
+  }
+  
+  return adj;
+}
+
+static gint
+get_scrollbar_adjustment(int rotated, const char* scroller_name) {
+  static int scrollbar_width_h = -1, scrollbar_width_v = -1;
+  GtkWidget* scroller;
+  GtkWidget* scrollbar_h;
+  GtkWidget* scrollbar_v;
+  
+  if(scrollbar_width_h == -1) {
+    scroller = lookup_widget(MainWindow, scroller_name);
+    if(scroller) {
+      scrollbar_h = gtk_scrolled_window_get_hscrollbar(GTK_SCROLLED_WINDOW(scroller));
+      scrollbar_v = gtk_scrolled_window_get_vscrollbar(GTK_SCROLLED_WINDOW(scroller));
+    }
+
+    scrollbar_width_h = find_scrollbar_width(scroller, scrollbar_h, FIT_WIDTH_MARGIN);
+    scrollbar_width_v = find_scrollbar_width(scroller, scrollbar_v, FIT_WIDTH_MARGIN);
+  }
+  return rotated ? scrollbar_width_h : scrollbar_width_v;
+}
+
 void
 set_zoom_width(void)
 {
-  int w, h;
-  
+  int w, h, adj;
+  adj = get_scrollbar_adjustment(rotated, "main_scroller");
   gtk_window_get_size(GTK_WINDOW(MainWindow), &w, &h);
-  if(rotated)
-    fit_width(h - FIT_WIDTH_MARGIN);
-  else
-    fit_width(w - FIT_WIDTH_MARGIN);
+
+  fit_width((rotated ? h : w) - adj);
 }
 
 
@@ -771,15 +839,35 @@
 
 
 void
-main_canvas_keypressed(GdkEventKey *event)
+main_canvas_keyevent(GdkEventKey *event, gboolean is_pressed)
 {
 #if USE_HILDON
-    if(event->keyval == HILDON_HARDKEY_MENU)
-    {
+  if(event->keyval == HILDON_HARDKEY_MENU) {
+    return;
+  } else {
+    /* workaround Maemo bug--dpad does not return key events properly,
+     * so use the key up event instead of key down 
+     */
+    switch(event->keyval) {
+    case HILDON_HARDKEY_LEFT:
+    case HILDON_HARDKEY_RIGHT:
+    case HILDON_HARDKEY_UP:
+    case HILDON_HARDKEY_DOWN:
+    case HILDON_HARDKEY_SELECT:
+      if(is_pressed)
+	return;
+      break;
+    default:
+      if(!is_pressed)
 	return;
     }
- #endif
-     simulate_accelerator(event->keyval, event->state);
+  }
+#else
+  if(!is_pressed) {
+    return;
+  }
+#endif
+  simulate_accelerator(event->keyval, event->state);
  }
 
  void
@@ -844,8 +932,6 @@
  static gboolean
  is_in_right_zone(gint x, gint y, const GtkAllocation alloc)
  {
-   gint left, top, right, bottom;
-
    if(rotated)
      return y >= alloc.height - pref.zone_size && y < alloc.height;
    else