From 5d014cbff52bce01007e5ab440abe9e5fcaa8ca2 Mon Sep 17 00:00:00 2001 From: Gammasoft Date: Sun, 12 May 2024 20:56:25 +0200 Subject: [PATCH] Add owner draw param --- .../forms/native/wxwidgets/wx_picture_box.h | 14 ++++++++++- src/xtd.forms/src/xtd/forms/picture_box.cpp | 24 +++++++++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/xtd.forms.native.wxwidgets/include/xtd/forms/native/wxwidgets/wx_picture_box.h b/src/xtd.forms.native.wxwidgets/include/xtd/forms/native/wxwidgets/wx_picture_box.h index 4ba17256defa..3673dbc345ee 100644 --- a/src/xtd.forms.native.wxwidgets/include/xtd/forms/native/wxwidgets/wx_picture_box.h +++ b/src/xtd.forms.native.wxwidgets/include/xtd/forms/native/wxwidgets/wx_picture_box.h @@ -6,6 +6,7 @@ /// @endcond #include "control_handler.h" +#include "wx_user_window.h" #include #include #include @@ -24,7 +25,9 @@ namespace xtd { private: explicit wx_picture_box(const xtd::forms::native::create_params& create_params) { if (!create_params.parent) throw xtd::argument_exception("control must have a parent"_t, csf_); - if ((create_params.style & SS_BITMAP_CENTER) == SS_BITMAP_CENTER) { + owner_draw_ = (create_params.style & SS_OWNERDRAW) == SS_OWNERDRAW; + if (owner_draw_) control_handler::create(reinterpret_cast(create_params.parent)->main_control(), wxID_ANY, wxPoint(create_params.location.x(), create_params.location.y()), wxSize(create_params.size.width(), create_params.size.height()), style_to_wx_user_window_style(create_params.style, create_params.ex_style)); + else if ((create_params.style & SS_BITMAP_CENTER) == SS_BITMAP_CENTER) { control_handler::create(reinterpret_cast(create_params.parent)->main_control(), wxID_ANY, wxNullBitmap, wxPoint(create_params.location.x(), create_params.location.y()), wxSize(create_params.size.width(), create_params.size.height()), style_to_wx_style(create_params.style, create_params.ex_style)); static_cast(control())->SetScaleMode(wxStaticBitmap::Scale_None); } else { @@ -59,7 +62,16 @@ namespace xtd { return wx_style; } + static long style_to_wx_user_window_style(size_t style, size_t ex_style) { + long wx_style = common_control_style_to_wx_style(style, ex_style); + + wx_style |= wxBORDER_NONE; + + return wx_style; + } + bool auto_size = false; + bool owner_draw_ = false; }; } } diff --git a/src/xtd.forms/src/xtd/forms/picture_box.cpp b/src/xtd.forms/src/xtd/forms/picture_box.cpp index 5a29aafac6dc..a2eae513f408 100644 --- a/src/xtd.forms/src/xtd/forms/picture_box.cpp +++ b/src/xtd.forms/src/xtd/forms/picture_box.cpp @@ -44,10 +44,9 @@ forms::border_sides picture_box::border_sides() const noexcept { } picture_box& picture_box::border_sides(forms::border_sides border_sides) { - if (data_->border_sides != border_sides) { - data_->border_sides = border_sides; - if (control_appearance() == forms::control_appearance::standard) invalidate(); - } + if (data_->border_sides == border_sides) return *this; + data_->border_sides = border_sides; + refresh(); return *this; } @@ -59,7 +58,7 @@ picture_box& picture_box::border_style(forms::border_style border_style) { if (this->border_style() == border_style) return *this; data_->border_style = border_style; if (is_handle_created() && control_appearance() == forms::control_appearance::system) post_recreate_handle(); - else invalidate(); + refresh(); return *this; } @@ -67,7 +66,7 @@ picture_box& picture_box::border_style(nullptr_t) { if (data_->border_style) return *this; data_->border_style.reset(); if (is_handle_created() && control_appearance() == forms::control_appearance::system) post_recreate_handle(); - else invalidate(); + refresh(); return *this; } @@ -80,16 +79,15 @@ picture_box& picture_box::image(const drawing::image& image) { if (image == drawing::image::empty) return this->image(nullptr); data_->image = image; if (is_handle_created() && control_appearance() == forms::control_appearance::system) native::picture_box::image(handle(), data_->image.value()); - else invalidate(); + refresh(); return *this; } picture_box& picture_box::image(std::nullptr_t) { - if (data_->image.has_value()) { - data_->image.reset(); - if (is_handle_created() && control_appearance() == forms::control_appearance::system) native::picture_box::reset(handle()); - else invalidate(); - } + if (!data_->image.has_value()) return *this; + data_->image.reset(); + if (is_handle_created() && control_appearance() == forms::control_appearance::system) native::picture_box::reset(handle()); + refresh(); return *this; } @@ -235,6 +233,8 @@ forms::create_params picture_box::create_params() const noexcept { else if (border_style() != forms::border_style::none) create_params.ex_style(create_params.ex_style() | WS_EX_CLIENTEDGE); } + if (control_appearance() != forms::control_appearance::system) create_params.style(create_params.style() | SS_OWNERDRAW); + switch (data_->size_mode) { case picture_box_size_mode::normal: create_params.style(create_params.style() | SS_BITMAP_NORMAL); break; case picture_box_size_mode::stretch_image: create_params.style(create_params.style() | SS_BITMAP_STRETCH); break;