1 /*
2 **
3 ** misc_private.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 #include "ac_config.h"
33 
34 /*
35 #define MESSAGES
36 */
37 #include "message.h"
38 
39 #include <stdlib.h>
40 
41 #include "paths.h"
42 #include INC_X11(Intrinsic.h)
43 #include INC_X11(StringDefs.h)
44 #include INC_XAW(Cardinals.h)
45 #include INC_X11(IntrinsicP.h)
46 #include INC_XAW(LabelP.h)
47 #include "GhostviewP.h"
48 
49 #include "types.h"
50 #include "misc_private.h"
51 #include "VlistP.h"
52 
53 /*############################################################*/
54 /* update_label */
55 /*############################################################*/
56 
57 void
update_label(widget,text)58 update_label(widget,text)
59    Widget widget;
60    char   *text;
61 {
62    LabelWidget w = (LabelWidget) widget;
63    VlistWidget vw = (VlistWidget) widget;
64    int shadow;
65 
66    BEGINMESSAGE1(update_label)
67 
68    if (!XtIsRealized(widget)) {
69       INFMESSAGE(not realized) ENDMESSAGE(update_label)
70       return;
71    }
72 
73    shadow = w->threeD.shadow_width;
74    if ((w->core.width > shadow+shadow) && (w->core.height > shadow+shadow)) {
75       XClearArea(XtDisplay(widget),XtWindow(widget),
76                  shadow,shadow,
77                  (Dimension)(w->core.width-shadow-shadow),
78                  (Dimension)(w->core.height-shadow-shadow), (text) ? False : True);
79    }
80    if (text) {      /* most of the following comes from X11/Xaw/Label.c */
81       Position x,y;
82       INFSMESSAGE(update_label,text)
83 #ifdef HAVE_XAW3D_INTERNATIONAL
84       if( vw->simple.international == True ) {
85 	y = w->label.label_y - XExtentsOfFontSet(w->label.fontset)->max_logical_extent.y;
86       } else {
87 #endif
88 	y = w->label.label_y + w->label.font->max_bounds.ascent;
89 #ifdef HAVE_XAW3D_INTERNATIONAL
90       }
91 #endif
92       if (w->label.justify == XtJustifyCenter) {
93          unsigned int width;
94          int len = (int) strlen(text);
95 #ifdef HAVE_XAW3D_INTERNATIONAL
96 	 if( vw->simple.international == True ) {
97 	   XFontSet     fs = w->label.fontset;
98 	   width = XmbTextEscapement(fs, text, (int)len );
99 	 } else {
100 #endif
101 	   XFontStruct *fs = w->label.font;
102 	   if   (w->label.encoding) width = XTextWidth16 (fs, (XChar2b*)text, (int)(len/2) );
103 	   else                     width = XTextWidth   (fs, text          , (int)(len)   );
104 #ifdef HAVE_XAW3D_INTERNATIONAL
105 	 }
106 #endif
107          x = (Position) ((w->core.width-width)/2);
108       } else {
109          x = w->label.internal_width + w->threeD.shadow_width;
110       }
111 
112 #ifdef HAVE_XAW3D_INTERNATIONAL
113       if( vw->simple.international == True ) {
114 	XmbDrawString(XtDisplay(widget), XtWindow(widget),
115 		      w->label.fontset, w->label.normal_GC,
116 		      x, y, text, (int)(strlen(text)));
117       } else {
118 #endif
119 	if (w->label.encoding) {
120 	   XDrawString16(XtDisplay(widget), XtWindow(widget),
121                          w->label.normal_GC,
122 	  	         x, y,(XChar2b*)text, (int)(strlen(text)));
123 	} else {
124            XDrawString(XtDisplay(widget), XtWindow(widget),
125                        w->label.normal_GC,
126 	  	       x, y, text, (int)(strlen(text)));
127 	}
128 #ifdef HAVE_XAW3D_INTERNATIONAL
129       }
130 #endif
131    }
132 
133    ENDMESSAGE1(update_label)
134 }
135 
136