2 * ion/ioncore/infowin.h
4 * Copyright (c) Tuomo Valkonen 1999-2007.
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);
49 gr_stylespec_init(&p->attr);
56 p->wwin.region.flags|=REGION_SKIP_FOCUS;
58 /* Enable save unders */
60 XChangeWindowAttributes(ioncore_g.dpy, p->wwin.win, CWSaveUnder, &attr);
62 window_select_input(&(p->wwin), IONCORE_EVENTMASK_NORMAL);
67 gr_stylespec_unalloc(&p->attr);
72 window_deinit(&(p->wwin));
77 WInfoWin *create_infowin(WWindow *parent, const WFitParams *fp,
80 CREATEOBJ_IMPL(WInfoWin, infowin, (p, parent, fp, style));
84 void infowin_deinit(WInfoWin *p)
97 grbrush_release(p->brush);
101 gr_stylespec_unalloc(&p->attr);
103 window_deinit(&(p->wwin));
110 /*{{{ Drawing and geometry */
113 void infowin_draw(WInfoWin *p, bool complete)
122 g.w=REGION_GEOM(p).w;
123 g.h=REGION_GEOM(p).h;
125 grbrush_begin(p->brush, &g, GRBRUSH_NO_CLEAR_OK);
126 grbrush_init_attr(p->brush, &p->attr);
127 grbrush_draw_textbox(p->brush, &g, p->buffer, 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 GrStyleSpec *infowin_stylespec(WInfoWin *p)
166 static void infowin_do_set_text(WInfoWin *p, const char *str)
168 strncpy(INFOWIN_BUFFER(p), str, INFOWIN_BUFFER_LEN);
169 INFOWIN_BUFFER(p)[INFOWIN_BUFFER_LEN-1]='\0';
173 static void infowin_resize(WInfoWin *p)
175 WRQGeomParams rq=RQGEOMPARAMS_INIT;
176 const char *str=INFOWIN_BUFFER(p);
180 rq.flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
182 rq.geom.x=REGION_GEOM(p).x;
183 rq.geom.y=REGION_GEOM(p).y;
185 grbrush_get_border_widths(p->brush, &bdw);
186 grbrush_get_font_extents(p->brush, &fnte);
188 rq.geom.w=bdw.left+bdw.right;
189 rq.geom.w+=grbrush_get_text_width(p->brush, str, strlen(str));
190 rq.geom.h=fnte.max_height+bdw.top+bdw.bottom;
192 if(rectangle_compare(&rq.geom, ®ION_GEOM(p))!=RECTANGLE_SAME)
193 region_rqgeom((WRegion*)p, &rq, NULL);
198 * Set contents of the info window.
201 void infowin_set_text(WInfoWin *p, const char *str)
203 infowin_do_set_text(p, str);
207 /* sometimes unnecessary */
208 window_draw((WWindow*)p, TRUE);
218 WRegion *infowin_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
220 char *style=NULL, *text=NULL;
223 extl_table_gets_s(tab, "style", &style);
225 p=create_infowin(par, fp, style);
232 if(extl_table_gets_s(tab, "text", &text)){
233 infowin_do_set_text(p, text);
244 /*{{{ Dynamic function table and class implementation */
247 static DynFunTab infowin_dynfuntab[]={
248 {window_draw, infowin_draw},
249 {region_updategr, infowin_updategr},
255 IMPLCLASS(WInfoWin, WWindow, infowin_deinit, infowin_dynfuntab);