Event for container coming to front

Can I get/make/fake an event when a container comes to front? I’ve got several containercontrols on a page panel. A new design needs to disable and later enable a button on the main window when a specific containercontrol comes to front. I could use a paint event but this is so unelegant.

Does only the ContainerControl change or the PagePanel too? In which case the PagePanel.Change event should work …

Activate ?

This event is not raised. It only shows up as event in the IDE because ContainerControl is a subclass of Window. Same for Deactivate.

@Markus: the pagepanel is on the window. I want the information to travel up and not down.

@Michel: neither Activate nor GetFocus work. They don’t fire.

[quote=175552:@Beatrix Willius]@Markus: the pagepanel is on the window. I want the information to travel up and not down.

@Michel: neither Activate nor GetFocus work. They don’t fire.[/quote]

You are not manipulating the zorder, right ? When you say “come up front”, you mean the page becomes visible ?

If so, why not simply use the PagePanel Change event and PanelIndex ?

@Michel: nope, I’m not manipulating the zorder. I just want to have the containercontrol announce to the window that it is on “I’m now there”. The pagepanel change event - of course - also will work.

But I’m not sure if the design and the number of pages on the page panel will stay. Therefore, I’d rather not hardcode the number of the pagepanel. The window is a wizard style window where the steps may change depending on the situation.

Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”. This did what I wanted. Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.

Where is the code available? Maybe someine can figure out how to fix it?

It has been in MacOSLib as an example since a few years.

The problem with it is that it is subclass of ContainerControl which shadows the Visible property. So to work properly you always need to cast the ContainerControl to BetterContainerControl ot the Visible property of ContainerControl will be called – thereby omitting the following code:

ComputedProperty Visible As Boolean Get return ContainerControl(me).Visible End Get Set if value = me.Visible then return end if if value then me.Show // Raises a VisibilityChanged event else me.Hide // Raises a VisibilityChanged event end if End Set EndComputedProperty

Looking at code of BetterContainerControl in MacOSLib I doubt this is really an error in BetterContainerControl. Do you have a screenshot of the code where this happens?

[quote=175554:@Beatrix Willius]@Michel: nope, I’m not manipulating the zorder. I just want to have the containercontrol announce to the window that it is on “I’m now there”. The pagepanel change event - of course - also will work.

But I’m not sure if the design and the number of pages on the page panel will stay. Therefore, I’d rather not hardcode the number of the pagepanel. The window is a wizard style window where the steps may change depending on the situation.

Once upon a time there was some code from Charles Yeomans called “Better ContainerControl”. This did what I wanted. Unfortunately, this makes a nice infinite loop and then a crash since Xojo 2015r1.[/quote]

Your idea of the Paint even seems to work.

The issue with a container control is that it does not have a PanelIndex property. I tried to cast it as RectControl but got an illegal cast exception.

For any other control, you can compare control.PanelIndex with PagePanel(control.Parent).Value and if it is the same the control is displayed. The best I could find is to place the instance of the ContainerControl on a Canvas, which has PagePanel.

Silly question (not on my Mac for a few weeks): could you not add a property PanelIndex to the ContainerControl and set it when the ContainerControl is initiated?

The containerControl has a TabPanelIndex property (that’s used on embedWithin for example)

it’s 0 for a CC on a window
it’s panelIndex+1 for a page or tab panel

[quote=175564:@Antonio Rinaldi]The containerControl has a TabPanelIndex property (that’s used on embedWithin for example)

it’s 0 for a CC on a window
it’s panelIndex+1 for a page or tab panel[/quote]

Oh you are right. Except it is not PanelIndex, but the deprecated TabPanelIndex which is 1 based. Thank you, though. Guess Xojo should update its event name.

This in the Change event of the TabPanel very nicely spots when the Container Control is displayed :

if ContainerControl11.TabPanelIndex-1 = me.Value then msgbox "You win !" end if

Your question is not silly, but there is simply no event in ContainerControl that fires when it is displayed. Except for Paint, but it fires so often it is a mess.

I wrote panelIndex+1 to say that it’s current panel number+1 not that the property is PanelIndex.

I understand. It is somewhat inconsistent for Xojo to keep TabPanelIndex for ContainerControl while having PanelIndex for other controls, though. I missed it when I tried to have CC.PanelIndex autocomplete and saw it was not there. I should have looked at the LR instead.

Thanks for the ideas, guys.

Regarding BetterContainerControl: it makes a StackOverflowException in the Shown event. My guess it that the order of events changed internally. You can find an example here: https://conbr.io/d/sEey5rsw .

This should work in 2015r1:

[code]Class BetterContainerControl Inherits ContainerControl

Event Open()
Event VisibilityChanged()
Event VisibilityChanging()

Sub Open()
Self.Visible = True
RaiseEvent Open()
End

Sub Hide()
If Self.Visible Then
RaiseEvent VisibilityChanging()
Window(Self).Hide()
RaiseEvent VisibilityChanged()
End
End

Sub Show()
? If Not Self.Visible Then
RaiseEvent VisibilityChanging()
Window(Self).Show()
RaiseEvent VisibilityChanged()
End
End

Property Visible As Boolean
Get
Return ContainerControl(Self).Visible
End
Set
If value <> ContainerControl(Self).Visible Then
If value Then
Show()
Else
Hide()
End
End
End
End[/code]

@Eli: thanks! Scratching head: what is the difference? Why does your version work and my version crash? There are a couple of raiseevents and self is used instead of me.