how to get item from sizer...

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
roarek82
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sat Aug 26, 2006 2:40 am

how to get item from sizer...

Post by roarek82 » Wed Dec 27, 2006 1:11 am

I had function in file Sizers_wdr.cpp

Code: Select all

wxSizer *MyDialogFunc( wxWindow *parent, bool call_fit, bool set_sizer )
{
    wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item1 = new wxBoxSizer( wxHORIZONTAL );

    MyButton *item2 = new MyButton( parent, ID_BITMAPBUTTONG1, MyBitmapsFunc21( 6 ), wxDefaultPosition, wxSize(84,46) );
    item1->Add( item2, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item3 = new wxBitmapButton( parent, ID_BITMAPBUTTON, MyBitmapsFunc11( 5 ), wxDefaultPosition, wxDefaultSize );
    item1->Add( item3, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item4 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item4, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item5 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item5, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item6 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item6, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item7 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item7, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item8 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item8, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item9 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item9, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item10 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item10, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item11 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item11, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item12 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item12, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item13 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item13, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item14 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item14, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item15 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item15, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item16 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item16, 0, wxALIGN_CENTER|wxALL, 5 );

    wxButton *item17 = new wxButton( parent, ID_BITMAPBUTTON, wxT("No image"), wxDefaultPosition, wxDefaultSize );
    item1->Add( item17, 0, wxALIGN_CENTER|wxALL, 5 );

    item0->Add( item1, 0, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );

    wxBoxSizer *item18 = new wxBoxSizer( wxHORIZONTAL );

    wxBoxSizer *item19 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item20 = new wxBoxSizer( wxVERTICAL );

    wxBitmapButton *item21 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item21, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item22 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item22, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item23 = new RectangleButton( parent, ID_BITMAPBUTTONL1, MyBitmapsFunc21( 0 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item23, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item24 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item24->SetBackgroundColour( *wxBLUE );
    item20->Add( item24, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item25 = new RectangleButton( parent, ID_BITMAPBUTTONL2, MyBitmapsFunc21( 1 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item25, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item26 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item26, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item27 = new RectangleButton( parent, ID_BITMAPBUTTONL3, MyBitmapsFunc21( 2 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item27, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item28 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item28, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item29 = new RectangleButton( parent, ID_BITMAPBUTTONL4, MyBitmapsFunc21( 3 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item29, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item30 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item30, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item31 = new RectangleButton( parent, ID_BITMAPBUTTONL5, MyBitmapsFunc21( 4 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item31, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item32 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item32, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item33 = new RectangleButton( parent, ID_BITMAPBUTTONL6, MyBitmapsFunc21( 5 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item33, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item34 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item34, 0, wxALIGN_CENTER, 5 );

    RectangleButton *item35 = new RectangleButton( parent, ID_BITMAPBUTTONL7, MyBitmapsFunc21( 6 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item35, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item36 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item36, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item37 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item37, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item38 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item38, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item39 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item39, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item40 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item40, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item41 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item41, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item42 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item42, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item43 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item43, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item44 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,25), wxNO_3D );
    item20->Add( item44, 0, wxALIGN_CENTER, 5 );

    wxBitmapButton *item45 = new wxBitmapButton( parent, ID_BITMAPBUTTONL0, MyBitmapsFunc21( 7 ), wxDefaultPosition, wxSize(80,15), wxNO_3D );
    item20->Add( item45, 0, wxALIGN_CENTER, 5 );

    item19->Add( item20, 10, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );

    wxBoxSizer *item46 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item47 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item48 = new wxBoxSizer( wxHORIZONTAL );

    SmallButton *item49 = new SmallButton( parent, ID_BITMAPBUTTON1, MyBitmapsFunc12( 0 ), wxDefaultPosition, wxSize(20,20), wxNO_3D );
    item49->SetToolTip( wxT("Subiekt") );
    item49->SetName( wxT("l1") );
    item48->Add( item49, 0, wxALIGN_CENTER, 5 );

    SmallButton *item50 = new SmallButton( parent, ID_BITMAPBUTTON2, MyBitmapsFunc11( 1 ), wxDefaultPosition, wxSize(20,20), wxNO_3D );
    item50->SetToolTip( wxT("Sprzedaz") );
    item48->Add( item50, 0, wxALIGN_CENTER, 5 );

    SmallButton *item51 = new SmallButton( parent, ID_BITMAPBUTTON3, MyBitmapsFunc11( 2 ), wxDefaultPosition, wxSize(20,20), wxNO_3D );
    item51->SetToolTip( wxT("Detal") );
    item48->Add( item51, 0, wxALIGN_BOTTOM|wxALIGN_CENTER_HORIZONTAL, 5 );

    SmallButton *item52 = new SmallButton( parent, ID_BITMAPBUTTON4, MyBitmapsFunc11( 3 ), wxDefaultPosition, wxSize(20,20), wxNO_3D );
    item52->SetToolTip( wxT("Zakup") );
    item48->Add( item52, 0, wxALIGN_CENTER, 5 );

    item47->Add( item48, 0, wxALIGN_CENTER, 5 );

    item46->Add( item47, 1, wxGROW|wxALIGN_CENTER_VERTICAL, 5 );

    wxBoxSizer *item53 = new wxBoxSizer( wxVERTICAL );

    wxBoxSizer *item54 = new wxBoxSizer( wxHORIZONTAL );

    SmallButton *item55 = new SmallButton( parent, ID_BITMAPBUTTON5, MyBitmapsFunc11( 4 ), wxDefaultPosition, wxSize(20,20), wxNO_3D );
    item55->SetToolTip( wxT("Zam

User avatar
tierra
Site Admin
Site Admin
Posts: 1343
Joined: Sun Aug 29, 2004 7:14 pm
Location: Salt Lake City, Utah, USA
Contact:

Post by tierra » Wed Dec 27, 2006 5:08 am

You need to cast the wxWindow pointer returned from wxSizerItem::GetWindow() where wxSizerItem is found from wxSizer::GetItem(...).

But rather than doing that, you should assign each control a different window ID, then you can use FindWindow(ID) to get the window, and cast that.

roarek82
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sat Aug 26, 2006 2:40 am

Post by roarek82 » Wed Dec 27, 2006 9:45 pm

GetId() working good but its only number of ID wxBitmapButton or other controls but I cant control it...I want one thing.

if I click on button A , and I wanna to change Bitmap on button B

to do it I must catch wxBitmapButton , ID of wxBitmapButton dont help me...because I cant use SetBitmapLabel.

Anyone help?

roarek82
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sat Aug 26, 2006 2:40 am

Post by roarek82 » Wed Dec 27, 2006 11:14 pm

I check my code and I think problem is not there...
There is a function which I use when I clicked on button:

Code: Select all

void MyButton::OnButtonClick( wxMouseEvent &event)
{
    //item49->SetToolTip( wxT("SubiektZZZ") );
    
    int i,tmp;
    int j=0;
    
    
    wxImage bmp0x=GetBitmapLabel().ConvertToImage();
    //wxImage next=GetBitmapLabel()+1;
    unsigned char* tab1=bmp0x.GetData();
    while (j<8){
        tmp=0;
        wxImage bmp1x=MyBitmapsFunc11( j ).ConvertToImage();
        unsigned char* tab2=bmp1x.GetData();
        i=0;
        while (i<sizeof(tab1)){
            if (tab1[i]!=tab2[i]){
                tmp=1;
            } 
            i++;
        }
        if (tmp==0){nr=j;}
    //SetBitmapLabel(MyBitmapsFunc11(j));
    j++;
    }
    j=0;
        x=event.GetPosition().x;
        y=event.GetPosition().y;
        //event.GetItem();
        wxString x1,y1,z1;
		int id=GetId();
        x1 << x;
        y1 << y;
        z1 << id;
		
		
        
        if ((x>min_x) && (x<max_x) && (y>min_y) && (y<max_y)){
            
            SetBitmapLabel(MyBitmapsFunc12(nr));

			//numer=nr;
            wxMessageDialog dialog( this, wxT("x:"+x1+"y:"+y1+"z:"+z1),
            wxT("O programie"), wxOK|wxICON_INFORMATION );
            dialog.ShowModal();
			
        }
    
}
for example
when I clicked on buttonA , bitmap on buttonA was change but I want change also other bitmaps(for examples button B , C,D which is not click on the same time) So how to do it? when I use this function I can change bitmap on one button (which clicked) but other bitmap on other buttons I cant change. How to control it?

roarek82
Earned a small fee
Earned a small fee
Posts: 13
Joined: Sat Aug 26, 2006 2:40 am

Post by roarek82 » Fri Dec 29, 2006 1:02 am

any ideas?

JSThePatriot
Earned some good credits
Earned some good credits
Posts: 146
Joined: Sun Nov 26, 2006 7:37 am
Location: Tennessee, USA
Contact:

Post by JSThePatriot » Fri Dec 29, 2006 2:16 pm

Okay, I have a couple of possible solutions, but only one idea.

You need to declare your own set of ID's for those buttons. There are a couple of ways to do this.

Code: Select all

//Method 1
int ID_BTN_Bitmap01 = wxNewId();
int ID_BTN_Bitmap02 = wxNewId();

//Method 2
#define ID_BTN_Bitmap01 = 100501
#define ID_BTN_Bitmap02 = 100502

//Method 3
enum {
    ID_BTN_Bitmap01 = wxID_HIGHEST + 1,
    ID_BTN_Bitmap02
};
I hope this helps you in some way. Also if there is a better way of doing this that I have not listed above someone please let me know.

Edit: I just had an idea. Each control should have its own pointer. So what you could do is something like the following.

Code: Select all

//Method 1
m_BitmapButton01->GetId();
m_BitmapButton02->GetId();
You would need to use that code inside the function you are trying to use, but it should work to complete your needs.

Thanks,
JS

Post Reply