GuiProgressBar.cpp 3.7 KB

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