- }
- else
- {
- // If there is no tabframe at all, create one
- wxTabFrame* new_tabs = new wxTabFrame;
- new_tabs->SetTabCtrlHeight(m_tab_ctrl_height);
- new_tabs->m_tabs = new wxAuiTabCtrl(this,
- m_tab_id_counter++,
- wxDefaultPosition,
- wxDefaultSize,
- wxNO_BORDER);
- new_tabs->m_tabs->SetFlags(m_flags);
+
+ if (tab_ctrl)
+ {
+ wxAuiNotebook* nb = (wxAuiNotebook*)tab_ctrl->GetParent();
+
+ if (nb != this)
+ {
+ // find out from the destination control
+ // if it's ok to drop this tab here
+ wxAuiNotebookEvent e(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, m_windowId);
+ e.SetSelection(evt.GetSelection());
+ e.SetOldSelection(evt.GetSelection());
+ e.SetEventObject(this);
+ e.SetDragSource(this);
+ e.Veto(); // dropping must be explicitly approved by control owner
+
+ nb->GetEventHandler()->ProcessEvent(e);
+
+ if (!e.IsAllowed())
+ {
+ // no answer or negative answer
+ m_mgr.HideHint();
+ return;
+ }
+
+ // drop was allowed
+ int src_idx = evt.GetSelection();
+ wxWindow* src_page = src_tabs->GetWindowFromIdx(src_idx);
+
+ // get main index of the page
+ int main_idx = m_tabs.GetIdxFromWindow(src_page);
+
+ // make a copy of the page info
+ wxAuiNotebookPage page_info = m_tabs.GetPage((size_t)main_idx);
+
+ // remove the page from the source notebook
+ RemovePage(main_idx);
+
+ // reparent the page
+ src_page->Reparent(nb);
+
+
+ // found out the insert idx
+ wxAuiTabCtrl* dest_tabs = (wxAuiTabCtrl*)tab_ctrl;
+ wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt);
+
+ wxWindow* target = NULL;
+ int insert_idx = -1;
+ dest_tabs->TabHitTest(pt.x, pt.y, &target);
+ if (target)
+ {
+ insert_idx = dest_tabs->GetIdxFromWindow(target);
+ }