BList* ColumnListView::SortItemsInThisLevel(int32 OriginalListStartIndex) { uint32 ThisLevel = ((CLVListItem*)fFullItemList.ItemAt(OriginalListStartIndex))->fOutlineLevel; //Create a new BList of the items in this level int32 Counter = OriginalListStartIndex; int32 ItemsInThisLevel = 0; BList* ThisLevelItems = new BList(16); while(true) { CLVListItem* ThisItem = (CLVListItem*)fFullItemList.ItemAt(Counter); if(ThisItem == NULL) break; uint32 ThisItemLevel = ThisItem->fOutlineLevel; if(ThisItemLevel == ThisLevel) { ThisLevelItems->AddItem(ThisItem); ItemsInThisLevel++; } else if(ThisItemLevel < ThisLevel) break; Counter++; } //Sort the BList of the items in this level CLVListItem** SortArray = new CLVListItem*[ItemsInThisLevel]; CLVListItem** ListItems = (CLVListItem**)ThisLevelItems->Items(); for(Counter = 0; Counter < ItemsInThisLevel; Counter++) SortArray[Counter] = ListItems[Counter]; ThisLevelItems->MakeEmpty(); SortListArray(SortArray,ItemsInThisLevel); for(Counter = 0; Counter < ItemsInThisLevel; Counter++) ThisLevelItems->AddItem(SortArray[Counter]); return ThisLevelItems; }
int32_t PListViewAddItems(void *pobject, void *in, void *out, void *extraData) { if (!pobject || !in || !out) return B_ERROR; PView *parent = static_cast<PView*>(pobject); if (!parent) return B_BAD_TYPE; BListView *backend = (BListView*)parent->GetView(); PArgs *args = static_cast<PArgs*>(in), *outArgs = static_cast<PArgs*>(out); int32 index; if (args->FindInt32("index", &index) != B_OK) index = -1; if (backend->Window()) backend->Window()->Lock(); BList list; BString itemName; int32 nameIndex = 0; while (args->FindString("items", &itemName, nameIndex) == B_OK) { list.AddItem(new BString(itemName)); nameIndex++; } bool outValue = true; if (list.CountItems() > 0) { if (index >= 0) outValue = backend->AddList(&list, index); else outValue = backend->AddList(&list); } if (backend->Window()) backend->Window()->Unlock(); for (int32 i = 0; i < list.CountItems(); i++) delete ((BString*)list.ItemAt(i)); list.MakeEmpty(); outArgs->MakeEmpty(); outArgs->AddBool("value", outValue); return B_OK; }
// _GetBuffersFor // // Adds pointers to all buffers to the list that contain data of the // supplied interval. void MediaTrackAudioSupplier::_GetBuffersFor(BList& buffers, int64 position, int64 frames) const { buffers.MakeEmpty(); for (int32 i = 0; Buffer* buffer = _BufferAt(i); i++) { // Calculate the intersecting interval and add the buffer if it is // not empty. int32 startFrame = max(position, buffer->offset); int32 endFrame = min(position + frames, buffer->offset + buffer->size); if (startFrame < endFrame) buffers.AddItem(buffer); } }
/*********************************************************** * Build ***********************************************************/ void AddOnMenu::Build() { // Build add addons menus if(!fPath.Path()) return; BDirectory dir(fPath.Path()); entry_ref ref; BEntry entry; BList itemList; itemList.MakeEmpty(); char name[B_FILE_NAME_LENGTH]; char shortcut = 0; BBitmap *bitmap(NULL); while(dir.GetNextEntry(&entry,true) == B_OK) { if(entry.IsFile() && entry.GetRef(&ref) == B_OK) { shortcut = 0; bitmap = NULL; BMessage *msg = new BMessage(fWhat); msg->AddRef("refs",&ref); // make name and shortcut int32 nameLen = ::strlen(ref.name); ::strcpy(name,ref.name); if(name[nameLen-2] == '-') { shortcut = name[nameLen-1]; name[nameLen-2] = '\0'; } if(fUseIcon) bitmap = GetIcon(ref); itemList.AddItem(new IconMenuItem(name,msg,shortcut,0,bitmap)); } } // sort items itemList.SortItems(SortItems); int32 count = itemList.CountItems(); for(int32 i = 0;i < count;i++) AddItem((IconMenuItem*)itemList.ItemAt(i)); }
void pmd_start(void) { song.beat = 0; song.samples = 0; song.samples_per_beat = MSToSamples(song.ms_per_beat); song.samples_left_in_beat = 0; running_notes.MakeEmpty(); queue_and_start_buffer(0); queue_and_start_buffer(1); buffer_needed = false; curbuffer = 0; stat("Starting pmd playback: %d ms per beat, %d samples per beat", \ song.ms_per_beat, song.samples_per_beat); pmd_set_volume(PMD_NORMAL_VOLUME); song.playing = true; }
// MouseDown void TestView::MouseDown(BPoint where) { // clear previous stroke int32 count = fMouseSamples.CountItems(); for (int32 i = 0; i < count; i++) delete (BPoint*)fMouseSamples.ItemAtFast(i); fMouseSamples.MakeEmpty(); FillRect(Bounds(), B_SOLID_LOW); // sample new stroke uint32 buttons; GetMouse(&where, &buttons); MovePenTo(where); while (buttons) { StrokeLine(where); fMouseSamples.AddItem(new BPoint(where)); snooze(20000); GetMouse(&where, &buttons); } }
status_t CDDBDaemon::_Lookup(const dev_t device) { scsi_toc_toc* toc = (scsi_toc_toc*)malloc(kMaxTocSize); if (toc == NULL) return B_NO_MEMORY; uint32 cddbId; if (!_CanLookup(device, &cddbId, toc)) { free(toc); printf("Skipping device with id %ld.\n", device); return B_BAD_TYPE; } printf("Looking up CD with CDDB Id %08lx.\n", cddbId); CDDBServer cddb_server("freedb.freedb.org:80"); status_t result; BList queryResponse; if ((result = cddb_server.Query(cddbId, toc, &queryResponse)) != B_OK) { printf("Error when querying CD.\n"); free(toc); return result; } free(toc); QueryResponseData* diskData = _SelectResult(&queryResponse); if (diskData == NULL) { printf("Could not find any CD entries in query response.\n"); return B_BAD_INDEX; } ReadResponseData readResponse; if ((result = cddb_server.Read(diskData, &readResponse)) != B_OK) { return result; } if (_WriteCDData(device, diskData, &readResponse) == B_OK) { printf("CD data saved.\n"); } else { printf("Error writting CD data.\n" ); } // Delete itens in the query response BList; int32 count = queryResponse.CountItems(); for (int32 i = 0; i < count; ++i) { delete (QueryResponseData*)queryResponse.RemoveItem(0L); } queryResponse.MakeEmpty(); // Delete itens in the track data BList in the read response data; count = readResponse.tracks.CountItems(); for (int32 i = 0; i < count; ++i) { delete (TrackData*)readResponse.tracks.RemoveItem(0L); } readResponse.tracks.MakeEmpty(); return B_OK; }
int main(int, char **argv) { BApplication app(kAppSignature); bool atLeastOnePath = false; BList titleList; BList actionList; BDeskbar deskbar; status_t err = B_OK; for (int32 i = 1; argv[i]!=NULL; i++) { if (strcmp(argv[i], "--help") == 0) break; if (strcmp(argv[i], "--list") == 0) { int32 count = deskbar.CountItems(); int32 found = 0; int32 j = 0; printf("Deskbar items:\n"); while (found < count) { const char *name = NULL; if (deskbar.GetItemInfo(j, &name) == B_OK) { printf("Item %ld: '%s'\n", j, name); free((void *)name); found++; } j++; } return 0; } if (strcmp(argv[i], "--add-volume") == 0) { entry_ref ref; if (get_ref_for_path(argv[0], &ref) == B_OK) { deskbar.AddItem(&ref); } return 0; } if (strcmp(argv[i], "--volume-control") == 0) { BWindow* window = new VolumeWindow(BRect(200, 150, 400, 200)); window->Show(); wait_for_thread(window->Thread(), NULL); return 0; } if (strncmp(argv[i], "--remove", 8) == 0) { BString replicant = "DeskButton"; if (strncmp(argv[i] + 8, "=", 1) == 0) { if (strlen(argv[i] + 9) > 0) { replicant = argv[i] + 9; } else { printf("desklink: Missing replicant name.\n"); return 1; } } int32 found = 0; int32 found_id; while (deskbar.GetItemInfo(replicant.String(), &found_id) == B_OK) { err = deskbar.RemoveItem(found_id); if (err != B_OK) { printf("desklink: Error removing replicant id %ld: %s\n", found_id, strerror(err)); break; } found++; } printf("Removed %ld items.\n", found); return err; } if (strncmp(argv[i], "cmd=", 4) == 0) { BString *title = new BString(argv[i] + 4); int32 index = title->FindFirst(':'); if (index <= 0) { printf("desklink: usage: cmd=title:action\n"); } else { title->Truncate(index); BString *action = new BString(argv[i] + 4); action->Remove(0, index+1); titleList.AddItem(title); actionList.AddItem(action); } continue; } atLeastOnePath = true; BEntry entry(argv[i], true); entry_ref ref; if (entry.Exists()) { entry.GetRef(&ref); } else if (BMimeType::IsValid(argv[i])) { if (be_roster->FindApp(argv[i], &ref) != B_OK) { printf("desklink: cannot find '%s'\n", argv[i]); return 1; } } else { printf("desklink: cannot find '%s'\n", argv[i]); return 1; } err = deskbar.AddItem(&ref); if (err != B_OK) { err = deskbar.AddItem(new DeskButton(BRect(0, 0, 15, 15), &ref, ref.name, titleList, actionList)); if (err != B_OK) { printf("desklink: Deskbar refuses link to '%s': %s\n", argv[i], strerror(err)); return 1; } } titleList.MakeEmpty(); actionList.MakeEmpty(); } if (!atLeastOnePath) { printf( "usage: desklink { [ --list|--remove|[cmd=title:action ... ] [ path|signature ] } ...\n" "--add-volume: install volume control into Deskbar.\n" "--volume-control: show window with global volume control.\n" "--list: list all Deskbar addons.\n" "--remove: remove all desklink addons.\n" "--remove=name: remove all 'name' addons.\n"); return 1; } return 0; }
SDL_bool clipboard_copy_text( struct machine *oric ) { unsigned char *vidmem = (&oric->mem[oric->vid_addr]); int line, col; // TEXT BString text; BList textruns; textruns.AddItem(new_run(0, 0)); for (line = 0; line < 28; line++) { for (col = 0; col < 40; col++) { bool inverted = false; unsigned char c = vidmem[line * 40 + col]; if (c > 127) { inverted = true; c -= 128; } if (c < 8) { textruns.AddItem(new_run(text.Length(), c)); text << ' '; } else if (c < ' ' || c == 127) { text << ' '; } else if (c == 0x60) { text << B_UTF8_COPYRIGHT; } else text << (char)c; } text << '\n'; } //printf("%s\n", text.String()); BMessage *clip = NULL; if (be_clipboard->Lock()) { be_clipboard->Clear(); clip = be_clipboard->Data(); if (clip) { clip->AddData("text/plain", B_MIME_TYPE, text.String(), text.Length()); int arraySize = sizeof(text_run_array) + textruns.CountItems() * sizeof(text_run); text_run_array *array = (text_run_array *)malloc(arraySize); array->count = textruns.CountItems(); for (int i = 0; i < array->count; i++) { memcpy(&array->runs[i], textruns.ItemAt(i), sizeof(text_run)); } clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, array, arraySize); free(array); be_clipboard->Commit(); } be_clipboard->Unlock(); } for (int i = 0; i < textruns.CountItems(); i++) { delete (text_run *)(textruns.ItemAt(i)); } textruns.MakeEmpty(); return SDL_TRUE; }