2 * ion/mod_query/wmessage.c
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 <ioncore/common.h>
15 #include <libtu/objp.h>
16 #include <ioncore/strings.h>
17 #include <ioncore/global.h>
18 #include <ioncore/event.h>
23 #define WMSG_BRUSH(WMSG) ((WMSG)->input.brush)
24 #define WMSG_WIN(WMSG) ((WMSG)->input.win.win)
30 static void get_geom(WMessage *wmsg, bool max, WRectangle *geom)
33 geom->w=wmsg->input.last_fp.g.w;
34 geom->h=wmsg->input.last_fp.g.h;
36 geom->w=REGION_GEOM(wmsg).w;
37 geom->h=REGION_GEOM(wmsg).h;
44 static void wmsg_calc_size(WMessage *wmsg, WRectangle *geom)
46 WRectangle max_geom=*geom;
50 if(WMSG_BRUSH(wmsg)!=NULL){
57 fit_listing(WMSG_BRUSH(wmsg), &g, &(wmsg->listing));
59 grbrush_get_border_widths(WMSG_BRUSH(wmsg), &bdw);
61 h=bdw.top+bdw.bottom+wmsg->listing.toth;
64 if(h>max_geom.h || !(wmsg->input.last_fp.mode®ION_FIT_BOUNDS))
69 geom->y=max_geom.y+max_geom.h-geom->h;
80 static void wmsg_draw(WMessage *wmsg, bool complete)
82 const char *style=(REGION_IS_ACTIVE(wmsg) ? "active" : "inactive");
85 if(WMSG_BRUSH(wmsg)==NULL)
88 get_geom(wmsg, FALSE, &geom);
90 grbrush_begin(WMSG_BRUSH(wmsg), &geom,
91 (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
93 draw_listing(WMSG_BRUSH(wmsg), &geom, &(wmsg->listing),
96 grbrush_end(WMSG_BRUSH(wmsg));
106 static void wmsg_scrollup(WMessage *wmsg)
108 if(scrollup_listing(&(wmsg->listing)))
109 wmsg_draw(wmsg, TRUE);
113 static void wmsg_scrolldown(WMessage *wmsg)
115 if(scrolldown_listing(&(wmsg->listing)))
116 wmsg_draw(wmsg, TRUE);
123 /*{{{ Init, deinit draw config update */
126 static bool wmsg_init(WMessage *wmsg, WWindow *par, const WFitParams *fp,
139 if(p==NULL || *(p+1)=='\0')
147 ptr=ALLOC_N(char*, n);
159 cmsg=ALLOC_N(char, l+1);
177 init_listing(&(wmsg->listing));
178 setup_listing(&(wmsg->listing), ptr, k, TRUE);
180 if(!input_init((WInput*)wmsg, par, fp)){
181 deinit_listing(&(wmsg->listing));
189 WMessage *create_wmsg(WWindow *par, const WFitParams *fp, const char *msg)
191 CREATEOBJ_IMPL(WMessage, wmsg, (p, par, fp, msg));
195 static void wmsg_deinit(WMessage *wmsg)
197 if(wmsg->listing.strs!=NULL)
198 deinit_listing(&(wmsg->listing));
200 input_deinit((WInput*)wmsg);
204 static const char *wmsg_style(WMessage *wmsg)
206 return "input-message";
213 /*{{{ Dynamic function table and class implementation */
216 static DynFunTab wmsg_dynfuntab[]={
217 {window_draw, wmsg_draw},
218 {input_calc_size, wmsg_calc_size},
219 {input_scrollup, wmsg_scrollup},
220 {input_scrolldown, wmsg_scrolldown},
221 {(DynFun*)input_style,
222 (DynFun*)wmsg_style},
228 IMPLCLASS(WMessage, WInput, wmsg_deinit, wmsg_dynfuntab);