2 * ion/mod_query/wmessage.c
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 <ioncore/common.h>
15 #include <libtu/objp.h>
16 #include <ioncore/strings.h>
17 #include <ioncore/global.h>
18 #include <ioncore/event.h>
19 #include <ioncore/gr-util.h>
24 #define WMSG_BRUSH(WMSG) ((WMSG)->input.brush)
25 #define WMSG_WIN(WMSG) ((WMSG)->input.win.win)
31 static void get_geom(WMessage *wmsg, bool max, WRectangle *geom)
34 geom->w=wmsg->input.last_fp.g.w;
35 geom->h=wmsg->input.last_fp.g.h;
37 geom->w=REGION_GEOM(wmsg).w;
38 geom->h=REGION_GEOM(wmsg).h;
45 static void wmsg_calc_size(WMessage *wmsg, WRectangle *geom)
47 WRectangle max_geom=*geom;
51 if(WMSG_BRUSH(wmsg)!=NULL){
58 fit_listing(WMSG_BRUSH(wmsg), &g, &(wmsg->listing));
60 grbrush_get_border_widths(WMSG_BRUSH(wmsg), &bdw);
62 h=bdw.top+bdw.bottom+wmsg->listing.toth;
65 if(h>max_geom.h || !(wmsg->input.last_fp.mode®ION_FIT_BOUNDS))
70 geom->y=max_geom.y+max_geom.h-geom->h;
85 static void init_attr()
89 GR_ALLOCATTR(inactive);
94 static void wmsg_draw(WMessage *wmsg, bool complete)
98 if(WMSG_BRUSH(wmsg)==NULL)
101 get_geom(wmsg, FALSE, &geom);
103 grbrush_begin(WMSG_BRUSH(wmsg), &geom,
104 (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
106 grbrush_set_attr(WMSG_BRUSH(wmsg), REGION_IS_ACTIVE(wmsg)
108 : GR_ATTR(inactive));
110 draw_listing(WMSG_BRUSH(wmsg), &geom, &(wmsg->listing),
113 grbrush_end(WMSG_BRUSH(wmsg));
123 static void wmsg_scrollup(WMessage *wmsg)
125 if(scrollup_listing(&(wmsg->listing)))
126 wmsg_draw(wmsg, TRUE);
130 static void wmsg_scrolldown(WMessage *wmsg)
132 if(scrolldown_listing(&(wmsg->listing)))
133 wmsg_draw(wmsg, TRUE);
140 /*{{{ Init, deinit draw config update */
143 static bool wmsg_init(WMessage *wmsg, WWindow *par, const WFitParams *fp,
156 if(p==NULL || *(p+1)=='\0')
164 ptr=ALLOC_N(char*, n);
176 cmsg=ALLOC_N(char, l+1);
196 init_listing(&(wmsg->listing));
197 setup_listing(&(wmsg->listing), ptr, k, TRUE);
199 if(!input_init((WInput*)wmsg, par, fp)){
200 deinit_listing(&(wmsg->listing));
208 WMessage *create_wmsg(WWindow *par, const WFitParams *fp, const char *msg)
210 CREATEOBJ_IMPL(WMessage, wmsg, (p, par, fp, msg));
214 static void wmsg_deinit(WMessage *wmsg)
216 if(wmsg->listing.strs!=NULL)
217 deinit_listing(&(wmsg->listing));
219 input_deinit((WInput*)wmsg);
223 static const char *wmsg_style(WMessage *wmsg)
225 return "input-message";
232 /*{{{ Dynamic function table and class implementation */
235 static DynFunTab wmsg_dynfuntab[]={
236 {window_draw, wmsg_draw},
237 {input_calc_size, wmsg_calc_size},
238 {input_scrollup, wmsg_scrollup},
239 {input_scrolldown, wmsg_scrolldown},
240 {(DynFun*)input_style,
241 (DynFun*)wmsg_style},
247 IMPLCLASS(WMessage, WInput, wmsg_deinit, wmsg_dynfuntab);