HaikuDepot: notify work status from main window
[haiku.git] / src / apps / icon-o-matic / document / Document.cpp
blobc78ae8c6ed89798f0b66dc2cdb03318961c1e7b0
1 /*
2 * Copyright 2006-2007, Haiku.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Stephan Aßmus <superstippi@gmx.de>
7 */
10 #include "Document.h"
12 #include "CommandStack.h"
13 #include "DocumentSaver.h"
14 #include "Icon.h"
15 #include "PathContainer.h"
16 #include "Selection.h"
17 #include "ShapeContainer.h"
18 #include "StyleContainer.h"
20 #include <Entry.h>
22 #include <new>
23 #include <stdio.h>
26 using std::nothrow;
27 _USING_ICON_NAMESPACE
30 // constructor
31 Document::Document(const char* name)
32 : RWLocker("document rw lock"),
33 fIcon(new (nothrow) _ICON_NAMESPACE Icon()),
34 fCommandStack(new (nothrow) ::CommandStack()),
35 fSelection(new (nothrow) ::Selection()),
37 fName(name),
39 fNativeSaver(NULL),
40 fExportSaver(NULL)
44 // destructor
45 Document::~Document()
47 delete fCommandStack;
48 delete fSelection;
49 fIcon->ReleaseReference();
50 delete fNativeSaver;
51 delete fExportSaver;
54 // SetName
55 void
56 Document::SetName(const char* name)
58 if (fName == name)
59 return;
61 fName = name;
62 Notify();
65 // Name
66 const char*
67 Document::Name() const
69 return fName.String();
72 // SetNativeSaver
73 void
74 Document::SetNativeSaver(::DocumentSaver* saver)
76 delete fNativeSaver;
77 fNativeSaver = saver;
80 // SetExportSaver
81 void
82 Document::SetExportSaver(::DocumentSaver* saver)
84 delete fExportSaver;
85 fExportSaver = saver;
88 // SetIcon
89 void
90 Document::SetIcon(_ICON_NAMESPACE Icon* icon)
92 if (fIcon == icon)
93 return;
95 fIcon->ReleaseReference();
97 fIcon = icon;
99 // we don't acquire, since we own the icon
102 // MakeEmpty
103 void
104 Document::MakeEmpty(bool includingSavers)
106 fCommandStack->Clear();
107 fSelection->DeselectAll();
108 fIcon->MakeEmpty();
110 if (includingSavers) {
111 delete fNativeSaver;
112 fNativeSaver = NULL;
113 delete fExportSaver;
114 fExportSaver = NULL;
118 // IsEmpty
119 bool
120 Document::IsEmpty() const
122 return fIcon->Styles()->CountStyles() == 0
123 && fIcon->Paths()->CountPaths() == 0
124 && fIcon->Shapes()->CountShapes() == 0;