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 23using std::nothrow; 24_USING_ICON_NAMESPACE 25 26 27// constructor 28Document::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 42Document::~Document() 43{ 44 delete fCommandStack; 45 delete fSelection; 46 fIcon->ReleaseReference(); 47 delete fNativeSaver; 48 delete fExportSaver; 49} 50 51// SetName 52void 53Document::SetName(const char* name) 54{ 55 if (fName == name) 56 return; 57 58 fName = name; 59 Notify(); 60} 61 62// Name 63const char* 64Document::Name() const 65{ 66 return fName.String(); 67} 68 69// SetNativeSaver 70void 71Document::SetNativeSaver(::DocumentSaver* saver) 72{ 73 delete fNativeSaver; 74 fNativeSaver = saver; 75} 76 77// SetExportSaver 78void 79Document::SetExportSaver(::DocumentSaver* saver) 80{ 81 delete fExportSaver; 82 fExportSaver = saver; 83} 84 85// SetIcon 86void 87Document::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 100void 101Document::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 116bool 117Document::IsEmpty() const 118{ 119 return fIcon->Styles()->CountItems() == 0 120 && fIcon->Paths()->CountItems() == 0 121 && fIcon->Shapes()->CountItems() == 0; 122} 123 124