2005-11-14 22:46:20 +03:00
|
|
|
/*
|
2006-02-05 21:14:14 +03:00
|
|
|
* Copyright 2001-2006, Haiku.
|
2005-11-14 22:46:20 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* DarkWyrm <bpmagic@columbus.rr.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Handles the system's cursor infrastructure */
|
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
#include "CursorManager.h"
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
#include "CursorData.h"
|
2005-11-14 22:46:20 +03:00
|
|
|
#include "HaikuSystemCursor.h"
|
2003-01-23 17:25:16 +03:00
|
|
|
#include "ServerCursor.h"
|
2003-07-24 23:38:24 +04:00
|
|
|
#include "ServerConfig.h"
|
2005-11-14 22:46:20 +03:00
|
|
|
#include "ServerTokenSpace.h"
|
|
|
|
|
2006-02-05 21:14:14 +03:00
|
|
|
#include <Autolock.h>
|
|
|
|
#include <Directory.h>
|
|
|
|
#include <String.h>
|
|
|
|
|
2006-02-28 17:48:23 +03:00
|
|
|
#include <new>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2003-01-24 17:00:48 +03:00
|
|
|
|
2005-07-12 21:41:22 +04:00
|
|
|
CursorManager::CursorManager()
|
2006-02-05 21:14:14 +03:00
|
|
|
: BLocker("CursorManager")
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
|
|
|
// Set system cursors to "unassigned"
|
2005-07-18 04:22:08 +04:00
|
|
|
// ToDo: decide about default cursor
|
2005-11-14 22:46:20 +03:00
|
|
|
|
2005-07-18 04:22:08 +04:00
|
|
|
#if 1
|
|
|
|
fDefaultCursor = new ServerCursor(kHaikuCursorBits, kHaikuCursorWidth,
|
|
|
|
kHaikuCursorHeight, kHaikuCursorFormat);
|
|
|
|
// we just happen to know where the hotspot is
|
|
|
|
fDefaultCursor->SetHotSpot(BPoint(1, 0));
|
|
|
|
#else
|
2005-07-18 01:26:28 +04:00
|
|
|
fDefaultCursor = new ServerCursor(default_cursor_data);
|
2005-07-18 04:22:08 +04:00
|
|
|
#endif
|
2006-02-05 21:14:14 +03:00
|
|
|
AddCursor(fDefaultCursor, B_CURSOR_DEFAULT);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fTextCursor = new ServerCursor(default_text_data);
|
2006-02-05 21:14:14 +03:00
|
|
|
AddCursor(fTextCursor, B_CURSOR_TEXT);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fMoveCursor = new ServerCursor(default_move_data);
|
|
|
|
AddCursor(fMoveCursor);
|
2003-07-24 23:38:24 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fDragCursor = new ServerCursor(default_drag_data);
|
|
|
|
AddCursor(fDragCursor);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fResizeCursor = new ServerCursor(default_resize_data);
|
|
|
|
AddCursor(fResizeCursor);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fNWSECursor = new ServerCursor(default_resize_nwse_data);
|
|
|
|
AddCursor(fNWSECursor);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fNESWCursor = new ServerCursor(default_resize_nesw_data);
|
|
|
|
AddCursor(fNESWCursor);
|
2003-07-16 03:27:50 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fNSCursor = new ServerCursor(default_resize_ns_data);
|
|
|
|
AddCursor(fNSCursor);
|
2003-07-24 23:38:24 +04:00
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
fEWCursor = new ServerCursor(default_resize_ew_data);
|
|
|
|
AddCursor(fEWCursor);
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
//! Does all the teardown
|
2005-07-12 21:41:22 +04:00
|
|
|
CursorManager::~CursorManager()
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2005-07-18 01:26:28 +04:00
|
|
|
for (int32 i = 0; i < fCursorList.CountItems(); i++) {
|
2006-02-26 21:15:31 +03:00
|
|
|
delete (ServerCursor*)fCursorList.ItemAtFast(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerCursor*
|
|
|
|
CursorManager::CreateCursor(team_id clientTeam, const uint8* cursorData)
|
|
|
|
{
|
|
|
|
if (!Lock())
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
ServerCursor* cursor = _FindCursor(clientTeam, cursorData);
|
|
|
|
|
|
|
|
if (!cursor) {
|
2006-02-28 17:48:23 +03:00
|
|
|
cursor = new (std::nothrow) ServerCursor(cursorData);
|
2006-02-26 21:15:31 +03:00
|
|
|
if (cursor) {
|
|
|
|
cursor->SetOwningTeam(clientTeam);
|
|
|
|
if (AddCursor(cursor) < B_OK) {
|
|
|
|
delete cursor;
|
|
|
|
cursor = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cursor->Acquire();
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
2006-02-26 21:15:31 +03:00
|
|
|
|
|
|
|
Unlock();
|
|
|
|
|
|
|
|
return cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
|
|
|
\brief Registers a cursor with the manager.
|
2006-02-26 21:15:31 +03:00
|
|
|
\param cursor ServerCursor object to register
|
|
|
|
\return The token assigned to the cursor or B_ERROR if cursor is NULL
|
2003-01-23 17:25:16 +03:00
|
|
|
*/
|
2005-07-18 01:26:28 +04:00
|
|
|
int32
|
2006-02-05 21:14:14 +03:00
|
|
|
CursorManager::AddCursor(ServerCursor* cursor, int32 token)
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2006-02-26 21:15:31 +03:00
|
|
|
if (!cursor || !Lock())
|
2003-01-23 17:25:16 +03:00
|
|
|
return B_ERROR;
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
if (!fCursorList.AddItem(cursor)) {
|
|
|
|
Unlock();
|
|
|
|
return B_ERROR;
|
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
if (token == -1) {
|
|
|
|
token = fTokenSpace.NewToken(kCursorToken, cursor);
|
|
|
|
} else {
|
2006-02-05 21:14:14 +03:00
|
|
|
fTokenSpace.SetToken(token, kCursorToken, cursor);
|
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
cursor->fToken = token;
|
|
|
|
cursor->AttachedToManager(this);
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
Unlock();
|
2006-02-05 21:14:14 +03:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
return token;
|
2006-02-05 21:14:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
2007-01-04 15:28:31 +03:00
|
|
|
\brief Removes a cursor if it's not referenced anymore.
|
2006-02-05 22:43:44 +03:00
|
|
|
|
|
|
|
If this was the last reference to this cursor, it will be deleted.
|
2007-01-04 15:28:31 +03:00
|
|
|
Only if the cursor is deleted, \c true is returned.
|
2003-01-23 17:25:16 +03:00
|
|
|
*/
|
2007-01-04 15:28:31 +03:00
|
|
|
bool
|
2006-02-26 21:15:31 +03:00
|
|
|
CursorManager::RemoveCursor(ServerCursor* cursor)
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2006-02-26 21:15:31 +03:00
|
|
|
if (!Lock())
|
2007-01-04 15:28:31 +03:00
|
|
|
return false;
|
|
|
|
|
2007-01-04 15:32:44 +03:00
|
|
|
// TODO: this doesn't work as it looks like, and it's not safe!
|
2007-01-04 15:28:31 +03:00
|
|
|
if (cursor->ReferenceCount() > 0) {
|
|
|
|
// cursor has been referenced again in the mean time
|
|
|
|
Unlock();
|
|
|
|
return false;
|
|
|
|
}
|
2003-01-23 17:25:16 +03:00
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
_RemoveCursor(cursor);
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
2007-01-04 15:28:31 +03:00
|
|
|
return true;
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
|
|
|
\brief Removes and deletes all of an application's cursors
|
|
|
|
\param signature Signature to which the cursors belong
|
|
|
|
*/
|
2005-07-01 14:13:50 +04:00
|
|
|
void
|
2006-02-05 21:14:14 +03:00
|
|
|
CursorManager::DeleteCursors(team_id team)
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2006-02-26 21:15:31 +03:00
|
|
|
if (!Lock())
|
|
|
|
return;
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2006-02-05 21:14:14 +03:00
|
|
|
for (int32 index = fCursorList.CountItems(); index-- > 0;) {
|
2006-02-26 21:15:31 +03:00
|
|
|
ServerCursor *cursor = (ServerCursor*)fCursorList.ItemAtFast(index);
|
|
|
|
if (cursor->OwningTeam() == team)
|
|
|
|
cursor->Release();
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
2005-07-01 14:13:50 +04:00
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
/*!
|
|
|
|
\brief Sets all the cursors from a specified CursorSet
|
|
|
|
\param path Path to the cursor set
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
All cursors in the set will be assigned. If the set does not specify a
|
|
|
|
cursor for a particular cursor specifier, it will remain unchanged.
|
|
|
|
This function will fail if passed a NULL path, an invalid path, or the
|
|
|
|
path to a non-CursorSet file.
|
2003-07-24 23:38:24 +04:00
|
|
|
*/
|
2005-07-18 01:26:28 +04:00
|
|
|
void
|
|
|
|
CursorManager::SetCursorSet(const char *path)
|
2003-07-24 23:38:24 +04:00
|
|
|
{
|
2006-02-05 21:14:14 +03:00
|
|
|
BAutolock locker (this);
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
CursorSet cursorSet(NULL);
|
|
|
|
|
|
|
|
if (!path || cursorSet.Load(path) != B_OK)
|
2003-07-24 23:38:24 +04:00
|
|
|
return;
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
ServerCursor *cursor = NULL;
|
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_DEFAULT, &cursor) == B_OK) {
|
|
|
|
if (fDefaultCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fDefaultCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fDefaultCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_TEXT, &cursor) == B_OK) {
|
|
|
|
if (fTextCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fTextCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fTextCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_MOVE, &cursor) == B_OK) {
|
|
|
|
if (fMoveCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fMoveCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fMoveCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_DRAG, &cursor) == B_OK) {
|
|
|
|
if (fDragCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fDragCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fDragCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_RESIZE, &cursor) == B_OK) {
|
|
|
|
if (fResizeCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fResizeCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fResizeCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_RESIZE_NWSE, &cursor) == B_OK) {
|
|
|
|
if (fNWSECursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fNWSECursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNWSECursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_RESIZE_NESW, &cursor) == B_OK) {
|
|
|
|
if (fNESWCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fNESWCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNESWCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_RESIZE_NS, &cursor) == B_OK) {
|
|
|
|
if (fNSCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fNSCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNSCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
if (cursorSet.FindCursor(B_CURSOR_RESIZE_EW, &cursor) == B_OK) {
|
|
|
|
if (fEWCursor)
|
2004-06-26 06:15:48 +04:00
|
|
|
delete fEWCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fEWCursor = cursor;
|
2003-07-24 23:38:24 +04:00
|
|
|
}
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
|
|
|
\brief Acquire the cursor which is used for a particular system cursor
|
|
|
|
\param which Which system cursor to get
|
|
|
|
\return Pointer to the particular cursor used or NULL if which is
|
|
|
|
invalid or the cursor has not been assigned
|
|
|
|
*/
|
2005-07-18 01:26:28 +04:00
|
|
|
ServerCursor *
|
|
|
|
CursorManager::GetCursor(cursor_which which)
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2006-02-05 21:14:14 +03:00
|
|
|
BAutolock locker(this);
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
switch (which) {
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_DEFAULT:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fDefaultCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_TEXT:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fTextCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_MOVE:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fMoveCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_DRAG:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fDragCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_RESIZE:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fResizeCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_RESIZE_NWSE:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fNWSECursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_RESIZE_NESW:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fNESWCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_RESIZE_NS:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fNSCursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_RESIZE_EW:
|
2006-02-05 21:14:14 +03:00
|
|
|
return fEWCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
default:
|
2006-02-05 21:14:14 +03:00
|
|
|
return NULL;
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
|
|
|
\brief Gets the current system cursor value
|
|
|
|
\return The current cursor value or CURSOR_OTHER if some non-system cursor
|
|
|
|
*/
|
2005-07-18 01:26:28 +04:00
|
|
|
cursor_which
|
|
|
|
CursorManager::GetCursorWhich()
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2003-07-24 23:38:24 +04:00
|
|
|
Lock();
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
// ToDo: Where is fCurrentWhich set?
|
|
|
|
cursor_which which;
|
|
|
|
which = fCurrentWhich;
|
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
2005-07-18 01:26:28 +04:00
|
|
|
return which;
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
/*!
|
|
|
|
\brief Sets the specified system cursor to the a particular cursor
|
|
|
|
\param which Which system cursor to change
|
|
|
|
\param token The ID of the cursor to become the new one
|
|
|
|
|
|
|
|
A word of warning: once a cursor has been assigned to the system, the
|
|
|
|
system will take ownership of the cursor and deleting the cursor
|
2005-07-12 21:41:22 +04:00
|
|
|
will have no effect on the system.
|
2003-01-23 17:25:16 +03:00
|
|
|
*/
|
2005-07-18 01:26:28 +04:00
|
|
|
void
|
|
|
|
CursorManager::ChangeCursor(cursor_which which, int32 token)
|
2003-01-23 17:25:16 +03:00
|
|
|
{
|
2003-07-24 23:38:24 +04:00
|
|
|
Lock();
|
2003-01-23 17:25:16 +03:00
|
|
|
|
|
|
|
// Find the cursor, based on the token
|
2005-07-18 01:26:28 +04:00
|
|
|
ServerCursor *cursor = FindCursor(token);
|
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
// Did we find a cursor with this token?
|
2005-07-18 01:26:28 +04:00
|
|
|
if (!cursor) {
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
2003-01-23 17:25:16 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do the assignment
|
2005-07-18 01:26:28 +04:00
|
|
|
switch (which) {
|
2003-01-23 17:25:16 +03:00
|
|
|
case B_CURSOR_DEFAULT:
|
2005-11-14 22:46:20 +03:00
|
|
|
delete fDefaultCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fDefaultCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_TEXT:
|
|
|
|
delete fTextCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fTextCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_MOVE:
|
|
|
|
delete fMoveCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fMoveCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_DRAG:
|
|
|
|
delete fDragCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fDragCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_RESIZE:
|
|
|
|
delete fResizeCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fResizeCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_RESIZE_NWSE:
|
|
|
|
delete fNWSECursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNWSECursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_RESIZE_NESW:
|
|
|
|
delete fNESWCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNESWCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_RESIZE_NS:
|
|
|
|
delete fNSCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fNSCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
|
|
|
|
2005-11-14 22:46:20 +03:00
|
|
|
case B_CURSOR_RESIZE_EW:
|
|
|
|
delete fEWCursor;
|
2005-07-18 01:26:28 +04:00
|
|
|
fEWCursor = cursor;
|
2003-01-23 17:25:16 +03:00
|
|
|
break;
|
2005-11-14 22:46:20 +03:00
|
|
|
|
2003-01-23 17:25:16 +03:00
|
|
|
default:
|
2005-07-18 01:26:28 +04:00
|
|
|
Unlock();
|
|
|
|
return;
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
2005-07-18 01:26:28 +04:00
|
|
|
|
|
|
|
fCursorList.RemoveItem(cursor);
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
2003-01-23 17:25:16 +03:00
|
|
|
}
|
|
|
|
|
2005-07-18 01:26:28 +04:00
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
//! Sets the cursors to the defaults and saves them to CURSOR_SETTINGS_DIR/"d
|
2005-07-18 01:26:28 +04:00
|
|
|
void
|
|
|
|
CursorManager::SetDefaults()
|
2003-07-24 23:38:24 +04:00
|
|
|
{
|
|
|
|
Lock();
|
2005-07-18 01:26:28 +04:00
|
|
|
CursorSet cursorSet("Default");
|
|
|
|
cursorSet.AddCursor(B_CURSOR_DEFAULT, default_cursor_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_TEXT, default_text_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_MOVE, default_move_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_DRAG, default_drag_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_RESIZE, default_resize_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_RESIZE_NWSE, default_resize_nwse_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_RESIZE_NESW, default_resize_nesw_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_RESIZE_NS, default_resize_ns_data);
|
|
|
|
cursorSet.AddCursor(B_CURSOR_RESIZE_EW, default_resize_ew_data);
|
2006-04-26 13:03:28 +04:00
|
|
|
#if 0
|
2003-07-24 23:38:24 +04:00
|
|
|
BDirectory dir;
|
2005-07-18 01:26:28 +04:00
|
|
|
if (dir.SetTo(CURSOR_SET_DIR) == B_ENTRY_NOT_FOUND)
|
|
|
|
create_directory(CURSOR_SET_DIR, 0777);
|
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
BString string(CURSOR_SET_DIR);
|
2005-07-18 01:26:28 +04:00
|
|
|
string += "Default";
|
|
|
|
cursorSet.Save(string.String(), B_CREATE_FILE | B_FAIL_IF_EXISTS);
|
|
|
|
|
2003-07-24 23:38:24 +04:00
|
|
|
SetCursorSet(string.String());
|
2006-04-26 13:03:28 +04:00
|
|
|
#endif
|
2003-07-24 23:38:24 +04:00
|
|
|
Unlock();
|
|
|
|
}
|
2006-02-26 21:15:31 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\brief Internal function which finds the cursor with a particular ID
|
|
|
|
\param token ID of the cursor to find
|
|
|
|
\return The cursor or NULL if not found
|
|
|
|
*/
|
|
|
|
ServerCursor *
|
|
|
|
CursorManager::FindCursor(int32 token)
|
|
|
|
{
|
2006-03-20 01:34:05 +03:00
|
|
|
if (!Lock())
|
|
|
|
return NULL;
|
|
|
|
|
2006-02-26 21:15:31 +03:00
|
|
|
ServerCursor* cursor;
|
2006-03-20 01:34:05 +03:00
|
|
|
if (fTokenSpace.GetToken(token, kCursorToken, (void**)&cursor) != B_OK)
|
|
|
|
cursor = NULL;
|
2006-02-26 21:15:31 +03:00
|
|
|
|
2006-03-20 01:34:05 +03:00
|
|
|
Unlock();
|
|
|
|
|
|
|
|
return cursor;
|
2006-02-26 21:15:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ServerCursor *
|
|
|
|
CursorManager::_FindCursor(team_id clientTeam, const uint8* cursorData)
|
|
|
|
{
|
|
|
|
int32 count = fCursorList.CountItems();
|
|
|
|
for (int32 i = 0; i < count; i++) {
|
|
|
|
ServerCursor* cursor = (ServerCursor*)fCursorList.ItemAtFast(i);
|
|
|
|
if (cursor->OwningTeam() == clientTeam
|
|
|
|
&& cursor->CursorData()
|
|
|
|
&& memcmp(cursor->CursorData(), cursorData, 68) == 0) {
|
2006-03-20 01:34:05 +03:00
|
|
|
//printf("found already existing cursor\n");
|
2006-02-26 21:15:31 +03:00
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
CursorManager::_RemoveCursor(ServerCursor* cursor)
|
|
|
|
{
|
|
|
|
fCursorList.RemoveItem(cursor);
|
|
|
|
fTokenSpace.RemoveToken(cursor->fToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//ServerCursor*
|
|
|
|
//CursorManager::_RemoveCursor(int32 index)
|
|
|
|
//{
|
|
|
|
// ServerCursor* cursor = (ServerCursor*)fCursorList.RemoveItem(index);
|
|
|
|
// if (cursor != NULL)
|
|
|
|
// fTokenSpace.RemoveToken(cursor->fToken);
|
|
|
|
//
|
|
|
|
// return cursor;
|
|
|
|
//}
|
|
|
|
|
|
|
|
|