1 // Clipboard.cpp 2 3 #include <app/Clipboard.h> 4 5 #include "Clipboard.h" 6 7 /*! 8 \class Clipboard 9 \brief Server-side representation of a clipboard. 10 */ 11 12 // constructor 13 /*! \brief Creates and initializes a Clipboard. 14 \param name The name of the clipboard. 15 */ 16 Clipboard::Clipboard(const char *name) 17 : fName(name), 18 fData(B_SIMPLE_DATA), 19 fDataSource(), 20 fCount(0), 21 fWatchingService() 22 { 23 } 24 25 // destructor 26 /*! \brief Frees all resources associate with this object. 27 */ 28 Clipboard::~Clipboard() 29 { 30 } 31 32 // SetData 33 /*! \brief Sets the clipboard's data. 34 35 Also notifies all watchers that the clipboard data have changed. 36 37 \param data The new clipboard data. 38 \param dataSource The clipboards new data source. 39 */ 40 void 41 Clipboard::SetData(const BMessage *data, BMessenger dataSource) 42 { 43 fData = *data; 44 fDataSource = dataSource; 45 fCount++; 46 NotifyWatchers(); 47 } 48 49 // Data 50 /*! \brief Returns the clipboard's data. 51 \return The clipboard's data. 52 */ 53 const BMessage * 54 Clipboard::Data() const 55 { 56 return &fData; 57 } 58 59 // DataSource 60 /*! \brief Returns the clipboard's data source. 61 \return The clipboard's data source. 62 */ 63 BMessenger 64 Clipboard::DataSource() const 65 { 66 return fDataSource; 67 } 68 69 // Count 70 int32 71 Clipboard::Count() const 72 { 73 return fCount; 74 } 75 76 77 // AddWatcher 78 /*! \brief Adds a new watcher for this clipboard. 79 \param watcher The messenger referring to the new watcher. 80 \return \c true, if the watcher could be added successfully, 81 \c false otherwise. 82 */ 83 bool 84 Clipboard::AddWatcher(BMessenger watcher) 85 { 86 return fWatchingService.AddWatcher(watcher); 87 } 88 89 // RemoveWatcher 90 /*! \brief Removes a watcher from this clipboard. 91 \param watcher The watcher to be removed. 92 \return \c true, if the supplied watcher was watching the clipboard, 93 \c false otherwise. 94 */ 95 bool 96 Clipboard::RemoveWatcher(BMessenger watcher) 97 { 98 return fWatchingService.RemoveWatcher(watcher); 99 } 100 101 // NotifyWatchers 102 /*! \brief Sends a notification message that the clipboard data have changed 103 to all associated watchers. 104 */ 105 void 106 Clipboard::NotifyWatchers() 107 { 108 BMessage message(B_CLIPBOARD_CHANGED); 109 fWatchingService.NotifyWatchers(&message, NULL); 110 } 111 112