| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// flslider2.cxx |
| 3 |
// |
| 4 |
// Copyright (C) 2010 |
| 5 |
// Stelios Bounanos, M0GLD |
| 6 |
// |
| 7 |
// ---------------------------------------------------------------------------- |
| 8 |
// Copyright (C) 2014 |
| 9 |
// David Freese, W1HKJ |
| 10 |
// |
| 11 |
// This file is part of flmsg |
| 12 |
// |
| 13 |
// flrig is free software; you can redistribute it and/or modify |
| 14 |
// it under the terms of the GNU General Public License as published by |
| 15 |
// the Free Software Foundation; either version 3 of the License, or |
| 16 |
// (at your option) any later version. |
| 17 |
// |
| 18 |
// flrig is distributed in the hope that it will be useful, |
| 19 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 |
// GNU General Public License for more details. |
| 22 |
// |
| 23 |
// You should have received a copy of the GNU General Public License |
| 24 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 |
// ---------------------------------------------------------------------------- |
| 26 |
|
| 27 |
#include <config.h> |
| 28 |
|
| 29 |
#include <FL/Fl.H> |
| 30 |
|
| 31 |
#include "util.h" |
| 32 |
#include "flslider2.h" |
| 33 |
|
| 34 |
inline static int handle_scroll(Fl_Valuator* w, int event) |
| 35 |
{ |
| 36 |
if (!(event == FL_MOUSEWHEEL && Fl::event_inside(w))) |
| 37 |
return 0; |
| 38 |
double d; |
| 39 |
if ((d = Fl::event_dy()) || (d = Fl::event_dx())) { |
| 40 |
if (Fl::event_state() & FL_SHIFT) |
| 41 |
d *= 10.0; |
| 42 |
if (!dynamic_cast<Fl_Value_Input*>(w) && !dynamic_cast<Fl_Counter*>(w) && |
| 43 |
!(w->type() & FL_HOR_SLIDER)) |
| 44 |
d = -d; |
| 45 |
w->value(w->clamp(w->increment(w->value(), static_cast<int>(-d)))); |
| 46 |
w->do_callback(); |
| 47 |
} |
| 48 |
return 1; |
| 49 |
} |
| 50 |
|
| 51 |
int Fl_Slider2::handle(int event) |
| 52 |
{ |
| 53 |
return handle_scroll(this, event) ? 1 : Fl_Slider::handle(event); |
| 54 |
} |
| 55 |
|
| 56 |
int Fl_Value_Slider2::handle(int event) |
| 57 |
{ |
| 58 |
return handle_scroll(this, event) ? 1 : Fl_Value_Slider::handle(event); |
| 59 |
} |
| 60 |
|
| 61 |
int Fl_Counter2::handle(int event) |
| 62 |
{ |
| 63 |
return handle_scroll(this, event) ? 1 : Fl_Counter::handle(event); |
| 64 |
} |
| 65 |
|
| 66 |
int Fl_Value_Input2::handle(int event) |
| 67 |
{ |
| 68 |
return handle_scroll(this, event) ? 1 : Fl_Value_Input::handle(event); |
| 69 |
} |
| 70 |
|
| 71 |
inline static int handle_scroll(Fl_Spinner* w, int event) |
| 72 |
{ |
| 73 |
if (!(event == FL_MOUSEWHEEL && Fl::event_inside(w))) |
| 74 |
return 0; |
| 75 |
double d; |
| 76 |
if ((d = Fl::event_dy()) || (d = Fl::event_dx())) { |
| 77 |
if (Fl::event_state() & FL_SHIFT) |
| 78 |
d *= 10.0; |
| 79 |
d = w->value() - d * w->step(); |
| 80 |
w->value(WCLAMP(d, w->minimum(), w->maximum())); |
| 81 |
w->do_callback(); |
| 82 |
} |
| 83 |
return 1; |
| 84 |
} |
| 85 |
|
| 86 |
int Fl_Spinner2::handle(int event) |
| 87 |
{ |
| 88 |
return handle_scroll(this, event) ? 1 : Fl_Spinner::handle(event); |
| 89 |
} |