Page 1 of 1

I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Jul 14, 2018 7:11 am
by lfjking
I want to move a wxStaticBitmap from frame to another Dialog, how to do?

frame:

Code: Select all

///////////////////////////////////////////////////////////////////////////////
/// Class MyFrame.h
///////////////////////////////////////////////////////////////////////////////
#include "MyDialog.h"
class MyFrame : public wxFrame 
{
	private:
	
	protected:
		wxScrolledWindow* m_scrolledWindow;
		wxStaticBitmap* m_bitmap;
		MyDialog* 		 m_dialog;
	public:
		
		MyFrame( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,300 ), long style = wxDEFAULT_FRAME_STYLE|wxTAB_TRAVERSAL );
		wxAuiManager m_mgr;
		
		~MyFrame();
	
};
/// Class MyFrame.cpp
MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	m_mgr.SetManagedWindow(this);
	m_mgr.SetFlags(wxAUI_MGR_DEFAULT);
	
	m_scrolledWindow = new wxScrolledWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHSCROLL|wxVSCROLL );
	m_scrolledWindow->SetScrollRate( 5, 5 );
	m_mgr.AddPane( m_scrolledWindow, wxAuiPaneInfo() .Center() .PinButton( true ).Dock().Resizable().FloatingSize( wxDefaultSize ) );
	
	wxGridSizer* gSizer;
	gSizer = new wxGridSizer( 0, 2, 0, 0 );
	
	m_bitmap = new wxStaticBitmap( m_scrolledWindow, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
	gSizer->Add( m_bitmap, 0, wxALL, 5 );
	
	
	m_scrolledWindow->SetSizer( gSizer );
	m_scrolledWindow->Layout();
	gSizer->Fit( m_scrolledWindow );
	
	m_dialog = new MyDialog(this);
	
	m_mgr.Update();
	this->Centre( wxBOTH );
}

MyFrame::~MyFrame()
{
	m_mgr.UnInit();
	
}
and the Dialog:

Code: Select all

///////////////////////////////////////////////////////////////////////////////
/// Class MyDialog.h
///////////////////////////////////////////////////////////////////////////////
class MyDialog : public wxDialog 
{
	private:
	
	protected:
	
	public:
		
		MyDialog( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = wxEmptyString, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); wxAuiManager m_mgr;
		
		~MyDialog();
	
};
/// Class MyDialog.cpp
MyDialog::MyDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	m_mgr.SetManagedWindow(this);
	m_mgr.SetFlags(wxAUI_MGR_DEFAULT);
	
	
	m_mgr.Update();
	this->Centre( wxBOTH );
}

MyDialog::~MyDialog()
{
	m_mgr.UnInit();
	
}

now ,how can I put the m_bitmap ( wxStaticBitmap ) from the MyFrame to the MyDialog?

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Jul 14, 2018 8:37 am
by doublemax
It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Jul 14, 2018 8:56 am
by lfjking
doublemax wrote:It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.
sorry , I use the wrong fun setParent .
I can switch normally after using Reparent
:D
thanks!

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Fri Nov 09, 2018 6:56 pm
by lfjking
doublemax wrote:It's not totally clear to me what you want to do. If you just want to display the same bitmap in another window, i would suggest to just create a new wxStaticBitmap based on the same bitmap. Everything else would be unnecessarily complicated.
the project same as this head page that I define
One of my classes is inherited from wxStaticBitmap, I call it myStBitmap.
I have to move him to work.
I can move him out. But when I tried to move him back, he warned:

Code: Select all

wxCHECK_RET( !m_containingSizer,
                     wxS("Adding a window already in a sizer, detach it first!") );
I don't know how to eliminate this warning.

I move the myStBitmap detach from the sizer first ,then Reparent the parent window. and move back too.

help me , please ! thanks.

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Nov 10, 2018 5:35 am
by lfjking
I check the code follow the breaking_point, I get the warried code:

Code: Select all

wxSizerItem* wxSizer::DoInsert( size_t index, wxSizerItem *item )
{
    m_children.Insert( index, item );

    if ( item->GetWindow() )
        item->GetWindow()->SetContainingSizer( this );

    if ( item->GetSizer() )
        item->GetSizer()->SetContainingWindow( m_containingWindow );

    return item;
}
Now I try to do like this:

Code: Select all

gSizer->Detach(myStBitmap);
if(m_is_away)
{
myStBitmap->Reparent(new_parent);
}
else{
myStBitmap->SetContainingSizer(NULL);//must set NULL, off warning !
myStBitmap->Reparent(this);
gSizer->Add(myStBitmap);
}



Then the warning was removed.

I don't know the SetContainingSizer what to do and why?
who can help me to understand it ?

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Nov 10, 2018 7:41 am
by Kvaz1r
lfjking wrote: I don't know the SetContainingSizer what to do and why?
According to documentation:
This normally does not need to be called by user code.

It is called when a window is added to a sizer, and is used so the window can remove itself from the sizer when it is destroyed.

Re: I want to move a wxStaticBitmap from frame to another Dialog, how to do?

Posted: Sat Nov 10, 2018 8:22 am
by lfjking
Kvaz1r wrote:
lfjking wrote: I don't know the SetContainingSizer what to do and why?
According to documentation:
This normally does not need to be called by user code.

It is called when a window is added to a sizer, and is used so the window can remove itself from the sizer when it is destroyed.
I follow the debug one by one. I know why! haha @!~
look at here

Code: Select all

// a frame member
wxframe* m_frame1;
wxAuiManager m_mgr;

// another frame member
wxframe* m_frame2;
wxSizer* m_sizer;

// a panel;
wxPanel* m_panel;

//do :
 m_frame2->SetSizer(m_sizer);
 m_sizer->Add(m_panel);
 Layout();
 
 //put m_panel to  m_frame1
 m_sizer->Detach(m_panel );
 m_panel->Reparent( m_frame1);
 m_mgr.AddPane(m_panel );
 m_mgr.UpData();
 
  //put back the m_panel  to  m_frame2
/***the worry code:****/
   m_mgr.DetachPane( m_panel);
 m_panel->Reparent( m_frame2);
   m_sizer->Add(m_panel);	               //here  worried
   m_frame2->Layout();
 m_mgr.UpData();
/***the ok code:****/
   m_mgr.DetachPane( m_panel);
   m_mgr.UpData();				//m_panel still inside the m_mgr if not call  Updata() first.
 m_panel->Reparent( m_frame2);
   m_sizer->Add(m_panel);	
   m_frame2->Layout();

This is the problem that plagued me for many days.
Now it is finally settled.
I can sleep well.