Skip to content

Commit

Permalink
Merge pull request #1382 from KeyWorksRW/ribbon_mockup
Browse files Browse the repository at this point in the history
Fix image size display in wxRibbon tools and buttons
  • Loading branch information
Randalphwa authored Jan 15, 2024
2 parents 23fcaa8 + c610536 commit be4600b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions src/generate/gen_ribbon_button.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/////////////////////////////////////////////////////////////////////////////
// Purpose: wxRibbonBar -- form and regular
// Author: Ralph Walden
// Copyright: Copyright (c) 2020-2023 KeyWorks Software (Ralph Walden)
// Copyright: Copyright (c) 2020-2024 KeyWorks Software (Ralph Walden)
// License: Apache License -- see ../../LICENSE
/////////////////////////////////////////////////////////////////////////////

Expand All @@ -11,6 +11,7 @@
#include "code.h" // Code -- Helper class for generating code
#include "gen_common.h" // GeneratorLibrary -- Generator classes
#include "image_gen.h" // Functions for generating embedded images
#include "mainframe.h" // MainFrame -- Main window frame
#include "node.h" // Node class
#include "utils.h" // Utility functions that work with properties

Expand All @@ -32,11 +33,13 @@ void RibbonButtonBarGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxp

for (const auto& child: node->getChildNodePtrs())
{
auto bmp = child->as_wxBitmap(prop_bitmap);
if (!bmp.IsOk())
auto bundle = child->as_wxBitmapBundle(prop_bitmap);
wxBitmap bmp;
if (bundle.IsOk())
bmp = bundle.GetBitmapFor(wxGetMainFrame()->getWindow());
else
bmp = GetInternalImage("default");

// REVIEW: This is still a bitmap rather then a bundle as of the 3.1.6 release
btn_bar->AddButton(wxID_ANY, child->as_wxString(prop_label), bmp, child->as_wxString(prop_help),
(wxRibbonButtonKind) child->as_int(prop_kind));
}
Expand Down
16 changes: 9 additions & 7 deletions src/generate/gen_ribbon_tool.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/////////////////////////////////////////////////////////////////////////////
// Purpose: wxRibbonToolBar generator
// Author: Ralph Walden
// Copyright: Copyright (c) 2020-2023 KeyWorks Software (Ralph Walden)
// Copyright: Copyright (c) 2020-2024 KeyWorks Software (Ralph Walden)
// License: Apache License -- see ../../LICENSE
/////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -36,7 +36,7 @@ wxObject* RibbonToolBarGenerator::CreateMockup(Node* node, wxObject* parent)

void RibbonToolBarGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxparent*/, Node* node, bool /* is_preview */)
{
auto btn_bar = wxDynamicCast(wxobject, wxRibbonToolBar);
auto btn_bar = wxStaticCast(wxobject, wxRibbonToolBar);

for (const auto& child: node->getChildNodePtrs())
{
Expand All @@ -46,12 +46,14 @@ void RibbonToolBarGenerator::AfterCreation(wxObject* wxobject, wxWindow* /*wxpar
}
else
{
auto bmp = child->as_wxBitmap(prop_bitmap);
if (!bmp.IsOk())
auto bundle = child->as_wxBitmapBundle(prop_bitmap);
wxBitmap bmp;
if (bundle.IsOk())
bmp = bundle.GetBitmapFor(wxGetMainFrame()->getWindow());
else
bmp = GetInternalImage("default");
auto scaled_bmp = child->as_wxBitmapBundle(prop_bitmap).GetBitmap(wxGetMainFrame()->FromDIP(bmp.GetSize()));
btn_bar->AddTool(wxID_ANY, scaled_bmp, child->as_wxString(prop_help),
(wxRibbonButtonKind) child->as_int(prop_kind));

btn_bar->AddTool(wxID_ANY, bmp, child->as_wxString(prop_help), (wxRibbonButtonKind) child->as_int(prop_kind));
}
}
btn_bar->Realize();
Expand Down

0 comments on commit be4600b

Please # to comment.