How select TComboBox item on Mac with Firemonkey? - delphi

I have a TComboBox with several Strings in its Items list. When run on Windows, this works properly - I am able to click the combo-box, have the items appear, and then select one of the items.
When I set the OS target to OS X, however, the TComboBox does not allow me to select an item. I can click the TComboBox and have the items appear, but when I try to click an item from the drop-down list I receive a 'bump' sound on the Mac, and nothing is selected.
How can I get TComboBoxes to work properly on the Mac using Firemonkey?
I am using C++ Builder XE6 with FMX (Firemonkey).

Workaround:
Basic idea: use Show () instead of ShowModal (), combined with a component that will make the main form non-clickable while the child form is shown.
On the main form, add a TRectangle (or TPanel) with Visibility = false, Opacity = 0.25 (or something like that - could also be 0), and HitTest = true.
Then, when about to show a child form, call a function that sets the TRectangle on the main form to cover the main form (setting its Position->X, Position->Y, Width, Height) and then sets its Visibility = true.
Then, call a child form with Show () instead of ShowModal ().
When the child form is done, call a function on the main form that sets the TRectangle back to Visibility = false.

Related

Parent components show over child form

I've been following the below page in order to have a child Form that I can click on its components (such as an edit) and have proper focus:
Working with MDI Forms in Delphi
The problem now is that the components on the parent Form show on top of the child Form. If I use the SendToBack() command for those components, they completely disappear. Here is a screenshot of what happens:
EDIT:
I have a Form with buttons and a ListView that displays client info. When I click on a client, I can click a button to view or edit that client, alternatively add a new one. The Edit/Add pops up a Form where I can input the info and save it. I'm using an OnClick event for each Edit that has a SetFocus(). That gets focus on each Edit, but then all the text is selected, so I cannot click on the line and start editing text - it just overrides unless I use an arrow first.
Initially, I used regular Forms and that's where I had the focus issue. MDI fixed that, but now it's the parent components that show on top of the child.
Concerning MDI forms: that is how MDI works. The main form is not supposed to have anything else than a menu bar and optionally a toolbar, aligned alTop. The child forms use the rest of the space. Well as #RemyLebeau suggested, you can add other controls too, if you align them.
But it turned out that the actual problem with using ordinary secondary forms was that the text in an edit control on the secondary form becomes selected when you set focus to the edit control in a button click. That is easy to change, right after you set the focus to an edit control:
Edit2.SelLength := 0; // nothing selected, cursor at beginning
Edit3.SelStart := Length(Edit3.Text); // nothing selected, cursor at end of text

How to prevent main menu actions from executing when child form is visible

In an MDI VCL application, when I have a non-modal Form showing, keyboard shortcuts for the MainForm's menu will switch focus to the MainForm and perform menu item actions - which is never what I want.
In earlier versions of Delphi, one could override the MainForm's IsShortCut() method (as answered here), but this no longer works in Delphi 10.4.2.
I have tried various permutations of using OnShortCut and IsShortCut() from TApplication and TForm without success.
Overriding IsShortCut() of a non-MainForm to return true for Alt+ keyboard combinations does work to block the MainForm menus, but it also blocks local hotkeys in the action form, so is not very helpful.
Is there now a better (or any!) way to do this?
I found that when the shortcut is invoked, the main form (or active MDI form) calls the container menu item's OnClick before testing for assignments of the shortcuts. So what works for me is enabling the menu item in the menu item's container menu's OnClick handler (e.g. for an item on the File menu, set the OnClick event for the File menu item itself). E.g. like this
procedure TMyForm.FileMenuClick(Sender: TObject);
begin
MyMenu.Enabled := Screen.ActiveForm = self;
end;
The corresponding shortcut for MyMenu is then not processed by the form, and can be correctly used by the active window.

How to change the color of active TAB in a TabControl, in Delphi

How to change the color of active TAB in a TabControl (on FireMonkey) as shown below?
There are 2 ways to make this happen.
1) First option is you can create CustomStyle for TabControl from TStyleBook (Style Designer).
Then you can add whatever you want to use in your custom design (TRectangle is recommmended for many shape and colors).
2) I prefer to use second way for it. Set the TTabControl's TabPosition to None, then add a TGridPanelLayout to where you want to add tabs in your form. After that, set your TGridPanelLayout's column count for your tab count.
Now you need to know that your each tab box should be same. Drop a TRectangle for first column then set Align to Client (All colors and inner components are depends on your choice).
Be sure that your TRectangle components HitTest parameter is true and inner components' HitTest parameter is false.
Also you can handle your tab selections from OnClick event. Set each TRectangle (for tab) a Tag then connect all tabs to same OnClick event. Then you get Sender's Tag and set your TabControl1.ActiveTab from your Tag.

Make popup window close when releasing mouse button on an item on the fly

When clicking on a button I open a popup menu, e.g. using popupMenu.popup().
To select an item I must first release the mouse button and then click on a menu item to execute it.
This is "normal", but what I want is the behavior that I won't have to do an extra click on the menu item. I would like to be able to click on the button, move over a menu item (still holding the button) and execute it immediately after releasing the mouse button.
This is similar to how cascaded sub menus work.
I tried the way using TrackPopupMenu to hook into the messages and execute the item when the button is released. This works, but...
When using images in the popup menu (either bitmap or imagelist items) together with TrackPopupMenu then the menu does not show any entry. Every entry is some pixels wide and empty. You can use them blindly, so they work somehow but the drawing is not done correctly.
I'm using Delphi XE2 Pro.
I also tried to find general articles to hook into menu messages but did not find anything that works without using TrackPopupMenu. Maybe there is a way to have TrackPopupMenu displaying menus with images?
Any help is much appreciated.
You are routing menu messages to the wrong window procedure, you are passing the handle of your form to TrackPopupMenu (you should post your code, then there would be no need to guess what you're doing wrong. And you'd probably receive a much quicker reply).
Forms have menu support for window menus. When a form window procedure receives a, say WM_DRAWITEM, it only draws the item if it belongs to the window menu. For popup menus, VCL uses a utility window which is accessible through the global PopupList. See below example.
var
Pt: TPoint;
begin
Pt := Button1.ClientToScreen(Point(0, Button1.Height));
TrackPopupMenu(PopupMenu1.Handle, TPM_LEFTBUTTON, Pt.X, Pt.Y, 0,
PopupList.Window, nil);

Delphi: What is type of window appears after you click a ComboBox

There is a window appear after you click that triangle icon of ComboBox. This I know it's not just a panel like object because for example in the following picture it' out of main form.
What is its type and how can I create something like this?
It is a standard ListBox control that the ComboBox creates internally (its HWND is accessible via the CB_GETCOMBOBOXINFO message). It is implemented as a free-floating window (so it can appear outside the ComboBox's parent window), except when the Style property is set to csSimple, in which case the ListBox resides as a child within the ComboBox's client area instead.

Resources