; _______________________________________________________________________________________
;|                                                                                       |
;| ..::FreshLib::..  Free, open source. Licensed under "BSD 2-clause" license."          |
;|_______________________________________________________________________________________|
;
;  Description: Actions management library.
;
;  Target OS: Any
;
;  Dependencies:
;
;  Notes: TActionList is set of TAction that provides some common functionality
;         for example the common icons. It is implemented as a parent object for
;         several TAction objects.
;_________________________________________________________________________________________

module "TActionList"


object TActionList, TObject

  ._img_icons dd ?
  ._icon_size  dd ?

  param .ImgIcons, ._img_icons, .SetIcons
  param .IconSize, ._icon_size, .SetIconSize

  method .Create, .parent

  method .SetIcons, .value
  method .SetIconSize, .value

  method .UpdateActions

endobj



method TActionList.Create
begin
        inherited [.parent]
        set     [.self], TActionList:IconSize, 16
        return
endp


method TActionList.SetIconSize
begin
        push    eax ecx

        mov     ecx, [.self]
        mov     eax, [.value]
        xchg    eax, [ecx+TActionList._icon_size]
        cmp     eax, [ecx+TActionList._icon_size]
        je      .finish

        exec    ecx, TActionList:UpdateActions

.finish:
        pop     ecx eax
        return
endp



method TActionList.UpdateActions
begin
        pushad

        get     edx, [.self], TActionList:Children
        test    edx, edx
        jz      .finish

        mov     ecx, [edx+TArray.count]

.loop:
        dec     ecx
        js      .finish

        exec    [edx+TArray.array+4*ecx], TAction:UpdateControls
        jmp     .loop

.finish:
        popad
        return
endp



method TActionList.SetIcons
begin
        pushad

; the .value parameter points to a PNG image in the memory.
        mov     esi, [.self]

        get     ecx, esi, TActionList:ImgIcons
        jecxz   .old_ok

        stdcall DestroyImage, ecx

.old_ok:
        mov     eax, [.value]
        test    eax, eax
        jz      .new_ok

        stdcall CreateImagePNG, eax, [eax-4]

.new_ok:
        mov     [esi+TActionList._img_icons], eax

        exec    [.self], TActionList:UpdateActions
        popad
        return
endp


endmodule