2 * ion/mod_query/wmessage.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
11 #include <libtu/objp.h>
12 #include <ioncore/common.h>
13 #include <ioncore/strings.h>
14 #include <ioncore/global.h>
15 #include <ioncore/event.h>
16 #include <ioncore/gr-util.h>
17 #include <ioncore/sizehint.h>
18 #include <ioncore/resize.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
;
74 void wmsg_size_hints(WMessage
*wmsg
, WSizeHints
*hints_ret
)
78 if(WMSG_BRUSH(wmsg
)!=NULL
){
79 mod_query_get_minimum_extents(WMSG_BRUSH(wmsg
), FALSE
, &w
, &h
);
81 w
+=grbrush_get_text_width(WMSG_BRUSH(wmsg
), "xxxxx", 5);
84 hints_ret
->min_set
=TRUE
;
85 hints_ret
->min_width
=w
;
86 hints_ret
->min_height
=h
;
100 static void init_attr()
103 GR_ALLOCATTR(active
);
104 GR_ALLOCATTR(inactive
);
109 static void wmsg_draw(WMessage
*wmsg
, bool complete
)
113 if(WMSG_BRUSH(wmsg
)==NULL
)
116 get_geom(wmsg
, FALSE
, &geom
);
118 grbrush_begin(WMSG_BRUSH(wmsg
), &geom
,
119 (complete
? 0 : GRBRUSH_NO_CLEAR_OK
));
121 grbrush_set_attr(WMSG_BRUSH(wmsg
), REGION_IS_ACTIVE(wmsg
)
123 : GR_ATTR(inactive
));
125 draw_listing(WMSG_BRUSH(wmsg
), &geom
, &(wmsg
->listing
),
128 grbrush_end(WMSG_BRUSH(wmsg
));
138 static void wmsg_scrollup(WMessage
*wmsg
)
140 if(scrollup_listing(&(wmsg
->listing
)))
141 wmsg_draw(wmsg
, TRUE
);
145 static void wmsg_scrolldown(WMessage
*wmsg
)
147 if(scrolldown_listing(&(wmsg
->listing
)))
148 wmsg_draw(wmsg
, TRUE
);
155 /*{{{ Init, deinit draw config update */
158 static bool wmsg_init(WMessage
*wmsg
, WWindow
*par
, const WFitParams
*fp
,
171 if(p
==NULL
|| *(p
+1)=='\0')
179 ptr
=ALLOC_N(char*, n
);
191 cmsg
=ALLOC_N(char, l
+1);
211 init_listing(&(wmsg
->listing
));
212 setup_listing(&(wmsg
->listing
), ptr
, k
, TRUE
);
214 if(!input_init((WInput
*)wmsg
, par
, fp
)){
215 deinit_listing(&(wmsg
->listing
));
223 WMessage
*create_wmsg(WWindow
*par
, const WFitParams
*fp
, const char *msg
)
225 CREATEOBJ_IMPL(WMessage
, wmsg
, (p
, par
, fp
, msg
));
229 static void wmsg_deinit(WMessage
*wmsg
)
231 if(wmsg
->listing
.strs
!=NULL
)
232 deinit_listing(&(wmsg
->listing
));
234 input_deinit((WInput
*)wmsg
);
238 static const char *wmsg_style(WMessage
*wmsg
)
240 return "input-message";
247 /*{{{ Dynamic function table and class implementation */
250 static DynFunTab wmsg_dynfuntab
[]={
251 {window_draw
, wmsg_draw
},
252 {input_calc_size
, wmsg_calc_size
},
253 {input_scrollup
, wmsg_scrollup
},
254 {input_scrolldown
, wmsg_scrolldown
},
255 {(DynFun
*)input_style
, (DynFun
*)wmsg_style
},
256 {region_size_hints
, wmsg_size_hints
},
262 IMPLCLASS(WMessage
, WInput
, wmsg_deinit
, wmsg_dynfuntab
);