12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188 |
- {
- This file is part of the Free Pascal run time library.
- Copyright (c) 2019-Now by Michael Van Canneyt, member of the
- Free Pascal development team
- WEB Widget Set : Basic bare HTML Widgets
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- **********************************************************************}
- unit htmlwidgets;
- {$mode objfpc}
- interface
- uses
- Classes, SysUtils, webwidget, js, web;
- Type
- TTextMode = (tmText,tmHTML);
- { TButtonWidget }
- TButtonWidget = Class(TWebWidget)
- private
- FText: String;
- FTextMode: TTextMode;
- procedure SetText(AValue: String);
- procedure SetTextMode(AValue: TTextMode);
- Protected
- procedure ApplyText(aElement: TJSHTMLElement);
- Procedure SetName(const NewName: TComponentName); override;
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Public
- Procedure Click;
- Function HTMLTag : String; override;
- Published
- Property Text : String Read FText Write SetText;
- Property TextMode : TTextMode Read FTextMode Write SetTextMode;
- end;
- { TViewPort }
- TViewPort = Class(TCustomWebWidget)
- Private
- Class var FInstance : TViewPort;
- Protected
- Class Function FixedParent : TJSHTMLElement; override;
- Class Function FixedElement : TJSHTMLElement; override;
- Function DoRenderHTML(aParent,aElement : TJSHTMLElement) :TJSHTMLElement; override;
- Public
- Constructor Create (aOwner: TComponent); override;
- Function HTMLTag : String; override;
- Class Function Instance : TViewPort;
- Property Element;
- end;
- { TWebPage }
- TWebPage = Class(TCustomWebWidget)
- private
- Protected
- Class Function DefaultParentElement: TJSHTMLElement; override;
- Class Function DefaultParent : TCustomWebWidget; override;
- Procedure DoUnRender(aParent : TJSHTMLElement) ; override;
- Public
- Constructor Create(AOwner : TComponent); override;
- Function HTMLTag : String; override;
- // Later on, allow IFrame;
- Published
- Property ParentID;
- Property ElementID;
- Property Classes;
- Property Styles;
- Property StyleRefresh;
- Property Visible;
- // Events
- Property BeforeRenderHTML;
- Property AfterRenderHTML;
- Property OnAbort;
- Property OnAnimationCancel;
- Property OnAnimationEnd;
- Property OnAnimationIteration;
- Property OnAnimationStart;
- Property OnAuxClick;
- Property OnBlur;
- Property OnCancel;
- Property OnCanPlay;
- Property OnCanPlayThrough;
- Property OnChange;
- Property OnClick;
- Property OnCompositionEnd;
- Property OnCompositionStart;
- Property OnCompositionUpdate;
- Property OnContextMenu;
- Property OnCopy;
- Property OnCut;
- Property OnCueChange;
- Property OnDblClick;
- Property OnDurationChange;
- Property OnEnded ;
- Property OnError ;
- Property OnFocus;
- Property OnFocusIn ;
- Property OnFocusOut ;
- Property OnGotPointerCapture;
- Property OnInput;
- Property OnInvalid;
- Property OnKeyDown;
- Property OnKeyPress;
- Property OnKeyUp;
- Property OnLoad;
- Property OnLoadedData;
- Property OnLoadedMetaData;
- Property OnLoadend;
- Property OnLoadStart;
- Property OnLostPointerCapture;
- Property OnMouseDown;
- Property OnMouseEnter;
- Property OnMouseLeave;
- Property OnMouseMove;
- Property OnMouseOut;
- Property OnMouseUp;
- Property OnOverFlow;
- Property OnPaste;
- Property OnPause;
- Property OnPlay;
- Property OnPointerCancel;
- Property OnPointerDown;
- Property OnPointerEnter;
- Property OnPointerLeave;
- Property OnPointerMove;
- Property OnPointerOut;
- Property OnPointerOver;
- Property OnPointerUp;
- Property OnReset;
- Property OnResize;
- Property OnScroll;
- Property OnSelect;
- Property OnSubmit;
- Property OnTouchStart;
- Property OnTransitionCancel;
- Property OnTransitionEnd;
- Property OnTransitionRun;
- Property OnTransitionStart;
- Property OnWheel;
- end;
- { TCustomInputWidget }
- TCustomInputWidget = Class(TWebWidget)
- private
- FValue : String;
- FValueName : String;
- FText : String;
- FReadOnly : Boolean;
- FRequired : Boolean;
- function GetReadOnly: Boolean;
- function GetRequired: Boolean;
- function GetText: String;
- function GetValue: String;
- function GetValueName: String;
- procedure SetReadonly(AValue: Boolean);
- procedure SetRequired(AValue: Boolean);
- procedure SetText(AValue: String);
- procedure SetValue(AValue: String);
- function GetInputElement: TJSHTMLInputElement;
- procedure SetValueName(AValue: String);
- Protected
- Procedure SetName(const NewName: TComponentName); override;
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Property InputElement : TJSHTMLInputElement Read GetInputElement;
- // Text to show (checkbox etc). Enable in descendents as needed
- Property Text : String Read GetText Write SetText;
- Public
- function InputType : String; virtual; abstract;
- Function HTMLTag : String; override;
- // Value as string
- Property Value : String Read GetValue Write SetValue;
- // Value Name to use when submitting using form.
- Property ValueName : String Read GetValueName Write SetValueName;
- Property ReadOnly : Boolean Read GetReadOnly Write SetReadonly;
- Property Required : Boolean Read GetRequired Write SetRequired;
- end;
- { TTextInputWidget }
- TInputTextType = (ittText,ittPassword,ittNumber,ittEmail,ittSearch,ittTelephone,ittURL,ittColor);
- TTextInputWidget = class(TCustomInputWidget)
- private
- FMaxLength : Integer;
- FMinLength : Integer;
- FTextType : TInputTextType;
- function GetAsNumber: NativeInt;
- function GetMaxLength: NativeInt;
- function GetMinLength: NativeInt;
- function GetTextType: TInputTextType;
- procedure SetAsNumber(AValue: NativeInt);
- procedure SetMaxLength(AValue: NativeInt);
- procedure SetMinLength(AValue: NativeInt);
- procedure SetTextType(AValue: TInputTextType);
- Protected
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Public
- Class Function AllowChildren : Boolean; override;
- function InputType : String; override;
- Published
- Property Value;
- Property ValueName;
- Property Required;
- Property TextType : TInputTextType Read GetTextType Write SetTextType;
- property AsNumber : NativeInt Read GetAsNumber Write SetAsNumber;
- Property MaxLength : NativeInt Read GetMaxLength Write SetMaxLength;
- Property MinLength : NativeInt Read GetMinLength Write SetMinLength;
- // Todo: List support
- end;
- { TButtonInputWidget }
- TInputButtonType = (ibtSubmit,ibtReset,ibtImage);
- TInputButtonTypes = set of TInputButtonType;
- TButtonInputWidget = class(TCustomInputWidget)
- private
- FButtonType: TInputButtonType;
- FSrc: String;
- procedure SetButtonType(AValue: TInputButtonType);
- procedure SetSrc(AValue: String);
- Public
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- function InputType : String; override;
- Class Function AllowChildren : Boolean; override;
- Published
- Property ButtonType : TInputButtonType Read FButtonType Write SetButtonType;
- Property Value;
- Property ValueName;
- Property Src : String Read FSrc Write SetSrc;
- end;
- { TCheckableInputWidget }
- TCheckableInputWidget = class(TCustomInputWidget)
- private
- FChecked: Boolean;
- function GetChecked: Boolean;
- procedure SetChecked(AValue: Boolean);
- Protected
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Public
- Property Value;
- Property ValueName;
- Property Checked : Boolean Read GetChecked Write SetChecked;
- Property Text;
- end;
- { TRadioInputWidget }
- TRadioInputWidget = class(TCheckableInputWidget)
- private
- Public
- function InputType : String; override;
- Published
- Property Value;
- Property ValueName;
- Property Checked;
- Property Text;
- end;
- { TCheckboxInputWidget }
- TCheckboxInputWidget = class(TCheckableInputWidget)
- private
- Public
- function InputType : String; override;
- Published
- Property Value;
- Property ValueName;
- Property Checked;
- Property Text;
- end;
- { TDateInputWidget }
- TDateInputWidget = class(TCustomInputWidget)
- private
- FDate: TDateTime;
- function GetDate: TDateTime;
- procedure SetDate(AValue: TDateTime);
- Public
- function InputType : String; override;
- Class Function AllowChildren : Boolean; override;
- Published
- Property Required;
- Property ValueName;
- Property Date : TDateTime Read GetDate Write SetDate;
- end;
- { TFileInputWidget }
- TFileInfo = record
- Name : String;
- TimeStamp : TDateTime;
- FileType : String;
- Size : NativeInt;
- end;
- TFileInputWidget = class(TCustomInputWidget)
- private
- FMultiple: Boolean;
- function GetFileCount: Integer;
- function GetFileDate(aIndex : Integer): TDateTime;
- function GetFileInfo(aIndex : Integer): TFileInfo;
- function GetFileName(aIndex : Integer): String;
- function GetFileSize(aIndex : Integer): NativeInt;
- function GetFileType(aIndex : Integer): String;
- function GetMultiple: Boolean;
- procedure SetMultiple(AValue: Boolean);
- Protected
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Public
- Class Function AllowChildren : Boolean; override;
- function InputType : String; override;
- Property FileCount : Integer read GetFileCount;
- Property Files[aIndex : Integer] : String Read GetFileName;
- Property FileSizes[aIndex : Integer] : NativeInt Read GetFileSize;
- Property FileTypes[aIndex : Integer] : String Read GetFileType;
- Property FileDates[aIndex : Integer] : TDateTime Read GetFileDate;
- Property FileInfos[aIndex : Integer] : TFileInfo Read GetFileInfo;
- Published
- Property ValueName;
- Property Required;
- Property Multiple : Boolean Read GetMultiple Write SetMultiple;
- end;
- { THiddenInputWidget }
- THiddenInputWidget = class(TCustomInputWidget)
- Public
- Class Function AllowChildren : Boolean; override;
- function InputType : String; override;
- Published
- Property ValueName;
- Property Value;
- Property Required;
- end;
- { TTextAreaWidget }
- TTextAreaWrap = (tawSoft,tawHard,tawOff);
- TTextAreaWidget = Class(TWebWidget)
- private
- FLines: TStrings;
- FIgnoreChanges : Boolean;
- FMaxLength: Cardinal;
- FValueName : String;
- FRows,
- FColumns : Cardinal;
- FWrap: TTextAreaWrap;
- FRequired,
- FReadOnly : Boolean;
- procedure ApplyWrap(aElement: TJSHTMLTextAreaElement);
- procedure DoLineChanges(Sender: TObject);
- function GetColumns: Cardinal;
- function GetLines: TStrings;
- function GetReadOnly: Boolean;
- function GetRequired: Boolean;
- function GetRows: Cardinal;
- function GetText: String;
- function GetValueName: string;
- procedure SetColumns(AValue: Cardinal);
- procedure SetLines(AValue: TStrings);
- procedure SetMaxLength(AValue: Cardinal);
- procedure SetReadonly(AValue: Boolean);
- procedure SetRequired(AValue: Boolean);
- procedure SetRows(AValue: Cardinal);
- procedure SetText(AValue: String);
- procedure SetValueName(AValue: string);
- Function GetTextArea : TJSHTMLTextAreaElement;
- procedure SetWrap(AValue: TTextAreaWrap);
- Protected
- procedure ApplyLines(aElement: TJSHTMLTextAreaElement);
- procedure LinesFromHTML(aHTML : String);
- Procedure SetName(const NewName: TComponentName); override;
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Property TextArea :TJSHTMLTextAreaElement Read GetTextArea;
- Public
- Constructor Create(aOwner : TComponent); override;
- Destructor Destroy; override;
- Class Function AllowChildren : Boolean; override;
- Function HTMLTag : String; override;
- Property InnerHTML : String Read GetText Write SetText;
- Published
- Property ValueName : string Read GetValueName Write SetValueName;
- Property Rows : Cardinal Read GetRows Write SetRows;
- Property Columns : Cardinal Read GetColumns Write SetColumns;
- Property Lines : TStrings Read GetLines Write SetLines;
- Property MaxLength : Cardinal Read FMaxLength Write SetMaxLength;
- Property Wrap : TTextAreaWrap Read FWrap Write SetWrap;
- Property ReadOnly : Boolean Read GetReadOnly Write SetReadonly;
- Property Required : Boolean Read GetRequired Write SetRequired;
- end;
- { TImageWidget }
- TImageWidget = class(TWebWidget)
- private
- FHeight: Integer;
- FWidth: Integer;
- FSrc : String;
- function GetHeight: Integer;
- function GetImg: TJSHTMLImageElement;
- function GetSrc: String;
- function GetWidth: Integer;
- procedure SetHeight(AValue: Integer);
- procedure SetSrc(AValue: String);
- procedure SetWidth(AValue: Integer);
- Protected
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Property ImgElement : TJSHTMLImageElement Read GetImg;
- Public
- Function HTMLTag : String; override;
- Published
- Property Src : String Read GetSrc Write SetSrc;
- Property Width : Integer Read GetWidth Write SetWidth;
- Property Height : Integer Read GetHeight Write SetHeight;
- end;
- { TSelectWidget }
- TJSHTMLOptionElementArray = Array of TJSHTMLOptionElement;
- TCustomSelectWidget = Class;
- { TCustomSelectWidget }
- TCustomSelectWidget = class(TWebWidget)
- Private
- FSize,
- FSelectedIndex : Integer;
- FOptions : TJSHTMLOptionElementArray;
- FMultiple : Boolean;
- function GetMultiple: Boolean;
- function GetSelected(Index : Integer): Boolean;
- function GetSelectedIndex: Integer;
- function GetSelect: TJSHTMLSelectElement;
- function GetSelectionCount: Integer;
- function GetSelectionItem(aIndex : Integer): String;
- function GetSelectionValue(aIndex : Integer): String;
- function GetSize: Integer;
- procedure SetMultiple(AValue: Boolean);
- procedure SetSelected(Index : Integer; AValue: Boolean);
- procedure SetSelectedIndex(AValue: Integer);
- procedure SetSize(AValue: Integer);
- Protected
- Type
- { TSelectOptionEnumerator }
- TSelectOptionEnumerator = Class
- private
- FSelect: TCustomSelectWidget;
- public
- constructor Create(ASelect : TCustomSelectWidget); reintroduce; virtual;
- Function OptionText : String; virtual; abstract;
- Function HasValue : boolean; virtual;
- Function Value : string; virtual;
- function MoveNext: Boolean; virtual; abstract;
- Property Select: TCustomSelectWidget Read FSelect;
- end;
- Protected
- function GetItemCount: Integer; virtual;
- Function CreateOptionEnumerator : TSelectOptionEnumerator; virtual; abstract;
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Procedure BuildOptions(aSelect : TJSHTMLSelectElement); virtual;
- Property Options : TJSHTMLOptionElementArray Read Foptions;
- Property SelectElement : TJSHTMLSelectElement Read GetSelect;
- Protected
- // Can be made public/published
- // Items that are selected
- Property ItemCount : Integer Read GetItemCount;
- Property Selected[Index : Integer] : Boolean Read GetSelected Write SetSelected;
- Property SelectionCount : Integer Read GetSelectionCount;
- Property SelectionValue[aIndex : Integer] : String Read GetSelectionValue;
- Property SelectionItem[aIndex : Integer] : String Read GetSelectionItem;
- property SelectedIndex : Integer Read GetSelectedIndex Write SetSelectedindex;
- Property Multiple : Boolean Read GetMultiple Write SetMultiple;
- Property Size : Integer Read GetSize Write SetSize;
- Public
- Constructor Create(aOWner : TComponent); override;
- Function HTMLTag : String; override;
- end;
- TSelectWidget = class(TCustomSelectWidget)
- private
- FItems : TStrings;
- FValues : TStrings;
- function GetItems: TStrings;
- function GetValues: TStrings;
- procedure OptionsChanged(Sender: TObject);
- procedure setItems(AValue: TStrings);
- procedure setValues(AValue: TStrings);
- Protected
- Type
- { TStringsSelectOptionEnumerator }
- TStringsSelectOptionEnumerator = Class(TSelectOptionEnumerator)
- FCurrent : Integer;
- constructor Create(ASelect : TCustomSelectWidget); override;
- Function OptionText : String; override;
- Function HasValue : boolean; override;
- Function Value : string; override;
- function MoveNext: Boolean; override;
- end;
- Function CreateOptionEnumerator: TSelectOptionEnumerator; override;
- Public
- Constructor Create(aOWner : TComponent); override;
- Destructor Destroy; override;
- Property SelectionCount;
- Property SelectionValue;
- Property SelectionItem;
- Property Selected;
- Property Options;
- Property SelectElement;
- Property ItemCount;
- Published
- Property Items : TStrings Read GetItems Write setItems;
- Property Values : TStrings Read GetValues Write setValues;
- property SelectedIndex;
- Property Multiple;
- property size;
- property Classes;
- end;
- { TLabelWidget }
- TLabelWidget = Class(TWebWidget)
- private
- FLabelFor: TWebWidget;
- FText: String;
- function GetLabelEl: TJSHTMLLabelElement;
- function GetText: String;
- procedure SetLabelFor(AValue: TWebWidget);
- procedure SetText(AValue: String);
- Protected
- procedure ApplyLabelFor(aLabelElement: TJSHTMLLabelElement);
- Procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- Procedure SetName(const NewName: TComponentName); override;
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Property LabelElement : TJSHTMLLabelElement Read GetLabelEl;
- Public
- Function HTMLTag : String; override;
- Property Text : String Read GetText Write SetText;
- Property LabelFor : TWebWidget Read FLabelFor Write SetLabelFor;
- end;
- TTextTag = (ttParagraph,ttBold,ttItalic,ttUnderline,ttStrikeThrough,ttSpan,ttQuote,ttBlockQuote,ttH1,ttH2,ttH3,ttH4,ttH5,ttH6,ttPre,ttRuby,ttArticle,ttAddress,ttAbbr,ttCustom);
- { TTextWidget }
- { TCustomTextWidget }
- TCustomTextWidget = Class(TCustomWebWidget)
- private
- FCustomTag: String;
- FEnvelopeTag: TTextTag;
- FTextMode: TTextMode;
- procedure SetCustomTag(AValue: String);
- procedure SetEnvelopeTag(AValue: TTextTag);
- procedure SetTextMode(AValue: TTextMode);
- Protected
- procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- procedure ApplyText(aElement : TJSHTMLElement); virtual;
- Function GetText : String; virtual; abstract;
- Public
- Function HTMLTag : String; override;
- Published
- Property CustomTag : String Read FCustomTag Write SetCustomTag;
- Property EnvelopeTag : TTextTag Read FEnvelopeTag Write SetEnvelopeTag;
- Property TextMode : TTextMode Read FTextMode Write SetTextMode;
- end;
- TTextWidget = Class(TCustomTextWidget)
- private
- FText : String;
- procedure SetText(AValue: String);
- Protected
- Function GetText : String; override;
- published
- Property Text : String Read FText Write SetText;
- end;
- { TTextLinesWidget }
- TTextLinesWidget = Class(TCustomTextWidget)
- private
- FLines : TStrings;
- FForceLineBreaks: Boolean;
- procedure DoLinesChanged(Sender: TObject);
- procedure SetLines(AValue: TStrings);
- procedure SetForceLineBreaks(AValue: Boolean);
- Protected
- Function GetText : String; override;
- procedure ApplyText(aElement : TJSHTMLElement); override;
- Public
- Constructor Create(aOwner : TComponent); override;
- Destructor Destroy; override;
- published
- Property Lines : TStrings Read FLines Write SetLines;
- // When forcelinebreaks is true a <br> will be appended to every line.
- // Note that for TextMode=tmText this means the lines will be rendered as-is, but there will still be a <br> between the lines
- Property ForceLineBreaks : Boolean Read FForceLineBreaks Write SetForceLineBreaks;
- end;
- { TCustomTableColumn }
- TColumnOption = (coHeader,coCaptionHeader);
- TColumnOptions = set of TColumnOption;
- TCustomTableColumn = Class(TCollectionItem)
- private
- FAlignment: TAlignment;
- FCaption: String;
- FClassNames: String;
- procedure SetAlignment(AValue: TAlignment);
- procedure SetCaption(AValue: String);
- procedure SetClassNames(AValue: String);
- Protected
- Function RenderColumn : Boolean; virtual;
- Function GetDisplayName: string; override;
- function GetCaption: String; virtual;
- Public
- Procedure Assign(Source : TPersistent); override;
- Property Alignment : TAlignment Read FAlignment Write SetAlignment;
- Property Caption : String Read GetCaption Write SetCaption;
- Property ClassNames : String Read FClassNames Write SetClassNames;
- end;
- { TCustomTableColumns }
- TCustomTableColumns = Class(TCollection)
- private
- function GetCustomColumn(Index : Integer): TCustomTableColumn;
- procedure SetCustomColumn(Index : Integer; AValue: TCustomTableColumn);
- Protected
- Property CustomColumns [Index : Integer] : TCustomTableColumn Read GetCustomColumn Write SetCustomColumn; default;
- Public
- Function Add(aCaption : String): TCustomTableColumn; overload;
- end;
- { TCustomTableWidget }
- TTableOption = (toHeader, // use THead tag
- toHeaderRow, // Create header row
- toBody, // use TBody tag
- toFooter, // use TFoot tag
- toFooterRow, // create footer row
- toRowID, // add ID to tr: -kind-row
- toCellID, // add ID to cell td: -kind-row-col
- toHeaderRowData, // Add rowno to <tr data-row> for header.
- toHeaderCellDataRow, // Add rowno to <th data-row> for header. Automatic if onheadercellclick is set.
- toHeaderCellDataCol, // Add colno to <th data-col> for header. Automatic if onheadercellclick is set.
- toBodyRowData, // Add rowno to <tr data-row> for body.
- toBodyCellDataRow, // Add rowno to <th data-row> for body. Automatic if oncellclick is set.
- toBodyCellDataCol, // Add colno to <th data-col> for body. Automatic if oncellclick is set.
- tofooterRowData, // Add rowno to <tr data-row> for footer
- tofooterCellDataRow, // Add rowno to <th data-row> for footer. Automatic if onfootercellclick is set.
- tofooterCellDataCol // Add colno to <th data-col> for footer. Automatic if onfootercellclick is set.
- );
- TTableOptions = Set of TTableOption;
- TRowKind = (rkHeader,rkBody,rkFooter);
- Type
- TCustomTableWidget = Class;
- // Constructed only once when rendering !
- { TTableWidgetCelldata }
- TTableWidgetCellData = Class
- private
- FAsHTML: Boolean;
- FClassNames: String;
- FCol: Integer;
- FColumn: TCustomTableColumn;
- FContent: TJSHTMLElement;
- FKind: TRowKind;
- FRow: Integer;
- FTable: TCustomTableWidget;
- FTableID: String;
- FTag: String;
- FText: String;
- FWidget: TWebWidget;
- Protected
- Procedure SetRowColKind(aRow,aCol : Integer; aKind : TRowKind); virtual;
- Procedure Reset; // do not reset row,col, column
- Public
- Constructor Create(aTable : TCustomTableWidget;aTableID : String); virtual;
- Property Table : TCustomTableWidget Read FTable;
- Property Column : TCustomTableColumn Read FColumn Write FColumn;
- Property Row : Integer Read FRow;
- Property Col : Integer Read FCol;
- Property Kind : TRowKind Read FKind;
- Property Tag : String Read FTag Write FTag;
- Property ClassNames : String Read FClassNames Write FClassNames;
- Property Text : String Read FText Write FText;
- Property AsHTML : Boolean Read FAsHTML Write FAsHTML;
- Property Content : TJSHTMLElement Read FContent Write FContent;
- Property Widget : TWebWidget Read FWidget Write FWidget;
- Property TableID : String Read FTableID;
- end;
- TTableRowEnumerator = Class
- private
- FTable: TCustomTableWidget;
- FCurrent : Integer;
- public
- constructor Create(ATable : TCustomTableWidget); reintroduce; virtual;
- Procedure GetCellData(aCell : TTableWidgetCellData); virtual;
- function MoveNext: Boolean; virtual;
- property CurrentRow : Integer Read FCurrent;
- Property Table : TCustomTableWidget Read FTable;
- end;
- TTableRowCountEnumerator = Class (TTableRowEnumerator)
- private
- FRowCount: Integer;
- public
- constructor Create(ATable : TCustomTableWidget;aCount : Integer); reintroduce;
- function MoveNext: Boolean; override;
- Property RowCount : Integer read FRowCount;
- end;
- TOnCellDataEvent = Procedure (Sender : TObject; Enum : TTableRowEnumerator; aCell : TTableWidgetCellData) of object;
- TCustomTableWidget = Class(TCustomWebWidget)
- private
- FCaption: String;
- FColumns: TCustomTableColumns;
- FOnCellClick: THTMLNotifyEvent;
- FOnFooterCellClick: THTMLNotifyEvent;
- FOnFooterRowClick: THTMLNotifyEvent;
- FOnHeaderCellClick: THTMLNotifyEvent;
- FOnHeaderRowClick: THTMLNotifyEvent;
- FOnRowClick: THTMLNotifyEvent;
- FTableOptions: TTableOptions;
- FOnGetCellData : TOnCellDataEvent;
- FWidgets : Array of TWebWidget;
- FUpdateCount : Integer;
- procedure SetCaption(AValue: String);
- procedure SetColumns(AValue: TCustomTableColumns);
- procedure SetTableOptions(AValue: TTableOptions);
- Protected
- procedure AppendCaption(aCaptionElement: TJSHTMLElement); virtual;
- procedure RenderData(aElement: TJSHTMLElement); virtual;
- function DoCellClick(aEvent: TJSMouseEvent): boolean; virtual;
- function DoHeaderCellClick(aEvent: TJSMouseEvent): boolean;virtual;
- function DoFooterCellClick(aEvent: TJSMouseEvent): boolean;virtual;
- function DoRowClick(aEvent: TJSMouseEvent): boolean; virtual;
- function DoHeaderRowClick(aEvent: TJSMouseEvent): boolean;virtual;
- function DoFooterRowClick(aEvent: TJSMouseEvent): boolean;virtual;
- function CreateColumns: TCustomTableColumns; virtual;
- Function DefaultTableOptions: TTableOptions; virtual;
- Procedure CreateDefaultColumns; virtual;
- Function GetRowEnumerator(aKind : TRowKind) : TTableRowEnumerator; virtual;
- function RenderCell(aCell: TTableWidgetCellData): TJSHTMLElement; virtual;
- procedure RenderRow(aEnum : TTableRowEnumerator; aParent: TJSHTMLElement; aKind: TRowKind; aCell: TTableWidgetCellData); virtual;
- procedure RenderRows(aParent: TJSHTMLElement; aKind : TRowKind; aCell: TTableWidgetCellData); virtual;
- Procedure ApplyWidgetSettings(aElement : TJSHTMLElement); override;
- Function HTMLTag : String; override;
- Function CreateCellData(const aTableID : String) : TTableWidgetCellData; virtual;
- Function GetBodyRowEnumerator : TTableRowEnumerator; virtual; abstract;
- Protected
- // These can be made public/published
- Property CustomColumns : TCustomTableColumns Read FColumns Write SetColumns;
- Property TableOptions : TTableOptions read FTableOptions write SetTableOptions;
- Property Caption : String Read FCaption Write SetCaption;
- Property OnGetCellData : TOnCellDataEvent Read FOnGetCellData Write FOnGetCellData;
- Property OnCellClick : THTMLNotifyEvent Read FOnCellClick Write FOnCellClick;
- Property OnHeaderCellClick : THTMLNotifyEvent Read FOnHeaderCellClick Write FOnHeaderCellClick;
- Property OnFooterCellClick : THTMLNotifyEvent Read FOnFooterCellClick Write FOnFooterCellClick;
- Property OnRowClick : THTMLNotifyEvent Read FOnRowClick Write FOnRowClick;
- Property OnHeaderRowClick : THTMLNotifyEvent Read FOnHeaderRowClick Write FOnHeaderRowClick;
- Property OnFooterRowClick : THTMLNotifyEvent Read FOnFooterRowClick Write FOnFooterRowClick;
- Public
- Constructor Create(aOwner : TComponent); override;
- Destructor Destroy; override;
- Procedure BeginUpdate;
- Procedure EndUpdate;
- Procedure RefreshBody;
- end;
- { TEventTableWidget }
- TEventTableWidget = Class(TCustomTableWidget)
- private
- FRowCount: Integer;
- procedure SetRowCount(AValue: Integer);
- Protected
- Function GetBodyRowEnumerator : TTableRowEnumerator; override;
- Published
- Property RowCount : Integer Read FRowCount Write SetRowCount;
- Property CustomColumns;
- Property TableOptions;
- Property Caption;
- Property OnGetCellData;
- Property OnCellClick;
- Property OnHeaderCellClick;
- Property OnFooterCellClick;
- Property OnRowClick;
- Property OnHeaderRowClick;
- Property OnFooterRowClick;
- end;
- { TCustomStringsTableWidget }
- TCustomStringsTableWidget = Class(TCustomTableWidget)
- private
- Type
- TRow = Array of string;
- private
- FRows : Array of TRow;
- function GetRowCount: Integer;
- procedure SetRowCount(AValue: Integer);
- Protected
- Type
- TStringRowsEnumerator = Class(TTableRowCountEnumerator)
- Procedure GetCellData(aCell : TTableWidgetCellData); override;
- end;
- Protected
- Procedure CheckIndex(aCol,aRow : Integer);
- function GetCell(aCol, aRow : integer): String;
- procedure SetCell(aCol, aRow : integer; AValue: String);
- Function GetBodyRowEnumerator : TTableRowEnumerator; override;
- Public
- Property RowCount : Integer Read GetRowCount Write SetRowCount;
- Property Cells[aCol,aRow : integer] : String Read GetCell Write SetCell;
- Property CustomColumns;
- Property TableOptions;
- Property Caption;
- Property OnGetCellData;
- Property OnCellClick;
- Property OnHeaderCellClick;
- Property OnFooterCellClick;
- Property OnRowClick;
- Property OnHeaderRowClick;
- Property OnFooterRowClick;
- end;
- TStringsTableWidget = Class(TCustomStringsTableWidget)
- Published
- Property RowCount;
- Property CustomColumns;
- Property TableOptions;
- Property Caption;
- Property OnGetCellData;
- Property OnCellClick;
- Property OnHeaderCellClick;
- Property OnFooterCellClick;
- Property OnRowClick;
- Property OnHeaderRowClick;
- Property OnFooterRowClick;
- end;
- { TDivWidget }
- THTMLElementTag = (
- etUnknown, eta, etabbr, etacronym, etaddress, etapplet, etarea, etb, etbase,
- etbasefont, etbdo, etbig, etblockquote, etbody, etbr, etbutton,
- etcaption, etcenter, etcite, etcode, etcol, etcolgroup, etdd, etdel,
- etdfn, etdir, etdiv, etdl, etdt, etem, etfieldset, etfont, etform,
- etframe, etframeset, eth1, eth2, eth3, eth4, eth5, eth6, ethead, ethr,
- ethtml, eti, etiframe, etimg, etinput, etins, etisindex, etkbd, etlabel,
- etlegend, etli, etlink, etmap, etmenu, etmeta, etnoframes, etnoscript,
- etobject, etol, etoptgroup, etoption, etp, etparam, etpre, etq, ets,
- etsamp, etscript, etselect, etsmall, etspan, etstrike, etstrong,
- etstyle, etsub, etsup, ettable, ettbody, ettd, ettextarea, ettfoot,
- etth, etthead, ettitle, ettr, ettt, etu, etul, etvar,
- etText,etAudio,etVideo,etSource
- );
- THTMLElementTagSet = set of THTMLElementTag;
- { TCustomTagWidget }
- TCustomTagWidget = Class(TWebWidget)
- private
- FElementTag: THTMLElementTag;
- FTextContent: String;
- procedure SetElementTag(AValue: THTMLElementTag);
- procedure SetTextContent(AValue: String);
- Protected
- Procedure ApplyWidgetSettings(aElement: TJSHTMLElement); override;
- Function HTMLTag : String; override;
- // Set tag you wish to use
- Property elementTag : THTMLElementTag Read FElementTag Write SetElementTag;
- // If set, the text will be set as InnerText of the tag
- Property TextContent : String Read FTextContent Write SetTextContent;
- end;
- { TTagWidget }
- TTagWidget = Class(TCustomTagWidget)
- Public
- Constructor Create(aOwner : TComponent); override;
- Published
- Property elementTag;
- Property TextContent;
- end;
- TDivWidget = Class(TCustomTagWidget)
- Public
- Constructor Create(aOwner : TComponent); override;
- end;
- { TParagraphWidget }
- TParagraphWidget = Class(TCustomTagWidget)
- Public
- Constructor Create(aOwner : TComponent); override;
- end;
- { TMediaWidget }
- TMediaWidget = Class(TCustomTagWidget)
- private
- Const
- MaxAttrs = 20;
- PropAttrs : Array[0..MaxAttrs] of string
- = ('src','defaultPlaybackRate','duration','playbackRate','ended', // 0..4
- 'paused','seeking','sinkId','mediaGroup','currentSrc', // 5..9
- 'volume','controls','autoplay','crossOrigin', 'defaultMuted', // 10..14
- 'currentTime', 'disableRemotePlayback', 'preservesPitch','loop','muted', // 15..19
- 'preload' // 20
- );
- function GetAudioTrack: TJSHTMLAudioTrackList;
- function getBool(AIndex: Integer): Boolean;
- function GetError: TJSMEdiaError;
- function getFloat(AIndex: Integer): Double;
- function GetSrcObj: TJSHTMLMediaStream;
- function getString(AIndex: Integer): String;
- function GetTextTrack: TJSHTMLTextTrackList;
- function GetVideoTrack: TJSHTMLVideoTrackList;
- procedure SetBool(AIndex: Integer; AValue: Boolean);
- procedure SetFloat(AIndex: Integer; AValue: Double);
- procedure SetString(AIndex: Integer; AValue: String);
- function getEl: TJSObject;
- Public
- Property DefaultPlayBackRate : Double Index 1 Read getFloat;
- Property Duration : Double Index 2 Read getFloat;
- Property PlayBackRate : Double Index 3 Read getFloat;
- Property Ended : Boolean Index 4 Read getBool;
- Property Paused : Boolean Index 5 Read getBool;
- Property Seeking : Boolean Index 6 Read getBool;
- Property SinkID : String Index 7 Read getString Write SetString;
- Property MediaGroup : String Index 8 Read getString Write SetString;
- Property SrcObject : TJSHTMLMediaStream Read GetSrcObj;
- Property textTracks : TJSHTMLTextTrackList Read GetTextTrack;
- Property videoTracks : TJSHTMLVideoTrackList Read GetVideoTrack;
- Property audioTracks : TJSHTMLAudioTrackList Read GetAudioTrack;
- Property Error : TJSMEdiaError Read GetError;
- Property CurrentSrc : String Index 9 Read getString;
- Published
- Property Src : String Index 0 Read getString Write SetString;
- Property Controls : Boolean Index 11 Read getBool Write SetBool;
- Property AutoPlay : Boolean Index 12 Read getBool Write SetBool;
- Property CrossOrigin : String index 13 Read getString Write SetString;
- Property DefaultMuted : Boolean Index 14 Read getBool Write SetBool;
- Property CurrentTime : Double Index 15 Read getFloat Write SetFloat;
- Property DisableRemotePlayback : Boolean Index 16 Read getBool Write SetBool;
- Property PreservesPitch : Boolean Index 17 Read getBool Write SetBool;
- Property Loop : Boolean Index 18 Read getBool Write SetBool;
- Property Muted : Boolean Index 19 Read getBool Write SetBool;
- Property Preload : String Index 20 Read getString Write SetString;
- Property Volume : Double Index 10 Read getFloat Write SetFloat;
- end;
- { TVideoWidget }
- TVideoWidget = Class(TMediaWidget)
- Public
- Constructor Create(aOwner : TComponent); override;
- end;
- { TAudioWidget }
- TAudioWidget = Class(TMediaWidget)
- Public
- Constructor Create(aOwner : TComponent); override;
- end;
- Function ViewPort : TViewPort;
- Const
- TextTagNames : Array[TTextTag] of string
- = ('p','b','i','u','s','span','quote','blockquote','h1','h2','h3','h4','h5','h6','pre','ruby','article','address','abbr','');
- RowKindNames : Array[TRowKind] of string = ('header','body','footer');
- HTMLTagNames : Array[THTMLElementTag] of string = (
- '?', 'a', 'abbr', 'acronym', 'address', 'applet', 'area', 'b', 'base',
- 'basefont', 'bdo', 'big', 'blockquote', 'body', 'br', 'button',
- 'caption', 'center', 'cite', 'code', 'col', 'colgroup', 'dd', 'del',
- 'dfn', 'dir', 'div', 'dl', 'dt', 'em', 'fieldset', 'font', 'form',
- 'frame', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'hr',
- 'html', 'i', 'iframe', 'img', 'input', 'ins', 'isindex', 'kbd', 'label',
- 'legend', 'li', 'link', 'map', 'menu', 'meta', 'noframes', 'noscript',
- 'object', 'ol', 'optgroup', 'option', 'p', 'param', 'pre', 'q', 's',
- 'samp', 'script', 'select', 'small', 'span', 'strike', 'strong',
- 'style', 'sub', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot',
- 'th', 'thead', 'title', 'tr', 'tt', 'u', 'ul', 'var',
- 'Text','Audio','Video','Source'
- );
- implementation
- uses DateUtils;
- resourcestring
- SErrInvalidIndex = 'Index %d not in valid range of [0..%d]';
- SErrInvalidRowCount = 'Invalid row count: %d';
- SRow = 'Row';
- SCol = 'Column';
- Function ViewPort : TViewPort;
- begin
- Result:=TViewPort.Instance;
- end;
- { TTableRowCountEnumerator }
- Const
- CellTags : Array[TRowKind] of string = ('th','td','td');
- { TEventTableWidget }
- procedure TEventTableWidget.SetRowCount(AValue: Integer);
- begin
- if FRowCount=AValue then Exit;
- BeginUpdate;
- FRowCount:=AValue;
- EndUpdate;
- end;
- function TEventTableWidget.GetBodyRowEnumerator: TTableRowEnumerator;
- begin
- Result:=TTableRowCountEnumerator.Create(Self,RowCount);
- end;
- { TCustomStringsTableWidget.TStringRowsEnumerator }
- procedure TCustomStringsTableWidget.TStringRowsEnumerator.GetCellData(aCell: TTableWidgetCellData);
- begin
- aCell.Text:=TCustomStringsTableWidget(Table).Cells[aCell.Col,aCell.Row];
- end;
- { TCustomStringsTableWidget }
- function TCustomStringsTableWidget.GetCell(aCol, aRow : integer): String;
- begin
- CheckIndex(aCol,aRow);
- Result:=FRows[aRow][aCol];
- end;
- function TCustomStringsTableWidget.GetRowCount: Integer;
- begin
- Result:=Length(FRows);
- end;
- procedure TCustomStringsTableWidget.SetCell(aCol, aRow : integer; AValue: String);
- begin
- CheckIndex(aCol,aRow);
- BeginUpdate;
- try
- FRows[aRow][aCol]:=AValue;
- Finally
- EndUpdate;
- end;
- end;
- function TCustomStringsTableWidget.GetBodyRowEnumerator: TTableRowEnumerator;
- begin
- Result:=TStringRowsEnumerator.Create(Self,RowCount);
- end;
- procedure TCustomStringsTableWidget.SetRowCount(AValue: Integer);
- begin
- if AValue<0 then
- raise EWidgets.CreateFmt(SerrInvalidRowCount, [aValue]);
- BeginUpdate;
- try
- SetLength(FRows,aValue);
- Finally
- EndUpdate;
- end;
- end;
- procedure TCustomStringsTableWidget.CheckIndex(aCol, aRow: Integer);
- begin
- If (aCol<0) or (aCol>=CustomColumns.Count) then
- Raise EWidgets.CreateFmt(SCol+' '+SErrInvalidIndex,[aCol,0,CustomColumns.Count-1]);
- If (aRow<0) or (aRow>=RowCount) then
- Raise EWidgets.CreateFmt(SRow+' '+SErrInvalidIndex,[aRow,0,RowCount-1]);
- end;
- { TTagWidget }
- constructor TTagWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- ElementTag:=etdiv;
- end;
- { TMediaWidget }
- function TMediaWidget.GetAudioTrack: TJSHTMLAudioTrackList;
- begin
- if Assigned(Element) then
- Result:=TJSHTMLMediaElement(Element).AudioTracks
- else
- Result:=Nil;
- end;
- function TMediaWidget.getBool(AIndex: Integer): Boolean;
- Var
- El : TJSObject;
- Att : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- Result:=Assigned(el) and isDefined(El[Att]) and (Boolean(El[Att]));
- end;
- function TMediaWidget.GetError: TJSMEdiaError;
- begin
- If Assigned(Element) then
- Result:=TJSHTMLMediaElement(Element).Error
- else
- Result:=Nil;
- end;
- function TMediaWidget.getFloat(AIndex: Integer): Double;
- Var
- El : TJSObject;
- Att : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- if Assigned(el) and isDefined(El[Att]) then
- Result:=Double(El[Att])
- else
- Result:=0;
- end;
- function TMediaWidget.GetSrcObj: TJSHTMLMediaStream;
- begin
- If Assigned(Element) then
- Result:=TJSHTMLMediaElement(Element).srcObject
- else
- Result:=Nil;
- end;
- function TMediaWidget.getString(AIndex: Integer): String;
- Var
- El : TJSObject;
- Att : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- if Assigned(el) and isDefined(El[Att]) then
- Result:=String(El[Att])
- else
- Result:='';
- end;
- function TMediaWidget.GetTextTrack: TJSHTMLTextTrackList;
- begin
- If Assigned(Element) then
- Result:=TJSHTMLMediaElement(Element).TextTracks
- else
- Result:=Nil;
- end;
- function TMediaWidget.GetVideoTrack: TJSHTMLVideoTrackList;
- begin
- If Assigned(Element) then
- Result:=TJSHTMLMediaElement(Element).VideoTracks
- else
- Result:=Nil;
- end;
- procedure TMediaWidget.SetBool(AIndex: Integer; AValue: Boolean);
- Var
- El : TJSObject;
- Att : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- if Assigned(el) then
- El[Att]:=aValue
- else
- Attrs[Att]:=IntToStr(Ord(AValue));
- end;
- procedure TMediaWidget.SetFloat(AIndex: Integer; AValue: Double);
- Var
- El : TJSObject;
- Att,S : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- if Assigned(el) then
- El[Att]:=aValue
- else
- begin
- Str(aValue,S);
- Attrs[Att]:=S;
- end;
- end;
- procedure TMediaWidget.SetString(AIndex: Integer; AValue: String);
- Var
- El : TJSObject;
- Att : String;
- begin
- El:=GetEl;
- Att:=PropAttrs[aIndex];
- if Assigned(el) then
- El[Att]:=aValue
- else
- Attrs[Att]:=aValue;
- end;
- function TMediaWidget.getEl: TJSObject;
- begin
- Result:=Element;
- if Not Assigned(Result) then
- Result:=Self.StoredAttrs;
- end;
- { TVideoWidget }
- constructor TVideoWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- elementTag:=etVideo;
- end;
- { TAudioWidget }
- constructor TAudioWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- elementTag:=etAudio;
- end;
- { TSelectWidget.TStringsSelectOptionEnumerator }
- constructor TSelectWidget.TStringsSelectOptionEnumerator.Create(ASelect: TCustomSelectWidget);
- begin
- inherited Create(ASelect);
- FCurrent:=-1;
- end;
- function TSelectWidget.TStringsSelectOptionEnumerator.OptionText: String;
- begin
- Result:=TSelectWidget(Select).Items[FCurrent];
- end;
- function TSelectWidget.TStringsSelectOptionEnumerator.HasValue: boolean;
- begin
- Result:=FCurrent<TSelectWidget(Select).Values.Count;
- end;
- function TSelectWidget.TStringsSelectOptionEnumerator.Value: string;
- begin
- Result:=TSelectWidget(Select).Values[FCurrent];
- end;
- function TSelectWidget.TStringsSelectOptionEnumerator.MoveNext: Boolean;
- begin
- Result:=FCurrent<TSelectWidget(Select).Items.Count-1;
- if Result then
- Inc(FCurrent);
- end;
- { TCustomSelectWidget.TSelectOptionEnumerator }
- constructor TCustomSelectWidget.TSelectOptionEnumerator.Create(ASelect: TCustomSelectWidget);
- begin
- FSelect:=ASelect;
- end;
- function TCustomSelectWidget.TSelectOptionEnumerator.HasValue: boolean;
- begin
- Result:=False;
- end;
- function TCustomSelectWidget.TSelectOptionEnumerator.Value: string;
- begin
- Result:='';
- end;
- constructor TTableRowCountEnumerator.Create(ATable: TCustomTableWidget; aCount: Integer);
- begin
- Inherited Create(aTable);
- FRowCount:=aCount;
- end;
- function TTableRowCountEnumerator.MoveNext: Boolean;
- begin
- Result:=Inherited MoveNext and (CurrentRow<RowCount)
- end;
- { TTableWidgetCellData }
- procedure TTableWidgetCellData.SetRowColKind(aRow, aCol: Integer; aKind: TRowKind);
- begin
- if (aRow<>-1) then
- FRow:=aRow;
- if (aCol<>-1) then
- FCol:=aCol;
- FKind:=aKind;
- end;
- procedure TTableWidgetCellData.Reset;
- begin
- Ftag:='td';
- FClassNames:='';
- FText:='';
- FContent:=Nil;
- FAsHTML:=False;
- FWidget:=Nil;
- end;
- constructor TTableWidgetCellData.Create(aTable: TCustomTableWidget; aTableID: String);
- begin
- FTable:=aTable;
- FTableID:=aTableID;
- SetRowColKind(0,0,rkBody);
- end;
- { TCustomTableWidget }
- procedure TCustomTableWidget.SetColumns(AValue: TCustomTableColumns);
- begin
- if FColumns=AValue then Exit;
- FColumns.Assign(AValue);
- end;
- procedure TCustomTableWidget.SetCaption(AValue: String);
- begin
- if FCaption=AValue then Exit;
- FCaption:=AValue;
- if isRendered then Refresh;
- end;
- function TCustomTableWidget.DoCellClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnCellClick) then
- FOnCellClick(Self,aEvent);
- If Assigned(FOnRowClick) then
- FOnRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for cell',aEvent.targetElement.innerText);
- end;
- function TCustomTableWidget.DoHeaderCellClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnHeaderCellClick) then
- FOnHeaderCellClick(Self,aEvent);
- If Assigned(FOnHeaderRowClick) then
- FOnHeaderRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for header cell',aEvent.targetElement.innerText);
- end;
- function TCustomTableWidget.DoFooterCellClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnFooterCellClick) then
- FOnFooterCellClick(Self,aEvent);
- If Assigned(FOnFooterRowClick) then
- FOnFooterRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for Footer cell',aEvent.targetElement.innerText);
- end;
- function TCustomTableWidget.DoRowClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnRowClick) then
- FOnRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for Row',aEvent.targetElement.innerText);
- end;
- function TCustomTableWidget.DoHeaderRowClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnHeaderRowClick) then
- FOnHeaderRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for Header Row',aEvent.targetElement.innerText);
- end;
- function TCustomTableWidget.DoFooterRowClick(aEvent: TJSMouseEvent): boolean;
- begin
- If Assigned(FOnFooterRowClick) then
- FOnFooterRowClick(Self,aEvent);
- Result:=False;
- // Writeln('On click for Footer Row',aEvent.targetElement.innerText);
- end;
- procedure TCustomTableWidget.SetTableOptions(AValue: TTableOptions);
- begin
- if FTableOptions=AValue then Exit;
- FTableOptions:=AValue;
- if IsRendered then
- Refresh;
- end;
- procedure TCustomTableWidget.AppendCaption(aCaptionElement: TJSHTMLElement);
- begin
- aCaptionElement.InnerHTML:=Caption;
- end;
- function TCustomTableWidget.GetRowEnumerator(aKind: TRowKind): TTableRowEnumerator;
- begin
- Case aKind of
- rkHeader : Result:=TTableRowCountEnumerator.Create(Self,1);
- rkFooter : Result:=TTableRowCountEnumerator.Create(Self,1);
- rkBody : Result:=GetBodyRowEnumerator;
- end;
- end;
- procedure TTableRowEnumerator.GetCellData(aCell: TTableWidgetCellData);
- Var
- K : TRowKind;
- begin
- K:=aCell.Kind;
- Case K of
- rkHeader:
- begin
- aCell.Tag:='th';
- aCell.Text:=ACell.Column.Caption;
- end;
- rkFooter,
- rkBody :
- begin
- aCell.Tag:='td';
- end;
- end;
- end;
- function TCustomTableWidget.HTMLTag: String;
- begin
- Result:='table';
- end;
- function TCustomTableWidget.RenderCell(aCell: TTableWidgetCellData): TJSHTMLElement;
- Const
- Aligns : Array[TAlignment] of string = ('left','right','center');
- RowChecks : Array[TRowKind] of TTableOption = (toHeaderCellDataRow,toBodyCellDataRow,toFooterCellDataRow);
- ColChecks : Array[TRowKind] of TTableOption = (toHeaderCellDataCol,toBodyCellDataCol,toFooterCellDataCol);
- Var
- C : TJSHtmlElement;
- cl : THTMLNotifyEvent;
- K : TRowKind;
- M : THTMLClickEventHandler;
- elID : string;
- begin
- K:=aCell.Kind;
- if (toCellID in TableOptions) or Assigned(aCell.Widget) then
- elID:=aCell.TableID+'-'+RowKindNames[K]+'-'+IntToStr(ACell.Row)+'-'+IntToStr(aCell.Col)
- else
- elID:='';
- C:=CreateElement(aCell.Tag,elID);
- if aCell.Widget<>Nil then
- aCell.Widget.ParentID:=elID;
- if aCell.Content<>Nil then
- C.AppendChild(aCell.Content)
- else if aCell.AsHTML then
- C.innerHTML:=aCell.text
- else
- C.innerText:=aCell.text;
- C.className:=AddClasses(aCell.Column.ClassNames,aCell.ClassNames);
- if ACell.Column.Alignment<>taLeftJustify then
- C.Style.setProperty('text-align',Aligns[ACell.Column.Alignment]);
- Case K of
- rkBody :
- begin
- CL:=FOnCellClick;
- M:=@DoCellClick;
- end;
- rkHeader :
- begin
- CL:=FOnHeaderCellClick;
- M:=@DoHeaderCellClick;
- end;
- rkFooter :
- begin
- CL:=FOnFooterCellClick;
- M:=@DoFooterCellClick;
- end;
- else
- CL:=Nil;
- M:=nil;
- end;
- if Assigned(cl) or (RowChecks[K] in TableOptions) then
- begin
- C.dataset['row']:=ACell.Row;
- C.Dataset['kind']:=RowKindNames[K];
- end;
- if Assigned(cl) or (ColChecks[K] in TableOptions) then
- begin
- C.dataset['col']:=ACell.Col;
- C.Dataset['kind']:=RowKindNames[K];
- end;
- if Assigned(M) then
- C.OnClick:=M;
- if aCell.Widget<>Nil then
- TJSArray(FWidgets).Push(aCell.Widget);
- Result:=C;
- end;
- procedure TCustomTableWidget.RenderRow(aEnum: TTableRowEnumerator; aParent: TJSHTMLElement; aKind: TRowKind; aCell: TTableWidgetCellData);
- Var
- I: integer;
- begin
- For I:=0 to CustomColumns.Count-1 do
- if CustomColumns[i].RenderColumn then
- begin
- aCell.Reset;
- aCell.FColumn:=CustomColumns[i];
- aCell.SetRowColKind(-1,I,aKind);
- // Writeln(CellKinds[aKind],' cell before : ',aCell.Tag,' data : ',aCell.Text);
- aEnum.GetCellData(aCell);
- // Writeln(CellKinds[aKind],' cell after : ',aCell.Tag,' data : ',aCell.Text);
- if aCell.Tag='' then
- ACell.Tag:=CellTags[aKind];
- if Assigned(FOnGetCellData) then
- FOnGetCellData(Self,aEnum,aCell);
- aParent.appendChild(RenderCell(aCell));
- end;
- end;
- procedure TCustomTableWidget.RenderRows(aParent: TJSHTMLElement; aKind: TRowKind; aCell: TTableWidgetCellData);
- Const
- TableRowChecks : Array[TRowKind] of TTableOption = (toHeaderRowData,toBodyRowData,toFooterRowData);
- Var
- RowEl : TJSHTMLElement;
- Enum : TTableRowEnumerator;
- M : THTMLClickEventHandler;
- cl : THTMLNotifyEvent;
- elid : String;
- begin
- Enum:=GetRowEnumerator(aKind);
- if Enum=Nil then
- Exit;
- try
- While Enum.MoveNext do
- begin
- if toRowID in TableOptions then
- elID:=aCell.TableID+'-'+RowKindNames[aKind]+'-'+IntToStr(Enum.CurrentRow)
- else
- elID:='';
- RowEl:=CreateElement('tr',elID);
- aCell.SetRowColKind(Enum.CurrentRow,-1,aKind);
- Case aKind of
- rkBody :
- begin
- CL:=FOnRowClick;
- M:=@DoRowClick;
- end;
- rkHeader :
- begin
- CL:=FOnHeaderRowClick;
- M:=@DoHeaderRowClick;
- end;
- rkFooter :
- begin
- CL:=FOnFooterRowClick;
- M:=@DoFooterRowClick;
- end;
- end;
- if Assigned(CL) or (TableRowChecks[Akind] in TableOptions) then
- begin
- RowEl.dataset['row']:=Enum.CurrentRow;
- RowEl.dataset['kind']:=RowKindNames[aKind];
- end;
- if Assigned(M) then
- RowEl.OnClick:=M;
- RenderRow(Enum,RowEl,aKind,aCell);
- aParent.AppendChild(RowEl);
- end;
- finally
- Enum.Free;
- end;
- end;
- procedure TCustomTableWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- inherited ApplyWidgetSettings(aElement);
- RenderData(aElement);
- end;
- procedure TCustomTableWidget.RenderData(aElement: TJSHTMLElement);
- Var
- El : TJSHTMLElement;
- aCell : TTableWidgetCellData;
- W : TWebWidget;
- begin
- FWidgets:=[];
- if (Caption<>'') then
- begin
- El:=CreateElement('caption',aElement.ID+'-caption');
- AppendCaption(EL);
- aElement.AppendChild(EL);
- end;
- aCell:=CreateCellData(aElement.ID);
- If (CustomColumns.Count=0) then
- CreateDefaultColumns;
- if toHeaderRow in TableOptions then
- begin
- if toHeader in TableOptions then
- begin
- El:=CreateElement('thead',aElement.ID+'-head');
- aElement.AppendChild(el);
- end
- else
- El:=aElement;
- aCell.SetRowColKind(-1,-1,rkHeader);
- RenderRows(El,rkHeader,aCell);
- end;
- if toBody in TableOptions then
- begin
- El:=CreateElement('tbody',aElement.ID+'-body');
- aElement.AppendChild(el);
- end
- else
- El:=aElement;
- aCell.SetRowColKind(-1,-1,rkBody);
- RenderRows(El,rkBody,aCell);
- if toFooterRow in TableOptions then
- begin
- if toFooter in TableOptions then
- begin
- El:=CreateElement('tFoot',aElement.ID+'-foot');
- aElement.AppendChild(el);
- end
- else
- El:=aElement;
- aCell.SetRowColKind(-1,-1,rkFooter);
- RenderRows(El,rkFooter,aCell);
- end;
- for W in FWidgets do
- W.Refresh;
- FWidgets:=[];
- end;
- function TCustomTableWidget.CreateCellData(const aTableID : String): TTableWidgetCellData;
- begin
- Result:=TTableWidgetCellData.Create(Self,aTableID);
- end;
- function TCustomTableWidget.CreateColumns: TCustomTableColumns;
- begin
- Result:=TCustomTableColumns.Create(TCustomTableColumn);
- end;
- function TCustomTableWidget.DefaultTableOptions: TTableOptions;
- begin
- Result:=[toHeader,toBody,toFooter,toHeaderRow]
- end;
- procedure TCustomTableWidget.CreateDefaultColumns;
- begin
- // Do nothing
- end;
- constructor TCustomTableWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- FTableOptions:=DefaultTableOptions;
- FColumns:=CreateColumns;
- end;
- destructor TCustomTableWidget.Destroy;
- begin
- FreeAndNil(FColumns);
- inherited Destroy;
- end;
- procedure TCustomTableWidget.BeginUpdate;
- begin
- Inc(FUpDateCount);
- end;
- procedure TCustomTableWidget.EndUpdate;
- begin
- if (FUpdateCount>0) then
- Dec(FUpDateCount);
- if (FUpdateCount=0) and IsRendered then
- Refresh;
- end;
- procedure TCustomTableWidget.RefreshBody;
- begin
- if Not Assigned(Element) then
- Refresh
- else
- begin
- Element.Innerhtml:='';
- RenderData(Element);
- end;
- end;
- { TCustomTableColumn }
- procedure TCustomTableColumn.SetAlignment(AValue: TAlignment);
- begin
- if FAlignment=AValue then Exit;
- FAlignment:=AValue;
- end;
- function TCustomTableColumn.GetCaption: String;
- begin
- Result:=FCaption;
- end;
- procedure TCustomTableColumn.SetCaption(AValue: String);
- begin
- if FCaption=AValue then Exit;
- FCaption:=AValue;
- end;
- procedure TCustomTableColumn.SetClassNames(AValue: String);
- begin
- if FClassNames=AValue then Exit;
- FClassNames:=AValue;
- end;
- function TCustomTableColumn.RenderColumn: Boolean;
- begin
- Result:=True;
- end;
- function TCustomTableColumn.GetDisplayName: string;
- begin
- Result:=Caption;
- end;
- procedure TCustomTableColumn.Assign(Source: TPersistent);
- Var
- C : TCustomTableColumn;
- begin
- if Source is TCustomTableColumn then
- begin
- C:=Source as TCustomTableColumn;
- FCaption:=C.FCaption;
- FClassNames:=C.FClassNames;
- FAlignment:=C.Alignment;
- end
- else
- inherited Assign(Source);
- end;
- { TCustomTableColumns }
- function TCustomTableColumns.GetCustomColumn(Index : Integer): TCustomTableColumn;
- begin
- Result:=TCustomTableColumn(Items[Index]);
- end;
- procedure TCustomTableColumns.SetCustomColumn(Index : Integer; AValue: TCustomTableColumn);
- begin
- Items[Index]:=aValue;
- end;
- function TCustomTableColumns.Add(aCaption: String): TCustomTableColumn;
- begin
- Result:=add as TCustomTableColumn;
- Result.Caption:=aCaption;
- end;
- { TTableRowEnumerator }
- constructor TTableRowEnumerator.Create(ATable: TCustomTableWidget);
- begin
- FTable:=aTable;
- FCurrent:=-1;
- end;
- function TTableRowEnumerator.MoveNext: Boolean;
- begin
- Inc(FCurrent);
- Result:=True;
- end;
- { TCustomTextWidget }
- procedure TCustomTextWidget.SetEnvelopeTag(AValue: TTextTag);
- begin
- // Writeln('Setting text tag : ',aValue);
- if FEnvelopeTag=AValue then Exit;
- FEnvelopeTag:=AValue;
- if (FEnvelopeTag=ttCustom) and (FCustomTag='') then
- FCustomTag:='div';
- if IsRendered then
- Refresh;
- end;
- procedure TCustomTextWidget.SetCustomTag(AValue: String);
- begin
- if FCustomTag=AValue then Exit;
- FCustomTag:=AValue;
- if (FCustomTag<>'') then
- FEnvelopeTag:=ttCustom;
- if IsRendered then
- Refresh;
- end;
- procedure TCustomTextWidget.SetTextMode(AValue: TTextMode);
- begin
- if FTextMode=AValue then Exit;
- FTextMode:=AValue;
- if IsRendered then
- ApplyText(Element);
- end;
- procedure TCustomTextWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- // Writeln('ApplyWidgetSettings: ',aElement.tagName);
- inherited ApplyWidgetSettings(aElement);
- ApplyText(aElement);
- end;
- procedure TCustomTextWidget.ApplyText(aElement: TJSHTMLElement);
- begin
- if FTextMode=tmText then
- aElement.innerText:=GetText
- else
- aElement.innerHTML:=GetText;
- end;
- function TCustomTextWidget.HTMLTag: String;
- begin
- Result:=TextTagNames[FEnvelopeTag];
- if Result='' then
- Result:='div';
- // Writeln('Getting element tag: ',Result);
- end;
- { TTextLinesWidget }
- procedure TTextLinesWidget.SetLines(AValue: TStrings);
- begin
- if FLines=AValue then Exit;
- FLines.Assign(AValue);
- end;
- procedure TTextLinesWidget.SetForceLineBreaks(AValue: Boolean);
- begin
- if FForceLineBreaks=AValue then Exit;
- FForceLineBreaks:=AValue;
- if IsRendered then
- ApplyText(Element);
- end;
- procedure TTextLinesWidget.DoLinesChanged(Sender: TObject);
- begin
- if IsRendered then
- ApplyText(Element);
- end;
- function TTextLinesWidget.GetText: String;
- Var
- I : integer;
- begin
- if (FTextMode=tmHTML) and ForceLineBreaks then
- begin
- Result:='';
- For I:=0 to FLines.Count-1 do
- Result:=Result+flines[i]+'<br/>';
- end
- else
- Result:=FLines.Text;
- end;
- procedure TTextLinesWidget.ApplyText(aElement: TJSHTMLElement);
- Var
- I : integer;
- begin
- if (TextMode=tmHTML) or (Not ForceLineBreaks) then
- inherited ApplyText(aElement)
- else
- begin
- For I:=0 to FLines.Count-1 do
- begin
- aElement.AppendChild(Document.createTextNode(FLines[i]));
- aElement.AppendChild(CreateElement('br',''));
- end;
- end;
- end;
- constructor TTextLinesWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- FLines:=TstringList.Create;
- TstringList(FLines).OnChange:=@DoLinesChanged;
- end;
- destructor TTextLinesWidget.Destroy;
- begin
- FLines:=TstringList.Create;
- inherited Destroy;
- end;
- { TTextWidget }
- procedure TTextWidget.SetText(AValue: String);
- begin
- if FText=AValue then Exit;
- FText:=AValue;
- if IsRendered then
- ApplyText(Element);
- end;
- function TTextWidget.GetText: String;
- begin
- Result:=FText;
- end;
- { TLabelWidget }
- procedure TLabelWidget.ApplyLabelFor(aLabelElement : TJSHTMLLabelElement);
- begin
- if Assigned(FlabelFor) then
- begin
- FlabelFor.EnsureElement;
- aLabelElement.for_:=FlabelFor.ElementID;
- end
- else
- aLabelElement.for_:='';
- end;
- procedure TLabelWidget.SetLabelFor(AValue: TWebWidget);
- begin
- if (FLabelFor=AValue) then Exit;
- if Assigned(FLabelFor) then
- FLabelFor.RemoveFreeNotification(Self);
- FLabelFor:=AValue;
- if Assigned(FLabelFor) then
- FLabelFor.FreeNotification(Self);
- If IsRendered then
- ApplyLabelFor(LabelElement);
- end;
- function TLabelWidget.GetText: String;
- begin
- if IsElementDirty then
- FText:=Element.InnerText;
- Result:=FText;
- end;
- function TLabelWidget.GetLabelEl: TJSHTMLLabelElement;
- begin
- Result:=TJSHTMLLabelElement(Element);
- end;
- procedure TLabelWidget.SetText(AValue: String);
- begin
- If Text=aValue then exit;
- Ftext:=aValue;
- If IsRendered then
- Element.innerText:=aValue;
- end;
- procedure TLabelWidget.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- inherited Notification(AComponent, Operation);
- if (Operation=opRemove) and (aComponent=FLabelFor) then
- FLabelFor:=Nil;
- end;
- procedure TLabelWidget.SetName(const NewName: TComponentName);
- Var
- Old : String;
- begin
- Old:=Name;
- inherited SetName(NewName);
- if (csDesigning in ComponentState) then
- if Old=Text then
- Text:=Old;
- end;
- procedure TLabelWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- var
- lbl : TJSHTMLLabelElement absolute aElement;
- begin
- inherited ApplyWidgetSettings(aElement);
- lbl.InnerText:=Text;
- ApplyLabelFor(Lbl);
- end;
- function TLabelWidget.HTMLTag: String;
- begin
- Result:='label';
- end;
- { TSelectWidget }
- function TCustomSelectWidget.GetSelectedIndex: Integer;
- begin
- if IsRendered then
- FSelectedIndex:=SelectElement.selectedIndex;
- Result:=FSelectedIndex
- end;
- function TCustomSelectWidget.GetMultiple: Boolean;
- begin
- if IsElementDirty then
- FMultiple:=SelectElement.multiple;
- Result:=FMultiple;
- end;
- function TCustomSelectWidget.GetItemCount: Integer;
- begin
- Result:=Length(Options);
- end;
- function TCustomSelectWidget.GetSelected(Index : Integer): Boolean;
- begin
- if (Index<0) or (Index>=Length(Foptions)) then
- Raise EWidgets.CreateFmt(SErrInvalidIndex,[Index,Length(Foptions)-1]);
- Result:=FOptions[Index].Selected
- end;
- function TCustomSelectWidget.GetSelect: TJSHTMLSelectElement;
- begin
- Result:=TJSHTMLSelectElement(Element);
- end;
- function TCustomSelectWidget.GetSelectionCount: Integer;
- begin
- Result:=SelectElement.selectedOptions.length;
- end;
- function TCustomSelectWidget.GetSelectionItem(aIndex : Integer): String;
- begin
- if (aIndex<0) or (aindex>=GetSelectionCount) then
- Raise EWidgets.CreateFmt(SErrInvalidIndex,[aIndex,GetSelectionCount-1]);
- Result:=TJSHTMLOptionElement(SelectElement.selectedOptions.item(aIndex)).innerText;
- end;
- function TCustomSelectWidget.GetSelectionValue(aIndex : Integer): String;
- begin
- if (aIndex<0) or (aindex>=GetSelectionCount) then
- Raise EWidgets.CreateFmt(SErrInvalidIndex,[aIndex,GetSelectionCount-1]);
- Result:=TJSHTMLOptionElement(SelectElement.selectedOptions.item(aIndex)).value;
- end;
- function TCustomSelectWidget.GetSize: Integer;
- begin
- if IsElementDirty then
- FSize:=SelectElement.Size;
- Result:=FSize;
- end;
- procedure TCustomSelectWidget.SetMultiple(AValue: Boolean);
- begin
- If (AValue=Multiple) then exit;
- FMultiple:=aValue;
- If IsRendered then
- SelectElement.multiple:=FMultiple;
- end;
- procedure TCustomSelectWidget.SetSelected(Index : Integer; AValue: Boolean);
- begin
- if (Index<0) or (Index>=Length(Foptions)) then
- Raise EWidgets.CreateFmt(SErrInvalidIndex,[Index,Length(Foptions)-1]);
- FOptions[Index].Selected:=aValue;
- end;
- procedure TCustomSelectWidget.SetSelectedIndex(AValue: Integer);
- begin
- if (SelectedIndex=aValue) then
- Exit;
- FSelectedIndex:=aValue;
- if IsRendered then
- SelectElement.SelectedIndex:=FSelectedIndex;
- if Assigned(OnChange) then
- OnChange(Self,Nil);
- end;
- procedure TCustomSelectWidget.SetSize(AValue: Integer);
- begin
- If (AValue=Size) then exit;
- FSize:=aValue;
- If IsRendered then
- SelectElement.Size:=FSize;
- end;
- procedure TCustomSelectWidget.BuildOptions(aSelect: TJSHTMLSelectElement);
- Var
- O : TJSHTMLOptionElement;
- Idx : Integer;
- enum : TSelectOptionEnumerator;
- begin
- // Clear
- SetLength(FOptions,0);
- aSelect.InnerHTML:='';
- // Rebuild
- Idx:=0;
- enum:=CreateOptionEnumerator;
- While enum.MoveNext do
- begin
- O:=TJSHTMLOptionElement(CreateElement('option',''));
- O.innerText:=enum.OptionText;
- if enum.HasValue then
- O.value:=enum.Value;
- if Idx=FSelectedIndex then
- O.selected:=True;
- aSelect.AppendChild(O);
- Inc(Idx);
- end;
- SetLength(Foptions,Idx);
- Dec(idx);
- While Idx>=0 do
- begin
- FOptions[Idx]:=TJSHTMLOptionElement(aSelect.Children[Idx]);
- dec(Idx);
- end;
- end;
- constructor TCustomSelectWidget.Create(aOWner: TComponent);
- begin
- inherited Create(aOWner);
- FSelectedIndex:=-1;
- end;
- procedure TCustomSelectWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- Var
- el : TJSHTmlSelectElement absolute aElement;
- begin
- inherited ApplyWidgetSettings(aElement);
- el.multiple:=Self.Multiple;
- el.Size:=Self.Size;
- BuildOptions(el);
- // We need to force this.
- if SelectedIndex=-1 then
- el.selectedIndex:=-1;
- end;
- function TCustomSelectWidget.HTMLTag: String;
- begin
- Result:='select';
- end;
- { TSelectWidget }
- function TSelectWidget.GetItems: TStrings;
- begin
- Result:=FItems;
- end;
- function TSelectWidget.GetValues: TStrings;
- begin
- Result:=FValues;
- end;
- procedure TSelectWidget.OptionsChanged(Sender: TObject);
- begin
- if IsRendered then
- BuildOptions(SelectElement);
- end;
- procedure TSelectWidget.setItems(AValue: TStrings);
- begin
- If (AValue=FItems) then exit;
- FItems.Assign(aValue);
- end;
- procedure TSelectWidget.setValues(AValue: TStrings);
- begin
- If (AValue=FValues) then exit;
- FValues.Assign(aValue);
- end;
- function TSelectWidget.CreateOptionEnumerator: TSelectOptionEnumerator;
- begin
- Result:=TStringsSelectOptionEnumerator.Create(Self);
- end;
- constructor TSelectWidget.Create(aOWner: TComponent);
- begin
- inherited Create(aOWner);
- FItems:=TStringList.Create;
- TStringList(FItems).OnChange:=@OptionsChanged;
- FValues:=TStringList.Create;
- TStringList(FValues).OnChange:=@OptionsChanged;
- end;
- destructor TSelectWidget.Destroy;
- begin
- FreeAndNil(FItems);
- FreeAndNil(FValues);
- inherited Destroy;
- end;
- { TImageWidget }
- function TImageWidget.GetHeight: Integer;
- begin
- if IsElementDirty then
- FHeight:=ImgElement.Height;
- Result:=Fheight;
- end;
- function TImageWidget.GetImg: TJSHTMLImageElement;
- begin
- Result:=TJSHTMLImageElement(Element);
- end;
- function TImageWidget.GetSrc: String;
- begin
- if IsElementDirty then
- FSrc:=ImgElement.Src;
- Result:=FSrc;
- end;
- function TImageWidget.GetWidth: Integer;
- begin
- if IsElementDirty then
- FWidth:=ImgElement.Width;
- Result:=FWidth;
- end;
- procedure TImageWidget.SetHeight(AValue: Integer);
- begin
- if AValue=Height then exit;
- FHeight:=AValue;
- If isrendered then
- ImgElement.Height:=aValue;
- end;
- procedure TImageWidget.SetSrc(AValue: String);
- begin
- if AValue=Src then exit;
- FSrc:=AValue;
- If isrendered then
- ImgElement.Src:=FSrc;
- end;
- procedure TImageWidget.SetWidth(AValue: Integer);
- begin
- if AValue=Width then exit;
- FWidth:=AValue;
- If isrendered then
- ImgElement.Width:=aValue;
- end;
- procedure TImageWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- var
- img : TJSHTMLImageElement absolute aElement;
- begin
- inherited ApplyWidgetSettings(aElement);
- Img.Src:=FSrc;
- Img.Height:=FHeight;
- Img.Width:=FWidth;
- end;
- function TImageWidget.HTMLTag: String;
- begin
- Result:='img';
- end;
- { TTextAreaWidget }
- procedure TTextAreaWidget.SetLines(AValue: TStrings);
- begin
- if FLines=AValue then Exit;
- FLines.Assign(AValue);
- end;
- procedure TTextAreaWidget.SetMaxLength(AValue: Cardinal);
- begin
- if FMaxLength=AValue then Exit;
- FMaxLength:=AValue;
- if IsRendered then
- TextArea.maxLength:=aValue;
- end;
- procedure TTextAreaWidget.SetReadonly(AValue: Boolean);
- begin
- If aValue=ReadOnly then exit;
- FReadOnly:=aValue;
- if IsRendered then
- TextArea.Readonly:=FReadOnly;
- end;
- procedure TTextAreaWidget.SetRequired(AValue: Boolean);
- begin
- If aValue=Required then exit;
- FRequired:=aValue;
- if IsRendered then
- TextArea.Required:=FRequired;
- end;
- function TTextAreaWidget.GetColumns: Cardinal;
- begin
- if IsElementDirty then
- FColumns:=TextArea.Cols;
- Result:=FColumns;
- end;
- procedure TTextAreaWidget.DoLineChanges(Sender: TObject);
- begin
- if isRendered and not FIgnoreChanges then
- ApplyLines(TextArea);
- end;
- function TTextAreaWidget.GetLines: TStrings;
- begin
- // We may want to change this to something more efficient. Maybe handle onchange
- // Note that if yo
- if IsElementDirty then
- begin
- FIgnoreChanges:=True;
- try
- LinesFromHTML(Element.InnerHTml);
- finally
- FIgnoreChanges:=False;
- end;
- end;
- Result:=FLines;
- end;
- function TTextAreaWidget.GetReadOnly: Boolean;
- begin
- if IsElementDirty then
- FReadonly:=TextArea.readOnly;
- Result:=FReadonly;
- end;
- function TTextAreaWidget.GetRequired: Boolean;
- begin
- if IsElementDirty then
- FRequired:=TextArea.Required;
- Result:=FRequired;
- end;
- function TTextAreaWidget.GetRows: Cardinal;
- begin
- if IsElementDirty then
- FRows:=TextArea.Rows;
- Result:=FRows;
- end;
- function TTextAreaWidget.GetText: String;
- begin
- if IsElementDirty then
- Result:=Element.InnerHTML
- else
- Result:=FLines.Text;
- end;
- function TTextAreaWidget.GetValueName: string;
- begin
- if IsElementDirty then
- FValueName:=Element.Name;
- Result:=FValueName;
- end;
- procedure TTextAreaWidget.SetColumns(AValue: Cardinal);
- begin
- if AValue=FColumns then exit;
- FColumns:=aValue;
- if isRendered then
- TextArea.cols:=aValue;
- end;
- procedure TTextAreaWidget.SetRows(AValue: Cardinal);
- begin
- if AValue=FRows then exit;
- FRows:=aValue;
- if isRendered then
- TextArea.Rows:=aValue;
- end;
- procedure TTextAreaWidget.SetText(AValue: String);
- begin
- if isRendered then
- element.InnerText:=aValue
- else
- LinesFromHTML(aValue);
- end;
- procedure TTextAreaWidget.SetValueName(AValue: string);
- begin
- if aValue=FValueName then exit;
- FValueName:=aValue;
- if IsRendered then
- TextArea.Name:=aValue;
- end;
- procedure TTextAreaWidget.SetName(const NewName: TComponentName);
- var
- Old : String;
- begin
- Old:=Name;
- inherited SetName(NewName);
- if csDesigning in ComponentState then
- begin
- if (FLines.Count=0) then
- FLines.Add(Name)
- else if (FLines.Count=1) and (FLines[0]=Old) then
- FLines[0]:=Name;
- end;
- end;
- procedure TTextAreaWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- var
- area : TJSHTMLTextAreaElement absolute aElement;
- begin
- inherited ApplyWidgetSettings(aElement);
- if FMaxLength>0 then
- area.maxlength:=FMaxLength;
- if FColumns>0 then
- area.cols:=FColumns;
- if FRows>0 then
- area.Rows:=FRows;
- if FLines.Count>0 then
- ApplyLines(area);
- if FValueName<>'' then
- area.Name:=FValueName;
- area.Readonly:=FReadOnly;
- area.Required:=FRequired;
- ApplyWrap(area);
- end;
- constructor TTextAreaWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- FLines:=TStringList.Create;
- TStringList(FLines).OnChange:=@DoLineChanges;
- FColumns:=50;
- FRows:=10;
- end;
- destructor TTextAreaWidget.Destroy;
- begin
- FreeAndNil(Flines);
- inherited;
- end;
- class function TTextAreaWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- function TTextAreaWidget.GetTextArea: TJSHTMLTextAreaElement;
- begin
- Result:=TJSHTMLTextAreaElement(Element);
- end;
- procedure TTextAreaWidget.ApplyWrap(aElement :TJSHTMLTextAreaElement);
- Const
- Wraps : Array[TTextAreaWrap] of string = ('soft','hard','off');
- begin
- aElement.wrap:=Wraps[FWrap];
- end;
- procedure TTextAreaWidget.ApplyLines(aElement: TJSHTMLTextAreaElement);
- begin
- aElement.innerHTML:=FLines.Text;
- end;
- procedure TTextAreaWidget.LinesFromHTML(aHTML: String);
- begin
- FLines.Text:= StringReplace(aHTML,'<br>',sLineBreak,[rfIgnoreCase,rfReplaceAll]);
- end;
- procedure TTextAreaWidget.SetWrap(AValue: TTextAreaWrap);
- begin
- if FWrap=AValue then Exit;
- FWrap:=AValue;
- if IsRendered then
- ApplyWrap(TextArea)
- end;
- function TTextAreaWidget.HTMLTag: String;
- begin
- result:='textarea';
- end;
- { TCheckboxInputWidget }
- function TCheckboxInputWidget.InputType: String;
- begin
- Result:='checkbox';
- end;
- { TRadioInputWidget }
- function TRadioInputWidget.InputType: String;
- begin
- Result:='radio';
- end;
- { THiddenInputWidget }
- class function THiddenInputWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- function THiddenInputWidget.InputType: String;
- begin
- Result:='hidden';
- end;
- { TFileInputWidget }
- procedure TFileInputWidget.SetMultiple(AValue: Boolean);
- begin
- if FMultiple=AValue then Exit;
- FMultiple:=AValue;
- if Isrendered then
- InputElement.multiple:=FMultiple;
- end;
- function TFileInputWidget.GetMultiple: Boolean;
- begin
- if IsElementDirty then
- FMultiple:=InputElement.multiple;
- Result:=FMultiple;
- end;
- function TFileInputWidget.GetFileName(aIndex : Integer): String;
- begin
- Result:=InputElement.files.Files[aIndex].name;
- end;
- function TFileInputWidget.GetFileSize(aIndex : Integer): NativeInt;
- begin
- Result:=InputElement.files.Files[aIndex].Size;
- end;
- function TFileInputWidget.GetFileType(aIndex : Integer): String;
- begin
- Result:=InputElement.files.Files[aIndex]._Type;
- end;
- function TFileInputWidget.GetFileCount: Integer;
- begin
- Result:=InputElement.files.Length;
- end;
- function TFileInputWidget.GetFileDate(aIndex : Integer): TDateTime;
- begin
- Result:=JSDateToDateTime(InputElement.files.Files[aIndex].lastModifiedDate);
- end;
- function TFileInputWidget.GetFileInfo(aIndex : Integer): TFileInfo;
- Var
- f : TJSHTMLFile;
- begin
- F:=InputElement.files.Files[aIndex];
- Result.Name:=F.name;
- Result.Size:=F.size;
- Result.FileType:=F._type;
- Result.TimeStamp:= JSDateToDateTime(F.lastModifiedDate);
- end;
- procedure TFileInputWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- Var
- Old : String;
- begin
- Old:=FValue;
- FValue:='';
- try
- inherited ApplyWidgetSettings(aElement);
- TJSHTMLInputElement(aElement).multiple:=FMultiple;
- finally
- FValue:=Old;
- end;
- end;
- class function TFileInputWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- function TFileInputWidget.InputType: String;
- begin
- Result:='file';
- end;
- { TDateInputWidget }
- function TDateInputWidget.GetDate: TDateTime;
- var
- aDate : TDateTime;
- begin
- if IsElementDirty then
- begin
- aDate:=ScanDateTime('yyyy-mm-dd',Value);
- if aDate<>0 then
- FDate:=aDate;
- end;
- Result:=FDate;
- end;
- procedure TDateInputWidget.SetDate(AValue: TDateTime);
- begin
- FDate:=aValue;
- Value:=FormatDateTime('yyyy-mm-dd',FDate);
- end;
- function TDateInputWidget.InputType: String;
- begin
- Result:='date';
- end;
- class function TDateInputWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- { TCheckableInputWidget }
- procedure TCheckableInputWidget.SetChecked(AValue: Boolean);
- begin
- // Get actual value
- if Checked=AValue then Exit;
- if isRendered then
- InputElement.checked:=aValue;
- FChecked:=AValue;
- end;
- procedure TCheckableInputWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- inherited ApplyWidgetSettings(aElement);
- TJSHTMLInputElement(aElement).Checked:=FChecked;
- end;
- function TCheckableInputWidget.GetChecked: Boolean;
- begin
- if IsElementDirty then
- FChecked:=InputElement.Checked;
- Result:=FChecked;
- end;
- { TButtonInputWidget }
- procedure TButtonInputWidget.SetButtonType(AValue: TInputButtonType);
- begin
- if FButtonType=AValue then Exit;
- FButtonType:=AValue;
- if IsRendered then
- Refresh;
- end;
- procedure TButtonInputWidget.SetSrc(AValue: String);
- begin
- if FSrc=AValue then Exit;
- FSrc:=AValue;
- if IsRendered and (ButtonType=ibtImage) then
- Element.setAttribute('src',FSrc);
- end;
- procedure TButtonInputWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- inherited ApplyWidgetSettings(aElement);
- if ButtonType=ibtImage then
- aElement.setAttribute('src',FSrc);
- end;
- function TButtonInputWidget.InputType: String;
- Const
- Types : Array[TInputButtonType] of string = ('submit','reset','image');
- begin
- Result:=Types[FButtonType]
- end;
- class function TButtonInputWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- { TTextInputWidget }
- function TTextInputWidget.GetAsNumber: NativeInt;
- begin
- Result:=StrToIntDef(Value,0);
- end;
- function TTextInputWidget.GetMaxLength: NativeInt;
- begin
- if IsElementDirty then
- FMaxLength:=InputElement.maxLength;
- Result:=FMaxLength;
- end;
- function TTextInputWidget.GetMinLength: NativeInt;
- begin
- if IsElementDirty then
- FMinLength:=InputElement.minLength;
- Result:=FMinLength;
- end;
- function TTextInputWidget.GetTextType: TInputTextType;
- begin
- Result:=FTextType;
- end;
- procedure TTextInputWidget.SetAsNumber(AValue: NativeInt);
- begin
- Value:=IntToStr(aValue);
- end;
- procedure TTextInputWidget.SetMaxLength(AValue: NativeInt);
- begin
- if (aValue=FMaxLength) then exit;
- FMaxLength:=aValue;
- if IsRendered then
- InputElement.maxLength:=FMaxLength;
- end;
- procedure TTextInputWidget.SetMinLength(AValue: NativeInt);
- begin
- if (aValue=FMinLength) then exit;
- FMinLength:=aValue;
- if IsRendered then
- InputElement.minLength:=FMinLength;
- end;
- procedure TTextInputWidget.SetTextType(AValue: TInputTextType);
- begin
- if aValue=FTextType then exit;
- FTextType:=aValue;
- if IsRendered then
- Refresh;
- end;
- procedure TTextInputWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- var
- inp : TJSHTMLInputElement absolute aElement;
- begin
- inherited ApplyWidgetSettings(aElement);
- if FMaxLength<>0 then
- inp.maxLength:=FMaxLength;
- if FMinLength<>0 then
- inp.minLength:=FMinLength;
- end;
- class function TTextInputWidget.AllowChildren: Boolean;
- begin
- Result:=False;
- end;
- function TTextInputWidget.InputType: String;
- Const
- Types : Array[TInputTextType] of string =
- ('text','password','number','email','search','tel','url','color');
- begin
- Result:=Types[FTextType];
- end;
- { TWebPage }
- constructor TWebPage.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- Classes:='WebPage';
- end;
- class function TWebPage.DefaultParentElement: TJSHTMLElement;
- begin
- Result:=TViewport.Instance.Element;
- end;
- class function TWebPage.DefaultParent: TCustomWebWidget;
- begin
- Result:=TViewport.Instance;
- end;
- procedure TWebPage.DoUnRender(aParent: TJSHTMLElement);
- begin
- inherited DoUnRender(aParent);
- end;
- function TWebPage.HTMLTag: String;
- begin
- Result:='div';
- end;
- { TViewPort }
- function TViewPort.HTMLTag: String;
- begin
- Result:='body';
- end;
- class function TViewPort.FixedParent: TJSHTMLElement;
- begin
- Result:=TJSHTMLElement(Document.documentElement);
- end;
- class function TViewPort.FixedElement: TJSHTMLElement;
- begin
- Result:=TJSHTMLElement(Document.Body);
- end;
- function TViewPort.DoRenderHTML(aParent, aElement: TJSHTMLElement): TJSHTMLElement;
- begin
- Result:=FixedElement;
- end;
- constructor TViewPort.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- EnsureElement;
- end;
- class function TViewPort.Instance: TViewPort;
- begin
- if Finstance=Nil then
- FInstance:=TViewPort.Create(Nil);
- Result:=FInstance;
- end;
- { TButtonWidget }
- { TButtonWidget }
- procedure TButtonWidget.SetText(AValue: String);
- begin
- if FText=AValue then Exit;
- FText:=AValue;
- if IsRendered then
- ApplyText(Element);
- end;
- procedure TButtonWidget.SetTextMode(AValue: TTextMode);
- begin
- if FTextMode=AValue then Exit;
- FTextMode:=AValue;
- if IsRendered then
- ApplyText(Element)
- end;
- procedure TButtonWidget.SetName(const NewName: TComponentName);
- Var
- Old : String;
- begin
- Old:=Name;
- inherited SetName(NewName);
- if (FText=Old) and (csDesigning in ComponentState) then
- FText:=NewName;
- end;
- function TButtonWidget.HTMLTag: String;
- begin
- Result:='button';
- end;
- procedure TButtonWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- Inherited;
- ApplyText(aElement);
- end;
- Procedure TButtonWidget.ApplyText(aElement : TJSHTMLElement);
- begin
- if FTextMode=tmText then
- aElement.InnerText:=FText
- else
- aElement.InnerHTML:=FText;
- end;
- procedure TButtonWidget.Click;
- begin
- DispatchEvent('click');
- end;
- { TCustomInputWidget }
- function TCustomInputWidget.GetValue: String;
- Var
- Inp : TJSHTMLInputElement;
- begin
- Inp:=InputElement;
- If Assigned(Inp) then
- Result:=Inp.value
- else
- Result:=FValue
- end;
- function TCustomInputWidget.GetText: String;
- Var
- Inp : TJSHTMLElement;
- begin
- Inp:=Element;
- If Assigned(Inp) then
- Result:=Inp.InnerText
- else
- Result:=FText;
- // Writeln('Getting text: ',Result,' inner : ',FText);
- end;
- function TCustomInputWidget.GetReadOnly: Boolean;
- begin
- if IsElementDirty then
- FReadonly:=InputElement.readOnly;
- Result:=FReadonly;
- end;
- function TCustomInputWidget.GetRequired: Boolean;
- begin
- if IsElementDirty then
- FRequired:=InputElement.Required;
- Result:=FRequired;
- end;
- function TCustomInputWidget.GetValueName: String;
- Var
- Inp : TJSHTMLInputElement;
- begin
- Inp:=InputElement;
- If Assigned(Inp) then
- Result:=Inp.Name
- else
- begin
- Result:=FValueName;
- if Result='' then
- Result:=Name;
- end;
- end;
- procedure TCustomInputWidget.SetReadonly(AValue: Boolean);
- begin
- If aValue=ReadOnly then exit;
- FReadOnly:=aValue;
- if IsRendered then
- InputElement.Readonly:=FReadOnly;
- end;
- procedure TCustomInputWidget.SetRequired(AValue: Boolean);
- begin
- If aValue=Required then exit;
- FRequired:=aValue;
- if IsRendered then
- InputElement.Required:=FRequired;
- end;
- procedure TCustomInputWidget.SetText(AValue: String);
- Var
- Inp : TJSHTMLElement;
- begin
- Writeln('Setting text: ',AValue,' previous : ',Text);
- if aValue=Text then exit;
- FText:=aValue;
- Inp:=Element;
- If Assigned(Inp) then
- Inp.innerText:=aValue;
- end;
- procedure TCustomInputWidget.SetValue(AValue: String);
- Var
- Inp : TJSHTMLInputElement;
- begin
- if aValue=Value then exit;
- FValue:=aValue;
- Inp:=InputElement;
- If Assigned(Inp) then
- Inp.value:=aValue;
- end;
- procedure TCustomInputWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- var
- Inp : TJSHTMLInputElement absolute aElement;
- begin
- Inherited;
- if (ExternalElement) and (FValue='') then
- FValue:=TJSHTMLInputElement(aElement).value
- else
- begin
- Inp._type:=InputType;
- Inp.name:=FValueName;
- Inp.value:=FValue;
- Inp.Required:=FRequired;
- Inp.ReadOnly:=FReadOnly;
- Writeln('Setting inner text to "',FText,'"');
- Inp.innerHtml:=FText;
- Writeln('Setting inner text is now "',Inp.innerText,'"');
- end;
- end;
- function TCustomInputWidget.HTMLTag: String;
- begin
- Result:='input';
- end;
- function TCustomInputWidget.GetInputElement: TJSHTMLInputElement;
- begin
- Result:=TJSHTMLInputElement(Element);
- end;
- procedure TCustomInputWidget.SetValueName(AValue: String);
- Var
- Inp : TJSHTMLInputElement;
- begin
- if aValue=ValueName then exit;
- FValueName:=aValue;
- Inp:=InputElement;
- If Assigned(Inp) then
- Inp.name:=aValue;
- end;
- procedure TCustomInputWidget.SetName(const NewName: TComponentName);
- Var
- Old : String;
- begin
- Old:=Name;
- inherited SetName(NewName);
- if (Value=Old) then
- Value:=NewName;
- end;
- { TCustomTagWidget }
- procedure TCustomTagWidget.SetElementTag(AValue: THTMLElementTag);
- begin
- if FElementTag=AValue then Exit;
- FElementTag:=AValue;
- if IsRendered then
- Refresh;
- end;
- procedure TCustomTagWidget.SetTextContent(AValue: String);
- begin
- if FTextContent=AValue then Exit;
- FTextContent:=AValue;
- if IsRendered then
- Refresh;
- end;
- procedure TCustomTagWidget.ApplyWidgetSettings(aElement: TJSHTMLElement);
- begin
- inherited ApplyWidgetSettings(aElement);
- if FTextContent<>'' then
- aElement.InnerText:=TextContent;
- end;
- function TCustomTagWidget.HTMLTag: String;
- begin
- Result:=HTMLTagNames[ElementTag];
- end;
- { TDivWidget }
- constructor TDivWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- ElementTag:=etDiv;
- end;
- constructor TParagraphWidget.Create(aOwner: TComponent);
- begin
- inherited Create(aOwner);
- ElementTag:=etP;
- end;
- end.
|