[Q] Window pointer

Moderators: LCMark, LCfraser

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

[Q] Window pointer

Post by shaosean » Mon Nov 13, 2017 6:21 am

Is there a way to get the window pointer?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5460
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: [Q] Window pointer

Post by FourthWorld » Mon Nov 13, 2017 6:29 am

If memory serves the windowID can be used in OS calls to address the window structure.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Mon Nov 13, 2017 6:34 am

Thanks.. Been a while since I've used RunRev/LiveCode and just started to play with LCB..

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Mon Nov 13, 2017 9:25 am

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5460
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: [Q] Window pointer

Post by FourthWorld » Mon Nov 13, 2017 10:05 pm

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.
Richard Gaskin
Community volunteer LiveCode Community Liaison

LiveCode development, training, and consulting services: Fourth World Systems: http://FourthWorld.com
LiveCode User Group on Facebook : http://FaceBook.com/groups/LiveCodeUsers/

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1547
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: [Q] Window pointer

Post by [-hh] » Mon Nov 13, 2017 11:42 pm

shaosean wrote:Is there a way to get the window pointer?
You can see an example in the source code of the browser widget .
shiftLock happens

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Tue Nov 14, 2017 8:10 am

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 :D

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Tue Nov 14, 2017 11:17 am

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?

LCMark
Livecode Staff Member
Livecode Staff Member
Posts: 949
Joined: Thu Apr 11, 2013 11:27 am

Re: [Q] Window pointer

Post by LCMark » Tue Nov 14, 2017 5:09 pm

@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.

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Tue Nov 14, 2017 8:54 pm

Thanks for the info. I'll play with it some more tonight.

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Wed Nov 15, 2017 7:22 pm

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

PaulDaMacMan
Posts: 128
Joined: Wed Apr 24, 2013 4:53 pm

Re: [Q] Window pointer

Post by PaulDaMacMan » Wed Nov 22, 2017 2:42 am

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

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Wed Nov 22, 2017 3:29 am

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..

shaosean
Posts: 873
Joined: Thu Nov 04, 2010 7:53 am

Re: [Q] Window pointer

Post by shaosean » Mon Nov 27, 2017 3:47 pm

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..

capellan
Posts: 409
Joined: Wed Aug 15, 2007 11:09 pm
Contact:

Re: [Q] Window pointer

Post by capellan » Mon Nov 27, 2017 6:35 pm

Probably, I do not understand how to use this feature, but
What is the difference between using fullscreenmodes and
windows pointers?

Al

Post Reply

Return to “LiveCode Builder”