Programming on the Mac platform

Mac OSX specific forum
WilliamL
Addict
Addict
Posts: 1214
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

Programming on the Mac platform

Post by WilliamL »

This is a listing of the Mac only programming constraints. Maybe this list would help new users or porting programs from windows to the Mac. These are not bugs. This is not a complete list and I don't have a Windows machine to compare with so I need your suggestions. Updated 3/22/13 *

J. Baker has posted a detailed guide for submitting your app to iTunes with a further discussion here.

Tools - work within IDE as 'Tools'
-plistTool for OS X tool that works thru the debugger! - wilbert/J. Baker Updated 3/22/13 *
-PureMonitor for OS X tool that monitors CPU & threads, logs, and more! - J. Baker/wilbert Updated 3/14/13 *

Platform specific:
-use .app after program name, when creating an executable, to signal compiler to create a stand-alone application
-plists look like this.
-plist are found by right-clicking (cntrl+click) on the app and selecting 'Show Package Contents' and looking in 'Contents' folder
-plists are always replaced with a default after creating an executable (you must copy your plist over it every time)
-plists can automatically be copied to new executable with this code - jamirokwai
-a plist tool that works within the debugger plistTool for OS X - J. Baker/wilbert *
-windows must be moved down the height of the MenuBar (22 px)
-only one menu per program (they seem to be accessible from any window and must have a menu window open at all times!)
-pre defined constants of #PB_Menu_About, #PB_Menu_Preferences,#PB_Menu_Quit
-file path uses '/' instead of '\' (as in windows) eg. "user/WilliamL/Library/MyPrefs.txt" Multi-platform workaround
-colors designated by '$0000FF' are shown as BGR, pb commands like RGB(0,0,255) are shown as RGB
-color constants like #White are not defined on the Mac platform (but you can define them)
-color values in the API are word values ($FFFF) instead of byte values ($FF), see conversion here.
-pb preferences can be found here.
-supporting file are saved here updated info from J Baker
-Mac use a single button mouse and right clicks are entered by using ctrl+mouse to cause a right click. Laptops only have a singe button also. This does not work on the Canvas gadget but a work-around is here. Multiple button mice work fine on the Mac along with the scroll wheel and many use them (as I do).
-Freak explains how to compile 'universal binaries'
-Drawing can be done with CGContext functions for arcs, curves, blend modes that are antialiased.

Platform limitations:
-color in gadgets is generally not supported in pb - but may be added by API. Here is a chart of all gadget possibilities, and pictures of gadgets. Note: with 5.1 the color options are better.
-CalendarGadget on the Mac is just text (not like in manual) a CanvasCalendarGadget or datepicker are possible replacements.
-arrow keys don't work with AddKeyboardShortcut (yet!) but do work with Keyboard commands. (Arrow keys work in 5.10+)
-button height over (22 px ?) gives a square button instead of the rounded box (use 25 px for default button)
-printing is achieved by creating an image and printing it out (poor text rendering), text can be printed clearly by using the Carbon print manager (example) * (see next item)
-with version 5.00 printing size changed to 1/4 size. So to print 12 pt. text you have to use a 48 pt. font - same with images (x4).
-Console does not work on the Mac! Fred says OpenConsole() does nothing on OSX/Linux as there is no special console format.
-Tools are created using the 'Console' option when creating the executable
-Arr.Point(1) (eg.) will not work since Point is not a default structure. The structure can be defined.
-Color constants are not defined (eg. #White, #Black, etc)
-Text is limited to font and size - italics/underline/bold can be achieved by API in gadgets
-Text in images can achieve underline/strike-out with drawing commands

Platform suggestions:
-Arial (spelled with a capital A) and Geneva are safe fonts if you are coming from Windows (along with Monaco, Courier and many others). Also check to see if font is loaded.
-line feeds, as explained by Shardik, are:
  • Line feeds on the Mac are #CR$, on Linux #LF$ and on Windows #CRLF$.
    MessageRequester() a #CR$ works on all 3 platforms the same
-use of FontID() is required [ eg. DrawingFont (FontID(F2)) ] - in another thread, freak says this is the correct behavior but it seems to be optional on Windows
- OpenWindow flags should be limited to #PB_Window_SystemMenu and #PB_Window_WindowCentered for compatibility or at least to the defined pb constants.
- see 'Re: Create threadsafe executable' by jesperbrannmark for his suggestions about using threads and programming on the Mac in general
- (your contributions)?

I strongly suggest looking at API List of the Mac for many additional abilities.
Last edited by WilliamL on Fri Mar 22, 2013 5:22 pm, edited 52 times in total.
MacBook Pro-M1 (2021), Sonoma 14.3.1 (CLT 15.3), PB 6.10b7 M1
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Re: Programming on the Mac platform

Post by Marlin »

First I thought, this will be of little value to me,
as I do not currently have access to a Mac.

After reading all of this, I thought:
I would not want a Mac anyways. ;-)
WilliamL wrote:-line feeds (like in a ToolTip) are just #CR$ or Chr(13) (windows= #LFCR$)
No, this is wrong.

