trunk: changeset 1958
[notion/jeffpc.git] / mod_query / input.c
blob1ce6a841b7b07ab4520348ec6eaf3c29dbc3d04d
1 /*
2 * ion/mod_query/input.c
4 * Copyright (c) Tuomo Valkonen 1999-2005.
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.
12 #include <libmainloop/defer.h>
13 #include <ioncore/common.h>
14 #include <ioncore/window.h>
15 #include <ioncore/global.h>
16 #include <ioncore/regbind.h>
17 #include <ioncore/event.h>
18 #include "inputp.h"
21 /*{{{ Dynfuns */
24 /*EXTL_DOC
25 * Scroll input \var{input} text contents up.
27 EXTL_EXPORT_MEMBER
28 void input_scrollup(WInput *input)
30 CALL_DYN(input_scrollup, input, (input));
34 /*EXTL_DOC
35 * Scroll input \var{input} text contents down.
37 EXTL_EXPORT_MEMBER
38 void input_scrolldown(WInput *input)
40 CALL_DYN(input_scrolldown, input, (input));
44 void input_calc_size(WInput *input, WRectangle *geom)
46 *geom=input->last_fp.g;
48 CALL_DYN(input_calc_size, input, (input, geom));
53 const char *input_style(WInput *input)
55 const char *ret="input";
56 CALL_DYN_RET(ret, const char*, input_style, input, (input));
57 return ret;
61 /*}}}*/
64 /*{{{ Resize and draw config update */
67 static void input_do_refit(WInput *input, WWindow *par)
69 WRectangle g;
70 input_calc_size(input, &g);
71 window_do_fitrep(&input->win, par, &g);
75 void input_refit(WInput *input)
77 input_do_refit(input, NULL);
81 void input_fitrep(WInput *input, WWindow *par, const WFitParams *fp)
83 input->last_fp=*fp;
84 input_do_refit(input, par);
88 void input_updategr(WInput *input)
90 GrBrush *brush;
92 brush=gr_get_brush(region_rootwin_of((WRegion*)input),
93 input->win.win,
94 input_style(input));
96 if(brush==NULL)
97 return;
99 if(input->brush!=NULL)
100 grbrush_release(input->brush, input->win.win);
101 input->brush=brush;
102 input_refit(input);
104 region_updategr_default((WRegion*)input);
106 window_draw((WWindow*)input, TRUE);
110 /*}}}*/
113 /*{{{ Init/deinit */
116 bool input_init(WInput *input, WWindow *par, const WFitParams *fp)
118 Window win;
120 input->last_fp=*fp;
122 if(!window_init((WWindow*)input, par, fp))
123 return FALSE;
125 win=input->win.win;
127 input->brush=gr_get_brush(region_rootwin_of((WRegion*)par),
128 win, input_style(input));
130 if(input->brush==NULL)
131 goto fail;
133 input_refit(input);
134 window_select_input(&(input->win), IONCORE_EVENTMASK_NORMAL);
136 region_add_bindmap((WRegion*)input, mod_query_input_bindmap);
138 return TRUE;
140 fail:
141 window_deinit((WWindow*)input);
142 return FALSE;
146 void input_deinit(WInput *input)
148 if(input->brush!=NULL)
149 grbrush_release(input->brush, input->win.win);
151 window_deinit((WWindow*)input);
155 /*EXTL_DOC
156 * Close input not calling any possible finish handlers.
158 EXTL_EXPORT_MEMBER
159 void input_cancel(WInput *input)
161 mainloop_defer_destroy((Obj*)input);
165 bool input_rqclose(WInput *input)
167 input_cancel(input);
168 return TRUE;
172 /*}}}*/
175 /*{{{ Focus */
178 static void input_inactivated(WInput *input)
180 window_draw((WWindow*)input, FALSE);
184 static void input_activated(WInput *input)
186 window_draw((WWindow*)input, FALSE);
190 /*}}}*/
193 /*{{{ Dynamic function table and class implementation */
196 static DynFunTab input_dynfuntab[]={
197 {(DynFun*)region_fitrep, (DynFun*)input_fitrep},
198 {region_updategr, input_updategr},
199 {(DynFun*)region_rqclose, (DynFun*)input_rqclose},
200 {region_activated, input_activated},
201 {region_inactivated, input_inactivated},
202 END_DYNFUNTAB
206 IMPLCLASS(WInput, WWindow, input_deinit, input_dynfuntab);
209 /*}}}*/