Author: czeidler Date: 2011-07-25 06:31:54 +0200 (Mon, 25 Jul 2011) New Revision: 42483 Changeset: https://dev.haiku-os.org/changeset/42483 Added: haiku/trunk/src/servers/app/decorator/ haiku/trunk/src/servers/app/decorator/DecorManager.cpp haiku/trunk/src/servers/app/decorator/DecorManager.h haiku/trunk/src/servers/app/decorator/Decorator.cpp haiku/trunk/src/servers/app/decorator/Decorator.h haiku/trunk/src/servers/app/decorator/DefaultDecorator.cpp haiku/trunk/src/servers/app/decorator/DefaultDecorator.h haiku/trunk/src/servers/app/decorator/DefaultWindowBehaviour.cpp haiku/trunk/src/servers/app/decorator/DefaultWindowBehaviour.h haiku/trunk/src/servers/app/decorator/MagneticBorder.cpp haiku/trunk/src/servers/app/decorator/MagneticBorder.h haiku/trunk/src/servers/app/decorator/WindowBehaviour.cpp haiku/trunk/src/servers/app/decorator/WindowBehaviour.h haiku/trunk/src/servers/app/font/ haiku/trunk/src/servers/app/font/FontCache.cpp haiku/trunk/src/servers/app/font/FontCache.h haiku/trunk/src/servers/app/font/FontCacheEntry.cpp haiku/trunk/src/servers/app/font/FontCacheEntry.h haiku/trunk/src/servers/app/font/FontEngine.cpp haiku/trunk/src/servers/app/font/FontEngine.h haiku/trunk/src/servers/app/font/FontFamily.cpp haiku/trunk/src/servers/app/font/FontFamily.h haiku/trunk/src/servers/app/font/FontManager.cpp haiku/trunk/src/servers/app/font/FontManager.h haiku/trunk/src/servers/app/font/FontStyle.cpp haiku/trunk/src/servers/app/font/FontStyle.h haiku/trunk/src/servers/app/font/GlyphLayoutEngine.h Removed: haiku/trunk/src/servers/app/DecorManager.cpp haiku/trunk/src/servers/app/DecorManager.h haiku/trunk/src/servers/app/Decorator.cpp haiku/trunk/src/servers/app/Decorator.h haiku/trunk/src/servers/app/DefaultDecorator.cpp haiku/trunk/src/servers/app/DefaultDecorator.h haiku/trunk/src/servers/app/DefaultWindowBehaviour.cpp haiku/trunk/src/servers/app/DefaultWindowBehaviour.h haiku/trunk/src/servers/app/FontCache.cpp haiku/trunk/src/servers/app/FontCache.h haiku/trunk/src/servers/app/FontCacheEntry.cpp haiku/trunk/src/servers/app/FontCacheEntry.h haiku/trunk/src/servers/app/FontEngine.cpp haiku/trunk/src/servers/app/FontEngine.h haiku/trunk/src/servers/app/FontFamily.cpp haiku/trunk/src/servers/app/FontFamily.h haiku/trunk/src/servers/app/FontManager.cpp haiku/trunk/src/servers/app/FontManager.h haiku/trunk/src/servers/app/FontStyle.cpp haiku/trunk/src/servers/app/FontStyle.h haiku/trunk/src/servers/app/GlyphLayoutEngine.h haiku/trunk/src/servers/app/MagneticBorder.cpp haiku/trunk/src/servers/app/MagneticBorder.h haiku/trunk/src/servers/app/WindowBehaviour.cpp haiku/trunk/src/servers/app/WindowBehaviour.h Modified: haiku/trunk/src/add-ons/decorators/SATDecorator/Jamfile haiku/trunk/src/servers/app/Desktop.cpp haiku/trunk/src/servers/app/DrawState.h haiku/trunk/src/servers/app/Jamfile haiku/trunk/src/servers/app/ServerPicture.cpp haiku/trunk/src/servers/app/drawing/Jamfile haiku/trunk/src/servers/app/drawing/Painter/Jamfile haiku/trunk/src/servers/app/drawing/remote/Jamfile Log: Cleanup app server directory a bit by creating a font and a decorator sub folder. Modified: haiku/trunk/src/add-ons/decorators/SATDecorator/Jamfile =================================================================== --- haiku/trunk/src/add-ons/decorators/SATDecorator/Jamfile 2011-07-25 03:32:14 UTC (rev 42482) +++ haiku/trunk/src/add-ons/decorators/SATDecorator/Jamfile 2011-07-25 04:31:54 UTC (rev 42483) @@ -4,6 +4,8 @@ UsePrivateHeaders app graphics interface shared kernel ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app ] ; +UseHeaders [ FDirName $(HAIKU_TOP) src servers app decorator ] ; +UseHeaders [ FDirName $(HAIKU_TOP) src servers app font ] ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing ] ; UseHeaders [ FDirName $(HAIKU_TOP) src servers app drawing Painter ] ; UseFreeTypeHeaders ; Modified: haiku/trunk/src/servers/app/Desktop.cpp =================================================================== --- haiku/trunk/src/servers/app/Desktop.cpp 2011-07-25 03:32:14 UTC (rev 42482) +++ haiku/trunk/src/servers/app/Desktop.cpp 2011-07-25 04:31:54 UTC (rev 42483) @@ -40,6 +40,7 @@ #include "DecorManager.h" #include "DesktopSettingsPrivate.h" #include "DrawingEngine.h" +#include "FontManager.h" #include "HWInterface.h" #include "InputManager.h" #include "Screen.h" Modified: haiku/trunk/src/servers/app/DrawState.h =================================================================== --- haiku/trunk/src/servers/app/DrawState.h 2011-07-25 03:32:14 UTC (rev 42482) +++ haiku/trunk/src/servers/app/DrawState.h 2011-07-25 04:31:54 UTC (rev 42483) @@ -17,7 +17,6 @@ #include <Point.h> #include <View.h> // for B_FONT_ALL -#include "FontManager.h" #include "ServerFont.h" #include "PatternHandler.h" Modified: haiku/trunk/src/servers/app/Jamfile =================================================================== --- haiku/trunk/src/servers/app/Jamfile 2011-07-25 03:32:14 UTC (rev 42482) +++ haiku/trunk/src/servers/app/Jamfile 2011-07-25 04:31:54 UTC (rev 42483) @@ -8,6 +8,26 @@ UseFreeTypeHeaders ; +UseHeaders [ FDirName $(HAIKU_TOP) src servers app decorator ] ; +local decorator_src = + DecorManager.cpp + Decorator.cpp + DefaultDecorator.cpp + DefaultWindowBehaviour.cpp + MagneticBorder.cpp + WindowBehaviour.cpp + ; + +UseHeaders [ FDirName $(HAIKU_TOP) src servers app font ] ; +local font_src = + FontCache.cpp + FontCacheEntry.cpp + FontEngine.cpp + FontFamily.cpp + FontManager.cpp + FontStyle.cpp + ; + Server app_server : Angle.cpp AppServer.cpp @@ -18,10 +38,6 @@ CursorData.cpp CursorManager.cpp CursorSet.cpp - DecorManager.cpp - Decorator.cpp - DefaultDecorator.cpp - DefaultWindowBehaviour.cpp Desktop.cpp DesktopListener.cpp DesktopSettings.cpp @@ -29,17 +45,10 @@ DrawState.cpp EventDispatcher.cpp EventStream.cpp - FontCache.cpp - FontCacheEntry.cpp - FontEngine.cpp - FontFamily.cpp - FontManager.cpp - FontStyle.cpp HashTable.cpp InputManager.cpp IntPoint.cpp IntRect.cpp - MagneticBorder.cpp MessageLooper.cpp MultiLocker.cpp OffscreenServerWindow.cpp @@ -60,11 +69,13 @@ View.cpp VirtualScreen.cpp Window.cpp - WindowBehaviour.cpp WindowList.cpp Workspace.cpp WorkspacesView.cpp + $(decorator_src) + $(font_src) + # libraries : libtranslation.so libbe.so libbnetapi.so @@ -74,4 +85,8 @@ : app_server.rdef ; +SEARCH on [ FGristFiles $(decorator_src) ] = [ FDirName $(HAIKU_TOP) src servers app decorator ] ; +SEARCH on [ FGristFiles $(font_src) ] = [ FDirName $(HAIKU_TOP) src servers app font ] ; + + SubInclude HAIKU_TOP src servers app drawing ; Modified: haiku/trunk/src/servers/app/ServerPicture.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerPicture.cpp 2011-07-25 03:32:14 UTC (rev 42482) +++ haiku/trunk/src/servers/app/ServerPicture.cpp 2011-07-25 04:31:54 UTC (rev 42483) @@ -16,6 +16,7 @@ #include "DrawingEngine.h" #include "DrawState.h" +#include "FontManager.h" #include "ServerApp.h" #include "ServerBitmap.h" #include "ServerFont.h" Copied: haiku/trunk/src/servers/app/decorator/DecorManager.cpp (from rev 42478, haiku/trunk/src/servers/app/DecorManager.cpp) =================================================================== --- haiku/trunk/src/servers/app/decorator/DecorManager.cpp (rev 0) +++ haiku/trunk/src/servers/app/decorator/DecorManager.cpp 2011-07-25 04:31:54 UTC (rev 42483) @@ -0,0 +1,378 @@ +/* + * Copyright (c) 2001-2011, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * DarkWyrm <bpmagic@xxxxxxxxxxxxxxx> + * Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + * Joseph Groover <looncraz@xxxxxxxxxxx> + */ + +#include "DecorManager.h" + +#include <Directory.h> +#include <Entry.h> +#include <File.h> +#include <FindDirectory.h> +#include <Message.h> +#include <Path.h> +#include <Rect.h> + +#include <syslog.h> + +#include "AppServer.h" +#include "DefaultDecorator.h" +#include "DefaultWindowBehaviour.h" +#include "Desktop.h" +#include "DesktopSettings.h" +#include "ServerConfig.h" +#include "Window.h" + +typedef float get_version(void); +typedef DecorAddOn* create_decor_addon(image_id id, const char* name); + +// Globals +DecorManager gDecorManager; + + +DecorAddOn::DecorAddOn(image_id id, const char* name) + : + fImageID(id), + fName(name) +{ +} + + +DecorAddOn::~DecorAddOn() +{ +} + + +status_t +DecorAddOn::InitCheck() const +{ + return B_OK; +} + + +Decorator* +DecorAddOn::AllocateDecorator(Desktop* desktop, DrawingEngine* engine, + BRect rect, const char* title, window_look look, uint32 flags) +{ + if (!desktop->LockSingleWindow()) + return NULL; + + DesktopSettings settings(desktop); + Decorator* decorator; + decorator = _AllocateDecorator(settings, rect, look, flags); + desktop->UnlockSingleWindow(); + if (!decorator) + return NULL; + + if (decorator->AddTab(title) == false) { + delete decorator; + return NULL; + } + + decorator->SetDrawingEngine(engine); + return decorator; +} + + +WindowBehaviour* +DecorAddOn::AllocateWindowBehaviour(Window* window) +{ + return new (std::nothrow)DefaultWindowBehaviour(window); +} + + +const DesktopListenerList& +DecorAddOn::GetDesktopListeners() +{ + return fDesktopListeners; +} + + +Decorator* +DecorAddOn::_AllocateDecorator(DesktopSettings& settings, BRect rect, + window_look look, uint32 flags) +{ + return new (std::nothrow)DefaultDecorator(settings, rect, look, flags); +} + + +// #pragma mark - + + +DecorManager::DecorManager() + : + fDefaultDecor(-1, "Default"), + fCurrentDecor(&fDefaultDecor), + fPreviewDecor(NULL), + fPreviewWindow(NULL), + fCurrentDecorPath("Default") +{ + _LoadSettingsFromDisk(); +} + + +DecorManager::~DecorManager() +{ +} + + +Decorator* +DecorManager::AllocateDecorator(Window* window) +{ + // Create a new instance of the current decorator. + // Ownership is that of the caller + + if (!fCurrentDecor) { + // We should *never* be here. If we do, it's a bug. + debugger("DecorManager::AllocateDecorator has a NULL decorator"); + return NULL; + } + + // Are we previewing a specific decorator? + if (window == fPreviewWindow) { + if (fPreviewDecor != NULL) { + return fPreviewDecor->AllocateDecorator(window->Desktop(), + window->GetDrawingEngine(), window->Frame(), window->Title(), + window->Look(), window->Flags()); + } else { + fPreviewWindow = NULL; + } + } + + return fCurrentDecor->AllocateDecorator(window->Desktop(), + window->GetDrawingEngine(), window->Frame(), window->Title(), + window->Look(), window->Flags()); +} + + +WindowBehaviour* +DecorManager::AllocateWindowBehaviour(Window* window) +{ + if (!fCurrentDecor) { + // We should *never* be here. If we do, it's a bug. + debugger("DecorManager::AllocateDecorator has a NULL decorator"); + return NULL; + } + + return fCurrentDecor->AllocateWindowBehaviour(window); +} + + +void +DecorManager::CleanupForWindow(Window* window) +{ + // Given window is being deleted, do any cleanup needed + if (fPreviewWindow == window && window != NULL){ + fPreviewWindow = NULL; + + if (fPreviewDecor != NULL) + unload_add_on(fPreviewDecor->ImageID()); + + fPreviewDecor = NULL; + } +} + + +status_t +DecorManager::PreviewDecorator(BString path, Window* window) +{ + if (fPreviewWindow != NULL && fPreviewWindow != window){ + // Reset other window to current decorator - only one can preview + Window* oldPreviewWindow = fPreviewWindow; + fPreviewWindow = NULL; + oldPreviewWindow->ReloadDecor(); + } + + if (window == NULL) + return B_BAD_VALUE; + + // We have to jump some hoops because the window must be able to + // delete its decorator before we unload the add-on + status_t error = B_OK; + DecorAddOn* decorPtr = _LoadDecor(path, error); + if (decorPtr == NULL) + return error == B_OK ? B_ERROR : error; + + BRegion border; + window->GetBorderRegion(&border); + + DecorAddOn* oldDecor = fPreviewDecor; + fPreviewDecor = decorPtr; + fPreviewWindow = window; + // After this call, the window has deleted its decorator. + fPreviewWindow->ReloadDecor(); + + BRegion newBorder; + window->GetBorderRegion(&newBorder); + + border.Include(&newBorder); + window->Desktop()->RebuildAndRedrawAfterWindowChange(window, border); + + if (oldDecor != NULL) + unload_add_on(oldDecor->ImageID()); + + return B_OK; +} + + +const DesktopListenerList& +DecorManager::GetDesktopListeners() +{ + return fCurrentDecor->GetDesktopListeners(); +} + + +BString +DecorManager::GetCurrentDecorator() const +{ + return fCurrentDecorPath.String(); +} + + +status_t +DecorManager::SetDecorator(BString path, Desktop* desktop) +{ + status_t error = B_OK; + DecorAddOn* newDecor = _LoadDecor(path, error); + if (newDecor == NULL) + return error == B_OK ? B_ERROR : error; + + DecorAddOn* oldDecor = fCurrentDecor; + BString oldPath = fCurrentDecorPath; + image_id oldImage = fCurrentDecor->ImageID(); + + fCurrentDecor = newDecor; + fCurrentDecorPath = path.String(); + + if (desktop->ReloadDecor()) { + // now safe to unload all old decorator data + // saves us from deleting oldDecor... + unload_add_on(oldImage); + _SaveSettingsToDisk(); + return B_OK; + } + + // TODO: unloading the newDecor and its image + // problem is we don't know how many windows failed... or why they failed... + syslog(LOG_WARNING, + "app_server:DecorManager:SetDecorator:\"%s\" *partly* failed\n", + fCurrentDecorPath.String()); + + fCurrentDecor = oldDecor; + fCurrentDecorPath = oldPath; + return B_ERROR; +} + + +DecorAddOn* +DecorManager::_LoadDecor(BString _path, status_t& error ) +{ + if (_path == "Default") { + error = B_OK; + return &fDefaultDecor; + } + + BEntry entry(_path.String(), true); + if (!entry.Exists()) { + error = B_ENTRY_NOT_FOUND; + return NULL; + } + + BPath path(&entry); + image_id image = load_add_on(path.Path()); + if (image < 0) { + error = B_BAD_IMAGE_ID; + return NULL; + } + + create_decor_addon* createFunc; + if (get_image_symbol(image, "instantiate_decor_addon", B_SYMBOL_TYPE_TEXT, + (void**)&createFunc) != B_OK) { + unload_add_on(image); + error = B_MISSING_SYMBOL; + return NULL; + } + + char name[B_FILE_NAME_LENGTH]; + entry.GetName(name); + DecorAddOn* newDecor = createFunc(image, name); + if (newDecor == NULL || newDecor->InitCheck() != B_OK) { + unload_add_on(image); + error = B_ERROR; + return NULL; + } + + return newDecor; +} + + +static const char* kSettingsDir = "system/app_server"; +static const char* kSettingsFile = "decorator_settings"; + + +bool +DecorManager::_LoadSettingsFromDisk() +{ + // get the user settings directory + BPath path; + status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); + if (error != B_OK) + return false; + + path.Append(kSettingsDir); + path.Append(kSettingsFile); + BFile file(path.Path(), B_READ_ONLY); + if (file.InitCheck() != B_OK) + return false; + + BMessage settings; + if (settings.Unflatten(&file) == B_OK) { + BString itemPath; + if (settings.FindString("decorator", &itemPath) == B_OK) { + status_t error = B_OK; + DecorAddOn* decor = _LoadDecor(itemPath, error); + if (decor != NULL) { + fCurrentDecor = decor; + return true; + } else { + //TODO: do something with the reported error + } + } + } + + return false; +} + + +bool +DecorManager::_SaveSettingsToDisk() +{ + // get the user settings directory + BPath path; + status_t error = find_directory(B_USER_SETTINGS_DIRECTORY, &path, true); + if (error != B_OK) + return false; + + path.Append(kSettingsDir); + if (create_directory(path.Path(), 777) != B_OK) + return false; + + path.Append(kSettingsFile); + BFile file(path.Path(), B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); + if (file.InitCheck() != B_OK) + return false; + + BMessage settings; + if (settings.AddString("decorator", fCurrentDecorPath.String()) != B_OK) + return false; + if (settings.Flatten(&file) != B_OK) + return false; + + return true; +} + Copied: haiku/trunk/src/servers/app/decorator/DecorManager.h (from rev 42471, haiku/trunk/src/servers/app/DecorManager.h) =================================================================== --- haiku/trunk/src/servers/app/decorator/DecorManager.h (rev 0) +++ haiku/trunk/src/servers/app/decorator/DecorManager.h 2011-07-25 04:31:54 UTC (rev 42483) @@ -0,0 +1,97 @@ +/* + * Copyright (c) 2001-2005, Haiku, Inc. + * Distributed under the terms of the MIT license. + * + * Author: + * DarkWyrm <bpmagic@xxxxxxxxxxxxxxx> + * Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + */ +#ifndef DECOR_MANAGER_H +#define DECOR_MANAGER_H + + +#include <image.h> +#include <String.h> +#include <Locker.h> +#include <ObjectList.h> +#include <Entry.h> +#include <DecorInfo.h> + +#include "Decorator.h" + +class Desktop; +class DesktopListener; +class DrawingEngine; +class Window; +class WindowBehaviour; + + +typedef BObjectList<DesktopListener> DesktopListenerList; + + +// special name to test for use of non-fs-tied default decorator +// this just keeps things clean and simple is all + +class DecorAddOn { +public: + DecorAddOn(image_id id, const char* name); + virtual ~DecorAddOn(); + + virtual status_t InitCheck() const; + + image_id ImageID() const { return fImageID; } + + Decorator* AllocateDecorator(Desktop* desktop, + DrawingEngine* engine, BRect rect, + const char* title, window_look look, + uint32 flags); + + virtual WindowBehaviour* AllocateWindowBehaviour(Window* window); + + virtual const DesktopListenerList& GetDesktopListeners(); + +protected: + virtual Decorator* _AllocateDecorator(DesktopSettings& settings, + BRect rect, window_look look, uint32 flags); + + DesktopListenerList fDesktopListeners; + +private: + image_id fImageID; + BString fName; +}; + + +class DecorManager { +public: + DecorManager(); + ~DecorManager(); + + Decorator* AllocateDecorator(Window *window); + WindowBehaviour* AllocateWindowBehaviour(Window *window); + void CleanupForWindow(Window *window); + + status_t PreviewDecorator(BString path, Window *window); + + const DesktopListenerList& GetDesktopListeners(); + + BString GetCurrentDecorator() const; + status_t SetDecorator(BString path, Desktop *desktop); + +private: + DecorAddOn* _LoadDecor(BString path, status_t &error); + bool _LoadSettingsFromDisk(); + bool _SaveSettingsToDisk(); + +private: + DecorAddOn fDefaultDecor; + DecorAddOn* fCurrentDecor; + DecorAddOn* fPreviewDecor; + + Window* fPreviewWindow; + BString fCurrentDecorPath; +}; + +extern DecorManager gDecorManager; + +#endif /* DECOR_MANAGER_H */ Copied: haiku/trunk/src/servers/app/decorator/Decorator.cpp (from rev 42478, haiku/trunk/src/servers/app/Decorator.cpp) =================================================================== --- haiku/trunk/src/servers/app/decorator/Decorator.cpp (rev 0) +++ haiku/trunk/src/servers/app/decorator/Decorator.cpp 2011-07-25 04:31:54 UTC (rev 42483) @@ -0,0 +1,906 @@ +/* + * Copyright 2001-2011, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm <bpmagic@xxxxxxxxxxxxxxx> + * Stephan Aßmus <superstippi@xxxxxx> + * Clemens Zeidler <haiku@xxxxxxxxxxxxxxxxxx> + * Ingo Weinhold <ingo_weinhold@xxxxxx> + */ + + +/*! Base class for window decorators */ + + +#include "Decorator.h" + +#include <stdio.h> + +#include <Region.h> + +#include "DrawingEngine.h" + + +Decorator::Tab::Tab() + : + zoomRect(), + closeRect(), + minimizeRect(), + + closePressed(false), + zoomPressed(false), + minimizePressed(false), + isFocused(false), + title("") +{ + +} + + +/*! \brief Constructor + + Does general initialization of internal data members and creates a colorset + object. + + \param rect Size of client area + \param wlook style of window look. See Window.h + \param wfeel style of window feel. See Window.h + \param wflags various window flags. See Window.h +*/ +Decorator::Decorator(DesktopSettings& settings, BRect rect, window_look look, + uint32 flags) + : + fDrawingEngine(NULL), + fDrawState(), + + fLook(look), + fFlags(flags), + + fTitleBarRect(), + fFrame(rect), + fResizeRect(), + fBorderRect(), + + fTopTab(NULL), + + fFootprintValid(false) +{ + memset(&fRegionHighlights, HIGHLIGHT_NONE, sizeof(fRegionHighlights)); +} + + +/*! + \brief Destructor + + Frees the color set and the title string +*/ +Decorator::~Decorator() +{ +} + + +Decorator::Tab* +Decorator::AddTab(const char* title, int32 index, BRegion* updateRegion) +{ + Decorator::Tab* tab = _AllocateNewTab(); + if (tab == NULL) + return NULL; + tab->title = title; + + bool ok = false; + if (index >= 0) { + if (fTabList.AddItem(tab, index) == true) + ok = true; + } else if (fTabList.AddItem(tab) == true) + ok = true; + + if (ok == false) { + delete tab; + return NULL; + } + + if (_AddTab(index, updateRegion) == false) { + fTabList.RemoveItem(tab); + delete tab; + return NULL; + } + + if (fTopTab == NULL) + fTopTab = tab; + + _InvalidateFootprint(); + return tab; +} + + +bool +Decorator::RemoveTab(int32 index, BRegion* updateRegion) +{ + Decorator::Tab* tab = fTabList.RemoveItemAt(index); + if (tab == NULL) + return false; + + _RemoveTab(index, updateRegion); + + delete tab; + _InvalidateFootprint(); + return true; +} + + +bool +Decorator::MoveTab(int32 from, int32 to, bool isMoving, BRegion* updateRegion) +{ + if (_MoveTab(from, to, isMoving, updateRegion) == false) + return false; + if (fTabList.MoveItem(from, to) == false) { + // move the tab back + _MoveTab(from, to, isMoving, updateRegion); + return false; + } + return true; +} + + +int32 +Decorator::TabAt(const BPoint& where) const +{ + for (int32 i = 0; i < fTabList.CountItems(); i++) { + Decorator::Tab* tab = fTabList.ItemAt(i); + if (tab->tabRect.Contains(where)) + return i; + } + + return -1; +} + + +void +Decorator::SetTopTap(int32 tab) +{ + fTopTab = fTabList.ItemAt(tab); +} + + +/*! \brief Assigns a display driver to the decorator + \param driver A valid DrawingEngine object +*/ +void +Decorator::SetDrawingEngine(DrawingEngine* engine) +{ + fDrawingEngine = engine; + // lots of subclasses will depend on the driver for text support, so call + // _DoLayout() after we have it + if (fDrawingEngine) + _DoLayout(); +} + + +/*! \brief Sets the decorator's window flags + + While this call will not update the screen, it will affect how future + updates work and immediately affects input handling. + + \param flags New value for the flags +*/ +void +Decorator::SetFlags(uint32 flags, BRegion* updateRegion) +{ + // we're nice to our subclasses - we make sure B_NOT_{H|V|}_RESIZABLE + // are in sync (it's only a semantical simplification, not a necessity) + if ((flags & (B_NOT_H_RESIZABLE | B_NOT_V_RESIZABLE)) + == (B_NOT_H_RESIZABLE | B_NOT_V_RESIZABLE)) + flags |= B_NOT_RESIZABLE; + if (flags & B_NOT_RESIZABLE) + flags |= B_NOT_H_RESIZABLE | B_NOT_V_RESIZABLE; + + _SetFlags(flags, updateRegion); + _InvalidateFootprint(); + // the border might have changed (smaller/larger tab) +} + + +/*! \brief Called whenever the system fonts are changed. +*/ +void +Decorator::FontsChanged(DesktopSettings& settings, BRegion* updateRegion) +{ + _FontsChanged(settings, updateRegion); + _InvalidateFootprint(); +} + + +/*! \brief Sets the decorator's window look + \param look New value for the look +*/ +void +Decorator::SetLook(DesktopSettings& settings, window_look look, + BRegion* updateRect) +{ + _SetLook(settings, look, updateRect); + _InvalidateFootprint(); + // the border very likely changed +} + + +/*! \brief Returns the decorator's window look + \return the decorator's window look +*/ +window_look +Decorator::Look() const +{ + return fLook; +} + + +/*! \brief Returns the decorator's window flags + \return the decorator's window flags +*/ +uint32 +Decorator::Flags() const +{ + return fFlags; +} + + +/*! \brief Returns the decorator's border rectangle + \return the decorator's border rectangle +*/ +BRect +Decorator::BorderRect() const +{ + return fBorderRect; +} + + +BRect +Decorator::TitleBarRect() const +{ + return fTitleBarRect; +} + + +/*! \brief Returns the decorator's tab rectangle + \return the decorator's tab rectangle +*/ +BRect +Decorator::TabRect(int32 tab) const +{ + Decorator::Tab* decoratorTab = fTabList.ItemAt(tab); + if (decoratorTab == NULL) + return BRect(); + return decoratorTab->tabRect; +} + + +BRect +Decorator::TabRect(Decorator::Tab* tab) const +{ + return tab->tabRect; +} + + +/*! \brief Sets the close button's value. + + Note that this does not update the button's look - it just updates the + internal button value + + \param is_down Whether the button is down or not +*/ +void +Decorator::SetClose(int32 tab, bool pressed) +{ + Decorator::Tab* decoratorTab = fTabList.ItemAt(tab); + if (decoratorTab == NULL) + return; + + if (pressed != decoratorTab->closePressed) { + decoratorTab->closePressed = pressed; + DrawClose(tab); + } +} + +/*! \brief Sets the minimize button's value. + + Note that this does not update the button's look - it just updates the + internal button value + + \param is_down Whether the button is down or not +*/ +void +Decorator::SetMinimize(int32 tab, bool pressed) +{ + Decorator::Tab* decoratorTab = fTabList.ItemAt(tab); + if (decoratorTab == NULL) + return; + + if (pressed != decoratorTab->minimizePressed) { + decoratorTab->minimizePressed = pressed; + DrawMinimize(tab); + } +} + +/*! \brief Sets the zoom button's value. + + Note that this does not update the button's look - it just updates the + internal button value + + \param is_down Whether the button is down or not +*/ +void +Decorator::SetZoom(int32 tab, bool pressed) +{ + Decorator::Tab* decoratorTab = fTabList.ItemAt(tab); + if (decoratorTab == NULL) + return; + + if (pressed != decoratorTab->zoomPressed) { + decoratorTab->zoomPressed = pressed; + DrawZoom(tab); + } +} + + +/*! \brief Updates the value of the decorator title + \param string New title value +*/ +void +Decorator::SetTitle(int32 tab, const char* string, BRegion* updateRegion) +{ + Decorator::Tab* decoratorTab = fTabList.ItemAt(tab); + if (decoratorTab == NULL) + return; + + decoratorTab->title.SetTo(string); + _SetTitle(decoratorTab, string, updateRegion); + + _InvalidateFootprint(); + // the border very likely changed + + // TODO: redraw? +} + + +/*! \brief Returns the decorator's title + \return the decorator's title +*/ +const char* +Decorator::Title(int32 tab) const +{ [... truncated: 8737 lines follow ...]