当前位置: 首页>>代码示例>>C++>>正文


C++ BList::AddItem方法代码示例

本文整理汇总了C++中BList::AddItem方法的典型用法代码示例。如果您正苦于以下问题:C++ BList::AddItem方法的具体用法?C++ BList::AddItem怎么用?C++ BList::AddItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BList的用法示例。


在下文中一共展示了BList::AddItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: BList

// constructor
Hall::Hall(void):
	List(NULL),
	List1(NULL),
	List2(NULL),
	List3(NULL),
	List4(NULL),
	List5(NULL),
	path(NULL),
	_changed(false),
	_count(0)
{
BFile F;
off_t size;
struct score s;
int i;

	List = new BList(1);
	List1 = new BList(6);	// for 14x6
	List2 = new BList(6);	// for 18x8
	List3 = new BList(6);	// for 24 x 12
	List4 = new BList(6);	// for 28 x 16
	List5 = new BList(6);	// for 32 x 20

	path = new BPath();
	
	/*
	 * Find the scores file, if it exists
	 *
	 */
	/*B_COMMON_SETTINGS_DIRECTORY*/
	if (
		find_directory(B_USER_SETTINGS_DIRECTORY, path) == B_NO_ERROR
		&& path->Append(FILE_NAME, true) == B_NO_ERROR
		&& F.SetTo(path->Path(), B_READ_ONLY) == B_NO_ERROR)
	{
		if ((F.GetSize(&size) == B_NO_ERROR) 
			&& ((size % sizeof (struct score))==0))
		{
			_count = size / sizeof (struct score);
			if (_count && _count <= NUMBER)
				for ( i = 0; i < _count; i++)
				{
					BList *L;
					F.Read(&s, sizeof(struct score));
					HSList *h = new HSList();

					h->SetName((char *)s.Name);
					h->SetGameID(s.gameID);
					h->SetGameTime(s.gameTime);
					h->SetNumberTiles(s.gameTiles);
					h->SetTimeOfGame(s.absTime);

					//List->AddItem(h);
					switch(s.gameTiles)
					{
					case 14 * 6: L = List1; break;
					case 18 * 8: L = List2; break;
					case 24 * 12: L = List3; break;
					case 28 * 16: L = List4; break;
					case 32 * 20: L = List5; break;
					default: L = NULL;
					}
					if (L) L->AddItem(h);
				}
		}
	}
	//else fprintf(stderr, "Couldn't open high scores file\n");

}
开发者ID:HaikuArchives,项目名称:BShisen,代码行数:70,代码来源:Hall.cpp

示例2: if

