Author: bgbnbigben
Date: 2011-05-26 23:31:17 -0700 (Thu, 26 May 2011)
New Revision: 8744
Log:
Weekly commit. Apologies for the huge commit; I haven't had much time this week.
Changes are as follows:
*       Documentation cleanup in src/Valuator.cxx
*       Modified the prototype of mose of the src/InputBrowser.cxx functions to 
match the CMP. 
        Added the ability to "toggle" the InputBrowser; clicking the down arrow 
once drops the list down, clicking it again retracts the list. 
        Removed the "was_wheel" section which would block repeated mouse 
scrolls as this seemed pretty backwards.
        Re-added the commented-out section of code that determines whether to 
open the popup down or up depending on monitor space.
*       Small code cleanup in src/FileBrowser.cxx
*       #ifdef'd the functions only used on WIN32 in src/file_chooser.cxx to 
stop the build noise under gcc
*       Unhacked a hack I implemented in src/Scrollbar.cxx to force proper 
redrawing of scrollbars. This means it does do slightly more work, some of 
which is unneccary, and will need to be looked at in the future.


Modified:
   trunk/src/FileBrowser.cxx
   trunk/src/InputBrowser.cxx
   trunk/src/Scrollbar.cxx
   trunk/src/Valuator.cxx
   trunk/src/file_chooser.cxx

Modified: trunk/src/FileBrowser.cxx
===================================================================
--- trunk/src/FileBrowser.cxx   2011-05-26 21:18:08 UTC (rev 8743)
+++ trunk/src/FileBrowser.cxx   2011-05-27 06:31:17 UTC (rev 8744)
@@ -159,10 +159,7 @@
       {
         sprintf(filename, "%c:/", i);
 
-       if (i < 'C')
-         add(filename, icon);
-       else
-         add(filename, icon);
+       add(filename, icon);
 
        num_files ++;
       }

Modified: trunk/src/InputBrowser.cxx
===================================================================
--- trunk/src/InputBrowser.cxx  2011-05-26 21:18:08 UTC (rev 8743)
+++ trunk/src/InputBrowser.cxx  2011-05-27 06:31:17 UTC (rev 8744)
@@ -66,15 +66,14 @@
   ibinput = &m_input;
 }
 
-void
-InputBrowser::input_cb(Input *w, InputBrowser *ib)
-{
+void InputBrowser::input_cb(Input *w, InputBrowser *ib) {
   ib->do_callback();
 }
 
 // these are only used when in grabbed state so only one exists at once
 static InputBrowser *ib;
 static Browser *browser;
+static bool toggle;
 
 namespace fltk {
 
@@ -82,13 +81,12 @@
   public:
     int handle(int);
 //    ComboWindow(int x, int y, int w, int h) : MenuWindow(x, y, w, h) { 
box(NO_BOX); }
-    ComboWindow(int x, int y, int w, int h) : MenuWindow(x, y, w, h) { ; }
+    ComboWindow(int x, int y, int w, int h) : MenuWindow(x, y, w, h) {}
 };
 
 }
 
