00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : VSG (MMM YYYY) 00022 **=======================================================================*/ 00023 00024 00025 #ifndef _SO_WIN_SLIDER_ 00026 #define _SO_WIN_SLIDER_ 00027 00028 #include <Inventor/Win/SoWinBeginStrict.h> 00029 #include <Inventor/misc/SoCallbackList.h> 00030 #include <Inventor/Win/SoWinGDIWidget.h> 00031 00032 class SoFloatCallbackList; 00033 class SoWinMouse; 00034 00035 // callback function prototypes 00036 typedef void SoWinSliderCB(void *userData, float val); 00037 00039 // 00040 // Class: SoWinSlider 00041 // 00042 // This is the basic slider type, which lets you set the slider value and 00043 // register callbacks when the slider is being moved (either as soon as the 00044 // slider changes values, or when the slider has stopped moving (mouse up)). 00045 // 00047 00048 { 00049 public: 00050 00051 // constructor/destructor 00052 SoWinSlider(SoWidget parent = NULL, 00053 const char *name = NULL, 00054 SbBool buildInsideParent = TRUE); 00055 ~SoWinSlider(); 00056 00057 // 00058 // Those routines are used to specify the slider value (which is automatically 00059 // reflected in the slider) and get the current value. 00060 // 00061 // NOTE: setValue() will call valueChanged callbacks if the value differs. 00062 // 00063 // NOTE: currently only values [0.0 , 1.0] are supported 00064 // 00065 void setValue(float v, SbBool updateText = TRUE); 00066 float getValue() const { return value; } 00067 00068 // 00069 // Specifies the label string which appears before the slider. A NULL 00070 // string will remove the label altogether. (default behavior) 00071 // 00072 void setLabel(const char *newlabel); 00073 const char *getLabel() const { return labelStr; } 00074 00075 // 00076 // Display a numeric value in a text field to the right of the slider 00077 // which can be edited to change the value of the slider. 00078 // Default is TRUE (display the numeric value). 00079 // 00080 void setNumericFieldVisible(SbBool b); 00081 SbBool isNumericFieldVisible() const { return numberVisible; } 00082 00083 // 00084 // Those routines are used to register callbacks for the different slider 00085 // actions. 00086 // 00087 // NOTE: the start and finish callbacks are only to signal when the mouse 00088 // goes down and up. No valid callback data is passed (0.0 passed). 00089 // 00090 void addStartCallback(SoWinSliderCB *f, void *userData = NULL); 00091 void addValueChangedCallback( SoWinSliderCB *f, void *userData = NULL); 00092 void addFinishCallback(SoWinSliderCB *f, void *userData = NULL); 00093 00094 void removeStartCallback(SoWinSliderCB *f, void *userData = NULL); 00095 void removeValueChangedCallback(SoWinSliderCB *f, void *userData = NULL); 00096 void removeFinishCallback(SoWinSliderCB *f, void *userData = NULL); 00097 00098 // true while the value is changing interactively 00099 void interactivity( SbBool flag ) { interactive = flag; } 00100 SbBool isInteractive() { return interactive; } 00101 00102 // sets/gets the size of the actual slider, excluding the label and 00103 // text field widget sizes which are fixed in size. 00104 // 00105 // This is the prefered behavior since it allows a user to align 00106 // multiple sliders (same size) regardless of the text label size 00107 // (which are usually different). 00108 // 00109 // NOTE: this is different from most widgets, which do resize their 00110 // container widgets. This functionality can still be achieved using 00111 // the setSize() and getSize() methods. 00112 // 00113 void setSliderSize(const SbVec2s &size); 00114 SbVec2s getSliderSize(); 00115 00116 void setNumberWidget(SoWidget hWnd) {numberWidget = hWnd;}; 00117 SoWidget getNumberWidget() {return numberWidget;} ; 00118 static void textFieldCB(SoWinSlider *p,SoWidget hCtrl); 00119 00120 private: 00121 00122 // This constructor takes a boolean whether to build the widget now. 00123 // Subclasses can pass FALSE, then call SoWinSlider::buildWidget() 00124 // when they are ready for it to be built. 00125 SoEXTENDER 00126 SoWinSlider(SoWidget parent, 00127 const char *name, 00128 SbBool buildInsideParent, 00129 SbBool buildNow); 00130 00131 // redefine these to do slider specific things 00132 virtual void redraw(); 00133 virtual void processEvent(XAnyEvent *anyevent); 00134 virtual void sizeChanged(const SbVec2s &newSize); 00135 00136 SoWidget buildWidget(SoWidget parent); 00137 00138 // 00139 // this is the routine subclasses would redefine to change the look of 00140 // the actual slider top region, which defaults to grey with a thin white marker. 00141 // 00142 virtual void drawSliderTopRegion(); 00143 00144 // slider top region area (used by subclasses to do their own 00145 // drawings in there). 00146 short slx1, sly1, slx2, sly2; 00147 short thumx1, thumy1, thumx2, thumy2; 00148 00149 private: 00150 00151 SoWidget mgrWidget, numberWidget, sliderWidget, labelWidget; 00152 SbBool numberVisible; // whether numeric field is visible 00153 char *labelStr; // label preceeding slider 00154 SbVec2s sliderSize; // size of the 'widget' and 'shell' 00155 SoWinMouse *mouse; 00156 00157 // slider local variables (slider value, thum position) 00158 float value; 00159 short position, posdiff; 00160 00161 // build routines 00162 void doLabelLayout(); 00163 void doNumberLayout(); 00164 00165 // callback variables 00166 SoFloatCallbackList *startCallbacks; 00167 SoFloatCallbackList *changedCallbacks; 00168 SoFloatCallbackList *finishCallbacks; 00169 SbBool interactive; 00170 00171 // this is called by both constructors 00172 void constructorCommon(SbBool buildNow); 00173 00174 }; 00175 00176 #include <Inventor/Win/SoWinEndStrict.h> 00177 00178 #endif /* _SO_WIN_SLIDER_ */ 00179 00180 00181