There is no OS I know of, that uses #LFCR$ as a line feed/line break!

Windows usually uses #CRLF$ for line break!
(The same also used by http.) ;-)
If liberty means anything at all, it means the right to tell people what they do not want to hear.
- George Orwell
User avatar
Shardik
Addict
Addict
Posts: 1984
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Programming on the Mac platform

Post by Shardik »

William,

I think your posting of collecting Mac only programming constraints is a very useful
idea. Especially newbies in Mac programming will see at once what pitfalls they
possibly might have to circumvent. But also more experienced programmers doing
cross-platform work would have a sort of checklist of what they have to pay attention
to.
WilliamL wrote:-line feeds (like in a ToolTip) are just #CR$ or Chr(13) (windows= #CRLF$ [edited])
That's right. Line feeds on the Mac are #CR$, on Linux #LF$ and on Windows #CRLF$.
But for example in a MessageRequester() a #CR$ works on all 3 platforms the same as
in this example (because presumably PureBasic takes care for that):

Code: Select all

MessageRequester("Info", "This line is splitted into line 1" + #CR$ + "plus line 2")
Marlin wrote:First I thought, this will be of little value to me,
as I do not currently have access to a Mac.

After reading all of this, I thought:
I would not want a Mac anyways. ;-)
Until last year's summer I thought the same. But then I got a programming request to
develop an application for all 3 platforms. Since September 2010 I own my first Mac
and I began to program my first cross-platform application. And I have to confess that
it is a lot of fun to delve into the Mac's Carbon API to circumvent some of PureBasic's
current shortcomings... :wink:
Last edited by Shardik on Tue Mar 01, 2011 1:28 pm, edited 1 time in total.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2050
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Programming on the Mac platform

Post by Andre »

A very good idea, I think! :D

It should be also useful to me, even if I will be more a "consumer" of tipps at the moment, and I'm probably not skilled enough to add many things to the list myself. :)


PS: made the post "sticky" to stay on top of the MacOS programming threads (beside the API list)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
User avatar
Shardik
Addict
Addict
Posts: 1984
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Programming on the Mac platform

Post by Shardik »

WilliamL wrote:Platform limitations:
-color in gadgets is generally not supported (in pb - but see API list) (see examples at http://www.purebasic.fr/english/viewtop ... 63#p340163 )
freak wrote:The color options on OSX are very poor. If it does not work, its probably not possible. I spent quite some time implementing coloring wherever possible.
I can confirm freak's findings but nevertheless I would suggest to change the help for Mac. Especially for a beginner it is annoying and frustrating to read in the help for SetGadgetColor:
PB help for SetGadgetColor wrote:Supported OS
all
And this function is not contained in "Platform-dependant functions" with a hint that most Gadgets don't work with SetGadgetColor...

I have therefore compiled a html table (in the style of "Platform-dependant functions") which indicates for each gadget whether it works or doesn't work with SetGadgetColor and SetGadgetFont or whether an API workaround exists. Unfortunately I don't know a way to display this table as html on this board. Therefore I had to include it as an image...

Hint to Andre: it would be nice if you could integrate this table into the help files. Please send me a PM if you are interested... :wink:

Image

Update 1: I have added SetGadgetItemColor to my table.
Update 2: I have changed the status of SetGadgetFont for the HyperLinkGadget to Red
Last edited by Shardik on Mon Aug 01, 2011 9:55 pm, edited 2 times in total.
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2050
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Programming on the Mac platform

Post by Andre »

@Shardik: thanks for your effort and the offer with the table :o)

But before I change the help, there is needed an official statement by the developers Fred / Timo. E.g. if they want such extensions in the help, if they will add (by workarounds...) mure functionality about the colors, etc.
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
freak
PureBasic Team
PureBasic Team
Posts: 5929
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Re: Programming on the Mac platform

