]> git.decadent.org.uk Git - ion3.git/blob - mod_panews/unusedwin.c
[svn-inject] Installing original source of ion3
[ion3.git] / mod_panews / unusedwin.c
1 /*
2  * ion/panews/unusedwin.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
5  *
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.
10  */
11
12 #include <string.h>
13
14 #include <libtu/objp.h>
15 #include <libtu/minmax.h>
16 #include <ioncore/common.h>
17 #include <ioncore/global.h>
18 #include <ioncore/event.h>
19 #include <ioncore/gr.h>
20 #include <ioncore/regbind.h>
21 #include <ioncore/framep.h>
22 #include <ioncore/presize.h>
23 #include <ioncore/frame-pointer.h>
24 #include "unusedwin.h"
25 #include "splitext.h"
26 #include "placement.h"
27 #include "main.h"
28
29
30 /*{{{ Init/deinit */
31
32
33 static void unusedwin_getbrush(WUnusedWin *uwin)
34 {
35     GrBrush *brush=gr_get_brush(uwin->wwin.win,
36                                 region_rootwin_of((WRegion*)uwin),
37                                 "frame-tiled-panews-unused");
38
39     if(brush!=NULL){
40         if(uwin->brush!=NULL)
41             grbrush_release(uwin->brush);
42         
43         uwin->brush=brush;
44         
45         grbrush_enable_transparency(brush, GR_TRANSPARENCY_YES);
46     }
47 }
48
49
50 bool unusedwin_init(WUnusedWin *uwin, WWindow *parent, const WFitParams *fp)
51 {
52     uwin->brush=NULL;
53     
54     if(!window_init(&(uwin->wwin), parent, fp))
55         return FALSE;
56     
57     unusedwin_getbrush(uwin);
58     
59     region_add_bindmap((WRegion*)uwin, mod_panews_unusedwin_bindmap);
60
61     window_select_input(&(uwin->wwin), IONCORE_EVENTMASK_NORMAL);
62
63     ((WRegion*)uwin)->flags|=REGION_PLEASE_WARP;
64     
65     return TRUE;
66 }
67
68
69 WUnusedWin *create_unusedwin(WWindow *parent, const WFitParams *fp)
70 {
71     CREATEOBJ_IMPL(WUnusedWin, unusedwin, (p, parent, fp));
72 }
73
74
75 void unusedwin_deinit(WUnusedWin *uwin)
76 {
77     if(uwin->brush!=NULL){
78         grbrush_release(uwin->brush);
79         uwin->brush=NULL;
80     }
81     
82     window_deinit(&(uwin->wwin));
83 }
84
85
86 /*}}}*/
87
88
89 /*{{{ unusedwin_press */
90
91
92 static void unusedwin_border_inner_geom(const WUnusedWin *uwin, 
93                                         WRectangle *geom)
94 {
95     GrBorderWidths bdw;
96     
97     geom->x=0;
98     geom->y=0;
99     geom->w=REGION_GEOM(uwin).w;
100     geom->h=REGION_GEOM(uwin).h;
101     
102     if(uwin->brush!=NULL){
103         grbrush_get_border_widths(uwin->brush, &bdw);
104
105         geom->x+=bdw.left;
106         geom->y+=bdw.top;
107         geom->w-=bdw.left+bdw.right;
108         geom->h-=bdw.top+bdw.bottom;
109     }
110     
111     geom->w=maxof(geom->w, 0);
112     geom->h=maxof(geom->h, 0);
113 }
114
115
116 static int unusedwin_press(WUnusedWin *uwin, XButtonEvent *ev, 
117                            WRegion **reg_ret)
118 {
119     WRectangle g;
120     
121     *reg_ret=NULL;
122     
123     window_p_resize_prepare(&uwin->wwin, ev);
124     
125     /* Check border */
126     
127     unusedwin_border_inner_geom(uwin, &g);
128     
129     if(rectangle_contains(&g, ev->x, ev->y))
130         return FRAME_AREA_CLIENT;
131     
132     return FRAME_AREA_BORDER;
133 }
134
135
136 /*}}}*/
137
138
139 /*{{{ unusedwin_handle_drop */
140
141
142 static bool unusedwin_handle_drop(WUnusedWin *uwin, int x, int y,
143                                   WRegion *dropped)
144 {
145     WSplitUnused *us=OBJ_CAST(splittree_node_of((WRegion*)uwin),
146                               WSplitUnused);
147     WPaneWS *ws=REGION_MANAGER_CHK(uwin, WPaneWS);
148     
149     if(us==NULL || ws==NULL)
150         return FALSE;
151     
152     return panews_handle_unused_drop(ws, us, dropped);
153 }
154
155
156 /*}}}*/
157
158
159 /*{{{ Drawing */
160
161
162 static void unusedwin_updategr(WUnusedWin *uwin)
163 {
164     unusedwin_getbrush(uwin);
165     region_updategr_default((WRegion*)uwin);
166 }
167
168
169 static void unusedwin_draw(WUnusedWin *uwin, bool complete)
170 {
171     WRectangle g;
172     const char *substyle=(REGION_IS_ACTIVE(uwin)
173                           ? "active"
174                           : "inactive");
175     
176     if(uwin->brush==NULL)
177         return;
178     
179     g.x=0;
180     g.y=0;
181     g.w=REGION_GEOM(uwin).w;
182     g.h=REGION_GEOM(uwin).h;
183     
184     grbrush_begin(uwin->brush, &g, (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
185     
186     grbrush_draw_border(uwin->brush, &g, substyle);
187     
188     grbrush_end(uwin->brush);
189 }
190
191
192 /*}}}*/
193
194
195 /*{{{ The class */
196
197
198 static DynFunTab unusedwin_dynfuntab[]={
199     {region_updategr, unusedwin_updategr},
200     {window_draw, unusedwin_draw},
201     {(DynFun*)window_press, (DynFun*)unusedwin_press},
202     {(DynFun*)region_handle_drop, (DynFun*)unusedwin_handle_drop},
203     END_DYNFUNTAB,
204 };
205
206
207 IMPLCLASS(WUnusedWin, WWindow, unusedwin_deinit, unusedwin_dynfuntab);
208
209
210 /*}}}*/
211