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_ICON_NAMESPACE 25 26 27 // constructor 28 Document::Document(const char* name) 29 : RWLocker("document rw lock"), 30 fIcon(new (nothrow) _ICON_NAMESPACE 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->ReleaseReference(); 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(_ICON_NAMESPACE Icon* icon) 88 { 89 if (fIcon == icon) 90 return; 91 92 fIcon->ReleaseReference(); 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 // IsEmpty 116 bool 117 Document::IsEmpty() const 118 { 119 return fIcon->Styles()->CountItems() == 0 120 && fIcon->Paths()->CountItems() == 0 121 && fIcon->Shapes()->CountItems() == 0; 122 } 123 124