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

📄 toplevel.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#if 0 //  having problems right now with that    if (HasFlag(wxSTAY_ON_TOP))        wclass = kUtilityWindowClass;#endif#endif    //this setup lets us have compositing and non-compositing    //windows in the same application.#if UNIVERSAL_INTERFACES_VERSION >= 0x0400    if ( wxTopLevelWindowMac::s_macWindowCompositing )    {        attr |= kWindowCompositingAttribute;        m_macUsesCompositing = true;    }    else#endif    {        m_macUsesCompositing = false;    }#if TARGET_CARBON    if ( HasFlag(wxFRAME_SHAPED) )    {        WindowDefSpec customWindowDefSpec;        customWindowDefSpec.defType = kWindowDefProcPtr;        customWindowDefSpec.u.defProc = NewWindowDefUPP(wxShapedMacWindowDef);        err = ::CreateCustomWindow( &customWindowDefSpec, wclass,                              attr, &theBoundsRect,                              (WindowRef*) &m_macWindow);    }    else#endif    {        err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;    }    wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );    wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;    UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;    if ( wxTopLevelWindowMac::s_macWindowCompositing )    {        ::GetRootControl( (WindowRef)m_macWindow, (ControlHandle*)&m_macRootControl ) ;    }    else    {        ::CreateRootControl( (WindowRef)m_macWindow , (ControlHandle*)&m_macRootControl ) ;    }#if TARGET_CARBON    InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;    InstallWindowEventHandler(MAC_WXHWND(m_macWindow), GetwxMacWindowEventHandlerUPP(),        GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler);#endif    m_macFocus = NULL ;#if TARGET_CARBON    if ( HasFlag(wxFRAME_SHAPED) )    {        // default shape matches the window size        wxRegion rgn(0, 0, m_width, m_height);        SetShape(rgn);    }#endif    wxWindowCreateEvent event(this);    GetEventHandler()->ProcessEvent(event);}bool wxTopLevelWindowMac::MacEnableCompositing( bool useCompositing ){    bool oldval = s_macWindowCompositing;    s_macWindowCompositing = useCompositing;    return oldval;}void wxTopLevelWindowMac::MacGetPortParams(WXPOINTPTR localOrigin, WXRECTPTR clipRect, WXWindow *window  , wxWindowMac** rootwin){    ((Point*)localOrigin)->h = 0;    ((Point*)localOrigin)->v = 0;    ((Rect*)clipRect)->left = 0;    ((Rect*)clipRect)->top = 0;    ((Rect*)clipRect)->right = m_width;    ((Rect*)clipRect)->bottom = m_height;    *window = m_macWindow ;    *rootwin = this ;}void wxTopLevelWindowMac::ClearBackground(){    wxWindow::ClearBackground() ;}WXWidget wxTopLevelWindowMac::MacGetContainerForEmbedding(){    return m_macRootControl ;}void wxTopLevelWindowMac::MacUpdate( long timestamp){    wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ;    RgnHandle       visRgn = NewRgn() ;    GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), visRgn );    BeginUpdate( (WindowRef)m_macWindow ) ;    RgnHandle       updateRgn = NewRgn();    RgnHandle       diffRgn = NewRgn() ;    if ( updateRgn && diffRgn )    {#if 1        // macos internal control redraws clean up areas we'd like to redraw ourselves        // therefore we pick the boundary rect and make sure we can redraw it        // this has to be intersected by the visRgn in order to avoid drawing over its own        // boundaries        RgnHandle trueUpdateRgn = NewRgn() ;        Rect trueUpdateRgnBoundary ;        GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), trueUpdateRgn );        GetRegionBounds( trueUpdateRgn , &trueUpdateRgnBoundary ) ;        RectRgn( updateRgn , &trueUpdateRgnBoundary ) ;        SectRgn( updateRgn , visRgn , updateRgn ) ;        if ( trueUpdateRgn )            DisposeRgn( trueUpdateRgn ) ;        SetPortVisibleRegion(  GetWindowPort( (WindowRef)m_macWindow ), updateRgn ) ;#else        GetPortVisibleRegion( GetWindowPort( (WindowRef)m_macWindow ), updateRgn );#endif        DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ;        if ( !EmptyRgn( updateRgn ) )        {            MacRedraw( updateRgn , timestamp , m_macNeedsErasing || !EmptyRgn( diffRgn )  ) ;        }    }    if ( updateRgn )        DisposeRgn( updateRgn );    if ( diffRgn )        DisposeRgn( diffRgn );    if ( visRgn )        DisposeRgn( visRgn ) ;    EndUpdate( (WindowRef)m_macWindow ) ;    SetEmptyRgn( (RgnHandle) m_macNoEraseUpdateRgn ) ;    m_macNeedsErasing = false ;}// Raise the window to the top of the Z ordervoid wxTopLevelWindowMac::Raise(){    ::SelectWindow( (WindowRef)m_macWindow ) ;}// Lower the window to the bottom of the Z ordervoid wxTopLevelWindowMac::Lower(){    ::SendBehind( (WindowRef)m_macWindow , NULL ) ;}void wxTopLevelWindowMac::MacFireMouseEvent(    wxUint16 kind , wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp ){    wxMouseEvent event(wxEVT_LEFT_DOWN);    bool isDown = !(modifiers & btnState) ; // 1 is for up    bool controlDown = modifiers & controlKey ; // for simulating right mouse    event.m_leftDown = isDown && !controlDown;    event.m_middleDown = false;    event.m_rightDown = isDown && controlDown;    if ( kind == mouseDown )    {        if ( controlDown )            event.SetEventType(wxEVT_RIGHT_DOWN ) ;        else            event.SetEventType(wxEVT_LEFT_DOWN ) ;    }    else if ( kind == mouseUp )    {        if ( controlDown )            event.SetEventType(wxEVT_RIGHT_UP ) ;        else            event.SetEventType(wxEVT_LEFT_UP ) ;    }    else    {        event.SetEventType(wxEVT_MOTION ) ;    }    event.m_shiftDown = modifiers & shiftKey;    event.m_controlDown = modifiers & controlKey;    event.m_altDown = modifiers & optionKey;    event.m_metaDown = modifiers & cmdKey;    Point       localwhere ;    localwhere.h = x ;    localwhere.v = y ;    GrafPtr     port ;    ::GetPort( &port ) ;    ::SetPort( UMAGetWindowPort( (WindowRef)m_macWindow ) ) ;    ::GlobalToLocal( &localwhere ) ;    ::SetPort( port ) ;    if ( kind == mouseDown )    {        if ( timestamp - gs_lastWhen <= (long) GetDblTime() )        {            if ( abs( localwhere.h - gs_lastWhere.h ) < 3 && abs( localwhere.v - gs_lastWhere.v ) < 3 )            {                // This is not right if the second mouse down                // event occurred in a different window. We                // correct this in MacDispatchMouseEvent.                if ( controlDown )                    event.SetEventType(wxEVT_RIGHT_DCLICK ) ;                else                    event.SetEventType(wxEVT_LEFT_DCLICK ) ;            }            gs_lastWhen = 0 ;        }        else        {            gs_lastWhen = timestamp ;        }        gs_lastWhere = localwhere ;    }    event.m_x = localwhere.h;    event.m_y = localwhere.v;    event.m_x += m_x;    event.m_y += m_y;    event.SetTimestamp(timestamp);    event.SetEventObject(this);    if ( wxTheApp->s_captureWindow )    {        int x = event.m_x ;        int y = event.m_y ;        wxTheApp->s_captureWindow->ScreenToClient( &x , &y ) ;        event.m_x = x ;        event.m_y = y ;        event.SetEventObject( wxTheApp->s_captureWindow ) ;        wxTheApp->s_captureWindow->GetEventHandler()->ProcessEvent( event ) ;        if ( kind == mouseUp )        {            wxTheApp->s_captureWindow = NULL ;            if ( !wxIsBusy() )            {                m_cursor.MacInstall() ;            }        }    }    else    {        MacDispatchMouseEvent( event ) ;    }}#if !TARGET_CARBONvoid wxTopLevelWindowMac::MacMouseDown( WXEVENTREF ev , short part){    MacFireMouseEvent( mouseDown , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,        ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;}void wxTopLevelWindowMac::MacMouseUp( WXEVENTREF ev , short part){    switch (part)    {        case inContent:            {                MacFireMouseEvent( mouseUp , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,                    ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;            }            break ;    }}void wxTopLevelWindowMac::MacMouseMoved( WXEVENTREF ev , short part){    switch (part)    {        case inContent:            {                MacFireMouseEvent( nullEvent /*moved*/ , ((EventRecord*)ev)->where.h , ((EventRecord*)ev)->where.v ,                    ((EventRecord*)ev)->modifiers , ((EventRecord*)ev)->when ) ;            }            break ;    }}#endifvoid wxTopLevelWindowMac::MacDelayedDeactivation(long timestamp){    if(s_macDeactivateWindow)    {        wxLogDebug(wxT("Doing delayed deactivation of %p"),s_macDeactivateWindow);        s_macDeactivateWindow->MacActivate(timestamp, false);    }}void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ){    // wxLogDebug(wxT("TopLevel=%p::MacActivate"),this);    if(s_macDeactivateWindow==this)        s_macDeactivateWindow=NULL;    MacDelayedDeactivation(timestamp);    wxActivateEvent event(wxEVT_ACTIVATE, inIsActivating , m_windowId);    event.SetTimestamp(timestamp);    event.SetEventObject(this);    GetEventHandler()->ProcessEvent(event);    UMAHighlightAndActivateWindow( (WindowRef)m_macWindow , inIsActivating ) ;    // Early versions of MacOS X don't refresh backgrounds properly,    // so refresh the whole window on activation and deactivation.    long osVersion = UMAGetSystemVersion();    if (osVersion >= 0x1000 && osVersion < 0x1020 )    {        Refresh(true);    }    else    {        // for the moment we have to resolve some redrawing issues like this        // the OS is stealing some redrawing areas as soon as it draws a control        Refresh(true);    }}#if !TARGET_CARBONvoid wxTopLevelWindowMac::MacKeyDown( WXEVENTREF ev ){}#endifvoid wxTopLevelWindowMac::SetTitle(const wxString& title){    wxWindow::SetLabel( title ) ;    UMASetWTitle( (WindowRef)m_macWindow , title , m_font.GetEncoding() ) ;}wxString wxTopLevelWindowMac::GetTitle() const{    return wxWindow::GetLabel();}bool wxTopLevelWindowMac::Show(bool show){    if ( !wxWindow::Show(show) )        return false;    if (show)    {        #if wxUSE_SYSTEM_OPTIONS    //code contributed by Ryan Wilcox December 18, 2003        if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) )        {           ::ShowWindow( (WindowRef)m_macWindow );

⌨️ 快捷键说明

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