"Fossies" - the Fresh Open Source Software Archive

Member "audacity-minsrc-2.3.2/src/widgets/AButton.h" (13 Apr 2019, 5821 Bytes) of package /linux/misc/audacity-minsrc-2.3.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AButton.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.1_vs_2.3.2.

    1 /**********************************************************************
    2 
    3   Audacity: A Digital Audio Editor
    4 
    5   AButton.h
    6 
    7   Dominic Mazzoni
    8 
    9 
   10 **********************************************************************/
   11 
   12 #ifndef __AUDACITY_BUTTON__
   13 #define __AUDACITY_BUTTON__
   14 
   15 #include "../MemoryX.h"
   16 #include <vector>
   17 
   18 #include <wx/setup.h> // for wxUSE_* macros
   19 #include <wx/window.h> // to inherit
   20 
   21 #include "ImageRoll.h"
   22 
   23 class wxImage;
   24 
   25 class AButton final : public wxWindow {
   26    friend class AButtonAx;
   27    class Listener;
   28 
   29  public:
   30 
   31     // Construct button, specifying images (button up, highlight, button down,
   32     // and disabled) for the default state
   33    AButton(wxWindow * parent,
   34            wxWindowID id,
   35            const wxPoint & pos,
   36            const wxSize & size,
   37            ImageRoll up,
   38            ImageRoll over,
   39            ImageRoll down,
   40            ImageRoll overDown,
   41            ImageRoll dis,
   42            bool toggle);
   43 
   44     // Construct button, specifying images (button up, highlight, button down,
   45     // and disabled) for the default state
   46    AButton(wxWindow * parent,
   47            wxWindowID id,
   48            const wxPoint & pos,
   49            const wxSize & size,
   50            wxImage up,
   51            wxImage over,
   52            wxImage down,
   53            wxImage overDown,
   54            wxImage dis,
   55            bool toggle);
   56 
   57    virtual ~ AButton();
   58 
   59    bool AcceptsFocus() const override { return s_AcceptsFocus; }
   60    bool AcceptsFocusFromKeyboard() const override { return mEnabled; }
   61 
   62    void SetFocusFromKbd() override;
   63 
   64    // Associate a set of four images (button up, highlight, button down,
   65    // disabled) with one nondefault state of the button
   66    void SetAlternateImages(unsigned idx,
   67                                    ImageRoll up,
   68                                    ImageRoll over,
   69                                    ImageRoll down,
   70                                    ImageRoll overDown,
   71                                    ImageRoll dis);
   72 
   73    // Associate a set of four images (button up, highlight, button down,
   74    // disabled) with one nondefault state of the button
   75    void SetAlternateImages(unsigned idx,
   76                                    wxImage up,
   77                                    wxImage over,
   78                                    wxImage down,
   79                                    wxImage overDown,
   80                                    wxImage dis);
   81 
   82    // Choose state of the button
   83    void SetAlternateIdx(unsigned idx);
   84 
   85    // Make the button change appearance with the modifier keys, no matter
   86    // where the mouse is:
   87    // Use state 2 when CTRL is down, else 1 when SHIFT is down, else 0
   88    void FollowModifierKeys();
   89 
   90    void SetFocusRect(wxRect & r);
   91 
   92    bool IsEnabled() const { return mEnabled; }
   93    void Disable();
   94    void Enable();
   95    void SetEnabled(bool state) {
   96       state ? Enable() : Disable();
   97    }
   98 
   99    void PushDown();
  100    void PopUp();
  101 
  102    void OnErase(wxEraseEvent & event);
  103    void OnPaint(wxPaintEvent & event);
  104    void OnSize(wxSizeEvent & event);
  105    void OnMouseEvent(wxMouseEvent & event);
  106 
  107    // Update the status bar message if the pointer is in the button.
  108    // Else do nothing.
  109    void UpdateStatus();
  110 
  111    void OnCaptureLost(wxMouseCaptureLostEvent & event);
  112    void OnKeyDown(wxKeyEvent & event);
  113    void OnSetFocus(wxFocusEvent & event);
  114    void OnKillFocus(wxFocusEvent & event);
  115 
  116    bool WasShiftDown(); // returns true if shift was held down
  117                                 // the last time the button was clicked
  118    bool WasControlDown(); // returns true if control was held down
  119                                   // the last time the button was clicked
  120    bool IsDown(){ return mButtonIsDown;}
  121 
  122    // Double click is detected, but not automatically cleared.
  123    bool IsDoubleClicked() const { return mIsDoubleClicked; }
  124    void ClearDoubleClicked() { mIsDoubleClicked = false; }
  125 
  126    void SetButtonToggles( bool toggler ){ mToggle = toggler;}
  127    // When click is over and mouse has moved away, a normal button
  128    // should pop up.
  129    void InteractionOver(){ if( !mToggle ) PopUp();}
  130    void Toggle(){ mButtonIsDown ? PopUp() : PushDown();}
  131    void Click();
  132    void SetShift(bool shift);
  133    void SetControl(bool control);
  134 
  135    enum AButtonState {
  136       AButtonUp,
  137       AButtonOver,
  138       AButtonDown,
  139       AButtonOverDown,
  140       AButtonDis
  141    };
  142 
  143    AButtonState GetState();
  144 
  145    void UseDisabledAsDownHiliteImage(bool flag);
  146 
  147  private:
  148    static bool s_AcceptsFocus;
  149    struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
  150    using TempAllowFocus = std::unique_ptr<bool, Resetter>;
  151 
  152  public:
  153    static TempAllowFocus TemporarilyAllowFocus();
  154 
  155  private:
  156 
  157    bool HasAlternateImages(unsigned idx);
  158 
  159    void Init(wxWindow * parent,
  160              wxWindowID id,
  161              const wxPoint & pos,
  162              const wxSize & size,
  163              ImageRoll up,
  164              ImageRoll over,
  165              ImageRoll down,
  166              ImageRoll overDown,
  167              ImageRoll dis,
  168              bool toggle);
  169 
  170    unsigned mAlternateIdx;
  171    bool mToggle;   // This bool, if true, makes the button able to
  172                    // process events when it is in the down state, and
  173                    // moving to the opposite state when it is clicked.
  174                    // It is used for the Pause button, and possibly
  175                    // others.  If false, it (should) behave just like
  176                    // a standard button.
  177 
  178    bool mWasShiftDown;
  179    bool mWasControlDown;
  180 
  181    bool mCursorIsInWindow;
  182    bool mButtonIsDown;
  183    bool mIsClicking;
  184    bool mEnabled;
  185    bool mUseDisabledAsDownHiliteImage;
  186    bool mIsDoubleClicked {};
  187 
  188    struct ImageArr { ImageRoll mArr[5]; };
  189    std::vector<ImageArr> mImages;
  190 
  191    wxRect mFocusRect;
  192    bool mForceFocusRect;
  193 
  194    std::unique_ptr<Listener> mListener;
  195 
  196 public:
  197 
  198     DECLARE_EVENT_TABLE()
  199 };
  200 
  201 #endif