I'm tryin' to create a toolbar as in image below.
This image was taken from DialogBlocks, this is the compiled one:
I believe that was a DialogBlocks fault so I contact Dialog Block's author for answers.
He gently answer me that it's unusual to have static text controls and wxButtons in a toolbar but in theory it should be possible;
also it's unusual having toolbars in dialogs, but again sizers should in theory be able to cope.
So I'll try to create a toolbar from scratch using a panel and stardard controls but I've failed.
I'm in trouble with sizer stuff (and wxWidgets in general )
As you can see there are some bugs:
- the panel do not extend to width of frame
- the wxStaticLine is not showed ( there's a small pixel on the left of X button)
- the list do not appears at all ( should be just below the panel )
How can I fix that ?
I haven't understand sizers ( and I've read about it from documentation and some tutorials)
For example, if I create an horizontal wxBoxSize and add two buttons on it,
one with wxLEFT style, the other with wxRIGHT style.
Why if I resize window, the right button do not move ?
I expect that right button should be aligned with width of window.
Thank you,
this is the code I use for toolbar stuff:
Code: Select all
wxBoxSizer* vSizer = new wxBoxSizer(wxVERTICAL);
frame->SetSizer(vSizer);
wxPanel* toolbar = new wxPanel(this, ID_TOOLBAR);
toolbar->SetFont(*g_ToolbarFont);
vSizer->Add(toolbar);
wxBoxSizer* hSizer = new wxBoxSizer(wxHORIZONTAL);
toolbar->SetSizer(hSizer);
wxBitmapButton* btnNew = new wxBitmapButton(toolbar, ID_TOOL_NEW, newBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
hSizer->Add(btnNew, 0, wxALIGN_CENTER_VERTICAL, 0);
wxBitmapButton* btnModify = new wxBitmapButton(toolbar, ID_TOOL_MODIFY, modifyBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
hSizer->Add(btnModify, 0, wxALIGN_CENTER_VERTICAL, 0);
wxBitmapButton* btnErase = new wxBitmapButton(toolbar, ID_TOOL_ERASE, eraseBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
hSizer->Add(btnErase, 0, wxALIGN_CENTER_VERTICAL, 0);
wxStaticLine* line1 = new wxStaticLine(toolbar, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL);
hSizer->Add(line1, 0, wxALIGN_CENTER_VERTICAL, 10);
wxStaticText* form_text = new wxStaticText(toolbar, wxID_STATIC, _(" Item: "), wxDefaultPosition, wxDefaultSize, 0 );
hSizer->Add(form_text, 0, wxALIGN_CENTER_VERTICAL, 5);
m_comboList = new wxComboBox(toolbar, ID_COMBO_LIST, szComboListContent[g_combo_list_idx], wxDefaultPosition, wxSize(100, -1), WXSIZEOF(szComboListContent), szComboListContent, wxCB_READONLY|wxTE_PROCESS_ENTER);
hSizer->Add(m_comboList, 0, wxALIGN_CENTER_VERTICAL, 5);
wxStaticText* search_text = new wxStaticText(toolbar, wxID_STATIC, _(" Find "), wxDefaultPosition, wxDefaultSize, 0 );
hSizer->Add(search_text, 0, wxALIGN_CENTER_VERTICAL, 5);
wxTextCtrl* search = new wxTextCtrl(toolbar, ID_SEARCH_TXT, wxEmptyString, wxDefaultPosition, wxSize(150, -1), wxTE_PROCESS_ENTER);
hSizer->Add(search, 0, wxALIGN_CENTER_VERTICAL, 5);
wxStaticText* search_in = new wxStaticText(toolbar, wxID_STATIC, _(" in "), wxDefaultPosition, wxDefaultSize, 0 );
hSizer->Add(search_in, 0, wxALIGN_CENTER_VERTICAL, 5);
m_comboSearch = new wxComboBox(toolbar, ID_COMBO_SEARCH, szComboSearchItemContent[g_combo_search_idx], wxDefaultPosition, wxSize(200, -1), 0, NULL, wxCB_READONLY|wxTE_PROCESS_ENTER);
hSizer->Add(m_comboSearch, 0, wxALIGN_CENTER_VERTICAL, 5);
wxBitmapButton* btnSearch = new wxBitmapButton(toolbar, ID_SEARCH_BTN, wxNullBitmap, wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW );
hSizer->Add(btnSearch, 0, wxALIGN_CENTER_VERTICAL, 5);
// list
{
wxBitmap bmps[2];
wxArrayString pngs;
bmps[0] = wxBitmap(GetBitmapFromMemory(plus_png, LOGO_PNG_SIZE, wxBITMAP_TYPE_PNG));
bmps[1] = wxBitmap(GetBitmapFromMemory(minus_png, LOGO_PNG_SIZE, wxBITMAP_TYPE_PNG));
pngs.reserve(2);
pngs.Add("plus.png");
pngs.Add("minus.png");
m_list = new HtmlListBoxEx(frame, ID_LIST, bmps, pngs);
m_list->SetBackgroundColour(LIST_BACK_COLOR);
m_list->SetSelectionBackground(LIST_SELECTION_COLOR);
vSizer->Add(m_list);
}