2 * ion/ioncore/infowin.h
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
11 #include <libtu/objp.h>
25 bool infowin_init(WInfoWin
*p
, WWindow
*parent
, const WFitParams
*fp
,
28 XSetWindowAttributes attr
;
30 if(!window_init(&(p
->wwin
), parent
, fp
, "WInfoWin"))
33 p
->buffer
=ALLOC_N(char, INFOWIN_BUFFER_LEN
);
41 p
->style
=scopy(style
);
47 gr_stylespec_init(&p
->attr
);
54 /* Enable save unders */
56 XChangeWindowAttributes(ioncore_g
.dpy
, p
->wwin
.win
, CWSaveUnder
, &attr
);
58 window_select_input(&(p
->wwin
), IONCORE_EVENTMASK_NORMAL
);
63 gr_stylespec_unalloc(&p
->attr
);
68 window_deinit(&(p
->wwin
));
73 WInfoWin
*create_infowin(WWindow
*parent
, const WFitParams
*fp
,
76 CREATEOBJ_IMPL(WInfoWin
, infowin
, (p
, parent
, fp
, style
));
80 void infowin_deinit(WInfoWin
*p
)
93 grbrush_release(p
->brush
);
97 gr_stylespec_unalloc(&p
->attr
);
99 window_deinit(&(p
->wwin
));
106 /*{{{ Drawing and geometry */
109 void infowin_draw(WInfoWin
*p
, bool complete
)
118 g
.w
=REGION_GEOM(p
).w
;
119 g
.h
=REGION_GEOM(p
).h
;
121 grbrush_begin(p
->brush
, &g
, GRBRUSH_NO_CLEAR_OK
);
122 grbrush_init_attr(p
->brush
, &p
->attr
);
123 grbrush_draw_textbox(p
->brush
, &g
, p
->buffer
, TRUE
);
124 grbrush_end(p
->brush
);
128 void infowin_updategr(WInfoWin
*p
)
132 assert(p
->style
!=NULL
);
134 nbrush
=gr_get_brush(p
->wwin
.win
,
135 region_rootwin_of((WRegion
*)p
),
141 grbrush_release(p
->brush
);
145 window_draw(&(p
->wwin
), TRUE
);
153 /*{{{ Content-setting */
156 GrStyleSpec
*infowin_stylespec(WInfoWin
*p
)
162 static void infowin_do_set_text(WInfoWin
*p
, const char *str
)
164 strncpy(INFOWIN_BUFFER(p
), str
, INFOWIN_BUFFER_LEN
);
165 INFOWIN_BUFFER(p
)[INFOWIN_BUFFER_LEN
-1]='\0';
169 static void infowin_resize(WInfoWin
*p
)
171 WRQGeomParams rq
=RQGEOMPARAMS_INIT
;
172 const char *str
=INFOWIN_BUFFER(p
);
176 rq
.flags
=REGION_RQGEOM_WEAK_X
|REGION_RQGEOM_WEAK_Y
;
178 rq
.geom
.x
=REGION_GEOM(p
).x
;
179 rq
.geom
.y
=REGION_GEOM(p
).y
;
181 grbrush_get_border_widths(p
->brush
, &bdw
);
182 grbrush_get_font_extents(p
->brush
, &fnte
);
184 rq
.geom
.w
=bdw
.left
+bdw
.right
;
185 rq
.geom
.w
+=grbrush_get_text_width(p
->brush
, str
, strlen(str
));
186 rq
.geom
.h
=fnte
.max_height
+bdw
.top
+bdw
.bottom
;
188 if(rectangle_compare(&rq
.geom
, ®ION_GEOM(p
))!=RECTANGLE_SAME
)
189 region_rqgeom((WRegion
*)p
, &rq
, NULL
);
194 * Set contents of the info window.
197 void infowin_set_text(WInfoWin
*p
, const char *str
, int maxw
)
202 INFOWIN_BUFFER(p
)[0]='\0';
204 if(maxw
>0 && p
->brush
!=NULL
){
205 char *tmp
=grbrush_make_label(p
->brush
, str
, maxw
);
207 infowin_do_set_text(p
, tmp
);
214 infowin_do_set_text(p
, str
);
219 /* sometimes unnecessary */
220 window_draw((WWindow
*)p
, TRUE
);
230 WRegion
*infowin_load(WWindow
*par
, const WFitParams
*fp
, ExtlTab tab
)
232 char *style
=NULL
, *text
=NULL
;
235 extl_table_gets_s(tab
, "style", &style
);
237 p
=create_infowin(par
, fp
, style
);
244 if(extl_table_gets_s(tab
, "text", &text
)){
245 infowin_do_set_text(p
, text
);
256 /*{{{ Dynamic function table and class implementation */
259 static DynFunTab infowin_dynfuntab
[]={
260 {window_draw
, infowin_draw
},
261 {region_updategr
, infowin_updategr
},
267 IMPLCLASS(WInfoWin
, WWindow
, infowin_deinit
, infowin_dynfuntab
);