-int
-ComboWindow::handle(int event) {
+int ComboWindow::handle(int event) {
   switch (event) {
   case MOVE:
   case DRAG:
@@ -123,8 +121,7 @@
 ComboBrowser::ComboBrowser(int x, int y, int w, int h)
 : Browser(x, y, w, h, 0) {}
 
-int
-ComboBrowser::handle(int event) {
+int ComboBrowser::handle(int event) {
   if(event_key()==DownKey && (!item() || children()==1)) {
     item(child(0));
     fltk::focus(item());
@@ -138,11 +135,13 @@
         (event_key()!=EscapeKey) &&
        (event_key()!=UpKey) &&
        (event_key()!=DownKey) && 
-       (event_key()!=ReturnKey && !item()) )
+       (event_key()!=ReturnKey && !item()) ) 
       // give a chance to the browser to handle the menu shortcuts
       return ibinput->handle(KEY);
   }
 
+  // This "was_wheel" section seems pretty counter-intuitive; if 
+  // I scroll the mouse 8 times I expect it to move 8 times.
   static bool was_wheel=false;
   if(was_wheel) {
     was_wheel=false;
@@ -165,6 +164,10 @@
 
   case PUSH: {
     if (!event_inside(Rectangle(0, 0, w(), h()))) {
+      // If we've just clicked on the button, set toggle
+      // the button is a h() x h() square
+      if (event_x() < ib->w() && event_x() > ib->w() - ib->h() && event_y() > 
-ib->h() && event_y() < 0) 
+       toggle = true;
       ib->hide_popup();
       // Rectangle below is InputBrowser area
       if (event_inside(Rectangle(0, -ib->h(), ib->w(), 0))) ib->send(PUSH);
@@ -185,11 +188,11 @@
       fltk::pushed(this);
       return 0;
     }
-
+    break;
+  
   default:
     break;
   }
-
   return Browser::handle(event);
 }
 
@@ -231,8 +234,7 @@
 } share_list; // only one instance of this.
 
 
-int
-InputBrowser::handle(int event) {
+int InputBrowser::handle(int event) {
   int TX, TY = 0, TW, TH = h();
   if(type()&NONEDITABLE) {
       TX = 0;
@@ -271,13 +273,16 @@
     case MOUSEWHEEL: {
 
       // prevent double events
-      static bool was_wheel=false;
+      // BS: Why? What possible purpose does that serve?
+      //     If I roll the mousewheel 8 times, I expect it to cycle through
+      //     8 elements.
+     /* static bool was_wheel=false;
       if(was_wheel) {
          was_wheel=false;
          return 1;
       } else {
          was_wheel=true;
-      }
+      }*/
 
       // horizontal wheel
       if (event_dy() == 0)
@@ -307,10 +312,15 @@
     }
 
     case PUSH: {
-      if (!win || !win->visible())
-         popup();
-      else
-         hide_popup();
+      // BS: The following lines are unnessecary; the PUSH in the ComboBrowser
+      // automatically calls exit_modal() before this.
+      // Further, when exec returns it calls hide(); which will destroy the 
window
+//      if ((!win || !win->visible())) {
+      popup();
+//      }
+//      else 
+//     hide_popup();
+      
       return 1;
     }
 
@@ -324,8 +334,7 @@
   return 0;
 }
 
-void
-InputBrowser::draw() {
+void InputBrowser::draw() {
   drawstyle(style(),flags());
   minw_ = w();
   Rectangle r(w(),h()); box()->inset(r);
@@ -358,15 +367,19 @@
   }
 }
 
-void
-InputBrowser::hide_popup() {
+void InputBrowser::hide_popup() {
   if (win && win->visible()) {
     fltk::exit_modal();
   }
 }
 
-void
-InputBrowser::popup() {
+void InputBrowser::popup() {
+  // if the user is pressing the down button to close the popup, honour this!
+  if (toggle) {
+    toggle = false;
+    return;
+  }
+
   bool resize_only = false;
 
   if (!win || !win->visible()) {
@@ -416,21 +429,23 @@
   // I don't know what this code does, but it doesn't work
   // WAS: I believe it is trying to make the menu go above the combobox
   //      if it does not fit below on the screen
-  /*      const Monitor& monitor = Monitor::find(event_x_root(), 
event_y_root());
-         int down = monitor.h() - Y;
-         int up = event_y_root() - event_y();
-         if (H > down) {
-         if (up > down) {
-         Y = event_y_root() - event_y() - H;
-         if (Y < 0) { Y = 0; H = up; }
-         } else {
-         H = down;
-         }
-         }
-         if (X + W > monitor.r()) {
-         X = monitor.r() - W;
-         if (X < 0) { X = 0; W = monitor.r(); }
-         }*/
+  // BS: It works fine, and has been re-incorporated as it's terrifically
+  //     useful 
+  const Monitor& monitor = Monitor::find(event_x_root(), event_y_root());
+  int down = monitor.h() - Y;
+  int up = event_y_root() - event_y();
+  if (H > down) {
+    if (up > down) {
+      Y = event_y_root() - event_y() - H;
+      if (Y < 0) { Y = 0; H = up; }
+    } else {
+      H = down;
+    }
+  }
+  if (X + W > monitor.r()) {
+    X = monitor.r() - W;
+    if (X < 0) { X = 0; W = monitor.r(); }
+  }
 
   win->resize(X, Y, W, H);
   list->Widget::resize(W, H);

Modified: trunk/src/Scrollbar.cxx
===================================================================
--- trunk/src/Scrollbar.cxx     2011-05-26 21:18:08 UTC (rev 8743)
+++ trunk/src/Scrollbar.cxx     2011-05-27 06:31:17 UTC (rev 8744)
@@ -187,7 +187,7 @@
     }
     goto J1;
   case DRAG:
-    if (which_pushed==SLIDER) {redraw(); return Slider::handle(event, r);}
+    if (which_pushed==SLIDER) {redraw(DAMAGE_HIGHLIGHT); return 
Slider::handle(event, r);}
     if (which_part == SLIDER) which_part = NOTHING;
     // it is okay to switch between arrows and nothing, but no other
     // changes are allowed:
@@ -241,7 +241,7 @@
 }
 
 void Scrollbar::draw() {
-  if (damage()&DAMAGE_ALL) draw_frame();
+  if (damage()&(DAMAGE_ALL|DAMAGE_HIGHLIGHT)) draw_frame();
 
   Rectangle r(w(),h()); box()->inset(r);
 

Modified: trunk/src/Valuator.cxx
===================================================================
--- trunk/src/Valuator.cxx      2011-05-26 21:18:08 UTC (rev 8743)
+++ trunk/src/Valuator.cxx      2011-05-27 06:31:17 UTC (rev 8744)
@@ -232,7 +232,7 @@
   value. It may call the callback. */
 void Valuator::handle_release() {
   if (when()&WHEN_RELEASE && !pushed()) {
-    // insure changed() is off even if no callback is done.  It may have
+    // ensure changed() is off even if no callback is done.  It may have
     // been turned on by the drag, and then the slider returned to it's
     // initial position:
     clear_changed();

Modified: trunk/src/file_chooser.cxx
===================================================================
--- trunk/src/file_chooser.cxx  2011-05-26 21:18:08 UTC (rev 8743)
+++ trunk/src/file_chooser.cxx  2011-05-27 06:31:17 UTC (rev 8744)
@@ -39,9 +39,11 @@
 static void            (*current_callback)(const char*) = default_callback;
 static const char      *current_label = "Ok";
 
-// Prototype for a local function
+#ifdef _WIN32
+// Prototype for local functions regarding the WIN32 filechooser
 static wchar_t* patternToWin(const char* const pat, int len);
 static unsigned windowsWLen(const wchar_t* const string);
+#endif
 
 // Do a file chooser callback...
 static void callback(FileChooser *, void*) {
@@ -275,7 +277,7 @@
   else return 0;
 }
 
-
+#ifdef _WIN32
 // This function converts a FLTK pattern to Windows' format.
 // It is only static and not available via the API.
 wchar_t* patternToWin(const char* const pat, int len) {
@@ -350,6 +352,7 @@
     if (!string[out] && !string[out+1])
       return out;
 }
+#endif
 
 //
 // End of "$Id$".

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to