]> git.decadent.org.uk Git - ion3.git/blob - mod_query/input.c
[svn-upgrade] Integrating new upstream version, ion3 (20080411)
[ion3.git] / mod_query / input.c
1 /*
2  * ion/mod_query/input.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2008. 
5  *
6  * See the included file LICENSE for details.
7  */
8
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"
17
18
19 /*{{{ Dynfuns */
20
21
22 /*EXTL_DOC
23  * Scroll input \var{input} text contents up.
24  */
25 EXTL_EXPORT_MEMBER
26 void input_scrollup(WInput *input)
27 {
28     CALL_DYN(input_scrollup, input, (input));
29 }
30
31
32 /*EXTL_DOC
33  * Scroll input \var{input} text contents down.
34  */
35 EXTL_EXPORT_MEMBER
36 void input_scrolldown(WInput *input)
37 {
38     CALL_DYN(input_scrolldown, input, (input));
39 }
40
41
42 void input_calc_size(WInput *input, WRectangle *geom)
43 {
44     *geom=input->last_fp.g;
45     {
46         CALL_DYN(input_calc_size, input, (input, geom));
47     }
48 }
49
50
51 const char *input_style(WInput *input)
52 {
53     const char *ret="input";
54     CALL_DYN_RET(ret, const char*, input_style, input, (input));
55     return ret;
56 }
57
58
59 /*}}}*/
60
61
62 /*{{{ Resize and draw config update */
63
64
65 static void input_do_refit(WInput *input, WWindow *par)
66 {
67     WRectangle g;
68     input_calc_size(input, &g);
69     window_do_fitrep(&input->win, par, &g);
70 }
71
72
73 void input_refit(WInput *input)
74 {
75     input_do_refit(input, NULL);
76 }
77
78
79 bool input_fitrep(WInput *input, WWindow *par, const WFitParams *fp)
80 {
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);
85     
86     return TRUE;
87 }
88
89
90 void input_updategr(WInput *input)
91 {
92     GrBrush *brush;
93     
94     brush=gr_get_brush(input->win.win,
95                        region_rootwin_of((WRegion*)input),
96                        input_style(input));
97     
98     if(brush==NULL)
99         return;
100     
101     if(input->brush!=NULL)
102         grbrush_release(input->brush);
103     input->brush=brush;
104     input_refit(input);
105     
106     region_updategr_default((WRegion*)input);
107     
108     window_draw((WWindow*)input, TRUE);
109 }
110
111
112 /*}}}*/
113
114
115 /*{{{ Init/deinit */
116
117
118 bool input_init(WInput *input, WWindow *par, const WFitParams *fp)
119 {
120     Window win;
121
122     input->last_fp=*fp;
123
124     if(!window_init((WWindow*)input, par, fp))
125         return FALSE;
126
127     win=input->win.win;
128     
129     input->brush=gr_get_brush(win, region_rootwin_of((WRegion*)par),
130                               input_style(input));
131     
132     if(input->brush==NULL)
133         goto fail;
134     
135     input_refit(input);
136     window_select_input(&(input->win), IONCORE_EVENTMASK_NORMAL);
137
138     region_add_bindmap((WRegion*)input, mod_query_input_bindmap);
139     
140     region_register((WRegion*)input);
141     
142     return TRUE;
143     
144 fail:
145     window_deinit((WWindow*)input);
146     return FALSE;
147 }
148
149
150 void input_deinit(WInput *input)
151 {
152     if(input->brush!=NULL)
153         grbrush_release(input->brush);
154     
155     window_deinit((WWindow*)input);
156 }
157
158
159 /*EXTL_DOC
160  * Close input not calling any possible finish handlers.
161  */
162 EXTL_EXPORT_MEMBER
163 void input_cancel(WInput *input)
164 {
165     region_defer_rqdispose((WRegion*)input);
166 }
167
168
169 /*}}}*/
170
171
172 /*{{{ Focus  */
173
174
175 static void input_inactivated(WInput *input)
176 {
177     window_draw((WWindow*)input, FALSE);
178 }
179
180
181 static void input_activated(WInput *input)
182 {
183     window_draw((WWindow*)input, FALSE);
184 }
185
186
187 /*}}}*/
188
189
190 /*{{{{ Misc */
191
192
193 void mod_query_get_minimum_extents(GrBrush *brush, bool with_spacing, 
194                                    int *w, int *h)
195 {
196     GrBorderWidths bdw;
197     GrFontExtents fnte;
198     int spc;
199     
200     grbrush_get_border_widths(brush, &bdw);
201     grbrush_get_font_extents(brush, &fnte);
202     
203     spc=(with_spacing ? bdw.spacing : 0);
204     
205     *h=(fnte.max_height+bdw.top+bdw.bottom+spc);
206     *w=(bdw.left+bdw.right+spc);
207 }
208
209
210 /*}}}*/
211
212
213 /*{{{ Dynamic function table and class implementation */
214
215
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
222 };
223
224
225 EXTL_EXPORT
226 IMPLCLASS(WInput, WWindow, input_deinit, input_dynfuntab);
227
228     
229 /*}}}*/