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>
28 bool infowin_init(WInfoWin *p, WWindow *parent, const WFitParams *fp,
31 XSetWindowAttributes attr;
33 if(!window_init(&(p->wwin), parent, fp))
36 p->buffer=ALLOC_N(char, INFOWIN_BUFFER_LEN);
44 p->style=scopy(style);
50 gr_stylespec_init(&p->attr);
57 p->wwin.region.flags|=REGION_SKIP_FOCUS;
59 /* Enable save unders */
61 XChangeWindowAttributes(ioncore_g.dpy, p->wwin.win, CWSaveUnder, &attr);
63 window_select_input(&(p->wwin), IONCORE_EVENTMASK_NORMAL);
68 gr_stylespec_unalloc(&p->attr);
73 window_deinit(&(p->wwin));
78 WInfoWin *create_infowin(WWindow *parent, const WFitParams *fp,
81 CREATEOBJ_IMPL(WInfoWin, infowin, (p, parent, fp, style));
85 void infowin_deinit(WInfoWin *p)
98 grbrush_release(p->brush);
102 gr_stylespec_unalloc(&p->attr);
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_init_attr(p->brush, &p->attr);
128 grbrush_draw_textbox(p->brush, &g, p->buffer, TRUE);
129 grbrush_end(p->brush);
133 void infowin_updategr(WInfoWin *p)
137 assert(p->style!=NULL);
139 nbrush=gr_get_brush(p->wwin.win,
140 region_rootwin_of((WRegion*)p),
146 grbrush_release(p->brush);
150 window_draw(&(p->wwin), TRUE);
158 /*{{{ Content-setting */
161 GrStyleSpec *infowin_stylespec(WInfoWin *p)
167 static void infowin_do_set_text(WInfoWin *p, const char *str)
169 strncpy(INFOWIN_BUFFER(p), str, INFOWIN_BUFFER_LEN);
170 INFOWIN_BUFFER(p)[INFOWIN_BUFFER_LEN-1]='\0';
174 static void infowin_resize(WInfoWin *p)
176 WRQGeomParams rq=RQGEOMPARAMS_INIT;
177 const char *str=INFOWIN_BUFFER(p);
181 rq.flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
183 rq.geom.x=REGION_GEOM(p).x;
184 rq.geom.y=REGION_GEOM(p).y;
186 grbrush_get_border_widths(p->brush, &bdw);
187 grbrush_get_font_extents(p->brush, &fnte);
189 rq.geom.w=bdw.left+bdw.right;
190 rq.geom.w+=grbrush_get_text_width(p->brush, str, strlen(str));
191 rq.geom.h=fnte.max_height+bdw.top+bdw.bottom;
193 if(rectangle_compare(&rq.geom, ®ION_GEOM(p))!=RECTANGLE_SAME)
194 region_rqgeom((WRegion*)p, &rq, NULL);
199 * Set contents of the info window.
202 void infowin_set_text(WInfoWin *p, const char *str, int maxw)
206 if(maxw>0 && p->brush!=NULL){
207 char *tmp=grbrush_make_label(p->brush, str, maxw);
209 infowin_do_set_text(p, tmp);
216 infowin_do_set_text(p, str);
220 /* sometimes unnecessary */
221 window_draw((WWindow*)p, TRUE);
231 WRegion *infowin_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
233 char *style=NULL, *text=NULL;
236 extl_table_gets_s(tab, "style", &style);
238 p=create_infowin(par, fp, style);
245 if(extl_table_gets_s(tab, "text", &text)){
246 infowin_do_set_text(p, text);
257 /*{{{ Dynamic function table and class implementation */
260 static DynFunTab infowin_dynfuntab[]={
261 {window_draw, infowin_draw},
262 {region_updategr, infowin_updategr},
268 IMPLCLASS(WInfoWin, WWindow, infowin_deinit, infowin_dynfuntab);