diff --git a/headers/private/servers/app/BitmapManager.h b/headers/private/servers/app/BitmapManager.h index 629566991c..3782127601 100644 --- a/headers/private/servers/app/BitmapManager.h +++ b/headers/private/servers/app/BitmapManager.h @@ -1,36 +1,19 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: BitmapManager.h -// Author: DarkWyrm -// Description: Handler for allocating and freeing area memory for BBitmaps -// on the server side. Utilizes the BGET pool allocator. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ #ifndef BITMAP_MANAGER_H_ #define BITMAP_MANAGER_H_ + #include #include #include #include +#include #include "BGet++.h" #include "TokenHandler.h" @@ -64,10 +47,10 @@ class BitmapManager { area_id fBitmapArea; int8* fBuffer; TokenHandler fTokenizer; - sem_id fLock; + BLocker fLock; AreaPool fMemPool; }; -extern BitmapManager *bitmapmanager; +extern BitmapManager *gBitmapManager; -#endif +#endif /* BITMAP_MANAGER_H_ */ diff --git a/headers/private/servers/app/FontServer.h b/headers/private/servers/app/FontServer.h index 3167b75aed..0c2d90771f 100644 --- a/headers/private/servers/app/FontServer.h +++ b/headers/private/servers/app/FontServer.h @@ -1,29 +1,10 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: FontServer.h -// Author: DarkWyrm -// Description: Handles the largest part of the font subsystem -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ #ifndef FONTSERVER_H_ #define FONTSERVER_H_ @@ -31,6 +12,8 @@ #include #include #include +#include + #include #include FT_FREETYPE_H #include FT_CACHE_H @@ -43,60 +26,59 @@ class ServerFont; \class FontServer FontServer.h \brief Manager for the largest part of the font subsystem */ -class FontServer -{ +class FontServer : public BLocker { public: FontServer(void); ~FontServer(void); - bool Lock(void); - void Unlock(void); - + /*! \brief Determines whether the font server has started up properly \return true if so, false if not. */ - bool IsInitialized(void) { return init; } + bool IsInitialized(void) { return fInit; } int32 CountFamilies(void); int32 CountStyles(const char *family); void RemoveFamily(const char *family); status_t ScanDirectory(const char *path); void SaveList(void); - + const char *GetFamilyName(uint16 id) const; const char *GetStyleName(const char *family, uint16 id) const; - + FontStyle *GetStyle(const char *family, const char *face); FontStyle *GetStyle(const char *family, uint16 id) const; FontStyle *GetStyle(const uint16 &familyid, const uint16 &styleid); FontFamily *GetFamily(const uint16 &familyid) const; FontFamily *GetFamily(const char *name) const; - + ServerFont *GetSystemPlain(void); ServerFont *GetSystemBold(void); ServerFont *GetSystemFixed(void); - + bool SetSystemPlain(const char *family, const char *style, float size); bool SetSystemBold(const char *family, const char *style, float size); bool SetSystemFixed(const char *family, const char *style, float size); - - bool FontsNeedUpdated(void) { return need_update; } + + bool FontsNeedUpdated(void) { return fNeedUpdate; } /*! \brief Called when the fonts list has been updated */ - void FontsUpdated(void) { need_update=false; } + void FontsUpdated(void) { fNeedUpdate = false; } + protected: uint16 TranslateStyleToFace(const char *name) const; FT_CharMap _GetSupportedCharmap(const FT_Face &face); - bool init; - sem_id lock; - BList *families; - ServerFont *plain, *bold, *fixed; - bool need_update; + +private: + bool fInit; + BList fFamilies; + ServerFont *fPlain, *fBold, *fFixed; + bool fNeedUpdate; }; extern FTC_Manager ftmanager; extern FT_Library ftlib; -extern FontServer *fontserver; +extern FontServer *gFontServer; -#endif +#endif /* FONTSERVER_H_ */ diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index a24450989f..bda5b87744 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -71,7 +71,7 @@ static AppServer *sAppServer; //RGBColor workspace_default_color(51,102,160); //! System-wide GUI color object -ColorSet gui_colorset; +ColorSet gGUIColorSet; /*! \brief Constructor @@ -104,22 +104,22 @@ AppServer::AppServer(void) : sAppServer = this; // Create the font server and scan the proper directories. - fontserver = new FontServer; - fontserver->Lock(); + gFontServer = new FontServer; + gFontServer->Lock(); // Used for testing purposes // TODO: Re-enable scanning of all font directories when server is actually put to use - fontserver->ScanDirectory("/boot/beos/etc/fonts/ttfonts/"); -// fontserver->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/"); -// fontserver->ScanDirectory("/boot/home/config/fonts/ttfonts/"); -// fontserver->ScanDirectory("/boot/home/config/fonts/psfonts/"); - fontserver->SaveList(); + gFontServer->ScanDirectory("/boot/beos/etc/fonts/ttfonts/"); +// gFontServer->ScanDirectory("/boot/beos/etc/fonts/PS-Type1/"); +// gFontServer->ScanDirectory("/boot/home/config/fonts/ttfonts/"); +// gFontServer->ScanDirectory("/boot/home/config/fonts/psfonts/"); + gFontServer->SaveList(); - if (!fontserver->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY, + if (!gFontServer->SetSystemPlain(DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE, DEFAULT_PLAIN_FONT_SIZE) && - !fontserver->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY, + !gFontServer->SetSystemPlain(FALLBACK_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE, DEFAULT_PLAIN_FONT_SIZE)) { printf("Couldn't set plain to %s (fallback: %s), %s %d pt\n", @@ -129,10 +129,10 @@ AppServer::AppServer(void) : DEFAULT_PLAIN_FONT_SIZE); } - if (!fontserver->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY, + if (!gFontServer->SetSystemBold(DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, DEFAULT_BOLD_FONT_SIZE) && - !fontserver->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY, + !gFontServer->SetSystemBold(FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, DEFAULT_BOLD_FONT_SIZE)) { printf("Couldn't set bold to %s (fallback: %s), %s %d pt\n", @@ -142,10 +142,10 @@ AppServer::AppServer(void) : DEFAULT_BOLD_FONT_SIZE); } - if (!fontserver->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY, + if (!gFontServer->SetSystemFixed(DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, DEFAULT_FIXED_FONT_SIZE) && - !fontserver->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY, + !gFontServer->SetSystemFixed(FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, DEFAULT_FIXED_FONT_SIZE)) { printf("Couldn't set fixed to %s (fallback: %s), %s %d pt\n", @@ -155,12 +155,12 @@ AppServer::AppServer(void) : DEFAULT_FIXED_FONT_SIZE); } - fontserver->Unlock(); + gFontServer->Unlock(); // Load the GUI colors here and set the global set to the values contained therein. If this // is not possible, set colors to the defaults - if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME,&gui_colorset)!=B_OK) - gui_colorset.SetToDefaults(); + if (LoadColorSet(SERVER_SETTINGS_DIR COLOR_SETTINGS_NAME, &gGUIColorSet) != B_OK) + gGUIColorSet.SetToDefaults(); // Set up the Desktop gDesktop = new Desktop(); @@ -170,7 +170,7 @@ AppServer::AppServer(void) : InitializeColorMap(); // Create the bitmap allocator. Object declared in BitmapManager.cpp - bitmapmanager = new BitmapManager(); + gBitmapManager = new BitmapManager(); // This is necessary to mediate access between the Poller and app_server threads fActiveAppLock = create_sem(1,"app_server_active_sem"); @@ -194,7 +194,7 @@ AppServer::AppServer(void) : Reached only when the server is asked to shut down in Test mode. Kills all apps, shuts down the desktop, kills the housekeeping threads, etc. */ -AppServer::~AppServer(void) +AppServer::~AppServer() { debugger("We shouldn't be here! MainLoop()::B_QUIT_REQUESTED should see if we can exit the server.\n"); /* @@ -210,7 +210,7 @@ AppServer::~AppServer(void) delete fAppList; release_sem(fAppListLock); - delete bitmapmanager; + delete gBitmapManager; delete gDesktop; @@ -221,7 +221,7 @@ AppServer::~AppServer(void) kill_thread(fCursorThreadID); kill_thread(fISThreadID); - delete fontserver; + delete gFontServer; make_decorator=NULL; */ @@ -504,9 +504,9 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg) case AS_UPDATED_CLIENT_FONTLIST: // received when the client-side global font list has been // refreshed - fontserver->Lock(); - fontserver->FontsUpdated(); - fontserver->Unlock(); + gFontServer->Lock(); + gFontServer->FontsUpdated(); + gFontServer->Unlock(); break; case AS_QUERY_FONTS_CHANGED: @@ -516,18 +516,18 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg) // Attached data: // 1) port_id reply port - - fontserver->Lock(); - bool needs_update=fontserver->FontsNeedUpdated(); - fontserver->Unlock(); - + + gFontServer->Lock(); + bool needsUpdate = gFontServer->FontsNeedUpdated(); + gFontServer->Unlock(); + // Seeing how the client merely wants an answer, we'll skip the BPortLink // and all its overhead and just write the code to port. port_id replyport; if (msg.Read(&replyport) < B_OK) break; BPrivate::PortLink replylink(replyport); - replylink.StartMessage(needs_update ? SERVER_TRUE : SERVER_FALSE); + replylink.StartMessage(needsUpdate ? SERVER_TRUE : SERVER_FALSE); replylink.Flush(); break; } @@ -564,8 +564,8 @@ AppServer::DispatchMessage(int32 code, BPrivate::PortLink &msg) release_sem(fAppListLock); delete gDesktop; - delete bitmapmanager; - delete fontserver; + delete gBitmapManager; + delete gFontServer; // we are now clear to exit exit_thread(0); diff --git a/src/servers/app/AppServer.h b/src/servers/app/AppServer.h index ec09acbcb2..93fb055d64 100644 --- a/src/servers/app/AppServer.h +++ b/src/servers/app/AppServer.h @@ -87,9 +87,8 @@ private: DisplayDriver *fDriver; }; -extern BitmapManager *bitmapmanager; -extern ColorSet gui_colorset; -extern AppServer *app_server; +extern BitmapManager *gBitmapManager; +extern ColorSet gGUIColorSet; extern port_id gAppServerPort; #endif /* _HAIKU_APP_SERVER_H_ */ diff --git a/src/servers/app/BitmapManager.cpp b/src/servers/app/BitmapManager.cpp index dce3533704..ee843d8614 100644 --- a/src/servers/app/BitmapManager.cpp +++ b/src/servers/app/BitmapManager.cpp @@ -1,40 +1,28 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: BitmapManager.cpp -// Author: DarkWyrm -// Description: Handler for allocating and freeing area memory for BBitmaps -// on the server side. Utilizes the BGET pool allocator. -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + +/** Handler for allocating and freeing area memory for BBitmaps + * on the server side. Utilizes the BGET pool allocator. + */ + #include #include #include -#include "ServerBitmap.h" +#include +#include "ServerBitmap.h" #include "BitmapManager.h" + //! The bitmap allocator for the server. Memory is allocated/freed by the AppServer class -BitmapManager *bitmapmanager = NULL; +BitmapManager *gBitmapManager = NULL; //! Number of bytes to allocate to each area used for bitmap storage #define BITMAP_AREA_SIZE B_PAGE_SIZE * 2 @@ -45,9 +33,8 @@ BitmapManager::BitmapManager() fBitmapArea(B_ERROR), fBuffer(NULL), fTokenizer(), - fLock(B_ERROR), + fLock("BitmapManager Lock"), fMemPool() - { // When create_area is passed the B_ANY_ADDRESS flag, the address of the area // is stored in the pointer to a pointer. @@ -57,11 +44,7 @@ BitmapManager::BitmapManager() if (fBitmapArea < B_OK) printf("PANIC: BitmapManager couldn't allocate area: %s\n", strerror(fBitmapArea)); - - fLock = create_sem(1,"bmpmanager_fLock"); - if (fLock < B_OK) - printf("PANIC: BitmapManager couldn't allocate fLocking semaphore!!\n"); - + fMemPool.AddToPool(fBuffer, BITMAP_AREA_SIZE); } @@ -75,8 +58,8 @@ BitmapManager::~BitmapManager() delete bitmap; } } + delete_area(fBitmapArea); - delete_sem(fLock); } /*! @@ -92,34 +75,37 @@ ServerBitmap* BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags, int32 bytesPerRow, screen_id screen) { - ServerBitmap* bitmap = NULL; - if (acquire_sem(fLock) >= B_OK) { - bitmap = new(nothrow) ServerBitmap(bounds, space, flags, bytesPerRow); + BAutolock locker(fLock); - // Server version of this code will also need to handle such things as - // bitmaps which accept child views by checking the flags. - uint8* buffer = (uint8*)fMemPool.GetBuffer(bitmap->BitsLength()); + if (!locker.IsLocked()) + return NULL; - if (buffer && fBitmapList.AddItem(bitmap)) { - bitmap->fArea = area_for(buffer); - bitmap->fBuffer = buffer; - bitmap->fToken = fTokenizer.GetToken(); - bitmap->fInitialized = true; - - // calculate area offset - area_info ai; - get_area_info(bitmap->fArea, &ai); - bitmap->fOffset = buffer - (uint8*)ai.address; + ServerBitmap* bitmap = new(nothrow) ServerBitmap(bounds, space, flags, bytesPerRow); + if (bitmap == NULL) + return NULL; - } else { - // Allocation failed for buffer or bitmap list - fMemPool.ReleaseBuffer(buffer); - delete bitmap; - bitmap = NULL; - } + // Server version of this code will also need to handle such things as + // bitmaps which accept child views by checking the flags. + uint8* buffer = (uint8*)fMemPool.GetBuffer(bitmap->BitsLength()); - release_sem(fLock); + if (buffer && fBitmapList.AddItem(bitmap)) { + bitmap->fArea = area_for(buffer); + bitmap->fBuffer = buffer; + bitmap->fToken = fTokenizer.GetToken(); + bitmap->fInitialized = true; + + // calculate area offset + area_info ai; + get_area_info(bitmap->fArea, &ai); + bitmap->fOffset = buffer - (uint8*)ai.address; + + } else { + // Allocation failed for buffer or bitmap list + fMemPool.ReleaseBuffer(buffer); + delete bitmap; + bitmap = NULL; } + return bitmap; } @@ -130,12 +116,14 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags, void BitmapManager::DeleteBitmap(ServerBitmap *bitmap) { - if (acquire_sem(fLock) >= B_OK) { - if (fBitmapList.RemoveItem(bitmap)) { - // Server code will require a check to ensure bitmap doesn't have its own area - fMemPool.ReleaseBuffer(bitmap->fBuffer); - delete bitmap; - } - release_sem(fLock); + BAutolock locker(fLock); + + if (!locker.IsLocked()) + return; + + if (fBitmapList.RemoveItem(bitmap)) { + // Server code will require a check to ensure bitmap doesn't have its own area + fMemPool.ReleaseBuffer(bitmap->fBuffer); + delete bitmap; } } diff --git a/src/servers/app/DecorManager.cpp b/src/servers/app/DecorManager.cpp index 90fdf14b54..e9885af0a3 100644 --- a/src/servers/app/DecorManager.cpp +++ b/src/servers/app/DecorManager.cpp @@ -5,51 +5,54 @@ * Author: DarkWyrm */ + #include #include #include #include #include +#include "AppServer.h" #include "ColorSet.h" #include "DefaultDecorator.h" #include "ServerConfig.h" #include "DecorManager.h" + // Globals DecorManager gDecorManager; -extern ColorSet gui_colorset; Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags); // This is a class used only by the DecorManager to track all the decorators in memory -class DecorInfo -{ +class DecorInfo { public: DecorInfo(const image_id &id, const char *name, create_decorator *alloc); ~DecorInfo(void); image_id GetID(void) const { return fID; } - const char * GetName(void) const { return fName.String(); } - Decorator * Instantiate(BRect rect, const char *title, + const char* GetName(void) const { return fName.String(); } + Decorator* Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, DisplayDriver *ddriver); private: - image_id fID; BString fName; create_decorator *fAllocator; }; + DecorInfo::DecorInfo(const image_id &id, const char *name, create_decorator *alloc) - : fID(id), + : + fID(id), fName(name), fAllocator(alloc) { } + DecorInfo::~DecorInfo(void) { // Do nothing. Normal programming practice would say that one should unload @@ -63,25 +66,31 @@ DecorInfo::~DecorInfo(void) // when the app_server quits. It's not pretty, but it gets the job done. } + Decorator * DecorInfo::Instantiate(BRect rect, const char *title, int32 wlook, int32 wfeel, - int32 wflags, DisplayDriver *ddriver) + int32 wflags, DisplayDriver *ddriver) { Decorator *dec = fAllocator(rect, wlook, wfeel, wflags); dec->SetDriver(ddriver); - gui_colorset.Lock(); - dec->SetColors(gui_colorset); - gui_colorset.Unlock(); + gGUIColorSet.Lock(); + dec->SetColors(gGUIColorSet); + gGUIColorSet.Unlock(); dec->SetTitle(title); return dec; } -DecorManager::DecorManager(void) - : fDecorList(0), + +// #pragma mark - + + +DecorManager::DecorManager() + : + fDecorList(0), fCurrentDecor(NULL) { // Start with the default decorator - index is always 0 @@ -90,196 +99,200 @@ DecorManager::DecorManager(void) // Add any on disk RescanDecorators(); - + // 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); - + BMessage settings; BFile file(SERVER_SETTINGS_DIR "decorator_settings", B_READ_ONLY); - + // Fallback to the default decorator if something goes wrong - if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) - { + if (file.InitCheck() == B_OK && settings.Unflatten(&file) == B_OK) { BString itemtext; - if( settings.FindString("decorator", &itemtext) == B_OK ) - { + if (settings.FindString("decorator", &itemtext) == B_OK) { fCurrentDecor = FindDecor(itemtext.String()); } } - - if(!fCurrentDecor) + + if (!fCurrentDecor) fCurrentDecor = (DecorInfo*) fDecorList.ItemAt(0L); } -DecorManager::~DecorManager(void) + +DecorManager::~DecorManager() { EmptyList(); } + void -DecorManager::RescanDecorators(void) +DecorManager::RescanDecorators() { BDirectory dir(DECORATORS_DIR); - - if(dir.InitCheck() != B_OK) + + if (dir.InitCheck() != B_OK) return; - + entry_ref ref; BString fullpath; - - while(dir.GetNextRef(&ref)==B_OK) - { + + while (dir.GetNextRef(&ref) == B_OK) { fullpath = DECORATORS_DIR; fullpath += ref.name; - + // 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. - - if( FindDecor(ref.name) ) + + if (FindDecor(ref.name)) continue; - + image_id tempID = load_add_on(fullpath.String()); - if(tempID == B_ERROR) + if (tempID == B_ERROR) continue; - + // 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. - + create_decorator *createfunc; - + // Get the instantiation function status_t status = get_image_symbol(tempID, "instantiate_decorator", B_SYMBOL_TYPE_TEXT, (void**)&createfunc); - - if (status != B_OK) - { + if (status != B_OK) { unload_add_on(tempID); continue; } - - fDecorList.AddItem( new DecorInfo(tempID, ref.name, createfunc) ); + + fDecorList.AddItem(new DecorInfo(tempID, ref.name, createfunc)); } } + Decorator * DecorManager::AllocateDecorator(BRect rect, const char *title, int32 wlook, int32 wfeel, int32 wflags, DisplayDriver *ddriver) { // Create a new instance of the current decorator. Ownership is that of the caller - - if(!fCurrentDecor) - { + + 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->Instantiate(rect,title,wlook,wfeel,wflags,ddriver); + + return fCurrentDecor->Instantiate(rect, title, wlook, wfeel, wflags, ddriver); } + int32 DecorManager::CountDecorators(void) const { return fDecorList.CountItems(); } + int32 DecorManager::GetDecorator(void) const { - return fDecorList.IndexOf( fCurrentDecor ); + return fDecorList.IndexOf(fCurrentDecor); } + bool DecorManager::SetDecorator(const int32 &index) { - DecorInfo *newDecInfo = (DecorInfo*) fDecorList.ItemAt(index); - - if(newDecInfo) - { + DecorInfo *newDecInfo = (DecorInfo*)fDecorList.ItemAt(index); + + if (newDecInfo) { fCurrentDecor = newDecInfo; return true; } - + return false; } + bool DecorManager::SetR5Decorator(const int32 &value) { BString string; - - switch(value) - { - case 0: string="BeOS"; break; - case 1: string="AmigaOS"; break; - case 2: string="Windows"; break; - case 3: string="MacOS"; break; + + switch (value) { + case 0: string = "BeOS"; break; + case 1: string = "AmigaOS"; break; + case 2: string = "Windows"; break; + case 3: string = "MacOS"; break; default: return false; } - + DecorInfo *newDecInfo = FindDecor(string.String()); - if(newDecInfo) - { + if (newDecInfo) { fCurrentDecor = newDecInfo; return true; } - + return false; } + const char * DecorManager::GetDecoratorName(const int32 &index) { - DecorInfo *info = (DecorInfo*) fDecorList.ItemAt(index); - - if(info) + DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(index); + + if (info) return info->GetName(); - + return NULL; } + void DecorManager::EmptyList(void) { - for(int32 i=0; i < fDecorList.CountItems(); i++) - { - DecorInfo *info=(DecorInfo*)fDecorList.ItemAt(i); + for (int32 i = 0; i < fDecorList.CountItems(); i++) { + DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i); delete info; } - + fCurrentDecor = NULL; } + DecorInfo* DecorManager::FindDecor(const char *name) { - if(!name) + if (!name) return NULL; - - for(int32 i=0; iGetName())==0 ) + + for (int32 i = 0; i < fDecorList.CountItems(); i++) { + DecorInfo *info = (DecorInfo*)fDecorList.ItemAt(i); + + if (info && strcmp(name, info->GetName()) == 0) return info; } - + return NULL; } + +// #pragma mark - + + // This is the allocator function for the default decorator -Decorator* create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) +Decorator* +create_default_decorator(BRect rect, int32 wlook, int32 wfeel, int32 wflags) { - return new DefaultDecorator(rect,wlook,wfeel,wflags); + return new DefaultDecorator(rect, wlook, wfeel, wflags); } diff --git a/src/servers/app/DefaultDecorator.cpp b/src/servers/app/DefaultDecorator.cpp index 7846ffcfbc..89cf545563 100644 --- a/src/servers/app/DefaultDecorator.cpp +++ b/src/servers/app/DefaultDecorator.cpp @@ -1,29 +1,13 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: DefaultDecorator.cpp -// Author: DarkWyrm -// Description: Default and fallback decorator for the app_server -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + +/** Default and fallback decorator for the app_server - the yellow tabs */ + #include @@ -53,7 +37,8 @@ DefaultDecorator::DefaultDecorator(BRect rect, int32 wlook, int32 wfeel, int32 w : Decorator(rect, wlook, wfeel, wflags), fTruncatedTitle("") { - ServerFont font(_look == B_FLOATING_WINDOW_LOOK ? *fontserver->GetSystemPlain() : *fontserver->GetSystemBold()); + ServerFont font(_look == B_FLOATING_WINDOW_LOOK ? + *gFontServer->GetSystemPlain() : *gFontServer->GetSystemBold()); font.SetFlags(B_FORCE_ANTIALIASING); font.SetSpacing(B_STRING_SPACING); SetFont(&font); diff --git a/src/servers/app/FontServer.cpp b/src/servers/app/FontServer.cpp index 05959ece9a..209f999075 100644 --- a/src/servers/app/FontServer.cpp +++ b/src/servers/app/FontServer.cpp @@ -1,29 +1,14 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: FontServer.cpp -// Author: DarkWyrm -// Description: Handles the largest part of the font subsystem -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + +/** Handles the largest part of the font subsystem */ + + #include #include #include @@ -37,27 +22,37 @@ #include #include "ServerConfig.h" + extern FTC_Manager ftmanager; FT_Library ftlib; -FontServer *fontserver=NULL; +FontServer *gFontServer = NULL; //#define PRINT_FONT_LIST /*! \brief Access function to request a face via the FreeType font cache */ -static FT_Error face_requester(FTC_FaceID face_id, FT_Library library, +static FT_Error +face_requester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface) { CachedFace face = (CachedFace) face_id; - return FT_New_Face(ftlib,face->file_path.String(),face->face_index,aface); + return FT_New_Face(ftlib, face->file_path.String(), face->face_index,aface); } + +// #pragma mark - + + //! Does basic set up so that directories can be scanned FontServer::FontServer(void) + : BLocker("font server lock"), + fFamilies(20), + fPlain(NULL), + fBold(NULL), + fFixed(NULL) { - lock=create_sem(1,"fontserver_lock"); - init=(FT_Init_FreeType(&ftlib)==0)?true:false; + fInit = FT_Init_FreeType(&ftlib) == 0; /* Fire up the font caching subsystem. @@ -66,37 +61,18 @@ FontServer::FontServer(void) these numbers in the future to maximize performance for your "average" application. */ - if(FTC_Manager_New(ftlib,0,0,0,&face_requester,NULL,&ftmanager)!=0 - && init) - init=false; - - families=new BList(20); - plain=NULL; - bold=NULL; - fixed=NULL; + if (FTC_Manager_New(ftlib, 0, 0, 0, &face_requester, NULL, &ftmanager) != 0) + fInit = false; } + //! Frees items allocated in the constructor and shuts down FreeType FontServer::~FontServer(void) { - delete_sem(lock); - delete families; FTC_Manager_Done(ftmanager); FT_Done_FreeType(ftlib); } -//! Locks access to the font server -bool -FontServer::Lock(void) -{ - return acquire_sem(lock) >= B_OK; -} - -//! Unlocks access to the font server -void FontServer::Unlock(void) -{ - release_sem(lock); -} /*! \brief Counts the number of font families available @@ -104,78 +80,83 @@ void FontServer::Unlock(void) */ int32 FontServer::CountFamilies(void) { - if(init) - return families->CountItems(); + if (fInit) + return fFamilies.CountItems(); + return 0; } + /*! \brief Counts the number of styles available in a font family \param family Name of the font family to scan \return The number of font styles currently available for the font family */ -int32 FontServer::CountStyles(const char *family) +int32 +FontServer::CountStyles(const char *familyName) { - FontFamily *f=GetFamily(family); - if(f) - { - return f->CountStyles(); - } + FontFamily *family = GetFamily(familyName); + if (family) + return family->CountStyles(); + return 0; } + /*! \brief Removes a font family from the font list \param family The family to remove */ -void FontServer::RemoveFamily(const char *family) +void +FontServer::RemoveFamily(const char *familyName) { - FontFamily *f=GetFamily(family); - if(f) - { - families->RemoveItem(f); - delete f; + FontFamily *family = GetFamily(familyName); + if (family) { + fFamilies.RemoveItem(family); + delete family; } } -const char *FontServer::GetFamilyName(uint16 id) const + +const char* +FontServer::GetFamilyName(uint16 id) const { - FontFamily *fam; - for(int32 i=0; iCountItems(); i++) - { - fam=(FontFamily*)families->ItemAt(i); - if(fam && fam->GetID()==id) - return fam->Name(); + for (int32 i = 0; i < fFamilies.CountItems(); i++) { + FontFamily* family = (FontFamily*)fFamilies.ItemAt(i); + if (family && family->GetID() == id) + return family->Name(); } + return NULL; } -const char *FontServer::GetStyleName(const char *family, uint16 id) const + +const char* +FontServer::GetStyleName(const char* familyName, uint16 id) const { - FontFamily *fam=GetFamily(family); - FontStyle *sty; - for(int32 i=0; iCountItems(); i++) - { - sty=fam->GetStyle(i); - if(sty && sty->GetID()==id) - return sty->Name(); - } + FontStyle* style = GetStyle(familyName, id); + if (style != NULL) + return style->Name(); + return NULL; } -FontStyle *FontServer::GetStyle(const char *family, uint16 id) const + +FontStyle* +FontServer::GetStyle(const char* familyName, uint16 id) const { - FontFamily *fam=GetFamily(family); - FontStyle *sty; - for(int32 i=0; iCountItems(); i++) - { - sty=fam->GetStyle(i); - if(sty && sty->GetID()==id) - return sty; + FontFamily* family = GetFamily(familyName); + + for (int32 i = 0; i < family->CountStyles(); i++) { + FontStyle* style = family->GetStyle(i); + if (style && style->GetID() == id) + return style; } + return NULL; } + /*! \brief Protected function which locates a FontFamily object \param name The family to find @@ -183,21 +164,24 @@ FontStyle *FontServer::GetStyle(const char *family, uint16 id) const Do NOT delete the FontFamily returned by this function. */ -FontFamily *FontServer::GetFamily(const char *name) const +FontFamily* +FontServer::GetFamily(const char* name) const { - if(!init) + if (!fInit) return NULL; - int32 count=families->CountItems(), i; - FontFamily *family; - for(i=0; iItemAt(i); - if(strcmp(family->Name(),name)==0) + + int32 count = fFamilies.CountItems(); + + for (int32 i = 0; i < count; i++) { + FontFamily *family = (FontFamily*)fFamilies.ItemAt(i); + if (!strcmp(family->Name(), name)) return family; } + return NULL; } + /*! \brief Scan a folder for all valid fonts \param fontspath Path of the folder to scan. @@ -212,42 +196,28 @@ FontFamily *FontServer::GetFamily(const char *name) const - \c B_FILE_ERROR An invalid file prevented the operation. - \c B_NO_MORE_FDS All file descriptors are in use (too many open files). */ -status_t FontServer::ScanDirectory(const char *fontspath) +status_t +FontServer::ScanDirectory(const char *directoryPath) { // This bad boy does all the real work. It loads each entry in the // directory. If a valid font file, it adds both the family and the style. // Both family and style are stored internally as BStrings. Once everything BDirectory dir; + status_t status = dir.SetTo(directoryPath); + if (status != B_OK) + return status; + BEntry entry; - BPath path; - entry_ref ref; - status_t stat; - int32 refcount,i, validcount=0; - FT_Face face; - FT_Error error; - FT_CharMap charmap; - FontFamily *family; - FontStyle *style; - - stat=dir.SetTo(fontspath); - if(stat!=B_OK) - return stat; - - refcount=dir.CountEntries(); - - for(i=0;i glyph-index mapping everywhere to handle other // char maps. We could also ignore fonts that don't support // the Unicode lookup as a temporary "solution". -/* charmap=_GetSupportedCharmap(face); - if(!charmap) - { +#if 0 + FT_CharMap charmap = _GetSupportedCharmap(face); + if (!charmap) { FT_Done_Face(face); continue; } - - face->charmap=charmap;*/ - family=GetFamily(face->family_name); - - if(!family) - { + face->charmap = charmap; +#endif + + FontFamily *family = GetFamily(face->family_name); + if (family == NULL) { #ifdef PRINT_FONT_LIST - printf("Font Family: %s\n",face->family_name); + printf("Font Family: %s\n", face->family_name); #endif - family=new FontFamily(face->family_name,families->CountItems()); - families->AddItem(family); + family = new FontFamily(face->family_name, fFamilies.CountItems()); + fFamilies.AddItem(family); } - - if(family->HasStyle(face->style_name)) - { + + if (family->HasStyle(face->style_name)) { FT_Done_Face(face); continue; } #ifdef PRINT_FONT_LIST - printf("\tFont Style: %s\n",face->style_name); + printf("\tFont Style: %s\n", face->style_name); #endif - style=new FontStyle(path.Path(),face); - if(!family->AddStyle(style)) + FontStyle *style = new FontStyle(path.Path(), face); + if (!family->AddStyle(style)) delete style; - else - validcount++; // FT_Face is kept open in FontStyle and will be unset in the // FontStyle destructor - - } // end for(inum_charmaps; i++) - { - charmap=face->charmaps[i]; - switch(charmap->platform_id) - { + for (int32 i = 0; i < face->num_charmaps; i++) { + FT_CharMap charmap = face->charmaps[i]; + + switch (charmap->platform_id) { case 3: - { // if Windows Symbol or Windows Unicode - if(charmap->encoding_id==0 || charmap->encoding_id==1) + if (charmap->encoding_id == 0 || charmap->encoding_id == 1) return charmap; break; - } + case 1: - { // if Apple Unicode - if(charmap->encoding_id==0) + if (charmap->encoding_id == 0) return charmap; break; - } + case 0: - { // if Apple Roman - if(charmap->encoding_id==0) + if (charmap->encoding_id == 0) return charmap; break; - } + default: - { break; - } } } - return NULL; + return NULL; } + /*! \brief This saves all family names and styles to the file specified in ServerConfig.h as SERVER_FONT_LIST as a flattened BMessage. @@ -364,7 +322,8 @@ FT_CharMap FontServer::_GetSupportedCharmap(const FT_Face &face) Additionally, any fonts which have bitmap strikes contained in them or any fonts which are fixed-width are named in the arrays 'tuned' and 'fixed'. */ -void FontServer::SaveList(void) +void +FontServer::SaveList(void) { /* int32 famcount=0, stycount=0,i=0,j=0; FontFamily *fam; @@ -424,85 +383,95 @@ void FontServer::SaveList(void) */ } + /*! \brief Retrieves the FontStyle object \param family The font's family \param style The font's style \return The FontStyle having those attributes or NULL if not available */ -FontStyle *FontServer::GetStyle(const char *family, const char *style) +FontStyle* +FontServer::GetStyle(const char* familyName, const char* styleName) { - FontFamily *ffam=GetFamily(family); + FontFamily* family = GetFamily(familyName); + + if (family) + return family->GetStyle(styleName); - if(ffam) - { - FontStyle *fsty=ffam->GetStyle(style); - return fsty; - } return NULL; } + /*! \brief Retrieves the FontStyle object \param family ID for the font's family \param style ID of the font's style \return The FontStyle having those attributes or NULL if not available */ -FontStyle *FontServer::GetStyle(const uint16 &familyid, const uint16 &styleid) +FontStyle* +FontServer::GetStyle(const uint16& familyID, const uint16& styleID) { - FontFamily *fam=GetFamily(familyid); - if(fam) - { - FontStyle *sty=fam->GetStyle(styleid); - return sty; - } + FontFamily *family = GetFamily(familyID); + + if (family) + return family->GetStyle(styleID); + return NULL; } -FontFamily *FontServer::GetFamily(const uint16 &familyid) const + +FontFamily* +FontServer::GetFamily(const uint16& familyID) const { - for(int32 i=0; iCountItems(); i++) - { - FontFamily *fam=(FontFamily*)families->ItemAt(i); - if(fam->GetID()==familyid) - return fam; + for (int32 i = 0; i < fFamilies.CountItems(); i++) { + FontFamily *family = (FontFamily*)fFamilies.ItemAt(i); + if (family->GetID() == familyID) + return family; } + return NULL; } + /*! \brief Returns the current object used for the regular style \return A ServerFont pointer which is the plain font. Do NOT delete this object. If you access it, make a copy of it. */ -ServerFont *FontServer::GetSystemPlain(void) +ServerFont* +FontServer::GetSystemPlain() { - return plain; + return fPlain; } + /*! \brief Returns the current object used for the bold style \return A ServerFont pointer which is the bold font. Do NOT delete this object. If you access it, make a copy of it. */ -ServerFont *FontServer::GetSystemBold(void) +ServerFont* +FontServer::GetSystemBold() { - return bold; + return fBold; } + /*! \brief Returns the current object used for the fixed style \return A ServerFont pointer which is the fixed font. Do NOT delete this object. If you access it, make a copy of it. */ -ServerFont *FontServer::GetSystemFixed(void) +ServerFont* +FontServer::GetSystemFixed() { - return fixed; + return fFixed; } + /*! \brief Sets the system's plain font to the specified family and style \param family Name of the font's family @@ -511,22 +480,20 @@ ServerFont *FontServer::GetSystemFixed(void) \return true if successful, false if not. */ -bool FontServer::SetSystemPlain(const char *family, const char *style, float size) +bool +FontServer::SetSystemPlain(const char* familyName, const char* styleName, float size) { - FontFamily *fam=GetFamily(family); - if(!fam) + FontStyle *style = GetStyle(familyName, styleName); + if (style == NULL) return false; - FontStyle *sty=fam->GetStyle(style); - if(!sty) - return false; - - if(plain) - delete plain; - - plain=new ServerFont(sty,size); + + delete fPlain; + fPlain = new ServerFont(style, size); + return true; } + /*! \brief Sets the system's bold font to the specified family and style \param family Name of the font's family @@ -535,22 +502,20 @@ bool FontServer::SetSystemPlain(const char *family, const char *style, float siz \return true if successful, false if not. */ -bool FontServer::SetSystemBold(const char *family, const char *style, float size) +bool +FontServer::SetSystemBold(const char* familyName, const char* styleName, float size) { - FontFamily *fam=GetFamily(family); - if(!fam) + FontStyle *style = GetStyle(familyName, styleName); + if (style == NULL) return false; - FontStyle *sty=fam->GetStyle(style); - if(!sty) - return false; - - if(bold) - delete bold; - - bold=new ServerFont(sty,size); + + delete fBold; + fBold = new ServerFont(style, size); + return true; } + /*! \brief Sets the system's fixed font to the specified family and style \param family Name of the font's family @@ -559,19 +524,16 @@ bool FontServer::SetSystemBold(const char *family, const char *style, float size \return true if successful, false if not. */ -bool FontServer::SetSystemFixed(const char *family, const char *style, float size) +bool +FontServer::SetSystemFixed(const char* familyName, const char* styleName, float size) { - FontFamily *fam=GetFamily(family); - if(!fam) + FontStyle *style = GetStyle(familyName, styleName); + if (style == NULL) return false; - FontStyle *sty=fam->GetStyle(style); - if(!sty) - return false; - - if(fixed) - delete fixed; - fixed=new ServerFont(sty,size); + delete fFixed; + fFixed = new ServerFont(style, size); + return true; } diff --git a/src/servers/app/LayerData.cpp b/src/servers/app/LayerData.cpp index 6738064aa9..0fafc8c845 100644 --- a/src/servers/app/LayerData.cpp +++ b/src/servers/app/LayerData.cpp @@ -1,31 +1,16 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2005, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: LayerData.cpp -// Author: DarkWyrm -// Adi Oanca -// Stephan Aßmus -// Description: Data classes for working with BView states and draw parameters -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + * Adi Oanca + * Stephan Aßmus + */ + +/** Data classes for working with BView states and draw parameters */ + + #include #include @@ -55,8 +40,8 @@ DrawData::DrawData() fLineJoinMode(B_BEVEL_JOIN), fMiterLimit(B_DEFAULT_MITER_LIMIT) { - if (fontserver && fontserver->GetSystemPlain()) - fFont = *(fontserver->GetSystemPlain()); + if (gFontServer && gFontServer->GetSystemPlain()) + fFont = *(gFontServer->GetSystemPlain()); fEscapementDelta.space = 0; fEscapementDelta.nonspace = 0; @@ -87,10 +72,10 @@ DrawData::operator=(const DrawData& from) // fOrigin and fScale and uses the current the font size as // fUnscaledFontSize. -// fOrigin = from.fOrigin; -// fScale = from.fScale; - fOrigin = BPoint(0.0, 0.0); - fScale = 1.0; +// fOrigin = from.fOrigin; +// fScale = from.fScale; + fOrigin = BPoint(0.0, 0.0); + fScale = 1.0; if (from.fClippingRegion) { SetClippingRegion(*(from.fClippingRegion)); diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index c85b5b9375..c2e65f69b2 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -10,6 +10,7 @@ * Axel Dörfler, axeld@pinc-software.de */ + #include #include @@ -765,7 +766,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&flags); link.Read(&bytesPerRow); if (link.Read(&screenID) == B_OK) { - bitmap = bitmapmanager->CreateBitmap(frame, colorSpace, flags, + bitmap = gBitmapManager->CreateBitmap(frame, colorSpace, flags, bytesPerRow, screenID); } @@ -805,7 +806,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) STRACE(("ServerApp %s: Deleting Bitmap %ld\n", fSignature.String(), id)); fBitmapList.RemoveItem(bitmap); - bitmapmanager->DeleteBitmap(bitmap); + gBitmapManager->DeleteBitmap(bitmap); fLink.StartMessage(SERVER_TRUE); } else fLink.StartMessage(SERVER_FALSE); @@ -1076,13 +1077,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // using a ColorSet object - gui_colorset.Lock(); + gGUIColorSet.Lock(); fLink.StartMessage(SERVER_TRUE); - fLink.Attach(gui_colorset); + fLink.Attach(gGUIColorSet); fLink.Flush(); - gui_colorset.Unlock(); + gGUIColorSet.Unlock(); break; } @@ -1090,14 +1091,14 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) { // Client application is asking to set all the system colors at once // using a ColorSet object - + // Attached data: // 1) ColorSet new colors to use - - gui_colorset.Lock(); - link.Read(&gui_colorset); - gui_colorset.Unlock(); - + + gGUIColorSet.Lock(); + link.Read(&gGUIColorSet); + gGUIColorSet.Unlock(); + BroadcastToAllApps(AS_UPDATE_COLORS); break; } @@ -1106,19 +1107,19 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) STRACE(("ServerApp %s: Get UI color\n", fSignature.String())); RGBColor color; - int32 whichcolor; - link.Read(&whichcolor); + int32 whichColor; + link.Read(&whichColor); - gui_colorset.Lock(); - color = gui_colorset.AttributeToColor(whichcolor); - gui_colorset.Unlock(); + gGUIColorSet.Lock(); + color = gGUIColorSet.AttributeToColor(whichColor); + gGUIColorSet.Unlock(); fLink.StartMessage(SERVER_TRUE); fLink.Attach(color.GetColor32()); fLink.Flush(); break; } - + case AS_UPDATED_CLIENT_FONTLIST: { STRACE(("ServerApp %s: Acknowledged update of client-side font list\n", @@ -1126,9 +1127,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // received when the client-side global font list has been // refreshed - fontserver->Lock(); - fontserver->FontsUpdated(); - fontserver->Unlock(); + gFontServer->Lock(); + gFontServer->FontsUpdated(); + gFontServer->Unlock(); break; } case AS_QUERY_FONTS_CHANGED: @@ -1157,8 +1158,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) int32 id; link.Read(&id); - fontserver->Lock(); - FontFamily *ffamily = fontserver->GetFamily(id); + gFontServer->Lock(); + FontFamily *ffamily = gFontServer->GetFamily(id); if (ffamily) { font_family fam; strcpy(fam, ffamily->Name()); @@ -1168,7 +1169,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_STYLE_NAME: @@ -1189,8 +1190,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(fam,sizeof(font_family)); link.Read(&styid); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(fam, styid); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(fam, styid); if (fstyle) { font_family sty; strcpy(sty, fstyle->Name()); @@ -1202,7 +1203,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_FAMILY_AND_STYLE: @@ -1222,8 +1223,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&famid); link.Read(&styid); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(famid, styid); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(famid, styid); if (fstyle) { strcpy(fam, fstyle->Family()->Name()); strcpy(sty, fstyle->Name()); @@ -1235,7 +1236,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_FONT_DIRECTION: @@ -1257,8 +1258,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&famid); link.Read(&styid); -/* fontserver->Lock(); - FontStyle *fstyle=fontserver->GetStyle(famid,styid); +/* gFontServer->Lock(); + FontStyle *fstyle=gFontServer->GetStyle(famid,styid); if(fstyle) { font_direction dir=fstyle->GetDirection(); @@ -1273,7 +1274,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.Flush(); // } -// fontserver->Unlock(); +// gFontServer->Unlock(); break; } case AS_GET_STRING_WIDTH: @@ -1354,8 +1355,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&famid); link.Read(&styid); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(famid, styid); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(famid, styid); if (fstyle) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(fstyle->TunedCount()); @@ -1363,7 +1364,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_TUNED_INFO: @@ -1396,8 +1397,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&famid); link.Read(&styid); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(famid, styid); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(famid, styid); if (fstyle) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(fstyle->IsFixedWidth()); @@ -1405,7 +1406,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_FAMILY_NAME: @@ -1420,8 +1421,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) font_family fam; link.Read(fam, sizeof(font_family)); - fontserver->Lock(); - FontFamily *ffam = fontserver->GetFamily(fam); + gFontServer->Lock(); + FontFamily *ffam = gFontServer->GetFamily(fam); if (ffam) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(ffam->GetID()); @@ -1429,7 +1430,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_FAMILY_AND_STYLE: @@ -1449,8 +1450,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(fam, sizeof(font_family)); link.Read(sty, sizeof(font_style)); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(fam, sty); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(fam, sty); if (fstyle) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(fstyle->Family()->GetID()); @@ -1459,7 +1460,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_FAMILY_AND_STYLE_FROM_ID: @@ -1511,13 +1512,13 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // Returns: // 1) int32 - # of font families - fontserver->Lock(); + gFontServer->Lock(); fLink.StartMessage(SERVER_TRUE); - fLink.Attach(fontserver->CountFamilies()); + fLink.Attach(gFontServer->CountFamilies()); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_COUNT_FONT_STYLES: @@ -1531,8 +1532,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) font_family fam; link.Read(fam,sizeof(font_family)); - fontserver->Lock(); - FontFamily *ffam = fontserver->GetFamily(fam); + gFontServer->Lock(); + FontFamily *ffam = gFontServer->GetFamily(fam); if (ffam) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(ffam->CountStyles()); @@ -1540,7 +1541,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_SYSFONT_PLAIN: @@ -1553,8 +1554,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // 4) uint16 - face flags // 5) uint32 - font flags - fontserver->Lock(); - ServerFont *sf = fontserver->GetSystemPlain(); + gFontServer->Lock(); + ServerFont *sf = gFontServer->GetSystemPlain(); if (sf) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(sf->FamilyID()); @@ -1566,7 +1567,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_FONT_HEIGHT: @@ -1582,8 +1583,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) link.Read(&styid); link.Read(&ptsize); - fontserver->Lock(); - FontStyle *fstyle = fontserver->GetStyle(famid, styid); + gFontServer->Lock(); + FontStyle *fstyle = gFontServer->GetStyle(famid, styid); if (fstyle) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(fstyle->GetHeight(ptsize)); @@ -1591,7 +1592,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_SYSFONT_BOLD: @@ -1604,8 +1605,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // 4) uint16 - face flags // 5) uint32 - font flags - fontserver->Lock(); - ServerFont *sf = fontserver->GetSystemBold(); + gFontServer->Lock(); + ServerFont *sf = gFontServer->GetSystemBold(); if (sf) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(sf->FamilyID()); @@ -1617,7 +1618,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_SET_SYSFONT_FIXED: @@ -1630,8 +1631,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) // 4) uint16 - face flags // 5) uint32 - font flags - fontserver->Lock(); - ServerFont *sf = fontserver->GetSystemFixed(); + gFontServer->Lock(); + ServerFont *sf = gFontServer->GetSystemFixed(); if (sf) { fLink.StartMessage(SERVER_TRUE); fLink.Attach(sf->FamilyID()); @@ -1643,7 +1644,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver &link) fLink.StartMessage(SERVER_FALSE); fLink.Flush(); - fontserver->Unlock(); + gFontServer->Unlock(); break; } case AS_GET_GLYPH_SHAPES: diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp index 268904fe54..d1987aef80 100644 --- a/src/servers/app/ServerFont.cpp +++ b/src/servers/app/ServerFont.cpp @@ -1,29 +1,12 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku, Inc. -// -// 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 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 MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS 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. -// -// File Name: ServerFont.cpp -// Author: DarkWyrm -// Description: Shadow BFont class -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + + #include #include #include @@ -40,6 +23,71 @@ #include "ServerFont.h" +// functions needed to convert a freetype vector graphics to a BShape +inline BPoint +VectorToPoint(FT_Vector *vector) +{ + BPoint result; + result.x = float(int32(vector->x)) / 2097152; + result.y = -float(int32(vector->y)) / 2097152; + return result; +} + +int +MoveToFunc(FT_Vector *to, void *user) +{ + ((BShape *)user)->MoveTo(VectorToPoint(to)); + return 0; +} + +int +LineToFunc(FT_Vector *to, void *user) +{ + ((BShape *)user)->LineTo(VectorToPoint(to)); + return 0; +} + +int +ConicToFunc(FT_Vector *control, FT_Vector *to, void *user) +{ + BPoint controls[3]; + + controls[0] = VectorToPoint(control); + controls[1] = VectorToPoint(to); + controls[2] = controls[1]; + + ((BShape *)user)->BezierTo(controls); + return 0; +} + +int +CubicToFunc(FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *user) +{ + BPoint controls[3]; + + controls[0] = VectorToPoint(control1); + controls[1] = VectorToPoint(control2); + controls[2] = VectorToPoint(to); + + ((BShape *)user)->BezierTo(controls); + return 0; +} + + +// is_white_space +inline bool +is_white_space(uint16 glyph) +{ + // TODO: handle them all! + if (glyph == ' ' || glyph == B_TAB) + return true; + return false; +} + + +// #pragma mark - + + /*! \brief Constructor \param style Style object to which the ServerFont belongs @@ -191,9 +239,9 @@ ServerFont::SetFamilyAndStyle(uint16 familyID, uint16 styleID) { FontStyle* style = NULL; - if (fontserver->Lock()) { - style = fontserver->GetStyle(familyID, styleID); - fontserver->Unlock(); + if (gFontServer->Lock()) { + style = gFontServer->GetStyle(familyID, styleID); + gFontServer->Unlock(); } if (!style) @@ -228,55 +276,6 @@ ServerFont::GetFamilyAndStyle(void) const return (FamilyID() << 16) | StyleID(); } -// functions needed to convert a freetype vector graphics to a BShape -inline BPoint -VectorToPoint(FT_Vector *vector) -{ - BPoint result; - result.x = float(int32(vector->x)) / 2097152; - result.y = -float(int32(vector->y)) / 2097152; - return result; -} - -int -MoveToFunc(FT_Vector *to, void *user) -{ - ((BShape *)user)->MoveTo(VectorToPoint(to)); - return 0; -} - -int -LineToFunc(FT_Vector *to, void *user) -{ - ((BShape *)user)->LineTo(VectorToPoint(to)); - return 0; -} - -int -ConicToFunc(FT_Vector *control, FT_Vector *to, void *user) -{ - BPoint controls[3]; - - controls[0] = VectorToPoint(control); - controls[1] = VectorToPoint(to); - controls[2] = controls[1]; - - ((BShape *)user)->BezierTo(controls); - return 0; -} - -int -CubicToFunc(FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *user) -{ - BPoint controls[3]; - - controls[0] = VectorToPoint(control1); - controls[1] = VectorToPoint(control2); - controls[2] = VectorToPoint(to); - - ((BShape *)user)->BezierTo(controls); - return 0; -} BShape ** ServerFont::GetGlyphShapes(const char charArray[], int32 numChars) const @@ -386,15 +385,6 @@ ServerFont::GetEscapements(const char charArray[], int32 numChars, return escapements; } -// is_white_space -inline bool -is_white_space(uint16 glyph) -{ - // TODO: handle them all! - if (glyph == ' ' || glyph == B_TAB) - return true; - return false; -} // GetEscapements bool diff --git a/src/servers/app/drawing/Painter/Painter.cpp b/src/servers/app/drawing/Painter/Painter.cpp index 63c3fd8716..8566bec944 100644 --- a/src/servers/app/drawing/Painter/Painter.cpp +++ b/src/servers/app/drawing/Painter/Painter.cpp @@ -89,8 +89,8 @@ Painter::Painter() fPatternHandler(new PatternHandler()), fTextRenderer(new AGGTextRenderer()) { - if (fontserver && fontserver->GetSystemPlain()) - fFont = *fontserver->GetSystemPlain(); + if (gFontServer && gFontServer->GetSystemPlain()) + fFont = *gFontServer->GetSystemPlain(); _UpdateFont(); _UpdateLineWidth();