Exemplo n.º 1
0
    void SetBitmap(const wxBitmap& bitmap)
    {
        wxBitmap bmp;
        if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) )
        {
            bmp = wxMakeStdSizeBitmap(bitmap);
            // TODO set bitmap in peer as well
        }
        else
            bmp = bitmap;

        ControlButtonContentInfo info;

        if ( GetWXPeer()->HasFlag( wxBORDER_NONE ) )
        {        
            wxMacCreateBitmapButton( &info, bmp, kControlContentIconRef );
            if ( info.contentType != kControlNoContent )
                SetData( kControlIconPart, kControlIconContentTag, info );
        }
        else
        {
            wxMacCreateBitmapButton( &info, bmp );
            if ( info.contentType != kControlNoContent )
                SetData( kControlButtonPart, kControlBevelButtonContentTag, info );
        }

        wxMacReleaseBitmapButton( &info );
    }
Exemplo n.º 2
0
    void Enable( bool enable )
    {
        MenuItemIndex i = FindMenuItemIndex() ;
        if ( i > 0 )
        {

            if ( GetWXPeer()->GetId() == wxApp::s_macPreferencesMenuItemId)
            {
                if ( enable )
                    EnableMenuCommand( NULL , kHICommandPreferences ) ;
                else
                    DisableMenuCommand( NULL , kHICommandPreferences ) ;
            }
            else if ( GetWXPeer()->GetId() == wxApp::s_macExitMenuItemId)
            {
                if ( enable )
                    EnableMenuCommand( NULL , kHICommandQuit ) ;
                else
                    DisableMenuCommand( NULL , kHICommandQuit ) ;
            }

            if ( enable )
                EnableMenuItem(m_parentMenuRef , i);
            else
                DisableMenuItem(m_parentMenuRef , i);

            if ( GetWXPeer()->IsSubMenu() )
            {
                UMAEnableMenuItem( GetWXPeer()->GetSubMenu()->GetHMenu() , 0 , enable ) ;
            }
        }
    }
Exemplo n.º 3
0
void wxMacDataBrowserListControl::ItemNotification(
                        DataBrowserItemID itemID,
                        DataBrowserItemNotification message,
                        DataBrowserItemDataRef itemData)
{
    wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox );
    wxCHECK_RET( list != NULL , wxT("Listbox expected"));

    if (list->HasMultipleSelection() && (message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
    {
        list->CalcAndSendEvent();
        return;
    }

    if ((message == kDataBrowserSelectionSetChanged) && (!list->MacGetBlockEvents()))
    {
        wxCommandEvent event( wxEVT_LISTBOX, list->GetId() );

        int sel = list->GetSelection();
        if ((sel < 0) || (sel > (int) list->GetCount()))  // OS X can select an item below the last item (why?)
           return;
        list->HandleLineEvent( sel, false );
        return;
    }

    // call super for item level(wxMacDataItem->Notification) callback processing
    wxMacDataItemBrowserControl::ItemNotification( itemID, message, itemData);
}
Exemplo n.º 4
0
wxMenuCarbonImpl::~wxMenuCarbonImpl()
{
    wxRemoveMacMenuAssociation( GetWXPeer() );
    // restore previous menu
    m_osxMenu.reset();
    if ( m_menuId > 0 )
        MacDeleteMenu(m_menuId);
    if ( m_oldMenuRef )
        MacInsertMenu(m_oldMenuRef, -1);
}
Exemplo n.º 5
0
int wxMacDataBrowserListControl::DoListHitTest(const wxPoint& inpoint) const
{
    OSStatus err;

    // There are few reasons why this is complicated:
    // 1) There is no native HitTest function for Mac
    // 2) GetDataBrowserItemPartBounds only works on visible items
    // 3) We can't do it through GetDataBrowserTableView[Item]RowHeight
    //    because what it returns is basically inaccurate in the context
    //    of the coordinates we want here, but we use this as a guess
    //    for where the first visible item lies

    wxPoint point = inpoint;

    // get column property ID (req. for call to itempartbounds)
    DataBrowserTableViewColumnID colId = 0;
    err = GetDataBrowserTableViewColumnProperty(GetControlRef(), 0, &colId);
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewColumnProperty"));

    // OK, first we need to find the first visible item we have -
    // this will be the "low" for our binary search. There is no real
    // easy way around this, as we will need to do a SLOW linear search
    // until we find a visible item, but we can do a cheap calculation
    // via the row height to speed things up a bit
    UInt32 scrollx, scrolly;
    err = GetDataBrowserScrollPosition(GetControlRef(), &scrollx, &scrolly);
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserScrollPosition"));

    UInt16 height;
    err = GetDataBrowserTableViewRowHeight(GetControlRef(), &height);
    wxCHECK_MSG(err == noErr, wxNOT_FOUND, wxT("Unexpected error from GetDataBrowserTableViewRowHeight"));

    wxListBox *list = wxDynamicCast( GetWXPeer() , wxListBox );

    // these indices are 0-based, as usual, so we need to add 1 to them when
    // passing them to data browser functions which use 1-based indices
    int low = scrolly / height,
        high = list->GetCount() - 1;

    // search for the first visible item (note that the scroll guess above
    // is the low bounds of where the item might lie so we only use that as a
    // starting point - we should reach it within 1 or 2 iterations of the loop)
    while ( low <= high )
    {
        Rect bounds;
        err = GetDataBrowserItemPartBounds(
            GetControlRef(), low + 1, colId,
            kDataBrowserPropertyEnclosingPart,
            &bounds); // note +1 to translate to Mac ID
        if ( err == noErr )
            break;

        // errDataBrowserItemNotFound is expected as it simply means that the
        // item is not currently visible -- but other errors are not
        wxCHECK_MSG( err == errDataBrowserItemNotFound, wxNOT_FOUND,
                     wxT("Unexpected error from GetDataBrowserItemPartBounds") );

        low++;
    }

    // NOW do a binary search for where the item lies, searching low again if
    // we hit an item that isn't visible
    while ( low <= high )
    {
        int mid = (low + high) / 2;

        Rect bounds;
        err = GetDataBrowserItemPartBounds(
            GetControlRef(), mid + 1, colId,
            kDataBrowserPropertyEnclosingPart,
            &bounds); //note +1 to trans to mac id
        wxCHECK_MSG( err == noErr || err == errDataBrowserItemNotFound,
                     wxNOT_FOUND,
                     wxT("Unexpected error from GetDataBrowserItemPartBounds") );

        if ( err == errDataBrowserItemNotFound )
        {
            // item not visible, attempt to find a visible one
            // search lower
            high = mid - 1;
        }
        else // visible item, do actual hitttest
        {
            // if point is within the bounds, return this item (since we assume
            // all x coords of items are equal we only test the x coord in
            // equality)
            if ((point.x >= bounds.left && point.x <= bounds.right) &&
                (point.y >= bounds.top && point.y <= bounds.bottom) )
            {
                // found!
                return mid;
            }

            if ( point.y < bounds.top )
                // index(bounds) greater than key(point)
                high = mid - 1;
            else
                // index(bounds) less than key(point)
                low = mid + 1;
        }
    }

    return wxNOT_FOUND;
}
Exemplo n.º 6
0
wxMenuCarbonImpl::~wxMenuCarbonImpl()
{
    wxRemoveMacMenuAssociation( GetWXPeer() );
}