Post by freak »

Andre wrote:@Shardik: thanks for your effort and the offer with the table :o)

But before I change the help, there is needed an official statement by the developers Fred / Timo. E.g. if they want such extensions in the help, if they will add (by workarounds...) mure functionality about the colors, etc.
I don't think there will be many changes in this area anymore (at least not until the day we switch to Cocoa as the underlying framework). So feel free to update the help accordingly.

> Hint to Andre: it would be nice if you could integrate this table into the help files. Please send me a PM if you are interested...

Don't add that table. Add a note in the topic for each function instead.
quidquid Latine dictum sit altum videtur
User avatar
Shardik
Addict
Addict
Posts: 1984
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Programming on the Mac platform

Post by Shardik »

freak wrote:I don't think there will be many changes in this area anymore (at least not until the day we switch to Cocoa as the underlying framework).
Timo,

I fully understand that there won't be many changes implemented in the
current Mac version of PB with its Carbon framework base. But do you
already have any plans in which PB version the porting from Carbon to
Cocoa will happen? I know that this task will take a lot of work because
all Gadgets will have to be reprogrammed and adapted to utilize the object
oriented Cocoa framework. In principle I would guess that this is almost as
much work as to develop a new Mac version of PureBasic from scratch...

Do you already know whether Carbon support will be ended completely or
will there exist a possibility to chose Carbon as an alternate subsystem? :)
freak wrote:Don't add that table. Add a note in the topic for each function instead.
That would be indeed the most user friendly solution... :wink:
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2050
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Re: Programming on the Mac platform

Post by Andre »

Informations about (restricted) coloring possibilities on MacOS were added to the manual, for PB4.61... :)
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Lebostein
Addict
Addict
Posts: 807
Joined: Fri Jun 11, 2004 7:07 am

Re: Programming on the Mac platform

Post by Lebostein »

This thread is pinned and seems to be important.

All these facts are correct also in the current version 5.10? Both listings (limitations and gadget colors) are from the year 2011 (PB version 4.6)...
Thanks!
Fred
Administrator
Administrator
Posts: 16581
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Programming on the Mac platform

Post by Fred »

No, it's no more accurate as we switched to Cocoa inbetween.
User avatar
Shardik
Addict
Addict
Posts: 1984
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Programming on the Mac platform

Post by Shardik »

Lebostein wrote:All these facts are correct also in the current version 5.10?
The limitations in the coloring of gadgets only apply if selecting subsystem Carbon. So SetGadgetColor() should work fine for all gadgets listed in the help for that command when using the Cocoa framework (default since PB 5.00).
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Programming on the Mac platform

Post by collectordave »

Just stating out.

i have written a small program to display a splash screen using a .png image in an image gadget.

Works fine on windows 7. Moved whole thing to MAC and program runs but no image is displayed in the image gadget. If I add image at design time as i add the image gadget it works. Code as follows

;Imports/Using statements
UsePNGImageDecoder()
UseSQLiteDatabase()

;Add binaries to exe section
DataSection
splash: :IncludeBinary "Images\WorldC.png"
EndDataSection

;Display Splash Screen
window_Splash = OpenWindow(#PB_Any,0,0,500,200,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
image_Splash = CatchImage(#PB_Any, ?splash)
gadget_Image = ImageGadget(#PB_Any,0,0,500,200,ImageID(image_Splash))

Delay(3000)

;Close Splash Screen
CloseWindow(window_Splash)

Looked at forum, not extensively but any help appreciated
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
collectordave
Addict
Addict
Posts: 1309
Joined: Fri Aug 28, 2015 6:10 pm
Location: Portugal

Re: Programming on the Mac platform

Post by collectordave »

Quick update on the above.

When i create the executable .app the splash screen shows Ok! Just not when running in compile and run.
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.
User avatar
TI-994A
Addict
Addict
Posts: 2512
Joined: Sat Feb 19, 2011 3:47 am
Location: Singapore
Contact:

Re: Programming on the Mac platform

Post by TI-994A »

collectordave wrote:...program runs but no image is displayed in the image gadget...
It seems that the Delay() function is the culprit. Remove it and the image displays.

Instead, try implementing a timer for the splash screen. :wink:
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too! Please visit my YouTube Channel :D
Post Reply