changed code for mouse input funtions.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5364 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -69,28 +69,9 @@
|
|||||||
# define STRACE_CLICK(x) ;
|
# define STRACE_CLICK(x) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace winborder_private
|
|
||||||
{
|
|
||||||
bool is_moving_window = false;
|
|
||||||
bool is_resizing_window = false;
|
|
||||||
bool is_sliding_tab = false;
|
|
||||||
WinBorder *active_winborder = NULL;
|
|
||||||
};
|
|
||||||
|
|
||||||
//! TokenHandler object used to provide IDs for all WinBorder objects
|
//! TokenHandler object used to provide IDs for all WinBorder objects
|
||||||
TokenHandler border_token_handler;
|
TokenHandler border_token_handler;
|
||||||
|
|
||||||
extern ServerWindow *active_serverwindow;
|
|
||||||
|
|
||||||
bool is_moving_window(void) { return winborder_private::is_moving_window; }
|
|
||||||
void set_is_moving_window(bool state) { winborder_private::is_moving_window=state; }
|
|
||||||
bool is_resizing_window(void) { return winborder_private::is_resizing_window; }
|
|
||||||
void set_is_resizing_window(bool state) { winborder_private::is_resizing_window=state; }
|
|
||||||
bool is_sliding_tab(void) { return winborder_private::is_sliding_tab; }
|
|
||||||
void set_is_sliding_tab(bool state) { winborder_private::is_sliding_tab=state; }
|
|
||||||
void set_active_winborder(WinBorder *win) { winborder_private::active_winborder=win; }
|
|
||||||
WinBorder* get_active_winborder(void) { return winborder_private::active_winborder; }
|
|
||||||
|
|
||||||
WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const int32 feel,
|
WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const int32 feel,
|
||||||
const int32 flags, ServerWindow *win)
|
const int32 flags, ServerWindow *win)
|
||||||
: Layer(r, name, B_NULL_TOKEN, B_FOLLOW_NONE, flags, win)
|
: Layer(r, name, B_NULL_TOKEN, B_FOLLOW_NONE, flags, win)
|
||||||
@@ -105,7 +86,7 @@ WinBorder::WinBorder(const BRect &r, const char *name, const int32 look, const i
|
|||||||
_update = false;
|
_update = false;
|
||||||
_hresizewin = false;
|
_hresizewin = false;
|
||||||
_vresizewin = false;
|
_vresizewin = false;
|
||||||
_mousepos.Set(0,0);
|
fLastMousePosition.Set(-1,-1);
|
||||||
|
|
||||||
_decorator = NULL;
|
_decorator = NULL;
|
||||||
|
|
||||||
@@ -167,82 +148,56 @@ void WinBorder::MouseDown(int8 *buffer)
|
|||||||
int32 modifiers = *((int32*)index); index+=sizeof(int32);
|
int32 modifiers = *((int32*)index); index+=sizeof(int32);
|
||||||
int32 buttons = *((int32*)index);
|
int32 buttons = *((int32*)index);
|
||||||
|
|
||||||
BPoint pt(x,y);
|
BPoint pt(x,y);
|
||||||
|
|
||||||
// user clicked on decorator
|
// user clicked on decorator
|
||||||
if (fDecFullVisible->Contains(pt)){
|
if (fDecFullVisible->Contains(pt)){
|
||||||
click_type click;
|
click_type click;
|
||||||
|
// TODO: modify this!!! _decorator->MouseDown(...);
|
||||||
click = _decorator->Clicked(pt, buttons, modifiers);
|
click = _decorator->Clicked(pt, buttons, modifiers);
|
||||||
|
|
||||||
switch(click){
|
switch(click){
|
||||||
case CLICK_MOVETOBACK:
|
case DEC_MOVETOBACK:
|
||||||
{
|
{
|
||||||
STRACE_CLICK(("Click: MoveToBack\n"));
|
STRACE_CLICK(("WinBorder: MoveToBack\n"));
|
||||||
MoveToBack();
|
MoveToBack();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLICK_MOVETOFRONT:
|
default:{
|
||||||
{
|
STRACE_CLICK(("WinBorder: MoveToFront\n"));
|
||||||
STRACE_CLICK(("Click: MoveToFront\n"));
|
|
||||||
MoveToFront();
|
MoveToFront();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLICK_CLOSE:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Close\n"));
|
|
||||||
RemoveSelf();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_ZOOM:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Zoom\n"));
|
|
||||||
// TODO: implement
|
|
||||||
// if (actual_coods != max_zoom_coords)
|
|
||||||
// MoveBy(X, Y);
|
|
||||||
// ResizeBy(X, Y);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_MINIMIZE:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Minimize\n"));
|
|
||||||
if ( !IsHidden() ){
|
|
||||||
Hide();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_DRAG:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Drag\n"));
|
|
||||||
set_is_moving_window(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_SLIDETAB:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Slide Tab\n"));
|
|
||||||
set_is_sliding_tab(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_RESIZE:
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("Click: Resize\n"));
|
|
||||||
set_is_resizing_window(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case CLICK_NONE:
|
|
||||||
default:
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// user clicked in window's area
|
// user clicked in window's area
|
||||||
else{
|
else{
|
||||||
/*
|
STRACE_CLICK(("WinBorder: MoveToFront 2\n"));
|
||||||
TODO: implement!!!
|
bool sendMessage = true;
|
||||||
NOTE: send that message to BViews registered for receiving mouse&keyboard events.
|
|
||||||
SendMouseMessage( B_MOUSE_DOWN );
|
if (1 /* TODO: uncomment: ActiveLayer() != this*/){
|
||||||
*/
|
MoveToFront();
|
||||||
|
if (0 /* B_FIRST_CLICK? what's the name of that flaaaag ??? */){
|
||||||
|
sendMessage = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sendMessage){
|
||||||
|
BMessage msg;
|
||||||
|
// a tweak for converting a point into local coords. :-)
|
||||||
|
BRect helpRect(pt.x, pt.y, pt.x+1, pt.y+1);
|
||||||
|
msg.what = B_MOUSE_DOWN;
|
||||||
|
msg.AddInt64("when", real_time_clock_usecs());
|
||||||
|
msg.AddPoint("where", (_win->top_layer->GetLayerAt(pt)->ConvertFromTop(helpRect)).LeftTop() );
|
||||||
|
msg.AddInt32("modifiers", modifiers);
|
||||||
|
msg.AddInt32("buttons", buttons);
|
||||||
|
msg.AddInt32("clicks", 1);
|
||||||
|
|
||||||
|
_win->SendMessageToClient( &msg );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// this is important to determine how much we should resize or move the Layer(WinBorder)(window)
|
||||||
|
fLastMousePosition = pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinBorder::MouseMoved(int8 *buffer)
|
void WinBorder::MouseMoved(int8 *buffer)
|
||||||
@@ -252,142 +207,48 @@ void WinBorder::MouseMoved(int8 *buffer)
|
|||||||
// 2) float - x coordinate of mouse click
|
// 2) float - x coordinate of mouse click
|
||||||
// 3) float - y coordinate of mouse click
|
// 3) float - y coordinate of mouse click
|
||||||
// 4) int32 - buttons down
|
// 4) int32 - buttons down
|
||||||
int8 *index=buffer; index+=sizeof(int64);
|
int8 *index = buffer; index+=sizeof(int64);
|
||||||
float x=*((float*)index); index+=sizeof(float);
|
float x = *((float*)index); index+=sizeof(float);
|
||||||
float y=*((float*)index); index+=sizeof(float);
|
float y = *((float*)index); index+=sizeof(float);
|
||||||
int32 buttons=*((int32*)index);
|
int32 buttons = *((int32*)index);
|
||||||
|
|
||||||
BPoint pt(x,y);
|
BPoint pt(x,y);
|
||||||
click_type click=_decorator->Clicked(pt, _mbuttons, _kmodifiers);
|
// TODO: modify this!!! _decorator->MouseMoved(...);
|
||||||
|
click_type action = _decorator->Clicked(pt, _mbuttons, _kmodifiers);
|
||||||
|
|
||||||
if(click!=CLICK_CLOSE && _decorator->GetClose())
|
switch (action){
|
||||||
{
|
case DEC_DRAG:
|
||||||
_decorator->SetClose(false);
|
|
||||||
_decorator->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(click!=CLICK_ZOOM && _decorator->GetZoom())
|
|
||||||
{
|
|
||||||
_decorator->SetZoom(false);
|
|
||||||
_decorator->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(click!=CLICK_MINIMIZE && _decorator->GetMinimize())
|
|
||||||
{
|
|
||||||
_decorator->SetMinimize(false);
|
|
||||||
_decorator->Draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(is_sliding_tab())
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("ClickMove: Slide Tab\n"));
|
|
||||||
float dx=pt.x-_mousepos.x;
|
|
||||||
float dy=pt.y-_mousepos.y;
|
|
||||||
|
|
||||||
if(dx != 0 || dy != 0)
|
|
||||||
{
|
{
|
||||||
// SlideTab returns how much things were moved, and currently
|
STRACE_CLICK(("WinBorder: Drag\n"));
|
||||||
// supports just the x direction, so get the value so
|
BPoint difference;
|
||||||
// we can invalidate the proper area.
|
difference = pt - fLastMousePosition;
|
||||||
lock_layers();
|
|
||||||
_parent->Invalidate(_decorator->SlideTab(dx,dy));
|
MoveBy( difference.x, difference.y );
|
||||||
// _parent->RequestDraw();
|
break;
|
||||||
// _decorator->DrawTab();
|
|
||||||
unlock_layers();
|
|
||||||
}
|
}
|
||||||
}
|
case DEC_RESIZE:
|
||||||
|
|
||||||
|
|
||||||
if(is_moving_window())
|
|
||||||
{
|
|
||||||
// We are moving the window. Because speed is of the essence, we need to handle a lot
|
|
||||||
// of stuff which we might otherwise not need to.
|
|
||||||
|
|
||||||
STRACE_CLICK(("ClickMove: Drag\n"));
|
|
||||||
float dx = pt.x - _mousepos.x,
|
|
||||||
dy = pt.y - _mousepos.y;
|
|
||||||
if(buttons!=0 && (dx!=0 || dy!=0))
|
|
||||||
{
|
{
|
||||||
// 2) Offset necessary data members
|
STRACE_CLICK(("WinBorder: Resize\n"));
|
||||||
_clientframe.OffsetBy(dx,dy);
|
BPoint difference;
|
||||||
|
difference = pt - fLastMousePosition;
|
||||||
_win->Lock();
|
|
||||||
_win->_frame.OffsetBy(dx,dy);
|
|
||||||
_win->Unlock();
|
|
||||||
|
|
||||||
lock_layers();
|
|
||||||
|
|
||||||
// Move the window decorator's footprint and remove the area occupied
|
|
||||||
// by the new location so we know what areas to invalidate.
|
|
||||||
|
|
||||||
// The original location
|
ResizeBy( difference.x, difference.y );
|
||||||
BRegion reg;
|
break;
|
||||||
_decorator->GetFootprint(®);
|
}
|
||||||
|
default:{
|
||||||
|
BMessage msg;
|
||||||
|
// a tweak for converting a point into local coords. :-)
|
||||||
|
BRect helpRect(pt.x, pt.y, pt.x+1, pt.y+1);
|
||||||
|
msg.what = B_MOUSE_MOVED;
|
||||||
|
msg.AddInt64("when", real_time_clock_usecs());
|
||||||
|
msg.AddPoint("where", (_win->top_layer->ConvertFromTop(helpRect)).LeftTop() );
|
||||||
|
msg.AddInt32("buttons", buttons);
|
||||||
|
|
||||||
// The new location
|
_win->SendMessageToClient( &msg );
|
||||||
BRegion reg2(reg);
|
|
||||||
reg2.OffsetBy((int32)dx, (int32)dy);
|
|
||||||
|
|
||||||
MoveBy(dx,dy);
|
|
||||||
_decorator->MoveBy(BPoint(dx, dy));
|
|
||||||
|
|
||||||
// 3) quickly move the window
|
|
||||||
// _driver->CopyRegion(®,reg2.Frame().LeftTop());
|
|
||||||
|
|
||||||
// 4) Invalidate only the areas which we can't redraw directly
|
|
||||||
for(int32 i=0; i<reg2.CountRects();i++)
|
|
||||||
reg.Exclude(reg2.RectAt(i));
|
|
||||||
|
|
||||||
// TODO: DW's notes to self
|
|
||||||
// As of right now, dragging the window is extremely slow despite the use
|
|
||||||
// of CopyRegion. The reason is because of the redraw taken. When Invalidate() is
|
|
||||||
// called the RootLayer invalidates things properly for itself, but the area which
|
|
||||||
// should be invalidated for the first of the two windows in my test case is not
|
|
||||||
// made dirty, so the entire first window is redrawn with RequestDraw being
|
|
||||||
// restructured as it is. Additionally, the second window is redrawn for the same reason
|
|
||||||
// when in fact it shouldn't be redrawn at all.
|
|
||||||
|
|
||||||
// Solution:
|
|
||||||
// Figure out what the exact usage of Layer::Invalidate() should be (parent coordinates,
|
|
||||||
// layer's coordinates, etc) and set things right. Secondly, nuke the invalid region
|
|
||||||
// in this call so that when RequestDraw is called, this WinBorder doesn't redraw itself
|
|
||||||
|
|
||||||
_parent->Invalidate(reg);
|
|
||||||
|
|
||||||
// _parent->RebuildRegions();
|
|
||||||
// _parent->RequestDraw();
|
|
||||||
|
|
||||||
unlock_layers();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// this is important to determine how much we should resize or move the Layer(WinBorder)(window)
|
||||||
|
fLastMousePosition = pt;
|
||||||
if(is_resizing_window())
|
|
||||||
{
|
|
||||||
STRACE_CLICK(("ClickMove: Resize\n"));
|
|
||||||
float dx = pt.x - _mousepos.x,
|
|
||||||
dy = pt.y - _mousepos.y;
|
|
||||||
if(buttons!=0 && (dx!=0 || dy!=0))
|
|
||||||
{
|
|
||||||
_clientframe.right+=dx;
|
|
||||||
_clientframe.bottom+=dy;
|
|
||||||
|
|
||||||
_win->Lock();
|
|
||||||
_win->_frame.right+=dx;
|
|
||||||
_win->_frame.bottom+=dy;
|
|
||||||
_win->Unlock();
|
|
||||||
|
|
||||||
lock_layers();
|
|
||||||
ResizeBy(dx,dy);
|
|
||||||
// _parent->RequestDraw();
|
|
||||||
unlock_layers();
|
|
||||||
_decorator->ResizeBy(dx,dy);
|
|
||||||
// _decorator->Draw();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_mousepos=pt;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WinBorder::MouseUp(int8 *buffer)
|
void WinBorder::MouseUp(int8 *buffer)
|
||||||
@@ -398,56 +259,58 @@ STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
|
|||||||
// 2) float - x coordinate of mouse click
|
// 2) float - x coordinate of mouse click
|
||||||
// 3) float - y coordinate of mouse click
|
// 3) float - y coordinate of mouse click
|
||||||
// 4) int32 - modifier keys down
|
// 4) int32 - modifier keys down
|
||||||
int8 *index=buffer; index+=sizeof(int64);
|
int8 *index = buffer; index+=sizeof(int64);
|
||||||
float x=*((float*)index); index+=sizeof(float);
|
float x = *((float*)index); index+=sizeof(float);
|
||||||
float y=*((float*)index); index+=sizeof(float);
|
float y = *((float*)index); index+=sizeof(float);
|
||||||
int32 modifiers=*((int32*)index);
|
int32 modifiers = *((int32*)index);
|
||||||
BPoint pt(x,y);
|
|
||||||
|
|
||||||
_mbuttons=0;
|
BPoint pt(x,y);
|
||||||
_kmodifiers=modifiers;
|
// TODO: modify this!!! _decorator->MouseUp(...);
|
||||||
|
click_type action =_decorator->Clicked(pt, _mbuttons, _kmodifiers);
|
||||||
|
|
||||||
set_is_moving_window(false);
|
switch (action){
|
||||||
set_is_resizing_window(false);
|
case DEC_CLOSE:
|
||||||
set_is_sliding_tab(false);
|
|
||||||
|
|
||||||
click_type click=_decorator->Clicked(pt, _mbuttons, _kmodifiers);
|
|
||||||
|
|
||||||
switch(click)
|
|
||||||
{
|
|
||||||
case CLICK_CLOSE:
|
|
||||||
{
|
{
|
||||||
_decorator->SetClose(false);
|
STRACE_CLICK(("WinBorder: Close\n"));
|
||||||
_decorator->DrawClose();
|
/* NOTE: I think you better put this code in... ServerWindow::Close()
|
||||||
|
* and call that here!!!
|
||||||
// call close window stuff here
|
* SW::Close() must send B_QUIT_REQUESTED and wait for an answer first.
|
||||||
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_CLOSE unimplemented\n",_title->String()));
|
*/
|
||||||
|
|
||||||
|
RemoveSelf();
|
||||||
|
delete this;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLICK_ZOOM:
|
case DEC_ZOOM:
|
||||||
{
|
{
|
||||||
_decorator->SetZoom(false);
|
STRACE_CLICK(("WinBorder: Zoom\n"));
|
||||||
_decorator->DrawZoom();
|
/* NOTE: I think you better put this code in... ServerWindow::Zoom()
|
||||||
|
* and call that here!!!
|
||||||
// call zoom stuff here
|
*/
|
||||||
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_ZOOM unimplemented\n",_title->String()));
|
// TODO: implement
|
||||||
|
// if (actual_coods != max_zoom_coords)
|
||||||
|
// MoveBy(X, Y);
|
||||||
|
// ResizeBy(X, Y);
|
||||||
|
// TODO: send B_ZOOM to client;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CLICK_MINIMIZE:
|
case DEC_MINIMIZE:
|
||||||
{
|
|
||||||
_decorator->SetMinimize(false);
|
|
||||||
_decorator->DrawMinimize();
|
|
||||||
|
|
||||||
// call minimize stuff here
|
|
||||||
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_MINIMIZE unimplemented\n",_title->String()));
|
|
||||||
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
{
|
{
|
||||||
|
STRACE_CLICK(("WinBoder: Minimize\n"));
|
||||||
|
_win->Minimize(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:{
|
||||||
|
BMessage msg;
|
||||||
|
// a tweak for converting a point into local coords. :-)
|
||||||
|
BRect helpRect(pt.x, pt.y, pt.x+1, pt.y+1);
|
||||||
|
msg.what = B_MOUSE_UP;
|
||||||
|
msg.AddInt64("when", real_time_clock_usecs());
|
||||||
|
msg.AddPoint("where", (_win->top_layer->GetLayerAt(pt)->ConvertFromTop(helpRect)).LeftTop() );
|
||||||
|
msg.AddInt32("modifiers", modifiers);
|
||||||
|
|
||||||
|
_win->SendMessageToClient( &msg );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -695,6 +558,7 @@ void WinBorder::ResizeBy(float x, float y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WinBorder::MoveToBack(){
|
void WinBorder::MoveToBack(){
|
||||||
|
// TODO: take care of focus.
|
||||||
if (this == _parent->_topchild)
|
if (this == _parent->_topchild)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -726,6 +590,7 @@ void WinBorder::MoveToBack(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void WinBorder::MoveToFront(){
|
void WinBorder::MoveToFront(){
|
||||||
|
// TODO: take care of focus.
|
||||||
if (this == _parent->_bottomchild)
|
if (this == _parent->_bottomchild)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|||||||
@@ -72,13 +72,20 @@ protected:
|
|||||||
BRect _clientframe;
|
BRect _clientframe;
|
||||||
int32 _mbuttons,
|
int32 _mbuttons,
|
||||||
_kmodifiers;
|
_kmodifiers;
|
||||||
BPoint _mousepos;
|
BPoint fLastMousePosition;
|
||||||
bool _update;
|
bool _update;
|
||||||
bool _hresizewin,_vresizewin;
|
bool _hresizewin,_vresizewin;
|
||||||
|
|
||||||
BRegion *fDecFull,
|
BRegion *fDecFull,
|
||||||
*fDecFullVisible,
|
*fDecFullVisible,
|
||||||
*fDecVisible;
|
*fDecVisible;
|
||||||
|
|
||||||
|
/* bool fIsMoving;
|
||||||
|
bool fIsResizing;
|
||||||
|
bool fIsClosing;
|
||||||
|
bool fIsMinimizing;
|
||||||
|
bool fIsZooming
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
bool is_moving_window(void);
|
bool is_moving_window(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user