Page 1 of 2
[Q] Window pointer
Posted: Mon Nov 13, 2017 6:21 am
by shaosean
Is there a way to get the window pointer?
Re: [Q] Window pointer
Posted: Mon Nov 13, 2017 6:29 am
by FourthWorld
If memory serves the windowID can be used in OS calls to address the window structure.
Re: [Q] Window pointer
Posted: Mon Nov 13, 2017 6:34 am
by shaosean
Thanks.. Been a while since I've used RunRev/LiveCode and just started to play with LCB..
Re: [Q] Window pointer
Posted: Mon Nov 13, 2017 9:25 am
by shaosean
okay, now how to use the windowID in LCB? I pass it from LiveScript as Integer but all the choices I've used for the Obj-C calls has either ended with LiveCode complaining about the data types being wrong or just crashing LiveCode..
I've used Integer, ObjcId and Pointer.. What should I be using?
Re: [Q] Window pointer
Posted: Mon Nov 13, 2017 10:05 pm
by FourthWorld
I should have checked the LCB Guide before suggesting windowID. I know externals authors who've used it, but I don't know if it's available in LCB. If not, it would seem a valuable addition to the language.
Re: [Q] Window pointer
Posted: Mon Nov 13, 2017 11:42 pm
by [-hh]
shaosean wrote:Is there a way to get the window pointer?
You can see an example in the source code of the browser widget .
Re: [Q] Window pointer
Posted: Tue Nov 14, 2017 8:10 am
by shaosean
I've used it before in an external, so I know it has worked..
I will check out the source of the browser widget..
Thanks to both of you
Re: [Q] Window pointer
Posted: Tue Nov 14, 2017 11:17 am
by shaosean
My bad.. I am trying to do this from a library and not a widget.. I did try the method used in the browser widget, but because there is no window control, the call fails "No current widget"
Code: Select all
library tk.shaosean.library.mac.test
use com.livecode.foreign
use com.livecode.widget
metadata version is "1.0.0"
metadata author is "shaosean.tk"
metadata title is "test"
public handler Test() returns nothing
if (the operating system is "mac") then
variable tParent as Pointer
MCWidgetGetMyStackNativeView(tParent)
end if
end handler
end library
Guess it is time to file a feature request?
Re: [Q] Window pointer
Posted: Tue Nov 14, 2017 5:09 pm
by LCMark
@shaosean : I take it you are wanting the NSWindow* for a stack? If so, what are you wanting to do with it?
The windowId property of stacks gives you the Cocoa window number, which you can convert to an NSWindow* by using the NSApp's windowWithWindowNumber class method (which you should be able to bind to using Obj-C FFI).
You can fetch the windowNumber from LCB using 'execute script'. As you are running in a library, you can do this at any point currently - there are no execute script restrictions in LCB libraries. (Even in a widget, you can't really get the windowNUmber of a widget's stack until Open - and OnOpen is not execution restricted so it is pretty much the same).
If you are wanting to embed a NSView you manage in a widget, then all you need to do is 'set my native layer to' in the widget. The property takes a raw pointer to the obj-c NSView object - which you need to fetch from an ObjcObject typed variable. e.g:
Code: Select all
variable tButtonView as ObjcObject
/* For a standard push button we need:
* type to be UIButtonTypeSystem = 1 */
put ObjC_UIButtonButtonWithType(1) into tButtonView
set my native layer to PointerFromObjcObject(tButtonView)
put tButtonView into mButtonView
For widgets you should set the native layer in OnOpen, and then set it to nothing in OnClose.
Re: [Q] Window pointer
Posted: Tue Nov 14, 2017 8:54 pm
by shaosean
Thanks for the info. I'll play with it some more tonight.
Re: [Q] Window pointer
Posted: Wed Nov 15, 2017 7:22 pm
by shaosean
This is what I've got.. It doesn't throw any errors and it doesn't crash, but it doesn't seem to do anything..
Code: Select all
library tk.shaosean.library.mac.test
use com.livecode.foreign
use com.livecode.objc
metadata version is "1.0.0"
metadata author is "shaosean.tk"
metadata title is "test"
---------------------
private foreign handler NSApplicationSharedApplication() returns ObjcId binds to "objc:NSApplication.+sharedApplication"
private foreign handler NSApplicationWindowWithWindowNumber(in sharedApplication as ObjcId, in windowNumber as Integer) returns ObjcId binds to "objc:NSApplication.-windowWithWindowNumber:"
private foreign handler NSWindowToggleFullScreen(in aNSWindow as ObjcID) returns nothing binds to "objc:NSWindow.-toggleFullScreen:"
---------------------
public handler Test(windowID as Integer) returns nothing
if the operating system is "mac" then
unsafe
variable NSSharedApplication as ObjcId
put NSApplicationSharedApplication() into NSSharedApplication
variable aNSWindow as ObjcID
put NSApplicationWindowWithWindowNumber(NSSharedApplication, windowID) into aNSWindow
NSWindowToggleFullScreen(aNSWindow)
end unsafe
end if
end handler
end library
Re: [Q] Window pointer
Posted: Wed Nov 22, 2017 2:42 am
by PaulDaMacMan
Maybe a key has to be set in the (LiveCode IDE or Standalone) Application's plist for a certain PresentationMode so the System Knows the app can put into full-screen? Just a guess.
https://developer.apple.com/library/con ... 431-113616
Re: [Q] Window pointer
Posted: Wed Nov 22, 2017 3:29 am
by shaosean
Good idea, but for full screen, it's not needed.. The presentation keys are for doing kiosk applications (I browsed that linked page just to make sure I didn't miss anything)
For now, I'll wait until a new release of LiveCode comes out before playing with LCB..
Re: [Q] Window pointer
Posted: Mon Nov 27, 2017 3:47 pm
by shaosean
I got the full screen thing working, but only as a widget, which doesn't really make too much sense.. Would still like to get it working with the windowID, or some way of getting the NSWindow pointer without having to use a widget..
Re: [Q] Window pointer
Posted: Mon Nov 27, 2017 6:35 pm
by capellan
Probably, I do not understand how to use this feature, but
What is the difference between using fullscreenmodes and
windows pointers?
Al