Use Tracker Scripting to find next/previous image.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6203 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Pfeiffer
2004-01-20 19:46:45 +00:00
parent d97178c901
commit 134d607647
6 changed files with 105 additions and 62 deletions
+8 -1
View File
@@ -150,6 +150,13 @@ ShowImageApp::MessageReceived(BMessage *pmsg)
void void
ShowImageApp::RefsReceived(BMessage *pmsg) ShowImageApp::RefsReceived(BMessage *pmsg)
{ {
//
// If a tracker window opened me, get a messenger from it.
//
if (pmsg->HasMessenger("TrackerViewToken")) {
pmsg->FindMessenger("TrackerViewToken", &fTrackerMessenger);
}
uint32 type; uint32 type;
int32 count; int32 count;
status_t ret = pmsg->GetInfo("refs", &type, &count); status_t ret = pmsg->GetInfo("refs", &type, &count);
@@ -166,7 +173,7 @@ ShowImageApp::RefsReceived(BMessage *pmsg)
void void
ShowImageApp::Open(const entry_ref *pref) ShowImageApp::Open(const entry_ref *pref)
{ {
new ShowImageWindow(pref); new ShowImageWindow(pref, fTrackerMessenger);
} }
void void
+1
View File
@@ -54,6 +54,7 @@ private:
void BroadcastToWindows(BMessage *pmsg); void BroadcastToWindows(BMessage *pmsg);
void CheckClipboard(); void CheckClipboard();
BMessenger fTrackerMessenger; // of the window this was launched
BFilePanel *fOpenPanel; BFilePanel *fOpenPanel;
bool fPulseStarted; bool fPulseStarted;
ShowImageSettings fSettings; ShowImageSettings fSettings;
+81 -57
View File
@@ -252,6 +252,12 @@ ShowImageView::IsImage(const entry_ref *pref)
return true; return true;
} }
void
ShowImageView::SetTrackerMessenger(const BMessenger& trackerMessenger)
{
fTrackerMessenger = trackerMessenger;
}
// send message to parent about new image // send message to parent about new image
void void
ShowImageView::Notify(const char* status) ShowImageView::Notify(const char* status)
@@ -1879,62 +1885,61 @@ ShowImageView::FreeEntries(BList* entries)
entries->MakeEmpty(); entries->MakeEmpty();
} }
bool
ShowImageView::FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind) void
ShowImageView::SetTrackerSelectionToCurrent()
{ {
ASSERT(next || !rewind); BMessage setsel(B_SET_PROPERTY);
BEntry curImage(in_current); setsel.AddSpecifier("Selection");
entry_ref entry, *ref; setsel.AddRef("data", &fCurrentRef);
BDirectory parent; fTrackerMessenger.SendMessage(&setsel);
BList entries; }
bool found = false;
int32 cur; bool
ShowImageView::FindNextImage(entry_ref *in_current, entry_ref *ref, bool next, bool rewind)
if (curImage.GetParent(&parent) != B_OK) {
// shamelessly stolen, I mean copied from BeMail!
// XXX rewind is not implemented yet => slide show will stop with last image
if (!fTrackerMessenger.IsValid())
return false; return false;
while (parent.GetNextRef(&entry) == B_OK) { //
if (entry != *in_current) { // Ask the Tracker what the next/prev file in the window is.
entries.AddItem(new entry_ref(entry)); // Continue asking for the next reference until a valid
} else { // image is found.
// insert current ref, so we can find it easily after sorting //
entries.AddItem(in_current); entry_ref nextRef = *in_current;
} bool foundRef = false;
} while (!foundRef)
{
entries.SortItems(CompareEntries); BMessage request(B_GET_PROPERTY);
BMessage spc;
cur = entries.IndexOf(in_current); if (next)
ASSERT(cur >= 0); spc.what = 'snxt';
else
spc.what = 'sprv';
// remove it so FreeEntries() does not delete it spc.AddString("property", "Entry");
entries.RemoveItem(in_current); spc.AddRef("data", &nextRef);
if (next) { request.AddSpecifier(&spc);
// find the next image in the list BMessage reply;
if (rewind) cur = 0; // start with first if (fTrackerMessenger.SendMessage(&request, &reply) != B_OK) {
for (; (ref = (entry_ref*)entries.ItemAt(cur)) != NULL; cur ++) { return false;
if (IsImage(ref)) {
found = true;
*out_image = (const entry_ref)*ref;
break;
}
} }
} else {
// find the previous image in the list if (reply.FindRef("result", &nextRef) != B_OK) {
cur --; return false;
for (; cur >= 0; cur --) { }
ref = (entry_ref*)entries.ItemAt(cur);
if (IsImage(ref)) { if (IsImage(&nextRef)) {
found = true; foundRef = true;
*out_image = (const entry_ref)*ref;
break;
}
} }
} }
FreeEntries(&entries); *ref = nextRef;
return found; return foundRef;
} }
bool bool
@@ -1957,6 +1962,7 @@ ShowImageView::ShowNextImage(bool next, bool rewind)
if (!found) if (!found)
return false; return false;
} }
SetTrackerSelectionToCurrent();
return true; return true;
} }
return false; return false;
@@ -1974,6 +1980,20 @@ ShowImageView::PrevFile()
return ShowNextImage(false, false); return ShowNextImage(false, false);
} }
bool
ShowImageView::HasNextFile()
{
entry_ref ref;
return FindNextImage(&fCurrentRef, &ref, true, false);
}
bool
ShowImageView::HasPrevFile()
{
entry_ref ref;
return FindNextImage(&fCurrentRef, &ref, false, false);
}
bool bool
ShowImageView::FirstFile() ShowImageView::FirstFile()
{ {
@@ -2087,26 +2107,31 @@ ShowImageView::DoImageOperation(ImageProcessor::operation op, bool quiet)
} }
} }
// image operation initiated by user
void
ShowImageView::UserDoImageOperation(ImageProcessor::operation op, bool quiet)
{
fUndo.Clear();
DoImageOperation(op, quiet);
}
void void
ShowImageView::Rotate(int degree) ShowImageView::Rotate(int degree)
{ {
if (degree == 90) { if (degree == 90) {
fUndo.Clear(); UserDoImageOperation(ImageProcessor::kRotateClockwise);
DoImageOperation(ImageProcessor::kRotateClockwise);
} else if (degree == 270) { } else if (degree == 270) {
fUndo.Clear(); UserDoImageOperation(ImageProcessor::kRotateAntiClockwise);
DoImageOperation(ImageProcessor::kRotateAntiClockwise);
} }
} }
void void
ShowImageView::Mirror(bool vertical) ShowImageView::Mirror(bool vertical)
{ {
fUndo.Clear();
if (vertical) { if (vertical) {
DoImageOperation(ImageProcessor::kMirrorVertical); UserDoImageOperation(ImageProcessor::kMirrorVertical);
} else { } else {
DoImageOperation(ImageProcessor::kMirrorHorizontal); UserDoImageOperation(ImageProcessor::kMirrorHorizontal);
} }
} }
@@ -2117,8 +2142,7 @@ ShowImageView::Invert()
// Only allow an invert operation if the // Only allow an invert operation if the
// bitmap color space is supported by the // bitmap color space is supported by the
// invert algorithm // invert algorithm
fUndo.Clear(); UserDoImageOperation(ImageProcessor::kInvert);
DoImageOperation(ImageProcessor::kInvert);
} }
} }
+7
View File
@@ -39,6 +39,7 @@
#include "Filter.h" #include "Filter.h"
#include "ShowImageUndo.h" #include "ShowImageUndo.h"
// delay scaling operation, so that a sequence of zoom in/out operations works smoother
#define DELAYED_SCALING 1 #define DELAYED_SCALING 1
class ShowImageView : public BView { class ShowImageView : public BView {
@@ -49,6 +50,7 @@ public:
void Pulse(); void Pulse();
void SetTrackerMessenger(const BMessenger& trackerMessenger);
status_t SetImage(const entry_ref *pref); status_t SetImage(const entry_ref *pref);
void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, const translation_format* format); void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, const translation_format* format);
void SetDither(bool dither); void SetDither(bool dither);
@@ -99,6 +101,8 @@ public:
void GoToPage(int32 page); void GoToPage(int32 page);
bool NextFile(); bool NextFile();
bool PrevFile(); bool PrevFile();
bool HasNextFile();
bool HasPrevFile();
void SetSlideShowDelay(float seconds); void SetSlideShowDelay(float seconds);
float GetSlideShowDelay() const { return fSlideShowDelay / 10.0; } float GetSlideShowDelay() const { return fSlideShowDelay / 10.0; }
bool SlideShowStarted() const { return fSlideShow; } bool SlideShowStarted() const { return fSlideShow; }
@@ -150,6 +154,7 @@ private:
inline void CopyPixel(uchar* dest, int32 destX, int32 destY, int32 destBPR, uchar* src, int32 x, int32 y, int32 bpr, int32 bpp); inline void CopyPixel(uchar* dest, int32 destX, int32 destY, int32 destBPR, uchar* src, int32 x, int32 y, int32 bpr, int32 bpp);
inline void InvertPixel(int32 x, int32 y, uchar* dest, int32 destBPR, uchar* src, int32 bpr, int32 bpp); inline void InvertPixel(int32 x, int32 y, uchar* dest, int32 destBPR, uchar* src, int32 bpr, int32 bpp);
void DoImageOperation(enum ImageProcessor::operation op, bool quiet = false); void DoImageOperation(enum ImageProcessor::operation op, bool quiet = false);
void UserDoImageOperation(enum ImageProcessor::operation op, bool quiet = false);
BRect AlignBitmap(); BRect AlignBitmap();
void Setup(BRect r); void Setup(BRect r);
BPoint ImageToView(BPoint p) const; BPoint ImageToView(BPoint p) const;
@@ -158,6 +163,7 @@ private:
bool IsImage(const entry_ref* pref); bool IsImage(const entry_ref* pref);
static int CompareEntries(const void* a, const void* b); static int CompareEntries(const void* a, const void* b);
void FreeEntries(BList* entries); void FreeEntries(BList* entries);
void SetTrackerSelectionToCurrent();
bool FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind); bool FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind);
bool ShowNextImage(bool next, bool rewind); bool ShowNextImage(bool next, bool rewind);
bool FirstFile(); bool FirstFile();
@@ -189,6 +195,7 @@ private:
void SettingsSetBool(const char* name, bool value); void SettingsSetBool(const char* name, bool value);
void SetIcon(bool clear, icon_size which); void SetIcon(bool clear, icon_size which);
BMessenger fTrackerMessenger; // of the window that this was launched from
entry_ref fCurrentRef; // of the image entry_ref fCurrentRef; // of the image
bool fDither; // dither the image bool fDither; // dither the image
int32 fDocumentIndex; // of the image in the file int32 fDocumentIndex; // of the image in the file
+7 -3
View File
@@ -93,7 +93,7 @@ RecentDocumentsMenu::AddDynamicItem(add_state s)
// Implementation of ShowImageWindow // Implementation of ShowImageWindow
ShowImageWindow::ShowImageWindow(const entry_ref *pref) ShowImageWindow::ShowImageWindow(const entry_ref *pref, const BMessenger& trackerMessenger)
: BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0) : BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0)
{ {
fSavePanel = NULL; fSavePanel = NULL;
@@ -154,8 +154,9 @@ ShowImageWindow::ShowImageWindow(const entry_ref *pref)
SetSizeLimits(250, 100000, 100, 100000); SetSizeLimits(250, 100000, 100, 100000);
// finish creating window // finish creating the window
fImageView->SetImage(pref); fImageView->SetImage(pref);
fImageView->SetTrackerMessenger(trackerMessenger);
if (InitCheck() == B_OK) { if (InitCheck() == B_OK) {
// add View menu here so it can access ShowImageView methods // add View menu here so it can access ShowImageView methods
@@ -512,6 +513,9 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
EnableMenuItem(fBar, MSG_PAGE_NEXT, benable); EnableMenuItem(fBar, MSG_PAGE_NEXT, benable);
EnableMenuItem(fBar, MSG_PAGE_PREV, benable); EnableMenuItem(fBar, MSG_PAGE_PREV, benable);
EnableMenuItem(fBar, MSG_FILE_NEXT, fImageView->HasNextFile());
EnableMenuItem(fBar, MSG_FILE_PREV, fImageView->HasPrevFile());
if (fGoToPageMenu->CountItems() != pages) { if (fGoToPageMenu->CountItems() != pages) {
// Only rebuild the submenu if the number of // Only rebuild the submenu if the number of
// pages is different // pages is different
@@ -759,7 +763,7 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
case MSG_SCALE_BILINEAR: case MSG_SCALE_BILINEAR:
fImageView->SetScaleBilinear(ToggleMenuItem(pmsg->what)); fImageView->SetScaleBilinear(ToggleMenuItem(pmsg->what));
break; break;
default: default:
BWindow::MessageReceived(pmsg); BWindow::MessageReceived(pmsg);
break; break;
+1 -1
View File
@@ -56,7 +56,7 @@ private:
class ShowImageWindow : public BWindow { class ShowImageWindow : public BWindow {
public: public:
ShowImageWindow(const entry_ref *pref); ShowImageWindow(const entry_ref *pref, const BMessenger& trackerMessenger);
virtual ~ShowImageWindow(); virtual ~ShowImageWindow();
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);