Page 1 of 4

COCOA quests?

Posted: Sat Feb 11, 2017 5:05 pm
by minimy
Exist some thing in OSX (cocoa or other way) similar to MSAPI:

FindWindow_(0, win_name.s)
SetParent_(hWnd,WindowID(window))
SendMessage_(hWnd,#WM_CLOSE,0,0)
MoveWindow_(hWnd,x,y,w,h,#True)

Somebody can help with this?
Thanks a lot!

Re: COCOA quests?

Posted: Sat Feb 11, 2017 5:40 pm
by wilbert
It helps if you explain what those windows api calls actually do.

On OSX you use CocoaMessage.
For example to close a window

Code: Select all

CocoaMessage(0, WindowID(0), "close")
or to add a child window

Code: Select all

CocoaMessage(0, WindowID(0), "addChildWindow:", WindowID(1), "ordered:", 1); NSWindowAbove = 1

Re: COCOA quests?

Posted: Sat Feb 11, 2017 7:43 pm
by minimy
Wow! Thanks willbert!
Do you know how set position window?, some thing like setposition(hwnd,x,y,w,h)

Re: COCOA quests?

Posted: Sat Feb 11, 2017 8:39 pm
by mk-soft
minimy wrote: Do you know how set position window?, some thing like setposition(hwnd,x,y,w,h)
Why not with native PB-Function ResizeWindow(...)

Re: COCOA quests?

Posted: Mon Feb 13, 2017 8:53 pm
by minimy
mk-soft wrote:
minimy wrote: Do you know how set position window?, some thing like setposition(hwnd,x,y,w,h)
Why not with native PB-Function ResizeWindow(...)
Hi mk-soft! because i need a window based in a handle not in windowid or window number. Is not a PBwindow.
Thanks for help.

Re: COCOA quests?

Posted: Tue Feb 14, 2017 7:02 am
by wilbert
minimy wrote:Do you know how set position window?
Screen coordinates are flipped. (0, 0) is the bottom left of the screen.

Set bottom left coordinate of window

Code: Select all

Point.NSPoint\x = 100
Point\y = 100
CocoaMessage(0, WindowID(0), "setFrameOrigin:@", @Point)
Set top left coordinate of window

Code: Select all

Point.NSPoint\x = 100
Point\y = 100
CocoaMessage(0, WindowID(0), "setFrameTopLeftPoint:@", @Point)
Center window

Code: Select all

CocoaMessage(0, WindowID(0), "center")

Re: COCOA quests?

Posted: Tue Feb 14, 2017 1:58 pm
by minimy
Hi willbert! Fantastic! :shock: its exactly i need. :D
Thousend thanks to both for quick and perfect answer!

Re: COCOA quests?

Posted: Tue Feb 14, 2017 9:49 pm
by fsw
In regards to Center Window:

Just be aware that your perception of center will probably not match Apple's perception of center.

More info in this thread.

:mrgreen:

Re: COCOA quests?

Posted: Thu Jan 03, 2019 8:08 pm
by mestnyi
Is there something like this in cocoa?

Code: Select all

SetParent_ (GadgetID (Gadget_1), GadgetID (Gadget_2)) 

Re: COCOA quests?

Posted: Fri Jan 04, 2019 7:42 am
by wilbert
mestnyi wrote:Is there something like this in cocoa?

Code: Select all

SetParent_ (GadgetID (Gadget_1), GadgetID (Gadget_2)) 
You can use addSubview:

Code: Select all

OpenWindow(0, 0, 0, 320, 250, "addSubview: example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
FrameGadget(0, 10, 10, 300, 50, "FrameGadget")
TextGadget(1, 0, 0, 250, 20, "TextGadget")

CocoaMessage(0, GadgetID(0), "addSubview:", GadgetID(1))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: COCOA quests?

Posted: Fri Jan 04, 2019 8:49 am
by mestnyi
Hi, in principle, it solved my problem at the moment, thank you.
But why here from the bottom up?
It does not move the listview, listicon, tree.
Can you help me with this?
Thanks again. :)

Code: Select all

OpenWindow(0, 0, 0, 320, 320, "addSubview: example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
CanvasGadget(0, 10, 10, 300, 300)
ButtonGadget(1, 50, 10, 150, 20, "ButtonGadget")

CocoaMessage(0, GadgetID(0), "addSubview:", GadgetID(1))


; ResizeGadget(1, #PB_Ignore, 300-20-10, #PB_Ignore, #PB_Ignore)
     
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: COCOA quests?

Posted: Fri Jan 04, 2019 3:49 pm
by wilbert
mestnyi wrote:But why here from the bottom up?
I'm not sure if I understand your question but with Cocoa, coordinates are different.
(0,0) is bottom left instead of top left.
PureBasic normally handles this for you so coordinates work the same on all supported platforms but in this case you will have to handle the different coordinates yourself.

Re: COCOA quests?

Posted: Fri Jan 04, 2019 6:12 pm
by mestnyi
I talk about it.

Code: Select all

OpenWindow(0, 0, 0, 320, 320, "addSubview: example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CanvasGadget(0, 10, 10, 300, 300)
ListViewGadget(1, 50, 10, 150, 50)
AddGadgetItem(1,-1, "ListView_1")
AddGadgetItem(1,-1, "ListView_2")

CocoaMessage(0, GadgetID(0), "addSubview:", GadgetID(1))
     
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: COCOA quests?

Posted: Fri Jan 04, 2019 7:48 pm
by wilbert
mestnyi wrote:I talk about it.
Sorry, I don't know a solution. :(
Canvas is not just a simple Cocoa object. It's made up of multiple objects.

I don't know if you are aware of it but you can use a canvas as a container.

Code: Select all

OpenWindow(0, 0, 0, 320, 320, "Canvas container", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

CanvasGadget(0, 10, 10, 300, 300, #PB_Canvas_Container)
ListViewGadget(1, 50, 10, 150, 50)
CloseGadgetList()
AddGadgetItem(1,-1, "ListView_1")
AddGadgetItem(1,-1, "ListView_2")

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow

Re: COCOA quests?

Posted: Fri Jan 04, 2019 9:02 pm
by mestnyi
Canvas is not just a simple Cocoa object. It's made up of multiple objects.
Similarly, the list view consists of several objects. I think the problem is with this.
in Linux it was also similar, but there I could get a parent and a child, but here I do not know how to do it. :oops:

And generally, how do you convert the code of the apple into the code of the purebasic
why the apple documentation has two functions?
How to use these functions in the Purebasic?
I do not understand help me please.

Code: Select all

; func addSubview(_ view: UIView)
; func addSubview(_ view: NSView)
CocoaMessage (0, GadgetID (Gadget), "addSubview:", GadgetID (Gadget_1)) 
Why doesn't it work in the same way?
What is going on here where you can find out how you know where you read it?

Code: Select all

; func bringSubviewToFront(_ view: UIView)
CocoaMessage (0, GadgetID (Gadget), "bringSubviewToFront:", GadgetID (Gadget_1))