~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/replacetextcmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
 
4
// (c) copyright 1997, Vrije Universiteit Amsterdam.
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
//
 
7
// TCM is free software; you can redistribute it and/or modify
 
8
// it under the terms of the GNU General Public License as published by
 
9
// the Free Software Foundation; either version 2 of the License, or
 
10
// (at your option) any later version.
 
11
//
 
12
// TCM is distributed in the hope that it will be useful,
 
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
// GNU General Public License for more details.
 
16
//
 
17
// You should have received a copy of the GNU General Public License
 
18
// along with TCM; if not, write to the Free Software
 
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "gshape.h"
 
23
#include "shapeview.h"
 
24
#include "diagramviewer.h"
 
25
#include "diagram.h"
 
26
#include "replacetextcmd.h"
 
27
 
 
28
ReplaceTextCmd::ReplaceTextCmd(ShapeView *v, const string *p, const string *o, 
 
29
                bool c, bool s, bool n): 
 
30
                Command(v->GetViewer()->GetDiagram(), v->GetViewer()) {
 
31
        view = v;
 
32
        diagram = v->GetViewer()->GetDiagram();
 
33
        pattern = new string(*p);
 
34
        replace = new string(*o);
 
35
        caseSensitive = c;
 
36
        substring = s;
 
37
        nameOnly = n;
 
38
        oldSelection = new List<GShape *> (*view->GetSelection());
 
39
        textShapes = new List<TextShape *>;
 
40
        oldStrings = new List<string *>;
 
41
        oldSizes = new List<Point *>;
 
42
}
 
43
 
 
44
ReplaceTextCmd::~ReplaceTextCmd() {
 
45
        oldStrings->clear();
 
46
        oldSizes->clear();
 
47
        delete textShapes;
 
48
        delete pattern;
 
49
        delete replace;
 
50
        delete oldSelection;
 
51
        delete oldSizes;
 
52
        delete oldStrings;
 
53
}
 
54
 
 
55
void ReplaceTextCmd::UnExecute() {
 
56
        for (unsigned i=0; i<textShapes->count(); i++) {
 
57
                TextShape *s = (*textShapes)[i];
 
58
                if (diagram->SetText(s, ((*oldStrings)[i]))) {
 
59
                        if (GetViewer()->IsAutoResize()) {
 
60
                                GShape *parent = (GShape *)s->GetParent();
 
61
                                int oldWidth = (*oldSizes)[i]->x;
 
62
                                int oldHeight = (*oldSizes)[i]->y;
 
63
                                if (parent->GetWidth() != oldWidth || 
 
64
                                        parent->GetHeight() != oldHeight) {
 
65
                                        parent->UpdateSize(oldWidth, oldHeight);
 
66
                                        view->GetViewer()->
 
67
                                                ShapePositionUpdate(parent);
 
68
                                }
 
69
                        }
 
70
                }
 
71
        }
 
72
        view->DeselectAll();
 
73
        for (oldSelection->first(); !oldSelection->done(); oldSelection->next())
 
74
        {
 
75
                GShape *shape = oldSelection->cur();
 
76
                view->SelectShape(shape);
 
77
        }
 
78
        Command::UnExecute();
 
79
}
 
80
 
 
81
void ReplaceTextCmd::ReExecute() {
 
82
        textShapes->empty();
 
83
        oldStrings->clear();
 
84
        oldSizes->clear();
 
85
        Execute();
 
86
}