2 * ion/ioncore/infowin.h
4 * Copyright (c) Tuomo Valkonen 1999-2007.
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))
33 p->buffer=ALLOC_N(char, INFOWIN_BUFFER_LEN);
41 p->style=scopy(style);
47 gr_stylespec_init(&p->attr);
54 p->wwin.region.flags|=REGION_SKIP_FOCUS;
56 /* Enable save unders */
58 XChangeWindowAttributes(ioncore_g.dpy, p->wwin.win, CWSaveUnder, &attr);
60 window_select_input(&(p->wwin), IONCORE_EVENTMASK_NORMAL);
65 gr_stylespec_unalloc(&p->attr);
70 window_deinit(&(p->wwin));
75 WInfoWin *create_infowin(WWindow *parent, const WFitParams *fp,
78 CREATEOBJ_IMPL(WInfoWin, infowin, (p, parent, fp, style));
82 void infowin_deinit(WInfoWin *p)
95 grbrush_release(p->brush);
99 gr_stylespec_unalloc(&p->attr);
101 window_deinit(&(p->wwin));
108 /*{{{ Drawing and geometry */
111 void infowin_draw(WInfoWin *p, bool complete)
120 g.w=REGION_GEOM(p).w;
121 g.h=REGION_GEOM(p).h;
123 grbrush_begin(p->brush, &g, GRBRUSH_NO_CLEAR_OK);
124 grbrush_init_attr(p->brush, &p->attr);
125 grbrush_draw_textbox(p->brush, &g, p->buffer, TRUE);
126 grbrush_end(p->brush);
130 void infowin_updategr(WInfoWin *p)
134 assert(p->style!=NULL);
136 nbrush=gr_get_brush(p->wwin.win,
137 region_rootwin_of((WRegion*)p),
143 grbrush_release(p->brush);
147 window_draw(&(p->wwin), TRUE);
155 /*{{{ Content-setting */
158 GrStyleSpec *infowin_stylespec(WInfoWin *p)
164 static void infowin_do_set_text(WInfoWin *p, const char *str)
166 strncpy(INFOWIN_BUFFER(p), str, INFOWIN_BUFFER_LEN);
167 INFOWIN_BUFFER(p)[INFOWIN_BUFFER_LEN-1]='\0';
171 static void infowin_resize(WInfoWin *p)
173 WRQGeomParams rq=RQGEOMPARAMS_INIT;
174 const char *str=INFOWIN_BUFFER(p);
178 rq.flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
180 rq.geom.x=REGION_GEOM(p).x;
181 rq.geom.y=REGION_GEOM(p).y;
183 grbrush_get_border_widths(p->brush, &bdw);
184 grbrush_get_font_extents(p->brush, &fnte);
186 rq.geom.w=bdw.left+bdw.right;
187 rq.geom.w+=grbrush_get_text_width(p->brush, str, strlen(str));
188 rq.geom.h=fnte.max_height+bdw.top+bdw.bottom;
190 if(rectangle_compare(&rq.geom, ®ION_GEOM(p))!=RECTANGLE_SAME)
191 region_rqgeom((WRegion*)p, &rq, NULL);
196 * Set contents of the info window.
199 void infowin_set_text(WInfoWin *p, const char *str, int maxw)
203 if(maxw>0 && p->brush!=NULL){
204 char *tmp=grbrush_make_label(p->brush, str, maxw);
206 infowin_do_set_text(p, tmp);
213 infowin_do_set_text(p, str);
217 /* sometimes unnecessary */
218 window_draw((WWindow*)p, TRUE);
228 WRegion *infowin_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
230 char *style=NULL, *text=NULL;
233 extl_table_gets_s(tab, "style", &style);
235 p=create_infowin(par, fp, style);
242 if(extl_table_gets_s(tab, "text", &text)){
243 infowin_do_set_text(p, text);
254 /*{{{ Dynamic function table and class implementation */
257 static DynFunTab infowin_dynfuntab[]={
258 {window_draw, infowin_draw},
259 {region_updategr, infowin_updategr},
265 IMPLCLASS(WInfoWin, WWindow, infowin_deinit, infowin_dynfuntab);