1/*
2* Copyright (c) 2018 (https://github.com/phase1geo/Minder)
3*
4* This program is free software; you can redistribute it and/or
5* modify it under the terms of the GNU General Public
6* License as published by the Free Software Foundation; either
7* version 2 of the License, or (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12* General Public License for more details.
13*
14* You should have received a copy of the GNU General Public
15* License along with this program; if not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17* Boston, MA 02110-1301 USA
18*
19* Authored by: Trevor Williams <phase1geo@gmail.com>
20*/
21
22public class LayoutManual : Layout {
23
24  /* Default constructor */
25  public LayoutManual() {
26    name = _( "Manual" );
27    icon = "minder-layout-manual-symbolic";
28    balanceable = false;
29  }
30
31  /* Initializes this layout */
32  public override void initialize( Node parent ) {}
33
34  /* Maps the given side to the appropriate side for this layout */
35  public override NodeSide side_mapping( NodeSide side ) {
36    return( side );
37  }
38
39  /* Updates the tree boundaries */
40  private void update_tree( Node n ) {
41    update_tree_size( n );
42    while( n.parent != null ) {
43      update_tree_size( n.parent );
44      n = n.parent;
45    }
46  }
47
48  /* Updates the layout when necessary when a node is edited */
49  public override void handle_update_by_edit( Node n, double diffw, double diffh ) {
50    update_tree( n );
51  }
52
53  /* Called when a node's fold indicator changes */
54  public override void handle_update_by_fold( Node n ) {
55    update_tree( n );
56  }
57
58  /* Called when we are inserting a node within a parent */
59  public override void handle_update_by_insert( Node parent, Node child, int pos ) {
60    if( !child.attached ) {
61      base.handle_update_by_insert( parent, child, pos );
62    } else {
63      update_tree( child );
64    }
65  }
66
67  /* Called to layout the leftover children of a parent node when a node is deleted */
68  public override void handle_update_by_delete( Node parent, int index, NodeSide side, double size ) {
69    update_tree( parent );
70  }
71
72}
73