[Aptitude-svn-commit] r4172 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows at costa.debian.org
Thu Sep 22 17:24:41 UTC 2005


Author: dburrows
Date: Thu Sep 22 17:24:38 2005
New Revision: 4172

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc
   branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h
Log:
Let menu bars that are too wide for the terminal scroll.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Thu Sep 22 17:24:38 2005
@@ -1,5 +1,10 @@
 2005-09-22  Daniel Burrows  <dburrows at debian.org>
 
+	* src/vscreen/vs_menubar.cc, src/vscreen/vs_menubar.h:
+
+	  If the screen is too narrow to display a whole menubar, allow it
+	  to "scroll" while the user is interacting with it.
+
 	* src/vscreen/vscreen.cc:
 
 	  (hopefully) fix the cursor placement problems that I was having.

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.cc	Thu Sep 22 17:24:38 2005
@@ -15,7 +15,8 @@
 keybindings *vs_menubar::bindings=NULL;
 
 vs_menubar::vs_menubar(bool _always_visible)
-  :vs_container(), active(false), always_visible(_always_visible), curloc(0), subwidget(NULL)
+  :vs_container(), startloc(0), active(false),
+   always_visible(_always_visible), curloc(0), subwidget(NULL)
 {
   do_layout.connect(sigc::mem_fun(*this, &vs_menubar::layout_me));
 
@@ -122,17 +123,67 @@
     return point(0, 0);
 }
 
-int vs_menubar::get_menustart(int idx)
+int vs_menubar::get_menustart(itemlist::size_type idx) const
 {
-  int rval=0;
-  for(int i=0; i<idx; i++)
+  int rval = 0;
+
+  if(idx >= startloc)
     {
-      const wstring &title=items[i].title;
-      rval+=wcswidth(title.c_str(), title.size());
+      for(itemlist::size_type i = startloc; i < idx; ++i)
+	{
+	  const wstring &title = items[i].title;
+	  rval += wcswidth(title.c_str(), title.size());
+	}
     }
+  else
+    {
+      for(itemlist::size_type i = idx; i < startloc; ++i)
+	{
+	  const wstring &title = items[i].title;
+	  rval -= wcswidth(title.c_str(), title.size());
+	}
+    }
+
   return rval;
 }
 
+void vs_menubar::update_x_start()
+{
+  if(!active)
+    startloc = 0;
+  else if(curloc < startloc)
+    startloc = curloc;
+  else
+    {
+      int width = get_width();
+      if(width == 0)
+	return;
+
+
+      int start_x = get_menustart(startloc);
+
+      const wstring &curr_title = items[curloc].title;
+      int curr_x = get_menustart(curloc);
+      int curr_width = wcswidth(curr_title.c_str(),
+				curr_title.size());
+
+      if(width < curr_width)
+	while(curr_x >= start_x + width)
+	  {
+	    const wstring &title = items[startloc].title;
+	    start_x += wcswidth(title.c_str(), title.size());
+	    ++startloc;
+	  }
+      else
+	while(curr_x + curr_width > start_x + width)
+	  {
+	    const wstring &title = items[startloc].title;
+	    start_x += wcswidth(title.c_str(), title.size());
+	    ++startloc;
+	  }
+    }
+}
+
 void vs_menubar::append_item(const wstring &title,
 			     const vs_menu_ref &menu)
 {
@@ -294,39 +345,45 @@
 {
   vs_widget_ref tmpref(this);
 
+  update_x_start();
+
   // Find the starting X location of each active menu.
   for(activemenulist::iterator i=active_menus.begin();
       i!=active_menus.end();
       i++)
     {
-      int menux=0;
+      int menuloc = -1;
 
-      for(itemlist::size_type j=0; j<items.size(); j++)
+      for(itemlist::size_type j = 0; j < items.size(); j++)
 	{
-	  if(items[j].menu==*i)
-	    break;
-
-	  const wstring &title=items[j].title;
-
-	  menux+=wcswidth(title.c_str(), title.size());
+	  if(items[j].menu == *i)
+	    {
+	      menuloc = j;
+	      break;
+	    }
 	}
 
+      int menux = get_menustart(menuloc);
+
       int req_w=(*i)->width_request();
-      if(getmaxx()<menux+req_w)
+
+      if(menux < 0)
+	menux = 0;
+      else if(getmaxx() < menux + req_w)
 	{
-	  if(getmaxx()>=req_w)
-	    menux=getmaxx()-req_w;
+	  if(getmaxx() >= req_w)
+	    menux = getmaxx() - req_w;
 	  else
 	    {
-	      menux=0;
-	      req_w=getmaxx();
+	      menux = 0;
+	      req_w = getmaxx();
 	    }
 	}
 
-      int req_h=(*i)->height_request(req_w);
+      int req_h = (*i)->height_request(req_w);
 
-      if(getmaxy()<1+req_h)
-	req_h=getmaxy()-1;
+      if(getmaxy() < 1 + req_h)
+	req_h = getmaxy()-1;
 
       (*i)->alloc_size(menux,
 		       1,
@@ -420,6 +477,7 @@
       if(items.size()>0)
 	items[curloc].menu->show();
 
+      update_x_start();
       vscreen_update();
     }
 }
@@ -485,6 +543,7 @@
 
 		  items[curloc].menu->show();
 
+		  update_x_start();
 		  vscreen_update();
 		}
 	    }
@@ -503,6 +562,8 @@
 		    curloc=items.size()-1;
 
 		  items[curloc].menu->show();
+
+		  update_x_start();
 		  vscreen_update();
 		}
 	    }
@@ -520,6 +581,7 @@
 	      else
 		curloc=0;
 
+	      update_x_start();
 	      vscreen_update();
 	    }
 	}
@@ -532,6 +594,7 @@
 	      else
 		curloc=items.size()-1;
 
+	      update_x_start();
 	      vscreen_update();
 	    }
 	}
@@ -580,7 +643,8 @@
 	add_wch(L' ');
 
       move(0, 0);
-      for(itemlist::size_type i=0; i<items.size() && pos<maxx; i++)
+      for(itemlist::size_type
+	    i = startloc; i < items.size() && pos < maxx; ++i)
 	{
 	  if(active && i==curloc)
 	    apply_style(highlightedmenubar_style);

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_menubar.h	Thu Sep 22 17:24:38 2005
@@ -38,19 +38,28 @@
   // A list of active menus
   activemenulist active_menus;
 
+  /** The index of the leftmost visible menu item. */
+  itemlist::size_type startloc;
+
   // True if the menu-bar is visible and/or being used
   bool active;
 
   // True if the menu-bar should always be visible
   bool always_visible;
 
+  /** The index of the currently selected item. */
   itemlist::size_type curloc;
 
   // the widget underneath this one.
   vs_widget_ref subwidget;
 
   // Returns the starting X location of the given item in the menu
-  int get_menustart(int idx);
+  int get_menustart(itemlist::size_type idx) const;
+
+  /** Re-calculates the starting X location, moving it left or right
+   *  if needed.
+   */
+  void update_x_start();
 
   // Show/hide menus
   void show_menu(const vs_menu_ref &w);



More information about the Aptitude-svn-commit mailing list