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

📄 tbarsmpl.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        contrib/src/deprecated//tbarsmpl.cpp// Purpose:     wxToolBarSimple// Author:      Julian Smart// Modified by: VZ on 14.12.99 during wxToolBarSimple reorganization// Created:     04/01/98// RCS-ID:      $Id: tbarsmpl.cpp,v 1.5 2005/09/23 12:47:39 MR Exp $// Copyright:   (c) Julian Smart// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__    #pragma hdrstop#endif#if wxUSE_TOOLBAR && wxUSE_TOOLBAR_SIMPLE#ifndef WX_PRECOMP    #include "wx/settings.h"    #include "wx/window.h"    #include "wx/dcclient.h"    #include "wx/dcmemory.h"#endif#include "wx/toolbar.h"#include "wx/deprecated/tbarsmpl.h"// ----------------------------------------------------------------------------// private classes// ----------------------------------------------------------------------------class WXDLLIMPEXP_DEPRECATED wxToolBarToolSimple : public wxToolBarToolBase{public:    wxToolBarToolSimple(wxToolBarSimple *tbar,                        int id,                        const wxString& label,                        const wxBitmap& bmpNormal,                        const wxBitmap& bmpDisabled,                        wxItemKind kind,                        wxObject *clientData,                        const wxString& shortHelp,                        const wxString& longHelp)        : wxToolBarToolBase(tbar, id, label, bmpNormal, bmpDisabled, kind,                            clientData, shortHelp, longHelp)    {    }    wxToolBarToolSimple(wxToolBarSimple *tbar, wxControl *control)        : wxToolBarToolBase(tbar, control)    {    }    void SetSize(const wxSize& size)    {        m_width = size.x;        m_height = size.y;    }    wxCoord GetWidth() const { return m_width; }    wxCoord GetHeight() const { return m_height; }    wxCoord m_x;    wxCoord m_y;    wxCoord m_width;    wxCoord m_height;    DECLARE_NO_COPY_CLASS(wxToolBarToolSimple)};// ----------------------------------------------------------------------------// wxWin macros// ----------------------------------------------------------------------------IMPLEMENT_DYNAMIC_CLASS(wxToolBarSimple, wxControl)#if !wxUSE_TOOLBAR_NATIVE && !defined(__WXUNIVERSAL__)    IMPLEMENT_DYNAMIC_CLASS(wxToolBar, wxToolBarSimple)#endifBEGIN_EVENT_TABLE(wxToolBarSimple, wxToolBarBase)    EVT_SIZE(wxToolBarSimple::OnSize)    EVT_SCROLL(wxToolBarSimple::OnScroll)    EVT_PAINT(wxToolBarSimple::OnPaint)    EVT_KILL_FOCUS(wxToolBarSimple::OnKillFocus)    EVT_MOUSE_EVENTS(wxToolBarSimple::OnMouseEvent)END_EVENT_TABLE()// ============================================================================// implementation// ============================================================================// ----------------------------------------------------------------------------// tool bar tools creation// ----------------------------------------------------------------------------wxToolBarToolBase *wxToolBarSimple::CreateTool(int id,                                               const wxString& label,                                               const wxBitmap& bmpNormal,                                               const wxBitmap& bmpDisabled,                                               wxItemKind kind,                                               wxObject *clientData,                                               const wxString& shortHelp,                                               const wxString& longHelp){    return new wxToolBarToolSimple(this, id, label, bmpNormal, bmpDisabled,                                   kind, clientData, shortHelp, longHelp);}wxToolBarToolBase *wxToolBarSimple::CreateTool(wxControl *control){    return new wxToolBarToolSimple(this, control);}// ----------------------------------------------------------------------------// wxToolBarSimple creation// ----------------------------------------------------------------------------void wxToolBarSimple::Init(){    m_currentRowsOrColumns = 0;    m_lastX =    m_lastY = 0;    m_maxWidth =    m_maxHeight = 0;    m_pressedTool =    m_currentTool = -1;    m_xPos =    m_yPos = wxDefaultCoord;    m_toolPacking = 1;    m_toolSeparation = 5;    m_defaultWidth = 16;    m_defaultHeight = 15;    m_xScrollPixelsPerLine = 1;    m_yScrollPixelsPerLine = 1;    m_xScrollingEnabled = false;    m_yScrollingEnabled = false;    m_xScrollPosition = 0;    m_yScrollPosition = 0;    m_xScrollLines = 0;    m_yScrollLines = 0;    m_xScrollLinesPerPage = 0;    m_yScrollLinesPerPage = 0;}wxToolBarToolBase *wxToolBarSimple::DoAddTool(int id,                                              const wxString& label,                                              const wxBitmap& bitmap,                                              const wxBitmap& bmpDisabled,                                              wxItemKind kind,                                              const wxString& shortHelp,                                              const wxString& longHelp,                                              wxObject *clientData,                                              wxCoord xPos,                                              wxCoord yPos){    // rememeber the position for DoInsertTool()    m_xPos = xPos;    m_yPos = yPos;    return wxToolBarBase::DoAddTool(id, label, bitmap, bmpDisabled, kind,                                    shortHelp, longHelp,                                    clientData, xPos, yPos);}bool wxToolBarSimple::DoInsertTool(size_t WXUNUSED(pos),                                   wxToolBarToolBase *toolBase){    wxToolBarToolSimple *tool = (wxToolBarToolSimple *)toolBase;    wxCHECK_MSG( !tool->IsControl(), false,                 _T("generic wxToolBarSimple doesn't support controls") );    tool->m_x = m_xPos;    if ( tool->m_x == wxDefaultCoord )        tool->m_x = m_xMargin;    tool->m_y = m_yPos;    if ( tool->m_y == wxDefaultCoord )        tool->m_y = m_yMargin;    tool->SetSize(GetToolSize());    if ( tool->IsButton() )    {        // Calculate reasonable max size in case Layout() not called        if ((tool->m_x + tool->GetNormalBitmap().GetWidth() + m_xMargin) > m_maxWidth)            m_maxWidth = (wxCoord)((tool->m_x + tool->GetWidth() + m_xMargin));        if ((tool->m_y + tool->GetNormalBitmap().GetHeight() + m_yMargin) > m_maxHeight)            m_maxHeight = (wxCoord)((tool->m_y + tool->GetHeight() + m_yMargin));    }    return true;}bool wxToolBarSimple::DoDeleteTool(size_t WXUNUSED(pos),                                   wxToolBarToolBase *tool){    // VZ: didn't test whether it works, but why not...    tool->Detach();    Refresh();    return true;}bool wxToolBarSimple::Create(wxWindow *parent,                             wxWindowID id,                             const wxPoint& pos,                             const wxSize& size,                             long style,                             const wxString& name){    if ( !wxWindow::Create(parent, id, pos, size, style, name) )        return false;    // Set it to grey (or other 3D face colour)    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));    if ( GetWindowStyleFlag() & wxTB_VERTICAL )    {        m_lastX = 7;        m_lastY = 3;        m_maxRows = 32000;      // a lot        m_maxCols = 1;    }    else    {        m_lastX = 3;        m_lastY = 7;        m_maxRows = 1;        m_maxCols = 32000;      // a lot    }    SetCursor(*wxSTANDARD_CURSOR);    return true;}wxToolBarSimple::~wxToolBarSimple(){}bool wxToolBarSimple::Realize(){    m_currentRowsOrColumns = 0;    m_lastX = m_xMargin;    m_lastY = m_yMargin;    m_maxWidth = 0;    m_maxHeight = 0;    int maxToolWidth = 0;    int maxToolHeight = 0;    // Find the maximum tool width and height    wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();    while ( node )    {        wxToolBarToolSimple *tool = (wxToolBarToolSimple *)node->GetData();        if ( tool->GetWidth() > maxToolWidth )            maxToolWidth = tool->GetWidth();        if (tool->GetHeight() > maxToolHeight)            maxToolHeight = tool->GetHeight();        node = node->GetNext();    }    int separatorSize = m_toolSeparation;    node = m_tools.GetFirst();    while ( node )    {        wxToolBarToolSimple *tool = (wxToolBarToolSimple *)node->GetData();        if ( tool->IsSeparator() )        {            if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )            {                if (m_currentRowsOrColumns >= m_maxCols)                    m_lastY += separatorSize;                else                    m_lastX += separatorSize;            }            else            {                if (m_currentRowsOrColumns >= m_maxRows)                    m_lastX += separatorSize;                else                    m_lastY += separatorSize;            }        }        else if ( tool->IsButton() )        {            if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )            {                if (m_currentRowsOrColumns >= m_maxCols)                {                    m_currentRowsOrColumns = 0;                    m_lastX = m_xMargin;                    m_lastY += maxToolHeight + m_toolPacking;                }                tool->m_x = (wxCoord)(m_lastX + (maxToolWidth - tool->GetWidth())/2.0);                tool->m_y = (wxCoord)(m_lastY + (maxToolHeight - tool->GetHeight())/2.0);                m_lastX += maxToolWidth + m_toolPacking;            }            else            {                if (m_currentRowsOrColumns >= m_maxRows)                {                    m_currentRowsOrColumns = 0;                    m_lastX += (maxToolWidth + m_toolPacking);                    m_lastY = m_yMargin;                }                tool->m_x = (wxCoord)(m_lastX + (maxToolWidth - tool->GetWidth())/2.0);                tool->m_y = (wxCoord)(m_lastY + (maxToolHeight - tool->GetHeight())/2.0);                m_lastY += maxToolHeight + m_toolPacking;            }            m_currentRowsOrColumns ++;        }        else        {            // TODO: support the controls        }        if (m_lastX > m_maxWidth)            m_maxWidth = m_lastX;        if (m_lastY > m_maxHeight)            m_maxHeight = m_lastY;        node = node->GetNext();    }    if ( GetWindowStyleFlag() & wxTB_HORIZONTAL )        m_maxHeight += maxToolHeight;    else        m_maxWidth += maxToolWidth;    m_maxWidth += m_xMargin;    m_maxHeight += m_yMargin;    SetSize(m_maxWidth, m_maxHeight);    return true;}// ----------------------------------------------------------------------------// event handlers// ----------------------------------------------------------------------------void wxToolBarSimple::OnPaint (wxPaintEvent& WXUNUSED(event)){    wxPaintDC dc(this);    PrepareDC(dc);    static int count = 0;    // Prevent reentry of OnPaint which would cause wxMemoryDC errors.    if ( count > 0 )        return;    count++;    for ( wxToolBarToolsList::compatibility_iterator node = m_tools.GetFirst();          node;          node = node->GetNext() )    {        wxToolBarToolBase *tool = node->GetData();        if ( tool->IsButton() )            DrawTool(dc, tool);    }    count--;}void wxToolBarSimple::OnSize (wxSizeEvent& WXUNUSED(event)){    if (GetAutoLayout())        Layout();    AdjustScrollbars();}void wxToolBarSimple::OnKillFocus(wxFocusEvent& WXUNUSED(event)){    OnMouseEnter(m_pressedTool = m_currentTool = -1);}void wxToolBarSimple::OnMouseEvent(wxMouseEvent & event){    wxCoord x, y;    event.GetPosition(&x, &y);    wxToolBarToolSimple *tool = (wxToolBarToolSimple *)FindToolForPosition(x, y);    if (event.LeftDown())    {        CaptureMouse();    }    if (event.LeftUp())    {        ReleaseMouse();    }    if (!tool)    {        if (m_currentTool > -1)        {            if (event.LeftIsDown())                SpringUpButton(m_currentTool);            m_currentTool = -1;            OnMouseEnter(-1);        }        return;    }    if (!event.IsButton())    {        if ( tool->GetId() != m_currentTool )        {            // If the left button is kept down and moved over buttons,            // press those buttons.            if ( event.LeftIsDown() && tool->IsEnabled() )            {                SpringUpButton(m_currentTool);                if ( tool->CanBeToggled() )                {                    tool->Toggle();                }                DrawTool(tool);            }            m_currentTool = tool->GetId();            OnMouseEnter(m_currentTool);        }        return;    }    // Left button pressed.    if ( event.LeftDown() && tool->IsEnabled() )    {        if ( tool->CanBeToggled() )        {            tool->Toggle();        }        DrawTool(tool);    }    else if (event.RightDown())    {        OnRightClick(tool->GetId(), x, y);    }    // Left Button Released.  Only this action confirms selection.    // If the button is enabled and it is not a toggle tool and it is    // in the pressed state, then raise the button and call OnLeftClick.    //    if ( event.LeftUp() && tool->IsEnabled() )    {        // Pass the OnLeftClick event to tool        if ( !OnLeftClick(tool->GetId(), tool->IsToggled()) &&                          tool->CanBeToggled() )        {            // If it was a toggle, and OnLeftClick says No Toggle allowed,            // then change it back            tool->Toggle();        }        DrawTool(tool);    }}// ----------------------------------------------------------------------------// drawing// ----------------------------------------------------------------------------void wxToolBarSimple::DrawTool(wxToolBarToolBase *tool){    wxClientDC dc(this);    DrawTool(dc, tool);}void wxToolBarSimple::DrawTool(wxDC& dc, wxToolBarToolBase *toolBase){

⌨️ 快捷键说明

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