Added a UpdateIfNeeded() method that you can call when you are not

interested in the data at all.
No longer imitates the BHandler observer model, but directly send
its update messages to the observers.
Now also stores the entry_ref of the file/device in the editor.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6704 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2004-02-24 03:27:45 +00:00
parent 2d7030fe25
commit 053bb7380a
2 changed files with 32 additions and 11 deletions
+26 -9
View File
@@ -195,6 +195,8 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
fIsReadOnly = true;
}
entry.GetRef(&fRef);
struct stat stat;
stat.st_mode = 0;
@@ -435,6 +437,7 @@ DataEditor::SetViewOffset(off_t offset)
fViewOffset = offset;
fNeedsUpdate = true;
SendNotices(kMsgDataEditorOffsetChange);
return B_OK;
}
@@ -485,19 +488,36 @@ DataEditor::Update()
status_t
DataEditor::GetViewBuffer(const uint8 **_buffer)
DataEditor::UpdateIfNeeded(bool *_updated = NULL)
{
if (!IsLocked())
debugger("DataEditor: view not locked");
if (!fNeedsUpdate) {
if (_updated)
*_updated = false;
return B_OK;
}
status_t status = B_OK;
if (fView == NULL)
status = SetViewOffset(fViewOffset);
if (status == B_OK && fNeedsUpdate)
if (status == B_OK && fNeedsUpdate) {
status = Update();
if (status == B_OK && _updated)
*_updated = true;
}
return status;
}
status_t
DataEditor::GetViewBuffer(const uint8 **_buffer)
{
if (!IsLocked())
debugger("DataEditor: view not locked");
status_t status = UpdateIfNeeded();
if (status < B_OK)
return status;
@@ -515,12 +535,9 @@ DataEditor::SendNotices(uint32 what, BMessage *message)
BMessage *notice;
if (message) {
notice = new BMessage(*message);
notice->what = B_OBSERVER_NOTICE_CHANGE;
notice->AddInt32(B_OBSERVE_ORIGINAL_WHAT, message->what);
notice->what = what;
} else
notice = new BMessage(B_OBSERVER_NOTICE_CHANGE);
notice->AddInt32(B_OBSERVE_WHAT_CHANGE, what);
notice = new BMessage(what);
for (int32 i = fObservers.CountItems(); i-- > 0;) {
BMessenger *messenger = fObservers.ItemAt(i);
+6 -2
View File
@@ -61,6 +61,7 @@ class DataEditor : public BLocker {
void SetBlockSize(size_t size);
size_t BlockSize() const { return fBlockSize; }
status_t UpdateIfNeeded(bool *_updated = NULL);
status_t GetViewBuffer(const uint8 **_buffer);
status_t StartWatching(BMessenger target);
@@ -69,6 +70,7 @@ class DataEditor : public BLocker {
void StopWatching(BHandler *handler, BLooper *looper = NULL);
BFile &File() { return fFile; }
const entry_ref &Ref() const { return fRef; }
private:
void SendNotices(uint32 what, BMessage *message = NULL);
@@ -79,6 +81,7 @@ class DataEditor : public BLocker {
BObjectList<BMessenger> fObservers;
entry_ref fRef;
BFile fFile;
const char *fAttribute;
bool fIsDevice, fIsReadOnly;
@@ -96,7 +99,8 @@ class DataEditor : public BLocker {
size_t fBlockSize;
};
static const uint32 kDataEditorStateChange = 'deSC';
static const uint32 kDataEditorUpdate = 'deUp';
static const uint32 kMsgDataEditorStateChange = 'deSC';
static const uint32 kMsgDataEditorUpdate = 'deUp';
static const uint32 kMsgDataEditorOffsetChange = 'deOC';
#endif /* DATA_EDITOR_H */