File: n_imagelist.sru
Size: 12665
Date: Thu, 14 Jul 2022 19:26:58 +0200
$PBExportHeader$n_imagelist.sru
forward
global type n_imagelist from nonvisualobject
end type
end forward

global type n_imagelist from nonvisualobject autoinstantiate
end type

type prototypes
Function longptr ImageList_Create( &
   long cx, &
   long cy, &
   ulong flags, &
   long cInitial, &
   long cGrow &
   ) Library "comctl32.dll"

Function boolean ImageList_Destroy( &
   longptr himl &
   ) Library "comctl32.dll"

Function long ImageList_GetImageCount( &
   longptr himl &
   ) Library "comctl32.dll"

Function long ImageList_ReplaceIcon( &
   longptr himl, &
   long i, &
   longptr hicon &
   ) Library "comctl32.dll"

Function long ImageList_Add( &
   longptr himl, &
   longptr hbmImage, &
   longptr hbmMask &
   ) Library "comctl32.dll"

// PowerBuilder VM Function
Function long FN_ResGetBitmapID_100( &
   string lpImageName &
   ) Library "pbvm100.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_105( &
   string lpImageName &
   ) Library "pbvm105.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_110( &
   string lpImageName &
   ) Library "pbvm110.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_115( &
   string lpImageName &
   ) Library "pbvm115.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_120( &
   string lpImageName &
   ) Library "pbvm120.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_125( &
   string lpImageName &
   ) Library "pbvm125.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_126( &
   string lpImageName &
   ) Library "pbvm126.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_170( &
   string lpImageName &
   ) Library "pbvm170.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_190( &
   string lpImageName &
   ) Library "pbvm190.dll" Alias For "FN_ResGetBitmapID"

Function long FN_ResGetBitmapID_Any( &
   string lpImageName &
   ) Library "pbvm.dll" Alias For "FN_ResGetBitmapID"

end prototypes

type variables
Private:
Longptr il_hImageList

Public:
Constant Long ILC_COLOR    = 0      // 0x0000
Constant Long ILC_MASK     = 1      // 0x0001
Constant Long ILC_COLOR4   = 4      // 0x0004
Constant Long ILC_COLOR8   = 8      // 0x0008
Constant Long ILC_COLOR16  = 16     // 0x0010
Constant Long ILC_COLOR24  = 24     // 0x0018
Constant Long ILC_COLOR32  = 32     // 0x0020
Constant Long ILC_COLORDDB = 254    // 0x00FE
Constant Long ILC_PALETTE  = 2048   // 0x0800

end variables

forward prototypes
public function boolean of_destroy ()
public function long of_getimagecount ()
public function boolean of_create (long al_size, unsignedlong aul_flags)
public function string of_getstockbitmap (string as_imagename)
public function string of_pbvmname ()
public function long of_addbitmap (longptr al_bitmap)
public function long of_addicon (longptr al_icon)
public function long of_replaceicon (long al_index, longptr al_icon)
public function longptr of_gethandle ()
public subroutine of_sethandle (longptr al_handle)
public function string pbvmbitmapid (string as_imagename)
end prototypes

public function boolean of_destroy ();// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_Destroy
//
// PURPOSE:    This function destroys the ImageList.
//
// RETURN:     True=Success, False=Failure
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

If il_hImageList > 0 Then
   Return ImageList_Destroy(il_hImageList)
Else
   Return True
End If

end function

public function long of_getimagecount ();// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_GetImageCount
//
// PURPOSE:    This function returns the number of images in the ImageList.
//
// RETURN:     Image count
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

If il_hImageList > 0 Then
   Return ImageList_GetImageCount(il_hImageList)
Else
   Return 0
End If

end function

public function boolean of_create (long al_size, unsignedlong aul_flags);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_Create
//
// PURPOSE:    This function creates the ImageList.
//
// ARGUMENTS:  al_size     - Width/Height of the images in pixels
//             aul_flags   - Creation flags
//
// RETURN:     True=Success, False=Failure
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Longptr  ll_hImageList
Boolean  lb_Return

ll_hImageList = ImageList_Create(al_Size, al_Size, aul_Flags, 0, 1)
If ll_hImageList > 0 Then
   il_hImageList = ll_hImageList
   lb_Return = True
Else
   il_hImageList = -1
   lb_Return = False
End If

Return lb_Return

end function

public function string of_getstockbitmap (string as_imagename);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_GetStockBitmap
//
// PURPOSE:    This function returns the ResourceID for named bitmaps.
//
// ARGUMENTS:  as_imagename   - Name of the Bitmap
//
// RETURN:     ResourceID
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return PBVMBitmapId(as_imagename)

end function

public function string of_pbvmname ();// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_PBVMName
//
// PURPOSE:    This function returns the name of the PBVM .dll file.
//
// RETURN:     The name of the file
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// 05/26/2015  RolandS     Updated for PB 12.6
// 02/10/2021  RolandS     Updated for PB 2019-R3
// -----------------------------------------------------------------------------

