1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
/* GuiLabel.cpp
*
* Copyright (C) 1993-2011,2012 Paul Boersma
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* pb & sdk 2007/12/28 gtk
* pb 2010/11/28 removed Motif
* pb 2011/04/06 C++
*/
#include "GuiP.h"
#undef iam
#define iam(x) x me = (x) void_me
#if win || mac
#define iam_label \
Melder_assert (widget -> widgetClass == xmLabelWidgetClass); \
GuiLabel me = (GuiLabel) widget -> userData
#else
#define iam_label \
GuiLabel me = (GuiLabel) _GuiObject_getUserData (widget)
#endif
typedef struct structGuiLabel {
GuiObject widget;
} *GuiLabel;
#if gtk
static void _GuiGtkLabel_destroyCallback (GuiObject widget, gpointer void_me) {
(void) widget;
iam (GuiLabel);
Melder_free (me);
}
#elif win
void _GuiWinLabel_destroy (GuiObject widget) {
iam_label;
_GuiNativeControl_destroy (widget);
Melder_free (me); // NOTE: my widget is not destroyed here
}
#elif mac
#if useCarbon
void _GuiMacLabel_destroy (GuiObject widget) {
iam_label;
_GuiNativeControl_destroy (widget);
Melder_free (me); // NOTE: my widget is not destroyed here
}
#else
#endif
#endif
GuiObject GuiLabel_create (GuiObject parent, int left, int right, int top, int bottom,
const wchar_t *labelText, unsigned long flags)
{
GuiLabel me = Melder_calloc_f (struct structGuiLabel, 1);
#if gtk
my widget = gtk_label_new (Melder_peekWcsToUtf8 (labelText));
_GuiObject_setUserData (my widget, me);
_GuiObject_position (my widget, left, right, top, bottom);
if (GTK_IS_BOX (parent)) {
gtk_box_pack_start (GTK_BOX (parent), GTK_WIDGET (my widget), FALSE, FALSE, 0);
}
g_signal_connect (G_OBJECT (my widget), "destroy",
G_CALLBACK (_GuiGtkLabel_destroyCallback), me);
//gtk_label_set_justify (GTK_LABEL (my widget),
// flags & GuiLabel_RIGHT ? GTK_JUSTIFY_RIGHT : flags & GuiLabel_CENTRE ? GTK_JUSTIFY_CENTER : GTK_JUSTIFY_LEFT);
gtk_misc_set_alignment (GTK_MISC (my widget),
flags & GuiLabel_RIGHT ? 1.0 : flags & GuiLabel_CENTRE ? 0.5 : 0.0, 0.5);
#elif win
my widget = _Gui_initializeWidget (xmLabelWidgetClass, parent, labelText);
_GuiObject_setUserData (my widget, me);
my widget -> window = CreateWindow (L"static", _GuiWin_expandAmpersands (my widget -> name),
WS_CHILD
| ( flags & GuiLabel_RIGHT ? SS_RIGHT : flags & GuiLabel_CENTRE ? SS_CENTER : SS_LEFT )
| SS_CENTERIMAGE,
my widget -> x, my widget -> y, my widget -> width, my widget -> height,
my widget -> parent -> window, (HMENU) 1, theGui.instance, NULL);
SetWindowLongPtr (my widget -> window, GWLP_USERDATA, (LONG_PTR) my widget);
SetWindowFont (my widget -> window, GetStockFont (ANSI_VAR_FONT), FALSE);
_GuiObject_position (my widget, left, right, top, bottom);
#elif mac
#if useCarbon
my widget = _Gui_initializeWidget (xmLabelWidgetClass, parent, labelText);
_GuiObject_setUserData (my widget, me);
ControlFontStyleRec macFontStyleRecord = { 0 }; // BUG: _GuiNativeControl_setFont will reset alignment (should do inheritance)
macFontStyleRecord. flags = kControlUseFontMask | kControlUseSizeMask | kControlUseJustMask;
macFontStyleRecord. font = systemFont;
macFontStyleRecord. size = 13;
macFontStyleRecord. just = ( flags & GuiLabel_RIGHT ? teFlushRight : flags & GuiLabel_CENTRE ? teCenter : teFlushLeft );
CreateStaticTextControl (my widget -> macWindow, & my widget -> rect, NULL, & macFontStyleRecord, & my widget -> nat.control.handle);
Melder_assert (my widget -> nat.control.handle != NULL);
SetControlReference (my widget -> nat.control.handle, (long) my widget);
my widget -> isControl = true;
_GuiNativeControl_setTitle (my widget);
_GuiObject_position (my widget, left, right, top, bottom);
#else
#endif
#endif
return my widget;
}
GuiObject GuiLabel_createShown (GuiObject parent, int left, int right, int top, int bottom,
const wchar_t *labelText, unsigned long flags)
{
GuiObject me = GuiLabel_create (parent, left, right, top, bottom, labelText, flags);
GuiObject_show (me);
return me;
}
void GuiLabel_setString (GuiObject widget, const wchar_t *text) {
#if gtk
gtk_label_set_text (GTK_LABEL (widget), Melder_peekWcsToUtf8 (text));
#elif win
Melder_free (widget -> name);
widget -> name = Melder_wcsdup_f (text);
_GuiNativeControl_setTitle (widget);
#elif mac
#if useCarbon
Melder_free (widget -> name);
widget -> name = Melder_wcsdup_f (text);
_GuiNativeControl_setTitle (widget);
#else
#endif
#endif
}
/* End of file GuiLabel.cpp */
|