COCOA quests?

Mac OSX specific forum
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

COCOA quests?

Post 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!
If translation=Error: reply="Sorry, Im Spanish": Endif
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: COCOA quests?

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: COCOA quests?

Post by minimy »

Wow! Thanks willbert!
Do you know how set position window?, some thing like setposition(hwnd,x,y,w,h)
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
mk-soft
Always Here
Always Here
Posts: 5333
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: COCOA quests?

Post 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(...)
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: COCOA quests?

Post 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.
If translation=Error: reply="Sorry, Im Spanish": Endif
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: COCOA quests?

Post 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")
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: COCOA quests?

Post by minimy »

Hi willbert! Fantastic! :shock: its exactly i need. :D
Thousend thanks to both for quick and perfect answer!
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
fsw
Addict
Addict
Posts: 1572
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Re: COCOA quests?

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

I am to provide the public with beneficial shocks.
Alfred Hitshock
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: COCOA quests?

Post by mestnyi »

Is there something like this in cocoa?

Code: Select all

SetParent_ (GadgetID (Gadget_1), GadgetID (Gadget_2)) 
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: COCOA quests?

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: COCOA quests?

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: COCOA quests?

Post 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.
Windows (x64)
Raspberry Pi OS (Arm64)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: COCOA quests?

Post 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
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: COCOA quests?

Post 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
Windows (x64)
Raspberry Pi OS (Arm64)
mestnyi
Addict
Addict
Posts: 995
Joined: Mon Nov 25, 2013 6:41 am

Re: COCOA quests?

Post 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)) 
Post Reply