TEdit and focus selection works different depending on Show/showmodal - delphi

When switching focus between TEdits, the selection changes depending on the way you show the form.
When you show it with Form.show, and swith between two TEdits, the text is selected.
When you show the form with Form.Showmodal, And switch between, the cursor is at the end of the newly focused TEdit
reproduce :
Create a new form with 2 TEdits, type some text in both. Then switch between both TEdits, the whole text is selected, but when I show the form with Modal, The caret is positioned behind the text.
Why is there a difference in functionality? And where can I change it.
I found the code responsible :
procedure TStyledEdit.DoEnter;
var
Form: TCommonCustomForm;
begin
inherited;
Form := TCommonCustomForm(Root);
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
//next part returns false
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing]) or
(Form.FormState = [TFmxFormState.Engaged])) then
Edit.SelectAll
else
begin
UpdateSelectionPointPositions;
UpdateCaretPosition;
end;
end;

DoEnter is a protected method and as such you can override with your own method if you wish.
You can either do this the classic way by creating your own descendant class (with a different type name) or you can use the so-called interceptor classes as described in this link: interceptor classes.
I believed that you need to extend the if clause like this (but not tested - sorry)
if not Model.IsReadOnly and Model.InputSupport and not FTextService.HasMarkedText and
((Form = nil)
or (Form.FormState * [TFmxFormState.Showing] = [TFmxFormState.Showing])
or (Form.FormState * [TFmxFormState.Modal] = [TFmxFormState.Modal])
or (Form.FormState = [TFmxFormState.Engaged])) then

Related

How to make TListView display order the same as the items were added?

I am adding a list of comet names and numbers into the VCL TListView and TListBox in C++Builder. I need the display order to be the order in which the names were added. This happens with the TListBox but not the TListView.
I am loading a .CSV file into a TStringList and then looping through the TStringList to load the contents into the TListBox and TListView. The TListBox displays the names in the order they are added. The TListView displays the names and numbers in two columns in an order I can't understand. With the TListView, I tried using the function Add() and Insert().
Below is my code. The picture shows the different results I get. How can I make the TListView display the names and numbers in the order they are added the same as the TListBox?
TListItem *ListItem;
std::auto_ptr<TStringList> MyCSVFile(new TStringList);
MyCSVFile->Delimiter = ',';
MyCSVFile->StrictDelimiter = true;
MyCSVFile->CommaText = "";
MyCSVFile->Clear();
MyCSVFile->LoadFromFile(GetFileName);
for(Row_Num=1; Row_Num < MyCSVFile->Count; Row_Num++){
Row_string = MyCSVFile->Strings[Row_Num];
Row_tokens->CommaText = Row_string;
Name_string = Row_tokens->Strings[Name_Cell_Num];
Num_string = Row_tokens->Strings[Num_Cell_Num];
ListBox1->Items->Add(Name_string);
//ListView - Add()
ListItem = ListView->Items->Add();
ListItem->Caption = Cell_string;
ListItem->SubItems->Add( Num_string );
//Alternate method ListView - Insert()
//ListItem = ListView->Items->Insert(0);
//ListItem->Caption = Cell_string;
//ListItem->SubItems->Insert(0, Num_string);
}
ListBox and ListView
I have tried using the Add() and Insert() functions with TListView but the display order is not the order items are added. I don't know any other way to get items into the TListView.
By default, the TListView sorts the items based on their captions or subitems, but setting the SortType to stNone will disable the sorting.
So, you can add the following line before the loop:
ListView->SortType = stNone;

CBuilder TMenu showing in wrong place

I have a Form that needs to be embedded in another Form. I'm placing on TCard:
EmbeddedForm->Parent = ACard;
EmbeddedForm->BorderStyle = bsNone;
EmbeddedForm->Align = alClient;
EmbeddedForm->Show();
All is working well, except that menus on the EmbeddedForm are offset to where they would be if the form were located in top left of the screen. To be clear, the menu shows up in the proper place on the EmbeddedForm, but when clicked, the sub-menu is in the wrong place.
I've tried modifying the DrawItem event, but so far I can't call the base class DrawItem() as it's protected:
void __fastcall TEmbeddedForm::File1DrawItem(TObject *Sender, TCanvas *ACanvas, TRect &ARect, bool Selected)
{
ARect.Left = MainMenu1.Left; // or some other calculation, not important yet
ARect.Top = MainMenu1.Top;
// ??? how to do normal drawItem from here?
}
I'm thinking, either I have to draw it myself (I don't want to) or somehow explain to TMainMenu where it's actually located (preferred solution).

