* The BView::FrameResized()/FrameMoved() hooks are now called asynchronously

as in R5, and no longer directly. This fixes bug #301.
* As a side effect, the hooks are now only called when the view is attached
  to a window, as on R5.
* Removed dead B_VIEW_RESIZED/MOVED code from BWindow.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17009 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-04-04 16:41:29 +00:00
parent 29c407a371
commit 7bb48db1f2
2 changed files with 70 additions and 102 deletions

View File

@ -3629,46 +3629,64 @@ BView::MessageReceived(BMessage *msg)
status_t err;
if (!msg->HasSpecifiers()) {
if (msg->what == B_MOUSE_WHEEL_CHANGED) {
float deltaX = 0.0f, deltaY = 0.0f;
switch (msg->what) {
case B_VIEW_RESIZED:
// By the time the message arrives, the bounds may have
// changed already, that's why we don't use the values
// in the message itself.
FrameResized(fBounds.Width(), fBounds.Height());
break;
BScrollBar *horizontal = ScrollBar(B_HORIZONTAL);
if (horizontal != NULL)
msg->FindFloat("be:wheel_delta_x", &deltaX);
case B_VIEW_MOVED:
FrameMoved(fParentOffset);
break;
BScrollBar *vertical = ScrollBar(B_VERTICAL);
if (vertical != NULL)
msg->FindFloat("be:wheel_delta_y", &deltaY);
if (deltaX == 0.0f && deltaY == 0.0f)
return;
float smallStep, largeStep;
if (horizontal != NULL) {
horizontal->GetSteps(&smallStep, &largeStep);
// pressing the option key scrolls faster
if (modifiers() & B_OPTION_KEY)
deltaX *= largeStep;
else
deltaX *= smallStep * 3;
horizontal->SetValue(horizontal->Value() + deltaX);
case B_MOUSE_WHEEL_CHANGED:
{
float deltaX = 0.0f, deltaY = 0.0f;
BScrollBar *horizontal = ScrollBar(B_HORIZONTAL);
if (horizontal != NULL)
msg->FindFloat("be:wheel_delta_x", &deltaX);
BScrollBar *vertical = ScrollBar(B_VERTICAL);
if (vertical != NULL)
msg->FindFloat("be:wheel_delta_y", &deltaY);
if (deltaX == 0.0f && deltaY == 0.0f)
return;
float smallStep, largeStep;
if (horizontal != NULL) {
horizontal->GetSteps(&smallStep, &largeStep);
// pressing the option key scrolls faster
if (modifiers() & B_OPTION_KEY)
deltaX *= largeStep;
else
deltaX *= smallStep * 3;
horizontal->SetValue(horizontal->Value() + deltaX);
}
if (vertical != NULL) {
vertical->GetSteps(&smallStep, &largeStep);
// pressing the option key scrolls faster
if (modifiers() & B_OPTION_KEY)
deltaY *= largeStep;
else
deltaY *= smallStep * 3;
vertical->SetValue(vertical->Value() + deltaY);
}
break;
}
if (vertical != NULL) {
vertical->GetSteps(&smallStep, &largeStep);
// pressing the option key scrolls faster
if (modifiers() & B_OPTION_KEY)
deltaY *= largeStep;
else
deltaY *= smallStep * 3;
vertical->SetValue(vertical->Value() + deltaY);
}
} else
BHandler::MessageReceived(msg);
default:
BHandler::MessageReceived(msg);
break;
}
return;
}
@ -4014,8 +4032,12 @@ BView::_MoveTo(int32 x, int32 y)
fParentOffset.Set(x, y);
if (Window() != NULL && fFlags & B_FRAME_EVENTS) {
// TODO: CurrentMessage() is not what it used to be!
FrameMoved(BPoint(x, y));
BMessage moved(B_VIEW_MOVED);
moved.AddInt64("when", system_time());
moved.AddPoint("where", BPoint(x, y));
BMessenger target(this);
target.SendMessage(&moved);
}
}
@ -4045,8 +4067,13 @@ BView::_ResizeBy(int32 deltaWidth, int32 deltaHeight)
child->_ParentResizedBy(deltaWidth, deltaHeight);
if (fFlags & B_FRAME_EVENTS) {
// TODO: CurrentMessage() is not what it used to be!
FrameResized(fBounds.Width(), fBounds.Height());
BMessage resized(B_VIEW_RESIZED);
resized.AddInt64("when", system_time());
resized.AddFloat("width", fBounds.Width());
resized.AddFloat("height", fBounds.Height());
BMessenger target(this);
target.SendMessage(&resized);
}
}

