Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 21, 2019 3:04 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next
Author Message
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:36 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This might be useful for creating preferences to keep track of the window's rectangle.. Basically it takes the position and size and converts it to a string and the other command will take the string and reset the window to that position and size..

Function frameString(Extends pWindow As Window) As String
// Returns a string representation of the window’s frame rectangle.
#if TargetCocoa
soft declare function stringWithSavedFrame lib "Cocoa" selector "stringWithSavedFrame" (WindowRef As WindowPtr) As CFStringRef
return stringWithSavedFrame(pWindow)
#endif
End Function


Sub frameString(Extends pWindow As Window, pFrameString As String)
// Sets the window’s frame rectangle from a given string representation.
#if TargetCocoa
soft declare sub setFrameFromString lib "Cocoa" selector "setFrameFromString:" (WindowRef As WindowPtr, inFrameString As CFStringRef)
setFrameFromString pWindow, pFrameString
#endif
End Sub


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:38 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Make your windows hide when your application is no longer active..

Sub hidesOnDeactivate(Extends pWindow As Window, pFlag As Boolean)
// Specifies whether the window is removed from the screen when the application is inactive.
#if TargetCocoa
soft declare sub setHidesOnDeactivate lib "Cocoa" selector "setHidesOnDeactivate:" (WindowRef As WindowPtr, inFlag As Boolean)
setHidesOnDeactivate pWindow, pFlag
#endif
End Sub


