Skip to content

Commit

Permalink
Add owner draw param
Browse files Browse the repository at this point in the history
  • Loading branch information
gammasoft71 committed May 12, 2024
1 parent 9a8fcdf commit 5d014cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/// @endcond

#include "control_handler.h"
#include "wx_user_window.h"
#include <xtd/drawing/system_colors>
#include <xtd/forms/native/create_params>
#include <xtd/forms/native/static_styles>
Expand All @@ -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<wx_user_window>(reinterpret_cast<control_handler*>(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<wxStaticBitmap>(reinterpret_cast<control_handler*>(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<wxStaticBitmap*>(control())->SetScaleMode(wxStaticBitmap::Scale_None);
} else {
Expand Down Expand Up @@ -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;
};
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/xtd.forms/src/xtd/forms/picture_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -59,15 +58,15 @@ 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;
}

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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d014cb

Please sign in to comment.