]> git.decadent.org.uk Git - ion3.git/blob - mod_tiling/panehandle.c
480e02d052fe8fc7d1cce81deba8e17cf806fc54
[ion3.git] / mod_tiling / panehandle.c
1 /*
2  * ion/mod_tiling/panehandle.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
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 "panehandle.h"
22 #include "main.h"
23
24
25 /*{{{ Init/deinit */
26
27
28 static void panehandle_getbrush(WPaneHandle *pwin)
29 {
30     GrBrush *brush=gr_get_brush(pwin->wwin.win, 
31                                 region_rootwin_of((WRegion*)pwin), 
32                                 "pane");
33
34     if(brush!=NULL){
35         if(pwin->brush!=NULL)
36             grbrush_release(pwin->brush);
37         
38         pwin->brush=brush;
39         
40         grbrush_get_border_widths(brush, &(pwin->bdw));
41         grbrush_enable_transparency(brush, GR_TRANSPARENCY_YES);
42     }
43 }
44
45
46 bool panehandle_init(WPaneHandle *pwin, WWindow *parent, const WFitParams *fp)
47 {
48     pwin->brush=NULL;
49     pwin->bline=GR_BORDERLINE_NONE;
50     pwin->splitfloat=NULL;
51     
52     if(!window_init(&(pwin->wwin), parent, fp))
53         return FALSE;
54     
55     ((WRegion*)pwin)->flags|=REGION_SKIP_FOCUS;
56     
57     panehandle_getbrush(pwin);
58     
59     if(pwin->brush==NULL){
60         GrBorderWidths bdw=GR_BORDER_WIDTHS_INIT;
61         memcpy(&(pwin->bdw), &bdw, sizeof(bdw));
62     }
63
64     window_select_input(&(pwin->wwin), IONCORE_EVENTMASK_NORMAL);
65     
66     return TRUE;
67 }
68
69
70 WPaneHandle *create_panehandle(WWindow *parent, const WFitParams *fp)
71 {
72     CREATEOBJ_IMPL(WPaneHandle, panehandle, (p, parent, fp));
73 }
74
75
76 void panehandle_deinit(WPaneHandle *pwin)
77 {
78     assert(pwin->splitfloat==NULL);
79     
80     if(pwin->brush!=NULL){
81         grbrush_release(pwin->brush);
82         pwin->brush=NULL;
83     }
84     
85     window_deinit(&(pwin->wwin));
86 }
87
88
89 /*}}}*/
90
91
92 /*{{{ Drawing */
93
94
95 static void panehandle_updategr(WPaneHandle *pwin)
96 {
97     panehandle_getbrush(pwin);
98     region_updategr_default((WRegion*)pwin);
99 }
100
101
102 static void panehandle_draw(WPaneHandle *pwin, bool complete)
103 {
104     WRectangle g;
105     
106     if(pwin->brush==NULL)
107         return;
108     
109     g.x=0;
110     g.y=0;
111     g.w=REGION_GEOM(pwin).w;
112     g.h=REGION_GEOM(pwin).h;
113     
114     grbrush_begin(pwin->brush, &g, (complete ? 0 : GRBRUSH_NO_CLEAR_OK));
115     
116     grbrush_draw_borderline(pwin->brush, &g, pwin->bline);
117     
118     grbrush_end(pwin->brush);
119 }
120
121
122 /*}}}*/
123
124
125 /*{{{ The class */
126
127
128 static DynFunTab panehandle_dynfuntab[]={
129     {region_updategr, panehandle_updategr},
130     {window_draw, panehandle_draw},
131     END_DYNFUNTAB,
132 };
133
134
135 IMPLCLASS(WPaneHandle, WWindow, panehandle_deinit, panehandle_dynfuntab);
136
137
138 /*}}}*/
139