Initial checkin of the Background replacement Preflet on behalf of Jerome
Duval ( jerome dot duval at free.fr ). Altered Jamfile to build Backgrounds. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@903 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
|
||||
"Backgrounds" by Jerome Duval ([email protected])
|
||||
|
||||
(C)2002 OpenBeOS under MIT license
|
||||
|
||||
*/
|
||||
|
||||
#include "BGMain.h"
|
||||
#include <TrackerAddOn.h>
|
||||
|
||||
BGApplication::BGApplication()
|
||||
:BApplication(APP_SIGNATURE)
|
||||
{
|
||||
fBGWin=new BGWindow(BRect(100,100,570,325));
|
||||
fBGWin->Show();
|
||||
}
|
||||
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
BGApplication myApplication;
|
||||
|
||||
// This function doesn't return until the application quits
|
||||
myApplication.Run();
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
void process_refs(entry_ref dir_ref, BMessage *msg, void* reserved)
|
||||
{
|
||||
BGWindow *fBGWin=new BGWindow(BRect(100,100,570,325), false);
|
||||
fBGWin->ProcessRefs(dir_ref, msg);
|
||||
snooze(500);
|
||||
fBGWin->Show();
|
||||
|
||||
status_t exit_value;
|
||||
wait_for_thread(fBGWin->Thread(), &exit_value);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
|
||||
"Backgrounds" by Jerome Duval ([email protected])
|
||||
|
||||
(C)2002 OpenBeOS under MIT license
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BG_WORLD_H
|
||||
#define BG_WORLD_H
|
||||
|
||||
#include <Application.h>
|
||||
#include "BGWindow.h"
|
||||
|
||||
#define APP_SIGNATURE "application/x-vnd.obos-Backgrounds"
|
||||
|
||||
class BGApplication : public BApplication {
|
||||
public:
|
||||
BGApplication();
|
||||
BGWindow *fBGWin;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
|
||||
"Backgrounds" by Jerome Duval ([email protected])
|
||||
|
||||
(C)2002 OpenBeOS under MIT license
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BG_VIEW_H_
|
||||
#define BG_VIEW_H_
|
||||
|
||||
#include <View.h>
|
||||
#include <ColorControl.h>
|
||||
#include <Message.h>
|
||||
#include <ListItem.h>
|
||||
#include <ListView.h>
|
||||
#include <Button.h>
|
||||
#include <ScrollView.h>
|
||||
#include <ScrollBar.h>
|
||||
#include <String.h>
|
||||
#include <Box.h>
|
||||
#include <CheckBox.h>
|
||||
#include <TextControl.h>
|
||||
#include <Menu.h>
|
||||
#include <MenuItem.h>
|
||||
#include <Entry.h>
|
||||
#include <Screen.h>
|
||||
#include <Control.h>
|
||||
#include <Picture.h>
|
||||
#include <FilePanel.h>
|
||||
#include <StringView.h>
|
||||
#include "BackgroundImage.h"
|
||||
|
||||
#define SETTINGS_FILE "Backgrounds_settings"
|
||||
|
||||
class BGImageMenuItem : public BMenuItem {
|
||||
public:
|
||||
BGImageMenuItem(const char *label, int32 imageIndex, BMessage *message,
|
||||
char shortcut=0, uint32 modifiers=0);
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
class BGView : public BView {
|
||||
public:
|
||||
BGView(BRect frame, const char *name, int32 resize, int32 flags);
|
||||
~BGView(void);
|
||||
|
||||
void SaveSettings(void);
|
||||
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 MessageReceived(BMessage *msg);
|
||||
void LoadDesktopFolder(void);
|
||||
void LoadDefaultFolder(void);
|
||||
void LoadFolder(bool isDesktop);
|
||||
void LoadRecentFolder(BPath path);
|
||||
void UpdateWithCurrent(void);
|
||||
void UpdatePreview(void);
|
||||
void UpdateButtons(void);
|
||||
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
|
||||
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
|
||||
|
||||
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
|
||||
int32 fLastImageIndex, fLastWorkspaceIndex; // last indexes for cancel
|
||||
BMessage fSettings; // settings loaded from settings directory
|
||||
|
||||
BObjectList<BPath> fPathList;
|
||||
BObjectList<Image> fImageList;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
|
||||
"Backgrounds" by Jerome Duval ([email protected])
|
||||
|
||||
(C)2002 OpenBeOS under MIT license
|
||||
|
||||
*/
|
||||
|
||||
#include "BGWindow.h"
|
||||
|
||||
BGWindow::BGWindow(BRect frame, bool standalone)
|
||||
: BWindow(frame, WINDOW_TITLE, B_TITLED_WINDOW,
|
||||
B_NOT_RESIZABLE | B_NOT_ZOOMABLE, B_ALL_WORKSPACES),
|
||||
fIsStandalone(standalone)
|
||||
{
|
||||
fBGView = new BGView(Bounds(),"BackgroundsView",B_FOLLOW_ALL, B_WILL_DRAW);
|
||||
AddChild(fBGView);
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
BGWindow::QuitRequested()
|
||||
{
|
||||
fBGView->SaveSettings();
|
||||
if(fIsStandalone)
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BGWindow::WorkspaceActivated(int32 oldWorkspaces, bool active)
|
||||
{
|
||||
fBGView->WorkspaceActivated(oldWorkspaces, active);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BGWindow::ProcessRefs(entry_ref dir_ref, BMessage* msg)
|
||||
{
|
||||
fBGView->ProcessRefs(dir_ref, msg);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
|
||||
"Backgrounds" by Jerome Duval ([email protected])
|
||||
|
||||
(C)2002 OpenBeOS under MIT license
|
||||
|
||||
*/
|
||||
|
||||
#ifndef BG_WINDOW_H
|
||||
#define BG_WINDOW_H
|
||||
|
||||
#include <Application.h>
|
||||
#include <Window.h>
|
||||
#include "BGView.h"
|
||||
|
||||
#define WINDOW_TITLE "Backgrounds"
|
||||
|
||||
class BGWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
BGWindow(BRect frame, bool standalone = true);
|
||||
BGView *GetView() {return fBGView;}
|
||||
void ProcessRefs(entry_ref dir_ref, BMessage* msg);
|
||||
protected:
|
||||
virtual bool QuitRequested();
|
||||
virtual void WorkspaceActivated(int32 oldWorkspaces, bool active);
|
||||
BGView *fBGView;
|
||||
bool fIsStandalone;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,494 @@
|
||||
/*
|
||||
Open Tracker License
|
||||
|
||||
Terms and Conditions
|
||||
|
||||
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice applies to all licensees
|
||||
and shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of Be Incorporated shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings in
|
||||
this Software without prior written authorization from Be Incorporated.
|
||||
|
||||
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
|
||||
of Be Incorporated in the United States and other countries. Other brand product
|
||||
names are registered trademarks or trademarks of their respective holders.
|
||||
All rights reserved.
|
||||
*/
|
||||
|
||||
// Classes used for setting up and managing background images
|
||||
//
|
||||
|
||||
#include <Bitmap.h>
|
||||
#include <Node.h>
|
||||
#include <TranslationKit.h>
|
||||
#include <View.h>
|
||||
#include <Window.h>
|
||||
#include <Message.h>
|
||||
#include <Entry.h>
|
||||
#include <Path.h>
|
||||
#include <Screen.h>
|
||||
#include <String.h>
|
||||
|
||||
#include <fs_attr.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "BGView.h"
|
||||
#include "BackgroundImage.h"
|
||||
|
||||
const char *kBackgroundImageInfo = "be:bgndimginfo";
|
||||
const char *kBackgroundImageInfoOffset = "be:bgndimginfooffset";
|
||||
const char *kBackgroundImageInfoEraseText = "be:bgndimginfoerasetext";
|
||||
const char *kBackgroundImageInfoMode = "be:bgndimginfomode";
|
||||
const char *kBackgroundImageInfoWorkspaces = "be:bgndimginfoworkspaces";
|
||||
const char *kBackgroundImageInfoPath = "be:bgndimginfopath";
|
||||
const char *kBackgroundImageInfoSet = "be:bgndimginfoset";
|
||||
const char *kBackgroundImageInfoCacheMode = "be:bgndimginfocachemode";
|
||||
const char *kBackgroundImageSetPeriod = "be:bgndimgsetperiod";
|
||||
const char *kBackgroundImageRandomChange = "be:bgndimgrandomchange";
|
||||
const char *kBackgroundImageCacheMode = "be:bgndimgcachemode";
|
||||
|
||||
BackgroundImage *
|
||||
BackgroundImage::GetBackgroundImage(const BNode *node, bool isDesktop,
|
||||
BGView* view)
|
||||
{
|
||||
BackgroundImage *result = new BackgroundImage(node, isDesktop);
|
||||
result->bgView = view;
|
||||
attr_info info;
|
||||
if (node->GetAttrInfo(kBackgroundImageInfo, &info) != B_OK)
|
||||
return result;
|
||||
|
||||
BMessage container;
|
||||
char *buffer = new char [info.size];
|
||||
|
||||
status_t error = node->ReadAttr(kBackgroundImageInfo, info.type, 0, buffer,
|
||||
(size_t)info.size);
|
||||
if (error == info.size)
|
||||
error = container.Unflatten(buffer);
|
||||
|
||||
delete [] buffer;
|
||||
|
||||
if (error != B_OK)
|
||||
return NULL;
|
||||
|
||||
container.PrintToStream();
|
||||
|
||||
uint32 imageSetPeriod = 0;
|
||||
uint32 globalCacheMode = 0;
|
||||
bool randomChange = false;
|
||||
uint32 maxImageSet = 0;
|
||||
|
||||
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;
|
||||
Mode mode = kTiled;
|
||||
bool eraseTextWidgetBackground = true;
|
||||
BPoint offset;
|
||||
uint32 imageSet = 0;
|
||||
uint32 cacheMode = 0;
|
||||
if (container.FindString(kBackgroundImageInfoPath, index, &path) != B_OK)
|
||||
break;
|
||||
|
||||
BPath bpath(path);
|
||||
int32 imageIndex = view->AddImage(bpath);
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
||||
|
||||
|
||||
result->Add(imageInfo);
|
||||
}
|
||||
|
||||
if(result) {
|
||||
result->fImageSetCount = maxImageSet + 1;
|
||||
result->fRandomChange = randomChange;
|
||||
result->fImageSetPeriod = imageSetPeriod;
|
||||
result->fCacheMode = globalCacheMode;
|
||||
if(result->fImageSetCount > 1)
|
||||
result->fShowingImageSet = random()%result->fImageSetCount;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
BackgroundImage::~BackgroundImage()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::Add(BackgroundImageInfo *info)
|
||||
{
|
||||
fBitmapForWorkspaceList.AddItem(info);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::RemoveAll()
|
||||
{
|
||||
for (int32 index = 0; index < fBitmapForWorkspaceList.CountItems();) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(info->fImageSet != fShowingImageSet)
|
||||
index++;
|
||||
else
|
||||
fBitmapForWorkspaceList.RemoveItemAt(index);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::Show(BView *view, int32 workspace)
|
||||
{
|
||||
fView = view;
|
||||
|
||||
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace);
|
||||
if (info) {
|
||||
/*BPoseView *poseView = dynamic_cast<BPoseView *>(fView);
|
||||
if (poseView)
|
||||
poseView->SetEraseWidgetTextBackground(info->fEraseTextWidgetBackground);*/
|
||||
Show(info, fView);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::Show(BackgroundImageInfo *info, BView *view)
|
||||
{
|
||||
BBitmap *bitmap = bgView->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;
|
||||
destinationBitmapBounds.bottom *= y_ratio;
|
||||
BPoint offset(info->fOffset);
|
||||
offset.x *= x_ratio;
|
||||
offset.y *= y_ratio;
|
||||
|
||||
uint32 tile = 0;
|
||||
uint32 followFlags = B_FOLLOW_TOP | B_FOLLOW_LEFT;
|
||||
|
||||
// figure out the display mode and the destination bounds for the bitmap
|
||||
switch (info->fMode) {
|
||||
case kCentered:
|
||||
if (fIsDesktop) {
|
||||
destinationBitmapBounds.OffsetBy(
|
||||
(viewBounds.Width() - destinationBitmapBounds.Width()) / 2,
|
||||
(viewBounds.Height() - destinationBitmapBounds.Height()) / 2);
|
||||
break;
|
||||
}
|
||||
// else fall thru
|
||||
case kScaledToFit:
|
||||
if (fIsDesktop) {
|
||||
destinationBitmapBounds = viewBounds;
|
||||
followFlags = B_FOLLOW_ALL;
|
||||
break;
|
||||
}
|
||||
// else fall thru
|
||||
case kAtOffset:
|
||||
{
|
||||
destinationBitmapBounds.OffsetTo(offset);
|
||||
break;
|
||||
}
|
||||
case kTiled:
|
||||
// Original Backgrounds Preferences center the tiled paper but the Tracker don't do that
|
||||
//if (fIsDesktop) {
|
||||
destinationBitmapBounds.OffsetBy(
|
||||
(viewBounds.Width() - destinationBitmapBounds.Width()) / 2,
|
||||
(viewBounds.Height() - destinationBitmapBounds.Height()) / 2);
|
||||
//}
|
||||
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);
|
||||
fShowingBitmap = info;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::Remove()
|
||||
{
|
||||
if (fShowingBitmap) {
|
||||
fView->ClearViewBitmap();
|
||||
fView->Invalidate();
|
||||
/*BPoseView *poseView = dynamic_cast<BPoseView *>(fView);
|
||||
// make sure text widgets draw the default way, erasing their background
|
||||
if (poseView)
|
||||
poseView->SetEraseWidgetTextBackground(true);*/
|
||||
}
|
||||
fShowingBitmap = NULL;
|
||||
}
|
||||
|
||||
|
||||
BackgroundImage::BackgroundImageInfo *
|
||||
BackgroundImage::ImageInfoForWorkspace(int32 workspace) const
|
||||
{
|
||||
uint32 workspaceMask = 1;
|
||||
|
||||
for ( ; workspace; workspace--)
|
||||
workspaceMask *= 2;
|
||||
|
||||
int32 count = fBitmapForWorkspaceList.CountItems();
|
||||
|
||||
// do a simple lookup for the most likely candidate bitmap -
|
||||
// pick the imageInfo that is only defined for this workspace over one
|
||||
// that supports multiple workspaces
|
||||
BackgroundImageInfo *result = NULL;
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(info->fImageSet != fShowingImageSet)
|
||||
continue;
|
||||
if(fIsDesktop) {
|
||||
if (info->fWorkspace == workspaceMask)
|
||||
return info;
|
||||
if (info->fWorkspace & workspaceMask)
|
||||
result = info;
|
||||
} else
|
||||
return info;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::WorkspaceActivated(BView *view, int32 workspace, bool state)
|
||||
{
|
||||
if (!fIsDesktop)
|
||||
// we only care for desktop bitmaps
|
||||
return;
|
||||
|
||||
if (!state)
|
||||
// we only care comming into a new workspace, not leaving one
|
||||
return;
|
||||
|
||||
BackgroundImageInfo *info = ImageInfoForWorkspace(workspace);
|
||||
if (info != fShowingBitmap) {
|
||||
if (info)
|
||||
Show(info, view);
|
||||
else {
|
||||
/*if (BPoseView *poseView = dynamic_cast<BPoseView *>(view))
|
||||
poseView->SetEraseWidgetTextBackground(true);*/
|
||||
view->ClearViewBitmap();
|
||||
view->Invalidate();
|
||||
}
|
||||
fShowingBitmap = info;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::ScreenChanged(BRect, color_space)
|
||||
{
|
||||
if (!fIsDesktop || !fShowingBitmap)
|
||||
return;
|
||||
|
||||
/*if (fShowingBitmap->fMode == kCentered) {
|
||||
BRect viewBounds(fView->Bounds());
|
||||
BRect bitmapBounds(fShowingBitmap->fBitmap->Bounds());
|
||||
BRect destinationBitmapBounds(bitmapBounds);
|
||||
destinationBitmapBounds.OffsetBy(
|
||||
(viewBounds.Width() - bitmapBounds.Width()) / 2,
|
||||
(viewBounds.Height() - bitmapBounds.Height()) / 2);
|
||||
|
||||
fView->SetViewBitmap(fShowingBitmap->fBitmap, bitmapBounds, destinationBitmapBounds,
|
||||
B_FOLLOW_NONE, 0);
|
||||
fView->Invalidate();
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
BackgroundImage::SetBackgroundImage(BNode *node)
|
||||
{
|
||||
status_t err;
|
||||
BMessage container;
|
||||
int32 count = fBitmapForWorkspaceList.CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
BackgroundImageInfo *info = fBitmapForWorkspaceList.ItemAt(index);
|
||||
if(bgView->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.PrintToStream();
|
||||
|
||||
char buffer[container.FlattenedSize()];
|
||||
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)
|
||||
return B_ERROR;
|
||||
return B_OK;
|
||||
}
|
||||
|
||||
|
||||
/*BackgroundImage *
|
||||
BackgroundImage::Refresh(BackgroundImage *oldBackgroundImage,
|
||||
const BNode *fromNode, bool desktop, BPoseView *poseView)
|
||||
{
|
||||
if (oldBackgroundImage) {
|
||||
oldBackgroundImage->Remove();
|
||||
delete oldBackgroundImage;
|
||||
}
|
||||
|
||||
BackgroundImage *result = GetBackgroundImage(fromNode, desktop);
|
||||
if (result && poseView->ViewMode() != kListMode)
|
||||
result->Show(poseView, current_workspace());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BackgroundImage::ChangeImageSet(BPoseView *poseView)
|
||||
{
|
||||
if(fRandomChange) {
|
||||
if(fImageSetCount > 1) {
|
||||
uint32 oldShowingImageSet = fShowingImageSet;
|
||||
while(oldShowingImageSet == fShowingImageSet)
|
||||
fShowingImageSet = random()%fImageSetCount;
|
||||
} else
|
||||
fShowingImageSet = 0;
|
||||
} else {
|
||||
fShowingImageSet++;
|
||||
if(fShowingImageSet > fImageSetCount - 1)
|
||||
fShowingImageSet = 0;
|
||||
}
|
||||
|
||||
this->Show(poseView, current_workspace());
|
||||
}*/
|
||||
|
||||
|
||||
Image::Image(BPath path)
|
||||
: fBitmap(NULL),
|
||||
fPath(path)
|
||||
{
|
||||
name = path.Leaf();
|
||||
}
|
||||
|
||||
|
||||
Image::~Image()
|
||||
{
|
||||
if(fBitmap!=NULL) {
|
||||
delete fBitmap;
|
||||
fBitmap = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BBitmap*
|
||||
Image::GetBitmap()
|
||||
{
|
||||
if(!fBitmap)
|
||||
fBitmap = BTranslationUtils::GetBitmap(fPath.Path());
|
||||
return fBitmap;
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
Open Tracker License
|
||||
|
||||
Terms and Conditions
|
||||
|
||||
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice applies to all licensees
|
||||
and shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of Be Incorporated shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings in
|
||||
this Software without prior written authorization from Be Incorporated.
|
||||
|
||||
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
|
||||
of Be Incorporated in the United States and other countries. Other brand product
|
||||
names are registered trademarks or trademarks of their respective holders.
|
||||
All rights reserved.
|
||||
*/
|
||||
|
||||
// Classes used for setting up and managing background images
|
||||
//
|
||||
|
||||
#ifndef __BACKGROUND_IMAGE__
|
||||
#define __BACKGROUND_IMAGE__
|
||||
|
||||
#include "String.h"
|
||||
#include "ObjectList.h"
|
||||
#include <Node.h>
|
||||
#include <Path.h>
|
||||
|
||||
|
||||
class BView;
|
||||
class BBitmap;
|
||||
|
||||
class BackgroundImage;
|
||||
class Image;
|
||||
class BGView;
|
||||
|
||||
extern const char *kBackgroundImageInfo;
|
||||
extern const char *kBackgroundImageInfoOffset;
|
||||
extern const char *kBackgroundImageInfoEraseText;
|
||||
extern const char *kBackgroundImageInfoMode;
|
||||
extern const char *kBackgroundImageInfoWorkspaces;
|
||||
extern const char *kBackgroundImageInfoPath;
|
||||
extern const char *kBackgroundImageInfoSet;
|
||||
extern const char *kBackgroundImageInfoSetPeriod;
|
||||
|
||||
const uint32 kRestoreBackgroundImage = 'Tbgr';
|
||||
const uint32 kChangeBackgroundImage = 'Cbgr';
|
||||
|
||||
class BackgroundImage {
|
||||
// This class knows everything about which bitmap to use for a given
|
||||
// view and how.
|
||||
// Unlike other windows, the Desktop window can have different backgrounds
|
||||
// for each workspace
|
||||
public:
|
||||
|
||||
enum Mode {
|
||||
kAtOffset,
|
||||
kCentered, // only works on Desktop
|
||||
kScaledToFit, // only works on Desktop
|
||||
kTiled
|
||||
};
|
||||
|
||||
class BackgroundImageInfo {
|
||||
// element of the per-workspace list
|
||||
public:
|
||||
BackgroundImageInfo(uint32 workspace, int32 imageIndex, Mode mode,
|
||||
BPoint offset, bool eraseTextWidget, uint32 imageSet,
|
||||
uint32 cacheMode);
|
||||
~BackgroundImageInfo();
|
||||
|
||||
void LoadBitmap();
|
||||
void UnloadBitmap(uint32 globalCacheMode);
|
||||
|
||||
uint32 fWorkspace;
|
||||
int32 fImageIndex;
|
||||
Mode fMode;
|
||||
BPoint fOffset;
|
||||
bool fEraseTextWidgetBackground;
|
||||
uint32 fImageSet;
|
||||
uint32 fCacheMode; // image cache strategy (0 cache , 1 no cache)
|
||||
};
|
||||
|
||||
|
||||
|
||||
static BackgroundImage *GetBackgroundImage(const BNode *, bool isDesktop,
|
||||
BGView* view);
|
||||
// create a BackgroundImage object by reading it from a node
|
||||
virtual ~BackgroundImage();
|
||||
|
||||
void Show(BView *view, int32 workspace);
|
||||
// display the right background for a given workspace
|
||||
void Remove();
|
||||
// remove the background from it's current view
|
||||
|
||||
void WorkspaceActivated(BView *view, int32 workspace, bool state);
|
||||
// respond to a workspace change
|
||||
void ScreenChanged(BRect , color_space);
|
||||
// respond to a screen size change
|
||||
/*static BackgroundImage *Refresh(BackgroundImage *oldBackgroundImage,
|
||||
const BNode *fromNode, bool desktop, BPoseView *poseView);
|
||||
// respond to a background image setting change
|
||||
void ChangeImageSet(BPoseView *poseView);
|
||||
// change to the next imageSet if any, no refresh*/
|
||||
BackgroundImageInfo *ImageInfoForWorkspace(int32) const;
|
||||
|
||||
// return fIsDesktop
|
||||
bool IsDesktop() { return fIsDesktop;}
|
||||
|
||||
status_t SetBackgroundImage(BNode *node);
|
||||
|
||||
void Show(BackgroundImageInfo *, BView *view);
|
||||
|
||||
uint32 GetShowingImageSet() {return fShowingImageSet;}
|
||||
|
||||
void Add(BackgroundImageInfo *);
|
||||
void RemoveAll();
|
||||
|
||||
private:
|
||||
BackgroundImage(const BNode *, bool);
|
||||
// no public constructor, GetBackgroundImage factory function is
|
||||
// used instead
|
||||
|
||||
bool fIsDesktop;
|
||||
BNode fDefinedByNode;
|
||||
BView *fView;
|
||||
BGView* bgView;
|
||||
BackgroundImageInfo *fShowingBitmap;
|
||||
|
||||
BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
|
||||
|
||||
uint32 fImageSetPeriod; // period between imagesets, 0 if none
|
||||
uint32 fShowingImageSet; // current imageset
|
||||
uint32 fImageSetCount; // imageset count
|
||||
uint32 fCacheMode;// image cache strategy (0 all, 1 none, 2 own strategy)
|
||||
bool fRandomChange; // random or sequential change
|
||||
};
|
||||
|
||||
class Image {
|
||||
// element for each image
|
||||
public:
|
||||
Image(BPath path);
|
||||
~Image();
|
||||
|
||||
void UnloadBitmap();
|
||||
const char* GetName() {return name.String();}
|
||||
BBitmap* GetBitmap();
|
||||
BPath GetPath() {return fPath;}
|
||||
private:
|
||||
BBitmap *fBitmap;
|
||||
BPath fPath;
|
||||
BString name;
|
||||
};
|
||||
|
||||
#endif
|
||||
Executable
BIN
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,7 @@
|
||||
SubDir OBOS_TOP src prefs backgrounds ;
|
||||
|
||||
AddResources Backgrounds : Backgrounds.rsrc ;
|
||||
|
||||
Preference Backgrounds : BackgroundImage.cpp BGMain.cpp BGView.cpp BGWindow.cpp ;
|
||||
|
||||
LinkSharedOSLibs Backgrounds : be tracker translation ;
|
||||
@@ -0,0 +1,800 @@
|
||||
/*
|
||||
Open Tracker License
|
||||
|
||||
Terms and Conditions
|
||||
|
||||
Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice applies to all licensees
|
||||
and shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Except as contained in this notice, the name of Be Incorporated shall not be
|
||||
used in advertising or otherwise to promote the sale, use or other dealings in
|
||||
this Software without prior written authorization from Be Incorporated.
|
||||
|
||||
Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
|
||||
of Be Incorporated in the United States and other countries. Other brand product
|
||||
names are registered trademarks or trademarks of their respective holders.
|
||||
All rights reserved.
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
|
||||
** **
|
||||
** DANGER, WILL ROBINSON! **
|
||||
** **
|
||||
** The interfaces contained here are part of BeOS's **
|
||||
** **
|
||||
** >> PRIVATE NOT FOR PUBLIC USE << **
|
||||
** **
|
||||
** implementation. **
|
||||
** **
|
||||
** These interfaces WILL CHANGE in future releases. **
|
||||
** If you use them, your app WILL BREAK at some future time. **
|
||||
** **
|
||||
** (And yes, this does mean that binaries built from OpenTracker will not **
|
||||
** be compatible with some future releases of the OS. When that happens, **
|
||||
** we will provide an updated version of this file to keep compatibility.) **
|
||||
** **
|
||||
** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING **
|
||||
****************************************************************************/
|
||||
|
||||
//
|
||||
// ObjectList is a wrapper around BList that adds type safety,
|
||||
// optional object ownership, search, insert operations, etc.
|
||||
//
|
||||
|
||||
#ifndef __OBJECT_LIST__
|
||||
#define __OBJECT_LIST__
|
||||
|
||||
#ifndef _BE_H
|
||||
#include <List.h>
|
||||
#endif
|
||||
|
||||
#include <Debug.h>
|
||||
|
||||
template<class T> class BObjectList;
|
||||
|
||||
template<class T>
|
||||
struct UnaryPredicate {
|
||||
|
||||
virtual int operator()(const T *) const
|
||||
// virtual could be avoided here if FindBinaryInsertionIndex,
|
||||
// etc. were member template functions
|
||||
{ return 0; }
|
||||
|
||||
private:
|
||||
static int _unary_predicate_glue(const void *item, void *context);
|
||||
|
||||
friend class BObjectList<T>;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
int
|
||||
UnaryPredicate<T>::_unary_predicate_glue(const void *item, void *context)
|
||||
{
|
||||
return ((UnaryPredicate<T> *)context)->operator()((const T *)item);
|
||||
}
|
||||
|
||||
|
||||
class _PointerList_ : public BList {
|
||||
public:
|
||||
_PointerList_(const _PointerList_ &list);
|
||||
_PointerList_(int32 itemsPerBlock = 20, bool owning = false);
|
||||
~_PointerList_();
|
||||
|
||||
typedef void *(* GenericEachFunction)(void *, void *);
|
||||
typedef int (* GenericCompareFunction)(const void *, const void *);
|
||||
typedef int (* GenericCompareFunctionWithState)(const void *, const void *,
|
||||
void *);
|
||||
typedef int (* UnaryPredicateGlue)(const void *, void *);
|
||||
|
||||
void *EachElement(GenericEachFunction, void *);
|
||||
void SortItems(GenericCompareFunction);
|
||||
void SortItems(GenericCompareFunctionWithState, void *state);
|
||||
void HSortItems(GenericCompareFunction);
|
||||
void HSortItems(GenericCompareFunctionWithState, void *state);
|
||||
|
||||
void *BinarySearch(const void *, GenericCompareFunction) const;
|
||||
void *BinarySearch(const void *, GenericCompareFunctionWithState, void *state) const;
|
||||
|
||||
int32 BinarySearchIndex(const void *, GenericCompareFunction) const;
|
||||
int32 BinarySearchIndex(const void *, GenericCompareFunctionWithState, void *state) const;
|
||||
int32 BinarySearchIndexByPredicate(const void *, UnaryPredicateGlue) const;
|
||||
|
||||
bool Owning() const;
|
||||
bool ReplaceItem(int32, void *);
|
||||
|
||||
protected:
|
||||
bool owning;
|
||||
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class BObjectList : private _PointerList_ {
|
||||
public:
|
||||
|
||||
// iteration and sorting
|
||||
typedef T *(* EachFunction)(T *, void *);
|
||||
typedef const T *(* ConstEachFunction)(const T *, void *);
|
||||
typedef int (* CompareFunction)(const T *, const T *);
|
||||
typedef int (* CompareFunctionWithState)(const T *, const T *, void *state);
|
||||
|
||||
BObjectList(int32 itemsPerBlock = 20, bool owning = false);
|
||||
BObjectList(const BObjectList &list);
|
||||
// clones list; if list is owning, makes copies of all
|
||||
// the items
|
||||
|
||||
virtual ~BObjectList();
|
||||
|
||||
BObjectList &operator=(const BObjectList &list);
|
||||
// clones list; if list is owning, makes copies of all
|
||||
// the items
|
||||
|
||||
// adding and removing
|
||||
// ToDo:
|
||||
// change Add calls to return const item
|
||||
bool AddItem(T *);
|
||||
bool AddItem(T *, int32);
|
||||
bool AddList(BObjectList *);
|
||||
bool AddList(BObjectList *, int32);
|
||||
|
||||
bool RemoveItem(T *, bool deleteIfOwning = true);
|
||||
// if owning, deletes the removed item
|
||||
T *RemoveItemAt(int32);
|
||||
// returns the removed item
|
||||
|
||||
void MakeEmpty();
|
||||
|
||||
// item access
|
||||
T *ItemAt(int32) const;
|
||||
|
||||
bool ReplaceItem(int32 index, T *);
|
||||
// if list is owning, deletes the item at <index> first
|
||||
T *SwapWithItem(int32 index, T *newItem);
|
||||
// same as ReplaceItem, except does not delete old item at <index>,
|
||||
// returns it instead
|
||||
|
||||
T *FirstItem() const;
|
||||
T *LastItem() const;
|
||||
|
||||
// misc. getters
|
||||
int32 IndexOf(const T *) const;
|
||||
bool HasItem(const T *) const;
|
||||
bool IsEmpty() const;
|
||||
int32 CountItems() const;
|
||||
|
||||
T *EachElement(EachFunction, void *);
|
||||
const T *EachElement(ConstEachFunction, void *) const;
|
||||
|
||||
void SortItems(CompareFunction);
|
||||
void SortItems(CompareFunctionWithState, void *state);
|
||||
void HSortItems(CompareFunction);
|
||||
void HSortItems(CompareFunctionWithState, void *state);
|
||||
|
||||
// linear search, returns first item that matches predicate
|
||||
const T *FindIf(const UnaryPredicate<T> &) const;
|
||||
T *FindIf(const UnaryPredicate<T> &);
|
||||
|
||||
// list must be sorted with CompareFunction for these to work
|
||||
const T *BinarySearch(const T &, CompareFunction) const;
|
||||
const T *BinarySearch(const T &, CompareFunctionWithState, void *state) const;
|
||||
|
||||
// Binary insertion - list must be sorted with CompareFunction for
|
||||
// these to work
|
||||
|
||||
// simple insert
|
||||
void BinaryInsert(T *, CompareFunction);
|
||||
void BinaryInsert(T *, CompareFunctionWithState, void *state);
|
||||
void BinaryInsert(T *, const UnaryPredicate<T> &);
|
||||
|
||||
// unique insert, returns false if item already in list
|
||||
bool BinaryInsertUnique(T *, CompareFunction);
|
||||
bool BinaryInsertUnique(T *, CompareFunctionWithState, void *state);
|
||||
bool BinaryInsertUnique(T *, const UnaryPredicate<T> &);
|
||||
|
||||
// insert a copy of the item, returns new inserted item
|
||||
T *BinaryInsertCopy(const T ©This, CompareFunction);
|
||||
T *BinaryInsertCopy(const T ©This, CompareFunctionWithState, void *state);
|
||||
|
||||
// insert a copy of the item if not in list already
|
||||
// returns new inserted item or existing item in case of a conflict
|
||||
T *BinaryInsertCopyUnique(const T ©This, CompareFunction);
|
||||
T *BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState, void *state);
|
||||
|
||||
|
||||
int32 FindBinaryInsertionIndex(const UnaryPredicate<T> &, bool *alreadyInList = 0) const;
|
||||
// returns either the index into which a new item should be inserted
|
||||
// or index of an existing item that matches the predicate
|
||||
|
||||
// deprecated API, will go away
|
||||
BList *AsBList()
|
||||
{ return this; }
|
||||
const BList *AsBList() const
|
||||
{ return this; }
|
||||
private:
|
||||
void SetItem(int32, T *);
|
||||
};
|
||||
|
||||
template<class Item, class Result, class Param1>
|
||||
Result
|
||||
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1), Param1 p1)
|
||||
{
|
||||
Result result = 0;
|
||||
int32 count = list->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if ((result = (list->ItemAt(index)->*func)(p1)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Item, class Result, class Param1>
|
||||
Result
|
||||
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1), Param1 p1)
|
||||
{
|
||||
Result result = 0;
|
||||
int32 count = list->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if ((result = (*func)(list->ItemAt(index), p1)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Item, class Result, class Param1, class Param2>
|
||||
Result
|
||||
WhileEachListItem(BObjectList<Item> *list, Result (Item::*func)(Param1, Param2),
|
||||
Param1 p1, Param2 p2)
|
||||
{
|
||||
Result result = 0;
|
||||
int32 count = list->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if ((result = (list->ItemAt(index)->*func)(p1, p2)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Item, class Result, class Param1, class Param2>
|
||||
Result
|
||||
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2),
|
||||
Param1 p1, Param2 p2)
|
||||
{
|
||||
Result result = 0;
|
||||
int32 count = list->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if ((result = (*func)(list->ItemAt(index), p1, p2)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Item, class Result, class Param1, class Param2, class Param3, class Param4>
|
||||
Result
|
||||
WhileEachListItem(BObjectList<Item> *list, Result (*func)(Item *, Param1, Param2,
|
||||
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
|
||||
{
|
||||
Result result = 0;
|
||||
int32 count = list->CountItems();
|
||||
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if ((result = (*func)(list->ItemAt(index), p1, p2, p3, p4)) != 0)
|
||||
break;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class Item, class Result>
|
||||
void
|
||||
EachListItemIgnoreResult(BObjectList<Item> *list, Result (Item::*func)())
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(list->ItemAt(index)->*func)();
|
||||
}
|
||||
|
||||
template<class Item, class Param1>
|
||||
void
|
||||
EachListItem(BObjectList<Item> *list, void (*func)(Item *, Param1), Param1 p1)
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(func)(list->ItemAt(index), p1);
|
||||
}
|
||||
|
||||
template<class Item, class Param1, class Param2>
|
||||
void
|
||||
EachListItem(BObjectList<Item> *list, void (Item::*func)(Param1, Param2),
|
||||
Param1 p1, Param2 p2)
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(list->ItemAt(index)->*func)(p1, p2);
|
||||
}
|
||||
|
||||
template<class Item, class Param1, class Param2>
|
||||
void
|
||||
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2),
|
||||
Param1 p1, Param2 p2)
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(func)(list->ItemAt(index), p1, p2);
|
||||
}
|
||||
|
||||
template<class Item, class Param1, class Param2, class Param3>
|
||||
void
|
||||
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
|
||||
Param3), Param1 p1, Param2 p2, Param3 p3)
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(func)(list->ItemAt(index), p1, p2, p3);
|
||||
}
|
||||
|
||||
|
||||
template<class Item, class Param1, class Param2, class Param3, class Param4>
|
||||
void
|
||||
EachListItem(BObjectList<Item> *list, void (*func)(Item *,Param1, Param2,
|
||||
Param3, Param4), Param1 p1, Param2 p2, Param3 p3, Param4 p4)
|
||||
{
|
||||
int32 count = list->CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
(func)(list->ItemAt(index), p1, p2, p3, p4);
|
||||
}
|
||||
|
||||
// inline code
|
||||
|
||||
inline bool
|
||||
_PointerList_::Owning() const
|
||||
{
|
||||
return owning;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BObjectList<T>::BObjectList(int32 itemsPerBlock, bool owning)
|
||||
: _PointerList_(itemsPerBlock, owning)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BObjectList<T>::BObjectList(const BObjectList<T> &list)
|
||||
: _PointerList_(list)
|
||||
{
|
||||
owning = list.owning;
|
||||
if (owning) {
|
||||
// make our own copies in an owning list
|
||||
int32 count = list.CountItems();
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
T *item = list.ItemAt(index);
|
||||
if (item)
|
||||
item = new T(*item);
|
||||
SetItem(index, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BObjectList<T>::~BObjectList()
|
||||
{
|
||||
if (Owning())
|
||||
// have to nuke elements first
|
||||
MakeEmpty();
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BObjectList<T> &
|
||||
BObjectList<T>::operator=(const BObjectList<T> &list)
|
||||
{
|
||||
owning = list.owning;
|
||||
BObjectList<T> &result = (BObjectList<T> &)_PointerList_::operator=(list);
|
||||
if (owning) {
|
||||
// make our own copies in an owning list
|
||||
int32 count = list.CountItems();
|
||||
for (int32 index = 0; index < count; index++) {
|
||||
T *item = list.ItemAt(index);
|
||||
if (item)
|
||||
item = new T(*item);
|
||||
SetItem(index, item);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::AddItem(T *item)
|
||||
{
|
||||
// need to cast to void * to make T work for const pointers
|
||||
return _PointerList_::AddItem((void *)item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::AddItem(T *item, int32 atIndex)
|
||||
{
|
||||
return _PointerList_::AddItem((void *)item, atIndex);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::AddList(BObjectList<T> *newItems)
|
||||
{
|
||||
return _PointerList_::AddList(newItems);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::AddList(BObjectList<T> *newItems, int32 atIndex)
|
||||
{
|
||||
return _PointerList_::AddList(newItems, atIndex);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::RemoveItem(T *item, bool deleteIfOwning)
|
||||
{
|
||||
bool result = _PointerList_::RemoveItem((void *)item);
|
||||
|
||||
if (result && Owning() && deleteIfOwning)
|
||||
delete item;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::RemoveItemAt(int32 index)
|
||||
{
|
||||
return (T *)_PointerList_::RemoveItem(index);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T *
|
||||
BObjectList<T>::ItemAt(int32 index) const
|
||||
{
|
||||
return (T *)_PointerList_::ItemAt(index);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::ReplaceItem(int32 index, T *item)
|
||||
{
|
||||
if (owning)
|
||||
delete ItemAt(index);
|
||||
return _PointerList_::ReplaceItem(index, (void *)item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::SwapWithItem(int32 index, T *newItem)
|
||||
{
|
||||
T *result = ItemAt(index);
|
||||
_PointerList_::ReplaceItem(index, (void *)newItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::SetItem(int32 index, T *newItem)
|
||||
{
|
||||
_PointerList_::ReplaceItem(index, (void *)newItem);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int32
|
||||
BObjectList<T>::IndexOf(const T *item) const
|
||||
{
|
||||
return _PointerList_::IndexOf((void *)item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::FirstItem() const
|
||||
{
|
||||
return (T *)_PointerList_::FirstItem();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::LastItem() const
|
||||
{
|
||||
return (T *)_PointerList_::LastItem();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::HasItem(const T *item) const
|
||||
{
|
||||
return _PointerList_::HasItem((void *)item);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::IsEmpty() const
|
||||
{
|
||||
return _PointerList_::IsEmpty();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int32
|
||||
BObjectList<T>::CountItems() const
|
||||
{
|
||||
return _PointerList_::CountItems();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::MakeEmpty()
|
||||
{
|
||||
if (owning) {
|
||||
int32 count = CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
delete ItemAt(index);
|
||||
}
|
||||
_PointerList_::MakeEmpty();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::EachElement(EachFunction func, void *params)
|
||||
{
|
||||
return (T *)_PointerList_::EachElement((GenericEachFunction)func, params);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
const T *
|
||||
BObjectList<T>::EachElement(ConstEachFunction func, void *params) const
|
||||
{
|
||||
return (const T *)
|
||||
const_cast<BObjectList<T> *>(this)->_PointerList_::EachElement(
|
||||
(GenericEachFunction)func, params);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T *
|
||||
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate) const
|
||||
{
|
||||
int32 count = CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if (predicate.operator()(ItemAt(index)) == 0)
|
||||
return ItemAt(index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::FindIf(const UnaryPredicate<T> &predicate)
|
||||
{
|
||||
int32 count = CountItems();
|
||||
for (int32 index = 0; index < count; index++)
|
||||
if (predicate.operator()(ItemAt(index)) == 0)
|
||||
return ItemAt(index);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::SortItems(CompareFunction function)
|
||||
{
|
||||
_PointerList_::SortItems((GenericCompareFunction)function);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::SortItems(CompareFunctionWithState function, void *state)
|
||||
{
|
||||
_PointerList_::SortItems((GenericCompareFunctionWithState)function, state);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::HSortItems(CompareFunction function)
|
||||
{
|
||||
_PointerList_::HSortItems((GenericCompareFunction)function);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::HSortItems(CompareFunctionWithState function, void *state)
|
||||
{
|
||||
_PointerList_::HSortItems((GenericCompareFunctionWithState)function, state);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T *
|
||||
BObjectList<T>::BinarySearch(const T &key, CompareFunction func) const
|
||||
{
|
||||
return (const T *)_PointerList_::BinarySearch(&key,
|
||||
(GenericCompareFunction)func);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
const T *
|
||||
BObjectList<T>::BinarySearch(const T &key, CompareFunctionWithState func, void *state) const
|
||||
{
|
||||
return (const T *)_PointerList_::BinarySearch(&key,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::BinaryInsert(T *item, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunction)func);
|
||||
if (index >= 0)
|
||||
// already in list, add after existing
|
||||
AddItem(item, index + 1);
|
||||
else
|
||||
AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::BinaryInsert(T *item, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0)
|
||||
// already in list, add after existing
|
||||
AddItem(item, index + 1);
|
||||
else
|
||||
AddItem(item, -index - 1);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunction)func);
|
||||
if (index >= 0)
|
||||
return false;
|
||||
|
||||
AddItem(item, -index - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(item,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0)
|
||||
return false;
|
||||
|
||||
AddItem(item, -index - 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::BinaryInsertCopy(const T ©This, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(©This,
|
||||
(GenericCompareFunction)func);
|
||||
|
||||
if (index >= 0)
|
||||
index++;
|
||||
else
|
||||
index = -index - 1;
|
||||
|
||||
T *newItem = new T(copyThis);
|
||||
AddItem(newItem, index);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::BinaryInsertCopy(const T ©This, CompareFunctionWithState func, void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(©This,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
|
||||
if (index >= 0)
|
||||
index++;
|
||||
else
|
||||
index = -index - 1;
|
||||
|
||||
T *newItem = new T(copyThis);
|
||||
AddItem(newItem, index);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::BinaryInsertCopyUnique(const T ©This, CompareFunction func)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(©This,
|
||||
(GenericCompareFunction)func);
|
||||
if (index >= 0)
|
||||
return ItemAt(index);
|
||||
|
||||
index = -index - 1;
|
||||
T *newItem = new T(copyThis);
|
||||
AddItem(newItem, index);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
T *
|
||||
BObjectList<T>::BinaryInsertCopyUnique(const T ©This, CompareFunctionWithState func,
|
||||
void *state)
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndex(©This,
|
||||
(GenericCompareFunctionWithState)func, state);
|
||||
if (index >= 0)
|
||||
return ItemAt(index);
|
||||
|
||||
index = -index - 1;
|
||||
T *newItem = new T(copyThis);
|
||||
AddItem(newItem, index);
|
||||
return newItem;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
int32
|
||||
BObjectList<T>::FindBinaryInsertionIndex(const UnaryPredicate<T> &pred, bool *alreadyInList)
|
||||
const
|
||||
{
|
||||
int32 index = _PointerList_::BinarySearchIndexByPredicate(&pred,
|
||||
(UnaryPredicateGlue)&UnaryPredicate<T>::_unary_predicate_glue);
|
||||
|
||||
if (alreadyInList)
|
||||
*alreadyInList = index >= 0;
|
||||
|
||||
if (index < 0)
|
||||
index = -index - 1;
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void
|
||||
BObjectList<T>::BinaryInsert(T *item, const UnaryPredicate<T> &pred)
|
||||
{
|
||||
int32 index = FindBinaryInsertionIndex(pred);
|
||||
AddItem(item, index);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
bool
|
||||
BObjectList<T>::BinaryInsertUnique(T *item, const UnaryPredicate<T> &pred)
|
||||
{
|
||||
bool alreadyInList;
|
||||
int32 index = FindBinaryInsertionIndex(pred, &alreadyInList);
|
||||
if (alreadyInList)
|
||||
return false;
|
||||
|
||||
AddItem(item, index);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user