1 /* === S I N F G =========================================================== */
2 /*! \file layermove.cpp
3 ** \brief Template File
5 ** $Id: layermove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "layermove.h"
32 #include <sinfgapp/canvasinterface.h>
38 using namespace sinfg;
39 using namespace sinfgapp;
40 using namespace Action;
42 /* === M A C R O S ========================================================= */
44 ACTION_INIT(Action::LayerMove);
45 ACTION_SET_NAME(Action::LayerMove,"layer_move");
46 ACTION_SET_LOCAL_NAME(Action::LayerMove,_("Move Layer"));
47 ACTION_SET_TASK(Action::LayerMove,"move");
48 ACTION_SET_CATEGORY(Action::LayerMove,Action::CATEGORY_LAYER);
49 ACTION_SET_PRIORITY(Action::LayerMove,0);
50 ACTION_SET_VERSION(Action::LayerMove,"0.0");
51 ACTION_SET_CVS_ID(Action::LayerMove,"$Id: layermove.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
53 /* === G L O B A L S ======================================================= */
55 static const int nindex=-1;
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 Action::LayerMove::LayerMove():
67 Action::LayerMove::get_param_vocab()
69 ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
71 ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
72 .set_local_name(_("Layer"))
73 .set_desc(_("Layer to be moved"))
76 ret.push_back(ParamDesc("new_index",Param::TYPE_INTEGER)
77 .set_local_name(_("New Index"))
78 .set_desc(_("Where the layer is to be moved to"))
81 ret.push_back(ParamDesc("dest_canvas",Param::TYPE_CANVAS)
82 .set_local_name(_("Destination Canvas"))
83 .set_desc(_("The canvas the layer is to be moved to"))
91 Action::LayerMove::is_canidate(const ParamList &x)
93 return canidate_check(get_param_vocab(),x);
97 Action::LayerMove::set_param(const sinfg::String& name, const Action::Param ¶m)
99 if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
102 layer=param.get_layer();
107 if(name=="new_index" && param.get_type()==Param::TYPE_INTEGER)
109 new_index=param.get_integer();
114 if(name=="dest_canvas" && param.get_type()==Param::TYPE_CANVAS)
116 dest_canvas=param.get_canvas();
121 return Action::CanvasSpecific::set_param(name,param);
125 Action::LayerMove::is_ready()const
127 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
128 if(!layer || (unsigned)new_index==0xdeadbeef)
130 return Action::CanvasSpecific::is_ready();
134 Action::LayerMove::perform()
136 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
138 Canvas::Handle subcanvas(layer->get_canvas());
139 src_canvas=subcanvas;
141 dest_canvas=subcanvas;
143 // Find the iterator for the layer
144 Canvas::iterator iter=find(src_canvas->begin(),src_canvas->end(),layer);
146 // If we couldn't find the layer in the canvas, then bail
148 throw Error(_("This layer doesn't exist anymore."));
150 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
152 // If the subcanvas isn't the same as the canvas,
153 // then it had better be an inline canvas. If not,
155 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
156 if(get_canvas()->get_root()!=dest_canvas->get_root() || get_canvas()->get_root()!=src_canvas->get_root())
157 throw Error(_("You cannot directly move layers across compositions"));
159 old_index=iter-src_canvas->begin();
163 depth=dest_canvas->size()+new_index+1;
167 set_dirty(layer->active());
169 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
171 // If we were to move it to where it is
172 if(old_index==depth && src_canvas==dest_canvas)
175 if(depth>dest_canvas->size())
176 depth=dest_canvas->size();
180 src_canvas->erase(iter);
182 dest_canvas->insert(dest_canvas->begin()+depth,layer);
183 layer->set_canvas(dest_canvas);
186 dest_canvas->changed(); if(dest_canvas!=src_canvas) src_canvas->changed();
188 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
190 if(get_canvas_interface())
192 if(src_canvas==dest_canvas)
194 if(new_index==old_index-1) // Raise
195 get_canvas_interface()->signal_layer_raised()(layer);
196 else if(new_index==old_index+1) // Lower
197 get_canvas_interface()->signal_layer_lowered()(layer);
200 get_canvas_interface()->signal_layer_moved()(layer,depth,dest_canvas);
205 get_canvas_interface()->signal_layer_moved()(layer,depth,dest_canvas);
208 else sinfg::warning("CanvasInterface not set on action");
210 sinfg::info(__FILE__":%d: layer->count()=%d",__LINE__,layer.count());
214 Action::LayerMove::undo()
216 // Find the iterator for the layer
217 Canvas::iterator iter=find(dest_canvas->begin(),dest_canvas->end(),layer);
219 // If we couldn't find the layer in the canvas, then bail
220 if(*iter!=layer || (get_canvas()!=dest_canvas && !dest_canvas->is_inline()))
221 throw Error(_("This layer doesn't exist anymore."));
223 // If we were to move it to where it is
224 if(old_index==new_index && src_canvas==dest_canvas)
227 // Mark ourselves as dirty if necessary
228 set_dirty(layer->active());
230 dest_canvas->erase(iter);
232 src_canvas->insert(src_canvas->begin()+old_index,layer);
233 layer->set_canvas(src_canvas);
236 dest_canvas->changed(); if(dest_canvas!=src_canvas) src_canvas->changed();
238 // Execute any signals
239 if(get_canvas_interface())
241 if(src_canvas==dest_canvas)
243 if(new_index==old_index+1) // Raise
244 get_canvas_interface()->signal_layer_raised()(layer);
245 else if(new_index==old_index-1) // Lower
246 get_canvas_interface()->signal_layer_lowered()(layer);
249 get_canvas_interface()->signal_layer_moved()(layer,old_index,src_canvas);
254 get_canvas_interface()->signal_layer_moved()(layer,old_index,src_canvas);
255 //get_canvas_interface()->signal_layer_removed()(layer);
256 //get_canvas_interface()->signal_layer_inserted()(layer,old_index);
259 else sinfg::warning("CanvasInterface not set on action");