;************************************************************
;*   Form class library                                     *
;*                                                          *
;*   This file is part of Fresh base library                *
;*   This is base window class for "Fresh" created project  *
;*                                                          *
;*   (C)2003, 2004 John Found                               *
;************************************************************






;;*********************************************************************************************
;; Main window procedure for 'TForm' window class.
;;*********************************************************************************************
;winproc FormMessageProc
;begin
;        push    ebx edi esi
;        mov     ebx, [.wmsg]
;
;ondefault
;        invoke  DefWindowProc, [.hwnd],[.wmsg],[.wparam],[.lparam]
;        pop     esi edi ebx
;        return
;
;;------------------------------------------------------------------------
;onmessage WM_SYSCOMMAND
;        mov     eax, [.wparam]
;        and     eax, $fff0
;
;        cmp     eax, SC_KEYMENU
;        jne     .ondefault
;
;        invoke  GetParent, [.hwnd]
;        mov     ebx, eax
;        test    eax, eax
;        jnz     .resendmessage
;
;; Get the main application window.
;        mov     eax, [Application]
;        mov     eax, [eax+TApplication.MainWindow]
;        test    eax, eax
;        jz      .ondefault
;
;        cmp     eax, [.hwnd]
;        je      .ondefault
;
;        mov     ebx, eax
;
;        invoke  GetMenu, [.hwnd]
;        test    eax, eax
;        jnz     .ondefault
;
;        invoke  GetFocus
;        mov     [hLastBeforeMenu], eax
;
;        invoke  SetFocus, ebx
;
;.resendmessage:
;        invoke  SendMessage, ebx, [.wmsg], [.wparam], [.lparam]
;
;        xor     eax, eax
;        pop     esi edi ebx
;        return
;
;;------------------------------------------------------------------------
;onmessage WM_ERASEBKGND
;locals
;  .rect    RECT
;endl
;        lea     eax, [.rect]
;        invoke  GetClientRect, [.hwnd], eax
;
;        invoke  GetSysColor, COLOR_BTNFACE
;
;.colorok:
;        and     eax, $ffffff
;        invoke  CreateSolidBrush, eax
;        push    eax
;        lea     ecx, [.rect]
;        invoke  FillRect, [.wparam], ecx, eax
;        invoke  DeleteObject ; from the stack.
;        xor     eax, eax
;        inc     eax
;        pop     esi edi ebx
;        return
;
;;------------------------------------------------------------------------
;onmessage WM_CLOSE
;
;        mov     eax, [Application]
;        mov     eax, [eax+TApplication.MainWindow]
;        cmp     eax, [.hwnd]
;        jne     .ondefault
;
;        invoke  PostQuitMessage, 0
;        jmp     .ondefault
;
;;------------------------------------------------------------------------
;onmessage WM_EXITMENULOOP
;        cmp     [hLastBeforeMenu], 0
;        je      @f
;
;        invoke  SetFocus, [hLastBeforeMenu]
;@@:
;        xor     eax, eax
;        mov     [hLastBeforeMenu], eax
;        pop     esi edi ebx
;        return
;
;endwp
;
;
;
;proc GetFocusedControl, .hwnd
;begin
;        push    esi ebx
;        invoke  GetFocus
;        mov     esi, eax
;
;.parentloop:
;        mov     ebx, eax
;        invoke  GetParent, eax
;        test    eax, eax
;        jnz     .parentloop
;
;;        xor     eax, eax     ; eax is zero here...
;        cmp     ebx, [.hwnd]
;        jne     .endfocused
;        mov     eax, esi
;.endfocused:
;        pop     ebx esi
;        return
;endp
;
;
;;*********************************************************************************************
;; Shows given form in modal form.
;; Returns modal result
;; This is first version so behaviour is not very proper.
;;*********************************************************************************************
;
;proc ShowModal, .hwnd, .flags
;
;.rect RECT
;
;        begin
;        push    esi edi ebx
;
;        invoke  GetFocus
;        push    eax      ; the parameter for SetFocus at the end of the procedure.
;
;        lea     eax, [.rect]
;        invoke  GetWindowRect, [.hwnd], eax
;
;        mov     esi, [.rect.left]
;        mov     edi, [.rect.top]
;
;        test    [.flags], MSF_HCENTER
;        jz      @f
;
;        invoke  GetSystemMetrics, SM_CXSCREEN
;        sub     eax, [.rect.right]
;        add     eax, [.rect.left]
;        sar     eax,1
;        mov     esi, eax
;@@:
;        test    [.flags], MSF_VCENTER
;        jz      @f
;
;        invoke  GetSystemMetrics, SM_CYSCREEN
;        sub     eax, [.rect.bottom]
;        add     eax, [.rect.top]
;        sar     eax,1
;        mov     edi, eax
;
;@@:
;        invoke  SendMessage, [.hwnd], WM_INITDIALOG, 0, 0
;        invoke  SetWindowPos, [.hwnd], HWND_TOP, esi, edi, 0, 0, SWP_NOSIZE
;        invoke  ShowWindow, [.hwnd], SW_SHOW
;;        invoke  SendMessage, [.hwnd], AM_CHILDRESIZED, 0, 0
;
;        invoke  GetWindow, [.hwnd], GW_OWNER
;        mov     ebx, eax
;
;; Disables window owner and all other windows owned by window owner.
;
;        invoke  EnableWindow, ebx, FALSE
;        stdcall EnableAllOwnedWindows, ebx, FALSE       ; This is useless if all top level windows
;                                                        ; are TForm, but it is important if not...
;
;        invoke  EnableWindow, [.hwnd], TRUE              ; IMPORTANT: re-enable modal window.
;
;        invoke  GetNextDlgTabItem, [.hwnd], NULL, FALSE
;        test    eax, eax
;        jz      @f
;        invoke  SetFocus, eax
;@@:
;        invoke  SetProp, [.hwnd], [propModalResult], MR_NONE
;
;; Special message loop for modal window. It not finish until window becomes invisible.
;.modalloop:
;        call    ProcessMessages
;
;        invoke  IsWindowVisible, [.hwnd]
;        test    eax,eax
;        jz      .endloop
;
;        invoke  GetProp, [.hwnd], [propModalResult]
;        test    eax,eax              ; mrNone = 0
;        jnz     .endloop
;
;        invoke  SendMessage, [.hwnd], AM_ONIDLE, 0, 0
;
;        invoke  WaitMessage
;        jmp     .modalloop
;
;.endloop:
;        stdcall EnableAllOwnedWindows, ebx, TRUE
;        invoke  EnableWindow, ebx, TRUE
;        invoke  ShowWindow, [.hwnd], SW_HIDE
;
;        invoke  SetFocus                       ; the parameter is in stack
;
;        invoke  GetProp, [.hwnd], [propModalResult]
;        pop     ebx edi esi
;        return
;endp
;
;
;;-------------------------------------------------------------
;; Enables or disables all windows owned by specifyed window.
;;
;; fEnable - TRUE = enable
;;           FALSE = disable
;;-------------------------------------------------------------
;proc EnableAllOwnedWindows, .hwnd, .fEnable
;        begin
;
;        mov     eax, _EnableOwnedProc
;        cmp     [.fEnable], FALSE
;        jne     @f
;        mov     eax, _DisableOwnedProc
;@@:
;        invoke  EnumWindows, eax, [.hwnd]
;        return
;endp
;
;
;; callback procedure used in EnableAllOwnedWindows
;proc _EnableOwnedProc, .hwnd, .owner
;begin
;
;        invoke  GetWindow, [.hwnd], GW_OWNER
;        cmp     eax, [.owner]
;        jne     .ready
;        invoke  EnableWindow, [.hwnd], TRUE
;
;.ready:
;        mov     eax, 1
;        return
;endp
;
;
;; callback procedure used in EnableAllOwnedWindows
;proc _DisableOwnedProc, .hwnd, .owner
;begin
;        invoke  GetWindow, [.hwnd], GW_OWNER
;
;        cmp     eax, [.owner]
;        jne     .ready
;        invoke  EnableWindow, [.hwnd], FALSE
;.ready:
;        mov     eax, 1
;        return
;endp