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:
Adi Oanca
2003-11-15 00:29:14 +00:00
parent 5580db514e
commit e9c5b47ef4
2 changed files with 115 additions and 243 deletions
+107 -242
View File
@@ -69,28 +69,9 @@
# define STRACE_CLICK(x) ;
#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 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,
const int32 flags, ServerWindow *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;
_hresizewin = false;
_vresizewin = false;
_mousepos.Set(0,0);
fLastMousePosition.Set(-1,-1);
_decorator = NULL;
@@ -167,82 +148,56 @@ void WinBorder::MouseDown(int8 *buffer)
int32 modifiers = *((int32*)index); index+=sizeof(int32);
int32 buttons = *((int32*)index);
BPoint pt(x,y);
BPoint pt(x,y);
// user clicked on decorator
if (fDecFullVisible->Contains(pt)){
click_type click;
// TODO: modify this!!! _decorator->MouseDown(...);
click = _decorator->Clicked(pt, buttons, modifiers);
switch(click){
case CLICK_MOVETOBACK:
case DEC_MOVETOBACK:
{
STRACE_CLICK(("Click: MoveToBack\n"));
STRACE_CLICK(("WinBorder: MoveToBack\n"));
MoveToBack();
break;
}
case CLICK_MOVETOFRONT:
{
STRACE_CLICK(("Click: MoveToFront\n"));
default:{
STRACE_CLICK(("WinBorder: MoveToFront\n"));
MoveToFront();
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
else{
/*
TODO: implement!!!
NOTE: send that message to BViews registered for receiving mouse&keyboard events.
SendMouseMessage( B_MOUSE_DOWN );
*/
STRACE_CLICK(("WinBorder: MoveToFront 2\n"));
bool sendMessage = true;
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)
@@ -252,142 +207,48 @@ void WinBorder::MouseMoved(int8 *buffer)
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - buttons down
int8 *index=buffer; index+=sizeof(int64);
float x=*((float*)index); index+=sizeof(float);
float y=*((float*)index); index+=sizeof(float);
int32 buttons=*((int32*)index);
int8 *index = buffer; index+=sizeof(int64);
float x = *((float*)index); index+=sizeof(float);
float y = *((float*)index); index+=sizeof(float);
int32 buttons = *((int32*)index);
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())
{
_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)
switch (action){
case DEC_DRAG:
{
// SlideTab returns how much things were moved, and currently
// supports just the x direction, so get the value so
// we can invalidate the proper area.
lock_layers();
_parent->Invalidate(_decorator->SlideTab(dx,dy));
// _parent->RequestDraw();
// _decorator->DrawTab();
unlock_layers();
STRACE_CLICK(("WinBorder: Drag\n"));
BPoint difference;
difference = pt - fLastMousePosition;
MoveBy( difference.x, difference.y );
break;
}
}
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))
case DEC_RESIZE:
{
// 2) Offset necessary data members
_clientframe.OffsetBy(dx,dy);
_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.
STRACE_CLICK(("WinBorder: Resize\n"));
BPoint difference;
difference = pt - fLastMousePosition;
// The original location
BRegion reg;
_decorator->GetFootprint(&reg);
ResizeBy( difference.x, difference.y );
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_MOVED;
msg.AddInt64("when", real_time_clock_usecs());
msg.AddPoint("where", (_win->top_layer->ConvertFromTop(helpRect)).LeftTop() );
msg.AddInt32("buttons", buttons);
// The new location
BRegion reg2(reg);
reg2.OffsetBy((int32)dx, (int32)dy);
MoveBy(dx,dy);
_decorator->MoveBy(BPoint(dx, dy));
// 3) quickly move the window
// _driver->CopyRegion(&reg,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();
_win->SendMessageToClient( &msg );
}
}
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;
// this is important to determine how much we should resize or move the Layer(WinBorder)(window)
fLastMousePosition = pt;
}
void WinBorder::MouseUp(int8 *buffer)
@@ -398,56 +259,58 @@ STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
// 2) float - x coordinate of mouse click
// 3) float - y coordinate of mouse click
// 4) int32 - modifier keys down
int8 *index=buffer; index+=sizeof(int64);
float x=*((float*)index); index+=sizeof(float);
float y=*((float*)index); index+=sizeof(float);
int32 modifiers=*((int32*)index);
BPoint pt(x,y);
int8 *index = buffer; index+=sizeof(int64);
float x = *((float*)index); index+=sizeof(float);
float y = *((float*)index); index+=sizeof(float);
int32 modifiers = *((int32*)index);
_mbuttons=0;
_kmodifiers=modifiers;
BPoint pt(x,y);
// TODO: modify this!!! _decorator->MouseUp(...);
click_type action =_decorator->Clicked(pt, _mbuttons, _kmodifiers);
set_is_moving_window(false);
set_is_resizing_window(false);
set_is_sliding_tab(false);
click_type click=_decorator->Clicked(pt, _mbuttons, _kmodifiers);
switch(click)
{
case CLICK_CLOSE:
switch (action){
case DEC_CLOSE:
{
_decorator->SetClose(false);
_decorator->DrawClose();
// call close window stuff here
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_CLOSE unimplemented\n",_title->String()));
STRACE_CLICK(("WinBorder: Close\n"));
/* NOTE: I think you better put this code in... ServerWindow::Close()
* and call that here!!!
* SW::Close() must send B_QUIT_REQUESTED and wait for an answer first.
*/
RemoveSelf();
delete this;
break;
}
case CLICK_ZOOM:
case DEC_ZOOM:
{
_decorator->SetZoom(false);
_decorator->DrawZoom();
// call zoom stuff here
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_ZOOM unimplemented\n",_title->String()));
STRACE_CLICK(("WinBorder: Zoom\n"));
/* NOTE: I think you better put this code in... ServerWindow::Zoom()
* and call that here!!!
*/
// TODO: implement
// if (actual_coods != max_zoom_coords)
// MoveBy(X, Y);
// ResizeBy(X, Y);
// TODO: send B_ZOOM to client;
break;
}
case CLICK_MINIMIZE:
{
_decorator->SetMinimize(false);
_decorator->DrawMinimize();
// call minimize stuff here
STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_MINIMIZE unimplemented\n",_title->String()));
}
default:
case DEC_MINIMIZE:
{
STRACE_CLICK(("WinBoder: Minimize\n"));
_win->Minimize(true);
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(){
// TODO: take care of focus.
if (this == _parent->_topchild)
return;
@@ -726,6 +590,7 @@ void WinBorder::MoveToBack(){
}
void WinBorder::MoveToFront(){
// TODO: take care of focus.
if (this == _parent->_bottomchild)
return;
+8 -1
View File
@@ -72,13 +72,20 @@ protected:
BRect _clientframe;
int32 _mbuttons,
_kmodifiers;
BPoint _mousepos;
BPoint fLastMousePosition;
bool _update;
bool _hresizewin,_vresizewin;
BRegion *fDecFull,
*fDecFullVisible,
*fDecVisible;
/* bool fIsMoving;
bool fIsResizing;
bool fIsClosing;
bool fIsMinimizing;
bool fIsZooming
*/
};
bool is_moving_window(void);