477 views
in Embedded Wizard Studio by
Hello,

Within my main application, I have two components / dialogs which occupy a quarter of the screen, and the lay on top of each other.  Within each of these components is a unique Keyhandler / slot method to service keyboard input for different options accessible to each dialog / component.  My question is how can I switch between the visibility of those dialogs with a KeyHandler / slot method that is defined within each of those components.  Is this possible, or does the Keyhandler have to be associated with the main application?  Basically, I'm not sure how I can make one component visible while in a another component.   

Thanks,

RichK

1 Answer

0 votes
by

Hello RichK,

Generally the code to present, dismiss, switch a dialog can be executed elsewhere. Essential is the component in context of which you invoke the methods PresentDialog(), SwitchToDialog() and DismissDialog(). Accordingly, the new dialog is presented in context of the specified component. It depends thus on what you expect in your application. Following examples demonstrate it:

1. Let's assume, there is a component A visible already on the screen.

2. Let's assume, there is a component B you want to present.

3. Let's assume, the component A contains a key handler and implement a method to execute when the handler is triggered. 

4. If you want the component B to be presented in context of the same GUI component, the component A belongs already to, then invoke the method PresentDialog() or SwitchToDialog() in context of A's variable Owner. Consequently, the component B and A will be siblings within the same owner component:

Owner.PresentDialog( compB, ... )

5. If you want the component B to be presented nested within component A (embedded within A), then invoke the method in context of this (this represents the component A itself). Please note, that this keyword can be omitted. The so presented component B will appear nested within A:

PresentDialog( compB, ... )

6. If you want the component B to be presented within the application component itself (the root object of the application), then use GetRoot() to obtain access to the root object. The so presented component will appear at top level of the entire application:

GetRoot().PresentDialog( compB, ... )

To make your implementation more robust and prevent eventual race conditions, I would recommend to prefix the above code by an additional condition. For example, if component A was presented originally as dialog, present component B only, when A still acts as dialog:

if ( IsCurrentDialog())
  GetRoot().PresentDialog( compB, ... )

... in turn, if A is just a regular component, but it is possible that it will be removed from the view tree, check whether it still belongs to the tree before presenting a new dialog:

if ( GetRoot())
  GetRoot().PresentDialog( compB, ... )

See also:

The methods: PresentDialog, DismissDialog and SwitchToDialog

Understand the view tree and the Owner relationships (the Owner variable)

Access the root object (GetRoot())

Identify the active Dialogs and avoid race conditions

Does it help you further?

Best regards

Paul Banach

by
Paul,

 

That does help - Thank you.  

A further clarification  - I have bounds defined for both Component A and B, but when calling "PresentDialog" from the context of the Main  Application (which is the owner of these two components), the presented component always appears in the center of the main application's region, even though its original bounds were defined to place it elsewhere on the region.  What am I missing here?

 

Thanks,

Rich
by

Hello Rich,

per default the dialogs are centered within the area of their superior component. This is most common application case.

If this behavior is not desired, you can provide own configuration to control how dialogs should be aligned. For example, add a new Show/Hide Transition object to your project and configure in the object the Layout and Margin properties. Then pass the object in the second parameter when invoking PresentDialog() or SwitchToDialog() methods.

Please see following sections for more details:

About positioning of Dialogs

Customize provided Dialog transition animations

Configure how to arrange the Dialog within its owner (here in case of the Show/Hide Transition)

Perform Dialog transitions with animations (explains the available method parameters)

I hope it helps you further.

Best regards

Paul Banach

by
Paul,

Got it - works great now.

 

Thanks,

Rich

Embedded Wizard Website | Privacy Policy | Imprint

...