From cd2d1ffddaf52a626186ee4b15320e9415fe5d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 29 Dec 2005 13:37:52 +0000 Subject: [PATCH] * 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 --- src/preferences/backgrounds/BGMain.cpp | 40 - src/preferences/backgrounds/BGMain.h | 23 - src/preferences/backgrounds/BGWindow.cpp | 42 - src/preferences/backgrounds/BGWindow.h | 31 - .../backgrounds/BackgroundImage.cpp | 183 ++-- src/preferences/backgrounds/BackgroundImage.h | 21 +- src/preferences/backgrounds/Backgrounds.cpp | 122 +++ .../{BGView.cpp => BackgroundsView.cpp} | 989 ++++++++---------- .../{BGView.h => BackgroundsView.h} | 104 +- .../backgrounds/ImageFilePanel.cpp | 166 +++ src/preferences/backgrounds/ImageFilePanel.h | 48 + src/preferences/backgrounds/Jamfile | 8 +- 12 files changed, 905 insertions(+), 872 deletions(-) delete mode 100644 src/preferences/backgrounds/BGMain.cpp delete mode 100644 src/preferences/backgrounds/BGMain.h delete mode 100644 src/preferences/backgrounds/BGWindow.cpp delete mode 100644 src/preferences/backgrounds/BGWindow.h create mode 100644 src/preferences/backgrounds/Backgrounds.cpp rename src/preferences/backgrounds/{BGView.cpp => BackgroundsView.cpp} (54%) rename src/preferences/backgrounds/{BGView.h => BackgroundsView.h} (64%) create mode 100644 src/preferences/backgrounds/ImageFilePanel.cpp create mode 100644 src/preferences/backgrounds/ImageFilePanel.h diff --git a/src/preferences/backgrounds/BGMain.cpp b/src/preferences/backgrounds/BGMain.cpp deleted file mode 100644 index f36b612639..0000000000 --- a/src/preferences/backgrounds/BGMain.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - -"Backgrounds" by Jerome Duval (jerome.duval@free.fr) - -(C)2002 OpenBeOS under MIT license - -*/ - -#include "BGMain.h" -#include - -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); -} diff --git a/src/preferences/backgrounds/BGMain.h b/src/preferences/backgrounds/BGMain.h deleted file mode 100644 index 759b474c40..0000000000 --- a/src/preferences/backgrounds/BGMain.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - -"Backgrounds" by Jerome Duval (jerome.duval@free.fr) - -(C)2002 OpenBeOS under MIT license - -*/ - -#ifndef BG_WORLD_H -#define BG_WORLD_H - -#include -#include "BGWindow.h" - -#define APP_SIGNATURE "application/x-vnd.haiku.Backgrounds" - -class BGApplication : public BApplication { - public: - BGApplication(); - BGWindow *fBGWin; -}; - -#endif diff --git a/src/preferences/backgrounds/BGWindow.cpp b/src/preferences/backgrounds/BGWindow.cpp deleted file mode 100644 index a96bd0524f..0000000000 --- a/src/preferences/backgrounds/BGWindow.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - -"Backgrounds" by Jerome Duval (jerome.duval@free.fr) - -(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); -} diff --git a/src/preferences/backgrounds/BGWindow.h b/src/preferences/backgrounds/BGWindow.h deleted file mode 100644 index 2112acedf0..0000000000 --- a/src/preferences/backgrounds/BGWindow.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - -"Backgrounds" by Jerome Duval (jerome.duval@free.fr) - -(C)2002 OpenBeOS under MIT license - -*/ - -#ifndef BG_WINDOW_H -#define BG_WINDOW_H - -#include -#include -#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 diff --git a/src/preferences/backgrounds/BackgroundImage.cpp b/src/preferences/backgrounds/BackgroundImage.cpp index 1b9c03c178..b1803e2680 100644 --- a/src/preferences/backgrounds/BackgroundImage.cpp +++ b/src/preferences/backgrounds/BackgroundImage.cpp @@ -49,8 +49,8 @@ All rights reserved. #include #include -#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; } diff --git a/src/preferences/backgrounds/BackgroundImage.h b/src/preferences/backgrounds/BackgroundImage.h index c49e8192e2..facac43536 100644 --- a/src/preferences/backgrounds/BackgroundImage.h +++ b/src/preferences/backgrounds/BackgroundImage.h @@ -40,6 +40,8 @@ All rights reserved. #include "String.h" #include "ObjectList.h" + +#include #include #include @@ -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 fBitmapForWorkspaceList; diff --git a/src/preferences/backgrounds/Backgrounds.cpp b/src/preferences/backgrounds/Backgrounds.cpp new file mode 100644 index 0000000000..3bdd3fb915 --- /dev/null +++ b/src/preferences/backgrounds/Backgrounds.cpp @@ -0,0 +1,122 @@ +/* + * Copyright 2002-2005, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jerome Duval (jerome.duval@free.fr) + * Axel Dörfler, axeld@pinc-software.de + */ + + +#include "BackgroundsView.h" + +#include +#include +#include + + +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; +} + + diff --git a/src/preferences/backgrounds/BGView.cpp b/src/preferences/backgrounds/BackgroundsView.cpp similarity index 54% rename from src/preferences/backgrounds/BGView.cpp rename to src/preferences/backgrounds/BackgroundsView.cpp index bb888c053c..f0af8486cc 100644 --- a/src/preferences/backgrounds/BGView.cpp +++ b/src/preferences/backgrounds/BackgroundsView.cpp @@ -1,16 +1,14 @@ /* + * Copyright 2002-2005, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Jerome Duval (jerome.duval@free.fr) + */ -"Backgrounds" by Jerome Duval (jerome.duval@free.fr) -(C)2002 OpenBeOS under MIT license - -*/ - -/* - BGView.cpp -*/ - -#include "BGView.h" +#include "BackgroundsView.h" +#include "ImageFilePanel.h" #include #include @@ -50,12 +48,10 @@ #define XY_PLACEMENT 'xypl' #define PREVIEW_PLACEMENT 'pvpl' -void SetRGBColor(rgb_color *col,uint8 r, uint8 g, uint8 b, uint8 a=255); -uint8 hand_cursor_data[68] = -{ - 16,1,2,2, - +const uint8 kHandCursorData[68] = { + 16, 1, 2, 2, + 0,0, // 0000000000000000 7,128, // 0000011110000000 61,112, // 0011110101110000 @@ -72,7 +68,7 @@ uint8 hand_cursor_data[68] = 12,1, // 0000110000000001 2,0, // 0000001000000000 1,0, // 0000000100000000 - + 0,0, // 0000000000000000 7,128, // 0000011110000000 63,240, // 0011111111110000 @@ -91,20 +87,22 @@ uint8 hand_cursor_data[68] = 1,248 // 0000000111111000 }; -BGView::BGView(BRect frame, const char *name, int32 resize, int32 flags) - :BBox(frame, name, resize, flags | B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER), - fCurrent(NULL), - fCurrentInfo(NULL), - fLastImageIndex(-1), - fPathList(1, true), - fImageList(1, true) + +BackgroundsView::BackgroundsView(BRect frame, const char *name, int32 resize, int32 flags) + : BBox(frame, name, resize, + flags | B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER), + fCurrent(NULL), + fCurrentInfo(NULL), + fLastImageIndex(-1), + fPathList(1, true), + fImageList(1, true) { // SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - + /* the preview box */ - + BFont font(be_plain_font); - fPreview = new PreviewBox(BRect(10,16,160,180), "preview"); + fPreview = new PreviewBox(BRect(10, 16, 160, 180), "preview"); fPreview->SetFont(&font); fPreview->SetLabel("Preview"); AddChild(fPreview); @@ -115,42 +113,43 @@ BGView::BGView(BRect frame, const char *name, int32 resize, int32 flags) fXPlacementText->SetDivider(12.0); fXPlacementText->TextView()->SetMaxBytes(4); fPreview->AddChild(fXPlacementText); - + xyrect.OffsetBy(65, 0); fYPlacementText = new BTextControl(xyrect, "yPlacementText", "Y:", NULL, new BMessage(XY_PLACEMENT)); fYPlacementText->SetDivider(12.0); fYPlacementText->TextView()->SetMaxBytes(4); fPreview->AddChild(fYPlacementText); - - for(int i=0; i<256; i++) - if(i<'0'||i>'9') { + + for (int i = 0; i < 256; i++) { + if (i < '0' || i > '9') { fXPlacementText->TextView()->DisallowChar(i); fYPlacementText->TextView()->DisallowChar(i); } - + } + fPreView = new PreView(BRect(15,25,135,115), "preView", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_SUBPIXEL_PRECISE); fPreview->AddChild(fPreView); - + /* the right box */ - - BBox *rightbox = new BBox(BRect(fPreview->Frame().right+10, - fPreview->Frame().top-6,this->Frame().right-10,fPreview->Frame().bottom), + + BBox *rightbox = new BBox(BRect(fPreview->Frame().right + 10, + fPreview->Frame().top - 6, Frame().right - 10, fPreview->Frame().bottom), "rightbox"); AddChild(rightbox); - - fPicker=new BColorControl(BPoint(10, 110),B_CELLS_32x8,5.0,"Picker", + + fPicker = new BColorControl(BPoint(10, 110), B_CELLS_32x8, 5.0, "Picker", new BMessage(UPDATE_COLOR)); rightbox->AddChild(fPicker); - + BRect cvrect(80, 76, 280, 96); fIconLabelBackground = new BCheckBox(cvrect, "iconLabelBackground", "Icon label background", new BMessage(ICONLABEL_CHECKBOX)); fIconLabelBackground->SetValue(B_CONTROL_ON); rightbox->AddChild(fIconLabelBackground); - + BMenuItem *menuItem; fWorkspaceMenu = new BPopUpMenu("pick one"); fWorkspaceMenu->AddItem(menuItem = new BMenuItem("All Workspaces", @@ -164,12 +163,12 @@ BGView::BGView(BRect frame, const char *name, int32 resize, int32 flags) new BMessage(DEFAULT_FOLDER))); fWorkspaceMenu->AddItem(menuItem = new BMenuItem("Other folder" B_UTF8_ELLIPSIS, new BMessage(OTHER_FOLDER))); - + fImageMenu = new BPopUpMenu("pick one"); fImageMenu->AddItem(new BGImageMenuItem("None", -1, new BMessage(NONE_IMAGE))); fImageMenu->AddSeparatorItem(); fImageMenu->AddItem(new BMenuItem("Other" B_UTF8_ELLIPSIS, new BMessage(OTHER_IMAGE))); - + fPlacementMenu = new BPopUpMenu("pick one"); fPlacementMenu->AddItem(new BMenuItem("Manual", new BMessage(MANUAL_PLACEMENT))); @@ -179,14 +178,14 @@ BGView::BGView(BRect frame, const char *name, int32 resize, int32 flags) new BMessage(SCALE_PLACEMENT))); fPlacementMenu->AddItem(new BMenuItem("Tile", new BMessage(TILE_PLACEMENT))); - + cvrect.OffsetBy(-70, -25); BMenuField *placementMenuField = new BMenuField(cvrect, "placementMenuField", "Placement:", fPlacementMenu); placementMenuField->SetDivider(70.0); placementMenuField->SetAlignment(B_ALIGN_RIGHT); rightbox->AddChild(placementMenuField); - + cvrect.OffsetBy(0, -25); BRect imageRect = cvrect; imageRect.right += 40; @@ -195,29 +194,28 @@ BGView::BGView(BRect frame, const char *name, int32 resize, int32 flags) imageMenuField->SetDivider(70.0); imageMenuField->SetAlignment(B_ALIGN_RIGHT); rightbox->AddChild(imageMenuField); - + cvrect.right -= 70; cvrect.bottom -= 2; BMenuField *workspaceMenuField = new BMenuField(cvrect, "workspaceMenuField", NULL, fWorkspaceMenu, true); rightbox->SetLabel(workspaceMenuField); - - fRevert=new BButton(BRect(fPreview->Frame().left, fPreview->Frame().bottom+10, - fPreview->Frame().left+80, this->Frame().bottom-10),"RevertButton", - "Revert", new BMessage(REVERT_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, + + fRevert = new BButton(BRect(fPreview->Frame().left, fPreview->Frame().bottom + 10, + fPreview->Frame().left + 80, Frame().bottom - 10), "RevertButton", + "Revert", new BMessage(REVERT_SETTINGS), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); AddChild(fRevert); - - fApply=new BButton(BRect(rightbox->Frame().right-70, fPreview->Frame().bottom - +10,rightbox->Frame().right,110),"ApplyButton","Apply", - new BMessage(APPLY_SETTINGS),B_FOLLOW_LEFT |B_FOLLOW_TOP, + + fApply = new BButton(BRect(rightbox->Frame().right - 70, fPreview->Frame().bottom + + 10, rightbox->Frame().right, 110), "ApplyButton", "Apply", + new BMessage(APPLY_SETTINGS), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_NAVIGABLE); AddChild(fApply); - } -BGView::~BGView(void) +BackgroundsView::~BackgroundsView() { delete fPanel; delete fFolderPanel; @@ -225,7 +223,7 @@ BGView::~BGView(void) void -BGView::AllAttached(void) +BackgroundsView::AllAttached() { fPlacementMenu->SetTargetForItems(this); fImageMenu->SetTargetForItems(this); @@ -236,31 +234,29 @@ BGView::AllAttached(void) fPicker->SetTarget(this); fApply->SetTarget(this); fRevert->SetTarget(this); - + fPanel = new ImageFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, B_FILE_NODE, false, NULL, new CustomRefFilter(true)); fPanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select"); - + fFolderPanel = new BFilePanel(B_OPEN_PANEL, new BMessenger(this), NULL, B_DIRECTORY_NODE, false, NULL, new CustomRefFilter(false)); fFolderPanel->SetButtonLabel(B_DEFAULT_BUTTON, "Select"); - + LoadSettings(); LoadDesktopFolder(); } void -BGView::MessageReceived(BMessage *msg) +BackgroundsView::MessageReceived(BMessage *msg) { - switch(msg->what) - { + switch (msg->what) { case B_SIMPLE_DATA: case B_REFS_RECEIVED: - { RefsReceived(msg); break; - } + case PREVIEW_PLACEMENT: { BString xstring, ystring; @@ -272,92 +268,82 @@ BGView::MessageReceived(BMessage *msg) UpdateButtons(); break; } + case MANUAL_PLACEMENT: - { UpdatePreview(); UpdateButtons(); break; - } + case TILE_PLACEMENT: case SCALE_PLACEMENT: case CENTER_PLACEMENT: - { UpdatePreview(); UpdateButtons(); break; - } + case ICONLABEL_CHECKBOX: - { UpdateButtons(); break; - } + case UPDATE_COLOR: case XY_PLACEMENT: - { UpdatePreview(); UpdateButtons(); break; - } + case CURRENT_WORKSPACE: case ALL_WORKSPACES: - { fImageMenu->FindItem(NONE_IMAGE)->SetLabel("None"); fLastWorkspaceIndex = fWorkspaceMenu->IndexOf( fWorkspaceMenu->FindMarked()); - if(!fCurrent->IsDesktop()) { + if (!fCurrent->IsDesktop()) { fPreview->SetDesktop(true); LoadDesktopFolder(); } else UpdateButtons(); break; - } + case DEFAULT_FOLDER: - { fImageMenu->FindItem(NONE_IMAGE)->SetLabel("None"); fLastWorkspaceIndex = fWorkspaceMenu->IndexOf( fWorkspaceMenu->FindMarked()); fPreview->SetDesktop(false); LoadDefaultFolder(); break; - } + case OTHER_FOLDER: - { fFolderPanel->Show(); break; - } + case OTHER_IMAGE: - { fPanel->Show(); break; - } + case B_CANCEL: { PRINT(("cancel received\n")); void* pointer; msg->FindPointer("source", &pointer); - if(pointer == fPanel) { - if(fLastImageIndex>=0) + if (pointer == fPanel) { + if (fLastImageIndex >= 0) FindImageItem(fLastImageIndex)->SetMarked(true); else fImageMenu->ItemAt(0)->SetMarked(true); - } - else if(pointer == fFolderPanel) { - if(fLastWorkspaceIndex>=0) + } else if (pointer == fFolderPanel) { + if (fLastWorkspaceIndex >= 0) fWorkspaceMenu->ItemAt(fLastWorkspaceIndex)->SetMarked(true); } break; } + case IMAGE_SELECTED: case NONE_IMAGE: - { - fLastImageIndex = ((BGImageMenuItem*)fImageMenu->FindMarked()) - ->ImageIndex(); + fLastImageIndex = ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex(); UpdatePreview(); UpdateButtons(); break; - } + case FOLDER_SELECTED: - { fImageMenu->FindItem(NONE_IMAGE)->SetLabel("Default"); fLastWorkspaceIndex = fWorkspaceMenu->IndexOf( fWorkspaceMenu->FindMarked()); @@ -365,23 +351,22 @@ BGView::MessageReceived(BMessage *msg) LoadRecentFolder(*fPathList.ItemAt(fWorkspaceMenu->IndexOf( fWorkspaceMenu->FindMarked()) - 6)); break; - } + case APPLY_SETTINGS: { Save(); //NotifyServer(); thread_id notify_thread; - notify_thread = spawn_thread(BGView::NotifyThread, "notifyServer", + notify_thread = spawn_thread(BackgroundsView::NotifyThread, "notifyServer", B_NORMAL_PRIORITY, this); resume_thread(notify_thread); UpdateButtons(); break; } case REVERT_SETTINGS: - { UpdateWithCurrent(); break; - } + default: BView::MessageReceived(msg); break; @@ -390,13 +375,13 @@ BGView::MessageReceived(BMessage *msg) void -BGView::LoadDesktopFolder(void) +BackgroundsView::LoadDesktopFolder() { BPath path; - if(find_directory(B_DESKTOP_DIRECTORY, &path) == B_OK) { + if (find_directory(B_DESKTOP_DIRECTORY, &path) == B_OK) { status_t err; - err = get_ref_for_path(path.Path(), &fCurrent_ref); - if(err!=B_OK) + err = get_ref_for_path(path.Path(), &fCurrentRef); + if (err != B_OK) printf("error in LoadDesktopSettings\n"); LoadFolder(true); } @@ -404,15 +389,15 @@ BGView::LoadDesktopFolder(void) void -BGView::LoadDefaultFolder(void) +BackgroundsView::LoadDefaultFolder() { BPath path; - if(find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { BString pathString = path.Path(); pathString << "/Tracker/DefaultFolderTemplate"; status_t err; - err = get_ref_for_path(pathString.String(), &fCurrent_ref); - if(err!=B_OK) + err = get_ref_for_path(pathString.String(), &fCurrentRef); + if (err != B_OK) printf("error in LoadDefaultFolderSettings\n"); LoadFolder(false); } @@ -420,144 +405,138 @@ BGView::LoadDefaultFolder(void) void -BGView::LoadRecentFolder(BPath path) +BackgroundsView::LoadRecentFolder(BPath path) { status_t err; - err = get_ref_for_path(path.Path(), &fCurrent_ref); - if(err!=B_OK) + err = get_ref_for_path(path.Path(), &fCurrentRef); + if (err != B_OK) printf("error in LoadRecentFolder\n"); LoadFolder(false); } void -BGView::LoadFolder(bool isDesktop) +BackgroundsView::LoadFolder(bool isDesktop) { - if(fCurrent) { + if (fCurrent) { delete fCurrent; fCurrent = NULL; } - BNode node(&fCurrent_ref); - if(node.InitCheck() == B_OK) { + + BNode node(&fCurrentRef); + if (node.InitCheck() == B_OK) fCurrent = BackgroundImage::GetBackgroundImage(&node, isDesktop, this); - } else { - printf("pb with the folder node\n"); - } + UpdateWithCurrent(); } void -BGView::UpdateWithCurrent(void) +BackgroundsView::UpdateWithCurrent(void) { - if(!fCurrent) - printf("current null\n"); - if(fCurrent) { - fPlacementMenu->FindItem(SCALE_PLACEMENT)->SetEnabled(fCurrent->IsDesktop()); - fPlacementMenu->FindItem(CENTER_PLACEMENT)->SetEnabled(fCurrent->IsDesktop()); - - if(fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked())>5) - fImageMenu->FindItem(NONE_IMAGE)->SetLabel("Default"); - else - fImageMenu->FindItem(NONE_IMAGE)->SetLabel("None"); - - for(int32 i=fImageMenu->CountItems()-5; i>=0; i--) - fImageMenu->RemoveItem(2); - - for(int32 i=fImageList.CountItems()-1; i>=0; i--) { - BMessage *message = new BMessage(IMAGE_SELECTED); - AddItem(new BGImageMenuItem(GetImage(i)->GetName(), i, message)); - } - - fImageMenu->SetTargetForItems(this); - - fCurrentInfo = fCurrent->ImageInfoForWorkspace(current_workspace()); - - if(!fCurrentInfo) { - - fImageMenu->FindItem(NONE_IMAGE)->SetMarked(true); - fPlacementMenu->FindItem(MANUAL_PLACEMENT)->SetMarked(true); - - } else { - if(fCurrentInfo->fEraseTextWidgetBackground) - fIconLabelBackground->SetValue(B_CONTROL_ON); - else - fIconLabelBackground->SetValue(B_CONTROL_OFF); - - BString xtext, ytext; - int32 cmd = 0; - switch(fCurrentInfo->fMode) - { - case BackgroundImage::kCentered: - cmd = CENTER_PLACEMENT; - break; - case BackgroundImage::kScaledToFit: - cmd = SCALE_PLACEMENT; - break; - case BackgroundImage::kAtOffset: - cmd = MANUAL_PLACEMENT; - xtext << (int)fCurrentInfo->fOffset.x; - ytext << (int)fCurrentInfo->fOffset.y; - break; - case BackgroundImage::kTiled: - cmd = TILE_PLACEMENT; - break; - } - if(cmd!=0) - fPlacementMenu->FindItem(cmd)->SetMarked(true); - fXPlacementText->SetText(xtext.String()); - fYPlacementText->SetText(ytext.String()); - - fLastImageIndex = fCurrentInfo->fImageIndex; - FindImageItem(fLastImageIndex)->SetMarked(true); - } - - rgb_color color; - if(fCurrent->IsDesktop()) { - color = BScreen().DesktopColor(); - fPicker->SetEnabled(true); - } else { - SetRGBColor(&color,255,255,255); - fPicker->SetEnabled(false); - } - fPicker->SetValue(color); - - UpdatePreview(); - UpdateButtons(); + if (fCurrent == NULL) + return; + + fPlacementMenu->FindItem(SCALE_PLACEMENT)->SetEnabled(fCurrent->IsDesktop()); + fPlacementMenu->FindItem(CENTER_PLACEMENT)->SetEnabled(fCurrent->IsDesktop()); + + if (fWorkspaceMenu->IndexOf(fWorkspaceMenu->FindMarked()) > 5) + fImageMenu->FindItem(NONE_IMAGE)->SetLabel("Default"); + else + fImageMenu->FindItem(NONE_IMAGE)->SetLabel("None"); + + for (int32 i = fImageMenu->CountItems() - 5; i >= 0; i--) { + fImageMenu->RemoveItem(2); } + + for (int32 i = fImageList.CountItems() - 1; i >= 0; i--) { + BMessage *message = new BMessage(IMAGE_SELECTED); + AddItem(new BGImageMenuItem(GetImage(i)->GetName(), i, message)); + } + + fImageMenu->SetTargetForItems(this); + + fCurrentInfo = fCurrent->ImageInfoForWorkspace(current_workspace()); + + if (!fCurrentInfo) { + fImageMenu->FindItem(NONE_IMAGE)->SetMarked(true); + fPlacementMenu->FindItem(MANUAL_PLACEMENT)->SetMarked(true); + } else { + fIconLabelBackground->SetValue(fCurrentInfo->fEraseTextWidgetBackground + ? B_CONTROL_ON : B_CONTROL_OFF); + + BString xtext, ytext; + int32 cmd = 0; + switch (fCurrentInfo->fMode) { + case BackgroundImage::kCentered: + cmd = CENTER_PLACEMENT; + break; + case BackgroundImage::kScaledToFit: + cmd = SCALE_PLACEMENT; + break; + case BackgroundImage::kAtOffset: + cmd = MANUAL_PLACEMENT; + xtext << (int)fCurrentInfo->fOffset.x; + ytext << (int)fCurrentInfo->fOffset.y; + break; + case BackgroundImage::kTiled: + cmd = TILE_PLACEMENT; + break; + } + + if (cmd != 0) + fPlacementMenu->FindItem(cmd)->SetMarked(true); + + fXPlacementText->SetText(xtext.String()); + fYPlacementText->SetText(ytext.String()); + + fLastImageIndex = fCurrentInfo->fImageIndex; + FindImageItem(fLastImageIndex)->SetMarked(true); + } + + rgb_color color = {255, 255, 255, 255}; + if (fCurrent->IsDesktop()) { + color = BScreen().DesktopColor(); + fPicker->SetEnabled(true); + } else + fPicker->SetEnabled(false); + + fPicker->SetValue(color); + + UpdatePreview(); + UpdateButtons(); } void -BGView::Save() +BackgroundsView::Save() { bool eraseTextWidgetBackground = - (fIconLabelBackground->Value()==B_CONTROL_ON); + fIconLabelBackground->Value() == B_CONTROL_ON; BackgroundImage::Mode mode = FindPlacementMode(); BPoint offset(atoi(fXPlacementText->Text()), atoi(fYPlacementText->Text())); - if(!fCurrent->IsDesktop()) { - if(fCurrentInfo==NULL) { - fCurrentInfo = new BackgroundImage::BackgroundImageInfo(B_ALL_WORKSPACES, + if (!fCurrent->IsDesktop()) { + if (fCurrentInfo == NULL) { + fCurrentInfo = new BackgroundImage::BackgroundImageInfo(B_ALL_WORKSPACES, fLastImageIndex, mode, offset, eraseTextWidgetBackground, 0, 0); fCurrent->Add(fCurrentInfo); } else { fCurrentInfo->fEraseTextWidgetBackground = eraseTextWidgetBackground; fCurrentInfo->fMode = mode; - if(fCurrentInfo->fMode == BackgroundImage::kAtOffset) + if (fCurrentInfo->fMode == BackgroundImage::kAtOffset) fCurrentInfo->fOffset = offset; fCurrentInfo->fImageIndex = fLastImageIndex; - } + } } else { uint32 workspaceMask = 1; uint32 workspace = current_workspace(); - for ( ; workspace; workspace--) + for (; workspace; workspace--) workspaceMask *= 2; - - if(fCurrentInfo!=NULL) { - if(fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()) { - - if(fCurrentInfo->fWorkspace != workspaceMask) { + + if (fCurrentInfo != NULL) { + if (fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()) { + if (fCurrentInfo->fWorkspace != workspaceMask) { fCurrentInfo->fWorkspace = fCurrentInfo->fWorkspace ^ workspaceMask; fCurrentInfo = new BackgroundImage::BackgroundImageInfo( @@ -566,151 +545,148 @@ BGView::Save() fCurrentInfo->fCacheMode); fCurrent->Add(fCurrentInfo); } else { - fCurrentInfo->fEraseTextWidgetBackground = + fCurrentInfo->fEraseTextWidgetBackground = eraseTextWidgetBackground; fCurrentInfo->fMode = mode; - if(fCurrentInfo->fMode == BackgroundImage::kAtOffset) { + if (fCurrentInfo->fMode == BackgroundImage::kAtOffset) fCurrentInfo->fOffset = offset; - } + fCurrentInfo->fImageIndex = fLastImageIndex; } - } else { fCurrent->RemoveAll(); - fCurrentInfo = new BackgroundImage::BackgroundImageInfo( + fCurrentInfo = new BackgroundImage::BackgroundImageInfo( B_ALL_WORKSPACES, fLastImageIndex, mode, offset, eraseTextWidgetBackground, fCurrent->GetShowingImageSet(), fCurrentInfo->fCacheMode); fCurrent->Add(fCurrentInfo); } } else { - if(fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()) { + if (fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()) { fCurrentInfo = new BackgroundImage::BackgroundImageInfo( workspaceMask, fLastImageIndex, mode, offset, eraseTextWidgetBackground, fCurrent->GetShowingImageSet(), 0); } else { fCurrent->RemoveAll(); - fCurrentInfo = new BackgroundImage::BackgroundImageInfo( + fCurrentInfo = new BackgroundImage::BackgroundImageInfo( B_ALL_WORKSPACES, fLastImageIndex, mode, offset, eraseTextWidgetBackground, fCurrent->GetShowingImageSet(), 0); } fCurrent->Add(fCurrentInfo); } - - if(fCurrentInfo->fWorkspace == B_ALL_WORKSPACES) - for(int32 i=0; ifWorkspace == B_ALL_WORKSPACES) { + for (int32 i = 0; i < count_workspaces(); i++) { BScreen().SetDesktopColor(fPicker->ValueAsColor(), i, true); - else + } + } else BScreen().SetDesktopColor(fPicker->ValueAsColor(), true); } - BNode node(&fCurrent_ref); + + BNode node(&fCurrentRef); fCurrent->SetBackgroundImage(&node); } void -BGView::NotifyServer() +BackgroundsView::NotifyServer() { - BMessenger tracker( "application/x-vnd.Be-TRAK" ); - if(fCurrent->IsDesktop()) { - tracker.SendMessage( new BMessage(B_RESTORE_BACKGROUND_IMAGE)); + BMessenger tracker("application/x-vnd.Be-TRAK"); + + if (fCurrent->IsDesktop()) { + tracker.SendMessage(new BMessage(B_RESTORE_BACKGROUND_IMAGE)); } else { int32 i = -1; BMessage reply; int32 err; - BEntry currentEnt( &fCurrent_ref ); - BPath currentPath( ¤tEnt ); + BEntry currentEntry(&fCurrentRef); + BPath currentPath(¤tEntry); bool isCustomFolder = !fWorkspaceMenu->FindItem(DEFAULT_FOLDER)->IsMarked(); do { + BMessage msg(B_GET_PROPERTY); i++; - - /* scripting message */ - BMessage msg( B_GET_PROPERTY ); - /* look at the "Poses" in every Tracker window */ - msg.AddSpecifier( "Poses" ); - msg.AddSpecifier( "Window", i ); + // look at the "Poses" in every Tracker window + msg.AddSpecifier("Poses"); + msg.AddSpecifier("Window", i); - reply.MakeEmpty(); + reply.MakeEmpty(); + tracker.SendMessage(&msg, &reply); - tracker.SendMessage( &msg, &reply ); + // break out of the loop when we're at the end of + // the windows + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD + && reply.FindInt32("error", &err) == B_OK + && err == B_BAD_INDEX) + break; - /* break out of the loop when we're at the end of - * the windows - */ - if( reply.what == B_MESSAGE_NOT_UNDERSTOOD && - reply.FindInt32( "error", &err ) == B_OK && - err == B_BAD_INDEX ) - break; + // don't stop for windows that don't understand + // a request for "Poses"; they're not displaying + // folders + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD + && reply.FindInt32("error", &err) == B_OK + && err != B_BAD_SCRIPT_SYNTAX) + continue; - /* don't stop for windows that don't understand - * a request for "Poses"; they're not displaying - * folders - */ - if( reply.what == B_MESSAGE_NOT_UNDERSTOOD && - reply.FindInt32( "error", &err ) == B_OK && - err != B_BAD_SCRIPT_SYNTAX ) - continue; + BMessenger trackerWindow; + if (reply.FindMessenger("result", &trackerWindow) != B_OK) + continue; - BMessenger m; - if( reply.FindMessenger( "result", &m ) != B_OK) - continue; - /* m is the messenger of a Tracker window with - * a folder inside - */ + if (isCustomFolder) { + // found a window with poses, ask for its path + msg.MakeEmpty(); + msg.what = B_GET_PROPERTY; + msg.AddSpecifier("Path"); + msg.AddSpecifier("Poses"); + msg.AddSpecifier("Window", i); - if(isCustomFolder) { - /* found a Window with a Poses, ask for its Path */ - msg.MakeEmpty(); - msg.what = B_GET_PROPERTY; - msg.AddSpecifier( "Path" ); - msg.AddSpecifier( "Poses" ); - msg.AddSpecifier( "Window", i ); + reply.MakeEmpty(); + tracker.SendMessage(&msg, &reply); - reply.MakeEmpty(); - - tracker.SendMessage( &msg, &reply ); + // go on with the next if this din't have a path + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD) + continue; - /* go on with the next if this din't have a Path */ - if( reply.what == B_MESSAGE_NOT_UNDERSTOOD ) continue; - - /* dig out the Path */ - entry_ref ref; - if( reply.FindRef( "result", &ref ) == B_OK ) { - BEntry ent( &ref ); - BPath path( &ent ); - - /* these are not the Paths you're looking for */ - if( currentPath != path) continue; - } - } - - m.SendMessage( B_RESTORE_BACKGROUND_IMAGE ); - } while( true ); + entry_ref ref; + if (reply.FindRef("result", &ref) == B_OK) { + BEntry entry(&ref); + BPath path(&entry); + + // these are not the paths you're looking for + if (currentPath != path) + continue; + } + } + + trackerWindow.SendMessage(B_RESTORE_BACKGROUND_IMAGE); + } while (true); } } -int32 BGView::NotifyThread(void *data) { - BGView *bgView = (BGView*)data; - bgView->NotifyServer(); +int32 +BackgroundsView::NotifyThread(void *data) +{ + BackgroundsView *view = (BackgroundsView*)data; + + view->NotifyServer(); return B_OK; } void -BGView::SaveSettings(void) +BackgroundsView::SaveSettings(void) { BPath path; - if(find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(SETTINGS_FILE); - BFile file(path.Path(),B_READ_WRITE|B_CREATE_FILE|B_ERASE_FILE); - + BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); + BPoint point = Window()->Frame().LeftTop(); - if(fSettings.ReplacePoint("pos", point)!=B_OK) + if (fSettings.ReplacePoint("pos", point)!=B_OK) fSettings.AddPoint("pos", point); - + entry_ref ref; BEntry entry; BPath path; @@ -718,54 +694,53 @@ BGView::SaveSettings(void) fPanel->GetPanelDirectory(&ref); entry.SetTo(&ref); entry.GetPath(&path); - if(fSettings.ReplaceString("paneldir", path.Path())!=B_OK) + if (fSettings.ReplaceString("paneldir", path.Path()) != B_OK) fSettings.AddString("paneldir", path.Path()); - + fFolderPanel->GetPanelDirectory(&ref); entry.SetTo(&ref); entry.GetPath(&path); - if(fSettings.ReplaceString("folderpaneldir", path.Path())!=B_OK) + if (fSettings.ReplaceString("folderpaneldir", path.Path()) != B_OK) fSettings.AddString("folderpaneldir", path.Path()); - + fSettings.RemoveName("recentfolder"); - for(int i=0; iPath()); - + } + fSettings.Flatten(&file); } } void -BGView::LoadSettings(void) +BackgroundsView::LoadSettings(void) { fSettings.MakeEmpty(); - + BPath path; - if(find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) { path.Append(SETTINGS_FILE); BFile file(path.Path(),B_READ_ONLY); - if((file.InitCheck()==B_OK)&&(fSettings.Unflatten(&file)==B_OK)) - { + if (file.InitCheck() == B_OK && fSettings.Unflatten(&file) == B_OK) { PRINT_OBJECT(fSettings); - + BPoint point; - if(fSettings.FindPoint("pos", &point)==B_OK) + if (fSettings.FindPoint("pos", &point) == B_OK) Window()->MoveTo(point); - + BString string; - if(fSettings.FindString("paneldir", &string)==B_OK) + if (fSettings.FindString("paneldir", &string) == B_OK) fPanel->SetPanelDirectory(string.String()); - - if(fSettings.FindString("folderpaneldir", &string)==B_OK) + + if (fSettings.FindString("folderpaneldir", &string) == B_OK) fFolderPanel->SetPanelDirectory(string.String()); - + int32 index = 0; - while(fSettings.FindString("recentfolder", index, &string)==B_OK) - { + while (fSettings.FindString("recentfolder", index, &string) == B_OK) { if (index == 0) fWorkspaceMenu->AddSeparatorItem(); - + BPath path(string.String()); int32 i = AddPath(path); BString s; @@ -776,144 +751,131 @@ BGView::LoadSettings(void) index++; } fWorkspaceMenu->SetTargetForItems(this); - + PRINT(("Settings Loaded\n")); - } else - { - printf("Error unflattening settings file %s\n",path.Path()); - } + } else { + printf("Error unflattening settings file %s\n", path.Path()); + } } } void -SetRGBColor(rgb_color *col,uint8 r, uint8 g, uint8 b, uint8 a) +BackgroundsView::WorkspaceActivated(uint32 oldWorkspaces, bool active) { - col->red=r; - col->green=g; - col->blue=b; - col->alpha=a; + UpdateWithCurrent(); } void -BGView::WorkspaceActivated(uint32 oldWorkspaces, bool active) -{ - if(true) { - UpdateWithCurrent(); - } -} - - -void -BGView::UpdatePreview() +BackgroundsView::UpdatePreview() { bool imageEnabled = !(fImageMenu->FindItem(NONE_IMAGE)->IsMarked()); - if(fPlacementMenu->IsEnabled()^imageEnabled) + if (fPlacementMenu->IsEnabled() ^ imageEnabled) fPlacementMenu->SetEnabled(imageEnabled); - if(fIconLabelBackground->IsEnabled()^imageEnabled) + if (fIconLabelBackground->IsEnabled() ^ imageEnabled) fIconLabelBackground->SetEnabled(imageEnabled); + bool textEnabled = (fPlacementMenu->FindItem(MANUAL_PLACEMENT)->IsMarked()) - &&imageEnabled; - if(fXPlacementText->IsEnabled()^textEnabled) + && imageEnabled; + if (fXPlacementText->IsEnabled() ^ textEnabled) fXPlacementText->SetEnabled(textEnabled); - if(fYPlacementText->IsEnabled()^textEnabled) + if (fYPlacementText->IsEnabled() ^ textEnabled) fYPlacementText->SetEnabled(textEnabled); - if (textEnabled && (fXPlacementText->TextView()->IsSelectable() != textEnabled)) - { + if (textEnabled && fXPlacementText->TextView()->IsSelectable() != textEnabled) { fXPlacementText->SetText("0"); fYPlacementText->SetText("0"); } - if (!textEnabled) - { + if (!textEnabled) { fXPlacementText->SetText(NULL); fYPlacementText->SetText(NULL); } + fXPlacementText->TextView()->MakeSelectable(textEnabled); fYPlacementText->TextView()->MakeSelectable(textEnabled); fXPlacementText->TextView()->MakeEditable(textEnabled); fYPlacementText->TextView()->MakeEditable(textEnabled); - int32 index = ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex(); + fPreView->ClearViewBitmap(); - if(index>=0) { + + int32 index = ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex(); + if (index >= 0) { BBitmap *bitmap = GetImage(index)->GetBitmap(); - if(bitmap) { - + if (bitmap) { BackgroundImage::BackgroundImageInfo *info = new BackgroundImage::BackgroundImageInfo(0, index, FindPlacementMode(), BPoint(atoi(fXPlacementText->Text()), atoi(fYPlacementText->Text())), - (fIconLabelBackground->Value()==B_CONTROL_ON), 0, 0); - if(info->fMode == BackgroundImage::kAtOffset) { + fIconLabelBackground->Value() == B_CONTROL_ON, 0, 0); + if (info->fMode == BackgroundImage::kAtOffset) { fPreView->SetEnabled(true); fPreView->fPoint.x = atoi(fXPlacementText->Text()); fPreView->fPoint.y = atoi(fYPlacementText->Text()); - } else { + } else fPreView->SetEnabled(false); - } - + fPreView->fImageBounds = BRect(bitmap->Bounds()); - fCurrent->Show(info, fPreView); + fCurrent->Show(info, fPreView); } } else fPreView->SetEnabled(false); + fPreView->SetViewColor(fPicker->ValueAsColor()); fPreView->Invalidate(); } BackgroundImage::Mode -BGView::FindPlacementMode() +BackgroundsView::FindPlacementMode() { BackgroundImage::Mode mode = BackgroundImage::kAtOffset; - if(fPlacementMenu->FindItem(CENTER_PLACEMENT)->IsMarked()) + + if (fPlacementMenu->FindItem(CENTER_PLACEMENT)->IsMarked()) mode = BackgroundImage::kCentered; - if(fPlacementMenu->FindItem(SCALE_PLACEMENT)->IsMarked()) + if (fPlacementMenu->FindItem(SCALE_PLACEMENT)->IsMarked()) mode = BackgroundImage::kScaledToFit; - if(fPlacementMenu->FindItem(MANUAL_PLACEMENT)->IsMarked()) + if (fPlacementMenu->FindItem(MANUAL_PLACEMENT)->IsMarked()) mode = BackgroundImage::kAtOffset; - if(fPlacementMenu->FindItem(TILE_PLACEMENT)->IsMarked()) + if (fPlacementMenu->FindItem(TILE_PLACEMENT)->IsMarked()) mode = BackgroundImage::kTiled; + return mode; } void -BGView::UpdateButtons() +BackgroundsView::UpdateButtons() { bool hasChanged = false; - if(fPicker->IsEnabled() && ((fPicker->ValueAsColor().green != - BScreen().DesktopColor().green) - ||(fPicker->ValueAsColor().red != BScreen().DesktopColor().red) - ||(fPicker->ValueAsColor().blue != BScreen().DesktopColor().blue))) + if (fPicker->IsEnabled() + && fPicker->ValueAsColor() != BScreen().DesktopColor()) { + hasChanged = true; + } else if (fCurrentInfo) { + if ((fIconLabelBackground->Value() == B_CONTROL_ON) ^ + fCurrentInfo->fEraseTextWidgetBackground) hasChanged = true; - else if(fCurrentInfo) { - if((fIconLabelBackground->Value()==B_CONTROL_ON) ^ - fCurrentInfo->fEraseTextWidgetBackground) + else if (FindPlacementMode() != fCurrentInfo->fMode) hasChanged = true; - else if(FindPlacementMode() != fCurrentInfo->fMode) + else if (fCurrentInfo->fImageIndex != + ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) hasChanged = true; - else if(fCurrentInfo->fImageIndex != - ((BGImageMenuItem*)fImageMenu->FindMarked())->ImageIndex()) + else if (fCurrent->IsDesktop() + && ((fCurrentInfo->fWorkspace != B_ALL_WORKSPACES) + ^ (fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()))) hasChanged = true; - else if(fCurrent->IsDesktop()&&((fCurrentInfo->fWorkspace != B_ALL_WORKSPACES) - ^ (fWorkspaceMenu->FindItem(CURRENT_WORKSPACE)->IsMarked()))) - hasChanged = true; - else if(fCurrentInfo->fMode == BackgroundImage::kAtOffset) { - BString oldString, newString; - oldString << (int)fCurrentInfo->fOffset.x; - if(oldString != BString(fXPlacementText->Text())) - hasChanged = true; - oldString = ""; - oldString << (int)fCurrentInfo->fOffset.y; - if(oldString != BString(fYPlacementText->Text())) - hasChanged = true; + else if (fCurrentInfo->fMode == BackgroundImage::kAtOffset) { + BString oldString, newString; + oldString << (int)fCurrentInfo->fOffset.x; + if (oldString != BString(fXPlacementText->Text())) + hasChanged = true; + oldString = ""; + oldString << (int)fCurrentInfo->fOffset.y; + if (oldString != BString(fYPlacementText->Text())) + hasChanged = true; } - } else { - if(fImageMenu->IndexOf(fImageMenu->FindMarked())>0) - hasChanged = true; - } + } else if (fImageMenu->IndexOf(fImageMenu->FindMarked()) > 0) + hasChanged = true; fApply->SetEnabled(hasChanged); fRevert->SetEnabled(hasChanged); @@ -921,29 +883,30 @@ BGView::UpdateButtons() void -BGView::RefsReceived(BMessage *msg) +BackgroundsView::RefsReceived(BMessage *msg) { entry_ref ref; int32 i = 0; BMimeType imageType("image"); while (msg->FindRef("refs", i++, &ref) == B_OK) { - BPath path; BEntry entry(&ref, true); path.SetTo(&entry); BNode node(&entry); - + if (node.IsFile()) { BNodeInfo nodeInfo(&node); char fileType[256]; - if(nodeInfo.GetType(fileType)!=B_OK) + if (nodeInfo.GetType(fileType) != B_OK) continue; + BMimeType refType(fileType); - if(!imageType.Contains(&refType)) + if (!imageType.Contains(&refType)) continue; + BGImageMenuItem *item; int32 index = AddImage(path); - if(index>=0) { + if (index >= 0) { item = FindImageItem(index); fLastImageIndex = index; } else { @@ -954,15 +917,16 @@ BGView::RefsReceived(BMessage *msg) item->SetTarget(this); fLastImageIndex = -index-1; } + item->SetMarked(true); BMessenger messenger(this); messenger.SendMessage(IMAGE_SELECTED); - } else if(node.IsDirectory()) { + } else if (node.IsDirectory()) { BMenuItem *item; int32 index = AddPath(path); - if(index>=0) { - item = fWorkspaceMenu->ItemAt(index+6); - fLastWorkspaceIndex = index+6; + if (index >= 0) { + item = fWorkspaceMenu->ItemAt(index + 6); + fLastWorkspaceIndex = index + 6; } else { if (fWorkspaceMenu->CountItems() <= 5) fWorkspaceMenu->AddSeparatorItem(); @@ -982,16 +946,17 @@ BGView::RefsReceived(BMessage *msg) int32 -BGView::AddPath(BPath path) +BackgroundsView::AddPath(BPath path) { int32 count = fPathList.CountItems(); - int32 index=0; - for(; indexPath()).ICompare(BString(path.Path()))); - if(c == 0) + int c = BString(p->Path()).ICompare(path.Path()); + if (c == 0) return index; - else if(c > 0) + + if (c > 0) break; } fPathList.AddItem(new BPath(path), index); @@ -1000,54 +965,56 @@ BGView::AddPath(BPath path) int32 -BGView::AddImage(BPath path) +BackgroundsView::AddImage(BPath path) { int32 count = fImageList.CountItems(); - int32 index=0; - for(; indexGetPath() == path) + if (image->GetPath() == path) return index; } + fImageList.AddItem(new Image(path)); - return -index-1; } void -BGView::ProcessRefs(entry_ref dir_ref, BMessage* msg) +BackgroundsView::ProcessRefs(entry_ref dir, BMessage* refs) { fWorkspaceMenu->FindItem(DEFAULT_FOLDER)->SetMarked(true); BMessenger messenger(this); messenger.SendMessage(DEFAULT_FOLDER); - if(msg->CountNames(B_REF_TYPE)>0) { - messenger.SendMessage(msg); + + if (refs->CountNames(B_REF_TYPE) > 0) { + messenger.SendMessage(refs); } else { BMessage message(B_REFS_RECEIVED); - message.AddRef("refs", &dir_ref); + message.AddRef("refs", &dir); messenger.SendMessage(&message); } } Image* -BGView::GetImage(int32 imageIndex) +BackgroundsView::GetImage(int32 imageIndex) { return fImageList.ItemAt(imageIndex); } BGImageMenuItem* -BGView::FindImageItem(const int32 imageIndex) +BackgroundsView::FindImageItem(const int32 imageIndex) { - if(imageIndex<0) + if (imageIndex < 0) return (BGImageMenuItem *)fImageMenu->ItemAt(0); + int32 count = fImageMenu->CountItems() - 2; - int32 index=2; - for(; indexItemAt(index); - if(image->ImageIndex() == imageIndex) + if (image->ImageIndex() == imageIndex) return image; } return NULL; @@ -1055,34 +1022,38 @@ BGView::FindImageItem(const int32 imageIndex) bool -BGView::AddItem(BGImageMenuItem *item) +BackgroundsView::AddItem(BGImageMenuItem *item) { int32 count = fImageMenu->CountItems() - 2; - int32 index=2; + int32 index = 2; if (count < index) { fImageMenu->AddItem(new BSeparatorItem(), 1); count = fImageMenu->CountItems() - 2; } - for(; indexItemAt(index); + + for (; index < count; index++) { + BGImageMenuItem* image = (BGImageMenuItem *)fImageMenu->ItemAt(index); int c = (BString(image->Label()).ICompare(BString(item->Label()))); - if(c > 0) + if (c > 0) break; } return fImageMenu->AddItem(item, index); } +// #pragma mark - + + PreView::PreView(BRect frame, const char *name, int32 resize, int32 flags) - :BControl(frame,name,NULL, NULL, resize,flags), - fMoveHandCursor(hand_cursor_data) + : BControl(frame, name, NULL, NULL, resize, flags), + fMoveHandCursor(kHandCursorData) { - } void -PreView::AttachedToWindow() { +PreView::AttachedToWindow() +{ rgb_color color = ViewColor(); BControl::AttachedToWindow(); SetViewColor(color); @@ -1111,7 +1082,7 @@ PreView::MouseDown(BPoint point) void PreView::MouseUp(BPoint point) { - if(IsTracking()) + if (IsTracking()) SetTracking(false); } @@ -1119,55 +1090,55 @@ PreView::MouseUp(BPoint point) void PreView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) { - if(IsEnabled()) + if (IsEnabled()) SetViewCursor(&fMoveHandCursor); else SetViewCursor(B_CURSOR_SYSTEM_DEFAULT); - if(IsTracking()) - { + + if (IsTracking()) { float x, y; x = fPoint.x + (point.x - fOldPoint.x)/ x_ratio; y = fPoint.y + (point.y - fOldPoint.y)/ y_ratio; bool min, max, mustSend = false; min = (x > -fImageBounds.Width()); max = (x < mode.virtual_width); - if( min && max) { + if (min && max) { fOldPoint.x = point.x; fPoint.x = x; mustSend = true; } else { - if(!min && fPoint.x > -fImageBounds.Width()) { + if (!min && fPoint.x > -fImageBounds.Width()) { fPoint.x = -fImageBounds.Width(); fOldPoint.x = point.x - (x - fPoint.x) * x_ratio; mustSend = true; } - if(!max && fPoint.x < mode.virtual_width) { + if (!max && fPoint.x < mode.virtual_width) { fPoint.x = mode.virtual_width; fOldPoint.x = point.x - (x - fPoint.x) * x_ratio; mustSend = true; } } - + min = (y > -fImageBounds.Height()); max = (y < mode.virtual_height); - if(min && max) { + if (min && max) { fOldPoint.y = point.y; fPoint.y = y; mustSend = true; } else { - if(!min && fPoint.y > -fImageBounds.Height()) { + if (!min && fPoint.y > -fImageBounds.Height()) { fPoint.y = -fImageBounds.Height(); fOldPoint.y = point.y - (y - fPoint.y) * y_ratio; mustSend = true; } - if(!max && fPoint.y < mode.virtual_height) { + if (!max && fPoint.y < mode.virtual_height) { fPoint.y = mode.virtual_height; fOldPoint.y = point.y - (y - fPoint.y) * y_ratio; mustSend = true; } } - - if(mustSend) { + + if (mustSend) { BMessenger messenger(Parent()); messenger.SendMessage(PREVIEW_PLACEMENT); } @@ -1176,8 +1147,11 @@ PreView::MouseMoved(BPoint point, uint32 transit, const BMessage *message) } +// #pragma mark - + + PreviewBox::PreviewBox(BRect frame, const char *name) - :BBox(frame,name) + : BBox(frame,name) { fIsDesktop = true; } @@ -1187,15 +1161,18 @@ void PreviewBox::Draw(BRect rect) { rgb_color color = HighColor(); - BPoint points[] = { BPoint(11,19), BPoint(139,19), BPoint(141,21), - BPoint(141,119), BPoint(139,121), BPoint(118,121), - BPoint(118,126), BPoint(117,127), BPoint(33,127), - BPoint(32,126), BPoint(32,121),BPoint(11,121), - BPoint(9,119),BPoint(9,21),BPoint(11,19) }; - + BPoint points[] = { + BPoint(11,19), BPoint(139,19), BPoint(141,21), + BPoint(141,119), BPoint(139,121), BPoint(118,121), + BPoint(118,126), BPoint(117,127), BPoint(33,127), + BPoint(32,126), BPoint(32,121),BPoint(11,121), + BPoint(9,119),BPoint(9,21),BPoint(11,19) + }; + SetHighColor(LowColor()); FillRect(BRect(9,19,141,127)); - if(fIsDesktop) { + + if (fIsDesktop) { SetHighColor(184,184,184); FillPolygon(points, 15); SetHighColor(96,96,96); @@ -1223,6 +1200,7 @@ PreviewBox::Draw(BRect rect) SetHighColor(200,200,200); StrokeRect(BRect(13,23,138,118)); } + SetHighColor(color); BBox::Draw(rect); } @@ -1236,149 +1214,12 @@ PreviewBox::SetDesktop(bool isDesktop) } -ImageFilePanel::ImageFilePanel(file_panel_mode mode, BMessenger *target, - const entry_ref *start_directory, uint32 node_flavors, - bool allow_multiple_selection, BMessage *message, BRefFilter *filter, - bool modal, bool hide_when_done) - :BFilePanel(mode,target,start_directory, node_flavors, - allow_multiple_selection,message,filter,modal,hide_when_done), - imageView(NULL) -{ -} - - -void -ImageFilePanel::Show() -{ - if(imageView==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); - imageView = new BView(rect, "ImageView", B_FOLLOW_LEFT|B_FOLLOW_BOTTOM, - B_SUBPIXEL_PRECISE); - imageView->SetViewColor(background->ViewColor()); - background->AddChild(imageView); - - rect = BRect(background->Bounds().left+132,background->Bounds().bottom-85, - background->Bounds().left+250,background->Bounds().bottom-65); - resolutionView = new BStringView(rect, "ResolutionView", NULL, - B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - background->AddChild(resolutionView); - - rect.OffsetBy(0, -16); - imageTypeView = new BStringView(rect, "ImageTypeView", NULL, - B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - background->AddChild(imageTypeView); - Window()->Unlock(); - } - BFilePanel::Show(); -} - - -void -ImageFilePanel::SelectionChanged(void) -{ - entry_ref ref; - Rewind(); - if(GetNextSelectedRef(&ref)==B_OK) { - BEntry entry(&ref); - BNode node(&ref); - imageView->ClearViewBitmap(); - - if(node.IsFile()) { - BBitmap *bitmap = BTranslationUtils::GetBitmap(&ref); - - if(bitmap!=NULL) { - BRect dest(imageView->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); - } - imageView->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); - resolutionView->SetText(resolution.String()); - delete bitmap; - - BNode node(&ref); - BNodeInfo nodeInfo(&node); - char fileType[256]; - if(nodeInfo.GetType(fileType)==B_OK) - { - if(strncmp(fileType, "image/jpeg", 10)==0) - imageTypeView->SetText("JPEG Image"); - else - imageTypeView->SetText(""); - } - } - } else { - resolutionView->SetText(""); - imageTypeView->SetText(""); - } - imageView->Invalidate(); - resolutionView->Invalidate(); - } - BFilePanel::SelectionChanged(); -} - - -CustomRefFilter::CustomRefFilter(bool imageFiltering) - : BRefFilter(), - fImageFiltering(imageFiltering) -{ -} - - -bool -CustomRefFilter::Filter(const entry_ref *ref, BNode* node, struct stat *st, - const char *filetype) -{ - if(fImageFiltering){ - if(node->IsDirectory()) - return true; - else { - BMimeType imageType("image"), refType(filetype); - if(imageType.Contains(&refType)) - return true; - } - return false; - } else { - return (node->IsDirectory()); - } -} +// #pragma mark - BGImageMenuItem::BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message, char shortcut, uint32 modifiers) - :BMenuItem(label, message, shortcut, modifiers), + : BMenuItem(label, message, shortcut, modifiers), fImageIndex(imageIndex) { } diff --git a/src/preferences/backgrounds/BGView.h b/src/preferences/backgrounds/BackgroundsView.h similarity index 64% rename from src/preferences/backgrounds/BGView.h rename to src/preferences/backgrounds/BackgroundsView.h index 267f31c2e3..e7f97096f5 100644 --- a/src/preferences/backgrounds/BGView.h +++ b/src/preferences/backgrounds/BackgroundsView.h @@ -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 #include @@ -30,51 +32,28 @@ #include #include #include -#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 fPathList; BObjectList fImageList; }; -#endif +#endif // BACKGROUNDS_VIEW_H diff --git a/src/preferences/backgrounds/ImageFilePanel.cpp b/src/preferences/backgrounds/ImageFilePanel.cpp new file mode 100644 index 0000000000..0b168c3685 --- /dev/null +++ b/src/preferences/backgrounds/ImageFilePanel.cpp @@ -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 +#include +#include +#include +#include +#include + + +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; +} + diff --git a/src/preferences/backgrounds/ImageFilePanel.h b/src/preferences/backgrounds/ImageFilePanel.h new file mode 100644 index 0000000000..41ac1cbb0d --- /dev/null +++ b/src/preferences/backgrounds/ImageFilePanel.h @@ -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 +#include + +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 diff --git a/src/preferences/backgrounds/Jamfile b/src/preferences/backgrounds/Jamfile index 6854c7ada3..9af33dda45 100644 --- a/src/preferences/backgrounds/Jamfile +++ b/src/preferences/backgrounds/Jamfile @@ -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 ;