2 Star 1 Fork 0

wyrover/FlatStyle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
FlatCtrls.pas 148.44 KB
一键复制 编辑 原始数据 按行查看 历史
wyrover 提交于 2015-06-17 17:38 . + Init FlatStyle
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618
unit FlatCtrls;
interface
{$I FlatStyle.inc}
uses
Windows, Messages, Classes, Controls, Forms, Graphics, SysUtils,
StdCtrls, Dialogs, ExtCtrls, FlatUtils, FlatSkins, FlatBtns,
MaskUtils, FlatWatet;
type
{ TFlatTicket }
TFlatTicket = class(TCustomLabel)
private
function GetTop: Integer;
function GetLeft: Integer;
function GetWidth: Integer;
function GetHeight: Integer;
procedure SetHeight(const Value: Integer);
procedure SetWidth(const Value: Integer);
protected
procedure AdjustBounds; override;
property AutoSize default True;
public
constructor Create(AOwner: TComponent); override;
published
property Caption;
property Font;
property Height: Integer read GetHeight write SetHeight;
property ParentFont;
property Left: Integer read GetLeft;
property Top: Integer read GetTop;
property Width: Integer read GetWidth write SetWidth;
end;
{ TDefineEdit }
TDefineEdit = class(TVersionEdit)
private
FParentColor: Boolean;
FFocusColor: TColor;
FBorderColor: TColor;
FFlatColor: TColor;
FAlignment: TAlignment;
FTicketSpace: Integer;
FTicket: TFlatTicket;
FTicketPosition: TTicketPosition;
procedure SetColors(Index: Integer; Value: TColor);
procedure SetParentColor (Value: Boolean);
protected
FMouseIn: Boolean;
fLabel: TLabel;
procedure RedrawBorder(const Clip: HRGN);
procedure NewAdjustHeight;
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure SetAlignment(const Value: TAlignment);
procedure LabelMouseEnter(Sender: TObject);
procedure SetTicketPosition(const Value: TTicketPosition);
procedure SetTicketSpace(const Value: Integer);
procedure SetName(const Value: TComponentName); override;
procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
procedure SetParent(AParent: TWinControl); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure KeyPress(var Key: Char); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure Loaded; override;
procedure SetupInternalLabel;
property Ticket: TFlatTicket read FTicket;
property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
property TicketSpace: Integer read FTicketSpace write SetTicketSpace default 3;
property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
property ParentColor: Boolean read FParentColor write SetParentColor default false;
property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
end;
{ TFlatEdit }
TFlatEdit = class(TDefineEdit)
published
property Alignment;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property ParentColor;
property CharCase;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property ImeMode;
property ImeName;
property Ticket;
property TicketPosition;
property TicketSpace;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{ TFlatInteger }
TFlatInteger = class(TDefineEdit)
private
FMinValue: LongInt;
FMaxValue: LongInt;
FIncrement: LongInt;
FButton: TDefineSpin;
FEditorEnabled: Boolean;
function GetMinHeight: Integer;
function GetValue: LongInt;
function CheckValue (NewValue: LongInt): LongInt;
procedure SetValue (NewValue: LongInt);
protected
function IsValidChar (Key: Char): Boolean; virtual;
procedure UpClick (Sender: TObject); virtual;
procedure DownClick (Sender: TObject); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Loaded; override;
procedure CreateWnd; override;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure WMCut(var Message: TWMCut); message WM_CUT;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Button: TDefineSpin read FButton;
published
property Increment: LongInt read FIncrement write FIncrement default 1;
property MaxValue: LongInt read FMaxValue write FMaxValue default 0;
property MinValue: LongInt read FMinValue write FMinValue default 0;
property Value: LongInt read GetValue write SetValue default 0;
property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
property Alignment;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property AutoSelect;
property AutoSize;
property DragCursor;
property DragMode;
property Enabled;
property ImeMode;
property ImeName;
property Font;
property Ticket;
property TicketPosition;
property TicketSpace;
property ParentColor;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{ TFlatFloat }
TFlatFloat = class(TDefineEdit)
private
FPrecision, FDigits: Integer;
FFloatFormat: TFloatFormat;
FMinValue: Extended;
FMaxValue: Extended;
FIncrement: Extended;
FButton: TDefineSpin;
FEditorEnabled: Boolean;
function GetMinHeight: Integer;
function GetValue: Extended;
function CheckValue (Value: Extended): Extended;
procedure SetValue (Value: Extended);
procedure SetPrecision (Value: Integer);
procedure SetDigits (Value: Integer);
procedure SetFloatFormat (Value: TFloatFormat);
protected
function IsValidChar (Key: Char): Boolean; virtual;
procedure UpClick (Sender: TObject); virtual;
procedure DownClick (Sender: TObject); virtual;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
procedure Loaded; override;
procedure CreateWnd; override;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
procedure WMCut(var Message: TWMCut); message WM_CUT;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Button: TDefineSpin read FButton;
published
property Digits: Integer read FDigits write SetDigits;
property Precision: Integer read FPrecision write SetPrecision;
property FloatFormat: TFloatFormat read FFloatFormat write SetFloatFormat;
property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
property Increment: Extended read FIncrement write FIncrement;
property MaxValue: Extended read FMaxValue write FMaxValue;
property MinValue: Extended read FMinValue write FMinValue;
property Value: Extended read GetValue write SetValue;
property Alignment;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property AutoSelect;
property AutoSize;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property Ticket;
property TicketPosition;
property TicketSpace;
property ParentColor;
property ParentFont;
property ParentShowHint;
property ImeMode;
property ImeName;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{ TDefineMemo }
TDefineMemo = class(TVersionMemo)
private
FParentColor: Boolean;
FFocusColor: TColor;
FBorderColor: TColor;
FFlatColor: TColor;
FMouseIn: Boolean;
procedure SetColors(Index: Integer; Value: TColor);
procedure SetParentColor(Value: Boolean);
protected
procedure RedrawBorder (const Clip: HRGN);
procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
public
constructor Create(AOwner: TComponent); override;
published
property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
property ParentColor: Boolean read FParentColor write SetParentColor default false;
property Align;
property Alignment;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property ScrollBars;
property TabOrder;
property TabStop;
property Visible;
property Lines;
property WantReturns;
property WantTabs;
property WordWrap;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{ TFlatMemo }
TFlatMemo = class(TDefineMemo)
published
property ColorFocused;
property ColorBorder;
property ColorFlat;
property ParentColor;
property Version;
property Align;
property Alignment;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property ScrollBars;
property TabOrder;
property TabStop;
property Visible;
property Lines;
property WantReturns;
property WantTabs;
property WordWrap;
property ImeMode;
property ImeName;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{TDefineMask}
DefineError = class(Exception);
TDefineState = set of (msMasked, msReEnter, msDBSetText);
TDefineMask = class(TDefineEdit)
private
FEditMask: TEditMask;
FMaskBlank: Char;
FMaxChars: Integer;
FMaskSave: Boolean;
FMaskState: TDefineState;
FCaretPos: Integer;
FBtnDownX: Integer;
FOldValue: string;
FSettingCursor: Boolean;
FOnValidate: TValidateEvent;
function DoInputChar(var NewChar: Char; MaskOffset: Integer): Boolean;
function InputChar(var NewChar: Char; Offset: Integer): Boolean;
function DeleteSelection(var Value: string; Offset: Integer; Len: Integer): Boolean;
function InputString(var Value: string; const NewValue: string; Offset: Integer): Integer;
function AddEditFormat(const Value: string; Active: Boolean): string;
function RemoveEditFormat(const Value: string): string;
function FindLiteralChar (MaskOffset: Integer; InChar: Char): Integer;
function GetEditText: string;
function GetMasked: Boolean;
function GetText: TMaskedText;
function GetMaxLength: Integer;
function CharKeys(var CharCode: Char): Boolean;
procedure SetEditText(const Value: string);
procedure SetEditMask(const Value: TEditMask);
procedure SetMaxLength(Value: Integer);
procedure SetText(const Value: TMaskedText);
procedure DeleteKeys(CharCode: Word);
procedure HomeEndKeys(CharCode: Word; Shift: TShiftState);
procedure CursorInc(CursorPos: Integer; Incr: Integer);
procedure CursorDec(CursorPos: Integer);
procedure ArrowKeys(CharCode: Word; Shift: TShiftState);
procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
procedure WMCut(var Message: TMessage); message WM_CUT;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
protected
procedure ReformatText(const NewMask: string);
procedure GetSel(var SelStart: Integer; var SelStop: Integer);
procedure SetSel(SelStart: Integer; SelStop: Integer);
procedure SetCursor(Pos: Integer);
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
function EditCanModify: Boolean; virtual;
procedure Reset; virtual;
function GetFirstEditChar: Integer;
function GetLastEditChar: Integer;
function GetNextEditChar(Offset: Integer): Integer;
function GetPriorEditChar(Offset: Integer): Integer;
function GetMaxChars: Integer;
function Validate(const Value: string; var Pos: Integer): Boolean; virtual;
procedure ValidateError; virtual;
procedure CheckCursor;
property MaskState: TDefineState read FMaskState write FMaskState;
property MaxLength: Integer read GetMaxLength write SetMaxLength default 0;
property OnValidate : TValidateEvent read FOnValidate write FOnValidate;
public
constructor Create(AOwner: TComponent); override;
procedure ValidateEdit; virtual;
procedure Clear; override;
function GetTextLen: Integer;
property IsMasked: Boolean read GetMasked;
property EditText: string read GetEditText write SetEditText;
property Text: TMaskedText read GetText write SetText;
property EditMask: TEditMask read FEditMask write SetEditMask;
end;
{ TFlatIPEdit }
TFlatIPEdit = class(TDefineMask)
protected
{ Protected declarations }
IPText:TIP;
fIPAddress : String;
function GetInx: integer;
function GetIPText: String;
procedure SetIPText(const Value: String);
function Replace(Start, Len: Integer):integer;
procedure KeyPress(var Key: Char); override;
procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
procedure CMExit(var Message: TCMExit); message CM_EXIT;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
public
property Index:integer read GetInx;
constructor Create(AOwner: TComponent); override;
published
property IPAddress: String read GetIPText write SetIPText;
property Text;
property Ticket;
property TicketPosition;
property TicketSpace;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property ParentColor;
property Alignment;
property AutoSelect;
property CharCase;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property OnValidate;
end;
{ TFlatMaskEdit }
TFlatMaskEdit = class(TDefineMask)
published
property Ticket;
property TicketPosition;
property TicketSpace;
property ColorFocused;
property ColorBorder;
property ColorFlat;
property ParentColor;
property Alignment;
property CharCase;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property EditMask;
property Font;
property HideSelection;
property MaxLength;
property OEMConvert;
property ParentFont;
property ParentShowHint;
property PasswordChar;
property PopupMenu;
property ImeMode;
property ImeName;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property Text;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
property OnValidate;
end;
{ TDefineComboBox }
TDefineComboBox = class(TVersionComboBox)
private
FArrowColor: TColor;
FArrowBackgroundColor: TColor;
FBorderColor: TColor;
FButtonWidth: Integer;
FChildHandle: HWND;
FDefListProc: Pointer;
FListHandle: HWND;
FListInstance: Pointer;
FSysBtnWidth: Integer;
FSolidBorder: Boolean;
FTicketSpace: Integer;
FTicket: TFlatTicket;
FMouseInControl: Boolean;
FTicketPosition: TTicketPosition;
FFocusedColor: TColor;
FFlatColor: TColor;
fParentColor: Boolean;
FReadOnly: boolean;
procedure SetColors(Index: Integer; Value: TColor);
function GetButtonRect: TRect;
procedure PaintButton;
procedure PaintBorder;
procedure RedrawBorders;
procedure InvalidateSelection;
function GetSolidBorder: Boolean;
procedure SetSolidBorder;
procedure SetParentColor(const Value: Boolean);
protected
procedure ListWndProc(var Message: TMessage);
procedure KeyPress(var Key: Char); override;
procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
procedure WMKeyDown(var Message: TMessage); message WM_KEYDOWN;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure WndProc(var Message: TMessage); override;
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
procedure SetTicketPosition(const Value: TTicketPosition);
procedure SetTicketSpace(const Value: Integer);
procedure SetName(const Value: TComponentName); override;
procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
procedure SetParent(AParent: TWinControl); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetupInternalLabel;
property SolidBorder: Boolean read FSolidBorder;
property Ticket: TFlatTicket read FTicket;
property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
property TicketSpace: Integer read FTicketSpace write SetTicketSpace;
property ParentColor: Boolean read fParentColor write SetParentColor default true;
property ColorArrow: TColor index 0 read FArrowColor write SetColors default clBlack;
property ColorArrowBackground: TColor index 1 read FArrowBackgroundColor write SetColors default $00C5D6D9;
property ColorBorder: TColor index 2 read FBorderColor write SetColors default DefaultBorderColor;
property ColorFlat: TColor index 3 read FFlatColor write SetColors default DefaultFlatColor;
property ColorFocued: TColor index 4 read FFocusedColor write SetColors default clWhite;
property ReadOnly: boolean read FReadOnly write FReadOnly default false;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
end;
{ TFlatComboBox }
TFlatComboBox = class(TDefineComboBox)
published
property Ticket;
property TicketPosition;
property TicketSpace;
property CharCase;
property Style;
property ParentColor;
property ColorArrow;
property ColorArrowBackground;
property ColorBorder;
property ColorFlat;
property ColorFocued;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property ReadOnly;
property Font;
property ItemHeight;
property Items;
property MaxLength;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property Sorted;
property TabOrder;
property TabStop;
property ImeMode;
property ImeName;
property Text;
property Visible;
property ItemIndex;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDrawItem;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnStartDrag;
property Anchors;
property BiDiMode;
property Constraints;
property DragKind;
property ParentBiDiMode;
property OnEndDock;
property OnStartDock;
end;
{ TDefineColorBox }
TDefineColorBox = class(TVersionComboBox)
private
FArrowColor: TColor;
FArrowBackgroundColor: TColor;
FBorderColor: TColor;
FHighlightColor: TColor;
FButtonWidth: Integer;
FChildHandle: HWND;
FDefListProc: Pointer;
FListHandle: HWND;
FListInstance: Pointer;
FSysBtnWidth: Integer;
FSolidBorder: Boolean;
FShowNames: Boolean;
FValue: TColor;
FColorBoxWidth: Integer;
FColorDlg: TColorDialog;
FTicketSpace: Integer;
FTicket: TFlatTicket;
FTicketPosition: TTicketPosition;
fLanguage: TLanguage;
procedure SetColors(Index: Integer; Value: TColor);
function GetButtonRect: TRect;
procedure PaintButton;
procedure PaintBorder;
procedure RedrawBorders;
procedure InvalidateSelection;
function GetSolidBorder: Boolean;
procedure SetSolidBorder;
procedure SetShowNames(Value: Boolean);
procedure SetColorValue(Value: TColor);
procedure SetColorBoxWidth(Value: Integer);
procedure SetTicketPosition(const Value: TTicketPosition);
procedure SetTicketSpace(const Value: Integer);
procedure SetLanguage(const Value: TLanguage);
protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
procedure CreateWnd; override;
procedure WndProc(var Message: TMessage); override;
procedure ListWndProc(var Message: TMessage);
procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
procedure WMKeyDown(var Message: TMessage); message WM_KEYDOWN;
procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
property SolidBorder: Boolean read FSolidBorder;
procedure Click; override;
procedure SetName(const Value: TComponentName); override;
procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
procedure SetParent(AParent: TWinControl); override;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
procedure SetupInternalLabel;
property Color default DefaultFlatColor;
property ColorArrow: TColor index 0 read FArrowColor write SetColors default clBlack;
property ColorArrowBackground: TColor index 1 read FArrowBackgroundColor write SetColors default $00C5D6D9;
property ColorBorder: TColor index 2 read FBorderColor write SetColors default DefaultBorderColor;
property ColorHighlight: TColor index 3 read FHighlightColor write SetColors default clHighlight;
property ColorBoxWidth: Integer read FColorBoxWidth write SetColorBoxWidth default 30;
property ShowNames: Boolean read FShowNames write SetShowNames;
property Value: TColor read FValue write SetColorValue;
property Language:TLanguage read fLanguage write SetLanguage default lgChinese;
property Ticket: TFlatTicket read FTicket;
property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
property TicketSpace: Integer read FTicketSpace write SetTicketSpace default 3;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function AddColor(ColorName: String; Color: TColor): Boolean;
function DeleteColorByName(ColorName: String): Boolean;
function DeleteColorByColor(Color: TColor): Boolean;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
end;
{ TFlatColorBox }
TFlatColorBox = class(TDefineColorBox)
published
property Color;
property ColorArrow;
property ColorArrowBackground;
property ColorBorder;
property ColorHighlight;
property ColorBoxWidth;
property ShowNames;
property Value;
property Language;
property Ticket;
property TicketPosition;
property TicketSpace;
property DragMode;
property DragCursor;
property DropDownCount;
property Enabled;
property Font;
property MaxLength;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property ImeMode;
property ImeName;
property Sorted;
property TabOrder;
property TabStop;
property Visible;
property OnChange;
property OnClick;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnDropDown;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMeasureItem;
property OnStartDrag;
end;
{ TDefineSplitter }
TDefineHack = class(TWinControl);
TDefineSplitter = class(TVersionGraphic)
private
FBorderColor: TColor;
FFocusedColor: TColor;
FLineDC: HDC;
FDownPos: TPoint;
FSplit: Integer;
FMinSize: NaturalNumber;
FMaxSize: Integer;
FControl: TControl;
FNewSize: Integer;
FActiveControl: TWinControl;
FOldKeyDown: TKeyEvent;
FLineVisible: Boolean;
FOnMoved: TNotifyEvent;
FStatus: TSplitterStatus;
procedure AllocateLineDC;
procedure DrawLine;
procedure ReleaseLineDC;
procedure UpdateSize(X, Y: Integer);
procedure FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure SetColors (Index: Integer; Value: TColor);
procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure CMEnter(var Message: TMessage); message CM_MOUSEENTER;
procedure CMExit(var Message: TMessage); message CM_MOUSELEAVE;
protected
procedure Paint; override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure StopSizing;
public
constructor Create(AOwner: TComponent); override;
published
property Color default $00E0E9EF;
property ColorFocused: TColor index 0 read FFocusedColor write SetColors default $0053D2FF;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default $00555E66;
property MinSize: NaturalNumber read FMinSize write FMinSize default 30;
property OnMoved: TNotifyEvent read FOnMoved write FOnMoved;
property Align default alLeft;
property Enabled;
property ParentColor;
property ParentShowHint;
property ShowHint;
property Visible;
end;
{ TFlatSplitter }
TFlatSplitter = class(TDefineSplitter)
published
property Color;
property ColorFocused;
property ColorBorder;
property MinSize;
property OnMoved;
property Align;
property Enabled;
property ParentColor;
property ParentShowHint;
property ShowHint;
property Visible;
end;
{ TDefineAnimation }
TDefineAnimation = class(TVersionControl)
private
FTransparent: Boolean;
FAnimation: TBitmap;
FFrames: Integer;
FFrameWidth: Integer;
FFrame: Integer;
FInterval: Integer;
FTransColor: TColor;
FActive: Boolean;
FLoop: Boolean;
FReverse: Boolean;
FTimer: TTimer;
FBorderColor: TColor;
FBorder: Boolean;
FFrameChange: TOnFrameChange;
FAnimationLayout: TAnimationLayout;
procedure SetAnimation(Value: TBitmap);
procedure SetFrames(Value: Integer);
procedure SetFrameWidth(Value: Integer);
procedure SetFrame(Value: Integer);
procedure SetActive(Value: Boolean);
procedure SetTransparent(Value: Boolean);
procedure SetLoop(Value: Boolean);
procedure SetReverse(Value: Boolean);
procedure SetInterval(Value: Integer);
procedure SetBorder(Value: Boolean);
procedure DoTimer(Sender: TObject);
procedure SetColors(Index: Integer; Value: TColor);
procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
procedure WMSize(var Message: TWMSize); message WM_SIZE;
procedure SetAnimationLayout(const Value: TAnimationLayout);
protected
procedure Paint; override;
property Animation: TBitmap read FAnimation write SetAnimation;
property Frames: Integer read FFrames write SetFrames;
property FrameWidth: Integer read FFrameWidth write SetFrameWidth;
property Frame: Integer read FFrame write SetFrame default 1;
property Interval: Integer read FInterval write SetInterval;
property ColorTransparent: TColor index 0 read FTransColor write SetColors default clFuchsia;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
property Active: Boolean read FActive write SetActive;
property Loop: Boolean read FLoop write SetLoop;
property Reverse: Boolean read FReverse write SetReverse;
property Border: Boolean read FBorder write SetBorder default false;
property AnimationLayout: TAnimationLayout read FAnimationLayout write SetAnimationLayout;
property OnFrameChange: TOnFrameChange read FFrameChange write FFrameChange;
property Transparent: Boolean read FTransparent write SetTransparent default false;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
{ TFlatAnimation }
TFlatAnimation = class(TDefineAnimation)
published
property Color;
property Animation;
property Frames;
property FrameWidth;
property Frame;
property Interval;
property ColorTransparent;
property ColorBorder;
property Active;
property Loop;
property Reverse;
property Border;
property AnimationLayout;
property OnFrameChange;
property Transparent;
property Align;
property Enabled;
property ParentColor;
property ParentShowHint;
property ShowHint;
property Visible;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDrag;
end;
{ TFlatHint }
TFlatHint = class(TVersionComponent)
private
FHintFont: TFont;
FBackgroundColor: TColor;
FBorderColor: TColor;
FArrowBackgroundColor: TColor;
FArrowColor: TColor;
FHintWidth: Integer;
FOnShowHint: TShowHintEvent;
procedure SetColors (Index: Integer; Value: TColor);
procedure SetHintFont (Value: TFont);
procedure GetHintInfo (var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
public
constructor Create (AOwner: TComponent); override;
destructor Destroy; override;
published
property ColorBackground: TColor index 0 read FBackgroundColor write SetColors default clWhite;
property ColorBorder: TColor index 1 read FBorderColor write SetColors default clBlack;
property ColorArrowBackground: TColor index 2 read FArrowBackgroundColor write SetColors default $0053D2FF;
property ColorArrow: TColor index 3 read FArrowColor write SetColors default clBlack;
property MaxWidth: Integer read FHintWidth write FHintWidth default 200;
property Font: TFont read FHintFont write SetHintFont;
property OnShowHint: TShowHintEvent read FOnShowHint write FOnShowHint;
end;
{ TFlatHintWindow }
TFlatHintWindow = class(THintWindow)
private
FArrowPos: TArrowPos;
FArrowPoint: TPoint;
FHint: TFlatHint;
function FindFlatHint: TFlatHint;
protected
procedure Paint; override;
procedure CreateParams(var Params: TCreateParams); override;
public
procedure ActivateHint(HintRect: TRect; const AHint: string); Override;
end;
TDefineImage = class(TVersionGraphic)
private
FBitmap: TBitmap;
FOnProgress: TProgressEvent;
FStretch: Boolean;
FCenter: Boolean;
FIncrementalDisplay: Boolean;
FTransparent: Boolean;
FDrawing: Boolean;
FProportional: Boolean;
FAutoShowCursor: Boolean;
FAutoImage: Boolean;
FLeaveImage: TBitmap;
FEnterImage: TBitmap;
FAutoCursor: TCursor;
FMouseState: Boolean;
procedure PictureChanged(Sender: TObject);
procedure SetCenter(Value: Boolean);
procedure SetPicture(Value: TBitmap);
procedure SetStretch(Value: Boolean);
procedure SetTransparent(Value: Boolean);
procedure SetProportional(Value: Boolean);
procedure SetEnterImage(const Value: TBitmap);
procedure SetLeaveImage(const Value: TBitmap);
protected
procedure MouseEnter(Var Msg:TMessage);message CM_MouseEnter;
procedure MouseLeave(Var Msg:TMessage);message CM_MouseLeave;
function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
function DestRect: TRect;
function DoPaletteChange: Boolean;
function GetPalette: HPALETTE; override;
function GetCanvas: TCanvas;
procedure Paint; override;
procedure Progress(Sender: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string); dynamic;
property Center: Boolean read FCenter write SetCenter default False;
property IncrementalDisplay: Boolean read FIncrementalDisplay write FIncrementalDisplay default False;
property Proportional: Boolean read FProportional write SetProportional default false;
property Stretch: Boolean read FStretch write SetStretch default False;
property Transparent: Boolean read FTransparent write SetTransparent default False;
property OnProgress: TProgressEvent read FOnProgress write FOnProgress;
property BMPEnter:TBitmap read FEnterImage write SetEnterImage;
property BMPLeave:TBitmap read FLeaveImage write SetLeaveImage;
property AutoImage:Boolean read FAutoImage write FAutoImage default false;
property AutoCursor:TCursor read FAutoCursor Write FAutoCursor default crHandPoint;
property AutoShowCursor:Boolean read FAutoShowCursor write FAutoShowCursor default false;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Bitmap: TBitmap read FBitmap write SetPicture;
property Canvas: TCanvas read GetCanvas;
property OnMouseMove;
end;
TFlatImage = class(TDefineImage)
published
property AutoImage;
property AutoCursor;
property AutoShowCursor;
property Align;
property Anchors;
property AutoSize;
property Center;
property Constraints;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property IncrementalDisplay;
property ParentShowHint;
property Bitmap;
property BMPEnter;
property BMPLeave;
property PopupMenu;
property Proportional;
property ShowHint;
property Stretch;
property Transparent;
property Visible;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnProgress;
property OnStartDock;
property OnStartDrag;
end;
TDefineTimer = class(TVersionComponent)
private
FInterval: Cardinal;
FHandle: HWND;
FOnTimer: TNotifyEvent;
FEnabled: Boolean;
procedure SetEnabled(Value: Boolean);
procedure SetInterval(Value: Cardinal);
procedure SetOnTimer(Value: TNotifyEvent);
protected
procedure Timer; dynamic;
procedure UpdateTimer;
procedure WndProc(var Msg: TMessage);
property Enabled: Boolean read FEnabled write SetEnabled default True;
property Interval: Cardinal read FInterval write SetInterval default 50;
property OnTimer: TNotifyEvent read FOnTimer write SetOnTimer;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
TDefineWater = class(TDefineTimer)
private
FState: Integer;
FParam: TOtherParam;
FDamping: TWaterDamping;
FBitmap: TBitmap;
FImage: TDefineImage;
FPlayState: boolean;
FItems: TStringList;
procedure SetDamping(Value: TWaterDamping);
procedure SetItems(const Value: TStringList);
protected
FWater: TDefineWatet;
FMoveHeight: Integer;
procedure OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure Notification(AComponent: TComponent;Operation: TOperation); override;
procedure Play(sender: TObject);
procedure InitiateWater;
property Bitmap: TBitmap read FBitmap;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property Damping: TWaterDamping read FDamping write SetDamping;
property CtrlImage: TDefineImage read FImage write FImage;
property Items: TStringList read FItems write SetItems;
property Enabled;
property Interval;
end;
TFlatWater = class(TDefineWater)
published
property Damping;
property CtrlImage;
property Items;
property Enabled;
property Interval;
end;
implementation
uses Clipbrd, FlatConsts;
{ TFlatTicket }
constructor TFlatTicket.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
Name := 'Ticket'; { do not localize }
SetSubComponent(True);
if Assigned(AOwner) then
Caption := '';//AOwner.Name;
AutoSize := True;
end;
procedure TFlatTicket.AdjustBounds;
begin
inherited AdjustBounds;
if Owner is TDefineEdit then begin
with Owner as TDefineEdit do begin
SetTicketPosition(TicketPosition);
end;
end;
if Owner is TDefineComboBox then begin
with Owner as TDefineComboBox do
SetTicketPosition(TicketPosition);
end;
if Owner is TDefineColorBox then begin
with Owner as TDefineColorBox do
SetTicketPosition(TicketPosition);
end;
end;
function TFlatTicket.GetHeight: Integer;
begin
Result := inherited Height;
end;
function TFlatTicket.GetLeft: Integer;
begin
Result := inherited Left;
end;
function TFlatTicket.GetTop: Integer;
begin
Result := inherited Top;
end;
function TFlatTicket.GetWidth: Integer;
begin
Result := inherited Width;
end;
procedure TFlatTicket.SetHeight(const Value: Integer);
begin
SetBounds(Left, Top, Width, Value);
end;
procedure TFlatTicket.SetWidth(const Value: Integer);
begin
SetBounds(Left, Top, Value, Height);
end;
{ TDefineEdit }
procedure TDefineEdit.SetupInternalLabel;
begin
if not(csDesigning in ComponentState) then begin
fLabel := TLabel.Create(Self);
fLabel.Parent := self;
fLabel.OnClick := LabelMouseEnter;
fLabel.AutoSize := false;
fLabel.Visible := false;
fLabel.Transparent := True;
fLabel.FocusControl := self;
fLabel.Font.Assign(Font);
end;
if (DefaultHasTicket)and(not Assigned(FTicket)) then
begin
FTicket := TFlatTicket.Create(self);
FTicket.FreeNotification(Self);
FTicket.AutoSize := True;
FTicket.Transparent := True;
FTicket.FocusControl := Self;
end;
end;
constructor TDefineEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csFramed];
ParentFont := True;
AutoSize := False;
Ctl3D := False;
BorderStyle := bsNone;
FFocusColor := clWhite;
FBorderColor := DefaultBorderColor;
FFlatColor := DefaultFlatColor;
FParentColor := True;
FAlignment := taLeftJustify;
FTicketPosition := poLeft;
FTicketSpace := 3;
SetupInternalLabel;
end;
destructor TDefineEdit.Destroy;
begin
if Assigned(fLabel) then
fLabel.Free;
if Assigned(FTicket) then
FTicket.Free;
inherited destroy;
end;
procedure TDefineEdit.RedrawBorder(const Clip: HRGN);
var
Attrib:TBorderAttrib;
begin
with Attrib do
begin
Ctrl := self;
FocusColor := ColorFocused;
BorderColor := ColorBorder;
FlatColor := ColorFlat;
MouseState := FMouseIn;
FocusState := Focused;
DesignState := ComponentState;
HasBars := false;
end;
Color := DrawEditBorder(Attrib,Clip);
if (not(csDesigning in ComponentState))and(Assigned(fLabel)) then
begin
if not Focused then
fLabel.Visible := self.Text = ''
else
fLabel.Visible := False;
if fLabel.Visible then
begin
fLabel.Font.Assign(self.Font);
fLabel.Width := self.Width;
fLabel.Top := (self.Height-fLabel.Height) div 2;
fLabel.Left := 0;
fLabel.Caption := self.Hint;
end;
end;
end;
procedure TDefineEdit.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do begin
Params.Style := Params.Style or ES_MULTILINE or Aligns[FAlignment];
end;
end;
procedure TDefineEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if (Key = Char(VK_RETURN)) then
Key := #0;
end;
procedure TDefineEdit.SetParentColor(Value: Boolean);
begin
if Value <> FParentColor then
begin
FParentColor := Value;
if FParentColor then
begin
if Parent <> nil then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
end;
end;
procedure TDefineEdit.LabelMouseEnter(Sender: TObject);
begin
if (not(csDesigning in ComponentState))and(Assigned(fLabel)) then begin
fLabel.Visible := false;
self.SetFocus;
end;
end;
procedure TDefineEdit.SetTicketPosition(const Value: TTicketPosition);
begin
if Assigned(FTicket) then
begin
FTicketPosition := Value;
SetTicketPoint(Value,Self,Ticket,FTicketSpace);
end;
end;
procedure TDefineEdit.SetTicketSpace(const Value: Integer);
begin
if Assigned(FTicket) then
begin
FTicketSpace := Value;
SetTicketPosition(FTicketPosition);
end;
end;
procedure TDefineEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetTicketPosition(FTicketPosition);
end;
procedure TDefineEdit.SetParent(AParent: TWinControl);
begin
if Assigned(FTicket) then
begin
FTicket.Parent := AParent;
FTicket.Visible := Visible;
end;
inherited SetParent(AParent);
end;
procedure TDefineEdit.CMBidimodechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
end;
procedure TDefineEdit.CMVisiblechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.Visible := Visible;
end;
procedure TDefineEdit.SetName(const Value: TComponentName);
begin
if Assigned(FTicket) then
begin
if (csDesigning in ComponentState) and ((FTicket.GetTextLen = 0) or
(CompareText(FTicket.Caption, Name) = 0)) then
FTicket.Caption := Value;
end;
inherited SetName(Value);
if (csDesigning in ComponentState)and(Assigned(FTicket))and
((GetTextLen = 0)or(CompareText(Text, Name) = 0)) then
Text := '';
end;
procedure TDefineEdit.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (AComponent = FTicket) and (Operation = opRemove) then
FTicket := nil;
end;
procedure TDefineEdit.CMSysColorChange(var Message: TMessage);
begin
if (Parent <> nil)and(FParentColor) then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
procedure TDefineEdit.CMParentColorChanged(var Message: TWMNoParams);
begin
if (Parent <> nil)and(FParentColor) then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
procedure TDefineEdit.SetColors(Index: Integer; Value: TColor);
begin
case Index of
0: FFocusColor := Value;
1: FBorderColor := Value;
2: begin
FFlatColor := Value;
FParentColor := False;
end;
end;
RedrawBorder(0);
end;
procedure TDefineEdit.CMMouseEnter(var Message: TMessage);
begin
inherited;
if (GetActiveWindow <> 0) then
begin
FMouseIn := True;
RedrawBorder(0);
end;
end;
procedure TDefineEdit.CMMouseLeave(var Message: TMessage);
begin
inherited;
FMouseIn := False;
RedrawBorder(0);
end;
procedure TDefineEdit.NewAdjustHeight;
var
DC: HDC;
SaveFont: HFONT;
Metrics: TTextMetric;
begin
DC := GetDC(0);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
Height := Metrics.tmHeight + 6;
end;
procedure TDefineEdit.Loaded;
begin
inherited;
if not(csDesigning in ComponentState) then
begin
NewAdjustHeight;
end;
end;
procedure TDefineEdit.CMTextChanged(var Message: TMessage);
begin
inherited;
if not(csDesigning in ComponentState) and Assigned(fLabel) then
begin
if fLabel.Visible then
fLabel.Visible := false;
if (not fLabel.Visible) and (Text = '') then
fLabel.Visible := True;
end;
end;
procedure TDefineEdit.CMEnabledChanged(var Message: TMessage);
const
EnableColors: array[Boolean] of TColor= (clBtnFace, clWindow);
begin
inherited;
Color := EnableColors[Enabled];
if assigned(FTicket) then FTicket.Enabled := Enabled;
if (not(csDesigning in ComponentState))and(assigned(fLabel)) then
fLabel.Enabled := Enabled;
RedrawBorder(0);
end;
procedure TDefineEdit.CMFontChanged(var Message: TMessage);
begin
inherited;
if not((csDesigning in ComponentState) and (csLoading in ComponentState)) then
NewAdjustHeight;
if (not(csDesigning in ComponentState))and(assigned(fLabel)) then
fLabel.Font.Assign(Font);
end;
procedure TDefineEdit.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if not(csDesigning in ComponentState) then
begin
RedrawBorder(0);
SelectAll;
end;
end;
procedure TDefineEdit.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not(csDesigning in ComponentState) then
RedrawBorder(0);
end;
procedure TDefineEdit.WMNCCalcSize(var Message: TWMNCCalcSize);
begin
inherited;
InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
end;
procedure TDefineEdit.WMNCPaint(var Message: TMessage);
begin
inherited;
RedrawBorder(HRGN(Message.WParam));
end;
procedure TDefineEdit.SetAlignment(const Value: TAlignment);
begin
If FAlignment <> Value Then
begin
FAlignment := Value;
RecreateWnd;
end;
end;
{ TFlatInteger }
constructor TFlatInteger.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csSetCaption];
FButton := TDefineSpin.Create(Self);
FButton.Parent := Self;
FButton.Width := 32;
FButton.Height := 10;
FButton.Visible := True;
FButton.FocusControl := Self;
FButton.OnUpClick := UpClick;
FButton.OnDownClick := DownClick;
Text := '0';
FIncrement := 1;
FMaxValue := 0;
FMinValue := 0;
FEditorEnabled := True;
end;
destructor TFlatInteger.Destroy;
begin
FButton := nil;
inherited Destroy;
end;
procedure TFlatInteger.UpClick (Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
Value := Value + FIncrement;
end;
procedure TFlatInteger.DownClick (Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
Value := Value - FIncrement;
end;
procedure TFlatInteger.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_UP: UpClick(Self);
VK_DOWN: DownClick(Self);
end;
inherited KeyDown(Key, Shift);
end;
function TFlatInteger.IsValidChar(Key: Char): Boolean;
begin
Result := (Key in ['0'..'9',#8,#13]);
if not FEditorEnabled and Result then
Result := False;
end;
procedure TFlatInteger.KeyPress(var Key: Char);
begin
if not IsValidChar(Key) then begin
Key := #0;
MessageBeep(0)
end;
if Key <> #0 then
inherited KeyPress(Key);
end;
procedure TFlatInteger.WMSize(var Message: TWMSize);
var
MinHeight: Integer;
begin
inherited;
MinHeight := GetMinHeight;
if Height < MinHeight then
Height := MinHeight
else
if FButton <> nil then
begin
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
end;
end;
function TFlatInteger.GetMinHeight: Integer;
var
DC: HDC;
SaveFont: HFont;
SysMetrics, Metrics: TTextMetric;
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
Result := Metrics.tmHeight + 7;
ReleaseDC(0, DC);
end;
function TFlatInteger.CheckValue(NewValue: LongInt): LongInt;
begin
Result := NewValue;
if (FMaxValue <> FMinValue) then
begin
if NewValue < FMinValue then
Result := FMinValue
else
if NewValue > FMaxValue then
Result := FMaxValue;
end;
end;
procedure TFlatInteger.WMPaste(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TFlatInteger.WMCut(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TFlatInteger.CMExit(var Message: TCMExit);
begin
inherited;
if Text = '' then
Value := 0;
if CheckValue(Value) <> Value then
SetValue(Value)
else
SetValue(Value);
end;
function TFlatInteger.GetValue: LongInt;
begin
if Text = '' then
Text := '0';
try
result := StrToInt(Text);
except
result := FMinValue;
end;
end;
procedure TFlatInteger.SetValue(NewValue: LongInt);
begin
Text := IntToStr(CheckValue(NewValue));
end;
procedure TFlatInteger.CMEnter(var Message: TCMGotFocus);
begin
if AutoSelect and not (csLButtonDown in ControlState) then
SelectAll;
inherited;
end;
procedure TFlatInteger.Loaded;
begin
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
inherited;
end;
procedure TFlatInteger.CreateWnd;
begin
inherited;
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
end;
procedure TFlatInteger.CMTextChanged(var Message: TMessage);
begin
inherited;
if Text = '' then begin
Text := '0';
end;
Value := CheckValue(StrToInt(Text));
end;
{ TFlatFloat }
constructor TFlatFloat.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csSetCaption];
FButton := TDefineSpin.Create (Self);
FButton.Parent := Self;
FButton.Width := 32;
FButton.Height := 10;
FButton.Visible := True;
FButton.FocusControl := Self;
FButton.OnUpClick := UpClick;
FButton.OnDownClick := DownClick;
Text := '0' + DecimalSeparator + '00';
FDigits := 2;
FPrecision := 9;
FIncrement := 0.5;
FEditorEnabled := True;
end;
destructor TFlatFloat.Destroy;
begin
FButton := nil;
inherited Destroy;
end;
procedure TFlatFloat.KeyDown(var Key: Word; Shift: TShiftState);
begin
case Key of
VK_UP: UpClick(Self);
VK_DOWN: DownClick(Self);
end;
inherited KeyDown(Key, Shift);
end;
procedure TFlatFloat.KeyPress(var Key: Char);
begin
if (not IsValidChar(Key))or((key='.') and (pos('.',Text)>0)) then begin
Key := #0;
MessageBeep(0)
end;
if Key <> #0 then
inherited KeyPress(Key);
end;
function TFlatFloat.IsValidChar(Key: Char): Boolean;
begin
Result := (Key in [DecimalSeparator, '0'..'9',#8,#13,#46]);
if not FEditorEnabled and Result then
Result := False;
end;
procedure TFlatFloat.WMSize(var Message: TWMSize);
var
MinHeight: Integer;
begin
inherited;
MinHeight := GetMinHeight;
if Height < MinHeight then
Height := MinHeight
else
if FButton <> nil then
begin
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
end;
end;
function TFlatFloat.CheckValue(Value: Extended): Extended;
begin
Result := Value;
if (FMaxValue <> FMinValue) then begin
if Value < FMinValue then
Result := FMinValue
else
if Value > FMaxValue then
Result := FMaxValue;
end;
end;
function TFlatFloat.GetMinHeight: Integer;
var
DC: HDC;
SaveFont: HFont;
SysMetrics, Metrics: TTextMetric;
begin
DC := GetDC(0);
GetTextMetrics(DC, SysMetrics);
SaveFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, SaveFont);
ReleaseDC(0, DC);
Result := Metrics.tmHeight + 7;
end;
procedure TFlatFloat.UpClick(Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
Value := Value + FIncrement;
end;
procedure TFlatFloat.DownClick(Sender: TObject);
begin
if ReadOnly then
MessageBeep(0)
else
Value := Value - FIncrement;
end;
procedure TFlatFloat.WMPaste(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TFlatFloat.WMCut(var Message: TWMPaste);
begin
if not FEditorEnabled or ReadOnly then
Exit;
inherited;
end;
procedure TFlatFloat.CMExit(var Message: TCMExit);
begin
inherited;
if (Text = '')or(Text = '')or(Text = '.') then
Value := 0;
if CheckValue(Value) <> Value then
SetValue(Value)
else
SetValue(Value);
end;
function TFlatFloat.GetValue: Extended;
var
s: string;
begin
try
s := Text;
while Pos(CurrencyString, S) > 0 do
Delete(S, Pos(CurrencyString, S), Length(CurrencyString));
while Pos(#32, S) > 0 do
Delete(S, Pos(#32, S), 1);
while Pos(ThousandSeparator, S) > 0 do
Delete(S, Pos(ThousandSeparator, S), Length(ThousandSeparator));
//Delete negative numbers in format Currency
if Pos('(', S) > 0 then
begin
Delete(S, Pos('(', S), 1);
if Pos(')', S) > 0 then
Delete(S, Pos(')', S), 1);
Result := StrToFloat(S)*-1;
end
else
Result := StrToFloat(S);
except
Result := FMinValue;
end;
end;
procedure TFlatFloat.SetFloatFormat(Value: TFloatFormat);
begin
FFloatFormat := Value;
Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
end;
procedure TFlatFloat.SetDigits(Value: Integer);
begin
FDigits := Value;
Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
end;
procedure TFlatFloat.SetPrecision(Value: Integer);
begin
FPrecision := Value;
Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
end;
procedure TFlatFloat.SetValue(Value: Extended);
begin
Text := FloatToStrF(CheckValue(Value), FloatFormat, Precision, Digits);
end;
procedure TFlatFloat.CMEnter(var Message: TCMGotFocus);
begin
if AutoSelect and not (csLButtonDown in ControlState) then
SelectAll;
inherited;
end;
procedure TFlatFloat.Loaded;
begin
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
inherited;
end;
procedure TFlatFloat.CreateWnd;
begin
inherited;
SetEditRect(Handle, Clientwidth, ClientHeight, FButton.Width);
FButton.SetBounds(Width - FButton.Width - 5, 0, FButton.Width, Height - 6);
end;
procedure TFlatFloat.CMTextChanged(var Message: TMessage);
begin
inherited;
if Text = '' then begin
Text := '0';
end;
Value := GetValue;
end;
{ TDefineMemo }
constructor TDefineMemo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csFramed];
ParentFont := True;
AutoSize := False;
Ctl3D := False;
BorderStyle := bsNone;
FFocusColor := clWhite;
FBorderColor := DefaultBorderColor;
FFlatColor := DefaultFlatColor;
FParentColor := True;
FMouseIn := False;
end;
procedure TDefineMemo.RedrawBorder(const Clip: HRGN);
var
Attrib:TBorderAttrib;
begin
with Attrib do
begin
Ctrl := self;
FocusColor := ColorFocused;
BorderColor := ColorBorder;
FlatColor := ColorFlat;
MouseState := FMouseIn;
FocusState := Focused;
DesignState := ComponentState;
HasBars := ScrollBars = ssBoth;
end;
Color := DrawEditBorder(Attrib,Clip);
end;
procedure TDefineMemo.SetParentColor(Value: Boolean);
begin
if Value <> FParentColor then
begin
FParentColor := Value;
if FParentColor then
begin
if Parent <> nil then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
end;
end;
procedure TDefineMemo.CMSysColorChange(var Message: TMessage);
begin
if (Parent <> nil)and(FParentColor) then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
procedure TDefineMemo.CMParentColorChanged(var Message: TWMNoParams);
begin
if (Parent <> nil)and(FParentColor) then
FFlatColor := TForm(Parent).Color;
RedrawBorder(0);
end;
procedure TDefineMemo.SetColors(Index: Integer; Value: TColor);
begin
case Index of
0: FFocusColor := Value;
1: FBorderColor := Value;
2: begin
FFlatColor := Value;
FParentColor := False;
end;
end;
RedrawBorder(0);
end;
procedure TDefineMemo.CMMouseEnter(var Message: TMessage);
begin
inherited;
if (GetActiveWindow <> 0) then
begin
FMouseIn := True;
RedrawBorder(0);
end;
end;
procedure TDefineMemo.CMMouseLeave(var Message: TMessage);
begin
inherited;
FMouseIn := False;
RedrawBorder(0);
end;
procedure TDefineMemo.CMEnabledChanged(var Message: TMessage);
const
EnableColors: array[Boolean] of TColor = (clBtnFace, clWindow);
begin
inherited;
Color := EnableColors[Enabled];
RedrawBorder(0);
end;
procedure TDefineMemo.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if not(csDesigning in ComponentState) then
RedrawBorder(0);
end;
procedure TDefineMemo.WMKillFocus(var Message: TWMKillFocus);
begin
inherited;
if not(csDesigning in ComponentState) then
RedrawBorder(0);
end;
procedure TDefineMemo.WMNCCalcSize(var Message: TWMNCCalcSize);
begin
inherited;
InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
end;
procedure TDefineMemo.WMNCPaint(var Message: TMessage);
begin
inherited;
RedrawBorder(HRGN(Message.WParam));
end;
{ TFlatIPEdit }
function TFlatIPEdit.Replace(Start, Len: Integer): integer;
var t,s:String;
begin
s := Text;
t := trim(copy(Text,Start-Len,Len));
if t <> '' then begin
if StrToInt(t)>255 then begin
delete(s,Start-Len,Len);
insert('255',s,Start-Len);
Text := s;
SelStart := Start-4;
SelLength := Len;
end;
end;
result := SelStart;
end;
procedure TFlatIPEdit.CMTextChanged(var Message: TMessage);
begin
inherited;
SetIPText(Text);
end;
constructor TFlatIPEdit.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
EditMask := IPMaskStr;
Text := IPStart;
end;
function TFlatIPEdit.GetIPText: String;
begin
result := self.Text;
while Pos(#32,Result) > 0 do
delete(Result,Pos(#32,Result),1);
end;
procedure TFlatIPEdit.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
end;
procedure TFlatIPEdit.SetIPText(const Value: String);
var i:integer;
t:TIPChar;
s:string;
begin
if fIPAddress <> Value then begin
if Value <> '' then begin
s := '';
for i:=1 to Length(Value) do begin
if Value[i] in ['0'..'9','.'] then
s := s + Value[i];
end;
if Length(s)>0 then
begin
if s[Length(s)]<>'.' then
s:=s+'.';
IPEmpty(IPText);
i:=1;
while (pos('.',s)>0)and(i<=4) do begin
t:=Trim(Copy(s,1,Pos('.',s)-1));
if t <> '' then begin
if StrToInt(t) > 255 then
IPValue(IPText,I,'255')
else begin
case Length(t) of
1:t := #32+t+#32;
2:t := #32+t;
end;
IPValue(IPText,I,t);
end;
end;
s:=copy(s,Pos('.',s)+1,Length(s));
Inc(I);
end;
end;
fIPAddress := format('%s.%s.%s.%s',[IPText.NO1,IPText.NO2,IPText.NO3,IPText.NO4]);
end else begin
fIPAddress := IPStart;
end;
end;
Text := fIPAddress;
end;
procedure TFlatIPEdit.CMExit(var Message: TCMExit);
begin
if IsMasked and not (csDesigning in ComponentState) then
SetIPText(Text);
inherited;
end;
function TFlatIPEdit.GetInx: integer;
var inx:integer;
begin
GetSel(Result,inx);
end;
procedure TFlatIPEdit.KeyDown(var Key: Word; Shift: TShiftState);
begin
inherited KeyDown(Key, Shift);
end;
procedure TFlatIPEdit.KeyUp(var Key: Word; Shift: TShiftState);
begin
if IsMasked then begin
if SelStart <= 4 then
Replace( 4,3)
else if SelStart <= 8 then
Replace( 8,3)
else if SelStart <= 12 then
Replace(12,3)
else
Replace(16,3);
end;
inherited KeyUp(Key,Shift);
end;
{ TDefineComboBox }
procedure TDefineComboBox.SetupInternalLabel;
begin
if DefaultHasTicket then begin
if Assigned(FTicket) then exit;
FTicket := TFlatTicket.Create(Self);
FTicket.FreeNotification(Self);
FTicket.Transparent := True;
FTicket.FocusControl := Self;
end;
end;
constructor TDefineComboBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csFixedHeight] + [csOpaque];
TControlCanvas(Canvas).Control := self;
SetBounds(0,0,120,20);
FButtonWidth := 16;
FSysBtnWidth := GetSystemMetrics(SM_CXVSCROLL);
FListInstance := MakeObjectInstance(ListWndProc);
FDefListProc := nil;
ItemHeight := 13;
FArrowColor := clBlack;
FArrowBackgroundColor := $00C5D6D9;
FFocusedColor := clWhite;
FFlatColor := DefaultFlatColor;
FParentColor := True;
FBorderColor := DefaultBorderColor;
FReadOnly := false;
FTicketPosition := poLeft;
FTicketSpace := 3;
SetupInternalLabel;
end;
destructor TDefineComboBox.Destroy;
begin
FreeObjectInstance(FListInstance);
inherited Destroy;
end;
procedure TDefineComboBox.SetColors(Index: Integer; Value: TColor);
begin
case Index of
0: FArrowColor := Value;
1: FArrowBackgroundColor := Value;
2: FBorderColor := Value;
3: FFlatColor := Value;
4: FFocusedColor := Value;
end;
if index = 3 then
FParentColor := False;
Invalidate;
end;
procedure TDefineComboBox.CMSysColorChange(var Message: TMessage);
begin
if FParentColor then begin
if Parent <> nil then
FFlatColor := TForm(Parent).Color;
end;
Invalidate;
end;
procedure TDefineComboBox.InvalidateSelection;
var
R: TRect;
begin
R := ClientRect;
InflateRect(R, -2, -3);
R.Left := R.Right - FButtonWidth - 8;
Dec(R.Right, FButtonWidth + 3);
if(GetFocus = Handle) and not DroppedDown then
Canvas.Brush.Color := clHighlight
else
Canvas.Brush.Color := Color;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(R);
if(GetFocus = Handle) and not DroppedDown then
begin
R := ClientRect;
InflateRect(R, -3, -3);
Dec(R.Right, FButtonWidth + 2);
Canvas.FrameRect(R);
Canvas.Brush.Color := clWindow;
end;
ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
end;
procedure TDefineComboBox.CMParentColorChanged(var Message: TWMNoParams);
begin
if FParentColor then begin
if Parent <> nil then
FFlatColor := TForm(Parent).Color;
end;
Invalidate;
end;
procedure TDefineComboBox.WndProc(var Message: TMessage);
begin
if (Message.Msg = WM_PARENTNOTIFY) then
case LoWord(Message.wParam) of
WM_CREATE:
if FDefListProc <> nil then
begin
SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FDefListProc));
FDefListProc := nil;
FChildHandle := Message.lParam;
end
else
if FChildHandle = 0 then
FChildHandle := Message.lParam
else
FListHandle := Message.lParam;
end
else
if (Message.Msg = WM_WINDOWPOSCHANGING) then
if Style in [csDropDown, csSimple] then
SetWindowPos( EditHandle, 0,
0, 0, ClientWidth - FButtonWidth - 2 * 2 - 4, Height - 2 * 2 - 2,
SWP_NOMOVE + SWP_NOZORDER + SWP_NOACTIVATE + SWP_NOREDRAW);
inherited;
if Message.Msg = WM_CTLCOLORLISTBOX then
begin
SetBkColor(Message.wParam, ColorToRGB(Color));
Message.Result := CreateSolidBrush(ColorToRGB(Color));
end;
end;
procedure TDefineComboBox.ListWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_WINDOWPOSCHANGING:
with TWMWindowPosMsg(Message).WindowPos^ do
begin
// size of the drop down list
if Style in [csDropDown, csDropDownList] then
cy := (GetFontHeight(Font)-2) * Min(DropDownCount, Items.Count) + 4
else
cy := (ItemHeight) * Min(DropDownCount, Items.Count) + 4;
if cy <= 4 then
cy := 10;
end;
else
with Message do
Result := CallWindowProc(FDefListProc, FListHandle, Msg, WParam, LParam);
end;
end;
procedure TDefineComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
begin
inherited;
if (ComboWnd = EditHandle) then
case Message.Msg of
WM_SETFOCUS, WM_KILLFOCUS:
SetSolidBorder;
end;
end;
procedure TDefineComboBox.WMSetFocus(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
begin
SetSolidBorder;
Color := FFocusedColor;
if not (Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
end;
procedure TDefineComboBox.WMKillFocus(var Message: TMessage);
begin
inherited;
if not (csDesigning in ComponentState) then
begin
SetSolidBorder;
Color := FFlatColor;
if not (Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
end;
procedure TDefineComboBox.CMEnabledChanged(var Msg: TMessage);
begin
inherited;
Invalidate;
if Assigned(FTicket) then FTicket.Enabled := Enabled;
end;
procedure TDefineComboBox.CNCommand(var Message: TWMCommand);
var
R: TRect;
begin
inherited;
if Message.NotifyCode in [1, 9, CBN_DROPDOWN, CBN_SELCHANGE] then
begin
if not (Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
if (Message.NotifyCode in [CBN_CLOSEUP]) then
begin
R := GetButtonRect;
Dec(R.Left, 2);
InvalidateRect(Handle, @R, FALSE);
end;
end;
procedure TDefineComboBox.WMKeyDown(var Message: TMessage);
var
S: String;
begin
S := Text;
inherited;
if not (Style in [csSimple, csDropDown]) and(Text <> S) then
InvalidateSelection;
end;
procedure TDefineComboBox.WMPaint(var Message: TWMPaint);
var
R: TRect;
DC: HDC;
PS: TPaintStruct;
begin
DC := BeginPaint(Handle, PS);
try
R := PS.rcPaint;
if R.Right > Width - FButtonWidth - 4 then
R.Right := Width - FButtonWidth - 4;
FillRect(DC, R, Brush.Handle);
if RectInRect(GetButtonRect, PS.rcPaint) then
PaintButton;
ExcludeClipRect(DC, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
PaintWindow(DC);
if(Style = csDropDown) and DroppedDown then
begin
R := ClientRect;
InflateRect(R, -2, -2);
R.Right := Width - FButtonWidth - 3;
Canvas.Brush.Color := clWindow;
Canvas.FrameRect(R);
end
else
if Style <> csDropDown then
InvalidateSelection;
finally
EndPaint(Handle, PS);
end;
RedrawBorders;
Message.Result := 0;
end;
procedure TDefineComboBox.WMNCPaint(var Message: TMessage);
begin
inherited;
RedrawBorders;
end;
procedure TDefineComboBox.CMFontChanged(var Message: TMessage);
begin
inherited;
ItemHeight := 13;
RecreateWnd;
end;
function TDefineComboBox.GetButtonRect: TRect;
begin
GetWindowRect(Handle, Result);
OffsetRect(Result, -Result.Left, -Result.Top);
Inc(Result.Left, ClientWidth - FButtonWidth);
OffsetRect(Result, -1, 0);
end;
procedure TDefineComboBox.PaintButton;
var
R: TRect;
x, y: Integer;
begin
R := GetButtonRect;
InflateRect(R, 1, 0);
Canvas.Brush.Color := FArrowBackgroundColor;
Canvas.FillRect(R);
Canvas.Brush.Color := FBorderColor;
Canvas.FrameRect(R);
x :=(R.Right - R.Left) div 2 - 6 + R.Left;
if DroppedDown then
y :=(R.Bottom - R.Top) div 2 - 1 + R.Top
else
y :=(R.Bottom - R.Top) div 2 - 1 + R.Top;
if Enabled then
begin
Canvas.Brush.Color := FArrowColor;
Canvas.Pen.Color := FArrowColor;
if DroppedDown then
Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
end
else
begin
Canvas.Brush.Color := clWhite;
Canvas.Pen.Color := clWhite;
Inc(x); Inc(y);
if DroppedDown then
Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
Dec(x); Dec(y);
Canvas.Brush.Color := clGray;
Canvas.Pen.Color := clGray;
if DroppedDown then
Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
end;
ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth, 0, ClientWidth, ClientHeight);
end;
procedure TDefineComboBox.PaintBorder;
var
DC: HDC;
R: TRect;
BtnFaceBrush, WindowBrush: HBRUSH;
begin
DC := GetWindowDC(Handle);
GetWindowRect(Handle, R);
OffsetRect(R, -R.Left, -R.Top);
Dec(R.Right, FButtonWidth + 1);
try
BtnFaceBrush := CreateSolidBrush(ColorToRGB(FBorderColor));
WindowBrush := CreateSolidBrush(ColorToRGB(Color));
if(not(csDesigning in ComponentState) and
(Focused or(FMouseInControl and not(Screen.ActiveControl is TDefineComboBox)))) then
Color := FFocusedColor
else
Color := FFlatColor;
FrameRect(DC, R, BtnFaceBrush);
InflateRect(R, -1, -1);
FrameRect(DC, R, WindowBrush);
InflateRect(R, -1, -1);
FrameRect(DC, R, WindowBrush);
finally
ReleaseDC(Handle, DC);
end;
DeleteObject(WindowBrush);
DeleteObject(BtnFaceBrush);
end;
function TDefineComboBox.GetSolidBorder: Boolean;
begin
Result :=((csDesigning in ComponentState) and Enabled) or
(not(csDesigning in ComponentState) and
(DroppedDown or(GetFocus = Handle) or(GetFocus = EditHandle)) );
end;
procedure TDefineComboBox.SetSolidBorder;
var
sb: Boolean;
begin
sb := GetSolidBorder;
if sb <> FSolidBorder then begin
FSolidBorder := sb;
RedrawBorders;
end;
end;
procedure TDefineComboBox.RedrawBorders;
begin
PaintBorder;
if Style <> csSimple then
PaintButton;
end;
procedure TDefineComboBox.CMBidimodechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
end;
procedure TDefineComboBox.CMVisiblechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.Visible := Visible;
end;
procedure TDefineComboBox.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if(AComponent = FTicket) and(Operation = opRemove) then
FTicket := nil;
end;
procedure TDefineComboBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetTicketPosition(FTicketPosition);
end;
procedure TDefineComboBox.SetTicketPosition(const Value: TTicketPosition);
begin
if FTicket = nil then exit;
FTicketPosition := Value;
SetTicketPoint(Value,Self,Ticket,FTicketSpace);
end;
procedure TDefineComboBox.SetTicketSpace(const Value: Integer);
begin
if assigned(FTicket) then FTicketSpace := Value;
SetTicketPosition(FTicketPosition);
end;
procedure TDefineComboBox.SetName(const Value: TComponentName);
begin
if assigned(FTicket) then begin
if(csDesigning in ComponentState) and((FTicket.GetTextLen = 0) or
(CompareText(FTicket.Caption, Name) = 0)) then
FTicket.Caption := Value;
end;
inherited SetName(Value);
if csDesigning in ComponentState then
Text := '';
end;
procedure TDefineComboBox.SetParent(AParent: TWinControl);
begin
inherited SetParent(AParent);
if FTicket = nil then exit;
FTicket.Parent := AParent;
FTicket.Visible := True;
end;
procedure TDefineComboBox.SetParentColor(const Value: Boolean);
begin
if Value <> FParentColor then begin
FParentColor := Value;
if FParentColor then begin
if Parent <> nil then
FFlatColor := TForm(Parent).Color;
RedrawBorders;
end;
end;
end;
procedure TDefineComboBox.CMMouseEnter(var Message: TMessage);
begin
inherited;
if(GetActiveWindow <> 0) then
begin
FMouseInControl := True;
RedrawBorders;
end;
end;
procedure TDefineComboBox.CMMouseLeave(var Message: TMessage);
begin
inherited;
FMouseInControl := False;
RedrawBorders;
end;
procedure TDefineComboBox.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if(Key in [#32..#255]) and(FReadOnly) then begin
MessageBeep(0);
Key := #0;
end;
end;
{ TDefineColorBox }
procedure TDefineColorBox.SetupInternalLabel;
begin
if DefaultHasTicket then begin
if Assigned(FTicket) then exit;
FTicket := TFlatTicket.Create(Self);
FTicket.FreeNotification(Self);
FTicket.Transparent := True;
FTicket.FocusControl := Self;
end;
end;
constructor TDefineColorBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle - [csFixedHeight] + [csOpaque];
TControlCanvas(Canvas).Control := Self;
FColorDlg := TColorDialog.Create(Self);
Style := csOwnerDrawFixed;
SetBounds(0,0,120,20);
FButtonWidth := 16;
FSysBtnWidth := GetSystemMetrics(SM_CXVSCROLL);
FListInstance := MakeObjectInstance(ListWndProc);
FDefListProc := nil;
FArrowColor := clBlack;
FArrowBackgroundColor := $00C5D6D9;
FBorderColor := DefaultBorderColor;
FHighlightColor := clHighlight;
FShowNames := True;
FColorBoxWidth := 30;
FValue := clBlack;
FTicketPosition := poLeft;
FTicketSpace := 3;
fLanguage := lgChinese;
SetupInternalLabel;
end;
destructor TDefineColorBox.Destroy;
begin
FColorDlg.Free;
FreeObjectInstance(FListInstance);
inherited;
end;
procedure TDefineColorBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetTicketPosition(FTicketPosition);
end;
procedure TDefineColorBox.CMBidimodechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
end;
procedure TDefineColorBox.CMVisiblechanged(var Message: TMessage);
begin
inherited;
if Assigned(FTicket) then FTicket.Visible := Visible;
end;
procedure TDefineColorBox.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if(AComponent = FTicket) and(Operation = opRemove) then
FTicket := nil;
end;
procedure TDefineColorBox.SetName(const Value: TComponentName);
begin
if Assigned(FTicket) then begin
if(csDesigning in ComponentState) and((FTicket.GetTextLen = 0) or
(CompareText(FTicket.Caption, Name) = 0)) then begin
FTicket.Caption := Value;
case fLanguage of
lgChinese:FTicket.Caption := StdColorCN;
lgEnglish:FTicket.Caption := StdColorEN;
end;
end;
end;
inherited SetName(Value);
end;
procedure TDefineColorBox.SetParent(AParent: TWinControl);
begin
inherited SetParent(AParent);
if FTicket = nil then exit;
FTicket.Parent := AParent;
FTicket.Visible := True;
end;
procedure TDefineColorBox.SetLanguage(const Value: TLanguage);
var Item:Integer;
begin
if(fLanguage <> Value)and(Items.Count>=StdColorCount) then begin
fLanguage := Value;
for Item := Low(StdColors) to High(StdColors) do begin
case Value of
lgChinese : Items[Item] := StdColors[Item].cnName;
lgEnglish : Items[Item] := StdColors[Item].enName;
end;
end;
if Assigned(FTicket) then begin
case fLanguage of
lgChinese : FTicket.Caption := StdColorCN;
lgEnglish : FTicket.Caption := StdColorEN;
end;
end;
for Item := 0 to Pred(Items.Count) do
begin
if TColor(Items.Objects[Item]) = FValue then
begin
ItemIndex := Item;
Change;
Break;
end;
end;
end;
end;
procedure TDefineColorBox.SetTicketSpace(const Value: Integer);
begin
FTicketSpace := Value;
SetTicketPosition(FTicketPosition);
end;
procedure TDefineColorBox.SetTicketPosition(const Value: TTicketPosition);
begin
if FTicket = nil then exit;
FTicketPosition := Value;
SetTicketPoint(Value,Self,Ticket,FTicketSpace);;
end;
procedure TDefineColorBox.CreateWnd;
var
I: Integer;
ColorName: string;
begin
inherited CreateWnd;
Clear;
for I := Low(StdColors) to High(StdColors) do begin
case fLanguage of
lgChinese : ColorName := StdColors[I].cnName;
lgEnglish : ColorName := StdColors[I].enName;
end;
Items.AddObject(ColorName, TObject(StdColors[I].Value));
end;
ItemIndex := 0;
Change;
end;
procedure TDefineColorBox.SetColors(Index: Integer; Value: TColor);
begin
case Index of
0: FArrowColor := Value;
1: FArrowBackgroundColor := Value;
2: FBorderColor := Value;
3: FHighlightColor := Value;
end;
Invalidate;
end;
procedure TDefineColorBox.WndProc(var Message: TMessage);
begin
if(Message.Msg = WM_PARENTNOTIFY) then
case LoWord(Message.wParam) of
WM_CREATE:
if FDefListProc <> nil then
begin
SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FDefListProc));
FDefListProc := nil;
FChildHandle := Message.lParam;
end
else
if FChildHandle = 0 then
FChildHandle := Message.lParam
else
FListHandle := Message.lParam;
end
else
if(Message.Msg = WM_WINDOWPOSCHANGING) then
if Style in [csDropDown, csSimple] then
SetWindowPos( EditHandle, 0,
0, 0, ClientWidth - FButtonWidth - 2 * 2 - 4, Height - 2 * 2 - 2,
SWP_NOMOVE + SWP_NOZORDER + SWP_NOACTIVATE + SWP_NOREDRAW);
inherited;
if Message.Msg = WM_CTLCOLORLISTBOX then
begin
SetBkColor(Message.wParam, ColorToRGB(Color));
Message.Result := CreateSolidBrush(ColorToRGB(Color));
end;
end;
procedure TDefineColorBox.ListWndProc(var Message: TMessage);
begin
case Message.Msg of
WM_WINDOWPOSCHANGING:
with TWMWindowPosMsg(Message).WindowPos^ do
begin
// size of the drop down list
if Style in [csDropDown, csDropDownList] then
cy :=(GetFontHeight(Font)-2) * Min(DropDownCount, Items.Count) + 4
else
cy :=(ItemHeight) * Min(DropDownCount, Items.Count) + 4;
if cy <= 4 then
cy := 12;
end;
else
with Message do
Result := CallWindowProc(FDefListProc, FListHandle, Msg, WParam, LParam);
end;
end;
procedure TDefineColorBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
begin
inherited;
if(ComboWnd = EditHandle) then
case Message.Msg of
WM_SETFOCUS, WM_KILLFOCUS:
SetSolidBorder;
end;
end;
procedure TDefineColorBox.WMSetFocus(var Message: TMessage);
begin
inherited;
if not(csDesigning in ComponentState) then
begin
SetSolidBorder;
if not(Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
end;
procedure TDefineColorBox.WMKillFocus(var Message: TMessage);
begin
inherited;
if not(csDesigning in ComponentState) then
begin
SetSolidBorder;
if not(Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
end;
procedure TDefineColorBox.CMEnabledChanged(var Msg: TMessage);
begin
inherited;
FTicket.Enabled := Enabled;
Invalidate;
end;
procedure TDefineColorBox.CNCommand(var Message: TWMCommand);
var
R: TRect;
begin
inherited;
if Message.NotifyCode in [1, 9, CBN_DROPDOWN, CBN_SELCHANGE] then
begin
if not(Style in [csSimple, csDropDown]) then
InvalidateSelection;
end;
if(Message.NotifyCode in [CBN_CLOSEUP]) then
begin
R := GetButtonRect;
Dec(R.Left, 2);
InvalidateRect(Handle, @R, FALSE);
end;
end;
procedure TDefineColorBox.WMKeyDown(var Message: TMessage);
var
S: String;
begin
S := Text;
inherited;
if not(Style in [csSimple, csDropDown]) and(Text <> S) then
InvalidateSelection;
end;
procedure TDefineColorBox.WMPaint(var Message: TWMPaint);
var
R: TRect;
DC: HDC;
PS: TPaintStruct;
begin
DC := BeginPaint(Handle, PS);
try
R := PS.rcPaint;
if R.Right > Width - FButtonWidth - 4 then
R.Right := Width - FButtonWidth - 4;
FillRect(DC, R, Brush.Handle);
if RectInRect(GetButtonRect, PS.rcPaint) then
PaintButton;
ExcludeClipRect(DC, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
PaintWindow(DC);
if(Style = csDropDown) and DroppedDown then
begin
R := ClientRect;
InflateRect(R, -2, -2);
R.Right := Width - FButtonWidth - 3;
Canvas.Brush.Color := clWindow;
Canvas.FrameRect(R);
end
else
if Style <> csDropDown then
InvalidateSelection;
finally
EndPaint(Handle, PS);
end;
RedrawBorders;
Message.Result := 0;
end;
procedure TDefineColorBox.WMNCPaint(var Message: TMessage);
begin
inherited;
RedrawBorders;
end;
procedure TDefineColorBox.CMFontChanged(var Message: TMessage);
begin
inherited;
ItemHeight := 13;
RecreateWnd;
end;
procedure TDefineColorBox.InvalidateSelection;
var
R: TRect;
begin
R := ClientRect;
InflateRect(R, -2, -3);
R.Left := R.Right - FButtonWidth - 8;
Dec(R.Right, FButtonWidth + 3);
if(GetFocus = Handle) and not DroppedDown then
Canvas.Brush.Color := FHighLightcolor
else
Canvas.Brush.Color := Color;
Canvas.Brush.Style := bsSolid;
Canvas.FillRect(R);
if(GetFocus = Handle) and not DroppedDown then
begin
R := ClientRect;
InflateRect(R, -3, -3);
Dec(R.Right, FButtonWidth + 2);
Canvas.FrameRect(R);
Canvas.Brush.Color := clWindow;
end;
ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
end;
function TDefineColorBox.GetButtonRect: TRect;
begin
GetWindowRect(Handle, Result);
OffsetRect(Result, -Result.Left, -Result.Top);
Inc(Result.Left, ClientWidth - FButtonWidth);
OffsetRect(Result, -1, 0);
end;
procedure TDefineColorBox.PaintButton;
var
R: TRect;
x, y: Integer;
begin
R := GetButtonRect;
InflateRect(R, 1, 0);
Canvas.Brush.Color := FArrowBackgroundColor;
Canvas.FillRect(R);
Canvas.Brush.Color := FBorderColor;
Canvas.FrameRect(R);
x :=(R.Right - R.Left) div 2 - 6 + R.Left;
if DroppedDown then
y :=(R.Bottom - R.Top) div 2 - 1 + R.Top
else
y :=(R.Bottom - R.Top) div 2 - 1 + R.Top;
if Enabled then begin
canvas.Brush.Color := FArrowColor;
canvas.Pen.Color := FArrowColor;
if DroppedDown then
canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
end else begin
canvas.Brush.Color := clWhite;
canvas.Pen.Color := clWhite;
Inc(x); Inc(y);
if DroppedDown then
canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
Dec(x); Dec(y);
canvas.Brush.Color := clGray;
canvas.Pen.Color := clGray;
if DroppedDown then
canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
else
canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
end;
ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth, 0, ClientWidth, ClientHeight);
end;
procedure TDefineColorBox.PaintBorder;
var
DC: HDC;
R: TRect;
BtnFaceBrush, WindowBrush: HBRUSH;
begin
DC := GetWindowDC(Handle);
GetWindowRect(Handle, R);
OffsetRect(R, -R.Left, -R.Top);
Dec(R.Right, FButtonWidth + 1);
try
BtnFaceBrush := CreateSolidBrush(ColorToRGB(FBorderColor));
WindowBrush := CreateSolidBrush(ColorToRGB(Color));
FrameRect(DC, R, BtnFaceBrush);
InflateRect(R, -1, -1);
FrameRect(DC, R, WindowBrush);
InflateRect(R, -1, -1);
FrameRect(DC, R, WindowBrush);
finally
ReleaseDC(Handle, DC);
end;
DeleteObject(WindowBrush);
DeleteObject(BtnFaceBrush);
end;
function TDefineColorBox.GetSolidBorder: Boolean;
begin
Result :=((csDesigning in ComponentState) and Enabled) or
(not(csDesigning in ComponentState) and
(DroppedDown or(GetFocus = Handle) or(GetFocus = EditHandle)) );
end;
procedure TDefineColorBox.SetSolidBorder;
var
sb: Boolean;
begin
sb := GetSolidBorder;
if sb <> FSolidBorder then
begin
FSolidBorder := sb;
RedrawBorders;
end;
end;
procedure TDefineColorBox.RedrawBorders;
begin
PaintBorder;
if Style <> csSimple then PaintButton;
end;
procedure TDefineColorBox.SetShowNames(Value: Boolean);
begin
if Value <> FShowNames then
begin
FShowNames := Value;
Invalidate;
end;
end;
procedure TDefineColorBox.SetColorValue(Value: TColor);
var
Item: Integer;
CurrentColor: TColor;
begin
if(ItemIndex < 0) or(Value <> FValue) then
begin
for Item := 0 to Pred(Items.Count) do
begin
CurrentColor := TColor(Items.Objects[Item]);
if CurrentColor = Value then
begin
FValue := Value;
if ItemIndex <> Item then ItemIndex := Item;
Change;
Break;
end;
end;
end;
end;
procedure TDefineColorBox.SetColorBoxWidth(Value: Integer);
begin
if Value <> FColorBoxWidth then
begin
FColorBoxWidth := Value;
end;
Invalidate;
end;
procedure TDefineColorBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
var
ARect: TRect;
Text: array[0..255] of Char;
Safer: TColor;
begin
ARect := Rect;
with ARect do begin
Inc(Top, 1);
Inc(Left, 1);
Dec(Right, 1);
Dec(Bottom, 1);
if FShowNames then begin
Right := Left + FColorBoxWidth;
end else begin
Dec(Right, 5);
end;
end;
with Canvas do begin
Safer := Brush.Color;
if(odSelected in State) then begin
Brush.Color := FHighlightColor;
end else begin
Brush.Color := Color;
end;
FillRect(Rect);
Pen.Color := clBlack;
Rectangle(ARect);
Brush.Color := ColorToRgb(TColor(Items.Objects[Index]));
try
InflateRect(ARect, -1, -1);
FillRect(ARect)
finally
Brush.Color := Safer;
end;
if FShowNames then begin
StrPCopy(Text, Items[Index]);
Rect.Left := ARect.Right + 5;
Brush.Style := bsClear;
DrawText(Canvas.Handle, Text, StrLen(Text), Rect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
Brush.Style := bsSolid;
end;
end;
end;
procedure TDefineColorBox.Click;
begin
if ItemIndex >= 0 then
begin
if(Items[ItemIndex] = StdCustomCN)or(Items[ItemIndex] = StdCustomEN) then
begin
if not FColorDlg.Execute then
Exit;
Items.Objects[ItemIndex] := TObject(FColorDlg.Color);
end;
Value := TColor(Items.Objects[ItemIndex]);
end;
inherited Click;
end;
function TDefineColorBox.AddColor(ColorName: String; Color: TColor): Boolean;
var
I: Integer;
begin
for I := 0 to Items.Count - 1 do begin
if UpperCase(ColorName) = UpperCase(Items[I]) then begin
Result := False;
Exit;
end;
end;
Items.InsertObject(Items.Count - 1, ColorName, TObject(Color));
Result := True;
end;
function TDefineColorBox.DeleteColorByName(ColorName: String): Boolean;
var
I: Integer;
begin
for I := 0 to Items.Count - 1 do begin
if UpperCase(ColorName) = UpperCase(Items[I]) then begin
Items.Delete(I);
Result := True;
Exit;
end;
end;
Result := False;
end;
function TDefineColorBox.DeleteColorByColor(Color: TColor): Boolean;
var
I: Integer;
begin
for I := 0 to Items.Count - 1 do begin
if Color = TColor(Items.Objects[I]) then begin
Items.Delete(I);
Result := True;
Exit;
end;
end;
Result := False;
end;
{ TDefineSplitter }
constructor TDefineSplitter.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque];
Align := alLeft;
Width := 5;
Cursor := crHSplit;
FMinSize := 30;
FStatus := ssOut;
ParentColor := true;
ColorFocused := $0053D2FF;
ColorBorder := $00555E66;
end;
procedure TDefineSplitter.AllocateLineDC;
begin
FLineDC := GetDCEx(Parent.Handle, 0, DCX_CACHE or DCX_CLIPSIBLINGS or DCX_LOCKWINDOWUPDATE);
end;
procedure TDefineSplitter.DrawLine;
var
P: TPoint;
begin
FLineVisible := not FLineVisible;
P := Point(Left, Top);
if Align in [alLeft, alRight] then
P.X := Left + FSplit
else
P.Y := Top + FSplit;
with P do
PatBlt(FLineDC, X, Y, Width, Height, PATINVERT);
end;
procedure TDefineSplitter.ReleaseLineDC;
begin
ReleaseDC(Parent.Handle, FLineDC);
end;
procedure TDefineSplitter.Paint;
var
memBitmap: TBitmap;
begin
memBitmap := TBitmap.Create; // create memory-bitmap to draw flicker-free
try
memBitmap.Height := ClientRect.Bottom;
memBitmap.Width := ClientRect.Right;
if FStatus = ssIn then
begin
memBitmap.Canvas.Brush.Color := FFocusedColor;
memBitmap.Canvas.FillRect(ClientRect);
DrawButtonBorder(memBitmap.Canvas, ClientRect, FBorderColor, 1);
end;
if FStatus = ssOut then
begin
memBitmap.Canvas.Brush.Color := Color;
memBitmap.Canvas.FillRect(ClientRect);
DrawButtonBorder(memBitmap.Canvas, ClientRect, FBorderColor, 1);
end;
canvas.CopyRect(ClientRect, memBitmap.canvas, ClientRect); // Copy bitmap to screen
finally
memBitmap.free; // delete the bitmap
end;
end;
procedure TDefineSplitter.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
function FindControl: TControl;
var
P: TPoint;
I: Integer;
begin
Result := nil;
P := Point(Left, Top);
case Align of
alLeft: Dec(P.X);
alRight: Inc(P.X, Width);
alTop: Dec(P.Y);
alBottom: Inc(P.Y, Height);
else
Exit;
end;
for I := 0 to Parent.ControlCount - 1 do
begin
Result := Parent.Controls[I];
if PtInRect(Result.BoundsRect, P) then
Exit;
end;
Result := nil;
end;
var
I: Integer;
begin
inherited;
if Button = mbLeft then
begin
FControl := FindControl;
FDownPos := Point(X, Y);
if Assigned(FControl) then
begin
if Align in [alLeft, alRight] then
begin
FMaxSize := Parent.ClientWidth - FMinSize;
for I := 0 to Parent.ControlCount - 1 do
with Parent.Controls[I] do
if Align in [alLeft, alRight] then
Dec(FMaxSize, Width);
Inc(FMaxSize, FControl.Width);
end
else
begin
FMaxSize := Parent.ClientHeight - FMinSize;
for I := 0 to Parent.ControlCount - 1 do
with Parent.Controls[I] do
if Align in [alTop, alBottom] then Dec(FMaxSize, Height);
Inc(FMaxSize, FControl.Height);
end;
UpdateSize(X, Y);
AllocateLineDC;
with ValidParentForm(Self) do
if ActiveControl <> nil then
begin
FActiveControl := ActiveControl;
FOldKeyDown := TDefineHack(FActiveControl).OnKeyDown;
TDefineHack(FActiveControl).OnKeyDown := FocusKeyDown;
end;
DrawLine;
end;
end;
end;
procedure TDefineSplitter.UpdateSize(X, Y: Integer);
var
S: Integer;
begin
if Align in [alLeft, alRight] then
FSplit := X - FDownPos.X
else
FSplit := Y - FDownPos.Y;
S := 0;
case Align of
alLeft: S := FControl.Width + FSplit;
alRight: S := FControl.Width - FSplit;
alTop: S := FControl.Height + FSplit;
alBottom: S := FControl.Height - FSplit;
end;
FNewSize := S;
if S < FMinSize then
FNewSize := FMinSize
else
if S > FMaxSize then
FNewSize := FMaxSize;
if S <> FNewSize then
begin
if Align in [alRight, alBottom] then
S := S - FNewSize
else
S := FNewSize - S;
Inc(FSplit, S);
end;
end;
procedure TDefineSplitter.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
if Assigned(FControl) then
begin
DrawLine;
UpdateSize(X, Y);
DrawLine;
end;
end;
procedure TDefineSplitter.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
inherited;
if Assigned(FControl) then
begin
DrawLine;
case Align of
alLeft: FControl.Width := FNewSize;
alTop: FControl.Height := FNewSize;
alRight:
begin
Parent.DisableAlign;
try
FControl.Left := FControl.Left + (FControl.Width - FNewSize);
FControl.Width := FNewSize;
finally
Parent.EnableAlign;
end;
end;
alBottom:
begin
Parent.DisableAlign;
try
FControl.Top := FControl.Top + (FControl.Height - FNewSize);
FControl.Height := FNewSize;
finally
Parent.EnableAlign;
end;
end;
end;
StopSizing;
end;
end;
procedure TDefineSplitter.FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_ESCAPE then
StopSizing
else
if Assigned(FOldKeyDown) then
FOldKeyDown(Sender, Key, Shift);
end;
procedure TDefineSplitter.StopSizing;
begin
if Assigned(FControl) then
begin
if FLineVisible then DrawLine;
FControl := nil;
ReleaseLineDC;
if Assigned(FActiveControl) then
begin
TDefineHack(FActiveControl).OnKeyDown := FOldKeyDown;
FActiveControl := nil;
end;
end;
if Assigned(FOnMoved) then
FOnMoved(Self);
end;
procedure TDefineSplitter.CMEnter(var Message: TMessage);
begin
if FStatus <> ssIn then
begin
FStatus := ssIn;
Invalidate;
end;
end;
procedure TDefineSplitter.CMExit(var Message: TMessage);
begin
if FStatus <> ssOut then
begin
FStatus := ssOut;
Invalidate;
end;
end;
procedure TDefineSplitter.SetColors (Index: Integer; Value: TColor);
begin
case Index of
0: FFocusedColor := Value;
1: FBorderColor := Value;
end;
Invalidate;
end;
procedure TDefineSplitter.CMSysColorChange (var Message: TMessage);
begin
inherited;
if (ParentColor) and (Parent <> nil) then
Color := TForm(Parent).Color;
Invalidate;
end;
procedure TDefineSplitter.CMParentColorChanged (var Message: TWMNoParams);
begin
inherited;
if (ParentColor) and (Parent <> nil) then
Color := TForm(Parent).Color;
Invalidate;
end;
{ TDefineMask }
constructor TDefineMask.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMaskState := [];
FMaskBlank := DefaultBlank;
end;
procedure TDefineMask.KeyDown(var Key: Word; Shift: TShiftState);
begin
if not FSettingCursor then inherited KeyDown(Key, Shift);
if IsMasked and (Key <> 0) and not (ssAlt in Shift) then
begin
if (Key = VK_LEFT) or(Key = VK_RIGHT) then
begin
ArrowKeys(Key, Shift);
if not ((ssShift in Shift) or (ssCtrl in Shift)) then
Key := 0;
Exit;
end
else if (Key = VK_UP) or(Key = VK_DOWN) then
begin
Key := 0;
Exit;
end
else if (Key = VK_HOME) or(Key = VK_END) then
begin
HomeEndKeys(Key, Shift);
Key := 0;
Exit;
end
else if ((Key = VK_DELETE) and not (ssShift in Shift)) or
(Key = VK_BACK) then
begin
if EditCanModify then
DeleteKeys(Key);
Key := 0;
Exit;
end;
CheckCursor;
end;
end;
procedure TDefineMask.KeyUp(var Key: Word; Shift: TShiftState);
begin
if not FSettingCursor then inherited KeyUp(Key, Shift);
if IsMasked and (Key <> 0) then
begin
if ((Key = VK_LEFT) or(Key = VK_RIGHT)) and (ssCtrl in Shift) then
CheckCursor;
end;
end;
procedure TDefineMask.KeyPress(var Key: Char);
begin
inherited KeyPress(Key);
if IsMasked and (Key <> #0) and not (Char(Key) in [^V, ^X, ^C]) then
begin
CharKeys(Key);
Key := #0;
end;
end;
procedure TDefineMask.WMLButtonDown(var Message: TWMLButtonDown);
begin
inherited;
FBtnDownX := Message.XPos;
end;
procedure TDefineMask.WMLButtonUp(var Message: TWMLButtonUp);
var
SelStart, SelStop : Integer;
begin
inherited;
if (IsMasked) then
begin
GetSel(SelStart, SelStop);
FCaretPos := SelStart;
if (SelStart <> SelStop) and (Message.XPos > FBtnDownX) then
FCaretPos := SelStop;
CheckCursor;
end;
end;
procedure TDefineMask.WMSetFocus(var Message: TWMSetFocus);
begin
inherited;
if (IsMasked) then
CheckCursor;
end;
procedure TDefineMask.SetEditText(const Value: string);
begin
if GetEditText <> Value then
begin
SetTextBuf(PChar(Value));
CheckCursor;
end;
end;
function TDefineMask.GetEditText: string;
begin
Result := inherited Text;
end;
function TDefineMask.GetTextLen: Integer;
begin
Result := Length(Text);
end;
function TDefineMask.GetText: TMaskedText;
begin
if not IsMasked then
Result := inherited Text
else
begin
Result := RemoveEditFormat(EditText);
if FMaskSave then
Result := AddEditFormat(Result, False);
end;
end;
procedure TDefineMask.SetText(const Value: TMaskedText);
var
OldText: string;
Pos: Integer;
begin
if not IsMasked then
inherited Text := Value
else
begin
OldText := Value;
if FMaskSave then
OldText := PadInputLiterals(EditMask, OldText, FMaskBlank)
else
OldText := AddEditFormat(OldText, True);
if not (msDBSetText in FMaskState) and
(csDesigning in ComponentState) and
not (csLoading in ComponentState) and
not Validate(OldText, Pos) then
raise DefineError.Create(SMaskErr);
EditText := OldText;
end;
end;
procedure TDefineMask.WMCut(var Message: TMessage);
begin
if not (IsMasked) then
inherited
else
begin
CopyToClipboard;
DeleteKeys(VK_DELETE);
end;
end;
procedure TDefineMask.WMPaste(var Message: TMessage);
var
Value: string;
Str: string;
SelStart, SelStop : Integer;
begin
if not (IsMasked) or ReadOnly then
inherited
else
begin
Clipboard.Open;
Value := Clipboard.AsText;
Clipboard.Close;
GetSel(SelStart, SelStop);
Str := EditText;
DeleteSelection(Str, SelStart, SelStop - SelStart);
EditText := Str;
SelStart := InputString(Str, Value, SelStart);
EditText := Str;
SetCursor(SelStart);
end;
end;
function TDefineMask.GetMasked: Boolean;
begin
Result := EditMask <> '';
end;
function TDefineMask.GetMaxChars: Integer;
begin
if IsMasked then
Result := FMaxChars
else
Result := inherited GetTextLen;
end;
procedure TDefineMask.ReformatText(const NewMask: string);
var
OldText: string;
begin
OldText := RemoveEditFormat(EditText);
FEditMask := NewMask;
FMaxChars := MaskOffsetToOffset(EditMask, Length(NewMask));
FMaskSave := MaskGetMaskSave(NewMask);
FMaskBlank := MaskGetMaskBlank(NewMask);
OldText := AddEditFormat(OldText, True);
EditText := OldText;
end;
procedure TDefineMask.SetEditMask(const Value: TEditMask);
var
SelStart, SelStop: Integer;
begin
if Value <> EditMask then
begin
if (csDesigning in ComponentState) and (Value <> '') and
not (csLoading in ComponentState) then
EditText := '';
if HandleAllocated then GetSel(SelStart, SelStop);
ReformatText(Value);
Exclude(FMaskState, msMasked);
if EditMask <> '' then Include(FMaskState, msMasked);
inherited MaxLength := 0;
if IsMasked and (FMaxChars > 0) then
inherited MaxLength := FMaxChars;
if HandleAllocated and (GetFocus = Handle) and
not (csDesigning in ComponentState) then
SetCursor(SelStart);
end;
end;
function TDefineMask.GetMaxLength: Integer;
begin
Result := inherited MaxLength;
end;
procedure TDefineMask.SetMaxLength(Value: Integer);
begin
if not IsMasked then
inherited MaxLength := Value
else
inherited MaxLength := FMaxChars;
end;
procedure TDefineMask.GetSel(var SelStart: Integer; var SelStop: Integer);
begin
SendMessage(Handle, EM_GETSEL, Integer(@SelStart), Integer(@SelStop));
end;
procedure TDefineMask.SetSel(SelStart: Integer; SelStop: Integer);
begin
SendMessage(Handle, EM_SETSEL, SelStart, SelStop);
end;
procedure TDefineMask.SetCursor(Pos: Integer);
const
ArrowKey: array[Boolean] of Word = (VK_LEFT, VK_RIGHT);
var
SelStart, SelStop: Integer;
KeyState: TKeyboardState;
NewKeyState: TKeyboardState;
I: Integer;
begin
if (Pos >= 1) and (ByteType(EditText, Pos) = mbLeadByte) then Dec(Pos);
SelStart := Pos;
if (IsMasked) then
begin
if SelStart < 0 then
SelStart := 0;
SelStop := SelStart + 1;
if (Length(EditText) > SelStop) and (EditText[SelStop] in LeadBytes) then
Inc(SelStop);
if SelStart >= FMaxChars then
begin
SelStart := FMaxChars;
SelStop := SelStart;
end;
SetSel(SelStop, SelStop);
if SelStart <> SelStop then
begin
GetKeyboardState(KeyState);
for I := Low(NewKeyState) to High(NewKeyState) do
NewKeyState[I] := 0;
NewKeyState [VK_SHIFT] := $81;
NewKeyState [ArrowKey[UseRightToLeftAlignment]] := $81;
SetKeyboardState(NewKeyState);
FSettingCursor := True;
try
SendMessage(Handle, WM_KEYDOWN, ArrowKey[UseRightToLeftAlignment], 1);
SendMessage(Handle, WM_KEYUP, ArrowKey[UseRightToLeftAlignment], 1);
finally
FSettingCursor := False;
end;
SetKeyboardState(KeyState);
end;
FCaretPos := SelStart;
end
else
begin
if SelStart < 0 then
SelStart := 0;
if SelStart >= Length(EditText) then
SelStart := Length(EditText);
SetSel(SelStart, SelStart);
end;
end;
procedure TDefineMask.CheckCursor;
var
SelStart, SelStop: Integer;
begin
if not HandleAllocated then Exit;
if (IsMasked) then
begin
GetSel(SelStart, SelStop);
if SelStart = SelStop then
SetCursor(SelStart);
end;
end;
procedure TDefineMask.Clear;
begin
Text := '';
end;
function TDefineMask.EditCanModify: Boolean;
begin
Result := True;
end;
procedure TDefineMask.Reset;
begin
if Modified then
begin
EditText := FOldValue;
Modified := False;
end;
end;
function TDefineMask.CharKeys(var CharCode: Char): Boolean;
var
SelStart, SelStop : Integer;
Txt: string;
CharMsg: TMsg;
begin
Result := False;
if Word(CharCode) = VK_ESCAPE then
begin
Reset;
Exit;
end;
if not EditCanModify or ReadOnly then Exit;
if (Word(CharCode) = VK_BACK) then Exit;
if (Word(CharCode) = VK_RETURN) then
begin
ValidateEdit;
Exit;
end;
GetSel(SelStart, SelStop);
if (SelStop - SelStart) > 1 then
begin
DeleteKeys(VK_DELETE);
SelStart := GetNextEditChar(SelStart);
SetCursor(SelStart);
end;
if (CharCode in LeadBytes) then
if PeekMessage(CharMsg, Handle, WM_CHAR, WM_CHAR, PM_REMOVE) then
if CharMsg.Message = WM_Quit then
PostQuitMessage(CharMsg.wparam);
Result := InputChar(CharCode, SelStart);
if Result then
begin
if (CharCode in LeadBytes) then
begin
Txt := CharCode + Char(CharMsg.wParam);
SetSel(SelStart, SelStart + 2);
end
else
Txt := CharCode;
SendMessage(Handle, EM_REPLACESEL, 0, LongInt(PChar(Txt)));
GetSel(SelStart, SelStop);
CursorInc(SelStart, 0);
end;
end;
procedure TDefineMask.ArrowKeys(CharCode: Word; Shift: TShiftState);
var
SelStart, SelStop : Integer;
begin
if (ssCtrl in Shift) then Exit;
GetSel(SelStart, SelStop);
if (ssShift in Shift) then
begin
if (CharCode = VK_RIGHT) then
begin
Inc(FCaretPos);
if (SelStop = SelStart + 1) then
begin
SetSel(SelStart, SelStop); {reset caret to end of string}
Inc(FCaretPos);
end;
if FCaretPos > FMaxChars then FCaretPos := FMaxChars;
end
else {if (CharCode = VK_LEFT) then}
begin
Dec(FCaretPos);
if (SelStop = SelStart + 2) and
(FCaretPos > SelStart) then
begin
SetSel(SelStart + 1, SelStart + 1); {reset caret to show up at start}
Dec(FCaretPos);
end;
if FCaretPos < 0 then FCaretPos := 0;
end;
end
else
begin
if (SelStop - SelStart) > 1 then
begin
if ((SelStop - SelStart) = 2) and (EditText[SelStart+1] in LeadBytes) then
begin
if (CharCode = VK_LEFT) then
CursorDec(SelStart)
else
CursorInc(SelStart, 2);
Exit;
end;
if SelStop = FCaretPos then
Dec(FCaretPos);
SetCursor(FCaretPos);
end
else if (CharCode = VK_LEFT) then
CursorDec(SelStart)
else { if (CharCode = VK_RIGHT) then }
begin
if SelStop = SelStart then
SetCursor(SelStart)
else
if EditText[SelStart+1] in LeadBytes then
CursorInc(SelStart, 2)
else
CursorInc(SelStart, 1);
end;
end;
end;
procedure TDefineMask.CursorInc(CursorPos: Integer; Incr: Integer);
var
NuPos: Integer;
begin
NuPos := CursorPos + Incr;
NuPos := GetNextEditChar(NuPos);
if IsLiteralChar(EditMask, nuPos) then
NuPos := CursorPos;
SetCursor(NuPos);
end;
procedure TDefineMask.CursorDec(CursorPos: Integer);
var
nuPos: Integer;
begin
nuPos := CursorPos;
Dec(nuPos);
nuPos := GetPriorEditChar(nuPos);
SetCursor(NuPos);
end;
function TDefineMask.GetFirstEditChar: Integer;
begin
Result := 0;
if IsMasked then
Result := GetNextEditChar(0);
end;
function TDefineMask.GetLastEditChar: Integer;
begin
Result := GetMaxChars;
if IsMasked then
Result := GetPriorEditChar(Result - 1);
end;
function TDefineMask.GetNextEditChar(Offset: Integer): Integer;
begin
Result := Offset;
while(Result < FMaxChars) and (IsLiteralChar(EditMask, Result)) do
Inc(Result);
end;
function TDefineMask.GetPriorEditChar(Offset: Integer): Integer;
begin
Result := Offset;
while(Result >= 0) and (IsLiteralChar(EditMask, Result)) do
Dec(Result);
if Result < 0 then
Result := GetNextEditChar(Result);
end;
procedure TDefineMask.HomeEndKeys(CharCode: Word; Shift: TShiftState);
var
SelStart, SelStop : Integer;
begin
GetSel(SelStart, SelStop);
if (CharCode = VK_HOME) then
begin
if (ssShift in Shift) then
begin
if (SelStart <> FCaretPos) and (SelStop <> (SelStart + 1)) then
SelStop := SelStart + 1;
SetSel(0, SelStop);
CheckCursor;
end
else
SetCursor(0);
FCaretPos := 0;
end
else
begin
if (ssShift in Shift) then
begin
if (SelStop <> FCaretPos) and (SelStop <> (SelStart + 1)) then
SelStart := SelStop - 1;
SetSel(SelStart, FMaxChars);
CheckCursor;
end
else
SetCursor(FMaxChars);
FCaretPos := FMaxChars;
end;
end;
procedure TDefineMask.DeleteKeys(CharCode: Word);
var
SelStart, SelStop : Integer;
NuSelStart: Integer;
Str: string;
begin
if ReadOnly then Exit;
GetSel(SelStart, SelStop);
if ((SelStop - SelStart) <= 1) and (CharCode = VK_BACK) then
begin
NuSelStart := SelStart;
CursorDec(SelStart);
GetSel(SelStart, SelStop);
if SelStart = NuSelStart then Exit;
end;
if (SelStop - SelStart) < 1 then Exit;
Str := EditText;
DeleteSelection(Str, SelStart, SelStop - SelStart);
Str := Copy(Str, SelStart+1, SelStop - SelStart);
SendMessage(Handle, EM_REPLACESEL, 0, LongInt(PChar(Str)));
if (SelStop - SelStart) <> 1 then
begin
SelStart := GetNextEditChar(SelStart);
SetCursor(SelStart);
end
else begin
GetSel(SelStart, SelStop);
SetCursor(SelStart - 1);
end;
end;
procedure TDefineMask.CMEnter(var Message: TCMEnter);
begin
if IsMasked and not (csDesigning in ComponentState) then
begin
if not (msReEnter in FMaskState) then
begin
FOldValue := EditText;
inherited;
end;
Exclude(FMaskState, msReEnter);
CheckCursor;
end
else
inherited;
end;
procedure TDefineMask.CMTextChanged(var Message: TMessage);
var
SelStart, SelStop : Integer;
Temp: Integer;
begin
inherited;
FOldValue := EditText;
if HandleAllocated then
begin
GetSel(SelStart, SelStop);
Temp := GetNextEditChar(SelStart);
if Temp <> SelStart then
SetCursor(Temp);
end;
end;
procedure TDefineMask.CMWantSpecialKey(var Message: TCMWantSpecialKey);
begin
inherited;
if (Message.CharCode = VK_ESCAPE) and IsMasked and Modified then
Message.Result := 1;
end;
procedure TDefineMask.CMExit(var Message: TCMExit);
begin
if IsMasked and not (csDesigning in ComponentState) then
begin
ValidateEdit;
CheckCursor;
end;
inherited;
end;
procedure TDefineMask.ValidateEdit;
var
Str: string;
Pos: Integer;
begin
Str := EditText;
if IsMasked and Modified then
begin
if not Validate(Str, Pos) then
begin
if not (csDesigning in ComponentState) then
begin
Include(FMaskState, msReEnter);
SetFocus;
end;
SetCursor(Pos);
ValidateError;
end;
end;
end;
procedure TDefineMask.ValidateError;
begin
MessageBeep(0);
raise DefineError.Create(SMaskEditErr);
end;
function TDefineMask.AddEditFormat(const Value: string; Active: Boolean): string;
begin
if not Active then
Result := MaskDoFormatText(EditMask, Value, ' ')
else
Result := MaskDoFormatText(EditMask, Value, FMaskBlank);
end;
function TDefineMask.RemoveEditFormat(const Value: string): string;
var
I: Integer;
OldLen: Integer;
Offset, MaskOffset: Integer;
CType: TMaskCharType;
Dir: TMaskDirectives;
begin
Offset := 1;
Result := Value;
for MaskOffset := 1 to Length(EditMask) do
begin
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral] then
Result := Copy(Result, 1, Offset - 1) +
Copy(Result, Offset + 1, Length(Result) - Offset);
if CType in [mcMask, mcMaskOpt] then Inc(Offset);
end;
Dir := MaskGetCurrentDirectives(EditMask, 1);
if mdReverseDir in Dir then
begin
Offset := 1;
for I := 1 to Length(Result) do
begin
if Result[I] = FMaskBlank then
Inc(Offset)
else
break;
end;
if Offset <> 1 then
Result := Copy(Result, Offset, Length(Result) - Offset + 1);
end
else begin
OldLen := Length(Result);
for I := 1 to OldLen do
begin
if Result[OldLen - I + 1] = FMaskBlank then
SetLength(Result, Length(Result) - 1)
else Break;
end;
end;
if FMaskBlank <> ' ' then
begin
OldLen := Length(Result);
for I := 1 to OldLen do
begin
if Result[I] = FMaskBlank then
Result[I] := ' ';
if I > OldLen then Break;
end;
end;
end;
function TDefineMask.InputChar(var NewChar: Char; Offset: Integer): Boolean;
var
MaskOffset: Integer;
CType: TMaskCharType;
InChar: Char;
begin
Result := True;
if EditMask <> '' then
begin
Result := False;
MaskOffset := OffsetToMaskOffset(EditMask, Offset);
if MaskOffset >= 0 then
begin
CType := MaskGetCharType(EditMask, MaskOffset);
InChar := NewChar;
Result := DoInputChar(NewChar, MaskOffset);
if not Result and (CType in [mcMask, mcMaskOpt]) then
begin
MaskOffset := FindLiteralChar (MaskOffset, InChar);
if MaskOffset > 0 then
begin
MaskOffset := MaskOffsetToOffset(EditMask, MaskOffset);
SetCursor (MaskOffset);
Exit;
end;
end;
end;
end;
if not Result then
MessageBeep(0)
end;
function TDefineMask.DoInputChar(var NewChar: Char; MaskOffset: Integer): Boolean;
var
Dir: TMaskDirectives;
Str: string;
CType: TMaskCharType;
function IsKatakana(const Chr: Byte): Boolean;
begin
Result := (SysLocale.PriLangID = LANG_JAPANESE) and (Chr in [$A1..$DF]);
end;
function TestChar(NewChar: Char): Boolean;
var
Offset: Integer;
begin
Offset := MaskOffsetToOffset(EditMask, MaskOffset);
Result := not ((MaskOffset < Length(EditMask)) and
(UpCase(EditMask[MaskOffset]) = UpCase(EditMask[MaskOffset+1]))) or
(ByteType(EditText, Offset) = mbTrailByte) or
(ByteType(EditText, Offset+1) = mbLeadByte);
end;
begin
Result := True;
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral] then
NewChar := MaskIntlLiteralToChar(EditMask[MaskOffset])
else
begin
Dir := MaskGetCurrentDirectives(EditMask, MaskOffset);
case EditMask[MaskOffset] of
mMskNumeric, mMskNumericOpt:
begin
if not ((NewChar >= '0') and (NewChar <= '9')) then
Result := False;
end;
mMskNumSymOpt:
begin
if not (((NewChar >= '0') and (NewChar <= '9')) or
(NewChar = ' ') or(NewChar = '+') or(NewChar = '-')) then
Result := False;
end;
mMskAscii, mMskAsciiOpt:
begin
if (NewChar in LeadBytes) and TestChar(NewChar) then
begin
Result := False;
Exit;
end;
if IsCharAlpha(NewChar) then
begin
Str := ' ';
Str[1] := NewChar;
if (mdUpperCase in Dir) then
Str := AnsiUpperCase(Str)
else if mdLowerCase in Dir then
Str := AnsiLowerCase(Str);
NewChar := Str[1];
end;
end;
mMskAlpha, mMskAlphaOpt, mMskAlphaNum, mMskAlphaNumOpt:
begin
if (NewChar in LeadBytes) then
begin
if TestChar(NewChar) then
Result := False;
Exit;
end;
Str := ' ';
Str[1] := NewChar;
if IsKatakana(Byte(NewChar)) then
begin
NewChar := Str[1];
Exit;
end;
if not IsCharAlpha(NewChar) then
begin
Result := False;
if ((EditMask[MaskOffset] = mMskAlphaNum) or
(EditMask[MaskOffset] = mMskAlphaNumOpt)) and
(IsCharAlphaNumeric(NewChar)) then
Result := True;
end
else if mdUpperCase in Dir then
Str := AnsiUpperCase(Str)
else if mdLowerCase in Dir then
Str := AnsiLowerCase(Str);
NewChar := Str[1];
end;
end;
end;
end;
function TDefineMask.Validate(const Value: string; var Pos: Integer): Boolean;
var
Offset, MaskOffset: Integer;
CType: TMaskCharType;
begin
Result := True;
Offset := 1;
for MaskOffset := 1 to Length(EditMask) do
begin
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral, mcMaskOpt] then
Inc(Offset)
else if (CType = mcMask) and (Value <> '') then
begin
if (Value [Offset] = FMaskBlank) or
((Value [Offset] = ' ') and (EditMask[MaskOffset] <> mMskAscii)) then
begin
Result := False;
Pos := Offset - 1;
Exit;
end;
Inc(Offset);
end;
end;
end;
function TDefineMask.DeleteSelection(var Value: string; Offset: Integer;
Len: Integer): Boolean;
var
EndDel: Integer;
StrOffset, MaskOffset, Temp: Integer;
CType: TMaskCharType;
begin
Result := True;
if Len = 0 then Exit;
StrOffset := Offset + 1;
EndDel := StrOffset + Len;
Temp := OffsetToMaskOffset(EditMask, Offset);
if Temp < 0 then Exit;
for MaskOffset := Temp to Length(EditMask) do
begin
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral] then
Inc(StrOffset)
else if CType in [mcMask, mcMaskOpt] then
begin
Value[StrOffset] := FMaskBlank;
Inc(StrOffset);
end;
if StrOffset >= EndDel then Break;
end;
end;
function TDefineMask.InputString(var Value: string; const NewValue: string;
Offset: Integer): Integer;
var
NewOffset, MaskOffset, Temp: Integer;
CType: TMaskCharType;
NewVal: string;
NewChar: Char;
begin
Result := Offset;
if NewValue = '' then Exit;
{ replace chars with new chars, except literals }
NewOffset := 1;
NewVal := NewValue;
Temp := OffsetToMaskOffset(EditMask, Offset);
if Temp < 0 then Exit;
MaskOffset := Temp;
While MaskOffset <= Length(EditMask) do
begin
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral, mcMask, mcMaskOpt] then
begin
NewChar := NewVal[NewOffset];
if not (DoInputChar(NewChar, MaskOffset)) then
begin
if (NewChar in LeadBytes) then
NewVal[NewOffset + 1] := FMaskBlank;
NewChar := FMaskBlank;
end;
{ if pasted text does not contain a literal in the right place,
insert one }
if not ((CType in [mcLiteral, mcIntlLiteral]) and
(NewChar <> NewVal[NewOffset])) then
begin
NewVal[NewOffset] := NewChar;
if (NewChar in LeadBytes) then
begin
Inc(NewOffset);
Inc(MaskOffset);
end;
end
else
NewVal := Copy(NewVal, 1, NewOffset-1) + NewChar +
Copy(NewVal, NewOffset, Length (NewVal));
Inc(NewOffset);
end;
if (NewOffset + Offset) > FMaxChars then Break;
if (NewOffset) > Length(NewVal) then Break;
Inc(MaskOffset);
end;
if (Offset + Length(NewVal)) < FMaxChars then
begin
if ByteType(Value, OffSet + Length(NewVal) + 1) = mbTrailByte then
begin
NewVal := NewVal + FMaskBlank;
Inc(NewOffset);
end;
Value := Copy(Value, 1, Offset) + NewVal +
Copy(Value, OffSet + Length(NewVal) + 1,
FMaxChars -(Offset + Length(NewVal)));
end
else
begin
Temp := Offset;
if (ByteType(NewVal, FMaxChars - Offset) = mbLeadByte) then
Inc(Temp);
Value := Copy(Value, 1, Offset) +
Copy(NewVal, 1, FMaxChars - Temp);
end;
Result := NewOffset + Offset - 1;
end;
function TDefineMask.FindLiteralChar(MaskOffset: Integer; InChar: Char): Integer;
var
CType: TMaskCharType;
LitChar: Char;
begin
Result := -1;
while MaskOffset < Length(EditMask) do
begin
Inc(MaskOffset);
CType := MaskGetCharType(EditMask, MaskOffset);
if CType in [mcLiteral, mcIntlLiteral] then
begin
LitChar := EditMask[MaskOffset];
if CType = mcIntlLiteral then
LitChar := MaskIntlLiteralToChar(LitChar);
if LitChar = InChar then
Result := MaskOffset;
Exit;
end;
end;
end;
{ TDefineAnimation }
constructor TDefineAnimation.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FAnimation := TBitmap.Create;
ControlStyle := ControlStyle + [csOpaque];
SetBounds(0, 0, 60, 60);
FTransColor := clFuchsia;
FBorderColor := DefaultBorderColor;
FBorder := false;
FTransparent := false;
FActive := False;
FLoop := True;
FInterval := 100; // 1 Second
FFrameWidth := 30;
FFrames := 1;
FFrame := 0;
end;
destructor TDefineAnimation.Destroy;
begin
FAnimation.Free;
inherited Destroy;
end;
procedure TDefineAnimation.Paint;
var
X, Y, Pos, W, H: Integer;
SrcRect, DestRect: TRect;
memGlyph: TBitmap;
begin
W := FAnimation.Width div FFrames;
H := FAnimation.Height div FFrames;
case FAnimationLayout of
alAcross:
begin
X := (Width - W) div 2;
Y := (Height - FAnimation.Height) div 2;
Pos := W * FFrame;
DestRect := Rect(X, Y, X + W, Y + FAnimation.Height);
SrcRect := Rect(Pos, 0, Pos + W, FAnimation.Height);
end;
alDown:
begin
X := (Width - FFrameWidth) div 2;
Y := (Height - H) div 2;
Pos := H * FFrame;
DestRect := Rect(X, Y, X + FFrameWidth, Y + H);
SrcRect := Rect(0, Pos, FFrameWidth, Pos + FFrameWidth);
end;
end;
memGlyph := TBitmap.Create;
try
memGlyph.Height := Height;
memGlyph.Width := Width;
with memGlyph.Canvas do
begin
Brush.Style := bsClear;
Brush.Color := Color;
FillRect(ClipRect);
if FTransparent then begin
DrawParentImage(self, memGlyph.Canvas);
Brush.Style := bsClear;
Brush.Color := FTransColor;
BrushCopy(DestRect, FAnimation, SrcRect, FTransColor);
end else begin
CopyRect(DestRect, FAnimation.Canvas, SrcRect);
end;
if (csDesigning in ComponentState) and (not FBorder) then
begin
Pen.Style := psDot;
Pen.Color := clBlack;
Brush.Style := bsClear;
Rectangle(ClipRect);
end else if FBorder then begin
DrawButtonBorder(memGlyph.Canvas, ClipRect, FBorderColor, 1);
end;
end;
Canvas.CopyRect(ClientRect, memGlyph.Canvas, ClientRect);
finally
memGlyph.Free;
end;
end;
procedure TDefineAnimation.SetAnimation(Value: TBitmap);
begin
if Value <> FAnimation then
begin
FAnimation.Assign(Value);
if not FAnimation.Empty then
begin
if FAnimation.Width > FAnimation.Height then
FAnimationLayout := alAcross
else
FAnimationLayout := alDown;
case FAnimationLayout of
alAcross:
if FAnimation.Width mod FAnimation.Height = 0 then
FFrames := FAnimation.Width div FAnimation.Height;
alDown:
if FAnimation.Height mod FAnimation.Width = 0 then
FFrames := FAnimation.Height div FAnimation.Width;
end;
FFrame := 1;
case FAnimationLayout of
alAcross:
FFrameWidth := FAnimation.Width div FFrames;
alDown:
FFrameWidth := FAnimation.Height div FFrames;
end;
FTransColor := FAnimation.Canvas.Pixels[0, FAnimation.Height - 1];
end;
Invalidate;
end;
end;
procedure TDefineAnimation.SetFrames(Value: Integer);
begin
if Value <> FFrames then
begin
FFrames := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetFrameWidth(Value: Integer);
begin
if Value <> FFrameWidth then
begin
FFrameWidth := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetFrame(Value: Integer);
var
Temp: Integer;
begin
if Value < 0 then
Temp := FFrames - 1
else
Temp := Value mod FFrames;
if Temp <> FFrame then
begin
FFrame := Temp;
if Assigned(FFrameChange) then
begin
FFrameChange(Self,FFrame);
end;
Invalidate;
end;
end;
procedure TDefineAnimation.SetActive(Value: Boolean);
begin
if Value <> FActive then
begin
FActive := Value;
if not Value then
begin
FTimer.Free;
FTimer := nil;
end
else
if FInterval > 0 then
begin
FTimer := TTimer.Create(Self);
FTimer.Interval := FInterval;
FTimer.OnTimer := DoTimer;
end;
end;
end;
procedure TDefineAnimation.SetTransparent(Value: Boolean);
begin
if Value <> FTransparent then
begin
FTransparent := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetLoop(Value: Boolean);
begin
if Value <> FLoop then
begin
FLoop := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetReverse(Value: Boolean);
begin
if Value <> FReverse then
begin
FReverse := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetInterval(Value: Integer);
begin
if Value <> FInterval then
begin
FInterval := Value;
if FActive then
FTimer.Interval := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetBorder(Value: Boolean);
begin
if Value <> FBorder then
begin
FBorder := Value;
Invalidate;
end;
end;
procedure TDefineAnimation.SetColors (Index: Integer; Value: TColor);
begin
case Index of
0: FTransColor := Value;
1: FBorderColor := Value;
end;
Invalidate;
end;
procedure TDefineAnimation.CMSysColorChange (var Message: TMessage);
begin
inherited;
if (ParentColor)and(Parent<>nil) then
begin
ParentColor := True;
Color := TForm(Parent).Color;
end;
Invalidate;
end;
procedure TDefineAnimation.CMParentColorChanged (var Message: TWMNoParams);
begin
inherited;
if (ParentColor)and(Parent<>nil) then
begin
ParentColor := True;
Color := TForm(Parent).Color;
end;
Invalidate;
end;
procedure TDefineAnimation.WMSize (var Message: TWMSize);
begin
inherited;
Invalidate;
end;
procedure TDefineAnimation.DoTimer(Sender: TObject);
procedure ChkStop;
begin
if not FLoop then
begin
FActive := False;
FTimer.Free;
FTimer := nil;
end;
end;
begin
if FReverse then
begin
Frame := Frame - 1;
if FFrame = 0 then ChkStop;
end
else
begin
Frame := Frame + 1;
if FFrame = Frames - 1 then ChkStop;
end;
end;
procedure TDefineAnimation.SetAnimationLayout(const Value: TAnimationLayout);
begin
FAnimationLayout := Value;
Invalidate;
end;
{ TFlatHint }
constructor TFlatHint.Create (AOwner: TComponent);
begin
inherited Create(AOwner);
FHintFont := TFont.Create;
if not (csDesigning in ComponentState) then
begin
HintWindowClass := TFlatHintWindow;
with Application do
begin
ShowHint := not ShowHint;
ShowHint := not ShowHint;
OnShowHint := GetHintInfo;
HintShortPause := 25;
HintPause := 500;
HintHidePause := 5000;
end;
end;
FBackgroundColor := clWhite;
FBorderColor := clBlack;
FArrowBackgroundColor := $0053D2FF;
FArrowColor := clBlack;
FHintWidth := 200;
end;
destructor TFlatHint.Destroy;
begin
FHintFont.Free;
inherited Destroy;
end;
procedure TFlatHint.SetColors (Index: Integer; Value: TColor);
begin
case Index of
0: FBackgroundColor := Value;
1: FBorderColor := Value;
2: FArrowBackgroundColor := Value;
3: FArrowColor := Value;
end;
end;
procedure TFlatHint.SetHintFont (Value: TFont);
begin
FHintFont.Assign(Value);
end;
procedure TFlatHint.GetHintInfo (var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
begin
if Assigned(FOnShowHint) then
FOnShowHint(HintStr, CanShow, HintInfo);
end;
{ TFlatHintWindow }
function TFlatHintWindow.FindFlatHint: TFlatHint;
var
curInx: Integer;
begin
Result := nil;
with Application.MainForm do
for curInx := 0 to ComponentCount - 1 do
if Components[curInx] is TFlatHint then
begin
Result := TFlatHint(Components[curInx]);
Break;
end;
end;
procedure TFlatHintWindow.CreateParams (var Params: TCreateParams);
begin
inherited CreateParams(Params);
Params.Style := Params.Style - WS_BORDER;
end;
procedure TFlatHintWindow.Paint;
var
ArrowRect, TextRect: TRect;
begin
// Set the Rect's
case FArrowPos of
NW, SW:
begin
ArrowRect := Rect(ClientRect.Left + 1, ClientRect.Top + 1, ClientRect.Left + 15, ClientRect.Bottom - 1);
TextRect := Rect(ClientRect.Left + 15, ClientRect.Top + 1, ClientRect.Right - 1, ClientRect.Bottom - 1);
end;
NE, SE:
begin
ArrowRect := Rect(ClientRect.Right - 15, ClientRect.Top + 1, ClientRect.Right - 1, ClientRect.Bottom - 1);
TextRect := Rect(ClientRect.Left + 1, ClientRect.Top + 1, ClientRect.Right - 15, ClientRect.Bottom - 1);
end;
end;
// DrawBackground
canvas.brush.color := FHint.FArrowBackgroundColor;
canvas.FillRect(ArrowRect);
canvas.brush.color := FHint.FBackgroundColor;
canvas.FillRect(TextRect);
// DrawBorder
canvas.Brush.Color := FHint.FBorderColor;
canvas.FrameRect(ClientRect);
// DrawArrow
case FArrowPos of
NW: FArrowPoint := Point(ArrowRect.Left + 2, ArrowRect.Top + 2);
NE: FArrowPoint := Point(ArrowRect.Right - 3, ArrowRect.Top + 2);
SW: FArrowPoint := Point(ArrowRect.Left + 2, ArrowRect.Bottom - 3);
SE: FArrowPoint := Point(ArrowRect.Right - 3, ArrowRect.Bottom - 3);
end;
canvas.Pen.Color := FHint.FArrowColor;
case FArrowPos of
NW: canvas.Polyline([Point(FArrowPoint.x, FArrowPoint.y), Point(FArrowPoint.x, FArrowPoint.y + 6),
Point(FArrowPoint.x + 1, FArrowPoint.y + 6), Point(FArrowPoint.x + 1, FArrowPoint.y),
Point(FArrowPoint.x + 6, FArrowPoint.y), Point(FArrowPoint.x + 6, FArrowPoint.y + 1),
Point(FArrowPoint.x + 2, FArrowPoint.y + 1), Point(FArrowPoint.x + 2, FArrowPoint.y + 4),
Point(FArrowPoint.x + 5, FArrowPoint.y + 7), Point(FArrowPoint.x + 6, FArrowPoint.y + 7),
Point(FArrowPoint.x + 3, FArrowPoint.y + 4), Point(FArrowPoint.x + 3, FArrowPoint.y + 3),
Point(FArrowPoint.x + 6, FArrowPoint.y + 6), Point(FArrowPoint.x + 7, FArrowPoint.y + 6),
Point(FArrowPoint.x + 3, FArrowPoint.y + 2), Point(FArrowPoint.x + 4, FArrowPoint.y + 2),
Point(FArrowPoint.x + 7, FArrowPoint.y + 5), Point(FArrowPoint.x + 7, FArrowPoint.y + 6)]);
NE: canvas.Polyline([Point(FArrowPoint.x, FArrowPoint.y), Point(FArrowPoint.x, FArrowPoint.y + 6),
Point(FArrowPoint.x - 1, FArrowPoint.y + 6), Point(FArrowPoint.x - 1, FArrowPoint.y),
Point(FArrowPoint.x - 6, FArrowPoint.y), Point(FArrowPoint.x - 6, FArrowPoint.y + 1),
Point(FArrowPoint.x - 2, FArrowPoint.y + 1), Point(FArrowPoint.x - 2, FArrowPoint.y + 4),
Point(FArrowPoint.x - 5, FArrowPoint.y + 7), Point(FArrowPoint.x - 6, FArrowPoint.y + 7),
Point(FArrowPoint.x - 3, FArrowPoint.y + 4), Point(FArrowPoint.x - 3, FArrowPoint.y + 3),
Point(FArrowPoint.x - 6, FArrowPoint.y + 6), Point(FArrowPoint.x - 7, FArrowPoint.y + 6),
Point(FArrowPoint.x - 3, FArrowPoint.y + 2), Point(FArrowPoint.x - 4, FArrowPoint.y + 2),
Point(FArrowPoint.x - 7, FArrowPoint.y + 5), Point(FArrowPoint.x - 7, FArrowPoint.y + 6)]);
SW: canvas.Polyline([Point(FArrowPoint.x, FArrowPoint.y), Point(FArrowPoint.x, FArrowPoint.y - 6),
Point(FArrowPoint.x + 1, FArrowPoint.y - 6), Point(FArrowPoint.x + 1, FArrowPoint.y),
Point(FArrowPoint.x + 6, FArrowPoint.y), Point(FArrowPoint.x + 6, FArrowPoint.y - 1),
Point(FArrowPoint.x + 2, FArrowPoint.y - 1), Point(FArrowPoint.x + 2, FArrowPoint.y - 4),
Point(FArrowPoint.x + 5, FArrowPoint.y - 7), Point(FArrowPoint.x + 6, FArrowPoint.y - 7),
Point(FArrowPoint.x + 3, FArrowPoint.y - 4), Point(FArrowPoint.x + 3, FArrowPoint.y - 3),
Point(FArrowPoint.x + 6, FArrowPoint.y - 6), Point(FArrowPoint.x + 7, FArrowPoint.y - 6),
Point(FArrowPoint.x + 3, FArrowPoint.y - 2), Point(FArrowPoint.x + 4, FArrowPoint.y - 2),
Point(FArrowPoint.x + 7, FArrowPoint.y - 5), Point(FArrowPoint.x + 7, FArrowPoint.y - 6)]);
SE: canvas.Polyline([Point(FArrowPoint.x, FArrowPoint.y), Point(FArrowPoint.x, FArrowPoint.y - 6),
Point(FArrowPoint.x - 1, FArrowPoint.y - 6), Point(FArrowPoint.x - 1, FArrowPoint.y),
Point(FArrowPoint.x - 6, FArrowPoint.y), Point(FArrowPoint.x - 6, FArrowPoint.y - 1),
Point(FArrowPoint.x - 2, FArrowPoint.y - 1), Point(FArrowPoint.x - 2, FArrowPoint.y - 4),
Point(FArrowPoint.x - 5, FArrowPoint.y - 7), Point(FArrowPoint.x - 6, FArrowPoint.y - 7),
Point(FArrowPoint.x - 3, FArrowPoint.y - 4), Point(FArrowPoint.x - 3, FArrowPoint.y - 3),
Point(FArrowPoint.x - 6, FArrowPoint.y - 6), Point(FArrowPoint.x - 7, FArrowPoint.y - 6),
Point(FArrowPoint.x - 3, FArrowPoint.y - 2), Point(FArrowPoint.x - 4, FArrowPoint.y - 2),
Point(FArrowPoint.x - 7, FArrowPoint.y - 5), Point(FArrowPoint.x - 7, FArrowPoint.y - 6)]);
end;
// DrawHintText
canvas.brush.Style := bsClear;
InflateRect(TextRect, -3, -1);
{$IFDEF DFS_COMPILER_4_UP}
if BidiMode = bdRightToLeft then
DrawText(canvas.handle, PChar(Caption), Length(Caption), TextRect, DT_RIGHT or DT_WORDBREAK or DT_NOPREFIX)
else
DrawText(canvas.handle, PChar(Caption), Length(Caption), TextRect, DT_WORDBREAK or DT_NOPREFIX);
{$ELSE}
DrawText(canvas.handle, PChar(Caption), Length(Caption), TextRect, DT_WORDBREAK or DT_NOPREFIX);
{$ENDIF}
end;
procedure TFlatHintWindow.ActivateHint (HintRect: TRect; const AHint: string);
var
curWidth: Byte;
Pnt: TPoint;
HintHeight, HintWidth: Integer;
NordWest, NordEast, SouthWest, SouthEast: TRect;
begin
Caption := AHint;
FHint := FindFlatHint;
if FHint <> nil then
Canvas.Font.Assign(FHint.Font);
// Calculate width and height
HintRect.Right := HintRect.Left + FHint.MaxWidth - 22;
{$IFDEF DFS_COMPILER_4_UP}
if BidiMode = bdRightToLeft then
DrawText(Canvas.Handle, @AHint[1], Length(AHint), HintRect, DT_RIGHT or DT_CALCRECT or DT_WORDBREAK or DT_NOPREFIX)
else
DrawText(Canvas.Handle, @AHint[1], Length(AHint), HintRect, DT_CALCRECT or DT_WORDBREAK or DT_NOPREFIX);
{$ELSE}
DrawText(Canvas.Handle, @AHint[1], Length(AHint), HintRect, DT_CALCRECT or DT_WORDBREAK or DT_NOPREFIX);
{$ENDIF}
DrawText(Canvas.Handle, @AHint[1], Length(AHint), HintRect, DT_CALCRECT or DT_WORDBREAK or DT_NOPREFIX);
Inc(HintRect.Right, 22);
Inc(HintRect.Bottom, 6);
// Divide the screen in 4 pices
NordWest := Rect(0, 0, Screen.Width div 2, Screen.Height div 2);
NordEast := Rect(Screen.Width div 2, 0, Screen.Width, Screen.Height div 2);
SouthWest := Rect(0, Screen.Height div 2, Screen.Width div 2, Screen.Height);
SouthEast := Rect(Screen.Width div 2, Screen.Height div 2, Screen.Width, Screen.Height);
GetCursorPos(Pnt);
if PtInRect(NordWest, Pnt) then
FArrowPos := NW
else
if PtInRect(NordEast, Pnt) then
FArrowPos := NE
else
if PtInRect(SouthWest, Pnt) then
FArrowPos := SW
else
FArrowPos := SE;
// Calculate the position of the hint
if FArrowPos = NW then
curWidth := 12
else
curWidth := 5;
HintHeight := HintRect.Bottom - HintRect.Top;
HintWidth := HintRect.Right - HintRect.Left;
case FArrowPos of
NW: HintRect := Rect(Pnt.x + curWidth, Pnt.y + curWidth, Pnt.x + HintWidth + curWidth, Pnt.y + HintHeight + curWidth);
NE: HintRect := Rect(Pnt.x - HintWidth - curWidth, Pnt.y + curWidth, Pnt.x - curWidth, Pnt.y + HintHeight + curWidth);
SW: HintRect := Rect(Pnt.x + curWidth, Pnt.y - HintHeight - curWidth, Pnt.x + HintWidth + curWidth, Pnt.y - curWidth);
SE: HintRect := Rect(Pnt.x - HintWidth - curWidth, Pnt.y - HintHeight - curWidth, Pnt.x - curWidth, Pnt.y - curWidth);
end;
BoundsRect := HintRect;
Pnt := ClientToScreen(Point(0, 0));
SetWindowPos(Handle, HWND_TOPMOST, Pnt.X, Pnt.Y, 0, 0, SWP_SHOWWINDOW or SWP_NOACTIVATE or SWP_NOSIZE);
end;
{ TDefineImage }
constructor TDefineImage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ControlStyle := ControlStyle + [csReplicatable];
FEnterImage := TBitmap.Create;
FLeaveImage := TBitmap.Create;
FMouseState := True;
FAutoImage := False;
FAutoCursor := crHandPoint;
FAutoShowCursor := false;
FBitmap := TBitmap.Create;
FBitmap.OnChange := PictureChanged;
FBitmap.OnProgress := Progress;
Height := 105;
Width := 105;
end;
destructor TDefineImage.Destroy;
begin
FEnterImage.Free;
FLeaveImage.Free;
FBitmap.Free;
inherited Destroy;
end;
function TDefineImage.GetPalette: HPALETTE;
begin
Result := 0;
if FBitmap <> nil then
Result := FBitmap.Palette;
end;
function TDefineImage.DestRect: TRect;
var
w, h, cw, ch: Integer;
xyaspect: Double;
begin
w := Bitmap.Width;
h := Bitmap.Height;
cw := ClientWidth;
ch := ClientHeight;
if Stretch or (Proportional and ((w > cw) or (h > ch))) then
begin
if Proportional and (w > 0) and (h > 0) then
begin
xyaspect := w / h;
if w > h then
begin
w := cw;
h := Trunc(cw / xyaspect);
if h > ch then // woops, too big
begin
h := ch;
w := Trunc(ch * xyaspect);
end;
end
else
begin
h := ch;
w := Trunc(ch * xyaspect);
if w > cw then // woops, too big
begin
w := cw;
h := Trunc(cw / xyaspect);
end;
end;
end
else
begin
w := cw;
h := ch;
end;
end;
with Result do
begin
Left := 0;
Top := 0;
Right := w;
Bottom := h;
end;
if Center then
OffsetRect(Result, (cw - w) div 2, (ch - h) div 2);
end;
procedure TDefineImage.Paint;
var
Save: Boolean;
begin
if csDesigning in ComponentState then
with inherited Canvas do
begin
Pen.Style := psDash;
Brush.Style := bsClear;
Rectangle(0, 0, Width, Height);
end;
Save := FDrawing;
FDrawing := True;
try
with inherited Canvas do
begin
StretchDraw(DestRect, Bitmap);
end;
finally
FDrawing := Save;
end;
end;
function TDefineImage.DoPaletteChange: Boolean;
var
ParentForm: TCustomForm;
Tmp: TGraphic;
begin
Result := False;
Tmp := Bitmap;
if Visible and (not (csLoading in ComponentState)) and (Tmp <> nil) and
(Tmp.PaletteModified) then
begin
if (Tmp.Palette = 0) then
Tmp.PaletteModified := False
else
begin
ParentForm := GetParentForm(Self);
if Assigned(ParentForm) and ParentForm.Active and Parentform.HandleAllocated then
begin
if FDrawing then
ParentForm.Perform(wm_QueryNewPalette, 0, 0)
else
PostMessage(ParentForm.Handle, wm_QueryNewPalette, 0, 0);
Result := True;
Tmp.PaletteModified := False;
end;
end;
end;
end;
procedure TDefineImage.Progress(Sender: TObject; Stage: TProgressStage;
PercentDone: Byte; RedrawNow: Boolean; const R: TRect; const Msg: string);
begin
if FIncrementalDisplay and RedrawNow then
begin
if DoPaletteChange then Update
else Paint;
end;
if Assigned(FOnProgress) then FOnProgress(Sender, Stage, PercentDone, RedrawNow, R, Msg);
end;
function TDefineImage.GetCanvas: TCanvas;
var
fBit: TBitmap;
begin
if Bitmap = nil then
begin
fBit := TBitmap.Create;
try
fBit.Width := Width;
fBit.Height := Height;
fBit := Bitmap;
finally
fBit.Free;
end;
end;
if Bitmap is TBitmap then
Result := TBitmap(Bitmap).Canvas
else
raise EInvalidOperation.Create(SImageCanvasNeedsBitmap);
end;
procedure TDefineImage.SetCenter(Value: Boolean);
begin
if FCenter <> Value then
begin
FCenter := Value;
PictureChanged(Self);
end;
end;
procedure TDefineImage.SetPicture(Value: TBitmap);
begin
FBitmap.Assign(Value);
end;
procedure TDefineImage.SetStretch(Value: Boolean);
begin
if Value <> FStretch then
begin
FStretch := Value;
PictureChanged(Self);
end;
end;
procedure TDefineImage.SetTransparent(Value: Boolean);
begin
if Value <> FTransparent then
begin
FTransparent := Value;
PictureChanged(Self);
end;
end;
procedure TDefineImage.SetProportional(Value: Boolean);
begin
if FProportional <> Value then
begin
FProportional := Value;
PictureChanged(Self);
end;
end;
procedure TDefineImage.PictureChanged(Sender: TObject);
var
G: TGraphic;
D : TRect;
begin
if AutoSize and (Bitmap.Width > 0) and (Bitmap.Height > 0) then
SetBounds(Left, Top, Bitmap.Width, Bitmap.Height);
G := Bitmap;
if G <> nil then
begin
if not ((G is TMetaFile) or (G is TIcon)) then
G.Transparent := FTransparent;
D := DestRect;
if (not G.Transparent) and (D.Left <= 0) and (D.Top <= 0) and
(D.Right >= Width) and (D.Bottom >= Height) then
ControlStyle := ControlStyle + [csOpaque]
else // picture might not cover entire clientrect
ControlStyle := ControlStyle - [csOpaque];
if DoPaletteChange and FDrawing then Update;
end
else ControlStyle := ControlStyle - [csOpaque];
if not FDrawing then Invalidate;
end;
function TDefineImage.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
begin
Result := True;
if not (csDesigning in ComponentState) or (Bitmap.Width > 0) and
(Bitmap.Height > 0) then
begin
if Align in [alNone, alLeft, alRight] then
NewWidth := Bitmap.Width;
if Align in [alNone, alTop, alBottom] then
NewHeight := Bitmap.Height;
end;
end;
procedure TDefineImage.MouseEnter(var Msg: TMessage);
begin
if not(csDesigning in ComponentState) then
begin
if FAutoImage and FMouseState Then
begin
Bitmap.Assign(FEnterImage);
FMouseState := False;
end;
If FAutoShowCursor Then
Cursor := FAutoCursor;
end;
end;
procedure TDefineImage.MouseLeave(var Msg: TMessage);
begin
if not(csDesigning in ComponentState) then
begin
if FAutoImage and not FMouseState Then
begin
Bitmap.Assign(FLeaveImage);
FMouseState := True;
end;
end;
end;
procedure TDefineImage.SetEnterImage(const Value: TBitmap);
begin
FEnterImage.Assign(Value);
end;
procedure TDefineImage.SetLeaveImage(const Value: TBitmap);
begin
FLeaveImage.Assign(Value);
end;
{ TDefineTimer }
constructor TDefineTimer.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEnabled := True;
FInterval := 50;
{$IFDEF MSWINDOWS}
FHandle := Classes.AllocateHWnd(WndProc);
{$ENDIF}
{$IFDEF LINUX}
FHandle := WinUtils.AllocateHWnd(WndProc);
{$ENDIF}
end;
destructor TDefineTimer.Destroy;
begin
FEnabled := False;
UpdateTimer;
{$IFDEF MSWINDOWS}
Classes.DeallocateHWnd(FHandle);
{$ENDIF}
{$IFDEF LINUX}
WinUtils.DeallocateHWnd(FHandle);
{$ENDIF}
inherited Destroy;
end;
procedure TDefineTimer.WndProc(var Msg: TMessage);
begin
with Msg do
if Msg = WM_TIMER then
try
Timer;
except
Application.HandleException(Self);
end
else
Result := DefWindowProc(FHandle, Msg, wParam, lParam);
end;
procedure TDefineTimer.UpdateTimer;
begin
KillTimer(FHandle, 1);
if (FInterval <> 0) and FEnabled and Assigned(FOnTimer) then
if SetTimer(FHandle, 1, FInterval, nil) = 0 then
raise EOutOfResources.Create(SNoTimers);
end;
procedure TDefineTimer.SetEnabled(Value: Boolean);
begin
if Value <> FEnabled then
begin
FEnabled := Value;
UpdateTimer;
end;
end;
procedure TDefineTimer.SetInterval(Value: Cardinal);
begin
if Value <> FInterval then
begin
FInterval := Value;
UpdateTimer;
end;
end;
procedure TDefineTimer.SetOnTimer(Value: TNotifyEvent);
begin
FOnTimer := Value;
UpdateTimer;
end;
procedure TDefineTimer.Timer;
begin
if Assigned(FOnTimer) then FOnTimer(Self);
end;
{ TDefineWater }
const
RAND_MAX = $7FFF;
constructor TDefineWater.Create(AOwner: TComponent);
begin
FBitmap := TBitmap.Create;
FWater := TDefineWatet.Create;
FItems := TStringList.Create;
inherited Create(AOwner);
FDamping := csDefDamping;
FPlayState := true;
OnTimer := Play;
end;
destructor TDefineWater.Destroy;
begin
FItems.Free;
FWater.Free;
FBitmap.Free;
inherited Destroy;
end;
procedure TDefineWater.OnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
FWater.Blob(x,y,1,5000);
end;
procedure TDefineWater.SetDamping(Value: TWaterDamping);
begin
if (Value >= Low(TWaterDamping)) and (Value <= High(TWaterDamping)) then
begin
FDamping := Value;
FWater.Damping := Value;
end;
end;
procedure TDefineWater.InitiateWater;
var inx:Integer;
TitleValue:String;
begin
FBitmap.Assign(FImage.Bitmap);
FImage.OnMouseMove := OnMouseMove;
with FImage do
begin
Bitmap.FreeImage;
Bitmap.Width := FBitmap.Width;
Bitmap.Height := FBitmap.Height;
end;
FWater.SetSize(FBitmap);
FState := FBitmap.Height;
FPlayState := false;
FMoveHeight := 10;
for inx := 0 to FItems.Count - 1 do
begin
TitleValue := FItems.Strings[inx];
GetTitleParam(FParam, TitleValue);
with FImage.Canvas do
begin
Font.Name := FParam.Name;
Font.Size := FParam.Size;
Font.Style := FParam.Style;
Font.Pitch := FParam.Pitch;
FMoveHeight := FMoveHeight + TextHeight(TitleValue)+FParam.Row;
end;
end;
if FMoveHeight < FImage.Height then
FMoveHeight := FImage.Height+10;
end;
procedure TDefineWater.Play;
var
TitleValue:String;
Inx,Cur: Integer;
begin
if (FImage <> nil)and(not(csDesigning in ComponentState)) then
begin
if FPlayState then
InitiateWater;
if Random(8)= 1 then
FWater.Blob(-1,-1,Random(1)+1,Random(500)+50);
FWater.Render(Bitmap,FImage.Bitmap);
FState:=FState-1;
if FState<-FMoveHeight then
FState:=FImage.height+10;
with FImage.Canvas do
begin
Brush.Style:=bsClear;
Cur := FState;
for inx:=0 to FItems.Count - 1 do
begin
TitleValue := FItems.Strings[inx];
GetTitleParam(FParam, TitleValue);
Font.Name := FParam.Name;
Font.Size := FParam.Size;
Font.Style := FParam.Style;
Font.Pitch := FParam.Pitch;
if FParam.Draw3D then
begin
Font.Color := 0;
case FParam.Align of
wpLeft :TextOut(21,Cur,TitleValue);
wpCenter:TextOut((FImage.Width - TextWidth(TitleValue))div 2+1,Cur,TitleValue);
wpRight :TextOut((FImage.Width - TextWidth(TitleValue))-21,Cur,TitleValue);
end;
end;
Font.Color := FParam.Color;
case FParam.Align of
wpLeft :TextOut(20,Cur,TitleValue);
wpCenter:TextOut((FImage.Width - TextWidth(TitleValue))div 2,Cur,TitleValue);
wpRight :TextOut((FImage.Width - TextWidth(TitleValue))-20,Cur,TitleValue);
end;
Cur := Cur+TextHeight('H')+FParam.Row;
end;
if FItems.Count <= 0 then
begin
TextOut((FImage.Width - TextWidth(''))div 2,Cur,'');
end;
end;
end;
end;
procedure TDefineWater.SetItems(const Value: TStringList);
begin
FItems.Assign(Value);
end;
procedure TDefineWater.Notification(AComponent: TComponent; Operation: TOperation);
begin
inherited;
if (Operation = opRemove) and (AComponent <> nil) then
begin
if AComponent=FImage then CtrlImage:=nil;
end;
end;
end.
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Pascal
1
https://gitee.com/wyrover/FlatStyle.git
git@gitee.com:wyrover/FlatStyle.git
wyrover
FlatStyle
FlatStyle
master

搜索帮助