| 1 |
/* GuiScale.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 1993-2011,2012,2015,2016,2017,2026 Paul Boersma, 2020 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
* See the GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "GuiP.h" |
| 20 |
|
| 21 |
Thing_implement (GuiScale, GuiControl, 0); |
| 22 |
|
| 23 |
#if motif |
| 24 |
#define iam_scale \ |
| 25 |
Melder_assert (widget -> widgetClass == xmScaleWidgetClass); \ |
| 26 |
GuiScale me = (GuiScale) widget -> userData |
| 27 |
#else |
| 28 |
#define iam_scale \ |
| 29 |
GuiScale me = (GuiScale) _GuiObject_getUserData (widget) |
| 30 |
#endif |
| 31 |
|
| 32 |
#if gtk |
| 33 |
static void _GuiGtkScale_destroyCallback (GuiObject widget, gpointer void_me) { |
| 34 |
(void) widget; |
| 35 |
iam (GuiScale); |
| 36 |
forget (me); |
| 37 |
} |
| 38 |
#elif motif |
| 39 |
void _GuiWinScale_destroy (GuiObject widget) { |
| 40 |
iam_scale; |
| 41 |
DestroyWindow (widget -> window); |
| 42 |
trace (U"forgetting a scale or a progress bar"); |
| 43 |
forget (me); // NOTE: my widget is not destroyed here |
| 44 |
} |
| 45 |
#elif cocoa |
| 46 |
@implementation GuiCocoaScale { |
| 47 |
GuiScale d_userData; |
| 48 |
} |
| 49 |
- (void) dealloc { // override |
| 50 |
GuiScale me = d_userData; |
| 51 |
forget (me); |
| 52 |
trace (U"deleting a progress bar"); |
| 53 |
[super dealloc]; |
| 54 |
} |
| 55 |
- (GuiThing) getUserData { |
| 56 |
return d_userData; |
| 57 |
} |
| 58 |
- (void) setUserData: (GuiThing) userData { |
| 59 |
Melder_assert (userData == nullptr || Thing_isa (userData, classGuiScale)); |
| 60 |
d_userData = static_cast <GuiScale> (userData); |
| 61 |
} |
| 62 |
@end |
| 63 |
#endif |
| 64 |
|
| 65 |
GuiScale GuiScale_create (GuiForm parent, int left, int right, int top, int bottom, |
| 66 |
int minimum, int maximum, int value, uint32 /* flags */) |
| 67 |
{ |
| 68 |
autoGuiScale me = Thing_new (GuiScale); |
| 69 |
my d_shell = parent -> d_shell; |
| 70 |
my d_parent = parent; |
| 71 |
#if gtk |
| 72 |
my d_widget = gtk_hscrollbar_new (nullptr); |
| 73 |
gtk_range_set_range (GTK_RANGE (my d_widget), 0, 1000); |
| 74 |
GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (my d_widget)); |
| 75 |
gtk_adjustment_set_page_size (adj, 150.0); |
| 76 |
gtk_adjustment_changed (adj); |
| 77 |
_GuiObject_setUserData (my d_widget, me.get()); |
| 78 |
my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 79 |
g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_GuiGtkScale_destroyCallback), me.get()); |
| 80 |
#elif motif |
| 81 |
my d_widget = XmCreateScale (parent -> d_widget, "scale", nullptr, 0); |
| 82 |
_GuiObject_setUserData (my d_widget, me.get()); |
| 83 |
my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 84 |
XtVaSetValues (my d_widget, XmNorientation, XmHORIZONTAL, |
| 85 |
XmNminimum, minimum, XmNmaximum, maximum, XmNvalue, value, //XmNy, 300, |
| 86 |
nullptr |
| 87 |
); |
| 88 |
#elif cocoa |
| 89 |
my d_cocoaScale = [[GuiCocoaScale alloc] init]; |
| 90 |
my d_widget = my d_cocoaScale; |
| 91 |
my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 92 |
[my d_cocoaScale setUserData: me.get()]; |
| 93 |
[my d_cocoaScale setIndeterminate: false]; |
| 94 |
[my d_cocoaScale setMinValue: minimum]; |
| 95 |
[my d_cocoaScale setMaxValue: maximum]; |
| 96 |
[my d_cocoaScale setDoubleValue: value]; |
| 97 |
#endif |
| 98 |
return me.releaseToAmbiguousOwner(); |
| 99 |
} |
| 100 |
|
| 101 |
GuiScale GuiScale_createShown (GuiForm parent, int left, int right, int top, int bottom, |
| 102 |
int minimum, int maximum, int value, uint32 flags) |
| 103 |
{ |
| 104 |
GuiScale me = GuiScale_create (parent, left, right, top, bottom, minimum, maximum, value, flags); |
| 105 |
GuiThing_show (me); |
| 106 |
return me; |
| 107 |
} |
| 108 |
|
| 109 |
void GuiScale_setValue (GuiScale me, int value) { |
| 110 |
#if gtk |
| 111 |
gtk_range_set_value (GTK_RANGE (my d_widget), value); |
| 112 |
#elif motif |
| 113 |
XmScaleSetValue (my d_widget, value); |
| 114 |
#elif cocoa |
| 115 |
[my d_cocoaScale setDoubleValue: value]; |
| 116 |
#endif |
| 117 |
} |
| 118 |
|
| 119 |
/* End of file GuiScale.cpp */ |