debug code looks nicer...

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4581 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Adi Oanca
2003-09-08 22:09:10 +00:00
parent 3ecfa8e102
commit 32a9b6b6e2
+84 -124
View File
@@ -36,6 +36,7 @@
#include "Desktop.h" #include "Desktop.h"
#include "WinBorder.h" #include "WinBorder.h"
#include "AppServer.h" // for new_decorator() #include "AppServer.h" // for new_decorator()
#include "TokenHandler.h"
// TODO: Document this file completely // TODO: Document this file completely
@@ -47,82 +48,93 @@
//#define DEBUG_WINBORDER_CLICK //#define DEBUG_WINBORDER_CLICK
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
#include <stdio.h> # include <stdio.h>
# define STRACE(x) printf x
#else
# define STRACE(x) ;
#endif #endif
#ifdef DEBUG_WINBORDER_MOUSE #ifdef DEBUG_WINBORDER_MOUSE
#include <stdio.h> # include <stdio.h>
# define STRACE_MOUSE(x) printf x
#else
# define STRACE_MOUSE(x) ;
#endif #endif
#ifdef DEBUG_WINBORDER_CLICK #ifdef DEBUG_WINBORDER_CLICK
#include <stdio.h> # include <stdio.h>
# define STRACE_CLICK(x) printf x
#else
# define STRACE_CLICK(x) ;
#endif #endif
namespace winborder_private namespace winborder_private
{ {
bool is_moving_window=false; bool is_moving_window = false;
bool is_resizing_window=false; bool is_resizing_window = false;
bool is_sliding_tab=false; bool is_sliding_tab = false;
WinBorder *active_winborder=NULL; WinBorder *active_winborder = NULL;
}; };
extern ServerWindow *active_serverwindow; //! TokenHandler object used to provide IDs for all WinBorder objects
TokenHandler border_token_handler;
bool is_moving_window(void) { return winborder_private::is_moving_window; } extern ServerWindow *active_serverwindow;
void set_is_moving_window(bool state) { winborder_private::is_moving_window=state; }
bool is_resizing_window(void) { return winborder_private::is_resizing_window; } bool is_moving_window(void) { return winborder_private::is_moving_window; }
void set_is_resizing_window(bool state) { winborder_private::is_resizing_window=state; } void set_is_moving_window(bool state) { winborder_private::is_moving_window=state; }
bool is_sliding_tab(void) { return winborder_private::is_sliding_tab; } bool is_resizing_window(void) { return winborder_private::is_resizing_window; }
void set_is_sliding_tab(bool state) { winborder_private::is_sliding_tab=state; } void set_is_resizing_window(bool state) { winborder_private::is_resizing_window=state; }
WinBorder * get_active_winborder(void) { return winborder_private::active_winborder; } bool is_sliding_tab(void) { return winborder_private::is_sliding_tab; }
void set_active_winborder(WinBorder *win) { winborder_private::active_winborder=win; } 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_FOLLOW_NONE,flags,win) : Layer(r, name, B_NULL_TOKEN, B_FOLLOW_NONE, flags, win)
{ {
// unlike BViews, windows start off as hidden, so we need to tweak the hidecount // unlike BViews, windows start off as hidden, so we need to tweak the hidecount
// assignment made by Layer(). // assignment made by Layer().
_hidecount=1; _hidden = true;
_mbuttons=0; _mbuttons = 0;
_kmodifiers=0; _kmodifiers = 0;
_win=win; _win = win;
if(_win)
_frame=_win->_frame;
_clientframe=_frame;
_mousepos.Set(0,0);
_update=false;
_title=new BString(name); _mousepos.Set(0,0);
_hresizewin=false; _update = false;
_vresizewin=false;
_driver=GetGfxDriver(ActiveScreen()); _title = new BString(name);
_decorator=new_decorator(r,name,look,feel,flags,GetGfxDriver(ActiveScreen())); _hresizewin = false;
_vresizewin = false;
_driver = GetGfxDriver(ActiveScreen());
_decorator = new_decorator(r,name,look,feel,flags,GetGfxDriver(ActiveScreen()));
// We need to do this because GetFootprint is supposed to generate a new BRegion. // We need to do this because GetFootprint is supposed to generate a new BRegion.
// I suppose the call probably ought to be void GetFootprint(BRegion *recipient), but we can // I suppose the call probably ought to be void GetFootprint(BRegion *recipient), but we can
// change that later. // change that later.
delete _visible; // it was initialized in Layer's constructor.
_visible = _decorator->GetFootprint();
*_full = *_visible;
*_invalid = *_visible;
_frame = _visible->Frame();
if(_visible) // I tend to think it is not needed, so if it isn't, DW, please remove it.
delete _visible; _view_token = border_token_handler.GetToken();
_visible=_decorator->GetFootprint();
*_full=*_visible;
_decorator->SetDriver(_driver); _decorator->SetDriver(_driver);
_decorator->SetTitle(name); _decorator->SetTitle(name);
#ifdef DEBUG_WINBORDER
printf("WinBorder %s:\n",_title->String()); STRACE(("WinBorder %s:\n",_title->String()));
printf("\tFrame: (%.1f,%.1f,%.1f,%.1f)\n",r.left,r.top,r.right,r.bottom); STRACE(("\tFrame: (%.1f,%.1f,%.1f,%.1f)\n",r.left,r.top,r.right,r.bottom));
printf("\tWindow %s\n",win?win->Title():"NULL"); STRACE(("\tWindow %s\n",win?win->Title():"NULL"));
#endif
} }
WinBorder::~WinBorder(void) WinBorder::~WinBorder(void)
{ {
#ifdef DEBUG_WINBORDER STRACE(("WinBorder %s:~WinBorder()\n",_title->String()));
printf("WinBorder %s:~WinBorder()\n",_title->String());
#endif
delete _title; delete _title;
} }
@@ -152,48 +164,33 @@ void WinBorder::MouseDown(int8 *buffer)
{ {
case CLICK_MOVETOBACK: case CLICK_MOVETOBACK:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: MoveToBack\n"));
printf("Click: MoveToBack\n");
#endif
MakeTopChild(); MakeTopChild();
break; break;
} }
case CLICK_MOVETOFRONT: case CLICK_MOVETOFRONT:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: MoveToFront\n"));
printf("Click: MoveToFront\n");
#endif
MakeBottomChild(); MakeBottomChild();
break; break;
} }
case CLICK_CLOSE: case CLICK_CLOSE:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Close\n"));
printf("Click: Close\n");
#endif
_decorator->SetClose(true); _decorator->SetClose(true);
_decorator->DrawClose(); _decorator->DrawClose();
break; break;
} }
case CLICK_ZOOM: case CLICK_ZOOM:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Zoom\n"));
printf("Click: Zoom\n");
#endif
_decorator->SetZoom(true); _decorator->SetZoom(true);
_decorator->DrawZoom(); _decorator->DrawZoom();
break; break;
} }
case CLICK_MINIMIZE: case CLICK_MINIMIZE:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Minimize\n"));
printf("Click: Minimize\n");
#endif
_decorator->SetMinimize(true); _decorator->SetMinimize(true);
_decorator->DrawMinimize(); _decorator->DrawMinimize();
break; break;
@@ -202,30 +199,21 @@ void WinBorder::MouseDown(int8 *buffer)
{ {
if(buttons==B_PRIMARY_MOUSE_BUTTON) if(buttons==B_PRIMARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Drag\n"));
printf("Click: Drag\n");
#endif
MakeBottomChild(); MakeBottomChild();
set_is_moving_window(true); set_is_moving_window(true);
} }
if(buttons==B_SECONDARY_MOUSE_BUTTON) if(buttons==B_SECONDARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: MoveToBack\n"));
printf("Click: MoveToBack\n");
#endif
MakeTopChild(); MakeTopChild();
} }
break; break;
} }
case CLICK_SLIDETAB: case CLICK_SLIDETAB:
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Slide Tab\n"));
printf("Click: Slide Tab\n");
#endif
set_is_sliding_tab(true); set_is_sliding_tab(true);
break; break;
} }
@@ -233,10 +221,7 @@ void WinBorder::MouseDown(int8 *buffer)
{ {
if(buttons==B_PRIMARY_MOUSE_BUTTON) if(buttons==B_PRIMARY_MOUSE_BUTTON)
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("Click: Resize\n"));
printf("Click: Resize\n");
#endif
set_is_resizing_window(true); set_is_resizing_window(true);
} }
break; break;
@@ -287,10 +272,7 @@ void WinBorder::MouseMoved(int8 *buffer)
if(is_sliding_tab()) if(is_sliding_tab())
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("ClickMove: Slide Tab\n"));
printf("ClickMove: Slide Tab\n");
#endif
float dx=pt.x-_mousepos.x; float dx=pt.x-_mousepos.x;
float dy=pt.y-_mousepos.y; float dy=pt.y-_mousepos.y;
@@ -313,14 +295,9 @@ void WinBorder::MouseMoved(int8 *buffer)
// We are moving the window. Because speed is of the essence, we need to handle a lot // 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. // of stuff which we might otherwise not need to.
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("ClickMove: Drag\n"));
printf("ClickMove: Drag\n"); float dx = pt.x - _mousepos.x,
#endif dy = pt.y - _mousepos.y;
// 1) Get deltas
float dx=pt.x-_mousepos.x,
dy=pt.y-_mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0)) if(buttons!=0 && (dx!=0 || dy!=0))
{ {
// 2) Offset necessary data members // 2) Offset necessary data members
@@ -379,12 +356,9 @@ void WinBorder::MouseMoved(int8 *buffer)
if(is_resizing_window()) if(is_resizing_window())
{ {
#ifdef DEBUG_WINBORDER_CLICK STRACE_CLICK(("ClickMove: Resize\n"));
printf("ClickMove: Resize\n"); float dx = pt.x - _mousepos.x,
#endif dy = pt.y - _mousepos.y;
float dx=pt.x-_mousepos.x,
dy=pt.y-_mousepos.y;
if(buttons!=0 && (dx!=0 || dy!=0)) if(buttons!=0 && (dx!=0 || dy!=0))
{ {
_clientframe.right+=dx; _clientframe.right+=dx;
@@ -410,6 +384,7 @@ void WinBorder::MouseMoved(int8 *buffer)
void WinBorder::MouseUp(int8 *buffer) void WinBorder::MouseUp(int8 *buffer)
{ {
STRACE_MOUSE(("WinBorder %s: MouseUp() \n",_title->String()));
// buffer data: // buffer data:
// 1) int64 - time of mouse click // 1) int64 - time of mouse click
// 2) float - x coordinate of mouse click // 2) float - x coordinate of mouse click
@@ -421,7 +396,6 @@ void WinBorder::MouseUp(int8 *buffer)
int32 modifiers=*((int32*)index); int32 modifiers=*((int32*)index);
BPoint pt(x,y); BPoint pt(x,y);
_mbuttons=0; _mbuttons=0;
_kmodifiers=modifiers; _kmodifiers=modifiers;
@@ -439,9 +413,7 @@ void WinBorder::MouseUp(int8 *buffer)
_decorator->DrawClose(); _decorator->DrawClose();
// call close window stuff here // call close window stuff here
#ifdef DEBUG_WINBORDER_MOUSE STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_CLOSE unimplemented\n",_title->String()));
printf("WinBorder %s: MouseUp:CLICK_CLOSE unimplemented\n",_title->String());
#endif
break; break;
} }
@@ -451,9 +423,7 @@ void WinBorder::MouseUp(int8 *buffer)
_decorator->DrawZoom(); _decorator->DrawZoom();
// call zoom stuff here // call zoom stuff here
#ifdef DEBUG_WINBORDER_MOUSE STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_ZOOM unimplemented\n",_title->String()));
printf("WinBorder %s: MouseUp:CLICK_ZOOM unimplemented\n",_title->String());
#endif
break; break;
} }
@@ -463,9 +433,7 @@ void WinBorder::MouseUp(int8 *buffer)
_decorator->DrawMinimize(); _decorator->DrawMinimize();
// call minimize stuff here // call minimize stuff here
#ifdef DEBUG_WINBORDER_MOUSE STRACE_MOUSE(("WinBorder %s: MouseUp:CLICK_MINIMIZE unimplemented\n",_title->String()));
printf("WinBorder %s: MouseUp:CLICK_MINIMIZE unimplemented\n",_title->String());
#endif
} }
default: default:
@@ -487,9 +455,9 @@ void WinBorder::SetFocus(const bool &active)
void WinBorder::RequestDraw(const BRect &r) void WinBorder::RequestDraw(const BRect &r)
{ {
STRACE(("WinBorder %s: RequestDraw(BRect)\n",_title->String()));
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s: RequestDraw(BRect)\n",_title->String()); PrintToStream();
PrintToStream();
#endif #endif
_decorator->Draw(r); _decorator->Draw(r);
@@ -499,9 +467,9 @@ void WinBorder::RequestDraw(const BRect &r)
void WinBorder::RequestDraw(void) void WinBorder::RequestDraw(void)
{ {
STRACE(("WinBorder %s::RequestDraw()\n",_title->String()));
#ifdef DEBUG_WINBORDER #ifdef DEBUG_WINBORDER
printf("WinBorder %s::RequestDraw()\n",_title->String()); PrintToStream();
PrintToStream();
#endif #endif
if(_invalid) if(_invalid)
@@ -534,28 +502,20 @@ void WinBorder::ResizeBy(float x, float y)
*/ */
void WinBorder::UpdateColors(void) void WinBorder::UpdateColors(void)
{ {
#ifdef DEBUG_WINBORDER STRACE(("WinBorder %s: UpdateColors unimplemented\n",_title->String()));
printf("WinBorder %s: UpdateColors\n",_title->String());
#endif
} }
void WinBorder::UpdateDecorator(void) void WinBorder::UpdateDecorator(void)
{ {
#ifdef DEBUG_WINBORDER STRACE(("WinBorder %s: UpdateDecorator unimplemented\n",_title->String()));
printf("WinBorder %s: UpdateDecorator\n",_title->String());
#endif
} }
void WinBorder::UpdateFont(void) void WinBorder::UpdateFont(void)
{ {
#ifdef DEBUG_WINBORDER STRACE(("WinBorder %s: UpdateFont unimplemented\n",_title->String()));
printf("WinBorder %s: UpdateFont\n",_title->String());
#endif
} }
void WinBorder::UpdateScreen(void) void WinBorder::UpdateScreen(void)
{ {
#ifdef DEBUG_WINBORDER STRACE(("WinBorder %s: UpdateScreen unimplemented\n",_title->String()));
printf("WinBorder %s: UpdateScreen\n",_title->String());
#endif
} }