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

📄 ecscrolwin.cpp

📁 ecos实时嵌入式操作系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        ecscrolwin.cpp// Purpose:     ecScrolledWindow implementation// Author:      Julian Smart// Modified by:// Created:     01/02/97// RCS-ID:      $Id: ecscrolwin.cpp,v 1.3 2002/02/28 16:39:37 julians Exp $// Copyright:   (c) Julian Smart and Markus Holzem// Licence:     wxWindows license/////////////////////////////////////////////////////////////////////////////// ============================================================================// declarations// ============================================================================// ----------------------------------------------------------------------------// headers// ----------------------------------------------------------------------------#ifdef __GNUG__    #pragma implementation "ecscrolwin.h"#endif#ifdef __VMS#define XtDisplay XTDISPLAY#endif// Includes other headers for precompiled compilation#include "ecpch.h"#ifdef __BORLANDC__    #pragma hdrstop#endif#include "wx/utils.h"#include "wx/dcclient.h"#include "wx/panel.h"#include "ecscrolwin.h"#ifdef __WXMSW__    #include "windows.h"#endif#ifdef __WXMOTIF__// For wxRETAINED implementation#ifdef __VMS__ //VMS's Xm.h is not (yet) compatible with C++               //This code switches off the compiler warnings# pragma message disable nosimpint#endif#include <Xm/Xm.h>#ifdef __VMS__# pragma message enable nosimpint#endif#endif#if !ecUSE_OWN_SCROLLED_WINDOWIMPLEMENT_CLASS(ecScrolledWindow, wxScrolledWindow)#else// ----------------------------------------------------------------------------// event tables// ----------------------------------------------------------------------------BEGIN_EVENT_TABLE(ecScrolledWindow, wxPanel)    EVT_SCROLLWIN(ecScrolledWindow::OnScroll)    EVT_SIZE(ecScrolledWindow::OnSize)    EVT_PAINT(ecScrolledWindow::OnPaint)    EVT_CHAR(ecScrolledWindow::OnChar)END_EVENT_TABLE()IMPLEMENT_DYNAMIC_CLASS(ecScrolledWindow, wxPanel)// ============================================================================// implementation// ============================================================================// ----------------------------------------------------------------------------// ecScrolledWindow creation// ----------------------------------------------------------------------------ecScrolledWindow::ecScrolledWindow(){    m_xScrollPixelsPerLine = 0;    m_yScrollPixelsPerLine = 0;    m_xScrollingEnabled = TRUE;    m_yScrollingEnabled = TRUE;    m_xScrollPosition = 0;    m_yScrollPosition = 0;    m_xScrollLines = 0;    m_yScrollLines = 0;    m_xScrollLinesPerPage = 0;    m_yScrollLinesPerPage = 0;    m_scaleX = 1.0;    m_scaleY = 1.0;    m_targetWindow = (wxWindow*) NULL;}bool ecScrolledWindow::Create(wxWindow *parent,                              wxWindowID id,                              const wxPoint& pos,                              const wxSize& size,                              long style,                              const wxString& name){    m_xScrollPixelsPerLine = 0;    m_yScrollPixelsPerLine = 0;    m_xScrollingEnabled = TRUE;    m_yScrollingEnabled = TRUE;    m_xScrollPosition = 0;    m_yScrollPosition = 0;    m_xScrollLines = 0;    m_yScrollLines = 0;    m_xScrollLinesPerPage = 0;    m_yScrollLinesPerPage = 0;    m_scaleX = 1.0;    m_scaleY = 1.0;    m_targetWindow = this;    bool ok = wxPanel::Create(parent, id, pos, size, style, name);#if defined(__WXMSW__) && (wxVERSION_NUMBER < 2302)    // we need to process arrows ourselves for scrolling    m_lDlgCode |= DLGC_WANTARROWS;#endif // __WXMSW__    return ok;}ecScrolledWindow::~ecScrolledWindow(){}// ----------------------------------------------------------------------------// setting scrolling parameters// ----------------------------------------------------------------------------/* * pixelsPerUnitX/pixelsPerUnitY: number of pixels per unit (e.g. pixels per text line) * noUnitsX/noUnitsY:        : no. units per scrollbar */void ecScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY,               int noUnitsX, int noUnitsY,               int xPos, int yPos, bool noRefresh ){    int xpos, ypos;    CalcUnscrolledPosition(xPos, yPos, &xpos, &ypos);    bool do_refresh =    (      (noUnitsX != 0 && m_xScrollLines == 0) ||      (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX*noUnitsX) ||       (noUnitsY != 0 && m_yScrollLines == 0) ||      (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY*noUnitsY) ||      (xPos != m_xScrollPosition) ||      (yPos != m_yScrollPosition)//       (pixelsPerUnitX != m_xScrollPixelsPerLine) ||//       (pixelsPerUnitY != m_yScrollPixelsPerLine)    );    m_xScrollPixelsPerLine = pixelsPerUnitX;    m_yScrollPixelsPerLine = pixelsPerUnitY;    m_xScrollPosition = xPos;    m_yScrollPosition = yPos;    m_xScrollLines = noUnitsX;    m_yScrollLines = noUnitsY;#ifdef __WXMOTIF__    // Sorry, some Motif-specific code to implement a backing pixmap    // for the wxRETAINED style. Implementing a backing store can't    // be entirely generic because it relies on the wxWindowDC implementation    // to duplicate X drawing calls for the backing pixmap.    if ((m_windowStyle & wxRETAINED) == wxRETAINED)    {        Display* dpy = XtDisplay((Widget) GetMainWidget());        int totalPixelWidth = m_xScrollLines * m_xScrollPixelsPerLine;        int totalPixelHeight = m_yScrollLines * m_yScrollPixelsPerLine;        if (m_backingPixmap &&           !((m_pixmapWidth == totalPixelWidth) &&             (m_pixmapHeight == totalPixelHeight)))        {            XFreePixmap (dpy, (Pixmap) m_backingPixmap);            m_backingPixmap = (WXPixmap) 0;        }        if (!m_backingPixmap &&           (noUnitsX != 0) && (noUnitsY != 0))        {            int depth = wxDisplayDepth();            m_pixmapWidth = totalPixelWidth;            m_pixmapHeight = totalPixelHeight;            m_backingPixmap = (WXPixmap) XCreatePixmap (dpy, RootWindow (dpy, DefaultScreen (dpy)),            m_pixmapWidth, m_pixmapHeight, depth);        }    }#endif // Motif    AdjustScrollbars();    if (do_refresh && !noRefresh)        m_targetWindow->Refresh();#ifdef __WXMSW__    // GRG: if this turns out to be really necessary, we could    //   at least move it to the above if { ... } so that it is    //   only done if noRefresh = FALSE (the default). OTOH, if    //   this doesn't break anything, which seems to be the    //   case, we could just leave it out.    // Necessary?    // UpdateWindow ((HWND) m_targetWindow->GetHWND());#endif#ifdef __WXMAC__    m_targetWindow->MacUpdateImmediately() ;#endif}// ----------------------------------------------------------------------------// target window handling// ----------------------------------------------------------------------------void ecScrolledWindow::SetTargetWindow( wxWindow *target ){    wxASSERT_MSG( target, wxT("target window must not be NULL") );    m_targetWindow = target;}wxWindow *ecScrolledWindow::GetTargetWindow(){    return m_targetWindow;}// ----------------------------------------------------------------------------// scrolling implementation itself// ----------------------------------------------------------------------------void ecScrolledWindow::OnScroll(wxScrollWinEvent& event){    int orient = event.GetOrientation();    int nScrollInc = CalcScrollInc(event);    if (nScrollInc == 0) return;    if (orient == wxHORIZONTAL)    {        int newPos = m_xScrollPosition + nScrollInc;        SetScrollPos(wxHORIZONTAL, newPos, TRUE );    }    else    {        int newPos = m_yScrollPosition + nScrollInc;        SetScrollPos(wxVERTICAL, newPos, TRUE );    }    if (orient == wxHORIZONTAL)    {        m_xScrollPosition += nScrollInc;    }    else    {        m_yScrollPosition += nScrollInc;    }    if (orient == wxHORIZONTAL)    {       if (m_xScrollingEnabled)            m_targetWindow->ScrollWindow(-m_xScrollPixelsPerLine * nScrollInc, 0, (const wxRect *) NULL);       else            m_targetWindow->Refresh();    }    else    {        if (m_yScrollingEnabled)            m_targetWindow->ScrollWindow(0, -m_yScrollPixelsPerLine * nScrollInc, (const wxRect *) NULL);        else            m_targetWindow->Refresh();    }#ifdef __WXMAC__    m_targetWindow->MacUpdateImmediately() ;#endif}int ecScrolledWindow::CalcScrollInc(wxScrollWinEvent& event){    int pos = event.GetPosition();    int orient = event.GetOrientation();    int nScrollInc = 0;    if (event.GetEventType() == wxEVT_SCROLLWIN_TOP)    {            if (orient == wxHORIZONTAL)                nScrollInc = - m_xScrollPosition;            else                nScrollInc = - m_yScrollPosition;    } else    if (event.GetEventType() == wxEVT_SCROLLWIN_BOTTOM)    {            if (orient == wxHORIZONTAL)                nScrollInc = m_xScrollLines - m_xScrollPosition;            else                nScrollInc = m_yScrollLines - m_yScrollPosition;    } else    if (event.GetEventType() == wxEVT_SCROLLWIN_LINEUP)    {            nScrollInc = -1;    } else    if (event.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN)    {            nScrollInc = 1;    } else    if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEUP)    {            if (orient == wxHORIZONTAL)                nScrollInc = -GetScrollPageSize(wxHORIZONTAL);            else                nScrollInc = -GetScrollPageSize(wxVERTICAL);    } else    if (event.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN)    {            if (orient == wxHORIZONTAL)                nScrollInc = GetScrollPageSize(wxHORIZONTAL);            else                nScrollInc = GetScrollPageSize(wxVERTICAL);    } else    if ((event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK) ||        (event.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE))    {            if (orient == wxHORIZONTAL)                nScrollInc = pos - m_xScrollPosition;            else                nScrollInc = pos - m_yScrollPosition;    }    if (orient == wxHORIZONTAL)    {        if (m_xScrollPixelsPerLine > 0)        {            int w, h;            m_targetWindow->GetClientSize(&w, &h);            int nMaxWidth = m_xScrollLines*m_xScrollPixelsPerLine;            int noPositions = (int) ( ((nMaxWidth - w)/(double)m_xScrollPixelsPerLine) + 0.5 );            if (noPositions < 0)                noPositions = 0;            if ( (m_xScrollPosition + nScrollInc) < 0 )                nScrollInc = -m_xScrollPosition; // As -ve as we can go

⌨️ 快捷键说明

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