refactor class place
This commit is contained in:
parent
99564a9161
commit
e720866a94
@ -559,18 +559,22 @@ namespace nana
|
|||||||
return token::identifier;
|
return token::identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string err = "an invalid character '";
|
_m_throw_error(*sp_);
|
||||||
err += *sp_;
|
|
||||||
err += "'";
|
|
||||||
|
|
||||||
_m_throw_error(err);
|
|
||||||
return token::error; //Useless, just for syntax correction.
|
return token::error; //Useless, just for syntax correction.
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void _m_throw_error(char err_char)
|
void _m_throw_error(char err_char)
|
||||||
|
{
|
||||||
|
std::string str = "place: invalid character '";
|
||||||
|
str += err_char;
|
||||||
|
str += '\'';
|
||||||
|
_m_throw_error(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _m_throw_error(const std::string& err)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "place: invalid character '" << err_char << "' at " << static_cast<unsigned>(sp_ - divstr_);
|
ss << "place: " << err << " at " << static_cast<unsigned>(sp_ - divstr_);
|
||||||
throw std::runtime_error(ss.str());
|
throw std::runtime_error(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,8 +583,7 @@ namespace nana
|
|||||||
if (token::equal != read())
|
if (token::equal != read())
|
||||||
_m_throw_error("an equal sign is required after '" + idstr_ + "'");
|
_m_throw_error("an equal sign is required after '" + idstr_ + "'");
|
||||||
|
|
||||||
const char* p = sp_;
|
const char* p = _m_eat_whitespace(sp_);
|
||||||
for (; *p == ' '; ++p);
|
|
||||||
|
|
||||||
auto neg_ptr = p;
|
auto neg_ptr = p;
|
||||||
if ('-' == *p)
|
if ('-' == *p)
|
||||||
@ -599,8 +602,7 @@ namespace nana
|
|||||||
if (token::equal != read())
|
if (token::equal != read())
|
||||||
_m_throw_error("an equal sign is required after '" + idstr + "'");
|
_m_throw_error("an equal sign is required after '" + idstr + "'");
|
||||||
|
|
||||||
const char* p = sp_;
|
const char* p = _m_eat_whitespace(sp_);
|
||||||
for (; *p == ' ' || *p == '\t'; ++p);
|
|
||||||
|
|
||||||
reparray_.reset();
|
reparray_.reset();
|
||||||
auto tk = read();
|
auto tk = read();
|
||||||
@ -620,14 +622,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _m_throw_error(const std::string& err)
|
static const char* _m_eat_whitespace(const char* sp)
|
||||||
{
|
|
||||||
std::stringstream ss;
|
|
||||||
ss << "place: " << err << " at " << static_cast<unsigned>(sp_ - divstr_);
|
|
||||||
throw std::runtime_error(ss.str());
|
|
||||||
}
|
|
||||||
|
|
||||||
const char* _m_eat_whitespace(const char* sp)
|
|
||||||
{
|
{
|
||||||
while (*sp && !isgraph(*sp))
|
while (*sp && !isgraph(*sp))
|
||||||
++sp;
|
++sp;
|
||||||
@ -678,7 +673,7 @@ namespace nana
|
|||||||
|
|
||||||
if (gotcha)
|
if (gotcha)
|
||||||
{
|
{
|
||||||
for (; *sp == ' ' || *sp == '\t'; ++sp);
|
sp = _m_eat_whitespace(sp);
|
||||||
if ('%' == *sp)
|
if ('%' == *sp)
|
||||||
{
|
{
|
||||||
if (number_t::kind::integer == number_.kind_of())
|
if (number_t::kind::integer == number_.kind_of())
|
||||||
@ -758,6 +753,20 @@ namespace nana
|
|||||||
for (auto & e : fastened)
|
for (auto & e : fastened)
|
||||||
API::show_window(e.handle, vsb);
|
API::show_window(e.handle, vsb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static event_handle erase_element(std::vector<element_t>& elements, window handle)
|
||||||
|
{
|
||||||
|
for (auto i = elements.begin(), end = elements.end(); i != end; ++i)
|
||||||
|
{
|
||||||
|
if (i->handle == handle)
|
||||||
|
{
|
||||||
|
auto evt_destroy = i->evt_destroy;
|
||||||
|
elements.erase(i);
|
||||||
|
return evt_destroy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
//The defintion is moved after the definition of class division
|
//The defintion is moved after the definition of class division
|
||||||
template<typename Function>
|
template<typename Function>
|
||||||
@ -769,14 +778,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
return API::events(wd).destroy.connect([this](const arg_destroy& arg)
|
return API::events(wd).destroy.connect([this](const arg_destroy& arg)
|
||||||
{
|
{
|
||||||
for (auto i = elements.begin(), end = elements.end(); i != end; ++i)
|
if (erase_element(elements, arg.window_handle))
|
||||||
{
|
|
||||||
if (arg.window_handle == i->handle)
|
|
||||||
{
|
|
||||||
elements.erase(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
place_ptr_->collocate();
|
place_ptr_->collocate();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -816,13 +818,7 @@ namespace nana
|
|||||||
//does not change the layout.
|
//does not change the layout.
|
||||||
auto evt = API::events(wd).destroy([this](const arg_destroy& arg)
|
auto evt = API::events(wd).destroy([this](const arg_destroy& arg)
|
||||||
{
|
{
|
||||||
auto destroyed_wd = arg.window_handle;
|
erase_element(fastened, arg.window_handle);
|
||||||
auto i = std::find_if(fastened.begin(), fastened.end(), [destroyed_wd](element_t& e){
|
|
||||||
return (e.handle == destroyed_wd);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i != fastened.end())
|
|
||||||
fastened.erase(i);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
fastened.emplace_back(wd, evt);
|
fastened.emplace_back(wd, evt);
|
||||||
@ -930,16 +926,9 @@ namespace nana
|
|||||||
{
|
{
|
||||||
for (auto & child : div->children)
|
for (auto & child : div->children)
|
||||||
{
|
{
|
||||||
if (child->field)
|
if (child->field && (!vsb || child->visible))
|
||||||
{
|
child->field->visible(vsb);
|
||||||
if (vsb)
|
|
||||||
{
|
|
||||||
if (child->visible)
|
|
||||||
child->field->visible(true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
child->field->visible(false);
|
|
||||||
}
|
|
||||||
_m_visible_for_child(child.get(), vsb);
|
_m_visible_for_child(child.get(), vsb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1511,17 +1500,6 @@ namespace nana
|
|||||||
class place::implement::div_splitter
|
class place::implement::div_splitter
|
||||||
: public division
|
: public division
|
||||||
{
|
{
|
||||||
struct div_block
|
|
||||||
{
|
|
||||||
division * div;
|
|
||||||
int pixels;
|
|
||||||
double scale;
|
|
||||||
|
|
||||||
div_block(division* d, int px)
|
|
||||||
: div(d), pixels(px)
|
|
||||||
{}
|
|
||||||
};
|
|
||||||
|
|
||||||
enum{splitter_px = 4};
|
enum{splitter_px = 4};
|
||||||
public:
|
public:
|
||||||
div_splitter(place_parts::number_t init_weight)
|
div_splitter(place_parts::number_t init_weight)
|
||||||
@ -1534,14 +1512,9 @@ namespace nana
|
|||||||
this->weight.assign(splitter_px);
|
this->weight.assign(splitter_px);
|
||||||
}
|
}
|
||||||
|
|
||||||
void leaf_left(division * d)
|
void set_leaf(bool is_left, division * d)
|
||||||
{
|
{
|
||||||
leaf_left_ = d;
|
(is_left ? leaf_left_ : leaf_right_) = d;
|
||||||
}
|
|
||||||
|
|
||||||
void leaf_right(division * d)
|
|
||||||
{
|
|
||||||
leaf_right_ = d;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void direction(bool horizontal)
|
void direction(bool horizontal)
|
||||||
@ -1787,7 +1760,7 @@ namespace nana
|
|||||||
if (!children.empty() && (division::kind::splitter != children.back()->kind_of_division))
|
if (!children.empty() && (division::kind::splitter != children.back()->kind_of_division))
|
||||||
{
|
{
|
||||||
auto splitter = new div_splitter(tknizer.number());
|
auto splitter = new div_splitter(tknizer.number());
|
||||||
splitter->leaf_left(children.back().get());
|
splitter->set_leaf(true, children.back().get());
|
||||||
children.back()->div_next = splitter;
|
children.back()->div_next = splitter;
|
||||||
children.emplace_back(splitter);
|
children.emplace_back(splitter);
|
||||||
}
|
}
|
||||||
@ -1799,7 +1772,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
children.back()->div_next = div.get();
|
children.back()->div_next = div.get();
|
||||||
if (division::kind::splitter == children.back()->kind_of_division)
|
if (division::kind::splitter == children.back()->kind_of_division)
|
||||||
dynamic_cast<div_splitter&>(*children.back()).leaf_right(div.get());
|
dynamic_cast<div_splitter&>(*children.back()).set_leaf(false, div.get());
|
||||||
}
|
}
|
||||||
children.emplace_back(div.release());
|
children.emplace_back(div.release());
|
||||||
}
|
}
|
||||||
@ -2184,29 +2157,14 @@ namespace nana
|
|||||||
bool recollocate = false;
|
bool recollocate = false;
|
||||||
for (auto & fld : impl_->fields)
|
for (auto & fld : impl_->fields)
|
||||||
{
|
{
|
||||||
auto & elements = fld.second->elements;
|
auto evt = fld.second->erase_element(fld.second->elements, handle);
|
||||||
for (auto i = elements.begin(); i != elements.end();)
|
if (evt)
|
||||||
{
|
{
|
||||||
if (i->handle == handle)
|
API::umake_event(evt);
|
||||||
{
|
|
||||||
API::umake_event(i->evt_destroy);
|
|
||||||
i = elements.erase(i);
|
|
||||||
recollocate |= (nullptr != fld.second->attached);
|
recollocate |= (nullptr != fld.second->attached);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto i = std::find_if(fld.second->fastened.begin(), fld.second->fastened.end(), [handle](implement::field_impl::element_t& e)
|
API::umake_event( fld.second->erase_element(fld.second->fastened, handle));
|
||||||
{
|
|
||||||
return (e.handle == handle);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (i != fld.second->fastened.end())
|
|
||||||
{
|
|
||||||
API::umake_event(i->evt_destroy);
|
|
||||||
fld.second->fastened.erase(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recollocate)
|
if (recollocate)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user