BPopUpMenu* TPrefsWindow::_BuildFontMenu(BFont* font) { font_family def_family; font_style def_style; font_family f_family; font_style f_style; BPopUpMenu *menu = new BPopUpMenu(""); font->GetFamilyAndStyle(&def_family, &def_style); int32 family_menu_index = 0; int family_count = count_font_families(); for (int family_loop = 0; family_loop < family_count; family_loop++) { get_font_family(family_loop, &f_family); BMenu *family_menu = new BMenu(f_family); int style_count = count_font_styles(f_family); for (int style_loop = 0; style_loop < style_count; style_loop++) { get_font_style(f_family, style_loop, &f_style); BMessage *msg = new BMessage(P_FONT); msg->AddString("font", f_family); msg->AddString("style", f_style); // we send this to make setting the Family easier when things // change msg->AddInt32("parent_index", family_menu_index); BMenuItem *item = new BMenuItem(f_style, msg); family_menu->AddItem(item); if ((strcmp(def_family, f_family) == 0) && (strcmp(def_style, f_style) == 0)) { item->SetMarked(true); } item->SetTarget(this); } menu->AddItem(family_menu); BMenuItem *item = menu->ItemAt(family_menu_index); BMessage *msg = new BMessage(P_FONT); msg->AddString("font", f_family); item->SetMessage(msg); item->SetTarget(this); if (strcmp(def_family, f_family) == 0) item->SetMarked(true); family_menu_index++; } return menu; }
void AccountView::AttachedToWindow() { // Once we are attached to window, the GUI is already created // so we can set our window as target for messages for (int32 i = 0; i < CountChildren(); i++) { BView* child = ChildAt(i); BMenu* menu = dynamic_cast<BMenu*>(child); BMenuField* menuField = dynamic_cast<BMenuField*>(child); BTextControl* textControl = dynamic_cast<BTextControl*>(child); NotifyingTextView* textView = dynamic_cast<NotifyingTextView*>(child); BCheckBox* checkBox = dynamic_cast<BCheckBox*>(child); if (menuField) menu = menuField->Menu(); if (menu) { for (int32 j = 0; j < menu->CountItems(); j++) { BMenuItem* item = menu->ItemAt(j); item->SetMessage(new BMessage(kChanged)); item->SetTarget(Window()); } menu->SetTargetForItems(Window()); } if (textControl) { textControl->SetMessage(new BMessage(kChanged)); textControl->SetTarget(Window()); } if (checkBox) { checkBox->SetMessage(new BMessage(kChanged)); checkBox->SetTarget(Window()); } if (textView) { textView->SetMessage(new BMessage(kChanged)); textView->SetTarget(Window()); } } }
void BNavMenu::AddNavParentDir(const char *name,const Model *model,uint32 what,BHandler *target) { BNavMenu *menu = new BNavMenu(name,what,target); menu->SetNavDir(model->EntryRef()); menu->SetShowParent(true); menu->InitTrackingHook(fTrackingHook.fTrackingHook, &(fTrackingHook.fTarget), fTrackingHook.fDragMessage); BMenuItem *item = new SpecialModelMenuItem(model,menu); BMessage *message = new BMessage(what); message->AddRef("refs",model->EntryRef()); item->SetMessage(message); AddItem(item); }
status_t PMenuItem::SetProperty(const char *name, PValue *value, const int32 &index) { if (!name || !value) return B_ERROR; BString str(name); PProperty *prop = FindProperty(name,index); if (!prop) return B_NAME_NOT_FOUND; if (FlagsForProperty(prop) & PROPERTY_READ_ONLY) return B_READ_ONLY; BMenuItem *backend = (BMenuItem*)fBackend; BoolValue boolval; CharValue charval; ColorValue colorval; FloatValue floatval; IntValue intval; PointValue pointval; RectValue rectval; StringValue stringval; status_t status = prop->SetValue(value); if (status != B_OK) return status; if (str.ICompare("Message") == 0) { prop->GetValue(&intval); backend->SetMessage(new BMessage(*intval.value)); } else if (str.ICompare("Trigger") == 0) { prop->GetValue(&charval); backend->SetTrigger(*charval.value); } else if (str.ICompare("Label") == 0) { prop->GetValue(&stringval); backend->SetLabel(*stringval.value); } else if (str.ICompare("Marked") == 0) { prop->GetValue(&boolval); backend->SetMarked(*boolval.value); } else if (str.ICompare("Enabled") == 0) { prop->GetValue(&boolval); backend->SetEnabled(*boolval.value); } else { return PObject::SetProperty(name, value, index); } return prop->GetValue(value); }
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); if (email.Length() != 0 || name.Length() != 0) AddPersonItem(&ref, node, name, email, NULL, groupMenu, superItem); // support for 3rd-party People apps for (int16 i = 2; i < 6; i++) { char attr[16]; sprintf(attr, "META:email%d", i); if (file.ReadAttrString(attr, &email) >= B_OK && email.Length() > 0) AddPersonItem(&ref, node, name, email, attr, groupMenu, superItem); } } while (groups.Length() > 0); }