
// Iieo?eou iieiia eiy iauaeoa iaoaaaiiuo
function getFullMDName(mdObj)
{
    if(!mdObj)
        return "no object"
    var names = []
    while(true)
    {
        names.unshift(mdObj.name)
        var className = mdObj.mdclass.name(1)
        if(!className.length || !mdObj.parent)
        {
            names.unshift(mdObj.container.identifier)
            break
        }
        names.unshift(className)
        mdObj = mdObj.parent
    }
    return names.join('.')
}

// Aica?auaao ?eoaaiia eiy aey ninoiyiey ioia?a?aiey
function state(s)
{
    switch(s)
    {
        case 1:
            return 'vsDock'
        case 2:
            return 'vsFloat'
        case 4:
            return 'vsMDI'
        case 8:
            return 'vsHardDock'
        case 16:
          return 'vsHiding'
      default:
            return s
   }
}
// Aica?auaao ?eoaaiia eiy aey iiei?aiey ioia?a?aiey
function placement(s)
{
    switch(s)
    {
        case 1:
            return 'vpLeft'
        case 2:
            return 'vpTop'
        case 4:
            return 'vpRight'
        case 8:
            return 'vpBottom'
        case 16:
          return 'vpCenter'
        case 32:
          return 'vpTabbed'
      default:
            return s
   }
}

// Auaia eiou ia ioia?a?aiee e aai ai?a?ieo ioia?a?aiee
function printView(view, indent)
{
    Message(indent + "id = " + view.id, mExc1)
    Message(indent + " Title = " + view.title)
    Message(indent + " HWND = 0x" + view.hwnd.toString(16))
    Message(indent + " wndClass = " + view.wndClass)
    Message(indent + " container = " + view.isContainer)
    var pos = view.position()
    Message(indent + " pos.state = " + state(pos.state))
    Message(indent + " pos.placement = " + placement(pos.placement))
    var parent = view.parent
    if(parent)
        Message(indent + " parent id = " + parent.id)
   
    var childs = view.enumChilds()
    Message(indent + " childs = " + childs.count)
    for(var k = 0; k < childs.count; k++)
        printView(childs.item(k), indent + '\t')
}

// ?ania?aoea MDI ioia?a?aiee
function macrosPrintMdiViews()
{
    var mdiWnds = windows.mdiView.enumChilds()
    Message("Mdi windows=" + mdiWnds.count)
    for(var k = 0, c = mdiWnds.count; k < c; k++)
        printView(mdiWnds.item(k), '')
}
// ?ania?aoea anao ioia?a?aiee
function macrosPrintViewsFromRoot()
{
    printView(windows.mainView, "")
}
// I?iaa?ea aeoeaiiai e oieoniiai ioia?a?aiey
function macrosTestActiveView()
{
    // Aeoeaiia e oieoniia ioia?a?aiea iiaoo ioee?aouny. Iai?eia?, anee oieon a no?iea iienea a noaiaa?oiii ooeaa?a
    Message("Active view")
    printView(windows.getActiveView(), '')
    Message("Focused view")
    printView(windows.getFocusedView(), '')
}
// I?iaa?ea ?acee?iuo naienoa aeoeaiiai ioia?a?aiey
function macrosOestViewMD()
{
    var v = windows.getActiveView()
    printView(v, '')
    var text = getFullMDName(v.mdObj)
    var mdProp = v.mdProp
    if(mdProp)
    {
        var n = mdProp.name(1)
        text += "::" + n
        if(n == "Iaeao")
            text += " (" + toV8Value(v.mdObj.property("OeiIaeaoa")).presentation() + ")"
    }
    Message(text)
    var obj = v.getObject()
    if(obj)
        Message("object - " + toV8Value(obj).typeName(1))
}

function printMdObj(mdObj, indent, text)
{
    // Iieo?ei e iiea?ai eeann iauaeoa
    var mdc = mdObj.mdclass
    text.push(indent + "mdclass " + mdc.name(1))
    // Ia?aaa?ai naienoaa iauaeoa. Eiee?anoai ainooiiuo naienoa iauaeoa
    // ii?aaaeyaony a aai eeanna. Naie naienoaa iauaeoa iieo?a?ony iaoiaii
    // property(eiaaen), aaa eiaaen ii?ao auou - ii?yaeiaui iiia?ii naienoaa (n ioey)
    // eee iacaaieai naienoaa, eee no?ieie n aoeaii naienoaa
    for(var i = 0, c = mdc.propertiesCount; i < c; i++)
    {
        var mdProp = mdc.propertyAt(i)
        var propVal = toV8Value(mdObj.property(i))
        if (propVal.presentation() == "IaecaanoiueIauaeo") {
            //toV8Value(mdRefValue).toStringInternal().split("\n")
            text.push(indent + " prop " + mdProp.name(1) + " " + mdProp.id + " = " + propVal.toStringInternal().split("\n"))
        } else {
            text.push(indent + " prop " + mdProp.name(1) + " " + mdProp.id + " = " + propVal.presentation())
        }
        if (mdProp.name(1)=="Eiy" && propVal.presentation()=="Oi?aaeaieaOi?aiauiI?aai?eyoeaiAeyOe?aeiu"){
            try {
                Message(""+propVal )
            } catch (e) {
                Message(""+e.description)
            }
            
        }
    }
    // Ia?aae?aai eeannu iioiieia (iai?eia? o Aieoiaioa yoi ?aeaeceou, Oaaee?iua?anoe, Oi?iu)
    for(var i = 0; i < mdc.childsClassesCount; i++)
    {
        var childMdClass = mdc.childClassAt(i)
        // Iiea?ai iacaaiea ia ?onneii ycuea ai iii?anoaaiiie oi?ia
        text.push(indent + childMdClass.name(1, true))
        // Oaia?u ia?aaa?ai iioiieia yoiai eeanna.
        for(var chldidx = 0, c = mdObj.childObjectsCount(i); chldidx < c; chldidx++)
            printMdObj(mdObj.childObject(i, chldidx), indent + "\t", text)
    }
}

function macrosTestViewMetadata() {
    text = []
    printMdObj(metadata.current.rootObject, "", text)
}