📄 toplevel.cpp
字号:
} else #endif { ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowShowTransitionAction,nil); } ::SelectWindow( (WindowRef)m_macWindow ) ; // no need to generate events here, they will get them triggered by macos // actually they should be , but apparently they are not wxSize size(m_width, m_height); wxSizeEvent event(size, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } else { #if wxUSE_SYSTEM_OPTIONS if ( (wxSystemOptions::HasOption(wxMAC_WINDOW_PLAIN_TRANSITION) ) && ( wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION ) == 1) ) { ::HideWindow((WindowRef) m_macWindow ); } else #endif { ::TransitionWindow((WindowRef)m_macWindow,kWindowZoomTransitionEffect,kWindowHideTransitionAction,nil); } } if ( !show ) { } else { Refresh() ; } return true;}void wxTopLevelWindowMac::DoMoveWindow(int x, int y, int width, int height){ wxMacPortStateHelper help( (GrafPtr) GetWindowPort( (WindowRef) m_macWindow) ) ; wxMacWindowClipper clip (this); int former_x = m_x ; int former_y = m_y ; int former_w = m_width ; int former_h = m_height ; int actualWidth = width; int actualHeight = height; int actualX = x; int actualY = y; if ((m_minWidth != -1) && (actualWidth < m_minWidth)) actualWidth = m_minWidth; if ((m_minHeight != -1) && (actualHeight < m_minHeight)) actualHeight = m_minHeight; if ((m_maxWidth != -1) && (actualWidth > m_maxWidth)) actualWidth = m_maxWidth; if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) actualHeight = m_maxHeight; bool doMove = false ; bool doResize = false ; if ( actualX != former_x || actualY != former_y ) { doMove = true ; } if ( actualWidth != former_w || actualHeight != former_h ) { doResize = true ; } if ( doMove || doResize ) { m_x = actualX ; m_y = actualY ; if ( doMove ) ::MoveWindow((WindowRef)m_macWindow, m_x, m_y , false); // don't make frontmost m_width = actualWidth ; m_height = actualHeight ; if ( doResize ) ::SizeWindow((WindowRef)m_macWindow, m_width, m_height , true); // the OS takes care of invalidating and erasing the new area so we only have to // take care of refreshing for full repaints if ( doResize && HasFlag(wxFULL_REPAINT_ON_RESIZE) ) Refresh() ; if ( IsKindOf( CLASSINFO( wxFrame ) ) ) { wxFrame* frame = (wxFrame*) this ;#if wxUSE_STATUSBAR frame->PositionStatusBar();#endif#if wxUSE_TOOLBAR frame->PositionToolBar();#endif } if ( doMove ) wxWindowMac::MacTopLevelWindowChangedPosition() ; // like this only children will be notified MacRepositionScrollBars() ; if ( doMove ) { wxPoint point(m_x, m_y); wxMoveEvent event(point, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event) ; } if ( doResize ) { MacRepositionScrollBars() ; wxSize size(m_width, m_height); wxSizeEvent event(size, m_windowId); event.SetEventObject(this); GetEventHandler()->ProcessEvent(event); } }}/* * Invalidation Mechanism * * The update mechanism reflects exactely the windows mechanism * the rect gets added to the window invalidate region, if the eraseBackground flag * has been true for any part of the update rgn the background is erased in the entire region * not just in the specified rect. * * In order to achive this, we also have an internal m_macNoEraseUpdateRgn, all rects that have * the eraseBackground flag set to false are also added to this rgn. upon receiving an update event * the update rgn is compared to the m_macNoEraseUpdateRgn and in case they differ, every window * will get the eraseBackground event first */void wxTopLevelWindowMac::MacInvalidate( const WXRECTPTR rect, bool eraseBackground ){ GrafPtr formerPort ; GetPort( &formerPort ) ; SetPortWindowPort( (WindowRef)m_macWindow ) ; m_macNeedsErasing |= eraseBackground ; // if we already know that we will have to erase, there's no need to track the rest if ( !m_macNeedsErasing) { // we end only here if eraseBackground is false // if we already have a difference between m_macNoEraseUpdateRgn and UpdateRgn // we will have to erase anyway RgnHandle updateRgn = NewRgn(); RgnHandle diffRgn = NewRgn() ; if ( updateRgn && diffRgn ) { GetWindowUpdateRgn( (WindowRef)m_macWindow , updateRgn ); Point pt = {0,0} ; LocalToGlobal( &pt ) ; OffsetRgn( updateRgn , -pt.h , -pt.v ) ; DiffRgn( updateRgn , (RgnHandle) m_macNoEraseUpdateRgn , diffRgn ) ; if ( !EmptyRgn( diffRgn ) ) { m_macNeedsErasing = true ; } } if ( updateRgn ) DisposeRgn( updateRgn ); if ( diffRgn ) DisposeRgn( diffRgn ); if ( !m_macNeedsErasing ) { RgnHandle rectRgn = NewRgn() ; SetRectRgn( rectRgn , ((Rect*)rect)->left , ((Rect*)rect)->top , ((Rect*)rect)->right , ((Rect*)rect)->bottom ) ; UnionRgn( (RgnHandle) m_macNoEraseUpdateRgn , rectRgn , (RgnHandle) m_macNoEraseUpdateRgn ) ; DisposeRgn( rectRgn ) ; } } InvalWindowRect( (WindowRef)m_macWindow , (Rect*)rect ) ; // turn this on to debug the refreshing cycle#if wxMAC_DEBUG_REDRAW PaintRect( rect ) ;#endif SetPort( formerPort ) ;}bool wxTopLevelWindowMac::SetShape(const wxRegion& region){ wxCHECK_MSG( HasFlag(wxFRAME_SHAPED), false, _T("Shaped windows must be created with the wxFRAME_SHAPED style."));#if TARGET_CARBON // The empty region signifies that the shape should be removed from the // window. if ( region.IsEmpty() ) { wxSize sz = GetClientSize(); wxRegion rgn(0, 0, sz.x, sz.y); return SetShape(rgn); } // Make a copy of the region RgnHandle shapeRegion = NewRgn(); CopyRgn( (RgnHandle)region.GetWXHRGN(), shapeRegion ); // Dispose of any shape region we may already have RgnHandle oldRgn = (RgnHandle)GetWRefCon( (WindowRef)MacGetWindowRef() ); if ( oldRgn ) DisposeRgn(oldRgn); // Save the region so we can use it later SetWRefCon((WindowRef)MacGetWindowRef(), (SInt32)shapeRegion); // Tell the window manager that the window has changed shape ReshapeCustomWindow((WindowRef)MacGetWindowRef()); return true;#else return false;#endif}// ---------------------------------------------------------------------------// Support functions for shaped windows, based on Apple's CustomWindow sample at// http://developer.apple.com/samplecode/Sample_Code/Human_Interface_Toolbox/Mac_OS_High_Level_Toolbox/CustomWindow.htm// ---------------------------------------------------------------------------#if TARGET_CARBONstatic void wxShapedMacWindowGetPos(WindowRef window, Rect* inRect){ GetWindowPortBounds(window, inRect); Point pt = {inRect->left, inRect->top}; SetPort((GrafPtr) GetWindowPort(window)); LocalToGlobal(&pt); inRect->top = pt.v; inRect->left = pt.h; inRect->bottom += pt.v; inRect->right += pt.h;}static SInt32 wxShapedMacWindowGetFeatures(WindowRef window, SInt32 param){ /*------------------------------------------------------ Define which options your custom window supports. --------------------------------------------------------*/ //just enable everything for our demo *(OptionBits*)param=//kWindowCanGrow| //kWindowCanZoom| //kWindowCanCollapse| //kWindowCanGetWindowRegion| //kWindowHasTitleBar| //kWindowSupportsDragHilite| kWindowCanDrawInCurrentPort| //kWindowCanMeasureTitle| kWindowWantsDisposeAtProcessDeath| kWindowSupportsSetGrowImageRegion| kWindowDefSupportsColorGrafPort; return 1;}// The content region is left as a rectangle matching the window size, this is// so the origin in the paint event, and etc. still matches what the// programmer expects.static void wxShapedMacWindowContentRegion(WindowRef window, RgnHandle rgn){ SetEmptyRgn(rgn); wxTopLevelWindowMac* win = wxFindWinFromMacWindow(window); if (win) { wxRect r = win->GetRect(); SetRectRgn(rgn, r.GetLeft(), r.GetTop(), r.GetRight(), r.GetBottom()); }}// The structure region is set to the shape given to the SetShape method.static void wxShapedMacWindowStructureRegion(WindowRef window, RgnHandle rgn){ RgnHandle cachedRegion = (RgnHandle) GetWRefCon(window); SetEmptyRgn(rgn); if (cachedRegion) { Rect windowRect; wxShapedMacWindowGetPos(window, &windowRect); //how big is the window CopyRgn(cachedRegion, rgn); //make a copy of our cached region OffsetRgn(rgn, windowRect.left, windowRect.top); // position it over window //MapRgn(rgn, &mMaskSize, &windowRect); //scale it to our actual window size }}static SInt32 wxShapedMacWindowGetRegion(WindowRef window, SInt32 param){ GetWindowRegionPtr rgnRec=(GetWindowRegionPtr)param; switch(rgnRec->regionCode) { case kWindowStructureRgn: wxShapedMacWindowStructureRegion(window, rgnRec->winRgn); break; case kWindowContentRgn: wxShapedMacWindowContentRegion(window, rgnRec->winRgn); break; default: SetEmptyRgn(rgnRec->winRgn); } //switch return noErr;}static SInt32 wxShapedMacWindowHitTest(WindowRef window,SInt32 param){ /*------------------------------------------------------ Determine the region of the window which was hit --------------------------------------------------------*/ Point hitPoint; static RgnHandle tempRgn=nil; if(!tempRgn) tempRgn=NewRgn(); SetPt(&hitPoint,LoWord(param),HiWord(param));//get the point clicked //Mac OS 8.5 or later wxShapedMacWindowStructureRegion(window, tempRgn); if (PtInRgn(hitPoint, tempRgn)) //in window content region? return wInContent; return wNoHit;//no significant area was hit.}static pascal long wxShapedMacWindowDef(short varCode, WindowRef window, SInt16 message, SInt32 param){ switch(message) { case kWindowMsgHitTest: return wxShapedMacWindowHitTest(window,param); case kWindowMsgGetFeatures: return wxShapedMacWindowGetFeatures(window,param); // kWindowMsgGetRegion is sent during CreateCustomWindow and ReshapeCustomWindow case kWindowMsgGetRegion: return wxShapedMacWindowGetRegion(window,param); } return 0;}#endif// ---------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -