1 /******************************************************************************** 2 * * 3 * S l i d e r W i d g e t * 4 * * 5 ********************************************************************************* 6 * Copyright (C) 1997,2005 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.40 2005/01/16 16:06:06 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 onLeftBtnPress(FXObject*,FXSelector,void*); 85 long onLeftBtnRelease(FXObject*,FXSelector,void*); 86 long onMiddleBtnPress(FXObject*,FXSelector,void*); 87 long onMiddleBtnRelease(FXObject*,FXSelector,void*); 88 long onMouseWheel(FXObject*,FXSelector,void*); 89 long onUngrabbed(FXObject*,FXSelector,void*); 90 long onMotion(FXObject*,FXSelector,void*); 91 long onAutoSlide(FXObject*,FXSelector,void*); 92 long onCmdSetValue(FXObject*,FXSelector,void*); 93 long onCmdSetIntValue(FXObject*,FXSelector,void*); 94 long onCmdGetIntValue(FXObject*,FXSelector,void*); 95 long onCmdSetRealValue(FXObject*,FXSelector,void*); 96 long onCmdGetRealValue(FXObject*,FXSelector,void*); 97 long onCmdSetIntRange(FXObject*,FXSelector,void*); 98 long onCmdGetIntRange(FXObject*,FXSelector,void*); 99 long onCmdSetRealRange(FXObject*,FXSelector,void*); 100 long onCmdGetRealRange(FXObject*,FXSelector,void*); 101 long onCmdSetHelp(FXObject*,FXSelector,void*); 102 long onCmdGetHelp(FXObject*,FXSelector,void*); 103 long onCmdSetTip(FXObject*,FXSelector,void*); 104 long onCmdGetTip(FXObject*,FXSelector,void*); 105 long onQueryHelp(FXObject*,FXSelector,void*); 106 long onQueryTip(FXObject*,FXSelector,void*); 107 public: 108 enum{ 109 ID_AUTOSLIDE=FXFrame::ID_LAST, 110 ID_LAST 111 }; 112 public: 113 114 /// Construct a slider widget 115 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); 116 117 /// Return default width 118 virtual FXint getDefaultWidth(); 119 120 /// Return default height 121 virtual FXint getDefaultHeight(); 122 123 /// Perform layout 124 virtual void layout(); 125 126 /// Enable the slider 127 virtual void enable(); 128 129 /// Disable the slider 130 virtual void disable(); 131 132 /// Change slider value 133 void setValue(FXint value); 134 135 /// Return slider value getValue()136 FXint getValue() const { return pos; } 137 138 /// Change the slider's range 139 void setRange(FXint lo,FXint hi); 140 141 /// Get the slider's current range getRange(FXint & lo,FXint & hi)142 void getRange(FXint& lo,FXint& hi) const { lo=range[0]; hi=range[1]; } 143 144 /// Change the slider style 145 FXuint getSliderStyle() const; 146 147 /// Get the current slider style 148 void setSliderStyle(FXuint style); 149 150 /// Get the slider's head size getHeadSize()151 FXint getHeadSize() const { return headsize; } 152 153 /// Change the slider's head size 154 void setHeadSize(FXint hs); 155 156 /// Get the slider's current slot size getSlotSize()157 FXint getSlotSize() const { return slotsize; } 158 159 /// Change the slider's slot size 160 void setSlotSize(FXint bs); 161 162 /// Get the slider's auto-increment/decrement value getIncrement()163 FXint getIncrement() const { return incr; } 164 165 /// Change the slider's auto-increment/decrement value 166 void setIncrement(FXint inc); 167 168 /// Change the delta between ticks 169 void setTickDelta(FXint dist); 170 171 /// Get delta between ticks getTickDelta()172 FXint getTickDelta() const { return delta; } 173 174 /// Change the color of the slot the slider head moves in 175 void setSlotColor(FXColor clr); 176 177 /// Get the current slot color getSlotColor()178 FXColor getSlotColor() const { return slotColor; } 179 180 /// Set the help text to be displayed on the status line setHelpText(const FXString & text)181 void setHelpText(const FXString& text){ help=text; } 182 183 /// Get the current help text getHelpText()184 const FXString& getHelpText() const { return help; } 185 186 /// Set the tip text to be displayed in the tooltip setTipText(const FXString & text)187 void setTipText(const FXString& text){ tip=text; } 188 189 /// Get the current tooltip text value getTipText()190 const FXString& getTipText() const { return tip; } 191 192 /// Save to stream 193 virtual void save(FXStream& store) const; 194 195 /// Load from stream 196 virtual void load(FXStream& store); 197 198 /// Destroy the slider 199 virtual ~FXSlider(); 200 }; 201 202 } 203 204 #endif 205