📄 window.cpp
字号:
{
}
wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers)
{
return kControlNoPart ;
}
void wxWindowMac::MacControlUserPaneActivateProc(bool activating)
{
}
wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action)
{
if ( AcceptsFocus() )
return 1 ;
else
return kControlNoPart ;
}
void wxWindowMac::MacControlUserPaneBackgroundProc(void* info)
{
}
#endif
// ---------------------------------------------------------------------------
// Scrollbar Tracking for all
// ---------------------------------------------------------------------------
pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode ) ;
pascal void wxMacLiveScrollbarActionProc( ControlRef control , ControlPartCode partCode )
{
if ( partCode != 0)
{
wxWindow* wx = wxFindControlFromMacControl( control ) ;
if ( wx )
wx->MacHandleControlClick( (WXWidget) control , partCode , true /* stillDown */ ) ;
}
}
wxMAC_DEFINE_PROC_GETTER( ControlActionUPP , wxMacLiveScrollbarActionProc ) ;
// ===========================================================================
// implementation
// ===========================================================================
WX_DECLARE_HASH_MAP(ControlRef, wxWindow*, wxPointerHash, wxPointerEqual, MacControlMap);
static MacControlMap wxWinMacControlList;
wxWindow *wxFindControlFromMacControl(ControlRef inControl )
{
MacControlMap::iterator node = wxWinMacControlList.find(inControl);
return (node == wxWinMacControlList.end()) ? NULL : node->second;
}
void wxAssociateControlWithMacControl(ControlRef inControl, wxWindow *control)
{
// adding NULL ControlRef is (first) surely a result of an error and
// (secondly) breaks native event processing
wxCHECK_RET( inControl != (ControlRef) NULL, wxT("attempt to add a NULL WindowRef to window list") );
wxWinMacControlList[inControl] = control;
}
void wxRemoveMacControlAssociation(wxWindow *control)
{
// iterate over all the elements in the class
// is the iterator stable ? as we might have two associations pointing to the same wxWindow
// we should go on...
bool found = true ;
while ( found )
{
found = false ;
MacControlMap::iterator it;
for ( it = wxWinMacControlList.begin(); it != wxWinMacControlList.end(); ++it )
{
if ( it->second == control )
{
wxWinMacControlList.erase(it);
found = true ;
break;
}
}
}
}
// ----------------------------------------------------------------------------
// constructors and such
// ----------------------------------------------------------------------------
wxWindowMac::wxWindowMac()
{
Init();
}
wxWindowMac::wxWindowMac(wxWindowMac *parent,
wxWindowID id,
const wxPoint& pos ,
const wxSize& size ,
long style ,
const wxString& name )
{
Init();
Create(parent, id, pos, size, style, name);
}
void wxWindowMac::Init()
{
m_peer = NULL ;
m_frozenness = 0 ;
#if WXWIN_COMPATIBILITY_2_4
m_backgroundTransparent = false;
#endif
#if wxMAC_USE_CORE_GRAPHICS
m_cgContextRef = NULL ;
#endif
// as all windows are created with WS_VISIBLE style...
m_isShown = true;
m_hScrollBar = NULL ;
m_vScrollBar = NULL ;
m_macBackgroundBrush = wxNullBrush ;
m_macIsUserPane = true;
m_clipChildren = false ;
m_cachedClippedRectValid = false ;
// we need a valid font for the encodings
wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
wxWindowMac::~wxWindowMac()
{
SendDestroyEvent();
m_isBeingDeleted = true;
MacInvalidateBorders() ;
#ifndef __WXUNIVERSAL__
// VS: make sure there's no wxFrame with last focus set to us:
for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
{
wxFrame *frame = wxDynamicCast(win, wxFrame);
if ( frame )
{
if ( frame->GetLastFocus() == this )
frame->SetLastFocus((wxWindow*)NULL);
break;
}
}
#endif
// destroy children before destroying this window itself
DestroyChildren();
// wxRemoveMacControlAssociation( this ) ;
// If we delete an item, we should initialize the parent panel,
// because it could now be invalid.
wxWindow *parent = GetParent() ;
if ( parent )
{
if (parent->GetDefaultItem() == (wxButton*) this)
parent->SetDefaultItem(NULL);
}
if ( m_peer && m_peer->Ok() )
{
// in case the callback might be called during destruction
wxRemoveMacControlAssociation( this) ;
::RemoveEventHandler( (EventHandlerRef ) m_macControlEventHandler ) ;
// we currently are not using this hook
// ::SetControlColorProc( *m_peer , NULL ) ;
m_peer->Dispose() ;
}
if ( g_MacLastWindow == this )
g_MacLastWindow = NULL ;
wxFrame* frame = wxDynamicCast( wxGetTopLevelParent( this ) , wxFrame ) ;
if ( frame )
{
if ( frame->GetLastFocus() == this )
frame->SetLastFocus( NULL ) ;
}
// delete our drop target if we've got one
#if wxUSE_DRAG_AND_DROP
if ( m_dropTarget != NULL )
{
delete m_dropTarget;
m_dropTarget = NULL;
}
#endif
delete m_peer ;
}
WXWidget wxWindowMac::GetHandle() const
{
return (WXWidget) m_peer->GetControlRef() ;
}
void wxWindowMac::MacInstallEventHandler( WXWidget control )
{
wxAssociateControlWithMacControl( (ControlRef) control , this ) ;
InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(),
GetEventTypeCount(eventList), eventList, this,
(EventHandlerRef *)&m_macControlEventHandler);
#if !TARGET_API_MAC_OSX
if ( (ControlRef) control == m_peer->GetControlRef() )
{
m_peer->SetData<ControlUserPaneDrawUPP>(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ;
m_peer->SetData<ControlUserPaneHitTestUPP>(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ;
m_peer->SetData<ControlUserPaneTrackingUPP>(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ;
m_peer->SetData<ControlUserPaneIdleUPP>(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ;
m_peer->SetData<ControlUserPaneKeyDownUPP>(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ;
m_peer->SetData<ControlUserPaneActivateUPP>(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ;
m_peer->SetData<ControlUserPaneFocusUPP>(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ;
m_peer->SetData<ControlUserPaneBackgroundUPP>(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ;
}
#endif
}
// Constructor
bool wxWindowMac::Create(wxWindowMac *parent,
wxWindowID id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
{
wxCHECK_MSG( parent, false, wxT("can't create wxWindowMac without parent") );
if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
return false;
m_windowVariant = parent->GetWindowVariant() ;
if ( m_macIsUserPane )
{
Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
UInt32 features = 0
| kControlSupportsEmbedding
| kControlSupportsLiveFeedback
| kControlGetsFocusOnClick
// | kControlHasSpecialBackground
// | kControlSupportsCalcBestRect
| kControlHandlesTracking
| kControlSupportsFocus
| kControlWantsActivate
| kControlWantsIdle ;
m_peer = new wxMacControl(this) ;
OSStatus err =::CreateUserPaneControl( MAC_WXHWND(GetParent()->MacGetTopLevelWindowRef()) , &bounds, features , m_peer->GetControlRefAddr() );
verify_noerr( err );
MacPostControlCreate(pos, size) ;
}
#ifndef __WXUNIVERSAL__
// Don't give scrollbars to wxControls unless they ask for them
if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar)))
|| (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL))))
{
MacCreateScrollBars( style ) ;
}
#endif
wxWindowCreateEvent event(this);
GetEventHandler()->AddPendingEvent(event);
return true;
}
void wxWindowMac::MacChildAdded()
{
if ( m_vScrollBar )
m_vScrollBar->Raise() ;
if ( m_hScrollBar )
m_hScrollBar->Raise() ;
}
void wxWindowMac::MacPostControlCreate(const wxPoint& pos, const wxSize& size)
{
wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
m_peer->SetReference( (long)this ) ;
GetParent()->AddChild( this );
MacInstallEventHandler( (WXWidget) m_peer->GetControlRef() );
ControlRef container = (ControlRef) GetParent()->GetHandle() ;
wxASSERT_MSG( container != NULL , wxT("No valid mac container control") ) ;
::EmbedControl( m_peer->GetControlRef() , container ) ;
GetParent()->MacChildAdded() ;
// adjust font, controlsize etc
DoSetWindowVariant( m_windowVariant ) ;
m_peer->SetLabel( wxStripMenuCodes(m_label) ) ;
if (!m_macIsUserPane)
SetInitialBestSize(size);
SetCursor( *wxSTANDARD_CURSOR ) ;
}
void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant )
{
// Don't assert, in case we set the window variant before
// the window is created
// wxASSERT( m_peer->Ok() ) ;
m_windowVariant = variant ;
if (m_peer == NULL || !m_peer->Ok())
return;
ControlSize size ;
ThemeFontID themeFont = kThemeSystemFont ;
// we will get that from the settings later
// and make this NORMAL later, but first
// we have a few calculations that we must fix
switch ( variant )
{
case wxWINDOW_VARIANT_NORMAL :
size = kControlSizeNormal;
themeFont = kThemeSystemFont ;
break ;
case wxWINDOW_VARIANT_SMALL :
size = kControlSizeSmall;
themeFont = kThemeSmallSystemFont ;
break ;
case wxWINDOW_VARIANT_MINI :
if (UMAGetSystemVersion() >= 0x1030 )
{
// not always defined in the headers
size = 3 ;
themeFont = 109 ;
}
else
{
size = kControlSizeSmall;
themeFont = kThemeSmallSystemFont ;
}
break ;
case wxWINDOW_VARIANT_LARGE :
size = kControlSizeLarge;
themeFont = kThemeSystemFont ;
break ;
default:
wxFAIL_MSG(_T("unexpected window variant"));
break ;
}
m_peer->SetData<ControlSize>(kControlEntireControl, kControlSizeTag, &size ) ;
wxFont font ;
font.MacCreateThemeFont( themeFont ) ;
SetFont( font ) ;
}
void wxWindowMac::MacUpdateControlFont()
{
m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ;
Refresh() ;
}
bool wxWindowMac::SetFont(const wxFont& font)
{
bool retval = wxWindowBase::SetFont( font );
MacUpdateControlFont() ;
return retval;
}
bool wxWindowMac::SetForegroundColour(const wxColour& col )
{
bool retval = wxWindowBase::SetForegroundColour( col );
if (retval)
MacUpdateControlFont();
return retval;
}
bool wxWindowMac::SetBackgroundColour(const wxColour& col )
{
if ( !wxWindowBase::SetBackgroundColour(col) && m_hasBgCol )
return false ;
wxBrush brush ;
wxColour newCol(GetBackgroundColour());
if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_APPWORKSPACE ) )
brush.MacSetTheme( kThemeBrushDocumentWindowBackground ) ;
else if ( newCol == wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ) )
brush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -