A Genie Style Dialog with Tabs

Description

This script shows how you can create a Genie style Xdialog that also has tabs allowing quick access to individual pages of the Genie.

First specify the tab names.

dim lv as P
lv = local_variables()
'Specify the List of Tab Names for the Genie
panes = <<%a%
Page 1
Page 2
Page 3
%a%

Next, specify the Xdialog code (dialog body and event code) for each Genie page.

dim code_pages[1] as P
code_pages[1].name = "Page 1"
code_pages[1].dialog_body = <<%dlg%
This is the body of the 'Page 1' page;
%dlg%
code_pages[1].dialog_events = <<%code%
1=1
%code%
code_pages.insert(1,1)
code_pages[1].name = "Page 2"
code_pages[1].dialog_body = <<%dlg%
This is the body of the 'Page 2' page;
%dlg%
code_pages[1].dialog_events = <<%code%
1=1
%code%
code_pages.insert(1,1)
code_pages[1].name = "Page 3"
code_pages[1].dialog_body = <<%dlg%
This is the body of the 'Page 3' page;
%dlg%
code_pages[1].dialog_events = <<%code%
1=1
%code%

Next, display the dialog box.

current_pane = 1
dim flag_next as L
dim flag_prev as L
dim flag_finish as L
flag_next = .t.
flag_prev = .f.
flag_finish = .f.
ui_dlg_box("Genie with Tabs",<<%dlg%
{startup=init}
[%R=1%.144,19current_pane^^panes!current_pane_*]
{embedded=142,13embedded1}
{line=1,0};
{justify=right}<10&Cancel> <10&< Previous!prev?flag_prev><10&Next \>!next?flag_next> <10&Finish?flag_finish>;
%dlg%,<<%code%
if a_dlg_button = "init" then
    a_dlg_button = ""
    show_page(lv)
end if
if left(a_dlg_button, 13) = "current_pane_" then
    if a_dlg_button = "current_pane_change" then
        show_page(lv)
        set_flags(lv)
    end if
    a_dlg_button = ""
end if
if a_dlg_button = "prev" then
    a_dlg_button = ""
    current_pane = current_pane - 1
    if current_pane = 0 then
        current_pane = 1
    end if
    show_page(lv)
    set_flags(lv)
end if
if a_dlg_button = "next" then
    current_pane = current_pane + 1
    if current_pane > line_count(panes) then
        current_pane = line_count(panes)
    end if
    a_dlg_button = ""
    show_page(lv)
    set_flags(lv)
end if
%code%)

The show_page()function swaps the embedded dialog boxes as the user clicks the tabs.

function show_page as v (vars as P)
with vars
    dim page_to_show as C
    dim dlg_body_embedded as C
    dim dlg_event_embedded as C
    page_to_show = word(panes,current_pane,crlf())
    dim tempIndx as N
    tempIndx = code_pages.find(ut(page_to_show), "ut(name)")
    if tempIndx > 0 then
        dlg_body_embedded = code_pagestempIndx.dialog_body
        dlg_event_embedded = code_pagestempIndx.dialog_events
    else
        dlg_body_embedded = "Code for this page not found"
        dlg_event_embedded = "1=1"
    end if
    ui_modeless_dlg_box("embedded1", dlg_body_embedded, dlg_event_embedded)
end with
end function

The set_flags()function sets the values of the logical variables, which in turn determine whether buttons will display.

function set_flags as v (vars as P)
with vars
    if current_pane = 1 then
        flag_prev = .f.
    else
        flag_prev = .t.
    end if
    if current_pane = line_count(panes) then
        flag_next = .f.
        flag_finish = .t.
    else
        flag_next = .t.
    end if
end with
end function

Limitations

Desktop applications only.

See Also