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