| 1 | /* GuiLabel.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-2008,2010-2018,2020,2024 Paul Boersma, 2007 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"cxx . . $ `<file>/sys/GuiP.h`/ |
| 20 | |
| 21 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiLabel, GuiControl, 0); |
| 22 | |
| 23 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 24 | #define iam_labelcxx . . $ `sys/GuiLabel.cpp:24:10`! GuiLabel me = (GuiLabel) _GuiObject_getUserData (widget) |
| 25 | #elif motif |
| 26 | #define iam_label GuiLabel me = (GuiLabel) widget -> userData |
| 27 | #elif cocoa |
| 28 | #define iam_label GuiLabel me = (GuiLabel) [(GuiCocoaLabel *) widget userData]; |
| 29 | #endif |
| 30 | |
| 31 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 32 | static void _GuiGtkLabel_destroyCallbackcxx . . $ _GuiGtkLabel_destroyCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer void_me) { |
| 33 | (void) widget; |
| 34 | iamcxx . . $ `melder/melder.h:50:9`! (GuiLabel); |
| 35 | forgetcxx . . $ `sys/Thing.h:158:9`! (me); |
| 36 | } |
| 37 | #elif motif |
| 38 | void _GuiWinLabel_destroy (GuiObject widget) { |
| 39 | iam_label; |
| 40 | _GuiNativeControl_destroy (widget); |
| 41 | forget (me); // NOTE: my widget is not destroyed here |
| 42 | } |
| 43 | #elif cocoa |
| 44 | @implementation GuiCocoaLabel { |
| 45 | GuiLabel d_userData; |
| 46 | } |
| 47 | - (void) dealloc { // override |
| 48 | GuiLabel me = d_userData; |
| 49 | forget (me); |
| 50 | trace (U"deleting a label"); |
| 51 | [super dealloc]; |
| 52 | } |
| 53 | - (GuiThing) getUserData { |
| 54 | return d_userData; |
| 55 | } |
| 56 | - (void) setUserData: (GuiThing) userData { |
| 57 | Melder_assert (userData == nullptr || Thing_isa (userData, classGuiLabel)); |
| 58 | d_userData = static_cast <GuiLabel> (userData); |
| 59 | } |
| 60 | @end |
| 61 | #endif |
| 62 | |
| 63 | GuiLabelcxx . . $ GuiLabel# GuiLabel_createcxx . . $ GuiLabel_create(39026c9008a6a07). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, |
| 64 | conststring32cxx . . $ conststring32# labelText, uint32cxx . . $ uint32# flags) |
| 65 | { |
| 66 | autoGuiLabelcxx . . $ autoGuiLabel# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiLabel); |
| 67 | mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = parent -> d_shellcxx . . $ structGuiThing#d_shell.; |
| 68 | mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = parent; |
| 69 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 70 | if (flags & GuiLabel_BOLDcxx . . $ `sys/Gui.h:678:9`!) { |
| 71 | mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_label_new (nullptr); |
| 72 | const char *format = "<b>%s</b>"; |
| 73 | char *markedUpText = g_markup_printf_escaped (format, Melder_peek32to8 (labelText)); |
| 74 | gtk_label_set_markup (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), markedUpText); |
| 75 | g_free (markedUpText); |
| 76 | } else { |
| 77 | mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_label_new (Melder_peek32to8 (labelText)); |
| 78 | } |
| 79 | _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 80 | mycxx . . $ `melder/melder.h:44:9`! v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., left, right, top, bottom, parent); |
| 81 | g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "destroy", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkLabel_destroyCallback), me.get()); |
| 82 | /* |
| 83 | The following is deprecated in GTK 3: |
| 84 | */ |
| 85 | //gtk_misc_set_alignment (GTK_MISC (my d_widget), flags & GuiLabel_RIGHT ? 1.0 : flags & GuiLabel_CENTRE ? 0.5 : 0.0, 0.5); |
| 86 | /* |
| 87 | So, what to do after the above function is removed from GTK? |
| 88 | First, it was meant to be this: |
| 89 | */ |
| 90 | #if 0 |
| 91 | gtk_widget_set_halign (GTK_WIDGET (my d_widget), (flags & GuiLabel_RIGHT ? GTK_ALIGN_END : (flags & GuiLabel_CENTRE ? GTK_ALIGN_CENTER : GTK_ALIGN_START))); |
| 92 | gtk_widget_set_valign (GTK_WIDGET (my d_widget), GTK_ALIGN_BASELINE); |
| 93 | #endif |
| 94 | /* |
| 95 | Unfortunately, those two functions do nothing at all. |
| 96 | Second, GTK 3.15 or so introduced the following: |
| 97 | */ |
| 98 | #if 1 |
| 99 | gtk_label_set_xalign (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), flags & GuiLabel_RIGHTcxx . . $ `sys/Gui.h:677:9`! ? 1.0 : flags & GuiLabel_CENTREcxx . . $ `sys/Gui.h:676:9`! ? 0.5 : 0.0); |
| 100 | gtk_label_set_yalign (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), 0.5); |
| 101 | #endif |
| 102 | /* |
| 103 | A perhaps related comment by the authors of GTK 3 (https://bugzilla.gnome.org/show_bug.cgi?id=733981): |
| 104 | " |
| 105 | Matthias Clasen 2015-08-28 20:14:23 UTC |
| 106 | Don't think there is anything for us to fix here. |
| 107 | " |
| 108 | */ |
| 109 | /* |
| 110 | For multiline labels: |
| 111 | */ |
| 112 | gtk_label_set_line_wrap (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true); |
| 113 | gtk_label_set_justify (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), flags & GuiLabel_RIGHTcxx . . $ `sys/Gui.h:677:9`! ? GTK_JUSTIFY_RIGHT : flags & GuiLabel_CENTREcxx . . $ `sys/Gui.h:676:9`! ? GTK_JUSTIFY_CENTER : GTK_JUSTIFY_LEFT); |
| 114 | #elif motif |
| 115 | my d_widget = _Gui_initializeWidget (xmLabelWidgetClass, parent -> d_widget, labelText); |
| 116 | _GuiObject_setUserData (my d_widget, me.get()); |
| 117 | my d_widget -> window = CreateWindow (L"static", Melder_peek32toW (_GuiWin_expandAmpersands (my d_widget -> name.get())), |
| 118 | WS_CHILD |
| 119 | | ( flags & GuiLabel_RIGHT ? SS_RIGHT : flags & GuiLabel_CENTRE ? SS_CENTER : SS_LEFT ) |
| 120 | | ( flags & GuiLabel_MULTILINE ? 0 : SS_CENTERIMAGE), |
| 121 | my d_widget -> x, my d_widget -> y, my d_widget -> width, my d_widget -> height, |
| 122 | my d_widget -> parent -> window, (HMENU) 1, theGui.instance, nullptr); |
| 123 | SetWindowLongPtr (my d_widget -> window, GWLP_USERDATA, (LONG_PTR) my d_widget); |
| 124 | if (flags & GuiLabel_BOLD) |
| 125 | SetWindowFont (my d_widget -> window, theWinGuiBoldLabelFont (), false); |
| 126 | else |
| 127 | SetWindowFont (my d_widget -> window, theWinGuiNormalLabelFont (), false); |
| 128 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 129 | #elif cocoa |
| 130 | trace (U"create"); |
| 131 | GuiCocoaLabel *label = [[GuiCocoaLabel alloc] init]; |
| 132 | my d_widget = label; |
| 133 | trace (U"position"); |
| 134 | my v_positionInForm (my d_widget, left, right, top, bottom, parent); |
| 135 | trace (U"set user data"); |
| 136 | [label setUserData: me.get()]; |
| 137 | trace (U"set bezel style"); |
| 138 | [label setBezelStyle: NSTextFieldRoundedBezel]; |
| 139 | trace (U"set bordered"); |
| 140 | [label setBordered: NO]; |
| 141 | trace (U"set selectable"); |
| 142 | [label setSelectable: NO]; |
| 143 | trace (U"title"); |
| 144 | [label setTitleWithMnemonic: (NSString *) Melder_peek32toCfstring (labelText)]; |
| 145 | [label setAlignment:( flags & GuiLabel_RIGHT ? NSRightTextAlignment : flags & GuiLabel_CENTRE ? NSCenterTextAlignment : NSLeftTextAlignment )]; |
| 146 | if (flags & GuiLabel_BOLD) |
| 147 | [label setFont: theMacGuiBoldLabelFont ()]; |
| 148 | else |
| 149 | [label setFont: theMacGuiNormalLabelFont ()]; |
| 150 | #endif |
| 151 | return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).(); |
| 152 | } |
| 153 | |
| 154 | GuiLabelcxx . . $ GuiLabel# GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, |
| 155 | conststring32cxx . . $ conststring32# labelText, uint32cxx . . $ uint32# flags) |
| 156 | { |
| 157 | GuiLabelcxx . . $ GuiLabel# me = GuiLabel_createcxx . . $ GuiLabel_create(39026c9008a6a07). (parent, left, right, top, bottom, labelText, flags); |
| 158 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me); |
| 159 | return me; |
| 160 | } |
| 161 | |
| 162 | void GuiLabel_setTextcxx . . $ GuiLabel_setText(8fd1a6a47d1f7702). (GuiLabelcxx . . $ GuiLabel# me, conststring32cxx . . $ conststring32# text /* cattable */) { |
| 163 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 164 | gtk_label_set_text (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), Melder_peek32to8 (text)); |
| 165 | #elif motif |
| 166 | my d_widget -> name = Melder_dup_f (text); |
| 167 | _GuiNativeControl_setTitle (my d_widget); |
| 168 | #elif cocoa |
| 169 | [(NSTextField *) my d_widget setTitleWithMnemonic: (NSString *) Melder_peek32toCfstring (text)]; |
| 170 | #endif |
| 171 | } |
| 172 | |
| 173 | /* End of file GuiLabel.cpp */ |