GuiScale.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* GuiScale.cpp
  2. *
  3. * Copyright (C) 1993-2011,2012,2015,2016,2017 Paul Boersma
  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 (GuiScale, GuiControl, 0);
  20. #if motif
  21. #define iam_scale \
  22. Melder_assert (widget -> widgetClass == xmScaleWidgetClass); \
  23. GuiScale me = (GuiScale) widget -> userData
  24. #else
  25. #define iam_scale \
  26. GuiScale me = (GuiScale) _GuiObject_getUserData (widget)
  27. #endif
  28. #if gtk
  29. static void _GuiGtkScale_destroyCallback (GuiObject widget, gpointer void_me) {
  30. (void) widget;
  31. iam (GuiScale);
  32. forget (me);
  33. }
  34. #elif motif
  35. void _GuiWinScale_destroy (GuiObject widget) {
  36. iam_scale;
  37. DestroyWindow (widget -> window);
  38. trace (U"forgetting a scale or a progress bar");
  39. forget (me); // NOTE: my widget is not destroyed here
  40. }
  41. #elif cocoa
  42. @implementation GuiCocoaScale {
  43. GuiScale d_userData;
  44. }
  45. - (void) dealloc { // override
  46. GuiScale me = d_userData;
  47. forget (me);
  48. trace (U"deleting a progress bar");
  49. [super dealloc];
  50. }
  51. - (GuiThing) getUserData {
  52. return d_userData;
  53. }
  54. - (void) setUserData: (GuiThing) userData {
  55. Melder_assert (userData == nullptr || Thing_isa (userData, classGuiScale));
  56. d_userData = static_cast <GuiScale> (userData);
  57. }
  58. @end
  59. #endif
  60. GuiScale GuiScale_create (GuiForm parent, int left, int right, int top, int bottom,
  61. int minimum, int maximum, int value, uint32 /* flags */)
  62. {
  63. autoGuiScale me = Thing_new (GuiScale);
  64. my d_shell = parent -> d_shell;
  65. my d_parent = parent;
  66. #if gtk
  67. my d_widget = gtk_hscrollbar_new (nullptr);
  68. gtk_range_set_range (GTK_RANGE (my d_widget), 0, 1000);
  69. GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (my d_widget));
  70. adj -> page_size = 150;
  71. gtk_adjustment_changed (adj);
  72. _GuiObject_setUserData (my d_widget, me.get());
  73. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  74. g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_GuiGtkScale_destroyCallback), me.get());
  75. #elif motif
  76. my d_widget = XmCreateScale (parent -> d_widget, "scale", nullptr, 0);
  77. _GuiObject_setUserData (my d_widget, me.get());
  78. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  79. XtVaSetValues (my d_widget, XmNorientation, XmHORIZONTAL,
  80. XmNminimum, minimum, XmNmaximum, maximum, XmNvalue, value, //XmNy, 300,
  81. nullptr);
  82. #elif cocoa
  83. my d_cocoaScale = [[GuiCocoaScale alloc] init];
  84. my d_widget = my d_cocoaScale;
  85. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  86. [my d_cocoaScale setUserData: me.get()];
  87. [my d_cocoaScale setIndeterminate: false];
  88. [my d_cocoaScale setMinValue: minimum];
  89. [my d_cocoaScale setMaxValue: maximum];
  90. [my d_cocoaScale setDoubleValue: value];
  91. #endif
  92. return me.releaseToAmbiguousOwner();
  93. }
  94. GuiScale GuiScale_createShown (GuiForm parent, int left, int right, int top, int bottom,
  95. int minimum, int maximum, int value, uint32 flags)
  96. {
  97. GuiScale me = GuiScale_create (parent, left, right, top, bottom, minimum, maximum, value, flags);
  98. GuiThing_show (me);
  99. return me;
  100. }
  101. void GuiScale_setValue (GuiScale me, int value) {
  102. #if gtk
  103. gtk_range_set_value (GTK_RANGE (my d_widget), value);
  104. #elif motif
  105. XmScaleSetValue (my d_widget, value);
  106. #elif cocoa
  107. [my d_cocoaScale setDoubleValue: value];
  108. #endif
  109. }
  110. /* End of file GuiScale.cpp */