// Author: Wil van Antwerpen // // Special thanks to Stuart Booth and Michael Kurz for helping me out with the correct API calls // to use. // // This package needs at least VDF7 to add the transparancy, otherwise a plain bitmapcontainer // is included by the compiler // // (c) 2001, Antwise Solutions / VDF-GUIdance // // 10-23-2001 WvA: The bitmap was not repainted when a new bitmap was set. // Added an object existincy check in the userpaint method to avoid errors if no // bitmapfile is selected. // // // #IF (FMAC_VERSION < 7) Class vcBitmapContainer Is a BitmapContainer End_Class // vcBitmapContainer #ELSE Use RgbColor.pkg Use DfShape.pkg Use cImageList.pkg Use mBitmapStuff.pkg Use vWin32fh.pkg //BOOL ImageList_Draw( // // HIMAGELIST himl, // handle to the image list // int i, // index of the image to draw // HDC hdcDst, // handle to the destination device context // int x, // x-coordinate to draw at // int y, // y-coordinate to draw at // UINT fStyle // drawing style // ); Define vILD_NORMAL For |CI$0000 Define vILD_TRANSPARENT For |CI$0001 //define LR_LOADFROMFILE for |CI$0010 Define LR_CREATEDIBSECTION For |CI$2000 External_function vWin32_ImageList_Draw "ImageList_Draw" comctl32.dll Handle hImageList Integer iIndex ; Handle hDC Integer iXPos Integer iYPos Integer iStyle Returns Integer Object voRGBColorSystem Is A RgbColorSystem End_Object // voRGBColorSystem // Register_Function psFileName Returns String Register_Function piBitmapHeight Returns Integer Register_Function piBitmapWidth Returns Integer // **WvA // These functions need to be defined in the case no workspace is used #IF (FMAC_VERSION < 8) Register_Function CurrentProgramPath Returns String Register_Function CurrentBitmapPath Returns String #ELSE Register_Function psProgramPath Returns String Register_Function psBitmapPath Returns String #ENDIF // This subclass should only be used from within the vBitmap class as it expects to be a child object of // an instance of the vBitmap class. Class cvBitmapImageList Is A cImageList Procedure Construct_Object Forward Send Construct_Object Set piMaxImages To 1 End_Procedure // Construct_Object Procedure onCreate String sFileName Integer iIndex iColor Move (Trim(psFileName(parent(Self)))) To sFileName If (sFileName <> "") Begin Get piTransparentColor To iColor Get AddTransparentImage sFileName iColor To iIndex If (iIndex = -1) Error 300 ("Transparent image ["+sFileName+"] could not be found") End End_Procedure // onCreate Procedure doCreate Integer cx cy iGrowBy Move (piBitmapHeight(parent(Self))) To cy Move (piBitmapWidth(parent(Self))) To cx Set piImageHeight To cy Set piImageWidth To cx Forward Send doCreate End_Procedure // doCreate End_Class // vcBitmapImageList Class cvBitmapContainer Is A ShapeControl Procedure Construct_Object Forward Send Construct_Object Property Integer phoImageList 0 Property Integer pbAutoSize True Property Integer piBitmapHeight 0 Property Integer piBitmapWidth 0 Property String psBitmap "" Property String psFileName "" // includes a full path Property Integer piTransparentColor (rgb(191,191,191)) // default is clBtnColor End_Procedure // Construct_Object // A function to retrieve the full pathname of the bitmap. // If a workspace is defined it will first look in the programpath and // if the icon is not present it will look into the bitmappath after that. // When no workspacename is defined the normal bitmapname is returned and // the program assumes that the icon resides in the same folder as the program. // Or it will Function BitMapFullPathName String sBitmap Returns String String sBitmapFullPathName String sBitmapPath Integer bFile_Exists String sDirSeperator // this is "\" for windows, or "/" for unix #IF (FMAC_VERSION < 8) If ghoWorkSpace Begin Move (sysconf(SYSCONF_DIR_SEPARATOR)) To sDirSeperator Get CurrentProgramPath Of ghoWorkSpace To sBitmapPath Move (sBitmapPath+sDirSeperator+sBitmap) To sBitmapFullPathName Get vFilePathExists sBitmapFullPathName To bFile_Exists If bFile_Exists Function_Return sBitmapFullPathName Else Begin Get CurrentBitmapPath Of ghoWorkSpace To sBitmapPath Move (sBitmapPath+sDirSeperator+sBitmap) To sBitmapFullPathName Get vFilePathExists sBitmapFullPathName To bFile_Exists If bFile_Exists Function_Return sBitmapFullPathName End End #ELSE If ghoApplication Begin Move (sysconf(SYSCONF_DIR_SEPARATOR)) To sDirSeperator Get psProgramPath Of (phoWorkSpace(ghoApplication)) To sBitmapPath Move (sBitmapPath+sDirSeperator+sBitmap) To sBitmapFullPathName Get vFilePathExists sBitmapFullPathName To bFile_Exists If bFile_Exists Function_Return sBitmapFullPathName Else Begin Get psBitmapPath Of (phoWorkSpace(ghoApplication)) To sBitmapPath Move (sBitmapPath+sDirSeperator+sBitmap) To sBitmapFullPathName Get vFilePathExists sBitmapFullPathName To bFile_Exists If bFile_Exists Function_Return sBitmapFullPathName End End #ENDIF // does not exist or no workspace available, search in DFPATH Get_File_Path sBitmap To sBitmap Function_Return sBitmap End_Function // BitmapFullPathName Procedure doRedrawBitmap Handle hWnd Integer iVoid Get Window_Handle To hWnd Move (InvalidateRect(hWnd,0,TRUE)) To iVoid Move (UpdateWindow (hWnd)) To iVoid End_Procedure // doRedrawBitmap Procedure Set Bitmap String sFileName Integer iChannel iX iY hoSelf hoOldSelf hoImageList iSize Set Dynamic_Update_State To False Set psBitmap To sFileName Get BitmapFullPathname sFileName To sFileName Get APIBitmapSize sFileName To iSize Move (Hi(iSize)) To iY Move (Low(iSize)) To iX Set psFileName To sFileName Set piBitmapHeight To iY Set piBitmapWidth To iX Get phoImageList To hoImageList If (hoImageList <> 0) Send Destroy_Object To hoImageList // Get Create U_vcBitmapImageList To hoSelf Object oImageList Is A cvBitmapImageList Move Self To hoImageList End_Object Set phoImageList To hoImageList Set Dynamic_Update_State To True //Send doRedrawBitmap End_Procedure // Set Bitmap Function Bitmap Returns String Function_Return (psBitmap(Self)) End_Function // Bitmap // The page is executed before the UserPaint, so this can be used to set up // an appropriate imagelist Procedure Page Integer bState Integer iBackColor iY iX hoImageList Forward Send Page bState If (bState) Begin Get phoImageList To hoImageList If (hoImageList <> 0) Begin Delegate Get Color To iBackColor Get ColorIdToRGB Of voRGBColorSystem iBackColor To iBackColor Set piBackColor Of hoImageList To iBackColor Get piImageWidth Of hoImageList To iX Get piImageHeight Of hoImageList To iY Set GuiSize To iY iX Send Adjust_Logicals End End End_Procedure // Page Procedure UserPaint Handle hDC Integer hoImages iVoid Handle hImageList Get phoImageList To hoImages If (hoImages <> 0) Begin Get phImageList Of hoImages To hImageList If (hImageList <> 0) Begin Move (vWin32_ImageList_Draw(hImageList,0,hDC,0,0,vILD_NORMAL )) To iVoid End End End_Procedure End_Class #ENDIF