示例#1
0
// 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());
    }
}
示例#2
0
void wxFrame::AttachMenuBar( wxMenuBar *menuBar )
{
    wxFrame* tlf = wxDynamicCast( wxFindWinFromMacWindow( FrontNonFloatingWindow() ) , wxFrame );
    bool makeCurrent = false;

    // if this is already the current menubar or we are the frontmost window
    if ( (tlf == this) || (m_frameMenuBar == wxMenuBar::MacGetInstalledMenuBar()) )
        makeCurrent = true;
    // or there is an app-level menubar like MDI
    else if ( tlf && (tlf->GetMenuBar() == NULL) && (((wxFrame*)wxTheApp->GetTopWindow()) == this) )
        makeCurrent = true;

    wxFrameBase::AttachMenuBar( menuBar );

    if (m_frameMenuBar)
    {
        m_frameMenuBar->SetInvokingWindow( this );
        if (makeCurrent)
            m_frameMenuBar->MacInstallMenuBar();
    }
}
示例#3
0
文件: dnd.cpp 项目: EdgarTx/wx
pascal OSErr wxMacWindowDragTrackingHandler(
    DragTrackingMessage theMessage, WindowPtr theWindow,
    void *handlerRefCon, DragReference theDrag )
{
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;

    Point mouse, localMouse;
    DragAttributes attributes;

    GetDragAttributes( theDrag, &attributes );

    wxNonOwnedWindow* toplevel = wxFindWinFromMacWindow( theWindow );

    bool optionDown = GetCurrentKeyModifiers() & optionKey;
    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;

    switch (theMessage)
    {
        case kDragTrackingEnterHandler:
        case kDragTrackingLeaveHandler:
            break;

        case kDragTrackingEnterWindow:
            if (trackingGlobals != NULL)
            {
                trackingGlobals->m_currentTargetWindow = NULL;
                trackingGlobals->m_currentTarget = NULL;
            }
            break;

        case kDragTrackingInWindow:
            if (trackingGlobals == NULL)
                break;
            if (toplevel == NULL)
                break;

            GetDragMouse( theDrag, &mouse, 0L );
            localMouse = mouse;
            wxMacGlobalToLocal( theWindow, &localMouse );

            {
                wxWindowMac *win = NULL;
                ControlPartCode controlPart;
                ControlRef control = FindControlUnderMouse( localMouse, theWindow, &controlPart );
                if ( control )
                    win = wxFindControlFromMacControl( control );
                else
                    win = toplevel;

                int localx, localy;
                localx = localMouse.h;
                localy = localMouse.v;

                if ( win )
                    win->MacRootWindowToWindow( &localx, &localy );
                if ( win != trackingGlobals->m_currentTargetWindow )
                {
                    if ( trackingGlobals->m_currentTargetWindow )
                    {
                        // this window is left
                        if ( trackingGlobals->m_currentTarget )
                        {
#ifndef __LP64__
                            HideDragHilite( theDrag );
#endif
                            trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                            trackingGlobals->m_currentTarget->OnLeave();
                            trackingGlobals->m_currentTarget = NULL;
                            trackingGlobals->m_currentTargetWindow = NULL;
                        }
                    }

                    if ( win )
                    {
                        // this window is entered
                        trackingGlobals->m_currentTargetWindow = (wxWindow*)win;
                        trackingGlobals->m_currentTarget = win->GetDropTarget();
                        {
                            if ( trackingGlobals->m_currentTarget )
                            {
                                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                                result = trackingGlobals->m_currentTarget->OnEnter( localx, localy, result );
                            }

                            if ( result != wxDragNone )
                            {
                                int x, y;

                                x = y = 0;
                                win->MacWindowToRootWindow( &x, &y );
                                RgnHandle hiliteRgn = NewRgn();
                                Rect r = { y, x, y + win->GetSize().y, x + win->GetSize().x };
                                RectRgn( hiliteRgn, &r );
#ifndef __LP64__
                                ShowDragHilite( theDrag, hiliteRgn, true );
#endif
                                DisposeRgn( hiliteRgn );
                            }
                        }
                    }
                }
                else
                {
                    if ( trackingGlobals->m_currentTarget )
                    {
                        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                        result = trackingGlobals->m_currentTarget->OnDragOver( localx, localy, result );
                    }
                }

                // set cursor for OnEnter and OnDragOver
                if ( trackingGlobals->m_currentSource && !trackingGlobals->m_currentSource->GiveFeedback( result ) )
                {
                  if ( !trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) )
                  {
                      int cursorID = wxCURSOR_NONE;

                      switch (result)
                      {
                          case wxDragCopy:
                              cursorID = wxCURSOR_COPY_ARROW;
                              break;

                          case wxDragMove:
                              cursorID = wxCURSOR_ARROW;
                              break;

                          case wxDragNone:
                              cursorID = wxCURSOR_NO_ENTRY;
                              break;

                          case wxDragError:
                          case wxDragLink:
                          case wxDragCancel:
                          default:
                              // put these here to make gcc happy
                              ;
                      }

                      if (cursorID != wxCURSOR_NONE)
                      {
                          wxCursor cursor( cursorID );
                          cursor.MacInstall();
                      }
                   }
                }
            }
            break;

        case kDragTrackingLeaveWindow:
            if (trackingGlobals == NULL)
                break;

            if (trackingGlobals->m_currentTarget)
            {
                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag );
                trackingGlobals->m_currentTarget->OnLeave();
#ifndef __LP64__
                HideDragHilite( theDrag );
#endif
                trackingGlobals->m_currentTarget = NULL;
            }
            trackingGlobals->m_currentTargetWindow = NULL;
            break;

        default:
            break;
    }

    return noErr;
}
示例#4
0
文件: app.cpp 项目: gitrider/wxsj2
bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar  )
{
    if ( !focus )
        return false ;

    short keycode ;
    short keychar ;
    keychar = short(keymessage & charCodeMask);
    keycode = short(keymessage & keyCodeMask) >> 8 ;

    if ( modifiers & ( controlKey|shiftKey|optionKey ) )
    {
        // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
        // and look at the character after
        UInt32 state = 0;
        UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
        keychar = short(keyInfo & charCodeMask);
    }
    long keyval = wxMacTranslateKey(keychar, keycode) ;
    long realkeyval = keyval ;
    if ( keyval == keychar )
    {
        // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
        realkeyval = short(keymessage & charCodeMask) ;
        keyval = wxToupper( keyval ) ;
    }

    // Check for NUMPAD keys
    if (keyval >= '0' && keyval <= '9' && keycode >= 82 && keycode <= 92)
    {
        keyval = keyval - '0' + WXK_NUMPAD0;
    }
    else if (keycode >= 67 && keycode <= 81)
    {
        switch (keycode)
        {
        case 76 :
            keyval = WXK_NUMPAD_ENTER;
            break;
        case 81:
            keyval = WXK_NUMPAD_EQUAL;
            break;
        case 67:
            keyval = WXK_NUMPAD_MULTIPLY;
            break;
        case 75:
            keyval = WXK_NUMPAD_DIVIDE;
            break;
        case 78:
            keyval = WXK_NUMPAD_SUBTRACT;
            break;
        case 69:
            keyval = WXK_NUMPAD_ADD;
            break;
        case 65:
            keyval = WXK_NUMPAD_DECIMAL;
            break;
        } // end switch
    }

    wxKeyEvent event(wxEVT_KEY_DOWN);
    bool handled = false ;
    event.m_shiftDown = modifiers & shiftKey;
    event.m_controlDown = modifiers & controlKey;
    event.m_altDown = modifiers & optionKey;
    event.m_metaDown = modifiers & cmdKey;
    event.m_keyCode = keyval ;
#if wxUSE_UNICODE
    event.m_uniChar = uniChar ;
#endif
    event.m_rawCode = keymessage;
    event.m_rawFlags = modifiers;
    event.m_x = wherex;
    event.m_y = wherey;
    event.SetTimestamp(when);
    event.SetEventObject(focus);
    handled = focus->GetEventHandler()->ProcessEvent( event ) ;
    if ( handled && event.GetSkipped() )
        handled = false ;
    if ( !handled )
    {
#if wxUSE_ACCEL
        if (!handled)
        {
            wxWindow *ancestor = focus;
            while (ancestor)
            {
                int command = ancestor->GetAcceleratorTable()->GetCommand( event );
                if (command != -1)
                {
                    wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
                    handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
                    break;
                }
                if (ancestor->IsTopLevel())
                    break;
                ancestor = ancestor->GetParent();
            }
        }
#endif // wxUSE_ACCEL
    }
    if (!handled)
    {
        wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ;

        if (tlw)
        {
            event.Skip( FALSE ) ;
            event.SetEventType( wxEVT_CHAR_HOOK );
            // raw value again
            event.m_keyCode = realkeyval ;

            handled = tlw->GetEventHandler()->ProcessEvent( event );
            if ( handled && event.GetSkipped() )
                handled = false ;
        }
    }
    
    if ( !handled )
    {        
        event.Skip( FALSE ) ;
        event.SetEventType( wxEVT_CHAR ) ;
        // raw value again
        event.m_keyCode = realkeyval ;

        handled = focus->GetEventHandler()->ProcessEvent( event ) ;
        if ( handled && event.GetSkipped() )
            handled = false ;
    }
    if ( !handled && (keyval == WXK_TAB) )
    {
        wxWindow* iter = focus->GetParent() ;
        while( iter && !handled )
        {
            if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
            {
                wxNavigationKeyEvent new_event;
                new_event.SetEventObject( focus );
                new_event.SetDirection( !event.ShiftDown() );
                /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
                new_event.SetWindowChange( event.ControlDown() );
                new_event.SetCurrentFocus( focus );
                handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
                if ( handled && new_event.GetSkipped() )
                    handled = false ;
            }
            iter = iter->GetParent() ;
        }
    }
    // backdoor handler for default return and command escape
    if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
    {
          // if window is not having a focus still testing for default enter or cancel
          // TODO add the UMA version for ActiveNonFloatingWindow
          wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
          if ( focus )
          {
            if ( keyval == WXK_RETURN )
            {
                 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
                                                       wxButton);
                 if ( def && def->IsEnabled() )
                 {
                     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
                     event.SetEventObject(def);
                     def->Command(event);
                     return true ;
                }
            }
            /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
            else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
            {
                  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
                  new_event.SetEventObject( focus );
                  handled = focus->GetEventHandler()->ProcessEvent( new_event );
            }
          }
    }
    return handled ;
}
示例#5
0
文件: dnd.cpp 项目: Duion/Torsion
pascal OSErr wxMacWindowDragTrackingHandler(DragTrackingMessage theMessage, WindowPtr theWindow,
  void *handlerRefCon, DragReference theDrag)
{ 
    MacTrackingGlobals* trackingGlobals = (MacTrackingGlobals*) handlerRefCon;
    Point mouse, localMouse;
    DragAttributes attributes;
    GetDragAttributes(theDrag, &attributes);
    wxTopLevelWindowMac* toplevel = wxFindWinFromMacWindow( (WXWindow) theWindow ) ; 

    KeyMap keymap;
    GetKeys(keymap);
    bool optionDown = keymap[1] & 4;
    wxDragResult result = optionDown ? wxDragCopy : wxDragMove;

    switch(theMessage) 
    {
        case kDragTrackingEnterHandler:
            break;
        case kDragTrackingLeaveHandler:
            break;
        case kDragTrackingEnterWindow:
            trackingGlobals->m_currentTargetWindow = NULL ;
            trackingGlobals->m_currentTarget = NULL ;
            break;
        case kDragTrackingInWindow:
            if (toplevel == NULL)
                break;

            GetDragMouse(theDrag, &mouse, 0L);
            localMouse = mouse;
            GlobalToLocal(&localMouse);


            
//            if (attributes & kDragHasLeftSenderWindow) 
            {
                wxPoint point(localMouse.h , localMouse.v) ;
                wxWindow *win = NULL ;
                toplevel->MacGetWindowFromPointSub( point , &win ) ;
                int localx , localy ;
                localx = localMouse.h ;
                localy = localMouse.v ;
                //TODO : should we use client coordinates
                if ( win )
                    win->MacRootWindowToWindow( &localx , &localy ) ;
                if ( win != trackingGlobals->m_currentTargetWindow )
                {
                    if ( trackingGlobals->m_currentTargetWindow )
                    {
                        // this window is left
                        if ( trackingGlobals->m_currentTarget )
                        {
                            HideDragHilite(theDrag);
                            trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            trackingGlobals->m_currentTarget->OnLeave() ;
                            trackingGlobals->m_currentTarget = NULL;
                            trackingGlobals->m_currentTargetWindow = NULL ;
                        }
                    }
                    if ( win )
                    {
                        // this window is entered
                        trackingGlobals->m_currentTargetWindow = win ;
                        trackingGlobals->m_currentTarget = win->GetDropTarget() ;
                        {

                        	if ( trackingGlobals->m_currentTarget )
                        	{
                            	trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                            	result = trackingGlobals->m_currentTarget->OnEnter(
                                	localx , localy , result ) ;
                            }
                                
                           
                            if ( result != wxDragNone )
                            {
                                int x , y ;
                                x = y = 0 ;
                                win->MacWindowToRootWindow( &x , &y ) ;
                                RgnHandle hiliteRgn = NewRgn() ;
                                SetRectRgn( hiliteRgn , x , y , x+win->GetSize().x ,y+win->GetSize().y) ;
                                ShowDragHilite(theDrag, hiliteRgn, true);
                                DisposeRgn( hiliteRgn ) ;
                            }
                        }
                    }
                }
                else
                {
                    if( trackingGlobals->m_currentTarget )
                    {
                        trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                        trackingGlobals->m_currentTarget->OnDragOver(
                            localx , localy , result ) ;
                    }
                }

                // set cursor for OnEnter and OnDragOver
                if ( trackingGlobals->m_currentSource && trackingGlobals->m_currentSource->GiveFeedback( result ) == FALSE )
                {
                  if ( trackingGlobals->m_currentSource->MacInstallDefaultCursor( result ) == FALSE )
                  {
                      switch( result )
                      {
                          case wxDragCopy :
                              {
                                  wxCursor cursor(wxCURSOR_COPY_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragMove :
                              {
                                  wxCursor cursor(wxCURSOR_ARROW) ;
                                  cursor.MacInstall() ;
                              }
                              break ;
                          case wxDragNone :
                              {
                                  wxCursor cursor(wxCURSOR_NO_ENTRY) ;
                                  cursor.MacInstall() ;
                              }
                              break ;

                          case wxDragError:
                          case wxDragLink:
                          case wxDragCancel:
                              // put these here to make gcc happy
                              ;
                      }
                  }
                }
                
          }
            // MyTrackItemUnderMouse(localMouse, theWindow);
            break;
        case kDragTrackingLeaveWindow:
            if (trackingGlobals->m_currentTarget) 
            {
                trackingGlobals->m_currentTarget->SetCurrentDrag( theDrag ) ;
                trackingGlobals->m_currentTarget->OnLeave() ;
                HideDragHilite(theDrag);
                trackingGlobals->m_currentTarget = NULL ;
            }
            trackingGlobals->m_currentTargetWindow = NULL ;
            break;
    }
    return(noErr);
}
示例#6
0
文件: app.cpp 项目: hgwells/tive
bool wxApp::MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar )
{
    if ( !focus )
        return false ;

    wxKeyEvent event(wxEVT_CHAR) ;
    MacCreateKeyEvent( event, focus , keymessage , modifiers , when , wherex , wherey , uniChar ) ;
    long keyval = event.m_keyCode ;

    bool handled = false ;

    wxTopLevelWindowMac *tlw = focus->MacGetTopLevelWindow() ;

    if (tlw)
    {
        event.SetEventType( wxEVT_CHAR_HOOK );
        handled = tlw->GetEventHandler()->ProcessEvent( event );
        if ( handled && event.GetSkipped() )
            handled = false ;
    }

    if ( !handled )
    {
        event.SetEventType( wxEVT_CHAR );
        event.Skip( false ) ;
        handled = focus->GetEventHandler()->ProcessEvent( event ) ;
    }

    if ( !handled && (keyval == WXK_TAB) )
    {
        wxWindow* iter = focus->GetParent() ;
        while ( iter && !handled )
        {
            if ( iter->HasFlag( wxTAB_TRAVERSAL ) )
            {
                wxNavigationKeyEvent new_event;
                new_event.SetEventObject( focus );
                new_event.SetDirection( !event.ShiftDown() );
                /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
                new_event.SetWindowChange( event.ControlDown() );
                new_event.SetCurrentFocus( focus );
                handled = focus->GetParent()->GetEventHandler()->ProcessEvent( new_event );
                if ( handled && new_event.GetSkipped() )
                    handled = false ;
            }

            iter = iter->GetParent() ;
        }
    }

    // backdoor handler for default return and command escape
    if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
    {
        // if window is not having a focus still testing for default enter or cancel
        // TODO: add the UMA version for ActiveNonFloatingWindow
        wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
        if ( focus )
        {
            if ( keyval == WXK_RETURN || keyval == WXK_NUMPAD_ENTER )
            {
                wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(focus), wxTopLevelWindow);
                if ( tlw && tlw->GetDefaultItem() )
                {
                    wxButton *def = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
                    if ( def && def->IsEnabled() )
                    {
                        wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
                        event.SetEventObject(def);
                        def->Command(event);

                        return true ;
                    }
                }
            }
            else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
            {
                // generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs)
                wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
                new_event.SetEventObject( focus );
                handled = focus->GetEventHandler()->ProcessEvent( new_event );
            }
        }
    }
    return handled ;
}