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
+97 -232
View File
@@ -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;
@@ -172,79 +153,53 @@ void WinBorder::MouseDown(int8 *buffer)
// 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)
{ {
// Buffer data: // Buffer data:
@@ -258,136 +213,42 @@ void WinBorder::MouseMoved(int8 *buffer)
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); STRACE_CLICK(("WinBorder: Drag\n"));
_decorator->Draw(); BPoint difference;
difference = pt - fLastMousePosition;
MoveBy( difference.x, difference.y );
break;
} }
case DEC_RESIZE:
if(click!=CLICK_ZOOM && _decorator->GetZoom())
{ {
_decorator->SetZoom(false); STRACE_CLICK(("WinBorder: Resize\n"));
_decorator->Draw(); BPoint difference;
difference = pt - fLastMousePosition;
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);
if(click!=CLICK_MINIMIZE && _decorator->GetMinimize()) _win->SendMessageToClient( &msg );
{
_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
// 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();
} }
} }
// this is important to determine how much we should resize or move the Layer(WinBorder)(window)
fLastMousePosition = pt;
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
_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.
// The original location
BRegion reg;
_decorator->GetFootprint(&reg);
// 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();
}
}
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)
@@ -402,52 +263,54 @@ STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
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); BPoint pt(x,y);
// TODO: modify this!!! _decorator->MouseUp(...);
click_type action =_decorator->Clicked(pt, _mbuttons, _kmodifiers);
_mbuttons=0; switch (action){
_kmodifiers=modifiers; case DEC_CLOSE:
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: STRACE_CLICK(("WinBorder: Close\n"));
{ /* NOTE: I think you better put this code in... ServerWindow::Close()
_decorator->SetClose(false); * and call that here!!!
_decorator->DrawClose(); * SW::Close() must send B_QUIT_REQUESTED and wait for an answer first.
*/
// call close window stuff here
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;
+8 -1
View File
@@ -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);