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)
29 static void get_geom(WMessage
*wmsg
, bool max
, WRectangle
*geom
)
32 geom
->w
=wmsg
->input
.last_fp
.g
.w
;
33 geom
->h
=wmsg
->input
.last_fp
.g
.h
;
35 geom
->w
=REGION_GEOM(wmsg
).w
;
36 geom
->h
=REGION_GEOM(wmsg
).h
;
43 static void wmsg_calc_size(WMessage
*wmsg
, WRectangle
*geom
)
45 WRectangle max_geom
=*geom
;
49 if(WMSG_BRUSH(wmsg
)!=NULL
){
56 fit_listing(WMSG_BRUSH(wmsg
), &g
, &(wmsg
->listing
));
58 grbrush_get_border_widths(WMSG_BRUSH(wmsg
), &bdw
);
60 h
=bdw
.top
+bdw
.bottom
+wmsg
->listing
.toth
;
63 if(h
>max_geom
.h
|| !(wmsg
->input
.last_fp
.mode
®ION_FIT_BOUNDS
))
68 geom
->y
=max_geom
.y
+max_geom
.h
-geom
->h
;
73 void wmsg_size_hints(WMessage
*wmsg
, WSizeHints
*hints_ret
)
77 if(WMSG_BRUSH(wmsg
)!=NULL
){
78 mod_query_get_minimum_extents(WMSG_BRUSH(wmsg
), FALSE
, &w
, &h
);
80 w
+=grbrush_get_text_width(WMSG_BRUSH(wmsg
), "xxxxx", 5);
83 hints_ret
->min_set
=TRUE
;
84 hints_ret
->min_width
=w
;
85 hints_ret
->min_height
=h
;
99 static void init_attr()
102 GR_ALLOCATTR(active
);
103 GR_ALLOCATTR(inactive
);
108 static void wmsg_draw(WMessage
*wmsg
, bool complete
)
112 if(WMSG_BRUSH(wmsg
)==NULL
)
115 get_geom(wmsg
, FALSE
, &geom
);
117 grbrush_begin(WMSG_BRUSH(wmsg
), &geom
,
118 (complete
? 0 : GRBRUSH_NO_CLEAR_OK
));
120 grbrush_set_attr(WMSG_BRUSH(wmsg
), REGION_IS_ACTIVE(wmsg
)
122 : GR_ATTR(inactive
));
124 draw_listing(WMSG_BRUSH(wmsg
), &geom
, &(wmsg
->listing
),
127 grbrush_end(WMSG_BRUSH(wmsg
));
137 static void wmsg_scrollup(WMessage
*wmsg
)
139 if(scrollup_listing(&(wmsg
->listing
)))
140 wmsg_draw(wmsg
, TRUE
);
144 static void wmsg_scrolldown(WMessage
*wmsg
)
146 if(scrolldown_listing(&(wmsg
->listing
)))
147 wmsg_draw(wmsg
, TRUE
);
154 /*{{{ Init, deinit draw config update */
157 static bool wmsg_init(WMessage
*wmsg
, WWindow
*par
, const WFitParams
*fp
,
170 if(p
==NULL
|| *(p
+1)=='\0')
178 ptr
=ALLOC_N(char*, n
);
190 cmsg
=ALLOC_N(char, l
+1);
210 init_listing(&(wmsg
->listing
));
211 setup_listing(&(wmsg
->listing
), ptr
, k
, TRUE
);
213 if(!input_init((WInput
*)wmsg
, par
, fp
)){
214 deinit_listing(&(wmsg
->listing
));
222 WMessage
*create_wmsg(WWindow
*par
, const WFitParams
*fp
, const char *msg
)
224 CREATEOBJ_IMPL(WMessage
, wmsg
, (p
, par
, fp
, msg
));
228 static void wmsg_deinit(WMessage
*wmsg
)
230 if(wmsg
->listing
.strs
!=NULL
)
231 deinit_listing(&(wmsg
->listing
));
233 input_deinit((WInput
*)wmsg
);
237 static const char *wmsg_style(WMessage
*UNUSED(wmsg
))
239 return "input-message";
246 /*{{{ Dynamic function table and class implementation */
249 static DynFunTab wmsg_dynfuntab
[]={
250 {window_draw
, wmsg_draw
},
251 {input_calc_size
, wmsg_calc_size
},
252 {input_scrollup
, wmsg_scrollup
},
253 {input_scrolldown
, wmsg_scrolldown
},
254 {(DynFun
*)input_style
, (DynFun
*)wmsg_style
},
255 {region_size_hints
, wmsg_size_hints
},
261 IMPLCLASS(WMessage
, WInput
, wmsg_deinit
, wmsg_dynfuntab
);