Page 1 of 1

View/Edit proper table in editorgadget

Posted: Wed Feb 21, 2007 9:35 pm
by Uncle B
Hey Everyone!

I've managed to insert a table into the editor gadget by translating the code from the following link: http://www.codeproject.com/docview/Tabl ... editor.asp
Procedure OnInsertTable(gadget, rows.l, cols.l)

tbl.settextex\flags = #ST_SELECTION
tbl.settextex\codepage = 1200

s.s = "{\rtf1";

sTable.s = s
sTable + "\ansi\ansicpg1252\deff0\deflang1033{\fonttbl"
sTable + "{\f0\froman\fprq2\fcharset0 Times New Roman;}"
sTable + "{\f1\fswiss\fcharset0 Arial;}}"
sTable + "{\*\generator Msftedit 5.41.15.1503;}\viewkind4\uc1";

row.s = ""

row + "\trowd\trgaph108\trleft8\"
row + "trbrdrl\brdrs\brdrw10 \trbrdrt\"
row + "brdrs\brdrw10 \trbrdrr\brdrs\"
row + "brdrw10 \trbrdrb\brdrs\brdrw10 \"
row + "trpaddl108\trpaddr108\trpaddfl3\trpaddfr3";

col.s = ""
col + "\clbrdrl\brdrw10\brdrs\clbrdrt\brdrw10\brdrs\clbrdrr\"
col + "brdrw10\brdrs\clbrdrb\brdrw10\brdrs\cellx";

endcell.s = "\cell";
endrow.s = "\row";
width.l = 8748/cols;

;Loop For numbers of rows

For i = 0 To rows

sTable = sTable + row;

;Loop For number of columns
For j = 0 To cols

sTable = sTable + col;
sTable = sTable + Str(width * (j+1))

Next


sTable = sTable + "\pard\intbl";

For j = 0 To cols
sTable = sTable + endcell;
Next

sTable = sTable + endrow + Chr(10);

Next

sTable = sTable + "\par}";/

Debug sTable


SendMessage_(GadgetID(gadget), #EM_SETTEXTEX, @tbl, @sTable)




EndProcedure

so far so good, but when I use this code the table get's inserted but won't properly wrap and resize with the text inside the cells. also i'm not able to hide the borders with a 'Paraformat2' api function. after days of googling i'm quite sure that the PB editorgadget uses the windows riched20.dll instead of msftedit.dll wich has better functionality with rtf tables.... I hope i'm wrong...

Does anyone here have any idea on how to set up the editorgadget to properly view tables? (please don't tell me to buy a $500 rich edit control.. :wink: )

thanks in advance!

Bart

Posted: Thu Feb 22, 2007 4:00 am
by netmaestro
Well, you can get one of these going with this:

Code: Select all

Procedure MySetGadgetText(gadget, text.s)
  txt.SETTEXTEX
  txt\flags = 0
  txt\codepage = #CP_ACP
  SendMessage_(gadget, #EM_SETTEXTEX, @txt, @text)
EndProcedure

OpenLibrary(0,"msftedit.dll") 
OpenWindow(0,0,0,320,240,"",$cf0001) 
InitCommonControls_() 

flags = #WS_CHILD|#WS_VISIBLE|#ES_MULTILINE|#WS_VSCROLL|#ES_NOHIDESEL|#ES_AUTOVSCROLL|#ES_WANTRETURN 

hRichEd = CreateWindowEx_(#WS_EX_CLIENTEDGE,"RichEdit50W","",flags, 0, 0, 320, 240, WindowID(0), 0, GetModuleHandle_(0), 0) 
SendMessage_(hRichEd, #WM_SETFONT, GetStockObject_(#DEFAULT_GUI_FONT), 0)
MySetGadgetText(hRichEd, "Holy animal crackers Batman, it's a zebra!")

Repeat:Until WaitWindowEvent() = #WM_CLOSE 

DestroyWindow_(hRichEd)                                          
CloseLibrary(0)
but you'll have to manage it using API messages, as it isn't a PureBasic native control. Here's where someone has done some work with it, should give some ideas:

http://www.codeproject.com/richedit/CRi ... ct=1066649

The PB EditorGadget only takes a few native commands to begin with, so replacing them with messages shouldn't be too much hardship. I implemented one for fun, SetGadgetText().

Posted: Thu Feb 22, 2007 1:48 pm
by Uncle B
:D Works great!!! Thanks!!
I've inserted a table with the code from my previous message and the table expands with the text and I can press enter!!!!!!!!!!!!!