source: filezilla/trunk/fuentes/src/interface/xrc_helper.h @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 1.7 KB
Line 
1#ifndef FILEZILLA_XRC_HELPER_HEADER
2#define FILEZILLA_XRC_HELPER_HEADER
3
4/*
5xrc_call is a safer and simpler alternative to XRCCTRL:
6- uses dynamic_cast
7- Returns default-contructed return value if object does not exist
8- Asserts in debug if object does not exist
9
10Usage:
11  bool always = xrc_call(*this, "ID_ALWAYS", &wxCheckBox::GetValue);
12
13  Instead of this:
14  bool always = XRCCTRL(*this, "ID_ALWAYS", wxCheckBox)->GetValue();
15
16*/
17
18template<typename F, typename Control, typename ...Args, typename ...Args2>
19F xrc_call(wxWindow const& parent, char const* name, F(Control::* ptr)(Args...), Args2&& ... args)
20{
21        F ret{};
22        Control* c = dynamic_cast<Control*>(parent.FindWindow(XRCID(name)));
23        wxASSERT(c);
24        if (c) {
25                ret = (c->*ptr)(std::forward<Args2>(args)...);
26        }
27
28        return ret;
29}
30
31template<typename Control, typename ...Args, typename ...Args2>
32void xrc_call(wxWindow const& parent, char const* name, void (Control::* ptr)(Args...), Args2&& ... args)
33{
34        Control* c = dynamic_cast<Control*>(parent.FindWindow(XRCID(name)));
35        wxASSERT(c);
36        if (c) {
37                (c->*ptr)(std::forward<Args2>(args)...);
38        }
39}
40
41template<typename S, typename F, typename Control, typename ...Args, typename ...Args2>
42F xrc_call(wxWindow const& parent, S&& name, F(Control::* ptr)(Args...) const, Args2&& ... args)
43{
44        F ret{};
45        Control* c = dynamic_cast<Control*>(parent.FindWindow(XRCID(name)));
46        wxASSERT(c);
47        if (c) {
48                ret = (c->*ptr)(std::forward<Args2>(args)...);
49        }
50
51        return ret;
52}
53
54template<typename S, typename Control, typename ...Args, typename ...Args2>
55void xrc_call(wxWindow const& parent, S&& name, void (Control::* ptr)(Args...) const, Args2&& ... args)
56{
57        Control* c = dynamic_cast<Control*>(parent.FindWindow(XRCID(name)));
58        wxASSERT(c);
59        if (c) {
60                (c->*ptr)(std::forward<Args2>(args)...);
61        }
62}
63
64#endif
Note: See TracBrowser for help on using the repository browser.