~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/tb/celltext.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 1996, 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 "celltext.h"
 
23
#include "cell.h"
 
24
#include "grafport.h"
 
25
#include "inputfile.h"
 
26
#include "outputfile.h"
 
27
 
 
28
CellText::CellText(Grafport *g, XFont *ft, Cell *p): SimpleLabel(g, ft) {
 
29
        parent = p;
 
30
        underlined = False;
 
31
}
 
32
 
 
33
CellText::CellText(const CellText &t): SimpleLabel(t) {
 
34
        parent = 0;
 
35
        underlined = False;
 
36
}
 
37
 
 
38
void CellText::Draw() {
 
39
        DrawAligned(TextAlign::CENTER);
 
40
}
 
41
 
 
42
void CellText::DrawAligned(TextAlign::Type a) {
 
43
        if (parent && !parent->IsVisible())
 
44
                return;
 
45
        if (GetText()->length() > 0) {
 
46
                GetGrafport()->SetFont(GetFont());
 
47
                Point tl = *GetTopLeft();
 
48
                Point pos = *GetPosition();
 
49
                if (a == TextAlign::LEFT)
 
50
                        GetGrafport()->DrawStringsLeft(tl.x, tl.y, 
 
51
                                                        GetText(), IsUnderlined());
 
52
                else if (a == TextAlign::RIGHT)
 
53
                        GetGrafport()->DrawStringsRight(tl.x+GetWidth(), tl.y, 
 
54
                                                        GetText(), IsUnderlined());
 
55
                else
 
56
                        GetGrafport()->DrawStringsCentered(pos.x, pos.y, 
 
57
                                                        GetText(), IsUnderlined());
 
58
        }
 
59
}
 
60
 
 
61
void CellText::UndrawAligned(TextAlign::Type a) {
 
62
        DrawAligned(a);
 
63
}
 
64
 
 
65
void CellText::UpdatePosition(const Point *pt) {
 
66
        if (parent) {
 
67
                if (parent->IsVisible())
 
68
                        UndrawAligned(parent->GetColumnAlignment());
 
69
        }
 
70
        else
 
71
                UndrawAligned(TextAlign::CENTER);
 
72
        SetPosition(pt);
 
73
        if (parent) {
 
74
                if (parent->IsVisible())
 
75
                        DrawAligned(parent->GetColumnAlignment());
 
76
        }
 
77
        else
 
78
                DrawAligned(TextAlign::CENTER);
 
79
}
 
80
 
 
81
void CellText::UpdateText(const string *s) {
 
82
        if (parent)
 
83
                UndrawAligned(parent->GetColumnAlignment());
 
84
        else
 
85
                UndrawAligned(TextAlign::CENTER);
 
86
        SetText(s);
 
87
        if (parent)
 
88
                DrawAligned(parent->GetColumnAlignment());
 
89
        else
 
90
                DrawAligned(TextAlign::CENTER);
 
91
}
 
92
 
 
93
void CellText::UpdateFont(XFont *ft) {
 
94
        if (parent)
 
95
                UndrawAligned(parent->GetColumnAlignment());
 
96
        else
 
97
                UndrawAligned(TextAlign::CENTER);
 
98
        SetFont(ft);
 
99
        if (parent)
 
100
                DrawAligned(parent->GetColumnAlignment());
 
101
        else
 
102
                DrawAligned(TextAlign::CENTER);
 
103
}
 
104
 
 
105
void CellText::Write(OutputFile *ofile) {
 
106
        string fontString;
 
107
        GetFont()->GetXLFD(&fontString);
 
108
        (*ofile) << "\t{ Text \"" << *GetText() << "\"}\n";
 
109
        (*ofile) << "\t{ Font \"" << fontString << "\"}\n";
 
110
}
 
111
 
 
112
bool CellText::Read(InputFile *ifile, double format) {
 
113
        string s;
 
114
        if (!ifile->ReadStringAttribute("Text", &s))
 
115
                return False;
 
116
        if (s != "")
 
117
                SetText(&s);
 
118
        if (format >= 1.09) {
 
119
                if (!ifile->ReadStringAttribute("Font", &s))
 
120
                        return False;
 
121
                parent->SetXLFD(s.getstr());
 
122
        }
 
123
        return True;
 
124
}
 
125
 
 
126
 
 
127
void CellText::UpdateUnderlined(bool b) {
 
128
        if (underlined != b) {
 
129
                Undraw();
 
130
                underlined = b;
 
131
                Draw();
 
132
        }
 
133
}