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 <libtu/objp.h>
15 #include <ioncore/common.h>
16 #include <ioncore/strings.h>
17 #include <ioncore/global.h>
18 #include <ioncore/event.h>
19 #include <ioncore/gr-util.h>
20 #include <ioncore/sizehint.h>
21 #include <ioncore/resize.h>
26 #define WMSG_BRUSH(WMSG) ((WMSG)->input.brush)
27 #define WMSG_WIN(WMSG) ((WMSG)->input.win.win)
33 static void get_geom(WMessage *wmsg, bool max, WRectangle *geom)
36 geom->w=wmsg->input.last_fp.g.w;
37 geom->h=wmsg->input.last_fp.g.h;
39 geom->w=REGION_GEOM(wmsg).w;
40 geom->h=REGION_GEOM(wmsg).h;
47 static void wmsg_calc_size(WMessage *wmsg, WRectangle *geom)
49 WRectangle max_geom=*geom;
53 if(WMSG_BRUSH(wmsg)!=NULL){
60 fit_listing(WMSG_BRUSH(wmsg), &g, &(wmsg->listing));
62 grbrush_get_border_widths(WMSG_BRUSH(wmsg), &bdw);
64 h=bdw.top+bdw.bottom+wmsg->listing.toth;
67 if(h>max_geom.h || !(wmsg->input.last_fp.mode®ION_FIT_BOUNDS))
72 geom->y=max_geom.y+max_geom.h-geom->h;
77 void wmsg_size_hints(WMessage *wmsg, WSizeHints *hints_ret)
81 if(WMSG_BRUSH(wmsg)!=NULL){
82 mod_query_get_minimum_extents(WMSG_BRUSH(wmsg), FALSE, &w, &h);
84 w+=grbrush_get_text_width(WMSG_BRUSH(wmsg), "xxxxx", 5);
87 hints_ret->min_set=TRUE;
88 hints_ret->min_width=w;
89 hints_ret->min_height=h;
100 GR_DEFATTR(inactive);
103 static void init_attr()
106 GR_ALLOCATTR(active);
107 GR_ALLOCATTR(inactive);
112 static void wmsg_draw(WMessage *wmsg, bool complete)
116 if(WMSG_BRUSH(wmsg)==NULL)
119 get_geom(wmsg, FALSE, &geom);
121 grbrush_begin(WMSG_BRUSH(wmsg), &geom,
122 (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
124 grbrush_set_attr(WMSG_BRUSH(wmsg), REGION_IS_ACTIVE(wmsg)
126 : GR_ATTR(inactive));
128 draw_listing(WMSG_BRUSH(wmsg), &geom, &(wmsg->listing),
131 grbrush_end(WMSG_BRUSH(wmsg));
141 static void wmsg_scrollup(WMessage *wmsg)
143 if(scrollup_listing(&(wmsg->listing)))
144 wmsg_draw(wmsg, TRUE);
148 static void wmsg_scrolldown(WMessage *wmsg)
150 if(scrolldown_listing(&(wmsg->listing)))
151 wmsg_draw(wmsg, TRUE);
158 /*{{{ Init, deinit draw config update */
161 static bool wmsg_init(WMessage *wmsg, WWindow *par, const WFitParams *fp,
174 if(p==NULL || *(p+1)=='\0')
182 ptr=ALLOC_N(char*, n);
194 cmsg=ALLOC_N(char, l+1);
214 init_listing(&(wmsg->listing));
215 setup_listing(&(wmsg->listing), ptr, k, TRUE);
217 if(!input_init((WInput*)wmsg, par, fp)){
218 deinit_listing(&(wmsg->listing));
226 WMessage *create_wmsg(WWindow *par, const WFitParams *fp, const char *msg)
228 CREATEOBJ_IMPL(WMessage, wmsg, (p, par, fp, msg));
232 static void wmsg_deinit(WMessage *wmsg)
234 if(wmsg->listing.strs!=NULL)
235 deinit_listing(&(wmsg->listing));
237 input_deinit((WInput*)wmsg);
241 static const char *wmsg_style(WMessage *wmsg)
243 return "input-message";
250 /*{{{ Dynamic function table and class implementation */
253 static DynFunTab wmsg_dynfuntab[]={
254 {window_draw, wmsg_draw},
255 {input_calc_size, wmsg_calc_size},
256 {input_scrollup, wmsg_scrollup},
257 {input_scrolldown, wmsg_scrolldown},
258 {(DynFun*)input_style, (DynFun*)wmsg_style},
259 {region_size_hints, wmsg_size_hints},
265 IMPLCLASS(WMessage, WInput, wmsg_deinit, wmsg_dynfuntab);