* last change set window title to "Unnamed Window" if the title was empty - but
that's probably not wanted, as a window without a title is perfectly okay. * AS_CREATE_WINDOW will now return a proper error code on failure. * The title read from the link is no longer adopted by the ServerWindow constructor, but copied - while the previous version was a bit faster, this is a lot cleaner. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14851 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
d28dc0ce83
commit
dfd5b49996
@ -400,47 +400,48 @@ ServerApp::_MessageLooper()
|
|||||||
frame.right = frame.left + 1;
|
frame.right = frame.left + 1;
|
||||||
frame.bottom = frame.top + 1;
|
frame.bottom = frame.top + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool success = false;
|
status_t status = B_ERROR;
|
||||||
ServerWindow *window = NULL;
|
ServerWindow *window = NULL;
|
||||||
|
|
||||||
if (code == AS_CREATE_OFFSCREEN_WINDOW) {
|
if (code == AS_CREATE_OFFSCREEN_WINDOW) {
|
||||||
ServerBitmap* bitmap = FindBitmap(bitmapToken);
|
ServerBitmap* bitmap = FindBitmap(bitmapToken);
|
||||||
|
|
||||||
if (bitmap != NULL)
|
if (bitmap != NULL) {
|
||||||
// ServerWindow constructor will reply with port_id of a newly created port
|
window = new OffscreenServerWindow(title, this, clientReplyPort,
|
||||||
window = new OffscreenServerWindow(title, this, clientReplyPort,
|
looperPort, token, bitmap);
|
||||||
looperPort, token, bitmap);
|
}
|
||||||
else
|
|
||||||
free(title);
|
|
||||||
} else {
|
} else {
|
||||||
window = new ServerWindow(title, this, clientReplyPort, looperPort, token);
|
window = new ServerWindow(title, this, clientReplyPort, looperPort, token);
|
||||||
STRACE(("\nServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n",
|
STRACE(("\nServerApp %s: New Window %s (%.1f,%.1f,%.1f,%.1f)\n",
|
||||||
fSignature(), title, frame.left, frame.top, frame.right, frame.bottom));
|
fSignature(), title, frame.left, frame.top, frame.right, frame.bottom));
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: the reply to the client is handled in window->Run()
|
free(title);
|
||||||
|
|
||||||
|
// NOTE: the reply to the client is handled in ServerWindow::Run()
|
||||||
if (window != NULL) {
|
if (window != NULL) {
|
||||||
success = window->Init(frame, look, feel, flags, workspaces) >= B_OK && window->Run();
|
status = window->Init(frame, look, feel, flags, workspaces);
|
||||||
|
if (status == B_OK && !window->Run())
|
||||||
|
status = B_ERROR;
|
||||||
|
|
||||||
// add the window to the list
|
// add the window to the list
|
||||||
if (success && fWindowListLock.Lock()) {
|
if (status == B_OK && fWindowListLock.Lock()) {
|
||||||
success = fWindowList.AddItem(window);
|
status = fWindowList.AddItem(window) ? B_OK : B_NO_MEMORY;
|
||||||
fWindowListLock.Unlock();
|
fWindowListLock.Unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success)
|
if (status < B_OK)
|
||||||
delete window;
|
delete window;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!success) {
|
// if sucessful, ServerWindow::Run() will already have replied
|
||||||
|
if (status < B_OK) {
|
||||||
// window creation failed, we need to notify the client
|
// window creation failed, we need to notify the client
|
||||||
BPrivate::LinkSender reply(clientReplyPort);
|
BPrivate::LinkSender reply(clientReplyPort);
|
||||||
reply.StartMessage(SERVER_FALSE);
|
reply.StartMessage(status);
|
||||||
reply.Flush();
|
reply.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't have to free the title, as it's owned by the ServerWindow now
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ struct dw_sync_data {
|
|||||||
ServerWindow::ServerWindow(const char *title, ServerApp *app,
|
ServerWindow::ServerWindow(const char *title, ServerApp *app,
|
||||||
port_id clientPort, port_id looperPort, int32 handlerID)
|
port_id clientPort, port_id looperPort, int32 handlerID)
|
||||||
: MessageLooper(title && *title ? title : "Unnamed Window"),
|
: MessageLooper(title && *title ? title : "Unnamed Window"),
|
||||||
fTitle(title),
|
fTitle(NULL),
|
||||||
fDesktop(app->GetDesktop()),
|
fDesktop(app->GetDesktop()),
|
||||||
fServerApp(app),
|
fServerApp(app),
|
||||||
fWinBorder(NULL),
|
fWinBorder(NULL),
|
||||||
@ -146,6 +146,7 @@ ServerWindow::ServerWindow(const char *title, ServerApp *app,
|
|||||||
{
|
{
|
||||||
STRACE(("ServerWindow(%s)::ServerWindow()\n", title));
|
STRACE(("ServerWindow(%s)::ServerWindow()\n", title));
|
||||||
|
|
||||||
|
SetTitle(title);
|
||||||
fServerToken = BPrivate::gDefaultTokens.NewToken(B_SERVER_TOKEN, this);
|
fServerToken = BPrivate::gDefaultTokens.NewToken(B_SERVER_TOKEN, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +161,7 @@ ServerWindow::~ServerWindow()
|
|||||||
|
|
||||||
delete fWinBorder;
|
delete fWinBorder;
|
||||||
|
|
||||||
free(const_cast<char *>(fTitle));
|
free(fTitle);
|
||||||
delete_port(fMessagePort);
|
delete_port(fMessagePort);
|
||||||
|
|
||||||
BPrivate::gDefaultTokens.RemoveToken(fServerToken);
|
BPrivate::gDefaultTokens.RemoveToken(fServerToken);
|
||||||
@ -173,8 +174,6 @@ ServerWindow::~ServerWindow()
|
|||||||
status_t
|
status_t
|
||||||
ServerWindow::Init(BRect frame, uint32 look, uint32 feel, uint32 flags, uint32 workspace)
|
ServerWindow::Init(BRect frame, uint32 look, uint32 feel, uint32 flags, uint32 workspace)
|
||||||
{
|
{
|
||||||
if (fTitle == NULL)
|
|
||||||
fTitle = strdup("Unnamed Window");
|
|
||||||
if (fTitle == NULL)
|
if (fTitle == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@ -240,7 +239,11 @@ ServerWindow::_PrepareQuit()
|
|||||||
void
|
void
|
||||||
ServerWindow::_GetLooperName(char* name, size_t length)
|
ServerWindow::_GetLooperName(char* name, size_t length)
|
||||||
{
|
{
|
||||||
snprintf(name, length, "w:%ld:%s", ClientTeam(), Title());
|
const char *title = Title();
|
||||||
|
if (title == NULL || !title[0])
|
||||||
|
title = "Unnamed Window";
|
||||||
|
|
||||||
|
snprintf(name, length, "w:%ld:%s", ClientTeam(), title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -301,23 +304,23 @@ ServerWindow::Hide()
|
|||||||
void
|
void
|
||||||
ServerWindow::SetTitle(const char* newTitle)
|
ServerWindow::SetTitle(const char* newTitle)
|
||||||
{
|
{
|
||||||
const char* oldTitle = fTitle;
|
char* oldTitle = fTitle;
|
||||||
|
|
||||||
if (newTitle == NULL || !newTitle[0])
|
if (newTitle == NULL)
|
||||||
fTitle = strdup("Unnamed Window");
|
newTitle = "";
|
||||||
else
|
|
||||||
fTitle = strdup(newTitle);
|
|
||||||
|
|
||||||
|
fTitle = strdup(newTitle);
|
||||||
if (fTitle == NULL) {
|
if (fTitle == NULL) {
|
||||||
|
// out of memory condition
|
||||||
fTitle = oldTitle;
|
fTitle = oldTitle;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(const_cast<char*>(oldTitle));
|
free(oldTitle);
|
||||||
|
|
||||||
if (Thread() >= B_OK) {
|
if (Thread() >= B_OK) {
|
||||||
char name[B_OS_NAME_LENGTH];
|
char name[B_OS_NAME_LENGTH];
|
||||||
snprintf(name, sizeof(name), "w:%ld:%s", ClientTeam(), fTitle);
|
_GetLooperName(name, sizeof(name));
|
||||||
rename_thread(Thread(), name);
|
rename_thread(Thread(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ private:
|
|||||||
BPoint where);
|
BPoint where);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* fTitle;
|
char* fTitle;
|
||||||
|
|
||||||
Desktop* fDesktop;
|
Desktop* fDesktop;
|
||||||
ServerApp* fServerApp;
|
ServerApp* fServerApp;
|
||||||
|
Loading…
Reference in New Issue
Block a user