; This macro aims to provide some limited use of the old visual editor
; with the new template engine, until the new one is created.


macro __define_one_property class, subtype, style, property {
common
  local ..txt, ..set, ..subtype

  match id==value, property \{

    ; class
    if class eq 'TForm'
      ..set = TForm.\#id\#.set
    else
      if class eq 'BUTTON'

        if subtype = 0  ; BS_PUSHBUTTON
          ..set = TButton.\#id\#.set
        end if

        if subtype = 2  ; BS_CHECKBOX
          ..set = TButton.\#id\#.set
        end if

      else

         if class eq 'EDIT'
           if (style and 4)  ;ES_MULTILINE
             ..set = TAsmEdit.\#id\#.set
           else
             ..set = TEdit.\#id\#.set
           end if
         else

           if class eq 'STATIC'
             ..set = TLabel.\#id\#.set
           else
             if class eq 'msctls_progress32'
               ..set = TProgress.\#id\#.set
             else
               if class eq 'SysTreeView32'
                 ..set = TTreeView.\#id\#.set
               end if
             end if
           end if
         end if
      end if
    end if


         dd ..set
         if value eqtype 2
            dd  value
         else
           if value eqtype 'A'
             dd  ..txt
           else
             dd value
           end if
         end if
    ..txt text value
  \}
}



macro Window  name, flags, walign, class, txt, style, styleEx, ID, left, top, width, height, [props] {
common
  local ..paramsize, ..prms, ..caption, ..name, ..subtype, ..txtalign, ..class, ..size, ..here, ..capset, ..alset

  ..subtype = style and $0f

  ..txtalign = 0
  ..alset = 0

  if ~name eq NONE
     name#.template#:
  end if

  ..class = vtables.TWindow
  ..size  = sizeof.TWindow
  ..capset = 0

  ; class
  if class eq 'TForm'
    ..class = vtables.TForm
    ..size  = sizeof.TForm
  else
    if class eq 'BUTTON'


      if ..subtype = 0  ; BS_PUSHBUTTON
        ..class = vtables.TButton
        ..size  = sizeof.TButton
        ..txtalign = dtfAlignCenter or dtfAlignMiddle
        ..alset = TButton.TextAlign.set
        ..capset = TButton.Caption.set
      end if

      if ..subtype = 2  ; BS_CHECKBOX
        ..class = vtables.TCheckbox
        ..size = sizeof.TCheckbox
        ..capset = TCheckbox.Caption.set
      end if

    else

       if class eq 'EDIT'
         if (style and 4)  ;ES_MULTILINE
           ..class = vtables.TAsmEdit    ; it is not good to use TAsmEdit, but we don't have light multiline edit.
           ..size = sizeof.TAsmEdit
           ..capset = TAsmEdit.Text.set
         else
           ..class = vtables.TEdit
           ..size = sizeof.TEdit
           ..capset = TEdit.Text.set
         end if
       else

         if class eq 'STATIC'
           ..class = vtables.TLabel
           ..size = sizeof.TLabel
           ..capset = TLabel.Caption.set
           ..alset = TLabel.TextAlign.set

           if ..subtype = 1     ; SS_CENTER
             ..txtalign = ..txtalign or dtfAlignCenter
           end if

           if ..subtype = 2     ; SS_RIGHT
             ..txtalign = ..txtalign or dtfAlignCenter
           end if

           if (style and $200) ;SS_CENTERIMAGE
             ..txtalign = ..txtalign or dtfAlignMiddle
           end if

         else
           if class eq 'msctls_progress32'
             ..class = vtables.TProgress
             ..size = sizeof.TProgress
           else
             if class eq 'SysTreeView32'
               ..class = vtables.TTreeView
               ..size = sizeof.TTreeView
             end if
           end if
         end if
       end if

    end if
  end if


  dd flags              ; flags - the values are the same
  dd ..size
  dd ..class
  dd ..paramsize        ;parameters size

  ; name
  if name eq NONE
        dd  ..name
  else
        dd  name
  end if


..prms:
        dd      TWindow.x.set
        dd      left

        dd      TWindow.y.set
        dd      top

        dd      TWindow.width.set
        dd      width

        dd      TWindow.height.set
        dd      height

        if ..capset
          dd      ..capset
          dd      ..caption
        end if

  if (style and $10000000) <> 0   ; WS_VISIBLE
        dd      TWindow.Visible.set
        dd      TRUE
  end if

  if ..txtalign
        dd      ..alset
        dd      ..txtalign
  end if

forward
       __define_one_property class, ..subtype, style, props

common
       dd  -1   ; end of params

  if name eq NONE
    ..name dd ?
  else
    name dd ?
  end if

  ..paramsize = $ - ..prms

  ..caption text txt

}
