// PopulateMenu void FontValueView::_PolulateMenu(BMenu* menu, BHandler* target, const char* markedFamily, const char* markedStyle) { if (!menu) return; FontManager* manager = FontManager::Default(); if (!manager->Lock()) return; BMenu* fontMenu = NULL; font_family family; font_style style; int32 count = manager->CountFontFiles(); for (int32 i = 0; i < count; i++) { if (!manager->GetFontAt(i, family, style)) break; BMessage* message = new BMessage(MSG_FONT_CHANGED); message->AddString("font family", family); message->AddString("font style", style); FontMenuItem* item = new FontMenuItem(style, family, style, message); item->SetTarget(target); bool markStyle = false; if (!fontMenu || (fontMenu->Name() && strcmp(fontMenu->Name(), family) != 0)) { // create new entry fontMenu = new BMenu(family); fontMenu->AddItem(item); menu->AddItem(fontMenu); // mark the menu if necessary if (markedFamily && strcmp(markedFamily, family) == 0) { if (BMenuItem* superItem = fontMenu->Superitem()) superItem->SetMarked(true); markStyle = true; } } else { // reuse old entry fontMenu->AddItem(item); } // mark the item if necessary if (markStyle && markedStyle && strcmp(markedStyle, style) == 0) item->SetMarked(true); } manager->Unlock(); }
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); }
void BYdpMainWindow::MessageReceived(BMessage *Message) { int item; this->DisableUpdates(); switch (Message->what) { case MSG_MODIFIED_INPUT: HandleModifiedInput(false); break; case MSG_LIST_INVOKED: item = dictList->CurrentSelection(0); wordInput->SetText(((BStringItem*)dictList->ItemAt(item))->Text()); break; case MSG_LIST_SELECTED: item = dictList->CurrentSelection(0); if (item>dictList->CountItems()) item = dictList->CountItems(); if (item>=0) myDict->GetDefinition(myDict->wordPairs[item+dictList->topIndex]); break; case MSG_LISTUP: case MSG_LISTDOWN: // printf("got listup\n"); myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); break; // case MSG_LISTDOWN: // printf("got listdown\n"); // myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); // break; case MSG_CLEAR_INPUT: wordInput->SetText(""); wordInput->MakeFocus(); break; case MENU_ENG2POL: UpdateLanguages(true); break; case MENU_POL2ENG: UpdateLanguages(false); break; case MENU_SWITCH: UpdateLanguages(!config->toPolish); break; case MENU_FUZZY: config->searchmode = SEARCH_FUZZY; config->save(); HandleModifiedInput(true); UpdateMenus(); break; case MENU_PLAIN: config->searchmode = SEARCH_BEGINS; config->save(); HandleModifiedInput(true); UpdateMenus(); break; /* case MENU_ENGINESQ2: SwitchEngine(DICTIONARY_SQ2); break; */ case MENU_ENGINESAP: SwitchEngine(DICTIONARY_SAP); break; case MENU_ENGINEYDP: SwitchEngine(DICTIONARY_YDP); break; case MENU_PATH: ConfigPath(); break; case MENU_COLOR0: ConfigColour(0); break; case MENU_COLOR1: ConfigColour(1); break; case MENU_COLOR2: ConfigColour(2); break; case MENU_COLOR3: ConfigColour(3); break; case MENU_CLIP: config->clipboardTracking = !config->clipboardTracking; config->save(); UpdateMenus(); break; case MENU_FOCUS: config->setFocusOnSelf = !config->setFocusOnSelf; config->save(); UpdateMenus(); break; case MENU_DISTANCE: ConfigDistance(); break; /* case MENU_SQL: ConfigSQLTables(); break; */ case MENU_ABOUT: { BString about; about = "\n\n" APP_NAME " " APP_VERSION "\n"; about += "English-Polish, Polish-English dictionary\n"; about += "\n\nBeOS version:\n"; about += "Maciej Witkowiak <*****@*****.**>"; about += "\n\nSAP engine based on sap v0.2b\n"; about += "(c) 1998 Bohdan R. Rau,\n(c) 2001 Daniel Mealha Cabrita"; about += "\nYDP and SQL engines by Maciej Witkowiak\n"; about += "\n\nSoftware released under GNU/GPL license"; about += "\n\nvisit:\n"; about += "http://home.elysium.pl/ytm/html/beos.html\n"; about += "\nDevelopment has been encouraged by:\n"; about += "http://www.haiku-os.pl"; outputView->SetText(about.String()); } break; case FONT_SIZE: { float fontSize; Message->FindFloat("size",&fontSize); SetFontSize(fontSize); } break; case FONT_FAMILY: { const char * fontFamily = 0, * fontStyle = 0; void * ptr; if (Message->FindPointer("source",&ptr) == B_OK) { currentFontItem = static_cast<BMenuItem*>(ptr); fontFamily = currentFontItem->Label(); } SetFontStyle(fontFamily, fontStyle); } case FONT_STYLE: { const char * fontFamily = 0, * fontStyle = 0; void * ptr; if (Message->FindPointer("source",&ptr) == B_OK) { BMenuItem * item = static_cast<BMenuItem*>(ptr); fontStyle = item->Label(); BMenu * menu = item->Menu(); if (menu != 0) { currentFontItem = menu->Superitem(); if (currentFontItem != 0) { fontFamily = currentFontItem->Label(); } } } SetFontStyle(fontFamily, fontStyle); } case MSG_SCROLL: // printf("scroll value changed\n"); if (scrollBar->Value() != dictList->topIndex) { dictList->ListScrolled(scrollBar->Value()); myDict->GetDefinition(myDict->wordPairs[dictList->topIndex+dictList->CurrentSelection(0)]); } break; case MSG_COLOURUPDATE: // printf("colour update\n"); myDict->ReGetDefinition(); break; case MSG_FUZZYUPDATE: // printf("fuzzy update\n"); if (config->searchmode == SEARCH_FUZZY) HandleModifiedInput(true); break; /* case MSG_SQLTABLESUPDATE: // printf("sql tables updated\n"); myDict->FlushCache(); SwitchEngine(config->dictionarymode); break; */ case B_CLIPBOARD_CHANGED: NewClipData(); break; case B_REFS_RECEIVED: RefsReceived(Message); break; case B_CANCEL: // printf("canceled\n"); if (firstStart) { config->dictionarymode = DICTIONARY_SAP; // will be saved in QuitRequested below BAlert *alert = new BAlert(APP_NAME, "Couldn't open dictionary. Dictionary engine has been reset to SAP.", "OK", NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->Go(); QuitRequested(); } else delete myPanel; // break; default: BWindow::MessageReceived(Message); break; } this->EnableUpdates(); }