Function hidesOnDeactivate(Extends pWindow As Window) As Boolean
// Indicates whether the window is removed from the screen when its application becomes inactive.
#if TargetCocoa
soft declare function hidesOnDeactivate lib "Cocoa" selector "hidesOnDeactivate" (WindowRef As WindowPtr) As Boolean
return hidesOnDeactivate(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:45 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This is the "getter" for the command posted previously < viewtopic.php?p=229482#p229482 >

Function movableByWindowBackground(Extends pWindow As Window) As Boolean
// Indicates whether the window is movable by clicking and dragging anywhere in its background.
#if TargetCocoa
soft declare function isMovableByWindowBackground lib "Cocoa" selector "isMovableByWindowBackground" (WindowRef As WindowPtr) As Boolean
return isMovableByWindowBackground(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:48 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This code worked fine in my testing, but I was unable to find any other way of going from a WindowPtr to a Window.. If you have a child window (as set with addChildWindow command < viewtopic.php?p=229480#p229480 >) this will return the parent window (hopefully ;-)..

Function parentWindow(Extends pWindow As Window) As Window
#if TargetCocoa
soft declare function parentWindow lib "Cocoa" selector "parentWindow" (WindowRef As WindowPtr) As Integer
DIM tWindowPtr As Integer = parentWindow(pWindow)

for i as Integer = 0 to (WindowCount() - 1)
DIM tWindow As Window = Window(i)
if (tWindow.Handle = tWindowPtr) then
return tWindow
end if
next

return NIL
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:51 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This is the "getter" funciton to the previously posted setRepresentedFilename command < viewtopic.php?p=229483#p229483 >

Function representedFilename(Extends pWindow As Window) As String
// Returns the pathname of the file the window represents.
#if TargetCocoa
soft declare function representedFilename lib "Cocoa" selector "representedFilename" (WindowRef As WindowPtr) As CFStringRef
return representedFilename(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 7:55 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This is the "getter" function to the previously posted setUsesLightBottomGradient command < viewtopic.php?p=229044#p229044 >

Function usesLightBottomGradient(Extends pWindow As Window) As Boolean
// Indicates that the textured window uses a light gradient at the bottom of the window.
#if TargetCocoa
if (pWindow.Frame = integer(frames.textured)) then
soft declare function usesLightBottomGradient lib "Cocoa" selector "_usesLightBottomGradient" (WindowRef As WindowPtr) As Boolean
return usesLightBottomGradient(pWindow)
end if
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 8:04 pm 
Offline
Real Software Engineer

Joined: Fri Jan 28, 2011 5:24 pm
Posts: 145
shaosean wrote:
soft declare sub setBottomCornerRounded lib "Cocoa" selector "setBottomCornerRounded:" (WindowRef As Integer, IsSet As Boolean)

soft declare function bottomCornerRounded lib "Cocoa" selector "bottomCornerRounded" (WindowRef As WindowPtr) As Boolean

soft declare sub setUsesLightBottomGradient lib "Cocoa" selector "_setUsesLightBottomGradient:" (WindowRef As Integer, Flag As Boolean)

soft declare function usesLightBottomGradient lib "Cocoa" selector "_usesLightBottomGradient" (WindowRef As WindowPtr) As Boolean



Please don't post declares that use private Apple API. These are undocumented, unstable, and should not be used for any purpose.

As for some other points: all Cocoa declares are "soft"; there is no need to explicitly specify it. In fact, this may turn into a compile time error in the future. Also, WindowPtr should be avoided in favor of passing in an integer (or pointer!).

_________________
Joe Ranieri
Mac Frameworks & Compiler
REAL Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 8:17 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
jranieri wrote:
all Cocoa declares are "soft"; there is no need to explicitly specify it.

good to know, but the documentation needs updating to reflect this..

jranieri wrote:
Also, WindowPtr should be avoided in favor of passing in an integer (or pointer!).

hmm.. i was originally using integer and then stumbled across the WindowPtr and thought it looked much cleaner (and less typing ;-)) Would passing a Ptr be the same thing or do I still need to do window.handle ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Thu Nov 03, 2011 8:33 pm 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
These both give an error about incompatible parameter type..
#if TargetCocoa
soft declare function isOnActiveSpace lib "Cocoa" selector "isOnActiveSpace" (WindowRef As Ptr) As Boolean
return isOnActiveSpace(pWindow.Handle)
#endif


#if TargetCocoa
soft declare function isOnActiveSpace lib "Cocoa" selector "isOnActiveSpace" (WindowRef As Ptr) As Boolean
return isOnActiveSpace(pWindow)
#endif



This works though, but is more typing (and not as clean looking IMO)
#if TargetCocoa
soft declare function isOnActiveSpace lib "Cocoa" selector "isOnActiveSpace" (WindowRef As Integer) As Boolean
return isOnActiveSpace(pWindow.Handle)
#endif


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Fri Nov 04, 2011 12:09 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Show/hide the toolbar button in the window's title bar.. This only works if there is a toolbar associated with the window..

Sub showsToolbarButton(Extends pWindow As Window, pFlag As Boolean)
// Specifies whether the window shows the toolbar control button.
// If the window does not have a toolbar, this method has no effect.
#if TargetCocoa
soft declare sub setShowsToolbarButton lib "Cocoa" selector "setShowsToolbarButton:" (WindowRef As WindowPtr, Flag As Boolean)
setShowsToolbarButton pWindow, pFlag
#endif
End Sub


Function showsToolbarButton(Extends pWindow As Window) As Boolean
// Indicates whether the toolbar control button is currently displayed.
#if TargetCocoa
soft declare function showsToolbarButton lib "Cocoa" selector "showsToolbarButton" (WindowRef As WindowPtr) As Boolean
return showsToolbarButton(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Fri Nov 04, 2011 12:19 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Make the window ignore mouse clicks :-)

Sub ignoresMouseEvents(Extends pWindow As Window, pFlag As Boolean = FALSE)
// Specifies whether the window is transparent to mouse clicks and other mouse events, allowing overlay windows.
#if TargetCocoa
soft declare sub setIgnoresMouseEvents lib "Cocoa" selector "setIgnoresMouseEvents:" (WindowRef As WindowPtr, inFlag As Boolean)
setIgnoresMouseEvents pWindow, pFlag
#endif
End Sub


Function ignoresMouseEvents(Extends pWindow As Window) As Boolean
// Indicates whether the window is transparent to mouse events.
#if TargetCocoa
soft declare function ignoresMouseEvents lib "Cocoa" selector "ignoresMouseEvents" (WindowRef As WindowPtr) As Boolean
return ignoresMouseEvents(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Fri Nov 04, 2011 9:21 am 
Offline
Real Software Engineer

Joined: Fri Jan 28, 2011 5:24 pm
Posts: 145
shaosean wrote:
This works though, but is more typing (and not as clean looking IMO)
#if TargetCocoa
soft declare function isOnActiveSpace lib "Cocoa" selector "isOnActiveSpace" (WindowRef As Integer) As Boolean
return isOnActiveSpace(pWindow.Handle)
#endif


Yeah, like this. It uses integers instead of the old WindowPtr type.

_________________
Joe Ranieri
Mac Frameworks & Compiler
REAL Software, Inc.


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Sun Nov 06, 2011 7:51 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Sub isMovable(Extends pWindow As Window, pFlag As Boolean = TRUE)
// Specifies whether the window can be dragged by clicking in its title bar or background.
#if TargetCocoa
soft declare sub setMovable lib "Cocoa" selector "setMovable:" (WindowRef As WindowPtr, inFlag As Boolean)
setMovable pWindow, pFlag
#endif
End Sub


Function isMovable(Extends pWindow As Window) As Boolean
// Indicates whether the window can be moved by clicking in its title bar or background.
#if TargetCocoa
soft declare function isMovable lib "Cocoa" selector "isMovable" (WindowRef As WindowPtr) As Boolean
return isMovable(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Sun Nov 06, 2011 8:12 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
Function isMiniaturized(Extends pWindow As Window) As Boolean
// Indicates whether the window is minimized.
#if TargetCocoa
soft declare function isMiniaturized lib "Cocoa" selector "isMiniaturized" (WindowRef As WindowPtr) As Boolean
return isMiniaturized(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
 Post subject: Re: Mac OS X - Cocoa - Window extenders
PostPosted: Sun Nov 06, 2011 8:28 am 
Offline

Joined: Mon Aug 15, 2011 10:25 pm
Posts: 293
This changes the text that is displayed in the "tooltip" of the minimized dock window..

Sub miniwindowTitle(Extends pWindow As Window, pTitle As String)
// Sets the title of the window’s miniaturized counterpart to a given string and redisplays it.
#if TargetCocoa
soft declare sub setMiniwindowTitle lib "Cocoa" selector "setMiniwindowTitle:" (WindowRef As WindowPtr, inTitle As CFStringRef)
setMiniwindowTitle pWindow, pTitle
#endif
End Sub


Function miniwindowTitle(Extends pWindow As Window) As String
// Returns the title displayed in the window’s minimized window.
#if TargetCocoa
soft declare function miniwindowTitle lib "Cocoa" selector "miniwindowTitle" (WindowRef As WindowPtr) As CFStringRef
return miniwindowTitle(pWindow)
#endif
End Function


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 36 posts ]  Go to page Previous  1, 2, 3  Next

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group