2005-06-17 23:10:15 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001-2005, Haiku, Inc.
|
|
|
|
* Distributed under the terms of the MIT license.
|
|
|
|
*
|
|
|
|
* Author: DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
*/
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
#include <Directory.h>
|
2005-11-03 20:03:36 +03:00
|
|
|
#include <Entry.h>
|
2005-06-17 23:10:15 +04:00
|
|
|
#include <File.h>
|
|
|
|
#include <Message.h>
|
2005-11-03 20:03:36 +03:00
|
|
|
#include <Path.h>
|
|
|
|
#include <Rect.h>
|
2005-06-17 23:10:15 +04:00
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
#include "AppServer.h"
|
2005-06-17 23:10:15 +04:00
|
|
|
#include "DefaultDecorator.h"
|
2005-11-03 20:03:36 +03:00
|
|
|
#include "Desktop.h"
|
|
|
|
#include "DesktopSettings.h"
|
2005-06-17 23:10:15 +04:00
|
|
|
#include "ServerConfig.h"
|
|
|
|
#include "DecorManager.h"
|
|
|
|
|
2007-02-24 02:35:01 +03:00
|
|
|
typedef float get_version(void);
|
|
|
|
typedef Decorator* create_decorator(DesktopSettings& desktopSettings, BRect rect,
|
|
|
|
window_look look, uint32 flags);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// Globals
|
|
|
|
DecorManager gDecorManager;
|
|
|
|
|
|
|
|
|
|
|
|
// This is a class used only by the DecorManager to track all the decorators in memory
|
2005-06-24 07:31:41 +04:00
|
|
|
class DecorInfo {
|
2005-11-03 20:03:36 +03:00
|
|
|
public:
|
|
|
|
DecorInfo(image_id id, const char* name,
|
|
|
|
create_decorator* allocator = NULL);
|
|
|
|
~DecorInfo();
|
|
|
|
|
|
|
|
status_t InitCheck() const;
|
|
|
|
|
|
|
|
image_id ID() const { return fID; }
|
|
|
|
const char* Name() const { return fName.String(); }
|
|
|
|
|
2006-12-16 02:05:35 +03:00
|
|
|
Decorator* Instantiate(Desktop* desktop, DrawingEngine* engine,
|
|
|
|
BRect rect, const char* title,
|
2005-12-01 17:56:01 +03:00
|
|
|
window_look look, uint32 flags);
|
2005-11-03 20:03:36 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
image_id fID;
|
|
|
|
BString fName;
|
2006-12-16 02:05:35 +03:00
|
|
|
create_decorator* fAllocator;
|
2005-06-17 23:10:15 +04:00
|
|
|
};
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo::DecorInfo(image_id id, const char* name, create_decorator* allocator)
|
2005-06-24 07:31:41 +04:00
|
|
|
:
|
|
|
|
fID(id),
|
2005-06-17 23:10:15 +04:00
|
|
|
fName(name),
|
2005-11-03 20:03:36 +03:00
|
|
|
fAllocator(allocator)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo::~DecorInfo()
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
|
|
|
// Do nothing. Normal programming practice would say that one should unload
|
|
|
|
// the object's associate image_id. However, there is some funkiness with
|
|
|
|
// the R5 kernel in which addons aren't unloaded when unload_add_on() is
|
|
|
|
// called -- perhaps it's lazy unloading or something. In any event, it
|
|
|
|
// causes crashes which are *extremely* hard to track down to this.
|
|
|
|
|
|
|
|
// Considering the usage of DecorInfo and DecorManager, we can live with
|
|
|
|
// this because the app_server will not the DecorManager is freed only
|
|
|
|
// when the app_server quits. It's not pretty, but it gets the job done.
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
Decorator *
|
2006-12-16 02:05:35 +03:00
|
|
|
DecorInfo::Instantiate(Desktop* desktop, DrawingEngine* engine, BRect rect,
|
|
|
|
const char *title, window_look look, uint32 flags)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2006-11-29 06:13:15 +03:00
|
|
|
if (!desktop->LockSingleWindow())
|
2006-08-26 19:13:08 +04:00
|
|
|
return NULL;
|
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
DesktopSettings settings(desktop);
|
|
|
|
Decorator *decorator;
|
2005-06-17 23:10:15 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
try {
|
|
|
|
if (fAllocator != NULL)
|
2005-12-01 17:56:01 +03:00
|
|
|
decorator = fAllocator(settings, rect, look, flags);
|
2005-11-03 20:03:36 +03:00
|
|
|
else
|
2005-12-01 17:56:01 +03:00
|
|
|
decorator = new DefaultDecorator(settings, rect, look, flags);
|
2005-11-03 20:03:36 +03:00
|
|
|
} catch (...) {
|
2006-08-26 19:13:08 +04:00
|
|
|
desktop->UnlockSingleWindow();
|
2005-11-03 20:03:36 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-26 19:13:08 +04:00
|
|
|
desktop->UnlockSingleWindow();
|
|
|
|
|
2006-12-16 02:05:35 +03:00
|
|
|
decorator->SetDrawingEngine(engine);
|
2005-11-03 20:03:36 +03:00
|
|
|
decorator->SetTitle(title);
|
2006-04-26 13:03:28 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
return decorator;
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
// #pragma mark -
|
|
|
|
|
|
|
|
|
|
|
|
DecorManager::DecorManager()
|
2005-11-04 19:56:15 +03:00
|
|
|
: BLocker("DecorManager"),
|
2005-06-24 07:31:41 +04:00
|
|
|
fDecorList(0),
|
2005-06-17 23:10:15 +04:00
|
|
|
fCurrentDecor(NULL)
|
|
|
|
{
|
|
|
|
// Start with the default decorator - index is always 0
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo *defaultDecor = new DecorInfo(-1, "Default", NULL);
|
|
|
|
fDecorList.AddItem(defaultDecor);
|
|
|
|
|
2006-04-26 13:03:28 +04:00
|
|
|
#if 0
|
2005-06-17 23:10:15 +04:00
|
|
|
// Add any on disk
|
|
|
|
RescanDecorators();
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// Find out which one should be the active one
|
|
|
|
BDirectory dir;
|
|
|
|
if (dir.SetTo(SERVER_SETTINGS_DIR) == B_ENTRY_NOT_FOUND)
|
|
|
|
create_directory(SERVER_SETTINGS_DIR, 0777);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
BMessage settings;
|
|
|
|
BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// Fallback to the default decorator if something goes wrong
|
2005-06-24 07:31:41 +04:00
|
|
|
if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) {
|
2005-06-17 23:10:15 +04:00
|
|
|
BString itemtext;
|
2005-06-24 07:31:41 +04:00
|
|
|
if (settings.FindString("decorator", &itemtext) == B_OK) {
|
2005-11-03 20:03:36 +03:00
|
|
|
fCurrentDecor = _FindDecor(itemtext.String());
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
}
|
2006-04-26 13:03:28 +04:00
|
|
|
#endif
|
2005-06-24 07:31:41 +04:00
|
|
|
if (!fCurrentDecor)
|
2005-11-03 20:03:36 +03:00
|
|
|
fCurrentDecor = (DecorInfo*)fDecorList.ItemAt(0L);
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
DecorManager::~DecorManager()
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
_EmptyList();
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
void
|
2005-06-24 07:31:41 +04:00
|
|
|
DecorManager::RescanDecorators()
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
|
|
|
BDirectory dir(DECORATORS_DIR);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
if (dir.InitCheck() != B_OK)
|
2005-06-17 23:10:15 +04:00
|
|
|
return;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
entry_ref ref;
|
2005-06-24 07:31:41 +04:00
|
|
|
while (dir.GetNextRef(&ref) == B_OK) {
|
2005-11-03 20:03:36 +03:00
|
|
|
BPath path;
|
|
|
|
path.SetTo(DECORATORS_DIR);
|
|
|
|
path.Append(ref.name);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// Because this function is used for both initialization and for keeping
|
|
|
|
// the list up to date, check for existence in the list. Note that we
|
|
|
|
// do not check to see if a decorator has been removed. This is for
|
|
|
|
// stability. If there is a decorator in memory already whose file has
|
|
|
|
// been deleted, it is still available until the next boot, at which point
|
|
|
|
// it will obviously not be loaded.
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
if (_FindDecor(ref.name))
|
2005-06-17 23:10:15 +04:00
|
|
|
continue;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
image_id image = load_add_on(path.Path());
|
|
|
|
if (image != B_OK)
|
2005-06-17 23:10:15 +04:00
|
|
|
continue;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// As of now, we do nothing with decorator versions, but the possibility
|
|
|
|
// exists that the API will change even though I cannot forsee any reason
|
|
|
|
// to do so. If we *did* do anything with decorator versions, the
|
|
|
|
// assignment would go here.
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
create_decorator* createFunc;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
// Get the instantiation function
|
2005-11-03 20:03:36 +03:00
|
|
|
status_t status = get_image_symbol(image, "instantiate_decorator",
|
|
|
|
B_SYMBOL_TYPE_TEXT, (void**)&createFunc);
|
2005-06-24 07:31:41 +04:00
|
|
|
if (status != B_OK) {
|
2005-11-03 20:03:36 +03:00
|
|
|
unload_add_on(image);
|
2005-06-17 23:10:15 +04:00
|
|
|
continue;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
// TODO: unload images until they are actually used!
|
|
|
|
fDecorList.AddItem(new DecorInfo(image, ref.name, createFunc));
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
Decorator *
|
2006-12-16 02:05:35 +03:00
|
|
|
DecorManager::AllocateDecorator(Desktop* desktop, DrawingEngine* engine,
|
|
|
|
BRect rect, const char* title, window_look look, uint32 flags)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2006-12-16 02:05:35 +03:00
|
|
|
// Create a new instance of the current decorator.
|
|
|
|
// Ownership is that of the caller
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
if (!fCurrentDecor) {
|
2005-06-17 23:10:15 +04:00
|
|
|
// We should *never* be here. If we do, it's a bug.
|
|
|
|
debugger("DecorManager::AllocateDecorator has a NULL decorator");
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2006-12-16 02:05:35 +03:00
|
|
|
return fCurrentDecor->Instantiate(desktop, engine, rect, title,
|
|
|
|
look, flags);
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
int32
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::CountDecorators() const
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
|
|
|
return fDecorList.CountItems();
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
int32
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::GetDecorator() const
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
return fDecorList.IndexOf(fCurrentDecor);
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
bool
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::SetDecorator(int32 index)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2006-12-16 02:05:35 +03:00
|
|
|
DecorInfo* newDecInfo = (DecorInfo*)fDecorList.ItemAt(index);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
if (newDecInfo) {
|
2005-06-17 23:10:15 +04:00
|
|
|
fCurrentDecor = newDecInfo;
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
bool
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::SetR5Decorator(int32 value)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
|
|
|
BString string;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
switch (value) {
|
|
|
|
case 0: string = "BeOS"; break;
|
|
|
|
case 1: string = "AmigaOS"; break;
|
|
|
|
case 2: string = "Windows"; break;
|
|
|
|
case 3: string = "MacOS"; break;
|
2005-06-17 23:10:15 +04:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo *newDecInfo = _FindDecor(string.String());
|
2005-06-24 07:31:41 +04:00
|
|
|
if (newDecInfo) {
|
2005-06-17 23:10:15 +04:00
|
|
|
fCurrentDecor = newDecInfo;
|
|
|
|
return true;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
const char *
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::GetDecoratorName(int32 index)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo *info = fDecorList.ItemAt(index);
|
2005-06-24 07:31:41 +04:00
|
|
|
if (info)
|
2005-11-03 20:03:36 +03:00
|
|
|
return info->Name();
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
void
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::_EmptyList()
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
for (int32 i = 0; i < fDecorList.CountItems(); i++) {
|
2005-11-03 20:03:36 +03:00
|
|
|
delete fDecorList.ItemAt(i);;
|
2005-06-17 23:10:15 +04:00
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
fDecorList.MakeEmpty();
|
2005-06-17 23:10:15 +04:00
|
|
|
fCurrentDecor = NULL;
|
|
|
|
}
|
|
|
|
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
DecorInfo*
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorManager::_FindDecor(const char *name)
|
2005-06-17 23:10:15 +04:00
|
|
|
{
|
2005-06-24 07:31:41 +04:00
|
|
|
if (!name)
|
2005-06-17 23:10:15 +04:00
|
|
|
return NULL;
|
2005-06-24 07:31:41 +04:00
|
|
|
|
|
|
|
for (int32 i = 0; i < fDecorList.CountItems(); i++) {
|
2005-11-03 20:03:36 +03:00
|
|
|
DecorInfo* info = fDecorList.ItemAt(i);
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-11-03 20:03:36 +03:00
|
|
|
if (strcmp(name, info->Name()) == 0)
|
2005-06-17 23:10:15 +04:00
|
|
|
return info;
|
|
|
|
}
|
2005-06-24 07:31:41 +04:00
|
|
|
|
2005-06-17 23:10:15 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|