* Cleanup, no functional change.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32244 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-08-11 10:01:37 +00:00
parent 07e13b5fe6
commit 6c36406800
2 changed files with 194 additions and 160 deletions
+174 -144
View File
@@ -13,11 +13,33 @@
* Philippe Saint-Pierre, [email protected] * Philippe Saint-Pierre, [email protected]
*/ */
/*!
\class ServerApp ServerApp.h /*! \class ServerApp ServerApp.h
\brief Counterpart to BApplication within the app_server \brief Counterpart to BApplication within the app_server
*/ */
#include "ServerApp.h"
#include <new>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
#include <AppDefs.h>
#include <Autolock.h>
#include <Debug.h>
#include <List.h>
#include <ScrollBar.h>
#include <Shape.h>
#include <String.h>
#include <FontPrivate.h>
#include <MessengerPrivate.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h>
#include <WindowPrivate.h>
#include "AppServer.h" #include "AppServer.h"
#include "BitmapManager.h" #include "BitmapManager.h"
#include "CursorManager.h" #include "CursorManager.h"
@@ -31,7 +53,6 @@
#include "InputManager.h" #include "InputManager.h"
#include "OffscreenServerWindow.h" #include "OffscreenServerWindow.h"
#include "Screen.h" #include "Screen.h"
#include "ServerApp.h"
#include "ServerBitmap.h" #include "ServerBitmap.h"
#include "ServerConfig.h" #include "ServerConfig.h"
#include "ServerCursor.h" #include "ServerCursor.h"
@@ -41,25 +62,6 @@
#include "SystemPalette.h" #include "SystemPalette.h"
#include "Window.h" #include "Window.h"
#include <FontPrivate.h>
#include <MessengerPrivate.h>
#include <RosterPrivate.h>
#include <ServerProtocol.h>
#include <WindowPrivate.h>
#include <AppDefs.h>
#include <Autolock.h>
#include <Debug.h>
#include <List.h>
#include <ScrollBar.h>
#include <Shape.h>
#include <String.h>
#include <new>
#include <stdio.h>
#include <string.h>
#include <syslog.h>
//#define DEBUG_SERVERAPP //#define DEBUG_SERVERAPP
#ifdef DEBUG_SERVERAPP #ifdef DEBUG_SERVERAPP
@@ -84,7 +86,8 @@ static const uint32 kMsgAppQuit = 'appQ';
ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort, ServerApp::ServerApp(Desktop* desktop, port_id clientReplyPort,
port_id clientLooperPort, team_id clientTeam, port_id clientLooperPort, team_id clientTeam,
int32 clientToken, const char* signature) int32 clientToken, const char* signature)
: MessageLooper("application"), :
MessageLooper("application"),
fMessagePort(-1), fMessagePort(-1),
fClientReplyPort(clientReplyPort), fClientReplyPort(clientReplyPort),
@@ -160,8 +163,8 @@ ServerApp::~ServerApp()
for (int32 i = fWindowList.CountItems(); i-- > 0;) { for (int32 i = fWindowList.CountItems(); i-- > 0;) {
ServerWindow* window = fWindowList.ItemAt(i); ServerWindow* window = fWindowList.ItemAt(i);
// a window could have been remove in the mean time (if those 20 millisecs // A window could have been removed in the mean time
// from above weren't enough) // (if those 20 milli seconds from above weren't enough)
if (window == NULL) if (window == NULL)
continue; continue;
@@ -183,7 +186,7 @@ ServerApp::~ServerApp()
} }
for (int32 i = fBitmapList.CountItems(); i-- > 0;) { for (int32 i = fBitmapList.CountItems(); i-- > 0;) {
gBitmapManager->DeleteBitmap(static_cast<ServerBitmap *>(fBitmapList.ItemAt(i))); gBitmapManager->DeleteBitmap((ServerBitmap*)fBitmapList.ItemAt(i));
} }
for (int32 i = fPictureList.CountItems(); i-- > 0;) { for (int32 i = fPictureList.CountItems(); i-- > 0;) {
@@ -196,8 +199,7 @@ ServerApp::~ServerApp()
} }
/*! /*! \brief Checks if the application was initialized correctly
\brief Checks if the application was initialized correctly
*/ */
status_t status_t
ServerApp::InitCheck() ServerApp::InitCheck()
@@ -215,8 +217,7 @@ ServerApp::InitCheck()
} }
/*! /*! \brief This quits the application and deletes it. You're not supposed
\brief This quits the application and deletes it. You're not supposed
to call its destructor directly. to call its destructor directly.
At the point you're calling this method, the application should already At the point you're calling this method, the application should already
@@ -239,16 +240,18 @@ ServerApp::Quit(sem_id shutdownSemaphore)
} }
/*! /*! \brief Send a message to the ServerApp's BApplication
\brief Send a message to the ServerApp's BApplication \param message The message to send
\param msg The message to send
*/ */
void void
ServerApp::SendMessageToClient(BMessage *msg) const ServerApp::SendMessageToClient(BMessage* message) const
{ {
status_t status = fHandlerMessenger.SendMessage(msg, (BHandler*)NULL, 100000); status_t status = fHandlerMessenger.SendMessage(message, (BHandler*)NULL,
if (status != B_OK) 100000);
printf("app %s send to client failed: %s\n", Signature(), strerror(status)); if (status != B_OK) {
syslog(LOG_ERR, "app %s send to client failed: %s\n", Signature(),
strerror(status));
}
} }
@@ -268,8 +271,7 @@ ServerApp::_HasWindowUnderMouse()
} }
/*! /*! \brief Sets the ServerApp's active status
\brief Sets the ServerApp's active status
\param value The new status of the ServerApp. \param value The new status of the ServerApp.
This changes an internal flag and also sets the current cursor to the one This changes an internal flag and also sets the current cursor to the one
@@ -332,8 +334,7 @@ ServerApp::_GetLooperName(char* name, size_t length)
} }
/*! /*! \brief The thread function ServerApps use to monitor messages
\brief The thread function ServerApps use to monitor messages
*/ */
void void
ServerApp::_MessageLooper() ServerApp::_MessageLooper()
@@ -352,9 +353,11 @@ ServerApp::_MessageLooper()
status_t err = B_OK; status_t err = B_OK;
while (!fQuitting) { while (!fQuitting) {
STRACE(("info: ServerApp::_MessageLooper() listening on port %ld.\n", fMessagePort)); STRACE(("info: ServerApp::_MessageLooper() listening on port %ld.\n",
fMessagePort));
err = receiver.GetNextMessage(code, B_INFINITE_TIMEOUT); err = receiver.GetNextMessage(code, B_INFINITE_TIMEOUT);
if (err < B_OK || code == B_QUIT_REQUESTED) { if (err != B_OK || code == B_QUIT_REQUESTED) {
STRACE(("ServerApp: application seems to be gone...\n")); STRACE(("ServerApp: application seems to be gone...\n"));
// Tell desktop to quit us // Tell desktop to quit us
@@ -373,12 +376,15 @@ ServerApp::_MessageLooper()
case AS_QUIT_APP: case AS_QUIT_APP:
{ {
// This message is received only when the app_server is asked to shut down in // This message is received only when the app_server is asked to
// test/debug mode. Of course, if we are testing while using AccelerantDriver, we do // shut down in test/debug mode. Of course, if we are testing
// NOT want to shut down client applications. The server can be quit o in this fashion // while using AccelerantDriver, we do NOT want to shut down
// through the driver's interface, such as closing the ViewDriver's window. // client applications. The server can be quit in this fashion
// through the driver's interface, such as closing the
// ViewDriver's window.
STRACE(("ServerApp %s:Server shutdown notification received\n", Signature())); STRACE(("ServerApp %s:Server shutdown notification received\n",
Signature()));
// If we are using the real, accelerated version of the // If we are using the real, accelerated version of the
// DrawingEngine, we do NOT want the user to be able shut down // DrawingEngine, we do NOT want the user to be able shut down
@@ -391,7 +397,8 @@ ServerApp::_MessageLooper()
} }
default: default:
STRACE(("ServerApp %s: Got a Message to dispatch\n", Signature())); STRACE(("ServerApp %s: Got a Message to dispatch\n",
Signature()));
_DispatchMessage(code, receiver); _DispatchMessage(code, receiver);
break; break;
} }
@@ -409,8 +416,7 @@ ServerApp::_MessageLooper()
} }
/*! /*! \brief Handler function for BApplication API messages
\brief Handler function for BApplication API messages
\param code Identifier code for the message. Equivalent to BMessage::what \param code Identifier code for the message. Equivalent to BMessage::what
\param buffer Any attachments \param buffer Any attachments
@@ -424,15 +430,16 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
switch (code) { switch (code) {
case AS_REGISTER_INPUT_SERVER: case AS_REGISTER_INPUT_SERVER:
{ {
EventStream* stream = new (nothrow) InputServerStream(fHandlerMessenger); EventStream* stream
= new(std::nothrow) InputServerStream(fHandlerMessenger);
if (stream != NULL if (stream != NULL
&& (!stream->IsValid() || !gInputManager->AddStream(stream))) { && (!stream->IsValid() || !gInputManager->AddStream(stream))) {
delete stream; delete stream;
break; break;
} }
// TODO: this should be done using notifications (so that an abandoned // TODO: this should be done using notifications (so that an
// stream will get noticed directly) // abandoned stream will get noticed directly)
if (fDesktop->EventDispatcher().InitCheck() != B_OK) if (fDesktop->EventDispatcher().InitCheck() != B_OK)
fDesktop->EventDispatcher().SetTo(gInputManager->GetStream()); fDesktop->EventDispatcher().SetTo(gInputManager->GetStream());
break; break;
@@ -538,9 +545,6 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
case AS_SET_DECORATOR: case AS_SET_DECORATOR:
{ {
// Received from an application when the user wants to set the window
// decorator to a new one
// Attached Data: // Attached Data:
// int32 the index of the decorator to use // int32 the index of the decorator to use
@@ -581,8 +585,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_R5_SET_DECORATOR: case AS_R5_SET_DECORATOR:
{ {
// Sort of supports Tracker's nifty Easter Egg. It was easy to do and // Sort of supports Tracker's nifty Easter Egg. It was easy to do
// it's kind of neat, so why not? // and it's kind of neat, so why not?
// Attached Data: // Attached Data:
// int32 value of the decorator to use // int32 value of the decorator to use
@@ -601,7 +605,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_CREATE_BITMAP: case AS_CREATE_BITMAP:
{ {
STRACE(("ServerApp %s: Received BBitmap creation request\n", Signature())); STRACE(("ServerApp %s: Received BBitmap creation request\n",
Signature()));
// Allocate a bitmap for an application // Allocate a bitmap for an application
// Attached Data: // Attached Data:
@@ -617,7 +623,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// 3) int32 area pointer offset used to calculate fBasePtr // 3) int32 area pointer offset used to calculate fBasePtr
// First, let's attempt to allocate the bitmap // First, let's attempt to allocate the bitmap
ServerBitmap *bitmap = NULL; ServerBitmap* bitmap = NULL;
uint8 allocationFlags = kAllocator; uint8 allocationFlags = kAllocator;
BRect frame; BRect frame;
@@ -631,10 +637,11 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
link.Read<uint32>(&flags); link.Read<uint32>(&flags);
link.Read<int32>(&bytesPerRow); link.Read<int32>(&bytesPerRow);
if (link.Read<screen_id>(&screenID) == B_OK) { if (link.Read<screen_id>(&screenID) == B_OK) {
// TODO: choose the right HWInterface with regards to the screenID // TODO: choose the right HWInterface with regards to the
// screenID
bitmap = gBitmapManager->CreateBitmap(&fMemoryAllocator, bitmap = gBitmapManager->CreateBitmap(&fMemoryAllocator,
*fDesktop->HWInterface(), frame, colorSpace, flags, bytesPerRow, *fDesktop->HWInterface(), frame, colorSpace, flags,
screenID, &allocationFlags); bytesPerRow, screenID, &allocationFlags);
} }
STRACE(("ServerApp %s: Create Bitmap (%.1fx%.1f)\n", STRACE(("ServerApp %s: Create Bitmap (%.1fx%.1f)\n",
@@ -647,8 +654,10 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
fLink.Attach<int32>(bitmap->Token()); fLink.Attach<int32>(bitmap->Token());
fLink.Attach<uint8>(allocationFlags); fLink.Attach<uint8>(allocationFlags);
fLink.Attach<area_id>(fMemoryAllocator.Area(bitmap->AllocationCookie())); fLink.Attach<area_id>(
fLink.Attach<int32>(fMemoryAllocator.AreaOffset(bitmap->AllocationCookie())); fMemoryAllocator.Area(bitmap->AllocationCookie()));
fLink.Attach<int32>(
fMemoryAllocator.AreaOffset(bitmap->AllocationCookie()));
if (allocationFlags & kFramebuffer) if (allocationFlags & kFramebuffer)
fLink.Attach<int32>(bitmap->BytesPerRow()); fLink.Attach<int32>(bitmap->BytesPerRow());
@@ -664,7 +673,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_DELETE_BITMAP: case AS_DELETE_BITMAP:
{ {
STRACE(("ServerApp %s: received BBitmap delete request\n", Signature())); STRACE(("ServerApp %s: received BBitmap delete request\n",
Signature()));
// Delete a bitmap's allocated memory // Delete a bitmap's allocated memory
// Attached Data: // Attached Data:
@@ -674,7 +685,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
ServerBitmap *bitmap = FindBitmap(token); ServerBitmap *bitmap = FindBitmap(token);
if (bitmap && fBitmapList.RemoveItem(bitmap)) { if (bitmap && fBitmapList.RemoveItem(bitmap)) {
STRACE(("ServerApp %s: Deleting Bitmap %ld\n", Signature(), token)); STRACE(("ServerApp %s: Deleting Bitmap %ld\n", Signature(),
token));
gBitmapManager->DeleteBitmap(bitmap); gBitmapManager->DeleteBitmap(bitmap);
} }
@@ -691,8 +703,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
ServerBitmap *bitmap = FindBitmap(token); ServerBitmap *bitmap = FindBitmap(token);
if (bitmap != NULL) { if (bitmap != NULL) {
STRACE(("ServerApp %s: Get overlay restrictions for bitmap %ld\n", STRACE(("ServerApp %s: Get overlay restrictions for bitmap "
Signature(), token)); "%ld\n", Signature(), token));
status = fDesktop->HWInterface()->GetOverlayRestrictions( status = fDesktop->HWInterface()->GetOverlayRestrictions(
bitmap->Overlay(), &restrictions); bitmap->Overlay(), &restrictions);
@@ -881,7 +893,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_QUERY_CURSOR_HIDDEN: case AS_QUERY_CURSOR_HIDDEN:
{ {
STRACE(("ServerApp %s: Received IsCursorHidden request\n", Signature())); STRACE(("ServerApp %s: Received IsCursorHidden request\n",
Signature()));
fLink.StartMessage(fCursorHideLevel > 0 ? B_OK : B_ERROR); fLink.StartMessage(fCursorHideLevel > 0 ? B_OK : B_ERROR);
fLink.Flush(); fLink.Flush();
break; break;
@@ -893,7 +907,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Attached data: // Attached data:
// 1) bool flag to send a reply // 1) bool flag to send a reply
// 2) int32 token ID of the cursor to set // 2) int32 token ID of the cursor to set
// 3) port_id port to receive a reply. Only exists if the sync flag is true. // 3) port_id port to receive a reply. Only exists if the sync flag
// is true.
bool sync; bool sync;
int32 token; int32 token;
@@ -961,10 +976,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// The cursor might need to be updated now. // The cursor might need to be updated now.
Window* window = view->Window(); Window* window = view->Window();
if (window != NULL && window->IsFocus()) { if (window != NULL && window->IsFocus()) {
if (fDesktop->ViewUnderMouse(window) if (fDesktop->ViewUnderMouse(window) == view->Token())
== view->Token()) {
SetCurrentCursor(cursor); SetCurrentCursor(cursor);
}
} }
} }
@@ -1017,7 +1030,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
if (cursor != NULL) { if (cursor != NULL) {
// Synchronous message - BApplication is waiting on the cursor's ID // Synchronous message - BApplication is waiting on the
// cursor's ID
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<int32>(cursor->Token()); fLink.Attach<int32>(cursor->Token());
} else } else
@@ -1139,7 +1153,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
case AS_SET_MOUSE_MODE: case AS_SET_MOUSE_MODE:
{ {
STRACE(("ServerApp %s: Set Focus Follows Mouse mode\n", Signature())); STRACE(("ServerApp %s: Set Focus Follows Mouse mode\n",
Signature()));
// Attached Data: // Attached Data:
// 1) enum mode_mouse FFM mouse mode // 1) enum mode_mouse FFM mouse mode
mode_mouse mouseMode; mode_mouse mouseMode;
@@ -1151,7 +1166,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_GET_MOUSE_MODE: case AS_GET_MOUSE_MODE:
{ {
STRACE(("ServerApp %s: Get Focus Follows Mouse mode\n", Signature())); STRACE(("ServerApp %s: Get Focus Follows Mouse mode\n",
Signature()));
if (fDesktop->LockSingleWindow()) { if (fDesktop->LockSingleWindow()) {
DesktopSettings settings(fDesktop); DesktopSettings settings(fDesktop);
@@ -1241,7 +1257,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
&& link.Read<float>(&size) == B_OK) { && link.Read<float>(&size) == B_OK) {
gFontManager->Lock(); gFontManager->Lock();
FontStyle* style = gFontManager->GetStyle(familyName, styleName); FontStyle* style
= gFontManager->GetStyle(familyName, styleName);
if (style != NULL) { if (style != NULL) {
ServerFont font(*style, size); ServerFont font(*style, size);
gFontManager->Unlock(); gFontManager->Unlock();
@@ -1361,7 +1378,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
STRACE(("ServerApp %s: AS_GET_FONT_LIST_REVISION\n", Signature())); STRACE(("ServerApp %s: AS_GET_FONT_LIST_REVISION\n", Signature()));
fLink.StartMessage(B_OK); fLink.StartMessage(B_OK);
fLink.Attach<int32>(gFontManager->CheckRevision(fDesktop->UserID())); fLink.Attach<int32>(
gFontManager->CheckRevision(fDesktop->UserID()));
fLink.Flush(); fLink.Flush();
break; break;
} }
@@ -1438,7 +1456,9 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
} }
case AS_GET_FAMILY_AND_STYLE_IDS: case AS_GET_FAMILY_AND_STYLE_IDS:
{ {
FTRACE(("ServerApp %s: AS_GET_FAMILY_AND_STYLE_IDS\n", Signature())); FTRACE(("ServerApp %s: AS_GET_FAMILY_AND_STYLE_IDS\n",
Signature()));
// Attached Data: // Attached Data:
// 1) font_family - name of font family to use // 1) font_family - name of font family to use
// 2) font_style - name of style in family // 2) font_style - name of style in family
@@ -1882,11 +1902,11 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
uint32 numBytes; uint32 numBytes;
link.Read<uint32>(&numBytes); link.Read<uint32>(&numBytes);
char *charArray = new (nothrow) char[numBytes]; char* charArray = new(std::nothrow) char[numBytes];
BPoint *escapements = new (nothrow) BPoint[numChars]; BPoint* escapements = new(std::nothrow) BPoint[numChars];
BPoint *offsets = NULL; BPoint* offsets = NULL;
if (wantsOffsets) if (wantsOffsets)
offsets = new (nothrow) BPoint[numChars]; offsets = new(std::nothrow) BPoint[numChars];
if (charArray == NULL || escapements == NULL if (charArray == NULL || escapements == NULL
|| (offsets == NULL && wantsOffsets)) { || (offsets == NULL && wantsOffsets)) {
@@ -2042,23 +2062,23 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Returns: // Returns:
// 1) BRect - rects with numChar entries // 1) BRect - rects with numChar entries
uint16 famid, styid; uint16 familyID, styleID;
uint32 flags; uint32 flags;
float ptsize, rotation, shear, falseBoldWidth; float size, rotation, shear, falseBoldWidth;
uint8 spacing; uint8 spacing;
font_metric_mode mode; font_metric_mode mode;
bool string_escapement; bool stringEscapement;
link.Read<uint16>(&famid); link.Read<uint16>(&familyID);
link.Read<uint16>(&styid); link.Read<uint16>(&styleID);
link.Read<float>(&ptsize); link.Read<float>(&size);
link.Read<float>(&rotation); link.Read<float>(&rotation);
link.Read<float>(&shear); link.Read<float>(&shear);
link.Read<float>(&falseBoldWidth); link.Read<float>(&falseBoldWidth);
link.Read<uint8>(&spacing); link.Read<uint8>(&spacing);
link.Read<uint32>(&flags); link.Read<uint32>(&flags);
link.Read<font_metric_mode>(&mode); link.Read<font_metric_mode>(&mode);
link.Read<bool>(&string_escapement); link.Read<bool>(&stringEscapement);
escapement_delta delta; escapement_delta delta;
link.Read<escapement_delta>(&delta); link.Read<escapement_delta>(&delta);
@@ -2069,43 +2089,49 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
uint32 numBytes; uint32 numBytes;
link.Read<uint32>(&numBytes); link.Read<uint32>(&numBytes);
// TODO: proper error checking
char *charArray = new (nothrow) char[numBytes];
link.Read(charArray, numBytes);
BRect rectArray[numChars];
// figure out escapements
ServerFont font;
bool success = false; bool success = false;
if (font.SetFamilyAndStyle(famid, styid) == B_OK) {
font.SetSize(ptsize);
font.SetRotation(rotation);
font.SetShear(shear);
font.SetFalseBoldWidth(falseBoldWidth);
font.SetSpacing(spacing);
font.SetFlags(flags);
// TODO implement for real char* charArray = new(std::nothrow) char[numBytes];
if (font.GetBoundingBoxes(charArray, numBytes, BRect* rectArray = new(std::nothrow) BRect[numChars];
rectArray, string_escapement, mode, delta, if (charArray != NULL && rectArray != NULL) {
code == AS_GET_BOUNDINGBOXES_STRING) == B_OK) { link.Read(charArray, numBytes);
fLink.StartMessage(B_OK);
fLink.Attach(rectArray, sizeof(rectArray)); // figure out escapements
success = true;
ServerFont font;
if (font.SetFamilyAndStyle(familyID, styleID) == B_OK) {
font.SetSize(size);
font.SetRotation(rotation);
font.SetShear(shear);
font.SetFalseBoldWidth(falseBoldWidth);
font.SetSpacing(spacing);
font.SetFlags(flags);
// TODO: implement for real
if (font.GetBoundingBoxes(charArray, numBytes,
rectArray, stringEscapement, mode, delta,
code == AS_GET_BOUNDINGBOXES_STRING) == B_OK) {
fLink.StartMessage(B_OK);
fLink.Attach(rectArray, sizeof(rectArray));
success = true;
}
} }
} }
if (!success) if (!success)
fLink.StartMessage(B_ERROR); fLink.StartMessage(B_ERROR);
delete[] charArray;
fLink.Flush(); fLink.Flush();
delete[] charArray;
delete[] rectArray;
break; break;
} }
case AS_GET_BOUNDINGBOXES_STRINGS: case AS_GET_BOUNDINGBOXES_STRINGS:
{ {
FTRACE(("ServerApp %s: AS_GET_BOUNDINGBOXES_STRINGS\n", Signature())); FTRACE(("ServerApp %s: AS_GET_BOUNDINGBOXES_STRINGS\n",
Signature()));
// Attached Data: // Attached Data:
// 1) uint16 - family ID // 1) uint16 - family ID
// 2) uint16 - style ID // 2) uint16 - style ID
@@ -2126,14 +2152,14 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// Returns: // Returns:
// 1) BRect - rects with numStrings entries // 1) BRect - rects with numStrings entries
uint16 famid, styid; uint16 familyID, styleID;
uint32 flags; uint32 flags;
float ptsize, rotation, shear, falseBoldWidth; float ptsize, rotation, shear, falseBoldWidth;
uint8 spacing; uint8 spacing;
font_metric_mode mode; font_metric_mode mode;
link.Read<uint16>(&famid); link.Read<uint16>(&familyID);
link.Read<uint16>(&styid); link.Read<uint16>(&styleID);
link.Read<float>(&ptsize); link.Read<float>(&ptsize);
link.Read<float>(&rotation); link.Read<float>(&rotation);
link.Read<float>(&shear); link.Read<float>(&shear);
@@ -2146,19 +2172,22 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
link.Read<int32>(&numStrings); link.Read<int32>(&numStrings);
escapement_delta deltaArray[numStrings]; escapement_delta deltaArray[numStrings];
char *stringArray[numStrings]; char* stringArray[numStrings];
int32 lengthArray[numStrings]; int32 lengthArray[numStrings];
for(int32 i=0; i<numStrings; i++) { for(int32 i = 0; i < numStrings; i++) {
// This version of ReadString allocates the strings, we free them below // This version of ReadString allocates the strings, we free
link.ReadString(&stringArray[i], (size_t *)&lengthArray[i]); // them below
// TODO: this does not work on 64-bit (size_t != int32)
link.ReadString(&stringArray[i], (size_t*)&lengthArray[i]);
link.Read<escapement_delta>(&deltaArray[i]); link.Read<escapement_delta>(&deltaArray[i]);
} }
// TODO: don't do this on the heap! (at least check the size before)
BRect rectArray[numStrings]; BRect rectArray[numStrings];
ServerFont font; ServerFont font;
bool success = false; bool success = false;
if (font.SetFamilyAndStyle(famid, styid) == B_OK) { if (font.SetFamilyAndStyle(familyID, styleID) == B_OK) {
font.SetSize(ptsize); font.SetSize(ptsize);
font.SetRotation(rotation); font.SetRotation(rotation);
font.SetShear(shear); font.SetShear(shear);
@@ -2184,7 +2213,7 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
break; break;
} }
/* screen commands */ // Screen commands
case AS_VALID_SCREEN_ID: case AS_VALID_SCREEN_ID:
{ {
@@ -2258,8 +2287,8 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
// TODO: the display_mode can be different between // TODO: the display_mode can be different between
// the various screens. // the various screens.
// We have the screen_id and the workspace number, with these // We have the screen_id and the workspace number, with these we
// we need to find the corresponding "driver", and call getmode on it // need to find the corresponding "driver", and call getmode on it
display_mode mode; display_mode mode;
fDesktop->ScreenAt(0)->GetMode(&mode); fDesktop->ScreenAt(0)->GetMode(&mode);
// actually this isn't still enough as different workspaces can // actually this isn't still enough as different workspaces can
@@ -2829,12 +2858,13 @@ ServerApp::_CreateWindow(int32 code, BPrivate::LinkReceiver& link,
ServerBitmap* bitmap = FindBitmap(bitmapToken); ServerBitmap* bitmap = FindBitmap(bitmapToken);
if (bitmap != NULL) { if (bitmap != NULL) {
window = new (nothrow) OffscreenServerWindow(title, this, clientReplyPort, window = new (nothrow) OffscreenServerWindow(title, this,
looperPort, token, bitmap); clientReplyPort, looperPort, token, bitmap);
} else } else
status = B_ERROR; status = B_ERROR;
} else { } else {
window = new (nothrow) ServerWindow(title, this, clientReplyPort, looperPort, token); window = new (nothrow) ServerWindow(title, this, clientReplyPort,
looperPort, token);
STRACE(("\nServerApp %s: New Window %s (%g:%g, %g:%g)\n", STRACE(("\nServerApp %s: New Window %s (%g:%g, %g:%g)\n",
Signature(), title, frame.left, frame.top, Signature(), title, frame.left, frame.top,
frame.right, frame.bottom)); frame.right, frame.bottom));
@@ -2847,7 +2877,8 @@ ServerApp::_CreateWindow(int32 code, BPrivate::LinkReceiver& link,
status = window->Init(frame, (window_look)look, (window_feel)feel, status = window->Init(frame, (window_look)look, (window_feel)feel,
flags, workspaces); flags, workspaces);
if (status == B_OK && !window->Run()) { if (status == B_OK && !window->Run()) {
fprintf(stderr, "ServerApp::_CreateWindow() - failed to run the window thread\n"); syslog(LOG_ERR, "ServerApp::_CreateWindow() - failed to run the "
"window thread\n");
status = B_ERROR; status = B_ERROR;
} }
@@ -2896,7 +2927,8 @@ ServerApp::InWorkspace(int32 index) const
// only normal and unhidden windows count // only normal and unhidden windows count
if (window->IsNormal() && !window->IsHidden() && window->InWorkspace(index)) if (window->IsNormal() && !window->IsHidden()
&& window->InWorkspace(index))
return true; return true;
} }
@@ -2939,8 +2971,7 @@ ServerApp::CountBitmaps() const
} }
/*! /*! \brief Looks up a ServerApp's ServerBitmap in its list
\brief Looks up a ServerApp's ServerBitmap in its list
\param token ID token of the bitmap to find \param token ID token of the bitmap to find
\return The bitmap having that ID or NULL if not found \return The bitmap having that ID or NULL if not found
*/ */
@@ -2963,14 +2994,14 @@ ServerApp::CountPictures() const
} }
ServerPicture * ServerPicture*
ServerApp::CreatePicture(const ServerPicture *original) ServerApp::CreatePicture(const ServerPicture* original)
{ {
ServerPicture *picture; ServerPicture* picture;
if (original != NULL) if (original != NULL)
picture = new (nothrow) ServerPicture(*original); picture = new(std::nothrow) ServerPicture(*original);
else else
picture = new (nothrow) ServerPicture(); picture = new(std::nothrow) ServerPicture();
if (picture != NULL) if (picture != NULL)
fPictureList.AddItem(picture); fPictureList.AddItem(picture);
@@ -2979,8 +3010,8 @@ ServerApp::CreatePicture(const ServerPicture *original)
} }
ServerPicture * ServerPicture*
ServerApp::FindPicture(const int32 &token) const ServerApp::FindPicture(int32 token) const
{ {
// TODO: we need to make sure the picture is ours?! // TODO: we need to make sure the picture is ours?!
ServerPicture* picture; ServerPicture* picture;
@@ -2992,9 +3023,9 @@ ServerApp::FindPicture(const int32 &token) const
bool bool
ServerApp::DeletePicture(const int32 &token) ServerApp::DeletePicture(int32 token)
{ {
ServerPicture *picture = FindPicture(token); ServerPicture* picture = FindPicture(token);
if (picture == NULL) if (picture == NULL)
return false; return false;
@@ -3012,4 +3043,3 @@ ServerApp::ClientTeam() const
{ {
return fClientTeam; return fClientTeam;
} }
+20 -16
View File
@@ -39,7 +39,7 @@ namespace BPrivate {
}; };
class ServerApp : public MessageLooper { class ServerApp : public MessageLooper {
public: public:
ServerApp(Desktop* desktop, ServerApp(Desktop* desktop,
port_id clientAppPort, port_id clientAppPort,
port_id clientLooperPort, port_id clientLooperPort,
@@ -57,7 +57,7 @@ class ServerApp : public MessageLooper {
\brief Determines whether the application is the active one \brief Determines whether the application is the active one
\return true if active, false if not. \return true if active, false if not.
*/ */
bool IsActive(void) const { return fIsActive; } bool IsActive() const { return fIsActive; }
void Activate(bool value); void Activate(bool value);
void SendMessageToClient(BMessage* message) const; void SendMessageToClient(BMessage* message) const;
@@ -66,22 +66,27 @@ class ServerApp : public MessageLooper {
ServerCursor* CurrentCursor() const; ServerCursor* CurrentCursor() const;
team_id ClientTeam() const; team_id ClientTeam() const;
const char* Signature() const { return fSignature.String(); }
const char* SignatureLeaf() const { return fSignature.String() + 12; } const char* Signature() const
{ return fSignature.String(); }
const char* SignatureLeaf() const
{ return fSignature.String() + 12; }
bool AddWindow(ServerWindow* window); bool AddWindow(ServerWindow* window);
void RemoveWindow(ServerWindow* window); void RemoveWindow(ServerWindow* window);
bool InWorkspace(int32 index) const; bool InWorkspace(int32 index) const;
uint32 Workspaces() const; uint32 Workspaces() const;
int32 InitialWorkspace() const { return fInitialWorkspace; } int32 InitialWorkspace() const
{ return fInitialWorkspace; }
int32 CountBitmaps() const; int32 CountBitmaps() const;
ServerBitmap* FindBitmap(int32 token) const; ServerBitmap* FindBitmap(int32 token) const;
int32 CountPictures() const; int32 CountPictures() const;
ServerPicture* CreatePicture(const ServerPicture* original = NULL); ServerPicture* CreatePicture(
ServerPicture* FindPicture(const int32& token) const; const ServerPicture* original = NULL);
bool DeletePicture(const int32& token); ServerPicture* FindPicture(int32 token) const;
bool DeletePicture(int32 token);
Desktop* GetDesktop() const { return fDesktop; } Desktop* GetDesktop() const { return fDesktop; }
@@ -89,14 +94,14 @@ class ServerApp : public MessageLooper {
BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; } BPrivate::BTokenSpace& ViewTokens() { return fViewTokens; }
private: private:
virtual void _DispatchMessage(int32 code, virtual void _DispatchMessage(int32 code,
BPrivate::LinkReceiver& link); BPrivate::LinkReceiver& link);
virtual void _MessageLooper(); virtual void _MessageLooper();
virtual void _GetLooperName(char* name, size_t size); virtual void _GetLooperName(char* name, size_t size);
status_t _CreateWindow(int32 code, status_t _CreateWindow(int32 code,
BPrivate::LinkReceiver& link, BPrivate::LinkReceiver& link,
port_id& clientReplyPort); port_id& clientReplyPort);
bool _HasWindowUnderMouse(); bool _HasWindowUnderMouse();
@@ -124,10 +129,9 @@ class ServerApp : public MessageLooper {
int32 fInitialWorkspace; int32 fInitialWorkspace;
// NOTE: Bitmaps and Pictures are stored globally, but ServerApps remember // NOTE: Bitmaps and Pictures are stored globally, but ServerApps
// which ones they own so that they can destroy them when they quit. // remember which ones they own so that they can destroy them when
// TODO: // they quit.
// - As we reference these stuff by token, what about putting them in hash tables ?
BList fBitmapList; BList fBitmapList;
BList fPictureList; BList fPictureList;