Toolbar and wxIFM Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
forlognao2
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon May 23, 2005 3:39 pm

Toolbar and wxIFM

Post by forlognao2 »

How to create toolbar in applicaton using wxIFM?
When I do it in such way:

Code: Select all

wxToolBar *toolBar = new wxToolBar(frame, -1, wxDefaultPosition, wxDefaultSize,
        wxTB_FLAT | wxTB_DOCKABLE);
    toolBar->AddTool(MNU_FILE_NEW, new_xpm);
    toolBar->Realize();
    frame->SetToolBar(toolBar);
the toolbar is created correctly, but some elements of other controls are shifted (for exaple 'x' mark of child frames are displayed below its normal position). Also the main control of the frame is partially displayed on the statusbar.
I tried to place above code in different places (before and after creating wxIFM controls) but nothing works.[/code]
forlognao2
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon May 23, 2005 3:39 pm

Post by forlognao2 »

Do you have the same problem?
Can you show me a piece of code which creates a toolbar in your application?
User avatar
kolo
Earned some good credits
Earned some good credits
Posts: 120
Joined: Tue Jun 21, 2005 1:19 pm
Location: Russia, Cheboksary
Contact:

Post by kolo »

in your main frame constructor or init function you can try put that piece of code :)

Code: Select all

	wxBitmap bit(32,32);
	wxIcon ico = wxICON(sample);	
	bit.CopyFromIcon(ico);	

	wxToolBar *tb;
	tb =  CreateToolBar( wxTB_FLAT|wxTB_HORIZONTAL|wxTB_TEXT|wxTB_NODIVIDER, 2000);
	tb->SetToolBitmapSize(wxSize(32, 32));
	tb->AddTool(2500, wxT("   Tool1   "), bit);
	tb->AddTool(2501, wxT("   Tool2   "),bit);
	tb->AddCheckTool(2502, wxT("   Tool3   "), bit);
        tb->Realize();
	SetToolBar(tb);
where sample really icon in your *.rc file
only MSW & MSVS ))
forlognao2
Knows some wx things
Knows some wx things
Posts: 31
Joined: Mon May 23, 2005 3:39 pm

Post by forlognao2 »

This is my window without a toolbar:
Image

and that is my window with a toolbar:
Image

The red color is the background of the frame.

code (placed in the constructor of the frame):

Code: Select all

wxBitmap bit(exefile_xpm); //icon taken from /art
wxToolBar *tb;
tb =  CreateToolBar( wxTB_FLAT|wxTB_HORIZONTAL|wxTB_TEXT|wxTB_NODIVIDER, 2000);
tb->SetToolBitmapSize(wxSize(16, 16));
tb->AddTool(2500, wxT("   Tool1   "), bit);
tb->AddTool(2501, wxT("   Tool2   "),bit);
tb->Realize();
SetToolBar(tb);
The toolbar looks ok without wxIFM and with only the main control. I initialize wxIFM in the same way as it is done in wxIFM demo (after the above code, in the constructor of the frame).

Has wxIFM got a problem with toolbars? Could anyone (kolo?) show a whole frame constructor with initialization of the wxIFM and toolbar?
SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am

Post by SnakeChomp »

This is either a problem with wxWidgets or with wxIFM. I am investigating this now.
SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am

Post by SnakeChomp »

Unfortunately, this is caused by a design problem in wxWidgets. The Frame offsets the client area when it is managing a toolbar and moves the position of (0,0) within the client area. When painting to the frames DC however, (0,0) is in a different spot. wxIFM assumes that (0,0) on the DC is in the same spot as (0,0) in its client area, which is untrue. The fact that wxFrame messes up the client area so much completely confuses wxIFM which causes the errors that you see. Its going to be really anoying to fix properly, because there is no way to add a global offset to children or painting within wxIFM, and all of its positioning code relies on the fact that (0,0) in a DC is in the same spot as (0,0) in the client area.
ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Post by ssigala »

SnakeChomp wrote:Its going to be really anoying to fix properly, because there is no way to add a global offset to children or painting within wxIFM, and all of its positioning code relies on the fact that (0,0) in a DC is in the same spot as (0,0) in the client area.
This means that standard wx toolbars are not supported and a new wxIFM compatible toolbar widget is needed?
Sandro Sigala - Kynosoft, Brescia
SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am

Post by SnakeChomp »

It means that wxFrame is doing stupid things which confuses wxIFM. The real fix is to fix wxFrame, but it would be backwards incompatible and I know the wx guys would never agree to it. I'm looking into hacking wxIFM to work around the defect in wxFrame.
arucard
Experienced Solver
Experienced Solver
Posts: 61
Joined: Tue Dec 28, 2004 10:16 am
Location: Czech rep.

Post by arucard »

In my program I use wxIFM with toolbars without problems. I use following approach:

- in the main frame is a vertical sizer which contains toolbar (or another horizontal sizer with more toolbars) and thePanel

- when I initialize wxIFM I call its constructor with thePanel

- then when I add some childs or set the content window, I create these windows with thePanel as parent

And everything works fine
wxWidgets 2.8.4, winxp, VC2003 and above
SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am

Workaround

Post by SnakeChomp »

Ok, I have thought of a workaround for this problem. If you create a wxPanel as the only child of the wxFrame, and tell wxIFM to manage this panel, everything will work fine. Position (0,0) on the panels client area is in the same location as position (0,0) in the panels client DC, so wxIFM will behave. I have tested this locally with the wxIFM sample and it works just fine. The only thing that won't work is the wxInterfaceManager::SetStatusMessagePane and related functions. To use them, the window that wxIFM is managing must be a wxFrame. This is an oversight on my part and will be corrected in a future release; you will give wxIFM a pointer to the toolbar to use for status messages as well as telling it what status pane.

www.snakesoft.net/wxifm/images/wxifm_toolbar.png
arucard
Experienced Solver
Experienced Solver
Posts: 61
Joined: Tue Dec 28, 2004 10:16 am
Location: Czech rep.

Post by arucard »

Looks like we have both the same idea in the same time :)
wxWidgets 2.8.4, winxp, VC2003 and above
vasek
Experienced Solver
Experienced Solver
Posts: 77
Joined: Wed Jul 27, 2005 2:52 pm
Location: Ostrava, Czech Republic
Contact:

Post by vasek »

Great! But is the toolbar dockable? Your screenshot doesn't say so :)
SnakeChomp
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 235
Joined: Sun Oct 10, 2004 2:53 am

Post by SnakeChomp »

vasek wrote:Great! But is the toolbar dockable? Your screenshot doesn't say so :)
No. This would just be a regular wx toolbar. wxIFM does not support dockable toolbars in a way I am satisfied with so as far as I am concerned it does not support dockable toolbars.
Post Reply