* 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
+97 -86
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,14 +66,13 @@ 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;
BMessage container; BMessage container;
char *buffer = new char [info.size]; char *buffer = new char [info.size];
@@ -81,9 +80,9 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
(size_t)info.size); (size_t)info.size);
if (error == info.size) if (error == info.size)
error = container.Unflatten(buffer); error = container.Unflatten(buffer);
delete [] buffer; delete [] buffer;
if (error != B_OK) if (error != B_OK)
return NULL; return NULL;
@@ -93,13 +92,13 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
uint32 globalCacheMode = 0; uint32 globalCacheMode = 0;
bool randomChange = false; bool randomChange = false;
uint32 maxImageSet = 0; uint32 maxImageSet = 0;
if(isDesktop) { if (isDesktop) {
container.FindInt32(kBackgroundImageSetPeriod, (int32 *)&imageSetPeriod); container.FindInt32(kBackgroundImageSetPeriod, (int32 *)&imageSetPeriod);
container.FindInt32(kBackgroundImageCacheMode, (int32 *)&globalCacheMode); container.FindInt32(kBackgroundImageCacheMode, (int32 *)&globalCacheMode);
container.FindBool(kBackgroundImageRandomChange, &randomChange); container.FindBool(kBackgroundImageRandomChange, &randomChange);
} }
for (int32 index = 0; ; index++) { for (int32 index = 0; ; index++) {
const char *path; const char *path;
uint32 workspaces = B_ALL_WORKSPACES; uint32 workspaces = B_ALL_WORKSPACES;
@@ -110,49 +109,47 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
uint32 cacheMode = 0; uint32 cacheMode = 0;
if (container.FindString(kBackgroundImageInfoPath, index, &path) != B_OK) if (container.FindString(kBackgroundImageInfoPath, index, &path) != B_OK)
break; break;
BPath bpath(path); BPath bpath(path);
int32 imageIndex = view->AddImage(bpath); int32 imageIndex = view->AddImage(bpath);
if(imageIndex < 0) if (imageIndex < 0)
imageIndex = -imageIndex - 1; imageIndex = -imageIndex - 1;
container.FindInt32(kBackgroundImageInfoWorkspaces, index, container.FindInt32(kBackgroundImageInfoWorkspaces, index,
(int32 *)&workspaces); (int32 *)&workspaces);
container.FindInt32(kBackgroundImageInfoMode, index, (int32 *)&mode); container.FindInt32(kBackgroundImageInfoMode, index, (int32 *)&mode);
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,
(int32 *)&cacheMode); (int32 *)&cacheMode);
} }
BackgroundImage::BackgroundImageInfo *imageInfo = new BackgroundImage::BackgroundImageInfo *imageInfo = new
BackgroundImage::BackgroundImageInfo(workspaces, imageIndex, BackgroundImage::BackgroundImageInfo(workspaces, imageIndex,
mode, offset, eraseTextWidgetBackground, imageSet, cacheMode); mode, offset, eraseTextWidgetBackground, imageSet, cacheMode);
//imageInfo->UnloadBitmap(globalCacheMode);
if(imageSet > maxImageSet)
maxImageSet = imageSet;
//imageInfo->UnloadBitmap(globalCacheMode);
if (imageSet > maxImageSet)
maxImageSet = imageSet;
result->Add(imageInfo); result->Add(imageInfo);
} }
if(result) { if (result) {
result->fImageSetCount = maxImageSet + 1; result->fImageSetCount = maxImageSet + 1;
result->fRandomChange = randomChange; result->fRandomChange = randomChange;
result->fImageSetPeriod = imageSetPeriod; result->fImageSetPeriod = imageSetPeriod;
result->fCacheMode = globalCacheMode; result->fCacheMode = globalCacheMode;
if(result->fImageSetCount > 1) if (result->fImageSetCount > 1)
result->fShowingImageSet = random()%result->fImageSetCount; result->fShowingImageSet = random()%result->fImageSetCount;
} }
return result; return result;
} }
@@ -160,13 +157,14 @@ 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), :
fImageIndex(imageIndex), fWorkspace(workspaces),
fMode(mode), fImageIndex(imageIndex),
fOffset(offset), fMode(mode),
fEraseTextWidgetBackground(eraseTextWidget), fOffset(offset),
fImageSet(imageSet), fEraseTextWidgetBackground(eraseTextWidget),
fCacheMode(cacheMode) fImageSet(imageSet),
fCacheMode(cacheMode)
{ {
} }
@@ -176,19 +174,23 @@ BackgroundImage::BackgroundImageInfo::~BackgroundImageInfo()
} }
BackgroundImage::BackgroundImage(const BNode *node, bool desktop) // #pragma mark -
: fIsDesktop(desktop),
fDefinedByNode(*node),
fView(NULL), BackgroundImage::BackgroundImage(const BNode *node, bool desktop, BackgroundsView* view)
fShowingBitmap(NULL), :
fBitmapForWorkspaceList(1, true), fIsDesktop(desktop),
fImageSetPeriod(0), fDefinedByNode(*node),
fShowingImageSet(0), fView(NULL),
fImageSetCount(0), fBackgroundsView(view),
fCacheMode(0), fShowingBitmap(NULL),
fRandomChange(false) fBitmapForWorkspaceList(1, true),
{ fImageSetPeriod(0),
fShowingImageSet(0),
fImageSetCount(0),
fCacheMode(0),
fRandomChange(false)
{
} }
@@ -209,7 +211,7 @@ BackgroundImage::RemoveAll()
{ {
for (int32 index = 0; index < fBitmapForWorkspaceList.CountItems();) { for (int32 index = 0; index < fBitmapForWorkspaceList.CountItems();) {
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index); BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
if(info->fImageSet != fShowingImageSet) if (info->fImageSet != fShowingImageSet)
index++; index++;
else else
fBitmapForWorkspaceList.RemoveItemAt(index); fBitmapForWorkspaceList.RemoveItemAt(index);
@@ -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,18 +237,18 @@ 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;
BRect viewBounds(view->Bounds()); BRect viewBounds(view->Bounds());
display_mode mode; display_mode mode;
BScreen().GetMode(&mode); BScreen().GetMode(&mode);
float x_ratio = viewBounds.Width() / mode.virtual_width; float x_ratio = viewBounds.Width() / mode.virtual_width;
float y_ratio = viewBounds.Height() / mode.virtual_height; float y_ratio = viewBounds.Height() / mode.virtual_height;
BRect bitmapBounds(bitmap->Bounds()); BRect bitmapBounds(bitmap->Bounds());
BRect destinationBitmapBounds(bitmapBounds); BRect destinationBitmapBounds(bitmapBounds);
destinationBitmapBounds.right *= x_ratio; destinationBitmapBounds.right *= x_ratio;
@@ -255,7 +256,7 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
BPoint offset(info->fOffset); BPoint offset(info->fOffset);
offset.x *= x_ratio; offset.x *= x_ratio;
offset.y *= y_ratio; offset.y *= y_ratio;
uint32 tile = 0; uint32 tile = 0;
uint32 followFlags = B_FOLLOW_TOP | B_FOLLOW_LEFT; uint32 followFlags = B_FOLLOW_TOP | B_FOLLOW_LEFT;
@@ -291,12 +292,12 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
tile = B_TILE_BITMAP; tile = B_TILE_BITMAP;
break; break;
} }
// switch to the bitmap and force a redraw // switch to the bitmap and force a redraw
view->SetViewBitmap(bitmap, bitmapBounds, destinationBitmapBounds, view->SetViewBitmap(bitmap, bitmapBounds, destinationBitmapBounds,
followFlags, tile); followFlags, tile);
view->Invalidate(); view->Invalidate();
/*if(fShowingBitmap != info) { /*if(fShowingBitmap != info) {
if(fShowingBitmap) if(fShowingBitmap)
fShowingBitmap->UnloadBitmap(fCacheMode); fShowingBitmap->UnloadBitmap(fCacheMode);
@@ -325,9 +326,9 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
{ {
uint32 workspaceMask = 1; uint32 workspaceMask = 1;
for ( ; workspace; workspace--) for (; workspace; workspace--)
workspaceMask *= 2; workspaceMask *= 2;
int32 count = fBitmapForWorkspaceList.CountItems(); int32 count = fBitmapForWorkspaceList.CountItems();
// do a simple lookup for the most likely candidate bitmap - // do a simple lookup for the most likely candidate bitmap -
@@ -336,9 +337,10 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
BackgroundImageInfo *result = NULL; BackgroundImageInfo *result = NULL;
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(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;
if (info->fWorkspace & workspaceMask) if (info->fWorkspace & workspaceMask)
@@ -354,14 +356,16 @@ 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) {
if (info) if (info)
@@ -382,7 +386,7 @@ BackgroundImage::ScreenChanged(BRect, color_space)
{ {
if (!fIsDesktop || !fShowingBitmap) if (!fIsDesktop || !fShowingBitmap)
return; return;
/*if (fShowingBitmap->fMode == kCentered) { /*if (fShowingBitmap->fMode == kCentered) {
BRect viewBounds(fView->Bounds()); BRect viewBounds(fView->Bounds());
BRect bitmapBounds(fShowingBitmap->fBitmap->Bounds()); BRect bitmapBounds(fShowingBitmap->fBitmap->Bounds());
@@ -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.AddInt32( kBackgroundImageInfoWorkspaces, info->fWorkspace); container.AddString(kBackgroundImageInfoPath,
container.AddPoint( kBackgroundImageInfoOffset, info->fOffset); fBackgroundsView->GetImage(info->fImageIndex)->GetPath().Path());
container.AddInt32( kBackgroundImageInfoMode, info->fMode); container.AddInt32(kBackgroundImageInfoWorkspaces, info->fWorkspace);
if(fIsDesktop) { container.AddPoint(kBackgroundImageInfoOffset, info->fOffset);
container.AddInt32( kBackgroundImageInfoSet, info->fImageSet); container.AddInt32(kBackgroundImageInfoMode, info->fMode);
}
if (fIsDesktop)
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());
if(size <= 0) ssize_t size = node->WriteAttr(kBackgroundImageInfo, 0, 0, buffer,
container.FlattenedSize());
if (size <= 0)
return B_ERROR; return B_ERROR;
return B_OK; return B_OK;
} }
@@ -468,9 +477,13 @@ BackgroundImage::ChangeImageSet(BPoseView *poseView)
}*/ }*/
// #pragma mark -
Image::Image(BPath path) Image::Image(BPath path)
: fBitmap(NULL), :
fPath(path) fBitmap(NULL),
fPath(path)
{ {
name = path.Leaf(); name = path.Leaf();
} }
@@ -478,17 +491,15 @@ Image::Image(BPath path)
Image::~Image() Image::~Image()
{ {
if(fBitmap!=NULL) { delete fBitmap;
delete fBitmap;
fBitmap = NULL;
}
} }
BBitmap* BBitmap*
Image::GetBitmap() Image::GetBitmap()
{ {
if(!fBitmap) if (!fBitmap)
fBitmap = BTranslationUtils::GetBitmap(fPath.Path()); fBitmap = BTranslationUtils::GetBitmap(fPath.Path());
return fBitmap; return fBitmap;
} }
+11 -10
View File
@@ -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);
@@ -127,20 +128,20 @@ public:
void Show(BackgroundImageInfo *, BView *view); void Show(BackgroundImageInfo *, BView *view);
uint32 GetShowingImageSet() {return fShowingImageSet;} uint32 GetShowingImageSet() { return fShowingImageSet; }
void Add(BackgroundImageInfo *); void Add(BackgroundImageInfo *);
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.
* Distributed under the terms of the MIT License.
*
* Authors:
* Jerome Duval (jerome.duval@free.fr)
*/
#ifndef BACKGROUNDS_VIEW_H
#define BACKGROUNDS_VIEW_H
"Backgrounds" by Jerome Duval (jerome.duval@free.fr)
(C)2002 OpenBeOS under MIT license #include "BackgroundImage.h"
*/
#ifndef BG_VIEW_H_
#define BG_VIEW_H_
#include <View.h> #include <View.h>
#include <ColorControl.h> #include <ColorControl.h>
@@ -30,51 +32,28 @@
#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"
class BGImageMenuItem : public BMenuItem { 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,75 +62,76 @@ 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;
protected: protected:
void MouseDown(BPoint point); void MouseDown(BPoint point);
void MouseUp(BPoint point); void MouseUp(BPoint point);
void MouseMoved(BPoint point, uint32 transit, const BMessage *message); void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
void AttachedToWindow(); void AttachedToWindow();
BPoint fOldPoint; BPoint fOldPoint;
float x_ratio,y_ratio; float x_ratio,y_ratio;
display_mode mode; display_mode mode;
BCursor fMoveHandCursor; BCursor fMoveHandCursor;
}; };
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);
static int32 NotifyThread(void *data); static int32 NotifyThread(void *data);
BGImageMenuItem *FindImageItem(const int32 imageIndex); BGImageMenuItem *FindImageItem(const int32 imageIndex);
bool AddItem(BGImageMenuItem *item); bool AddItem(BGImageMenuItem *item);
BackgroundImage::Mode FindPlacementMode(); BackgroundImage::Mode FindPlacementMode();
BColorControl *fPicker; // color picker BColorControl *fPicker; // color picker
BButton *fApply,*fRevert; // apply and revert buttons BButton *fApply, *fRevert; // apply and revert buttons
BCheckBox *fIconLabelBackground; // label ckeckbox BCheckBox *fIconLabelBackground; // label ckeckbox
BMenu* fPlacementMenu, *fImageMenu, *fWorkspaceMenu; // the three comboboxes BMenu* fPlacementMenu, *fImageMenu, *fWorkspaceMenu; // the three comboboxes
BTextControl *fXPlacementText, *fYPlacementText; // x and y textboxes BTextControl *fXPlacementText, *fYPlacementText; // x and y textboxes
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
BObjectList<BPath> fPathList; BObjectList<BPath> fPathList;
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
+4 -4
View File
@@ -6,10 +6,10 @@ AddSubDirSupportedPlatforms libbe_test ;
UsePrivateHeaders shared ; 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
; ;