Setting default property for a button on a dialog box window

This is almost hard to believe, but maybe somebody has encountered this. With Xojo 2014 R2.1, I have created a portable dialog box infrastructure (I preached about how to do that as a document-view-controller model at 2014 Xojo conference. For some reason, this works only on OS X and not with either Windows 7 or 8.1. I could have sworn it worked before.

The behavior that I want is when a dialog box is initialized:

  1. Detect which OS it is (OS X or Windows) and then.
  2. Set the Default property for the bottom left and right dialog dismissal buttons (OK/Cancel for Windows and Cancel/OK for OS X viewing left to right).

Works for OS X. Doesn’t for Windows.

[code] ’ OK and Cancel buttons
mfRightButtonIsOk = App.platformInfo.ifMacOSX()

Dim strLabelLeft, strLabelRight As String
If (mfRightButtonIsOk = True) Then
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelRight = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissRight.Default = True
Self.pbtnDismissLeft.Cancel = True
Else
strLabelRight = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissLeft.Default = True
Self.pbtnDismissRight.Cancel = True
End If[/code]

Any ideas? TW, the ifMacOSX() function returns a Boolean True if the OS is OS X. I also, as you can see retrieve the appropriate language-dependent text for Cancel and OK from a Dictionary class (storeLanguage.cp). I’ve also tried playing around by setting the Default setting in the IDE. Doesn’t seem to work either. This isn’t catastrophic though, but I sure could use some advice.

[quote=136304:@Howard Whitaker]This is almost hard to believe, but maybe somebody has encountered this. With Xojo 2014 R2.1, I have created a portable dialog box infrastructure (I preached about how to do that as a document-view-controller model at 2014 Xojo conference. For some reason, this works only on OS X and not with either Windows 7 or 8.1. I could have sworn it worked before.

The behavior that I want is when a dialog box is initialized:

  1. Detect which OS it is (OS X or Windows) and then.
  2. Set the Default property for the bottom left and right dialog dismissal buttons (OK/Cancel for Windows and Cancel/OK for OS X viewing left to right).

Works for OS X. Doesn’t for Windows.

[code] ’ OK and Cancel buttons
mfRightButtonIsOk = App.platformInfo.ifMacOSX()

Dim strLabelLeft, strLabelRight As String
If (mfRightButtonIsOk = True) Then
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelRight = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissRight.Default = True
Self.pbtnDismissLeft.Cancel = True
Else
strLabelRight = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissLeft.Default = True
Self.pbtnDismissRight.Cancel = True
End If[/code]

Any ideas? TW, the ifMacOSX() function returns a Boolean True if the OS is OS X. I also, as you can see retrieve the appropriate language-dependent text for Cancel and OK from a Dictionary class (storeLanguage.cp). I’ve also tried playing around by setting the Default setting in the IDE. Doesn’t seem to work either. This isn’t catastrophic though, but I sure could use some advice.[/quote]

You mean under Windows buttons remain Cancel/OK ? Is that the issue or something else ?

Are you sure your platform detection works as expected ? What about simply replacing

mfRightButtonIsOk = App.platformInfo.ifMacOSX()

by

mfRightButtonIsOk = TargetMacOS

Take a look at the OKCancelContainer project that is in the Examples (Dekstop:Custom Controls). It will automatically set the OK and Cancel buttons depending on the OS. Paul Lefevre actually used it in one of the webinars. (I wonder why it wasn’t used on the Xojo Project Chooser window as that has the button locations wrong on Windows.)

thank you both, Michel and Dale. I have tried this with both Xojo 2014R2.1 and 2014R2.0 on Windows 8.1 Pro. Even the example doesn’t default correctly. The sample brings up the dialog box with the correct default on OS X and on Windows? Cancel button. Could one of you please try the example on your Windows and convince me I’m not seeing things? :wink:

[quote=136304:@Howard Whitaker] ’ OK and Cancel buttons
mfRightButtonIsOk = App.platformInfo.ifMacOSX()

Dim strLabelLeft, strLabelRight As String
If (mfRightButtonIsOk = True) Then
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelRight = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissRight.Default = True
Self.pbtnDismissLeft.Cancel = True
Else
strLabelRight = App.storeLanguage.cp.getValue(“ButtonCancel”)
strLabelLeft = App.storeLanguage.cp.getValue(“ButtonOk”)
Self.pbtnDismissLeft.Default = True
Self.pbtnDismissRight.Cancel = True
End If[/quote]

Your code as I read it should work. You should try to set mfRightButtonIsOk as false and check if it works.

I ran the Xojo example on Windows 10, and it does put OK on the left. Given the way it is written, it relies on conditional compilation based on TargetMacOS, I frankly do not see how it could not work properly. I have never observed any Mac program run under Windows :wink:

msgbox str(TargetMacOS) reports False here under Windows* …

Unless some very strange effect of a VM ?

  • Well, apart from Hackintosh, but that’s a far fetched hypothesis.

Actually, you’re not seeing things. The example does work that way.

I “solved” it by adding LeftButton.SetFocus at the end of the Else clause in the Open event of the Container control.

[code]Sub Open()
Open

// Don’t forget to set the default button

#If TargetMacOS Then
LeftButton.Caption = CancelButtonText
LeftButton.Default = False
LeftButton.Cancel = True
RightButton.Caption = ActionButtonText
RightButton.Default = True
RightButton.Cancel = False
#Else
RightButton.Caption = CancelButtonText
LeftButton.Caption = ActionButtonText
LeftButton.SetFocus ’ <— add this line. It works for me on Win 7
#Endif

End Sub[/code]

Ah ha!!! I will try that!

Guys! The SetFocus member function does the trick! Thank you.