This week since releasing the RTFSource, I decided to expand the RTF Formatting, I've figured out Numeric Lists, Alphabetic Lists ( both upper & Lower Case), and Roman Numeral Lists(Bot upper & Lower), and I have (today) have Images working perfectly.
I've hit a wall with "Tables". I have them working last on 5.40 X64 (I didn't try the X86) and then it stops. Sadly the code to have Imaged doesn't work on 5.40, but does of 5.71, in which Tables no longer work.
I have everything working on 6.12 X86 and 6.12 X64..xcept Tables.
Here is the verified correct code for Tables in RTF:
{\rtf1\ansi\deff0
\trowd
\cellx1000
\cellx2000
\cellx3000
\intbl cell 1\cell
\intbl cell 2\cell
\intbl cell 3\cell
\row
}
Here is a runnable PureBasic encapsulation
I have Included some simple Bold, Italics, Strike-Out, and underline for proof of rtf...
Thanks in advance...
Pete
Code: Select all
Enumeration
#Window_frmMain
#Window_frmMain_MainMenu
#Gadget_frmMain_Edit_Note
#Window_frmMain_Menu_InsertTable
#Window_frmMain_Menu_Bold
#Window_frmMain_Menu_Italics
#Window_frmMain_Menu_UnderScore
#Window_frmMain_Menu_StrikeOut
#Gadget_frmMain_BtnImg_Bold
#Gadget_frmMain_BtnImg_Italics
#Gadget_frmMain_BtnImg_UnderScore
#Gadget_frmMain_BtnImg_StrikeOut
EndEnumeration
Procedure Editor_Format(Gadget, flags, alternate=0)
Protected format.CHARFORMAT2
format\cbSize = SizeOf(CHARFORMAT2)
If alternate
SendMessage_(GadgetID(Gadget), #EM_GETCHARFORMAT, 1, @format)
flags=format\dwEffects!flags
EndIf
format\dwMask = #CFM_ITALIC|#CFM_BOLD|#CFM_STRIKEOUT|#CFM_UNDERLINE|#CFM_LINK|#CFM_SUBSCRIPT|#CFM_SUPERSCRIPT
format\dwEffects = flags
SendMessage_(GadgetID(Gadget), #EM_SETCHARFORMAT, #SCF_SELECTION, @format)
EndProcedure
Procedure AddTextRTF(Gadget, Text.s , NewLine=#False)
If Left(Text, 5) <> "{\rtf"
Text = "{\rtf " + Text + "}"
EndIf
If NewLine
Text = Left(Text, Len(text) - 1) + "\line}"
EndIf
CompilerIf #PB_Compiler_Unicode
Protected hEdit = GadgetID(Gadget)
Protected ndx = GetWindowTextLength_(hEdit)
Protected *szBuffer = UTF8(Text)
SendMessage_(hEdit, #EM_SETSEL, ndx, ndx)
SendMessage_(hEdit, #EM_REPLACESEL, 0, *szBuffer)
FreeMemory(*szBuffer)
CompilerElse
AddGadgetItem(Gadget, -1 , Text)
CompilerEndIf
EndProcedure
Procedure.i InsertTable(Gadget)
Protected i, j, rtfTable.s
;initial \par adds a line feed To ensure table starts on new line.
;trgaph sets marginLeft in cells, in twips (here 30 twips)
rtfTable = "{\rtf1\ansi\deff0"
rtfTable + "\trowd"
rtfTable + "\cellx1000"
rtfTable + "\cellx2000"
rtfTable + "\cellx3000"
rtfTable + "\intbl cell 1\cell"
rtfTable + "\intbl cell 2\cell"
rtfTable + "\intbl cell 3\cell"
rtfTable + "\row"
rtfTable + "}"
Debug rtfTable
ProcedureReturn AddTextRTF(Gadget, rtfTable, #False)
EndProcedure
Procedure Bold(Gadget, Value)
Editor_Format(Gadget, #CFE_BOLD, Value)
EndProcedure
Procedure Italics(Gadget, Value)
Editor_Format(Gadget, #CFE_ITALIC, Value)
EndProcedure
Procedure Underline(Gadget, Value)
Editor_Format(Gadget, #CFE_UNDERLINE, Value)
EndProcedure
Procedure StrikeOut(Gadget, Value)
Editor_Format(Gadget, #CFE_STRIKEOUT, Value)
EndProcedure
Procedure Menu_Window_frmMain()
If CreateImageMenu(#Window_frmMain_MainMenu, WindowID(#Window_frmMain))
MenuTitle("Insert")
MenuItem(#Window_frmMain_Menu_InsertTable, "Table", 0)
MenuTitle("Edit")
MenuItem(#Window_frmMain_Menu_Bold , "Bold", 0)
MenuItem(#Window_frmMain_Menu_Italics , "Itallics", 0)
MenuItem(#Window_frmMain_Menu_UnderScore , "Under Score", 0)
MenuItem(#Window_frmMain_Menu_StrikeOut , "Strike Out", 0)
EndIf
EndProcedure
Procedure Open_Window_frmMain()
If OpenWindow(#Window_frmMain, 0, 0, 500, 500, "RTF", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget | #PB_Window_ScreenCentered)
EditorGadget(#Gadget_frmMain_Edit_Note, 5, 5, 490, 490, #PB_Editor_WordWrap)
ProcedureReturn #True
EndIf
EndProcedure
Define BLD, ITA, UDL, STH
Define Quit_frmMain, EventID, MenuID, GadgetID, WindowID
If Open_Window_frmMain()
Menu_Window_frmMain()
ClearGadgetItems(#Gadget_frmMain_Edit_Note)
SendMessage_(GadgetID(#Gadget_frmMain_Edit_Note), #EM_SETTEXTMODE, #TM_RICHTEXT, 0)
Quit_frmMain = #False
Repeat
EventID =WaitWindowEvent()
MenuID =EventMenu()
GadgetID =EventGadget()
WindowID =EventWindow()
Select EventID
Case #PB_Event_CloseWindow
Quit_frmMain = #True
Case #PB_Event_Menu
Select MenuID
Case #Window_frmMain_Menu_InsertTable
Select EventType()
Case #PB_EventType_LeftClick
InsertTable(#Gadget_frmMain_Edit_Note)
EndSelect
Case #Window_frmMain_Menu_Bold
Select EventType()
Case #PB_EventType_LeftClick
If BLD
BLD=#False
Bold(#Gadget_frmMain_Edit_Note, #True)
;SetGadgetState(#Gadget_frmMain_BtnImg_Bold, #False)
Else
Bold(#Gadget_frmMain_Edit_Note, #True)
BLD=#True
;SetGadgetState(#Gadget_frmMain_BtnImg_Bold, #True)
EndIf
EndSelect
Case #Window_frmMain_Menu_Italics
Select EventType()
Case #PB_EventType_LeftClick
If ITA
ITA=#False
Italics(#Gadget_frmMain_Edit_Note, #True)
;SetGadgetState(#Gadget_frmMain_BtnImg_Itallics, #False)
Else
Italics(#Gadget_frmMain_Edit_Note, #True)
ITA=#True
;SetGadgetState(#Gadget_frmMain_BtnImg_Itallics, #True)
EndIf
EndSelect
Case #Window_frmMain_Menu_UnderScore
Select EventType()
Case #PB_EventType_LeftClick
If UDL
UDL=#False
Underline(#Gadget_frmMain_Edit_Note, #True)
;SetGadgetState(#Gadget_frmMain_BtnImg_UnderScore, #False)
;SetGadgetAttribute(#Gadget_frmMain_BtnImg_UnderScore, #PB_Button_Image, ImageID(#Imag_frmMain_Underline))
Else
UDL=#True
Underline(#Gadget_frmMain_Edit_Note, #True)
;SetGadgetState(#Gadget_frmMain_BtnImg_UnderScore, #True)
;SetGadgetAttribute(#Gadget_frmMain_BtnImg_UnderScore, #PB_Button_Image, ImageID(#Image_frmMain_UnderScorePush))
EndIf
EndSelect
Case #Window_frmMain_Menu_StrikeOut
Select EventType()
Case #PB_EventType_LeftClick
If STH
STH=#False
StrikeOut(#Gadget_frmMain_Edit_Note, #True)
;SetGadgetState(#Gadget_frmMain_BtnImg_StrikeThru, #False)
;SetGadgetAttribute(#Gadget_frmMain_BtnImg_StrikeThru, #PB_Button_Image, ImageID(#Imag_frmMain_StrikeOut))
Else
StrikeOut(#Gadget_frmMain_Edit_Note, #True)
STH=#True
;SetGadgetState(#Gadget_frmMain_BtnImg_StrikeThru, #True)
;SetGadgetAttribute(#Gadget_frmMain_BtnImg_StrikeThru, #PB_Button_Image, ImageID(#Image_frmMain_StrikeThruPush))
EndIf
EndSelect
Case #Window_frmMain_Menu_StrikeOut
Select EventType()
EndSelect
EndSelect
Case #PB_Event_Gadget
EndSelect
Until Quit_frmMain
EndIf
End
// Moved from "Game Programming" to "Coding Questions" (Kiffi)


