2 * ion/ioncore/infowin.h
4 * Copyright (c) Tuomo Valkonen 1999-2006.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <libtu/objp.h>
27 bool infowin_init(WInfoWin *p, WWindow *parent, const WFitParams *fp,
30 XSetWindowAttributes attr;
32 if(!window_init(&(p->wwin), parent, fp))
35 p->buffer=ALLOC_N(char, INFOWIN_BUFFER_LEN);
43 p->style=scopy(style);
55 p->wwin.region.flags|=REGION_SKIP_FOCUS;
57 /* Enable save unders */
59 XChangeWindowAttributes(ioncore_g.dpy, p->wwin.win, CWSaveUnder, &attr);
61 window_select_input(&(p->wwin), IONCORE_EVENTMASK_NORMAL);
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)
100 grbrush_release(p->brush);
104 window_deinit(&(p->wwin));
111 /*{{{ Drawing and geometry */
114 void infowin_draw(WInfoWin *p, bool complete)
123 g.w=REGION_GEOM(p).w;
124 g.h=REGION_GEOM(p).h;
126 grbrush_begin(p->brush, &g, GRBRUSH_NO_CLEAR_OK);
127 grbrush_draw_textbox(p->brush, &g, p->buffer, p->attr, TRUE);
128 grbrush_end(p->brush);
132 void infowin_updategr(WInfoWin *p)
136 assert(p->style!=NULL);
138 nbrush=gr_get_brush(p->wwin.win,
139 region_rootwin_of((WRegion*)p),
145 grbrush_release(p->brush);
149 window_draw(&(p->wwin), TRUE);
157 /*{{{ Content-setting */
160 bool infowin_set_attr2(WInfoWin *p, const char *attr1, const char *attr2)
168 libtu_asprintf(&p2, "%s-%s", attr1, attr2);
182 static void infowin_do_set_text(WInfoWin *p, const char *str)
184 strncpy(INFOWIN_BUFFER(p), str, INFOWIN_BUFFER_LEN);
185 INFOWIN_BUFFER(p)[INFOWIN_BUFFER_LEN-1]='\0';
189 static void infowin_resize(WInfoWin *p)
191 WRQGeomParams rq=RQGEOMPARAMS_INIT;
192 const char *str=INFOWIN_BUFFER(p);
196 rq.flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
198 rq.geom.x=REGION_GEOM(p).x;
199 rq.geom.y=REGION_GEOM(p).y;
201 grbrush_get_border_widths(p->brush, &bdw);
202 grbrush_get_font_extents(p->brush, &fnte);
204 rq.geom.w=bdw.left+bdw.right;
205 rq.geom.w+=grbrush_get_text_width(p->brush, str, strlen(str));
206 rq.geom.h=fnte.max_height+bdw.top+bdw.bottom;
208 if(rectangle_compare(&rq.geom, ®ION_GEOM(p))!=RECTANGLE_SAME)
209 region_rqgeom((WRegion*)p, &rq, NULL);
214 * Set contents of the info window.
217 void infowin_set_text(WInfoWin *p, const char *str)
219 infowin_do_set_text(p, str);
223 /* sometimes unnecessary */
224 window_draw((WWindow*)p, TRUE);
234 WRegion *infowin_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
236 char *style=NULL, *text=NULL;
239 extl_table_gets_s(tab, "style", &style);
241 p=create_infowin(par, fp, style);
248 if(extl_table_gets_s(tab, "text", &text)){
249 infowin_do_set_text(p, text);
260 /*{{{ Dynamic function table and class implementation */
263 static DynFunTab infowin_dynfuntab[]={
264 {window_draw, infowin_draw},
265 {region_updategr, infowin_updategr},
271 IMPLCLASS(WInfoWin, WWindow, infowin_deinit, infowin_dynfuntab);