Slightly better logging for font loading
[notion/jeffpc.git] / mod_query / input.c
blob0414aa31c556432569c044dcb47d3b6c032b1dd0
1 /*
2 * ion/mod_query/input.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libmainloop/defer.h>
10 #include <ioncore/common.h>
11 #include <ioncore/window.h>
12 #include <ioncore/global.h>
13 #include <ioncore/regbind.h>
14 #include <ioncore/event.h>
15 #include <ioncore/names.h>
16 #include "inputp.h"
19 /*{{{ Dynfuns */
22 /*EXTL_DOC
23 * Scroll input \var{input} text contents up.
25 EXTL_EXPORT_MEMBER
26 void input_scrollup(WInput *input)
28 CALL_DYN(input_scrollup, input, (input));
32 /*EXTL_DOC
33 * Scroll input \var{input} text contents down.
35 EXTL_EXPORT_MEMBER
36 void input_scrolldown(WInput *input)
38 CALL_DYN(input_scrolldown, input, (input));
42 void input_calc_size(WInput *input, WRectangle *geom)
44 *geom=input->last_fp.g;
46 CALL_DYN(input_calc_size, input, (input, geom));
51 const char *input_style(WInput *input)
53 const char *ret="input";
54 CALL_DYN_RET(ret, const char*, input_style, input, (input));
55 return ret;
59 /*}}}*/
62 /*{{{ Resize and draw config update */
65 static void input_do_refit(WInput *input, WWindow *par)
67 WRectangle g;
68 input_calc_size(input, &g);
69 window_do_fitrep(&input->win, par, &g);
73 void input_refit(WInput *input)
75 input_do_refit(input, NULL);
79 bool input_fitrep(WInput *input, WWindow *par, const WFitParams *fp)
81 if(par!=NULL && !region_same_rootwin((WRegion*)input, (WRegion*)par))
82 return FALSE;
83 input->last_fp=*fp;
84 input_do_refit(input, par);
86 return TRUE;
90 void input_updategr(WInput *input)
92 GrBrush *brush;
94 brush=gr_get_brush(input->win.win,
95 region_rootwin_of((WRegion*)input),
96 input_style(input));
98 if(brush==NULL)
99 return;
101 if(input->brush!=NULL)
102 grbrush_release(input->brush);
103 input->brush=brush;
104 input_refit(input);
106 region_updategr_default((WRegion*)input);
108 window_draw((WWindow*)input, TRUE);
112 /*}}}*/
115 /*{{{ Init/deinit */
118 bool input_init(WInput *input, WWindow *par, const WFitParams *fp)
120 Window win;
122 input->last_fp=*fp;
124 if(!window_init((WWindow*)input, par, fp, "WInput"))
125 return FALSE;
127 win=input->win.win;
129 input->brush=gr_get_brush(win, region_rootwin_of((WRegion*)par),
130 input_style(input));
132 if(input->brush==NULL)
133 goto fail;
135 input_refit(input);
136 window_select_input(&(input->win), IONCORE_EVENTMASK_NORMAL);
138 region_add_bindmap((WRegion*)input, mod_query_input_bindmap);
140 region_register((WRegion*)input);
142 return TRUE;
144 fail:
145 window_deinit((WWindow*)input);
146 return FALSE;
150 void input_deinit(WInput *input)
152 if(input->brush!=NULL)
153 grbrush_release(input->brush);
155 window_deinit((WWindow*)input);
159 /*EXTL_DOC
160 * Close input not calling any possible finish handlers.
162 EXTL_EXPORT_MEMBER
163 void input_cancel(WInput *input)
165 region_defer_rqdispose((WRegion*)input);
169 /*}}}*/
172 /*{{{ Focus */
175 static void input_inactivated(WInput *input)
177 window_draw((WWindow*)input, FALSE);
181 static void input_activated(WInput *input)
183 window_draw((WWindow*)input, FALSE);
187 /*}}}*/
190 /*{{{{ Misc */
193 void mod_query_get_minimum_extents(GrBrush *brush, bool with_spacing,
194 int *w, int *h)
196 GrBorderWidths bdw;
197 GrFontExtents fnte;
198 int spc;
200 grbrush_get_border_widths(brush, &bdw);
201 grbrush_get_font_extents(brush, &fnte);
203 spc=(with_spacing ? bdw.spacing : 0);
205 *h=(fnte.max_height+bdw.top+bdw.bottom+spc);
206 *w=(bdw.left+bdw.right+spc);
210 /*}}}*/
213 /*{{{ Dynamic function table and class implementation */
216 static DynFunTab input_dynfuntab[]={
217 {(DynFun*)region_fitrep, (DynFun*)input_fitrep},
218 {region_updategr, input_updategr},
219 {region_activated, input_activated},
220 {region_inactivated, input_inactivated},
221 END_DYNFUNTAB
225 EXTL_EXPORT
226 IMPLCLASS(WInput, WWindow, input_deinit, input_dynfuntab);
229 /*}}}*/