Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/Runtime/XSharp.VFP.UI.Tests/MenuDefinitionTests.prg
Original file line number Diff line number Diff line change
Expand Up @@ -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 "\<Open"
DEFINE BAR 2 OF mdt_pop5 PROMPT "\-"
DEFINE BAR 5 OF mdt_pop5 PROMPT "Exit"
DEFINE POPUP mdt_pop6
DEFINE BAR 10 OF mdt_pop6 PROMPT "Ten"
DEFINE BAR 20 OF mdt_pop6 PROMPT "Twenty"
TRY
Assert.Equal(5, (INT) CNTBAR("mdt_pop5"))
Assert.Equal(5, (INT) CNTBAR("MDT_POP5"))
Assert.Equal(20, (INT) CNTBAR("mdt_pop6"))
FINALLY
RELEASE POPUPS mdt_pop5, mdt_pop6
END TRY
END METHOD

[Fact, Trait("Category", "MenuFunctions")];
METHOD CntBarCountsASeparatorAtTheEnd AS VOID
DEFINE POPUP mdt_pop7
DEFINE BAR 1 OF mdt_pop7 PROMPT "Open"
DEFINE BAR 2 OF mdt_pop7 PROMPT "Save"
DEFINE BAR 3 OF mdt_pop7 PROMPT "\-"
TRY
Assert.Equal(3, (INT) CNTBAR("mdt_pop7"))
FINALLY
RELEASE POPUPS mdt_pop7
END TRY
END METHOD

[Fact, Trait("Category", "MenuFunctions")];
METHOD CntBarIsZeroForAnEmptyOrUnknownPopup AS VOID
DEFINE POPUP mdt_pop8
TRY
Assert.Equal(0, (INT) CNTBAR("mdt_pop8"))
Assert.Equal(0, (INT) CNTBAR("nosuchpopup"))
FINALLY
RELEASE POPUPS mdt_pop8
END TRY
END METHOD

[Fact, Trait("Category", "MenuFunctions")];
METHOD CntPadReturnsTheNumberOfPads AS VOID
DEFINE MENU mdt_m4 BAR
TRY
Assert.Equal(0, (INT) CNTPAD("mdt_m4"))
DEFINE PAD mdt_p1 OF mdt_m4 PROMPT "\<File"
DEFINE PAD mdt_p2 OF mdt_m4 PROMPT "Edit"
Assert.Equal(2, (INT) CNTPAD("mdt_m4"))
Assert.Equal(2, (INT) CNTPAD("MDT_M4"))
Assert.Equal(0, (INT) CNTPAD("nosuchmenu"))
FINALLY
RELEASE MENUS mdt_m4
END TRY
END METHOD

// BAR(), POPUP(), PAD() and MENU() describe the last selection, inside the
// handler and after it. BAR() is the bar number from DEFINE BAR.
[Fact, Trait("Category", "MenuFunctions")];
Expand Down
44 changes: 43 additions & 1 deletion src/Runtime/XSharp.VFP.UI/MenuFunctions.prg
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
// VFP-compatible menu information functions.
// BAR(), PAD(), POPUP(), MENU() read from MenuState, which Bar.OnVFPClick
// populates before dispatching each handler.
// MRKBAR/MRKPAD/PRMBAR/PRMPAD look up the named registry on Popup/Menu.
// MRKBAR/MRKPAD/PRMBAR/PRMPAD and CNTBAR/CNTPAD look up the named registry
// on Popup/Menu.

USING XSharp.VFP.UI

Expand Down Expand Up @@ -103,6 +104,47 @@ FUNCTION PRMPAD( cMenuName AS STRING, cPadName AS STRING ) AS STRING
ENDIF
RETURN ""

/// <summary>
/// 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.
/// <paramref name="cPopupName"/> — name of the Popup.
/// </summary>
[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

/// <summary>
/// Returns the number of pads of a menu. Returns 0 for an empty or unknown menu.
/// <paramref name="cMenuName"/> — name of the Menu.
/// </summary>
[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


/// <summary>The prompt of a bar or pad the way PRMBAR() and PRMPAD() report it.</summary>
INTERNAL STATIC CLASS MenuPrompt
Expand Down
10 changes: 0 additions & 10 deletions src/Runtime/XSharp.VFP/UI/UIAndWindows.prg
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
// See License.txt in the project root for license information.
//

/// <include file="VfpRuntimeDocs.xml" path="Runtimefunctions/cntbar/*" />
[FoxProFunction("CNTBAR", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Stub, FoxCriticality.Medium)];
FUNCTION CntBar(cPopupName AS STRING) AS INT
THROW NotImplementedException{}

/// <include file="VfpRuntimeDocs.xml" path="Runtimefunctions/cntpad/*" />
[FoxProFunction("CNTPAD", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Stub, FoxCriticality.Medium)];
FUNCTION CntPad(cMenuName AS STRING) AS INT
THROW NotImplementedException{}

/// <include file="VfpRuntimeDocs.xml" path="Runtimefunctions/col/*" />
[FoxProFunction("COL", FoxFunctionCategory.UIAndWindow, FoxEngine.UI, FoxFunctionStatus.Full, FoxCriticality.Medium)];
FUNCTION Col() AS INT
Expand Down