Skip to content

Commit 22efa82

Browse files
committed
implement form with keep_cloned_controls
1 parent 6d91a3c commit 22efa82

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

src/xtd.forms/include/xtd/forms/application.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ namespace xtd {
509509
/// @}
510510

511511
private:
512+
friend class control;
512513
friend class form;
513514
friend class input_dialog;
514515
friend class message_box;
@@ -538,6 +539,7 @@ namespace xtd {
538539
static bool system_font_size_;
539540
static bool use_wait_cursor_;
540541
static bool visual_styles_;
542+
static xtd::collections::generic::list<xtd::sptr<xtd::forms::control>> top_level_forms_;
541543
};
542544
}
543545
}

src/xtd.forms/src/xtd/forms/application.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ bool application::system_controls_ = false;
9999
bool application::system_font_size_ = false;
100100
bool application::use_wait_cursor_ = false;
101101
bool application::visual_styles_ = false;
102+
xtd::collections::generic::list<xtd::sptr<xtd::forms::control>> application::top_level_forms_;
102103

103104
event<application, event_handler> application::application_exit;
104105
event<application, event_handler> application::enter_thread_modal;
@@ -238,10 +239,16 @@ bool application::message_loop() noexcept {
238239

239240
const form_collection application::open_forms() noexcept {
240241
auto forms = form_collection {};
242+
if (keep_cloned_controls()) {
243+
for (auto control : top_level_forms_)
244+
forms.push_back(dynamic_cast<form&>(*control));
245+
return forms;
246+
}
247+
241248
for (auto control : control::top_level_controls_)
242249
forms.push_back(dynamic_cast<form&>(control.get()));
243250
return forms;
244-
251+
245252
/*
246253
auto forms = form_collection {};
247254
for (intptr handle : native::application::open_forms()) {
@@ -438,6 +445,7 @@ void application::run(xtd::forms::application_context& context) {
438445
application::message_loop_ = false;
439446
internal_context_.main_form(nullptr);
440447
native::application::cleanup();
448+
top_level_forms_.clear();
441449
}
442450

443451
void application::run(const form& form) {

src/xtd.forms/src/xtd/forms/control.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1206,8 +1206,10 @@ void control::on_control_appearance_changed(const event_args& e) {
12061206
}
12071207

12081208
void control::on_create_control() {
1209-
if (!parent().has_value())
1210-
top_level_controls_.add(*this);
1209+
if (!parent().has_value()) {
1210+
if (!application::keep_cloned_controls()) top_level_controls_.add(*this);
1211+
else top_level_controls_.add(*application::top_level_forms_[~1_z]);
1212+
}
12111213
for (auto control : data_->controls) {
12121214
control.get().data_->parent = handle();
12131215
control.get().create_control();

src/xtd.forms/src/xtd/forms/form.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ form::form() : data_(xtd::new_sptr<data>()) {
6363
fore_color(application::style_sheet().is_system_style_sheet() ? system_colors::control_text() : default_fore_color());
6464
font(default_font());
6565
create_control();
66+
application::top_level_forms_.add(as<control>(as<iclonable>(*this).clone()));
6667
}
6768

6869
std::optional<form::ibutton_control_ref> form::accept_button() const noexcept {

0 commit comments

Comments
 (0)