OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container, Boolean recurse, DataBrowserItemState state, ItemCount *numItems) const { return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems ); }
OSStatus MySimpleNotificationCallback(ControlRef browser, DataBrowserItemID item, DataBrowserItemNotification message) { UInt32 numItems; Rect browserBounds; SInt16 height; OSStatus err = noErr; switch (message) { case kDataBrowserItemAdded: if (item <= kMaxNeighborhoods) { gNeighborhoodInfo.isNeighborhoodVisible[item - 1] = true; } break; case kDataBrowserItemRemoved: if (item <= kMaxNeighborhoods) { gNeighborhoodInfo.isNeighborhoodVisible[item - 1] = false; } break; case kDataBrowserContainerOpened: gNeighborhoodInfo.isNeighborhoodOpen[item - 1] = true; DoNeighborhoodLookup(item); DoServicesLookup(item); break; case kDataBrowserContainerClosing: gNeighborhoodInfo.isNeighborhoodOpen[item - 1] = false; CancelServicesLookup(item); CancelNeighborhoodLookup(item); break; case kDataBrowserContainerClosed: RemoveServicesFromNeighborhood(item, false); if (gNeighborhoodInfo.isDefaultNeighborhood[item - 1] == true) { SetDataBrowserScrollPosition(gDataBrowserControl, 0 , 0); } else { err = GetDataBrowserItemCount(gDataBrowserControl, 0, true, kDataBrowserItemAnyState, &numItems); if (err == noErr) { GetControlBounds(gDataBrowserControl, &browserBounds); height = browserBounds.bottom - browserBounds.top; if (numItems < (height/kDataBrowserRowHeight)) SetDataBrowserScrollPosition(gDataBrowserControl, 0 , 0); } } break; case kDataBrowserItemSelected: gSelectedItem = item; break; case kDataBrowserItemDeselected: if (gSelectedItem == item) gSelectedItem = kDataBrowserNoItem; break; } return noErr; }
static pascal void DBItemNotificationCallBack (HIViewRef browser, DataBrowserItemID itemID, DataBrowserItemNotification message) { OSStatus err; HIViewRef ctl; HIViewID cid = { kDelButton, 0 }; ItemCount selectionCount; switch (message) { case kDataBrowserSelectionSetChanged: HIViewFindByID(HIViewGetRoot(wRef), cid, &ctl); err = GetDataBrowserItemCount(browser, kDataBrowserNoItem, true, kDataBrowserItemIsSelected, &selectionCount); if (selectionCount == 0) err = DeactivateControl(ctl); else err = ActivateControl(ctl); } }
void UpdateItemCount() { ControlID controlID = { kNSLSample, kServicesCountText }; ControlRef control; Str255 countStr; char count[16]; UInt32 itemCount; static UInt32 previousItemCount = 0; OSStatus err = noErr; err = GetControlByID(gMainWindow, &controlID, &control); if (err == noErr) { err = GetDataBrowserItemCount(gDataBrowserControl, 0, true, kDataBrowserItemAnyState, &itemCount); // Only update if the count has actually changed since last time. if (err == noErr && previousItemCount != itemCount) { previousItemCount = itemCount; NumToString (itemCount, countStr); CopyPascalStringToC(countStr, count); if (itemCount == 1) { strcat(count, " Item"); SetControlData(control, kControlNoPart, kControlEditTextTextTag, strlen(count), count); ShowControl(control); } else { strcat(count, " Items"); SetControlData(control, kControlNoPart, kControlEditTextTextTag, strlen(count), count); ShowControl(control); } DrawOneControl(control); DrawOneControl(gDataBrowserControl); } } }
int main(int argc, char* argv[]) { IBNibRef nibRef; OSStatus err; glob_t g; // check the correct BASS was loaded if (HIWORD(BASS_GetVersion())!=BASSVERSION) { Error("An incorrect version of BASS was loaded"); return 0; } // initialize default output device if (!BASS_Init(-1,44100,0,NULL,NULL)) { Error("Can't initialize device"); return 0; } // Create Window and stuff err = CreateNibReference(CFSTR("plugins"), &nibRef); if (err) return err; err = CreateWindowFromNib(nibRef, CFSTR("Window"), &win); if (err) return err; DisposeNibReference(nibRef); DataBrowserCallbacks dbc; dbc.version=kDataBrowserLatestCallbacks; InitDataBrowserCallbacks(&dbc); dbc.u.v1.itemDataCallback=MyDataBrowserItemDataCallback; ControlRef list=GetControl(20); SetDataBrowserCallbacks(list,&dbc); { // look for plugins (in the executable directory) char path[300]; DWORD l=sizeof(path); _NSGetExecutablePath(path,&l); strcpy(strrchr(path,'/')+1,"libbass*.dylib"); if (!glob(path,0,0,&g)) { int a; for (a=0;a<g.gl_pathc;a++) { if (BASS_PluginLoad(g.gl_pathv[a],0)) { // plugin loaded, add it to the list... char *p=strrchr(g.gl_pathv[a],'/')+1; AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&p,kDataBrowserItemNoProperty); } } } DWORD c; GetDataBrowserItemCount(list,kDataBrowserNoItem,FALSE,kDataBrowserItemNoState,(DataBrowserItemState*)&c); if (!c) { // no plugins... static const char *noplugins="no plugins - visit the BASS webpage to get some"; AddDataBrowserItems(list,kDataBrowserNoItem,1,(DataBrowserItemID*)&noplugins,kDataBrowserItemNoProperty); } } SetupControlHandler(10,kEventControlHit,OpenEventHandler); SetControlAction(GetControl(12),NewControlActionUPP(PosEventHandler)); EventLoopTimerRef timer; InstallEventLoopTimer(GetCurrentEventLoop(),kEventDurationNoWait,kEventDurationSecond/2,NewEventLoopTimerUPP(TimerProc),0,&timer); ShowWindow(win); RunApplicationEventLoop(); globfree(&g); // "free" the output device and all plugins BASS_Free(); BASS_PluginFree(0); return 0; }