本文整理汇总了C++中BMenu::SetFont方法的典型用法代码示例。如果您正苦于以下问题:C++ BMenu::SetFont方法的具体用法?C++ BMenu::SetFont怎么用?C++ BMenu::SetFont使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BMenu
的用法示例。
在下文中一共展示了BMenu::SetFont方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: NewChangeViewItem
BMenuItem* AmTrackInfoView::NewChangeViewItem() const
{
AmViewFactory* factory = AmGlobals().FactoryNamed(mFactorySignature);
if (!factory) return NULL;
BMenu* menu = new BMenu(AM_INFO_CHANGE_VIEW_STR);
if (!menu) return NULL;
BMenuItem* item;
BString name;
for (uint32 k = 0; factory->DataNameAt(k, mViewType, name) == B_OK; k++) {
BMessage* msg = new BMessage(CHANGE_INFO_MSG);
if( msg && (item = new BMenuItem( name.String(), msg )) ) {
msg->AddPointer(SZ_VIEW_ID, this);
msg->AddString(SZ_FACTORY_SIGNATURE, mFactorySignature.String() );
msg->AddString(SZ_FACTORY_VIEW_NAME, name.String() );
item->SetTarget(this);
menu->AddItem(item);
if (name == mViewName) item->SetEnabled(false);
}
name = (const char*)NULL;
}
item = new BMenuItem(menu);
if( !item ) {
delete menu;
return NULL;
}
menu->SetFontSize( Prefs().Size(FONT_Y) );
menu->SetFont( be_plain_font );
return item;
}
示例2: copy_font
void ArpMenuBar::copy_font(BMenu* menu, BFont* font)
{
if( !menu ) return;
int32 num = menu->CountItems();
for( int32 i=0; i<num; i++ ) {
BMenu* child = menu->SubmenuAt(i);
if( child ) {
copy_font(child,font);
child->SetFont(font);
child->InvalidateLayout();
}
}
}
示例3: copy_attrs
void ArpMenuField::copy_attrs(BMenu* menu)
{
if( !menu ) return;
int32 num = menu->CountItems();
for( int32 i=0; i<num; i++ ) {
BMenu* child = menu->SubmenuAt(i);
if( child ) {
copy_attrs(child);
// the menu doesn't seem to see this.
child->SetFont(&PV_MenuFont);
child->SetHighColor(PV_MenuForeColor);
child->SetLowColor(PV_MenuBackColor);
child->SetViewColor(PV_MenuBackColor);
child->InvalidateLayout();
}
}
}
示例4: ComputeDimens
void ArpMenuField::ComputeDimens(ArpDimens& cur_dimens)
{
BMenu* menu = MenuBar();
BMenu* popup = Menu();
if( menu ) {
copy_attrs(menu);
copy_attrs(popup);
menu->SetFont(&PV_MenuFont);
menu->InvalidateLayout();
}
get_view_dimens(&cur_dimens, this, false);
font_height fhs;
BasicFont()->GetHeight(&fhs);
const float fh = fhs.ascent+fhs.descent+fhs.leading;
float fw = BasicFont()->StringWidth("WWWW");
float pref_w=0;
if( popup ) {
int32 num = popup->CountItems();
for( int32 i=0; i<num; i++ ) {
BMenuItem* item = popup->ItemAt(i);
if( item ) {
const float w=BasicFont()->StringWidth(item->Label());
ArpD(cdb << ADH << "Dimensions for popup label "
<< item->Label() << ": " << w << endl);
if( w > pref_w ) pref_w = w;
}
}
}
cur_dimens.Y().SetTo(0, fh+12, fh+12, fh+12, 0);
float labelWidth = (Label() && *Label())
? BasicFont()->StringWidth(Label()) + BasicFont()->StringWidth(" ")
: 0;
cur_dimens.X().SetTo(labelWidth,
(fw < pref_w ? fw : pref_w) + 20,
pref_w + 20, pref_w + 20,
0);
}
示例5: BMessage
BPopUpMenu*
DeskbarView::_BuildMenu()
{
BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING, false, false);
menu->SetFont(be_plain_font);
menu->AddItem(new BMenuItem(MDR_DIALECT_CHOICE (
"Create new message", "N) 新規メッセージ作成")B_UTF8_ELLIPSIS,
new BMessage(MD_OPEN_NEW)));
menu->AddSeparatorItem();
BMessenger tracker(kTrackerSignature);
BNavMenu* navMenu;
BMenuItem* item;
BMessage* msg;
entry_ref ref;
BPath path;
find_directory(B_USER_SETTINGS_DIRECTORY, &path);
path.Append("Mail/Menu Links");
BDirectory directory;
if (_CreateMenuLinks(directory, path)) {
int32 count = 0;
while (directory.GetNextRef(&ref) == B_OK) {
count++;
path.SetTo(&ref);
// the true here dereferences the symlinks all the way :)
BEntry entry(&ref, true);
// do we want to use the NavMenu, or just an ordinary BMenuItem?
// we are using the NavMenu only for directories and queries
bool useNavMenu = false;
if (entry.InitCheck() == B_OK) {
if (entry.IsDirectory())
useNavMenu = true;
else if (entry.IsFile()) {
// Files should use the BMenuItem unless they are queries
char mimeString[B_MIME_TYPE_LENGTH];
BNode node(&entry);
BNodeInfo info(&node);
if (info.GetType(mimeString) == B_OK
&& strcmp(mimeString, "application/x-vnd.Be-query")
== 0)
useNavMenu = true;
}
// clobber the existing ref only if the symlink derefernces
// completely, otherwise we'll stick with what we have
entry.GetRef(&ref);
}
msg = new BMessage(B_REFS_RECEIVED);
msg->AddRef("refs", &ref);
if (useNavMenu) {
item = new BMenuItem(navMenu = new BNavMenu(path.Leaf(),
B_REFS_RECEIVED, tracker), msg);
navMenu->SetNavDir(&ref);
} else
item = new BMenuItem(path.Leaf(), msg);
menu->AddItem(item);
if(entry.InitCheck() != B_OK)
item->SetEnabled(false);
}
if (count > 0)
menu->AddSeparatorItem();
}
// Hack for R5's buggy Query Notification
#ifdef HAIKU_TARGET_PLATFORM_BEOS
menu->AddItem(new BMenuItem(
MDR_DIALECT_CHOICE("Refresh New Mail Count",
"未読メールカウントを更新"),
new BMessage(MD_REFRESH_QUERY)));
#endif
// The New E-mail query
if (fNewMessages > 0) {
BString string;
MDR_DIALECT_CHOICE(
string << fNewMessages << " new message"
<< (fNewMessages != 1 ? "s" : B_EMPTY_STRING),
string << fNewMessages << " 通の未読メッセージ");
_GetNewQueryRef(ref);
item = new BMenuItem(navMenu = new BNavMenu(string.String(),
B_REFS_RECEIVED, BMessenger(kTrackerSignature)),
msg = new BMessage(B_REFS_RECEIVED));
msg->AddRef("refs", &ref);
navMenu->SetNavDir(&ref);
menu->AddItem(item);
} else {
menu->AddItem(item = new BMenuItem(
//.........这里部分代码省略.........
示例6: HDialog
CInfoDialog::CInfoDialog(BRect frame, const char *name, window_type type, int flags,
BWindow *owner, BPositionIO* data)
: HDialog(frame, name, type, flags, owner, data)
{
fDoc = dynamic_cast<PDoc*>(owner);
FailNil(fDoc);
SetText("name", owner->Title());
char s[32];
sprintf(s, "%d", fDoc->TextView()->Size());
SetText("docsize", s);
sprintf(s, "%d", fDoc->TextView()->LineCount());
SetText("lines", s);
BMenuField *mf = dynamic_cast<BMenuField*>(FindView("mime"));
FailNil(mf);
fTypes = mf->Menu();
const char *p;
int i = 0;
while ((p = gPrefs->GetIxPrefString(prf_X_Mimetype, i++)) != NULL)
fTypes->AddItem(new BMenuItem(p, new BMessage(msg_FieldChanged)));
if (i == 1)
fTypes->AddItem(new BMenuItem("text/plain", new BMessage(msg_FieldChanged)));
const char *mime = fDoc->MimeType();
if (mime && mime[0])
{
for (i = 0; i < fTypes->CountItems(); i++)
{
BMenuItem *item = fTypes->ItemAt(i);
if (strcmp(item->Label(), mime) == 0)
{
item->SetMarked(true);
break;
}
}
if (i == fTypes->CountItems())
{
fTypes->AddSeparatorItem();
fTypes->AddItem(new BMenuItem(mime, new BMessage(msg_FieldChanged)));
fTypes->ItemAt(fTypes->CountItems() - 1)->SetMarked(true);
}
}
else
{
BMenuItem *item;
fTypes->AddSeparatorItem();
fTypes->AddItem(item = new BMenuItem("<undefined>", new BMessage(msg_FieldChanged)));
item->SetMarked(true);
}
if (fDoc->EntryRef())
{
BNode node;
FailOSErr(node.SetTo(fDoc->EntryRef()));
time_t t;
node.GetModificationTime(&t);
char time[256];
strcpy(time, ctime(&t));
time[strlen(time) - 1] = 0;
SetText("time", time);
}
else
{
//SetEnabled("mime", false);
SetText("time", "Not Saved");
}
mf = dynamic_cast<BMenuField*>(FindView("font"));
FailNil(mf);
fMenu = mf->Menu();
FailNil(fMenu);
font_family ff;
font_style fs;
for (int i = 0; i < count_font_families(); i++)
{
get_font_family(i, &ff);
BMenu *fontItem = new BMenu(ff);
FailNil(fontItem);
fMenu->AddItem(new BMenuItem(fontItem, new BMessage(msg_FieldChanged)));
fontItem->SetFont(be_plain_font);
for (int j = 0; j < count_font_styles(ff); j++)
{
get_font_style(ff, j, &fs);
BMessage *msg = new BMessage(msg_FieldChanged);
msg->AddString("family", ff);
//.........这里部分代码省略.........
示例7: showContextMenu
void MediaNodePanel::showContextMenu(
BPoint point)
{
D_METHOD(("MediaNodePanel::showContextMenu()\n"));
BPopUpMenu *menu = new BPopUpMenu("MediaNodePanel PopUp", false, false, B_ITEMS_IN_COLUMN);
menu->SetFont(be_plain_font);
BMenuItem *item;
BMessage *message;
// add the "Tweak Parameters" item
message = new BMessage(MediaRoutingView::M_NODE_TWEAK_PARAMETERS);
menu->AddItem(item = new BMenuItem("Tweak parameters", message, 'P'));
if (!(ref->kind() & B_CONTROLLABLE))
{
item->SetEnabled(false);
}
message = new BMessage(InfoWindowManager::M_INFO_WINDOW_REQUESTED);
message->AddInt32("nodeID", ref->id());
menu->AddItem(new BMenuItem("Get info", message, 'I'));
menu->AddSeparatorItem();
menu->AddItem(item = new BMenuItem("Release", new BMessage(MediaRoutingView::M_DELETE_SELECTION), 'T'));
if (!ref->isInternal())
{
item->SetEnabled(false);
}
menu->AddSeparatorItem();
// add the "Cycle" item
message = new BMessage(MediaRoutingView::M_NODE_CHANGE_CYCLING);
message->AddBool("cycle", !ref->isCycling());
menu->AddItem(item = new BMenuItem("Cycle", message));
item->SetMarked(ref->isCycling());
if (ref->flags() & NodeRef::NO_SEEK)
{
item->SetEnabled(false);
}
// add the "Run Mode" sub menu
BMenu *subMenu = new BMenu("Run mode");
subMenu->SetFont(be_plain_font);
for (uint32 runMode = 1; runMode <= BMediaNode::B_RECORDING; runMode++)
{
BString itemName = MediaString::getStringFor(static_cast<BMediaNode::run_mode>
(runMode));
message = new BMessage(MediaRoutingView::M_NODE_CHANGE_RUN_MODE);
message->AddInt32("run_mode", runMode);
subMenu->AddItem(item = new BMenuItem(itemName.String(), message));
if (ref->runMode() == runMode)
{
item->SetMarked(true);
}
else if ((ref->runMode() == 0)
&& (ref->group()) && (ref->group()->runMode() == BMediaNode::run_mode(runMode)))
{
item->SetMarked(true);
}
}
subMenu->AddSeparatorItem();
message = new BMessage(MediaRoutingView::M_NODE_CHANGE_RUN_MODE);
message->AddInt32("run_mode", 0);
subMenu->AddItem(item = new BMenuItem("(same as group)", message));
if (ref->group() == 0)
{
item->SetEnabled(false);
}
else if ((ref->runMode() < 1) && (ref->group()->runMode() > 0))
{
item->SetMarked(true);
}
menu->AddItem(subMenu);
subMenu->SetTargetForItems(view());
// [c.lenz 24dec99] hide rarely used commands in a 'Advanced' submenu
subMenu = new BMenu("Advanced");
subMenu->SetFont(be_plain_font);
// [e.moon 5dec99] ad-hoc timesource support
if(ref->kind() & B_TIME_SOURCE) {
message = new BMessage(MediaRoutingView::M_NODE_START_TIME_SOURCE);
message->AddInt32("nodeID", ref->id());
subMenu->AddItem(new BMenuItem(
"Start time source",
message));
message = new BMessage(MediaRoutingView::M_NODE_START_TIME_SOURCE);
message->AddInt32("nodeID", ref->id());
subMenu->AddItem(new BMenuItem(
"Stop time source",
message));
}
// [c.lenz 24dec99] support for BControllable::StartControlPanel()
if(ref->kind() & B_CONTROLLABLE) {
if (subMenu->CountItems() > 0)
subMenu->AddSeparatorItem();
message = new BMessage(MediaRoutingView::M_NODE_START_CONTROL_PANEL);
subMenu->AddItem(new BMenuItem("Start Control Panel", message,
'P', B_COMMAND_KEY | B_SHIFT_KEY));
}
//.........这里部分代码省略.........
示例8: BMessage
bool
TDeskbarMenu::AddStandardDeskbarMenuItems()
{
bool dragging = false;
if (fBarView)
dragging = fBarView->Dragging();
BMenuItem* item;
// One of them is used if HAIKU_DISTRO_COMPATIBILITY_OFFICIAL, and the other if
// not. However, we want both of them to end up in the catalog, so we have to
// make them visible to collectcatkeys in either case.
B_TRANSLATE_MARK_VOID("About Haiku")
B_TRANSLATE_MARK_VOID("About this system")
item = new BMenuItem(
#ifdef HAIKU_DISTRO_COMPATIBILITY_OFFICIAL
B_TRANSLATE_NOCOLLECT("About Haiku")
#else
B_TRANSLATE_NOCOLLECT("About this system")
#endif
, new BMessage(kShowSplash));
item->SetEnabled(!dragging);
AddItem(item);
static const char* kFindMenuItemStr
= B_TRANSLATE_MARK("Find" B_UTF8_ELLIPSIS);
#ifdef SHOW_RECENT_FIND_ITEMS
item = new BMenuItem(
TrackerBuildRecentFindItemsMenu(kFindMenuItemStr),
new BMessage(kFindButton));
#else
item = new BMenuItem(B_TRANSLATE_NOCOLLECT(kFindMenuItemStr),
new BMessage(kFindButton));
#endif
item->SetEnabled(!dragging);
AddItem(item);
item = new BMenuItem(B_TRANSLATE("Show replicants"),
new BMessage(kToggleDraggers));
item->SetEnabled(!dragging);
item->SetMarked(BDragger::AreDraggersDrawn());
AddItem(item);
static const char* kMountMenuStr = B_TRANSLATE_MARK("Mount");
#ifdef MOUNT_MENU_IN_DESKBAR
DeskbarMountMenu* mountMenu = new DeskbarMountMenu(
B_TRANSLATE_NOCOLLECT(kMountMenuStr));
mountMenu->SetEnabled(!dragging);
AddItem(mountMenu);
#endif
item = new BMenuItem(B_TRANSLATE("Deskbar preferences" B_UTF8_ELLIPSIS),
new BMessage(kConfigShow));
item->SetTarget(be_app);
AddItem(item);
AddSeparatorItem();
BMenu* shutdownMenu = new BMenu(B_TRANSLATE("Shutdown" B_UTF8_ELLIPSIS));
item = new BMenuItem(B_TRANSLATE("Restart system"),
new BMessage(kRebootSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
B_TRANSLATE_MARK_VOID("Suspend");
#ifdef APM_SUPPORT
if (_kapm_control_(APM_CHECK_ENABLED) == B_OK) {
item = new BMenuItem(B_TRANSLATE_NOCOLLECT("Suspend"),
new BMessage(kSuspendSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
}
#endif
item = new BMenuItem(B_TRANSLATE("Power off"),
new BMessage(kShutdownSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
shutdownMenu->SetFont(be_plain_font);
shutdownMenu->SetTargetForItems(be_app);
BMessage* message = new BMessage(kShutdownSystem);
message->AddBool("confirm", true);
AddItem(new BMenuItem(shutdownMenu, message));
fAddState = kAddingRecents;
return true;
}
示例9: BMessage
bool
TBeMenu::AddStandardBeMenuItems()
{
bool dragging = false;
if (fBarView)
dragging = fBarView->Dragging();
BMenuItem* item = new BMenuItem(
#ifdef ANTARES_DISTRO_COMPATIBILITY_OFFICIAL
"About Antares"
#else
"About this system"
#endif
B_UTF8_ELLIPSIS, new BMessage(kShowSplash));
item->SetEnabled(!dragging);
AddItem(item);
#ifdef SHOW_RECENT_FIND_ITEMS
item = new BMenuItem(TrackerBuildRecentFindItemsMenu("Find"B_UTF8_ELLIPSIS),
new BMessage(kFindButton));
#else
item = new BMenuItem("Find"B_UTF8_ELLIPSIS, new BMessage(kFindButton));
#endif
item->SetEnabled(!dragging);
AddItem(item);
item = new BMenuItem("Show replicants", new BMessage(kToggleDraggers));
item->SetEnabled(!dragging);
item->SetMarked(BDragger::AreDraggersDrawn());
AddItem(item);
#ifdef MOUNT_MENU_IN_DESKBAR
DeskbarMountMenu* mountMenu = new DeskbarMountMenu("Mount");
mountMenu->SetEnabled(!dragging);
AddItem(mountMenu);
#endif
item = new BMenuItem("Deskbar preferences" B_UTF8_ELLIPSIS,
new BMessage(kConfigShow));
item->SetTarget(be_app);
AddItem(item);
AddSeparatorItem();
BMenu* shutdownMenu = new BMenu("Shutdown" B_UTF8_ELLIPSIS);
item = new BMenuItem("Restart system", new BMessage(kRebootSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
#ifdef APM_SUPPORT
if (_kapm_control_(APM_CHECK_ENABLED) == B_OK) {
item = new BMenuItem("Suspend", new BMessage(kSuspendSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
}
#endif
item = new BMenuItem("Power off", new BMessage(kShutdownSystem));
item->SetEnabled(!dragging);
shutdownMenu->AddItem(item);
shutdownMenu->SetFont(be_plain_font);
shutdownMenu->SetTargetForItems(be_app);
BMessage* message = new BMessage(kShutdownSystem);
message->AddBool("confirm", true);
AddItem(new BMenuItem(shutdownMenu, message));
fAddState = kAddingRecents;
return true;
}
示例10: BMessage
void
PadView::DisplayMenu(BPoint where, LaunchButton* button) const
{
MainWindow* window = dynamic_cast<MainWindow*>(Window());
if (window == NULL)
return;
LaunchButton* nearestButton = button;
if (!nearestButton) {
// find the nearest button
for (int32 i = 0; (nearestButton = ButtonAt(i)); i++) {
if (nearestButton->Frame().top > where.y)
break;
}
}
BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("launch popup"), false, false);
// add button
BMessage* message = new BMessage(MSG_ADD_SLOT);
message->AddPointer("be:source", (void*)nearestButton);
BMenuItem* item = new BMenuItem(B_TRANSLATE("Add button here"), message);
item->SetTarget(window);
menu->AddItem(item);
// button options
if (button) {
// clear button
message = new BMessage(MSG_CLEAR_SLOT);
message->AddPointer("be:source", (void*)button);
item = new BMenuItem(B_TRANSLATE("Clear button"), message);
item->SetTarget(window);
menu->AddItem(item);
// remove button
message = new BMessage(MSG_REMOVE_SLOT);
message->AddPointer("be:source", (void*)button);
item = new BMenuItem(B_TRANSLATE("Remove button"), message);
item->SetTarget(window);
menu->AddItem(item);
// Open containing folder button
if (button->Ref() != NULL) {
message = new BMessage(MSG_OPEN_CONTAINING_FOLDER);
message->AddPointer("be:source", (void*)button);
item = new BMenuItem(B_TRANSLATE("Open containing folder"), message);
item->SetTarget(window);
menu->AddItem(item);
}
// set button description
if (button->Ref()) {
message = new BMessage(MSG_SET_DESCRIPTION);
message->AddPointer("be:source", (void*)button);
item = new BMenuItem(B_TRANSLATE("Set description"B_UTF8_ELLIPSIS),
message);
item->SetTarget(window);
menu->AddItem(item);
}
}
menu->AddSeparatorItem();
// window settings
BMenu* settingsM = new BMenu(B_TRANSLATE("Settings"));
settingsM->SetFont(be_plain_font);
const char* toggleLayoutLabel;
if (fButtonLayout->Orientation() == B_HORIZONTAL)
toggleLayoutLabel = B_TRANSLATE("Vertical layout");
else
toggleLayoutLabel = B_TRANSLATE("Horizontal layout");
item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT));
item->SetTarget(this);
settingsM->AddItem(item);
BMenu* iconSizeM = new BMenu(B_TRANSLATE("Icon size"));
for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) {
uint32 iconSize = kIconSizes[i];
message = new BMessage(MSG_SET_ICON_SIZE);
message->AddInt32("size", iconSize);
BString label;
label << iconSize << " x " << iconSize;
item = new BMenuItem(label.String(), message);
item->SetTarget(this);
item->SetMarked(IconSize() == iconSize);
iconSizeM->AddItem(item);
}
settingsM->AddItem(iconSizeM);
item = new BMenuItem(B_TRANSLATE("Ignore double-click"),
new BMessage(MSG_SET_IGNORE_DOUBLECLICK));
item->SetTarget(this);
item->SetMarked(IgnoreDoubleClick());
settingsM->AddItem(item);
uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER;
item = new BMenuItem(B_TRANSLATE("Show window border"), new BMessage(what));
item->SetTarget(window);
item->SetMarked(what == MSG_HIDE_BORDER);
settingsM->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Auto-raise"), new BMessage(MSG_TOGGLE_AUTORAISE));
item->SetTarget(window);
item->SetMarked(window->AutoRaise());
settingsM->AddItem(item);
item = new BMenuItem(B_TRANSLATE("Show on all workspaces"), new BMessage(MSG_SHOW_ON_ALL_WORKSPACES));
//.........这里部分代码省略.........
示例11: CountItems
void
QPopupMenu::EntryCreated(const entry_ref &ref, ino_t node)
{
BNode file;
if (file.SetTo(&ref) < B_OK)
return;
// Make sure the pop-up menu is ready for additions. Need a bunch of
// groups at the top, a divider line, and miscellaneous people added below
// the line.
int32 items = CountItems();
if (!items)
AddSeparatorItem();
// Does the file have a group attribute? OK to have none.
BString groups;
const char *kNoGroup = "NoGroup!";
file.ReadAttrString("META:group", &groups);
if (groups.Length() <= 0)
groups = kNoGroup;
// Add the e-mail address to the all people group. Then add it to all the
// group menus that it exists in (based on the comma separated list of
// groups from the People file), optionally making the group menu if it
// doesn't exist. If it's in the special NoGroup! list, then add it below
// the groups.
bool allPeopleGroupDone = false;
BMenu *groupMenu;
do {
BString group;
if (!allPeopleGroupDone) {
// Create the default group for all people, if it doesn't exist yet.
group = "All People";
allPeopleGroupDone = true;
} else {
// Break out the next group from the comma separated string.
int32 comma;
if ((comma = groups.FindFirst(',')) > 0) {
groups.MoveInto(group, 0, comma);
groups.Remove(0, 1);
} else
group.Adopt(groups);
}
// trim white spaces
int32 i = 0;
for (i = 0; isspace(group.ByteAt(i)); i++) {}
if (i)
group.Remove(0, i);
for (i = group.Length() - 1; isspace(group.ByteAt(i)); i--) {}
group.Truncate(i + 1);
groupMenu = NULL;
BMenuItem *superItem = NULL; // Corresponding item for group menu.
if (group.Length() > 0 && group != kNoGroup) {
BMenu *sub;
// Look for submenu with label == group name
for (int32 i = 0; i < items; i++) {
if ((sub = SubmenuAt(i)) != NULL) {
superItem = sub->Superitem();
if (!strcmp(superItem->Label(), group.String())) {
groupMenu = sub;
i++;
break;
}
}
}
// If no submenu, create one
if (!groupMenu) {
// Find where it should go (alphabetical)
int32 mindex = 0;
for (; mindex < fGroups; mindex++) {
if (strcmp(ItemAt(mindex)->Label(), group.String()) > 0)
break;
}
groupMenu = new BMenu(group.String());
groupMenu->SetFont(be_plain_font);
AddItem(groupMenu, mindex);
superItem = groupMenu->Superitem();
superItem->SetMessage(new BMessage(B_SIMPLE_DATA));
if (fTargetHandler)
superItem->SetTarget(fTargetHandler);
fGroups++;
}
}
BString name;
file.ReadAttrString("META:name", &name);
BString email;
file.ReadAttrString("META:email", &email);
//.........这里部分代码省略.........
示例12: BMenu
void
FontSelectionView::UpdateFontsMenu()
{
int32 numFamilies = count_font_families();
fFontsMenu->RemoveItems(0, fFontsMenu->CountItems(), true);
BFont font;
fFontsMenu->GetFont(&font);
font_family currentFamily;
font_style currentStyle;
fCurrentFont.GetFamilyAndStyle(¤tFamily, ¤tStyle);
for (int32 i = 0; i < numFamilies; i++) {
font_family family;
uint32 flags;
if (get_font_family(i, &family, &flags) != B_OK)
continue;
// if we're setting the fixed font, we only want to show fixed and
// full-and-half-fixed fonts
if (strcmp(Name(), "fixed") == 0
&& (flags
& (B_IS_FIXED | B_PRIVATE_FONT_IS_FULL_AND_HALF_FIXED)) == 0) {
continue;
}
float width = font.StringWidth(family);
if (width > fMaxFontNameWidth)
fMaxFontNameWidth = width;
BMenu* stylesMenu = new BMenu(family);
stylesMenu->SetRadioMode(true);
stylesMenu->SetFont(&font);
BMessage* message = new BMessage(kMsgSetFamily);
message->AddString("family", family);
message->AddString("name", Name());
BMenuItem* familyItem = new BMenuItem(stylesMenu, message);
fFontsMenu->AddItem(familyItem);
int32 numStyles = count_font_styles(family);
for (int32 j = 0; j < numStyles; j++) {
font_style style;
if (get_font_style(family, j, &style, &flags) != B_OK)
continue;
message = new BMessage(kMsgSetStyle);
message->AddString("family", (char*)family);
message->AddString("style", (char*)style);
message->AddString("name", Name());
BMenuItem* item = new BMenuItem(style, message);
if (!strcmp(style, currentStyle)
&& !strcmp(family, currentFamily)) {
item->SetMarked(true);
familyItem->SetMarked(true);
}
stylesMenu->AddItem(item);
}
stylesMenu->SetTargetForItems(fMessageTarget);
}
fFontsMenu->SetTargetForItems(fMessageTarget);
}
示例13: MemoryBarMenuItem
status_t
thread_popup(void *arg)
{
Tpopup_param* param = (Tpopup_param*) arg;
int32 mcookie, hcookie;
unsigned long m;
long h;
BMenuItem* item;
bool top = param->top;
system_info systemInfo;
get_system_info(&systemInfo);
info_pack* infos = new info_pack[systemInfo.used_teams];
// TODO: this doesn't necessarily get all teams
for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
infos[m].team_icon = NULL;
infos[m].team_name[0] = 0;
infos[m].thread_info = NULL;
if (get_next_team_info(&mcookie, &infos[m].team_info) == B_OK) {
infos[m].thread_info = new thread_info[infos[m].team_info.thread_count];
for (h = 0, hcookie = 0; h < infos[m].team_info.thread_count; h++) {
if (get_next_thread_info(infos[m].team_info.team, &hcookie,
&infos[m].thread_info[h]) != B_OK)
infos[m].thread_info[h].thread = -1;
}
get_team_name_and_icon(infos[m], true);
} else {
systemInfo.used_teams = m;
infos[m].team_info.team = -1;
}
}
BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
popup->SetFont(be_plain_font);
// Quit section
BMenu* QuitPopup = new QuitMenu(B_TRANSLATE("Quit an application"),
infos, systemInfo.used_teams);
QuitPopup->SetFont(be_plain_font);
popup->AddItem(QuitPopup);
// Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu(B_TRANSLATE("Memory usage"),
infos, systemInfo);
int64 committedMemory = (int64)systemInfo.used_pages * B_PAGE_SIZE / 1024;
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
MemoryBarMenuItem* memoryItem =
new MemoryBarMenuItem(infos[m].team_name,
infos[m].team_info.team, infos[m].team_icon, false, NULL);
MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(committedMemory);
}
}
addtopbottom(MemoryPopup);
// CPU Load section
TeamBarMenu* CPUPopup = new TeamBarMenu(B_TRANSLATE("Threads and CPU "
"usage"), infos, systemInfo.used_teams);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].team_name,
infos[m].team_info.team, infos[m].team_info.thread_count);
BMessage* kill_team = new BMessage('KlTm');
kill_team->AddInt32("team", infos[m].team_info.team);
TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team,
infos[m].team_info.team, infos[m].team_icon, false);
item->SetTarget(gPCView);
CPUPopup->AddItem(item);
}
}
addtopbottom(CPUPopup);
addtopbottom(new BSeparatorItem());
// CPU on/off section
if (gCPUcount > 1) {
for (unsigned int i = 0; i < gCPUcount; i++) {
char item_name[32];
sprintf (item_name, B_TRANSLATE("Processor %d"), i + 1);
BMessage* m = new BMessage ('CPU ');
m->AddInt32 ("cpu", i);
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
if (_kern_cpu_enabled(i))
item->SetMarked (true);
item->SetTarget(gPCView);
addtopbottom(item);
}
addtopbottom (new BSeparatorItem ());
}
// Scheduler modes
static const char* schedulerModes[] = { B_TRANSLATE_MARK("Low latency"),
B_TRANSLATE_MARK("Power saving") };
unsigned int modesCount = sizeof(schedulerModes) / sizeof(const char*);
int32 currentMode = get_scheduler_mode();
for (unsigned int i = 0; i < modesCount; i++) {
BMessage* m = new BMessage('Schd');
m->AddInt32("mode", i);
//.........这里部分代码省略.........
示例14: MemoryBarMenuItem
long
thread_popup(void *arg)
{
Tpopup_param* param = (Tpopup_param*) arg;
int32 mcookie, hcookie;
long m, h;
BMenuItem* item;
bool top = param->top;
system_info systemInfo;
get_system_info(&systemInfo);
info_pack* infos = new info_pack[systemInfo.used_teams];
// TODO: this doesn't necessarily get all teams
for (m = 0, mcookie = 0; m < systemInfo.used_teams; m++) {
infos[m].team_icon = NULL;
infos[m].team_name[0] = 0;
infos[m].thread_info = NULL;
if (get_next_team_info(&mcookie, &infos[m].team_info) == B_OK) {
infos[m].thread_info = new thread_info[infos[m].team_info.thread_count];
for (h = 0, hcookie = 0; h < infos[m].team_info.thread_count; h++) {
if (get_next_thread_info(infos[m].team_info.team, &hcookie,
&infos[m].thread_info[h]) != B_OK)
infos[m].thread_info[h].thread = -1;
}
get_team_name_and_icon(infos[m], true);
} else {
systemInfo.used_teams = m;
infos[m].team_info.team = -1;
}
}
BPopUpMenu* popup = new BPopUpMenu("Global Popup", false, false);
popup->SetFont(be_plain_font);
// Quit section
BMenu* QuitPopup = new QuitMenu(B_TRANSLATE("Quit an application"),
infos, systemInfo.used_teams);
QuitPopup->SetFont(be_plain_font);
popup->AddItem(QuitPopup);
// Memory Usage section
MemoryBarMenu* MemoryPopup = new MemoryBarMenu(B_TRANSLATE("Memory usage"),
infos, systemInfo);
int commitedMemory = int(systemInfo.used_pages * B_PAGE_SIZE / 1024);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
MemoryBarMenuItem* memoryItem =
new MemoryBarMenuItem(infos[m].team_name,
infos[m].team_info.team, infos[m].team_icon, false, NULL);
MemoryPopup->AddItem(memoryItem);
memoryItem->UpdateSituation(commitedMemory);
}
}
addtopbottom(MemoryPopup);
// CPU Load section
TeamBarMenu* CPUPopup = new TeamBarMenu(B_TRANSLATE("Threads and CPU "
"usage"), infos, systemInfo.used_teams);
for (m = 0; m < systemInfo.used_teams; m++) {
if (infos[m].team_info.team >= 0) {
ThreadBarMenu* TeamPopup = new ThreadBarMenu(infos[m].team_name,
infos[m].team_info.team, infos[m].team_info.thread_count);
BMessage* kill_team = new BMessage('KlTm');
kill_team->AddInt32("team", infos[m].team_info.team);
TeamBarMenuItem* item = new TeamBarMenuItem(TeamPopup, kill_team,
infos[m].team_info.team, infos[m].team_icon, false);
item->SetTarget(gPCView);
CPUPopup->AddItem(item);
}
}
addtopbottom(CPUPopup);
addtopbottom(new BSeparatorItem());
// CPU on/off section
if (gCPUcount > 1) {
for (int i = 0; i < gCPUcount; i++) {
char item_name[32];
sprintf (item_name, B_TRANSLATE("Processor %d"), i + 1);
BMessage* m = new BMessage ('CPU ');
m->AddInt32 ("cpu", i);
item = new IconMenuItem (gPCView->fProcessorIcon, item_name, m);
if (_kern_cpu_enabled(i))
item->SetMarked (true);
item->SetTarget(gPCView);
addtopbottom(item);
}
addtopbottom (new BSeparatorItem ());
}
if (!be_roster->IsRunning(kTrackerSig)) {
item = new IconMenuItem(gPCView->fTrackerIcon,
B_TRANSLATE("Restart Tracker"), new BMessage('Trac'));
item->SetTarget(gPCView);
addtopbottom(item);
}
if (!be_roster->IsRunning(kDeskbarSig)) {
item = new IconMenuItem(gPCView->fDeskbarIcon,
B_TRANSLATE("Restart Deskbar"), new BMessage('Dbar'));
//.........这里部分代码省略.........