Some refactoring and cleanup:

- renamed some members and methods to fit our style guide
- moved removeSelf() to RemoveSelf() (as those two are essentially
  the same), and fixed it on the way: the state of the child views
  is now also updated by the new _UpdateStateForRemove() method
- Moved BWindow::sendPulse() and activateView() to BView::_Pulse()
  and BView::_Activate()
- some minor stuff

This also fixes the broken previous commit - I forgot to update
View.h; this update contains the previous changes as well. Sorry
for the inconvenience.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13334 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-06-28 23:02:44 +00:00
parent 3783821c25
commit bb1336b44f
4 changed files with 735 additions and 752 deletions
+56 -54
View File
@@ -132,15 +132,16 @@ class BShape;
class BShelf; class BShelf;
class BString; class BString;
class BWindow; class BWindow;
class ViewAttr;
struct _view_attr_;
struct _array_data_; struct _array_data_;
struct _array_hdr_; struct _array_hdr_;
struct overlay_restrictions; struct overlay_restrictions;
// BView class ----------------------------------------------------------------- namespace BPrivate {
class BView : public BHandler { class ViewState;
};
class BView : public BHandler {
public: public:
BView(BRect frame, const char* name, BView(BRect frame, const char* name,
uint32 resizeMask, uint32 flags); uint32 resizeMask, uint32 flags);
@@ -558,11 +559,9 @@ private:
void DoShape(int32 gr, BShape* shape, pattern p); void DoShape(int32 gr, BShape* shape, pattern p);
void DoPictureClip(BPicture* picture, BPoint where, bool invert, void DoPictureClip(BPicture* picture, BPoint where, bool invert,
bool sync); bool sync);
bool removeFromList(BView* a_view);
bool removeSelf();
bool do_owner_check() const; bool do_owner_check() const;
void setOwner(BWindow* the_owner); void _SetOwner(BWindow* newOwner);
void do_activate(int32 state);
void check_lock() const; void check_lock() const;
void check_lock_no_pick() const; void check_lock_no_pick() const;
void movesize(uint32 code, int32 h, int32 v); void movesize(uint32 code, int32 h, int32 v);
@@ -570,42 +569,42 @@ private:
char *test_area(int32 length); char *test_area(int32 length);
void removeCommArray(); void removeCommArray();
_array_hdr_ *new_comm_array(int32 cnt); _array_hdr_ *new_comm_array(int32 cnt);
BView *RealParent() const;
void SetScroller(BScrollBar* sb); void SetScroller(BScrollBar* sb);
void UnsetScroller(BScrollBar* sb); void UnsetScroller(BScrollBar* sb);
void RealScrollTo(BPoint); void RealScrollTo(BPoint);
void initCachedState();
void setCachedState();
void updateCachedState();
void setFontState(const BFont* font, uint16 mask);
void fetch_font(); void fetch_font();
uchar font_encoding() const; uchar font_encoding() const;
BShelf* shelf() const; BShelf* shelf() const;
void set_shelf(BShelf* ); void set_shelf(BShelf* shelf);
void _Activate(bool state);
void _Pulse();
void _UpdateStateForRemove();
void _UpdatePattern(::pattern pattern);
void deleteView( BView* aView); void deleteView( BView* aView);
bool do_owner_check_no_pick() const; bool do_owner_check_no_pick() const;
bool attachView( BView *aView ); bool attachView( BView *aView );
bool addToList( BView *aView, BView *before = NULL); bool _AddChildToList(BView* child, BView* before = NULL);
bool removeFromList(); bool _RemoveChildFromList(BView* child);
void callAttachHooks( BView *aView ); void callAttachHooks( BView *aView );
void callDetachHooks( BView *aView ); void callDetachHooks( BView *aView );
// Debugging methods // Debugging methods
void PrintToStream(); void PrintToStream();
void PrintTree(); void PrintTree();
int32 server_token; int32 server_token;
uint32 fFlags; // used // was: f_type uint32 fFlags;
float originX; // used // was: origin_h BPoint fParentOffset;
float originY; // used // was: origin_v BWindow* fOwner;
BWindow* owner; // used BView* fParent;
BView* parent; // used BView* fNextSibling;
BView* next_sibling; // used BView* fPreviousSibling;
BView* prev_sibling; // used BView* fFirstChild;
BView* first_child; // used
int16 fShowLevel; // used int16 fShowLevel;
bool top_level_view; // used bool top_level_view; // used
bool fNoISInteraction; bool fNoISInteraction;
BPicture* cpicture; // used BPicture* cpicture; // used
@@ -617,50 +616,53 @@ private:
bool _unused_bool0; // was: attached; bool _unused_bool0; // was: attached;
bool _unused_bool1; bool _unused_bool1;
bool _unused_bool2; bool _unused_bool2;
ViewAttr* fPermanentState;// used BPrivate::ViewState* fPermanentState; // not used
ViewAttr* fState; // used BPrivate::ViewState* fState;
BRect fBounds; // used BRect fBounds;
BShelf* fShelf; // used BShelf* fShelf;
void* pr_state; void* pr_state; // not used
uint32 fEventMask; // used uint32 fEventMask;
uint32 fEventOptions; // used uint32 fEventOptions;
uint32 _reserved[4]; uint32 _reserved[4];
#if !_PR3_COMPATIBLE_ #if !_PR3_COMPATIBLE_
uint32 _more_reserved[3]; uint32 _more_reserved[3];
#endif #endif
}; };
//------------------------------------------------------------------------------
// inline definitions ---------------------------------------------------------- // inline definitions ----------------------------------------------------------
inline void BView::ScrollTo(float x, float y)
inline void
BView::ScrollTo(float x, float y)
{ {
ScrollTo(BPoint(x, y)); ScrollTo(BPoint(x, y));
} }
//------------------------------------------------------------------------------
inline void BView::SetViewColor(uchar r, uchar g, uchar b, uchar a) inline void
BView::SetViewColor(uchar r, uchar g, uchar b, uchar a)
{ {
rgb_color a_color; rgb_color color;
a_color.red = r; a_color.green = g; color.red = r; color.green = g;
a_color.blue = b; a_color.alpha = a; color.blue = b; color.alpha = a;
SetViewColor(a_color); SetViewColor(color);
} }
//------------------------------------------------------------------------------
inline void BView::SetHighColor(uchar r, uchar g, uchar b, uchar a) inline void
BView::SetHighColor(uchar r, uchar g, uchar b, uchar a)
{ {
rgb_color a_color; rgb_color color;
a_color.red = r; a_color.green = g; color.red = r; color.green = g;
a_color.blue = b; a_color.alpha = a; color.blue = b; color.alpha = a;
SetHighColor(a_color); SetHighColor(color);
} }
//------------------------------------------------------------------------------
inline void BView::SetLowColor(uchar r, uchar g, uchar b, uchar a) inline void
BView::SetLowColor(uchar r, uchar g, uchar b, uchar a)
{ {
rgb_color a_color; rgb_color color;
a_color.red = r; a_color.green = g; color.red = r; color.green = g;
a_color.blue = b; a_color.alpha = a; color.blue = b; color.alpha = a;
SetLowColor(a_color); SetLowColor(color);
} }
//------------------------------------------------------------------------------
#endif // _VIEW_H #endif // _VIEW_H
-2
View File
@@ -358,7 +358,6 @@ private:
// message: B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED // message: B_MOUSE_UP, B_MOUSE_DOWN, B_MOUSE_MOVED
void sendMessageUsingEventMask(int32 message, BPoint where); void sendMessageUsingEventMask(int32 message, BPoint where);
BView* sendMessageUsingEventMask2(BView* aView, int32 message, BPoint where); BView* sendMessageUsingEventMask2(BView* aView, int32 message, BPoint where);
void sendPulse(BView *view);
int32 findShortcut(uint32 key, uint32 modifiers); int32 findShortcut(uint32 key, uint32 modifiers);
bool findHandler(BView* start, BHandler* handler); bool findHandler(BView* start, BHandler* handler);
BView* findView(BView* aView, const char* viewName) const; BView* findView(BView* aView, const char* viewName) const;
@@ -370,7 +369,6 @@ private:
BView* findLastChild(BView *parent); BView* findLastChild(BView *parent);
bool handleKeyDown(const char key, uint32 modifiers); bool handleKeyDown(const char key, uint32 modifiers);
void handleActivation( bool active); void handleActivation( bool active);
void activateView(BView *aView, bool active);
void drawAllViews(BView* aView); void drawAllViews(BView* aView);
void DoUpdate(BView* aView, BRect& area); void DoUpdate(BView* aView, BRect& area);
File diff suppressed because it is too large Load Diff
+31 -59
View File
@@ -787,7 +787,7 @@ BWindow::DispatchMessage(BMessage *msg, BHandler *target)
case B_PULSE: case B_PULSE:
if (fPulseEnabled) { if (fPulseEnabled) {
sendPulse(top_view); top_view->_Pulse();
fLink->Flush(); fLink->Flush();
} }
break; break;
@@ -2353,7 +2353,7 @@ BWindow::BuildTopView()
STRACE(("Calling setowner top_view = %p this = %p.\n", STRACE(("Calling setowner top_view = %p this = %p.\n",
top_view, this)); top_view, this));
top_view->setOwner(this); top_view->_SetOwner(this);
//we can't use AddChild() because this is the top_view //we can't use AddChild() because this is the top_view
top_view->attachView(top_view); top_view->attachView(top_view);
@@ -2414,20 +2414,7 @@ BWindow::handleActivation(bool active)
// recursively call hook function 'WindowActivated(bool)' // recursively call hook function 'WindowActivated(bool)'
// for all views attached to this window. // for all views attached to this window.
activateView(top_view, active); top_view->_Activate(active);
}
void
BWindow::activateView(BView *view, bool active)
{
view->WindowActivated(active);
BView *child = view->first_child;
while (child) {
activateView(child, active);
child = child->next_sibling;
}
} }
@@ -2585,7 +2572,7 @@ BWindow::sendMessageUsingEventMask2(BView *view, int32 message, BPoint where)
} }
// Code for Event Masks // Code for Event Masks
BView *child = view->first_child; BView *child = view->fFirstChild;
while (child) { while (child) {
// see if a BView registered for mouse events and it's not the current focus view // see if a BView registered for mouse events and it's not the current focus view
if (view != fFocus if (view != fFocus
@@ -2623,7 +2610,7 @@ BWindow::sendMessageUsingEventMask2(BView *view, int32 message, BPoint where)
// one of the children contains the point // one of the children contains the point
if (target) if (target)
destView = target; destView = target;
child = child->next_sibling; child = child->fNextSibling;
} }
return destView; return destView;
@@ -2679,7 +2666,7 @@ BWindow::sendMessageUsingEventMask(int32 message, BPoint where)
// TODO: Do research on mouse capturing -- maybe it has something to do // TODO: Do research on mouse capturing -- maybe it has something to do
// with this // with this
if (fFocus != destView) if (fFocus != destView)
fFocus->MouseMoved( ConvertFromScreen(where), B_OUTSIDE_VIEW, dragMessage); fFocus->MouseMoved(ConvertFromScreen(where), B_OUTSIDE_VIEW, dragMessage);
break; break;
} }
} }
@@ -2693,21 +2680,6 @@ BWindow::ConvertToMessage(void *raw, int32 code)
} }
void
BWindow::sendPulse(BView *view)
{
BView *child = view->first_child;
while (child) {
if (child->Flags() & B_PULSE_NEEDED)
child->Pulse();
sendPulse(child);
child = child->next_sibling;
}
}
int32 int32
BWindow::findShortcut(uint32 key, uint32 modifiers) BWindow::findShortcut(uint32 key, uint32 modifiers)
{ {
@@ -2730,13 +2702,13 @@ BWindow::findView(BView *view, int32 token)
if (_get_object_token_(view) == token) if (_get_object_token_(view) == token)
return view; return view;
BView *child = view->first_child; BView *child = view->fFirstChild;
while (child != NULL) { while (child != NULL) {
if ((view = findView(child, token)) != NULL) if ((view = findView(child, token)) != NULL)
return view; return view;
child = child->next_sibling; child = child->fNextSibling;
} }
return NULL; return NULL;
@@ -2749,13 +2721,13 @@ BWindow::findView(BView *view, const char *name) const
if (!strcmp(name, view->Name())) if (!strcmp(name, view->Name()))
return view; return view;
BView *child = view->first_child; BView *child = view->fFirstChild;
while (child != NULL) { while (child != NULL) {
if ((view = findView(child, name)) != NULL) if ((view = findView(child, name)) != NULL)
return view; return view;
child = child->next_sibling; child = child->fNextSibling;
} }
return NULL; return NULL;
@@ -2765,16 +2737,16 @@ BWindow::findView(BView *view, const char *name) const
BView * BView *
BWindow::findView(BView *view, BPoint point) const BWindow::findView(BView *view, BPoint point) const
{ {
if (view->Bounds().Contains(point) && !view->first_child) if (view->Bounds().Contains(point) && !view->fFirstChild)
return view; return view;
BView *child = view->first_child; BView *child = view->fFirstChild;
while (child != NULL) { while (child != NULL) {
if ((view = findView(child, point)) != NULL) if ((view = findView(child, point)) != NULL)
return view; return view;
child = child->next_sibling; child = child->fNextSibling;
} }
return NULL; return NULL;
@@ -2792,18 +2764,18 @@ BWindow::findNextView(BView *focus, uint32 flags)
// Ufff... this took me some time... this is the best form I've reached. // Ufff... this took me some time... this is the best form I've reached.
// This algorithm searches the tree for BViews that accept focus. // This algorithm searches the tree for BViews that accept focus.
while (true) { while (true) {
if (nextFocus->first_child) if (nextFocus->fFirstChild)
nextFocus = nextFocus->first_child; nextFocus = nextFocus->fFirstChild;
else if (nextFocus->next_sibling) else if (nextFocus->fNextSibling)
nextFocus = nextFocus->next_sibling; nextFocus = nextFocus->fNextSibling;
else { else {
while (!nextFocus->next_sibling && nextFocus->parent) while (!nextFocus->fNextSibling && nextFocus->fParent)
nextFocus = nextFocus->parent; nextFocus = nextFocus->fParent;
if (nextFocus == top_view) if (nextFocus == top_view)
nextFocus = nextFocus->first_child; nextFocus = nextFocus->fFirstChild;
else else
nextFocus = nextFocus->next_sibling; nextFocus = nextFocus->fNextSibling;
} }
// It means that the hole tree has been searched and there is no // It means that the hole tree has been searched and there is no
@@ -2826,16 +2798,16 @@ BWindow::findPrevView(BView *focus, uint32 flags)
BView *view; BView *view;
if ((view = findLastChild(prevFocus)) != NULL) if ((view = findLastChild(prevFocus)) != NULL)
prevFocus = view; prevFocus = view;
else if (prevFocus->prev_sibling) else if (prevFocus->fPreviousSibling)
prevFocus = prevFocus->prev_sibling; prevFocus = prevFocus->fPreviousSibling;
else { else {
while (!prevFocus->prev_sibling && prevFocus->parent) while (!prevFocus->fPreviousSibling && prevFocus->fParent)
prevFocus = prevFocus->parent; prevFocus = prevFocus->fParent;
if (prevFocus == top_view) if (prevFocus == top_view)
prevFocus = findLastChild(prevFocus); prevFocus = findLastChild(prevFocus);
else else
prevFocus = prevFocus->prev_sibling; prevFocus = prevFocus->fPreviousSibling;
} }
// It means that the hole tree has been searched and there is no // It means that the hole tree has been searched and there is no
@@ -2852,12 +2824,12 @@ BWindow::findPrevView(BView *focus, uint32 flags)
BView * BView *
BWindow::findLastChild(BView *parent) BWindow::findLastChild(BView *parent)
{ {
BView *last = parent->first_child; BView *last = parent->fFirstChild;
if (last == NULL) if (last == NULL)
return NULL; return NULL;
while (last->next_sibling) while (last->fNextSibling)
last = last->next_sibling; last = last->fNextSibling;
return last; return last;
} }
@@ -2902,7 +2874,7 @@ BWindow::DoUpdate(BView *view, BRect &area)
aView->SetHighColor(c);*/ aView->SetHighColor(c);*/
} }
BView *child = view->first_child; BView *child = view->fFirstChild;
while (child) { while (child) {
if (area.Intersects(child->Frame())) { if (area.Intersects(child->Frame())) {
BRect newArea = area & child->Frame(); BRect newArea = area & child->Frame();
@@ -2910,7 +2882,7 @@ BWindow::DoUpdate(BView *view, BRect &area)
DoUpdate(child, newArea); DoUpdate(child, newArea);
} }
child = child->next_sibling; child = child->fNextSibling;
} }
if (view->Flags() & B_WILL_DRAW) { if (view->Flags() & B_WILL_DRAW) {