wxToolBar::GetToolSize() broken on wxGTK2.8.6?

Volker Bartheld dr_versaeg at freenet.de
Wed Oct 10 08:08:11 PDT 2007


Hi!

I have found that unter wxGTK2.8.6 wxToolBar::GetToolSize()
doesn't return the value I expect. The docu
(http://www.wxwidgets.org/manuals/stable/wx_wxtoolbar.html#wxtoolbargettoolsize)
says:

"[...] wxSize GetToolSize()
Returns the size of a whole button, which is usually larger
than a tool bitmap because of added 3D effects. [...]"

Running the little program [1] below will result in bmpsize==wxSize(32, 32)
and tbartoolsize==wxSize(48, 52) unter wxMSW2.8.6 with WinXP, "classic theme",
but wxGTK returns tbartoolsize==wxSize(32, 32) which is just the size of
the image - not the button.

Is that supposed to be that way?

Of course, I could do some calculations like
tbarsize.y/pToolBar->GetToolsCount(), but that won't take into account
separators, margins etc., so I'm hesitant to use it.

Is that a bug or am I missing something?

Thanks a lot in advance and have a nice day!

Volker



[1]
<toolbartest.cpp>
#include <wx/toolbar.h>
#include <wx/frame.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <wx/sizer.h>
#include <wx/app.h>

static const char *sample_xpm[] = {
  "32 32 6 1",
  "  c black",
  ". c navy",
  "X c red",
  "o c yellow",
  "O c gray100",
  "+ c None",
  /* pixels */
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++              ++++++++++",
  "++++++++ ............ ++++++++++",
  "++++++++ ............ ++++++++++",
  "++++++++ .OO......... ++++++++++",
  "++++++++ .OO......... ++++++++++",
  "++++++++ .OO......... ++++++++++",
  "++++++++ .OO......              ",
  "++++++++ .OO...... oooooooooooo ",
  "         .OO...... oooooooooooo ",
  " XXXXXXX .OO...... oOOooooooooo ",
  " XXXXXXX .OO...... oOOooooooooo ",
  " XOOXXXX ......... oOOooooooooo ",
  " XOOXXXX ......... oOOooooooooo ",
  " XOOXXXX           oOOooooooooo ",
  " XOOXXXXXXXXX ++++ oOOooooooooo ",
  " XOOXXXXXXXXX ++++ oOOooooooooo ",
  " XOOXXXXXXXXX ++++ oOOooooooooo ",
  " XOOXXXXXXXXX ++++ oooooooooooo ",
  " XOOXXXXXXXXX ++++ oooooooooooo ",
  " XXXXXXXXXXXX ++++              ",
  " XXXXXXXXXXXX ++++++++++++++++++",
  "              ++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++",
  "++++++++++++++++++++++++++++++++"
};

// ----------------------------------------------------------------------------
// main frame
// ----------------------------------------------------------------------------
class MyFrame : public wxFrame
{
public:
  MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title)
  {
    wxImage::AddHandler(new wxXPMHandler);

    SetIcon(wxICON(sample));
    wxSizer *pMainSizer=new wxBoxSizer(wxHORIZONTAL);
    SetSizer(pMainSizer);

    wxBitmap bmp_xpm(sample_xpm);
    wxSize bmpsize=wxSize(bmp_xpm.GetWidth(), bmp_xpm.GetHeight());
    wxToolBar* pToolBar=new wxToolBar(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxNO_BORDER|wxTB_VERTICAL|wxTB_TEXT|wxTB_FLAT|wxTB_NODIVIDER);
    pToolBar->SetToolBitmapSize(bmpsize);
    for(int i=0; i<5; ++i) pToolBar->AddTool(i, wxString::Format(wxT("Button %i"), i), bmp_xpm, wxString(wxEmptyString), wxITEM_RADIO);

    pToolBar->Realize();
    pToolBar->Fit();

    wxSize tbarsize=pToolBar->GetSize(), tbartoolsize=pToolBar->GetToolSize();
    pMainSizer->Add(pToolBar);
    pMainSizer->SetSizeHints(this);
    Layout();
  }
}; // class MyFrame : public wxFrame

// ----------------------------------------------------------------------------
// the application
// ----------------------------------------------------------------------------
class MyApp : public wxApp
{
public:
  virtual bool OnInit()
  {
    if(!wxApp::OnInit()) return false;
    MyFrame *frame=new MyFrame(_T("Minimal wxWidgets App"));
    frame->Show(true);
    return true;
  }
}; // class MyApp : public wxApp
IMPLEMENT_APP(MyApp)
</toolbartest.cpp>


-- 
mailto:  V B A R T H E L D at G M X dot D E






More information about the wx-users mailing list