From 81fc468ebdd6c9ceb189186a708c3da950481eed Mon Sep 17 00:00:00 2001
From: rds <rds>
Date: Wed, 8 Nov 2006 08:35:45 +0000
Subject: [PATCH] navigator packed into scrolled window

---
 src/zmapControl/zmapControlNavigator.c | 280 ++++++++-----------------
 1 file changed, 89 insertions(+), 191 deletions(-)

diff --git a/src/zmapControl/zmapControlNavigator.c b/src/zmapControl/zmapControlNavigator.c
index 367b7d979..8dce4d308 100755
--- a/src/zmapControl/zmapControlNavigator.c
+++ b/src/zmapControl/zmapControlNavigator.c
@@ -29,9 +29,9 @@
  *              
  * Exported functions: See zmapControl_P.h
  * HISTORY:
- * Last edited: Oct 18 16:48 2006 (rds)
+ * Last edited: Nov  8 08:32 2006 (rds)
  * Created: Thu Jul  8 12:54:27 2004 (edgrif)
- * CVS info:   $Id: zmapControlNavigator.c,v 1.26 2006-10-19 13:15:18 rds Exp $
+ * CVS info:   $Id: zmapControlNavigator.c,v 1.27 2006-11-08 08:35:45 rds Exp $
  *-------------------------------------------------------------------
  */
 
