Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_04 / synfig-studio / src / synfigapp / actions / layerlower.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file layerlower.cpp
3 **      \brief Template File
4 **
5 **      $Id: layerlower.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "layerlower.h"
33 #include "layermove.h"
34 #include <synfigapp/canvasinterface.h>
35
36 #endif
37
38 using namespace std;
39 using namespace etl;
40 using namespace synfig;
41 using namespace synfigapp;
42 using namespace Action;
43
44 /* === M A C R O S ========================================================= */
45
46 ACTION_INIT(Action::LayerLower);
47 ACTION_SET_NAME(Action::LayerLower,"layer_lower");
48 ACTION_SET_LOCAL_NAME(Action::LayerLower,"Lower Layer");
49 ACTION_SET_TASK(Action::LayerLower,"lower");
50 ACTION_SET_CATEGORY(Action::LayerLower,Action::CATEGORY_LAYER);
51 ACTION_SET_PRIORITY(Action::LayerLower,10);
52 ACTION_SET_VERSION(Action::LayerLower,"0.0");
53 ACTION_SET_CVS_ID(Action::LayerLower,"$Id: layerlower.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
54
55 /* === G L O B A L S ======================================================= */
56
57 /* === P R O C E D U R E S ================================================= */
58
59 /* === M E T H O D S ======================================================= */
60
61 Action::LayerLower::LayerLower()
62 {
63 }
64
65 Action::ParamVocab
66 Action::LayerLower::get_param_vocab()
67 {
68         ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
69         
70         ret.push_back(ParamDesc("layer",Param::TYPE_LAYER)
71                 .set_local_name(_("Layer"))
72                 .set_desc(_("Layer to be lowered"))
73                 .set_supports_multiple()
74         );
75         
76         return ret;
77 }
78
79 bool
80 Action::LayerLower::is_canidate(const ParamList &x)
81 {
82         if(!canidate_check(get_param_vocab(),x))
83                 return false;
84         
85         Layer::Handle layer(x.find("layer")->second.get_layer());
86         //synfig::info("layer->get_depth()= %d ; layer->get_canvas()->size()=%d ;",layer->get_depth(),layer->get_canvas()->size());
87         if(layer->get_depth()+1>=layer->get_canvas()->size())
88                 return false;
89         return true;
90 }
91
92 bool
93 Action::LayerLower::set_param(const synfig::String& name, const Action::Param &param)
94 {
95         if(name=="layer" && param.get_type()==Param::TYPE_LAYER)
96         {
97                 layers.push_back(param.get_layer());
98                 
99                 return true;
100         }
101
102         return Action::CanvasSpecific::set_param(name,param);
103 }
104
105 bool
106 Action::LayerLower::is_ready()const
107 {
108         if(layers.empty())
109                 return false;
110         return Action::CanvasSpecific::is_ready();
111 }
112
113 void
114 Action::LayerLower::prepare()
115 {
116         std::list<synfig::Layer::Handle>::const_iterator iter;
117
118         clear();
119         
120         for(iter=layers.begin();iter!=layers.end();++iter)
121         {
122                 Layer::Handle layer(*iter);
123                 
124                 Canvas::Handle subcanvas(layer->get_canvas());
125                 
126                 // Find the iterator for the layer
127                 Canvas::iterator iter=find(subcanvas->begin(),subcanvas->end(),layer);
128                 
129                 // If we couldn't find the layer in the canvas, then bail
130                 if(*iter!=layer)
131                         throw Error(_("This layer doesn't exist anymore."));
132         
133                 // If the subcanvas isn't the same as the canvas,
134                 // then it had better be an inline canvas. If not,
135                 // bail
136                 //if(get_canvas()!=subcanvas && !subcanvas->is_inline())
137                 //      throw Error(_("This layer doesn't belong to this canvas anymore"));
138                 
139                 int new_index=iter-subcanvas->begin();
140                                 
141                 new_index++;
142                 
143                 // If this lowers the layer past the bottom then don't bother
144                 if(new_index==subcanvas->size())
145                         continue;
146                 
147                 Action::Handle layer_move(LayerMove::create());
148                 
149                 layer_move->set_param("canvas",get_canvas());
150                 layer_move->set_param("canvas_interface",get_canvas_interface());
151                 layer_move->set_param("layer",layer);
152                 layer_move->set_param("new_index",new_index);
153                 
154                 add_action_front(layer_move);
155         }
156 }