Posted: 2 Oct 2007 7:02
Here are the codes for richControl.pro corresponding to richControl.cnt.
Use setText() and setStyle() to initialize the control.
Chan Bok
Axon Research
Use setText() and setStyle() to initialize the control.
Code: Select all
implement richControl
inherits window, controlSupport
open core, vpiDomains, gui_native
constants
className = "axon/rich/richControl".
classVersion = "".
clauses
classInfo(className, classVersion).
%============================
% CONSTANTS
%============================
constants
em_STREAMIN = 1097.
em_STREAMOUT = 1098.
% sf_text = 0x0001.
sf_rtf = 0x0002.
%============================
% DOMAINS
%============================
domains
editstream = editstream(unsigned32 Cookie,unsigned32 Error,stream_callback).
% Cookie domains can also be a string or cookie = cookie(unsigned).
stream_callback = (unsigned32 Cookie,string Buff,unsigned Cb,unsigned Pb) ->
unsigned32 determ (i,i,i,o) language stdcall.
%============================
% FACTS
%============================
class facts
content_ : string := "".
% Not a good design to use class facts, but difficult otherwise.
facts
hwnd_ : windowHandle := erroneous.
style_ : unsigned := 0.
%============================
% NEW
%============================
clauses
new(Parent):-
new(),
setContainer(Parent).
new():-
window::new(),
controlSupport::new(This),
generatedInitialize().
%============================
% SETSTYLE An interface
%============================
setStyle(Style):- style_ := Style. % Style is windows native style
%============================
% SHOW
%============================
clauses
show():-
rich::richLoadDLL(DLL_class), % - (o) Usually DLL_class = "RichEdit50W"
% Above loads "Msftedit.dll" at most once
Container = getContainer(),
_RichWin = vpi::createCustomControl(getEventHandler(), getRect(),
u_dlgbase, "", Container:getVpiWindow(), getState(), getCtrlId()), % Note - hardcoded for u_dlgbase only
Style = ws_child + style_,
% e.g. style_ = ws_visible + ws_vscroll + es_multiline + es_autovscroll + es_nohidesel + es_readonly,
% Note - vscrollbar is created in hwnd_, not in RichWin
getClientSize(Width, Height),
hwnd_ := gui_native::createWindowEx(0,DLL_class,"",Style,
0,0,Width,Height,getVpiWindow(),null,mainExe::getCurrentHinstance(),null),
content_ := getText(),
Cookie = convert(unsigned32,0+0), % Trick to avoid compiler warning "Superfluous conversion..."
ESTREAM = editstream(Cookie,0,rich_callback),
LPARAM = uncheckedConvert(integer,ESTREAM),
_NoChar = vpi::winSendEvent(hwnd_,e_Native(em_STREAMIN,sf_rtf,LPARAM)). % Access violation here if Cookie is a constant
%============================
% CALLBACK
%============================
class predicates % object predicate (i.e. std call) cannot be used as a value (gives privileged instruction error)
rich_callback : stream_callback. % - (i,i,i,o)
clauses
rich_callback(_Cookie,Buff,Cb,Actual) = 0:-!,
stream_in(Buff,Cb,Actual). % - (i,i,o)
class predicates
stream_in: (string Buff,unsigned Cb,unsigned Actual) procedure (i,i,o).
clauses
stream_in(Buff,Cb,Cb):- % Case(1) All but last Streams (Observed Cb=4094)
Len = string::length(content_),
Cb < (Len+Len),!,
string::front(content_,Cb div 2,Front,Rest),
content_ := Rest,
Source = uncheckedConvert(pointer,Front),
Dest = uncheckedConvert(pointer,Buff),
memory::copy(Dest,Source,convert(byteCount,Cb)).
stream_in(Buff,_Cb,ActualRead*2):- % Case(2) Last Stream
ActualRead = string::length(content_),
Source = uncheckedConvert(pointer,content_),
Dest = uncheckedConvert(pointer,Buff),
memory::copy(Dest,Source,ActualRead*2),
content_ := "".
%============================
% ONSIZE Without this vscrollbar won't be resized
%============================
predicates
onSize : window::sizeListener.
clauses
onSize(_Source):-
getClientSize(Width, Height), % This is in pixel
vpi::winMove(hwnd_,rct(0,0,Width,Height)).
%============================
% AUTO CODES
%============================
% This code is maintained automatically, do not update it manually. 14:05:40-1.10.2007
facts
predicates
generatedInitialize : ().
clauses
generatedInitialize():-
setText("richControl"),
This:setSize(148, 74),
addSizeListener(onSize).
% end of automatic code
end implement richControl
Chan Bok
Axon Research