X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/25d7497c18a95bb2953ccad72a127c955285ae84..7bb82a7415a0fae8b691611665593e8550a7bcf7:/src/aui/auibook.cpp diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index 9ea8880bc8..6de8fcede5 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -198,33 +198,27 @@ void wxDefaultTabArt::DrawTab(wxDC* dc, { wxCoord normal_textx, normal_texty; wxCoord selected_textx, selected_texty; - wxCoord measured_textx, measured_texty; wxCoord textx, texty; - - + // if the caption is empty, measure some temporary text wxString caption = caption_text; if (caption_text.empty()) caption = wxT("Xj"); - - // measure text - dc->SetFont(m_measuring_font); - dc->GetTextExtent(caption, &measured_textx, &measured_texty); - + dc->SetFont(m_selected_font); dc->GetTextExtent(caption, &selected_textx, &selected_texty); - + dc->SetFont(m_normal_font); dc->GetTextExtent(caption, &normal_textx, &normal_texty); + + // figure out the size of the tab + wxSize tab_size = GetTabSize(dc, caption, active, x_extent); - caption = caption_text; - - wxCoord tab_height = measured_texty + 4; - wxCoord tab_width = measured_textx + tab_height + 5; + wxCoord tab_height = tab_size.y; + wxCoord tab_width = tab_size.x; wxCoord tab_x = in_rect.x; wxCoord tab_y = in_rect.y + in_rect.height - tab_height; - // select pen, brush and font for the tab to be drawn if (active) @@ -274,10 +268,9 @@ void wxDefaultTabArt::DrawTab(wxDC* dc, dc->DrawText(caption, tab_x + (tab_height/3) + (tab_width/2) - (textx/2), - tab_y + tab_height - texty - 2); + (tab_y + tab_height)/2 - (texty/2) + 1); *out_rect = wxRect(tab_x, tab_y, tab_width, tab_height); - *x_extent = tab_width - (tab_height/2) - 1; } @@ -368,7 +361,14 @@ void wxDefaultTabArt::DrawButton( - +int wxDefaultTabArt::GetBestTabCtrlSize(wxWindow* wnd) +{ + wxClientDC dc(wnd); + dc.SetFont(m_measuring_font); + int x_ext = 0; + wxSize s = GetTabSize(&dc, wxT("ABCDEFGHIj"), true, &x_ext); + return s.y+3; +} void wxDefaultTabArt::SetNormalFont(const wxFont& font) { @@ -477,6 +477,25 @@ bool wxAuiTabContainer::InsertPage(wxWindow* page, return true; } +bool wxAuiTabContainer::MovePage(wxWindow* page, + size_t new_idx) +{ + int idx = GetIdxFromWindow(page); + if (idx == -1) + return false; + + // get page entry, make a copy of it + wxAuiNotebookPage p = GetPage(idx); + + // remove old page entry + RemovePage(page); + + // insert page where it should be + InsertPage(page, p, new_idx); + + return true; +} + bool wxAuiTabContainer::RemovePage(wxWindow* wnd) { size_t i, page_count = m_pages.GetCount(); @@ -952,6 +971,9 @@ wxAuiTabCtrl::wxAuiTabCtrl(wxWindow* parent, m_hover_button = NULL; } +wxAuiTabCtrl::~wxAuiTabCtrl() +{ +} void wxAuiTabCtrl::OnPaint(wxPaintEvent&) { @@ -979,7 +1001,7 @@ void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) CaptureMouse(); m_click_pt = wxDefaultPosition; m_is_dragging = false; - m_click_tab = -1; + m_click_tab = NULL; wxWindow* wnd; if (TabHitTest(evt.m_x, evt.m_y, &wnd)) @@ -992,7 +1014,7 @@ void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) m_click_pt.x = evt.m_x; m_click_pt.y = evt.m_y; - m_click_tab = e.GetSelection(); + m_click_tab = wnd; } if (m_hover_button) @@ -1011,8 +1033,8 @@ void wxAuiTabCtrl::OnLeftUp(wxMouseEvent&) if (m_is_dragging) { wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, m_windowId); - evt.SetSelection(m_click_tab); - evt.SetOldSelection(m_click_tab); + evt.SetSelection(GetIdxFromWindow(m_click_tab)); + evt.SetOldSelection(evt.GetSelection()); evt.SetEventObject(this); GetEventHandler()->ProcessEvent(evt); return; @@ -1035,7 +1057,7 @@ void wxAuiTabCtrl::OnLeftUp(wxMouseEvent&) m_click_pt = wxDefaultPosition; m_is_dragging = false; - m_click_tab = -1; + m_click_tab = NULL; } void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) @@ -1081,8 +1103,8 @@ void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) if (m_is_dragging) { wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, m_windowId); - evt.SetSelection(m_click_tab); - evt.SetOldSelection(m_click_tab); + evt.SetSelection(GetIdxFromWindow(m_click_tab)); + evt.SetOldSelection(evt.GetSelection()); evt.SetEventObject(this); GetEventHandler()->ProcessEvent(evt); return; @@ -1096,8 +1118,8 @@ void wxAuiTabCtrl::OnMotion(wxMouseEvent& evt) abs(pos.y - m_click_pt.y) > drag_y_threshold) { wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, m_windowId); - evt.SetSelection(m_click_tab); - evt.SetOldSelection(m_click_tab); + evt.SetSelection(GetIdxFromWindow(m_click_tab)); + evt.SetOldSelection(evt.GetSelection()); evt.SetEventObject(this); GetEventHandler()->ProcessEvent(evt); @@ -1306,11 +1328,7 @@ void wxAuiMultiNotebook::InitNotebook() m_selected_font.SetWeight(wxBOLD); // choose a default for the tab height - wxClientDC dc(this); - int tx, ty; - dc.SetFont(m_selected_font); - dc.GetTextExtent(wxT("ABCDEFGHhijklm"), &tx, &ty); - m_tab_ctrl_height = (ty*150)/100; + m_tab_ctrl_height = m_tabs.GetArtProvider()->GetBestTabCtrlSize(this); m_dummy_wnd = new wxWindow(this, wxID_ANY, wxPoint(0,0), wxSize(0,0)); m_dummy_wnd->SetSize(200, 200); @@ -1697,6 +1715,7 @@ void wxAuiMultiNotebook::OnTabClicked(wxCommandEvent& command_evt) void wxAuiMultiNotebook::OnTabBeginDrag(wxCommandEvent&) { + m_last_drag_x = 0; } void wxAuiMultiNotebook::OnTabDragMotion(wxCommandEvent& evt) @@ -1707,17 +1726,46 @@ void wxAuiMultiNotebook::OnTabDragMotion(wxCommandEvent& evt) wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); - wxAuiTabCtrl* tab_ctrl = GetTabCtrlFromPoint(client_pt); - if (tab_ctrl == src_tabs) + wxAuiTabCtrl* dest_tabs = GetTabCtrlFromPoint(client_pt); + if (dest_tabs == src_tabs) { - // inner-tabctrl dragging is not yet implemented + // always hide the hint for inner-tabctrl drag m_mgr.HideHint(); + + wxPoint pt = dest_tabs->ScreenToClient(screen_pt); + wxWindow* dest_location_tab; + + // this is an inner-tab drag/reposition + if (dest_tabs->TabHitTest(pt.x, pt.y, &dest_location_tab)) + { + int src_idx = evt.GetSelection(); + int dest_idx = dest_tabs->GetIdxFromWindow(dest_location_tab); + + // prevent jumpy drag + if ((src_idx == dest_idx) || dest_idx == -1 || + (src_idx > dest_idx && m_last_drag_x <= pt.x) || + (src_idx < dest_idx && m_last_drag_x >= pt.x)) + { + m_last_drag_x = pt.x; + return; + } + + + wxWindow* src_tab = dest_tabs->GetWindowFromIdx(src_idx); + dest_tabs->MovePage(src_tab, dest_idx); + dest_tabs->SetActivePage((size_t)dest_idx); + dest_tabs->DoShowHide(); + dest_tabs->Refresh(); + m_last_drag_x = pt.x; + + } + return; } - if (tab_ctrl) + if (dest_tabs) { - wxRect hint_rect = tab_ctrl->GetRect(); + wxRect hint_rect = dest_tabs->GetRect(); ClientToScreen(&hint_rect.x, &hint_rect.y); m_mgr.ShowHint(hint_rect); } @@ -1749,12 +1797,22 @@ void wxAuiMultiNotebook::OnTabEndDrag(wxCommandEvent& command_evt) // If the pointer is in an existing tab frame, do a tab insert wxWindow* hit_wnd = ::wxFindWindowAtPoint(mouse_screen_pt); wxTabFrame* tab_frame = (wxTabFrame*)GetTabFrameFromTabCtrl(hit_wnd); + int insert_idx = -1; if (tab_frame) { dest_tabs = tab_frame->m_tabs; if (dest_tabs == src_tabs) return; + + + wxPoint pt = dest_tabs->ScreenToClient(mouse_screen_pt); + wxWindow* target = NULL; + dest_tabs->TabHitTest(pt.x, pt.y, &target); + if (target) + { + insert_idx = dest_tabs->GetIdxFromWindow(target); + } } else { @@ -1789,7 +1847,9 @@ void wxAuiMultiNotebook::OnTabEndDrag(wxCommandEvent& command_evt) // add the page to the destination tabs - dest_tabs->AddPage(page_info.window, page_info); + if (insert_idx == -1) + insert_idx = dest_tabs->GetPageCount(); + dest_tabs->InsertPage(page_info.window, page_info, insert_idx); if (src_tabs->GetPageCount() == 0) {