GuiScrolledWindow.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* GuiScrolledWindow.cpp
  2. *
  3. * Copyright (C) 1993-2011,2012,2015,2016,2017 Paul Boersma, 2013 Tom Naughton
  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 (GuiScrolledWindow, GuiControl, 0);
  20. #if motif
  21. #define iam_scrolledwindow \
  22. Melder_assert (widget -> widgetClass == xmScrolledWindowWidgetClass); \
  23. GuiScrolledWindow me = (GuiScrolledWindow) widget -> userData
  24. #else
  25. #define iam_scrolledwindow \
  26. GuiScrolledWindow me = (GuiScrolledWindow) _GuiObject_getUserData (widget)
  27. #endif
  28. #if gtk
  29. static void _GuiGtkScrolledWindow_destroyCallback (GuiObject widget, gpointer void_me) {
  30. (void) widget;
  31. iam (GuiScrolledWindow);
  32. forget (me);
  33. }
  34. #elif motif
  35. void _GuiWinScrolledWindow_destroy (GuiObject widget) {
  36. DestroyWindow (widget -> window);
  37. iam_scrolledwindow;
  38. forget (me); // NOTE: my widget is not destroyed here
  39. }
  40. #elif cocoa
  41. @implementation GuiCocoaScrolledWindow {
  42. GuiScrolledWindow d_userData;
  43. }
  44. - (void) dealloc { // override
  45. GuiScrolledWindow me = d_userData;
  46. forget (me);
  47. trace (U"deleting a scrolled window");
  48. [super dealloc];
  49. }
  50. - (GuiThing) getUserData {
  51. return d_userData;
  52. }
  53. - (void) setUserData: (GuiThing) userData {
  54. Melder_assert (userData == nullptr || Thing_isa (userData, classGuiScrolledWindow));
  55. d_userData = static_cast <GuiScrolledWindow> (userData);
  56. }
  57. @end
  58. #endif
  59. GuiScrolledWindow GuiScrolledWindow_create (GuiForm parent, int left, int right, int top, int bottom,
  60. int horizontalScrollbarPersistence, int verticalScrollbarPersistence, uint32 /* flags */)
  61. {
  62. autoGuiScrolledWindow me = Thing_new (GuiScrolledWindow);
  63. my d_shell = parent -> d_shell;
  64. my d_parent = parent;
  65. #if gtk
  66. my d_widget = gtk_scrolled_window_new (nullptr, nullptr);
  67. gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (my d_widget),
  68. horizontalScrollbarPersistence == 0 ? GTK_POLICY_NEVER : horizontalScrollbarPersistence == 1 ? GTK_POLICY_AUTOMATIC : GTK_POLICY_ALWAYS,
  69. verticalScrollbarPersistence == 0 ? GTK_POLICY_NEVER : verticalScrollbarPersistence == 1 ? GTK_POLICY_AUTOMATIC : GTK_POLICY_ALWAYS);
  70. _GuiObject_setUserData (my d_widget, me.get());
  71. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  72. g_signal_connect (G_OBJECT (my d_widget), "destroy", G_CALLBACK (_GuiGtkScrolledWindow_destroyCallback), me.get());
  73. #elif motif
  74. (void) horizontalScrollbarPersistence;
  75. (void) verticalScrollbarPersistence;
  76. my d_widget = XmCreateScrolledWindow (parent -> d_widget, "scrolledWindow", nullptr, 0);
  77. _GuiObject_setUserData (my d_widget, me.get());
  78. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  79. Melder_assert (my classInfo == classGuiScrolledWindow);
  80. trace (U"me = ", Melder_pointer (me.get()), U", user data = ", Melder_pointer (my d_widget -> userData));
  81. #elif cocoa
  82. (void) horizontalScrollbarPersistence;
  83. (void) verticalScrollbarPersistence;
  84. GuiCocoaScrolledWindow *scrollView = [[GuiCocoaScrolledWindow alloc] init];
  85. my d_widget = (GuiObject) scrollView;
  86. my v_positionInForm (my d_widget, left, right, top, bottom, parent);
  87. [scrollView setUserData: me.get()];
  88. [scrollView setHasVerticalScroller: YES];
  89. [scrollView setHasHorizontalScroller: YES];
  90. [scrollView setBackgroundColor: [NSColor lightGrayColor]];
  91. #endif
  92. return me.releaseToAmbiguousOwner();
  93. }
  94. GuiScrolledWindow GuiScrolledWindow_createShown (GuiForm parent, int left, int right, int top, int bottom,
  95. int horizontalScrollbarPersistence, int verticalScrollbarPersistence, uint32 flags)
  96. {
  97. GuiScrolledWindow me = GuiScrolledWindow_create (parent, left, right, top, bottom, horizontalScrollbarPersistence, verticalScrollbarPersistence, flags);
  98. GuiThing_show (me);
  99. return me;
  100. }
  101. /* End of file GuiScrolledWindow.cpp */