Environment le_env
String ls_vmname
Integer li_major, li_minor

GetEnvironment(le_env)

li_major = le_env.PBMajorRevision
li_minor = le_env.PBMinorRevision

choose case li_major
   case 10, 11, 12, 17
      choose case li_minor
         case 5
            ls_vmname = "pbvm" + String(li_major) + "5.dll"
         case 6
            ls_vmname = "pbvm" + String(li_major) + "6.dll"
         case else
            ls_vmname = "pbvm" + String(li_major) + "0.dll"
      end choose
   case 19
      If li_minor < 2 Then
         ls_vmname = "pbvm190.dll"
      Else
         ls_vmname = "pbvm.dll"
      End If
   case else
      ls_vmname = "pbvm.dll"
end choose

Return ls_vmname

end function

public function long of_addbitmap (longptr al_bitmap);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_AddBitmap
//
// PURPOSE:    This function adds a bitmap to the ImageList.
//
// ARGUMENTS:  al_bitmap   - Handle of the loaded bitmap
//
// RETURN:     Index of the added bitmap
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return ImageList_Add(il_hImageList, al_Bitmap, 0) + 1

end function

public function long of_addicon (longptr al_icon);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_AddIcon
//
// PURPOSE:    This function adds an icon to the ImageList.
//
// ARGUMENTS:  al_icon  - Handle of the loaded icon
//
// RETURN:     Index of the added icon
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return of_ReplaceIcon(-1, al_Icon)

end function

public function long of_replaceicon (long al_index, longptr al_icon);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_ReplaceIcon
//
// PURPOSE:    This function adds/replaces an icon in the ImageList.
//
// ARGUMENTS:  al_index    - Index to replace ( -1 means add to end )
//             al_icon     - Handle of the loaded icon
//
// RETURN:     Index of the added/replaced icon
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return ImageList_ReplaceIcon(il_hImageList, al_Index, al_Icon)

end function

public function longptr of_gethandle ();// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_GetHandle
//
// PURPOSE:    This function returns the ImageList handle.
//
// RETURN:     ImageList handle
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

Return il_hImageList

end function

public subroutine of_sethandle (longptr al_handle);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.of_SetHandle
//
// PURPOSE:    This function saves the existing ImageList handle for later use.
//
// ARGUMENTS:  al_handle   - Handle of the existing ImageList
//
// DATE        CHANGED BY  DESCRIPTION OF CHANGE / REASON
// ----------  ----------  -----------------------------------------------------
// 04/20/2012  RolandS     Initial coding
// -----------------------------------------------------------------------------

il_hImageList = al_handle

end subroutine

public function string pbvmbitmapid (string as_imagename);// -----------------------------------------------------------------------------
// SCRIPT:     n_imagelist.PBVMBitmapId
//
// PURPOSE:    This function returns PowerBuilder VM resource id for a named
//             bitmap.
//
// ARGUMENTS:  as_imagename   - The image name
//
// RETURN:     Resource ID
//
// DATE        PROG/ID     DESCRIPTION OF CHANGE / REASON
// ----------  --------    -----------------------------------------------------
// 07/01/2013  RolandS     Initial coding
// 07/19/2021  RolandS     Added PB 2019 & higher
// -----------------------------------------------------------------------------

Environment le_env
String ls_return
Long ll_index

GetEnvironment(le_env)

choose case le_env.PBMajorRevision
   case 10
      If le_env.PBMinorRevision = 5 Then
         ll_index = FN_ResGetBitmapID_105(as_imagename)
      Else
         ll_index = FN_ResGetBitmapID_100(as_imagename)
      End If
   case 11
      If le_env.PBMinorRevision = 5 Then
         ll_index = FN_ResGetBitmapID_115(as_imagename)
      Else
         ll_index = FN_ResGetBitmapID_110(as_imagename)
      End If
   case 12
      choose case le_env.PBMinorRevision
         case 5
            ll_index = FN_ResGetBitmapID_125(as_imagename)
         case 6
            ll_index = FN_ResGetBitmapID_126(as_imagename)
         case else
            ll_index = FN_ResGetBitmapID_120(as_imagename)
      end choose
   case 17
      ll_index = FN_ResGetBitmapID_170(as_imagename)
   case 19
      If le_env.PBMinorRevision < 2 Then
         ll_index = FN_ResGetBitmapID_190(as_imagename)
      Else
         ll_index = FN_ResGetBitmapID_Any(as_imagename)
      End If
   case else
      ll_index = FN_ResGetBitmapID_Any(as_imagename)
end choose

If ll_index = 0 Then
   SetNull(ls_return)
Else
   ls_return = String(ll_index)
End If

Return ls_return

end function

on n_imagelist.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_imagelist.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

event constructor;il_hImageList = -1

end event