How to replace REALGetTabPanelVisible

How are we supposed to replace this one here:

REALGetTabPanelVisible ? (Its marked as Deprecated)

This function checks if your control is invisible because a Tab that it lives on has put it in to to the back. I am not aware of any function in Xojo that I could dynamically load to replace this one ?

Dim TabVisible as Boolean = (me.PanelIndex = TabPanel(me.Parent).Value) msgbox str(tabvisible)

Nice Michel, now translate to SDK calls, please :slight_smile:

I would think you get crash with that if the me.Parent is not TabPanel

And also the SDK function REALGetTabPanelVisible works on more than just the TabPanel, it also works on the PagePanel if I remember correctly. (Maybe container controls too ? I never actually gave it a thought)

Well, if you call REALGetPropValue with “Value” as property name for an Integer, you either get a number or the function returns false. So that may work for both PagePanel and TabPanel.

Anyway, for REALGetTabPanelVisible replacement, we need to lookup control hierarchy to see if plugin control is in a tab panel which is on a page panel.

TabPanel is a subclass of PagePanel, so that isn’t a problem. Here’s some Xojo code that does the same thing as REALGetTabPanelVisible:

Function GetTabPanelVisible(ctrl As RectControl) As Boolean Dim panelIndex As Integer = ctrl.PanelIndex While ctrl.Parent <> Nil Dim parent As RectControl = ctrl.Parent If parent IsA PagePanel Then If panelIndex <> PagePanel(parent).Value Then Return False panelIndex = parent.PanelIndex End If ctrl = parent Wend Return True End Function

It shouldn’t be too hard to port to a plugin. All you’d need is REALGetPropValue (for PanelIndex, Parent, and Value) and REALObjectIsA. In fact, here’s some untested code that might do the trick:

[code]// Load this from PluginMain via REALGetClassRef
static REALclassRef sPagePanelClass;

bool GetTabPanelVisible(REALobject ctrl)
{
assert(ctrl);
REALLockObject(ctrl);

RBInteger panelIndex;
bool success = REALGetPropValue(ctrl, “PanelIndex”, &panelIndex);
assert(success);

while (ctrl) {
REALobject parent;
success = REALGetPropValue(ctrl, “Parent”, &parent);
assert(success);

bool visible = true;
if (parent && REALObjectIsA(parent, sPagePanelClass)) {
  RBInteger value;
  success = REALGetPropValue(parent, "Value", &value);
  assert(success);

  visible = (value == panelIndex);

  success = REALGetPropValue(parent, "PanelIndex", &panelIndex);
  assert(success);
}

REALUnlockObject(ctrl);
ctrl = parent;
if (!visible) return false;

}
return true;
}[/code]

Thanks Joe !

[quote=164342:@Björn Eiríksson]I would think you get crash with that if the me.Parent is not TabPanel
[/quote]

Not a crash. If you try this for a control that is on a window you will get “window has no member named Parent”.

But it is easy to wrap this in a condition like

if me.parent isa TabPanel or me.parent isa PagePanel then Dim TabVisible as Boolean = (me.PanelIndex = TabPanel(me.Parent).Value) msgbox str(tabvisible) end if

Joe has just done that above :wink: In fact we use exactly the same principle.

So does what I posted.

Joe is your friend :wink: