Add a blocker for invalidate_layout().

This will be used by classes that can (partly) handle their own resizes.
This commit is contained in:
Mark de Wever 2009-12-20 19:35:02 +00:00
parent 3b69aec985
commit e45d341f6a
2 changed files with 45 additions and 1 deletions

View file

@ -229,6 +229,7 @@ twindow::twindow(CVideo& video,
, retval_(NONE)
, owner_(0)
, need_layout_(true)
, invalidate_layout_blocked_(false)
, suspend_drawing_(true)
, restorer_()
, tooltip_()
@ -667,6 +668,26 @@ void twindow::draw()
cursor::undraw(frame_buffer);
}
twindow::tinvalidate_layout_blocker::tinvalidate_layout_blocker(twindow& window)
: window_(window)
{
assert(!window_.invalidate_layout_blocked_);
window_.invalidate_layout_blocked_ = true;
}
twindow::tinvalidate_layout_blocker::~tinvalidate_layout_blocker()
{
assert(window_.invalidate_layout_blocked_);
window_.invalidate_layout_blocked_ = false;
}
void twindow::invalidate_layout()
{
if(!invalidate_layout_blocked_) {
need_layout_ = true;
}
}
void twindow::init_linked_size_group(const std::string& id,
const bool fixed_width, const bool fixed_height)
{

View file

@ -56,6 +56,7 @@ class twindow
friend class tdebug_layout_graph;
friend twindow* build(CVideo&, const std::string&);
friend struct twindow_implementation;
friend class tinvalidate_layout_blocker;
public:
@ -181,6 +182,25 @@ public:
*/
void close() { status_ = REQUEST_CLOSE; }
/**
* Helper class to block invalidate_layout.
*
* Some widgets can handling certain layout aspects without help. For
* example a listbox can handle hiding and showing rows without help but
* setting the visibility calls invalidate_layout(). When this blocker is
* instanciated the call to invalidate_layout() becomes a nop.
*
* @note The class can't be used recursively.
*/
class tinvalidate_layout_blocker
{
public:
tinvalidate_layout_blocker(twindow& window);
~tinvalidate_layout_blocker();
private:
twindow& window_;
};
/**
* Updates the size of the window.
*
@ -188,7 +208,7 @@ public:
* window. To be used after creation and after modification or items which
* can have different sizes eg listboxes.
*/
void invalidate_layout() { need_layout_ = true; }
void invalidate_layout();
/** Inherited from tevent_handler. */
twindow& get_window() { return *this; }
@ -363,6 +383,9 @@ private:
*/
bool need_layout_;
/** Is invalidate layout blocked see tinvalidate_layout_blocker. */
bool invalidate_layout_blocked_;
/** Avoid drawing the window. */
bool suspend_drawing_;