DialogItemEx *DialogBuilder::AddListControl(FARDIALOGITEMTYPES Type, IntOption& Value, string *Text, int Width, int Height, const std::vector<FarDialogBuilderListItem2> &Items, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(Type, Text ? Text->c_str() : L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Y2 = Item->Y1 + Height; Item->Flags |= DIF_DROPDOWNLIST|Flags; m_NextY += Height; const auto ListItems = new FarListItem[Items.size()]; std::transform(ALL_CONST_RANGE(Items), ListItems, [&Value](const auto& i) { FarListItem NewItem = {}; NewItem.Text = i.Text.c_str(); NewItem.Flags = i.Flags | ((Value == i.ItemValue)? LIF_SELECTED : 0); NewItem.UserData = i.ItemValue; return NewItem; }); const auto List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = Items.size(); Item->ListItems = List; SetLastItemBinding(new FarListControlBinding<IntOption>(Value, Text, List)); return Item; }
DialogItemEx *DialogBuilder::AddListControl(FARDIALOGITEMTYPES Type, IntOption& Value, string *Text, int Width, int Height, const FarDialogBuilderListItem *Items, size_t ItemCount, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(Type, Text ? Text->c_str() : L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Y2 = Item->Y1 + Height; Item->Flags |= Flags; m_NextY += Height; const auto ListItems = Items? new FarListItem[ItemCount] : nullptr; if (Items) { std::transform(Items, Items + ItemCount, ListItems, [&Value](const auto& i) { FarListItem NewItem = {}; NewItem.Text = msg(static_cast<lng>(i.MessageId)).c_str(); NewItem.Flags = (Value == i.ItemValue)? LIF_SELECTED : 0; NewItem.UserData = i.ItemValue; return NewItem; }); } const auto List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = ItemCount; Item->ListItems = List; SetLastItemBinding(new FarListControlBinding<IntOption>(Value, Text, List)); return Item; }
FarDialogItem *AddListControl(FARDIALOGITEMTYPES Type, int *SelectedItem, wchar_t *Text, int Width, int Height, const wchar_t* ItemsText [], size_t ItemCount, FARDIALOGITEMFLAGS ItemFlags) { FarDialogItem *Item = AddDialogItem(Type, Text ? Text : L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Y2 = Item->Y2 + Height; Item->Flags |= ItemFlags; m_NextY += Height; FarListItem *ListItems = nullptr; if (ItemsText) { ListItems = new FarListItem[ItemCount]; for(size_t i=0; i<ItemCount; i++) { ListItems[i].Text = ItemsText[i]; ListItems[i].Flags = SelectedItem && (*SelectedItem == static_cast<int>(i)) ? LIF_SELECTED : 0; } } FarList *List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = ListItems ? ItemCount : 0; Item->ListItems = List; SetLastItemBinding(new PluginListControlBinding(Info, &DialogHandle, m_DialogItemsCount - 1, SelectedItem, Text, List)); return Item; }
DialogItemEx *DialogBuilder::AddListControl(FARDIALOGITEMTYPES Type, int& Value, string *Text, int Width, int Height, const DialogBuilderListItem *Items, size_t ItemCount, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(Type, Text ? Text->data() : L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Y2 = Item->Y1 + Height; Item->Flags |= Flags; m_NextY += Height; const auto ListItems = Items? new FarListItem[ItemCount] : nullptr; if (Items) { std::transform(Items, Items + ItemCount, ListItems, [&Value](const DialogBuilderListItem& Item) -> FarListItem { FarListItem NewItem = {}; NewItem.Text = MSG(static_cast<LNGID>(Item.MessageId)); NewItem.Flags = (Value == Item.ItemValue)? LIF_SELECTED : 0; NewItem.Reserved[0] = Item.ItemValue; return NewItem; }); } const auto List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = ItemCount; Item->ListItems = List; SetLastItemBinding(new ListControlBinding<DialogItemEx>(Value, Text, List)); return Item; }
DialogItemEx *DialogBuilder::AddComboBox(IntOption& Value, int Width, const std::vector<DialogBuilderListItem2> &Items, FARDIALOGITEMFLAGS Flags) { DialogItemEx *Item = AddDialogItem(DI_COMBOBOX, L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Flags |= DIF_DROPDOWNLIST|Flags; size_t ItemsCount = Items.size(); FarListItem *ListItems = new FarListItem[ItemsCount]; for(size_t i=0; i<ItemsCount; i++) { ListItems[i].Text = Items[i].Text.data(); ListItems[i].Flags = (Value == Items[i].ItemValue) ? LIF_SELECTED : 0; ListItems[i].Reserved[0] = Items[i].ItemValue; ListItems[i].Flags |= Items[i].Flags; } FarList *List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = ItemsCount; Item->ListItems = List; SetLastItemBinding(new FarComboBoxBinding<IntOption>(Value, List)); return Item; }
DialogItemEx *DialogBuilder::AddComboBox(IntOption& Value, int Width, const DialogBuilderListItem *Items, size_t ItemCount, FARDIALOGITEMFLAGS Flags) { DialogItemEx *Item = AddDialogItem(DI_COMBOBOX, L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Flags |= Flags; FarListItem *ListItems = new FarListItem[ItemCount]; for(size_t i=0; i<ItemCount; i++) { ListItems [i].Text = MSG(static_cast<LNGID>(Items[i].MessageId)); ListItems [i].Flags = (Value == Items [i].ItemValue) ? LIF_SELECTED : 0; ListItems [i].Reserved [0] = Items [i].ItemValue; } FarList *List = new FarList; List->StructSize = sizeof(FarList); List->Items = ListItems; List->ItemsNumber = ItemCount; Item->ListItems = List; SetLastItemBinding(new FarComboBoxBinding<IntOption>(Value, List)); return Item; }
DialogItemEx *DialogBuilder::AddConstEditField(const string& Value, int Width, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(DI_EDIT, Value.c_str()); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Flags |= Flags|DIF_READONLY; return Item; }
DialogItemEx *DialogBuilder::AddCheckbox(const wchar_t* Caption, BoolOption& Value) { const auto Item = AddDialogItem(DI_CHECKBOX, Caption); SetNextY(Item); Item->X2 = Item->X1 + ItemWidth(*Item); Item->Selected = Value; SetLastItemBinding(CreateCheckBoxBinding(Value)); return Item; }
FarDialogItem *AddPasswordField(wchar_t *Value, int MaxSize, int Width) { FarDialogItem *Item = AddDialogItem(DI_PSWEDIT, Value); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; SetLastItemBinding(new PluginEditFieldBinding(Info, &DialogHandle, m_DialogItemsCount-1, Value, MaxSize)); return Item; }
DialogItemEx *DialogBuilder::AddCheckbox(lng TextMessageId, Bool3Option& Value) { const auto Item = AddDialogItem(DI_CHECKBOX, GetLangString(TextMessageId)); Item->Flags |= DIF_3STATE; SetNextY(Item); Item->X2 = Item->X1 + ItemWidth(*Item); Item->Selected = Value; SetLastItemBinding(CreateCheckBoxBinding(Value)); return Item; }
DialogItemEx *DialogBuilder::AddHexEditField(IntOption& Value, int Width) { const auto Item = AddDialogItem(DI_FIXEDIT, L""); Item->strData = format(L"{0:016X}"sv, as_unsigned(Value.Get())); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; const auto Binding = new EditFieldHexBinding<IntOption>(&Value); SetLastItemBinding(Binding); Item->Flags |= DIF_MASKEDIT; Item->strMask = Binding->GetMask(); return Item; }
virtual FarDialogItem *AddUIntEditField(unsigned int *Value, int Width) { FarDialogItem *Item = AddDialogItem(DI_FIXEDIT, L""); Item->Flags |= DIF_MASKEDIT; PluginUIntEditFieldBinding *Binding; Binding = new PluginUIntEditFieldBinding(Info, &DialogHandle, m_DialogItemsCount-1, Value, Width); Item->Data = Binding->GetBuffer(); Item->Mask = Binding->GetMask(); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; SetLastItemBinding(Binding); return Item; }
DialogItemEx *DialogBuilder::AddIntEditField(IntOption& Value, int Width) { const auto Item = AddDialogItem(DI_FIXEDIT, L""); Item->strData = str(Value.Get()); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; const auto Binding = new EditFieldIntBinding<IntOption>(&Value, Width); SetLastItemBinding(Binding); Item->Flags |= DIF_MASKEDIT; Item->strMask = Binding->GetMask(); return Item; }
DialogItemEx *DialogBuilder::AddIntEditField(int *Value, int Width) { DialogItemEx *Item = AddDialogItem(DI_FIXEDIT, L""); Item->strData = std::to_wstring(*Value); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; auto *Binding = new EditFieldIntBinding<int>(Value, Width); SetLastItemBinding(Binding); Item->Flags |= DIF_MASKEDIT; Item->strMask = Binding->GetMask(); return Item; }
DialogItemEx *DialogBuilder::AddFixEditField(string *Value, int Width, const wchar_t *Mask) { DialogItemEx *Item = AddDialogItem(DI_FIXEDIT, Value->data()); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; if (Mask) { Item->Mask = Mask; Item->Flags |= DIF_MASKEDIT; } SetLastItemBinding(new EditFieldBinding<decltype(*Value)>(*Value)); return Item; }
DialogItemEx *DialogBuilder::AddFixEditField(StringOption& Value, int Width, const wchar_t *Mask) { const auto Item = AddDialogItem(DI_FIXEDIT, Value.c_str()); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; if (Mask) { Item->Mask = Mask; Item->Flags |= DIF_MASKEDIT; } SetLastItemBinding(new EditFieldBinding(Value)); return Item; }
// Добавляет чекбокс. T *AddCheckbox(int TextMessageId, int *Value, int Mask=0, bool ThreeState=false) { T *Item = AddDialogItem(DI_CHECKBOX, GetLangString(TextMessageId)); if (ThreeState && !Mask) Item->Flags |= DIF_3STATE; SetNextY(Item); Item->X2 = Item->X1 + ItemWidth(*Item); if (!Mask) Item->Selected = *Value; else Item->Selected = (*Value & Mask) != 0; SetLastItemBinding(CreateCheckBoxBinding(Value, Mask)); return Item; }
DialogItemEx *DialogBuilder::AddCheckbox(lng TextMessageId, IntOption& Value, int Mask, bool ThreeState) { const auto Item = AddDialogItem(DI_CHECKBOX, GetLangString(TextMessageId)); if (ThreeState && !Mask) Item->Flags |= DIF_3STATE; SetNextY(Item); Item->X2 = Item->X1 + ItemWidth(*Item); if (!Mask) Item->Selected = Value; else Item->Selected = (Value & Mask) != 0; SetLastItemBinding(CreateCheckBoxBinding(Value, Mask)); return Item; }
FarDialogItem *AddFixEditField(wchar_t *Value, int MaxSize, int Width, const wchar_t *Mask = nullptr) { FarDialogItem *Item = AddDialogItem(DI_FIXEDIT, Value); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; if (Mask) { Item->Mask = Mask; Item->Flags |= DIF_MASKEDIT; } SetLastItemBinding(new PluginEditFieldBinding(Info, &DialogHandle, m_DialogItemsCount-1, Value, MaxSize)); return Item; }
DialogItemEx *DialogBuilder::AddEditField(StringOption& Value, int Width, const wchar_t *HistoryID, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(DI_EDIT, Value.data()); SetNextY(Item); Item->X2 = Item->X1 + Width; if (HistoryID) { Item->strHistory = HistoryID; Item->Flags |= DIF_HISTORY; } Item->Flags |= Flags; SetLastItemBinding(new EditFieldBinding<decltype(Value)>(Value)); return Item; }
DialogItemEx *DialogBuilder::AddHexEditField(IntOption& Value, int Width) { const auto Item = AddDialogItem(DI_FIXEDIT, L""); std::wostringstream oss; oss << L'x' << std::hex << std::setw(8) << std::setfill(L'0') << Value.Get(); Item->strData = oss.str(); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; const auto Binding = new EditFieldHexBinding<IntOption>(&Value, Width); SetLastItemBinding(Binding); Item->Flags |= DIF_MASKEDIT; Item->strMask = Binding->GetMask(); return Item; }
DialogItemEx *DialogBuilder::AddEditField(StringOption& Value, int Width, string_view const HistoryID, FARDIALOGITEMFLAGS Flags) { const auto Item = AddDialogItem(DI_EDIT, Value.c_str()); SetNextY(Item); Item->X2 = Item->X1 + Width; if (!HistoryID.empty()) { Item->strHistory = HistoryID; Item->Flags |= DIF_HISTORY; } Item->Flags |= Flags; SetLastItemBinding(new EditFieldBinding(Value)); return Item; }
DialogItemEx *DialogBuilder::AddEditField(string *Value, int Width, const wchar_t *HistoryID, int Flags) { DialogItemEx *Item = AddDialogItem(DI_EDIT, *Value); SetNextY(Item); Item->X2 = Item->X1 + Width; if (HistoryID) { Item->strHistory = HistoryID; Item->Flags |= DIF_HISTORY; } Item->Flags |= Flags; SetLastItemBinding(new EditFieldBinding(Value)); return Item; }
DialogItemEx *DialogBuilder::AddIntEditField(int *Value, int Width) { DialogItemEx *Item = AddDialogItem(DI_FIXEDIT, L""); FormatString ValueText; ValueText<<*Value; Item->strData = ValueText; SetNextY(Item); Item->X2 = Item->X1 + Width - 1; EditFieldIntBinding *Binding = new EditFieldIntBinding(Value, Width); SetLastItemBinding(Binding); Item->Flags |= DIF_MASKEDIT; Item->strMask = Binding->GetMask(); return Item; }
FarDialogItem *AddEditField(wchar_t *Value, int MaxSize, int Width, const wchar_t *HistoryID = nullptr, bool UseLastHistory = false) { FarDialogItem *Item = AddDialogItem(DI_EDIT, Value); SetNextY(Item); Item->X2 = Item->X1 + Width - 1; if (HistoryID) { Item->History = HistoryID; Item->Flags |= DIF_HISTORY; if (UseLastHistory) Item->Flags |= DIF_USELASTHISTORY; } SetLastItemBinding(new PluginEditFieldBinding(Info, &DialogHandle, m_DialogItemsCount-1, Value, MaxSize)); return Item; }
// Добавляет группу радиокнопок. void AddRadioButtons(int *Value, int OptionCount, const int MessageIDs[], bool FocusOnSelected=false) { for(int i=0; i<OptionCount; i++) { T *Item = AddDialogItem(DI_RADIOBUTTON, GetLangString(MessageIDs[i])); SetNextY(Item); Item->X2 = Item->X1 + ItemWidth(*Item); if (!i) Item->Flags |= DIF_GROUP; if (*Value == i) { Item->Selected = TRUE; if (FocusOnSelected) Item->Flags |= DIF_FOCUS; } SetLastItemBinding(CreateRadioButtonBinding(Value)); } }
DialogItemEx *DialogBuilder::AddComboBox(int *Value, int Width, DialogBuilderListItem *Items, int ItemCount, DWORD Flags) { DialogItemEx *Item = AddDialogItem(DI_COMBOBOX, L""); SetNextY(Item); Item->X2 = Item->X1 + Width; Item->Flags |= Flags; FarListItem *ListItems = new FarListItem[ItemCount]; for(int i=0; i<ItemCount; i++) { ListItems [i].Text = MSG(Items [i].MessageId); ListItems [i].Flags = (*Value == Items [i].ItemValue) ? LIF_SELECTED : 0; ListItems [i].Reserved [0] = Items [i].ItemValue; } FarList *List = new FarList; List->Items = ListItems; List->ItemsNumber = ItemCount; Item->ListItems = List; SetLastItemBinding(new ComboBoxBinding<DialogItemEx>(Value, List)); return Item; }
// Добавляет статический текст, расположенный на отдельной строке в диалоге. T *AddText(const wchar_t *Label) { T *Item = AddDialogItem(DI_TEXT, Label); SetNextY(Item); return Item; }
// Добавляет статический текст, расположенный на отдельной строке в диалоге. T *AddText(int LabelId) { T *Item = AddDialogItem(DI_TEXT, LabelId == -1 ? L"" : GetLangString(LabelId)); SetNextY(Item); return Item; }