summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlbrecht Schlosser <albrechts.fltk@online.de>2017-03-09 22:08:29 +0000
committerAlbrecht Schlosser <albrechts.fltk@online.de>2017-03-09 22:08:29 +0000
commit7123b78f3fd6758421f46a9fe735cb7de6bc6904 (patch)
treef42bbee0143517f09dc8aec912335e0a9ab86172
parentfdee9dbf5d3d90e1258fb110fe7ce8d09e818d0d (diff)
Separated Fl_Spinner.H and Fl_Spinner.cxx (STR #2776).
Also removed deprecated (misspelled) method names mininum() and maxinum(). git-svn-id: file:///fltk/svn/fltk/branches/branch-1.4@12189 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
-rw-r--r--CHANGES5
-rw-r--r--FL/Fl_Spinner.H264
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Fl_Group.cxx28
-rw-r--r--src/Fl_Spinner.cxx194
-rw-r--r--src/Makefile3
6 files changed, 285 insertions, 210 deletions
diff --git a/CHANGES b/CHANGES
index 84d3df40a..d42c83f9c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -45,8 +45,9 @@ Changes in FLTK 1.4.0 Released: ??? ?? 2017
Other Improvements
- (add new items here)
- - Renamed test/help demo program to test/help_dialog to avoid name
- conflict with CMake auto-generated target 'help'.
+ - Separated Fl_Spinner.H and Fl_Spinner.cxx (STR #2776).
+ - Renamed test/help.cxx demo program to test/help_dialog.cxx to avoid
+ name conflict with CMake auto-generated target 'help'.
- Many documentation fixes, clarifications, and enhancements.
diff --git a/FL/Fl_Spinner.H b/FL/Fl_Spinner.H
index 10df08613..107bebb3b 100644
--- a/FL/Fl_Spinner.H
+++ b/FL/Fl_Spinner.H
@@ -3,7 +3,7 @@
//
// Spinner widget for the Fast Light Tool Kit (FLTK).
//
-// Copyright 1998-2016 by Bill Spitzak and others.
+// Copyright 1998-2017 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
@@ -20,237 +20,143 @@
Fl_Spinner widget . */
#ifndef Fl_Spinner_H
-# define Fl_Spinner_H
-
-//
-// Include necessary headers...
-//
-
-# include <FL/Enumerations.H>
-# include <FL/Fl_Group.H>
-# include <FL/Fl_Input.H>
-# include <FL/Fl_Repeat_Button.H>
-# include <stdio.h>
-# include <stdlib.h>
+#define Fl_Spinner_H
+#include <FL/Enumerations.H>
+#include <FL/Fl_Group.H>
+#include <FL/Fl_Input.H>
+#include <FL/Fl_Repeat_Button.H>
/**
- This widget is a combination of the input
- widget and repeat buttons. The user can either type into the
- input area or use the buttons to change the value.
+ This widget is a combination of a numerical input widget and repeat buttons.
+
+ The user can either type into the input area or use the buttons to
+ change the value.
\image html Fl_Spinner.png "Fl_Spinner widget"
\image latex Fl_Spinner.png "Fl_Spinner widget" width=6cm
*/
class FL_EXPORT Fl_Spinner : public Fl_Group {
-
+
double value_; // Current value
double minimum_; // Minimum value
double maximum_; // Maximum value
double step_; // Amount to add/subtract for up/down
- const char *format_; // Format string
+ const char *format_; // Format string for input field
+
+private:
+
+ static void sb_cb(Fl_Widget *w, Fl_Spinner *sb); // internal callback
+ void update(); // update input field
protected:
+
Fl_Input input_; // Input field for the value
Fl_Repeat_Button
up_button_, // Up button
down_button_; // Down button
-private:
- static void sb_cb(Fl_Widget *w, Fl_Spinner *sb) {
- double v; // New value
-
- if (w == &(sb->input_)) {
- // Something changed in the input field...
- v = atof(sb->input_.value());
-
- if (v < sb->minimum_) {
- sb->value_ = sb->minimum_;
- sb->update();
- } else if (v > sb->maximum_) {
- sb->value_ = sb->maximum_;
- sb->update();
- } else sb->value_ = v;
- } else if (w == &(sb->up_button_)) {
- // Up button pressed...
- v = sb->value_ + sb->step_;
-
- if (v > sb->maximum_) sb->value_ = sb->minimum_;
- else sb->value_ = v;
-
- sb->update();
- } else if (w == &(sb->down_button_)) {
- // Down button pressed...
- v = sb->value_ - sb->step_;
-
- if (v < sb->minimum_) sb->value_ = sb->maximum_;
- else sb->value_ = v;
-
- sb->update();
- }
-
- sb->set_changed();
- sb->do_callback();
- }
- void update() {
- char s[255]; // Value string
-
- if (format_[0]=='%'&&format_[1]=='.'&&format_[2]=='*') { // precision argument
- // this code block is a simplified version of
- // Fl_Valuator::format() and works well (but looks ugly)
- int c = 0;
- char temp[64], *sp = temp;
- sprintf(temp, "%.12f", step_);
- while (*sp) sp++;
- sp--;
- while (sp>temp && *sp=='0') sp--;
- while (sp>temp && (*sp>='0' && *sp<='9')) { sp--; c++; }
- sprintf(s, format_, c, value_);
- } else {
- sprintf(s, format_, value_);
- }
- input_.value(s);
- }
-
- public:
-
- /**
- Creates a new Fl_Spinner widget using the given position, size,
- and label string.
- <P>Inherited destructor Destroys the widget and any value associated with it.
- */
+public:
+
+ // Constructor
Fl_Spinner(int X, int Y, int W, int H, const char *L = 0);
+ // Event handling
+ int handle(int event);
+ // Resize group and subwidgets
+ void resize(int X, int Y, int W, int H);
+
+ /** Returns the format string for the value. */
+ const char *format() const { return (format_); }
+
+ /** Sets the format string for the value. */
+ void format(const char *f) { format_ = f; update(); }
- /** Sets or returns the format string for the value. */
- const char *format() { return (format_); }
- /** Sets or returns the format string for the value. */
- void format(const char *f) { format_ = f; update(); }
-
- int handle(int event) {
- switch (event) {
- case FL_KEYDOWN :
- case FL_SHORTCUT :
- if (Fl::event_key() == FL_Up) {
- up_button_.do_callback();
- return 1;
- } else if (Fl::event_key() == FL_Down) {
- down_button_.do_callback();
- return 1;
- } else return 0;
-
- case FL_FOCUS :
- if (input_.take_focus()) return 1;
- else return 0;
- }
-
- return Fl_Group::handle(event);
- }
-
- /** Speling mistakes retained for source compatibility \deprecated */
- double maxinum() const { return (maximum_); }
/** Gets the maximum value of the widget. */
- double maximum() const { return (maximum_); }
+ double maximum() const { return (maximum_); }
+
/** Sets the maximum value of the widget. */
- void maximum(double m) { maximum_ = m; }
- /** Speling mistakes retained for source compatibility \deprecated */
- double mininum() const { return (minimum_); }
+ void maximum(double m) { maximum_ = m; }
+
/** Gets the minimum value of the widget. */
- double minimum() const { return (minimum_); }
+ double minimum() const { return (minimum_); }
+
/** Sets the minimum value of the widget. */
- void minimum(double m) { minimum_ = m; }
+ void minimum(double m) { minimum_ = m; }
+
/** Sets the minimum and maximum values for the widget. */
- void range(double a, double b) { minimum_ = a; maximum_ = b; }
- void resize(int X, int Y, int W, int H) {
- Fl_Group::resize(X,Y,W,H);
-
- input_.resize(X, Y, W - H / 2 - 2, H);
- up_button_.resize(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2);
- down_button_.resize(X + W - H / 2 - 2, Y + H - H / 2,
- H / 2 + 2, H / 2);
- }
+ void range(double a, double b) { minimum_ = a; maximum_ = b; }
+
+ // Sets the amount to change the value when the user clicks a button.
+ // Docs in src/Fl_Spinner.cxx
+ void step(double s);
+
/**
- Sets or returns the amount to change the value when the user clicks a button.
- Before setting step to a non-integer value, the spinner
- type() should be changed to floating point.
+ Gets the amount to change the value when the user clicks a button.
+ \see Fl_Spinner::step(double)
*/
- double step() const { return (step_); }
- /** See double Fl_Spinner::step() const */
- void step(double s) {
- step_ = s;
- if (step_ != (int)step_) input_.type(FL_FLOAT_INPUT);
- else input_.type(FL_INT_INPUT);
- update();
- }
+ double step() const { return (step_); }
+
/** Gets the color of the text in the input field. */
- Fl_Color textcolor() const {
- return (input_.textcolor());
- }
+ Fl_Color textcolor() const { return (input_.textcolor()); }
+
/** Sets the color of the text in the input field. */
- void textcolor(Fl_Color c) {
- input_.textcolor(c);
- }
+ void textcolor(Fl_Color c) { input_.textcolor(c); }
+
/** Gets the font of the text in the input field. */
- Fl_Font textfont() const {
- return (input_.textfont());
- }
+ Fl_Font textfont() const { return (input_.textfont()); }
+
/** Sets the font of the text in the input field. */
- void textfont(Fl_Font f) {
- input_.textfont(f);
- }
+ void textfont(Fl_Font f) { input_.textfont(f); }
+
/** Gets the size of the text in the input field. */
- Fl_Fontsize textsize() const {
- return (input_.textsize());
- }
+ Fl_Fontsize textsize() const { return (input_.textsize()); }
+
/** Sets the size of the text in the input field. */
- void textsize(Fl_Fontsize s) {
- input_.textsize(s);
- }
+ void textsize(Fl_Fontsize s) { input_.textsize(s); }
+
+ // Sets the numeric representation in the input field.
+ // Docs see src/Fl_Spinner.cxx
+ void type(uchar v);
+
/** Gets the numeric representation in the input field.
- \see Fl_Spinner::type(uchar)
+ \see Fl_Spinner::type(uchar)
*/
- uchar type() const { return (input_.type()); }
- /** Sets the numeric representation in the input field.
- Valid values are FL_INT_INPUT and FL_FLOAT_INPUT.
- Also changes the format() template.
- Setting a new spinner type via a superclass pointer will not work.
- \note type is not a virtual function.
- */
- void type(uchar v) {
- if (v==FL_FLOAT_INPUT) {
- format("%.*f");
- } else {
- format("%.0f");
- }
- input_.type(v);
- }
+ uchar type() const { return (input_.type()); }
+
/** Gets the current value of the widget. */
- double value() const { return (value_); }
+ double value() const { return (value_); }
+
/**
- Sets the current value of the widget.
+ Sets the current value of the input widget.
Before setting value to a non-integer value, the spinner
type() should be changed to floating point.
*/
- void value(double v) { value_ = v; update(); }
+ void value(double v) { value_ = v; update(); }
+
/**
- Change the background color of the spinner widget's input field.
+ Sets the background color of the spinner widget's input field.
*/
- void color(Fl_Color v) { input_.color(v); }
+ void color(Fl_Color v) { input_.color(v); }
+
/**
- Return the background color of the spinner widget's input field.
+ Returns the background color of the spinner widget's input field.
*/
- Fl_Color color() const { return(input_.color()); }
+ Fl_Color color() const { return(input_.color()); }
+
/**
- Change the selection color of the spinner widget's input field.
+ Sets the selection color of the spinner widget's input field.
*/
- void selection_color(Fl_Color val) { input_.selection_color(val); }
+ void selection_color(Fl_Color val) { input_.selection_color(val); }
+
/**
- Return the selection color of the spinner widget's input field.
+ Returns the selection color of the spinner widget's input field.
*/
- Fl_Color selection_color() const { return input_.selection_color(); }
+ Fl_Color selection_color() const { return input_.selection_color(); }
};
#endif // !Fl_Spinner_H
+
//
// End of "$Id$".
//
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b3384614a..0aac7cb1d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -60,6 +60,7 @@ set (CPPFILES
Fl_Shared_Image.cxx
Fl_Single_Window.cxx
Fl_Slider.cxx
+ Fl_Spinner.cxx
Fl_System_Driver.cxx
Fl_Table.cxx
Fl_Table_Row.cxx
diff --git a/src/Fl_Group.cxx b/src/Fl_Group.cxx
index b4ef6d91c..5a8fb1fd4 100644
--- a/src/Fl_Group.cxx
+++ b/src/Fl_Group.cxx
@@ -852,34 +852,6 @@ Fl_Input_Choice::Fl_Input_Choice (int X,int Y,int W,int H,const char*L)
}
-Fl_Spinner::Fl_Spinner(int X, int Y, int W, int H, const char *L)
-: Fl_Group(X, Y, W, H, L),
- input_(X, Y, W - H / 2 - 2, H),
- up_button_(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2, "@-42<"),
- down_button_(X + W - H / 2 - 2, Y + H - H / 2,
- H / 2 + 2, H / 2, "@-42>")
-{
- end();
-
- value_ = 1.0;
- minimum_ = 1.0;
- maximum_ = 100.0;
- step_ = 1.0;
- format_ = "%g";
-
- align(FL_ALIGN_LEFT);
-
- input_.value("1");
- input_.type(FL_INT_INPUT);
- input_.when(FL_WHEN_ENTER_KEY | FL_WHEN_RELEASE);
- input_.callback((Fl_Callback *)sb_cb, this);
-
- up_button_.callback((Fl_Callback *)sb_cb, this);
-
- down_button_.callback((Fl_Callback *)sb_cb, this);
-}
-
-
//
// End of "$Id$".
//
diff --git a/src/Fl_Spinner.cxx b/src/Fl_Spinner.cxx
new file mode 100644
index 000000000..b9b08efa8
--- /dev/null
+++ b/src/Fl_Spinner.cxx
@@ -0,0 +1,194 @@
+//
+// "$Id$"
+//
+// Spinner widget for the Fast Light Tool Kit (FLTK).
+//
+// Copyright 1998-2017 by Bill Spitzak and others.
+//
+// This library is free software. Distribution and use rights are outlined in
+// the file "COPYING" which should have been included with this file. If this
+// file is missing or damaged, see the license at:
+//
+// http://www.fltk.org/COPYING.php
+//
+// Please report all bugs and problems on the following page:
+//
+// http://www.fltk.org/str.php
+//
+
+/* \file
+ Fl_Spinner widget . */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <FL/Fl_Spinner.H>
+
+/*
+ This widget is a combination of the input widget and repeat buttons.
+
+ The user can either type into the input area or use the buttons to
+ change the value.
+*/
+
+void Fl_Spinner::sb_cb(Fl_Widget *w, Fl_Spinner *sb) {
+ double v; // New value
+
+ if (w == &(sb->input_)) {
+ // Something changed in the input field...
+ v = atof(sb->input_.value());
+
+ if (v < sb->minimum_) {
+ sb->value_ = sb->minimum_;
+ sb->update();
+ } else if (v > sb->maximum_) {
+ sb->value_ = sb->maximum_;
+ sb->update();
+ } else sb->value_ = v;
+ } else if (w == &(sb->up_button_)) {
+ // Up button pressed...
+ v = sb->value_ + sb->step_;
+
+ if (v > sb->maximum_) sb->value_ = sb->minimum_;
+ else sb->value_ = v;
+
+ sb->update();
+ } else if (w == &(sb->down_button_)) {
+ // Down button pressed...
+ v = sb->value_ - sb->step_;
+
+ if (v < sb->minimum_) sb->value_ = sb->maximum_;
+ else sb->value_ = v;
+
+ sb->update();
+ }
+
+ sb->set_changed();
+ sb->do_callback();
+}
+
+void Fl_Spinner::update() {
+ char s[255]; // Value string
+
+ if (format_[0] == '%' && format_[1] == '.' && format_[2] == '*') { // precision argument
+ // this code block is a simplified version of
+ // Fl_Valuator::format() and works well (but looks ugly)
+ int c = 0;
+ char temp[64], *sp = temp;
+ sprintf(temp, "%.12f", step_);
+ while (*sp) sp++;
+ sp--;
+ while (sp > temp && *sp == '0') sp--;
+ while (sp > temp && (*sp >= '0' && *sp <= '9')) { sp--; c++; }
+ sprintf(s, format_, c, value_);
+ } else {
+ sprintf(s, format_, value_);
+ }
+ input_.value(s);
+}
+
+#define FL_UP_ARROW_TX "@-42<"
+#define FL_DOWN_ARROW_TX "@-42>"
+
+/**
+ Creates a new Fl_Spinner widget using the given position, size,
+ and label string.
+
+ The inherited destructor destroys the widget and any value associated with it.
+*/
+
+Fl_Spinner::Fl_Spinner(int X, int Y, int W, int H, const char *L)
+: Fl_Group(X, Y, W, H, L),
+ input_(X, Y, W - H / 2 - 2, H),
+ up_button_(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2, FL_UP_ARROW_TX),
+ down_button_(X + W - H / 2 - 2, Y + H - H / 2,
+ H / 2 + 2, H / 2, FL_DOWN_ARROW_TX)
+{
+ end();
+
+ value_ = 1.0;
+ minimum_ = 1.0;
+ maximum_ = 100.0;
+ step_ = 1.0;
+ format_ = "%g";
+
+ align(FL_ALIGN_LEFT);
+
+ input_.value("1");
+ input_.type(FL_INT_INPUT);
+ input_.when(FL_WHEN_ENTER_KEY | FL_WHEN_RELEASE);
+ input_.callback((Fl_Callback *)sb_cb, this);
+
+ up_button_.callback((Fl_Callback *)sb_cb, this);
+
+ down_button_.callback((Fl_Callback *)sb_cb, this);
+}
+
+int Fl_Spinner::handle(int event) {
+
+ switch (event) {
+
+ case FL_KEYDOWN:
+ case FL_SHORTCUT:
+ if (Fl::event_key() == FL_Up) {
+ up_button_.do_callback();
+ return 1;
+ } else if (Fl::event_key() == FL_Down) {
+ down_button_.do_callback();
+ return 1;
+ }
+ return 0;
+
+ case FL_FOCUS:
+ if (input_.take_focus()) return 1;
+ return 0;
+ }
+
+ return Fl_Group::handle(event);
+}
+
+void Fl_Spinner::resize(int X, int Y, int W, int H) {
+ Fl_Group::resize(X,Y,W,H);
+
+ input_.resize(X, Y, W - H / 2 - 2, H);
+ up_button_.resize(X + W - H / 2 - 2, Y, H / 2 + 2, H / 2);
+ down_button_.resize(X + W - H / 2 - 2, Y + H - H / 2,
+ H / 2 + 2, H / 2);
+}
+
+/**
+ Sets or returns the amount to change the value when the user clicks a button.
+ Before setting step to a non-integer value, the spinner
+ type() should be changed to floating point.
+
+ \see double Fl_Spinner::step() const
+*/
+
+void Fl_Spinner::step(double s) {
+ step_ = s;
+ if (step_ != (int)step_) input_.type(FL_FLOAT_INPUT);
+ else input_.type(FL_INT_INPUT);
+ update();
+}
+
+/** Sets the numeric representation in the input field.
+
+ Valid values are FL_INT_INPUT and FL_FLOAT_INPUT.
+ Also changes the format() template.
+ Setting a new spinner type via a superclass pointer will not work.
+ \note type() is not a virtual function.
+*/
+
+void Fl_Spinner::type(uchar v) {
+ if (v == FL_FLOAT_INPUT) {
+ format("%.*f");
+ } else {
+ format("%.0f");
+ }
+ input_.type(v);
+}
+
+
+//
+// End of "$Id$".
+//
diff --git a/src/Makefile b/src/Makefile
index 265cab062..cecae2845 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -3,7 +3,7 @@
#
# Library Makefile for the Fast Light Tool Kit (FLTK).
#
-# Copyright 1998-2016 by Bill Spitzak and others.
+# Copyright 1998-2017 by Bill Spitzak and others.
#
# This library is free software. Distribution and use rights are outlined in
# the file "COPYING" which should have been included with this file. If this
@@ -79,6 +79,7 @@ CPPFILES = \
Fl_Shared_Image.cxx \
Fl_Single_Window.cxx \
Fl_Slider.cxx \
+ Fl_Spinner.cxx \
Fl_System_Driver.cxx \
Fl_Table.cxx \
Fl_Table_Row.cxx \