diff --git a/src/Runtime/XSharp.VFP.UI.Tests/MenuDefinitionTests.prg b/src/Runtime/XSharp.VFP.UI.Tests/MenuDefinitionTests.prg index 596127d823..555b548818 100644 --- a/src/Runtime/XSharp.VFP.UI.Tests/MenuDefinitionTests.prg +++ b/src/Runtime/XSharp.VFP.UI.Tests/MenuDefinitionTests.prg @@ -99,6 +99,64 @@ BEGIN NAMESPACE XSharp.VFP.UI.Tests END TRY END METHOD + // CNTBAR() is the highest bar number, not how many bars were defined + [Fact, Trait("Category", "MenuFunctions")]; + METHOD CntBarReturnsTheHighestBarNumber AS VOID + DEFINE POPUP mdt_pop5 + DEFINE BAR 1 OF mdt_pop5 PROMPT "\ +/// Returns the number of bars of a popup. VFP reports the highest bar number given in +/// DEFINE BAR, so a separator and a gap in the numbering count as well. +/// Returns 0 for an empty or unknown popup. +/// — name of the Popup. +/// +[FoxProFunction("CNTBAR", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Full, FoxCriticality.Medium)]; +FUNCTION CNTBAR( cPopupName AS STRING ) AS INT + LOCAL nCount := 0 AS INT + IF String.IsNullOrEmpty( cPopupName ) + RETURN 0 + ENDIF + // the separators are items of the popup but not Bar objects, so go through the items + IF __VFPFindPopupContainer( cPopupName ) IS System.Windows.Forms.ToolStrip VAR oStrip + LOCAL i AS INT + FOR i := 0 TO oStrip:Items:Count - 1 + LOCAL nNumber AS INT + // a bar created from code without a numeric name counts by its position + IF ! Int32.TryParse( oStrip:Items[i]:Name, OUT nNumber ) + nNumber := i + 1 + ENDIF + nCount := Math.Max( nCount, nNumber ) + NEXT + ENDIF + RETURN nCount + +/// +/// Returns the number of pads of a menu. Returns 0 for an empty or unknown menu. +/// — name of the Menu. +/// +[FoxProFunction("CNTPAD", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Full, FoxCriticality.Medium)]; +FUNCTION CNTPAD( cMenuName AS STRING ) AS INT + IF String.IsNullOrEmpty( cMenuName ) + RETURN 0 + ENDIF + LOCAL oMenu := Menu.Find( cMenuName ) AS Menu + IF oMenu != NULL + RETURN oMenu:PadCount + ENDIF + RETURN 0 + /// The prompt of a bar or pad the way PRMBAR() and PRMPAD() report it. INTERNAL STATIC CLASS MenuPrompt diff --git a/src/Runtime/XSharp.VFP/UI/UIAndWindows.prg b/src/Runtime/XSharp.VFP/UI/UIAndWindows.prg index 82505cdbae..1336822ef1 100644 --- a/src/Runtime/XSharp.VFP/UI/UIAndWindows.prg +++ b/src/Runtime/XSharp.VFP/UI/UIAndWindows.prg @@ -4,16 +4,6 @@ // See License.txt in the project root for license information. // -/// -[FoxProFunction("CNTBAR", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Stub, FoxCriticality.Medium)]; -FUNCTION CntBar(cPopupName AS STRING) AS INT - THROW NotImplementedException{} - -/// -[FoxProFunction("CNTPAD", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Stub, FoxCriticality.Medium)]; -FUNCTION CntPad(cMenuName AS STRING) AS INT - THROW NotImplementedException{} - /// [FoxProFunction("COL", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Full, FoxCriticality.Medium)]; FUNCTION Col() AS INT