xref: /haiku/src/apps/icon-o-matic/document/Document.cpp (revision ba499cdc3336fb89429027418871bf263f1f5e14)
1 /*
2  * Copyright 2006, Haiku.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Stephan Aßmus <superstippi@gmx.de>
7  */
8 
9 #include "Document.h"
10 
11 #include <new>
12 #include <stdio.h>
13 
14 #include <Entry.h>
15 
16 #include "CommandStack.h"
17 #include "DocumentSaver.h"
18 #include "Icon.h"
19 #include "Selection.h"
20 
21 using std::nothrow;
22 
23 // constructor
24 Document::Document(const char* name)
25 	: RWLocker("document rw lock"),
26 	  fIcon(new (nothrow) ::Icon()),
27 	  fCommandStack(new (nothrow) ::CommandStack()),
28 	  fSelection(new (nothrow) ::Selection()),
29 
30 	  fName(name),
31 
32 	  fNativeSaver(NULL),
33 	  fExportSaver(NULL)
34 {
35 }
36 
37 // destructor
38 Document::~Document()
39 {
40 	delete fCommandStack;
41 	delete fSelection;
42 	fIcon->Release();
43 	delete fNativeSaver;
44 	delete fExportSaver;
45 }
46 
47 // SetName
48 void
49 Document::SetName(const char* name)
50 {
51 	if (fName == name)
52 		return;
53 
54 	fName = name;
55 	Notify();
56 }
57 
58 // Name
59 const char*
60 Document::Name() const
61 {
62 	return fName.String();
63 }
64 
65 // SetNativeSaver
66 void
67 Document::SetNativeSaver(::DocumentSaver* saver)
68 {
69 	delete fNativeSaver;
70 	fNativeSaver = saver;
71 }
72 
73 // SetExportSaver
74 void
75 Document::SetExportSaver(::DocumentSaver* saver)
76 {
77 	delete fExportSaver;
78 	fExportSaver = saver;
79 }
80 
81 // SetIcon
82 void
83 Document::SetIcon(::Icon* icon)
84 {
85 	if (fIcon == icon)
86 		return;
87 
88 	fIcon->Release();
89 
90 	fIcon = icon;
91 
92 	// we don't acquire, since we own the icon
93 }
94 
95 // MakeEmpty
96 void
97 Document::MakeEmpty(bool includingSavers)
98 {
99 	fCommandStack->Clear();
100 	fSelection->DeselectAll();
101 	fIcon->MakeEmpty();
102 
103 	if (includingSavers) {
104 		delete fNativeSaver;
105 		fNativeSaver = NULL;
106 		delete fExportSaver;
107 		fExportSaver = NULL;
108 	}
109 }
110 
111 
112