I am working on an application which, while having no menu bar, presents a floating window when certain applications are frontmost. The floating window contains a specialized WebView and even a download manager. I have no Carbon/Cocoa preference, believing that you should concentrate on the application you are building rather than the tools used, and have years of Carbon experience but Cocoa is obviously the API of choice for this application [1].

The issue I am having is that I want my NSPanel to have the title bar on the (left) side. In Carbon there is an WindowAttribute (kWindowSideTitlebarAttribute) which makes this trivial but I can't find anything equivalent in Cocoa. Searching found an item on cocodev <http://www.cocoadev.com/index.pl?TitlebarOnSide > which suggests that this isn't possible and suggests subclassing NSWindow using NSBorderlessWindowMask which directed me to the "RoundTransparentWindow" sample. Of course, the issue with this is that the entire title bar, all of the close/minimize/maximize buttons and resize box have to be custom controls which is not an insignificant amount of work.

The cocoadev item also lead me to NSWindow's initWithWindowRef: and windowRef methods which looked promising. I moved the contents of my NSPanel to an NSView and programmatically created a Carbon window with the kWindowSideTitlebarAttribute, passing it to the initWithWindowRef: method. The window appears, the window controls (close/minimize/ maximize) and the title all work as expected via NSWindow's methods. However, the view I created inserted via setContentView: doesn't appear in most circumstances and "po" in gdb return that the panel is actually a NSCarbonWindow, which is undocumented. Next, I tried to simply get the Carbon WindowRef using windowRef and attempting to set the WindowAttribute using Carbon's ChangeWindowAttributes() but this didn't change the window's appearance. The documentation on initWithWindowRef: and windowRef is minimal and I wonder what is possible using these calls.

More searching suggested that the controls in the window created by Carbon and initWithWindowRef: would have to be Carbon controls even though it would be much easier in this case that they be Cocoa. The solution in Leopard appears to be HICocoaView but that isn't an option for me as the application has to run on Tiger (10.4) too.

I am trying to decide what the best path forward is. I would also like to constrain the window position to the sides of the screen [2] which would be easy with CarbonEvents and according to <http://www.wodeveloper.com/omniLists/macosx-dev/2001/February/msg00415.html > has to be done in Cocoa by intercepting the click in the titlebar and handling the drag manually, again probably in a sub-class.

Both the left side title bar and constraining window dragging are possible using Carbon and as I am agnostic about Carbon/Cocoa if I could get initWithWindowRef: to allow Cocoa views to be embedded in the NSCarbonWindow while also using CarbonEvents that would be an acceptable (and probably quicker for me to implement) solution. I wonder if anyone has had much luck blending Carbon and Cocoa in this way without having to use HICocoaView.

Up until now my exposure to Cocoa has been purely through using the provided classes and now it looks like I am going to have to start subclassing to achieve what I need to do. Does anyone know of any publicly available examples of NSPanel/NSWindow which implements the titlebar on the side? Failing that is there any example code to reproduce the look or a titlebar or window controls (close/minimize/ maximize).

Thanks,
Nick

[1] Apple is pushing Cocoa very hard (64-bit anyone) and WebKit is much easier to use in Cocoa than Carbon. The download manager is also almost trivial to implement in Cocoa too. I have had to use a Carbon Events { kEventClassApplication, kEventAppFrontSwitched } to handle application switching detection though. [2] In many ways DragThing (http://www.dragthing.com) does similar things to what I am trying to achieve, including snapping to screen edges. However, I am almost certain that DragThing uses fully custom drawing inside a Carbon window.

--
Nick Beadman
[EMAIL PROTECTED]
(sent from my mailing list account, [EMAIL PROTECTED])

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to