Remove unused variables
[notion.git] / mod_query / wmessage.c
blob80ba20331a7da4900f778b04766cf09450c3d084
1 /*
2 * ion/mod_query/wmessage.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <string.h>
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>
19 #include "wmessage.h"
20 #include "inputp.h"
23 #define WMSG_BRUSH(WMSG) ((WMSG)->input.brush)
26 /*{{{ Sizecalc */
29 static void get_geom(WMessage *wmsg, bool max, WRectangle *geom)
31 if(max){
32 geom->w=wmsg->input.last_fp.g.w;
33 geom->h=wmsg->input.last_fp.g.h;
34 }else{
35 geom->w=REGION_GEOM(wmsg).w;
36 geom->h=REGION_GEOM(wmsg).h;
38 geom->x=0;
39 geom->y=0;
43 static void wmsg_calc_size(WMessage *wmsg, WRectangle *geom)
45 WRectangle max_geom=*geom;
46 GrBorderWidths bdw;
47 int h=16;
49 if(WMSG_BRUSH(wmsg)!=NULL){
50 WRectangle g;
51 g.w=max_geom.w;
52 g.h=max_geom.h;
53 g.x=0;
54 g.y=0;
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&REGION_FIT_BOUNDS))
64 h=max_geom.h;
66 geom->h=h;
67 geom->w=max_geom.w;
68 geom->y=max_geom.y+max_geom.h-geom->h;
69 geom->x=max_geom.x;
73 void wmsg_size_hints(WMessage *wmsg, WSizeHints *hints_ret)
75 int w=1, h=1;
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;
89 /*}}}*/
92 /*{{{ Draw */
95 GR_DEFATTR(active);
96 GR_DEFATTR(inactive);
99 static void init_attr()
101 GR_ALLOCATTR_BEGIN;
102 GR_ALLOCATTR(active);
103 GR_ALLOCATTR(inactive);
104 GR_ALLOCATTR_END;
108 static void wmsg_draw(WMessage *wmsg, bool complete)
110 WRectangle geom;
112 if(WMSG_BRUSH(wmsg)==NULL)
113 return;
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)
121 ? GR_ATTR(active)
122 : GR_ATTR(inactive));
124 draw_listing(WMSG_BRUSH(wmsg), &geom, &(wmsg->listing),
125 FALSE, GRATTR_NONE);
127 grbrush_end(WMSG_BRUSH(wmsg));
131 /*}}}*/
134 /*{{{ Scroll */
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);
151 /*}}}*/
154 /*{{{ Init, deinit draw config update */
157 static bool wmsg_init(WMessage *wmsg, WWindow *par, const WFitParams *fp,
158 const char *msg)
160 char **ptr;
161 int k, n=0;
162 char *cmsg;
163 const char *p;
164 size_t l;
166 p=msg;
167 while(1){
168 n=n+1;
169 p=strchr(p, '\n');
170 if(p==NULL || *(p+1)=='\0')
171 break;
172 p=p+1;
175 if(n==0)
176 return FALSE;
178 ptr=ALLOC_N(char*, n);
180 if(ptr==NULL)
181 return FALSE;
183 for(k=0; k<n; k++)
184 ptr[k]=NULL;
186 p=msg;
187 k=0;
188 while(k<n){
189 l=strcspn(p, "\n");
190 cmsg=ALLOC_N(char, l+1);
191 if(cmsg==NULL){
192 while(k>0){
193 k--;
194 free(ptr[k]);
196 free(ptr);
197 return FALSE;
199 strncpy(cmsg, p, l);
200 cmsg[l]='\0';
201 ptr[k]=cmsg;
202 k++;
203 if(p[l]=='\0')
204 break;
205 p=p+l+1;
208 init_attr();
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));
215 return FALSE;
218 return TRUE;
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";
243 /*}}}*/
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},
256 END_DYNFUNTAB
260 EXTL_EXPORT
261 IMPLCLASS(WMessage, WInput, wmsg_deinit, wmsg_dynfuntab);
264 /*}}}*/