* 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:
Axel Dörfler 2005-11-11 13:06:22 +00:00
parent d28dc0ce83
commit dfd5b49996
3 changed files with 39 additions and 35 deletions

View File

@ -400,47 +400,48 @@ ServerApp::_MessageLooper()
frame.right = frame.left + 1;
frame.bottom = frame.top + 1;
}
bool success = false;
status_t status = B_ERROR;
ServerWindow *window = NULL;
if (code == AS_CREATE_OFFSCREEN_WINDOW) {
ServerBitmap* bitmap = FindBitmap(bitmapToken);
if (bitmap != NULL)
// ServerWindow constructor will reply with port_id of a newly created port
window = new OffscreenServerWindow(title, this, clientReplyPort,
looperPort, token, bitmap);
else
free(title);
if (bitmap != NULL) {
window = new OffscreenServerWindow(title, this, clientReplyPort,
looperPort, token, bitmap);
}
} else {
window = new ServerWindow(title, this, clientReplyPort, looperPort, token);
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) {
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
if (success && fWindowListLock.Lock()) {
success = fWindowList.AddItem(window);
if (status == B_OK && fWindowListLock.Lock()) {
status = fWindowList.AddItem(window) ? B_OK : B_NO_MEMORY;
fWindowListLock.Unlock();
}
if (!success)
if (status < B_OK)
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
BPrivate::LinkSender reply(clientReplyPort);
reply.StartMessage(SERVER_FALSE);
reply.StartMessage(status);
reply.Flush();
}
// We don't have to free the title, as it's owned by the ServerWindow now
break;
}

View File

@ -131,7 +131,7 @@ struct dw_sync_data {
ServerWindow::ServerWindow(const char *title, ServerApp *app,
port_id clientPort, port_id looperPort, int32 handlerID)
: MessageLooper(title && *title ? title : "Unnamed Window"),
fTitle(title),
fTitle(NULL),
fDesktop(app->GetDesktop()),
fServerApp(app),
fWinBorder(NULL),
@ -146,6 +146,7 @@ ServerWindow::ServerWindow(const char *title, ServerApp *app,
{
STRACE(("ServerWindow(%s)::ServerWindow()\n", title));
SetTitle(title);
fServerToken = BPrivate::gDefaultTokens.NewToken(B_SERVER_TOKEN, this);
}
@ -160,7 +161,7 @@ ServerWindow::~ServerWindow()
delete fWinBorder;
free(const_cast<char *>(fTitle));
free(fTitle);
delete_port(fMessagePort);
BPrivate::gDefaultTokens.RemoveToken(fServerToken);
@ -173,8 +174,6 @@ ServerWindow::~ServerWindow()
status_t
ServerWindow::Init(BRect frame, uint32 look, uint32 feel, uint32 flags, uint32 workspace)
{
if (fTitle == NULL)
fTitle = strdup("Unnamed Window");
if (fTitle == NULL)
return B_NO_MEMORY;
@ -240,7 +239,11 @@ ServerWindow::_PrepareQuit()
void
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
ServerWindow::SetTitle(const char* newTitle)
{
const char* oldTitle = fTitle;
char* oldTitle = fTitle;
if (newTitle == NULL || !newTitle[0])
fTitle = strdup("Unnamed Window");
else
fTitle = strdup(newTitle);
if (newTitle == NULL)
newTitle = "";
fTitle = strdup(newTitle);
if (fTitle == NULL) {
// out of memory condition
fTitle = oldTitle;
return;
}
free(const_cast<char*>(oldTitle));
free(oldTitle);
if (Thread() >= B_OK) {
char name[B_OS_NAME_LENGTH];
snprintf(name, sizeof(name), "w:%ld:%s", ClientTeam(), fTitle);
_GetLooperName(name, sizeof(name));
rename_thread(Thread(), name);
}

View File

@ -128,7 +128,7 @@ private:
BPoint where);
private:
const char* fTitle;
char* fTitle;
Desktop* fDesktop;
ServerApp* fServerApp;