You could also create a class to hold all the information required. Store an instance in a property and then the buttons can access that. It could be easier than doing lots of extra properties. The action event methods can go in the class also.
Thanks, thatâs a good idea. Making a class as a workaround isnât my favourite thing to do, but it may be what should happen to keep things clean.
Are you sure? I have a xojo app and on Ventura and Sonoma, modal dialogs that are shown using ShowModalWithin() are showing up centered on the parent window. They look different than before in terms of style, but they are definitely centered and modal to a single window.
The problem is with the centred over the window they are placed on. The Op wanted it at the top, as before.
I donât know why you think you canât do it that way but hereâs a function:
Public Function ShowMesssageDialog(parent as DesktopWindow, message as string, defaultbutton as string, cancelbutton as string) As String
dim md as new MessageDialog
md.ActionButton.Caption = defaultbutton
md.CancelButton.Caption = cancelbutton
md.CancelButton.Visible = (cancelbutton<>"")
md.Message = message
dim mdb as MessageDialogButton = md.ShowModal(parent)
return mdb.Caption
End Function
it would be used like this, assuming it was run from within a control on a window:
if ShowMessageDialog(self, "Confirm or Reject", "Confirm", "Reject") = "Confirm" then
// hereâs more code after confirming
else
// reject code
end if
if youâre using a Window
object, youâll want to duplicate the method and change the first parameterâs type to Window
.
Ahh, the OP wrote âthey appear in the center of the screenâ perhaps they meant âcenter of the windowâ? That would be different.
Sorry, yes I meant the center of the window. Iâm normally working with the window maximised, so mixed up the language a little there.
That still shows in the centre of the parent window, not at the top as before.
Perhaps the window was maximised.
I just did a quick test where I try to override the Window.Top position to 0 of a Sheet window, both before and after calling ShowWindowWithin() and it appears to have no effect in Ventura and Sonoma - the sheet window is still centered vertically on the parent window. You can change the Width and Height of the sheet, but it appears that the .Top value is ignored.
Right. Itâs the same on Monterey. Apple changed it apparently to make the user experience the same as iOS.
Yes. And this is a source of extreme irritation, since the iOS device I have sits on the desk by itself all day, and if I go out, sits in my pocket all day.
Is that real code? If so, I would recommend making the dialog much more verbose, e.g.:
Are you sure you want to Delete the frazzle biz bug? You will be deleting the biz bug that has foo bar razzles. Once deleted, the naxblogs that belong to the razzles will also be deleted. This action is not Undoable. [Delete] [Cancel] "
Remember, the user could be using your app on a small window, in which case the Sheet would occlude the content anyway. This way, the user should not need to see whatâs underneath the dialog.
(Though of course this does depend on just what your app does, not all apps are the same)
No. (I wrote above it: âIn pseudocode:â)
Youâre fighting an uphill battle if you want control over the location of a sheet. Apple changed the location and appearance of modal sheets and your app needs to adapt to the change if your app is going to look native in the newer OSs.
Youâre absolutely right - a sheet window is no longer the answer here due to the changes Apple insists on making to macOS. But if not sheets, than what? Iâve been thinking about this problem ever since I read the original post, and outside of a self-contained modal dialog, I canât think of a standard approach to this.
Samâs suggestion of a popover is excellent, if non-standard, but I hesitate a little to make a popover modal. Most popovers I deal with self-close if you click away from them. I donât think thatâs the right solution here, as the user is required to make a decision to continue. Theyâre generally informative, or present extra options not needed for the primary function of whatever is in play.
Popovers also donât ever seem to contain default buttons, activated by the Return and Escape keys, like modal dialogs can, and this can be tiring to the user who now must mouse over to the popover to deal with it.
In case anoyone else is suffering over this â one thing Iâve done is to take a hint from the LR and change any windows I had set to type Sheet to type MovableModal instead. This changes the aesthetic of the Mac app, but at least then the behaviour will be basically the same x-platform.
### Understanding sheet windows
A *Sheet Window* is the official name for a type of macOS window that is modal to a parent window. On other platforms, they behave as an ordinary movable modal dialog box.
The above text is from the DesktopWindow. For many reasons I still use the old Window class. The text in the LR is a little different there, describing the old behaviour of sheets, which doesnât apply any more.
Obviously, this doesnât fix the problem for Xojoâs MessageDialog class, which has no option to make it movable. Seems like a reasonable feature request. I tried navigating the (new for me) Xojo issue tracker and didnât see a way to submit a feature request, but I saw a request to use native dialogs for the class, which should also (sort of) solve the problem, since Apple does provide an option for their NSAlert windows to be movable.
So the function you need to override is below. Itâs part of the NSWindowDelegate. Xojo already creates a NSWindowDelegate, called âXOJWindowControllerâ and due to the dynamic nature of Objective-C, you can âSwizzleâ the function pointers to steal that function from Xojo (or in this case, handle that function yourself).
The code below includes the function description, which is needed for this kind of hacking as we canât just create a XojWindowController subclass and override it like normal people.
call class_replaceMethod( delegateClass, NSSelectorFromString( "window:willPositionSheet:usingRect:" ), _
addressOf windowwillPositionSheetUsingRect, "{NSRect}@:@{NSRect}" )
Iâll leave the rest up to you folk to figure out.
Oh and donât forget that Xojoâs co-ordinate system is the vertical opposite of Appleâs, so Zero is the bottom of the window and not the top.