how to make list with buttons at each item in Delphi

As shown in figure, I need to make a list with buttons on each item, one button at down left of the item, and some on the down right.
I Make the demo app using ListBox control and some Buttons within Panel above on ListBox, but when the ListBox scrolling, it's difficult to make the Buttons follow the ListItem.
who can help, thanks~~~
I got the way to make it!so, I'll post the answer myself~, but Remy Lebeau inspired me.
in the beginning, I used DrawFrameControl() to make button on list, It works but the style was look like classic windows style, and it's hard to make back color like the pic in the example.
then, I used FillRect() and DrawEdge() make the Button, I think it's well, here is the code:
hitPoint := lst1.ScreenToClient(Mouse.CursorPos);
// there is a btnRect var of the Button Rect
edgeRect.Left := btnRect.Left - 1;
edgeRect.Top := btnRect.Top - 1;
edgeRect.Right := btnRect.Right + 1;
edgeRect.Bottom := btnRect.Bottom + 1;
// make button
lst1.Canvas.FillRect(btnRect);
// make edge, FListMouseDown is bool var and setting value at MouseDown/MouseUp Event
//
if PtInRect(edgeRect, hitPoint) and FListMouseDown then begin
DrawEdge(lst1.Canvas.Handle, edgeRect, EDGE_ETCHED, BF_RECT); // button down style
end else begin
DrawEdge(lst1.Canvas.Handle, edgeRect, EDGE_RAISED, BF_RECT);
end;
The following work is store the Rect of Buttons in memory, write the ButtonOnClick event code, and calling ButtonOnClick event at ListMouseUp() event after judge if Mouse Hit Position is in the Button Rect, The Code is not important like the above drawing Buttons, so it is omitted

Add a combobox in to listview control in c++ builder

I want to create a listview with 2 columns. in the first column it must be the row number and in the second number it should contains a combobox. I write the following code, but second column just show "combo" string. it does not show any combo box. what is the wrong?
for (int i = 0; i < 10; i++) {
TListItem *items;
items= this->ListView1->Items->Add();
items->Caption=IntToStr(i);
items->SubItems->AddObject("combo"+IntToStr(i),(TObject *)this->ComboBox1);
}
It does not show a TComboBox because you have not actually set the TComboBox to be a child control of the TListView. All you have done is store the TComboBox pointer as a user-defined value associated with the TListItem. That has no effect on the UI, so get rid of it:
for (int i = 0; i < 10; i++)
{
TListItem *items = ListView1->Items->Add();
items->Caption = IntToStr(i);
items->SubItems->Add("combo"+IntToStr(i));
}
To actually show a TComboBox inside of the TListView, you have to assign the TListView as the Parent of the TComboBox, and then use the SetBounds() method to position and size the TComboBox whenever you need to show it:
ComboBox1->Parent = ListView1;
...
RECT rect = {0};
ListView_GetSubItemRect(ListView1->Handle, SomeListItem->Index, 1, LVIR_BOUNDS, &rect);
ComboBox1->SetBounds(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
// update ComboBox1->Items as needed...
ComboBox1->Visible = true;
...
ComboBox1->Visible = false;
With that said, what you are attempting to do is better handled using the TValueListEditor component instead. Add items to it as needed, then use its ItemProps property to set each item's TItemProp.EditStyle property to esPickList, and then use the TValueListEditor.OnGetPickList event or the TItemProp.PickList property to manage the ComboBox strings as needed.

Modify the "arrow" with of a split button in TActionToolBar

I have a toolbar using TActionToolBar and TActionManager. A button has sub-buttons that are available clicking the small down arrow placed in the right of the button.
The width of the "arrow down" button is very thin and requires precise mouse control. How can I customize it?
Thank you
A solution is using the OnGetControlClass event of TActionToolBar.
Before, it is necessary to derive a class from TThemedDropDownButton and override the GetDropDownButtonWidth function:
function TThemedDropDownButtonEx.GetDropDownButtonWidth: Integer;
begin
Result := 14; // default drop down button width
end;
Then, in OnGetControlClass function:
void __fastcall TWorkAreaToolBarFrame::ActionToolBarLeftGetControlClass(TCustomActionBar *Sender,
TActionClient *AnItem, TCustomActionControlClass &ControlClass)
{
if(ControlClass == __classid(TThemedDropDownButton))
ControlClass = __classid(TThemedDropDownButtonEx);
}
In few words, in GetControlClass event, the toolbar allows you to define which button class you want to use. We use a custom class with the default width changed.

Resources