xref: /haiku/src/apps/icon-o-matic/document/Document.cpp (revision 55b40aa53a835472ec7952b138ae4256203d02e4)
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 "Icon.h"
18 #include "Selection.h"
19 
20 using std::nothrow;
21 
22 // constructor
23 Document::Document(const char* name)
24 	: RWLocker("document rw lock"),
25 	  fIcon(new (nothrow) ::Icon()),
26 	  fCommandStack(new (nothrow) ::CommandStack()),
27 	  fSelection(new (nothrow) ::Selection()),
28 
29 	  fName(name),
30 	  fRef(NULL),
31 	  fExportRef(NULL)
32 {
33 }
34 
35 // destructor
36 Document::~Document()
37 {
38 	delete fCommandStack;
39 	delete fSelection;
40 	fIcon->Release();
41 	delete fRef;
42 	delete fExportRef;
43 }
44 
45 // SetName
46 void
47 Document::SetName(const char* name)
48 {
49 	if (fName == name)
50 		return;
51 
52 	fName = name;
53 	Notify();
54 }
55 
56 // Name
57 const char*
58 Document::Name() const
59 {
60 	return fName.String();
61 }
62 
63 // SetRef
64 void
65 Document::SetRef(const entry_ref& ref)
66 {
67 	if (!fRef)
68 		fRef = new (nothrow) entry_ref(ref);
69 	else
70 		*fRef = ref;
71 }
72 
73 // SetExportRef
74 void
75 Document::SetExportRef(const entry_ref& ref)
76 {
77 	if (!fExportRef)
78 		fExportRef = new (nothrow) entry_ref(ref);
79 	else
80 		*fExportRef = ref;
81 }
82 
83 // SetIcon
84 void
85 Document::SetIcon(::Icon* icon)
86 {
87 	if (fIcon == icon)
88 		return;
89 
90 	fIcon->Release();
91 
92 	fIcon = icon;
93 
94 	// we don't acquire, since we own the icon
95 }
96 
97 // MakeEmpty
98 void
99 Document::MakeEmpty()
100 {
101 	fCommandStack->Clear();
102 	fSelection->DeselectAll();
103 	fIcon->MakeEmpty();
104 
105 	delete fRef;
106 	fRef = NULL;
107 	delete fExportRef;
108 	fExportRef = NULL;
109 }
110 
111 
112