@@ -65,138 +65,88 @@ static void canvasValueCB(gpointer user_data, double top, double bottom)
 ZMapNavigator zMapNavigatorCreate(GtkWidget **top_widg_out, GtkWidget **canvas_out)
 {
   ZMapNavigator navigator ;
-  GtkWidget *pane ;
   GtkObject *adjustment ;
-  GtkWidget *label ;
-
-  navigator = g_new0(ZMapNavStruct, 1);
-
-  navigator->pane = pane = gtk_hpaned_new() ;
-
-#ifdef ED_G_NEVER_INCLUDE_THIS_CODE
-  gtk_widget_set_size_request(pane, 100, -1) ;
-#endif /* ED_G_NEVER_INCLUDE_THIS_CODE */
-
-
-  /* Construct the region locator. */
-
-  /* Need a vbox so we can add a label with sequence size at the bottom later,
-   * we set it to a fixed width so that the text is always visible. */
-  navigator->navVBox = gtk_vbox_new(FALSE, 0);
-  gtk_paned_add1(GTK_PANED(pane), navigator->navVBox) ;
-
-  label = gtk_label_new("Region") ;
-  gtk_box_pack_start(GTK_BOX(navigator->navVBox), label, FALSE, TRUE, 0);
-
-  navigator->topLabel = gtk_label_new(TOPTEXT_NO_SCALE) ;
-  gtk_box_pack_start(GTK_BOX(navigator->navVBox), navigator->topLabel, FALSE, TRUE, 0);
-
-
-  /* Make the navigator with a default, "blank" adjustment obj. */
-  adjustment = gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ;
-
-  navigator->navVScroll = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustment)) ;
-  gtk_box_pack_start(GTK_BOX(navigator->navVBox), navigator->navVScroll, TRUE, TRUE, 0) ;
-
-  /* Note how we pack the label at the end of the vbox and set "expand" to FALSE so that it
-   * remains small and the vscale expands to fill the rest of the box. */
-  navigator->botLabel = gtk_label_new(BOTTEXT_NO_SCALE) ;
-  gtk_box_pack_end(GTK_BOX(navigator->navVBox), navigator->botLabel, FALSE, TRUE, 0);
-
-
-  /* Construct the window locator. Note that we set the update policy to discontinuous so if
-   * user drags this scroll bar the position is only reported on button release. This is
-   * necessary because the underlying canvas window cannot be remapped rapidly. */
-  navigator->wind_vbox = gtk_vbox_new(FALSE, 0);
-
-  {
-    GtkWidget *locator_frame = NULL,
-      *locator_canvas = NULL,
-      *locator_pane   = NULL, 
-      *locator_vbox   = NULL,
-      *locator_label  = NULL,
-      *event_box      = NULL,
-      *event_label    = NULL;
-    ZMapWindowNavigatorCallbackStruct cbs = {NULL};
-
-#ifdef RDS_USE_SCROLL
-    locator_pane = gtk_hpaned_new();
-    gtk_paned_add2(GTK_PANED(pane), locator_pane) ; /* add this pane to main pane */
-
-    gtk_paned_add1(GTK_PANED(locator_pane), navigator->wind_vbox) ; /* add scroll to this pane */
-#endif /* RDS_USE_SCROLL */
-    
-    locator_vbox = gtk_vbox_new(FALSE, 0);
-
-#ifdef RDS_USE_SCROLL
-    gtk_paned_add2(GTK_PANED(locator_pane), locator_vbox) ; /* add locusnav to this pane */
-#else
-    gtk_paned_add2(GTK_PANED(pane), locator_vbox) ; /* add locusnav to this pane */
-#endif /* RDS_USE_SCROLL */
-
-    locator_label = gtk_label_new("Scroll Navigator") ;
-    gtk_box_pack_start(GTK_BOX(locator_vbox), locator_label, FALSE, TRUE, 0);
-
-    locator_frame = gtk_frame_new(NULL);
-    gtk_frame_set_shadow_type(GTK_FRAME(locator_frame), GTK_SHADOW_NONE);
-    gtk_box_pack_start(GTK_BOX(locator_vbox), locator_frame, TRUE, TRUE, 0);
-
-    cbs.valueCB    = canvasValueCB;
-    locator_canvas = navigator->locator_widget = 
-      zMapWindowNavigatorCreateCanvas(&cbs, navigator);
-    
-    gtk_container_add(GTK_CONTAINER(locator_frame), locator_canvas);
-    
-    event_box = gtk_event_box_new();
-    /* gtk_widget_set_name(event_box, "zmap-control-infopanel"); */
-    gtk_box_pack_start(GTK_BOX(locator_vbox), event_box, FALSE, FALSE, 2);
-    
-    event_label = gtk_label_new("drag box to navigate");
-    gtk_label_set_selectable(GTK_LABEL(event_label), TRUE);
-    gtk_container_add(GTK_CONTAINER(event_box), event_label);
-#ifdef RDS_USE_SCROLL
-    g_object_connect(G_OBJECT(pane), 
-                     "signal::notify::position", 
-                     G_CALLBACK(paneNotifyPositionCB), 
-                     (gpointer)navigator,
-                     NULL);
-#endif
-    if(canvas_out)
-      *canvas_out = locator_canvas;
-    
-  }
-
-#ifdef RDS_USE_SCROLL
-  label = gtk_label_new("Scroll") ;
-  gtk_box_pack_start(GTK_BOX(navigator->wind_vbox), label, FALSE, TRUE, 0);
-
-  navigator->wind_top_label = gtk_label_new(TOPTEXT_NO_SCALE) ;
-  gtk_box_pack_start(GTK_BOX(navigator->wind_vbox), navigator->wind_top_label, FALSE, TRUE, 0);
-
-  adjustment = gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ; /* "blank" adjustment obj. */
-
-#ifdef RDS_DONT_INCLUDE_UNUSED
-  gtk_signal_connect(GTK_OBJECT(adjustment), "value-changed",
-                     GTK_SIGNAL_FUNC(valueCB), (void *)navigator) ;
-#endif /* RDS_DONT_INCLUDE_UNUSED */
-
-  navigator->wind_scroll = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustment)) ;
-  gtk_range_set_update_policy(GTK_RANGE(navigator->wind_scroll), GTK_UPDATE_DISCONTINUOUS) ;
-  gtk_box_pack_start(GTK_BOX(navigator->wind_vbox), navigator->wind_scroll, TRUE, TRUE, 0) ;
-
-
-  /* Note how we pack the label at the end of the vbox and set "expand" to FALSE so that it
-   * remains small and the vscale expands to fill the rest of the box. */
-  navigator->wind_bot_label = gtk_label_new(BOTTEXT_NO_SCALE) ;
-  gtk_box_pack_end(GTK_BOX(navigator->wind_vbox), navigator->wind_bot_label, FALSE, TRUE, 0);
-#endif /* RDS_USE_SCROLL */
-
-  navigator->wind_top = navigator->wind_bot = 0.0 ;
-
-  /* Set left hand (region view) pane closed by default. */
-  gtk_paned_set_position(GTK_PANED(pane), 0) ;
-
-  *top_widg_out = pane ;
+  GtkWidget *pane, *label,
+    *locator_frame  = NULL,
+    *locator_canvas = NULL,
+    *locator_vbox   = NULL,
+    *locator_label  = NULL,
+    *locator_sw     = NULL;
+  ZMapWindowNavigatorCallbackStruct cbs = {NULL};
+
+  if((navigator = g_new0(ZMapNavStruct, 1)))
+    {
+      navigator->pane = pane = gtk_hpaned_new() ;
+      
+      /* Construct the region locator. */
+      
+      /* Need a vbox so we can add a label with sequence size at the bottom later,
+       * we set it to a fixed width so that the text is always visible. */
+      navigator->navVBox = gtk_vbox_new(FALSE, 0);
+      gtk_paned_add1(GTK_PANED(pane), navigator->navVBox) ;
+      
+      label = gtk_label_new("Region") ;
+      gtk_box_pack_start(GTK_BOX(navigator->navVBox), label, FALSE, TRUE, 0);
+      
+      navigator->topLabel = gtk_label_new(TOPTEXT_NO_SCALE) ;
+      gtk_box_pack_start(GTK_BOX(navigator->navVBox), navigator->topLabel, FALSE, TRUE, 0);
+      
+      
+      /* Make the navigator with a default, "blank" adjustment obj. */
+      adjustment = gtk_adjustment_new(0.0, 0.0, 0.0, 0.0, 0.0, 0.0) ;
+      
+      navigator->navVScroll = gtk_vscrollbar_new(GTK_ADJUSTMENT(adjustment)) ;
+      gtk_box_pack_start(GTK_BOX(navigator->navVBox), navigator->navVScroll, TRUE, TRUE, 0) ;
+      
+      /* Note how we pack the label at the end of the vbox and set "expand" to FALSE so that it
+       * remains small and the vscale expands to fill the rest of the box. */
+      navigator->botLabel = gtk_label_new(BOTTEXT_NO_SCALE) ;
+      gtk_box_pack_end(GTK_BOX(navigator->navVBox), navigator->botLabel, FALSE, TRUE, 0);
+      
+      
+      /* Construct the window locator ... */
+      locator_vbox  = gtk_vbox_new(FALSE, 0);
+
+      /* A label */
+      locator_label = gtk_label_new("Scroll Navigator") ;
+      gtk_box_pack_start(GTK_BOX(locator_vbox), locator_label, FALSE, TRUE, 0);
+
+      /* A frame */
+      locator_frame = gtk_frame_new(NULL);
+      gtk_frame_set_shadow_type(GTK_FRAME(locator_frame), GTK_SHADOW_NONE);
+      gtk_box_pack_start(GTK_BOX(locator_vbox), locator_frame, TRUE, TRUE, 0);
+      
+      /* A canvas */
+      cbs.valueCB    = canvasValueCB;
+      locator_canvas = navigator->locator_widget = 
+        zMapWindowNavigatorCreateCanvas(&cbs, navigator);
+      
+      locator_sw = gtk_scrolled_window_new(NULL, NULL);
+      gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(locator_sw),
+                                     GTK_POLICY_ALWAYS, GTK_POLICY_NEVER);
+      gtk_container_add(GTK_CONTAINER(locator_sw), locator_canvas);
+      gtk_container_add(GTK_CONTAINER(locator_frame), locator_sw);
+      gtk_container_set_border_width(GTK_CONTAINER(locator_frame), 2);
+
+      /* pack into the pane */
+      gtk_paned_add2(GTK_PANED(pane), locator_vbox) ;
+      
+#ifdef RDS_DONT_INCLUDE_UNUSED  
+      g_object_connect(G_OBJECT(pane), 
+                       "signal::notify::position", 
+                       G_CALLBACK(paneNotifyPositionCB), 
+                       (gpointer)navigator,
+                       NULL);
+#endif  
+      
+      /* Set left hand (region view) pane closed by default. */
+      gtk_paned_set_position(GTK_PANED(pane), 0) ;
+
+      if(canvas_out)
+        *canvas_out = locator_canvas;
+      if(top_widg_out)
+        *top_widg_out = pane ;
+    }
 
   return navigator ;
 }
