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

📄 toplevel.cpp

📁 很牛的GUI源码wxWidgets-2.8.0.zip 可在多种平台下运行.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    wxSize m_size ;    bool m_wasResizable ;} FullScreenData ;void wxTopLevelWindowMac::Init(){    m_iconized =    m_maximizeOnShow = false;    m_macWindow = NULL ;    m_macEventHandler = NULL ;    m_macFullScreenData = NULL ;}class wxMacDeferredWindowDeleter : public wxObject{public :    wxMacDeferredWindowDeleter( WindowRef windowRef )    {        m_macWindow = windowRef ;    }    virtual ~wxMacDeferredWindowDeleter()    {        UMADisposeWindow( (WindowRef) m_macWindow ) ;    }protected :    WindowRef m_macWindow ;} ;bool wxTopLevelWindowMac::Create(wxWindow *parent,                                 wxWindowID id,                                 const wxString& title,                                 const wxPoint& pos,                                 const wxSize& size,                                 long style,                                 const wxString& name){    // init our fields    Init();    m_windowStyle = style;    SetName( name );    m_windowId = id == -1 ? NewControlId() : id;    wxWindow::SetLabel( title ) ;    MacCreateRealWindow( title, pos , size , MacRemoveBordersFromStyle(style) , name ) ;    SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));    if (GetExtraStyle() & wxFRAME_EX_METAL)        MacSetMetalAppearance(true);    wxTopLevelWindows.Append(this);    if ( parent )        parent->AddChild(this);    return true;}wxTopLevelWindowMac::~wxTopLevelWindowMac(){    if ( m_macWindow )    {#if wxUSE_TOOLTIPS        wxToolTip::NotifyWindowDelete(m_macWindow) ;#endif        wxPendingDelete.Append( new wxMacDeferredWindowDeleter( (WindowRef) m_macWindow ) ) ;    }    if ( m_macEventHandler )    {        ::RemoveEventHandler((EventHandlerRef) m_macEventHandler);        m_macEventHandler = NULL ;    }    wxRemoveMacWindowAssociation( this ) ;    if ( wxModelessWindows.Find(this) )        wxModelessWindows.DeleteObject(this);    FullScreenData *data = (FullScreenData *) m_macFullScreenData ;    delete data ;    m_macFullScreenData = NULL ;}// ----------------------------------------------------------------------------// wxTopLevelWindowMac maximize/minimize// ----------------------------------------------------------------------------void wxTopLevelWindowMac::Maximize(bool maximize){    Point idealSize = { 0 , 0 } ;    if ( maximize )    {#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5        HIRect bounds ;        HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,            &bounds);        idealSize.h = bounds.size.width;        idealSize.v = bounds.size.height;#else        Rect rect ;        GetAvailableWindowPositioningBounds(GetMainDevice(),&rect) ;        idealSize.h = rect.right - rect.left ;        idealSize.v = rect.bottom - rect.top ;#endif    }    ZoomWindowIdeal( (WindowRef)m_macWindow , maximize ? inZoomOut : inZoomIn , &idealSize ) ;}bool wxTopLevelWindowMac::IsMaximized() const{    return IsWindowInStandardState( (WindowRef)m_macWindow , NULL , NULL ) ;}void wxTopLevelWindowMac::Iconize(bool iconize){    if ( IsWindowCollapsable( (WindowRef)m_macWindow) )        CollapseWindow( (WindowRef)m_macWindow , iconize ) ;}bool wxTopLevelWindowMac::IsIconized() const{    return IsWindowCollapsed((WindowRef)m_macWindow ) ;}void wxTopLevelWindowMac::Restore(){    if ( IsMaximized() )        Maximize(false);    else if ( IsIconized() )        Iconize(false);}// ----------------------------------------------------------------------------// wxTopLevelWindowMac misc// ----------------------------------------------------------------------------wxPoint wxTopLevelWindowMac::GetClientAreaOrigin() const{    return wxPoint(0, 0) ;}void wxTopLevelWindowMac::SetIcon(const wxIcon& icon){    // this sets m_icon    wxTopLevelWindowBase::SetIcon(icon);}void  wxTopLevelWindowMac::MacSetBackgroundBrush( const wxBrush &brush ){    wxTopLevelWindowBase::MacSetBackgroundBrush( brush ) ;    if ( m_macBackgroundBrush.Ok() && m_macBackgroundBrush.GetStyle() != wxTRANSPARENT && m_macBackgroundBrush.MacGetBrushKind() == kwxMacBrushTheme )    {        SetThemeWindowBackground( (WindowRef) m_macWindow , m_macBackgroundBrush.MacGetTheme() , false ) ;    }}void wxTopLevelWindowMac::MacInstallTopLevelWindowEventHandler(){    if ( m_macEventHandler != NULL )    {        verify_noerr( ::RemoveEventHandler( (EventHandlerRef) m_macEventHandler ) ) ;    }    InstallWindowEventHandler(        MAC_WXHWND(m_macWindow), GetwxMacTopLevelEventHandlerUPP(),        GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macEventHandler );}void  wxTopLevelWindowMac::MacCreateRealWindow(    const wxString& title,    const wxPoint& pos,    const wxSize& size,    long style,    const wxString& name ){    OSStatus err = noErr ;    SetName(name);    m_windowStyle = style;    m_isShown = false;    // create frame.    int x = (int)pos.x;    int y = (int)pos.y;    Rect theBoundsRect;    wxRect display = wxGetClientDisplayRect() ;    if ( x == wxDefaultPosition.x )        x = display.x ;    if ( y == wxDefaultPosition.y )        y = display.y ;    int w = WidthDefault(size.x);    int h = HeightDefault(size.y);    ::SetRect(&theBoundsRect, x, y , x + w, y + h);    // translate the window attributes in the appropriate window class and attributes    WindowClass wclass = 0;    WindowAttributes attr = kWindowNoAttributes ;    WindowGroupRef group = NULL ;    if ( HasFlag( wxFRAME_TOOL_WINDOW) )    {        if (            HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||            HasFlag( wxSYSTEM_MENU ) || HasFlag( wxCAPTION ) ||            HasFlag(wxTINY_CAPTION_HORIZ) ||  HasFlag(wxTINY_CAPTION_VERT)            )        {            wclass = kFloatingWindowClass ;            if ( HasFlag(wxTINY_CAPTION_VERT) )                attr |= kWindowSideTitlebarAttribute ;        }        else        {            wclass = kPlainWindowClass ;        }    }    else if ( HasFlag( wxCAPTION ) )    {        wclass = kDocumentWindowClass ;        attr |= kWindowInWindowMenuAttribute ;    }#if defined( __WXMAC__ ) && TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_2 )    else if ( HasFlag( wxFRAME_DRAWER ) )    {        wclass = kDrawerWindowClass;    }#endif  //10.2 and up    else    {        if ( HasFlag( wxMINIMIZE_BOX ) || HasFlag( wxMAXIMIZE_BOX ) ||            HasFlag( wxCLOSE_BOX ) || HasFlag( wxSYSTEM_MENU ) )        {            wclass = kDocumentWindowClass ;        }        else        {            wclass = kPlainWindowClass ;        }    }    if ( wclass != kPlainWindowClass )    {        if ( HasFlag( wxMINIMIZE_BOX ) )            attr |= kWindowCollapseBoxAttribute ;        if ( HasFlag( wxMAXIMIZE_BOX ) )            attr |= kWindowFullZoomAttribute ;        if ( HasFlag( wxRESIZE_BORDER ) )            attr |= kWindowResizableAttribute ;        if ( HasFlag( wxCLOSE_BOX) )            attr |= kWindowCloseBoxAttribute ;    }    // turn on live resizing (OS X only)    if (UMAGetSystemVersion() >= 0x1000)        attr |= kWindowLiveResizeAttribute;    if ( HasFlag(wxSTAY_ON_TOP) )        group = GetWindowGroupOfClass(kUtilityWindowClass) ;    attr |= kWindowCompositingAttribute;#if 0 // wxMAC_USE_CORE_GRAPHICS ; TODO : decide on overall handling of high dpi screens (pixel vs userscale)    attr |= kWindowFrameworkScaledAttribute;#endif    if ( HasFlag(wxFRAME_SHAPED) )    {        WindowDefSpec customWindowDefSpec;        customWindowDefSpec.defType = kWindowDefProcPtr;        customWindowDefSpec.u.defProc = #ifdef __LP64__            (WindowDefUPP) wxShapedMacWindowDef;#else            NewWindowDefUPP(wxShapedMacWindowDef);#endif        err = ::CreateCustomWindow( &customWindowDefSpec, wclass,                              attr, &theBoundsRect,                              (WindowRef*) &m_macWindow);    }    else    {        err = ::CreateNewWindow( wclass , attr , &theBoundsRect , (WindowRef*)&m_macWindow ) ;    }    if ( err == noErr && m_macWindow != NULL && group != NULL )        SetWindowGroup( (WindowRef) m_macWindow , group ) ;    wxCHECK_RET( err == noErr, wxT("Mac OS error when trying to create new window") );    // setup a separate group for each window, so that overlays can be handled easily    verify_noerr( CreateWindowGroup( kWindowGroupAttrMoveTogether | kWindowGroupAttrLayerTogether | kWindowGroupAttrHideOnCollapse, &group ));    verify_noerr( SetWindowGroupParent( group, GetWindowGroup( (WindowRef) m_macWindow )));    verify_noerr( SetWindowGroup( (WindowRef) m_macWindow , group ));      // the create commands are only for content rect,    // so we have to set the size again as structure bounds    SetWindowBounds(  (WindowRef) m_macWindow , kWindowStructureRgn , &theBoundsRect ) ;    wxAssociateWinWithMacWindow( (WindowRef) m_macWindow , this ) ;    UMASetWTitle( (WindowRef) m_macWindow , title , m_font.GetEncoding() ) ;    m_peer = new wxMacControl(this , true /*isRootControl*/) ;    // There is a bug in 10.2.X for ::GetRootControl returning the window view instead of    // the content view, so we have to retrieve it explicitly    HIViewFindByID( HIViewGetRoot( (WindowRef) m_macWindow ) , kHIViewWindowContentID ,        m_peer->GetControlRefAddr() ) ;    if ( !m_peer->Ok() )    {        // compatibility mode fallback        GetRootControl( (WindowRef) m_macWindow , m_peer->GetControlRefAddr() ) ;    }    // the root control level handler    MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() ) ;    // Causes the inner part of the window not to be metal    // if the style is used before window creation.#if 0 // TARGET_API_MAC_OSX    if ( m_macUsesCompositing && m_macWindow != NULL )    {        if ( GetExtraStyle() & wxFRAME_EX_METAL )            MacSetMetalAppearance( true ) ;    }#endif    // the frame window event handler    InstallStandardEventHandler( GetWindowEventTarget(MAC_WXHWND(m_macWindow)) ) ;    MacInstallTopLevelWindowEventHandler() ;    DoSetWindowVariant( m_windowVariant ) ;    m_macFocus = NULL ;    if ( HasFlag(wxFRAME_SHAPED) )    {        // default shape matches the window size        wxRegion rgn( 0, 0, w, h );        SetShape( rgn );    }    wxWindowCreateEvent event(this);    GetEventHandler()->ProcessEvent(event);}void wxTopLevelWindowMac::ClearBackground(){    wxWindow::ClearBackground() ;}// 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::MacDelayedDeactivation(long timestamp){    if (s_macDeactivateWindow)    {        wxLogTrace(TRACE_ACTIVATE,                   wxT("Doing delayed deactivation of %p"),                   s_macDeactivateWindow);        s_macDeactivateWindow->MacActivate(timestamp, false);    }}void wxTopLevelWindowMac::MacActivate( long timestamp , bool inIsActivating ){    wxLogTrace(TRACE_ACTIVATE, wxT("TopLevel=%p::MacActivate"), this);    if (s_macDeactivateWindow == this)        s_macDeactivateWindow = NULL;    MacDelayedDeactivation(timestamp);    MacPropagateHiliteChanged() ;}void 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 ( !wxTopLevelWindowBase::Show(show) )        return false;    bool plainTransition = false;#if wxUSE_SYSTEM_OPTIONS    // code contributed by Ryan Wilcox December 18, 2003    plainTransition = UMAGetSystemVersion() >= 0x1000 ;    if ( wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) )        plainTransition = ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1 ) ;#endif    if (show)    {        if ( plainTransition )           ::ShowWindow( (WindowRef)m_macWindow );        else           ::TransitionWindow( (WindowRef)m_macWindow, kWindowZoomTransitionEffect, kWindowShowTransitionAction, NULL );        ::SelectWindow( (WindowRef)m_macWindow ) ;        // because apps expect a size event to occur at this moment        wxSizeEvent event(GetSize() , m_windowId);        event.SetEventObject(this);        GetEventHandler()->ProcessEvent(event);    }    else    {

⌨️ 快捷键说明

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