File: floatwspholder.c

package info (click to toggle)
ion3 20050502-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 5,188 kB
  • ctags: 5,450
  • sloc: ansic: 39,916; perl: 2,445; sh: 1,229; makefile: 639; ruby: 90
file content (161 lines) | stat: -rw-r--r-- 3,121 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
 * ion/mod_floatws/floatwspholder.c
 *
 * Copyright (c) Tuomo Valkonen 2005. 
 *
 * Ion is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 */

#include <libtu/objp.h>
#include <libtu/obj.h>
#include <libtu/pointer.h>

#include <ioncore/common.h>
#include "floatws.h"
#include "floatwspholder.h"


static void floatws_watch_handler(Watch *watch, Obj *floatws);


/*{{{ Init/deinit */


static void floatws_watch_handler(Watch *watch, Obj *floatws)
{
    WFloatWSPHolder *ph=FIELD_TO_STRUCT(WFloatWSPHolder, 
                                        floatws_watch, watch);
    pholder_redirect(&(ph->ph), (WRegion*)floatws);
}


bool floatwspholder_init(WFloatWSPHolder *ph, WFloatWS *floatws,
                         const WRectangle *geom)
{
    pholder_init(&(ph->ph));

    watch_init(&(ph->floatws_watch));
    
    if(floatws==NULL)
        return TRUE;
    
    if(!watch_setup(&(ph->floatws_watch), (Obj*)floatws, 
                    floatws_watch_handler)){
        pholder_deinit(&(ph->ph));
        return FALSE;
    }
    
    ph->geom=*geom;
    
    return TRUE;
}
 

WFloatWSPHolder *create_floatwspholder(WFloatWS *floatws,
                                       const WRectangle *geom)
{
    CREATEOBJ_IMPL(WFloatWSPHolder, floatwspholder, 
                   (p, floatws, geom));
}


void floatwspholder_deinit(WFloatWSPHolder *ph)
{
    watch_reset(&(ph->floatws_watch));
    pholder_deinit(&(ph->ph));
}


/*}}}*/


/*{{{ Dynfuns */


bool floatwspholder_do_attach(WFloatWSPHolder *ph, WRegionAttachHandler *hnd,
                              void *hnd_param)
{
    WFloatWS *ws=(WFloatWS*)ph->floatws_watch.obj;
    WFitParams fp;
    WRegion *reg;
    WWindow *par;

    if(ws==NULL)
        return FALSE;
    
    par=REGION_PARENT(ws);
    
    if(par==NULL)
        return FALSE;
    
    fp.g=ph->geom;
    fp.mode=REGION_FIT_EXACT;

    reg=hnd(par, &fp, hnd_param);
    
    if(reg==NULL)
        return FALSE;
    
    floatws_add_managed(ws, reg);

    return TRUE;
}


bool floatwspholder_do_goto(WFloatWSPHolder *ph)
{
    WFloatWS *ws=(WFloatWS*)ph->floatws_watch.obj;
    
    if(ws!=NULL)
        return region_goto((WRegion*)ws);
    
    return FALSE;
}


WRegion *floatwspholder_do_target(WFloatWSPHolder *ph)
{
    return (WRegion*)ph->floatws_watch.obj;
}


/*}}}*/


/*{{{ WFloatWS stuff */


WFloatWSPHolder *floatws_managed_get_pholder(WFloatWS *floatws, WRegion *mgd)
{
    return create_floatwspholder(floatws, &REGION_GEOM(mgd));
}


/*}}}*/


/*{{{ Class information */


static DynFunTab floatwspholder_dynfuntab[]={
    {(DynFun*)pholder_do_attach, 
     (DynFun*)floatwspholder_do_attach},

    {(DynFun*)pholder_do_goto, 
     (DynFun*)floatwspholder_do_goto},

    {(DynFun*)pholder_do_target, 
     (DynFun*)floatwspholder_do_target},
    
    END_DYNFUNTAB
};

IMPLCLASS(WFloatWSPHolder, WPHolder, floatwspholder_deinit, 
          floatwspholder_dynfuntab);


/*}}}*/