* Completed stippi's work on the ImageFileNavigator.
* ShowImageWindow is now using such a navigator. * Removed navigation support from ShowImageView. * Prepared everything to support asynchronous image loading (which is not yet implemented, though). * Note, this commit brings some regressions I intend to fix in the next few days, namely deleting files won't work anymore, and dropping images onto ShowImage. There might be more I don't know about, though :-) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39259 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -61,27 +61,11 @@ namespace BPrivate {
|
|||||||
const uint32 kMoveToTrash = 'Ttrs';
|
const uint32 kMoveToTrash = 'Ttrs';
|
||||||
}
|
}
|
||||||
|
|
||||||
using std::nothrow;
|
|
||||||
|
|
||||||
|
|
||||||
#define SHOW_IMAGE_ORIENTATION_ATTRIBUTE "ShowImage:orientation"
|
|
||||||
|
|
||||||
enum ImageFileNavigator::image_orientation
|
|
||||||
ImageFileNavigator::fTransformation[ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations] = {
|
|
||||||
// rotate 90°
|
|
||||||
{k90, k180, k270, k0, k270V, k0V, k90V, k0H},
|
|
||||||
// rotate -90°
|
|
||||||
{k270, k0, k90, k180, k90V, k0H, k270V, k0V},
|
|
||||||
// mirror vertical
|
|
||||||
{k0H, k270V, k0V, k90V, k180, k270, k0, k90},
|
|
||||||
// mirror horizontal
|
|
||||||
{k0V, k90V, k0H, k270V, k0, k90, k180, k270}
|
|
||||||
};
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
entry_ref_is_file(const entry_ref *ref)
|
entry_ref_is_file(const entry_ref& ref)
|
||||||
{
|
{
|
||||||
BEntry entry(ref, true);
|
BEntry entry(&ref, true);
|
||||||
if (entry.InitCheck() != B_OK)
|
if (entry.InitCheck() != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -89,11 +73,15 @@ entry_ref_is_file(const entry_ref *ref)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ImageFileNavigator::ImageFileNavigator(BRect rect, const char *name, uint32 resizingMode,
|
// #pragma mark -
|
||||||
uint32 flags)
|
|
||||||
|
|
||||||
|
ImageFileNavigator::ImageFileNavigator(const BMessenger& target)
|
||||||
:
|
:
|
||||||
|
fTarget(target),
|
||||||
|
fProgressWindow(NULL),
|
||||||
fDocumentIndex(1),
|
fDocumentIndex(1),
|
||||||
fDocumentCount(1),
|
fDocumentCount(1)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,39 +98,38 @@ ImageFileNavigator::SetTrackerMessenger(const BMessenger& trackerMessenger)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
void
|
||||||
ImageFileNavigator::LoadImage(const entry_ref* ref, BBitmap** bitmap)
|
ImageFileNavigator::SetProgressWindow(ProgressWindow* progressWindow)
|
||||||
{
|
{
|
||||||
if (bitmap == NULL)
|
fProgressWindow = progressWindow;
|
||||||
return B_BAD_VALUE;
|
}
|
||||||
|
|
||||||
// If no ref was specified, load the specified page of the current file.
|
|
||||||
if (ref == NULL)
|
|
||||||
ref = &fCurrentRef;
|
|
||||||
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
status_t
|
||||||
|
ImageFileNavigator::LoadImage(const entry_ref& ref, int32 page)
|
||||||
|
{
|
||||||
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
if (roster == NULL)
|
if (roster == NULL)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (!entry_ref_is_file(ref))
|
if (!entry_ref_is_file(ref))
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
BFile file(ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
translator_info info;
|
translator_info info;
|
||||||
memset(&info, 0, sizeof(translator_info));
|
memset(&info, 0, sizeof(translator_info));
|
||||||
BMessage ioExtension;
|
BMessage ioExtension;
|
||||||
if (ref != &fCurrentRef) {
|
|
||||||
// if new image, reset to first document
|
|
||||||
fDocumentIndex = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
|
if (page != 0 && ioExtension.AddInt32("/documentIndex", page) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
BMessage progress(kMsgProgressStatusUpdate);
|
if (fProgressWindow != NULL) {
|
||||||
if (ioExtension.AddMessenger("/progressMonitor", fProgressWindow) == B_OK
|
BMessage progress(kMsgProgressStatusUpdate);
|
||||||
&& ioExtension.AddMessage("/progressMessage", &progress) == B_OK)
|
if (ioExtension.AddMessenger("/progressMonitor",
|
||||||
fProgressWindow->Start();
|
fProgressWindow) == B_OK
|
||||||
|
&& ioExtension.AddMessage("/progressMessage", &progress) == B_OK)
|
||||||
|
fProgressWindow->Start();
|
||||||
|
}
|
||||||
|
|
||||||
// Translate image data and create a new ShowImage window
|
// Translate image data and create a new ShowImage window
|
||||||
|
|
||||||
@@ -155,25 +142,18 @@ ImageFileNavigator::LoadImage(const entry_ref* ref, BBitmap** bitmap)
|
|||||||
B_TRANSLATOR_BITMAP);
|
B_TRANSLATOR_BITMAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
fProgressWindow->Stop();
|
if (fProgressWindow != NULL)
|
||||||
|
fProgressWindow->Stop();
|
||||||
|
|
||||||
if (status != B_OK)
|
if (status != B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
if (outstream.DetachBitmap(bitmap) != B_OK)
|
BBitmap* bitmap;
|
||||||
|
if (outstream.DetachBitmap(&bitmap) != B_OK)
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
fCurrentRef = *ref;
|
fCurrentRef = ref;
|
||||||
|
fDocumentIndex = page;
|
||||||
// restore orientation
|
|
||||||
int32 orientation;
|
|
||||||
fImageOrientation = k0;
|
|
||||||
fInverted = false;
|
|
||||||
if (file.ReadAttr(SHOW_IMAGE_ORIENTATION_ATTRIBUTE, B_INT32_TYPE, 0,
|
|
||||||
&orientation, sizeof(orientation)) == sizeof(orientation)) {
|
|
||||||
fInverted = (orientation & 256) != 0;
|
|
||||||
fImageOrientation = (orientation & 255) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the number of documents (pages) if it has been supplied
|
// get the number of documents (pages) if it has been supplied
|
||||||
int32 documentCount = 0;
|
int32 documentCount = 0;
|
||||||
@@ -183,11 +163,19 @@ ImageFileNavigator::LoadImage(const entry_ref* ref, BBitmap** bitmap)
|
|||||||
else
|
else
|
||||||
fDocumentCount = 1;
|
fDocumentCount = 1;
|
||||||
|
|
||||||
fImageType = info.name;
|
BMessage message(kMsgImageLoaded);
|
||||||
fImageMime = info.MIME;
|
message.AddString("type", info.name);
|
||||||
|
message.AddString("mime", info.MIME);
|
||||||
|
message.AddRef("ref", &ref);
|
||||||
|
message.AddInt32("page", page);
|
||||||
|
message.AddPointer("bitmap", (void*)bitmap);
|
||||||
|
status = fTarget.SendMessage(&message);
|
||||||
|
if (status != B_OK) {
|
||||||
|
delete bitmap;
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
be_roster->AddToRecentDocuments(&fCurrentRef, kApplicationSignature);
|
be_roster->AddToRecentDocuments(&fCurrentRef, kApplicationSignature);
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,79 +218,80 @@ ImageFileNavigator::PageCount()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
ImageFileNavigator::FirstPage(BBitmap** bitmap)
|
ImageFileNavigator::FirstPage()
|
||||||
{
|
{
|
||||||
if (fDocumentIndex != 1) {
|
if (fDocumentIndex != 1) {
|
||||||
fDocumentIndex = 1;
|
LoadImage(fCurrentRef, 1);
|
||||||
return LoadImage(NULL, bitmap);
|
return true;
|
||||||
}
|
}
|
||||||
return B_BAD_INDEX;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
ImageFileNavigator::LastPage(BBitmap** bitmap)
|
ImageFileNavigator::LastPage()
|
||||||
{
|
{
|
||||||
if (fDocumentIndex != fDocumentCount) {
|
if (fDocumentIndex != fDocumentCount) {
|
||||||
fDocumentIndex = fDocumentCount;
|
LoadImage(fCurrentRef, fDocumentCount);
|
||||||
return LoadImage(NULL, bitmap);
|
return true;
|
||||||
}
|
}
|
||||||
return B_BAD_INDEX;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
ImageFileNavigator::NextPage(BBitmap** bitmap)
|
ImageFileNavigator::NextPage()
|
||||||
{
|
{
|
||||||
if (fDocumentIndex < fDocumentCount) {
|
if (fDocumentIndex < fDocumentCount) {
|
||||||
fDocumentIndex++;
|
LoadImage(fCurrentRef, ++fDocumentIndex);
|
||||||
return LoadImage(NULL, bitmap);
|
return true;
|
||||||
}
|
}
|
||||||
return B_BAD_INDEX;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
ImageFileNavigator::PrevPage(BBitmap** bitmap)
|
ImageFileNavigator::PreviousPage()
|
||||||
{
|
{
|
||||||
if (fDocumentIndex > 1) {
|
if (fDocumentIndex > 1) {
|
||||||
fDocumentIndex--;
|
LoadImage(fCurrentRef, --fDocumentIndex);
|
||||||
return LoadImage(NULL, bitmap);
|
return true;
|
||||||
}
|
}
|
||||||
return B_BAD_INDEX;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
ImageFileNavigator::GoToPage(int32 page, BBitmap** bitmap)
|
ImageFileNavigator::GoToPage(int32 page)
|
||||||
{
|
{
|
||||||
if (page > 0 && page <= fDocumentCount && page != fDocumentIndex) {
|
if (page > 0 && page <= fDocumentCount && page != fDocumentIndex) {
|
||||||
fDocumentIndex = page;
|
fDocumentIndex = page;
|
||||||
return LoadImage(NULL, bitmap);
|
LoadImage(fCurrentRef, fDocumentIndex);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return B_BAD_INDEX;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
void
|
||||||
ImageFileNavigator::FirstFile(BBitmap** bitmap)
|
ImageFileNavigator::FirstFile()
|
||||||
{
|
{
|
||||||
return _LoadNextImage(true, true, bitmap);
|
_LoadNextImage(true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
void
|
||||||
ImageFileNavigator::NextFile(BBitmap** bitmap)
|
ImageFileNavigator::NextFile()
|
||||||
{
|
{
|
||||||
return _LoadNextImage(true, false, bitmap);
|
_LoadNextImage(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
void
|
||||||
ImageFileNavigator::PrevFile(BBitmap** bitmap)
|
ImageFileNavigator::PreviousFile()
|
||||||
{
|
{
|
||||||
return _LoadNextImage(false, false, bitmap);
|
_LoadNextImage(false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -310,15 +299,36 @@ bool
|
|||||||
ImageFileNavigator::HasNextFile()
|
ImageFileNavigator::HasNextFile()
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
return _FindNextImage(&fCurrentRef, &ref, true, false);
|
return _FindNextImage(fCurrentRef, ref, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ImageFileNavigator::HasPrevFile()
|
ImageFileNavigator::HasPreviousFile()
|
||||||
{
|
{
|
||||||
entry_ref ref;
|
entry_ref ref;
|
||||||
return _FindNextImage(&fCurrentRef, &ref, false, false);
|
return _FindNextImage(fCurrentRef, ref, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ImageFileNavigator::DeleteFile()
|
||||||
|
{
|
||||||
|
// Move image to Trash
|
||||||
|
BMessage trash(BPrivate::kMoveToTrash);
|
||||||
|
trash.AddRef("refs", &fCurrentRef);
|
||||||
|
|
||||||
|
// TODO!
|
||||||
|
#if 0
|
||||||
|
// We create our own messenger because the member fTrackerMessenger
|
||||||
|
// could be invalid
|
||||||
|
BMessenger tracker(kTrackerSignature);
|
||||||
|
if (tracker.SendMessage(&trash) == B_OK && !NextFile()) {
|
||||||
|
// This is the last (or only file) in this directory,
|
||||||
|
// close the window
|
||||||
|
_SendMessageToWindow(B_QUIT_REQUESTED);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -326,12 +336,12 @@ ImageFileNavigator::HasPrevFile()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ImageFileNavigator::_IsImage(const entry_ref *ref)
|
ImageFileNavigator::_IsImage(const entry_ref& ref)
|
||||||
{
|
{
|
||||||
if (ref == NULL || !entry_ref_is_file(ref))
|
if (!entry_ref_is_file(ref))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BFile file(ref, B_READ_ONLY);
|
BFile file(&ref, B_READ_ONLY);
|
||||||
if (file.InitCheck() != B_OK)
|
if (file.InitCheck() != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -354,19 +364,17 @@ ImageFileNavigator::_IsImage(const entry_ref *ref)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ImageFileNavigator::_FindNextImage(entry_ref* currentRef, entry_ref* ref,
|
ImageFileNavigator::_FindNextImage(const entry_ref& currentRef, entry_ref& ref,
|
||||||
bool next, bool rewind)
|
bool next, bool rewind)
|
||||||
{
|
{
|
||||||
// Based on GetTrackerWindowFile function from BeMail
|
// Based on GetTrackerWindowFile function from BeMail
|
||||||
if (!fTrackerMessenger.IsValid())
|
if (!fTrackerMessenger.IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//
|
// Ask the Tracker what the next/prev file in the window is.
|
||||||
// Ask the Tracker what the next/prev file in the window is.
|
// Continue asking for the next reference until a valid
|
||||||
// Continue asking for the next reference until a valid
|
// image is found.
|
||||||
// image is found.
|
entry_ref nextRef = currentRef;
|
||||||
//
|
|
||||||
entry_ref nextRef = *currentRef;
|
|
||||||
bool foundRef = false;
|
bool foundRef = false;
|
||||||
while (!foundRef) {
|
while (!foundRef) {
|
||||||
BMessage request(B_GET_PROPERTY);
|
BMessage request(B_GET_PROPERTY);
|
||||||
@@ -392,35 +400,34 @@ ImageFileNavigator::_FindNextImage(entry_ref* currentRef, entry_ref* ref,
|
|||||||
if (reply.FindRef("result", &nextRef) != B_OK)
|
if (reply.FindRef("result", &nextRef) != B_OK)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (_IsImage(&nextRef))
|
if (_IsImage(nextRef))
|
||||||
foundRef = true;
|
foundRef = true;
|
||||||
|
|
||||||
rewind = false;
|
rewind = false;
|
||||||
// stop asking for the first ref in the directory
|
// stop asking for the first ref in the directory
|
||||||
}
|
}
|
||||||
|
|
||||||
*ref = nextRef;
|
ref = nextRef;
|
||||||
return foundRef;
|
return foundRef;
|
||||||
}
|
}
|
||||||
|
|
||||||
status_t
|
|
||||||
ImageFileNavigator::_LoadNextImage(bool next, bool rewind, BBitmap** bitmap)
|
|
||||||
{
|
|
||||||
if (bitmap == NULL)
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
entry_ref curRef = fCurrentRef;
|
status_t
|
||||||
entry_ref imgRef;
|
ImageFileNavigator::_LoadNextImage(bool next, bool rewind)
|
||||||
bool found = _FindNextImage(&curRef, &imgRef, next, rewind);
|
{
|
||||||
|
entry_ref currentRef = fCurrentRef;
|
||||||
|
entry_ref ref;
|
||||||
|
bool found = _FindNextImage(currentRef, ref, next, rewind);
|
||||||
if (found) {
|
if (found) {
|
||||||
// Keep trying to load images until:
|
// Keep trying to load images until:
|
||||||
// 1. The image loads successfully
|
// 1. The image loads successfully
|
||||||
// 2. The last file in the directory is found (for find next or find first)
|
// 2. The last file in the directory is found (for find next or find
|
||||||
|
// first)
|
||||||
// 3. The first file in the directory is found (for find prev)
|
// 3. The first file in the directory is found (for find prev)
|
||||||
// 4. The call to _FindNextImage fails for any other reason
|
// 4. The call to _FindNextImage fails for any other reason
|
||||||
while (LoadImage(&imgRef, bitmap) != B_OK) {
|
while (LoadImage(ref) != B_OK) {
|
||||||
curRef = imgRef;
|
currentRef = ref;
|
||||||
found = _FindNextImage(&curRef, &imgRef, next, false);
|
found = _FindNextImage(currentRef, ref, next, false);
|
||||||
if (!found)
|
if (!found)
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
@@ -434,10 +441,10 @@ ImageFileNavigator::_LoadNextImage(bool next, bool rewind, BBitmap** bitmap)
|
|||||||
void
|
void
|
||||||
ImageFileNavigator::_SetTrackerSelectionToCurrent()
|
ImageFileNavigator::_SetTrackerSelectionToCurrent()
|
||||||
{
|
{
|
||||||
BMessage setsel(B_SET_PROPERTY);
|
BMessage setSelection(B_SET_PROPERTY);
|
||||||
setsel.AddSpecifier("Selection");
|
setSelection.AddSpecifier("Selection");
|
||||||
setsel.AddRef("data", &fCurrentRef);
|
setSelection.AddRef("data", &fCurrentRef);
|
||||||
fTrackerMessenger.SendMessage(&setsel);
|
fTrackerMessenger.SendMessage(&setSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,26 +16,30 @@
|
|||||||
#define IMAGE_FILE_NAVIGATOR_H
|
#define IMAGE_FILE_NAVIGATOR_H
|
||||||
|
|
||||||
|
|
||||||
#include <Bitmap.h>
|
|
||||||
#include <Entry.h>
|
#include <Entry.h>
|
||||||
#include <NodeInfo.h>
|
#include <Messenger.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <TranslatorRoster.h>
|
|
||||||
|
|
||||||
|
|
||||||
class ProgressWindow;
|
class ProgressWindow;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kMsgImageLoaded = 'ifnL'
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class ImageFileNavigator {
|
class ImageFileNavigator {
|
||||||
public:
|
public:
|
||||||
ImageFileNavigator(
|
ImageFileNavigator(const BMessenger& target);
|
||||||
ProgressWindow* progressWindow);
|
|
||||||
virtual ~ImageFileNavigator();
|
virtual ~ImageFileNavigator();
|
||||||
|
|
||||||
void SetTrackerMessenger(
|
void SetTrackerMessenger(
|
||||||
const BMessenger& trackerMessenger);
|
const BMessenger& trackerMessenger);
|
||||||
|
void SetProgressWindow(
|
||||||
|
ProgressWindow* progressWindow);
|
||||||
|
|
||||||
status_t LoadImage(const entry_ref* ref, BBitmap** bitmap);
|
status_t LoadImage(const entry_ref& ref, int32 page = 1);
|
||||||
const entry_ref* ImageRef() const { return &fCurrentRef; }
|
const entry_ref& ImageRef() const { return fCurrentRef; }
|
||||||
|
|
||||||
void GetName(BString* name);
|
void GetName(BString* name);
|
||||||
void GetPath(BString* name);
|
void GetPath(BString* name);
|
||||||
@@ -45,11 +49,11 @@ public:
|
|||||||
int32 CurrentPage();
|
int32 CurrentPage();
|
||||||
int32 PageCount();
|
int32 PageCount();
|
||||||
|
|
||||||
status_t FirstPage(BBitmap** bitmap);
|
bool FirstPage();
|
||||||
status_t LastPage(BBitmap** bitmap);
|
bool LastPage();
|
||||||
status_t NextPage(BBitmap** bitmap);
|
bool NextPage();
|
||||||
status_t PrevPage(BBitmap** bitmap);
|
bool PreviousPage();
|
||||||
status_t GoToPage(int32 page, BBitmap** bitmap);
|
bool GoToPage(int32 page);
|
||||||
|
|
||||||
// Navigation to the next/previous image file is based on
|
// Navigation to the next/previous image file is based on
|
||||||
// communication with Tracker, the folder containing the current
|
// communication with Tracker, the folder containing the current
|
||||||
@@ -57,37 +61,29 @@ public:
|
|||||||
// to find the next candidate file, then tries to load it as image.
|
// to find the next candidate file, then tries to load it as image.
|
||||||
// As long as loading fails, the operation is repeated for the next
|
// As long as loading fails, the operation is repeated for the next
|
||||||
// candidate file.
|
// candidate file.
|
||||||
status_t FirstFile(BBitmap** bitmap);
|
void FirstFile();
|
||||||
status_t NextFile(BBitmap** bitmap);
|
void NextFile();
|
||||||
status_t PrevFile(BBitmap** bitmap);
|
void PreviousFile();
|
||||||
bool HasNextFile();
|
bool HasNextFile();
|
||||||
bool HasPrevFile();
|
bool HasPreviousFile();
|
||||||
|
|
||||||
|
void DeleteFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum image_orientation {
|
bool _IsImage(const entry_ref& ref);
|
||||||
k0, // 0
|
bool _FindNextImage(const entry_ref& current,
|
||||||
k90, // 1
|
entry_ref& next, bool next,
|
||||||
k180, // 2
|
|
||||||
k270, // 3
|
|
||||||
k0V, // 4
|
|
||||||
k90V, // 5
|
|
||||||
k0H, // 6
|
|
||||||
k270V, // 7
|
|
||||||
kNumberOfOrientations,
|
|
||||||
};
|
|
||||||
|
|
||||||
bool _IsImage(const entry_ref* pref);
|
|
||||||
bool _FindNextImage(entry_ref* inCurrent,
|
|
||||||
entry_ref* outImage, bool next,
|
|
||||||
bool rewind);
|
bool rewind);
|
||||||
status_t _LoadNextImage(bool next, bool rewind);
|
status_t _LoadNextImage(bool next, bool rewind);
|
||||||
void _SetTrackerSelectionToCurrent();
|
void _SetTrackerSelectionToCurrent();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BMessenger fTarget;
|
||||||
BMessenger fTrackerMessenger;
|
BMessenger fTrackerMessenger;
|
||||||
// of the window that this was launched from
|
// of the window that this was launched from
|
||||||
entry_ref fCurrentRef;
|
ProgressWindow* fProgressWindow;
|
||||||
|
|
||||||
|
entry_ref fCurrentRef;
|
||||||
int32 fDocumentIndex;
|
int32 fDocumentIndex;
|
||||||
// of the image in the file
|
// of the image in the file
|
||||||
int32 fDocumentCount;
|
int32 fDocumentCount;
|
||||||
@@ -96,14 +92,7 @@ private:
|
|||||||
BString fImageType;
|
BString fImageType;
|
||||||
// Type of image, for use in status bar and caption
|
// Type of image, for use in status bar and caption
|
||||||
BString fImageMime;
|
BString fImageMime;
|
||||||
|
|
||||||
ProgressWindow* fProgressWindow;
|
|
||||||
|
|
||||||
image_orientation fImageOrientation;
|
|
||||||
static image_orientation fTransformation[
|
|
||||||
ImageProcessor
|
|
||||||
::kNumberOfAffineTransformations]
|
|
||||||
[kNumberOfOrientations];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // IMAGE_FILE_NAVIGATOR_H
|
#endif // IMAGE_FILE_NAVIGATOR_H
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ UsePublicHeaders [ FDirName be_apps Tracker ] ;
|
|||||||
Application ShowImage :
|
Application ShowImage :
|
||||||
EntryMenuItem.cpp
|
EntryMenuItem.cpp
|
||||||
Filter.cpp
|
Filter.cpp
|
||||||
|
ImageFileNavigator.cpp
|
||||||
PrintOptionsWindow.cpp
|
PrintOptionsWindow.cpp
|
||||||
ProgressWindow.cpp
|
ProgressWindow.cpp
|
||||||
ResizerWindow.cpp
|
ResizerWindow.cpp
|
||||||
|
|||||||
@@ -55,11 +55,6 @@
|
|||||||
#include "ShowImageWindow.h"
|
#include "ShowImageWindow.h"
|
||||||
|
|
||||||
|
|
||||||
// TODO: Remove this and use Tracker's Command.h once it is moved into the private headers
|
|
||||||
namespace BPrivate {
|
|
||||||
const uint32 kMoveToTrash = 'Ttrs';
|
|
||||||
}
|
|
||||||
|
|
||||||
using std::nothrow;
|
using std::nothrow;
|
||||||
|
|
||||||
|
|
||||||
@@ -94,17 +89,6 @@ const rgb_color kAlphaHigh = (rgb_color){ 0xe0, 0xe0, 0xe0, 0xff };
|
|||||||
const uint32 kMsgPopUpMenuClosed = 'pmcl';
|
const uint32 kMsgPopUpMenuClosed = 'pmcl';
|
||||||
|
|
||||||
|
|
||||||
static bool
|
|
||||||
entry_ref_is_file(const entry_ref *ref)
|
|
||||||
{
|
|
||||||
BEntry entry(ref, true);
|
|
||||||
if (entry.InitCheck() != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return entry.IsFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
blend_colors(uint8* d, uint8 r, uint8 g, uint8 b, uint8 a)
|
blend_colors(uint8* d, uint8 r, uint8 g, uint8 b, uint8 a)
|
||||||
{
|
{
|
||||||
@@ -184,8 +168,6 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
|
|||||||
uint32 flags)
|
uint32 flags)
|
||||||
:
|
:
|
||||||
BView(rect, name, resizingMode, flags),
|
BView(rect, name, resizingMode, flags),
|
||||||
fDocumentIndex(1),
|
|
||||||
fDocumentCount(1),
|
|
||||||
fBitmap(NULL),
|
fBitmap(NULL),
|
||||||
fDisplayBitmap(NULL),
|
fDisplayBitmap(NULL),
|
||||||
fSelectionBitmap(NULL),
|
fSelectionBitmap(NULL),
|
||||||
@@ -252,6 +234,7 @@ ShowImageView::Pulse()
|
|||||||
fSelectionBox.Animate();
|
fSelectionBox.Animate();
|
||||||
fSelectionBox.Draw(this, Bounds());
|
fSelectionBox.Draw(this, Bounds());
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
if (fSlideShow) {
|
if (fSlideShow) {
|
||||||
fSlideShowCountDown --;
|
fSlideShowCountDown --;
|
||||||
if (fSlideShowCountDown <= 0) {
|
if (fSlideShowCountDown <= 0) {
|
||||||
@@ -261,6 +244,7 @@ ShowImageView::Pulse()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Hide cursor in full screen mode
|
// Hide cursor in full screen mode
|
||||||
if (fFullScreen && !fHasSelection && !fShowingPopUpMenu && fIsActiveWin) {
|
if (fFullScreen && !fHasSelection && !fShowingPopUpMenu && fIsActiveWin) {
|
||||||
@@ -272,34 +256,6 @@ ShowImageView::Pulse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ShowImageView::_IsImage(const entry_ref *ref)
|
|
||||||
{
|
|
||||||
if (ref == NULL || !entry_ref_is_file(ref))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BFile file(ref, B_READ_ONLY);
|
|
||||||
if (file.InitCheck() != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
|
||||||
if (!roster)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BMessage ioExtension;
|
|
||||||
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
translator_info info;
|
|
||||||
memset(&info, 0, sizeof(translator_info));
|
|
||||||
if (roster->Identify(&file, &ioExtension, &info, 0, NULL,
|
|
||||||
B_TRANSLATOR_BITMAP) != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetTrackerMessenger(const BMessenger& trackerMessenger)
|
ShowImageView::SetTrackerMessenger(const BMessenger& trackerMessenger)
|
||||||
{
|
{
|
||||||
@@ -310,8 +266,8 @@ ShowImageView::SetTrackerMessenger(const BMessenger& trackerMessenger)
|
|||||||
void
|
void
|
||||||
ShowImageView::_SendMessageToWindow(BMessage *message)
|
ShowImageView::_SendMessageToWindow(BMessage *message)
|
||||||
{
|
{
|
||||||
BMessenger msgr(Window());
|
BMessenger target(Window());
|
||||||
msgr.SendMessage(message);
|
target.SendMessage(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -329,7 +285,6 @@ ShowImageView::_Notify()
|
|||||||
{
|
{
|
||||||
BMessage msg(MSG_UPDATE_STATUS);
|
BMessage msg(MSG_UPDATE_STATUS);
|
||||||
|
|
||||||
msg.AddString("status", fImageType.String());
|
|
||||||
msg.AddInt32("width", fBitmap->Bounds().IntegerWidth() + 1);
|
msg.AddInt32("width", fBitmap->Bounds().IntegerWidth() + 1);
|
||||||
msg.AddInt32("height", fBitmap->Bounds().IntegerHeight() + 1);
|
msg.AddInt32("height", fBitmap->Bounds().IntegerHeight() + 1);
|
||||||
|
|
||||||
@@ -345,17 +300,16 @@ void
|
|||||||
ShowImageView::_UpdateStatusText()
|
ShowImageView::_UpdateStatusText()
|
||||||
{
|
{
|
||||||
BMessage msg(MSG_UPDATE_STATUS_TEXT);
|
BMessage msg(MSG_UPDATE_STATUS_TEXT);
|
||||||
BString status_to_send = fImageType;
|
|
||||||
|
|
||||||
if (fHasSelection) {
|
if (fHasSelection) {
|
||||||
char size[50];
|
char size[50];
|
||||||
sprintf(size, " (%.0fx%.0f)",
|
sprintf(size, "(%.0fx%.0f)",
|
||||||
fSelectionBox.Bounds().Width() + 1.0,
|
fSelectionBox.Bounds().Width() + 1.0,
|
||||||
fSelectionBox.Bounds().Height() + 1.0);
|
fSelectionBox.Bounds().Height() + 1.0);
|
||||||
status_to_send << size;
|
|
||||||
|
msg.AddString("status", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
msg.AddString("status", status_to_send.String());
|
|
||||||
_SendMessageToWindow(&msg);
|
_SendMessageToWindow(&msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,132 +337,94 @@ ShowImageView::_DeleteSelectionBitmap()
|
|||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
ShowImageView::SetImage(const entry_ref* ref)
|
ShowImageView::SetImage(const BMessage* message)
|
||||||
{
|
{
|
||||||
// If no file was specified, load the specified page of
|
BBitmap* bitmap;
|
||||||
// the current file.
|
entry_ref ref;
|
||||||
if (ref == NULL)
|
if (message->FindPointer("bitmap", (void**)&bitmap) != B_OK
|
||||||
ref = &fCurrentRef;
|
|| message->FindRef("ref", &ref) != B_OK || bitmap == NULL)
|
||||||
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
|
||||||
if (!roster)
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
|
|
||||||
if (!entry_ref_is_file(ref))
|
status_t status = SetImage(&ref, bitmap);
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
BFile file(ref, B_READ_ONLY);
|
|
||||||
translator_info info;
|
|
||||||
memset(&info, 0, sizeof(translator_info));
|
|
||||||
BMessage ioExtension;
|
|
||||||
if (ref != &fCurrentRef) {
|
|
||||||
// if new image, reset to first document
|
|
||||||
fDocumentIndex = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
BMessage progress(kMsgProgressStatusUpdate);
|
|
||||||
if (ioExtension.AddMessenger("/progressMonitor", fProgressWindow) == B_OK
|
|
||||||
&& ioExtension.AddMessage("/progressMessage", &progress) == B_OK)
|
|
||||||
fProgressWindow->Start();
|
|
||||||
|
|
||||||
// Translate image data and create a new ShowImage window
|
|
||||||
|
|
||||||
BBitmapStream outstream;
|
|
||||||
|
|
||||||
status_t status = roster->Identify(&file, &ioExtension, &info, 0, NULL,
|
|
||||||
B_TRANSLATOR_BITMAP);
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
status = roster->Translate(&file, &info, &ioExtension, &outstream,
|
fFormatDescription = message->FindString("type");
|
||||||
B_TRANSLATOR_BITMAP);
|
fMimeType = message->FindString("mime");
|
||||||
}
|
}
|
||||||
|
|
||||||
fProgressWindow->Stop();
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
if (status != B_OK)
|
|
||||||
return status;
|
|
||||||
|
|
||||||
BBitmap *newBitmap = NULL;
|
status_t
|
||||||
if (outstream.DetachBitmap(&newBitmap) != B_OK)
|
ShowImageView::SetImage(const entry_ref* ref, BBitmap* bitmap)
|
||||||
return B_ERROR;
|
{
|
||||||
|
// Delete the old one, and clear everything
|
||||||
// Now that I've successfully loaded the new bitmap,
|
|
||||||
// I can be sure it is safe to delete the old one,
|
|
||||||
// and clear everything
|
|
||||||
fUndo.Clear();
|
fUndo.Clear();
|
||||||
_SetHasSelection(false);
|
_SetHasSelection(false);
|
||||||
fCreatingSelection = false;
|
fCreatingSelection = false;
|
||||||
_DeleteBitmap();
|
_DeleteBitmap();
|
||||||
fBitmap = newBitmap;
|
|
||||||
fCurrentRef = *ref;
|
|
||||||
|
|
||||||
// prepare the display bitmap
|
fBitmap = bitmap;
|
||||||
if (fBitmap->ColorSpace() == B_RGBA32)
|
if (ref == NULL)
|
||||||
fDisplayBitmap = compose_checker_background(fBitmap);
|
fCurrentRef.device = -1;
|
||||||
|
else
|
||||||
|
fCurrentRef = *ref;
|
||||||
|
|
||||||
if (!fDisplayBitmap)
|
if (fBitmap != NULL) {
|
||||||
fDisplayBitmap = fBitmap;
|
// prepare the display bitmap
|
||||||
|
if (fBitmap->ColorSpace() == B_RGBA32)
|
||||||
|
fDisplayBitmap = compose_checker_background(fBitmap);
|
||||||
|
|
||||||
// restore orientation
|
if (!fDisplayBitmap)
|
||||||
int32 orientation;
|
fDisplayBitmap = fBitmap;
|
||||||
fImageOrientation = k0;
|
|
||||||
if (file.ReadAttr(SHOW_IMAGE_ORIENTATION_ATTRIBUTE, B_INT32_TYPE, 0,
|
BNode node(ref);
|
||||||
&orientation, sizeof(orientation)) == sizeof(orientation)) {
|
|
||||||
orientation &= 255;
|
// restore orientation
|
||||||
switch (orientation) {
|
int32 orientation;
|
||||||
case k0:
|
fImageOrientation = k0;
|
||||||
break;
|
if (node.ReadAttr(SHOW_IMAGE_ORIENTATION_ATTRIBUTE, B_INT32_TYPE, 0,
|
||||||
case k90:
|
&orientation, sizeof(orientation)) == sizeof(orientation)) {
|
||||||
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
orientation &= 255;
|
||||||
break;
|
switch (orientation) {
|
||||||
case k180:
|
case k0:
|
||||||
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
break;
|
||||||
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
case k90:
|
||||||
break;
|
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
||||||
case k270:
|
break;
|
||||||
_DoImageOperation(ImageProcessor::kRotateCounterClockwise, true);
|
case k180:
|
||||||
break;
|
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
||||||
case k0V:
|
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
||||||
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
break;
|
||||||
break;
|
case k270:
|
||||||
case k90V:
|
_DoImageOperation(ImageProcessor::kRotateCounterClockwise, true);
|
||||||
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
break;
|
||||||
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
case k0V:
|
||||||
break;
|
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
||||||
case k0H:
|
break;
|
||||||
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipLeftToRight, true);
|
case k90V:
|
||||||
break;
|
_DoImageOperation(ImageProcessor::kRotateClockwise, true);
|
||||||
case k270V:
|
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
||||||
_DoImageOperation(ImageProcessor::kRotateCounterClockwise, true);
|
break;
|
||||||
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
case k0H:
|
||||||
break;
|
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipLeftToRight, true);
|
||||||
|
break;
|
||||||
|
case k270V:
|
||||||
|
_DoImageOperation(ImageProcessor::kRotateCounterClockwise, true);
|
||||||
|
_DoImageOperation(ImageProcessor::ImageProcessor::kFlipTopToBottom, true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the number of documents (pages) if it has been supplied
|
BPath path(ref);
|
||||||
int32 documentCount = 0;
|
fCaption = path.Path();
|
||||||
if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK
|
fFormatDescription = "Bitmap";
|
||||||
&& documentCount > 0)
|
fMimeType = "image/x-be-bitmap";
|
||||||
fDocumentCount = documentCount;
|
|
||||||
else
|
|
||||||
fDocumentCount = 1;
|
|
||||||
|
|
||||||
fImageType = info.name;
|
|
||||||
fImageMime = info.MIME;
|
|
||||||
|
|
||||||
GetPath(&fCaption);
|
|
||||||
if (fDocumentCount > 1)
|
|
||||||
fCaption << ", " << fDocumentIndex << "/" << fDocumentCount;
|
|
||||||
|
|
||||||
fCaption << ", " << fImageType;
|
|
||||||
|
|
||||||
fFitToBoundsZoom = _FitToBoundsZoom();
|
fFitToBoundsZoom = _FitToBoundsZoom();
|
||||||
ResetZoom();
|
ResetZoom();
|
||||||
|
Invalidate();
|
||||||
be_roster->AddToRecentDocuments(&fCurrentRef, kApplicationSignature);
|
|
||||||
|
|
||||||
_Notify();
|
_Notify();
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
@@ -599,37 +515,13 @@ ShowImageView::SetFullScreen(bool fullScreen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BBitmap *
|
BBitmap*
|
||||||
ShowImageView::GetBitmap()
|
ShowImageView::Bitmap()
|
||||||
{
|
{
|
||||||
return fBitmap;
|
return fBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::GetName(BString* outName)
|
|
||||||
{
|
|
||||||
BEntry entry(&fCurrentRef);
|
|
||||||
char name[B_FILE_NAME_LENGTH];
|
|
||||||
if (entry.InitCheck() < B_OK || entry.GetName(name) < B_OK)
|
|
||||||
outName->SetTo("");
|
|
||||||
else
|
|
||||||
outName->SetTo(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::GetPath(BString *outPath)
|
|
||||||
{
|
|
||||||
BEntry entry(&fCurrentRef);
|
|
||||||
BPath path;
|
|
||||||
if (entry.InitCheck() < B_OK || entry.GetPath(&path) < B_OK)
|
|
||||||
outPath->SetTo("");
|
|
||||||
else
|
|
||||||
outPath->SetTo(path.Path());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetScaleBilinear(bool enabled)
|
ShowImageView::SetScaleBilinear(bool enabled)
|
||||||
{
|
{
|
||||||
@@ -679,6 +571,9 @@ ShowImageView::_ShouldStretch() const
|
|||||||
float
|
float
|
||||||
ShowImageView::_FitToBoundsZoom() const
|
ShowImageView::_FitToBoundsZoom() const
|
||||||
{
|
{
|
||||||
|
if (fBitmap == NULL)
|
||||||
|
return 1.0f;
|
||||||
|
|
||||||
// the width/height of the bitmap (in pixels)
|
// the width/height of the bitmap (in pixels)
|
||||||
float bitmapWidth = fBitmap->Bounds().Width() + 1;
|
float bitmapWidth = fBitmap->Bounds().Width() + 1;
|
||||||
float bitmapHeight = fBitmap->Bounds().Height() + 1;
|
float bitmapHeight = fBitmap->Bounds().Height() + 1;
|
||||||
@@ -935,9 +830,9 @@ ShowImageView::_AddSupportedTypes(BMessage* msg, BBitmap* bitmap)
|
|||||||
|
|
||||||
// add the current image mime first, will make it the preferred format on
|
// add the current image mime first, will make it the preferred format on
|
||||||
// left mouse drag
|
// left mouse drag
|
||||||
msg->AddString("be:types", fImageMime);
|
msg->AddString("be:types", fMimeType);
|
||||||
msg->AddString("be:filetypes", fImageMime);
|
msg->AddString("be:filetypes", fMimeType);
|
||||||
msg->AddString("be:type_descriptions", fImageType);
|
msg->AddString("be:type_descriptions", fFormatDescription);
|
||||||
|
|
||||||
bool foundOther = false;
|
bool foundOther = false;
|
||||||
bool foundCurrent = false;
|
bool foundCurrent = false;
|
||||||
@@ -951,7 +846,7 @@ ShowImageView::_AddSupportedTypes(BMessage* msg, BBitmap* bitmap)
|
|||||||
int32 count;
|
int32 count;
|
||||||
roster->GetOutputFormats(info[i].translator, &formats, &count);
|
roster->GetOutputFormats(info[i].translator, &formats, &count);
|
||||||
for (int32 j = 0; j < count; j++) {
|
for (int32 j = 0; j < count; j++) {
|
||||||
if (fImageMime == formats[j].MIME) {
|
if (fMimeType == formats[j].MIME) {
|
||||||
foundCurrent = true;
|
foundCurrent = true;
|
||||||
} else if (strcmp(formats[j].MIME, "image/x-be-bitmap") != 0) {
|
} else if (strcmp(formats[j].MIME, "image/x-be-bitmap") != 0) {
|
||||||
foundOther = true;
|
foundOther = true;
|
||||||
@@ -1026,22 +921,23 @@ ShowImageView::_OutputFormatForType(BBitmap* bitmap, const char* type,
|
|||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||||
if (roster == NULL)
|
if (roster == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BBitmapStream stream(bitmap);
|
BBitmapStream stream(bitmap);
|
||||||
|
|
||||||
translator_info *outInfo;
|
translator_info* outInfo;
|
||||||
int32 outNumInfo;
|
int32 outNumInfo;
|
||||||
if (roster->GetTranslators(&stream, NULL, &outInfo, &outNumInfo) == B_OK) {
|
if (roster->GetTranslators(&stream, NULL, &outInfo, &outNumInfo) == B_OK) {
|
||||||
for (int32 i = 0; i < outNumInfo; i++) {
|
for (int32 i = 0; i < outNumInfo; i++) {
|
||||||
const translation_format *fmts;
|
const translation_format* formats;
|
||||||
int32 num_fmts;
|
int32 formatCount;
|
||||||
roster->GetOutputFormats(outInfo[i].translator, &fmts, &num_fmts);
|
roster->GetOutputFormats(outInfo[i].translator, &formats,
|
||||||
for (int32 j = 0; j < num_fmts; j++) {
|
&formatCount);
|
||||||
if (strcmp(fmts[j].MIME, type) == 0) {
|
for (int32 j = 0; j < formatCount; j++) {
|
||||||
*format = fmts[j];
|
if (strcmp(formats[j].MIME, type) == 0) {
|
||||||
|
*format = formats[j];
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1441,18 +1337,8 @@ ShowImageView::KeyDown(const char* bytes, int32 numBytes)
|
|||||||
break;
|
break;
|
||||||
case B_DELETE:
|
case B_DELETE:
|
||||||
{
|
{
|
||||||
// Move image to Trash
|
// TODO!
|
||||||
BMessage trash(BPrivate::kMoveToTrash);
|
//fNavigator.DeleteFile();
|
||||||
trash.AddRef("refs", &fCurrentRef);
|
|
||||||
// We create our own messenger because the member fTrackerMessenger
|
|
||||||
// could be invalid
|
|
||||||
BMessenger tracker(kTrackerSignature);
|
|
||||||
if (tracker.SendMessage(&trash) == B_OK)
|
|
||||||
if (!NextFile()) {
|
|
||||||
// This is the last (or only file) in this directory,
|
|
||||||
// close the window
|
|
||||||
_SendMessageToWindow(B_QUIT_REQUESTED);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '+':
|
case '+':
|
||||||
@@ -1540,6 +1426,8 @@ void
|
|||||||
ShowImageView::MessageReceived(BMessage* message)
|
ShowImageView::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
// TODO!
|
||||||
|
#if 0
|
||||||
case B_SIMPLE_DATA:
|
case B_SIMPLE_DATA:
|
||||||
if (message->WasDropped()) {
|
if (message->WasDropped()) {
|
||||||
uint32 type;
|
uint32 type;
|
||||||
@@ -1553,7 +1441,7 @@ ShowImageView::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif
|
||||||
case B_COPY_TARGET:
|
case B_COPY_TARGET:
|
||||||
_HandleDrop(message);
|
_HandleDrop(message);
|
||||||
break;
|
break;
|
||||||
@@ -1610,20 +1498,6 @@ ShowImageView::FixupScrollBars()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
ShowImageView::CurrentPage()
|
|
||||||
{
|
|
||||||
return fDocumentIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int32
|
|
||||||
ShowImageView::PageCount()
|
|
||||||
{
|
|
||||||
return fDocumentCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetSelectionMode(bool selectionMode)
|
ShowImageView::SetSelectionMode(bool selectionMode)
|
||||||
{
|
{
|
||||||
@@ -1737,201 +1611,6 @@ ShowImageView::CopySelectionToClipboard()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::FirstPage()
|
|
||||||
{
|
|
||||||
if (fDocumentIndex != 1) {
|
|
||||||
fDocumentIndex = 1;
|
|
||||||
SetImage(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::LastPage()
|
|
||||||
{
|
|
||||||
if (fDocumentIndex != fDocumentCount) {
|
|
||||||
fDocumentIndex = fDocumentCount;
|
|
||||||
SetImage(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::NextPage()
|
|
||||||
{
|
|
||||||
if (fDocumentIndex < fDocumentCount) {
|
|
||||||
fDocumentIndex++;
|
|
||||||
SetImage(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::PrevPage()
|
|
||||||
{
|
|
||||||
if (fDocumentIndex > 1) {
|
|
||||||
fDocumentIndex--;
|
|
||||||
SetImage(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
ShowImageView::_CompareEntries(const void* a, const void* b)
|
|
||||||
{
|
|
||||||
entry_ref *r1, *r2;
|
|
||||||
r1 = *(entry_ref**)a;
|
|
||||||
r2 = *(entry_ref**)b;
|
|
||||||
return strcasecmp(r1->name, r2->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::GoToPage(int32 page)
|
|
||||||
{
|
|
||||||
if (page > 0 && page <= fDocumentCount && page != fDocumentIndex) {
|
|
||||||
fDocumentIndex = page;
|
|
||||||
SetImage(NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_FreeEntries(BList* entries)
|
|
||||||
{
|
|
||||||
const int32 n = entries->CountItems();
|
|
||||||
for (int32 i = 0; i < n; i ++) {
|
|
||||||
entry_ref* ref = (entry_ref*)entries->ItemAt(i);
|
|
||||||
delete ref;
|
|
||||||
}
|
|
||||||
entries->MakeEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
ShowImageView::_SetTrackerSelectionToCurrent()
|
|
||||||
{
|
|
||||||
BMessage setsel(B_SET_PROPERTY);
|
|
||||||
setsel.AddSpecifier("Selection");
|
|
||||||
setsel.AddRef("data", &fCurrentRef);
|
|
||||||
fTrackerMessenger.SendMessage(&setsel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ShowImageView::_FindNextImage(entry_ref *in_current, entry_ref *ref, bool next,
|
|
||||||
bool rewind)
|
|
||||||
{
|
|
||||||
// Based on GetTrackerWindowFile function from BeMail
|
|
||||||
if (!fTrackerMessenger.IsValid())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Ask the Tracker what the next/prev file in the window is.
|
|
||||||
// Continue asking for the next reference until a valid
|
|
||||||
// image is found.
|
|
||||||
//
|
|
||||||
entry_ref nextRef = *in_current;
|
|
||||||
bool foundRef = false;
|
|
||||||
while (!foundRef)
|
|
||||||
{
|
|
||||||
BMessage request(B_GET_PROPERTY);
|
|
||||||
BMessage spc;
|
|
||||||
if (rewind)
|
|
||||||
spc.what = B_DIRECT_SPECIFIER;
|
|
||||||
else if (next)
|
|
||||||
spc.what = 'snxt';
|
|
||||||
else
|
|
||||||
spc.what = 'sprv';
|
|
||||||
spc.AddString("property", "Entry");
|
|
||||||
if (rewind)
|
|
||||||
// if rewinding, ask for the ref to the
|
|
||||||
// first item in the directory
|
|
||||||
spc.AddInt32("data", 0);
|
|
||||||
else
|
|
||||||
spc.AddRef("data", &nextRef);
|
|
||||||
request.AddSpecifier(&spc);
|
|
||||||
|
|
||||||
BMessage reply;
|
|
||||||
if (fTrackerMessenger.SendMessage(&request, &reply) != B_OK)
|
|
||||||
return false;
|
|
||||||
if (reply.FindRef("result", &nextRef) != B_OK)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (_IsImage(&nextRef))
|
|
||||||
foundRef = true;
|
|
||||||
|
|
||||||
rewind = false;
|
|
||||||
// stop asking for the first ref in the directory
|
|
||||||
}
|
|
||||||
|
|
||||||
*ref = nextRef;
|
|
||||||
return foundRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
ShowImageView::_ShowNextImage(bool next, bool rewind)
|
|
||||||
{
|
|
||||||
entry_ref curRef = fCurrentRef;
|
|
||||||
entry_ref imgRef;
|
|
||||||
bool found = _FindNextImage(&curRef, &imgRef, next, rewind);
|
|
||||||
if (found) {
|
|
||||||
// Keep trying to load images until:
|
|
||||||
// 1. The image loads successfully
|
|
||||||
// 2. The last file in the directory is found (for find next or find first)
|
|
||||||
// 3. The first file in the directory is found (for find prev)
|
|
||||||
// 4. The call to _FindNextImage fails for any other reason
|
|
||||||
while (SetImage(&imgRef) != B_OK) {
|
|
||||||
curRef = imgRef;
|
|
||||||
found = _FindNextImage(&curRef, &imgRef, next, false);
|
|
||||||
if (!found)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
_SetTrackerSelectionToCurrent();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ShowImageView::NextFile()
|
|
||||||
{
|
|
||||||
return _ShowNextImage(true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
ShowImageView::PrevFile()
|
|
||||||
{
|
|
||||||
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
|
|
||||||
ShowImageView::_FirstFile()
|
|
||||||
{
|
|
||||||
return _ShowNextImage(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageView::SetZoom(float zoom, BPoint where)
|
ShowImageView::SetZoom(float zoom, BPoint where)
|
||||||
{
|
{
|
||||||
@@ -2126,11 +1805,10 @@ ShowImageView::Rotate(int degree)
|
|||||||
void
|
void
|
||||||
ShowImageView::Flip(bool vertical)
|
ShowImageView::Flip(bool vertical)
|
||||||
{
|
{
|
||||||
if (vertical) {
|
if (vertical)
|
||||||
_UserDoImageOperation(ImageProcessor::kFlipLeftToRight);
|
_UserDoImageOperation(ImageProcessor::kFlipLeftToRight);
|
||||||
} else {
|
else
|
||||||
_UserDoImageOperation(ImageProcessor::kFlipTopToBottom);
|
_UserDoImageOperation(ImageProcessor::kFlipTopToBottom);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,10 @@ public:
|
|||||||
|
|
||||||
void SetTrackerMessenger(
|
void SetTrackerMessenger(
|
||||||
const BMessenger& trackerMessenger);
|
const BMessenger& trackerMessenger);
|
||||||
status_t SetImage(const entry_ref* ref);
|
status_t SetImage(const BMessage* message);
|
||||||
|
status_t SetImage(const entry_ref* ref, BBitmap* bitmap);
|
||||||
const entry_ref* Image() const { return &fCurrentRef; }
|
const entry_ref* Image() const { return &fCurrentRef; }
|
||||||
|
BBitmap* Bitmap();
|
||||||
|
|
||||||
BPoint ImageToView(BPoint p) const;
|
BPoint ImageToView(BPoint p) const;
|
||||||
BPoint ViewToImage(BPoint p) const;
|
BPoint ViewToImage(BPoint p) const;
|
||||||
@@ -77,10 +79,6 @@ public:
|
|||||||
{ return fStretchToBounds; }
|
{ return fStretchToBounds; }
|
||||||
void SetFullScreen(bool fullScreen);
|
void SetFullScreen(bool fullScreen);
|
||||||
|
|
||||||
BBitmap* GetBitmap();
|
|
||||||
void GetName(BString* name);
|
|
||||||
void GetPath(BString* name);
|
|
||||||
|
|
||||||
void FixupScrollBar(enum orientation orientation,
|
void FixupScrollBar(enum orientation orientation,
|
||||||
float bitmapLength, float viewLength);
|
float bitmapLength, float viewLength);
|
||||||
void FixupScrollBars();
|
void FixupScrollBars();
|
||||||
@@ -94,26 +92,13 @@ public:
|
|||||||
|
|
||||||
void CopySelectionToClipboard();
|
void CopySelectionToClipboard();
|
||||||
|
|
||||||
int32 CurrentPage();
|
|
||||||
int32 PageCount();
|
|
||||||
|
|
||||||
void FirstPage();
|
|
||||||
void LastPage();
|
|
||||||
void NextPage();
|
|
||||||
void PrevPage();
|
|
||||||
void GoToPage(int32 page);
|
|
||||||
|
|
||||||
bool NextFile();
|
|
||||||
bool PrevFile();
|
|
||||||
bool HasNextFile();
|
|
||||||
bool HasPrevFile();
|
|
||||||
|
|
||||||
void SetSlideShowDelay(float seconds);
|
void SetSlideShowDelay(float seconds);
|
||||||
float GetSlideShowDelay() const
|
float GetSlideShowDelay() const
|
||||||
{ return fSlideShowDelay / 10.0; }
|
{ return fSlideShowDelay / 10.0; }
|
||||||
bool SlideShowStarted() const { return fSlideShow; }
|
bool SlideShowStarted() const { return fSlideShow; }
|
||||||
void StartSlideShow();
|
void StartSlideShow();
|
||||||
void StopSlideShow();
|
void StopSlideShow();
|
||||||
|
|
||||||
void SetZoom(float zoom,
|
void SetZoom(float zoom,
|
||||||
BPoint where = BPoint(-1, -1));
|
BPoint where = BPoint(-1, -1));
|
||||||
void ZoomIn(BPoint where = BPoint(-1, -1));
|
void ZoomIn(BPoint where = BPoint(-1, -1));
|
||||||
@@ -170,15 +155,6 @@ private:
|
|||||||
bool _ShouldStretch() const;
|
bool _ShouldStretch() const;
|
||||||
float _FitToBoundsZoom() const;
|
float _FitToBoundsZoom() const;
|
||||||
BRect _AlignBitmap();
|
BRect _AlignBitmap();
|
||||||
bool _IsImage(const entry_ref* pref);
|
|
||||||
static int _CompareEntries(const void* a, const void* b);
|
|
||||||
void _FreeEntries(BList* entries);
|
|
||||||
void _SetTrackerSelectionToCurrent();
|
|
||||||
bool _FindNextImage(entry_ref* inCurrent,
|
|
||||||
entry_ref* outImage, bool next,
|
|
||||||
bool rewind);
|
|
||||||
bool _ShowNextImage(bool next, bool rewind);
|
|
||||||
bool _FirstFile();
|
|
||||||
BBitmap* _CopySelection(uchar alpha = 255,
|
BBitmap* _CopySelection(uchar alpha = 255,
|
||||||
bool imageSize = true);
|
bool imageSize = true);
|
||||||
bool _AddSupportedTypes(BMessage* message,
|
bool _AddSupportedTypes(BMessage* message,
|
||||||
@@ -219,11 +195,6 @@ private:
|
|||||||
// of the window that this was launched from
|
// of the window that this was launched from
|
||||||
entry_ref fCurrentRef;
|
entry_ref fCurrentRef;
|
||||||
|
|
||||||
int32 fDocumentIndex;
|
|
||||||
// of the image in the file
|
|
||||||
int32 fDocumentCount;
|
|
||||||
// number of images in the file
|
|
||||||
|
|
||||||
BBitmap* fBitmap;
|
BBitmap* fBitmap;
|
||||||
BBitmap* fDisplayBitmap;
|
BBitmap* fDisplayBitmap;
|
||||||
BBitmap* fSelectionBitmap;
|
BBitmap* fSelectionBitmap;
|
||||||
@@ -259,9 +230,8 @@ private:
|
|||||||
bool fShowCaption;
|
bool fShowCaption;
|
||||||
BString fCaption;
|
BString fCaption;
|
||||||
|
|
||||||
BString fImageType;
|
BString fFormatDescription;
|
||||||
// Type of image, for use in status bar and caption
|
BString fMimeType;
|
||||||
BString fImageMime;
|
|
||||||
|
|
||||||
bool fShowingPopUpMenu;
|
bool fShowingPopUpMenu;
|
||||||
|
|
||||||
|
|||||||
@@ -51,16 +51,19 @@
|
|||||||
#include "ShowImageView.h"
|
#include "ShowImageView.h"
|
||||||
|
|
||||||
|
|
||||||
|
// BMessage field names used in Save messages
|
||||||
|
const char* kTypeField = "be:type";
|
||||||
|
const char* kTranslatorField = "be:translator";
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -- ShowImageWindow::RecentDocumentsMenu
|
// #pragma mark -- ShowImageWindow::RecentDocumentsMenu
|
||||||
|
|
||||||
|
|
||||||
class ShowImageWindow::RecentDocumentsMenu : public BMenu {
|
class ShowImageWindow::RecentDocumentsMenu : public BMenu {
|
||||||
public:
|
public:
|
||||||
RecentDocumentsMenu(const char* title,
|
RecentDocumentsMenu(const char* title,
|
||||||
menu_layout layout = B_ITEMS_IN_COLUMN);
|
menu_layout layout = B_ITEMS_IN_COLUMN);
|
||||||
bool AddDynamicItem(add_state addState);
|
bool AddDynamicItem(add_state addState);
|
||||||
|
|
||||||
private:
|
|
||||||
void UpdateRecentDocumentsMenu();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -102,18 +105,33 @@ ShowImageWindow::RecentDocumentsMenu::AddDynamicItem(add_state addState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark
|
||||||
|
|
||||||
|
|
||||||
|
// This is temporary solution for building BString with printf like format.
|
||||||
|
// will be removed in the future.
|
||||||
|
static void
|
||||||
|
bs_printf(BString* string, const char* format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char* buf;
|
||||||
|
|
||||||
|
va_start(ap, format);
|
||||||
|
vasprintf(&buf, format, ap);
|
||||||
|
string->SetTo(buf);
|
||||||
|
free(buf);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -- ShowImageWindow
|
// #pragma mark -- ShowImageWindow
|
||||||
|
|
||||||
|
|
||||||
// BMessage field names used in Save messages
|
|
||||||
const char* kTypeField = "be:type";
|
|
||||||
const char* kTranslatorField = "be:translator";
|
|
||||||
|
|
||||||
|
|
||||||
ShowImageWindow::ShowImageWindow(const entry_ref* ref,
|
ShowImageWindow::ShowImageWindow(const entry_ref* ref,
|
||||||
const BMessenger& trackerMessenger)
|
const BMessenger& trackerMessenger)
|
||||||
:
|
:
|
||||||
BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0),
|
BWindow(BRect(5, 24, 250, 100), "", B_DOCUMENT_WINDOW, 0),
|
||||||
|
fNavigator(this),
|
||||||
fSavePanel(NULL),
|
fSavePanel(NULL),
|
||||||
fBar(NULL),
|
fBar(NULL),
|
||||||
fOpenMenu(NULL),
|
fOpenMenu(NULL),
|
||||||
@@ -127,9 +145,7 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
|
|||||||
fShowCaption(true),
|
fShowCaption(true),
|
||||||
fPrintSettings(NULL),
|
fPrintSettings(NULL),
|
||||||
fResizerWindowMessenger(NULL),
|
fResizerWindowMessenger(NULL),
|
||||||
fResizeItem(NULL),
|
fResizeItem(NULL)
|
||||||
fHeight(0),
|
|
||||||
fWidth(0)
|
|
||||||
{
|
{
|
||||||
_LoadSettings();
|
_LoadSettings();
|
||||||
|
|
||||||
@@ -181,34 +197,16 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
|
|||||||
SetSizeLimits(250, 100000, 100, 100000);
|
SetSizeLimits(250, 100000, 100, 100000);
|
||||||
|
|
||||||
// finish creating the window
|
// finish creating the window
|
||||||
fImageView->SetImage(ref);
|
fNavigator.SetTrackerMessenger(trackerMessenger);
|
||||||
fImageView->SetTrackerMessenger(trackerMessenger);
|
if (fNavigator.LoadImage(*ref) != B_OK) {
|
||||||
|
_LoadError(*ref);
|
||||||
#undef B_TRANSLATE_CONTEXT
|
|
||||||
#define B_TRANSLATE_CONTEXT "LoadAlerts"
|
|
||||||
|
|
||||||
if (InitCheck() != B_OK) {
|
|
||||||
BAlert* alert;
|
|
||||||
alert = new BAlert(
|
|
||||||
B_TRANSLATE("ShowImage"),
|
|
||||||
B_TRANSLATE("Could not load image! Either the file or an image "
|
|
||||||
"translator for it does not exist."),
|
|
||||||
B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_INFO_ALERT);
|
|
||||||
alert->Go();
|
|
||||||
|
|
||||||
// quit if file could not be opened
|
|
||||||
Quit();
|
Quit();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef B_TRANSLATE_CONTEXT
|
|
||||||
#define B_TRANSLATE_CONTEXT "Menus"
|
|
||||||
|
|
||||||
// add View menu here so it can access ShowImageView methods
|
// add View menu here so it can access ShowImageView methods
|
||||||
BMenu* menu = new BMenu(B_TRANSLATE("View"));
|
BMenu* menu = new BMenu(B_TRANSLATE_WITH_CONTEXT("View", "Menus"));
|
||||||
_BuildViewMenu(menu, false);
|
_BuildViewMenu(menu, false);
|
||||||
fBar->AddItem(menu);
|
fBar->AddItem(menu);
|
||||||
UpdateTitle();
|
|
||||||
|
|
||||||
SetPulseRate(100000);
|
SetPulseRate(100000);
|
||||||
// every 1/10 second; ShowImageView needs it for marching ants
|
// every 1/10 second; ShowImageView needs it for marching ants
|
||||||
@@ -216,14 +214,12 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
|
|||||||
_MarkMenuItem(menu, MSG_SELECTION_MODE,
|
_MarkMenuItem(menu, MSG_SELECTION_MODE,
|
||||||
fImageView->IsSelectionModeEnabled());
|
fImageView->IsSelectionModeEnabled());
|
||||||
|
|
||||||
WindowRedimension(fImageView->GetBitmap());
|
|
||||||
fImageView->ResetZoom();
|
|
||||||
fImageView->MakeFocus(true); // to receive KeyDown messages
|
|
||||||
Show();
|
|
||||||
|
|
||||||
// Tell application object to query the clipboard
|
// Tell application object to query the clipboard
|
||||||
// and tell this window if it contains interesting data or not
|
// and tell this window if it contains interesting data or not
|
||||||
be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED);
|
be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED);
|
||||||
|
|
||||||
|
// The window will be shown on screen automatically
|
||||||
|
Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -233,22 +229,11 @@ ShowImageWindow::~ShowImageWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
|
||||||
ShowImageWindow::InitCheck()
|
|
||||||
{
|
|
||||||
if (!fImageView || fImageView->GetBitmap() == NULL)
|
|
||||||
return B_ERROR;
|
|
||||||
|
|
||||||
return B_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageWindow::UpdateTitle()
|
ShowImageWindow::UpdateTitle()
|
||||||
{
|
{
|
||||||
BString path;
|
BPath path(fImageView->Image());
|
||||||
fImageView->GetPath(&path);
|
SetTitle(path.Path());
|
||||||
SetTitle(path.String());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -559,6 +544,41 @@ void
|
|||||||
ShowImageWindow::MessageReceived(BMessage* message)
|
ShowImageWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
|
case kMsgImageLoaded:
|
||||||
|
{
|
||||||
|
bool first = fImageView->Bitmap() == NULL;
|
||||||
|
|
||||||
|
status_t status = fImageView->SetImage(message);
|
||||||
|
if (status != B_OK) {
|
||||||
|
entry_ref ref;
|
||||||
|
message->FindRef("ref", &ref);
|
||||||
|
|
||||||
|
_LoadError(ref);
|
||||||
|
|
||||||
|
// quit if file could not be opened
|
||||||
|
if (first)
|
||||||
|
Quit();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
fImageType = message->FindString("type");
|
||||||
|
|
||||||
|
if (first) {
|
||||||
|
WindowRedimension(fImageView->Bitmap());
|
||||||
|
fImageView->ResetZoom();
|
||||||
|
fImageView->MakeFocus(true);
|
||||||
|
// to receive key messages
|
||||||
|
|
||||||
|
Show();
|
||||||
|
} else {
|
||||||
|
if (!fImageView->StretchesToBounds()
|
||||||
|
&& !fImageView->ShrinksToBounds()
|
||||||
|
&& !fFullScreen)
|
||||||
|
WindowRedimension(fImageView->Bitmap());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MSG_MODIFIED:
|
case MSG_MODIFIED:
|
||||||
// If image has been modified due to a Cut or Paste
|
// If image has been modified due to a Cut or Paste
|
||||||
fModified = true;
|
fModified = true;
|
||||||
@@ -583,95 +603,61 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case MSG_UPDATE_STATUS:
|
case MSG_UPDATE_STATUS:
|
||||||
{
|
{
|
||||||
int32 pages = fImageView->PageCount();
|
int32 pages = fNavigator.PageCount();
|
||||||
int32 curPage = fImageView->CurrentPage();
|
int32 currentPage = fNavigator.CurrentPage();
|
||||||
|
|
||||||
bool enable = (pages > 1) ? true : false;
|
bool enable = pages > 1 ? true : false;
|
||||||
_EnableMenuItem(fBar, MSG_PAGE_FIRST, enable);
|
_EnableMenuItem(fBar, MSG_PAGE_FIRST, enable);
|
||||||
_EnableMenuItem(fBar, MSG_PAGE_LAST, enable);
|
_EnableMenuItem(fBar, MSG_PAGE_LAST, enable);
|
||||||
_EnableMenuItem(fBar, MSG_PAGE_NEXT, enable);
|
_EnableMenuItem(fBar, MSG_PAGE_NEXT, enable);
|
||||||
_EnableMenuItem(fBar, MSG_PAGE_PREV, enable);
|
_EnableMenuItem(fBar, MSG_PAGE_PREV, enable);
|
||||||
fGoToPageMenu->SetEnabled(enable);
|
fGoToPageMenu->SetEnabled(enable);
|
||||||
|
|
||||||
_EnableMenuItem(fBar, MSG_FILE_NEXT, fImageView->HasNextFile());
|
_EnableMenuItem(fBar, MSG_FILE_NEXT, fNavigator.HasNextFile());
|
||||||
_EnableMenuItem(fBar, MSG_FILE_PREV, fImageView->HasPrevFile());
|
_EnableMenuItem(fBar, MSG_FILE_PREV, fNavigator.HasPreviousFile());
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
while (fGoToPageMenu->CountItems() > 0)
|
while (fGoToPageMenu->CountItems() > 0) {
|
||||||
// Remove all page numbers
|
// Remove all page numbers
|
||||||
delete fGoToPageMenu->RemoveItem(0L);
|
delete fGoToPageMenu->RemoveItem(0L);
|
||||||
|
}
|
||||||
|
|
||||||
for (int32 i = 1; i <= pages; i++) {
|
for (int32 i = 1; i <= pages; i++) {
|
||||||
// Fill Go To page submenu with an entry for each page
|
// Fill Go To page submenu with an entry for each page
|
||||||
BMessage* pgomsg = new BMessage(MSG_GOTO_PAGE);
|
BMessage* goTo = new BMessage(MSG_GOTO_PAGE);
|
||||||
pgomsg->AddInt32("page", i);
|
goTo->AddInt32("page", i);
|
||||||
|
|
||||||
char shortcut = 0;
|
char shortcut = 0;
|
||||||
if (i < 10) {
|
if (i < 10)
|
||||||
shortcut = '0' + i;
|
shortcut = '0' + i;
|
||||||
} else if (i == 10) {
|
|
||||||
shortcut = '0';
|
|
||||||
}
|
|
||||||
|
|
||||||
BString strCaption;
|
BString strCaption;
|
||||||
strCaption << i;
|
strCaption << i;
|
||||||
|
|
||||||
BMenuItem* item = new BMenuItem(strCaption.String(), pgomsg,
|
BMenuItem* item = new BMenuItem(strCaption.String(), goTo,
|
||||||
shortcut);
|
shortcut);
|
||||||
if (curPage == i)
|
if (currentPage == i)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
fGoToPageMenu->AddItem(item);
|
fGoToPageMenu->AddItem(item);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Make sure the correct page is marked
|
// Make sure the correct page is marked
|
||||||
BMenuItem *pcurItem;
|
BMenuItem* currentItem = fGoToPageMenu->ItemAt(currentPage - 1);
|
||||||
pcurItem = fGoToPageMenu->ItemAt(curPage - 1);
|
if (currentItem != NULL && !currentItem->IsMarked())
|
||||||
if (!pcurItem->IsMarked()) {
|
currentItem->SetMarked(true);
|
||||||
pcurItem->SetMarked(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BString status;
|
_UpdateStatusText(message);
|
||||||
bool messageProvidesSize = false;
|
|
||||||
if (message->FindInt32("width", &fWidth) >= B_OK
|
|
||||||
&& message->FindInt32("height", &fHeight) >= B_OK) {
|
|
||||||
status << fWidth << "x" << fHeight;
|
|
||||||
messageProvidesSize = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
BString str;
|
|
||||||
if (message->FindString("status", &str) == B_OK && str.Length() > 0) {
|
|
||||||
if (status.Length() > 0)
|
|
||||||
status << ", ";
|
|
||||||
status << str;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (messageProvidesSize) {
|
|
||||||
_UpdateResizerWindow(fWidth, fHeight);
|
|
||||||
if (!fImageView->StretchesToBounds()
|
|
||||||
&& !fImageView->ShrinksToBounds()
|
|
||||||
&& !fFullScreen)
|
|
||||||
WindowRedimension(fImageView->GetBitmap());
|
|
||||||
}
|
|
||||||
|
|
||||||
fStatusView->SetText(status);
|
|
||||||
|
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case MSG_UPDATE_STATUS_TEXT:
|
case MSG_UPDATE_STATUS_TEXT:
|
||||||
{
|
{
|
||||||
BString status;
|
_UpdateStatusText(message);
|
||||||
status << fWidth << "x" << fHeight;
|
|
||||||
BString str;
|
|
||||||
if (message->FindString("status", &str) == B_OK && str.Length() > 0) {
|
|
||||||
status << ", " << str;
|
|
||||||
fStatusView->SetText(status);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -718,25 +704,26 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case MSG_PAGE_FIRST:
|
case MSG_PAGE_FIRST:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->FirstPage();
|
fNavigator.FirstPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_LAST:
|
case MSG_PAGE_LAST:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->LastPage();
|
fNavigator.LastPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_NEXT:
|
case MSG_PAGE_NEXT:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->NextPage();
|
fNavigator.NextPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_PAGE_PREV:
|
case MSG_PAGE_PREV:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->PrevPage();
|
fNavigator.PreviousPage();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_GOTO_PAGE: {
|
case MSG_GOTO_PAGE:
|
||||||
|
{
|
||||||
if (!_ClosePrompt())
|
if (!_ClosePrompt())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -744,19 +731,20 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
if (message->FindInt32("page", &newPage) != B_OK)
|
if (message->FindInt32("page", &newPage) != B_OK)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
int32 curPage = fImageView->CurrentPage();
|
int32 currentPage = fNavigator.CurrentPage();
|
||||||
int32 pages = fImageView->PageCount();
|
int32 pages = fNavigator.PageCount();
|
||||||
|
|
||||||
if (newPage > 0 && newPage <= pages) {
|
if (newPage > 0 && newPage <= pages) {
|
||||||
BMenuItem* pcurItem = fGoToPageMenu->ItemAt(curPage - 1);
|
BMenuItem* currentItem = fGoToPageMenu->ItemAt(currentPage - 1);
|
||||||
BMenuItem* pnewItem = fGoToPageMenu->ItemAt(newPage - 1);
|
BMenuItem* newItem = fGoToPageMenu->ItemAt(newPage - 1);
|
||||||
if (pcurItem && pnewItem) {
|
if (currentItem != NULL && newItem != NULL) {
|
||||||
pcurItem->SetMarked(false);
|
currentItem->SetMarked(false);
|
||||||
pnewItem->SetMarked(true);
|
newItem->SetMarked(true);
|
||||||
fImageView->GoToPage(newPage);
|
fNavigator.GoToPage(newPage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case MSG_SHRINK_TO_WINDOW:
|
case MSG_SHRINK_TO_WINDOW:
|
||||||
_ResizeToWindow(true, message->what);
|
_ResizeToWindow(true, message->what);
|
||||||
@@ -768,12 +756,12 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
|
|
||||||
case MSG_FILE_PREV:
|
case MSG_FILE_PREV:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->PrevFile();
|
fNavigator.PreviousFile();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_FILE_NEXT:
|
case MSG_FILE_NEXT:
|
||||||
if (_ClosePrompt())
|
if (_ClosePrompt())
|
||||||
fImageView->NextFile();
|
fNavigator.NextFile();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_ROTATE_90:
|
case MSG_ROTATE_90:
|
||||||
@@ -869,31 +857,20 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
fImageView->SetScaleBilinear(_ToggleMenuItem(message->what));
|
fImageView->SetScaleBilinear(_ToggleMenuItem(message->what));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_OPEN_RESIZER_WINDOW: {
|
|
||||||
if (fImageView->GetBitmap() != NULL) {
|
|
||||||
BRect rect = fImageView->GetBitmap()->Bounds();
|
|
||||||
_OpenResizerWindow(rect.IntegerWidth()+1, rect.IntegerHeight()+1);
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MSG_RESIZE: {
|
|
||||||
int w = message->FindInt32("w");
|
|
||||||
int h = message->FindInt32("h");
|
|
||||||
fImageView->ResizeImage(w, h);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case MSG_RESIZER_WINDOW_QUIT:
|
case MSG_RESIZER_WINDOW_QUIT:
|
||||||
delete fResizerWindowMessenger;
|
delete fResizerWindowMessenger;
|
||||||
fResizerWindowMessenger = NULL;
|
fResizerWindowMessenger = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_DESKTOP_BACKGROUND: {
|
case MSG_DESKTOP_BACKGROUND:
|
||||||
|
{
|
||||||
BMessage message(B_REFS_RECEIVED);
|
BMessage message(B_REFS_RECEIVED);
|
||||||
message.AddRef("refs", fImageView->Image());
|
message.AddRef("refs", fImageView->Image());
|
||||||
// This is used in the Backgrounds code for scaled placement
|
// This is used in the Backgrounds code for scaled placement
|
||||||
message.AddInt32("placement", 'scpl');
|
message.AddInt32("placement", 'scpl');
|
||||||
be_roster->Launch("application/x-vnd.haiku-backgrounds", &message);
|
be_roster->Launch("application/x-vnd.haiku-backgrounds", &message);
|
||||||
} break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
@@ -902,6 +879,40 @@ ShowImageWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageWindow::_UpdateStatusText(const BMessage* message)
|
||||||
|
{
|
||||||
|
BString status;
|
||||||
|
if (fImageView->Bitmap() != NULL) {
|
||||||
|
BRect bounds = fImageView->Bitmap()->Bounds();
|
||||||
|
status << bounds.IntegerWidth() + 1
|
||||||
|
<< "x" << bounds.IntegerHeight() + 1 << ", " << fImageType;
|
||||||
|
}
|
||||||
|
|
||||||
|
BString text;
|
||||||
|
if (message != NULL && message->FindString("status", &text) == B_OK
|
||||||
|
&& text.Length() > 0) {
|
||||||
|
status << ", " << text;
|
||||||
|
}
|
||||||
|
|
||||||
|
fStatusView->SetText(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ShowImageWindow::_LoadError(const entry_ref& ref)
|
||||||
|
{
|
||||||
|
// TODO: give a better error message!
|
||||||
|
BAlert* alert = new BAlert(B_TRANSLATE("ShowImage"),
|
||||||
|
B_TRANSLATE_WITH_CONTEXT("Could not load image! Either the "
|
||||||
|
"file or an image translator for it does not exist.",
|
||||||
|
"LoadAlerts"),
|
||||||
|
B_TRANSLATE_WITH_CONTEXT("OK", "Alerts"), NULL, NULL,
|
||||||
|
B_WIDTH_AS_USUAL, B_INFO_ALERT);
|
||||||
|
alert->Go();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
ShowImageWindow::_SaveAs(BMessage* message)
|
ShowImageWindow::_SaveAs(BMessage* message)
|
||||||
{
|
{
|
||||||
@@ -977,22 +988,6 @@ ShowImageWindow::_SaveToFile(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// This is temporary solution for building BString with printf like format.
|
|
||||||
// will be removed in the future.
|
|
||||||
static void
|
|
||||||
bs_printf(BString* string, const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
char* buf;
|
|
||||||
|
|
||||||
va_start(ap, format);
|
|
||||||
vasprintf(&buf, format, ap);
|
|
||||||
string->SetTo(buf);
|
|
||||||
free(buf);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#undef B_TRANSLATE_CONTEXT
|
#undef B_TRANSLATE_CONTEXT
|
||||||
#define B_TRANSLATE_CONTEXT "ClosePrompt"
|
#define B_TRANSLATE_CONTEXT "ClosePrompt"
|
||||||
|
|
||||||
@@ -1002,34 +997,32 @@ ShowImageWindow::_ClosePrompt()
|
|||||||
if (!fModified)
|
if (!fModified)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
int32 page, count;
|
int32 count = fNavigator.PageCount();
|
||||||
count = fImageView->PageCount();
|
int32 page = fNavigator.CurrentPage();
|
||||||
page = fImageView->CurrentPage();
|
BString prompt;
|
||||||
BString prompt, name;
|
|
||||||
fImageView->GetName(&name);
|
|
||||||
|
|
||||||
if (count > 1) {
|
if (count > 1) {
|
||||||
bs_printf(&prompt,
|
bs_printf(&prompt,
|
||||||
B_TRANSLATE("The document '%s' (page %d) has been changed. Do you "
|
B_TRANSLATE("The document '%s' (page %d) has been changed. Do you "
|
||||||
"want to close the document?"),
|
"want to close the document?"),
|
||||||
name.String(), page);
|
fImageView->Image()->name, page);
|
||||||
} else {
|
} else {
|
||||||
bs_printf(&prompt,
|
bs_printf(&prompt,
|
||||||
B_TRANSLATE("The document '%s' has been changed. Do you want to "
|
B_TRANSLATE("The document '%s' has been changed. Do you want to "
|
||||||
"close the document?"),
|
"close the document?"),
|
||||||
name.String());
|
fImageView->Image()->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
BAlert* pAlert = new BAlert(B_TRANSLATE("Close document"), prompt.String(),
|
BAlert* alert = new BAlert(B_TRANSLATE("Close document"), prompt.String(),
|
||||||
B_TRANSLATE("Cancel"), B_TRANSLATE("Close"));
|
B_TRANSLATE("Cancel"), B_TRANSLATE("Close"));
|
||||||
if (pAlert->Go() == 0) {
|
if (alert->Go() == 0) {
|
||||||
// Cancel
|
// Cancel
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
// Close
|
|
||||||
fModified = false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close
|
||||||
|
fModified = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1112,9 +1105,7 @@ ShowImageWindow::_SavePrintOptions()
|
|||||||
bool
|
bool
|
||||||
ShowImageWindow::_PageSetup()
|
ShowImageWindow::_PageSetup()
|
||||||
{
|
{
|
||||||
BString name;
|
BPrintJob printJob(fImageView->Image()->name);
|
||||||
fImageView->GetName(&name);
|
|
||||||
BPrintJob printJob(name.String());
|
|
||||||
if (fPrintSettings != NULL)
|
if (fPrintSettings != NULL)
|
||||||
printJob.SetSettings(new BMessage(*fPrintSettings));
|
printJob.SetSettings(new BMessage(*fPrintSettings));
|
||||||
|
|
||||||
@@ -1132,16 +1123,13 @@ void
|
|||||||
ShowImageWindow::_PrepareForPrint()
|
ShowImageWindow::_PrepareForPrint()
|
||||||
{
|
{
|
||||||
if (fPrintSettings == NULL) {
|
if (fPrintSettings == NULL) {
|
||||||
BString name;
|
BPrintJob printJob(fImageView->Image()->name);
|
||||||
fImageView->GetName(&name);
|
|
||||||
|
|
||||||
BPrintJob printJob("");
|
|
||||||
if (printJob.ConfigJob() == B_OK)
|
if (printJob.ConfigJob() == B_OK)
|
||||||
fPrintSettings = printJob.Settings();
|
fPrintSettings = printJob.Settings();
|
||||||
}
|
}
|
||||||
|
|
||||||
fPrintOptions.SetBounds(fImageView->GetBitmap()->Bounds());
|
fPrintOptions.SetBounds(fImageView->Bitmap()->Bounds());
|
||||||
fPrintOptions.SetWidth(fImageView->GetBitmap()->Bounds().Width() + 1);
|
fPrintOptions.SetWidth(fImageView->Bitmap()->Bounds().Width() + 1);
|
||||||
|
|
||||||
new PrintOptionsWindow(BPoint(Frame().left + 30, Frame().top + 50),
|
new PrintOptionsWindow(BPoint(Frame().left + 30, Frame().top + 50),
|
||||||
&fPrintOptions, this);
|
&fPrintOptions, this);
|
||||||
@@ -1157,10 +1145,7 @@ ShowImageWindow::_Print(BMessage* msg)
|
|||||||
|
|
||||||
_SavePrintOptions();
|
_SavePrintOptions();
|
||||||
|
|
||||||
BString name;
|
BPrintJob printJob(fImageView->Image()->name);
|
||||||
fImageView->GetName(&name);
|
|
||||||
|
|
||||||
BPrintJob printJob(name.String());
|
|
||||||
if (fPrintSettings)
|
if (fPrintSettings)
|
||||||
printJob.SetSettings(new BMessage(*fPrintSettings));
|
printJob.SetSettings(new BMessage(*fPrintSettings));
|
||||||
|
|
||||||
@@ -1178,7 +1163,7 @@ ShowImageWindow::_Print(BMessage* msg)
|
|||||||
if (lastPage < firstPage)
|
if (lastPage < firstPage)
|
||||||
lastPage = firstPage;
|
lastPage = firstPage;
|
||||||
|
|
||||||
BBitmap* bitmap = fImageView->GetBitmap();
|
BBitmap* bitmap = fImageView->Bitmap();
|
||||||
float imageWidth = bitmap->Bounds().Width() + 1.0;
|
float imageWidth = bitmap->Bounds().Width() + 1.0;
|
||||||
float imageHeight = bitmap->Bounds().Height() + 1.0;
|
float imageHeight = bitmap->Bounds().Height() + 1.0;
|
||||||
|
|
||||||
@@ -1186,7 +1171,8 @@ ShowImageWindow::_Print(BMessage* msg)
|
|||||||
switch (fPrintOptions.Option()) {
|
switch (fPrintOptions.Option()) {
|
||||||
case PrintOptions::kFitToPage: {
|
case PrintOptions::kFitToPage: {
|
||||||
float w1 = printableRect.Width()+1;
|
float w1 = printableRect.Width()+1;
|
||||||
float w2 = imageWidth * (printableRect.Height() + 1) / imageHeight;
|
float w2 = imageWidth * (printableRect.Height() + 1)
|
||||||
|
/ imageHeight;
|
||||||
if (w2 < w1)
|
if (w2 < w1)
|
||||||
width = w2;
|
width = w2;
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -11,11 +11,11 @@
|
|||||||
#define SHOW_IMAGE_WINDOW_H
|
#define SHOW_IMAGE_WINDOW_H
|
||||||
|
|
||||||
|
|
||||||
#include "PrintOptionsWindow.h"
|
|
||||||
|
|
||||||
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
|
#include "ImageFileNavigator.h"
|
||||||
|
#include "PrintOptionsWindow.h"
|
||||||
|
|
||||||
|
|
||||||
class BFilePanel;
|
class BFilePanel;
|
||||||
class BMenu;
|
class BMenu;
|
||||||
@@ -35,7 +35,6 @@ public:
|
|||||||
virtual void MessageReceived(BMessage* message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
virtual bool QuitRequested();
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
status_t InitCheck();
|
|
||||||
ShowImageView* GetShowImageView() const { return fImageView; }
|
ShowImageView* GetShowImageView() const { return fImageView; }
|
||||||
|
|
||||||
void UpdateTitle();
|
void UpdateTitle();
|
||||||
@@ -62,6 +61,8 @@ private:
|
|||||||
void _MarkSlideShowDelay(float value);
|
void _MarkSlideShowDelay(float value);
|
||||||
void _ResizeToWindow(bool shrink, uint32 what);
|
void _ResizeToWindow(bool shrink, uint32 what);
|
||||||
|
|
||||||
|
void _UpdateStatusText(const BMessage* message);
|
||||||
|
void _LoadError(const entry_ref& ref);
|
||||||
void _SaveAs(BMessage* message);
|
void _SaveAs(BMessage* message);
|
||||||
// Handle Save As submenu choice
|
// Handle Save As submenu choice
|
||||||
void _SaveToFile(BMessage* message);
|
void _SaveToFile(BMessage* message);
|
||||||
@@ -79,24 +80,24 @@ private:
|
|||||||
void _CloseResizerWindow();
|
void _CloseResizerWindow();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
ImageFileNavigator fNavigator;
|
||||||
BFilePanel* fSavePanel;
|
BFilePanel* fSavePanel;
|
||||||
BMenuBar* fBar;
|
BMenuBar* fBar;
|
||||||
BMenu* fOpenMenu
|
BMenu* fOpenMenu;
|
||||||
; BMenu* fBrowseMenu;
|
BMenu* fBrowseMenu;
|
||||||
BMenu* fGoToPageMenu;
|
BMenu* fGoToPageMenu;
|
||||||
BMenu* fSlideShowDelay;
|
BMenu* fSlideShowDelay;
|
||||||
ShowImageView* fImageView;
|
ShowImageView* fImageView;
|
||||||
ShowImageStatusView* fStatusView;
|
ShowImageStatusView* fStatusView;
|
||||||
bool fModified;
|
bool fModified;
|
||||||
bool fFullScreen;
|
bool fFullScreen;
|
||||||
BRect fWindowFrame;
|
|
||||||
bool fShowCaption;
|
bool fShowCaption;
|
||||||
|
BRect fWindowFrame;
|
||||||
BMessage* fPrintSettings;
|
BMessage* fPrintSettings;
|
||||||
PrintOptions fPrintOptions;
|
PrintOptions fPrintOptions;
|
||||||
BMessenger* fResizerWindowMessenger;
|
BMessenger* fResizerWindowMessenger;
|
||||||
BMenuItem* fResizeItem;
|
BMenuItem* fResizeItem;
|
||||||
int32 fHeight;
|
BString fImageType;
|
||||||
int32 fWidth;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user