-
-
Notifications
You must be signed in to change notification settings - Fork 337
/
Document.cpp
126 lines (101 loc) · 1.9 KB
/
Document.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* Copyright 2006-2007, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus <superstippi@gmx.de>
*/
#include "Document.h"
#include "CommandStack.h"
#include "DocumentSaver.h"
#include "Icon.h"
#include "PathContainer.h"
#include "Selection.h"
#include "ShapeContainer.h"
#include "StyleContainer.h"
#include <Entry.h>
#include <new>
#include <stdio.h>
using std::nothrow;
_USING_ICON_NAMESPACE
// constructor
Document::Document(const char* name)
: RWLocker("document rw lock"),
fIcon(new (nothrow) _ICON_NAMESPACE Icon()),
fCommandStack(new (nothrow) ::CommandStack()),
fSelection(new (nothrow) ::Selection()),
fName(name),
fNativeSaver(NULL),
fExportSaver(NULL)
{
}
// destructor
Document::~Document()
{
delete fCommandStack;
delete fSelection;
fIcon->ReleaseReference();
delete fNativeSaver;
delete fExportSaver;
}
// SetName
void
Document::SetName(const char* name)
{
if (fName == name)
return;
fName = name;
Notify();
}
// Name
const char*
Document::Name() const
{
return fName.String();
}
// SetNativeSaver
void
Document::SetNativeSaver(::DocumentSaver* saver)
{
delete fNativeSaver;
fNativeSaver = saver;
}
// SetExportSaver
void
Document::SetExportSaver(::DocumentSaver* saver)
{
delete fExportSaver;
fExportSaver = saver;
}
// SetIcon
void
Document::SetIcon(_ICON_NAMESPACE Icon* icon)
{
if (fIcon == icon)
return;
fIcon->ReleaseReference();
fIcon = icon;
// we don't acquire, since we own the icon
}
// MakeEmpty
void
Document::MakeEmpty(bool includingSavers)
{
fCommandStack->Clear();
fSelection->DeselectAll();
fIcon->MakeEmpty();
if (includingSavers) {
delete fNativeSaver;
fNativeSaver = NULL;
delete fExportSaver;
fExportSaver = NULL;
}
}
// IsEmpty
bool
Document::IsEmpty() const
{
return fIcon->Styles()->CountStyles() == 0
&& fIcon->Paths()->CountPaths() == 0
&& fIcon->Shapes()->CountShapes() == 0;
}