<?xml version="1.0" encoding="UTF-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="minibrowser_v01.xsd" xmlns="minibrowser_v01.xsd">
    <xs:complexType name="MenuType">
        <xs:annotation><xs:documentation>
            The menu itself may define Options as well as each single line-item.
            Note: Options accumulate. I.e. you cannot overwrite or delete an Option at line-item-level
            that was defined for the entire menu.
        </xs:documentation></xs:annotation>
        <xs:sequence>
            <xs:element type="textType" name="Title" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element type="ItemType" name="Item" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element type="ActionsType" name="AutomatedActions" maxOccurs="1" minOccurs="0" />
            <xs:element type="OptionsType" name="Options" maxOccurs="1" minOccurs="0" />
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>
    <xs:element type="MenuType" name="Menu" />
    <xs:element type="DialogType" name="Dialog" />
    <!-- not released yet.
    <xs:element type="UpdateType" name="Update" />
    <xs:complexType name="UpdateType">
        <xs:annotation>
            <xs:documentation>any element that has an id can be updated (TBD)</xs:documentation>
        </xs:annotation>
        <xs:choice maxOccurs="unbounded" minOccurs="1">
            <xs:element type="MenuType" name="Menu" />
            <xs:element type="DialogType" name="Dialog" />
            <xs:element type="UpdateType" name="Update" />
            <xs:element type="ItemType" name="Item"/>
            <xs:element type="ActionsType" name="AutomatedActions"/>
            <xs:element type="OptionsType" name="Options"/>
            <xs:element type="OptionType" name="Option"/>
            <xs:group ref="ActionsGroup"/>
            <xs:group ref="LineAppearanceGroup"/>
        </xs:choice>
    </xs:complexType>
    -->

    <xs:group name="LineAppearanceGroup">
        <xs:annotation>
            <xs:documentation>maybe in future: enum-choice/int-range/bool/date/time</xs:documentation>
        </xs:annotation>
        <xs:choice>
            <xs:element type="FixedTextType" name="TextLine"/>
            <xs:element type="TextInputType" name="TextInput"/>
        </xs:choice>
    </xs:group>

    <xs:attributeGroup name="ActionAttributesGroup">
        <xs:attribute type="TriggerType" name="on" use="optional" default="do it"/>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:attributeGroup>


    <xs:complexType name="EmptyActionType">
        <xs:attributeGroup ref="ActionAttributesGroup"/>
    </xs:complexType>


    <xs:complexType name="SimpleActionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="ItemType">
        <xs:sequence>
            <xs:group ref="LineAppearanceGroup"/>
            <xs:element type="ActionsType" name="AutomatedActions" maxOccurs="1" minOccurs="0" />
            <xs:element type="OptionsType" name="Options" maxOccurs="1" minOccurs="0" />
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>
    <xs:complexType name="TextInputType">
        <xs:sequence>
            <xs:element name="Default" type="xs:string" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>to pre-fill text-input-field</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element type="textType" name="Help" minOccurs="0">
                <xs:annotation>
                    <xs:documentation>shown while input is empty</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="InputMode" minOccurs="0">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="alphanumeric"/>
                        <xs:enumeration value="numbersOnly"/>
                        <xs:enumeration value="numbersPreferred"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="InputType">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:enumeration value="plain"/>
                        <xs:enumeration value="password"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="Parameter" type="xs:string" default="value"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>

    <xs:complexType name="textType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="langType" name="lang" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:group name="ActionsGroup">
        <xs:choice>
            <xs:element type="URLType" name="Url"/>
            <xs:element type="TriggerActionType" name="Trigger"/> <!--only allowed when used within options -->
            <xs:element type="DialActionType" name="Dial"/>
            <xs:element type="SelectActionType" name="Select"/>
            <xs:element type="TimerActionType" name="StartTimer"/>
            <xs:element type="TimerActionType" name="StopTimer"/>
            <xs:element type="TimerActionType" name="RestartTimer"/>
            <xs:element type="SimpleActionType" name="Input"/>
            <xs:element type="BeepActionType" name="Beep"/>
            <xs:element type="EmptyActionType" name="StopSignal"/>
            <xs:element type="EmptyActionType" name="Quit"/>
            <xs:element type="EmptyActionType" name="Backspace"/>
            <xs:element type="EmptyActionType" name="EditMode"/>
            <xs:element type="EmptyActionType" name="GoBack"/>
            <xs:element type="EmptyActionType" name="GoUp"/>
            <xs:element type="EmptyActionType" name="GoDown"/>
            <xs:element type="EmptyActionType" name="GoLeft"/>
            <xs:element type="EmptyActionType" name="GoRight"/>
            <xs:element type="EmptyActionType" name="Reload"/>
        </xs:choice>
    </xs:group>

    <xs:complexType name="ActionsType">
        <xs:sequence>
            <xs:choice maxOccurs="unbounded" minOccurs="0">
                <xs:group ref="ActionsGroup"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>

    <xs:complexType name="OptionsType">
        <xs:sequence>
            <xs:element type="OptionType" name="Option" maxOccurs="unbounded" minOccurs="0"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>
    <xs:complexType name="FixedTextType">
        <xs:sequence>
            <xs:element name="Text" type="textType" maxOccurs="unbounded" minOccurs="0" />
            <xs:element name="Help" type="textType" maxOccurs="unbounded" minOccurs="0" />
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>

    <xs:complexType name="DialogType">
        <xs:sequence>
            <xs:element name="Title" type="textType" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="Text" type="textType" maxOccurs="unbounded" minOccurs="0"/>
            <xs:element name="WebView" type="dialogWebType" maxOccurs="1" minOccurs="0"/>
            <xs:element name="AutomatedActions" type="ActionsType" maxOccurs="1" minOccurs="0"/>
            <xs:element type="OptionsType" name="Options" maxOccurs="1" minOccurs="0" />
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>

    <xs:complexType name="dialogWebType">
        <!-- alternative to Text, will only be used on color-screen models -->
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="enumDialogWebType" name="type" use="optional"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="enumDialogWebType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="html"/>  <!-- assume text-content is html-page, use a web-view to render it -->
            <xs:enumeration value="url"/>   <!-- assume text-content is an url to a web-page, use a web-view to render it -->
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="OptionType">
        <xs:sequence>
            <xs:choice maxOccurs="unbounded" minOccurs="0">
                <xs:element name="Text" type="textType"/>
            </xs:choice>
            <xs:choice maxOccurs="unbounded" minOccurs="0">
                <xs:group ref="ActionsGroup"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute type="xs:string" name="id" use="optional"/>
        <xs:attribute type="xs:string" name="ref" use="optional"/>
    </xs:complexType>

    <xs:simpleType name="httpUriType">
        <xs:restriction base="xs:anyURI">
            <xs:pattern value="https?://.+" />
        </xs:restriction>
    </xs:simpleType>

    <xs:complexType name="URLType">
        <xs:simpleContent>
            <xs:extension base="httpUriType">
                <xs:attribute type="UrlHandlingType" name="answer" default="show"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="SelectActionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="SelectActionLineIndexType" name="line" default="1"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="DialActionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="DialActionMinLenType" name="min_len" default="1"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="TimerActionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute type="xs:string" name="timer_id" default="MainTimer"/>
                <xs:attribute type="TimerActionTimeoutType" name="timeout" use="optional"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="TriggerActionType">
        <xs:simpleContent>
            <xs:extension base="TriggerType">
                <xs:attribute type="TriggerForType" name="for"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:complexType name="BeepActionType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <!-- choose the tone to play, select an internal melodie, same values as when
                     choosing a default ringtone (80s, American_Phone, ..)
                     if not set a short generated beep is played -->
                <xs:attribute type="xs:string" name="tone" use="optional"/>
                <!-- override volume as set by user (/sound/volumes/notifying)
                     choose value between 0 and 100 (inclusive)
                     only works when tone-attribute is set as well -->
                <xs:attribute type="xs:string" name="forcedVolume" use="optional"/>
                <xs:attributeGroup ref="ActionAttributesGroup"/>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="TriggerType">
        <xs:union memberTypes="enumTriggerType timeoutTriggerType xs:string"/><!--string for made-up (user defined) signals or for when comma, separating a list of std-trigger-types-->
    </xs:simpleType>

    <xs:simpleType name="enumTriggerType">
        <xs:restriction base="xs:string">
            <!-- triggers emitted by hard-keys or ui-gestures (e.g. touch). Some must be defined within the MB-document
            or they do nothing but some also have an implicit default-action that will be used so long as mb doen't
            define another action for the situation. -->
            <xs:enumeration value="do it"/> <!--OK-press or touch on item -> void if MB doesn't define an action-->
            <xs:enumeration value="back"/>      <!--default action: <GoBack on="back, mb back"/> -->
            <xs:enumeration value="up"/>        <!--default action: <GoUp on="up, mb up"/> -->
            <xs:enumeration value="down"/>      <!--default action: <GoDown on="down, mb down"/> -->
            <xs:enumeration value="left"/>      <!--default action: <GoLeft on="left, mb left"/> -->
            <xs:enumeration value="right"/>     <!--default action: <GoRight on="right, mb right"/> -->
            <xs:enumeration value="make call"/> <!--default action: <DIAL on="make call, mb make call"/> -->

            <!-- triggers emitted by elements defined within MB-XML: -->
            <xs:enumeration value="mb exit"/>
            <xs:enumeration value="mb back"/>
            <xs:enumeration value="mb up"/>
            <xs:enumeration value="mb down"/>
            <xs:enumeration value="mb left"/>
            <xs:enumeration value="mb right"/>
            <xs:enumeration value="mb make call"/>
            <xs:enumeration value="timeout"/>

            <!-- screen-triggers: -->
            <xs:enumeration value="user activity"/> <!--any touch or key-press-interaction of user with phone-->
            <xs:enumeration value="come back"/><!-- after going back and now handling previous xml .. default does nothing but one could add an automated reload-action -->
            <xs:enumeration value="app resume"/><!-- mb-app gets opend in foreground again, without a new url, so it would display old xml .. default does nothing but one could add an automated reload-action -->
            <xs:enumeration value="shown"/><!-- MB is shown, either after loading Url with this screen or after COME_BACK / APP_RESUME / .. -->
            <xs:enumeration value="recede"/><!-- MB containing this screen is closed, either by showing another mb-screen, switching apps or terminating MB all together -->

            <!-- item-triggers: -->
            <xs:enumeration value="selected"/><!-- a line got selected -->
            <xs:enumeration value="unselected"/><!-- a line got de-selected -->
            <xs:enumeration value="changed"/><!-- user changed content of an input field (characters entered, deleted or changed) -->
            <xs:enumeration value="edit done"/> <!--user is done editing an input field-->
            <!--<xs:enumeration value="shown"/> -> in item context: menu-line is shown -->
            <!--<xs:enumeration value="recede"/> -> in item context: menu-line is scrolled out of view -->
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="timeoutTriggerType">
        <xs:restriction base="xs:string">
            <xs:pattern value="timeout .+"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="langType">
        <xs:restriction base="xs:string">
            <xs:enumeration value="en"/>
            <xs:enumeration value="de"/>
            <xs:enumeration value="el"/><!--greek-->
            <xs:enumeration value="es"/>
            <xs:enumeration value="fr"/>
            <xs:enumeration value="it"/>
            <xs:enumeration value="nl"/>
            <xs:enumeration value="pl"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="DialActionMinLenType">
        <xs:restriction base="xs:integer">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="100"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="SelectActionLineIndexType">
        <xs:restriction base="xs:integer">
            <xs:minInclusive value="1"/>
            <xs:maxInclusive value="100"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="TimerActionTimeoutType">
        <xs:restriction base="xs:string">
            <xs:pattern value="[1-9][0-9]*((ms)|(sec))?"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="UrlHandlingType">
            <xs:restriction base="xs:string">
                <xs:enumeration value="ignore"><xs:annotation><xs:documentation>
                    fire url but never mind the answer
                </xs:documentation></xs:annotation></xs:enumeration>
                <xs:enumeration value="show"><xs:annotation><xs:documentation>
                    Expect Minibrowser-Menu or Dialog as answer, if it really is one of the two: show it
                    If answer is an update: apply it, if it changes the current menu the view will adapt.
                    Maybe in future also open Web-view on color-phones when answer is an html?
                </xs:documentation></xs:annotation></xs:enumeration>
                <xs:enumeration value="replace"><xs:annotation><xs:documentation>
                    Just like show but replace the currently shown document with the new one, so
                    that it gets replaced in history stack. A back-trigger won't open the replaced
                    document but instead the last one that wasn't replaced or exits the minibrowser
                    when none can be found.
                </xs:documentation></xs:annotation></xs:enumeration>
            </xs:restriction>
    </xs:simpleType>
    <xs:simpleType name="TriggerForType">
            <xs:restriction base="xs:string">
                <xs:enumeration value="menu"><xs:annotation><xs:documentation>
                    triggers all automated-actions for given trigger that are defined for this screen
                </xs:documentation></xs:annotation></xs:enumeration>
                <xs:enumeration value="item"><xs:annotation><xs:documentation>
                    triggers all automated-actions for given trigger that are defined for the currently focused item
                </xs:documentation></xs:annotation></xs:enumeration>
            </xs:restriction>
    </xs:simpleType>
</xs:schema>
