Patch by Wim van der Meer: Implemented global Interface Kit function to retrieve

the current mouse position and pressed buttons. I've changed the return code
to status_t and added anal error checking, most of the rest of the file is not
doing it, though... :-) Thanks, Wim!


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36811 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2010-05-14 15:53:09 +00:00
parent 4339f8be19
commit 1c73ffa102
5 changed files with 62 additions and 2 deletions

View File

@ -10,6 +10,7 @@
#include <OS.h>
class BRect;
class BPoint;
// some handy UTF-8 characters
@ -380,6 +381,8 @@ mode_mouse mouse_mode();
void set_focus_follows_mouse_mode(mode_focus_follows_mouse mode);
mode_focus_follows_mouse focus_follows_mouse_mode();
status_t get_mouse(BPoint* screenWhere, uint32* buttons);
void set_accept_first_click(bool acceptFirstClick);
bool accept_first_click();

View File

@ -81,6 +81,8 @@ enum {
AS_BEGIN_RECT_TRACKING,
AS_END_RECT_TRACKING,
AS_GET_CURSOR_POSITION,
// Window definitions
AS_SHOW_WINDOW,

View File

@ -7,6 +7,7 @@
* Caz <turok2@currantbun.com>
* Axel Dörfler, axeld@pinc-software.de
* Michael Lotz <mmlr@mlotz.ch>
* Wim van der Meer <WPJvanderMeer@gmail.com>
*/
@ -23,9 +24,10 @@
#include <ControlLook.h>
#include <Font.h>
#include <Menu.h>
#include <Point.h>
#include <Roster.h>
#include <ScrollBar.h>
#include <Screen.h>
#include <ScrollBar.h>
#include <String.h>
#include <TextView.h>
@ -925,6 +927,42 @@ focus_follows_mouse_mode()
}
status_t
get_mouse(BPoint* screenWhere, uint32* buttons)
{
if (screenWhere == NULL && buttons == NULL)
return B_BAD_VALUE;
BPrivate::AppServerLink link;
link.StartMessage(AS_GET_CURSOR_POSITION);
int32 code;
status_t ret = link.FlushWithReply(code);
if (ret != B_OK)
return ret;
if (code != B_OK)
return code;
if (screenWhere != NULL)
ret = link.Read<BPoint>(screenWhere);
else {
BPoint dummy;
ret = link.Read<BPoint>(&dummy);
}
if (ret != B_OK)
return ret;
if (buttons != NULL)
ret = link.Read<uint32>(buttons);
else {
uint32 dummy;
ret = link.Read<uint32>(&dummy);
}
return ret;
}
void
set_accept_first_click(bool acceptFirstClick)
{

View File

@ -61,6 +61,8 @@ string_for_message_code(uint32 code, BString& string)
CODE(AS_BEGIN_RECT_TRACKING);
CODE(AS_END_RECT_TRACKING);
CODE(AS_GET_CURSOR_POSITION);
// Window definitions
CODE(AS_SHOW_WINDOW);

View File

@ -11,6 +11,7 @@
* Jérôme Duval, jerome.duval@free.fr
* Andrej Spielmann, <andrej.spielmann@seh.ox.ac.uk>
* Philippe Saint-Pierre, stpere@gmail.com
* Wim van der Meer, <WPJvanderMeer@gmail.com>
*/
@ -1165,7 +1166,21 @@ ServerApp::_DispatchMessage(int32 code, BPrivate::LinkReceiver& link)
break;
}
case AS_GET_CURSOR_POSITION:
{
STRACE(("ServerApp %s: Get Cursor position\n", Signature()));
// Returns
// 1) BPoint mouse location
// 2) int32 button state
BPoint where;
int32 buttons;
fDesktop->GetLastMouseState(&where, &buttons);
fLink.StartMessage(B_OK);
fLink.Attach<BPoint>(where);
fLink.Attach<int32>(buttons);
fLink.Flush();
break;
}
case AS_GET_SCROLLBAR_INFO:
{
STRACE(("ServerApp %s: Get ScrollBar info\n", Signature()));