manager.cpp

来自「A*算法 A*算法 A*算法 A*算法A*算法A*算法」· C++ 代码 · 共 2,037 行 · 第 1/5 页

CPP
2,037
字号
                                 m_gradient_type);#else            DrawGradientRectangle(dc, rect,                                 m_inactive_caption_colour,                                 m_inactive_caption_gradient_colour,                                 m_gradient_type);#endif        }    }}void wxDefaultDockArt::DrawCaption(wxDC& dc,                                   const wxString& text,                                   const wxRect& rect,                                   wxPaneInfo& pane){    dc.SetPen(*wxTRANSPARENT_PEN);    dc.SetFont(m_caption_font);    DrawCaptionBackground(dc, rect,                          (pane.state & wxPaneInfo::optionActive)?true:false);    if (pane.state & wxPaneInfo::optionActive)        dc.SetTextForeground(m_active_caption_text_colour);     else        dc.SetTextForeground(m_inactive_caption_text_colour);    wxCoord w,h;    dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h);    dc.SetClippingRegion(rect);    dc.DrawText(text, rect.x+3, rect.y+(rect.height/2)-(h/2)-1);    dc.DestroyClippingRegion();}void wxDefaultDockArt::DrawGripper(wxDC& dc,                                   const wxRect& rect,                                   wxPaneInfo& pane){    dc.SetPen(*wxTRANSPARENT_PEN);    dc.SetBrush(m_gripper_brush);    dc.DrawRectangle(rect.x, rect.y, rect.width,rect.height);    int y = 5;    while (1)    {        dc.SetPen(m_gripper_pen1);        dc.DrawPoint(rect.x+3, rect.y+y);        dc.SetPen(m_gripper_pen2);        dc.DrawPoint(rect.x+3, rect.y+y+1);        dc.DrawPoint(rect.x+4, rect.y+y);                dc.SetPen(m_gripper_pen3);        dc.DrawPoint(rect.x+5, rect.y+y+1);        dc.DrawPoint(rect.x+5, rect.y+y+2);                dc.DrawPoint(rect.x+4, rect.y+y+2);                        y += 4;        if (y > rect.GetHeight()-5)            break;    }}void wxDefaultDockArt::DrawPaneButton(wxDC& dc,                                      int button,                                      int button_state,                                      const wxRect& _rect,                                      wxPaneInfo& pane){    wxRect rect = _rect;    if (button_state == wxAUI_BUTTON_STATE_PRESSED)    {        rect.x++;        rect.y++;    }    if (button_state == wxAUI_BUTTON_STATE_HOVER ||        button_state == wxAUI_BUTTON_STATE_PRESSED)    {        if (pane.state & wxPaneInfo::optionActive)        {            dc.SetBrush(wxBrush(StepColour(m_active_caption_colour, 120)));            dc.SetPen(wxPen(StepColour(m_active_caption_colour, 70)));        }         else        {            dc.SetBrush(wxBrush(StepColour(m_inactive_caption_colour, 120)));            dc.SetPen(wxPen(StepColour(m_inactive_caption_colour, 70)));        }        // draw the background behind the button        dc.DrawRectangle(rect.x, rect.y, 15, 15);    }    wxBitmap bmp;    switch (button)    {        default:        case wxPaneInfo::buttonClose:            if (pane.state & wxPaneInfo::optionActive)                bmp = m_active_close_bitmap;                 else                bmp = m_inactive_close_bitmap;            break;        case wxPaneInfo::buttonPin:            if (pane.state & wxPaneInfo::optionActive)                bmp = m_active_pin_bitmap;                 else                bmp = m_inactive_pin_bitmap;            break;    }    // draw the button itself    dc.DrawBitmap(bmp, rect.x, rect.y, true);}// -- wxFloatingPane class implementation --// wxFloatingPane implements a frame class with some special functionality// which allows the library to sense when the frame move starts, is active,// and completes.  Note that it contains it's own wxFrameManager instance,// which, in the future, would allow for nested managed frames.// For now, with wxMSW, the wxMiniFrame window is used, but on wxGTK, wxFrame#if defined( __WXMSW__ ) || defined( __WXMAC__ )#define wxFloatingPaneBaseClass wxMiniFrame#else#define wxFloatingPaneBaseClass wxFrame#endif#ifdef __WXGTK__extern "C" { void* gdk_window_get_pointer(void*, int*, int*, unsigned int*); }#endifclass wxFloatingPane : public wxFloatingPaneBaseClass{public:    wxFloatingPane(wxWindow* parent,                   wxFrameManager* owner_mgr,                   wxWindowID id = -1,                   const wxPoint& pos = wxDefaultPosition,                   const wxSize& size = wxDefaultSize)                    : wxFloatingPaneBaseClass(parent, id, wxT(""), pos, size,                            wxRESIZE_BORDER | wxSYSTEM_MENU | wxCAPTION |                            wxCLOSE_BOX | wxFRAME_NO_TASKBAR |                            wxFRAME_FLOAT_ON_PARENT | wxCLIP_CHILDREN)    {        m_owner_mgr = owner_mgr;        m_moving = false;        m_last_rect = wxRect();        m_mgr.SetFrame(this);        SetExtraStyle(wxWS_EX_PROCESS_IDLE);    }    ~wxFloatingPane()    {        m_mgr.UnInit();    }    void SetPaneWindow(const wxPaneInfo& pane)    {        m_pane_window = pane.window;        m_pane_window->Reparent(this);                wxPaneInfo contained_pane = pane;        contained_pane.Dock().Center().Show().                       CaptionVisible(false).                       PaneBorder(false).                       Layer(0).Row(0).Position(0);                                                      m_mgr.AddPane(m_pane_window, contained_pane);        m_mgr.Update();                   if (pane.min_size.IsFullySpecified())        {            // because SetSizeHints() calls Fit() too (which sets the window            // size to its minimum allowed), we keep the size before calling            // SetSizeHints() and reset it afterwards...            wxSize tmp = GetSize();            GetSizer()->SetSizeHints(this);            SetSize(tmp);        }                SetTitle(pane.caption);        if (contained_pane.IsFixed())            SetWindowStyle(GetWindowStyle() & ~wxRESIZE_BORDER);        if (pane.floating_size != wxDefaultSize)        {            SetSize(pane.floating_size);        }         else        {            wxSize size = pane.best_size;            if (size == wxDefaultSize)                size = pane.min_size;            if (size == wxDefaultSize)                size = m_pane_window->GetSize();            if (pane.HasGripper())                size.x += m_owner_mgr->m_art->GetMetric(wxAUI_ART_GRIPPER_SIZE);                            SetClientSize(size);        }    }private:    void OnSize(wxSizeEvent& event)    {        m_owner_mgr->OnFloatingPaneResized(m_pane_window, event.GetSize());    }        void OnClose(wxCloseEvent& event)    {        m_owner_mgr->OnFloatingPaneClosed(m_pane_window);        Destroy();    }    void OnMoveEvent(wxMoveEvent& event)    {        wxRect win_rect = GetRect();        // skip the first move event        if (m_last_rect.IsEmpty())        {            m_last_rect = win_rect;            return;        }        // prevent frame redocking during resize        if (m_last_rect.GetSize() != win_rect.GetSize())        {            m_last_rect = win_rect;            return;        }        m_last_rect = win_rect;                if (!isMouseDown())            return;        if (!m_moving)        {            OnMoveStart();            m_moving = true;        }        OnMoving(event.GetRect());    }    void OnIdle(wxIdleEvent& event)    {        if (m_moving)        {            if (!isMouseDown())            {                m_moving = false;                OnMoveFinished();            }             else            {                event.RequestMore();            }        }    }    void OnMoveStart()    {        // notify the owner manager that the pane has started to move        m_owner_mgr->OnFloatingPaneMoveStart(m_pane_window);    }    void OnMoving(const wxRect& window_rect)    {        // notify the owner manager that the pane is moving        m_owner_mgr->OnFloatingPaneMoving(m_pane_window);    }    void OnMoveFinished()    {        // notify the owner manager that the pane has finished moving        m_owner_mgr->OnFloatingPaneMoved(m_pane_window);    }    void OnActivate(wxActivateEvent& event)    {        if (event.GetActive())        {            m_owner_mgr->OnFloatingPaneActivated(m_pane_window);        }    }    // utility function which determines the state of the mouse button    // (independant of having a wxMouseEvent handy) - utimately a better    // mechanism for this should be found (possibly by adding the    // functionality to wxWidgets itself)    static bool isMouseDown()    {        #ifdef __WXMSW__        return (GetKeyState( VK_LBUTTON ) & (1<<15)) ? true : false;        #endif        #ifdef __WXGTK__        int x, y;        unsigned int m;        gdk_window_get_pointer(NULL, &x, &y, &m);        return (m & 0x100) ? true : false;        //return (m & 0x1F00) ? true : false;        #endif                #ifdef __WXMAC__        return GetCurrentEventButtonState() & 0x01 ;        #endif    }private:    wxWindow* m_pane_window;    // pane window being managed    bool m_moving;    wxRect m_last_rect;    wxSize m_last_size;    wxFrameManager* m_owner_mgr;    wxFrameManager m_mgr;    DECLARE_EVENT_TABLE()};BEGIN_EVENT_TABLE(wxFloatingPane, wxFloatingPaneBaseClass)    EVT_SIZE(wxFloatingPane::OnSize)    EVT_MOVE(wxFloatingPane::OnMoveEvent)    EVT_MOVING(wxFloatingPane::OnMoveEvent)    EVT_CLOSE(wxFloatingPane::OnClose)    EVT_IDLE(wxFloatingPane::OnIdle)    EVT_ACTIVATE(wxFloatingPane::OnActivate)END_EVENT_TABLE()// -- static utility functions --static wxBitmap wxPaneCreateStippleBitmap(){    unsigned char data[] = { 0,0,0,192,192,192, 192,192,192,0,0,0 };    wxImage img(2,2,data,true);    return wxBitmap(img);}static void DrawResizeHint(wxDC& dc, const wxRect& rect){    wxBitmap stipple = wxPaneCreateStippleBitmap();    wxBrush brush(stipple);    dc.SetBrush(brush);        dc.SetPen(*wxTRANSPARENT_PEN);    dc.SetLogicalFunction(wxXOR);    dc.DrawRectangle(rect);}#ifdef __WXMSW__// on supported windows systems (Win2000 and greater), this function// will make a frame window transparent by a certain amountstatic void MakeWindowTransparent(wxWindow* wnd, int amount){    // this API call is not in all SDKs, only the newer ones, so    // we will runtime bind this    typedef DWORD (WINAPI *PSETLAYEREDWINDOWATTR)(HWND, DWORD, BYTE, DWORD);    static PSETLAYEREDWINDOWATTR pSetLayeredWindowAttributes = NULL;    static HMODULE h = NULL;    HWND hwnd = (HWND)wnd->GetHWND();        if (!h)        h = LoadLibrary(_T("user32"));            if (!pSetLayeredWindowAttributes)    {        pSetLayeredWindowAttributes =         (PSETLAYEREDWINDOWATTR)GetProcAddress(h,"SetLayeredWindowAttributes");    }        if (pSetLayeredWindowAttributes == NULL)        return;            LONG exstyle = GetWindowLong(hwnd, GWL_EXSTYLE);    if (0 == (exstyle & 0x80000) /*WS_EX_LAYERED*/)        SetWindowLong(hwnd, GWL_EXSTYLE, exstyle | 0x80000 /*WS_EX_LAYERED*/);                    pSetLayeredWindowAttributes(hwnd, 0, amount, 2 /*LWA_ALPHA*/);}#endif// CopyDocksAndPanes() - this utility function creates copies of// the dock and pane info.  wxDockInfo's usually contain pointers// to wxPaneInfo classes, thus this function is necessary to reliably// reconstruct that relationship in the new dock info and pane info arraysstatic void CopyDocksAndPanes(wxDockInfoArray& dest_docks,                              wxPaneInfoArray& dest_panes,

⌨️ 快捷键说明

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