Window.DoubleClick event?

I am building an app for MacOSX with multiple document windows. I would like to have the old Mac functionality of when the user double clicks on the Window’s title bar, the height of the window is reduced to just the height of its titlebar. Double clicking on the titlebar again, restores the window back to its original height.
Can this be coded in Xojo?
Thanks in advance for your assistance,

The short answer is no you cannot recreate that behavior in Xojo.

However, Sierra has auto-tabbing (which Tabs are far more user friendly anyway)

I believe it can be done with declares. Like most things UI+declare related it’s not technically sanctioned by Xojo because it’s considered modifying-the-view-hierarchy. Still, it’s in MacOSLib, many use these techniques, and I haven’t heard of any problems so far.

There’s various ways to do it but basically declares are used to put an NSView in the Titlebar which can detect clicks. If the window has a toolbar it may have to be done differently.

OK, just tried it out and there’s a conflict with minimizing unless that’s turned off. Otherwise both collapsing to just the titlebar and minimizing occur on a double click. I imagine you’d want the minimizing button to still be available for minimizing while titlebar double-clicking only collapses. I’m sure there’s a way to accomplish that but Tim makes the better point. Unless this is just for yourself or in-house use then it’s quite unorthodox reintroducing legacy behavior, may confuse/frustrate people.

Thank you to both Tim and Will.
I am creating this app for in-house use only and it is updating an application that was written in the early 90s. That application only runs on classic Macs (OS 9!) and uses NuBus cards. We have a collection of old macs as their power supplies tend to give out after a while. Spare NuBus cards are another story and even eBay cannot provide a source of spares.
The window in question can have its minimize button disabled, so it might be possible to do what Will described. Presently, when I double-click on the titlebar, the window expands to its maximum width and screen height. Double clicking again reduces the window back to its original size.
I am unfamiliar with Declare statements but I will poke around with them and see what I can figure out. I may have some additional questions and ask in advance to post followups.

There is a non declare way to detect clicks in the window bar : use a timer to monitor System.MouseDown. Usually 20 ms period is enough.

Check is the click is between the and the, and between left and left+width.

Use property to store the first click time, then compare in the second. If it is within 30 ticks or 500 ms, then it is a double click.

Then you can set the window height to zero and back to full height. I would use a folded as boolean computed property to track its state and actually do the folding in the set method.

Then in the timer all you have to do is

folded = not folded

Here’s the code I tested with. This is actually the more improper modify-view-hierarchy as it moves a Xojo Canvas to the titlebar. I’ve used it for years without problem and it’s simple.

[code]//add this method to a Module with Global scope (as it’s an extension method)
Sub moveControlsToTitleRegion(extends w As Window, items() As RectControl)

declare function contentView lib “Cocoa” selector “contentView” (id As integer) As Ptr
declare function superView lib “Cocoa” selector “superview” (id As Ptr) As Ptr
declare function subviews lib “Cocoa” selector “subviews” (id As Ptr) As Ptr
declare function objAtIdx lib “Cocoa” selector “objectAtIndex:” (id As Ptr, idx As UInt32) As Ptr
declare sub addSubView lib “Cocoa” selector “addSubview:positioned:relativeTo:” _
(id As Ptr, aView As integer, order As integer, rel As Ptr)

dim cv As Ptr = contentView(w.Handle)

dim themeFrame As Ptr = superView(cv)

dim firstSubView As Ptr = objAtIdx(subViews(themeFrame), 0)

for i As integer = 0 to items.Ubound
addSubView(themeFrame, items(i).Handle, 0, firstSubView)

End Sub[/code]

In your window, lay out a Canvas over the titlebar, locked left and right, and implement it’s DoubleClick event

Sub DoubleClick(X As Integer, Y As Integer)

if self.Height = 0 then //placeholder/testing code to toggle height
self.Height = 500
self.Height = 0

End Sub[/code]

Finally, in the windows open event call that method like this which moves controls from the ContentView (where they start out) to the titlebar. The parameter is an array because I usually stuff several buttons and widgets up there.

//Window1 Sub Open() self.moveControlsToTitleRegion( Array(Canvas1) ) End Sub

The more sanctioned but still modifying-the-view-hierarchy approach is to make an NSView subclass using declares into the Obj-C runtime, add to that a Xojo Shared method to handle the mouse events and finally create and add an instance of the NSView to the titlebar. This is more sanctioned because it’s only adding a terminal view and not moving a Xojo control, but more involved. I’ll pull up a project later that does all this and see how quickly I can adapt it, or maybe someone will beat me to it :slight_smile:

Hmm, not sure about that, for me it minimizes to the dock. You might have to instead disable maximize then.

Which version of RB/RS are you using ?

Not sure the declare which has been posted would work in Carbon builds on PPC.

The underlying framework code that traps double click in the window bar needs declares to be disabled.

Here is an example that does what you want with a single click. It should work even in ancient versions of RS.


Ah, you’re right, didn’t think about that. My code doesn’t work in Carbon.

Does OS9 even predate Carbon? This would require InterfaceLib declares?

[quote=290198:@Will Shank]Ah, you’re right, didn’t think about that. My code doesn’t work in Carbon.

Does OS9 even predate Carbon? This would require InterfaceLib declares?[/quote]

I very vaguely remember that era. I think it might have been carbon anyway. Cocoa being the goal. But it is so far away now. I did not think I would ever see someone still using that platform. Although I did keep my Wall Street 17" portable PPC.

Not only does Xojo not recommend or support this, Apple doesn’t either. If an NSView must be placed in the titlebar, it needs to go through -[NSWindow insertTitlebarAccessoryViewController:atIndex:].