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

numberrange_b.h

Go to the documentation of this file.
00001 /*
00002     File        : numberrange_b.h
00003     Date        : 19-Sep-02
00004     Description : Base class to represent a number range toolbox gadget.
00005 
00006     Copyright © 1995-2002 Alexander Thoukydides
00007 
00008     This program is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU General Public License
00010     as published by the Free Software Foundation; either version 2
00011     of the License, or (at your option) any later version.
00012 
00013     This program 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
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
00021 */
00022 
00023 // Only include header file once
00024 #ifndef numberrange_b_h
00025 #define numberrange_b_h
00026 
00027 // Include oslib header files
00028 #include "oslib/numberrange.h"
00029 
00030 // Include alexlib header files
00031 #ifndef gadget_b_h
00032 #include "gadget_b.h"
00033 #endif
00034 #ifndef gadget_w_justification_h
00035 #include "gadget_w_justification.h"
00036 #endif
00037 #ifndef gadget_w_slider_h
00038 #include "gadget_w_slider.h"
00039 #endif
00040 
00041 // A base class to represent a number range gadget
00042 class numberrange_b : public virtual gadget_b,
00043                       public gadget_w_justification,
00044                       public gadget_w_slider
00045 {
00046 public:
00047 
00048     // Possible field alignments
00049     enum slider_type
00050     {
00051         slider_none,
00052         slider_right,
00053         slider_left
00054     };
00055 
00056     // Possible rounding modes
00057     enum rounding_mode
00058     {
00059         nearest,
00060         positive,
00061         negative,
00062         zero
00063     };
00064 
00065     /*
00066         Parameters  : generate  - The generate event status.
00067         Returns     : void
00068         Description : Set the NumberRange_ValueChanged event status.
00069     */
00070     void set_generate_value_changed(bool generate = TRUE);
00071 
00072     /*
00073         Parameters  : void
00074         Returns     : bool  - The generate event status.
00075         Description : Get the NumberRange_ValueChanged event status.
00076     */
00077     bool get_generate_value_changed() const;
00078 
00079     /*
00080         Parameters  : writable  - Is the field writable.
00081         Returns     : void
00082         Description : Set whether the numeric field is writable.
00083     */
00084     void set_writable(bool writable = TRUE);
00085 
00086     /*
00087         Parameters  : void
00088         Returns     : bool  - Is the field writable.
00089         Description : Get whether the numeric field is writable.
00090     */
00091     bool get_writable() const;
00092 
00093     /*
00094         Parameters  : display   - Is there a display area.
00095         Returns     : void
00096         Description : Set whether there is a diplay area.
00097     */
00098     void set_has_display(bool display = TRUE);
00099 
00100     /*
00101         Parameters  : void
00102         Returns     : bool  - Is there a display area.
00103         Description : Get whether there is a diplay area.
00104     */
00105     bool get_has_display() const;
00106 
00107     /*
00108         Parameters  : adjusters - Are there adjuster arrows.
00109         Returns     : void
00110         Description : Set whether there are adjuster arrows.
00111     */
00112     void set_has_adjusters(bool adjusters = TRUE);
00113 
00114     /*
00115         Parameters  : void
00116         Returns     : bool  - Are there adjuster arrows.
00117         Description : Get whether there are adjuster arrows.
00118     */
00119     bool get_has_adjusters() const;
00120 
00121     /*
00122         Parameters  : slider    - The type of slider.
00123         Returns     : void
00124         Description : Set the type of slider, if any.
00125     */
00126     void set_slider_type(slider_type slider = slider_none);
00127 
00128     /*
00129         Parameters  : void
00130         Returns     : slider_type   - The type of slider.
00131         Description : Get the type of slider, if any.
00132     */
00133     slider_type get_slider_type() const;
00134 
00135     /*
00136         Parameters  : precision - The precision.
00137         Returns     : void
00138         Description : Set the precision.
00139     */
00140     void set_precision(int precision);
00141 
00142     /*
00143         Parameters  : void
00144         Returns     : int   - The precision.
00145         Description : Get the precision.
00146     */
00147     int get_precision() const;
00148 
00149     /*
00150         Parameters  : value     - The value.
00151                       rounding  - The optional rounding mode.
00152         Returns     : void
00153         Description : Set the value scaled as displayed.
00154     */
00155     void set_value_scaled(double value, rounding_mode rounding = nearest);
00156 
00157     /*
00158         Parameters  : void
00159         Returns     : double    - The value.
00160         Description : Get the value scaled as displayed.
00161     */
00162     double get_value_scaled() const;
00163 
00164     /*
00165         Parameters  : lower     - The lower bound.
00166                       rounding  - The optional rounding mode.
00167         Returns     : void
00168         Description : Set the lower bound scaled as displayed.
00169     */
00170     void set_lower_bound_scaled(double lower, rounding_mode rounding = nearest);
00171 
00172     /*
00173         Parameters  : void
00174         Returns     : double    - The value.
00175         Description : Get the lower bound scaled as displayed.
00176     */
00177     double get_lower_bound_scaled() const;
00178 
00179     /*
00180         Parameters  : upper     - The lower bound.
00181                       rounding  - The optional rounding mode.
00182         Returns     : void
00183         Description : Set the upper bound scaled as displayed.
00184     */
00185     void set_upper_bound_scaled(double upper, rounding_mode rounding = nearest);
00186 
00187     /*
00188         Parameters  : void
00189         Returns     : double    - The value.
00190         Description : Get the upper bound scaled as displayed.
00191     */
00192     double get_upper_bound_scaled() const;
00193 
00194     /*
00195         Parameters  : step      - The step size.
00196                       rounding  - The optional rounding mode.
00197         Returns     : void
00198         Description : Set the step size scaled as displayed.
00199     */
00200     void set_step_size_scaled(double step, rounding_mode rounding = nearest);
00201 
00202     /*
00203         Parameters  : void
00204         Returns     : double    - The value.
00205         Description : Get the step size scaled as displayed.
00206     */
00207     double get_step_size_scaled() const;
00208 
00209     /*
00210         Parameters  : value         - The number to set.
00211         Returns     : numberrange_b - This object.
00212         Description : Set the value of this gadget. To reduce flicker the value
00213                       is not updated unless it has changed.
00214     */
00215     numberrange_b &operator=(int value);
00216 
00217 protected:
00218 
00219     /*
00220         Parameters  : position  - The field justification.
00221         Returns     : void
00222         Description : Gadget specific function to set the justification.
00223     */
00224     virtual void _set_justification(justification position);
00225 
00226     /*
00227         Parameters  : void
00228         Returns     : bool  - The field justification.
00229         Description : Gadget specific function to Get the justification.
00230     */
00231     virtual justification _get_justification() const;
00232 
00233     /*
00234         Parameters  : colour    - The slider colour.
00235         Returns     : void
00236         Description : Gadget specific function to set the colour of the slider.
00237     */
00238     virtual void _set_slider_colour(wimp_colour colour);
00239 
00240     /*
00241         Parameters  : void
00242         Returns     : wimp_colour   - The slider colour.
00243         Description : Gadget specific function to get the colour of the slider.
00244     */
00245     virtual wimp_colour _get_slider_colour() const;
00246 
00247     /*
00248         Parameters  : colour    - The well colour.
00249         Returns     : void
00250         Description : Gadget specific function to set the colour of the well.
00251     */
00252     virtual void _set_well_colour(wimp_colour colour);
00253 
00254     /*
00255         Parameters  : void
00256         Returns     : wimp_colour   - The well colour.
00257         Description : Gadget specific function to get the colour of the well.
00258     */
00259     virtual wimp_colour _get_well_colour() const;
00260 
00261     /*
00262         Parameters  : precision - The precision.
00263         Returns     : void
00264         Description : Set the precision.
00265     */
00266     virtual void _set_precision(int precision) = 0;
00267 
00268     /*
00269         Parameters  : void
00270         Returns     : int   - The precision.
00271         Description : Get the precision.
00272     */
00273     virtual int _get_precision() const = 0;
00274 
00275 private:
00276 
00277     /*
00278         Parameters  : value     - The floating point value to scale.
00279                       rounding  - The required rounding mode.
00280         Returns     : int       - The scaled and rounded value.
00281         Description : Scale the specified value according to the current
00282                       precision and round to an integer.
00283     */
00284     int scale(double value, rounding_mode rounding) const;
00285 
00286     /*
00287         Parameters  : value     - The integer value to scale.
00288         Returns     : double    - The scaled.
00289         Description : Scale the specified value according to the current
00290                       precision.
00291     */
00292     double scale(int value) const;
00293 };
00294 
00295 /*
00296     Parameters  : generate  - The generate event status.
00297     Returns     : void
00298     Description : Set the NumberRange_ValueChanged event status.
00299 */
00300 inline void numberrange_b::set_generate_value_changed(bool generate)
00301 {
00302     gadget_flags flags = _get_flags();
00303     _set_flags(generate
00304                ? flags | numberrange_GENERATE_VALUE_CHANGED
00305                : flags & ~numberrange_GENERATE_VALUE_CHANGED);
00306 }
00307 
00308 /*
00309     Parameters  : void
00310     Returns     : bool  - The generate event status.
00311     Description : Get the NumberRange_ValueChanged event status.
00312 */
00313 inline bool numberrange_b::get_generate_value_changed() const
00314 {
00315     return BOOL(_get_flags() & numberrange_GENERATE_VALUE_CHANGED);
00316 }
00317 
00318 /*
00319     Parameters  : writable  - Is the field writable.
00320     Returns     : void
00321     Description : Set whether the numeric field is writable.
00322 */
00323 inline void numberrange_b::set_writable(bool writable)
00324 {
00325     gadget_flags flags = _get_flags();
00326     _set_flags(writable
00327                ? flags | numberrange_WRITABLE
00328                : flags & ~numberrange_WRITABLE);
00329 }
00330 
00331 /*
00332     Parameters  : void
00333     Returns     : bool  - Is the field writable.
00334     Description : Get whether the numeric field is writable.
00335 */
00336 inline bool numberrange_b::get_writable() const
00337 {
00338     return BOOL(_get_flags() & numberrange_WRITABLE);
00339 }
00340 
00341 /*
00342     Parameters  : display   - Is there a display area.
00343     Returns     : void
00344     Description : Set whether there is a diplay area.
00345 */
00346 inline void numberrange_b::set_has_display(bool display)
00347 {
00348     gadget_flags flags = _get_flags();
00349     _set_flags(display
00350                ? flags | numberrange_HAS_NUMERICAL_DISPLAY
00351                : flags & ~numberrange_HAS_NUMERICAL_DISPLAY);
00352 }
00353 
00354 /*
00355     Parameters  : void
00356     Returns     : bool  - Is there a display area.
00357     Description : Get whether there is a diplay area.
00358 */
00359 inline bool numberrange_b::get_has_display() const
00360 {
00361     return BOOL(_get_flags() & numberrange_HAS_NUMERICAL_DISPLAY);
00362 }
00363 
00364 /*
00365     Parameters  : adjusters - Are there adjuster arrows.
00366     Returns     : void
00367     Description : Set whether there are adjuster arrows.
00368 */
00369 inline void numberrange_b::set_has_adjusters(bool adjusters)
00370 {
00371     gadget_flags flags = _get_flags();
00372     _set_flags(adjusters
00373                ? flags | numberrange_ADJUSTERS
00374                : flags & ~numberrange_ADJUSTERS);
00375 }
00376 
00377 /*
00378     Parameters  : void
00379     Returns     : bool  - Are there adjuster arrows.
00380     Description : Get whether there are adjuster arrows.
00381 */
00382 inline bool numberrange_b::get_has_adjusters() const
00383 {
00384     return BOOL(_get_flags() & numberrange_ADJUSTERS);
00385 }
00386 
00387 /*
00388     Parameters  : slider    - The type of slider.
00389     Returns     : void
00390     Description : Set the type of slider, if any.
00391 */
00392 inline void numberrange_b::set_slider_type(slider_type slider)
00393 {
00394     gadget_flags flags = _get_flags() & ~numberrange_SLIDER_TYPE;
00395     if (slider == slider_right)
00396     {
00397         flags |= numberrange_SLIDER_TYPE_RIGHT << numberrange_SLIDER_TYPE_SHIFT;
00398     }
00399     else if (slider == slider_left)
00400     {
00401         flags |= numberrange_SLIDER_TYPE_LEFT << numberrange_SLIDER_TYPE_SHIFT;
00402     }
00403     _set_flags(flags);
00404 }
00405 
00406 /*
00407     Parameters  : void
00408     Returns     : slider_type   - The type of slider.
00409     Description : Get the type of slider, if any.
00410 */
00411 inline numberrange_b::slider_type numberrange_b::get_slider_type() const
00412 {
00413     gadget_flags flags = _get_flags() >> numberrange_SLIDER_TYPE_SHIFT;
00414     return  flags & numberrange_SLIDER_TYPE_RIGHT
00415             ? slider_right
00416             : (flags & numberrange_SLIDER_TYPE_LEFT
00417                ? slider_left : slider_none);
00418 }
00419 
00420 /*
00421     Parameters  : precision - The precision.
00422     Returns     : void
00423     Description : Set the precision.
00424 */
00425 inline void numberrange_b::set_precision(int precision)
00426 {
00427     _set_precision(precision);
00428 }
00429 
00430 /*
00431     Parameters  : void
00432     Returns     : int   - The precision.
00433     Description : Get the precision.
00434 */
00435 inline int numberrange_b::get_precision() const
00436 {
00437     return _get_precision();
00438 }
00439 
00440 /*
00441     Parameters  : value     - The value.
00442                   rounding  - The optional rounding mode.
00443     Returns     : void
00444     Description : Set the value scaled as displayed.
00445 */
00446 inline void numberrange_b::set_value_scaled(double value,
00447                                             rounding_mode rounding)
00448 {
00449     _set_value(scale(value, rounding));
00450 }
00451 
00452 /*
00453     Parameters  : void
00454     Returns     : double    - The value.
00455     Description : Get the value scaled as displayed.
00456 */
00457 inline double numberrange_b::get_value_scaled() const
00458 {
00459     return scale(_get_value());
00460 }
00461 
00462 /*
00463     Parameters  : lower     - The lower bound.
00464                   rounding  - The optional rounding mode.
00465     Returns     : void
00466     Description : Set the lower bound scaled as displayed.
00467 */
00468 inline void numberrange_b::set_lower_bound_scaled(double lower,
00469                                                   rounding_mode rounding)
00470 {
00471     _set_lower_bound(scale(lower, rounding));
00472 }
00473 
00474 /*
00475     Parameters  : void
00476     Returns     : double    - The value.
00477     Description : Get the lower bound scaled as displayed.
00478 */
00479 inline double numberrange_b::get_lower_bound_scaled() const
00480 {
00481     return scale(_get_lower_bound());
00482 }
00483 
00484 /*
00485     Parameters  : upper     - The lower bound.
00486                   rounding  - The optional rounding mode.
00487     Returns     : void
00488     Description : Set the upper bound scaled as displayed.
00489 */
00490 inline void numberrange_b::set_upper_bound_scaled(double upper,
00491                                                   rounding_mode rounding)
00492 {
00493     _set_upper_bound(scale(upper, rounding));
00494 }
00495 
00496 /*
00497     Parameters  : void
00498     Returns     : double    - The value.
00499     Description : Get the upper bound scaled as displayed.
00500 */
00501 inline double numberrange_b::get_upper_bound_scaled() const
00502 {
00503     return scale(_get_upper_bound());
00504 }
00505 
00506 /*
00507     Parameters  : step      - The step size.
00508                   rounding  - The optional rounding mode.
00509     Returns     : void
00510     Description : Set the step size scaled as displayed.
00511 */
00512 inline void numberrange_b::set_step_size_scaled(double step,
00513                                                 rounding_mode rounding)
00514 {
00515     _set_step_size(scale(step, rounding));
00516 }
00517 
00518 /*
00519     Parameters  : void
00520     Returns     : double    - The value.
00521     Description : Get the step size scaled as displayed.
00522 */
00523 inline double numberrange_b::get_step_size_scaled() const
00524 {
00525     return scale(_get_step_size());
00526 }
00527 
00528 #endif

Generated on Sun Jan 26 10:18:44 2025 for NBLib by doxygen 1.3.3