View File

@ -750,17 +750,8 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
case B_WINDOW_RESIZED:
{
int32 width, height;
// if (msg->FindInt32("width", &width) == B_OK
// && msg->FindInt32("height", &height) == B_OK) {
// fFrame.right = fFrame.left + width;
// fFrame.bottom = fFrame.top + height;
//
// _AdoptResize();
// FrameResized(width, height);
// }
if (msg->FindInt32("width", &width) == B_OK
&& msg->FindInt32("height", &height) == B_OK) {
// combine with pending resize notifications
BMessage* pendingMessage;
while ((pendingMessage = MessageQueue()->FindMessage(B_WINDOW_RESIZED, 0))) {
@ -768,11 +759,11 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
int32 nextWidth;
if (pendingMessage->FindInt32("width", &nextWidth) == B_OK)
width = nextWidth;
int32 nextHeight;
if (pendingMessage->FindInt32("height", &nextHeight) == B_OK)
height = nextHeight;
MessageQueue()->RemoveMessage(pendingMessage);
// TODO: the BeBook says that MessageQueue::RemoveMessage() deletes the message!
delete pendingMessage;
@ -787,7 +778,7 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
// in an _UPDATE_ message
fFrame.right = fFrame.left + width;
fFrame.bottom = fFrame.top + height;
_AdoptResize();
// FrameResized(width, height);
}
@ -1040,56 +1031,6 @@ FrameMoved(origin);
break;
}
case B_VIEW_RESIZED:
case B_VIEW_MOVED:
{
// NOTE: The problem with this implementation is that BView::Window()->CurrentMessage()
// will show this message, and not what it used to be on R5. This might break apps and
// we need to fix this here or change the way this feature is implemented. However, this
// implementation shows what has to be done when Layers are moved or resized inside the
// app_server. This message is generated from Layer::MoveByHook() and ResizeByHook() in
// Layer::_AddToViewsWithInvalidCoords().
int32 token;
BPoint frameLeftTop;
float width;
float height;
BView *view;
for (int32 i = 0; CurrentMessage() && msg->FindInt32("_token", i, &token) >= B_OK; i++) {
if (token >= 0) {
msg->FindPoint("where", i, &frameLeftTop);
msg->FindFloat("width", i, &width);
msg->FindFloat("height", i, &height);
if ((view = _FindView(token)) != NULL) {
// update the views offset in parent
if (view->LeftTop() != frameLeftTop) {
view->fParentOffset = frameLeftTop;
// optionally call FrameMoved
if (view->fFlags & B_FRAME_EVENTS) {
STRACE(("Calling BView(%s)::FrameMoved( %.1f, %.1f )\n", view->Name(),
frameLeftTop.x, frameLeftTop.y));
view->FrameMoved(frameLeftTop);
}
}
// update the views width and height
if (view->fBounds.Width() != width || view->fBounds.Height() != height) {
// TODO: does this work when a views left/top side is resized?
view->fBounds.right = view->fBounds.left + width;
view->fBounds.bottom = view->fBounds.top + height;
// optionally call FrameResized
if (view->fFlags & B_FRAME_EVENTS) {
STRACE(("Calling BView(%s)::FrameResized( %f, %f )\n", view->Name(), width, height));
view->FrameResized(width, height);
}
}
} else {
fprintf(stderr, "B_VIEW_RESIZED ***PANIC: BW: Can't find view with ID: %ld !***\n", token);
}
}
}
break;
}
case _MENUS_DONE_:
MenusEnded();
break;