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