I can't find anything in the help file.

Code: Select all
Procedure LoadRTF(gadget, filename.s)
CocoaMessage(0,GadgetID(gadget),"readRTFDFromFile:$",@filename)
EndProcedure
Procedure.s GetEditorRTF(gadget)
Protected range.NSRange, result.s, length, theData
range\location = 0
range\length = Len(GetGadgetText(gadget))
CocoaMessage(@nsData,GadgetID(gadget),"RTFFromRange:@",@range)
If nsData
length = CocoaMessage(0,nsData,"length")
theData = CocoaMessage(0,nsData,"bytes")
result = PeekS(theData,length,#PB_UTF8) ; #PB_Ascii or #PB_UTF8 ?
EndIf
ProcedureReturn result
EndProcedure
Procedure Btn1_Clicked()
Protected filename.s = OpenFileRequester("Open RTF","","*.rtf",0)
If filename
LoadRTF(0,filename)
EndIf
EndProcedure
Procedure Btn2_Clicked()
Protected rtf.s = GetEditorRTF(0)
Debug rtf
Debug "-[RTF ends]---------------------------------------------------"
EndProcedure
If OpenWindow(0, 0, 0, 640, 480, "EditorGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
EditorGadget(0, 0, 0, 640, 455)
CocoaMessage(0,GadgetID(0),"setRichText:",#YES) ; enable RichText
CocoaMessage(0,GadgetID(0),"setAutomaticLinkDetectionEnabled:",#YES) ; Link detection
CocoaMessage(0,GadgetID(0),"setImportsGraphics:",#YES) ; import images
;CocoaMessage(0,GadgetID(0),"setAllowsImageEditing:",#YES) ; allow image editing
;CocoaMessage(0,GadgetID(0),"setRulerVisible:",#YES) ; enable Ruler
;CocoaMessage(0,GadgetID(0),"setUsesRuler:",#YES) ; enable Ruler
;CocoaMessage(0,GadgetID(0),"updateRuler") ; update Ruler
ButtonGadget(1,440,455,100,25,"Load RTF")
BindGadgetEvent(1,@Btn1_Clicked())
ButtonGadget(2,540,455,100,25,"Get RTF")
BindGadgetEvent(2,@Btn2_Clicked())
For a = 0 To 5
AddGadgetItem(0, a, "Line "+Str(a))
Next
SetActiveGadget(0)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
Procedure Btn2_Clicked()
Protected rtf.s = GetEditorRTF(0)
Debug rtf
Debug "-[RTF ends]---------------------------------------------------"
If CreateFile(0,GetHomeDirectory()+"output_test.rtf")
WriteString(0,rtf,#PB_UTF8)
CloseFile(0)
EndIf
EndProcedure
Code: Select all
Procedure SaveRTF(gadget, directoryName.s)
CocoaMessage(0,GadgetID(gadget),"writeRTFDToFile:$",@directoryName,"atomically:",#NO)
EndProcedure
SaveRTF(0,GetHomeDirectory()+"output_test_2")
Code: Select all
Procedure SaveFormattedText(EditorGadget, FileName.s, Type.s = "NSRTF")
; Type can be "NSPlainText", "NSRTF", "NSHTML", "NSDocFormat", "NSWordML", "NSOfficeOpenXML", "NSOpenDocument"
Protected.i range.NSRange, attributes, dataObj, textStorage = CocoaMessage(0, GadgetID(EditorGadget), "textStorage")
CocoaMessage(@range\length, textStorage, "length")
CocoaMessage(@attributes, 0, "NSDictionary dictionaryWithObject:$", @Type, "forKey:$", @"DocumentType")
CocoaMessage(@dataObj, textStorage, "dataFromRange:@", @range, "documentAttributes:", attributes, "error:", #Null)
ProcedureReturn CocoaMessage(0, dataObj, "writeToFile:$", @FileName, "atomically:", #NO)
EndProcedure
Code: Select all
SaveFormattedText(0, "MyFile.rtf", "NSRTF"); save as rtf file
Code: Select all
Procedure SaveRTFBuffer(gadget, filename.s)
Protected range.NSRange, result, length, theData, file
range\location = 0
range\length = Len(GetGadgetText(gadget))
CocoaMessage(@nsData,GadgetID(gadget),"RTFFromRange:@",@range)
If nsData
length = CocoaMessage(0,nsData,"length")
theData = CocoaMessage(0,nsData,"bytes")
If theData
file = CreateFile(#PB_Any,filename)
If file
WriteData(file,theData,length)
CloseFile(file)
result = #True
EndIf
EndIf
EndIf
ProcedureReturn result
EndProcedure
Code: Select all
CocoaMessage(0,GadgetID(0),"setAllowsUndo:",#YES) ; allow UNDO