//**************************************************************************** // $Module type: Package // $Module name: cRDCComboform.pkg // // $Author : Nils Svedmyr, RDC Tools International. // Copyright (c) 2014 RDC Tools International // E-mail : support@rdctools.com // Web-site : http://www.rdctools.com // // Created : 2014-03-17 @ 12:35 (Military date format - Year-Month-Day) // // Portions by : Raveen Sundram, Excellent Software Ltd // The auto-size combo width logic was developed by Raveen. // // The code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; // without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. // This is free software; you can redistribute it and/or modify it under the terms of the // GNU Lesser General Public License - see the "GNU Lesser General Public License.txt" // in the help folder for more details. // //**************************************************************************** Use Windows.pkg // Used by the "Page" message below to show // a focus rectangle around ComboForm and Checkbox objects. #IFNDEF WM_CHANGEUISTATE Define WM_CHANGEUISTATE For |CI$0127 Define WM_UPDATEUISTATE For |CI$0128 Define WM_QUERYUISTATE For |CI$0129 Define UIS_SET For 1 Define UIS_CLEAR For 2 Define UIS_INITIALIZE For 3 Define UISF_HIDEFOCUS For |CI$1 Define UISF_HIDEACCEL For |CI$2 Define UISF_ACTIVE For |CI$4 #ENDIF Class cComboFormIdleHandler is a cIdleHandler Procedure Construct_Object Forward Send Construct_Object End_Procedure Procedure OnIdle Delegate Send DoUpdate End_Procedure End_Class Class cRDCComboForm is a ComboForm Procedure Construct_Object Forward Send Construct_Object { MethodType=Property InitialValue=True } { Description='Autosizes the combo list to fit the widest combo item' } Property Boolean pbAutoListWidth True {Description="This will shadow the label if the form itself has its Enabled_State=False" { MethodType=Property InitialValue=True } { Category=Appearance } Property Boolean pbAutoShadowLabelObject True { MethodType=Property InitialValue=False } { Category=Appearance } Property Boolean pbAutoEnable False Set Label_Col_Offset to 2 { Visibility=Private } Property Boolean pbEnabled True Set Label_Justification_Mode to JMode_Right Property Handle phoIdleHandler (Create(Self, RefClass(cComboFormIdleHandler))) End_Procedure Procedure End_Construct_Object Boolean bAutoShadowLabelObject String sTooltip sStatus_Help Get pbAutoShadowLabelObject to bAutoShadowLabelObject If (bAutoShadowLabelObject = True) Begin Set Private.Label_Shadow_Display_Mode to TBSHADOW_ON_LOCAL End Forward Send End_Construct_Object #IF (!@ > 150) Get psToolTip to sTooltip Get Status_Help to sStatus_Help If (sTooltip = "" and sStatus_Help <> "") Begin Set psToolTip to sStatus_Help End Else If (sTooltip <> "" and sStatus_Help = "") Begin Set Status_Help to sTooltip End #ENDIF Set pbEnabled of (phoIdleHandler(Self)) to (pbAutoEnable(Self)) End_Procedure { Visibility=Private } Procedure DoUpdate If (pbAutoEnable(Self) = False) Begin Procedure_Return End Set Enabled_State to (IsEnabled(Self)) End_Procedure { MethodType=Event } Function IsEnabled Returns Boolean Boolean bEnabled Get pbEnabled to bEnabled Function_Return bEnabled End_Function // Enable the idle handler timer when the object is activated Procedure Activating Forward Send Activating Set pbEnabled of (phoIdleHandler(Self)) to True End_Procedure // Disable the idle handler when the object is deactivated Procedure Deactivating Set pbEnabled of (phoIdleHandler(Self)) to False Forward Send Deactivating End_Procedure // To "un-select" the text in the comboform on startup Procedure DoApplyAnchors Integer Arg1 Integer Arg2 Integer iStart iEnd If (Focus(Desktop)=Self) Begin Get SelStart to iStart Get SelEnd to iEnd End Forward Send DoApplyAnchors Arg1 Arg2 Send SetSel iStart iEnd End_Procedure // Message that will drop down the list without the user clicking it, // so you can send "DropDownList" to the combo to show the list. Procedure DropDownList Send Windows_Message CB_SHOWDROPDOWN 1 0 End_Procedure Procedure SizeComboWidth Integer iCount iItem iTextExt iRows iWd iNewWd iVertAdj String sVal // Initialise Width Set ListWidth to 0 Send DoSetListWidth Get ListRowCount to iRows Get Combo_Item_Count to iCount // Vertical scroll-bar adjustment is needed Move (iRows > 0 and iCount > iRows) to iVertAdj If (iVertAdj) Begin Move (GetSystemMetrics(SM_CXVSCROLL)+GetSystemMetrics(SM_CXEDGE)) to iVertAdj End Else Begin Move (GetSystemMetrics(SM_CXEDGE)) to iVertAdj End // Calculate New Width Decrement iCount For iItem from 0 to iCount Get Combo_Value iItem to sVal If (sVal <> "") Begin Get Text_Extent sVal to iTextExt Move (Low(iTextExt) + iVertAdj) to iWd If (iWd > iNewWd) Begin Move (iWd + GetSystemMetrics(SM_CXFIXEDFRAME) + GetSystemMetrics(SM_CXEDGE)) to iNewWd End End Loop // Set New Width Set ListWidth to iNewWd Send DoSetListWidth End_Procedure Procedure Combo_Add_Item String sValue Forward Send Combo_Add_Item sValue If (pbAutoListWidth(Self)) Begin Send SizeComboWidth End End_Procedure Procedure Combo_Fill_List Forward Send Combo_Fill_List If (pbAutoListWidth(Self)) Begin Send SizeComboWidth End End_Procedure // Fix for a bug when using manifest files & running Vista and above. // The bug being that the focus rectangle doesn't show. Procedure Page Integer iPageObject Handle hWnd Integer iRet iState Forward Send Page iPageObject If (iPageObject) Begin Get Window_Handle to hWnd If (hWnd) Begin Move (SendMessage(hWnd, WM_QUERYUISTATE, 0, 0)) to iRet If (iRet iand UISF_HIDEFOCUS) Begin Move (UIS_CLEAR + (UISF_HIDEFOCUS * 65536)) to iState Move (SendMessage(hWnd, WM_UPDATEUISTATE, iState, 0)) to iRet End End End // To "un-select" the text in the comboform If (iPageObject = 1 and Focus(Desktop) <> Self) Begin Send SetSel 0 0 End End_Procedure End_Class