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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
/*
* ion/mod_floatws/floatwsrescueph.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 "floatwsrescueph.h"
static void floatws_watch_handler(Watch *watch, Obj *floatws);
/*{{{ Init/deinit */
static void floatws_watch_handler(Watch *watch, Obj *floatws)
{
WFloatWSRescuePH *ph=FIELD_TO_STRUCT(WFloatWSRescuePH,
floatws_watch, watch);
pholder_redirect(&(ph->ph), (WRegion*)floatws);
}
bool floatwsrescueph_init(WFloatWSRescuePH *ph, WFloatWS *ws,
WRegion *contents, WRegion *or_this)
{
assert(contents!=NULL || or_this!=NULL);
pholder_init(&(ph->ph));
ph->pos_ok=FALSE;
ph->inner_geom=FALSE;
watch_init(&(ph->floatws_watch));
watch_init(&(ph->frame_watch));
if(ws==NULL)
return TRUE;
if(!watch_setup(&(ph->floatws_watch), (Obj*)ws, floatws_watch_handler)){
pholder_deinit(&(ph->ph));
return FALSE;
}
if(contents!=NULL){
ph->geom=REGION_GEOM(contents);
if(REGION_PARENT(contents)==REGION_PARENT(ws))
ph->pos_ok=TRUE;
}else{ /* or_this!=NULL */
WRegion *mgr=REGION_MANAGER(or_this);
if(REGION_PARENT(contents)==REGION_PARENT(ws))
ph->pos_ok=TRUE;
ph->geom=REGION_GEOM(or_this);
ph->inner_geom=TRUE;
}
return TRUE;
}
WFloatWSRescuePH *create_floatwsrescueph(WFloatWS *floatws,
WRegion *contents, WRegion *or_this)
{
CREATEOBJ_IMPL(WFloatWSRescuePH, floatwsrescueph,
(p, floatws, contents, or_this));
}
void floatwsrescueph_deinit(WFloatWSRescuePH *ph)
{
watch_reset(&(ph->floatws_watch));
watch_reset(&(ph->frame_watch));
pholder_deinit(&(ph->ph));
}
/*}}}*/
/*{{{ Dynfuns */
bool floatwsrescueph_do_attach(WFloatWSRescuePH *ph, WRegionAttachHandler *hnd,
void *hnd_param)
{
WFloatWS *ws=(WFloatWS*)ph->floatws_watch.obj;
WFrame *frame=(WFrame*)ph->frame_watch.obj;
if(ws==NULL)
return FALSE;
if(frame==NULL){
frame=(WFrame*)floatws_create_frame(ws, &(ph->geom), StaticGravity,
ph->inner_geom, ph->pos_ok);
if(frame==NULL)
return FALSE;
assert(watch_setup(&(ph->frame_watch), (Obj*)frame, NULL));
}
return (mplex_attach_hnd((WMPlex*)frame, hnd, hnd_param, 0)!=NULL);
}
bool floatwsrescueph_do_goto(WFloatWSRescuePH *ph)
{
WFloatWS *ws=(WFloatWS*)ph->floatws_watch.obj;
WFrame *frame=(WFrame*)ph->frame_watch.obj;
if(frame!=NULL)
return region_goto((WRegion*)frame);
else if(ws!=NULL)
return region_goto((WRegion*)ws);
return FALSE;
}
WRegion *floatwsrescueph_do_target(WFloatWSRescuePH *ph)
{
WRegion *ws=(WRegion*)ph->floatws_watch.obj;
WRegion *frame=(WRegion*)ph->frame_watch.obj;
return (frame!=NULL ? frame : ws);
}
/*}}}*/
/*{{{ WFloatWS stuff */
WFloatWSRescuePH *floatws_get_rescue_pholder_for(WFloatWS *floatws,
WRegion *forwhat)
{
return create_floatwsrescueph(floatws, forwhat, NULL);
}
/*}}}*/
/*{{{ Class information */
static DynFunTab floatwsrescueph_dynfuntab[]={
{(DynFun*)pholder_do_attach,
(DynFun*)floatwsrescueph_do_attach},
{(DynFun*)pholder_do_goto,
(DynFun*)floatwsrescueph_do_goto},
{(DynFun*)pholder_do_target,
(DynFun*)floatwsrescueph_do_target},
END_DYNFUNTAB
};
IMPLCLASS(WFloatWSRescuePH, WPHolder, floatwsrescueph_deinit,
floatwsrescueph_dynfuntab);
/*}}}*/
|