• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to use List View in Carbon?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to use List View in Carbon?


  • Subject: How to use List View in Carbon?
  • From: zheng cheng <email@hidden>
  • Date: Sun, 6 May 2007 17:00:31 +0800 (CST)

I find some information in the document,
but the application can't work well all the same, it cashes when i want to fill data in the list view,
Please see my code ,
can anybody tell me why or give me a sample code?


Code:

#include <Carbon/Carbon.h>

static OSStatus        AppEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon );
static OSStatus        HandleNew();
static OSStatus        WindowEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon );
static OSStatus        MyInitializeDataBrowserControl (WindowRef window);

static IBNibRef        sNibRef;

typedef struct myItemData
{
    char location[8];
    char MAC_addr[18];
    char rate[12];
} MyItemData;

MyItemData myTunesDatabase[32];
 
enum {
        kMyLocationColumn = '1111',    // property ID of Column
        kMyMACAddressColumn = '2222',
        kMyRatingColumn = '3333',
};

//--------------------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
    OSStatus                    err;
    static const EventTypeSpec    kAppEvents[] =
    {
        { kEventClassCommand, kEventCommandProcess }
    };

    // Create a Nib reference, passing the name of the nib file (without the .nib extension).
    // CreateNibReference only searches into the application bundle.
    err = CreateNibReference( CFSTR("main"), &sNibRef );
    require_noerr( err, CantGetNibRef );
   
    // Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
    // object. This name is set in InterfaceBuilder when the nib is created.
    err = SetMenuBarFromNib( sNibRef, CFSTR("MenuBar") );
    require_noerr( err, CantSetMenuBar );
   
    // Install our handler for common commands on the application target
    InstallApplicationEventHandler( NewEventHandlerUPP( AppEventHandler ),
                                    GetEventTypeCount( kAppEvents ), kAppEvents,
                                    0, NULL );
   
    // Create a new window. A full-fledged application would do this from an AppleEvent handler
    // for kAEOpenApplication.
    HandleNew();
   
    // Run the event loop
    RunApplicationEventLoop();

CantSetMenuBar:
CantGetNibRef:
    return err;
}

//--------------------------------------------------------------------------------------------
static OSStatus
AppEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon )
{
    OSStatus    result = eventNotHandledErr;
   
    switch ( GetEventClass( inEvent ) )
    {
        case kEventClassCommand:
        {
            HICommandExtended cmd;
            verify_noerr( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) );
           
            switch ( GetEventKind( inEvent ) )
            {
                case kEventCommandProcess:
                    switch ( cmd.commandID )
                    {
                        case kHICommandNew:
                            result = HandleNew();
                            break;
                           
                        // Add your own command-handling cases here
                       
                        default:
                            break;
                    }
                    break;
            }
            break;
        }
           
        default:
            break;
    }
   
    return result;
}

//--------------------------------------------------------------------------------------------
DEFINE_ONE_SHOT_HANDLER_GETTER( WindowEventHandler )

//--------------------------------------------------------------------------------------------
static OSStatus
HandleNew()
{
    OSStatus                    err;
    WindowRef                    window;
    static const EventTypeSpec    kWindowEvents[] =
    {
        { kEventClassCommand, kEventCommandProcess }
    };
   
    // Create a window. "MainWindow" is the name of the window object. This name is set in
    // InterfaceBuilder when the nib is created.
    err = CreateWindowFromNib( sNibRef, CFSTR("MainWindow"), &window );
    require_noerr( err, CantCreateWindow );

    // Install a command handler on the window. We don't use this handler yet, but nearly all
    // Carbon apps will need to handle commands, so this saves everyone a little typing.
    InstallWindowEventHandler( window, GetWindowEventHandlerUPP(),
                               GetEventTypeCount( kWindowEvents ), kWindowEvents,
                               window, NULL );
   
    // Position new windows in a staggered arrangement on the main screen
    RepositionWindow( window, NULL, kWindowCascadeOnMainScreen );
   
    // The window was created hidden, so show it
    ShowWindow( window );
   
    MyInitializeDataBrowserControl(window);
   
CantCreateWindow:
    return err;
}

