libDtSearch: Coverity 86579
[oweals/cde.git] / cde / lib / DtTerm / Term / TermEnhance.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 libraries 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 #ifndef lint
24 #ifdef  VERBOSE_REV_INFO
25 static char rcs_id[] = "$XConsortium: TermEnhance.c /main/1 1996/04/21 19:15:41 drk $";
26 #endif  /* VERBOSE_REV_INFO */
27 #endif  /* lint */
28
29 /*                                                                      *
30  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
31  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
32  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
33  * (c) Copyright 1993, 1994 Novell, Inc.                                *
34  */
35
36 #include "TermHeader.h"
37 #include <X11/X.h>
38 #include "TermP.h"
39 #include "TermColor.h"
40 #include "TermBuffer.h"
41
42 #define ourColorPair    (values[(int) enhFgColor])
43 #define ourBgColor      (values[(int) enhBgColor])
44 #define ourFont         (values[(int) enhFont])
45 #define ourVideo        (values[(int) enhVideo])
46
47 void
48 _DtTermEnhProc(Widget w, enhValues values, TermEnhInfo info)
49 {
50
51     DtTermWidget tw = (DtTermWidget) w;
52     DtTermData td = tw->vt.td;
53
54     /* initialize the color pair if we need to... */
55     if (!td->colorPairs[ourColorPair].initialized) {
56         (void) _DtTermColorInitializeColorPair(w,
57                 &td->colorPairs[ourColorPair]);
58     }
59     if (!td->colorPairs[ourBgColor].initialized) {
60         (void) _DtTermColorInitializeColorPair(w,
61                 &td->colorPairs[ourBgColor]);
62     }
63
64     /* take care of video enhancements...
65      */
66     /* half bright (picks fg color) ... */
67     if (IS_HALF_BRIGHT(ourVideo) && td->colorPairs[ourColorPair].hbValid) {
68         info->fg = td->colorPairs[ourColorPair].hb.pixel;
69     } else {
70         info->fg = td->colorPairs[ourColorPair].fg.pixel;
71     }
72
73     /* background is always background... */
74     info->bg = td->colorPairs[ourBgColor].bg.pixel;
75
76     /* if inverse video, swap fg and bg... */
77     if (IS_INVERSE(ourVideo)) {
78         Pixel tmp;
79
80         tmp = info->fg;
81         info->fg = info->bg;
82         info->bg = tmp;
83     }
84
85     info->flags = (unsigned long) 0;
86     if (IS_SECURE(ourVideo)) {
87         info->flags |= TermENH_SECURE;
88     }
89     if (IS_UNDERLINE(ourVideo)) {
90         info->flags |= TermENH_UNDERLINE;
91     }
92
93     info->font = td->renderFonts[RENDER_FONT_NORMAL].termFont;
94     if (IS_BOLD(ourVideo)) {
95         if (ourFont == FONT_NORMAL) {
96             if (td->renderFonts[RENDER_FONT_BOLD].termFont) {
97                 /* valid bold font -- use it... */
98                 info->font = td->renderFonts[RENDER_FONT_BOLD].termFont;
99             } else {
100                 /* embolden via overstrike... */
101                 info->flags |= TermENH_OVERSTRIKE;
102             }
103         } else {
104             /* DKS: can't do bold with the linedraw font... */
105             info->font = td->renderFonts[RENDER_FONT_LINEDRAW].termFont;
106         }
107     } else {
108         /* not bold -- default is FONT_NORMAL... */
109         if (ourFont == FONT_LINEDRAW) {
110             info->font = td->renderFonts[RENDER_FONT_LINEDRAW].termFont;
111         }
112     }
113                 
114     return;
115 }