1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
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.
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.
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.
19 #include <Xw_Extension.h>
21 /* ifdef then trace on */
23 #define TRACE_SET_TEXT_ATTRIB
24 #define TRACE_GET_TEXT_ATTRIB
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
35 Set Text Color,Type and Font current graphic attrib .
37 Returns Selected Text Attribute Index if successful
38 Returns 0 if Bad Color,Type or Font Index
43 XW_ATTRIB Xw_set_text_attrib (void *awindow,int color,int type,int font,XW_DRAWMODE mode)
45 XW_ATTRIB Xw_set_text_attrib (awindow,color,type,font,mode)
49 #endif /*XW_PROTOTYPE*/
51 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
54 int i,j,k,function,mask= 0 ;
55 unsigned long planemask,hcolor ;
57 if( !Xw_isdefine_window(pwindow) ) {
58 /*ERROR*Bad EXT_WINDOW Address*/
59 Xw_set_error(24,"Xw_set_text_attrib",pwindow) ;
63 if( _BINDEX > 0 ) return (1) ;
65 if ( !Xw_isdefine_color(_COLORMAP,color) ) {
66 /*ERROR*Bad Defined Color*/
67 Xw_set_error(41,"Xw_set_text_attrib",&color) ;
72 /*ERROR*Unimplemented Text type*/
73 Xw_set_error(81,"Xw_set_text_attrib",&type) ;
77 if ( !Xw_isdefine_font(_FONTMAP,font) ) {
78 /*WARNING*Bad Defined Font*/
79 Xw_set_error(43,"Xw_set_text_attrib",&font) ;
83 if( !_FONTMAP || !_FONTMAP->fonts[font] ) font = 0 ;
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) ;
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;
98 /* A GC index already exist,use it */
99 pwindow->textindex = k ;
100 pwindow->qgtext[k].count++ ;
104 pwindow->textindex = j ;
105 pwindow->qgtext[j].count = 1 ;
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 ;
118 if( type != QGTYPE(pwindow->qgtext[j].code) ) {
121 if( font != QGFONT(pwindow->qgtext[j].code) ) {
122 if( _FONTMAP && _FONTMAP->fonts[font] ) {
124 gc_values.font = _FONTMAP->fonts[font]->fid ;
131 XChangeGC(_DISPLAY,pwindow->qgtext[j].gc,mask,&gc_values) ;
132 pwindow->qgtext[j].code = code ;
134 #ifdef TRACE_SET_TEXT_ATTRIB
135 if( 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) ;
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
153 Returns Selected Polygon Attribute Index
158 XW_ATTRIB Xw_get_text_attrib (void *awindow,int *color,int *type,int *font,XW_DRAWMODE *mode)
160 XW_ATTRIB Xw_get_text_attrib (awindow,color,type,font,mode)
165 #endif /*XW_PROTOTYPE*/
167 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
171 j = pwindow->textindex; k = j+1;
173 code = pwindow->qgtext[j].code;
175 *color = QGCOLOR(code);
176 *type = QGTYPE(code);
177 *font = QGFONT(code);
178 *mode = (XW_DRAWMODE) QGMODE(code);
180 #ifdef TRACE_GET_TEXT_ATTRIB
181 if( 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) ;