* Removed click_type enum. Introduced a private Action enum in

DefaultWindowBehavior instead. DefaultDecorator uses the more appropriate
  Decorator::Region.
* DefaultWindowBehavior::MouseTrackingState: Generalized the fActivateOnMouseUp
  handling. It is now named fWindowActionOnMouseUp and the virtual method
  MouseUpWindowAction() is called.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39614 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-11-24 18:34:40 +00:00
parent ce36f05450
commit 0fd5329656
5 changed files with 74 additions and 75 deletions
-22
View File
@@ -25,28 +25,6 @@ class ServerFont;
class BRegion; class BRegion;
enum click_type {
CLICK_NONE = 0,
CLICK_ZOOM,
CLICK_CLOSE,
CLICK_MINIMIZE,
CLICK_TAB,
CLICK_DRAG,
CLICK_MOVE_TO_BACK,
CLICK_SLIDE_TAB,
CLICK_RESIZE,
CLICK_RESIZE_L,
CLICK_RESIZE_T,
CLICK_RESIZE_R,
CLICK_RESIZE_B,
CLICK_RESIZE_LT,
CLICK_RESIZE_RT,
CLICK_RESIZE_LB,
CLICK_RESIZE_RB
};
class Decorator { class Decorator {
public: public:
enum Region { enum Region {
+11 -8
View File
@@ -673,8 +673,8 @@ DefaultDecorator::_DrawClose(BRect rect)
int32 index = (fButtonFocus ? 0 : 1) + (GetClose() ? 0 : 2); int32 index = (fButtonFocus ? 0 : 1) + (GetClose() ? 0 : 2);
ServerBitmap* bitmap = fCloseBitmaps[index]; ServerBitmap* bitmap = fCloseBitmaps[index];
if (bitmap == NULL) { if (bitmap == NULL) {
bitmap = _GetBitmapForButton(CLICK_CLOSE, GetClose(), fButtonFocus, bitmap = _GetBitmapForButton(REGION_CLOSE_BUTTON, GetClose(),
rect.IntegerWidth(), rect.IntegerHeight(), this); fButtonFocus, rect.IntegerWidth(), rect.IntegerHeight(), this);
fCloseBitmaps[index] = bitmap; fCloseBitmaps[index] = bitmap;
} }
@@ -726,8 +726,8 @@ DefaultDecorator::_DrawZoom(BRect rect)
int32 index = (fButtonFocus ? 0 : 1) + (GetZoom() ? 0 : 2); int32 index = (fButtonFocus ? 0 : 1) + (GetZoom() ? 0 : 2);
ServerBitmap* bitmap = fZoomBitmaps[index]; ServerBitmap* bitmap = fZoomBitmaps[index];
if (bitmap == NULL) { if (bitmap == NULL) {
bitmap = _GetBitmapForButton(CLICK_ZOOM, GetZoom(), fButtonFocus, bitmap = _GetBitmapForButton(REGION_ZOOM_BUTTON, GetZoom(),
rect.IntegerWidth(), rect.IntegerHeight(), this); fButtonFocus, rect.IntegerWidth(), rect.IntegerHeight(), this);
fZoomBitmaps[index] = bitmap; fZoomBitmaps[index] = bitmap;
} }
@@ -1247,7 +1247,7 @@ DefaultDecorator::_InvalidateBitmaps()
ServerBitmap* ServerBitmap*
DefaultDecorator::_GetBitmapForButton(int32 item, bool down, bool focus, DefaultDecorator::_GetBitmapForButton(Region item, bool down, bool focus,
int32 width, int32 height, DefaultDecorator* object) int32 width, int32 height, DefaultDecorator* object)
{ {
// TODO: the list of shared bitmaps is never freed // TODO: the list of shared bitmaps is never freed
@@ -1294,14 +1294,14 @@ DefaultDecorator::_GetBitmapForButton(int32 item, bool down, bool focus,
BRect rect(0, 0, width - 1, height - 1); BRect rect(0, 0, width - 1, height - 1);
STRACE(("DefaultDecorator creating bitmap for %s %sfocus %s at size %ldx%ld\n", STRACE(("DefaultDecorator creating bitmap for %s %sfocus %s at size %ldx%ld\n",
item == CLICK_CLOSE ? "close" : "zoom", focus ? "" : "non-", item == REGION_CLOSE_BUTTON ? "close" : "zoom", focus ? "" : "non-",
down ? "down" : "up", width, height)); down ? "down" : "up", width, height));
switch (item) { switch (item) {
case CLICK_CLOSE: case REGION_CLOSE_BUTTON:
object->_DrawBlendedRect(sBitmapDrawingEngine, rect, down, focus); object->_DrawBlendedRect(sBitmapDrawingEngine, rect, down, focus);
break; break;
case CLICK_ZOOM: case REGION_ZOOM_BUTTON:
{ {
// init the background // init the background
sBitmapDrawingEngine->FillRect(rect, B_TRANSPARENT_COLOR); sBitmapDrawingEngine->FillRect(rect, B_TRANSPARENT_COLOR);
@@ -1321,6 +1321,9 @@ DefaultDecorator::_GetBitmapForButton(int32 item, bool down, bool focus,
down, focus); down, focus);
break; break;
} }
default:
break;
} }
UtilityBitmap* bitmap = sBitmapDrawingEngine->ExportToBitmap(width, height, UtilityBitmap* bitmap = sBitmapDrawingEngine->ExportToBitmap(width, height,
+1 -1
View File
@@ -89,7 +89,7 @@ private:
BRect rect, bool down, bool focus); BRect rect, bool down, bool focus);
void _LayoutTabItems(const BRect& tabRect); void _LayoutTabItems(const BRect& tabRect);
void _InvalidateBitmaps(); void _InvalidateBitmaps();
static ServerBitmap* _GetBitmapForButton(int32 item, bool down, static ServerBitmap* _GetBitmapForButton(Region item, bool down,
bool focus, int32 width, int32 height, bool focus, int32 width, int32 height,
DefaultDecorator* object); DefaultDecorator* object);
+50 -44
View File
@@ -92,10 +92,10 @@ protected:
struct DefaultWindowBehaviour::MouseTrackingState : State { struct DefaultWindowBehaviour::MouseTrackingState : State {
MouseTrackingState(DefaultWindowBehaviour& behavior, BPoint where, MouseTrackingState(DefaultWindowBehaviour& behavior, BPoint where,
bool activateOnMouseUp, bool minimizeCheckOnMouseUp) bool windowActionOnMouseUp, bool minimizeCheckOnMouseUp)
: :
State(behavior), State(behavior),
fActivateOnMouseUp(activateOnMouseUp), fWindowActionOnMouseUp(windowActionOnMouseUp),
fMinimizeCheckOnMouseUp(minimizeCheckOnMouseUp), fMinimizeCheckOnMouseUp(minimizeCheckOnMouseUp),
fLastMousePosition(where), fLastMousePosition(where),
fMouseMoveDistance(0), fMouseMoveDistance(0),
@@ -122,14 +122,12 @@ struct DefaultWindowBehaviour::MouseTrackingState : State {
} }
} }
// In FFM mode, activate the window and bring it to front in case // Perform the window action in case the mouse was not moved.
// this was a drag click but the mouse was not moved. if (fWindowActionOnMouseUp) {
if (fActivateOnMouseUp) { // There is a time window for this feature, i.e. click and press
fActivateOnMouseUp = false; // too long, nothing will happen.
// on R5, there is a time window for this feature
// ie, click and press too long, nothing will happen
if (system_time() - fLastMoveTime < kWindowActivationTimeout) if (system_time() - fLastMoveTime < kWindowActivationTimeout)
fDesktop->ActivateWindow(fWindow); MouseUpWindowAction();
} }
fBehavior._NextState(NULL); fBehavior._NextState(NULL);
@@ -146,11 +144,11 @@ struct DefaultWindowBehaviour::MouseTrackingState : State {
// the then current mouse position // the then current mouse position
return; return;
} }
if (fActivateOnMouseUp || fMinimizeCheckOnMouseUp) { if (fWindowActionOnMouseUp || fMinimizeCheckOnMouseUp) {
if (now - fLastMoveTime >= kWindowActivationTimeout) { if (now - fLastMoveTime >= kWindowActivationTimeout) {
// This click is too long already for window activation/ // This click is too long already for window activation/
// minimizing. // minimizing.
fActivateOnMouseUp = false; fWindowActionOnMouseUp = false;
fMinimizeCheckOnMouseUp = false; fMinimizeCheckOnMouseUp = false;
fLastMoveTime = now; fLastMoveTime = now;
} }
@@ -168,10 +166,10 @@ struct DefaultWindowBehaviour::MouseTrackingState : State {
// If the window was moved enough, it doesn't come to // If the window was moved enough, it doesn't come to
// the front in FFM mode when the mouse is released. // the front in FFM mode when the mouse is released.
if (fActivateOnMouseUp || fMinimizeCheckOnMouseUp) { if (fWindowActionOnMouseUp || fMinimizeCheckOnMouseUp) {
fMouseMoveDistance += delta.x * delta.x + delta.y * delta.y; fMouseMoveDistance += delta.x * delta.x + delta.y * delta.y;
if (fMouseMoveDistance > 16.0f) { if (fMouseMoveDistance > 16.0f) {
fActivateOnMouseUp = false; fWindowActionOnMouseUp = false;
fMinimizeCheckOnMouseUp = false; fMinimizeCheckOnMouseUp = false;
} else } else
delta = B_ORIGIN; delta = B_ORIGIN;
@@ -187,10 +185,18 @@ struct DefaultWindowBehaviour::MouseTrackingState : State {
UpdateFFMFocus(isFake); UpdateFFMFocus(isFake);
} }
virtual void MouseMovedAction(BPoint& delta, bigtime_t now) = 0; virtual void MouseMovedAction(BPoint& delta, bigtime_t now)
{
}
virtual void MouseUpWindowAction()
{
// default is window activation
fDesktop->ActivateWindow(fWindow);
}
protected: protected:
bool fActivateOnMouseUp : 1; bool fWindowActionOnMouseUp : 1;
bool fMinimizeCheckOnMouseUp : 1; bool fMinimizeCheckOnMouseUp : 1;
BPoint fLastMousePosition; BPoint fLastMousePosition;
@@ -538,7 +544,7 @@ DefaultWindowBehaviour::MouseDown(BMessage* message, BPoint where)
Decorator* decorator = fWindow->Decorator(); Decorator* decorator = fWindow->Decorator();
Region hitRegion = REGION_NONE; Region hitRegion = REGION_NONE;
click_type action = CLICK_NONE; Action action = ACTION_NONE;
bool inBorderRegion = false; bool inBorderRegion = false;
if (decorator != NULL) if (decorator != NULL)
@@ -575,48 +581,48 @@ DefaultWindowBehaviour::MouseDown(BMessage* message, BPoint where)
// strange // strange
if (leftButton && (modifiers & B_SHIFT_KEY) != 0 if (leftButton && (modifiers & B_SHIFT_KEY) != 0
&& fWindow->Look() != kLeftTitledWindowLook) { && fWindow->Look() != kLeftTitledWindowLook) {
action = CLICK_SLIDE_TAB; action = ACTION_SLIDE_TAB;
break; break;
} }
// otherwise fall through -- same handling as for the border... // otherwise fall through -- same handling as for the border...
case REGION_BORDER: case REGION_BORDER:
if (leftButton) if (leftButton)
action = CLICK_DRAG; action = ACTION_DRAG;
else if (rightButton) else if (rightButton)
action = CLICK_MOVE_TO_BACK; action = ACTION_RESIZE_BORDER;
break; break;
case REGION_CLOSE_BUTTON: case REGION_CLOSE_BUTTON:
if (leftButton) { if (leftButton) {
action = (flags & B_NOT_CLOSABLE) == 0 action = (flags & B_NOT_CLOSABLE) == 0
? CLICK_CLOSE : CLICK_DRAG; ? ACTION_CLOSE : ACTION_DRAG;
} else if (rightButton) } else if (rightButton)
action = CLICK_MOVE_TO_BACK; action = ACTION_RESIZE_BORDER;
break; break;
case REGION_ZOOM_BUTTON: case REGION_ZOOM_BUTTON:
if (leftButton) { if (leftButton) {
action = (flags & B_NOT_ZOOMABLE) == 0 action = (flags & B_NOT_ZOOMABLE) == 0
? CLICK_ZOOM : CLICK_DRAG; ? ACTION_ZOOM : ACTION_DRAG;
} else if (rightButton) } else if (rightButton)
action = CLICK_MOVE_TO_BACK; action = ACTION_RESIZE_BORDER;
break; break;
case REGION_MINIMIZE_BUTTON: case REGION_MINIMIZE_BUTTON:
if (leftButton) { if (leftButton) {
action = (flags & B_NOT_MINIMIZABLE) == 0 action = (flags & B_NOT_MINIMIZABLE) == 0
? CLICK_MINIMIZE : CLICK_DRAG; ? ACTION_MINIMIZE : ACTION_DRAG;
} else if (rightButton) } else if (rightButton)
action = CLICK_MOVE_TO_BACK; action = ACTION_RESIZE_BORDER;
break; break;
case REGION_RESIZE_CORNER: case REGION_RESIZE_CORNER:
if (leftButton) { if (leftButton) {
action = (flags & B_NOT_RESIZABLE) == 0 action = (flags & B_NOT_RESIZABLE) == 0
? CLICK_RESIZE : CLICK_DRAG; ? ACTION_RESIZE : ACTION_DRAG;
} else if (rightButton) } else if (rightButton)
action = CLICK_MOVE_TO_BACK; action = ACTION_RESIZE_BORDER;
break; break;
} }
} }
@@ -631,7 +637,7 @@ DefaultWindowBehaviour::MouseDown(BMessage* message, BPoint where)
fResetClickCount = 0; fResetClickCount = 0;
} }
if (action == CLICK_NONE) { if (action == ACTION_NONE) {
// No action -- if this is a click inside the window's contents, // No action -- if this is a click inside the window's contents,
// let it be forwarded to the window. // let it be forwarded to the window.
return inBorderRegion; return inBorderRegion;
@@ -642,13 +648,13 @@ DefaultWindowBehaviour::MouseDown(BMessage* message, BPoint where)
// Ignore clicks on decorator buttons if the // Ignore clicks on decorator buttons if the
// non-floating window doesn't have focus // non-floating window doesn't have focus
if (!fWindow->IsFocus() && !fWindow->IsFloating() if (!fWindow->IsFocus() && !fWindow->IsFloating()
&& action != CLICK_MOVE_TO_BACK && action != ACTION_RESIZE_BORDER
&& action != CLICK_RESIZE && action != CLICK_SLIDE_TAB) && action != ACTION_RESIZE && action != ACTION_SLIDE_TAB)
action = CLICK_DRAG; action = ACTION_DRAG;
} }
bool activateOnMouseUp = false; bool activateOnMouseUp = false;
if (action != CLICK_MOVE_TO_BACK) { if (action != ACTION_RESIZE_BORDER) {
// activate window if in click to activate mode, else only focus it // activate window if in click to activate mode, else only focus it
if (desktopSettings.MouseMode() == B_NORMAL_MOUSE) { if (desktopSettings.MouseMode() == B_NORMAL_MOUSE) {
fDesktop->ActivateWindow(fWindow); fDesktop->ActivateWindow(fWindow);
@@ -660,34 +666,34 @@ DefaultWindowBehaviour::MouseDown(BMessage* message, BPoint where)
// switch to the new state // switch to the new state
switch (action) { switch (action) {
case CLICK_CLOSE: case ACTION_CLOSE:
case CLICK_ZOOM: case ACTION_ZOOM:
case CLICK_MINIMIZE: case ACTION_MINIMIZE:
_NextState( _NextState(
new (std::nothrow) DecoratorButtonState(*this, hitRegion)); new (std::nothrow) DecoratorButtonState(*this, hitRegion));
STRACE_CLICK(("===> CLICK_CLOSE/ZOOM/MINIMIZE\n")); STRACE_CLICK(("===> ACTION_CLOSE/ZOOM/MINIMIZE\n"));
break; break;
case CLICK_DRAG: case ACTION_DRAG:
_NextState(new (std::nothrow) DragState(*this, where, _NextState(new (std::nothrow) DragState(*this, where,
activateOnMouseUp, clickCount == 2)); activateOnMouseUp, clickCount == 2));
STRACE_CLICK(("===> CLICK_DRAG\n")); STRACE_CLICK(("===> ACTION_DRAG\n"));
break; break;
case CLICK_RESIZE: case ACTION_RESIZE:
_NextState(new (std::nothrow) ResizeState(*this, where, _NextState(new (std::nothrow) ResizeState(*this, where,
activateOnMouseUp)); activateOnMouseUp));
STRACE_CLICK(("===> CLICK_RESIZE\n")); STRACE_CLICK(("===> ACTION_RESIZE\n"));
break; break;
case CLICK_SLIDE_TAB: case ACTION_SLIDE_TAB:
_NextState(new (std::nothrow) SlideTabState(*this, where)); _NextState(new (std::nothrow) SlideTabState(*this, where));
STRACE_CLICK(("===> CLICK_SLIDE_TAB\n")); STRACE_CLICK(("===> ACTION_SLIDE_TAB\n"));
break; break;
case CLICK_MOVE_TO_BACK: case ACTION_RESIZE_BORDER:
fDesktop->SendWindowBehind(fWindow); fDesktop->SendWindowBehind(fWindow);
STRACE_CLICK(("===> CLICK_MOVE_TO_BACK\n")); STRACE_CLICK(("===> ACTION_RESIZE_BORDER\n"));
break; break;
default: default:
+12
View File
@@ -48,6 +48,18 @@ private:
REGION_RESIZE_CORNER REGION_RESIZE_CORNER
}; };
enum Action {
ACTION_NONE,
ACTION_ZOOM,
ACTION_CLOSE,
ACTION_MINIMIZE,
ACTION_TAB,
ACTION_DRAG,
ACTION_SLIDE_TAB,
ACTION_RESIZE,
ACTION_RESIZE_BORDER
};
struct State; struct State;
struct MouseTrackingState; struct MouseTrackingState;
struct DragState; struct DragState;