diff --git a/headers/private/servers/app/BitmapManager.h b/headers/private/servers/app/BitmapManager.h index 5fdcfa5232..12371f5bd5 100644 --- a/headers/private/servers/app/BitmapManager.h +++ b/headers/private/servers/app/BitmapManager.h @@ -8,44 +8,31 @@ #ifndef BITMAP_MANAGER_H_ #define BITMAP_MANAGER_H_ + #include #include +#include #include #include -#include #include "BGet++.h" -#include "TokenHandler.h" class ServerBitmap; -/*! - \class BitmapManager BitmapManager.h - \brief Handler for BBitmap allocation - - Whenever a ServerBitmap associated with a client-side BBitmap needs to be - created or destroyed, the BitmapManager needs to handle it. It takes care of - all memory management related to them. - NOTE: The allocator used is not thread-safe, it is currently protected - by the BitmapManager lock. -*/ class BitmapManager { -public: + public: BitmapManager(); -virtual ~BitmapManager(); + virtual ~BitmapManager(); - ServerBitmap *CreateBitmap( BRect bounds, - color_space space, - int32 flags, - int32 bytesPerRow = -1, - screen_id screen = B_MAIN_SCREEN_ID); + ServerBitmap* CreateBitmap(BRect bounds, color_space space, + int32 flags, int32 bytesPerRow = -1, + screen_id screen = B_MAIN_SCREEN_ID); void DeleteBitmap(ServerBitmap* bitmap); -protected: + protected: BList fBitmapList; - int8 *fBuffer; - TokenHandler fTokenizer; + int8* fBuffer; BLocker fLock; AreaPool fMemPool; }; diff --git a/headers/private/servers/app/TokenHandler.h b/headers/private/servers/app/TokenHandler.h deleted file mode 100644 index b984614a90..0000000000 --- a/headers/private/servers/app/TokenHandler.h +++ /dev/null @@ -1,60 +0,0 @@ -//------------------------------------------------------------------------------ -// Copyright (c) 2001-2002, Haiku -// -// 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: TokenHandler.h -// Author: DarkWyrm -// Description: Class to provide tokens with excluded values possible. -// -//------------------------------------------------------------------------------ -#ifndef TOKENHANDLER_H_ -#define TOKENHANDLER_H_ - -#include -#include -#include - -// Local Defines --------------------------------------------------------------- -#define B_PREFERRED_TOKEN -2 /* A little bird told me about this one */ -#define B_NULL_TOKEN -1 -#define B_ANY_TOKEN 0 -#define B_HANDLER_TOKEN 1 - -/*! - \class TokenHandler TokenHandler.h - \brief Class to provide tokens with excluded values possible. -*/ -class TokenHandler -{ -public: - TokenHandler(void); - ~TokenHandler(void); - int32 GetToken(void); - void ExcludeValue(int32 value); - void Reset(void); - void ResetExcludes(void); - bool IsExclude(int32 value); -private: - int32 _index; - BLocker _lock; - BList *_excludes; -}; - -#endif diff --git a/src/servers/app/AppServer.cpp b/src/servers/app/AppServer.cpp index dbcb8ba3f3..4b10721523 100644 --- a/src/servers/app/AppServer.cpp +++ b/src/servers/app/AppServer.cpp @@ -8,19 +8,8 @@ * Stephan Aßmus */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "AppServer.h" #include "BitmapManager.h" #include "ColorSet.h" @@ -30,10 +19,9 @@ #include "Desktop.h" #include "FontManager.h" #include "HWInterface.h" -#include "RegistrarDefs.h" -#include "RGBColor.h" #include "Layer.h" -#include "WinBorder.h" +#include "RGBColor.h" +#include "RegistrarDefs.h" #include "RootLayer.h" #include "ScreenManager.h" #include "ServerApp.h" @@ -43,8 +31,21 @@ #include "ServerWindow.h" #include "SystemPalette.h" #include "Utils.h" +#include "WinBorder.h" -#include "AppServer.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include //#define DEBUG_KEYHANDLING //#define DEBUG_SERVER @@ -67,10 +68,12 @@ // Globals port_id gAppServerPort; static AppServer *sAppServer; +BTokenSpace gTokenSpace; //! System-wide GUI color object ColorSet gGUIColorSet; + /*! \brief Constructor diff --git a/src/servers/app/AppServer.h b/src/servers/app/AppServer.h index 4200166736..2116279476 100644 --- a/src/servers/app/AppServer.h +++ b/src/servers/app/AppServer.h @@ -4,9 +4,9 @@ * * Author: DarkWyrm */ +#ifndef APP_SERVER_H +#define APP_SERVER_H -#ifndef _HAIKU_APP_SERVER_H_ -#define _HAIKU_APP_SERVER_H_ #include #include @@ -15,6 +15,7 @@ #include #include #include +#include #include "ServerConfig.h" #include "MessageLooper.h" @@ -24,18 +25,12 @@ class BitmapManager; class ColorSet; class Desktop; +using BPrivate::BTokenSpace; + namespace BPrivate { class PortLink; }; -/*! - \class AppServer AppServer.h - \brief main manager object for the app_server - - File for the main app_server thread. This particular thread monitors for - application start and quit messages. It also starts the housekeeping threads - and initializes most of the server's globals. -*/ class AppServer : public MessageLooper { public: @@ -77,4 +72,4 @@ extern BitmapManager *gBitmapManager; extern ColorSet gGUIColorSet; extern port_id gAppServerPort; -#endif /* _HAIKU_APP_SERVER_H_ */ +#endif /* APP_SERVER_H */ diff --git a/src/servers/app/BitmapManager.cpp b/src/servers/app/BitmapManager.cpp index cfbcf029e7..b1aa070bc0 100644 --- a/src/servers/app/BitmapManager.cpp +++ b/src/servers/app/BitmapManager.cpp @@ -8,6 +8,10 @@ /** Handler for allocating and freeing area memory for BBitmaps * on the server side. Utilizes the BGET pool allocator. + * + * Whenever a ServerBitmap associated with a client-side BBitmap needs to be + * created or destroyed, the BitmapManager needs to handle it. It takes care of + * all memory management related to them. */ @@ -17,28 +21,31 @@ #include -#include "ServerBitmap.h" #include "BitmapManager.h" +#include "ServerBitmap.h" +#include "ServerTokenSpace.h" using std::nothrow; + //! The bitmap allocator for the server. Memory is allocated/freed by the AppServer class BitmapManager *gBitmapManager = NULL; //! Number of bytes to allocate to each area used for bitmap storage #define BITMAP_AREA_SIZE B_PAGE_SIZE * 2 + //! Sets up stuff to be ready to allocate space for bitmaps BitmapManager::BitmapManager() : fBitmapList(1024), fBuffer(NULL), - fTokenizer(), fLock("BitmapManager Lock"), fMemPool("bitmap pool", BITMAP_AREA_SIZE) { } + //! Deallocates everything associated with the manager BitmapManager::~BitmapManager() { @@ -51,6 +58,7 @@ BitmapManager::~BitmapManager() } } + /*! \brief Allocates a new ServerBitmap. \param bounds Size of the bitmap @@ -80,7 +88,7 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags, if (buffer && fBitmapList.AddItem(bitmap)) { bitmap->fArea = area_for(buffer); bitmap->fBuffer = buffer; - bitmap->fToken = fTokenizer.GetToken(); + bitmap->fToken = gTokenSpace.NewToken(kBitmapToken, bitmap); bitmap->fInitialized = true; // calculate area offset @@ -97,6 +105,7 @@ BitmapManager::CreateBitmap(BRect bounds, color_space space, int32 flags, return bitmap; } + /*! \brief Deletes a ServerBitmap. \param bitmap The bitmap to delete diff --git a/src/servers/app/CursorManager.cpp b/src/servers/app/CursorManager.cpp index d6ad655f1a..b294467d7d 100644 --- a/src/servers/app/CursorManager.cpp +++ b/src/servers/app/CursorManager.cpp @@ -1,46 +1,32 @@ -//------------------------------------------------------------------------------ -// 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: CursorManager.cpp -// Author: DarkWyrm -// Description: Handles the system's cursor infrastructure -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + +/** Handles the system's cursor infrastructure */ + + #include #include + #include "CursorData.h" #include "CursorManager.h" +#include "HaikuSystemCursor.h" #include "ServerCursor.h" #include "ServerConfig.h" -#include "HaikuSystemCursor.h" +#include "ServerTokenSpace.h" + //! Initializes the CursorManager CursorManager::CursorManager() : BLocker("CursorManager") { - // Error code for AddCursor - fTokenizer.ExcludeValue(B_ERROR); - // Set system cursors to "unassigned" // ToDo: decide about default cursor + #if 1 fDefaultCursor = new ServerCursor(kHaikuCursorBits, kHaikuCursorWidth, kHaikuCursorHeight, kHaikuCursorFormat); @@ -100,7 +86,7 @@ CursorManager::~CursorManager() \return The token assigned to the cursor or B_ERROR if sc is NULL */ int32 -CursorManager::AddCursor(ServerCursor *cursor) +CursorManager::AddCursor(ServerCursor* cursor) { if (!cursor) return B_ERROR; @@ -108,7 +94,7 @@ CursorManager::AddCursor(ServerCursor *cursor) Lock(); fCursorList.AddItem(cursor); - int32 token = fTokenizer.GetToken(); + int32 token = fTokenSpace.NewToken(B_SERVER_TOKEN, cursor); cursor->fToken = token; Unlock(); @@ -347,77 +333,50 @@ CursorManager::ChangeCursor(cursor_which which, int32 token) // Do the assignment switch (which) { case B_CURSOR_DEFAULT: - { - if (fDefaultCursor) - delete fDefaultCursor; - + delete fDefaultCursor; fDefaultCursor = cursor; break; - } - case B_CURSOR_TEXT: - { - if(fTextCursor) - delete fTextCursor; + case B_CURSOR_TEXT: + delete fTextCursor; fTextCursor = cursor; break; - } - case B_CURSOR_MOVE: - { - if(fMoveCursor) - delete fMoveCursor; + case B_CURSOR_MOVE: + delete fMoveCursor; fMoveCursor = cursor; break; - } - case B_CURSOR_DRAG: - { - if(fDragCursor) - delete fDragCursor; + case B_CURSOR_DRAG: + delete fDragCursor; fDragCursor = cursor; break; - } - case B_CURSOR_RESIZE: - { - if(fResizeCursor) - delete fResizeCursor; + case B_CURSOR_RESIZE: + delete fResizeCursor; fResizeCursor = cursor; break; - } - case B_CURSOR_RESIZE_NWSE: - { - if(fNWSECursor) - delete fNWSECursor; + case B_CURSOR_RESIZE_NWSE: + delete fNWSECursor; fNWSECursor = cursor; break; - } - case B_CURSOR_RESIZE_NESW: - { - if(fNESWCursor) - delete fNESWCursor; + case B_CURSOR_RESIZE_NESW: + delete fNESWCursor; fNESWCursor = cursor; break; - } - case B_CURSOR_RESIZE_NS: - { - if(fNSCursor) - delete fNSCursor; + case B_CURSOR_RESIZE_NS: + delete fNSCursor; fNSCursor = cursor; break; - } - case B_CURSOR_RESIZE_EW: - { - if(fEWCursor) - delete fEWCursor; + case B_CURSOR_RESIZE_EW: + delete fEWCursor; fEWCursor = cursor; break; - } + default: Unlock(); return; @@ -439,11 +398,9 @@ CursorManager::ChangeCursor(cursor_which which, int32 token) ServerCursor * CursorManager::FindCursor(int32 token) { - for (int32 i = 0; i < fCursorList.CountItems(); i++) { - ServerCursor *cursor = (ServerCursor *)fCursorList.ItemAt(i); - if (cursor && cursor->fToken == token) - return cursor; - } + ServerCursor* cursor; + if (gTokenSpace.GetToken(token, kCursorToken, (void**)&cursor) == B_OK) + return cursor; return NULL; } diff --git a/src/servers/app/CursorManager.h b/src/servers/app/CursorManager.h index 8cbb86ec7a..e201be77d5 100644 --- a/src/servers/app/CursorManager.h +++ b/src/servers/app/CursorManager.h @@ -1,39 +1,25 @@ -//------------------------------------------------------------------------------ -// 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: CursorManager.h -// Author: DarkWyrm -// Description: Handles the system's cursor infrastructure -// -//------------------------------------------------------------------------------ -#ifndef CURSORMANAGER_H_ -#define CURSORMANAGER_H_ +/* + * Copyright 2001-2005, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ +#ifndef CURSOR_MANAGER_H +#define CURSOR_MANAGER_H + #include #include -#include "CursorSet.h" -#include "TokenHandler.h" +#include + +#include "CursorSet.h" + +using BPrivate::BTokenSpace; class ServerCursor; + /*! \class CursorManager CursorManager.h \brief Handles almost all cursor management functions for the system @@ -43,22 +29,24 @@ class ServerCursor; of an application's cursors whenever an application closes. */ class CursorManager : public BLocker { -public: + public: CursorManager(); - ~CursorManager(); - int32 AddCursor(ServerCursor *sc); + virtual ~CursorManager(); + + int32 AddCursor(ServerCursor* cursor); void DeleteCursor(int32 token); void RemoveAppCursors(team_id team); - void SetCursorSet(const char *path); - ServerCursor *GetCursor(cursor_which which); + + void SetCursorSet(const char* path); + ServerCursor* GetCursor(cursor_which which); cursor_which GetCursorWhich(); void ChangeCursor(cursor_which which, int32 token); void SetDefaults(); - ServerCursor *FindCursor(int32 token); + ServerCursor* FindCursor(int32 token); -private: + private: BList fCursorList; - TokenHandler fTokenizer; + BTokenSpace fTokenSpace; // System cursor members ServerCursor *fDefaultCursor, @@ -73,4 +61,4 @@ private: cursor_which fCurrentWhich; }; -#endif +#endif /* CURSOR_MANAGER_H */ diff --git a/src/servers/app/IPoint.cpp b/src/servers/app/IPoint.cpp deleted file mode 100644 index c362a3b192..0000000000 --- a/src/servers/app/IPoint.cpp +++ /dev/null @@ -1,115 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: IPoint.h -// Author: DarkWyrm -// Based on BPoint code by Frans Van Nispen -// Description: Integer BPoint class -//------------------------------------------------------------------------------ -#include "IPoint.h" -#include -#include -#include - -void IPoint::ConstrainTo(BRect r) -{ - x = (int32)max_c(min_c(x, r.right), r.left); - y = (int32)max_c(min_c(y, r.bottom), r.top); -} - -void IPoint::PrintToStream() const -{ - printf("IPoint(x:%ld, y:%ld)\n", x, y); -} - -IPoint IPoint::operator+(const IPoint &p) const -{ - return IPoint(x + p.x, y + p.y); -} - -IPoint IPoint::operator+(const BPoint &p) const -{ - return IPoint(x + (int32)p.x, y + (int32)p.y); -} - -IPoint IPoint::operator-(const IPoint &p) const -{ - return IPoint(x - p.x, y - p.y); -} - -IPoint IPoint::operator-(const BPoint &p) const -{ - return IPoint(x - (int32)p.x, y - (int32)p.y); -} - -IPoint &IPoint::operator+=(const IPoint &p) -{ - x += p.x; - y += p.y; - - return *this; -} - -IPoint &IPoint::operator+=(const BPoint &p) -{ - x += (int32)p.x; - y += (int32)p.y; - - return *this; -} - -IPoint &IPoint::operator-=(const IPoint &p) -{ - x -= p.x; - y -= p.y; - - return *this; -} - -IPoint &IPoint::operator-=(const BPoint &p) -{ - x -= (int32)p.x; - y -= (int32)p.y; - - return *this; -} - -bool IPoint::operator!=(const IPoint &p) const -{ - return x != p.x || y != p.y; -} - -bool IPoint::operator!=(const BPoint &p) const -{ - return x != (int32)p.x || y != (int32)p.y; -} - -bool IPoint::operator==(const IPoint &p) const -{ - return x == p.x && y == p.y; -} - -bool IPoint::operator==(const BPoint &p) const -{ - return x == (int32)p.x && y == (int32)p.y; -} - - diff --git a/src/servers/app/Jamfile b/src/servers/app/Jamfile index 61d3308e2d..10c1a62925 100644 --- a/src/servers/app/Jamfile +++ b/src/servers/app/Jamfile @@ -48,7 +48,6 @@ Server app_server : ServerWindow.cpp SubWindowList.cpp SystemPalette.cpp - TokenHandler.cpp Utils.cpp VirtualScreen.cpp WinBorder.cpp diff --git a/src/servers/app/ServerApp.cpp b/src/servers/app/ServerApp.cpp index 65bae8f751..11f073b548 100644 --- a/src/servers/app/ServerApp.cpp +++ b/src/servers/app/ServerApp.cpp @@ -50,6 +50,7 @@ #include "ServerCursor.h" #include "ServerPicture.h" #include "ServerScreen.h" +#include "ServerTokenSpace.h" #include "ServerWindow.h" #include "SystemPalette.h" #include "Utils.h" @@ -2404,13 +2405,11 @@ ServerApp::CountBitmaps() const ServerBitmap* ServerApp::FindBitmap(int32 token) const { - int32 count = fBitmapList.CountItems(); - for (int32 i = 0; i < count; i++) { - ServerBitmap* bitmap = (ServerBitmap*)fBitmapList.ItemAt(i); - if (bitmap && bitmap->Token() == token) - return bitmap; - } - + // TODO: we need to make sure the bitmap is ours?! + ServerBitmap* bitmap; + if (gTokenSpace.GetToken(token, kBitmapToken, (void**)&bitmap) == B_OK) + return bitmap; + return NULL; } @@ -2425,12 +2424,11 @@ ServerApp::CountPictures() const ServerPicture * ServerApp::FindPicture(int32 token) const { - for (int32 i = 0; i < fPictureList.CountItems(); i++) { - ServerPicture *picture = static_cast(fPictureList.ItemAt(i)); - if (picture && picture->GetToken() == token) - return picture; - } - + // TODO: we need to make sure the picture is ours?! + ServerPicture* picture; + if (gTokenSpace.GetToken(token, kPictureToken, (void**)&picture) == B_OK) + return picture; + return NULL; } diff --git a/src/servers/app/ServerPicture.cpp b/src/servers/app/ServerPicture.cpp index 84b0f21b6f..1df6754f02 100644 --- a/src/servers/app/ServerPicture.cpp +++ b/src/servers/app/ServerPicture.cpp @@ -1,48 +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: ServerPicture.cpp -// Author: DarkWyrm -// Description: Server-side counterpart to BPicture -// -//------------------------------------------------------------------------------ -#include "TokenHandler.h" +/* + * Copyright 2001-2005, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ + +/** Server-side counterpart to BPicture */ + + #include "ServerPicture.h" +#include "ServerTokenSpace.h" -TokenHandler picture_token_handler; -ServerPicture::ServerPicture(void) +ServerPicture::ServerPicture() { - _token=picture_token_handler.GetToken(); - - _initialized=false; - + fToken = gTokenSpace.NewToken(B_SERVER_TOKEN, this); + int8 *ptr; - _area=create_area("ServerPicture",(void**)&ptr,B_ANY_ADDRESS,B_PAGE_SIZE, - B_NO_LOCK,B_READ_AREA | B_WRITE_AREA); - - if(_area!=B_BAD_VALUE && _area!=B_NO_MEMORY && _area!=B_ERROR) - _initialized=true; + fArea = create_area("ServerPicture", (void**)&ptr, B_ANY_ADDRESS, + B_PAGE_SIZE, B_NO_LOCK,B_READ_AREA | B_WRITE_AREA); } -ServerPicture::~ServerPicture(void) + +ServerPicture::~ServerPicture() { } diff --git a/src/servers/app/ServerPicture.h b/src/servers/app/ServerPicture.h index 67054362e7..0ef9677f31 100644 --- a/src/servers/app/ServerPicture.h +++ b/src/servers/app/ServerPicture.h @@ -1,51 +1,32 @@ -//------------------------------------------------------------------------------ -// 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: ServerPicture.cpp -// Author: DarkWyrm -// Description: Server-side counterpart to BPicture -// -//------------------------------------------------------------------------------ +/* + * Copyright 2001-2005, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * DarkWyrm + */ #ifndef SERVER_PICTURE_H #define SERVER_PICTURE_H + #include class AreaLink; -class ServerPicture -{ -public: - ServerPicture(void); - ~ServerPicture(void); - bool InitCheck(void) { return _initialized; } - area_id Area(void) { return _area; } - int32 GetToken(void) { return _token; } -private: - - AreaLink *arealink; - bool _initialized; - area_id _area; - int32 _token; +class ServerPicture { + public: + ServerPicture(); + ~ServerPicture(); + + status_t InitCheck() const { return fArea >= B_OK ? B_OK : fArea; } + area_id Area() const { return fArea; } + int32 Token() const { return fToken; } + + private: + AreaLink* fAreaLink; + area_id fArea; + int32 fToken; }; -#endif +#endif /* SERVER_PICTURE_H */ diff --git a/src/servers/app/ServerTokenSpace.h b/src/servers/app/ServerTokenSpace.h new file mode 100644 index 0000000000..46ef4d51a0 --- /dev/null +++ b/src/servers/app/ServerTokenSpace.h @@ -0,0 +1,24 @@ +/* + * Copyright 2005, Haiku, Inc. + * Distributed under the terms of the MIT License. + * + * Authors: + * Axel Dörfler, axeld@pinc-software.de + */ +#ifndef SERVER_TOKEN_SPACE_H +#define SERVER_TOKEN_SPACE_H + + +#include + + +using BPrivate::BTokenSpace; + +const int32 kCursorToken = 3; +const int32 kBitmapToken = 4; +const int32 kPictureToken = 5; + + +extern BTokenSpace gTokenSpace; + +#endif /* SERVER_TOKEN_SPACE_H */ diff --git a/src/servers/app/ServerWindow.cpp b/src/servers/app/ServerWindow.cpp index 9321a09084..30cee788f4 100644 --- a/src/servers/app/ServerWindow.cpp +++ b/src/servers/app/ServerWindow.cpp @@ -50,7 +50,6 @@ #include "ServerBitmap.h" #include "ServerPicture.h" #include "ServerProtocol.h" -#include "TokenHandler.h" #include "Utils.h" #include "WinBorder.h" #include "Workspace.h" diff --git a/src/servers/app/TokenHandler.cpp b/src/servers/app/TokenHandler.cpp deleted file mode 100644 index 0b7d52a611..0000000000 --- a/src/servers/app/TokenHandler.cpp +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// 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: TokenHandler.cpp -// Author: DarkWyrm -// Description: Class to provide tokens with excluded values possible. -// -//------------------------------------------------------------------------------ -#include "TokenHandler.h" - -//! Does setup -TokenHandler::TokenHandler(void) -{ - _index=-1; - _excludes=new BList(0); -} - -//! Undoes the setup from the constructor -TokenHandler::~TokenHandler(void) -{ - ResetExcludes(); - delete _excludes; -} - -/*! - \brief Returns a unique token - \return A unique token - - If a value is excluded the next higher non-excluded value is returned. -*/ -int32 TokenHandler::GetToken(void) -{ - int32 value; - - _lock.Lock(); - - _index++; - while(IsExclude(_index)) - _index++; - value=_index; - _lock.Unlock(); - return value; -} - -/*! - \brief Excludes a value from being returned as a token. - - This is quite useful for excluding values like B_ERROR and such. -*/ -void TokenHandler::ExcludeValue(int32 value) -{ - _lock.Lock(); - - if(!IsExclude(value)) - _excludes->AddItem(new int32(value)); - _lock.Unlock(); -} - -//! Resets the token index -void TokenHandler::Reset(void) -{ - _lock.Lock(); - _index=-1; - _lock.Unlock(); -} - -//! Empties object of all assigned excluded values -void TokenHandler::ResetExcludes(void) -{ - _lock.Lock(); - int32 *temp; - for(int32 i=0; i<_excludes->CountItems();i++) - { - temp=(int32*)_excludes->ItemAt(i); - if(temp) - delete temp; - } - _excludes->MakeEmpty(); - _lock.Unlock(); -} - -/*! - \brief Determines whether a value is excluded - \param value The value to be checked - \return True if the value is excluded from being a token, false if not. -*/ -bool TokenHandler::IsExclude(int32 value) -{ - bool match=false; - int32 *temp; - - _lock.Lock(); - for(int32 i=0;i<_excludes->CountItems();i++) - { - temp=(int32*)_excludes->ItemAt(i); - if(temp && *temp==value) - { - match=true; - break; - } - } - _lock.Unlock(); - return match; -} diff --git a/src/servers/app/WinBorder.cpp b/src/servers/app/WinBorder.cpp index 94856a885e..33afdb04e1 100644 --- a/src/servers/app/WinBorder.cpp +++ b/src/servers/app/WinBorder.cpp @@ -26,7 +26,6 @@ #include "RootLayer.h" #include "ServerApp.h" #include "ServerWindow.h" -#include "TokenHandler.h" #include "WinBorder.h" #include "Workspace.h" diff --git a/src/tests/servers/app/Jamfile b/src/tests/servers/app/Jamfile index b2884e51c5..fa9c47ddec 100644 --- a/src/tests/servers/app/Jamfile +++ b/src/tests/servers/app/Jamfile @@ -49,7 +49,6 @@ SharedLibrary libhwinterfaceimpl.so : SharedLibrary libhaikuappserver.so : Angle.cpp BGet++.cpp - BitmapManager.cpp ColorSet.cpp CursorData.cpp CursorSet.cpp @@ -57,14 +56,12 @@ SharedLibrary libhaikuappserver.so : DrawState.cpp FontFamily.cpp HashTable.cpp - IPoint.cpp RGBColor.cpp ServerBitmap.cpp ServerCursor.cpp ServerFont.cpp FontManager.cpp SystemPalette.cpp - TokenHandler.cpp Utils.cpp # drawing @@ -82,12 +79,12 @@ Server haiku_app_server : Decorator.cpp DebugInfoManager.cpp SubWindowList.cpp - #PicturePlayer.cpp PNGDump.cpp RAMLinkMsgReader.cpp MessageLooper.cpp # Manager Classes + BitmapManager.cpp CursorManager.cpp DecorManager.cpp ScreenManager.cpp diff --git a/src/tests/servers/app/bitmap_drawing/Jamfile b/src/tests/servers/app/bitmap_drawing/Jamfile index 7b28f4dec7..55c8e35b9b 100644 --- a/src/tests/servers/app/bitmap_drawing/Jamfile +++ b/src/tests/servers/app/bitmap_drawing/Jamfile @@ -11,3 +11,8 @@ Application BitmapDrawing : : be ; +if ( $(TARGET_PLATFORM) = libbe_test ) { + HaikuInstall install-test-apps : $(HAIKU_APP_TEST_DIR) : BitmapDrawing + : tests!apps ; +} +