void
update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what,
	const char* preferredFrom)
{
	// clear menu (but leave the first entry, ie. "None")

	for (int32 i = menu->CountItems(); i-- > 1;) {
		delete menu->RemoveItem(i);
	}

	// fill it again

	menu->ItemAt(0)->SetMarked(true);

	BMessage applications;
	if (type == NULL || type->GetSupportingApps(&applications) != B_OK)
		return;

	char preferred[B_MIME_TYPE_LENGTH];
	if (type->GetPreferredApp(preferred) != B_OK)
		preferred[0] = '\0';

	int32 lastFullSupport;
	if (applications.FindInt32("be:sub", &lastFullSupport) != B_OK)
		lastFullSupport = -1;

	BList subList;
	BList superList;

	const char* signature;
	int32 i = 0;
	while (applications.FindString("applications", i, &signature) == B_OK) {
		BMenuItem* item = create_application_item(signature, what);

		if (i < lastFullSupport)
			subList.AddItem(item);
		else
			superList.AddItem(item);

		i++;
	}

	// sort lists

	subList.SortItems(compare_menu_items);
	superList.SortItems(compare_menu_items);

	// add lists to the menu

	if (subList.CountItems() != 0 || superList.CountItems() != 0)
		menu->AddSeparatorItem();

	for (int32 i = 0; i < subList.CountItems(); i++) {
		menu->AddItem((BMenuItem*)subList.ItemAt(i));
	}

	// Add type separator
	if (superList.CountItems() != 0 && subList.CountItems() != 0)
		menu->AddSeparatorItem();

	for (int32 i = 0; i < superList.CountItems(); i++) {
		menu->AddItem((BMenuItem*)superList.ItemAt(i));
	}

	// make items unique and select current choice

	bool lastItemSame = false;
	const char* lastSignature = NULL;
	BMenuItem* last = NULL;
	BMenuItem* select = NULL;

	for (int32 index = 0; index < menu->CountItems(); index++) {
		BMenuItem* item = menu->ItemAt(index);
		if (item == NULL)
			continue;

		if (item->Message() == NULL
			|| item->Message()->FindString("signature", &signature) != B_OK)
			continue;

		if ((preferredFrom == NULL && !strcasecmp(signature, preferred))
			|| (preferredFrom != NULL
				&& !strcasecmp(signature, preferredFrom))) {
			select = item;
		}

		if (last == NULL || strcmp(last->Label(), item->Label())) {
			if (lastItemSame)
				add_signature(last, lastSignature);

			lastItemSame = false;
			last = item;
			lastSignature = signature;
			continue;
		}

		lastItemSame = true;
		add_signature(last, lastSignature);

		last = item;
//.........这里部分代码省略.........
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:101,代码来源:PreferredAppMenu.cpp

示例3: JudgeScore

// returns true if score is destined for greatness
bool Hall::JudgeScore(unsigned long gametime, unsigned long game, int tiles)
{
bool Yes = false;

BList *L;
	
	switch(tiles)
	{
	case 14 * 6: L = List1; break;
	case 18 * 8: L = List2; break;
	case 24 * 12: L = List3; break;
	case 28 * 16: L = List4; break;
	case 32 * 20: L = List5; break;
	default: L = NULL;
	}

	if (!L)
	{
		//printf("No game size!\n");
		return false;
	}

	HSList *h = new HSList();
		

	h->SetGameID(game);
	h->SetGameTime(gametime);
	h->SetNumberTiles(tiles);
	h->SetTimeOfGame(time(NULL));
			

	h->SetName(NULL);

	/* Add the new item
	 */
	L->AddItem(h); 

	L->SortItems(cmpFunc);


	/*
	 * Limit entries to 5
	 */
	if (L->CountItems() > 5)
	{
		HSList *hs;
		hs = (HSList *)L->RemoveItem(5);
		delete hs;
	}

	if (L->HasItem(h))
	{
	AskName *Ask = new AskName();
	char *name;

		name = Ask->Go();
		Ask->Lock();
		Ask->Quit();
		be_app->SetCursor(B_HAND_CURSOR);
		h->SetName(name);
		free(name);
		_changed = true;
		Yes = true;
	}

	return Yes;
}
开发者ID:HaikuArchives,项目名称:BShisen,代码行数:68,代码来源:Hall.cpp

示例4: BAlert

void
GrepWindow::_OnSelectInTracker()
{
	if (fSearchResults->CurrentSelection() < 0) {
		BAlert* alert = new BAlert("Info",
			B_TRANSLATE("Please select the files you wish to have selected for you in "
				"Tracker."),
			B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		return;
	}

	BMessage message;
	BString filePath;
	BPath folderPath;
	BList folderList;
	BString lastFolderAddedToList;

	for (int32 index = 0; ; index++) {
		BStringItem* item = dynamic_cast<BStringItem*>(
			fSearchResults->ItemAt(index));
		if (item == NULL)
			break;

		// only open selected and top level (file) items
		if (!item->IsSelected() || item->OutlineLevel() > 0)
			continue;

		// check if this was previously opened
		if (filePath == item->Text())
			continue;

		filePath = item->Text();
		entry_ref file_ref;
		if (get_ref_for_path(filePath.String(), &file_ref) != B_OK)
			continue;

		message.AddRef("refs", &file_ref);

		// add parent folder to list of folders to open
		folderPath.SetTo(filePath.String());
		if (folderPath.GetParent(&folderPath) == B_OK) {
			BPath* path = new BPath(folderPath);
			if (path->Path() != lastFolderAddedToList) {
				// catches some duplicates
				folderList.AddItem(path);
				lastFolderAddedToList = path->Path();
			} else
				delete path;
		}
	}

	_RemoveFolderListDuplicates(&folderList);
	_OpenFoldersInTracker(&folderList);

	int32 aShortWhile = 100000;
	snooze(aShortWhile);

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		for (int32 x = 0; x < 5; x++) {
			aShortWhile += 100000;
			snooze(aShortWhile);
			_OpenFoldersInTracker(&folderList);
		}
	}

	if (!_AreAllFoldersOpenInTracker(&folderList)) {
		BString str1;
		str1 << B_TRANSLATE("%APP_NAME couldn't open one or more folders.");
		str1.ReplaceFirst("%APP_NAME",APP_NAME);
		BAlert* alert = new BAlert(NULL, str1.String(), B_TRANSLATE("OK"),
			NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE);
		alert->Go(NULL);
		goto out;
	}

	_SelectFilesInTracker(&folderList, &message);

out:
	// delete folderList contents
	int32 folderCount = folderList.CountItems();
	for (int32 x = 0; x < folderCount; x++)
		delete static_cast<BPath*>(folderList.ItemAt(x));
}
开发者ID:AmirAbrams,项目名称:haiku,代码行数:86,代码来源:GrepWindow.cpp

示例5: dir

bool
ShortcutsSpec::_AttemptTabCompletion()
{
	bool ret = false;

	int32 argc;
	char** argv = ParseArgvFromString(fCommand, argc);
	if (argc > 0) {
		// Try to complete the path partially expressed in the last argument!
		char* arg = argv[argc - 1];
		char* fileFragment = strrchr(arg, '/');
		if (fileFragment) {
			const char* directoryName = (fileFragment == arg) ? "/" : arg;
			*fileFragment = '\0';
			fileFragment++;
			int fragLen = strlen(fileFragment);

			BDirectory dir(directoryName);
			if (dir.InitCheck() == B_NO_ERROR) {
				BEntry nextEnt;
				BPath nextPath;
				BList matchList;
				int maxEntryLen = 0;

				// Read in all the files in the directory whose names start 
				// with our fragment.
				while (dir.GetNextEntry(&nextEnt) == B_NO_ERROR) {
					if (nextEnt.GetPath(&nextPath) == B_NO_ERROR) {
						char* filePath = strrchr(nextPath.Path(), '/') + 1;
						if (strncmp(filePath, fileFragment, fragLen) == 0) {
							int len = strlen(filePath);
							if (len > maxEntryLen)
								maxEntryLen = len;
							char* newStr = new char[len + 1];
							strcpy(newStr, filePath);
							matchList.AddItem(newStr);
						}
					}
				}

				// Now slowly extend our keyword to its full length, counting
				// numbers of matches at each step. If the match list length 
				// is 1, we can use that whole entry. If it's greater than one
				// , we can use just the match length.
				int matchLen = matchList.CountItems();
				if (matchLen > 0) {
					int i;
					BString result(fileFragment);
					for (i = fragLen; i < maxEntryLen; i++) {
						// See if all the matching entries have the same letter
						// in the next position... if so, we can go farther.
						char commonLetter = '\0';
						for (int j = 0; j < matchLen; j++) {
							char nextLetter = GetLetterAt(
								(char*)matchList.ItemAt(j), i);
							if (commonLetter == '\0')
								commonLetter = nextLetter;
						
							if ((commonLetter != '\0') 
								&& (commonLetter != nextLetter)) {
								commonLetter = '\0';// failed;
								beep();
								break;
							}
						}
						if (commonLetter == '\0')
							break;
						else
							result.Append(commonLetter, 1);
					}

					// Free all the strings we allocated
					for (int k = 0; k < matchLen; k++)
						delete [] ((char*)matchList.ItemAt(k));

					DoStandardEscapes(result);

					BString wholeLine;
					for (int l = 0; l < argc - 1; l++) {
						wholeLine += argv[l];
						wholeLine += " ";
					}
				
					BString file(directoryName);
					DoStandardEscapes(file);

					if (directoryName[strlen(directoryName) - 1] != '/')
						file += "/";

					file += result;

					// Remove any trailing slash...
					const char* fileStr = file.String();
					if (fileStr[strlen(fileStr)-1] == '/')
						file.RemoveLast("/");

					// And re-append it iff the file is a dir.
					BDirectory testFileAsDir(file.String());
					if ((strcmp(file.String(), "/") != 0) 
						&& (testFileAsDir.InitCheck() == B_NO_ERROR))
//.........这里部分代码省略.........
开发者ID:mmanley,项目名称:Antares,代码行数:101,代码来源:ShortcutsSpec.cpp

示例6: ResetTransformationCommand

// MessageReceived
void
StyleListView::MessageReceived(BMessage* message)
{
    switch (message->what) {
    case MSG_ADD: {
        Style* style;
        AddStylesCommand* command;
        rgb_color color;
        if (fCurrentColor != NULL)
            color = fCurrentColor->Color();
        else {
            color.red = 0;
            color.green = 0;
            color.blue = 0;
            color.alpha = 255;
        }
        new_style(color, fStyleContainer, &style, &command);
        fCommandStack->Perform(command);
        break;
    }
    case MSG_REMOVE:
        RemoveSelected();
        break;
    case MSG_DUPLICATE: {
        int32 count = CountSelectedItems();
        int32 index = 0;
        BList items;
        for (int32 i = 0; i < count; i++) {
            index = CurrentSelection(i);
            BListItem* item = ItemAt(index);
            if (item)
                items.AddItem((void*)item);
        }
        CopyItems(items, index + 1);
        break;
    }
    case MSG_RESET_TRANSFORMATION: {
        int32 count = CountSelectedItems();
        BList gradients;
        for (int32 i = 0; i < count; i++) {
            StyleListItem* item = dynamic_cast<StyleListItem*>(
                                      ItemAt(CurrentSelection(i)));
            if (item && item->style && item->style->Gradient())
                if (!gradients.AddItem(
                            (void*)item->style->Gradient()))
                    break;
        }
        count = gradients.CountItems();
        if (count < 0)
            break;

        Transformable* transformables[count];
        for (int32 i = 0; i < count; i++) {
            Gradient* gradient = (Gradient*)gradients.ItemAtFast(i);
            transformables[i] = gradient;
        }

        ResetTransformationCommand* command =
            new ResetTransformationCommand(transformables, count);

        fCommandStack->Perform(command);
        break;
    }
    default:
        SimpleListView::MessageReceived(message);
        break;
    }
}
开发者ID:,项目名称:,代码行数:69,代码来源:

示例7: Do

BMessage* Delete::Do(PDocument *doc, BMessage *settings)
{
/*	BMessage	*node				= new BMessage();
	BMessage	*commandMessage		= PCommand::Do(doc,settings);
	BList		*parentGroupList	= NULL;
	BMessage	*connection			= new BMessage();
	int32		i					= 0;
	while (settings->FindPointer("node",i,(void **)&node))
	{
		if (settings->FindPointer("parentGroupList",i,(void **)&parentGroupList))
			parentGroupList->RemoveItem(node);
		else
			(doc->GetAllNodes())->RemoveItem(node);
		i++;
	}
	i = 0;
	while (settings->FindPointer("connection",i,(void **)&connection))
	{
		i++;
		(doc->GetAllConnections())->RemoveItem(connection);
	}
	return commandMessage;*/
	//**Todo
	BMessage		*undoMessage		= new BMessage();
	BList			*selected			= doc->GetSelected();
	BList			*connections		= doc->GetAllConnections();
	BList			*allNodes			= doc->GetAllNodes();
	BList			*changed			= doc->GetChangedNodes();
	BMessage		*node				= NULL;
	BMessage		*connection			= NULL;
	BList			*outgoing			= NULL;
	BList			*incoming			= NULL;
	int32			i					= 0;
	while (	(node = (BMessage *)selected->RemoveItem(i)) != NULL)
	{
		allNodes->RemoveItem(node);
		connections->RemoveItem(node);
		changed->AddItem(node);
		undoMessage->AddPointer("node",node);
		if (node->FindPointer("Node::outgoing",(void **)&outgoing) == B_OK)
		{
			for (int32 i=0;i<outgoing->CountItems();i++)
			{
				connection= (BMessage *)outgoing->ItemAt(i);
				connections->RemoveItem(connection);
//				trash->AddItem(connection);
				changed->AddItem(connection);
				undoMessage->AddPointer("node",connection);
			}
		}
		if (node->FindPointer("Node::incoming",(void **)&incoming) == B_OK)
		{
			for (int32 i=0;i<incoming->CountItems();i++)
			{
				connection= (BMessage *)incoming->ItemAt(i);
				connections->RemoveItem(connection);
//				trash->AddItem(connection);
				changed->AddItem(connection);
				undoMessage->AddPointer("node",connection);
			}
		}
	}
	doc->SetModified();
	settings->RemoveName("Delete::Undo");
	settings->AddMessage("Delete::Undo",undoMessage);
	settings = PCommand::Do(doc,settings);
	return settings;
}
开发者ID:BackupTheBerlios,项目名称:projectconcepto-svn,代码行数:68,代码来源:Delete.cpp

示例8: argMsg

void
NotificationView::MouseDown(BPoint point)
{
	int32 buttons;
	Window()->CurrentMessage()->FindInt32("buttons", &buttons);

	switch (buttons) {
		case B_PRIMARY_MOUSE_BUTTON:
		{
			BRect closeRect = Bounds().InsetByCopy(2,2);
			closeRect.left = closeRect.right - kCloseSize;
			closeRect.bottom = closeRect.top + kCloseSize;

			if (!closeRect.Contains(point)) {
				entry_ref launchRef;
				BString launchString;
				BMessage argMsg(B_ARGV_RECEIVED);
				BMessage refMsg(B_REFS_RECEIVED);
				entry_ref appRef;
				bool useArgv = false;
				BList messages;
				entry_ref ref;

				if (fNotification->OnClickApp() != NULL
					&& be_roster->FindApp(fNotification->OnClickApp(), &appRef)
				   		== B_OK) {
					useArgv = true;
				}

				if (fNotification->OnClickFile() != NULL
					&& be_roster->FindApp(
							(entry_ref*)fNotification->OnClickFile(), &appRef)
				   		== B_OK) {
					useArgv = true;
				}

				for (int32 i = 0; i < fNotification->CountOnClickRefs(); i++)
					refMsg.AddRef("refs", fNotification->OnClickRefAt(i));
				messages.AddItem((void*)&refMsg);

				if (useArgv) {
					int32 argc = fNotification->CountOnClickArgs() + 1;
					BString arg;

					BPath p(&appRef);
					argMsg.AddString("argv", p.Path());

					argMsg.AddInt32("argc", argc);

					for (int32 i = 0; i < argc - 1; i++) {
						argMsg.AddString("argv",
							fNotification->OnClickArgAt(i));
					}

					messages.AddItem((void*)&argMsg);
				}

				if (fNotification->OnClickApp() != NULL)
					be_roster->Launch(fNotification->OnClickApp(), &messages);
				else
					be_roster->Launch(fNotification->OnClickFile(), &messages);
			} else {
				fCloseClicked = true;
			}

			// Remove the info view after a click
			BMessage remove_msg(kRemoveView);
			remove_msg.AddPointer("view", this);

			BMessenger msgr(Parent());
			msgr.SendMessage(&remove_msg);
			break;
		}
	}
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:75,代码来源:NotificationView.cpp

示例9: argMsg

void
NotificationView::MouseDown(BPoint point)
{
	int32 buttons;
	Window()->CurrentMessage()->FindInt32("buttons", &buttons);

	switch (buttons) {
		case B_PRIMARY_MOUSE_BUTTON:
		{
			BRect closeRect = Bounds().InsetByCopy(2,2);
			closeRect.left = closeRect.right - kCloseSize;
			closeRect.bottom = closeRect.top + kCloseSize;	

			if (!closeRect.Contains(point)) {
				entry_ref launchRef;
				BString launchString;
				BMessage argMsg(B_ARGV_RECEIVED);
				BMessage refMsg(B_REFS_RECEIVED);
				entry_ref appRef;
				bool useArgv = false;
				BList messages;
				entry_ref ref;

				if (fDetails->FindString("onClickApp", &launchString) == B_OK)
					if (be_roster->FindApp(launchString.String(), &appRef) == B_OK)
						useArgv = true;
				if (fDetails->FindRef("onClickFile", &launchRef) == B_OK) {
					if (be_roster->FindApp(&launchRef, &appRef) == B_OK)
						useArgv = true;
				}

				if (fDetails->FindRef("onClickRef", &ref) == B_OK) {			
					for (int32 i = 0; fDetails->FindRef("onClickRef", i, &ref) == B_OK; i++)
						refMsg.AddRef("refs", &ref);

					messages.AddItem((void*)&refMsg);
				}

				if (useArgv) {
					type_code type;
					int32 argc = 0;
					BString arg;

					BPath p(&appRef);
					argMsg.AddString("argv", p.Path());

					fDetails->GetInfo("onClickArgv", &type, &argc);
					argMsg.AddInt32("argc", argc + 1);

					for (int32 i = 0; fDetails->FindString("onClickArgv", i, &arg) == B_OK; i++)
						argMsg.AddString("argv", arg);

					messages.AddItem((void*)&argMsg);
				}

				BMessage tmp;
				for (int32 i = 0; fDetails->FindMessage("onClickMsg", i, &tmp) == B_OK; i++)
					messages.AddItem((void*)&tmp);

				if (fDetails->FindString("onClickApp", &launchString) == B_OK)
					be_roster->Launch(launchString.String(), &messages);
				else
					be_roster->Launch(&launchRef, &messages);
			}

			// Remove the info view after a click
			BMessage remove_msg(kRemoveView);
			remove_msg.AddPointer("view", this);

			BMessenger msgr(Parent());
			msgr.SendMessage(&remove_msg);
			break;
		}
	}
}
开发者ID:mariuz,项目名称:haiku,代码行数:75,代码来源:NotificationView.cpp

示例10: separatorRect

BView *
DefaultMediaTheme::MakeViewFor(BParameterGroup& group, const BRect* hintRect)
{
	CALLED();

	if (group.Flags() & B_HIDDEN_PARAMETER)
		return NULL;

	BRect rect;
	if (hintRect != NULL)
		rect = *hintRect;

	GroupView *view = new GroupView(rect, group.Name());

	// Create the parameter views - but don't add them yet

	rect.OffsetTo(B_ORIGIN);
	rect.InsetBySelf(5, 5);

	BList views;
	for (int32 i = 0; i < group.CountParameters(); i++) {
		BParameter *parameter = group.ParameterAt(i);
		if (parameter == NULL)
			continue;

		BView *parameterView = MakeSelfHostingViewFor(*parameter,
			hintRect ? &rect : NULL);
		if (parameterView == NULL)
			continue;

		parameterView->SetViewColor(view->ViewColor());
			// ToDo: dunno why this is needed, but the controls
			// sometimes (!) have a white background without it

		views.AddItem(parameterView);
	}

	// Identify a title view, and add it at the top if present

	TitleView *titleView = dynamic_cast<TitleView *>((BView *)views.ItemAt(0));
	if (titleView != NULL) {
		view->AddChild(titleView);
		rect.OffsetBy(0, titleView->Bounds().Height());
	}

	// Add the sub-group views

	rect.right = rect.left + 20;
	rect.bottom = rect.top + 20;
	float lastHeight = 0;

	for (int32 i = 0; i < group.CountGroups(); i++) {
		BParameterGroup *subGroup = group.GroupAt(i);
		if (subGroup == NULL)
			continue;

		BView *groupView = MakeViewFor(*subGroup, &rect);
		if (groupView == NULL)
			continue;

		if (i > 0) {
			// add separator view
			BRect separatorRect(groupView->Frame());
			separatorRect.left -= 3;
			separatorRect.right = separatorRect.left + 1;
			if (lastHeight > separatorRect.Height())
				separatorRect.bottom = separatorRect.top + lastHeight;

			view->AddChild(new SeparatorView(separatorRect));
		}

		view->AddChild(groupView);

		rect.OffsetBy(groupView->Bounds().Width() + 5, 0);

		lastHeight = groupView->Bounds().Height();
		if (lastHeight > rect.Height())
			rect.bottom = rect.top + lastHeight - 1;
	}

	view->ResizeTo(rect.left + 10, rect.bottom + 5);
	view->SetContentBounds(view->Bounds());

	if (group.CountParameters() == 0)
		return view;

	// add the parameter views part of the group

	if (group.CountGroups() > 0) {
		rect.top = rect.bottom + 10;
		rect.bottom = rect.top + 20;
	}

	bool center = false;

	for (int32 i = 0; i < views.CountItems(); i++) {
		BView *parameterView = static_cast<BView *>(views.ItemAt(i));

		if (parameterView->Bounds().Width() + 5 > rect.Width())
			rect.right = parameterView->Bounds().Width() + rect.left + 5;
//.........这里部分代码省略.........
开发者ID:mmanley,项目名称:Antares,代码行数:101,代码来源:DefaultMediaTheme.cpp

示例11: clipboard_copy_text

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;
}
开发者ID:Godzil,项目名称:oricutron,代码行数:65,代码来源:gui_beos.cpp

示例12: BString

void
TBarView::ChangeState(int32 state, bool vertical, bool left, bool top)
{
	bool vertSwap = (fVertical != vertical);
	bool leftSwap = (fLeft != left);

	fState = state;
	fVertical = vertical;
	fLeft = left;
	fTop = top;
	
	BRect screenFrame = (BScreen(Window())).Frame();

	PlaceBeMenu();
	if (fVertical){
#if SA_CLOCK
		PlaceClock();	// tray dependent on clock location
#endif
		PlaceTray(vertSwap, leftSwap, screenFrame);
	} else {
		PlaceTray(vertSwap, leftSwap, screenFrame);
#if SA_CLOCK
		PlaceClock();	// clock is dependent on tray location
#endif
	}

	// We need to keep track of what apps are expanded.
	BList expandedItems;
	BString *signature = NULL;
	if (fVertical && Expando() && static_cast<TBarApp *>(be_app)->Settings()->superExpando) {
		// Get a list of the Signatures of expanded apps - Can't use team_id because
		// there can be more than one team per application
		if (fVertical && Expando() && vertical && fExpando) {
			for (int index = 0; index < fExpando->CountItems(); index++) {
				TTeamMenuItem *item = dynamic_cast<TTeamMenuItem *>(fExpando->ItemAt(index));
				if (item != NULL && item->IsExpanded()) {
					signature = new BString(item->Signature());
					expandedItems.AddItem((void *)signature);
				}
			}
		}
	}

	PlaceApplicationBar(screenFrame);
	SizeWindow(screenFrame);
	PositionWindow(screenFrame);
	Window()->UpdateIfNeeded();
	
	// Re-expand those apps.
	if (expandedItems.CountItems() > 0) {
		for (int sigIndex = expandedItems.CountItems(); sigIndex-- > 0;) {
			signature = static_cast<BString *>(expandedItems.ItemAt(sigIndex));
			if (signature == NULL)
				continue;

			// Start at the 'bottom' of the list working up.
			// Prevents being thrown off by expanding items.
			for (int teamIndex = fExpando->CountItems(); teamIndex-- > 0;) {
				TTeamMenuItem *item = dynamic_cast<TTeamMenuItem *>(fExpando->ItemAt(teamIndex));
				if (item != NULL && !signature->Compare(item->Signature())) {
					item->ToggleExpandState(false);
					break;
				}
			}
		}

		// Clean up expanded signature list.
		while (!expandedItems.IsEmpty()) {
			delete static_cast<BString *>(expandedItems.RemoveItem((int32)0));
		}

		fExpando->SizeWindow();
	}

	Invalidate();
}
开发者ID:Ithamar,项目名称:cosmoe,代码行数:76,代码来源:BarView.cpp

示例13: ConvertWordToCharset

_EXPORT ssize_t utf8_to_rfc2047 (char **bufp, ssize_t length, uint32 charset, char encoding) {
	struct word {
		BString	originalWord;
		BString	convertedWord;
		bool	needsEncoding;

		// Convert the word from UTF-8 to the desired character set.  The
		// converted version also includes the escape codes to return to ASCII
		// mode, if relevant.  Also note if it uses unprintable characters,
		// which means it will need that special encoding treatment later.
		void ConvertWordToCharset (uint32 charset) {
			int32 state = 0;
			int32 originalLength = originalWord.Length();
			int32 convertedLength = originalLength * 5 + 1;
			char *convertedBuffer = convertedWord.LockBuffer (convertedLength);
			mail_convert_from_utf8 (charset, originalWord.String(),
				&originalLength, convertedBuffer, &convertedLength, &state);
			for (int i = 0; i < convertedLength; i++) {
				if ((convertedBuffer[i] & (1 << 7)) ||
					(convertedBuffer[i] >= 0 && convertedBuffer[i] < 32)) {
					needsEncoding = true;
					break;
				}
			}
			convertedWord.UnlockBuffer (convertedLength);
		};
	};
	struct word *currentWord;
	BList words;

	// Break the header into words.  White space characters (including tabs and
	// newlines) separate the words.  Each word includes any space before it as
	// part of the word.  Actually, quotes and other special characters
	// (",()<>@) are treated as separate words of their own so that they don't
	// get encoded (because MIME headers get the quotes parsed before character
	// set unconversion is done).  The reader is supposed to ignore all white
	// space between encoded words, which can be inserted so that older mail
	// parsers don't have overly long line length problems.

	const char *source = *bufp;
	const char *bufEnd = *bufp + length;
	const char *specialChars = "\"()<>@,";

	while (source < bufEnd) {
		currentWord = new struct word;
		currentWord->needsEncoding = false;

		int wordEnd = 0;

		// Include leading spaces as part of the word.
		while (source + wordEnd < bufEnd && isspace (source[wordEnd]))
			wordEnd++;

		if (source + wordEnd < bufEnd &&
			strchr (specialChars, source[wordEnd]) != NULL) {
			// Got a quote mark or other special character, which is treated as
			// a word in itself since it shouldn't be encoded, which would hide
			// it from the mail system.
			wordEnd++;
		} else {
			// Find the end of the word.  Leave wordEnd pointing just after the
			// last character in the word.
			while (source + wordEnd < bufEnd) {
				if (isspace(source[wordEnd]) ||
					strchr (specialChars, source[wordEnd]) != NULL)
					break;
				if (wordEnd > 51 /* Makes Base64 ISO-2022-JP "word" a multiple of 4 bytes */ &&
					0xC0 == (0xC0 & (unsigned int) source[wordEnd])) {
					// No English words are that long (46 is the longest),
					// break up what is likely Asian text (which has no spaces)
					// at the start of the next non-ASCII UTF-8 character (high
					// two bits are both ones).  Note that two encoded words in
					// a row get joined together, even if there is a space
					// between them in the final output text, according to the
					// standard.  Next word will also be conveniently get
					// encoded due to the 0xC0 test.
					currentWord->needsEncoding = true;
					break;
				}
				wordEnd++;
			}
		}
		currentWord->originalWord.SetTo (source, wordEnd);
		currentWord->ConvertWordToCharset (charset);
		words.AddItem(currentWord);
		source += wordEnd;
	}

	// Combine adjacent words which contain unprintable text so that the
	// overhead of switching back and forth between regular text and specially
	// encoded text is reduced.  However, the combined word must be shorter
	// than the maximum of 75 bytes, including character set specification and
	// all those delimiters (worst case 22 bytes of overhead).

	struct word *run;

	for (int32 i = 0; (currentWord = (struct word *) words.ItemAt (i)) != NULL; i++) {
		if (!currentWord->needsEncoding)
			continue; // No need to combine unencoded words.
		for (int32 g = i+1; (run = (struct word *) words.ItemAt (g)) != NULL; g++) {
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:

示例14: BMessage

MidiMonitorApp::MidiMonitorApp ( void ) 
	: BApplication ("application/x-vnd.tebo-midimonitor")
{
	BRect aRect;
	BList windows;
	const float menuHeight = 20;
	int	initPort = 0; // set this from prefs instead...archive?
	bool isPortOpen = FALSE;
	char str[80], portname[132];
		

	midiPort = new BMidiPort;
	numPorts = midiPort->CountDevices();
	midiPort->GetDeviceName ( initPort, portname );
	if ( midiPort->Open (portname) != B_NO_ERROR ) {
		sprintf ( str, "can't open %s", portname );
		BAlert *b = new BAlert ("", str, "ug" );
		b->Go();
	} else {
//		sprintf ( str, "opened %s", portNames[initPort] );
//		BAlert *b = new BAlert ("", str, "okay!" );
//		b->Go();
		isPortOpen = TRUE;
	}
		
	theMidiMonitor = new M2BMidiMonitor ();
	theMidiMonitor->Start();
	
	midiPort->Connect ( theMidiMonitor );
	if ( isPortOpen )
		midiPort->Start();

	aRect.Set(20, 100, 340, 400);
	BWindow *aWindow = (BWindow *) new M2BWindow(aRect);
	aRect.OffsetTo(B_ORIGIN);
	BView *aView = (BView *) new M2BView(aRect, "M2BView", 
					(M2BMidiMonitor*)theMidiMonitor, menuHeight);
	aWindow->AddChild(aView);
	aWindow->Show();
	windows.AddItem ( aWindow );


	

		aRect.Set ( 0,0,1000,menuHeight);
		BMenuBar	*menubar = new BMenuBar ( aRect, "menubar" );
		menubar->SetBorder ( B_BORDER_FRAME );
	
		BMenuItem *item; 
		BMenu *menu = new BMenu("File"); 
   
		item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); 
		item->SetTarget(be_app); 
		menu->AddItem(item); 
	
		menubar->AddItem ( menu );
		
		// add the port selection menu
		menu = new BMenu ( "Port" );
		for ( int i = 0; i < numPorts; i++ ) {
			midiPort->GetDeviceName ( i, portname );
			item = new BMenuItem ( portname, 
									new BMessage ( MSG_MIDIMONITOR_MIDI_PORT ) );
			item->Message()->AddString ( "port", portname );
			menu->AddItem ( item );
		}
		menu->SetRadioMode ( TRUE );
		menu->ItemAt(initPort)->SetMarked ( TRUE );
		menu->SetTargetForItems ( be_app );	
		menubar->AddItem ( menu );


		aView->AddChild ( menubar );
	
	
}
开发者ID:HaikuArchives,项目名称:MidiMonitor,代码行数:76,代码来源:main.cpp

示例15: node

void
PairsView::_ReadRandomIcons()
{
	// TODO: maybe read the icons only once at startup

	// clean out any previous icons
	for (int i = 0; i < fCardBitmaps.CountItems(); i++)
		delete ((BBitmap*)fCardBitmaps.ItemAt(i));

	fCardBitmaps.MakeEmpty();

	BDirectory appsDirectory;
	BDirectory prefsDirectory;

	BPath path;
	if (find_directory(B_BEOS_APPS_DIRECTORY, &path) == B_OK)
		appsDirectory.SetTo(path.Path());
	if (find_directory(B_BEOS_PREFERENCES_DIRECTORY, &path) == B_OK)
		prefsDirectory.SetTo(path.Path());

	// read vector icons from apps and prefs folder and put them
	// into a BList as BBitmaps
	BList bitmaps;

	BEntry entry;
	while (appsDirectory.GetNextEntry(&entry) == B_OK
		|| prefsDirectory.GetNextEntry(&entry) == B_OK) {

		BNode node(&entry);
		BNodeInfo nodeInfo(&node);

		if (nodeInfo.InitCheck() < B_OK)
			continue;

		uint8* data;
		size_t size;
		type_code type;

		if (nodeInfo.GetIcon(&data, &size, &type) < B_OK)
			continue;

		if (type != B_VECTOR_ICON_TYPE) {
			delete[] data;
			continue;
		}

		BBitmap* bitmap = new BBitmap(
			BRect(0, 0, kBitmapSize - 1, kBitmapSize - 1), 0, B_RGBA32);
		if (BIconUtils::GetVectorIcon(data, size, bitmap) < B_OK) {
			delete[] data;
			delete bitmap;
			continue;
		}

		delete[] data;

		if (_HasBitmap(bitmaps, bitmap) || !bitmaps.AddItem(bitmap))
			delete bitmap;
		else if (bitmaps.CountItems() >= 128) {
			// this is enough to choose from, stop eating memory...
			break;
		}
	}

	// pick random bitmaps from the ones we got in the list
	srand((unsigned)time(0));

	for (int i = 0; i < fNumOfCards / 2; i++) {
		int32 index = rand() % bitmaps.CountItems();
		BBitmap* bitmap = ((BBitmap*)bitmaps.RemoveItem(index));
		if (bitmap == NULL) {
			char buffer[512];
			snprintf(buffer, sizeof(buffer), B_TRANSLATE("Pairs did not find "
				"enough vector icons in the system; it needs at least %d."),
				fNumOfCards / 2);
			BString msgStr(buffer);
			msgStr << "\n";
			BAlert* alert = new BAlert("Fatal", msgStr.String(),
				B_TRANSLATE("OK"), 	NULL, NULL, B_WIDTH_FROM_WIDEST,
				B_STOP_ALERT);
			alert->SetShortcut(0, B_ESCAPE);
			alert->Go();
			exit(1);
		}
		fCardBitmaps.AddItem(bitmap);
	}

	// delete the remaining bitmaps from the list
	while (BBitmap* bitmap = (BBitmap*)bitmaps.RemoveItem(0L))
		delete bitmap;
}
开发者ID:mmadia,项目名称:Haiku-services-branch,代码行数:91,代码来源:PairsView.cpp


注:本文中的BList::AddItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。