⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splittree.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 2 页
字号:
static wxRect CombineRectangles(const wxRect& rect1, const wxRect& rect2){    wxRect rect;    int right1 = rect1.GetRight();    int bottom1 = rect1.GetBottom();    int right2 = rect2.GetRight();    int bottom2 = rect2.GetBottom();    wxPoint topLeft = wxPoint(wxMin(rect1.x, rect2.x), wxMin(rect1.y, rect2.y));    wxPoint bottomRight = wxPoint(wxMax(right1, right2), wxMax(bottom1, bottom2));    rect.x = topLeft.x; rect.y = topLeft.y;    rect.SetRight(bottomRight.x);    rect.SetBottom(bottomRight.y);    return rect;}// Calculate the tree overall size so we can set the scrollbar// correctlyvoid wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect){    CalcTreeSize(GetRootItem(), rect);}void wxRemotelyScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId& id, wxRect& rect){    // More efficient implementation would be to find the last item (but how?)    // Q: is the bounding rect relative to the top of the virtual tree workspace    // or the top of the window? How would we convert?    wxRect itemSize;    if (GetBoundingRect(id, itemSize))    {        rect = CombineRectangles(rect, itemSize);    }    wxTreeItemIdValue cookie;    wxTreeItemId childId = GetFirstChild(id, cookie);    while (childId)    {        CalcTreeSize(childId, rect);        childId = GetNextChild(childId, cookie);    }}// Find the scrolled window that contains this controlwxScrolledWindow* wxRemotelyScrolledTreeCtrl::GetScrolledWindow() const{    wxWindow* parent = wxWindow::GetParent();    while (parent)    {        if (parent->IsKindOf(CLASSINFO(wxScrolledWindow)))            return (wxScrolledWindow*) parent;        parent = parent->GetParent();    }    return NULL;}void wxRemotelyScrolledTreeCtrl::OnScroll(wxScrollWinEvent& event){    int orient = event.GetOrientation();    if (orient == wxHORIZONTAL)    {        event.Skip();        return;    }    wxScrolledWindow* scrollWin = GetScrolledWindow();    if (!scrollWin)        return;    int x, y;    scrollWin->GetViewStart(& x, & y);    ScrollToLine(-1, y);}/* * wxTreeCompanionWindow * * A window displaying values associated with tree control items. */IMPLEMENT_CLASS(wxTreeCompanionWindow, wxWindow)BEGIN_EVENT_TABLE(wxTreeCompanionWindow, wxWindow)    EVT_PAINT(wxTreeCompanionWindow::OnPaint)    EVT_SCROLLWIN(wxTreeCompanionWindow::OnScroll)    EVT_TREE_ITEM_EXPANDED(-1, wxTreeCompanionWindow::OnExpand)    EVT_TREE_ITEM_COLLAPSED(-1, wxTreeCompanionWindow::OnExpand)END_EVENT_TABLE()wxTreeCompanionWindow::wxTreeCompanionWindow(wxWindow* parent, wxWindowID id,      const wxPoint& pos,      const wxSize& sz,      long style):    wxWindow(parent, id, pos, sz, style){    m_treeCtrl = NULL;}void wxTreeCompanionWindow::DrawItem(wxDC& dc, wxTreeItemId id, const wxRect& rect){    // TEST CODE#if 1    if (m_treeCtrl)    {        wxString text = m_treeCtrl->GetItemText(id);        dc.SetTextForeground(* wxBLACK);        dc.SetBackgroundMode(wxTRANSPARENT);        int textW, textH;        dc.GetTextExtent(text, & textW, & textH);        int x = 5;        int y = rect.GetY() + wxMax(0, (rect.GetHeight() - textH) / 2);        dc.DrawText(text, x, y);    }#endif}void wxTreeCompanionWindow::OnPaint(wxPaintEvent& WXUNUSED(event)){    wxPaintDC dc(this);    if (!m_treeCtrl)        return;        wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);    dc.SetPen(pen);    dc.SetBrush(* wxTRANSPARENT_BRUSH);    wxFont font(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));    dc.SetFont(font);    wxSize clientSize = GetClientSize();    wxRect itemRect;    wxTreeItemId h, lastH;    for (h=m_treeCtrl->GetFirstVisibleItem();         h.IsOk();         h=m_treeCtrl->GetNextVisible(h))    {        if (m_treeCtrl->GetBoundingRect(h, itemRect))        {            int cy = itemRect.GetTop();            wxRect drawItemRect(0, cy, clientSize.x, itemRect.GetHeight());            lastH = h;            // Draw the actual item            DrawItem(dc, h, drawItemRect);            dc.DrawLine(0, cy, clientSize.x, cy);        }        if (! m_treeCtrl->IsVisible(h))            break;    }    if (lastH.IsOk() && m_treeCtrl->GetBoundingRect(lastH, itemRect))    {        int cy = itemRect.GetBottom();        dc.DrawLine(0, cy, clientSize.x, cy);    }}void wxTreeCompanionWindow::OnScroll(wxScrollWinEvent& event){    int orient = event.GetOrientation();    if (orient == wxHORIZONTAL)    {        event.Skip();        return;    }    if (!m_treeCtrl)        return;    // TODO: scroll the window physically instead of just refreshing.    Refresh(true);}void wxTreeCompanionWindow::OnExpand(wxTreeEvent& WXUNUSED(event)){    // TODO: something more optimized than simply refresh the whole    // window when the tree is expanded/collapsed. Tricky.    Refresh();}/* * wxThinSplitterWindow */IMPLEMENT_CLASS(wxThinSplitterWindow, wxSplitterWindow)BEGIN_EVENT_TABLE(wxThinSplitterWindow, wxSplitterWindow)    EVT_SIZE(wxThinSplitterWindow::OnSize)END_EVENT_TABLE()wxThinSplitterWindow::wxThinSplitterWindow(wxWindow* parent, wxWindowID id,      const wxPoint& pos,      const wxSize& sz,      long style):      wxSplitterWindow(parent, id, pos, sz, style){    wxColour faceColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));    m_facePen = new wxPen(faceColour, 1, wxSOLID);    m_faceBrush = new wxBrush(faceColour, wxSOLID);}wxThinSplitterWindow::~wxThinSplitterWindow(){    delete m_facePen;    delete m_faceBrush;}void wxThinSplitterWindow::SizeWindows(){    // The client size may have changed inbetween    // the sizing of the first window and the sizing of    // the second. So repeat SizeWindows.    wxSplitterWindow::SizeWindows();    wxSplitterWindow::SizeWindows();}// Tests for x, y over sashbool wxThinSplitterWindow::SashHitTest(int x, int y, int WXUNUSED(tolerance)){    return wxSplitterWindow::SashHitTest(x, y, 4);}void wxThinSplitterWindow::DrawSash(wxDC& dc){    if ( m_sashPosition == 0 || !m_windowTwo)        return;    if (GetWindowStyle() & wxSP_NOSASH)        return;    int w, h;    GetClientSize(&w, &h);    if ( m_splitMode == wxSPLIT_VERTICAL )    {        dc.SetPen(* m_facePen);        dc.SetBrush(* m_faceBrush);        int h1 = h-1;        int y1 = 0;        if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )            h1 += 1; // Not sure why this is necessary...        if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)        {            y1 = 2; h1 -= 3;        }        dc.DrawRectangle(m_sashPosition, y1, GetSashSize(), h1);    }    else    {        dc.SetPen(* m_facePen);        dc.SetBrush(* m_faceBrush);        int w1 = w-1;        int x1 = 0;        if ( (GetWindowStyleFlag() & wxSP_BORDER) != wxSP_BORDER && (GetWindowStyleFlag() & wxSP_3DBORDER) != wxSP_3DBORDER )            w1 ++;        if ( (GetWindowStyleFlag() & wxSP_3DBORDER) == wxSP_3DBORDER)        {            x1 = 2; w1 -= 3;        }        dc.DrawRectangle(x1, m_sashPosition, w1, GetSashSize());    }    dc.SetPen(wxNullPen);    dc.SetBrush(wxNullBrush);}void wxThinSplitterWindow::OnSize(wxSizeEvent& event){    wxSplitterWindow::OnSize(event);}/* * wxSplitterScrolledWindow */IMPLEMENT_CLASS(wxSplitterScrolledWindow, wxScrolledWindow)BEGIN_EVENT_TABLE(wxSplitterScrolledWindow, wxScrolledWindow)    EVT_SCROLLWIN(wxSplitterScrolledWindow::OnScroll)    EVT_SIZE(wxSplitterScrolledWindow::OnSize)END_EVENT_TABLE()wxSplitterScrolledWindow::wxSplitterScrolledWindow(wxWindow* parent, wxWindowID id,      const wxPoint& pos,      const wxSize& sz,      long style):      wxScrolledWindow(parent, id, pos, sz, style){}void wxSplitterScrolledWindow::OnSize(wxSizeEvent& WXUNUSED(event)){    wxSize sz = GetClientSize();    if (GetChildren().GetFirst())    {        ((wxWindow*) GetChildren().GetFirst()->GetData())->SetSize(0, 0, sz.x, sz.y);    }}void wxSplitterScrolledWindow::OnScroll(wxScrollWinEvent& event){    // Ensure that events being propagated back up the window hierarchy    // don't cause an infinite loop    static bool inOnScroll = false;    if (inOnScroll)    {        event.Skip();        return;    }    inOnScroll = true;    int orient = event.GetOrientation();    int nScrollInc = CalcScrollInc(event);    if (nScrollInc == 0)    {        inOnScroll = false;        return;    }    if (orient == wxHORIZONTAL)    {        inOnScroll = false;        event.Skip();        return;#if 0        int newPos = m_xScrollPosition + nScrollInc;        SetScrollPos(wxHORIZONTAL, newPos, true );#endif    }    else    {        int newPos = m_yScrollPosition + nScrollInc;        SetScrollPos(wxVERTICAL, newPos, true );    }    if (orient == wxHORIZONTAL)    {        m_xScrollPosition += nScrollInc;    }    else    {        m_yScrollPosition += nScrollInc;    }    // Find targets in splitter window and send the event to them    wxWindowList::compatibility_iterator node = GetChildren().GetFirst();    while (node)    {        wxWindow* child = (wxWindow*) node->GetData();        if (child->IsKindOf(CLASSINFO(wxSplitterWindow)))        {            wxSplitterWindow* splitter = (wxSplitterWindow*) child;            if (splitter->GetWindow1())                splitter->GetWindow1()->ProcessEvent(event);            if (splitter->GetWindow2())                splitter->GetWindow2()->ProcessEvent(event);            break;        }        node = node->GetNext();    }    m_targetWindow->Update() ;    inOnScroll = false;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -