| 1 | /* GuiProgressBar.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-2012,2013,2015,2017 Paul Boersma, 2008 Stefan de Konink |
| 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 2 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 (GuiProgressBar, GuiControl, 0); |
| 22 | |
| 23 | #if gtk |
| 24 | static void _guiGtkProgressBar_destroyCallback (GuiObject widget, gpointer void_me) { |
| 25 | (void) widget; |
| 26 | iam (GuiProgressBar); |
| 27 | Melder_free (me); |
| 28 | } |
| 29 | #elif motif |
| 30 | static void _guiMotifProgressBar_destroyCallback (GuiObject widget, XtPointer void_me, XtPointer call) { |
| 31 | (void) widget; (void) call; |
| 32 | trace (U"destroying a progress bar"); |
| 33 | iam (GuiProgressBar); |
| 34 | //forget (me); // because I am already forgotten in the scale::destroy callback |
| 35 | trace (U"destroyed a progress bar"); |
| 36 | } |
| 37 | #elif cocoa |
| 38 | @implementation GuiCocoaProgressBar { |
| 39 | GuiProgressBar d_userData; |
| 40 | } |
| 41 | - (void) dealloc { // override |
| 42 | GuiProgressBar me = d_userData; |
| 43 | forget (me); |
| 44 | trace (U"deleting a progress bar"); |
| 45 | [super dealloc]; |
| 46 | } |
| 47 | - (GuiThing) getUserData { |
| 48 | return d_userData; |
| 49 | } |
| 50 | - (void) setUserData: (GuiThing) userData { |
| 51 | Melder_assert (userData == nullptr || Thing_isa (userData, classGuiProgressBar)); |
| 52 | d_userData = static_cast <GuiProgressBar> (userData); |
| 53 | } |
| 54 | @end |
| 55 | #endif |
| 56 | |
| 57 | GuiProgressBar GuiProgressBar_create (GuiForm parent, int left, int right, int top, int bottom, uint32 /* flags */) |
| 58 | { |
| 59 | autoGuiProgressBar me = Thing_new (GuiProgressBar); |
| 60 | my d_shell = parent -> d_shell; |
| 61 | my d_parent = parent; |
| 62 | #if gtk |
| 63 | my d_widget = gtk_progress_bar_new (); |
| 64 | _GuiObject_setUserData (my d_widget, me.get()); |
| 65 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 66 | #elif motif |
| 67 | my d_widget = XmCreateScale (parent -> d_widget, "scale", nullptr, 0); |
| 68 | _GuiObject_setUserData (my d_widget, me.get()); |
| 69 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 70 | XtVaSetValues (my d_widget, XmNorientation, XmHORIZONTAL, |
| 71 | XmNminimum, 0, XmNmaximum, 10000, XmNvalue, 0, |
| 72 | //XmNscaleHeight, 20, |
| 73 | nullptr); |
| 74 | #elif cocoa |
| 75 | my d_cocoaProgressBar = [[GuiCocoaProgressBar alloc] init]; |
| 76 | my d_widget = my d_cocoaProgressBar; |
| 77 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 78 | [my d_cocoaProgressBar setUserData: me.get()]; |
| 79 | [my d_cocoaProgressBar setIndeterminate: false]; |
| 80 | [my d_cocoaProgressBar setMaxValue: 1.0]; |
| 81 | #endif |
| 82 | |
| 83 | #if gtk |
| 84 | g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_guiGtkProgressBar_destroyCallback), me.get()); |
| 85 | #elif cocoa |
| 86 | #elif motif |
| 87 | XtAddCallback (my d_widget, XmNdestroyCallback, _guiMotifProgressBar_destroyCallback, me.get()); |
| 88 | #endif |
| 89 | |
| 90 | return me.releaseToAmbiguousOwner(); |
| 91 | } |
| 92 | |
| 93 | GuiProgressBar GuiProgressBar_createShown (GuiForm parent, int left, int right, int top, int bottom, uint32 flags) |
| 94 | { |
| 95 | GuiProgressBar me = GuiProgressBar_create (parent, left, right, top, bottom, flags); |
| 96 | GuiThing_show (me); |
| 97 | return me; |
| 98 | } |
| 99 | |
| 100 | void GuiProgressBar_setValue (GuiProgressBar me, double value) { |
| 101 | #if gtk |
| 102 | gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (my d_widget), value); |
| 103 | #elif motif |
| 104 | XmScaleSetValue (my d_widget, Melder_iround (value * 10000)); |
| 105 | #elif cocoa |
| 106 | [my d_cocoaProgressBar setDoubleValue: value]; |
| 107 | #endif |
| 108 | } |
| 109 | |
| 110 | /* End of file GuiProgressBar.cpp */ |