// --------------------------------------------------------------------------------------
ControlRef CreateIconDataBrowser(WindowRef window, const Rect *dbRect, ControlRef *userPanes)
{
    ControlRef dataBrowserControl;
    DataBrowserListViewColumnDesc columnDesc;
    DataBrowserItemID firstItem;

    CreateDataBrowserControl(window, dbRect, kDataBrowserListView, &dataBrowserControl);

    SetDataBrowserHasScrollBars(dataBrowserControl, false, true);
    SetDataBrowserSelectionFlags(dataBrowserControl, kDataBrowserDragSelect |
                                 kDataBrowserSelectOnlyOne);
    SetDataBrowserListViewHeaderBtnHeight(dataBrowserControl, 0);	// no header button
    SetDataBrowserTableViewHiliteStyle(dataBrowserControl, kDataBrowserTableViewFillHilite);
    // because kDataBrowserTableViewMinimalHilite would require us to provide a hit test
    // callback which we would just return true from anyways

    columnDesc.propertyDesc.propertyID = kCategoryProperty;
    columnDesc.propertyDesc.propertyType = kDataBrowserCustomType;	// because
    // kDataBrowserIconAndTextType doesn't draw the way we want
    columnDesc.propertyDesc.propertyFlags = kDataBrowserDefaultPropertyFlags |
                                            kDataBrowserListViewSelectionColumn;
    columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
    columnDesc.headerBtnDesc.minimumWidth = kColumnWidth;
    columnDesc.headerBtnDesc.maximumWidth = kColumnWidth;
    columnDesc.headerBtnDesc.titleOffset = 0;
    columnDesc.headerBtnDesc.titleString = NULL;
    columnDesc.headerBtnDesc.initialOrder = kDataBrowserOrderIncreasing;
    columnDesc.headerBtnDesc.btnFontStyle.flags = 0;
    columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
    AddDataBrowserListViewColumn(dataBrowserControl, &columnDesc,
                                 kDataBrowserListViewAppendColumn);

    /* We need to wait to set the row height until here because
       AddDataBrowserListViewColumn will resize the row height. */
#if TARGET_API_MAC_OSX
    SetDataBrowserTableViewRowHeight(dataBrowserControl, kRowHeight);
#else		// Mac OS 8/9 under CarbonLib adds 1 to the row height you provide
    SetDataBrowserTableViewRowHeight(dataBrowserControl, kRowHeight - 1);
#endif

    SetDataBrowserListViewUsePlainBackground(dataBrowserControl, true);

    if (gCallbackRefCount == 0)
    {
        gIconDBCallbacks.u.v1.itemNotificationCallback = NewDataBrowserItemNotificationUPP(IconDataBrowserItemSelectionCB);
        gIconDBCustomCallbacks.u.v1.drawItemCallback = NewDataBrowserDrawItemUPP(DrawIconDataBrowserItemCB);
    }
    SetDataBrowserCallbacks(dataBrowserControl, &gIconDBCallbacks);
    SetDataBrowserCustomCallbacks(dataBrowserControl, &gIconDBCustomCallbacks);
    gCallbackRefCount++;

    firstItem = addItemsToIconDB(dataBrowserControl, userPanes);
    SetDataBrowserSelectedItems(dataBrowserControl, 1, &firstItem, kDataBrowserItemsAssign);
    SetKeyboardFocus(window, dataBrowserControl, kControlFocusNextPart);

    return dataBrowserControl;
}
Esempio n. 2
0
bool wxListBox::Create(wxWindow *parent, wxWindowID id,
                       const wxPoint& pos,
                       const wxSize& size,
                       int n, const wxString choices[],
                       long style,
                       const wxValidator& validator,
                       const wxString& name)
{
    m_macIsUserPane = FALSE ;

    wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
                  _T("only one of listbox selection modes can be specified") );

    if ( !wxListBoxBase::Create(parent, id, pos, size, style & ~(wxHSCROLL|wxVSCROLL), validator, name) )
        return false;

    m_noItems = 0 ; // this will be increased by our append command
    m_selected = 0;

    Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;

    m_peer = new wxMacControl(this) ;
    verify_noerr( ::CreateDataBrowserControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, kDataBrowserListView , m_peer->GetControlRefAddr() ) );

    DataBrowserSelectionFlags  options = kDataBrowserDragSelect ;
    if ( style & wxLB_MULTIPLE )
    {
        options += kDataBrowserAlwaysExtendSelection + kDataBrowserCmdTogglesSelection  ;
    }
    else if ( style & wxLB_EXTENDED )
    {
        // default behaviour
    }
    else
    {
        options += kDataBrowserSelectOnlyOne ;
    }
    verify_noerr(m_peer->SetSelectionFlags( options ) );
    
    if ( gDataBrowserItemDataUPP == NULL ) gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(ListBoxGetSetItemData) ;
    if ( gDataBrowserItemNotificationUPP == NULL )
    { 
        gDataBrowserItemNotificationUPP = 
#if TARGET_API_MAC_OSX
	        (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc) ;
#else
	        NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc) ;
