[PATCH setup] (Usability improvement) Implement half-second wait for user to finish typing before searching packages

Ronald Ramos ronjoe223@gmail.com
Tue Aug 2 03:22:00 GMT 2016


commit 357c1e7576586349efb8514dc9d8d03950e225ee
Author: Ronald Ramos <ronjoe223@gmail.com>
Date:   Mon Aug 1 23:05:44 2016 -0400

     * proppage.h (PropertyPage)
         New member OnTimerMessage (delegates similarly to OnMouseWheel)

     * proppage.cc
         (DialogProc) Added handling of WM_TIMER

     * choose.h (ChooserPage)
         (OnTimerMessage) New function prototype
         (timer_id) New member variable
         Added DEFINE-ed default values for timer_id and search timer delay
         Reorganized private members for consistency

     * choose.cc
         (constructor) Initialize timer_id
         (OnMessageCmd) Replaced search-refresh with a SetTimer
         (OnSearchTimer) New; contains search-refresh removed from 
OnMessageCmd

diff --git a/choose.cc b/choose.cc
index 42d8b74..0e70e26 100644
--- a/choose.cc
+++ b/choose.cc
@@ -92,7 +92,8 @@ static ControlAdjuster::ControlInfo 
ChooserControlsInfo[] = {
  };

  ChooserPage::ChooserPage () :
-  cmd_show_set (false), saved_geom (false), saw_geom_change (false)
+  cmd_show_set (false), saved_geom (false), saw_geom_change (false),
+  timer_id (DEFAULT_TIMER_ID)
  {
    sizeProcessor.AddControlInfo (ChooserControlsInfo);

@@ -382,9 +383,7 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, 
UINT code)
  {
    if (code == EN_CHANGE && id == IDC_CHOOSE_SEARCH_EDIT)
      {
-      std::string value (egetString (GetHWND (), IDC_CHOOSE_SEARCH_EDIT));
-      chooser->SetPackageFilter (value);
-      chooser->refresh ();
+      SetTimer(GetHWND (), timer_id, SEARCH_TIMER_DELAY, (TIMERPROC) NULL);
        return true;
      }
    else if (code != BN_CLICKED && code != EN_CHANGE)
@@ -397,10 +396,10 @@ ChooserPage::OnMessageCmd (int id, HWND hwndctl, 
UINT code)
      {
      case IDC_CHOOSE_CLEAR_SEARCH:
        {
-	std::string value;
-	eset (GetHWND (), IDC_CHOOSE_SEARCH_EDIT, value);
-	chooser->SetPackageFilter (value);
-	chooser->refresh ();
+        std::string value;
+        eset (GetHWND (), IDC_CHOOSE_SEARCH_EDIT, value);
+        chooser->SetPackageFilter (value);
+        chooser->refresh ();
        }
        break;

@@ -444,3 +443,19 @@ ChooserPage::OnMouseWheel (UINT message, WPARAM 
wParam, LPARAM lParam)
  {
    return chooser->WindowProc (message, wParam, lParam);
  }
+
+INT_PTR CALLBACK
+ChooserPage::OnTimerMessage (UINT message, WPARAM wParam, LPARAM lparam)
+{
+  if (wParam == timer_id)
+    {
+      std::string value (egetString (GetHWND (), IDC_CHOOSE_SEARCH_EDIT));
+
+      KillTimer (GetHWND (), timer_id);
+      chooser->SetPackageFilter (value);
+      chooser->refresh ();
+      return TRUE;
+    }
+
+  return FALSE;
+}
diff --git a/choose.h b/choose.h
index 9dc5882..46f0f35 100644
--- a/choose.h
+++ b/choose.h
@@ -21,6 +21,9 @@
  #include "package_meta.h"
  #include "PickView.h"

+#define DEFAULT_TIMER_ID   5   //value doesn't matter, as long as it's 
unique
+#define SEARCH_TIMER_DELAY 500 //in milliseconds
+
  extern bool hasManualSelections;

  class ChooserPage:public PropertyPage
@@ -32,6 +35,8 @@ public:
    virtual bool OnMessageCmd (int id, HWND hwndctl, UINT code);
    virtual INT_PTR CALLBACK OnMouseWheel (UINT message, WPARAM wParam,
  					 LPARAM lParam);
+  virtual INT_PTR CALLBACK OnTimerMessage (UINT message, WPARAM wParam,
+										   LPARAM lparam);

    bool Create ();
    virtual void OnInit ();
@@ -53,20 +58,25 @@ private:
    void logOnePackageResult(packagemeta const *aPkg);
    void logResults();
    void setPrompt(char const *aPrompt);
-  PickView *chooser;
+  void PlaceDialog (bool);

+  PickView *chooser;
    static HWND ins_dialog;
    bool cmd_show_set;
    bool saved_geom;
    bool saw_geom_change;
    WINDOWPLACEMENT window_placement;
    WINDOWPLACEMENT pre_chooser_placement;
+  UINT_PTR timer_id;
    union writer
    {
      WINDOWPLACEMENT wp;
      UINT wpi[sizeof (WINDOWPLACEMENT) / sizeof (UINT)];
    };
-  void PlaceDialog (bool);
+
+
+
+
  };

  #endif /* SETUP_CHOOSE_H */
diff --git a/proppage.cc b/proppage.cc
index 8a63104..c03e5f7 100644
--- a/proppage.cc
+++ b/proppage.cc
@@ -343,7 +343,11 @@ PropertyPage::DialogProc (UINT message, WPARAM 
wParam, LPARAM lParam)
          // to the parent of the window that received the scroll, so it 
would
          // not work to just process this message there.)
          return OnMouseWheel (message, wParam, lParam);
-        break;
+
+      case WM_TIMER:
+		// similar delegation as with WM_MOUSEWHEEL
+        return OnTimerMessage (message, wParam, lParam);
+
        default:
          break;
      }
@@ -366,6 +370,12 @@ PropertyPage::OnMouseWheel (UINT message, WPARAM 
wParam, LPARAM lParam)
    return 1; // not handled; define in a derived class to support this
  }

+INT_PTR CALLBACK
+PropertyPage::OnTimerMessage (UINT message, WPARAM wParam, LPARAM lParam)
+{
+  return 1; // not handled; define in a derived class to support this
+}
+
  void
  PropertyPage::setTitleFont ()
  {
diff --git a/proppage.h b/proppage.h
index 8e2cb40..9424ffc 100644
--- a/proppage.h
+++ b/proppage.h
@@ -82,6 +82,8 @@ protected:
  					 LPARAM lParam);
      virtual INT_PTR CALLBACK OnMouseWheel (UINT message, WPARAM wParam,
  					   LPARAM lParam);
+    virtual INT_PTR CALLBACK OnTimerMessage (UINT message, WPARAM wParam,
+					     LPARAM lparam);

  public:
      PropertyPage ();



More information about the Cygwin-apps mailing list