Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXSlider.h

00001 /********************************************************************************
00002 *                                                                               *
00003 *                           S l i d e r   W i d g e t                           *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2002 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or                 *
00009 * modify it under the terms of the GNU Lesser General Public                    *
00010 * License as published by the Free Software Foundation; either                  *
00011 * version 2.1 of the License, or (at your option) any later version.            *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU             *
00016 * Lesser General Public License for more details.                               *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public              *
00019 * License along with this library; if not, write to the Free Software           *
00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
00021 *********************************************************************************
00022 * $Id: FXSlider.h,v 1.28 2002/09/30 13:06:56 fox Exp $                          *
00023 ********************************************************************************/
00024 #ifndef FXSLIDER_H
00025 #define FXSLIDER_H
00026 
00027 #ifndef FXFRAME_H
00028 #include "FXFrame.h"
00029 #endif
00030 
00031 namespace FX {
00032 
00033 
00034 struct FXTimer;
00035 
00036 
00037 /// Slider Control styles
00038 enum {
00039   SLIDER_HORIZONTAL   = 0,                        /// Slider shown horizontally
00040   SLIDER_VERTICAL     = 0x00008000,               /// Slider shown vertically
00041   SLIDER_ARROW_UP     = 0x00010000,               /// Slider has arrow head pointing up
00042   SLIDER_ARROW_DOWN   = 0x00020000,               /// Slider has arrow head pointing down
00043   SLIDER_ARROW_LEFT   = SLIDER_ARROW_UP,          /// Slider has arrow head pointing left
00044   SLIDER_ARROW_RIGHT  = SLIDER_ARROW_DOWN,        /// Slider has arrow head pointing right
00045   SLIDER_INSIDE_BAR   = 0x00040000,               /// Slider is inside the slot rather than overhanging
00046   SLIDER_TICKS_TOP    = 0x00080000,               /// Ticks on the top of horizontal slider
00047   SLIDER_TICKS_BOTTOM = 0x00100000,               /// Ticks on the bottom of horizontal slider
00048   SLIDER_TICKS_LEFT   = SLIDER_TICKS_TOP,         /// Ticks on the left of vertical slider
00049   SLIDER_TICKS_RIGHT  = SLIDER_TICKS_BOTTOM,      /// Ticks on the right of vertical slider
00050   SLIDER_NORMAL       = SLIDER_HORIZONTAL
00051   };
00052 
00053 
00054 
00055 /**
00056 * The slider widget is a valuator widget which provides simple linear value range.
00057 * Two visual appearances are supported:- the sunken look, which is enabled with
00058 * the SLIDER_INSIDE_BAR option and the regular look.  The latter may have optional
00059 * arrows on the slider thumb.
00060 * While being moved, the slider sends a SEL_CHANGED message to its target;
00061 * at the end of the interaction, a SEL_COMMAND message is sent.
00062 * The message data represents the current slider value, of type FXint.
00063 */
00064 class FXAPI FXSlider : public FXFrame {
00065   FXDECLARE(FXSlider)
00066 protected:
00067   FXint         range[2];                 // Reported data range
00068   FXint         pos;                      // Reported data position
00069   FXint         incr;                     // Increment when auto-sliding
00070   FXint         delta;                    // Interval between ticks
00071   FXint         headpos;                  // Head position
00072   FXint         headsize;                 // Head size
00073   FXint         slotsize;                 // Slot size
00074   FXColor       slotColor;                // Color of slot the head moves in
00075   FXTimer      *timer;                    // Timer for auto-sliding
00076   FXint         dragpoint;                // Where the head is grabbed
00077   FXString      help;                     // Help string
00078   FXString      tip;                      // Tip string
00079 protected:
00080   FXSlider();
00081   virtual void layout();
00082   FXint headPos(FXint v) const;
00083   FXint headVal(FXint p) const;
00084   void drawSliderHead(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00085   void drawHorzTicks(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00086   void drawVertTicks(FXDCWindow& dc,FXint x,FXint y,FXint w,FXint h);
00087 private:
00088   FXSlider(const FXSlider&);
00089   FXSlider &operator=(const FXSlider&);
00090 public:
00091   long onPaint(FXObject*,FXSelector,void*);
00092   long onLeftBtnPress(FXObject*,FXSelector,void*);
00093   long onLeftBtnRelease(FXObject*,FXSelector,void*);
00094   long onMiddleBtnPress(FXObject*,FXSelector,void*);
00095   long onMiddleBtnRelease(FXObject*,FXSelector,void*);
00096   long onUngrabbed(FXObject*,FXSelector,void*);
00097   long onMotion(FXObject*,FXSelector,void*);
00098   long onTimeInc(FXObject*,FXSelector,void*);
00099   long onTimeDec(FXObject*,FXSelector,void*);
00100   long onCmdSetValue(FXObject*,FXSelector,void*);
00101   long onCmdSetIntValue(FXObject*,FXSelector,void*);
00102   long onCmdGetIntValue(FXObject*,FXSelector,void*);
00103   long onCmdSetRealValue(FXObject*,FXSelector,void*);
00104   long onCmdGetRealValue(FXObject*,FXSelector,void*);
00105   long onCmdSetIntRange(FXObject*,FXSelector,void*);
00106   long onCmdGetIntRange(FXObject*,FXSelector,void*);
00107   long onCmdSetRealRange(FXObject*,FXSelector,void*);
00108   long onCmdGetRealRange(FXObject*,FXSelector,void*);
00109   long onQueryHelp(FXObject*,FXSelector,void*);
00110   long onQueryTip(FXObject*,FXSelector,void*);
00111 public:
00112   enum{
00113     ID_AUTOINC=FXFrame::ID_LAST,
00114     ID_AUTODEC,
00115     ID_LAST
00116     };
00117 public:
00118 
00119   /// Construct a slider widget
00120   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);
00121 
00122   /// Return default width
00123   virtual FXint getDefaultWidth();
00124 
00125   /// Return default height
00126   virtual FXint getDefaultHeight();
00127 
00128   /// Enable the slider
00129   virtual void enable();
00130 
00131   /// Disable the slider
00132   virtual void disable();
00133 
00134   /// Change slider value
00135   void setValue(FXint value);
00136 
00137   /// Return slider value
00138   FXint getValue() const { return pos; }
00139 
00140   /// Change the slider's range
00141   void setRange(FXint lo,FXint hi);
00142 
00143   /// Get the slider's current range
00144   void getRange(FXint& lo,FXint& hi) const { lo=range[0]; hi=range[1]; }
00145 
00146   /// Change the slider style
00147   FXuint getSliderStyle() const;
00148 
00149   /// Get the current slider style
00150   void setSliderStyle(FXuint style);
00151 
00152   /// Get the slider's head size
00153   FXint getHeadSize() const { return headsize; }
00154 
00155   /// Change the slider's head size
00156   void setHeadSize(FXint hs);
00157 
00158   /// Get the slider's current slot size
00159   FXint getSlotSize() const { return slotsize; }
00160 
00161   /// Change the slider's slot size
00162   void setSlotSize(FXint bs);
00163 
00164   /// Get the slider's auto-increment/decrement value
00165   FXint getIncrement() const { return incr; }
00166 
00167   /// Change the slider's auto-increment/decrement value
00168   void setIncrement(FXint inc);
00169 
00170   /// Change the delta between ticks
00171   void setTickDelta(FXint dist);
00172 
00173   /// Get delta between ticks
00174   FXint getTickDelta() const { return delta; }
00175 
00176   /// Change the color of the slot the slider head moves in
00177   void setSlotColor(FXColor clr);
00178 
00179   /// Get the current slot color
00180   FXColor getSlotColor() const { return slotColor; }
00181 
00182   /// Set the help text to be displayed on the status line
00183   void setHelpText(const FXString& text);
00184 
00185   /// Get the current help text
00186   const FXString& getHelpText() const { return help; }
00187 
00188   /// Set the tip text to be displayed in the tooltip
00189   void setTipText(const FXString& text);
00190 
00191   /// Get the current tooltip text value
00192   const FXString& getTipText() const { return tip; }
00193 
00194   /// Save to stream
00195   virtual void save(FXStream& store) const;
00196 
00197   /// Load from stream
00198   virtual void load(FXStream& store);
00199 
00200   /// Destroy the slider
00201   virtual ~FXSlider();
00202   };
00203 
00204 }
00205 
00206 #endif