Omnis Technical Note TNGI0027 December 2009

Using Subwindows in a Tab Pane

for Omnis Studio 5 or above
by Götz Krija

When you use multiple subwindows on different tabs of a tab pane, you may want to initialise the appropriate subwindow when the user switches from one tab to another. Under normal circumstances, you can initialise a window using its $construct() method, but when a window is opened as a subwindow its $construct() method is called when the main window opens. So in a window containing a tab pane and many subwindows, the subwindow initialisation cannot be done in the $construct() method, and therefore a different approach is needed.

Each subwindow could have a custom method called $init() in which the required initialisation takes place. For test purposes you can add an OK message to the $init() method to show it has been called; something like the following:

OK message {init [$cinst.$classname]}
; note $classname is valid for subwindows only

This method will be activated in the $event of the tab pane:

On evTabSelected
  Do $cobj.$objs.$sendall($ref.$init(),
   $cobj.$getPaneNumber($ref)=pTabNumber)

When the user switches to another tab, a message will be sent with $sendall() to all other objects in the window (including all the subwindows) which activates their $init() methods (if available). However, the method is executed only if the object is located on the selected tab (pTabNumber).

To find out the pane number of the object we need an additional method $getPaneNumber() that should not be created as a class method but should belong directly in the tab pane:

Method '$getPaneNumber'
(pRef Item reference)
Quit method $cobj.$panenumber(pRef)

When you open an instance of the main window, the OK message should be displayed every time the user switches from one tab to another.

In Omnis Studio 5 you don't need the additional method $getPaneNumber(), since the Tab pane field now has the $panenumber() method built-in that either gets or sets the current pane number. In this case, the following code will do the job:

On evTabSelected
  Do $cobj.$objs.$sendall($ref.$init(),
  $cobj.$panenumber($sendallref)=pTabNumber)

You may want the initialisation method in the subwindow on the first tab to run when the main window is opened. You could add code to the $construct() of the first subwindow, but you cannot always guarantee that this will be the first subwindow to be opened. A more object oriented approach would be to send a message to the subwindow on the current tab when the main window opens; the following code can be placed in the $construct() method of the main window:

Do $cwind.$objs.tabpane.$objs.$sendall($ref.$init(),
  $cwind.$objs.tabpane.$panenumber($sendallref)=$cwind.$objs.tabpane.$currenttab)

Download a sample library from Github: https://github.com/OmnisStudio/Omnis-SubTabs (for Studio 8.1.2 or above)
(or an archive: subtabs.zip for Studio 5 or above)

Search Omnis Developer Resources

 

Hit enter to search

X