* Fixed bug that prevented the font state to be properly popped. It could be

solved more efficiently by adding a new app_server call for this, though.
* Fixed stupid operator precedence bug that caused BView to always archive
  everything, instead of only those items with their archiving flag set.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31091 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-06-17 16:50:14 +00:00
parent f3b1ada54f
commit 834a9474ac
+58 -42
View File
@@ -9,16 +9,23 @@
* Ingo Weinhold <[email protected]> * Ingo Weinhold <[email protected]>
*/ */
#include <math.h> #include <View.h>
#include <stdio.h>
#include <new> #include <new>
#include <math.h>
#include <stdio.h>
#include <Application.h> #include <Application.h>
#include <Bitmap.h> #include <Bitmap.h>
#include <Button.h> #include <Button.h>
#include <Cursor.h> #include <Cursor.h>
#include <File.h> #include <File.h>
#include <GradientLinear.h>
#include <GradientRadial.h>
#include <GradientRadialFocus.h>
#include <GradientDiamond.h>
#include <GradientConic.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <Layout.h> #include <Layout.h>
#include <LayoutContext.h> #include <LayoutContext.h>
@@ -35,15 +42,8 @@
#include <Shape.h> #include <Shape.h>
#include <Shelf.h> #include <Shelf.h>
#include <String.h> #include <String.h>
#include <View.h>
#include <Window.h> #include <Window.h>
#include <GradientLinear.h>
#include <GradientRadial.h>
#include <GradientRadialFocus.h>
#include <GradientDiamond.h>
#include <GradientConic.h>
#include <AppMisc.h> #include <AppMisc.h>
#include <AppServerLink.h> #include <AppServerLink.h>
#include <binary_compatibility/Interface.h> #include <binary_compatibility/Interface.h>
@@ -154,13 +154,11 @@ ViewState::ViewState()
font_flags = font.Flags(); font_flags = font.Flags();
font_aliasing = false; font_aliasing = false;
/* // We only keep the B_VIEW_CLIP_REGION_BIT flag invalidated,
INFO: We include(invalidate) only B_VIEW_CLIP_REGION_BIT flag // because we should get the clipping region from app_server.
because we should get the clipping region from app_server. // The other flags do not need to be included because the data they
The other flags do not need to be included because the data they // represent is already in sync with app_server - app_server uses the
represent is already in sync with app_server - app_server uses the // same init (default) values.
same init(default) values.
*/
valid_flags = ~B_VIEW_CLIP_REGION_BIT; valid_flags = ~B_VIEW_CLIP_REGION_BIT;
archiving_flags = B_VIEW_FRAME_BIT | B_VIEW_RESIZE_BIT; archiving_flags = B_VIEW_FRAME_BIT | B_VIEW_RESIZE_BIT;
@@ -240,9 +238,9 @@ ViewState::UpdateServerState(BPrivate::PortLink &link)
link.Attach<int32>(-1); link.Attach<int32>(-1);
} }
// Although we might have a 'local' clipping region, when we call // Although we might have a 'local' clipping region, when we call
// BView::GetClippingRegion() we ask for the 'global' one and it // BView::GetClippingRegion() we ask for the 'global' one and it
// is kept on server, so we must invalidate B_VIEW_CLIP_REGION_BIT flag // is kept on server, so we must invalidate B_VIEW_CLIP_REGION_BIT flag
valid_flags = ~B_VIEW_CLIP_REGION_BIT; valid_flags = ~B_VIEW_CLIP_REGION_BIT;
} }
@@ -317,16 +315,17 @@ ViewState::UpdateFrom(BPrivate::PortLink &link)
struct BView::LayoutData { struct BView::LayoutData {
LayoutData() LayoutData()
: fMinSize(), :
fMaxSize(), fMinSize(),
fPreferredSize(), fMaxSize(),
fAlignment(), fPreferredSize(),
fLayoutInvalidationDisabled(0), fAlignment(),
fLayout(NULL), fLayoutInvalidationDisabled(0),
fLayoutContext(NULL), fLayout(NULL),
fLayoutValid(true), // <- TODO: Rethink this! fLayoutContext(NULL),
fLayoutInProgress(false), fLayoutValid(true), // <- TODO: Rethink this!
fNeedsRelayout(true) fLayoutInProgress(false),
fNeedsRelayout(true)
{ {
} }
@@ -470,7 +469,7 @@ BView::Archive(BMessage *data, bool deep) const
if (ret != B_OK) if (ret != B_OK)
return ret; return ret;
if (fState->archiving_flags & B_VIEW_FRAME_BIT) if ((fState->archiving_flags & B_VIEW_FRAME_BIT) != 0)
ret = data->AddRect("_frame", Bounds().OffsetToCopy(fParentOffset)); ret = data->AddRect("_frame", Bounds().OffsetToCopy(fParentOffset));
if (ret == B_OK) if (ret == B_OK)
@@ -479,13 +478,13 @@ BView::Archive(BMessage *data, bool deep) const
if (ret == B_OK) if (ret == B_OK)
ret = data->AddInt32("_flags", Flags()); ret = data->AddInt32("_flags", Flags());
if (ret == B_OK && fState->archiving_flags & B_VIEW_EVENT_MASK_BIT) { if (ret == B_OK && (fState->archiving_flags & B_VIEW_EVENT_MASK_BIT) != 0) {
ret = data->AddInt32("_evmask", fEventMask); ret = data->AddInt32("_evmask", fEventMask);
if (ret == B_OK) if (ret == B_OK)
ret = data->AddInt32("_evmask", fEventOptions); ret = data->AddInt32("_evmask", fEventOptions);
} }
if (ret == B_OK && fState->archiving_flags & B_VIEW_FONT_BIT) { if (ret == B_OK && (fState->archiving_flags & B_VIEW_FONT_BIT) != 0) {
BFont font; BFont font;
GetFont(&font); GetFont(&font);
@@ -516,16 +515,16 @@ BView::Archive(BMessage *data, bool deep) const
// ret = data->AddInt32("_dbuf", 1); // ret = data->AddInt32("_dbuf", 1);
// } // }
if (ret == B_OK && fState->archiving_flags & B_VIEW_ORIGIN_BIT) if (ret == B_OK && (fState->archiving_flags & B_VIEW_ORIGIN_BIT) != 0)
ret = data->AddPoint("_origin", Origin()); ret = data->AddPoint("_origin", Origin());
if (ret == B_OK && fState->archiving_flags & B_VIEW_PEN_SIZE_BIT) if (ret == B_OK && (fState->archiving_flags & B_VIEW_PEN_SIZE_BIT) != 0)
ret = data->AddFloat("_psize", PenSize()); ret = data->AddFloat("_psize", PenSize());
if (ret == B_OK && fState->archiving_flags & B_VIEW_PEN_LOCATION_BIT) if (ret == B_OK && (fState->archiving_flags & B_VIEW_PEN_LOCATION_BIT) != 0)
ret = data->AddPoint("_ploc", PenLocation()); ret = data->AddPoint("_ploc", PenLocation());
if (ret == B_OK && fState->archiving_flags & B_VIEW_LINE_MODES_BIT) { if (ret == B_OK && (fState->archiving_flags & B_VIEW_LINE_MODES_BIT) != 0) {
ret = data->AddInt16("_lmcapjoin", (int16)LineCapMode()); ret = data->AddInt16("_lmcapjoin", (int16)LineCapMode());
if (ret == B_OK) if (ret == B_OK)
ret = data->AddInt16("_lmcapjoin", (int16)LineJoinMode()); ret = data->AddInt16("_lmcapjoin", (int16)LineJoinMode());
@@ -533,7 +532,7 @@ BView::Archive(BMessage *data, bool deep) const
ret = data->AddFloat("_lmmiter", LineMiterLimit()); ret = data->AddFloat("_lmmiter", LineMiterLimit());
} }
if (ret == B_OK && fState->archiving_flags & B_VIEW_BLENDING_BIT) { if (ret == B_OK && (fState->archiving_flags & B_VIEW_BLENDING_BIT) != 0) {
source_alpha alphaSourceMode; source_alpha alphaSourceMode;
alpha_function alphaFunctionMode; alpha_function alphaFunctionMode;
GetBlendingMode(&alphaSourceMode, &alphaFunctionMode); GetBlendingMode(&alphaSourceMode, &alphaFunctionMode);
@@ -543,7 +542,7 @@ BView::Archive(BMessage *data, bool deep) const
ret = data->AddInt16("_blend", (int16)alphaFunctionMode); ret = data->AddInt16("_blend", (int16)alphaFunctionMode);
} }
if (ret == B_OK && fState->archiving_flags & B_VIEW_DRAWING_MODE_BIT) if (ret == B_OK && (fState->archiving_flags & B_VIEW_DRAWING_MODE_BIT) != 0)
ret = data->AddInt32("_dmod", DrawingMode()); ret = data->AddInt32("_dmod", DrawingMode());
if (deep) { if (deep) {
@@ -567,12 +566,15 @@ BView::~BView()
{ {
STRACE(("BView(%s)::~BView()\n", this->Name())); STRACE(("BView(%s)::~BView()\n", this->Name()));
if (fOwner) if (fOwner) {
debugger("Trying to delete a view that belongs to a window. Call RemoveSelf first."); debugger("Trying to delete a view that belongs to a window. "
"Call RemoveSelf first.");
}
RemoveSelf(); RemoveSelf();
// TODO: see about BShelf! must I delete it here? is it deleted by the window? // TODO: see about BShelf! must I delete it here? is it deleted by
// the window?
// we also delete all our children // we also delete all our children
@@ -627,6 +629,7 @@ BView::_ConvertToParent(BPoint *point, bool checkLock) const
point->y += -fBounds.top + fParentOffset.y; point->y += -fBounds.top + fParentOffset.y;
} }
void void
BView::ConvertToParent(BPoint *point) const BView::ConvertToParent(BPoint *point) const
{ {
@@ -658,6 +661,7 @@ BView::_ConvertFromParent(BPoint *point, bool checkLock) const
point->y += -fParentOffset.y + fBounds.top; point->y += -fParentOffset.y + fBounds.top;
} }
void void
BView::ConvertFromParent(BPoint *point) const BView::ConvertFromParent(BPoint *point) const
{ {
@@ -2195,7 +2199,7 @@ BView::SetFont(const BFont* font, uint32 mask)
if (mask == B_FONT_ALL) { if (mask == B_FONT_ALL) {
fState->font = *font; fState->font = *font;
} else { } else {
// ToDo: move this into a BFont method // TODO: move this into a BFont method
if (mask & B_FONT_FAMILY_AND_STYLE) if (mask & B_FONT_FAMILY_AND_STYLE)
fState->font.SetFamilyAndStyle(font->FamilyAndStyle()); fState->font.SetFamilyAndStyle(font->FamilyAndStyle());
@@ -2230,8 +2234,10 @@ BView::SetFont(const BFont* font, uint32 mask)
_CheckLockAndSwitchCurrent(); _CheckLockAndSwitchCurrent();
fState->UpdateServerFontState(*fOwner->fLink); fState->UpdateServerFontState(*fOwner->fLink);
fState->valid_flags |= B_VIEW_FONT_BIT;
} }
fState->archiving_flags |= B_VIEW_FONT_BIT;
// TODO: InvalidateLayout() here for convenience? // TODO: InvalidateLayout() here for convenience?
} }
@@ -2239,6 +2245,15 @@ BView::SetFont(const BFont* font, uint32 mask)
void void
BView::GetFont(BFont *font) const BView::GetFont(BFont *font) const
{ {
if (!fState->IsValid(B_VIEW_FONT_BIT)) {
// we don't keep graphics state information, therefor
// we need to ask the server for the origin after PopState()
_CheckOwnerLockAndSwitchCurrent();
// TODO: add a font getter!
fState->UpdateFrom(*fOwner->fLink);
}
*font = fState->font; *font = fState->font;
} }
@@ -5143,6 +5158,7 @@ BView::_Draw(BRect updateRect)
Flush(); Flush();
} }
void void
BView::_DrawAfterChildren(BRect updateRect) BView::_DrawAfterChildren(BRect updateRect)
{ {