Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtprintinfo / UI / DtDetailsLabel.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 /* $TOG: DtDetailsLabel.C /main/3 1998/07/24 16:11:46 mgreess $ */
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 "DtDetailsLabel.h"
32 #include "Icon.h"
33 #include "WorkArea.h"
34
35 #include "dtprintinfomsg.h"
36
37 boolean DtDetailsLabel::first_time = true;
38 Pixmap DtDetailsLabel::blank_pixmap;
39 Pixmap DtDetailsLabel::blank_mask;
40 XmString DtDetailsLabel::bottom_label[2];
41
42 DtDetailsLabel::DtDetailsLabel(MotifUI *parent)
43         : MotifUI(parent, "Details", NULL)
44 {
45    if (first_time)
46     {
47       char *label = new char[strlen(MESSAGE(OwnerL)) + strlen(MESSAGE(SizeL)) +
48                              strlen(MESSAGE(TimeL)) + strlen(MESSAGE(DateL)) +
49                              strlen(MESSAGE(JobNumberL)) + 5];
50       sprintf(label, "%s\n%s\n%s\n%s", MESSAGE(SizeL), 
51               MESSAGE(JobNumberL), MESSAGE(TimeL), MESSAGE(DateL));
52       bottom_label[0] = StringCreate(label);
53       sprintf(label, "%s\n%s\n%s\n%s\n%s",
54               MESSAGE(OwnerL), MESSAGE(SizeL), 
55               MESSAGE(JobNumberL), MESSAGE(TimeL), MESSAGE(DateL));
56       bottom_label[1] = StringCreate(label);
57
58       Dimension highlight;
59       XtVaGetValues(parent->BaseWidget(),
60                     XmNhighlightThickness, &highlight, NULL);
61       int height = 21 + 2 * highlight;
62       blank_pixmap = XCreatePixmap(display, root, 1, height, depth);
63       blank_mask = XCreatePixmap(display, root, 1, height, 1);
64       GC gc_mask = XCreateGC(display, blank_mask, 0, NULL);
65       XSetForeground(display, gc_mask, 0);
66       XFillRectangle(display, blank_mask, gc_mask, 0, 0, 1, height);
67
68       XFreeGC(display, gc_mask);
69       delete [] label;
70       first_time = false;
71     }
72
73    XmString top_string = StringCreate(MESSAGE(Position1L));
74    XmString label_string = StringCreate(MESSAGE(JobNameL));
75    Widget p = XtParent(parent->BaseWidget());
76    Pixel bg;
77    XtVaGetValues(p, XmNbackground, &bg, NULL);
78    _w = XtVaCreateManagedWidget("DtDetailsLabel", iconWidgetClass, p,
79                                 GuiNsuperNode, parent->BaseWidget(),
80                                 XmNalignment, XmALIGNMENT_END,
81                                 XmNtraversalOn, False,
82                                 XmNbackground, bg,
83                                 GuiNiconMarginThickness, 0,
84                                 XmNhighlightThickness, 0,
85                                 XmNlabelString, label_string,
86                                 GuiNtopLabelString, top_string,
87                                 XmNlabelPixmap, blank_pixmap,
88                                 GuiNiconMask, blank_mask,
89                                 GuiNpixmapPlacement, GuiPIXMAP_LEFT,
90                                 NULL);
91    StringFree(top_string);
92    StringFree(label_string);
93    XtAddCallback(_w, GuiNsingleClickCallback, &DtDetailsLabel::ClickCB, NULL);
94    XtAddCallback(_w, GuiNdoubleClickCallback, &DtDetailsLabel::ClickCB, NULL);
95 }
96
97 void DtDetailsLabel::Update(boolean show_only_my_jobs)
98 {
99    int i = 1;
100    if (show_only_my_jobs)
101       i = 0;
102    XtVaSetValues(_w, GuiNbottomLabelString, bottom_label[i], NULL);
103 }
104
105 void DtDetailsLabel::ClickCB(Widget w, XtPointer, XtPointer)
106 {
107    XtVaSetValues(w, GuiNselected, False, NULL);
108 }