Opened 6 months ago

Last modified 2 weeks ago

#17972 new defect

wxChoice missing from wxToolbar when added to wxAuiManager

Reported by: obfuscated Owned by:
Priority: normal Milestone:
Component: wxAui Version: dev-latest
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

I discovered that all choice controls are missing from our toolbars in Code::Blocks when I build it for OSX.

I'm using wx3.1, but the problem happens in master, too.
See the attached patch for the auidemo which demonstrates the problem.
The wxChoice in wxTooblar when not added to wxAui works correctly.

I've not tried any other versions, so I don't know if it works in some version.

Attachments (1)

auidemo_no_choice_in_toolbar.patch download (1.2 KB) - added by obfuscated 6 months ago.
patch for the auidemo

Download all attachments as: .zip

Change History (17)

Changed 6 months ago by obfuscated

patch for the auidemo

comment:1 Changed 6 months ago by obfuscated

  • Cc fuscated@… added

Any info about this one? Can someone confirm that this issue exists not only on my machine.

What would be the steps to try to debug it? Where should I put a breakpoint?

comment:2 Changed 5 months ago by obfuscated

  • Cc fuscated@… removed

Ping?

comment:3 Changed 5 months ago by pcor

With GTK3, the wxChoice is initially visible, but if I click on it, it disappears.

comment:4 Changed 5 months ago by pcor

The problem on GTK3 turns out to be that wxChoice::DoGetBestSize() doesn't work very well, the wxChoice ends up bigger than expected and doesn't fit in the available space, so wxToolBar doesn't show it. The problem on OSX might be similar, possibly triggered by this change: b1a19e6b6c9.

Regardless of whether this particular issue can be fixed, it looks to me like having AUI manage a native toolbar may not work all that well.

comment:5 Changed 3 months ago by vadz

  • Blocked By 18043 added

comment:6 Changed 3 months ago by pcor

  • Blocked By 18043 removed

comment:7 Changed 3 months ago by ufospoke

  • Blocked By 18043 added

comment:8 Changed 3 months ago by pcor

  • Blocked By 18043 removed

comment:9 Changed 3 months ago by pcor

Looking at this further (with wxGTK), the problem is actually that a native container isn't going to use our GetBestSize(). The correct size will be automatically set by the wxChoice ctor, if you use the form which takes all the strings as an wxArrayString. Otherwise, you'll have to call choice->SetInitialSize() yourself, after all the strings have been added.

comment:10 Changed 3 months ago by obfuscated

  • Cc fuscated@… added

Can you post a patch for the sample that works for you on GTK3, so I can test it on macOS?

comment:11 Changed 3 months ago by pcor

ctor method:

diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp
index f165a1e22b..6833ab6ad0 100644
--- a/samples/aui/auidemo.cpp
+++ b/samples/aui/auidemo.cpp
@@ -834,7 +834,7 @@ MyFrame::MyFrame(wxWindow* parent,
     tb3->Realize();
 
 
-    wxAuiToolBar* tb4 = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+    wxToolBar* tb4 = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                                          wxAUI_TB_DEFAULT_STYLE |
                                          wxAUI_TB_OVERFLOW |
                                          wxAUI_TB_TEXT |
@@ -850,11 +850,10 @@ MyFrame::MyFrame(wxWindow* parent,
     tb4->AddTool(ID_SampleItem+27, wxT("Item 6"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+28, wxT("Item 7"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+29, wxT("Item 8"), tb4_bmp1);
-    tb4->SetToolDropDown(ID_DropDownToolbarItem, true);
-    tb4->SetCustomOverflowItems(prepend_items, append_items);
-    wxChoice* choice = new wxChoice(tb4, ID_SampleItem+35);
-    choice->AppendString(wxT("One choice"));
-    choice->AppendString(wxT("Another choice"));
+    wxArrayString choices;
+    choices.Add("One choice");
+    choices.Add("Another choice");
+    wxChoice* choice = new wxChoice(tb4, ID_SampleItem+35, wxDefaultPosition, wxDefaultSize, choices);
     tb4->AddControl(choice);
     tb4->Realize();
 

SetInitialSize() method:

diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp
index f165a1e22b..26aac205cc 100644
--- a/samples/aui/auidemo.cpp
+++ b/samples/aui/auidemo.cpp
@@ -834,7 +834,7 @@ MyFrame::MyFrame(wxWindow* parent,
     tb3->Realize();
 
 
-    wxAuiToolBar* tb4 = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+    wxToolBar* tb4 = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                                          wxAUI_TB_DEFAULT_STYLE |
                                          wxAUI_TB_OVERFLOW |
                                          wxAUI_TB_TEXT |
@@ -850,11 +850,10 @@ MyFrame::MyFrame(wxWindow* parent,
     tb4->AddTool(ID_SampleItem+27, wxT("Item 6"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+28, wxT("Item 7"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+29, wxT("Item 8"), tb4_bmp1);
-    tb4->SetToolDropDown(ID_DropDownToolbarItem, true);
-    tb4->SetCustomOverflowItems(prepend_items, append_items);
     wxChoice* choice = new wxChoice(tb4, ID_SampleItem+35);
     choice->AppendString(wxT("One choice"));
     choice->AppendString(wxT("Another choice"));
+    choice->SetInitialSize();
     tb4->AddControl(choice);
     tb4->Realize();
 

comment:12 Changed 3 months ago by obfuscated

  • Cc fuscated@… removed

Thanks.

I've tried both variants but none fixed the problem.
I've also reverted b1a19e6b6c9 and it didn't fix the problem, too.. :(

I'm still at be35405129932325a506bc27064bff2dcb76a4ad if this matters.

comment:13 Changed 3 months ago by pcor

Does it work if you set a fixed width for the wxChoice?

diff --git a/samples/aui/auidemo.cpp b/samples/aui/auidemo.cpp
index f165a1e22b..62e01059b4 100644
--- a/samples/aui/auidemo.cpp
+++ b/samples/aui/auidemo.cpp
@@ -834,7 +834,7 @@ MyFrame::MyFrame(wxWindow* parent,
     tb3->Realize();
 
 
-    wxAuiToolBar* tb4 = new wxAuiToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+    wxToolBar* tb4 = new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
                                          wxAUI_TB_DEFAULT_STYLE |
                                          wxAUI_TB_OVERFLOW |
                                          wxAUI_TB_TEXT |
@@ -850,9 +850,7 @@ MyFrame::MyFrame(wxWindow* parent,
     tb4->AddTool(ID_SampleItem+27, wxT("Item 6"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+28, wxT("Item 7"), tb4_bmp1);
     tb4->AddTool(ID_SampleItem+29, wxT("Item 8"), tb4_bmp1);
-    tb4->SetToolDropDown(ID_DropDownToolbarItem, true);
-    tb4->SetCustomOverflowItems(prepend_items, append_items);
-    wxChoice* choice = new wxChoice(tb4, ID_SampleItem+35);
+    wxChoice* choice = new wxChoice(tb4, ID_SampleItem+35, wxDefaultPosition, wxSize(200, -1));
     choice->AppendString(wxT("One choice"));
     choice->AppendString(wxT("Another choice"));
     tb4->AddControl(choice);

comment:14 Changed 3 months ago by obfuscated

  • Cc fuscated@… added

Passing non-default size to the choice's c-tor doesn't help either. :(

comment:15 Changed 3 weeks ago by obfuscated

  • Cc fuscated@… removed

A users on the Code::Blocks forum suggested this fix:
http://forums.codeblocks.org/index.php/topic,21625.msg152848.html#msg152848

Another user confirmed that the fix works with wx3.1.1 but not with wx3.0.4
http://forums.codeblocks.org/index.php/topic,21625.msg153378.html#msg153378

Opinions?

comment:16 Changed 2 weeks ago by vadz

I don't see anything really wrong with hiding the old control in SetToolbarItemRef(), before replacing it, but I'm not sure if it's really needed neither...

The new control is supposed to be shown from -(NSToolbarItem*)toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar: AFAICS, I wonder if it's not being called for some reason?

Note: See TracTickets for help on using tickets.