Partial clean-up.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33910 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jonas Sundström
2009-11-05 23:39:57 +00:00
parent abf272eedb
commit dca191e9b7
8 changed files with 316 additions and 271 deletions
+71 -62
View File
@@ -35,8 +35,14 @@ All rights reserved.
// Classes used for setting up and managing background images // Classes used for setting up and managing background images
// //
#include "BackgroundImage.h"
#include <new>
#include <stdlib.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Debug.h> #include <Debug.h>
#include <fs_attr.h>
#include <Node.h> #include <Node.h>
#include <TranslationKit.h> #include <TranslationKit.h>
#include <View.h> #include <View.h>
@@ -47,43 +53,37 @@ All rights reserved.
#include <Screen.h> #include <Screen.h>
#include <String.h> #include <String.h>
#include <fs_attr.h>
#include <stdlib.h>
#include "BackgroundImage.h"
#include "BackgroundsView.h" #include "BackgroundsView.h"
#include <new>
const char* kBackgroundImageInfo = "be:bgndimginfo";
const char *kBackgroundImageInfo = "be:bgndimginfo"; const char* kBackgroundImageInfoOffset = "be:bgndimginfooffset";
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset"; // const char* kBackgroundImageInfoTextOutline = "be:bgndimginfotextoutline";
//const char *kBackgroundImageInfoTextOutline = "be:bgndimginfotextoutline"; const char* kBackgroundImageInfoTextOutline = "be:bgndimginfoerasetext";
const char *kBackgroundImageInfoTextOutline = "be:bgndimginfoerasetext";
// NOTE: the attribute keeps the old name for backwards compatibility, // NOTE: the attribute keeps the old name for backwards compatibility,
// just in case some users spend time configuring a few windows with // just in case some users spend time configuring a few windows with
// this feature on or off... // this feature on or off...
const char *kBackgroundImageInfoMode = "be:bgndimginfomode"; const char* kBackgroundImageInfoMode = "be:bgndimginfomode";
const char *kBackgroundImageInfoWorkspaces = "be:bgndimginfoworkspaces"; const char* kBackgroundImageInfoWorkspaces = "be:bgndimginfoworkspaces";
const char *kBackgroundImageInfoPath = "be:bgndimginfopath"; const char* kBackgroundImageInfoPath = "be:bgndimginfopath";
const char *kBackgroundImageInfoSet = "be:bgndimginfoset"; const char* kBackgroundImageInfoSet = "be:bgndimginfoset";
const char *kBackgroundImageInfoCacheMode = "be:bgndimginfocachemode"; const char* kBackgroundImageInfoCacheMode = "be:bgndimginfocachemode";
const char *kBackgroundImageSetPeriod = "be:bgndimgsetperiod"; const char* kBackgroundImageSetPeriod = "be:bgndimgsetperiod";
const char *kBackgroundImageRandomChange = "be:bgndimgrandomchange"; const char* kBackgroundImageRandomChange = "be:bgndimgrandomchange";
const char *kBackgroundImageCacheMode = "be:bgndimgcachemode"; const char* kBackgroundImageCacheMode = "be:bgndimgcachemode";
BackgroundImage * BackgroundImage*
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop, BackgroundImage::GetBackgroundImage(const BNode* node, bool isDesktop,
BackgroundsView* view) BackgroundsView* view)
{ {
BackgroundImage *result = new BackgroundImage(node, isDesktop, view); BackgroundImage* result = new BackgroundImage(node, isDesktop, 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];
status_t error = node->ReadAttr(kBackgroundImageInfo, info.type, 0, buffer, status_t error = node->ReadAttr(kBackgroundImageInfo, info.type, 0, buffer,
(size_t)info.size); (size_t)info.size);
@@ -103,13 +103,14 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
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;
Mode mode = kTiled; Mode mode = kTiled;
bool textWidgetLabelOutline = false; bool textWidgetLabelOutline = false;
@@ -118,7 +119,8 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
uint32 cacheMode = 0; uint32 cacheMode = 0;
int32 imageIndex = -1; int32 imageIndex = -1;
if (container.FindString(kBackgroundImageInfoPath, index, &path) == B_OK) { if (container.FindString(kBackgroundImageInfoPath, index, &path)
== B_OK) {
if (strcmp(path, "")) { if (strcmp(path, "")) {
BPath bpath(path); BPath bpath(path);
imageIndex = view->AddImage(bpath); imageIndex = view->AddImage(bpath);
@@ -130,24 +132,24 @@ BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
break; break;
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(kBackgroundImageInfoTextOutline, index, container.FindBool(kBackgroundImageInfoTextOutline, index,
&textWidgetLabelOutline); &textWidgetLabelOutline);
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, textWidgetLabelOutline, imageSet, cacheMode); mode, offset, textWidgetLabelOutline, imageSet, cacheMode);
//imageInfo->UnloadBitmap(globalCacheMode); // imageInfo->UnloadBitmap(globalCacheMode);
if (imageSet > maxImageSet) if (imageSet > maxImageSet)
maxImageSet = imageSet; maxImageSet = imageSet;
@@ -191,7 +193,8 @@ BackgroundImage::BackgroundImageInfo::~BackgroundImageInfo()
// #pragma mark - // #pragma mark -
BackgroundImage::BackgroundImage(const BNode *node, bool desktop, BackgroundsView* view) BackgroundImage::BackgroundImage(const BNode* node, bool desktop,
BackgroundsView* view)
: :
fIsDesktop(desktop), fIsDesktop(desktop),
fDefinedByNode(*node), fDefinedByNode(*node),
@@ -214,14 +217,14 @@ BackgroundImage::~BackgroundImage()
void void
BackgroundImage::Add(BackgroundImageInfo *info) BackgroundImage::Add(BackgroundImageInfo* info)
{ {
fBitmapForWorkspaceList.AddItem(info); fBitmapForWorkspaceList.AddItem(info);
} }
void void
BackgroundImage::Remove(BackgroundImageInfo *info) BackgroundImage::Remove(BackgroundImageInfo* info)
{ {
fBitmapForWorkspaceList.RemoveItem(info); fBitmapForWorkspaceList.RemoveItem(info);
} }
@@ -231,7 +234,7 @@ void
BackgroundImage::RemoveAll() 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
@@ -241,24 +244,26 @@ BackgroundImage::RemoveAll()
void void
BackgroundImage::Show(BView *view, int32 workspace) BackgroundImage::Show(BView* view, int32 workspace)
{ {
fView = view; fView = view;
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace); BackgroundImageInfo* info = ImageInfoForWorkspace(workspace);
if (info) { if (info) {
/*BPoseView *poseView = dynamic_cast<BPoseView *>(fView); /*BPoseView* poseView = dynamic_cast<BPoseView*>(fView);
if (poseView) if (poseView)
poseView->SetEraseWidgetTextBackground(info->fTextWidgetLabelOutline);*/ poseView
->SetEraseWidgetTextBackground(info->fTextWidgetLabelOutline);*/
Show(info, fView); Show(info, fView);
} }
} }
void void
BackgroundImage::Show(BackgroundImageInfo *info, BView *view) BackgroundImage::Show(BackgroundImageInfo* info, BView* view)
{ {
BBitmap *bitmap = fBackgroundsView->GetImage(info->fImageIndex)->GetBitmap(); BBitmap* bitmap
= fBackgroundsView->GetImage(info->fImageIndex)->GetBitmap();
if (!bitmap) if (!bitmap)
return; return;
@@ -287,7 +292,8 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
if (fIsDesktop) { if (fIsDesktop) {
destinationBitmapBounds.OffsetBy( destinationBitmapBounds.OffsetBy(
(viewBounds.Width() - destinationBitmapBounds.Width()) / 2, (viewBounds.Width() - destinationBitmapBounds.Width()) / 2,
(viewBounds.Height() - destinationBitmapBounds.Height()) / 2); (viewBounds.Height() - destinationBitmapBounds.Height())
/ 2);
break; break;
} }
// else fall thru // else fall thru
@@ -304,7 +310,8 @@ BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
break; break;
} }
case kTiled: case kTiled:
// Original Backgrounds Preferences center the tiled paper but the Tracker don't do that // Original Backgrounds Preferences center the tiled paper
// but Tracker doesn't do that
//if (fIsDesktop) { //if (fIsDesktop) {
destinationBitmapBounds.OffsetBy( destinationBitmapBounds.OffsetBy(
(viewBounds.Width() - destinationBitmapBounds.Width()) / 2, (viewBounds.Width() - destinationBitmapBounds.Width()) / 2,
@@ -333,7 +340,7 @@ BackgroundImage::Remove()
if (fShowingBitmap) { if (fShowingBitmap) {
fView->ClearViewBitmap(); fView->ClearViewBitmap();
fView->Invalidate(); fView->Invalidate();
/*BPoseView *poseView = dynamic_cast<BPoseView *>(fView); /*BPoseView* poseView = dynamic_cast<BPoseView*>(fView);
// make sure text widgets draw the default way, erasing their background // make sure text widgets draw the default way, erasing their background
if (poseView) if (poseView)
poseView->SetEraseWidgetTextBackground(true);*/ poseView->SetEraseWidgetTextBackground(true);*/
@@ -342,7 +349,7 @@ BackgroundImage::Remove()
} }
BackgroundImage::BackgroundImageInfo * BackgroundImage::BackgroundImageInfo*
BackgroundImage::ImageInfoForWorkspace(int32 workspace) const BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
{ {
uint32 workspaceMask = 1; uint32 workspaceMask = 1;
@@ -355,9 +362,9 @@ BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
// do a simple lookup for the most likely candidate bitmap - // do a simple lookup for the most likely candidate bitmap -
// pick the imageInfo that is only defined for this workspace over one // pick the imageInfo that is only defined for this workspace over one
// that supports multiple workspaces // that supports multiple workspaces
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;
@@ -375,7 +382,7 @@ 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
@@ -387,12 +394,12 @@ BackgroundImage::WorkspaceActivated(BView *view, int32 workspace, bool state)
return; return;
} }
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace); BackgroundImageInfo* info = ImageInfoForWorkspace(workspace);
if (info != fShowingBitmap) { if (info != fShowingBitmap) {
if (info) if (info)
Show(info, view); Show(info, view);
else { else {
/*if (BPoseView *poseView = dynamic_cast<BPoseView *>(view)) /*if (BPoseView* poseView = dynamic_cast<BPoseView*>(view))
poseView->SetEraseWidgetTextBackground(true);*/ poseView->SetEraseWidgetTextBackground(true);*/
view->ClearViewBitmap(); view->ClearViewBitmap();
view->Invalidate(); view->Invalidate();
@@ -416,28 +423,29 @@ BackgroundImage::ScreenChanged(BRect, color_space)
(viewBounds.Width() - bitmapBounds.Width()) / 2, (viewBounds.Width() - bitmapBounds.Width()) / 2,
(viewBounds.Height() - bitmapBounds.Height()) / 2); (viewBounds.Height() - bitmapBounds.Height()) / 2);
fView->SetViewBitmap(fShowingBitmap->fBitmap, bitmapBounds, destinationBitmapBounds, fView->SetViewBitmap(fShowingBitmap->fBitmap, bitmapBounds,
B_FOLLOW_NONE, 0); destinationBitmapBounds, B_FOLLOW_NONE, 0);
fView->Invalidate(); fView->Invalidate();
}*/ }*/
} }
status_t status_t
BackgroundImage::SetBackgroundImage(BNode *node) BackgroundImage::SetBackgroundImage(BNode* node)
{ {
status_t err; status_t err;
BMessage container; BMessage container;
int32 count = fBitmapForWorkspaceList.CountItems(); int32 count = fBitmapForWorkspaceList.CountItems();
for (int32 index = 0; index < count; index++) { for (int32 index = 0; index < count; index++) {
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index); BackgroundImageInfo* info = fBitmapForWorkspaceList.ItemAt(index);
container.AddBool(kBackgroundImageInfoTextOutline, container.AddBool(kBackgroundImageInfoTextOutline,
info->fTextWidgetLabelOutline); info->fTextWidgetLabelOutline);
if (fBackgroundsView->GetImage(info->fImageIndex) != NULL) { if (fBackgroundsView->GetImage(info->fImageIndex) != NULL) {
container.AddString(kBackgroundImageInfoPath, container.AddString(kBackgroundImageInfoPath,
fBackgroundsView->GetImage(info->fImageIndex)->GetPath().Path()); fBackgroundsView
->GetImage(info->fImageIndex)->GetPath().Path());
} else } else
container.AddString(kBackgroundImageInfoPath, ""); container.AddString(kBackgroundImageInfoPath, "");
@@ -473,16 +481,16 @@ BackgroundImage::SetBackgroundImage(BNode *node)
} }
/*BackgroundImage * /*BackgroundImage*
BackgroundImage::Refresh(BackgroundImage *oldBackgroundImage, BackgroundImage::Refresh(BackgroundImage* oldBackgroundImage,
const BNode *fromNode, bool desktop, BPoseView *poseView) const BNode* fromNode, bool desktop, BPoseView* poseView)
{ {
if (oldBackgroundImage) { if (oldBackgroundImage) {
oldBackgroundImage->Remove(); oldBackgroundImage->Remove();
delete oldBackgroundImage; delete oldBackgroundImage;
} }
BackgroundImage *result = GetBackgroundImage(fromNode, desktop); BackgroundImage* result = GetBackgroundImage(fromNode, desktop);
if (result && poseView->ViewMode() != kListMode) if (result && poseView->ViewMode() != kListMode)
result->Show(poseView, current_workspace()); result->Show(poseView, current_workspace());
return result; return result;
@@ -490,12 +498,12 @@ BackgroundImage::Refresh(BackgroundImage *oldBackgroundImage,
void void
BackgroundImage::ChangeImageSet(BPoseView *poseView) BackgroundImage::ChangeImageSet(BPoseView* poseView)
{ {
if (fRandomChange) { if (fRandomChange) {
if (fImageSetCount > 1) { if (fImageSetCount > 1) {
uint32 oldShowingImageSet = fShowingImageSet; uint32 oldShowingImageSet = fShowingImageSet;
while(oldShowingImageSet == fShowingImageSet) while (oldShowingImageSet == fShowingImageSet)
fShowingImageSet = random()%fImageSetCount; fShowingImageSet = random()%fImageSetCount;
} else } else
fShowingImageSet = 0; fShowingImageSet = 0;
@@ -535,3 +543,4 @@ Image::GetBitmap()
return fBitmap; return fBitmap;
} }
+27 -25
View File
@@ -38,13 +38,14 @@ All rights reserved.
#ifndef __BACKGROUND_IMAGE__ #ifndef __BACKGROUND_IMAGE__
#define __BACKGROUND_IMAGE__ #define __BACKGROUND_IMAGE__
#include "String.h"
#include "ObjectList.h"
#include <GraphicsDefs.h> #include <GraphicsDefs.h>
#include <Node.h> #include <Node.h>
#include <Path.h> #include <Path.h>
#include "ObjectList.h"
#include "String.h"
class BView; class BView;
class BBitmap; class BBitmap;
@@ -53,14 +54,14 @@ class BackgroundImage;
class Image; class Image;
class BackgroundsView; class BackgroundsView;
extern const char *kBackgroundImageInfo; extern const char* kBackgroundImageInfo;
extern const char *kBackgroundImageInfoOffset; extern const char* kBackgroundImageInfoOffset;
extern const char *kBackgroundImageInfoEraseText; extern const char* kBackgroundImageInfoEraseText;
extern const char *kBackgroundImageInfoMode; extern const char* kBackgroundImageInfoMode;
extern const char *kBackgroundImageInfoWorkspaces; extern const char* kBackgroundImageInfoWorkspaces;
extern const char *kBackgroundImageInfoPath; extern const char* kBackgroundImageInfoPath;
extern const char *kBackgroundImageInfoSet; extern const char* kBackgroundImageInfoSet;
extern const char *kBackgroundImageInfoSetPeriod; extern const char* kBackgroundImageInfoSetPeriod;
const uint32 kRestoreBackgroundImage = 'Tbgr'; const uint32 kRestoreBackgroundImage = 'Tbgr';
const uint32 kChangeBackgroundImage = 'Cbgr'; const uint32 kChangeBackgroundImage = 'Cbgr';
@@ -99,50 +100,50 @@ 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, static BackgroundImage* GetBackgroundImage(const BNode* node,
bool isDesktop, BackgroundsView* view); bool isDesktop, BackgroundsView* 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);
// display the right background for a given workspace // display the right background for a given workspace
void Remove(); void Remove();
// remove the background from it's current view // remove the background from it's current view
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 rect, color_space 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);
// respond to a background image setting change // respond to a background image setting change
void ChangeImageSet(BPoseView *poseView); void ChangeImageSet(BPoseView* poseView);
// change to the next imageSet if any, no refresh*/ // change to the next imageSet if any, no refresh*/
BackgroundImageInfo *ImageInfoForWorkspace(int32) const; BackgroundImageInfo* ImageInfoForWorkspace(int32) const;
bool IsDesktop() { return fIsDesktop;} bool IsDesktop() { return fIsDesktop;}
status_t SetBackgroundImage(BNode *node); status_t SetBackgroundImage(BNode* node);
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 Remove(BackgroundImageInfo *); void Remove(BackgroundImageInfo*);
void RemoveAll(); void RemoveAll();
private: private:
BackgroundImage(const BNode *node, bool isDesktop, BackgroundsView* view); 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;
BackgroundsView* fBackgroundsView; BackgroundsView* fBackgroundsView;
BackgroundImageInfo *fShowingBitmap; BackgroundImageInfo* fShowingBitmap;
BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList; BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
@@ -164,9 +165,10 @@ public:
BBitmap* GetBitmap(); BBitmap* GetBitmap();
BPath GetPath() {return fPath;} BPath GetPath() {return fPath;}
private: private:
BBitmap *fBitmap; BBitmap* fBitmap;
BPath fPath; BPath fPath;
BString name; BString name;
}; };
#endif #endif
+6 -5
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2008, Haiku, Inc. All Rights Reserved. * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -8,15 +8,15 @@
*/ */
#include "BackgroundsView.h"
#include <Application.h> #include <Application.h>
#include <LayoutBuilder.h> #include <LayoutBuilder.h>
#include <TrackerAddOnAppLaunch.h> #include <TrackerAddOnAppLaunch.h>
#include <Window.h> #include <Window.h>
#include "BackgroundsView.h"
static const char *kSignature = "application/x-vnd.Haiku-Backgrounds";
static const char* kSignature = "application/x-vnd.Haiku-Backgrounds";
class BackgroundsWindow : public BWindow { class BackgroundsWindow : public BWindow {
@@ -29,7 +29,7 @@ class BackgroundsWindow : public BWindow {
virtual bool QuitRequested(); virtual bool QuitRequested();
virtual void WorkspaceActivated(int32 oldWorkspaces, bool active); virtual void WorkspaceActivated(int32 oldWorkspaces, bool active);
BackgroundsView *fBackgroundsView; BackgroundsView* fBackgroundsView;
}; };
@@ -61,6 +61,7 @@ BackgroundsApplication::RefsReceived(BMessage* message)
fWindow->RefsReceived(message); fWindow->RefsReceived(message);
} }
// #pragma mark - // #pragma mark -
+38 -36
View File
@@ -10,7 +10,6 @@
#include "BackgroundsView.h" #include "BackgroundsView.h"
#include "ImageFilePanel.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@@ -28,6 +27,8 @@
#include <be_apps/Tracker/Background.h> #include <be_apps/Tracker/Background.h>
#include "ImageFilePanel.h"
static const uint32 kMsgApplySettings = 'aply'; static const uint32 kMsgApplySettings = 'aply';
static const uint32 kMsgRevertSettings = 'rvrt'; static const uint32 kMsgRevertSettings = 'rvrt';
@@ -162,7 +163,7 @@ BackgroundsView::BackgroundsView()
fPreview->AddChild(view); fPreview->AddChild(view);
BBox *rightbox = new BBox("rightbox"); BBox* rightbox = new BBox("rightbox");
fWorkspaceMenu = new BPopUpMenu("pick one"); fWorkspaceMenu = new BPopUpMenu("pick one");
fWorkspaceMenu->AddItem(new BMenuItem("All Workspaces", fWorkspaceMenu->AddItem(new BMenuItem("All Workspaces",
@@ -178,7 +179,7 @@ BackgroundsView::BackgroundsView()
fWorkspaceMenu->AddItem(new BMenuItem("Other folder" B_UTF8_ELLIPSIS, fWorkspaceMenu->AddItem(new BMenuItem("Other folder" B_UTF8_ELLIPSIS,
new BMessage(kMsgOtherFolder))); new BMessage(kMsgOtherFolder)));
BMenuField *workspaceMenuField = new BMenuField(BRect(0, 0, 130, 18), BMenuField* workspaceMenuField = new BMenuField(BRect(0, 0, 130, 18),
"workspaceMenuField", NULL, fWorkspaceMenu, true); "workspaceMenuField", NULL, fWorkspaceMenu, true);
workspaceMenuField->ResizeToPreferred(); workspaceMenuField->ResizeToPreferred();
rightbox->SetLabel(workspaceMenuField); rightbox->SetLabel(workspaceMenuField);
@@ -190,7 +191,7 @@ BackgroundsView::BackgroundsView()
fImageMenu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS, fImageMenu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS,
new BMessage(kMsgOtherImage))); new BMessage(kMsgOtherImage)));
BMenuField *imageMenuField = new BMenuField(NULL, fImageMenu); BMenuField* imageMenuField = new BMenuField(NULL, fImageMenu);
imageMenuField->SetAlignment(B_ALIGN_RIGHT); imageMenuField->SetAlignment(B_ALIGN_RIGHT);
imageMenuField->ResizeToPreferred(); imageMenuField->ResizeToPreferred();
@@ -204,7 +205,7 @@ BackgroundsView::BackgroundsView()
fPlacementMenu->AddItem(new BMenuItem("Tile", fPlacementMenu->AddItem(new BMenuItem("Tile",
new BMessage(kMsgTilePlacement))); new BMessage(kMsgTilePlacement)));
BMenuField *placementMenuField = new BMenuField(NULL, fPlacementMenu); BMenuField* placementMenuField = new BMenuField(NULL, fPlacementMenu);
placementMenuField->SetAlignment(B_ALIGN_RIGHT); placementMenuField->SetAlignment(B_ALIGN_RIGHT);
fIconLabelOutline = new BCheckBox("Icon label outline", fIconLabelOutline = new BCheckBox("Icon label outline",
@@ -319,7 +320,7 @@ BackgroundsView::AllAttached()
void void
BackgroundsView::MessageReceived(BMessage *msg) BackgroundsView::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { switch (msg->what) {
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
@@ -527,7 +528,7 @@ BackgroundsView::UpdateWithCurrent(void)
} }
for (int32 i = fImageList.CountItems() - 1; i >= 0; i--) { for (int32 i = fImageList.CountItems() - 1; i >= 0; i--) {
BMessage *message = new BMessage(kMsgImageSelected); BMessage* message = new BMessage(kMsgImageSelected);
AddItem(new BGImageMenuItem(GetImage(i)->GetName(), i, message)); AddItem(new BGImageMenuItem(GetImage(i)->GetName(), i, message));
} }
@@ -594,8 +595,8 @@ BackgroundsView::UpdateWithCurrent(void)
void void
BackgroundsView::Save() BackgroundsView::Save()
{ {
bool textWidgetLabelOutline = bool textWidgetLabelOutline
fIconLabelOutline->Value() == B_CONTROL_ON; = fIconLabelOutline->Value() == B_CONTROL_ON;
BackgroundImage::Mode mode = FindPlacementMode(); BackgroundImage::Mode mode = FindPlacementMode();
BPoint offset(atoi(fXPlacementText->Text()), atoi(fYPlacementText->Text())); BPoint offset(atoi(fXPlacementText->Text()), atoi(fYPlacementText->Text()));
@@ -631,8 +632,8 @@ BackgroundsView::Save()
fCurrentInfo->fCacheMode); fCurrentInfo->fCacheMode);
fCurrent->Add(fCurrentInfo); fCurrent->Add(fCurrentInfo);
} else if (fCurrentInfo->fWorkspace == workspaceMask) { } else if (fCurrentInfo->fWorkspace == workspaceMask) {
fCurrentInfo->fTextWidgetLabelOutline = fCurrentInfo->fTextWidgetLabelOutline
textWidgetLabelOutline; = textWidgetLabelOutline;
fCurrentInfo->fMode = mode; fCurrentInfo->fMode = mode;
if (fCurrentInfo->fMode == BackgroundImage::kAtOffset) if (fCurrentInfo->fMode == BackgroundImage::kAtOffset)
fCurrentInfo->fOffset = offset; fCurrentInfo->fOffset = offset;
@@ -759,9 +760,9 @@ BackgroundsView::NotifyServer()
int32 int32
BackgroundsView::NotifyThread(void *data) BackgroundsView::NotifyThread(void* data)
{ {
BackgroundsView *view = (BackgroundsView*)data; BackgroundsView* view = (BackgroundsView*)data;
view->NotifyServer(); view->NotifyServer();
return B_OK; return B_OK;
@@ -842,7 +843,7 @@ BackgroundsView::LoadSettings()
int32 i = AddPath(path); int32 i = AddPath(path);
BString s; BString s;
s << "Folder: " << path.Leaf(); s << "Folder: " << path.Leaf();
BMenuItem *item = new BMenuItem(s.String(), BMenuItem* item = new BMenuItem(s.String(),
new BMessage(kMsgFolderSelected)); new BMessage(kMsgFolderSelected));
fWorkspaceMenu->AddItem(item, -i - 1 + 6); fWorkspaceMenu->AddItem(item, -i - 1 + 6);
index++; index++;
@@ -893,10 +894,10 @@ BackgroundsView::UpdatePreview()
int32 index = ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex(); int32 index = ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex();
if (index >= 0) { if (index >= 0) {
BBitmap *bitmap = GetImage(index)->GetBitmap(); BBitmap* bitmap = GetImage(index)->GetBitmap();
if (bitmap) { if (bitmap) {
BackgroundImage::BackgroundImageInfo *info = BackgroundImage::BackgroundImageInfo* info
new BackgroundImage::BackgroundImageInfo(0, index, = new BackgroundImage::BackgroundImageInfo(0, index,
FindPlacementMode(), BPoint(atoi(fXPlacementText->Text()), FindPlacementMode(), BPoint(atoi(fXPlacementText->Text()),
atoi(fYPlacementText->Text())), atoi(fYPlacementText->Text())),
fIconLabelOutline->Value() == B_CONTROL_ON, 0, 0); fIconLabelOutline->Value() == B_CONTROL_ON, 0, 0);
@@ -944,20 +945,21 @@ BackgroundsView::UpdateButtons()
&& fPicker->ValueAsColor() != BScreen().DesktopColor()) { && fPicker->ValueAsColor() != BScreen().DesktopColor()) {
hasChanged = true; hasChanged = true;
} else if (fCurrentInfo) { } else if (fCurrentInfo) {
if ((fIconLabelOutline->Value() == B_CONTROL_ON) ^ if ((fIconLabelOutline->Value() == B_CONTROL_ON)
fCurrentInfo->fTextWidgetLabelOutline) { ^ fCurrentInfo->fTextWidgetLabelOutline) {
hasChanged = true; hasChanged = true;
} else if (FindPlacementMode() != fCurrentInfo->fMode) { } else if (FindPlacementMode() != fCurrentInfo->fMode) {
hasChanged = true; hasChanged = true;
} else if (fCurrentInfo->fImageIndex != } else if (fCurrentInfo->fImageIndex
((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) { != ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) {
hasChanged = true; hasChanged = true;
} else if (fCurrent->IsDesktop() } else if (fCurrent->IsDesktop()
&& ((fCurrentInfo->fWorkspace != B_ALL_WORKSPACES) && ((fCurrentInfo->fWorkspace != B_ALL_WORKSPACES)
^ (fWorkspaceMenu->FindItem(kMsgCurrentWorkspace)->IsMarked()))) { ^ (fWorkspaceMenu->FindItem(kMsgCurrentWorkspace)->IsMarked())))
{
hasChanged = true; hasChanged = true;
} else if (fCurrentInfo->fImageIndex > -1 && } else if (fCurrentInfo->fImageIndex > -1
fCurrentInfo->fMode == BackgroundImage::kAtOffset) { && fCurrentInfo->fMode == BackgroundImage::kAtOffset) {
BString oldString, newString; BString oldString, newString;
oldString << (int)fCurrentInfo->fOffset.x; oldString << (int)fCurrentInfo->fOffset.x;
if (oldString != BString(fXPlacementText->Text())) { if (oldString != BString(fXPlacementText->Text())) {
@@ -981,7 +983,7 @@ BackgroundsView::UpdateButtons()
void void
BackgroundsView::RefsReceived(BMessage *msg) BackgroundsView::RefsReceived(BMessage* msg)
{ {
if (!msg->HasRef("refs") && msg->HasRef("dir_ref")) { if (!msg->HasRef("refs") && msg->HasRef("dir_ref")) {
entry_ref dirRef; entry_ref dirRef;
@@ -1007,7 +1009,7 @@ BackgroundsView::RefsReceived(BMessage *msg)
if (!imageType.Contains(&refType)) if (!imageType.Contains(&refType))
continue; continue;
BGImageMenuItem *item; BGImageMenuItem* item;
int32 index = AddImage(path); int32 index = AddImage(path);
if (index >= 0) { if (index >= 0) {
item = FindImageItem(index); item = FindImageItem(index);
@@ -1036,7 +1038,7 @@ BackgroundsView::RefsReceived(BMessage *msg)
BMessenger(this).SendMessage(kMsgCurrentWorkspace); BMessenger(this).SendMessage(kMsgCurrentWorkspace);
break; break;
} }
BMenuItem *item; BMenuItem* item;
int32 index = AddPath(path); int32 index = AddPath(path);
if (index >= 0) { if (index >= 0) {
item = fWorkspaceMenu->ItemAt(index + 6); item = fWorkspaceMenu->ItemAt(index + 6);
@@ -1066,7 +1068,7 @@ BackgroundsView::AddPath(BPath path)
int32 count = fPathList.CountItems(); int32 count = fPathList.CountItems();
int32 index = 0; int32 index = 0;
for (; index < count; index++) { for (; index < count; index++) {
BPath *p = fPathList.ItemAt(index); BPath* p = fPathList.ItemAt(index);
int c = BString(p->Path()).ICompare(path.Path()); int c = BString(p->Path()).ICompare(path.Path());
if (c == 0) if (c == 0)
return index; return index;
@@ -1085,7 +1087,7 @@ BackgroundsView::AddImage(BPath path)
int32 count = fImageList.CountItems(); int32 count = fImageList.CountItems();
int32 index = 0; int32 index = 0;
for (; index < count; index++) { for (; index < count; index++) {
Image *image = fImageList.ItemAt(index); Image* image = fImageList.ItemAt(index);
if (image->GetPath() == path) if (image->GetPath() == path)
return index; return index;
} }
@@ -1106,12 +1108,12 @@ BGImageMenuItem*
BackgroundsView::FindImageItem(const int32 imageIndex) BackgroundsView::FindImageItem(const int32 imageIndex)
{ {
if (imageIndex < 0) if (imageIndex < 0)
return (BGImageMenuItem *)fImageMenu->ItemAt(0); return (BGImageMenuItem*)fImageMenu->ItemAt(0);
int32 count = fImageMenu->CountItems() - 2; int32 count = fImageMenu->CountItems() - 2;
int32 index = 2; int32 index = 2;
for (; index < count; index++) { for (; index < count; index++) {
BGImageMenuItem *image = (BGImageMenuItem *)fImageMenu->ItemAt(index); BGImageMenuItem* image = (BGImageMenuItem*)fImageMenu->ItemAt(index);
if (image->ImageIndex() == imageIndex) if (image->ImageIndex() == imageIndex)
return image; return image;
} }
@@ -1120,7 +1122,7 @@ BackgroundsView::FindImageItem(const int32 imageIndex)
bool bool
BackgroundsView::AddItem(BGImageMenuItem *item) BackgroundsView::AddItem(BGImageMenuItem* item)
{ {
int32 count = fImageMenu->CountItems() - 2; int32 count = fImageMenu->CountItems() - 2;
int32 index = 2; int32 index = 2;
@@ -1130,7 +1132,7 @@ BackgroundsView::AddItem(BGImageMenuItem *item)
} }
for (; index < count; index++) { for (; index < count; index++) {
BGImageMenuItem* image = (BGImageMenuItem *)fImageMenu->ItemAt(index); BGImageMenuItem* image = (BGImageMenuItem*)fImageMenu->ItemAt(index);
int c = (BString(image->Label()).ICompare(BString(item->Label()))); int c = (BString(image->Label()).ICompare(BString(item->Label())));
if (c > 0) if (c > 0)
break; break;
@@ -1217,7 +1219,7 @@ PreView::MouseUp(BPoint point)
void void
PreView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) PreView::MouseMoved(BPoint point, uint32 transit, const BMessage* message)
{ {
if (IsEnabled()) if (IsEnabled())
SetViewCursor(&fMoveHandCursor); SetViewCursor(&fMoveHandCursor);
@@ -1279,8 +1281,8 @@ PreView::MouseMoved(BPoint point, uint32 transit, const BMessage *message)
// #pragma mark - // #pragma mark -
BGImageMenuItem::BGImageMenuItem(const char *label, int32 imageIndex, BGImageMenuItem::BGImageMenuItem(const char* label, int32 imageIndex,
BMessage *message, char shortcut, uint32 modifiers) BMessage* message, char shortcut, uint32 modifiers)
: BMenuItem(label, message, shortcut, modifiers), : BMenuItem(label, message, shortcut, modifiers),
fImageIndex(imageIndex) fImageIndex(imageIndex)
{ {
+98 -84
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2007, Haiku, Inc. All Rights Reserved. * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,8 +9,6 @@
#define BACKGROUNDS_VIEW_H #define BACKGROUNDS_VIEW_H
#include "BackgroundImage.h"
#include <View.h> #include <View.h>
#include <ColorControl.h> #include <ColorControl.h>
#include <Message.h> #include <Message.h>
@@ -31,20 +29,25 @@
#include <StringView.h> #include <StringView.h>
#include <Cursor.h> #include <Cursor.h>
#define SETTINGS_FILE "Backgrounds_settings" #include "BackgroundImage.h"
#define SETTINGS_FILE "Backgrounds_settings"
class ImageFilePanel; class ImageFilePanel;
class BGImageMenuItem : public BMenuItem { class BGImageMenuItem : public BMenuItem {
public: public:
BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message, BGImageMenuItem(const char* label, int32 imageIndex,
char shortcut = 0, uint32 modifiers = 0); BMessage* message, char shortcut = 0,
uint32 modifiers = 0);
int32 ImageIndex() { return fImageIndex; } int32 ImageIndex() { return fImageIndex; }
private: private:
int32 fImageIndex; int32 fImageIndex;
}; };
@@ -61,107 +64,118 @@ enum frame_parts {
class FramePart : public BView { class FramePart : public BView {
public: public:
FramePart(int32 part); FramePart(int32 part);
void Draw(BRect rect); void Draw(BRect rect);
void SetDesktop(bool isDesktop); void SetDesktop(bool isDesktop);
private: private:
void _SetSizeAndAlignment(); void _SetSizeAndAlignment();
int32 fFramePart; int32 fFramePart;
bool fIsDesktop; bool fIsDesktop;
}; };
class PreView : public BControl { class PreView : public BControl {
public: public:
PreView(); PreView();
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,
void AttachedToWindow(); const BMessage* message);
void AttachedToWindow();
BPoint fOldPoint; BPoint fOldPoint;
float x_ratio, y_ratio; float x_ratio;
display_mode mode; float y_ratio;
display_mode mode;
BCursor fMoveHandCursor; BCursor fMoveHandCursor;
}; };
class BackgroundsView : public BBox { class BackgroundsView : public BBox {
public: public:
BackgroundsView(); BackgroundsView();
~BackgroundsView(); ~BackgroundsView();
void RefsReceived(BMessage* msg); void RefsReceived(BMessage* msg);
void SaveSettings(); void SaveSettings();
void WorkspaceActivated(uint32 oldWorkspaces, bool active); void WorkspaceActivated(uint32 oldWorkspaces,
int32 AddImage(BPath path); bool active);
Image* GetImage(int32 imageIndex); int32 AddImage(BPath path);
Image* GetImage(int32 imageIndex);
bool FoundPositionSetting(); bool FoundPositionSetting();
protected: protected:
void Save(); void Save();
void NotifyServer(); void NotifyServer();
void LoadSettings(); void LoadSettings();
void AllAttached(); void AllAttached();
void MessageReceived(BMessage *msg); void MessageReceived(BMessage* msg);
void LoadDesktopFolder(); void LoadDesktopFolder();
void LoadDefaultFolder(); void LoadDefaultFolder();
void LoadFolder(bool isDesktop); void LoadFolder(bool isDesktop);
void LoadRecentFolder(BPath path); void LoadRecentFolder(BPath path);
void UpdateWithCurrent(); void UpdateWithCurrent();
void UpdatePreview(); void UpdatePreview();
void UpdateButtons(); void UpdateButtons();
void SetDesktop(bool isDesktop); void SetDesktop(bool isDesktop);
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);
BackgroundImage::Mode FindPlacementMode(); bool AddItem(BGImageMenuItem* item);
BColorControl *fPicker; // color picker BackgroundImage::Mode FindPlacementMode();
BButton *fApply, *fRevert; // apply and revert buttons
BCheckBox *fIconLabelOutline; // label ckeckbox
BMenu* fPlacementMenu, *fImageMenu, *fWorkspaceMenu; // the three comboboxes
BTextControl *fXPlacementText, *fYPlacementText; // x and y textboxes
PreView *fPreView; // the view for previewing the result
BBox *fPreview; // the box which draws a computer/folder
BFilePanel *fFolderPanel; // the file panels for folders
ImageFilePanel *fPanel; // the file panels for images
BackgroundImage *fCurrent; // the current BackgroundImage object BColorControl* fPicker;
BackgroundImage::BackgroundImageInfo *fCurrentInfo;//the current BackgroundImageInfo object BButton* fApply;
entry_ref fCurrentRef; // the entry for the node which holds current BButton* fRevert;
int32 fLastImageIndex, fLastWorkspaceIndex; // last indexes for cancel BCheckBox* fIconLabelOutline;
BMessage fSettings; // settings loaded from settings directory BMenu* fPlacementMenu;
BMenu* fImageMenu;
BMenu* fWorkspaceMenu;
BTextControl* fXPlacementText;
BTextControl* fYPlacementText;
PreView* fPreView;
BBox* fPreview;
BFilePanel* fFolderPanel;
ImageFilePanel* fPanel;
BObjectList<BPath> fPathList; BackgroundImage* fCurrent;
BObjectList<Image> fImageList;
FramePart* fTopLeft; BackgroundImage::BackgroundImageInfo* fCurrentInfo;
FramePart* fTop;
FramePart* fTopRight;
FramePart* fLeft;
FramePart* fRight;
FramePart* fBottomLeft;
FramePart* fBottom;
FramePart* fBottomRight;
bool fFoundPositionSetting; entry_ref fCurrentRef;
int32 fLastImageIndex;
int32 fLastWorkspaceIndex;
BMessage fSettings;
BObjectList<BPath> fPathList;
BObjectList<Image> fImageList;
FramePart* fTopLeft;
FramePart* fTop;
FramePart* fTopRight;
FramePart* fLeft;
FramePart* fRight;
FramePart* fBottomLeft;
FramePart* fBottom;
FramePart* fBottomRight;
bool fFoundPositionSetting;
}; };
#endif // BACKGROUNDS_VIEW_H #endif // BACKGROUNDS_VIEW_H
+46 -35
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved. * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -17,10 +17,10 @@
#include <Window.h> #include <Window.h>
ImageFilePanel::ImageFilePanel(file_panel_mode mode, BMessenger *target, ImageFilePanel::ImageFilePanel(file_panel_mode mode, BMessenger* target,
const entry_ref *startDirectory, uint32 nodeFlavors, const entry_ref* startDirectory, uint32 nodeFlavors,
bool allowMultipleSelection, BMessage* message, BRefFilter* filter, bool allowMultipleSelection, BMessage* message, BRefFilter* filter,
bool modal, bool hideWhenDone) bool modal, bool hideWhenDone)
: BFilePanel(mode, target, startDirectory, nodeFlavors, : BFilePanel(mode, target, startDirectory, nodeFlavors,
allowMultipleSelection, message, filter, modal, hideWhenDone), allowMultipleSelection, message, filter, modal, hideWhenDone),
fImageView(NULL), fImageView(NULL),
@@ -42,35 +42,43 @@ ImageFilePanel::Show()
{ {
if (fImageView == NULL) { if (fImageView == NULL) {
Window()->Lock(); Window()->Lock();
BView *background = Window()->ChildAt(0); BView* background = Window()->ChildAt(0);
uint32 poseViewResizingMode = uint32 poseViewResizingMode
background->FindView("PoseView")->ResizingMode(); = background->FindView("PoseView")->ResizingMode();
uint32 countVwResizingMode = uint32 countVwResizingMode
background->FindView("CountVw")->ResizingMode(); = background->FindView("CountVw")->ResizingMode();
uint32 vScrollBarResizingMode = uint32 vScrollBarResizingMode
background->FindView("VScrollBar")->ResizingMode(); = background->FindView("VScrollBar")->ResizingMode();
uint32 hScrollBarResizingMode = uint32 hScrollBarResizingMode
background->FindView("HScrollBar")->ResizingMode(); = background->FindView("HScrollBar")->ResizingMode();
background->FindView("PoseView")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); background->FindView("PoseView")
background->FindView("CountVw")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); ->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP);
background->FindView("VScrollBar")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); background->FindView("CountVw")
background->FindView("HScrollBar")->SetResizingMode(B_FOLLOW_LEFT | B_FOLLOW_TOP); ->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); Window()->ResizeBy(0, 70);
background->FindView("PoseView")->SetResizingMode(poseViewResizingMode); background->FindView("PoseView")->SetResizingMode(poseViewResizingMode);
background->FindView("CountVw")->SetResizingMode(countVwResizingMode); background->FindView("CountVw")->SetResizingMode(countVwResizingMode);
background->FindView("VScrollBar")->SetResizingMode(vScrollBarResizingMode); background->FindView("VScrollBar")
background->FindView("HScrollBar")->SetResizingMode(hScrollBarResizingMode); ->SetResizingMode(vScrollBarResizingMode);
background->FindView("HScrollBar")
->SetResizingMode(hScrollBarResizingMode);
BRect rect(background->Bounds().left + 15, background->Bounds().bottom - 94, BRect rect(background->Bounds().left + 15,
background->Bounds().left + 122, background->Bounds().bottom - 15); background->Bounds().bottom - 94, background->Bounds().left + 122,
fImageView = new BView(rect, "ImageView", B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, background->Bounds().bottom - 15);
B_SUBPIXEL_PRECISE); fImageView = new BView(rect, "ImageView",
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_SUBPIXEL_PRECISE);
fImageView->SetViewColor(background->ViewColor()); fImageView->SetViewColor(background->ViewColor());
background->AddChild(fImageView); background->AddChild(fImageView);
rect = BRect(background->Bounds().left + 132, background->Bounds().bottom - 85, rect = BRect(background->Bounds().left + 132,
background->Bounds().right, background->Bounds().bottom - 65); background->Bounds().bottom - 85, background->Bounds().right,
background->Bounds().bottom - 65);
fResolutionView = new BStringView(rect, "ResolutionView", NULL, fResolutionView = new BStringView(rect, "ResolutionView", NULL,
B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
background->AddChild(fResolutionView); background->AddChild(fResolutionView);
@@ -99,24 +107,27 @@ ImageFilePanel::SelectionChanged()
fImageView->ClearViewBitmap(); fImageView->ClearViewBitmap();
if (node.IsFile()) { if (node.IsFile()) {
BBitmap *bitmap = BTranslationUtils::GetBitmap(&ref); BBitmap* bitmap = BTranslationUtils::GetBitmap(&ref);
if (bitmap != NULL) { if (bitmap != NULL) {
BRect dest(fImageView->Bounds()); BRect dest(fImageView->Bounds());
if (bitmap->Bounds().Width() > bitmap->Bounds().Height()) { if (bitmap->Bounds().Width() > bitmap->Bounds().Height()) {
dest.InsetBy(0, (dest.Height() + 1 - dest.InsetBy(0, (dest.Height() + 1
((bitmap->Bounds().Height() + 1) / - ((bitmap->Bounds().Height() + 1)
(bitmap->Bounds().Width() + 1) *(dest.Width() + 1))) / 2); / (bitmap->Bounds().Width() + 1)
* (dest.Width() + 1))) / 2);
} else { } else {
dest.InsetBy((dest.Width() + 1 - dest.InsetBy((dest.Width() + 1
((bitmap->Bounds().Width() + 1) / - ((bitmap->Bounds().Width() + 1)
(bitmap->Bounds().Height() + 1) *(dest.Height() + 1))) / 2, 0); / (bitmap->Bounds().Height() + 1)
* (dest.Height() + 1))) / 2, 0);
} }
fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest, fImageView->SetViewBitmap(bitmap, bitmap->Bounds(), dest,
B_FOLLOW_LEFT | B_FOLLOW_TOP, 0); B_FOLLOW_LEFT | B_FOLLOW_TOP, 0);
BString resolution; BString resolution;
resolution << "Resolution: " << (int)(bitmap->Bounds().Width() + 1) resolution << "Resolution: "
<< (int)(bitmap->Bounds().Width() + 1)
<< "x" << (int)(bitmap->Bounds().Height() + 1); << "x" << (int)(bitmap->Bounds().Height() + 1);
fResolutionView->SetText(resolution.String()); fResolutionView->SetText(resolution.String());
delete bitmap; delete bitmap;
@@ -161,8 +172,8 @@ CustomRefFilter::CustomRefFilter(bool imageFiltering)
bool bool
CustomRefFilter::Filter(const entry_ref *ref, BNode* node, CustomRefFilter::Filter(const entry_ref* ref, BNode* node,
struct stat_beos *stat, const char *filetype) struct stat_beos* stat, const char* filetype)
{ {
if (!fImageFiltering) if (!fImageFiltering)
return node->IsDirectory(); return node->IsDirectory();
+30 -23
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2005, Haiku, Inc. All Rights Reserved. * Copyright 2002-2009, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -9,43 +9,50 @@
#define IMAGE_FILE_PANEL_H #define IMAGE_FILE_PANEL_H
#include <Node.h>
#include <FilePanel.h> #include <FilePanel.h>
#include <Node.h>
class BStringView; class BStringView;
class BView; class BView;
class CustomRefFilter : public BRefFilter { class CustomRefFilter : public BRefFilter {
public: public:
CustomRefFilter(bool imageFiltering); CustomRefFilter(bool imageFiltering);
virtual ~CustomRefFilter() {}; virtual ~CustomRefFilter() {};
bool Filter(const entry_ref *ref, BNode* node, struct stat_beos *st, bool Filter(const entry_ref* ref, BNode* node,
const char *filetype); struct stat_beos* st, const char* filetype);
protected: protected:
bool fImageFiltering; // true for images only, false for directory only bool fImageFiltering;
// true for images
// false for directory
}; };
class ImageFilePanel : public BFilePanel { class ImageFilePanel : public BFilePanel {
public: public:
ImageFilePanel(file_panel_mode mode = B_OPEN_PANEL, ImageFilePanel(file_panel_mode mode = B_OPEN_PANEL,
BMessenger* target = NULL, const entry_ref* startDirectory = NULL, BMessenger* target = NULL,
uint32 nodeFlavors = 0, bool allowMultipleSelection = true, const entry_ref* startDirectory = NULL,
BMessage* message = NULL, BRefFilter* filter = NULL, uint32 nodeFlavors = 0,
bool modal = false, bool hideWhenDone = true); bool allowMultipleSelection = true,
~ImageFilePanel(); BMessage* message = NULL,
BRefFilter* filter = NULL,
bool modal = false,
bool hideWhenDone = true);
~ImageFilePanel();
virtual void SelectionChanged(); virtual void SelectionChanged();
void Show();
void Show(); protected:
BView* fImageView;
protected: BStringView* fResolutionView;
BView* fImageView; BStringView* fImageTypeView;
BStringView* fResolutionView;
BStringView* fImageTypeView;
}; };
#endif // IMAGE_FILE_PANEL_H #endif // IMAGE_FILE_PANEL_H
-1
View File
@@ -13,4 +13,3 @@ Preference Backgrounds :
: Backgrounds.rdef : Backgrounds.rdef
; ;