* Renamed BGView to BackgroundsView, etc.

* Moved ImageFilePanel code to its own file, so that it can be reused easily.
* Moved BGWindow stuff into Backgrounds.cpp.
* Cleanup to match our style guide better.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15712 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-12-29 13:37:52 +00:00
parent a4513d1c7c
commit cd2d1ffdda
12 changed files with 905 additions and 872 deletions
-40
View File
@@ -1,40 +0,0 @@
/*
"Backgrounds" by Jerome Duval ([email protected])
(C)2002 OpenBeOS under MIT license
*/
#include "BGMain.h"
#include <TrackerAddOn.h>
BGApplication::BGApplication()
:BApplication(APP_SIGNATURE)
{
fBGWin=new BGWindow(BRect(100,100,570,325));
fBGWin->Show();
}
int main(int, char**)
{
BGApplication myApplication;
// This function doesn't return until the application quits
myApplication.Run();
return(0);
}
void process_refs(entry_ref dir_ref, BMessage *msg, void* reserved)
{
BGWindow *fBGWin=new BGWindow(BRect(100,100,570,325), false);
fBGWin->ProcessRefs(dir_ref, msg);
snooze(500);
fBGWin->Show();
status_t exit_value;
wait_for_thread(fBGWin->Thread(), &exit_value);
}
-23
View File
@@ -1,23 +0,0 @@
/*
"Backgrounds" by Jerome Duval ([email protected])
(C)2002 OpenBeOS under MIT license
*/
#ifndef BG_WORLD_H
#define BG_WORLD_H
#include <Application.h>
#include "BGWindow.h"
#define APP_SIGNATURE "application/x-vnd.haiku.Backgrounds"
class BGApplication : public BApplication {
public:
BGApplication();
BGWindow *fBGWin;
};
#endif
-42
View File
@@ -1,42 +0,0 @@
/*
"Backgrounds" by Jerome Duval ([email protected])
(C)2002 OpenBeOS under MIT license
*/
#include "BGWindow.h"
BGWindow::BGWindow(BRect frame, bool standalone)
: BWindow(frame, WINDOW_TITLE, B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
fIsStandalone(standalone)
{
fBGView = new BGView(Bounds(),"BackgroundsView",B_FOLLOW_ALL, B_WILL_DRAW);
AddChild(fBGView);
}
bool
BGWindow::QuitRequested()
{
fBGView->SaveSettings();
if(fIsStandalone)
be_app->PostMessage(B_QUIT_REQUESTED);
return(true);
}
void
BGWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
{
fBGView->WorkspaceActivated(oldWorkspaces, active);
}
void
BGWindow::ProcessRefs(entry_ref dir_ref, BMessage* msg)
{
fBGView->ProcessRefs(dir_ref, msg);
}
-31
View File
@@ -1,31 +0,0 @@
/*
"Backgrounds" by Jerome Duval ([email protected])
(C)2002 OpenBeOS under MIT license
*/
#ifndef BG_WINDOW_H
#define BG_WINDOW_H
#include <Application.h>
#include <Window.h>
#include "BGView.h"
#define WINDOW_TITLE "Backgrounds"
class BGWindow : public BWindow
{
public:
BGWindow(BRect frame, bool standalone = true);
BGView *GetView() {return fBGView;}
void ProcessRefs(entry_ref dir_ref, BMessage* msg);
protected:
virtual bool QuitRequested();
virtual void WorkspaceActivated(int32 oldWorkspaces, bool active);
BGView *fBGView;
bool fIsStandalone;
};
#endif
+37 -26
View File
@@ -49,8 +49,8 @@ All rights reserved.
#include <fs_attr.h> #include <fs_attr.h>
#include <stdlib.h> #include <stdlib.h>
#include "BGView.h"
#include "BackgroundImage.h" #include "BackgroundImage.h"
#include "BackgroundsView.h"
const char *kBackgroundImageInfo = "be:bgndimginfo"; const char *kBackgroundImageInfo = "be:bgndimginfo";
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset"; const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset";
@@ -66,10 +66,9 @@ const char *kBackgroundImageCacheMode = "be:bgndimgcachemode";
BackgroundImage * BackgroundImage *
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop, BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
BGView* view) BackgroundsView* view)
{ {
BackgroundImage *result = new BackgroundImage(node, isDesktop); BackgroundImage *result = new BackgroundImage(node, isDesktop, view);
result->bgView = view;
attr_info info; attr_info info;
if (node->GetAttrInfo(kBackgroundImageInfo, &info) != B_OK) if (node->GetAttrInfo(kBackgroundImageInfo, &info) != B_OK)
return result; return result;
@@ -122,8 +121,8 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
container.FindBool(kBackgroundImageInfoEraseText, index, container.FindBool(kBackgroundImageInfoEraseText, index,
&eraseTextWidgetBackground); &eraseTextWidgetBackground);
container.FindPoint(kBackgroundImageInfoOffset, index, &offset); container.FindPoint(kBackgroundImageInfoOffset, index, &offset);
if(isDesktop)
{ if (isDesktop) {
container.FindInt32(kBackgroundImageInfoSet, index, container.FindInt32(kBackgroundImageInfoSet, index,
(int32 *)&imageSet); (int32 *)&imageSet);
container.FindInt32(kBackgroundImageInfoCacheMode, index, container.FindInt32(kBackgroundImageInfoCacheMode, index,
@@ -139,8 +138,6 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
if (imageSet > maxImageSet) if (imageSet > maxImageSet)
maxImageSet = imageSet; maxImageSet = imageSet;
result->Add(imageInfo); result->Add(imageInfo);
} }
@@ -160,7 +157,8 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
BackgroundImage::BackgroundImageInfo::BackgroundImageInfo(uint32 workspaces, BackgroundImage::BackgroundImageInfo::BackgroundImageInfo(uint32 workspaces,
int32 imageIndex, Mode mode, BPoint offset, bool eraseTextWidget, int32 imageIndex, Mode mode, BPoint offset, bool eraseTextWidget,
uint32 imageSet, uint32 cacheMode) uint32 imageSet, uint32 cacheMode)
: fWorkspace(workspaces), :
fWorkspace(workspaces),
fImageIndex(imageIndex), fImageIndex(imageIndex),
fMode(mode), fMode(mode),
fOffset(offset), fOffset(offset),
@@ -176,10 +174,15 @@ BackgroundImage::BackgroundImageInfo::~BackgroundImageInfo()
} }
BackgroundImage::BackgroundImage(const BNode *node, bool desktop) // #pragma mark -
: fIsDesktop(desktop),
BackgroundImage::BackgroundImage(const BNode *node, bool desktop, BackgroundsView* view)
:
fIsDesktop(desktop),
fDefinedByNode(*node), fDefinedByNode(*node),
fView(NULL), fView(NULL),
fBackgroundsView(view),
fShowingBitmap(NULL), fShowingBitmap(NULL),
fBitmapForWorkspaceList(1, true), fBitmapForWorkspaceList(1, true),
fImageSetPeriod(0), fImageSetPeriod(0),
@@ -188,7 +191,6 @@ BackgroundImage::BackgroundImage(const BNode *node, bool desktop)
fCacheMode(0), fCacheMode(0),
fRandomChange(false) fRandomChange(false)
{ {
} }
@@ -228,7 +230,6 @@ BackgroundImage::Show(BView *view, int32 workspace)
if (poseView) if (poseView)
poseView->SetEraseWidgetTextBackground(info->fEraseTextWidgetBackground);*/ poseView->SetEraseWidgetTextBackground(info->fEraseTextWidgetBackground);*/
Show(info, fView); Show(info, fView);
} }
} }
@@ -236,7 +237,7 @@ BackgroundImage::Show(BView *view, int32 workspace)
void void
BackgroundImage::Show(BackgroundImageInfo *info, BView *view) BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
{ {
BBitmap *bitmap = bgView->GetImage(info->fImageIndex)->GetBitmap(); BBitmap *bitmap = fBackgroundsView->GetImage(info->fImageIndex)->GetBitmap();
if (!bitmap) if (!bitmap)
return; return;
@@ -338,6 +339,7 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index); BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
if (info->fImageSet != fShowingImageSet) if (info->fImageSet != fShowingImageSet)
continue; continue;
if (fIsDesktop) { if (fIsDesktop) {
if (info->fWorkspace == workspaceMask) if (info->fWorkspace == workspaceMask)
return info; return info;
@@ -354,13 +356,15 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
void void
BackgroundImage::WorkspaceActivated(BView *view, int32 workspace, bool state) BackgroundImage::WorkspaceActivated(BView *view, int32 workspace, bool state)
{ {
if (!fIsDesktop) if (!fIsDesktop) {
// we only care for desktop bitmaps // we only care for desktop bitmaps
return; return;
}
if (!state) if (!state) {
// we only care comming into a new workspace, not leaving one // we only care comming into a new workspace, not leaving one
return; return;
}
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace); BackgroundImageInfo *info = ImageInfoForWorkspace(workspace);
if (info != fShowingBitmap) { if (info != fShowingBitmap) {
@@ -407,27 +411,32 @@ BackgroundImage::SetBackgroundImage(BNode *node)
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index); BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
if(bgView->GetImage(info->fImageIndex)==NULL) if (fBackgroundsView->GetImage(info->fImageIndex) == NULL)
continue; continue;
container.AddBool(kBackgroundImageInfoEraseText, info->fEraseTextWidgetBackground); container.AddBool(kBackgroundImageInfoEraseText,
container.AddString( kBackgroundImageInfoPath, bgView->GetImage(info->fImageIndex)->GetPath().Path()); info->fEraseTextWidgetBackground);
container.AddString(kBackgroundImageInfoPath,
fBackgroundsView->GetImage(info->fImageIndex)->GetPath().Path());
container.AddInt32(kBackgroundImageInfoWorkspaces, info->fWorkspace); container.AddInt32(kBackgroundImageInfoWorkspaces, info->fWorkspace);
container.AddPoint(kBackgroundImageInfoOffset, info->fOffset); container.AddPoint(kBackgroundImageInfoOffset, info->fOffset);
container.AddInt32(kBackgroundImageInfoMode, info->fMode); container.AddInt32(kBackgroundImageInfoMode, info->fMode);
if(fIsDesktop) {
if (fIsDesktop)
container.AddInt32(kBackgroundImageInfoSet, info->fImageSet); container.AddInt32(kBackgroundImageInfoSet, info->fImageSet);
} }
}
PRINT_OBJECT(container); PRINT_OBJECT(container);
char buffer[container.FlattenedSize()]; char buffer[container.FlattenedSize()];
if ((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK) if ((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK)
return err; return err;
ssize_t size = node->WriteAttr(kBackgroundImageInfo, 0, 0, buffer, container.FlattenedSize());
ssize_t size = node->WriteAttr(kBackgroundImageInfo, 0, 0, buffer,
container.FlattenedSize());
if (size <= 0) if (size <= 0)
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
} }
@@ -468,8 +477,12 @@ BackgroundImage::ChangeImageSet(BPoseView *poseView)
}*/ }*/
// #pragma mark -
Image::Image(BPath path) Image::Image(BPath path)
: fBitmap(NULL), :
fBitmap(NULL),
fPath(path) fPath(path)
{ {
name = path.Leaf(); name = path.Leaf();
@@ -478,10 +491,7 @@ Image::Image(BPath path)
Image::~Image() Image::~Image()
{ {
if(fBitmap!=NULL) {
delete fBitmap; delete fBitmap;
fBitmap = NULL;
}
} }
@@ -490,5 +500,6 @@ Image::GetBitmap()
{ {
if (!fBitmap) if (!fBitmap)
fBitmap = BTranslationUtils::GetBitmap(fPath.Path()); fBitmap = BTranslationUtils::GetBitmap(fPath.Path());
return fBitmap; return fBitmap;
} }
@@ -40,6 +40,8 @@ All rights reserved.
#include "String.h" #include "String.h"
#include "ObjectList.h" #include "ObjectList.h"
#include <GraphicsDefs.h>
#include <Node.h> #include <Node.h>
#include <Path.h> #include <Path.h>
@@ -49,7 +51,7 @@ class BBitmap;
class BackgroundImage; class BackgroundImage;
class Image; class Image;
class BGView; class BackgroundsView;
extern const char *kBackgroundImageInfo; extern const char *kBackgroundImageInfo;
extern const char *kBackgroundImageInfoOffset; extern const char *kBackgroundImageInfoOffset;
@@ -97,11 +99,10 @@ public:
uint32 fCacheMode; // image cache strategy (0 cache , 1 no cache) uint32 fCacheMode; // image cache strategy (0 cache , 1 no cache)
}; };
static BackgroundImage *GetBackgroundImage(const BNode *node,
bool isDesktop, BackgroundsView* view);
static BackgroundImage *GetBackgroundImage(const BNode *, bool isDesktop,
BGView* view);
// create a BackgroundImage object by reading it from a node // create a BackgroundImage object by reading it from a node
virtual ~BackgroundImage(); virtual ~BackgroundImage();
void Show(BView *view, int32 workspace); void Show(BView *view, int32 workspace);
@@ -111,7 +112,7 @@ public:
void WorkspaceActivated(BView *view, int32 workspace, bool state); void WorkspaceActivated(BView *view, int32 workspace, bool state);
// respond to a workspace change // respond to a workspace change
void ScreenChanged(BRect , color_space); void ScreenChanged(BRect rect, color_space space);
// respond to a screen size change // respond to a screen size change
/*static BackgroundImage *Refresh(BackgroundImage *oldBackgroundImage, /*static BackgroundImage *Refresh(BackgroundImage *oldBackgroundImage,
const BNode *fromNode, bool desktop, BPoseView *poseView); const BNode *fromNode, bool desktop, BPoseView *poseView);
@@ -133,14 +134,14 @@ public:
void RemoveAll(); void RemoveAll();
private: private:
BackgroundImage(const BNode *, bool); BackgroundImage(const BNode *node, bool isDesktop, BackgroundsView* view);
// no public constructor, GetBackgroundImage factory function is // no public constructor, GetBackgroundImage factory function is
// used instead // used instead
bool fIsDesktop; bool fIsDesktop;
BNode fDefinedByNode; BNode fDefinedByNode;
BView *fView; BView *fView;
BGView* bgView; BackgroundsView* fBackgroundsView;
BackgroundImageInfo *fShowingBitmap; BackgroundImageInfo *fShowingBitmap;
BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList; BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
+122
View File
@@ -0,0 +1,122 @@
/*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jerome Duval ([email protected])
* Axel Dörfler, [email protected]
*/
#include "BackgroundsView.h"
#include <Application.h>
#include <TrackerAddOn.h>
#include <Window.h>
static const char *kSignature = "application/x-vnd.haiku.Backgrounds";
class BackgroundsApplication : public BApplication {
public:
BackgroundsApplication();
};
class BackgroundsWindow : public BWindow {
public:
BackgroundsWindow(BRect frame, bool standalone = true);
void ProcessRefs(entry_ref dir, BMessage* refs);
protected:
virtual bool QuitRequested();
virtual void WorkspaceActivated(int32 oldWorkspaces, bool active);
BackgroundsView *fBackgroundsView;
bool fIsStandalone;
};
// #pragma mark -
BackgroundsApplication::BackgroundsApplication()
: BApplication(kSignature)
{
BWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325));
window->Show();
}
// #pragma mark -
BackgroundsWindow::BackgroundsWindow(BRect frame, bool standalone)
: BWindow(frame, "Backgrounds", B_TITLED_WINDOW,
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
fIsStandalone(standalone)
{
fBackgroundsView = new BackgroundsView(Bounds(), "BackgroundsView",
B_FOLLOW_ALL, B_WILL_DRAW);
AddChild(fBackgroundsView);
}
bool
BackgroundsWindow::QuitRequested()
{
fBackgroundsView->SaveSettings();
if (fIsStandalone)
be_app->PostMessage(B_QUIT_REQUESTED);
return true;
}
void
BackgroundsWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
{
fBackgroundsView->WorkspaceActivated(oldWorkspaces, active);
}
void
BackgroundsWindow::ProcessRefs(entry_ref dir, BMessage* refs)
{
fBackgroundsView->ProcessRefs(dir, refs);
}
// #pragma mark -
/*!
\brief Tracker add-on entry
*/
void
process_refs(entry_ref dir, BMessage* refs, void* /*reserved*/)
{
BackgroundsWindow* window = new BackgroundsWindow(BRect(100, 100, 570, 325), false);
window->ProcessRefs(dir, refs);
snooze(500);
window->Show();
status_t status;
wait_for_thread(window->Thread(), &status);
}
int
main(int argc, char** argv)
{
BApplication* app = new BackgroundsApplication;
// This function doesn't return until the application quits
app->Run();
delete app;
return 0;
}
@@ -1,13 +1,15 @@
/* /*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved.
"Backgrounds" by Jerome Duval (jerome.duval@free.fr) * Distributed under the terms of the MIT License.
*
(C)2002 OpenBeOS under MIT license * Authors:
* Jerome Duval (jerome.duval@free.fr)
*/ */
#ifndef BACKGROUNDS_VIEW_H
#define BACKGROUNDS_VIEW_H
#ifndef BG_VIEW_H_
#define BG_VIEW_H_ #include "BackgroundImage.h"
#include <View.h> #include <View.h>
#include <ColorControl.h> #include <ColorControl.h>
@@ -30,7 +32,6 @@
#include <FilePanel.h> #include <FilePanel.h>
#include <StringView.h> #include <StringView.h>
#include <Cursor.h> #include <Cursor.h>
#include "BackgroundImage.h"
#define SETTINGS_FILE "Backgrounds_settings" #define SETTINGS_FILE "Backgrounds_settings"
@@ -38,43 +39,21 @@ class BGImageMenuItem : public BMenuItem {
public: public:
BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message, BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message,
char shortcut = 0, uint32 modifiers = 0); char shortcut = 0, uint32 modifiers = 0);
int32 ImageIndex() { return fImageIndex; } int32 ImageIndex() { return fImageIndex; }
private: private:
int32 fImageIndex; int32 fImageIndex;
}; };
class CustomRefFilter : public BRefFilter {
public:
CustomRefFilter(bool imageFiltering);
bool Filter(const entry_ref *ref, BNode* node, struct stat *st,
const char *filetype);
protected:
bool fImageFiltering; // true for images only, false for directory only
};
class ImageFilePanel : public BFilePanel {
public:
ImageFilePanel(file_panel_mode mode = B_OPEN_PANEL,
BMessenger *target = 0, const entry_ref *start_directory = 0,
uint32 node_flavors = 0, bool allow_multiple_selection = true,
BMessage *message = 0, BRefFilter * = 0,
bool modal = false, bool hide_when_done = true);
virtual void SelectionChanged(void);
void Show(void);
protected:
BView *imageView;
BStringView *resolutionView, *imageTypeView;
};
class PreviewBox : public BBox { class PreviewBox : public BBox {
public: public:
PreviewBox(BRect frame, const char *name); PreviewBox(BRect frame, const char *name);
void Draw(BRect rect); void Draw(BRect rect);
void SetDesktop(bool isDesktop); void SetDesktop(bool isDesktop);
protected: protected:
bool fIsDesktop; bool fIsDesktop;
}; };
@@ -83,6 +62,7 @@ class PreviewBox : public BBox {
class PreView : public BControl { class PreView : public BControl {
public: public:
PreView(BRect frame, const char *name, int32 resize, int32 flags); PreView(BRect frame, const char *name, int32 resize, int32 flags);
BPoint fPoint; BPoint fPoint;
BRect fImageBounds; BRect fImageBounds;
@@ -100,30 +80,30 @@ class PreView : public BControl {
}; };
class BGView : public BBox { class BackgroundsView : public BBox {
public: public:
BGView(BRect frame, const char *name, int32 resize, int32 flags); BackgroundsView(BRect frame, const char *name, int32 resize, int32 flags);
~BGView(void); ~BackgroundsView(void);
void SaveSettings(void); void SaveSettings();
void WorkspaceActivated(uint32 oldWorkspaces, bool active); void WorkspaceActivated(uint32 oldWorkspaces, bool active);
int32 AddImage(BPath path); int32 AddImage(BPath path);
Image* GetImage(int32 imageIndex); Image* GetImage(int32 imageIndex);
void ProcessRefs(entry_ref dir_ref, BMessage* msg); void ProcessRefs(entry_ref dir_ref, BMessage* msg);
protected: protected:
void Save(void); void Save();
void NotifyServer(void); void NotifyServer();
void LoadSettings(void); void LoadSettings();
void AllAttached(void); void AllAttached();
void MessageReceived(BMessage *msg); void MessageReceived(BMessage *msg);
void LoadDesktopFolder(void); void LoadDesktopFolder();
void LoadDefaultFolder(void); void LoadDefaultFolder();
void LoadFolder(bool isDesktop); void LoadFolder(bool isDesktop);
void LoadRecentFolder(BPath path); void LoadRecentFolder(BPath path);
void UpdateWithCurrent(void); void UpdateWithCurrent();
void UpdatePreview(void); void UpdatePreview();
void UpdateButtons(void); void UpdateButtons();
void RefsReceived(BMessage *msg); void RefsReceived(BMessage *msg);
int32 AddPath(BPath path); int32 AddPath(BPath path);
@@ -142,11 +122,11 @@ class BGView : public BBox {
PreView *fPreView; // the view for previewing the result PreView *fPreView; // the view for previewing the result
PreviewBox *fPreview; // the box which draws a computer/folder PreviewBox *fPreview; // the box which draws a computer/folder
BFilePanel *fFolderPanel; // the file panels for folders BFilePanel *fFolderPanel; // the file panels for folders
ImageFilePanel *fPanel; // the file panels for images BFilePanel *fPanel; // the file panels for images
BackgroundImage *fCurrent; // the current BackgroundImage object BackgroundImage *fCurrent; // the current BackgroundImage object
BackgroundImage::BackgroundImageInfo *fCurrentInfo;//the current BackgroundImageInfo object BackgroundImage::BackgroundImageInfo *fCurrentInfo;//the current BackgroundImageInfo object
entry_ref fCurrent_ref; // the entry for the node which holds current entry_ref fCurrentRef; // the entry for the node which holds current
int32 fLastImageIndex, fLastWorkspaceIndex; // last indexes for cancel int32 fLastImageIndex, fLastWorkspaceIndex; // last indexes for cancel
BMessage fSettings; // settings loaded from settings directory BMessage fSettings; // settings loaded from settings directory
@@ -154,4 +134,4 @@ class BGView : public BBox {
BObjectList<Image> fImageList; BObjectList<Image> fImageList;
}; };
#endif #endif // BACKGROUNDS_VIEW_H
@@ -0,0 +1,166 @@
/*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jerome Duval ([email protected])
*/
#include "ImageFilePanel.h"
#include <Bitmap.h>
#include <NodeInfo.h>
#include <String.h>
#include <StringView.h>
#include <TranslationUtils.h>
#include <Window.h>
ImageFilePanel::ImageFilePanel(file_panel_mode mode, BMessenger *target,
const entry_ref *startDirectory, uint32 nodeFlavors,
bool allowMultipleSelection, BMessage* message, BRefFilter* filter,
bool modal, bool hideWhenDone)
: BFilePanel(mode, target, startDirectory, nodeFlavors,
allowMultipleSelection, message, filter, modal, hideWhenDone),
fImageView(NULL),
fResolutionView(NULL),
fImageTypeView(NULL)
{
}
void
ImageFilePanel::Show()
{
if (fImageView == NULL) {
Window()->Lock();
BView *background = Window()->ChildAt(0);
uint32 poseViewResizingMode =
background->FindView("PoseView")->ResizingMode();
uint32 countVwResizingMode =
background->FindView("CountVw")->ResizingMode();
uint32 vScrollBarResizingMode =
background->FindView("VScrollBar")->ResizingMode();
uint32 hScrollBarResizingMode =
background->FindView("HScrollBar")->ResizingMode();
background->FindView("PoseView")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP);
background->FindView("CountVw")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP);
background->FindView("VScrollBar")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP);
background->FindView("HScrollBar")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP);
Window()->ResizeBy(0, 70);
background->FindView("PoseView")->SetResizingMode(poseViewResizingMode);
background->FindView("CountVw")->SetResizingMode(countVwResizingMode);
background->FindView("VScrollBar")->SetResizingMode(vScrollBarResizingMode);
background->FindView("HScrollBar")->SetResizingMode(hScrollBarResizingMode);
BRect rect(background->Bounds().left + 15, background->Bounds().bottom - 94,
background->Bounds().left + 122, background->Bounds().bottom - 15);
fImageView = new BView(rect, "ImageView", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM,
B_SUBPIXEL_PRECISE);
fImageView->SetViewColor(background->ViewColor());
background->AddChild(fImageView);
rect = BRect(background->Bounds().left + 132, background->Bounds().bottom - 85,
background->Bounds().left + 250, background->Bounds().bottom - 65);
fResolutionView = new BStringView(rect, "ResolutionView", NULL,
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
background->AddChild(fResolutionView);
rect.OffsetBy(0, -16);
fImageTypeView = new BStringView(rect, "ImageTypeView", NULL,
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
background->AddChild(fImageTypeView);
Window()->Unlock();
}
BFilePanel::Show();
}
void
ImageFilePanel::SelectionChanged()
{
entry_ref ref;
Rewind();
if (GetNextSelectedRef(&ref) == B_OK) {
BEntry entry(&ref);
BNode node(&ref);
fImageView->ClearViewBitmap();
if (node.IsFile()) {
BBitmap *bitmap = BTranslationUtils::GetBitmap(&ref);
if (bitmap != NULL) {
BRect dest(fImageView->Bounds());
if (bitmap->Bounds().Width()>bitmap->Bounds().Height()) {
dest.InsetBy(0, (dest.Height()+1 -
((bitmap->Bounds().Height()+1) /
(bitmap->Bounds().Width()+1) * (dest.Width()+1)))/2);
} else {
dest.InsetBy((dest.Width()+1 -
((bitmap->Bounds().Width()+1) /
(bitmap->Bounds().Height()+1) * (dest.Height()+1)))/2, 0);
}
fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest,
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0);
BString resolution;
resolution << "Resolution: " << (int)(bitmap->Bounds().Width() + 1)
<< "x" << (int)(bitmap->Bounds().Height() + 1);
fResolutionView->SetText(resolution.String());
delete bitmap;
BNode node(&ref);
BNodeInfo nodeInfo(&node);
char fileType[256];
if (nodeInfo.GetType(fileType) == B_OK) {
// TODO: this is broken!
if (strncmp(fileType, "image/jpeg", 10) == 0)
fImageTypeView->SetText("JPEG Image");
else
fImageTypeView->SetText("");
}
}
} else {
fResolutionView->SetText("");
fImageTypeView->SetText("");
}
fImageView->Invalidate();
fResolutionView->Invalidate();
}
BFilePanel::SelectionChanged();
}
// #pragma mark -
CustomRefFilter::CustomRefFilter(bool imageFiltering)
:
fImageFiltering(imageFiltering)
{
}
bool
CustomRefFilter::Filter(const entry_ref *ref, BNode* node,
struct stat *stat, const char *filetype)
{
if (!fImageFiltering)
return node->IsDirectory();
if (node->IsDirectory())
return true;
BMimeType imageType("image"), refType(filetype);
if (imageType.Contains(&refType))
return true;
return false;
}
@@ -0,0 +1,48 @@
/*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jerome Duval ([email protected])
*/
#ifndef IMAGE_FILE_PANEL_H
#define IMAGE_FILE_PANEL_H
#include <Node.h>
#include <FilePanel.h>
class BStringView;
class BView;
class CustomRefFilter : public BRefFilter {
public:
CustomRefFilter(bool imageFiltering);
bool Filter(const entry_ref *ref, BNode* node, struct stat *st,
const char *filetype);
protected:
bool fImageFiltering; // true for images only, false for directory only
};
class ImageFilePanel : public BFilePanel {
public:
ImageFilePanel(file_panel_mode mode = B_OPEN_PANEL,
BMessenger* target = NULL, const entry_ref* startDirectory = NULL,
uint32 nodeFlavors = 0, bool allowMultipleSelection = true,
BMessage* message = NULL, BRefFilter* filter = NULL,
bool modal = false, bool hideWhenDone = true);
virtual void SelectionChanged();
virtual void Show();
protected:
BView* fImageView;
BStringView* fResolutionView;
BStringView* fImageTypeView;
};
#endif // IMAGE_FILE_PANEL_H
+3 -3
View File
@@ -7,9 +7,9 @@ UsePrivateHeaders shared ;
Preference Backgrounds : Preference Backgrounds :
BackgroundImage.cpp BackgroundImage.cpp
BGMain.cpp Backgrounds.cpp
BGView.cpp BackgroundsView.cpp
BGWindow.cpp ImageFilePanel.cpp
: be tracker translation : be tracker translation
: Backgrounds.rdef : Backgrounds.rdef
; ;