[Aptitude-devel] r3170 - in branches/aptitude-0.3/aptitude: . src/vscreen

Daniel Burrows dburrows@costa.debian.org
Thu, 28 Apr 2005 03:00:47 +0000


Author: dburrows
Date: Thu Apr 28 03:00:44 2005
New Revision: 3170

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc
Log:
Recognize mouse clicks on the 'tabs'.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Thu Apr 28 03:00:44 2005
@@ -1,5 +1,9 @@
 2005-04-27  Daniel Burrows  <dburrows@debian.org>
 
+	* src/vscreen/vs_multiplex.cc:
+
+	  Recognize mouse clicks on the "tabs".
+
 	* src/download.cc, src/pkg_item.cc, src/pkg_ver_item.cc, src/ui.cc, src/ui.h, src/view_changelog.cc:
 
 	  Use tabs for the main multiplex.

Modified: branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/vscreen/vs_multiplex.cc	Thu Apr 28 03:00:44 2005
@@ -120,7 +120,6 @@
       assert(visible_children>0);
 
       int remaining_w=getmaxx();
-      int startx=0;
       move(0, 0);
 
       for(list<child_info>::iterator i=children.begin();
@@ -140,11 +139,7 @@
 	    remaining_w-=thisw;
 
 	    if(i->title.size()>thisw)
-	      {
-		addnstr(i->title.c_str(), thisw);
-
-		startx+=thisw;
-	      }
+	      addnstr(i->title.c_str(), thisw);
 	    else
 	      {
 		unsigned int j=0;
@@ -176,7 +171,44 @@
 void vs_multiplex::dispatch_mouse(short id, int x, int y, int z,
 				  mmask_t bstate)
 {
-  if(visible_child!=children.end())
+  if(tabs_visible() && y == 0)
+    {
+      // FIXME: duplicated code from above, is there a good way to
+      // unduplicate it? (eg, an "iterator" for child locations)
+      int visible_children=0;
+
+      for(list<child_info>::iterator i=children.begin();
+	  i!=children.end(); ++i)
+	if(i->w->get_visible())
+	  ++visible_children;
+
+      assert(visible_children>0);
+
+      int startx=0;
+      int remaining_w=getmaxx();
+
+      for(list<child_info>::iterator i=children.begin();
+	  i!=children.end(); ++i)
+	if(i->w->get_visible())
+	  {
+	    int thisw=remaining_w/visible_children;
+	    --visible_children;
+	    remaining_w-=thisw;
+
+	    if(x>=startx && x<startx+thisw)
+	      {
+		visible_child=i;
+		vscreen_queuelayout();
+		return;
+	      }
+
+	    startx+=thisw;
+	  }
+
+      assert(x<0 || x>=getmaxx());
+      assert(visible_children == 0);
+    }
+  else if(visible_child!=children.end())
     visible_child->w->dispatch_mouse(id,
 				     x-visible_child->w->get_startx(),
 				     y-visible_child->w->get_starty(),