0023533: Unitialized variables used, IntTools_TopolTool.cxx
[occt.git] / src / Xw / Xw_set_text_attrib.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18
19#include <Xw_Extension.h>
20
b311480e 21/* ifdef then trace on */
7fd59977 22#ifdef TRACE
23#define TRACE_SET_TEXT_ATTRIB
24#define TRACE_GET_TEXT_ATTRIB
25#endif
26
27/*
28 XW_ATTRIB Xw_set_text_attrib (awindow,color,type,font,mode):
29 XW_EXT_WINDOW *awindow
30 int color ; Color index to used 0 >= x < MAXCOLOR
31 int type ; Type index to used 0 >= x < MAXTYPE
32 int font ; Font index to used 0 >= x < MAXFONT
33 DRAWMODE mode ; Draw Mode must be one of DRAWMODE enum
34
35 Set Text Color,Type and Font current graphic attrib .
36
37 Returns Selected Text Attribute Index if successful
38 Returns 0 if Bad Color,Type or Font Index
39
40*/
41
42#ifdef XW_PROTOTYPE
43XW_ATTRIB Xw_set_text_attrib (void *awindow,int color,int type,int font,XW_DRAWMODE mode)
44#else
45XW_ATTRIB Xw_set_text_attrib (awindow,color,type,font,mode)
46void *awindow;
47int color,type,font ;
48XW_DRAWMODE mode ;
49#endif /*XW_PROTOTYPE*/
50{
51XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
52XGCValues gc_values ;
53XW_ATTRIB code ;
54int i,j,k,function,mask= 0 ;
55unsigned long planemask,hcolor ;
56
57 if( !Xw_isdefine_window(pwindow) ) {
58 /*ERROR*Bad EXT_WINDOW Address*/
59 Xw_set_error(24,"Xw_set_text_attrib",pwindow) ;
60 return (0) ;
61 }
62
63 if( _BINDEX > 0 ) return (1) ;
64
65 if ( !Xw_isdefine_color(_COLORMAP,color) ) {
66 /*ERROR*Bad Defined Color*/
67 Xw_set_error(41,"Xw_set_text_attrib",&color) ;
68 return (0) ;
69 }
70
71 if( type != 0 ) {
72 /*ERROR*Unimplemented Text type*/
73 Xw_set_error(81,"Xw_set_text_attrib",&type) ;
74 type = 0 ;
75 }
76
77 if ( !Xw_isdefine_font(_FONTMAP,font) ) {
78 /*WARNING*Bad Defined Font*/
79 Xw_set_error(43,"Xw_set_text_attrib",&font) ;
80 font = 0 ;
81 }
82
83 if( !_FONTMAP || !_FONTMAP->fonts[font] ) font = 0 ;
84
85 code = QGCODE(color,type,font,mode) ;
86 if( code == pwindow->qgtext[pwindow->textindex].code ) {
87 /* The last index computed is already set*/
88 pwindow->qgtext[pwindow->textindex].count++ ;
89 return (pwindow->textindex+1) ;
90 }
91
92 for( i=j=0,k=MAXQG ; i<MAXQG ; i++ ) {
93 if( code == pwindow->qgtext[i].code ) k = i ;
94 if( pwindow->qgtext[i].count < pwindow->qgtext[j].count ) j = i;
95 }
96
97 if( k < MAXQG ) {
98 /* A GC index already exist,use it */
99 pwindow->textindex = k ;
100 pwindow->qgtext[k].count++ ;
101 return (k+1) ;
102 }
103
104 pwindow->textindex = j ;
105 pwindow->qgtext[j].count = 1 ;
106
107 Xw_get_color_attrib(pwindow,mode,color,&hcolor,&function,&planemask);
108 if( mode != QGMODE(pwindow->qgtext[j].code) ) {
109 mask |= GCFunction | GCPlaneMask | GCForeground ;
110 gc_values.function = function ;
111 gc_values.plane_mask = planemask ;
112 gc_values.foreground = hcolor ;
113 } else if( color != QGCOLOR(pwindow->qgtext[j].code) ) {
114 mask |= GCForeground;
115 gc_values.foreground = hcolor ;
116 }
117
118 if( type != QGTYPE(pwindow->qgtext[j].code) ) {
119 }
120
121 if( font != QGFONT(pwindow->qgtext[j].code) ) {
122 if( _FONTMAP && _FONTMAP->fonts[font] ) {
123 mask |= GCFont ;
124 gc_values.font = _FONTMAP->fonts[font]->fid ;
125 }
126 }
127
128 k = j+1 ;
129
130 if( mask ) {
131 XChangeGC(_DISPLAY,pwindow->qgtext[j].gc,mask,&gc_values) ;
132 pwindow->qgtext[j].code = code ;
133
134#ifdef TRACE_SET_TEXT_ATTRIB
135if( Xw_get_trace() > 1 ) {
136 printf(" %d = Xw_set_text_attrib(%lx,%d,%d,%d,%d)\n",
137 k,(long ) pwindow,color,type,font,mode) ;
138}
139#endif
140 }
141
142 return (k) ;
143}
144
145/*
146 XW_ATTRIB Xw_get_text_attrib (awindow,color,type,font,mode):
147 XW_EXT_WINDOW *awindow
148 int *color ; Returns current Color index
149 int *type ; Returns current Type
150 int *font ; Returns current Font index
151 DRAWMODE *mode ; Returns current Draw Mode
152
153 Returns Selected Polygon Attribute Index
154
155*/
156
157#ifdef XW_PROTOTYPE
158XW_ATTRIB Xw_get_text_attrib (void *awindow,int *color,int *type,int *font,XW_DRAWMODE *mode)
159#else
160XW_ATTRIB Xw_get_text_attrib (awindow,color,type,font,mode)
161void *awindow;
162int *color,*font ;
163int *type ;
164XW_DRAWMODE *mode ;
165#endif /*XW_PROTOTYPE*/
166{
167XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
168XW_ATTRIB code;
169int j,k;
170
171 j = pwindow->textindex; k = j+1;
172
173 code = pwindow->qgtext[j].code;
174
175 *color = QGCOLOR(code);
176 *type = QGTYPE(code);
177 *font = QGFONT(code);
178 *mode = (XW_DRAWMODE) QGMODE(code);
179
180#ifdef TRACE_GET_TEXT_ATTRIB
181if( Xw_get_trace() > 1 ) {
182 printf(" %d = Xw_get_text_attrib(%lx,%d,%d,%d,%d)\n",
183 k,(long ) pwindow,*color,*type,*font,*mode) ;
184}
185#endif
186
187 return code;
188}