//--------------------------------------------------------------------------------------------
static OSStatus
WindowEventHandler( EventHandlerCallRef inCaller, EventRef inEvent, void* inRefcon )
{
    OSStatus    err = eventNotHandledErr;
   
    switch ( GetEventClass( inEvent ) )
    {
        case kEventClassCommand:
        {
            HICommandExtended cmd;
            verify_noerr( GetEventParameter( inEvent, kEventParamDirectObject, typeHICommand, NULL, sizeof( cmd ), NULL, &cmd ) );
           
            switch ( GetEventKind( inEvent ) )
            {
                case kEventCommandProcess:
                    switch ( cmd.commandID )
                    {
                        // Add your own command-handling cases here
                       
                        default:
                            break;
                    }
                    break;
            }
            break;
        }
           
        default:
            break;
    }
   
    return err;
}

OSStatus    MyDataBrowserItemDataCallback (ControlRef browser,
                DataBrowserItemID itemID,
                DataBrowserPropertyID property,
                DataBrowserItemDataRef itemData,
                Boolean changeValue)
{
    OSStatus status = noErr;
 
    if (!changeValue) switch (property) // 1
    {
        case kMyLocationColumn:
            status = SetDataBrowserItemDataText (itemData,
                     myTunesDatabase[itemID].location); // 2
            break;
        case kMyMACAddressColumn:
            status = SetDataBrowserItemDataText(itemData,
                    myTunesDatabase[itemID].MAC_addr);
            break;
        case kMyRatingColumn:
            status = SetDataBrowserItemDataText(itemData,
                    myTunesDatabase[itemID].rate);
            break;
        default:
            status = errDataBrowserPropertyNotSupported;
            break;
    }
    else status = errDataBrowserPropertyNotSupported; // 3
 
 return status;
}

static int MyLoadData(void)
{
    int i;
    for(i=0;i<32;i++)
    {
        strcpy(myTunesDatabase[i].location,"aa");
        strcpy(myTunesDatabase[i].MAC_addr,"bb");
        strcpy(myTunesDatabase[i].rate,"cc");
    }
   
    return (int)32;
}

OSStatus MyInitializeDataBrowserControl (WindowRef window)
{
    const       ControlID  dbControlID  = { 'SLST', 1 };// 1
    OSStatus    status = noErr;
//    UInt32      i;
    SInt32      numRows;
    ControlRef  dbControl;
    DataBrowserCallbacks  dbCallbacks;
 
    GetControlByID (window, &dbControlID, &dbControl);  // 2
    dbCallbacks.version = kDataBrowserLatestCallbacks;// 3
    InitDataBrowserCallbacks (&dbCallbacks);// 4
    dbCallbacks.u.v1.itemDataCallback =
            NewDataBrowserItemDataUPP((DataBrowserItemDataProcPtr)
                         MyDataBrowserItemDataCallback);// 5
    SetDataBrowserCallbacks(dbControl, &dbCallbacks);// 6
    SetAutomaticControlDragTrackingEnabledForWindow (window, true);// 7
 
    numRows = MyLoadData ();// 8
    status = AddDataBrowserItems (dbControl, kDataBrowserNoItem, numRows,
                            NULL, kDataBrowserItemNoProperty );// 9
    return status;
}




抢注雅虎免费邮箱-3.5G容量,20M附件!
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: How to use List View in Carbon?
      • From: Quinn <email@hidden>
  • Prev by Date: Re: Developing applications for Airport
  • Next by Date: Re: How to use List View in Carbon?
  • Previous by thread: Re: Developing applications for Airport
  • Next by thread: Re: How to use List View in Carbon?
  • Index(es):
    • Date
    • Thread