#endif
    }    
    if ( gDataBrowserDrawItemUPP == NULL ) gDataBrowserDrawItemUPP = NewDataBrowserDrawItemUPP(ListBoxDrawProc) ;

    DataBrowserCallbacks callbacks ;
    InitializeDataBrowserCallbacks( &callbacks , kDataBrowserLatestCallbacks ) ;

    callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
	callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
    m_peer->SetCallbacks( &callbacks);

    DataBrowserCustomCallbacks customCallbacks ;
    InitializeDataBrowserCustomCallbacks( &customCallbacks , kDataBrowserLatestCustomCallbacks ) ; 
   
    customCallbacks.u.v1.drawItemCallback = gDataBrowserDrawItemUPP ;
   
    SetDataBrowserCustomCallbacks( m_peer->GetControlRef() , &customCallbacks ) ;    
    
    DataBrowserListViewColumnDesc columnDesc ;
    columnDesc.headerBtnDesc.titleOffset = 0;
	columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;

	columnDesc.headerBtnDesc.btnFontStyle.flags	=
		kControlUseFontMask | kControlUseJustMask;

	columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlNoContent;
	columnDesc.headerBtnDesc.btnFontStyle.just = teFlushDefault;
	columnDesc.headerBtnDesc.minimumWidth = 0;
	columnDesc.headerBtnDesc.maximumWidth = 10000;

	columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
	columnDesc.headerBtnDesc.btnFontStyle.style = normal;
	columnDesc.headerBtnDesc.titleString = NULL ; // CFSTR( "" );

	columnDesc.propertyDesc.propertyID = kTextColumnId;
	columnDesc.propertyDesc.propertyType = kDataBrowserTextType ; // kDataBrowserCustomType;
	columnDesc.propertyDesc.propertyFlags =
#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
	 kDataBrowserListViewTypeSelectColumn |
#endif
	 kDataBrowserTableViewSelectionColumn ;

	verify_noerr(m_peer->AddListViewColumn( &columnDesc, kDataBrowserListViewAppendColumn) ) ;
    verify_noerr(m_peer->AutoSizeListViewColumns() ) ;
    verify_noerr(m_peer->SetHasScrollBars(false , true ) ) ;
    verify_noerr(m_peer->SetTableViewHiliteStyle(kDataBrowserTableViewFillHilite  ) ) ;
    verify_noerr(m_peer->SetListViewHeaderBtnHeight( 0 ) ) ;

#if 0
    // shouldn't be necessary anymore under 10.2
    m_peer->SetData( kControlNoPart, kControlDataBrowserIncludesFrameAndFocusTag, (Boolean) false ) ;
    m_peer->SetNeedsFocusRect( true ) ;
#endif

    MacPostControlCreate(pos,size) ;

    for ( int i = 0 ; i < n ; i++ )
    {
        Append( choices[i] ) ;
    }

    SetBestSize(size);   // Needed because it is a wxControlWithItems

    return TRUE;
}