TextArea on OSX

BlitzMax Forums/MaxGUI Module/TextArea on OSX

Chalky(Posted 2014) [#1]
I have a fairly complex suite of programs written using MaxGUI which are used to create and upload newsletters and webpages as well as maintaining database entries (via server-side php-sql called from my application). Everything is now complete and running perfectly on windows.

I have now been advised that one of the users who will be responsible for using the programs is a Mac only user - and am therefore in the process of creating a Mac version of each one. Unfortunately, I appear to have fallen at the first hurdle...

The text editors rely on CTRL-C/X/V for copying and pasting text in a TextArea - as well as CTRL-Z/Y for undo and redo (all handled via a filter). However, non of this code works on OSX - all I get when I press CMD-C/V/X/Y/Z is the Apple "fart" sound. Also - single and double quotes are transformed into strange characters when the text is saved to a file, which are then magically stripped out when the file is reloaded (all via the same code which works fine on Win32).

This is my first attempt to program on a Mac - any advice on what I need to change to make my code OSX compatible would be very welcome.


skidracer(Posted 2014) [#2]
You don't say if you have changed your code from ctrl key checking to cmd key checking.

You may want to study the MaxIDE source code if it's behaviour is what you are after.


Chalky(Posted 2014) [#3]
I was (event.mods=8) but have finally realised that event.data returns ASCII values on Mac, which is why 26 ("Z" key) didn't work. After changing the Case statements (e.g. to 90,122) the filter works as expected.

However, the problem with quotes (single and double) remains. DebugLog shows the value returned in event.data for single/double quotes as 39/34 respectively.

My function for saving the Textareatext is:
Function DOC_Save()
	Local FileO:TStream=WriteFile(AppDir+"/notes.txt")
	Local TextOut:String=TextAreaText(txtContent)
	Local Content:String[]=TextOut.Split("~n")
	
	If FileO Then
		WriteLine FileO,"Content="+Content[0]
		For Local k:Long=1 To Content.Length-1
			WriteLine FileO,Content[k]
		Next 
		CloseFile FileO
	EndIf
EndFunction

This works fine on PC - but these are getting stripped out during the write on Mac (i.e. after saving, file notes.txt contains everything except ASCII 34 and 39 characters). Could it be that the Textarea is actually substituting other characters? For example, if I type "hello" (including quotes), the 2nd double quote definitely looks different to the 1st despite my typing the same character twice. Maybe I need to intercept this via the filter and force a Chr(34) instead of whatever it's inserting?


Chalky(Posted 2014) [#4]
Yep - the TextArea was changing the characters. I trapped the Chr(34/39) keypresses in the filter and manually inserted the required characters using:

Function TXT_Filter:Int(event:TEvent,context:Object)
	Select event.id
		Case EVENT_KEYCHAR
			Select event.data
			Case 34,39
				SetTextAreaText(txtContent,Chr(event.data),TextAreaCursor(txtContent),0)
				SelectTextAreaText(txtcontent,TextAreaCursor(txtContent)+1,0)
				RedrawGadget txtContent
				Return 0
			EndSelect
		EndSelect
End Function


and all is well - everything now saves and loads correctly.

I do have to question why the gadget behaves that way? Surely if the user presses a Chr(34) the TextArea should insert a Chr(34) - like it does on Windows?


Brucey(Posted 2014) [#5]
I do have to question why the gadget behaves that way?

The TextArea *should* perform the same on ALL platforms. If it doesn't consider it a bug.
Writing cross-platform GUI libraries which work the same on all platforms is difficult. Other alternatives do exist - like Qt and wxWidgets, which also aim to provide an identical service across platforms - they have the advantage of more than just Skid working on it.

You should *never* have to hack basic functionality for multiple platforms, if the intention of the library you are using is that it works the same on all - it just makes *your* job a nightmare.
Hence I consider these things are bugs.


skidracer(Posted 2014) [#6]
I kind of like the way MacOS turns double quotes into matching 66 99 quotes, it certainly looks better on a printed page.

MaxGUI was never intended to dumb all platforms down to the same level, only allow easy access in a uniform manner so simple desktop gadget based apps could be easily created with BlitzMax.