1 /******************************************************************************** 2 * * 3 * S l i d e r W i d g e t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2020 by Jeroen van der Zijp. All Rights Reserved. * 7 ********************************************************************************* 8 * This library is free software; you can redistribute it and/or modify * 9 * it under the terms of the GNU Lesser General Public License as published by * 10 * the Free Software Foundation; either version 3 of the License, or * 11 * (at your option) any later version. * 12 * * 13 * This library is distributed in the hope that it will be useful, * 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 16 * GNU Lesser General Public License for more details. * 17 * * 18 * You should have received a copy of the GNU Lesser General Public License * 19 * along with this program. If not, see <http://www.gnu.org/licenses/> * 20 ********************************************************************************/ 21 #ifndef FXSLIDER_H 22 #define FXSLIDER_H 23 24 #ifndef FXFRAME_H 25 #include "FXFrame.h" 26 #endif 27 28 namespace FX { 29 30 31 /// Slider Control styles 32 enum { 33 SLIDER_HORIZONTAL = 0, /// Slider shown horizontally 34 SLIDER_VERTICAL = 0x00008000, /// Slider shown vertically 35 SLIDER_ARROW_UP = 0x00010000, /// Slider has arrow head pointing up 36 SLIDER_ARROW_DOWN = 0x00020000, /// Slider has arrow head pointing down 37 SLIDER_ARROW_LEFT = SLIDER_ARROW_UP, /// Slider has arrow head pointing left 38 SLIDER_ARROW_RIGHT = SLIDER_ARROW_DOWN, /// Slider has arrow head pointing right 39 SLIDER_INSIDE_BAR = 0x00040000, /// Slider is inside the slot rather than overhanging 40 SLIDER_TICKS_TOP = 0x00080000, /// Ticks on the top of horizontal slider 41 SLIDER_TICKS_BOTTOM = 0x00100000, /// Ticks on the bottom of horizontal slider 42 SLIDER_TICKS_LEFT = SLIDER_TICKS_TOP, /// Ticks on the left of vertical slider 43 SLIDER_TICKS_RIGHT = SLIDER_TICKS_BOTTOM, /// Ticks on the right of vertical slider 44 SLIDER_NORMAL = SLIDER_HORIZONTAL 45 }; 46 47 48 /** 49 * The slider widget is a valuator widget which provides simple linear value range. 50 * Two visual appearances are supported:- the sunken look, which is enabled with 51 * the SLIDER_INSIDE_BAR option and the regular look. The latter may have optional 52 * arrows on the slider thumb. 53 * While being moved, the slider sends a SEL_CHANGED message to its target; 54 * at the end of the interaction, a SEL_COMMAND message is sent. 55 * The message data represents the current slider value, of type FXint. 56 */ 57 class FXAPI FXSlider : public FXFrame { 58 FXDECLARE(FXSlider) 59 protected: 60 FXint headPos; // Head position 61 FXint headSize; // Head size 62 FXint slotSize; // Slot size 63 FXColor slotColor; // Color of slot the head moves in 64 FXint dragPoint; // Where the head is grabbed 65 FXint range[2]; // Reported data range 66 FXint delta; // Interval between ticks 67 FXint incr; // Increment when auto-sliding 68 FXint pos; // Reported data position 69 FXString help; // Help string 70 FXString tip; // Tip string 71 protected: 72 FXSlider(); 73 void drawSliderHead(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 74 void drawHorzTicks(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 75 void drawVertTicks(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h); 76 private: 77 FXSlider(const FXSlider&); 78 FXSlider &operator=(const FXSlider&); 79 public: 80 long onPaint(FXObject*,FXSelector,void*); 81 long onMotion(FXObject*,FXSelector,void*); 82 long onMouseWheel(FXObject*,FXSelector,void*); 83 long onLeftBtnPress(FXObject*,FXSelector,void*); 84 long onLeftBtnRelease(FXObject*,FXSelector,void*); 85 long onMiddleBtnPress(FXObject*,FXSelector,void*); 86 long onMiddleBtnRelease(FXObject*,FXSelector,void*); 87 long onKeyPress(FXObject*,FXSelector,void*); 88 long onKeyRelease(FXObject*,FXSelector,void*); 89 long onUngrabbed(FXObject*,FXSelector,void*); 90 long onAutoSlide(FXObject*,FXSelector,void*); 91 long onCmdSetValue(FXObject*,FXSelector,void*); 92 long onCmdSetIntValue(FXObject*,FXSelector,void*); 93 long onCmdGetIntValue(FXObject*,FXSelector,void*); 94 long onCmdSetLongValue(FXObject*,FXSelector,void*); 95 long onCmdGetLongValue(FXObject*,FXSelector,void*); 96 long onCmdSetRealValue(FXObject*,FXSelector,void*); 97 long onCmdGetRealValue(FXObject*,FXSelector,void*); 98 long onCmdSetIntRange(FXObject*,FXSelector,void*); 99 long onCmdGetIntRange(FXObject*,FXSelector,void*); 100 long onCmdSetRealRange(FXObject*,FXSelector,void*); 101 long onCmdGetRealRange(FXObject*,FXSelector,void*); 102 long onCmdSetHelp(FXObject*,FXSelector,void*); 103 long onCmdGetHelp(FXObject*,FXSelector,void*); 104 long onCmdSetTip(FXObject*,FXSelector,void*); 105 long onCmdGetTip(FXObject*,FXSelector,void*); 106 long onQueryHelp(FXObject*,FXSelector,void*); 107 long onQueryTip(FXObject*,FXSelector,void*); 108 public: 109 enum{ 110 ID_AUTOSLIDE=FXFrame::ID_LAST, 111 ID_LAST 112 }; 113 public: 114 115 /// Construct a slider widget 116 FXSlider(FXComposite* p,FXObject* tgt=NULL,FXSelector sel=0,FXuint opts=SLIDER_NORMAL,FXint x=0,FXint y=0,FXint w=0,FXint h=0,FXint pl=0,FXint pr=0,FXint pt=0,FXint pb=0); 117 118 /// Return default width 119 virtual FXint getDefaultWidth(); 120 121 /// Return default height 122 virtual FXint getDefaultHeight(); 123 124 /// Returns true because a slider can receive focus 125 virtual FXbool canFocus() const; 126 127 /// Perform layout 128 virtual void layout(); 129 130 /// Enable the slider 131 virtual void enable(); 132 133 /// Disable the slider 134 virtual void disable(); 135 136 /// Change slider value 137 void setValue(FXint value,FXbool notify=false); 138 139 /// Return slider value getValue()140 FXint getValue() const { return pos; } 141 142 /// Change the slider's range 143 void setRange(FXint lo,FXint hi,FXbool notify=false); 144 145 /// Get the slider's current range getRange(FXint & lo,FXint & hi)146 void getRange(FXint& lo,FXint& hi) const { lo=range[0]; hi=range[1]; } 147 148 /// Change the slider style 149 FXuint getSliderStyle() const; 150 151 /// Get the current slider style 152 void setSliderStyle(FXuint style); 153 154 /// Get the slider's head size getHeadSize()155 FXint getHeadSize() const { return headSize; } 156 157 /// Change the slider's head size 158 void setHeadSize(FXint hs); 159 160 /// Get the slider's current slot size getSlotSize()161 FXint getSlotSize() const { return slotSize; } 162 163 /// Change the slider's slot size 164 void setSlotSize(FXint bs); 165 166 /// Get the slider's auto-increment/decrement value getIncrement()167 FXint getIncrement() const { return incr; } 168 169 /// Change the slider's auto-increment/decrement value 170 void setIncrement(FXint inc); 171 172 /// Change the delta between ticks 173 void setTickDelta(FXint dist); 174 175 /// Get delta between ticks getTickDelta()176 FXint getTickDelta() const { return delta; } 177 178 /// Change the color of the slot the slider head moves in 179 void setSlotColor(FXColor clr); 180 181 /// Get the current slot color getSlotColor()182 FXColor getSlotColor() const { return slotColor; } 183 184 /// Set the help text to be displayed on the status line setHelpText(const FXString & text)185 void setHelpText(const FXString& text){ help=text; } 186 187 /// Get the current help text getHelpText()188 const FXString& getHelpText() const { return help; } 189 190 /// Set the tip text to be displayed in the tooltip setTipText(const FXString & text)191 void setTipText(const FXString& text){ tip=text; } 192 193 /// Get the current tooltip text value getTipText()194 const FXString& getTipText() const { return tip; } 195 196 /// Save to stream 197 virtual void save(FXStream& store) const; 198 199 /// Load from stream 200 virtual void load(FXStream& store); 201 202 /// Destroy the slider 203 virtual ~FXSlider(); 204 }; 205 206 } 207 208 #endif 209