435 views
in GUI Development by

Can I set focus back to a modal screen without calling BeginModal?

I have a home screen (Application::aoHomeScreen) which is modal but in the background after creating new screens in front of it.

I call RestackBack and EndModal on the current screen and the modal home screen is displayed. However it's focus property is not set.

I have found that I can get back focus by calling BeginModal, but this causes an exception unless I call EndModal first. The code below works, but is there a more correct way of doing this? 

var Core::Root rootObject = GetRoot();

rootObject.RestackBack (this);  // put current screen to the background
rootObject.EndModal (this);  // endmodal on current screen

// beginmodal throws exception if the view is already modal
rootObject.EndModal (Application::aoHomeScreen);
rootObject.BeginModal (Application::aoHomeScreen);

 

1 Answer

0 votes
by

Hi,

I suppose there is still another component with modal state. So calling EndModal( this ) causes this another component to restore its focus instead of aoHomeScreen. Can you add the code line trace rootObject.GetModalGroup(), aoHomeScreen; to the above implementation just after rootObject.EndModal( this );? This would print the identity of the component which is actually modal and the identity of the aoHomeScreen component itself. Are they equal?

The exception caused when calling BeginModal() means, aoHomeScreen is already modal. Assigning the modal state twice is not possible. Thuse with EndModal() you revoke the modal state from the aoHomeScreen and then with BeginModal() you assign it again. If my assumption is correct, then the usage of EndModal() and BeginModal() restacks the aoHomeScreen to the top of the modal stack.

Best regards

Paul Banach

by

Hi Paul,

Thanks for the response. I added the GetModalGroup and it is the aoHomeScreen that is modal. I checked some other ViewState items and find that it's only the Focused state that is not set (Modal, Focusable, Enabled are all set). Is there a way of applying the Focused state on a modal component without calling BeginModal()?

Regards,

  Stephen

 

var Core::Root rootObject = GetRoot();

rootObject.RestackBack (this);
rootObject.EndModal (this);
trace rootObject.GetModalGroup(), Application::aoHomeScreen;

trace Application::aoHomeScreen.HasViewState( Core::ViewState[ Modal]);
trace Application::aoHomeScreen.HasViewState( Core::ViewState[ Focusable]);
trace Application::aoHomeScreen.HasViewState( Core::ViewState[ Enabled]);
trace Application::aoHomeScreen.HasViewState( Core::ViewState[ Focused]);

// beginmodal throws exception is view is already modal
rootObject.EndModal (Application::aoHomeScreen);
rootObject.BeginModal (Application::aoHomeScreen);

 

by
It is suspect. Is it possible for you to provide me a simple project demonstrating the problem? I would analyze it.

Embedded Wizard Website | Privacy Policy | Imprint

...