Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtprintinfo / libUI / MotifUI / LabelObj.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: LabelObj.C /main/2 1995/07/17 14:06:12 drk $ */
24 /*                                                                      *
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30
31 #include "LabelObj.h"
32
33 #include <Xm/Label.h>
34 #include <Xm/Frame.h>
35 #include "WorkArea.h"
36
37 LabelObj::LabelObj(MotifUI *parent,
38                    char *name,
39                    LabelType style,
40                    boolean has_border)
41         : MotifUI(parent, name, NULL)
42 {
43    XmString xm_string = StringCreate(name);
44    Widget p, super_node;
45    Pixel bg;
46    int alignment;
47
48    switch (_style = style)
49    {
50    case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break;
51    case CENTERED: alignment = XmALIGNMENT_CENTER; break;
52    case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break;
53    }
54
55    p = parent->InnerWidget();
56    if (!XtIsComposite(p))
57       p = XtParent(p);
58    XtVaGetValues(p, XmNbackground, &bg, NULL);
59    // If p is a icon then set superNode to it, otherwise set superNode to NULL
60    super_node = parent->UIClass() == ICON ? parent->BaseWidget() : NULL;
61    if (has_border)
62     {
63       _w = XtVaCreateManagedWidget(name, xmFrameWidgetClass, p,
64                                    XmNbackground, bg, XmNuserData, this,
65                                    XmNshadowType, XmSHADOW_OUT,
66                                    XmNshadowThickness, shadowThickness, NULL);
67       p = _w;
68     }
69    _label = XtVaCreateManagedWidget(name, xmLabelWidgetClass, p,
70                                     XmNlabelString, xm_string,
71                                     GuiNsuperNode, super_node,
72                                     XmNalignment, alignment,
73                                     XmNbackground, bg, XmNuserData, this, NULL);
74    if (!has_border)
75       _w = _label;
76
77    StringFree(xm_string);
78 }
79
80 void LabelObj::LabelStyle(LabelType style)
81 {
82    int alignment;
83
84    switch (_style = style)
85    {
86    case LEFT_JUSTIFIED: alignment = XmALIGNMENT_BEGINNING; break;
87    case CENTERED: alignment = XmALIGNMENT_CENTER; break;
88    case RIGHT_JUSTIFIED: alignment = XmALIGNMENT_END; break;
89    }
90    XtVaSetValues(_label, XmNalignment, alignment, NULL);
91 }