* 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:
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -49,8 +49,8 @@ All rights reserved.
|
||||
#include <fs_attr.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "BGView.h"
|
||||
#include "BackgroundImage.h"
|
||||
#include "BackgroundsView.h"
|
||||
|
||||
const char *kBackgroundImageInfo = "be:bgndimginfo";
|
||||
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset";
|
||||
@@ -66,14 +66,13 @@ const char *kBackgroundImageCacheMode = "be:bgndimgcachemode";
|
||||
|
||||
BackgroundImage *
|
||||
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
BGView* view)
|
||||
BackgroundsView* view)
|
||||
{
|
||||
BackgroundImage *result = new BackgroundImage(node, isDesktop);
|
||||
result->bgView = view;
|
||||
BackgroundImage *result = new BackgroundImage(node, isDesktop, view);
|
||||
attr_info info;
|
||||
if (node->GetAttrInfo(kBackgroundImageInfo, &info) != B_OK)
|
||||
return result;
|
||||
|
||||
|
||||
BMessage container;
|
||||
char *buffer = new char [info.size];
|
||||
|
||||
@@ -81,9 +80,9 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
(size_t)info.size);
|
||||
if (error == info.size)
|
||||
error = container.Unflatten(buffer);
|
||||
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
|
||||
if (error != B_OK)
|
||||
return NULL;
|
||||
|
||||
@@ -93,13 +92,13 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
uint32 globalCacheMode = 0;
|
||||
bool randomChange = false;
|
||||
uint32 maxImageSet = 0;
|
||||
|
||||
if(isDesktop) {
|
||||
|
||||
if (isDesktop) {
|
||||
container.FindInt32(kBackgroundImageSetPeriod, (int32 *)&imageSetPeriod);
|
||||
container.FindInt32(kBackgroundImageCacheMode, (int32 *)&globalCacheMode);
|
||||
container.FindBool(kBackgroundImageRandomChange, &randomChange);
|
||||
}
|
||||
|
||||
|
||||
for (int32 index = 0; ; index++) {
|
||||
const char *path;
|
||||
uint32 workspaces = B_ALL_WORKSPACES;
|
||||
@@ -110,49 +109,47 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
uint32 cacheMode = 0;
|
||||
if (container.FindString(kBackgroundImageInfoPath, index, &path) != B_OK)
|
||||
break;
|
||||
|
||||
|
||||
BPath bpath(path);
|
||||
int32 imageIndex = view->AddImage(bpath);
|
||||
if(imageIndex < 0)
|
||||
if (imageIndex < 0)
|
||||
imageIndex = -imageIndex - 1;
|
||||
|
||||
|
||||
container.FindInt32(kBackgroundImageInfoWorkspaces, index,
|
||||
(int32 *)&workspaces);
|
||||
container.FindInt32(kBackgroundImageInfoMode, index, (int32 *)&mode);
|
||||
container.FindBool(kBackgroundImageInfoEraseText, index,
|
||||
&eraseTextWidgetBackground);
|
||||
container.FindPoint(kBackgroundImageInfoOffset, index, &offset);
|
||||
if(isDesktop)
|
||||
{
|
||||
|
||||
if (isDesktop) {
|
||||
container.FindInt32(kBackgroundImageInfoSet, index,
|
||||
(int32 *)&imageSet);
|
||||
container.FindInt32(kBackgroundImageInfoCacheMode, index,
|
||||
(int32 *)&cacheMode);
|
||||
}
|
||||
|
||||
|
||||
BackgroundImage::BackgroundImageInfo *imageInfo = new
|
||||
BackgroundImage::BackgroundImageInfo(workspaces, imageIndex,
|
||||
mode, offset, eraseTextWidgetBackground, imageSet, cacheMode);
|
||||
|
||||
//imageInfo->UnloadBitmap(globalCacheMode);
|
||||
|
||||
if(imageSet > maxImageSet)
|
||||
maxImageSet = imageSet;
|
||||
|
||||
|
||||
//imageInfo->UnloadBitmap(globalCacheMode);
|
||||
|
||||
if (imageSet > maxImageSet)
|
||||
maxImageSet = imageSet;
|
||||
|
||||
result->Add(imageInfo);
|
||||
}
|
||||
|
||||
if(result) {
|
||||
|
||||
if (result) {
|
||||
result->fImageSetCount = maxImageSet + 1;
|
||||
result->fRandomChange = randomChange;
|
||||
result->fImageSetPeriod = imageSetPeriod;
|
||||
result->fCacheMode = globalCacheMode;
|
||||
if(result->fImageSetCount > 1)
|
||||
if (result->fImageSetCount > 1)
|
||||
result->fShowingImageSet = random()%result->fImageSetCount;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -160,13 +157,14 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
BackgroundImage::BackgroundImageInfo::BackgroundImageInfo(uint32 workspaces,
|
||||
int32 imageIndex, Mode mode, BPoint offset, bool eraseTextWidget,
|
||||
uint32 imageSet, uint32 cacheMode)
|
||||
: fWorkspace(workspaces),
|
||||
fImageIndex(imageIndex),
|
||||
fMode(mode),
|
||||
fOffset(offset),
|
||||
fEraseTextWidgetBackground(eraseTextWidget),
|
||||
fImageSet(imageSet),
|
||||
fCacheMode(cacheMode)
|
||||
:
|
||||
fWorkspace(workspaces),
|
||||
fImageIndex(imageIndex),
|
||||
fMode(mode),
|
||||
fOffset(offset),
|
||||
fEraseTextWidgetBackground(eraseTextWidget),
|
||||
fImageSet(imageSet),
|
||||
fCacheMode(cacheMode)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -176,19 +174,23 @@ BackgroundImage::BackgroundImageInfo::~BackgroundImageInfo()
|
||||
}
|
||||
|
||||
|
||||
BackgroundImage::BackgroundImage(const BNode *node, bool desktop)
|
||||
: fIsDesktop(desktop),
|
||||
fDefinedByNode(*node),
|
||||
fView(NULL),
|
||||
fShowingBitmap(NULL),
|
||||
fBitmapForWorkspaceList(1, true),
|
||||
fImageSetPeriod(0),
|
||||
fShowingImageSet(0),
|
||||
fImageSetCount(0),
|
||||
fCacheMode(0),
|
||||
fRandomChange(false)
|
||||
{
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
BackgroundImage::BackgroundImage(const BNode *node, bool desktop, BackgroundsView* view)
|
||||
:
|
||||
fIsDesktop(desktop),
|
||||
fDefinedByNode(*node),
|
||||
fView(NULL),
|
||||
fBackgroundsView(view),
|
||||
fShowingBitmap(NULL),
|
||||
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();) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(info->fImageSet != fShowingImageSet)
|
||||
if (info->fImageSet != fShowingImageSet)
|
||||
index++;
|
||||
else
|
||||
fBitmapForWorkspaceList.RemoveItemAt(index);
|
||||
@@ -228,7 +230,6 @@ BackgroundImage::Show(BView *view, int32 workspace)
|
||||
if (poseView)
|
||||
poseView->SetEraseWidgetTextBackground(info->fEraseTextWidgetBackground);*/
|
||||
Show(info, fView);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,18 +237,18 @@ BackgroundImage::Show(BView *view, int32 workspace)
|
||||
void
|
||||
BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
||||
{
|
||||
BBitmap *bitmap = bgView->GetImage(info->fImageIndex)->GetBitmap();
|
||||
|
||||
if(!bitmap)
|
||||
BBitmap *bitmap = fBackgroundsView->GetImage(info->fImageIndex)->GetBitmap();
|
||||
|
||||
if (!bitmap)
|
||||
return;
|
||||
|
||||
BRect viewBounds(view->Bounds());
|
||||
|
||||
|
||||
display_mode mode;
|
||||
BScreen().GetMode(&mode);
|
||||
float x_ratio = viewBounds.Width() / mode.virtual_width;
|
||||
float y_ratio = viewBounds.Height() / mode.virtual_height;
|
||||
|
||||
|
||||
BRect bitmapBounds(bitmap->Bounds());
|
||||
BRect destinationBitmapBounds(bitmapBounds);
|
||||
destinationBitmapBounds.right *= x_ratio;
|
||||
@@ -255,7 +256,7 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
||||
BPoint offset(info->fOffset);
|
||||
offset.x *= x_ratio;
|
||||
offset.y *= y_ratio;
|
||||
|
||||
|
||||
uint32 tile = 0;
|
||||
uint32 followFlags = B_FOLLOW_TOP | B_FOLLOW_LEFT;
|
||||
|
||||
@@ -291,12 +292,12 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
||||
tile = B_TILE_BITMAP;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
// switch to the bitmap and force a redraw
|
||||
view->SetViewBitmap(bitmap, bitmapBounds, destinationBitmapBounds,
|
||||
followFlags, tile);
|
||||
view->Invalidate();
|
||||
|
||||
|
||||
/*if(fShowingBitmap != info) {
|
||||
if(fShowingBitmap)
|
||||
fShowingBitmap->UnloadBitmap(fCacheMode);
|
||||
@@ -325,9 +326,9 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
|
||||
{
|
||||
uint32 workspaceMask = 1;
|
||||
|
||||
for ( ; workspace; workspace--)
|
||||
for (; workspace; workspace--)
|
||||
workspaceMask *= 2;
|
||||
|
||||
|
||||
int32 count = fBitmapForWorkspaceList.CountItems();
|
||||
|
||||
// do a simple lookup for the most likely candidate bitmap -
|
||||
@@ -336,9 +337,10 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
|
||||
BackgroundImageInfo *result = NULL;
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(info->fImageSet != fShowingImageSet)
|
||||
if (info->fImageSet != fShowingImageSet)
|
||||
continue;
|
||||
if(fIsDesktop) {
|
||||
|
||||
if (fIsDesktop) {
|
||||
if (info->fWorkspace == workspaceMask)
|
||||
return info;
|
||||
if (info->fWorkspace & workspaceMask)
|
||||
@@ -354,14 +356,16 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
|
||||
void
|
||||
BackgroundImage::WorkspaceActivated(BView *view, int32 workspace, bool state)
|
||||
{
|
||||
if (!fIsDesktop)
|
||||
if (!fIsDesktop) {
|
||||
// we only care for desktop bitmaps
|
||||
return;
|
||||
}
|
||||
|
||||
if (!state)
|
||||
if (!state) {
|
||||
// we only care comming into a new workspace, not leaving one
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace);
|
||||
if (info != fShowingBitmap) {
|
||||
if (info)
|
||||
@@ -382,7 +386,7 @@ BackgroundImage::ScreenChanged(BRect, color_space)
|
||||
{
|
||||
if (!fIsDesktop || !fShowingBitmap)
|
||||
return;
|
||||
|
||||
|
||||
/*if (fShowingBitmap->fMode == kCentered) {
|
||||
BRect viewBounds(fView->Bounds());
|
||||
BRect bitmapBounds(fShowingBitmap->fBitmap->Bounds());
|
||||
@@ -407,27 +411,32 @@ BackgroundImage::SetBackgroundImage(BNode *node)
|
||||
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(bgView->GetImage(info->fImageIndex)==NULL)
|
||||
if (fBackgroundsView->GetImage(info->fImageIndex) == NULL)
|
||||
continue;
|
||||
|
||||
container.AddBool(kBackgroundImageInfoEraseText, info->fEraseTextWidgetBackground);
|
||||
container.AddString( kBackgroundImageInfoPath, bgView->GetImage(info->fImageIndex)->GetPath().Path());
|
||||
container.AddInt32( kBackgroundImageInfoWorkspaces, info->fWorkspace);
|
||||
container.AddPoint( kBackgroundImageInfoOffset, info->fOffset);
|
||||
container.AddInt32( kBackgroundImageInfoMode, info->fMode);
|
||||
if(fIsDesktop) {
|
||||
container.AddInt32( kBackgroundImageInfoSet, info->fImageSet);
|
||||
}
|
||||
|
||||
container.AddBool(kBackgroundImageInfoEraseText,
|
||||
info->fEraseTextWidgetBackground);
|
||||
container.AddString(kBackgroundImageInfoPath,
|
||||
fBackgroundsView->GetImage(info->fImageIndex)->GetPath().Path());
|
||||
container.AddInt32(kBackgroundImageInfoWorkspaces, info->fWorkspace);
|
||||
container.AddPoint(kBackgroundImageInfoOffset, info->fOffset);
|
||||
container.AddInt32(kBackgroundImageInfoMode, info->fMode);
|
||||
|
||||
if (fIsDesktop)
|
||||
container.AddInt32(kBackgroundImageInfoSet, info->fImageSet);
|
||||
}
|
||||
|
||||
|
||||
PRINT_OBJECT(container);
|
||||
|
||||
|
||||
char buffer[container.FlattenedSize()];
|
||||
if((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK)
|
||||
if ((err = container.Flatten(buffer, container.FlattenedSize())) != B_OK)
|
||||
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_OK;
|
||||
}
|
||||
|
||||
@@ -468,9 +477,13 @@ BackgroundImage::ChangeImageSet(BPoseView *poseView)
|
||||
}*/
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
Image::Image(BPath path)
|
||||
: fBitmap(NULL),
|
||||
fPath(path)
|
||||
:
|
||||
fBitmap(NULL),
|
||||
fPath(path)
|
||||
{
|
||||
name = path.Leaf();
|
||||
}
|
||||
@@ -478,17 +491,15 @@ Image::Image(BPath path)
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if(fBitmap!=NULL) {
|
||||
delete fBitmap;
|
||||
fBitmap = NULL;
|
||||
}
|
||||
delete fBitmap;
|
||||
}
|
||||
|
||||
|
||||
BBitmap*
|
||||
Image::GetBitmap()
|
||||
{
|
||||
if(!fBitmap)
|
||||
if (!fBitmap)
|
||||
fBitmap = BTranslationUtils::GetBitmap(fPath.Path());
|
||||
|
||||
return fBitmap;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ All rights reserved.
|
||||
|
||||
#include "String.h"
|
||||
#include "ObjectList.h"
|
||||
|
||||
#include <GraphicsDefs.h>
|
||||
#include <Node.h>
|
||||
#include <Path.h>
|
||||
|
||||
@@ -49,7 +51,7 @@ class BBitmap;
|
||||
|
||||
class BackgroundImage;
|
||||
class Image;
|
||||
class BGView;
|
||||
class BackgroundsView;
|
||||
|
||||
extern const char *kBackgroundImageInfo;
|
||||
extern const char *kBackgroundImageInfoOffset;
|
||||
@@ -97,11 +99,10 @@ public:
|
||||
uint32 fCacheMode; // image cache strategy (0 cache , 1 no cache)
|
||||
};
|
||||
|
||||
|
||||
|
||||
static BackgroundImage *GetBackgroundImage(const BNode *, bool isDesktop,
|
||||
BGView* view);
|
||||
static BackgroundImage *GetBackgroundImage(const BNode *node,
|
||||
bool isDesktop, BackgroundsView* view);
|
||||
// create a BackgroundImage object by reading it from a node
|
||||
|
||||
virtual ~BackgroundImage();
|
||||
|
||||
void Show(BView *view, int32 workspace);
|
||||
@@ -111,7 +112,7 @@ public:
|
||||
|
||||
void WorkspaceActivated(BView *view, int32 workspace, bool state);
|
||||
// respond to a workspace change
|
||||
void ScreenChanged(BRect , color_space);
|
||||
void ScreenChanged(BRect rect, color_space space);
|
||||
// respond to a screen size change
|
||||
/*static BackgroundImage *Refresh(BackgroundImage *oldBackgroundImage,
|
||||
const BNode *fromNode, bool desktop, BPoseView *poseView);
|
||||
@@ -127,20 +128,20 @@ public:
|
||||
|
||||
void Show(BackgroundImageInfo *, BView *view);
|
||||
|
||||
uint32 GetShowingImageSet() {return fShowingImageSet;}
|
||||
uint32 GetShowingImageSet() { return fShowingImageSet; }
|
||||
|
||||
void Add(BackgroundImageInfo *);
|
||||
void RemoveAll();
|
||||
|
||||
|
||||
private:
|
||||
BackgroundImage(const BNode *, bool);
|
||||
BackgroundImage(const BNode *node, bool isDesktop, BackgroundsView* view);
|
||||
// no public constructor, GetBackgroundImage factory function is
|
||||
// used instead
|
||||
|
||||
bool fIsDesktop;
|
||||
BNode fDefinedByNode;
|
||||
BView *fView;
|
||||
BGView* bgView;
|
||||
BackgroundsView* fBackgroundsView;
|
||||
BackgroundImageInfo *fShowingBitmap;
|
||||
|
||||
BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+415
-574
File diff suppressed because it is too large
Load Diff
+42
-62
@@ -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
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BG_VIEW_H_
|
||||
#define BG_VIEW_H_
|
||||
#include "BackgroundImage.h"
|
||||
|
||||
#include <View.h>
|
||||
#include <ColorControl.h>
|
||||
@@ -30,51 +32,28 @@
|
||||
#include <FilePanel.h>
|
||||
#include <StringView.h>
|
||||
#include <Cursor.h>
|
||||
#include "BackgroundImage.h"
|
||||
|
||||
#define SETTINGS_FILE "Backgrounds_settings"
|
||||
|
||||
class BGImageMenuItem : public BMenuItem {
|
||||
public:
|
||||
BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message,
|
||||
char shortcut=0, uint32 modifiers=0);
|
||||
char shortcut = 0, uint32 modifiers = 0);
|
||||
|
||||
int32 ImageIndex() { return fImageIndex; }
|
||||
|
||||
private:
|
||||
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 {
|
||||
public:
|
||||
PreviewBox(BRect frame, const char *name);
|
||||
|
||||
void Draw(BRect rect);
|
||||
void SetDesktop(bool isDesktop);
|
||||
|
||||
protected:
|
||||
bool fIsDesktop;
|
||||
};
|
||||
@@ -83,75 +62,76 @@ class PreviewBox : public BBox {
|
||||
class PreView : public BControl {
|
||||
public:
|
||||
PreView(BRect frame, const char *name, int32 resize, int32 flags);
|
||||
|
||||
BPoint fPoint;
|
||||
BRect fImageBounds;
|
||||
|
||||
|
||||
protected:
|
||||
void MouseDown(BPoint point);
|
||||
void MouseUp(BPoint point);
|
||||
void MouseMoved(BPoint point, uint32 transit, const BMessage *message);
|
||||
void AttachedToWindow();
|
||||
|
||||
|
||||
BPoint fOldPoint;
|
||||
float x_ratio,y_ratio;
|
||||
display_mode mode;
|
||||
|
||||
|
||||
BCursor fMoveHandCursor;
|
||||
};
|
||||
|
||||
|
||||
class BGView : public BBox {
|
||||
class BackgroundsView : public BBox {
|
||||
public:
|
||||
BGView(BRect frame, const char *name, int32 resize, int32 flags);
|
||||
~BGView(void);
|
||||
|
||||
void SaveSettings(void);
|
||||
BackgroundsView(BRect frame, const char *name, int32 resize, int32 flags);
|
||||
~BackgroundsView(void);
|
||||
|
||||
void SaveSettings();
|
||||
void WorkspaceActivated(uint32 oldWorkspaces, bool active);
|
||||
int32 AddImage(BPath path);
|
||||
Image* GetImage(int32 imageIndex);
|
||||
void ProcessRefs(entry_ref dir_ref, BMessage* msg);
|
||||
|
||||
protected:
|
||||
void Save(void);
|
||||
void NotifyServer(void);
|
||||
void LoadSettings(void);
|
||||
void AllAttached(void);
|
||||
void Save();
|
||||
void NotifyServer();
|
||||
void LoadSettings();
|
||||
void AllAttached();
|
||||
void MessageReceived(BMessage *msg);
|
||||
void LoadDesktopFolder(void);
|
||||
void LoadDefaultFolder(void);
|
||||
void LoadDesktopFolder();
|
||||
void LoadDefaultFolder();
|
||||
void LoadFolder(bool isDesktop);
|
||||
void LoadRecentFolder(BPath path);
|
||||
void UpdateWithCurrent(void);
|
||||
void UpdatePreview(void);
|
||||
void UpdateButtons(void);
|
||||
void UpdateWithCurrent();
|
||||
void UpdatePreview();
|
||||
void UpdateButtons();
|
||||
void RefsReceived(BMessage *msg);
|
||||
int32 AddPath(BPath path);
|
||||
|
||||
|
||||
static int32 NotifyThread(void *data);
|
||||
|
||||
|
||||
BGImageMenuItem *FindImageItem(const int32 imageIndex);
|
||||
bool AddItem(BGImageMenuItem *item);
|
||||
|
||||
|
||||
BackgroundImage::Mode FindPlacementMode();
|
||||
|
||||
|
||||
BColorControl *fPicker; // color picker
|
||||
BButton *fApply,*fRevert; // apply and revert buttons
|
||||
BButton *fApply, *fRevert; // apply and revert buttons
|
||||
BCheckBox *fIconLabelBackground; // label ckeckbox
|
||||
BMenu* fPlacementMenu, *fImageMenu, *fWorkspaceMenu; // the three comboboxes
|
||||
BTextControl *fXPlacementText, *fYPlacementText; // x and y textboxes
|
||||
PreView *fPreView; // the view for previewing the result
|
||||
PreviewBox *fPreview; // the box which draws a computer/folder
|
||||
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::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
|
||||
BMessage fSettings; // settings loaded from settings directory
|
||||
|
||||
|
||||
BObjectList<BPath> fPathList;
|
||||
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 (jerome.duval@free.fr)
|
||||
*/
|
||||
|
||||
|
||||
#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 (jerome.duval@free.fr)
|
||||
*/
|
||||
#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
|
||||
@@ -6,10 +6,10 @@ AddSubDirSupportedPlatforms libbe_test ;
|
||||
UsePrivateHeaders shared ;
|
||||
|
||||
Preference Backgrounds :
|
||||
BackgroundImage.cpp
|
||||
BGMain.cpp
|
||||
BGView.cpp
|
||||
BGWindow.cpp
|
||||
BackgroundImage.cpp
|
||||
Backgrounds.cpp
|
||||
BackgroundsView.cpp
|
||||
ImageFilePanel.cpp
|
||||
: be tracker translation
|
||||
: Backgrounds.rdef
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user