@@ -225,38 +175,15 @@ void zMapNavigatorSetWindowCallback(ZMapNavigator navigator,
 int zMapNavigatorSetWindowPos(ZMapNavigator navigator, double top_pos, double bot_pos)
 {
   int pane_width = 0 ;
-  GtkAdjustment *window_adjuster ;
   double w, h;
   enum {PANED_WINDOW_GUTTER_SIZE = 10} ;		    /* There is no simple way to get this. */
 
-#ifdef RDS_USE_SCROLL
-  /* Set the new scrollbar size. */
-  window_adjuster = (GtkAdjustment *)gtk_range_get_adjustment(GTK_RANGE(navigator->wind_scroll)) ;
+  zMapWindowNavigatorPackDimensions(navigator->locator_widget, &w, &h);
 
-  window_adjuster->value = top_pos ;
-  window_adjuster->page_size = (gdouble)(fabs(bot_pos - top_pos) + 1) ;
-
-  gtk_adjustment_changed(window_adjuster) ;
-
-  /* find out if page_size is smaller than max pane size....if so then return width of window
-     navigator box, otherwise return 0 so the window navigator will not be visible. */
-  //  if (window_adjuster->page_size < (window_adjuster->upper - window_adjuster->lower + 1))
-    {
-      GtkRequisition box_size ;
-
-      gtk_widget_size_request(GTK_WIDGET(navigator->wind_vbox), &box_size) ;
-
-      pane_width = box_size.width + PANED_WINDOW_GUTTER_SIZE ;
-    }
-#endif /* RDS_USE_SCROLL */
+  pane_width = (int)fabs(w);
+  if(pane_width > 0)
+    pane_width += PANED_WINDOW_GUTTER_SIZE;
     
-    {
-      zMapWindowNavigatorPackDimensions(navigator->locator_widget, &w, &h);
-      pane_width = (int)fabs(w);
-      if(pane_width > 0)
-        pane_width += PANED_WINDOW_GUTTER_SIZE;
-    }
-
   return pane_width;
 }
 
@@ -269,9 +196,6 @@ void zMapNavigatorSetView(ZMapNavigator navigator, ZMapFeatureContext features,
   GtkObject *region_adjuster, *window_adjuster ;
   gchar *region_top_str, *region_bot_str, *window_top_str, *window_bot_str ;
   region_adjuster = (GtkObject *)gtk_range_get_adjustment(GTK_RANGE(navigator->navVScroll)) ;
-#ifdef RDS_USE_SCROLL
-  window_adjuster = (GtkObject *)gtk_range_get_adjustment(GTK_RANGE(navigator->wind_scroll)) ;
-#endif /* RDS_USE_SCROLL */
 
   /* May be called with no sequence to parent mapping so must set default navigator for this. */
   if (features)
@@ -294,16 +218,6 @@ void zMapNavigatorSetView(ZMapNavigator navigator, ZMapFeatureContext features,
       window_top_str = g_strdup_printf("%d", navigator->sequence_to_parent.c1) ;
       window_bot_str = g_strdup_printf("%d", navigator->sequence_to_parent.c2) ;
 
-#ifdef RDS_USE_SCROLL
-      /* I assume here that we start at the top. */
-      GTK_ADJUSTMENT(window_adjuster)->value = (0.0) ;
-      GTK_ADJUSTMENT(window_adjuster)->lower = (gdouble)navigator->sequence_to_parent.c1 ;
-      GTK_ADJUSTMENT(window_adjuster)->upper = (gdouble)navigator->sequence_to_parent.c2 ;
-      GTK_ADJUSTMENT(window_adjuster)->step_increment = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->page_increment = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->page_size = (gdouble)(fabs(navigator->sequence_to_parent.c2
-								  - navigator->sequence_to_parent.c1) + 1) ;
-#endif /* RDS_USE_SCROLL */
       zMapNavigatorSetWindowPos(navigator, top, bottom) ;
     }
   else
@@ -325,32 +239,16 @@ void zMapNavigatorSetView(ZMapNavigator navigator, ZMapFeatureContext features,
 
       window_top_str = g_strdup(TOPTEXT_NO_SCALE) ;
       window_bot_str = g_strdup(BOTTEXT_NO_SCALE) ;
-#ifdef RDS_USE_SCROLL
-      GTK_ADJUSTMENT(window_adjuster)->value = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->lower = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->upper = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->step_increment = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->page_increment = 0.0 ;
-      GTK_ADJUSTMENT(window_adjuster)->page_size = 0.0 ;
-#endif /* RDS_USE_SCROLL */
+
     }
 
   gtk_adjustment_changed(GTK_ADJUSTMENT(region_adjuster)) ;
-#ifdef RDS_USE_SCROLL
-  gtk_adjustment_changed(GTK_ADJUSTMENT(window_adjuster)) ;
-#endif /* RDS_USE_SCROLL */
+
   gtk_label_set_text(GTK_LABEL(navigator->topLabel), region_top_str) ;
   gtk_label_set_text(GTK_LABEL(navigator->botLabel), region_bot_str) ;
 
   g_free(region_top_str) ;
   g_free(region_bot_str) ;
-#ifdef RDS_USE_SCROLL
-  gtk_label_set_text(GTK_LABEL(navigator->wind_top_label), window_top_str) ;
-  gtk_label_set_text(GTK_LABEL(navigator->wind_bot_label), window_bot_str) ;
-
-  g_free(window_top_str) ;
-  g_free(window_bot_str) ;
-#endif /* RDS_USE_SCROLL */
 
   return ;
 }
-- 
GitLab