Files
haiku-beta6/src/kits/app/Cursor.cpp
T
Stephan Aßmus 588259b66d various changes to handling custom cursors:
* all cursors owned by a team are visually different,
  or (iaw) an already existing cursor is reused when
  it is set by the client again
* changed various occurances of cursor data from "int8*"
  to "uint8*"
* ServerCursors also remember the R5 data from which
  they were created
* the reference counting and destruction of
  ServerCursors changed: The cursor knows it is attached
  to a CursorManager and one can simply use
  ServerCursor::Acquire() and Release() and the reference
  counting and everything is being taken care of
* destroying a ViewLayer will now correctly release a set
  ServerCursor
* fixed a race condition when setting a cursor through
  BView::SetViewCursor(): If the client code looks like this:

  BCursor cursor(cursorData);
  someView->SetViewCursor(&cursor, false);

  there is a relatively high chance the BCursor destructor
  told the ServerApp thread to destroy the cursor before
  the ServerWindow thread got to "acquire" the cursor for
  use by the view layer. The very same problem is likely the
  reason that SetViewCursor works to unreliably on R5, even
  when the "sync" flag is set to "true" (although it should
  theoretically work in that case).

all these fixes make WonderBrush work fine again with the
new support of custom cursors.... coded by axeld and myself
(the joys of pair programming :-)



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16521 a95241bf-73f2-0310-859d-f6bbb57e9c96
2006-02-26 18:15:31 +00:00

116 lines
2.3 KiB
C++

/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* Frans van Nispen ([email protected])
* Gabe Yoder ([email protected])
* Axel Dörfler, [email protected]
*/
/** BCursor describes a view-wide or application-wide cursor. */
/**
@note: As BeOS only supports 16x16 monochrome cursors, and I would like
to see a nice shadowes one, we will need to extend this one.
*/
#include <AppDefs.h>
#include <Cursor.h>
#include <CursorSet.h>
#include <AppServerLink.h>
#include <ServerProtocol.h>
const BCursor *B_CURSOR_SYSTEM_DEFAULT;
const BCursor *B_CURSOR_I_BEAM;
// these are initialized in BApplication::InitData()
BCursor::BCursor(const void *cursorData)
:
fServerToken(-1),
fNeedToFree(false),
fPendingViewCursor(false)
{
const uint8 *data = (const uint8 *)cursorData;
if (data == B_HAND_CURSOR || data == B_I_BEAM_CURSOR) {
// just use the default cursors from the app_server
fServerToken = data == B_HAND_CURSOR ?
B_CURSOR_DEFAULT : B_CURSOR_TEXT;
return;
}
// Create a new cursor in the app_server
if (data == NULL
|| data[0] != 16 // size
|| data[1] != 1 // depth
|| data[2] >= 16 || data[3] >= 16) // hot-spot
return;
// Send data directly to server
BPrivate::AppServerLink link;
link.StartMessage(AS_CREATE_CURSOR);
link.Attach(cursorData, 68);
status_t status;
if (link.FlushWithReply(status) == B_OK && status == B_OK) {
link.Read<int32>(&fServerToken);
fNeedToFree = true;
}
}
BCursor::BCursor(BMessage *data)
{
// undefined on BeOS
fServerToken = -1;
fNeedToFree = false;
fPendingViewCursor = false;
}
BCursor::~BCursor()
{
// Notify server to deallocate server-side objects for this cursor
if (fNeedToFree) {
BPrivate::AppServerLink link;
link.StartMessage(AS_DELETE_CURSOR);
link.Attach<int32>(fServerToken);
link.Attach<bool>(fPendingViewCursor);
link.Flush();
}
}
status_t
BCursor::Archive(BMessage *into, bool deep) const
{
// not implemented on BeOS
return B_OK;
}
BArchivable *
BCursor::Instantiate(BMessage *data)
{
// not implemented on BeOS
return NULL;
}
status_t
BCursor::Perform(perform_code d, void *arg)
{
return B_OK;
}
void BCursor::_ReservedCursor1() {}
void BCursor::_ReservedCursor2() {}
void BCursor::_ReservedCursor3() {}
void BCursor::_ReservedCursor4() {}