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