@@ -518,7 +518,6 @@ void REHex::ToolDock::OnMotion(wxMouseEvent &event)
518518 if (dest_notebook->GetPageCount () == 1 )
519519 {
520520 ResetNotebookSize (dest_notebook);
521- dest_notebook->Show ();
522521 }
523522
524523 if (frame != NULL )
@@ -550,45 +549,64 @@ void REHex::ToolDock::OnMotion(wxMouseEvent &event)
550549 frame->SetPosition (frame_pos);
551550 frame->Show ();
552551
553- ToolPanel *tool = m_left_down_tool ;
552+ frame-> Bind (wxEVT_CLOSE_WINDOW, &REHex::ToolDock::OnFrameClose, this ) ;
554553
555- #if 0
556- frame->Bind(wxEVT_ICONIZE, [this, frame, tool](wxIconizeEvent &event)
554+ m_tool_frames.emplace (m_left_down_tool, frame);
555+ }
556+ }
557+ }
558+
559+ event.Skip ();
560+ }
561+
562+ void REHex::ToolDock::OnFrameClose (wxCloseEvent &event)
563+ {
564+ ToolFrame *frame = (ToolFrame*)(event.GetEventObject ());
565+
566+ ToolPanel *tool = frame->GetTool ();
567+ if (tool != NULL )
568+ {
569+ frame->RemoveTool (tool);
570+
571+ ToolNotebook *dest_notebook = NULL ;
572+
573+ switch (tool->shape ())
574+ {
575+ case ToolPanel::Shape::TPS_WIDE:
576+ if (m_bottom_notebook->GetPageCount () > 0 || m_top_notebook->GetPageCount () == 0 )
557577 {
558- if(event.IsIconized())
559- {
560- tool->Reparent(m_right_notebook);
561- m_right_notebook->AddPage(tool, tool->name(), true);
562-
563- m_tool_frames.erase(tool);
564- frame->Destroy();
565- }
566- });
567- #endif
578+ dest_notebook = m_bottom_notebook;
579+ }
580+ else {
581+ dest_notebook = m_top_notebook;
582+ }
583+
584+ break ;
568585
569- frame->Bind (wxEVT_CLOSE_WINDOW, [this , frame, tool](wxCloseEvent &event)
586+ case ToolPanel::Shape::TPS_TALL:
587+ if (m_right_notebook->GetPageCount () > 0 || m_left_notebook->GetPageCount () == 0 )
570588 {
571- frame->GetSizer ()->Detach (tool);
572- tool->Reparent (m_right_notebook);
573-
574- m_right_notebook->AddPage (tool, tool->name (), true );
575-
576- if (m_right_notebook->GetPageCount () == 1 )
577- {
578- ResetNotebookSize (m_right_notebook);
579- m_right_notebook->Show ();
580- }
581-
582- m_tool_frames.erase (tool);
583- frame->Destroy ();
584- });
589+ dest_notebook = m_right_notebook;
590+ }
591+ else {
592+ dest_notebook = m_left_notebook;
593+ }
585594
586- m_tool_frames.emplace (m_left_down_tool, frame);
587- }
595+ break ;
596+ }
597+
598+ tool->Reparent (dest_notebook);
599+ dest_notebook->AddPage (tool, tool->label (), true );
600+
601+ if (dest_notebook->GetPageCount () == 1 )
602+ {
603+ ResetNotebookSize (dest_notebook);
588604 }
605+
606+ m_tool_frames.erase (tool);
589607 }
590608
591- event. Skip ();
609+ frame-> Destroy ();
592610}
593611
594612BEGIN_EVENT_TABLE (REHex::ToolDock::ToolNotebook, wxNotebook)
@@ -603,6 +621,11 @@ bool REHex::ToolDock::ToolNotebook::AddPage(wxWindow *page, const wxString &text
603621 bool res = wxNotebook::AddPage (page, text, select, imageId);
604622 UpdateToolVisibility ();
605623
624+ if (GetPageCount () == 1 )
625+ {
626+ Show ();
627+ }
628+
606629 return res;
607630}
608631
@@ -611,6 +634,11 @@ bool REHex::ToolDock::ToolNotebook::DeletePage(size_t page)
611634 bool res = wxNotebook::DeletePage (page);
612635 UpdateToolVisibility ();
613636
637+ if (GetPageCount () == 0 )
638+ {
639+ Hide ();
640+ }
641+
614642 return res;
615643}
616644
@@ -619,6 +647,11 @@ bool REHex::ToolDock::ToolNotebook::InsertPage(size_t index, wxWindow *page, con
619647 bool res = wxNotebook::InsertPage (index, page, text, select, imageId);
620648 UpdateToolVisibility ();
621649
650+ if (GetPageCount () == 1 )
651+ {
652+ Show ();
653+ }
654+
622655 return res;
623656}
624657
@@ -627,6 +660,11 @@ bool REHex::ToolDock::ToolNotebook::RemovePage(size_t page)
627660 bool res = wxNotebook::RemovePage (page);
628661 UpdateToolVisibility ();
629662
663+ if (GetPageCount () == 0 )
664+ {
665+ Hide ();
666+ }
667+
630668 return res;
631669}
632670
@@ -721,15 +759,44 @@ void REHex::ToolDock::ToolNotebook::OnPageChanged(wxNotebookEvent& event)
721759}
722760
723761REHex::ToolDock::ToolFrame::ToolFrame (wxWindow *parent, ToolPanel *tool):
724- wxFrame(parent, wxID_ANY, tool->name (), wxDefaultPosition, wxDefaultSize,
725- (wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW | wxFRAME_FLOAT_ON_PARENT))
762+ wxFrame(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
763+ (wxCAPTION | wxCLOSE_BOX | wxRESIZE_BORDER | wxFRAME_TOOL_WINDOW | wxFRAME_FLOAT_ON_PARENT)),
764+ m_tool(NULL )
726765{
727- SetClientSize (tool->GetSize ());
766+ m_sizer = new wxBoxSizer (wxHORIZONTAL);
767+ SetSizer (m_sizer);
768+
769+ if (tool != NULL )
770+ {
771+ AdoptTool (tool);
772+ }
773+ }
728774
775+ void REHex::ToolDock::ToolFrame::AdoptTool (ToolPanel *tool)
776+ {
777+ assert (m_tool == NULL );
778+
779+ m_tool = tool;
780+
781+ SetClientSize (tool->GetSize ());
782+
729783 tool->Reparent (this );
730784 tool->Show ();
785+
786+ SetTitle (tool->label ());
787+ m_sizer->Add (tool, 1 , wxEXPAND);
788+ }
789+
790+ void REHex::ToolDock::ToolFrame::RemoveTool (ToolPanel *tool)
791+ {
792+ assert (m_tool == tool);
793+
794+ m_tool = NULL ;
795+
796+ m_sizer->Detach (tool);
797+ }
731798
732- wxBoxSizer *sizer = new wxBoxSizer (wxHORIZONTAL);
733- sizer-> Add (tool, 1 , wxEXPAND);
734- SetSizer (sizer) ;
799+ REHex::ToolPanel * REHex::ToolDock::ToolFrame::GetTool () const
800+ {
801+ return m_tool ;
735802}
0 commit comments