FlatCtrls.pas 644 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361
  1. unit FlatCtrls;
  2. interface
  3. {$I FlatStyle.inc}
  4. uses
  5. Windows, Messages, Classes, Controls, Forms, Graphics, SysUtils, MMSystem,
  6. StdCtrls, ExtCtrls, MaskUtils, Themes, Dialogs, ShellApi, ActnList, Grids,
  7. ComCtrls, Menus, CommCtrl, FlatUtils, FlatSkins;
  8. type
  9. { TDefineListBox }
  10. TDefineListBox = class(TVersionControl)
  11. private
  12. scrollType: TScrollType;
  13. FirstItem: Integer;
  14. FSorted: Boolean;
  15. FItems: TStringList;
  16. FRects: TList;
  17. FChecks: TList;
  18. FItemIndex: Integer;
  19. FMultiSelect: Boolean;
  20. FOnChange: TNotifyChange;
  21. FOnClick: TNotifyClick;
  22. FStyle: TListStyle;
  23. FCaption: TCaption;
  24. FMouseIn: boolean;
  25. procedure SetSorted(Value: Boolean);
  26. procedure SetItems(Value: TStringList);
  27. procedure SetSelected(Index: Integer; Value: Boolean);
  28. procedure SetItemIndex(Value: Integer);
  29. procedure SetMultiSelect(Value: Boolean);
  30. procedure SetListStyle(const Value: TListStyle);
  31. procedure SetCaption(const Value: TCaption);
  32. function GetItemCount: Integer;
  33. function GetMouseIn: Boolean;
  34. protected
  35. procedure SetItemsRect;
  36. procedure Paint; override;
  37. procedure Loaded; override;
  38. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  39. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  40. procedure SetName(const Value: TComponentName); override;
  41. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  42. procedure ScrollTimerHandler(Sender: TObject);
  43. procedure StyleChange(Sender: TObject);
  44. procedure SelectNotifyEvent;
  45. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  46. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  47. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  48. procedure WMKeyDown(var Message: TWMKeyDown); message CN_KEYDOWN;
  49. procedure WMMouseWheel(var Message: TMessage); message WM_MOUSEWHEEL;
  50. procedure WMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  51. procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
  52. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  53. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  54. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  55. procedure DeleteChecked(index: integer);
  56. procedure AddCheck(index: integer);
  57. function FindChecked(Value: Integer;var Index:Integer): boolean;
  58. function GetMaxItems: Integer;
  59. function GetSelected(Index: Integer): Boolean;
  60. function GetSelCount: Integer;
  61. function GetItemIndex: Integer;
  62. function GetItemText: TCaption;
  63. property Skin: TListStyle read FStyle write SetListStyle;
  64. property MaxItems: Integer read GetMaxItems;
  65. property Items: TStringList read FItems write SetItems;
  66. property MultiSelect: Boolean read FMultiSelect write SetMultiSelect default false;
  67. property Caption:TCaption read FCaption write SetCaption;
  68. property Sorted: Boolean read FSorted write SetSorted default false;
  69. property OnClick: TNotifyClick read FOnClick write FOnClick;
  70. property OnChange: TNotifyChange read FOnChange write FOnChange;
  71. property TabStop default True;
  72. property ParentColor default True;
  73. property ParentFont default True;
  74. property Enabled default True;
  75. property Visible default True;
  76. property MouseIn: Boolean read GetMouseIn;
  77. public
  78. constructor Create(AOwner: TComponent); override;
  79. destructor Destroy; override;
  80. procedure Click; override;
  81. procedure Clear;
  82. function Find(Value:String; var Index : Integer):boolean;
  83. property ItemText:TCaption read GetItemText;
  84. property Selected[Index: Integer]: Boolean read GetSelected write SetSelected;
  85. property SelCount: Integer read GetSelCount;
  86. property ItemIndex: Integer read GetItemIndex write SetItemIndex;
  87. property ItemCount: Integer read GetItemCount;
  88. end;
  89. { TDefineListChecks }
  90. TDefineListChecks = class(TVersionControl)
  91. private
  92. FSelected: Integer;
  93. FCurSelected :integer;
  94. scrollType: TScrollType;
  95. FirstItem: Integer;
  96. FSorted: Boolean;
  97. FItems: TStringList;
  98. FRects: TList;
  99. FChecks: TList;
  100. FOnChange: TNotifyChange;
  101. FOnClick: TNotifyClick;
  102. FOnClickCheck: TNotifyEvent;
  103. FCaption: TCaption;
  104. FStyle: TCheckStyle;
  105. FMouseIn: boolean;
  106. procedure SetSorted(Value: Boolean);
  107. procedure SetItems(Value: TStringList);
  108. procedure SetChecked(Index: Integer; Value: Boolean);
  109. procedure SetCaption(const Value: TCaption);
  110. procedure SetCheckStyle(const Value: TCheckStyle);
  111. procedure SetItemIndex(Value: Integer);
  112. function GetItemCount: Integer;
  113. function GetMouseIn: Boolean;
  114. protected
  115. procedure Paint; override;
  116. procedure Loaded; override;
  117. procedure SetItemsRect;
  118. procedure ScrollTimerHandler(Sender: TObject);
  119. procedure DrawCheckRect(Canvas: TCanvas; StartRect: TRect; checked: Boolean);
  120. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  121. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  122. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  123. procedure StyleChange( Sender: TObject);
  124. procedure SetName(const Value: TComponentName); override;
  125. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  126. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  127. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  128. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  129. procedure WMKeyDown(var Message: TWMKeyDown); message CN_KEYDOWN;
  130. procedure WMMouseWheel(var Message: TMessage); message WM_MOUSEWHEEL;
  131. procedure WMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  132. procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
  133. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  134. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  135. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  136. procedure SelectNotifyEvent;
  137. procedure DeleteChecked(index: integer);
  138. procedure AddCheck(index: integer);
  139. function FindChecked(Value: Integer;var Index:Integer): boolean;
  140. function GetChecked(Index: Integer): Boolean;
  141. function GetSelCount: Integer;
  142. function GetItemIndex: Integer;
  143. function GetItemText: TCaption;
  144. function GetMaxItems: Integer;
  145. property Skin: TCheckStyle read FStyle write SetCheckStyle;
  146. property Sorted: Boolean read FSorted write SetSorted default false;
  147. property Items: TStringList read FItems write SetItems;
  148. property MaxItems: Integer read GetMaxItems;
  149. property Caption: TCaption read FCaption write SetCaption;
  150. property OnClick: TNotifyClick read FOnClick write FOnClick;
  151. property OnChange: TNotifyChange read FOnChange write FOnChange;
  152. property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
  153. property TabStop default True;
  154. property ParentColor default True;
  155. property ParentFont default True;
  156. property Enabled default True;
  157. property Visible default True;
  158. property MouseIn: Boolean read GetMouseIn;
  159. public
  160. constructor Create(AOwner: TComponent); override;
  161. destructor Destroy; override;
  162. procedure Clear;
  163. procedure Click; override;
  164. procedure CheckAll;
  165. procedure CheckCancel;
  166. procedure Delete(Index:Integer);
  167. function Find(Value: String; var Index: Integer): boolean;
  168. property Checked[Index: Integer]: Boolean read GetChecked write SetChecked;
  169. property SelCount: Integer read GetSelCount;
  170. property ItemText: TCaption read GetItemText;
  171. property ItemIndex: Integer read GetItemIndex write SetItemIndex;
  172. property ItemCount: Integer read GetItemCount;
  173. end;
  174. { TDefineCheckBox }
  175. TDefineCheckBox = class(TVersionControl)
  176. private
  177. FMouseIn: Boolean;
  178. FMouseDown: Boolean;
  179. Focused: Boolean;
  180. FLayout: TLayoutPosition;
  181. FChecked: Boolean;
  182. FFocusedColor: TColor;
  183. FDownColor: TColor;
  184. FCheckedColor: TColor;
  185. FBorderColor: TColor;
  186. FTransparent: Boolean;
  187. procedure SetColors(Index: Integer; Value: TColor);
  188. procedure SetLayout(Value: TLayoutPosition);
  189. procedure SetChecked(Value: Boolean);
  190. procedure SetTransparent(const Value: Boolean);
  191. function GetMouseIn: Boolean;
  192. protected
  193. procedure DoEnter; override;
  194. procedure DoExit; override;
  195. procedure Click; override;
  196. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  197. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  198. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  199. procedure CMTextChanged(var Message: TWmNoParams); message CM_TEXTCHANGED;
  200. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  201. procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  202. procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  203. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  204. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  205. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  206. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  207. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  208. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  209. procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  210. procedure WMLButtonUP(var Message: TWMLButtonDown); message WM_LBUTTONUP;
  211. procedure Paint; override;
  212. property Transparent: Boolean read FTransparent write SetTransparent default True;
  213. property Checked: Boolean read FChecked write SetChecked default false;
  214. property ColorFocused: TColor index 0 read FFocusedColor write SetColors default DefaultBackdropColor;
  215. property ColorDown: TColor index 1 read FDownColor write SetColors default DefaultBarColor;
  216. property ColorChecked: TColor index 2 read FCheckedColor write SetColors default DefaultCheckColor;
  217. property ColorBorder: TColor index 3 read FBorderColor write SetColors default DefaultBorderColor;
  218. property Layout: TLayoutPosition read FLayout write SetLayout default lpLeft;
  219. property Color default DefaultFlatColor;
  220. property ParentColor default false;
  221. property TabStop default True;
  222. property MouseIn: Boolean read GetMouseIn;
  223. //property State: TCheckBoxState read FState write SetState default cbUnchecked;
  224. //property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
  225. public
  226. constructor Create(AOwner: TComponent); override;
  227. end;
  228. { TDefineGroupBox }
  229. TDefineGroupBox = class(TVersionControl)
  230. private
  231. FTransparent: Boolean;
  232. FBorderColor: TColor;
  233. FBorder: TGroupBoxBorder;
  234. FBackgropStopColor: TColor;
  235. FBackgropStartColor: TColor;
  236. FStyleFace: TStyleFace;
  237. FBackgropOrien: TFillDirection;
  238. FAlignment: TAlignmentText;
  239. procedure SetColors(const Index: Integer; const Value: TColor);
  240. procedure SetBorder(const Value: TGroupBoxBorder);
  241. procedure SetTransparent(const Value: Boolean);
  242. procedure SetFillDirect(const Value: TFillDirection);
  243. procedure SetStyleFace(const Value: TStyleFace); virtual;
  244. procedure SetAlignment(const Value: TAlignmentText);
  245. protected
  246. procedure Paint; override;
  247. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  248. procedure CMTextChanged(var Message: TWmNoParams); message CM_TEXTCHANGED;
  249. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  250. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  251. procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  252. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  253. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  254. procedure AdjustClientRect(var Rect: TRect); override;
  255. property ColorBorder: TColor index 0 read FBorderColor write SetColors default DefaultBorderColor;
  256. property BackgropStartColor: TColor index 1 read FBackgropStartColor write SetColors default DefaultColorStart;
  257. property BackgropStopColor: TColor index 2 read FBackgropStopColor write SetColors default DefaultColorStop;
  258. property BackgropOrien: TFillDirection read FBackgropOrien write SetFillDirect default fdLeftToRight;
  259. property StyleFace: TStyleFace read FStyleFace write SetStyleFace default fsDefault;
  260. property Border: TGroupBoxBorder read FBorder write SetBorder default brFull;
  261. property Transparent: Boolean read FTransparent write SetTransparent default false;
  262. property Alignment: TAlignmentText read FAlignment write SetAlignment default stLeft;
  263. public
  264. constructor Create(AOwner: TComponent); override;
  265. end;
  266. { TDefineRadioButton }
  267. TDefineRadioButton = class(TVersionControl)
  268. private
  269. FMouseIn: Boolean;
  270. FMouseDown: Boolean;
  271. FFocused: Boolean;
  272. FGroupIndex: Integer;
  273. FLayout: TLayoutPosition;
  274. FChecked: Boolean;
  275. FFocusedColor: TColor;
  276. FDownColor: TColor;
  277. FCheckedColor: TColor;
  278. FBorderColor: TColor;
  279. FTransparent: Boolean;
  280. procedure SetColors(Index: Integer; Value: TColor);
  281. procedure SetLayout(Value: TLayoutPosition);
  282. procedure SetChecked(Value: Boolean);
  283. procedure SetTransparent(const Value: Boolean);
  284. function GetMouseIn: Boolean;
  285. protected
  286. procedure DoEnter; override;
  287. procedure DoExit; override;
  288. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  289. procedure CMTextChanged(var Message: TWmNoParams); message CM_TEXTCHANGED;
  290. procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  291. procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  292. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  293. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  294. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  295. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  296. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  297. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  298. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  299. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  300. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  301. //procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  302. //procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  303. procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  304. procedure WMLButtonUP(var Message: TWMLButtonDown); message WM_LBUTTONUP;
  305. procedure Paint; override;
  306. property Transparent: Boolean read FTransparent write SetTransparent default true;
  307. property Checked: Boolean read FChecked write SetChecked default false;
  308. property ColorFocused: TColor index 0 read FFocusedColor write SetColors default DefaultBackdropColor;
  309. property ColorDown: TColor index 1 read FDownColor write SetColors default DefaultBarColor;
  310. property ColorChecked: TColor index 2 read FCheckedColor write SetColors default DefaultCheckColor;
  311. property ColorBorder: TColor index 3 read FBorderColor write SetColors default DefaultBorderColor;
  312. property GroupIndex: Integer read FGroupIndex write FGroupIndex default 0;
  313. property Layout: TLayoutPosition read FLayout write SetLayout default lpLeft;
  314. property Color default DefaultFlatColor;
  315. property ParentColor default false;
  316. property MouseIn: Boolean read GetMouseIn;
  317. public
  318. constructor Create(AOwner: TComponent); override;
  319. end;
  320. { TDefineRadioGroup }
  321. TDefineRadioGroup = class(TDefineGroupBox)
  322. private
  323. FButtons: TList;
  324. FItems: TStrings;
  325. FItemIndex: Integer;
  326. FColumns: Integer;
  327. FReading: Boolean;
  328. FUpdating: Boolean;
  329. function GetButtons(Index: Integer):TDefineRadioButton;// TFlatRadioButton;
  330. procedure ArrangeButtons;
  331. procedure ButtonClick(Sender: TObject);
  332. procedure ItemsChange(Sender: TObject);
  333. procedure SetButtonCount(Value: Integer);
  334. procedure SetColumns(Value: Integer);
  335. procedure SetItemIndex(Value: Integer);
  336. procedure SetItems(Value: TStrings);
  337. procedure SetStyleFace(const Value: TStyleFace); override;
  338. procedure UpdateButtons;
  339. protected
  340. procedure Loaded; override;
  341. procedure ReadState(Reader: TReader); override;
  342. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  343. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  344. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  345. property Columns: Integer read FColumns write SetColumns default 1;
  346. property ItemIndex: Integer read FItemIndex write SetItemIndex default -1;
  347. property Items: TStrings read FItems write SetItems;
  348. function CanModify: Boolean; virtual;
  349. public
  350. constructor Create(AOwner: TComponent); override;
  351. destructor Destroy; override;
  352. property Buttons[Index: Integer]: TDefineRadioButton read GetButtons;
  353. end;
  354. { TDefineListBoxExt }
  355. TDefineListBoxExt = class(TVersionListBoxExt)
  356. private
  357. FParentColor: Boolean;
  358. FFocusColor: TColor;
  359. FBorderColor: TColor;
  360. FFlatColor: TColor;
  361. FMouseIn: Boolean;
  362. procedure SetColors(Index: Integer; Value: TColor);
  363. procedure SetParentColor(Value: Boolean);
  364. function GetMouseIn: Boolean;
  365. protected
  366. procedure RedrawBorder (const Clip: HRGN = 0);
  367. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  368. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  369. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  370. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  371. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  372. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  373. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  374. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  375. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  376. property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
  377. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  378. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  379. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  380. property ParentFont default True;
  381. property AutoSize default False;
  382. property Ctl3D default False;
  383. property BorderStyle default bsNone;
  384. property MouseIn: Boolean read GetMouseIn;
  385. public
  386. constructor Create(AOwner: TComponent); override;
  387. end;
  388. { TDefineCheckListExt }
  389. TDefineCheckListExt = class(TDefineListBoxExt)
  390. private
  391. FAllowGrayed: Boolean;
  392. FFlat: Boolean;
  393. FStandardItemHeight: Integer;
  394. FOnClickCheck: TNotifyEvent;
  395. FSaveStates: TList;
  396. FHeaderColor: TColor;
  397. FHeaderBkColor: TColor;
  398. procedure ResetItemHeight;
  399. procedure DrawCheck(R: TRect; AState: TCheckBoxState; AEnabled: Boolean);
  400. procedure SetChecked(Index: Integer; AChecked: Boolean);
  401. function GetChecked(Index: Integer): Boolean;
  402. procedure SetState(Index: Integer; AState: TCheckBoxState);
  403. function GetState(Index: Integer): TCheckBoxState;
  404. procedure ToggleClickCheck(Index: Integer);
  405. procedure InvalidateCheck(Index: Integer);
  406. function CreateWrapper(Index: Integer): TObject;
  407. function ExtractWrapper(Index: Integer): TObject;
  408. function GetWrapper(Index: Integer): TObject;
  409. function HaveWrapper(Index: Integer): Boolean;
  410. procedure SetFlat(Value: Boolean);
  411. procedure CNDrawItem(var Message: TWMDrawItem); message CN_DRAWITEM;
  412. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  413. procedure WMDestroy(var Msg : TWMDestroy);message WM_DESTROY;
  414. function GetItemEnabled(Index: Integer): Boolean;
  415. procedure SetItemEnabled(Index: Integer; const Value: Boolean);
  416. function GetHeader(Index: Integer): Boolean;
  417. procedure SetHeader(Index: Integer; const Value: Boolean);
  418. procedure SetHeaderBkColor(const Value: TColor);
  419. procedure SetHeaderColor(const Value: TColor);
  420. protected
  421. procedure DrawItem(Index: Integer; Rect: TRect;
  422. State: TOwnerDrawState); override;
  423. function InternalGetItemData(Index: Integer): Longint; override;
  424. procedure InternalSetItemData(Index: Integer; AData: Longint); override;
  425. procedure SetItemData(Index: Integer; AData: LongInt); override;
  426. function GetItemData(Index: Integer): LongInt; override;
  427. procedure KeyPress(var Key: Char); override;
  428. procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  429. X, Y: Integer); override;
  430. procedure ResetContent; override;
  431. procedure DeleteString(Index: Integer); override;
  432. procedure ClickCheck; dynamic;
  433. procedure CreateParams(var Params: TCreateParams); override;
  434. procedure CreateWnd; override;
  435. procedure DestroyWnd; override;
  436. function GetCheckWidth: Integer;
  437. public
  438. constructor Create(AOwner: TComponent); override;
  439. destructor Destroy; override;
  440. procedure CheckAll;
  441. procedure CheckCancel;
  442. property Checked[Index: Integer]: Boolean read GetChecked write SetChecked;
  443. property ItemEnabled[Index: Integer]: Boolean read GetItemEnabled write SetItemEnabled;
  444. property State[Index: Integer]: TCheckBoxState read GetState write SetState;
  445. property Header[Index: Integer]: Boolean read GetHeader write SetHeader;
  446. published
  447. property OnClickCheck: TNotifyEvent read FOnClickCheck write FOnClickCheck;
  448. property HeaderColor: TColor read FHeaderColor write SetHeaderColor default clInfoText;
  449. property HeaderBkColor: TColor read FHeaderBkColor write SetHeaderBkColor default clInfoBk;
  450. property AllowGrayed: Boolean read FAllowGrayed write FAllowGrayed default False;
  451. property Flat: Boolean read FFlat write SetFlat default True;
  452. property ColorFocused;
  453. property ColorBorder;
  454. property ColorFlat;
  455. property ParentColor;
  456. property Align;
  457. property Anchors;
  458. property AutoComplete;
  459. property BiDiMode;
  460. property Columns;
  461. property Constraints;
  462. property DragCursor;
  463. property DragKind;
  464. property DragMode;
  465. property Enabled;
  466. property Font;
  467. property ImeMode;
  468. property ImeName;
  469. property IntegralHeight;
  470. property ItemHeight;
  471. property Items;
  472. property ParentBiDiMode;
  473. property ParentFont;
  474. property ParentShowHint;
  475. property PopupMenu;
  476. property ShowHint;
  477. property Sorted;
  478. property Style;
  479. property TabOrder;
  480. property TabStop;
  481. property TabWidth;
  482. property Visible;
  483. property OnClick;
  484. property OnContextPopup;
  485. property OnData;
  486. property OnDataFind;
  487. property OnDataObject;
  488. property OnDblClick;
  489. property OnDragDrop;
  490. property OnDragOver;
  491. property OnDrawItem;
  492. property OnEndDock;
  493. property OnEndDrag;
  494. property OnEnter;
  495. property OnExit;
  496. property OnKeyDown;
  497. property OnKeyPress;
  498. property OnKeyUp;
  499. property OnMeasureItem;
  500. property OnMouseDown;
  501. property OnMouseMove;
  502. property OnMouseUp;
  503. property OnStartDock;
  504. property OnStartDrag;
  505. end;
  506. { TDefineSpeed }
  507. TDefineSpeed = class(TVersionGraphic)
  508. private
  509. FOnMouseEnter: TNotifyEvent;
  510. FOnMouseLeave: TNotifyEvent;
  511. FTransparent: TTransparentMode;
  512. TextBounds: TRect;
  513. GlyphPos: TPoint;
  514. FNumGlyphs: TNumGlyphs;
  515. fColorDown: TColor;
  516. FColorBorder: TColor;
  517. FColorShadow: TColor;
  518. fColorFocused: TColor;
  519. FGroupIndex: Integer;
  520. FGlyph: TBitmap;
  521. FDown: Boolean;
  522. FDragging: Boolean;
  523. FAllowAllUp: Boolean;
  524. FLayout: TButtonLayout;
  525. FSpacing: Integer;
  526. FMargin: Integer;
  527. FMouseIn: Boolean;
  528. FModalResult: TModalResult;
  529. fColorFlat: TColor;
  530. FFoisChange: Boolean;
  531. FTransBorder: Boolean;
  532. FAutoColor: TColor;
  533. FAutoStyle: TFontStyles;
  534. procedure UpdateExclusive;
  535. procedure SetGlyph(Value: TBitmap);
  536. procedure SetNumGlyphs(Value: TNumGlyphs);
  537. procedure SetDown(Value: Boolean);
  538. procedure SetAllowAllUp(Value: Boolean);
  539. procedure SetGroupIndex(Value: Integer);
  540. procedure SetLayout(Value: TButtonLayout);
  541. procedure SetSpacing(Value: Integer);
  542. procedure SetMargin(Value: Integer);
  543. procedure UpdateTracking;
  544. procedure SetTransparent (const Value: TTransparentMode);
  545. procedure SetColors(Index: Integer; Value: TColor);
  546. procedure SetFoisChange(const Value: Boolean);
  547. procedure SetAutoStyle(const Value: TFontStyles);
  548. procedure SetTransBorder(const Value: Boolean);
  549. function GetMouseIn: Boolean;
  550. protected
  551. FState: TButtonState;
  552. function GetPalette: HPALETTE; override;
  553. procedure Loaded; override;
  554. procedure WMLButtonDblClk(var Message: TWMLButtonDown); message WM_LBUTTONDBLCLK;
  555. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  556. procedure CMButtonPressed(var Message: TMessage); message CM_BUTTONPRESSED;
  557. procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  558. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  559. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  560. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  561. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  562. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  563. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  564. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  565. procedure MouseMove (Shift: TShiftState; X, Y: Integer); override;
  566. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  567. procedure Paint; override;
  568. property Transparent: TTransparentMode read FTransparent write SetTransparent default tmNone;
  569. property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
  570. property Color default DefaultFlatColor;
  571. property ColorFocused: TColor index 0 read fColorFocused write SetColors default DefaultFocusedColor;
  572. property ColorDown: TColor index 1 read fColorDown write SetColors default DefaultDownColor;
  573. property ColorBorder: TColor index 2 read FColorBorder write SetColors default DefaultBorderColor;
  574. property ColorShadow: TColor index 3 read FColorShadow write SetColors default DefaultShadowColor;
  575. property ColorFlat: TColor index 4 read fColorFlat write SetColors default DefaultFlatColor;
  576. property FoisColor: TColor index 5 read FAutoColor write SetColors default DefaultFoisColor;
  577. property TransBorder: Boolean read FTransBorder write SetTransBorder default false;
  578. property FoisChange: Boolean read FFoisChange write SetFoisChange default true;
  579. property FoisStyle: TFontStyles read FAutoStyle write SetAutoStyle default [fsBold];
  580. property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
  581. property Down: Boolean read FDown write SetDown default False;
  582. property Glyph: TBitmap read FGlyph write SetGlyph;
  583. property Layout: TButtonLayout read FLayout write SetLayout default blGlyphTop;
  584. property Margin: Integer read FMargin write SetMargin default -1;
  585. property NumGlyphs: TNumGlyphs read FNumGlyphs write SetNumGlyphs default 1;
  586. property ModalResult: TModalResult read FModalResult write FModalResult default 0;
  587. property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  588. property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  589. property Spacing: Integer read FSpacing write SetSpacing default 4;
  590. property MouseIn: Boolean read GetMouseIn;
  591. {$IFDEF DFS_DELPHI_4_UP}
  592. procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); override;
  593. {$ENDIF}
  594. public
  595. constructor Create(AOwner: TComponent); override;
  596. destructor Destroy; override;
  597. procedure Click; override;
  598. procedure MouseEnter;
  599. procedure MouseLeave;
  600. end;
  601. { TTimeBtnState }
  602. TTimeBtnState = set of (tbFocusRect, tbAllowTimer);
  603. { TDefineSpins }
  604. TDefineSpins = class(TDefineSpeed)
  605. private
  606. FRepeatTimer: TTimer;
  607. FTimeBtnState: TTimeBtnState;
  608. procedure TimerExpired( Sender: TObject);
  609. protected
  610. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  611. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  612. property Cursor default crHandPoint;
  613. public
  614. constructor Create(AOwner: TComponent); override;
  615. destructor Destroy; override;
  616. property TimeBtnState: TTimeBtnState read FTimeBtnState write FTimeBtnState;
  617. end;
  618. TDefineSpin = class(TWinControl)
  619. private
  620. FUpButton: TDefineSpins;
  621. FDownButton: TDefineSpins;
  622. FFocusedButton: TDefineSpins;
  623. FFocusControl: TWinControl;
  624. FOnUpClick: TNotifyEvent;
  625. FOnDownClick: TNotifyEvent;
  626. function CreateButton: TDefineSpins;
  627. function GetUpGlyph: TBitmap;
  628. function GetDownGlyph: TBitmap;
  629. procedure SetUpGlyph(Value: TBitmap);
  630. procedure SetDownGlyph(Value: TBitmap);
  631. function GetUpNumGlyphs: TNumGlyphs;
  632. function GetDownNumGlyphs: TNumGlyphs;
  633. procedure SetUpNumGlyphs(Value: TNumGlyphs);
  634. procedure SetDownNumGlyphs(Value: TNumGlyphs);
  635. procedure BtnClick(Sender: TObject);
  636. procedure BtnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  637. procedure SetFocusBtn (Btn: TDefineSpins);
  638. procedure AdjustSize(var W, H: Integer); reintroduce;// {$IFDEF DFS_COMPILER_4_UP} reintroduce; {$ENDIF}
  639. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  640. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  641. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  642. procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  643. protected
  644. procedure Loaded; override;
  645. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  646. procedure Notification (AComponent: TComponent; Operation: TOperation); override;
  647. public
  648. constructor Create(AOwner: TComponent); override;
  649. procedure SetBounds (ALeft, ATop, AWidth, AHeight: Integer); override;
  650. published
  651. property DownGlyph: TBitmap read GetDownGlyph write SetDownGlyph;
  652. property DownNumGlyphs: TNumGlyphs read GetDownNumGlyphs write SetDownNumGlyphs default 1;
  653. property FocusControl: TWinControl read FFocusControl write FFocusControl;
  654. property UpGlyph: TBitmap read GetUpGlyph write SetUpGlyph;
  655. property UpNumGlyphs: TNumGlyphs read GetUpNumGlyphs write SetUpNumGlyphs default 1;
  656. property Enabled;
  657. property Visible;
  658. property OnDownClick: TNotifyEvent read FOnDownClick write FOnDownClick;
  659. property OnUpClick: TNotifyEvent read FOnUpClick write FOnUpClick;
  660. end;
  661. { TDefineTicket }
  662. TDefineTicket = class(TCustomLabel)
  663. private
  664. function GetTop: Integer;
  665. function GetLeft: Integer;
  666. function GetWidth: Integer;
  667. function GetHeight: Integer;
  668. procedure SetHeight(const Value: Integer);
  669. procedure SetWidth(const Value: Integer);
  670. protected
  671. procedure AdjustBounds; override;
  672. property AutoSize default True;
  673. public
  674. constructor Create(AOwner: TComponent); override;
  675. published
  676. property Caption;
  677. property Font;
  678. property Height: Integer read GetHeight write SetHeight;
  679. property ParentFont;
  680. property Left: Integer read GetLeft;
  681. property Top: Integer read GetTop;
  682. property Width: Integer read GetWidth write SetWidth;
  683. property Visible;
  684. end;
  685. { TDefineEdit }
  686. TDefineEdit = class(TVersionEdit)
  687. private
  688. FParentColor: Boolean;
  689. FFocusColor: TColor;
  690. FBorderColor: TColor;
  691. FFlatColor: TColor;
  692. FAlignment: TAlignment;
  693. FTicketSpace: Integer;
  694. FMouseIn: Boolean;
  695. FTicket: TDefineTicket;
  696. FTicketPosition: TTicketPosition;
  697. procedure SetColors(Index: Integer; Value: TColor);
  698. procedure SetParentColor (Value: Boolean);
  699. function GetMouseIn: Boolean;
  700. protected
  701. fHintLabel: TLabel;
  702. procedure RedrawBorder(const Clip: HRGN);
  703. procedure NewAdjustHeight;
  704. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  705. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  706. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  707. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  708. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  709. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  710. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  711. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  712. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  713. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  714. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  715. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  716. procedure SetAlignment(const Value: TAlignment);
  717. procedure LabelMouseEnter(Sender: TObject);
  718. procedure SetTicketPosition(const Value: TTicketPosition);
  719. procedure SetTicketSpace(const Value: Integer);
  720. procedure SetName(const Value: TComponentName); override;
  721. procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
  722. procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
  723. procedure SetParent(AParent: TWinControl); override;
  724. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  725. procedure KeyPress(var Key: Char); override;
  726. procedure CreateParams(var Params: TCreateParams); override;
  727. procedure Loaded; override;
  728. procedure SetupInternalLabel;
  729. property Ticket: TDefineTicket read FTicket;
  730. property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
  731. property TicketSpace: Integer read FTicketSpace write SetTicketSpace default 3;
  732. property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
  733. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  734. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  735. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  736. property Alignment: TAlignment read FAlignment write SetAlignment default taLeftJustify;
  737. property MouseIn: Boolean read GetMouseIn;
  738. public
  739. constructor Create(AOwner: TComponent); override;
  740. destructor Destroy; override;
  741. procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
  742. end;
  743. { TDefineInteger }
  744. TDefineInteger = class(TDefineEdit)
  745. private
  746. FMinValue: LongInt;
  747. FMaxValue: LongInt;
  748. FIncrement: LongInt;
  749. FButton: TDefineSpin;
  750. FEditorEnabled: Boolean;
  751. function GetValue: LongInt;
  752. function CheckValue (NewValue: LongInt): LongInt;
  753. procedure SetValue (NewValue: LongInt);
  754. protected
  755. function IsValidChar (Key: Char): Boolean; virtual;
  756. procedure UpClick (Sender: TObject); virtual;
  757. procedure DownClick (Sender: TObject); virtual;
  758. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  759. procedure KeyPress(var Key: Char); override;
  760. procedure Loaded; override;
  761. procedure CreateWnd; override;
  762. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  763. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  764. procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
  765. procedure CMExit(var Message: TCMExit); message CM_EXIT;
  766. procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
  767. procedure WMCut(var Message: TWMCut); message WM_CUT;
  768. property Increment: LongInt read FIncrement write FIncrement default 1;
  769. property MaxValue: LongInt read FMaxValue write FMaxValue default 0;
  770. property MinValue: LongInt read FMinValue write FMinValue default 0;
  771. property Value: LongInt read GetValue write SetValue default 0;
  772. property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
  773. public
  774. constructor Create(AOwner: TComponent); override;
  775. destructor Destroy; override;
  776. property Button: TDefineSpin read FButton;
  777. end;
  778. { TDefineFloat }
  779. TDefineFloat = class(TDefineEdit)
  780. private
  781. FPrecision, FDigits: Integer;
  782. FFloatFormat: TFloatFormat;
  783. FMinValue: Extended;
  784. FMaxValue: Extended;
  785. FIncrement: Extended;
  786. FButton: TDefineSpin;
  787. FEditorEnabled: Boolean;
  788. function GetValue: Extended;
  789. function CheckValue (Value: Extended): Extended;
  790. procedure SetValue (Value: Extended);
  791. procedure SetPrecision (Value: Integer);
  792. procedure SetDigits (Value: Integer);
  793. procedure SetFloatFormat (Value: TFloatFormat);
  794. protected
  795. function IsValidChar (Key: Char): Boolean; virtual;
  796. procedure UpClick (Sender: TObject); virtual;
  797. procedure DownClick (Sender: TObject); virtual;
  798. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  799. procedure KeyPress(var Key: Char); override;
  800. procedure Loaded; override;
  801. procedure CreateWnd; override;
  802. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  803. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  804. procedure CMEnter(var Message: TCMGotFocus); message CM_ENTER;
  805. procedure CMExit(var Message: TCMExit); message CM_EXIT;
  806. procedure WMPaste(var Message: TWMPaste); message WM_PASTE;
  807. procedure WMCut(var Message: TWMCut); message WM_CUT;
  808. property Digits: Integer read FDigits write SetDigits;
  809. property Precision: Integer read FPrecision write SetPrecision;
  810. property FloatFormat: TFloatFormat read FFloatFormat write SetFloatFormat;
  811. property EditorEnabled: Boolean read FEditorEnabled write FEditorEnabled default True;
  812. property Increment: Extended read FIncrement write FIncrement;
  813. property MaxValue: Extended read FMaxValue write FMaxValue;
  814. property MinValue: Extended read FMinValue write FMinValue;
  815. property Value: Extended read GetValue write SetValue;
  816. public
  817. constructor Create(AOwner: TComponent); override;
  818. destructor Destroy; override;
  819. property Button: TDefineSpin read FButton;
  820. end;
  821. { TDefineMemo }
  822. TDefineMemo = class(TVersionMemo)
  823. private
  824. FParentColor: Boolean;
  825. FFocusColor: TColor;
  826. FBorderColor: TColor;
  827. FFlatColor: TColor;
  828. FMouseIn: Boolean;
  829. procedure SetColors(Index: Integer; Value: TColor);
  830. procedure SetParentColor(Value: Boolean);
  831. function GetMouseIn: Boolean;
  832. protected
  833. procedure RedrawBorder (const Clip: HRGN);
  834. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  835. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  836. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  837. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  838. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  839. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  840. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  841. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  842. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  843. property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
  844. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  845. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  846. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  847. property MouseIn: Boolean read GetMouseIn;
  848. public
  849. constructor Create(AOwner: TComponent); override;
  850. end;
  851. {TDefineMask}
  852. TDefineError = class(Exception);
  853. TDefineState = set of (msMasked, msReEnter, msDBSetText);
  854. TDefineMask = class(TDefineEdit)
  855. private
  856. FEditMask: TEditMask;
  857. FMaskBlank: Char;
  858. FMaxChars: Integer;
  859. FMaskSave: Boolean;
  860. FMaskState: TDefineState;
  861. FCaretPos: Integer;
  862. FBtnDownX: Integer;
  863. FOldValue: string;
  864. FSettingCursor: Boolean;
  865. FOnValidate: TValidateEvent;
  866. function DoInputChar(var NewChar: Char; MaskOffset: Integer): Boolean;
  867. function InputChar(var NewChar: Char; Offset: Integer): Boolean;
  868. function DeleteSelection(var Value: string; Offset: Integer; Len: Integer): Boolean;
  869. function InputString(var Value: string; const NewValue: string; Offset: Integer): Integer;
  870. function AddEditFormat(const Value: string; Active: Boolean): string;
  871. function RemoveEditFormat(const Value: string): string;
  872. function FindLiteralChar (MaskOffset: Integer; InChar: Char): Integer;
  873. function GetEditText: string;
  874. function GetMasked: Boolean;
  875. function GetText: TMaskedText;
  876. function GetMaxLength: Integer;
  877. function CharKeys(var CharCode: Char): Boolean;
  878. procedure SetEditText(const Value: string);
  879. procedure SetEditMask(const Value: TEditMask);
  880. procedure SetMaxLength(Value: Integer);
  881. procedure SetText(const Value: TMaskedText);
  882. procedure DeleteKeys(CharCode: Word);
  883. procedure HomeEndKeys(CharCode: Word; Shift: TShiftState);
  884. procedure CursorInc(CursorPos: Integer; Incr: Integer);
  885. procedure CursorDec(CursorPos: Integer);
  886. procedure ArrowKeys(CharCode: Word; Shift: TShiftState);
  887. procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  888. procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
  889. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  890. procedure WMCut(var Message: TMessage); message WM_CUT;
  891. procedure WMPaste(var Message: TMessage); message WM_PASTE;
  892. procedure CMEnter(var Message: TCMEnter); message CM_ENTER;
  893. procedure CMExit(var Message: TCMExit); message CM_EXIT;
  894. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  895. procedure CMWantSpecialKey(var Message: TCMWantSpecialKey); message CM_WANTSPECIALKEY;
  896. protected
  897. procedure ReformatText(const NewMask: string);
  898. procedure GetSel(var SelStart: Integer; var SelStop: Integer);
  899. procedure SetSel(SelStart: Integer; SelStop: Integer);
  900. procedure SetCursor(Pos: Integer);
  901. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  902. procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  903. procedure KeyPress(var Key: Char); override;
  904. function EditCanModify: Boolean; virtual;
  905. procedure Reset; virtual;
  906. function GetFirstEditChar: Integer;
  907. function GetLastEditChar: Integer;
  908. function GetNextEditChar(Offset: Integer): Integer;
  909. function GetPriorEditChar(Offset: Integer): Integer;
  910. function GetMaxChars: Integer;
  911. function Validate(const Value: string; var Pos: Integer): Boolean; virtual;
  912. procedure ValidateError; virtual;
  913. procedure CheckCursor;
  914. property MaskState: TDefineState read FMaskState write FMaskState;
  915. property MaxLength: Integer read GetMaxLength write SetMaxLength default 0;
  916. property OnValidate : TValidateEvent read FOnValidate write FOnValidate;
  917. public
  918. constructor Create(AOwner: TComponent); override;
  919. procedure ValidateEdit; virtual;
  920. procedure Clear; override;
  921. function GetTextLen: Integer;
  922. property IsMasked: Boolean read GetMasked;
  923. property EditText: string read GetEditText write SetEditText;
  924. property Text: TMaskedText read GetText write SetText;
  925. property EditMask: TEditMask read FEditMask write SetEditMask;
  926. end;
  927. { TDefineIPEdit }
  928. TDefineIPEdit = class(TDefineMask)
  929. protected
  930. { Protected declarations }
  931. IPText:TIP;
  932. fIPAddress : String;
  933. function GetInx: integer;
  934. function GetIPText: String;
  935. procedure SetIPText(const Value: String);
  936. function Replace(Start, Len: Integer):integer;
  937. procedure KeyPress(var Key: Char); override;
  938. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  939. procedure CMExit(var Message: TCMExit); message CM_EXIT;
  940. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  941. procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  942. property IPAddress: String read GetIPText write SetIPText;
  943. public
  944. property Index:integer read GetInx;
  945. constructor Create(AOwner: TComponent); override;
  946. end;
  947. { TDefineComboBox }
  948. TDefineComboBox = class(TVersionComboBox)
  949. private
  950. FArrowColor: TColor;
  951. FArrowBackgroundColor: TColor;
  952. FBorderColor: TColor;
  953. FButtonWidth: Integer;
  954. FChildHandle: HWND;
  955. FDefListProc: Pointer;
  956. FListHandle: HWND;
  957. FListInstance: Pointer;
  958. FSysBtnWidth: Integer;
  959. FSolidBorder: Boolean;
  960. FTicketSpace: Integer;
  961. FTicket: TDefineTicket;
  962. FMouseIn: Boolean;
  963. FTicketPosition: TTicketPosition;
  964. FFocusedColor: TColor;
  965. FFlatColor: TColor;
  966. fParentColor: Boolean;
  967. FReadOnly: boolean;
  968. procedure SetColors(Index: Integer; Value: TColor);
  969. function GetButtonRect: TRect;
  970. procedure PaintButton;
  971. procedure PaintBorder;
  972. procedure RedrawBorders;
  973. procedure InvalidateSelection;
  974. function GetSolidBorder: Boolean;
  975. procedure SetSolidBorder;
  976. procedure SetParentColor(const Value: Boolean);
  977. procedure SetReadOnly(const Value: boolean);
  978. function GetMouseIn: boolean;
  979. protected
  980. procedure ListWndProc(var Message: TMessage);
  981. procedure KeyPress(var Key: Char); override;
  982. procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
  983. procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
  984. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  985. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  986. procedure WMKeyDown(var Message: TMessage); message WM_KEYDOWN;
  987. procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  988. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  989. procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
  990. procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  991. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  992. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  993. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  994. procedure WndProc(var Message: TMessage); override;
  995. procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
  996. procedure SetTicketPosition(const Value: TTicketPosition);
  997. procedure SetTicketSpace(const Value: Integer);
  998. procedure SetName(const Value: TComponentName); override;
  999. procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
  1000. procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
  1001. procedure SetParent(AParent: TWinControl); override;
  1002. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1003. procedure SetupInternalLabel;
  1004. procedure CreateWnd; override;
  1005. property SolidBorder: Boolean read FSolidBorder;
  1006. property Ticket: TDefineTicket read FTicket;
  1007. property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
  1008. property TicketSpace: Integer read FTicketSpace write SetTicketSpace;
  1009. property ParentColor: Boolean read fParentColor write SetParentColor default true;
  1010. property ColorArrow: TColor index 0 read FArrowColor write SetColors default clBlack;
  1011. property ColorArrowBackground: TColor index 1 read FArrowBackgroundColor write SetColors default $00C5D6D9;
  1012. property ColorBorder: TColor index 2 read FBorderColor write SetColors default DefaultBorderColor;
  1013. property ColorFlat: TColor index 3 read FFlatColor write SetColors default DefaultFlatColor;
  1014. property ColorFocued: TColor index 4 read FFocusedColor write SetColors default clWhite;
  1015. property ReadOnly: boolean read FReadOnly write SetReadOnly default false;
  1016. property MouseIn: boolean read GetMouseIn;
  1017. public
  1018. constructor Create(AOwner: TComponent); override;
  1019. destructor Destroy; override;
  1020. procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
  1021. end;
  1022. { TFlatComboBox }
  1023. { TDefineColorBox }
  1024. TDefineColorBox = class(TVersionComboBox)
  1025. private
  1026. FArrowColor: TColor;
  1027. FArrowBackgroundColor: TColor;
  1028. FBorderColor: TColor;
  1029. FHighlightColor: TColor;
  1030. FButtonWidth: Integer;
  1031. FChildHandle: HWND;
  1032. FDefListProc: Pointer;
  1033. FListHandle: HWND;
  1034. FListInstance: Pointer;
  1035. FSysBtnWidth: Integer;
  1036. FSolidBorder: Boolean;
  1037. FShowNames: Boolean;
  1038. FValue: TColor;
  1039. FColorBoxWidth: Integer;
  1040. FColorDlg: TColorDialog;
  1041. FTicketSpace: Integer;
  1042. FTicket: TDefineTicket;
  1043. FTicketPosition: TTicketPosition;
  1044. fLanguage: TLanguage;
  1045. procedure SetColors(Index: Integer; Value: TColor);
  1046. function GetButtonRect: TRect;
  1047. procedure PaintButton;
  1048. procedure PaintBorder;
  1049. procedure RedrawBorders;
  1050. procedure InvalidateSelection;
  1051. function GetSolidBorder: Boolean;
  1052. procedure SetSolidBorder;
  1053. procedure SetShowNames(Value: Boolean);
  1054. procedure SetColorValue(Value: TColor);
  1055. procedure SetColorBoxWidth(Value: Integer);
  1056. procedure SetTicketPosition(const Value: TTicketPosition);
  1057. procedure SetTicketSpace(const Value: Integer);
  1058. procedure SetLanguage(const Value: TLanguage);
  1059. protected
  1060. procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); override;
  1061. procedure CreateWnd; override;
  1062. procedure WndProc(var Message: TMessage); override;
  1063. procedure ListWndProc(var Message: TMessage);
  1064. procedure WMSetFocus(var Message: TMessage); message WM_SETFOCUS;
  1065. procedure WMKillFocus(var Message: TMessage); message WM_KILLFOCUS;
  1066. procedure WMKeyDown(var Message: TMessage); message WM_KEYDOWN;
  1067. procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  1068. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  1069. procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
  1070. procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  1071. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  1072. procedure ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer); override;
  1073. property SolidBorder: Boolean read FSolidBorder;
  1074. procedure Click; override;
  1075. procedure SetName(const Value: TComponentName); override;
  1076. procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
  1077. procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
  1078. procedure SetParent(AParent: TWinControl); override;
  1079. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1080. procedure SetupInternalLabel;
  1081. property Color default DefaultFlatColor;
  1082. property ColorArrow: TColor index 0 read FArrowColor write SetColors default clBlack;
  1083. property ColorArrowBackground: TColor index 1 read FArrowBackgroundColor write SetColors default $00C5D6D9;
  1084. property ColorBorder: TColor index 2 read FBorderColor write SetColors default DefaultBorderColor;
  1085. property ColorHighlight: TColor index 3 read FHighlightColor write SetColors default clHighlight;
  1086. property ColorBoxWidth: Integer read FColorBoxWidth write SetColorBoxWidth default 30;
  1087. property ShowNames: Boolean read FShowNames write SetShowNames;
  1088. property Value: TColor read FValue write SetColorValue;
  1089. property Language:TLanguage read fLanguage write SetLanguage default lgChinese;
  1090. property Ticket: TDefineTicket read FTicket;
  1091. property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
  1092. property TicketSpace: Integer read FTicketSpace write SetTicketSpace default 3;
  1093. public
  1094. constructor Create(AOwner: TComponent); override;
  1095. destructor Destroy; override;
  1096. function AddColor(ColorName: String; Color: TColor): Boolean;
  1097. function DeleteColorByName(ColorName: String): Boolean;
  1098. function DeleteColorByColor(Color: TColor): Boolean;
  1099. procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer); override;
  1100. end;
  1101. { TDefineSplitter }
  1102. TDefineHack = class(TWinControl);
  1103. TDefineSplitter = class(TVersionGraphic)
  1104. private
  1105. FBorderColor: TColor;
  1106. FFocusedColor: TColor;
  1107. FLineDC: HDC;
  1108. FDownPos: TPoint;
  1109. FSplit: Integer;
  1110. FMinSize: NaturalNumber;
  1111. FMaxSize: Integer;
  1112. FControl: TControl;
  1113. FNewSize: Integer;
  1114. FActiveControl: TWinControl;
  1115. FOldKeyDown: TKeyEvent;
  1116. FLineVisible: Boolean;
  1117. FOnMoved: TNotifyEvent;
  1118. FStatus: TSplitterStatus;
  1119. procedure AllocateLineDC;
  1120. procedure DrawLine;
  1121. procedure ReleaseLineDC;
  1122. procedure UpdateSize(X, Y: Integer);
  1123. procedure FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  1124. procedure SetColors (Index: Integer; Value: TColor);
  1125. procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
  1126. procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  1127. procedure CMEnter(var Message: TMessage); message CM_MOUSEENTER;
  1128. procedure CMExit(var Message: TMessage); message CM_MOUSELEAVE;
  1129. protected
  1130. procedure Paint; override;
  1131. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1132. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  1133. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1134. procedure StopSizing;
  1135. public
  1136. constructor Create(AOwner: TComponent); override;
  1137. published
  1138. property Color default $00E0E9EF;
  1139. property ColorFocused: TColor index 0 read FFocusedColor write SetColors default $0053D2FF;
  1140. property ColorBorder: TColor index 1 read FBorderColor write SetColors default $00555E66;
  1141. property MinSize: NaturalNumber read FMinSize write FMinSize default 30;
  1142. property OnMoved: TNotifyEvent read FOnMoved write FOnMoved;
  1143. property Align default alLeft;
  1144. property Enabled;
  1145. property ParentColor;
  1146. property ParentShowHint;
  1147. property ShowHint;
  1148. property Visible;
  1149. end;
  1150. { TDefinePucker }
  1151. TDefinePucker = class;
  1152. //Event types
  1153. TAfterSizeChanged = procedure(Sender : TDefinePucker; ASizeRestored : Boolean) of object;
  1154. TDefinePucker = class(TVersionControl)
  1155. private
  1156. FCloseBtnRect : TRect;
  1157. FMaxBtnRect : TRect;
  1158. FMinBtnRect : TRect;
  1159. FOldBounds : TRect;
  1160. FOldAlign : TAlign;
  1161. FMinimizing : Boolean;
  1162. FGradientFill : Boolean;
  1163. FFillDirection: TFillDirection;
  1164. FShadow : Boolean;
  1165. FShadowDist : Integer;
  1166. FHeight : Integer;
  1167. FDefaultHeight : Integer;
  1168. FShowHeader : Boolean;
  1169. FCaption : String;
  1170. FTitleFont : TFont;
  1171. FTitleHeight: Integer;
  1172. FTitleAlignment : TAlignment;
  1173. FTitleShadowOnMouseEnter : Boolean;
  1174. FTitleGradient : Boolean;
  1175. FStartColor : TColor;
  1176. FEndColor : TColor;
  1177. FTitleStartColor : TColor;
  1178. FTitleEndColor : TColor;
  1179. FTitleColor : TColor;
  1180. FBorderColor: TColor;
  1181. FTitleBtnBorderColor: TColor;
  1182. FTitleBtnBGColor: TColor;
  1183. FTitleFillDirect : TFillDirection;
  1184. FTitleImage : TBitmap;
  1185. FTitleImageAlign : TTitleImageAlign;
  1186. FTitleImageTransparent : Boolean;
  1187. FTitleCursor : TCursor;
  1188. FTitleButtons : TTitleButtons;
  1189. FAnimation : Boolean;
  1190. FMovable : Boolean;
  1191. FSizable : Boolean;
  1192. FMinimized : Boolean;
  1193. FMaximized : Boolean;
  1194. FBorderSize : Integer;
  1195. FShowBorder : Boolean;
  1196. FPanelCorner : TPanelCorners;
  1197. FBGImage : TBitmap;
  1198. FBGImageAlign : TBGImageAlign;
  1199. FBGImageTransparent : Boolean;
  1200. FMouseOnHeader : Boolean;
  1201. FOnTitleClick : TNotifyEvent;
  1202. FOnTitleDblClick : TNotifyEvent;
  1203. FOnTitleMouseDown : TMouseEvent;
  1204. FOnTitleMouseUp : TMouseEvent;
  1205. FOnTitleMouseEnter: TNotifyEvent;
  1206. FOnTitleMouseExit : TNotifyEvent;
  1207. FOnMouseEnter : TNotifyEvent;
  1208. FOnMouseExit : TNotifyEvent;
  1209. FAfterMinimized : TAfterSizeChanged;
  1210. FAfterMaximized : TAfterSizeChanged;
  1211. FBeforeMoving : TNotifyEvent;
  1212. FAfterMoving : TNotifyEvent;
  1213. FAfterClose : TNotifyEvent;
  1214. FFullRepaint: Boolean;
  1215. FTitleButtonsStyle: TTitleButtonsStyle;
  1216. FTitleBtnBorderSize: Integer;
  1217. procedure SetFillDirection(AFillDirection : TFillDirection);
  1218. procedure SetCaption(AValue : String);
  1219. procedure SetTitleFont(AFont : TFont);
  1220. procedure OnTitleFontChange(Sender : TObject);
  1221. procedure SetDefaultHeight(AValue : Integer);
  1222. procedure SetTitleHeight(AHeight : Integer);
  1223. procedure SetTitleAlignment(AValue : TAlignment);
  1224. procedure SetTitleFillDirect(AValue : TFillDirection);
  1225. procedure SetTitleImage(AValue : TBitmap);
  1226. procedure SetTitleImageAlign(AValue : TTitleImageAlign);
  1227. procedure SetTitleButtons(AValue : TTitleButtons);
  1228. procedure SetPanelCorner(AValue : TPanelCorners);
  1229. procedure SetMinimized(AValue : Boolean);
  1230. procedure SetMaximized(AValue : Boolean);
  1231. procedure SetBGImage(AImage : TBitmap);
  1232. procedure SetBGImageAlign(AImageAlign : TBGImageAlign);
  1233. procedure SetTitleButtonsStyle(AValue: TTitleButtonsStyle);
  1234. procedure SetTitleBtnBorderSize(AValue: Integer);
  1235. procedure SetColors(Index:Integer; Value:TColor);
  1236. procedure SetBools(Index:Integer; Value:Boolean);
  1237. protected
  1238. procedure DrawTitle(ACanvas : TCanvas; ATitleRect : TRect);
  1239. procedure DrawAllTitleButtons(ACanvas : TCanvas; ATitleRect : TRect);
  1240. procedure DrawTitleButton(ACanvas : TCanvas; AButtonRect : TRect; ABtnType : TTitleButton);
  1241. procedure DrawBorder(ACanvas : TCanvas; ARect : TRect; AClient : Boolean); //AClient = true - draw client area border only
  1242. procedure DrawBGImage(ACanvas : TCanvas);
  1243. procedure ForceReDraw;
  1244. procedure Loaded; override;
  1245. procedure SetShape(ARounded : TPanelCorners);
  1246. procedure WMSize(var Message : TMessage); message WM_SIZE;
  1247. procedure MouseEnter(var Message : TMessage); message CM_MOUSEENTER;
  1248. procedure MouseLeave(var Message : TMessage); message CM_MOUSELEAVE;
  1249. procedure NCHitTest(var Message : TWMNCHitTest); message WM_NCHITTEST;
  1250. procedure NCMouseDown(var Message : TWMNCLBUTTONDOWN); message WM_NCLBUTTONDOWN;
  1251. procedure NCMouseUp(var Message : TWMNCLBUTTONUP); message WM_NCLBUTTONUP;
  1252. procedure NCMouseDblClick(var Message : TWMNCLButtonDblClk); message WM_NCLBUTTONDBLCLK;
  1253. procedure WMNCPaint(var Message : TWMNCPaint); message WM_NCPAINT;
  1254. procedure WMNCCalcSize(var Message : TWMNCCalcSize); message WM_NCCALCSIZE;
  1255. procedure WMNCACTIVATE(var Message : TWMNCActivate); message WM_NCACTIVATE;
  1256. procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;
  1257. procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  1258. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  1259. procedure CMTextChanged(var Message: TWmNoParams); message CM_TEXTCHANGED;
  1260. procedure Paint; override;
  1261. procedure SetName(const Value: TComponentName); override;
  1262. property FillGradient : Boolean index 0 read FGradientFill write SetBools default True;
  1263. property FullRepaint: Boolean index 1 read FFullRepaint write SetBools default True;
  1264. property TitleShow : Boolean index 2 read FShowHeader write SetBools default True;
  1265. property Minimized : Boolean index 3 read FMinimized write SetBools default False;
  1266. property Maximized : Boolean index 4 read FMaximized write SetBools default False;
  1267. property TitleShadowOnMoseEnter : Boolean index 5 read FTitleShadowOnMouseEnter write SetBools default True;
  1268. property TitleFillGradient : Boolean index 6 read FTitleGradient write SetBools default True;
  1269. property Movable : Boolean index 7 read FMovable write SetBools default False;
  1270. property Sizable : Boolean index 8 read FSizable write SetBools default False;
  1271. property ShowBorder : Boolean index 9 read FShowBorder write SetBools default True;
  1272. property Animation : Boolean index 10 read FAnimation write SetBools default True;
  1273. property BGImageTransparent : Boolean index 11 read FBGImageTransparent write SetBools default True;
  1274. property TitleImageTransparent : Boolean index 12 read FTitleImageTransparent write SetBools default True;
  1275. property FillDirection : TFillDirection read FFillDirection write SetFillDirection;
  1276. property Caption : String read FCaption write SetCaption;
  1277. property TitleFont : TFont read FTitleFont write SetTitleFont;
  1278. property TitleHeight : Integer read FTitleHeight write SetTitleHeight default 30;
  1279. property TitleAlignment : TAlignment read FTitleAlignment write SetTitleAlignment;
  1280. property ColorStart : TColor index 0 read FStartColor write SetColors default DefaultColorStart;
  1281. property ColorEnd : TColor index 1 read FEndColor write SetColors default DefaultColorStop;
  1282. property TitleColorStart : TColor index 2 read FTitleStartColor write SetColors default DefaultTitleColorStart;
  1283. property TitleColorEnd : TColor index 3 read FTitleEndColor write SetColors default DefaultTitleColorEnd;
  1284. property TitleColor : TColor index 4 read FTitleColor write SetColors default clWhite;
  1285. property TitleBtnBorderColor: TColor index 5 read FTitleBtnBorderColor write SetColors default DefaultBorderColor;
  1286. property TitleBtnBGColor: TColor index 6 read FTitleBtnBGColor write SetColors default DefaultBackdropColor;
  1287. property ColorBorder : TColor index 7 read FBorderColor write SetColors default DefaultBorderColor;
  1288. property TitleImage : TBitmap read FTitleImage write SetTitleImage;
  1289. property TitleFillDirect : TFillDirection read FTitleFillDirect write SetTitleFillDirect;
  1290. property TitleImageAlign : TTitleImageAlign read FTitleImageAlign write SetTitleImageAlign;
  1291. property TitleButtons : TTitleButtons read FTitleButtons write SetTitleButtons;
  1292. property TitleBtnStyle: TTitleButtonsStyle read FTitleButtonsStyle write SetTitleButtonsStyle default tbsRectangle;
  1293. property TitleBtnBorderSize: Integer read FTitleBtnBorderSize write SetTitleBtnBorderSize default 1;
  1294. property DefaultHeight : Integer read FDefaultHeight write SetDefaultHeight default 100;
  1295. property PanelCorner : TPanelCorners read FPanelCorner write SetPanelCorner default [];
  1296. property BGImage : TBitmap read FBGImage write SetBGImage;
  1297. property BGImageAlign : TBGImageAlign read FBGImageAlign write SetBGImageAlign;
  1298. property AfterMinimized : TAfterSizeChanged read FAfterMinimized write FAfterMinimized;
  1299. property AfterMaximized : TAfterSizeChanged read FAfterMaximized write FAfterMaximized;
  1300. property BeforeMove : TNotifyEvent read FBeforeMoving write FBeforeMoving;
  1301. property AfterMove : TNotifyEvent read FAfterMoving write FAfterMoving;
  1302. property AfterClose : TNotifyEvent read FAfterClose write FAfterClose;
  1303. property OnTitleClick : TNotifyEvent read FOnTitleClick write FOnTitleClick;
  1304. property OnTitleDblClick : TNotifyEvent read FOnTitleDblClick write FOnTitleDblClick;
  1305. property OnTitleMouseDown : TMouseEvent read FOnTitleMouseDown write FOnTitleMouseDown;
  1306. property OnTitleMouseUp : TMouseEvent read FOnTitleMouseUp write FOnTitleMouseUp;
  1307. property OnTitleMouseEnter: TNotifyEvent read FOnTitleMouseEnter write FOnTitleMouseEnter;
  1308. property OnTitleMouseExit : TNotifyEvent read FOnTitleMouseExit write FOnTitleMouseExit;
  1309. property OnMouseEnter : TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  1310. property OnMouseExit : TNotifyEvent read FOnMouseExit write FOnMouseExit;
  1311. public
  1312. constructor Create(AOwner: TComponent); override;
  1313. destructor Destroy; override;
  1314. end;
  1315. { TDefineButton }
  1316. TDefineButton = class(TVersionControl)
  1317. private
  1318. FOnMouseEnter: TNotifyEvent;
  1319. FOnMouseLeave: TNotifyEvent;
  1320. FTransparent: TTransparentMode;
  1321. FModalResult: TModalResult;
  1322. TextBounds: TRect;
  1323. GlyphPos: TPoint;
  1324. FNumGlyphs: TNumGlyphs;
  1325. fColorDown: TColor;
  1326. FColorBorder: TColor;
  1327. FColorShadow: TColor;
  1328. fColorFocused: TColor;
  1329. FGroupIndex: Integer;
  1330. FGlyph: TBitmap;
  1331. FDown: Boolean;
  1332. FDragging: Boolean;
  1333. FAllowAllUp: Boolean;
  1334. FLayout: TButtonLayout;
  1335. FSpacing: Integer;
  1336. FMargin: Integer;
  1337. FMouseIn: Boolean;
  1338. FDefault: Boolean;
  1339. fHasFocusFrame: boolean;
  1340. fColorFlat: TColor;
  1341. FTransBorder: Boolean;
  1342. FFoisChange: Boolean;
  1343. FAutoColor: TColor;
  1344. FAutoStyle: TFontStyles;
  1345. procedure SetColors(Index: Integer; Value: TColor);
  1346. procedure UpdateExclusive;
  1347. procedure SetGlyph(Value: TBitmap);
  1348. procedure SetNumGlyphs(Value: TNumGlyphs);
  1349. procedure SetDown(Value: Boolean);
  1350. procedure SetAllowAllUp(Value: Boolean);
  1351. procedure SetGroupIndex(Value: Integer);
  1352. procedure SetLayout(Value: TButtonLayout);
  1353. procedure SetSpacing(Value: Integer);
  1354. procedure SetMargin(Value: Integer);
  1355. procedure UpdateTracking;
  1356. procedure SetDefault(const Value: Boolean);
  1357. procedure SetTransparent (const Value: TTransparentMode);
  1358. procedure SetTransBorder(const Value: Boolean);
  1359. procedure SetFoisChange(const Value: Boolean);
  1360. procedure SetAutoStyle(const Value: TFontStyles);
  1361. function GetMouseIn: Boolean;
  1362. protected
  1363. FState: TButtonState;
  1364. function GetPalette: HPALETTE; override;
  1365. procedure Loaded; override;
  1366. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  1367. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  1368. procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
  1369. procedure WMKeyUp(var Message: TWMKeyUp); message WM_KEYUP;
  1370. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  1371. procedure WMMove(var Message: TWMMove); message WM_MOVE;
  1372. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  1373. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  1374. procedure WMLButtonDblClk(var Message: TWMLButtonDown); message WM_LBUTTONDBLCLK;
  1375. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  1376. procedure CMButtonPressed(var Message: TMessage); message CM_BUTTONPRESSED;
  1377. procedure CMDialogKey(var Message: TCMDialogKey); message CM_DIALOGKEY;
  1378. procedure CMDialogChar(var Message: TCMDialogChar); message CM_DIALOGCHAR;
  1379. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  1380. procedure CMTextChanged(var Message: TMessage); message CM_TEXTCHANGED;
  1381. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  1382. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  1383. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1384. procedure MouseMove (Shift: TShiftState; X, Y: Integer); override;
  1385. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1386. procedure Paint; override;
  1387. procedure SetName(const Value: TComponentName); override;
  1388. procedure MouseEnter;
  1389. procedure MouseLeave;
  1390. property Transparent: TTransparentMode read FTransparent write SetTransparent default tmNone;
  1391. property HasFocusFrame:boolean read fHasFocusFrame write fHasFocusFrame default true;
  1392. property Default: Boolean read FDefault write SetDefault default False;
  1393. property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default False;
  1394. property ColorFocused: TColor index 0 read fColorFocused write SetColors default DefaultFocusedColor;
  1395. property ColorDown: TColor index 1 read fColorDown write SetColors default DefaultDownColor;
  1396. property ColorBorder: TColor index 2 read FColorBorder write SetColors default DefaultBorderColor;
  1397. property ColorShadow: TColor index 3 read FColorShadow write SetColors default DefaultShadowColor;
  1398. property ColorFlat: TColor index 4 read fColorFlat write SetColors default DefaultFlatColor;
  1399. property FoisColor: TColor index 5 read FAutoColor write SetColors default DefaultFoisColor;
  1400. property TransBorder: Boolean read FTransBorder write SetTransBorder default false;
  1401. property FoisChange: Boolean read FFoisChange write SetFoisChange default true;
  1402. property FoisStyle: TFontStyles read FAutoStyle write SetAutoStyle default [fsBold];
  1403. property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
  1404. property Down: Boolean read FDown write SetDown default False;
  1405. property Glyph: TBitmap read FGlyph write SetGlyph;
  1406. property Layout: TButtonLayout read FLayout write SetLayout default blGlyphTop;
  1407. property Margin: Integer read FMargin write SetMargin default -1;
  1408. property NumGlyphs: TNumGlyphs read FNumGlyphs write SetNumGlyphs default 1;
  1409. property TabStop default true;
  1410. property Spacing: Integer read FSpacing write SetSpacing default 4;
  1411. property ModalResult: TModalResult read FModalResult write FModalResult default 0;
  1412. property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
  1413. property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
  1414. property MouseIn: Boolean read GetMouseIn;
  1415. public
  1416. constructor Create(AOwner: TComponent); override;
  1417. destructor Destroy; override;
  1418. procedure Click; override;
  1419. end;
  1420. { TDefinePanel }
  1421. TDefinePanel = class(TVersionCtrlExt)
  1422. private
  1423. FAutoSizeDocking: Boolean;
  1424. FTransparent: Boolean;
  1425. FColorBorder: TColor;
  1426. FBackgropStartColor: TColor;
  1427. FBackgropStopColor: TColor;
  1428. FBackgropOrien: TFillDirection;
  1429. FStyleFace: TStyleFace;
  1430. FAlignment: TAlignment;
  1431. FLocked: Boolean;
  1432. FFullRepaint: Boolean;
  1433. FParentBackgroundSet: Boolean;
  1434. FTransBorder: boolean;
  1435. procedure SetTransparent(Value: Boolean);
  1436. procedure SetFillDirect(Value: TFillDirection);
  1437. procedure SetStyleFace(Value: TStyleFace);
  1438. procedure SetAlignment(Value: TAlignment);
  1439. procedure SetTransBorder(Value: boolean);
  1440. protected
  1441. procedure Paint; override;
  1442. procedure SetColors(Index: Integer; Value: TColor); virtual;
  1443. procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;
  1444. procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  1445. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  1446. procedure CMTextChanged(var Message: TWmNoParams); message CM_TEXTCHANGED;
  1447. procedure CMDockClient(var Message: TCMDockClient); message CM_DOCKCLIENT;
  1448. procedure SetParentBackground(Value: Boolean); override;
  1449. procedure CreateParams(var Params: TCreateParams); override;
  1450. procedure AdjustClientRect(var Rect: TRect); override;
  1451. function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
  1452. property Transparent: Boolean read FTransparent write SetTransparent default false;
  1453. property TransBorder: boolean read FTransBorder write SetTransBorder default false;
  1454. property Alignment: TAlignment read FAlignment write SetAlignment default taCenter;
  1455. property Locked: Boolean read FLocked write FLocked default False;
  1456. property FullRepaint: Boolean read FFullRepaint write FFullRepaint default True;
  1457. property ColorBorder: TColor index 0 read FColorBorder write SetColors default DefaultBorderColor;
  1458. property BackgropStartColor: TColor index 1 read FBackgropStartColor write SetColors default DefaultColorStart;
  1459. property BackgropStopColor: TColor index 2 read FBackgropStopColor write SetColors default DefaultColorStop;
  1460. property BackgropOrien: TFillDirection read FBackgropOrien write SetFillDirect default fdLeftToRight;
  1461. property StyleFace: TStyleFace read FStyleFace write SetStyleFace default fsDefault;
  1462. property Color default clBtnFace;
  1463. public
  1464. constructor Create(AOwner: TComponent); override;
  1465. function GetControlsAlignment: TAlignment; override;
  1466. property ParentBackground stored FParentBackgroundSet;
  1467. end;
  1468. { TDefineLabel }
  1469. TDefineLabel = class(TDefinePanel)
  1470. private
  1471. FTicketSpace: Integer;
  1472. FTicket: TDefineTicket;
  1473. FTicketPosition: TTicketPosition;
  1474. protected
  1475. procedure Loaded; override;
  1476. procedure NewAdjustHeight;
  1477. procedure SetTicketPosition(const Value: TTicketPosition);
  1478. procedure SetLabelSpacing(const Value: Integer);
  1479. procedure SetName(const Value: TComponentName); override;
  1480. procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
  1481. procedure CMVisiblechanged(var Message: TMessage); message CM_VISIBLECHANGED;
  1482. procedure CMBidimodechanged(var Message: TMessage); message CM_BIDIMODECHANGED;
  1483. procedure SetParent(AParent: TWinControl); override;
  1484. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  1485. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  1486. procedure SetupInternalLabel;
  1487. property Ticket: TDefineTicket read FTicket;
  1488. property TicketPosition: TTicketPosition read FTicketPosition write SetTicketPosition default poLeft;
  1489. property TicketSpace: Integer read FTicketSpace write SetLabelSpacing default 3;
  1490. public
  1491. constructor Create(AOwner: TComponent); override;
  1492. procedure SetBounds(ALeft, ATop, AWidth, AHeight: Integer);override;
  1493. end;
  1494. { TDefineProgressBar }
  1495. TDefineProgressBar = class(TVersionGraphic)
  1496. private
  1497. FTransparent: Boolean;
  1498. FSmooth: Boolean;
  1499. FUseAdvColors: Boolean;
  1500. FAdvColorBorder: TAdvColors;
  1501. FOrientation: TProgressBarOrientation;
  1502. FElementWidth: Integer;
  1503. FElementColor: TColor;
  1504. FBorderColor: TColor;
  1505. FPosition: Integer;
  1506. FMin: Integer;
  1507. FMax: Integer;
  1508. FStep: Integer;
  1509. procedure SetMin (Value: Integer);
  1510. procedure SetMax (Value: Integer);
  1511. procedure SetPosition (Value: Integer);
  1512. procedure SetStep (Value: Integer);
  1513. procedure SetColors (Index: Integer; Value: TColor);
  1514. procedure SetAdvColors (Index: Integer; Value: TAdvColors);
  1515. procedure SetUseAdvColors (Value: Boolean);
  1516. procedure SetOrientation (Value: TProgressBarOrientation);
  1517. procedure SetSmooth (Value: Boolean);
  1518. procedure CheckBounds;
  1519. procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
  1520. procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  1521. procedure SetTransparent (const Value: Boolean);
  1522. protected
  1523. procedure CalcAdvColors;
  1524. procedure DrawElements;
  1525. procedure Paint; override;
  1526. {$IFDEF DFS_COMPILER_4_UP}
  1527. procedure SetBiDiMode(Value: TBiDiMode); override;
  1528. property Anchors;
  1529. property BiDiMode write SetBidiMode;
  1530. property Constraints;
  1531. property DragKind;
  1532. property ParentBiDiMode;
  1533. property OnEndDock;
  1534. property OnStartDock;
  1535. {$ENDIF}
  1536. property Transparent: Boolean read FTransparent write SetTransparent default false;
  1537. property Color default DefaultFlatColor;
  1538. property ColorElement: TColor index 0 read FElementColor write SetColors default $00996633;
  1539. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  1540. property AdvColorBorder: TAdvColors index 0 read FAdvColorBorder write SetAdvColors default 50;
  1541. property UseAdvColors: Boolean read FUseAdvColors write SetUseAdvColors default false;
  1542. property Orientation: TProgressBarOrientation read FOrientation write SetOrientation default pbHorizontal;
  1543. property Min: Integer read FMin write SetMin;
  1544. property Max: Integer read FMax write SetMax;
  1545. property Position: Integer read FPosition write SetPosition default 0;
  1546. property Step: Integer read FStep write SetStep default 10;
  1547. property Smooth: Boolean read FSmooth write SetSmooth default false;
  1548. public
  1549. constructor Create (AOwner: TComponent); override;
  1550. procedure StepIt;
  1551. procedure StepBy (Delta: Integer);
  1552. end;
  1553. TDefineTitlebar = class(TVersionControl)
  1554. private
  1555. FForm: TCustomForm;
  1556. FWndProcInstance: Pointer;
  1557. FDefProc: LongInt;
  1558. FActive: Boolean;
  1559. FDown: Boolean;
  1560. FOldX, FOldY: Integer;
  1561. FActiveTextColor: TColor;
  1562. FInactiveTextColor: TColor;
  1563. FTitlebarColor: TColor;
  1564. FOnActivate: TNotifyEvent;
  1565. FOnDeactivate: TNotifyEvent;
  1566. procedure FormWndProc(var Message: TMessage);
  1567. procedure DoActivateMessage(var Message: TWMActivate);
  1568. procedure DoActivation;
  1569. procedure DoDeactivation;
  1570. procedure SetActiveTextColor(Value: TColor);
  1571. procedure SetInactiveTextColor(Value: TColor);
  1572. procedure SetTitlebarColor(Value: TColor);
  1573. procedure CMFontChanged (var Message: TMessage); message CM_FONTCHANGED;
  1574. procedure CMTextChanged (var Message: TMessage); message CM_TEXTCHANGED;
  1575. protected
  1576. procedure Loaded; override;
  1577. procedure Paint; override;
  1578. procedure SetParent(AParent: TWinControl); override;
  1579. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1580. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  1581. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1582. property ActiveTextColor: TColor read FActiveTextColor write SetActiveTextColor;
  1583. property InactiveTextColor: TColor read FInactiveTextColor write SetInactiveTextColor;
  1584. property TitlebarColor: TColor read FTitlebarColor write SetTitlebarColor;
  1585. property OnActivate: TNotifyEvent read FOnActivate write FOnActivate;
  1586. property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate;
  1587. public
  1588. { Public declarations }
  1589. constructor Create(AOwner: TComponent); override;
  1590. destructor Destroy; override;
  1591. end;
  1592. { TDefineScrollbarThumb }
  1593. TDefineScrollbarThumb = class(TDefineButton)
  1594. private
  1595. FDown: Boolean;
  1596. FOldX, FOldY: Integer;
  1597. FTopLimit: Integer;
  1598. FBottomLimit: Integer;
  1599. protected
  1600. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1601. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  1602. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1603. public
  1604. constructor Create(AOwner: TComponent); override;
  1605. property Color;
  1606. end;
  1607. { TDefineScrollbarTrack }
  1608. TDefineScrollbarTrack = class (TVersionControl)
  1609. private
  1610. FThumb: TDefineScrollbarThumb;
  1611. FKind: TScrollBarKind;
  1612. FSmallChange: Integer;
  1613. FLargeChange: Integer;
  1614. FMin: Integer;
  1615. FMax: Integer;
  1616. FPosition: Integer;
  1617. procedure SetSmallChange(Value: Integer);
  1618. procedure SetLargeChange(Value: Integer);
  1619. procedure SetMin(Value: Integer);
  1620. procedure SetMax(Value: Integer);
  1621. procedure SetPosition(Value: Integer);
  1622. procedure SetKind(Value: TScrollBarKind);
  1623. procedure WMSize(var Message: TMessage); message WM_SIZE;
  1624. function ThumbFromPosition: Integer;
  1625. function PositionFromThumb: Integer;
  1626. procedure DoPositionChange;
  1627. procedure DoThumbHighlightColor(Value: TColor);
  1628. procedure DoThumbShadowColor(Value: TColor);
  1629. procedure DoThumbBorderColor(Value: TColor);
  1630. procedure DoThumbFocusedColor(Value: TColor);
  1631. procedure DoThumbDownColor(Value: TColor);
  1632. procedure DoThumbColor(Value: TColor);
  1633. procedure DoHScroll(var Message: TWMScroll);
  1634. procedure DoVScroll(var Message: TWMScroll);
  1635. procedure DoEnableArrows(var Message: TMessage);
  1636. procedure DoGetPos(var Message: TMessage);
  1637. procedure DoGetRange(var Message: TMessage);
  1638. procedure DoSetPos(var Message: TMessage);
  1639. procedure DoSetRange(var Message: TMessage);
  1640. procedure DoKeyDown(var Message: TWMKeyDown);
  1641. protected
  1642. public
  1643. constructor Create(AOwner: TComponent); override;
  1644. destructor Destroy; override;
  1645. procedure Paint; override;
  1646. published
  1647. property Align;
  1648. property Color;
  1649. property ParentColor;
  1650. property Min: Integer read FMin write SetMin;
  1651. property Max: Integer read FMax write SetMax;
  1652. property SmallChange: Integer read FSmallChange write SetSmallChange;
  1653. property LargeChange: Integer read FLargeChange write SetLargeChange;
  1654. property Position: Integer read FPosition write SetPosition;
  1655. property Kind: TScrollBarKind read FKind write SetKind;
  1656. property Version;
  1657. end;
  1658. { TDefineScrollbarButton }
  1659. TDefineScrollbarButton = class (TDefineButton)
  1660. private
  1661. FNewDown: Boolean;
  1662. FTimer: TTimer;
  1663. FOnDown: TNotifyEvent;
  1664. procedure DoTimer(Sender: TObject);
  1665. protected
  1666. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1667. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  1668. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  1669. public
  1670. constructor Create(AOwner: TComponent); override;
  1671. destructor Destroy; override;
  1672. published
  1673. property Align;
  1674. property OnDown: TNotifyEvent read FOnDown write FOnDown;
  1675. property Version;
  1676. end;
  1677. { TDefineScrollbar }
  1678. TFlatOnScroll = procedure (Sender: TObject; ScrollPos: Integer) of object;
  1679. TDefineScrollbar = class(TVersionControl)
  1680. private
  1681. FTrack: TDefineScrollbarTrack;
  1682. FBtnOne: TDefineScrollbarButton;
  1683. FBtnTwo: TDefineScrollbarButton;
  1684. FMin: Integer;
  1685. FMax: Integer;
  1686. FSmallChange: Integer;
  1687. FLargeChange: Integer;
  1688. FPosition: Integer;
  1689. FKind: TScrollBarKind;
  1690. FButtonHighlightColor: TColor;
  1691. FButtonShadowColor: TColor;
  1692. FButtonBorderColor: TColor;
  1693. FButtonFocusedColor: TColor;
  1694. FButtonDownColor: TColor;
  1695. FButtonColor: TColor;
  1696. FThumbHighlightColor: TColor;
  1697. FThumbShadowColor: TColor;
  1698. FThumbBorderColor: TColor;
  1699. FThumbFocusedColor: TColor;
  1700. FThumbDownColor: TColor;
  1701. FThumbColor: TColor;
  1702. FOnScroll: TFlatOnScroll;
  1703. procedure SetSmallChange(Value: Integer);
  1704. procedure SetLargeChange(Value: Integer);
  1705. procedure SetMin(Value: Integer);
  1706. procedure SetMax(Value: Integer);
  1707. procedure SetPosition(Value: Integer);
  1708. procedure SetKind(Value: TScrollBarKind);
  1709. procedure SetButtonHighlightColor(Value: TColor);
  1710. procedure SetButtonShadowColor(Value: TColor);
  1711. procedure SetButtonBorderColor(Value: TColor);
  1712. procedure SetButtonFocusedColor(Value: TColor);
  1713. procedure SetButtonDownColor(Value: TColor);
  1714. procedure SetButtonColor(Value: TColor);
  1715. procedure SetThumbHighlightColor(Value: TColor);
  1716. procedure SetThumbShadowColor(Value: TColor);
  1717. procedure SetThumbBorderColor(Value: TColor);
  1718. procedure SetThumbFocusedColor(Value: TColor);
  1719. procedure SetThumbDownColor(Value: TColor);
  1720. procedure SetThumbColor(Value: TColor);
  1721. procedure BtnOneClick(Sender: TObject);
  1722. procedure BtnTwoClick(Sender: TObject);
  1723. procedure EnableBtnOne(Value: Boolean);
  1724. procedure EnableBtnTwo(Value: Boolean);
  1725. protected
  1726. procedure DoScroll;
  1727. procedure WMSize(var Message: TWMSize); message WM_SIZE;
  1728. procedure CNHScroll(var Message: TWMScroll); message WM_HSCROLL;
  1729. procedure CNVScroll(var Message: TWMScroll); message WM_VSCROLL;
  1730. procedure SBMEnableArrows(var Message: TMessage); message SBM_ENABLE_ARROWS;
  1731. procedure SBMGetPos(var Message: TMessage); message SBM_GETPOS;
  1732. procedure SBMGetRange(var Message: TMessage); message SBM_GETRANGE;
  1733. procedure SBMSetPos(var Message: TMessage); message SBM_SETPOS;
  1734. procedure SBMSetRange(var Message: TMessage); message SBM_SETRANGE;
  1735. procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
  1736. property Min: Integer read FMin write SetMin default 0;
  1737. property Max: Integer read FMax write SetMax default 100;
  1738. property SmallChange: Integer read FSmallChange write SetSmallChange default 1;
  1739. property LargeChange: Integer read FLargeChange write SetLargeChange default 1;
  1740. property Position: Integer read FPosition write SetPosition default 0;
  1741. property Kind: TScrollBarKind read FKind write SetKind default sbVertical;
  1742. property OnScroll: TFlatOnScroll read FOnScroll write FOnScroll;
  1743. property ButtonHighlightColor: TColor read FButtonHighlightColor write SetButtonHighlightColor;
  1744. property ButtonShadowColor: TColor read FButtonShadowColor write SetButtonShadowColor;
  1745. property ButtonBorderColor: TColor read FButtonBorderColor write SetButtonBorderColor;
  1746. property ButtonFocusedColor: TColor read FButtonFocusedColor write SetButtonFocusedColor;
  1747. property ButtonDownColor: TColor read FButtonDownColor write SetButtonDownColor;
  1748. property ButtonColor: TColor read FButtonColor write SetButtonColor;
  1749. property ThumbHighlightColor: TColor read FThumbHighlightColor write SetThumbHighlightColor;
  1750. property ThumbShadowColor: TColor read FThumbShadowColor write SetThumbShadowColor;
  1751. property ThumbBorderColor: TColor read FThumbBorderColor write SetThumbBorderColor;
  1752. property ThumbFocusedColor: TColor read FThumbFocusedColor write SetThumbFocusedColor;
  1753. property ThumbDownColor: TColor read FThumbDownColor write SetThumbDownColor;
  1754. property ThumbColor: TColor read FThumbColor write SetThumbColor;
  1755. public
  1756. constructor Create(AOwner: TComponent); override;
  1757. destructor Destroy; override;
  1758. end;
  1759. { TDefineGauge }
  1760. TDefineGauge = class(TVersionGraphic)
  1761. private
  1762. FTransparent: Boolean;
  1763. FUseAdvColors: Boolean;
  1764. FAdvColorBorder: TAdvColors;
  1765. FBarColor, FBorderColor: TColor;
  1766. FMinValue, FMaxValue, FProgress: LongInt;
  1767. FShowText: Boolean;
  1768. fTextFront: TCaption;
  1769. fTextAfter: TCaption;
  1770. fColorStop: TColor;
  1771. fColorStart: TColor;
  1772. fStyleBars: TStyleOrien;
  1773. fStyleFace: TStyleFace;
  1774. procedure SetShowText(Value: Boolean);
  1775. procedure SetMinValue(Value: Longint);
  1776. procedure SetMaxValue(Value: Longint);
  1777. procedure SetProgress(Value: Longint);
  1778. procedure SetColors (Index: Integer; Value: TColor);
  1779. procedure SetAdvColors (Index: Integer; Value: TAdvColors);
  1780. procedure SetUseAdvColors (Value: Boolean);
  1781. procedure CMSysColorChange (var Message: TMessage); message CM_SYSCOLORCHANGE;
  1782. procedure CMParentColorChanged (var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  1783. procedure SetTransparent (const Value: Boolean);
  1784. procedure SetTextFront(const Value: TCaption);
  1785. procedure SetTextAfter(const Value: TCaption);
  1786. procedure SetStyleOrien(const Value: TStyleOrien);
  1787. procedure SetStyleFace(const Value: TStyleFace);
  1788. protected
  1789. procedure CalcAdvColors;
  1790. procedure Paint; override;
  1791. {$IFDEF DFS_COMPILER_4_UP}
  1792. procedure SetBiDiMode(Value: TBiDiMode); override;
  1793. property Anchors;
  1794. property BiDiMode write SetBidiMode;
  1795. property Constraints;
  1796. property DragKind;
  1797. property ParentBiDiMode;
  1798. property OnEndDock;
  1799. property OnStartDock;
  1800. {$ENDIF}
  1801. property AdvColorBorder: TAdvColors index 0 read FAdvColorBorder write SetAdvColors default 50;
  1802. property Transparent: Boolean read FTransparent write SetTransparent default false;
  1803. property UseAdvColors: Boolean read FUseAdvColors write SetUseAdvColors default False;
  1804. property StyleFace: TStyleFace read fStyleFace write SetStyleFace default DefaultStyleFace;
  1805. property StyleOrien: TStyleOrien read fStyleBars write SetStyleOrien default DefaultStyleHorizontal;
  1806. property StyleColorStart: TColor index 2 read fColorStart write SetColors default DefaultColorStart;
  1807. property StyleColorStop: TColor index 3 read fColorStop write SetColors default DefaultColorStop;
  1808. property Version;
  1809. property Color default $00E0E9EF;
  1810. property ColorBorder: TColor index 0 read FBorderColor write SetColors default DefaultBorderColor;
  1811. property BarColor: TColor index 1 read FBarColor write SetColors default $00996633;
  1812. property Min: Longint read FMinValue write SetMinValue default 0;
  1813. property Max: Longint read FMaxValue write SetMaxValue default 100;
  1814. property Progress: Longint read FProgress write SetProgress;
  1815. property ShowText: Boolean read FShowText write SetShowText default True;
  1816. property TextFront: TCaption read fTextFront write SetTextFront;
  1817. property TextAfter: TCaption read fTextAfter write SetTextAfter;
  1818. public
  1819. constructor Create(AOwner: TComponent); override;
  1820. end;
  1821. { TDefineGUIScrollBar }
  1822. TDefineGUIScrollBar = class(TVersionGraphic)
  1823. private
  1824. FOnDrawControl: TScrollDrawEvent;
  1825. FX,
  1826. FY,
  1827. FTrackPos: integer;
  1828. FIsStartChange: Boolean;
  1829. FOnChange: TNotifyEvent;
  1830. FLeftBtn,
  1831. FRightBtn,
  1832. FTrackBtn,
  1833. FSpaceLeft,
  1834. FSpaceRight: TRect;
  1835. FTimer: TTimer;
  1836. FDownPos: TScrollBarPos;
  1837. FCurPos: TScrollBarPos;
  1838. FLargeChange,
  1839. FSmallChange: TScrollBarInc;
  1840. FPageSize: integer;
  1841. FPosition,
  1842. FMin: Integer;
  1843. FMax: Integer;
  1844. FAutoHide: boolean;
  1845. FScrollcode: TIScrollCode;
  1846. FScrollMode: TScrollMode;
  1847. FScrollBarKind: TScrollBarKind;
  1848. FOnScroll: TScrollEvent;
  1849. FWaitInterval: Cardinal; //点击对象之后等待的时间间隔
  1850. fOnEnabledChange: TNotifyEvent;
  1851. FOwnerDraw: Boolean;
  1852. procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
  1853. procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
  1854. procedure SetMax(Value: Integer);
  1855. procedure SetMin(Value: Integer);
  1856. procedure SetPageSize(const Value: integer);
  1857. procedure SetLargeChange(const Value: TScrollBarInc);
  1858. procedure SetSmallChange(const Value: TScrollBarInc);
  1859. procedure SetScrollBarKind(const Value: TScrollBarKind);
  1860. procedure OnTimer(Sender: TObject);
  1861. procedure SetPosition(Value: integer);
  1862. procedure SetAutoHide(const Value: boolean);
  1863. protected
  1864. procedure AdjustTrack(Value: Integer);//相同于命名 SetTrackPos
  1865. procedure UpdateHideState; //尝试隐藏自身
  1866. procedure UpdateEnabledState;//更新可用状态
  1867. Function GetSliderRect: TRect;
  1868. Function GetDrawStateBy(const Typ: TDrawScrollBar): TButtonState;
  1869. function CanShowTrack: Boolean;//当 ScrollBar 可视范围太小的时候,必须屏蔽 Track 的显示
  1870. Function GetMinTrackSize: integer;//返回 Track 许可的最小大小
  1871. procedure Changed;
  1872. Function GetValidSize: integer;//获取用于计算的参数 FMax - FMin - FPageSize ... - 1;
  1873. Function GetTrackPos: integer;//根据参数计算 Track 按钮的起始位置:
  1874. Function GetTrackSize: integer;//根据参数计算 Track 按钮的大小:
  1875. Function GetCurTrackSize: Integer;//速度更快的获取 Track 按钮的大小,依赖于 TRect 的计算:
  1876. Function GetSliderSize: integer;//简单计算滑动长度
  1877. procedure FreeTimer; //释放 TImer
  1878. procedure StartTimer(const Interval: Cardinal);//启动 Timer
  1879. procedure SetDownPos(const Value: TScrollBarPos); //设置鼠标左击对象
  1880. procedure SetCurPos(const value: TScrollBarPos); //设置当前鼠标指向对象
  1881. procedure DoMouseLeavePos(const Value: TScrollBarPos); //鼠标离开对象
  1882. procedure DoMouseEnterPos(const Value: TScrollBarPos);//鼠标进入对象
  1883. procedure DoMouseDownPos(const Value: TScrollBarPos);//鼠标左击对象
  1884. procedure DoMouseUpPos(const Value: TScrollBarPos); //鼠标释放左击对象
  1885. procedure Paint; override;//继承控件不要继承 Paint 事件
  1886. procedure DrawControl(const Typ: TDrawScrollBar; const R: TRect; const State: TButtonState); virtual; //继承这个 DrawControl 去画控件
  1887. procedure MouseDown(Button: TMouseButton; Shift: TShiftState; x, y: integer); override;
  1888. procedure MouseUp(Button: TMouseButton; Shift: TShiftState; x, y: integer); override;
  1889. procedure MouseMove(Shift: TShiftState; x, y: integer); override;
  1890. procedure UpdateScrollBarGUI; //更新控件各个状态的大小和位置
  1891. Function GetMousePos(const X, Y: integer): TScrollBarPos;//返回鼠标所在位置
  1892. procedure Scroll(Const Code:TIScrollCode;const Mode: TScrollMode);// 标准 Scroll
  1893. procedure DoAutoScroll(Const aCode:TIScrollCode; aScrollMode: TScrollMode); //自动 Scroll
  1894. property OnDrawControl: TScrollDrawEvent read FOnDrawControl write FOnDrawControl;
  1895. property OwnerDraw: Boolean Read FOwnerDraw write FOwnerDraw;
  1896. property OnEnabledChange: TNotifyEvent read fOnEnabledChange write FOnEnabledChange;
  1897. property OnScroll: TScrollEvent read FOnScroll write FOnScroll;
  1898. property OnChange: TNotifyEvent read FOnChange write FOnChange;
  1899. property Position: integer read FPosition write SetPosition;
  1900. property ScrollBarKind: TScrollBarKind read FScrollBarKind write SetScrollBarKind default sbHorizontal;
  1901. property LargeChange: TScrollBarInc read FLargeChange write SetLargeChange ;
  1902. property SmallChange: TScrollBarInc read FSmallChange write SetSmallChange;
  1903. property Max: Integer read FMax write SetMax;
  1904. property Min: Integer read FMin write SetMin;
  1905. property PageSize: integer read FPageSize write SetPageSize;
  1906. public
  1907. property WaitInterval: Cardinal read FWaitInterval write FWaitInterval;
  1908. property AutoHide: boolean read FAutoHide write SetAutoHide ;
  1909. constructor Create(AOwner: TComponent); override;
  1910. destructor Destroy; override;
  1911. procedure DoScroll(Const aMode: TScrollMode; const StartChange: boolean; const ScrollSize: integer);
  1912. procedure DrawArrows(Cav: TCanvas; const v: TDrawArrow;const R: TRect);
  1913. Function IsVertical: Boolean; //为了编码的方便
  1914. end;
  1915. TDefineGUICtrlList = class;
  1916. TDefineGUICtrlString = Class(TStringList)
  1917. private
  1918. FMoving: Boolean;
  1919. FControl: TDefineGUICtrlList;
  1920. protected
  1921. procedure SetListControl(const aListControl:TDefineGUICtrlList);
  1922. public
  1923. procedure InsertObject(Index: Integer; const S: string;
  1924. AObject: TObject); override;
  1925. function AddObject(const S: string; AObject: TObject): Integer; override;
  1926. procedure SetTextStr(const Value: string); override;
  1927. procedure Put(Index: Integer; const S: string); override;
  1928. procedure Clear; override;
  1929. procedure Delete(Index: Integer); override;
  1930. procedure Move(CurIndex, NewIndex: Integer); override;
  1931. end;
  1932. { TDefineGUISelectList }
  1933. TDefineGUISelectList = class(TBits)
  1934. public
  1935. procedure ChangeSelect(const Value: integer);
  1936. procedure ChangeSelectSome(V1, V2: integer);
  1937. procedure Select(const Value: integer);
  1938. procedure UnSelect(const Value: integer);
  1939. procedure SelectAll;
  1940. procedure UnSelectAll;
  1941. procedure SelectSome(V1, V2: integer);
  1942. procedure UnSelectSome(V1, V2: integer);
  1943. end;
  1944. { TDefineGUICtrlSave }
  1945. TDefineGUICtrlSave = class(TVersionCtrlExt)
  1946. private
  1947. FBmp: TBitMap;
  1948. FKeyPage:TKeyFirst; //键盘改变页面枚举
  1949. FMousePage: TMouseChangePage; //鼠标改变页面枚举
  1950. FWheel:TListControlWheel;
  1951. FActiveItem: integer;
  1952. FDownItem, //鼠标点击项目
  1953. FMoveItem: integer;
  1954. FCtrlIsClear: Boolean;
  1955. FDownShift: TShiftState;
  1956. FBakList,
  1957. FSelectList: TDefineGUISelectList;
  1958. FMouseDown: boolean;
  1959. FMouseItem: integer; //鼠标指向的项目
  1960. FVBar: TDefineGUIScrollBar;
  1961. FCount,
  1962. FItemIndex,
  1963. FFocusItem, //获得焦点的项目
  1964. FTopIndex: integer; //顶部项目
  1965. FMultiSelect: boolean;
  1966. FRefreshing: boolean; //更新项目中.... ?
  1967. FItemHeight: integer; //项目高度
  1968. FWorkRect: TRect;
  1969. FOnItemClick: TListItemEvent;
  1970. FOwnerDraw: Boolean;
  1971. FOnItemDraw: TListItemDrawEvent;
  1972. FOnItemDlbClick: TListItemEvent;
  1973. //为了让 KeyDown 事件支持系统按键:
  1974. procedure CMFONTCHANGED(var msg: TMessage);message CM_FONTCHANGED;
  1975. procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
  1976. procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
  1977. procedure WMSIZE(var msg: TWMSIZE); message WM_SIZE;
  1978. procedure OnTimer(var Msg: TWMTimer); Message WM_TIMER;
  1979. procedure WMKILLFOCUS(var Message: TMessage); message WM_KILLFOCUS;
  1980. procedure WMSETFOCUS(var message: TMessage); message WM_SETFOCUS;
  1981. procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBKGND;
  1982. procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
  1983. procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
  1984. procedure SetMultiSelect(const Value: boolean);
  1985. procedure SetSelected(const index: integer; const Value: Boolean);
  1986. procedure SetItemHeight(const Value: integer); virtual;
  1987. procedure SetItemIndex(Value: integer);
  1988. procedure SetTopIndex(Value: integer);
  1989. procedure SetMouseItem(const Index: Integer);
  1990. procedure SetCount(const Value: Integer);
  1991. procedure SetActiveItem(const Value: integer);
  1992. procedure OnVbarScroll(Sender: TObject; const StartChange:boolean;
  1993. Code:TIScrollCode; Mode:TScrollMode;
  1994. const ChangeValue: integer);
  1995. procedure SetMouseChangePage(const Value: TMouseChangePage);
  1996. procedure SetOwnerDraw(const Value: Boolean);
  1997. procedure SetOnDrawScrollBar(const Value: TScrollDrawEvent);
  1998. function GetItemRect(const Index: integer): TRect;
  1999. function GetPageSize: integer;
  2000. function GetTopIndex: integer;
  2001. function GetOnDrawScrollBar: TScrollDrawEvent;
  2002. function GetSelected(const index: integer): Boolean;
  2003. protected
  2004. //以下两个函数为了处理"多行选择" 和 Ctrl 状态的:
  2005. procedure LoadBakSelectState;
  2006. procedure SaveBakSelectState;
  2007. //画内存,为了滚动显示效果:
  2008. procedure DrawBitMap(bmp: TBitmap; BeginItem, EndItem: integer);
  2009. procedure AdjustSee(value: integer);
  2010. procedure StartTimer(const ID, interval: integer);
  2011. procedure CloseTimer(const ID: integer);
  2012. procedure DrawItem(Cav: TCanvas; const Index: Integer;
  2013. const R: TRect; const State: TListItemStates);virtual;
  2014. procedure SetFocusItem(const Value: integer; const DoRePaint:boolean);
  2015. procedure SetMouseDownItem(const Value: Integer);
  2016. procedure SimpleSetItemIndex(Value: integer);
  2017. procedure OnVbarEnabledChange(Sender: TObject);
  2018. procedure ItemClick(const Index: integer); dynamic;
  2019. procedure Paint; Override;
  2020. procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  2021. X, Y: Integer); override;
  2022. procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
  2023. X, Y: Integer); override;
  2024. procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
  2025. procedure CreateParams(var Params: TCreateParams);Override;
  2026. procedure KeyDown(var Key: word; Shift: TShiftState); Override;
  2027. procedure KeyUp(var Key: Word; shift: TShiftState); override;
  2028. procedure DblClick; override ;
  2029. procedure Clear;
  2030. procedure UpdatePageSizeOfVbar;
  2031. procedure UpdateMax;
  2032. procedure UpdateTopIndex;
  2033. procedure UpdateWorkRect;
  2034. procedure BeginUpdate;
  2035. procedure EndUpdate;
  2036. //复制,滚动动画 DC
  2037. procedure CopyBit(const EndY, startY: Integer;const Source: HDC; forward: boolean);
  2038. procedure MouseEnterItem(const Index: integer); virtual;
  2039. procedure MouseLeaveItem(const Index: integer); virtual;
  2040. procedure MouseDownItem(const Index: integer); virtual;
  2041. procedure MouseUpItem(const Index: integer); virtual;
  2042. procedure CalcSizeOfWoekRect(var R: TRect); virtual;
  2043. procedure Add; virtual;
  2044. procedure Delete(Index: Integer); virtual;
  2045. procedure Insert(Index: integer); virtual;
  2046. procedure Move(const CurIndex, NewIndex: Integer); virtual;
  2047. procedure Put(const Index: integer); virtual;
  2048. function VbarCanSee: boolean;
  2049. Function ItemCanSee(const Index: integer): boolean;
  2050. Function IsNoStandardSize: Boolean; //result := WorkRect:客户区 Mod ItemHeight = 0 ;
  2051. Function GetItemRectEx(const VirtualTopIndex, index: integer): TRect;
  2052. property VBar: TDefineGUIScrollBar read FVBar;
  2053. property MultiSelect: boolean read FMultiSelect write SetMultiSelect ;
  2054. property OnDrawScrollBar: TScrollDrawEvent read GetOnDrawScrollBar write SetOnDrawScrollBar;
  2055. property OwnerDraw: Boolean Read FOwnerDraw write SetOwnerDraw;
  2056. property OnItemClick: TListItemEvent read FOnItemClick write FOnItemClick;
  2057. property OnItemDlbClick:TListItemEvent read FOnItemDlbClick write FOnItemDlbClick;
  2058. property TopIndex: integer read GetTopIndex write SetTopIndex ;
  2059. property ItemIndex: integer read FItemIndex write SetItemIndex ;
  2060. property WorkRect: TRect read FWorkRect;
  2061. property ItemHeight: integer read FItemHeight write SetItemHeight ;
  2062. property ItemRect[const Index: integer]: TRect read GetItemRect;
  2063. // GetPageSize 返回包含仅一半可视项目的项目
  2064. property PageSize:integer read GetPageSize;
  2065. property Selected[const Index: Integer]: boolean read GetSelected write SetSelected;
  2066. property ActiveItem: integer read FActiveItem write SetActiveItem;
  2067. property Count: Integer read FCount write SetCount;
  2068. property Refreshing : boolean read FRefreshing ;
  2069. property OnItemDraw: TListItemDrawEvent read FOnItemDraw write FOnItemDraw;
  2070. public
  2071. //该函数的计算忽略 X 座标
  2072. Function ItemAtY(const y: integer): integer;
  2073. //该函数的计算包含 X 座标
  2074. Function ItemAtPoint(const X, Y: integer): integer; virtual;
  2075. Function IsItem(const Index: Integer): boolean;
  2076. procedure ToSeeItem(Index: integer); //如果真的需要执行,并且执行成功那么返回 true
  2077. constructor Create(AOwner: TComponent); override;
  2078. destructor Destroy; override;
  2079. end;
  2080. { TDefineGUICtrlList }
  2081. TDefineGUICtrlList = class(TDefineGUICtrlSave)
  2082. private
  2083. FGUIStyle: TListControlGUI;
  2084. FItemBorderColor: TColor;
  2085. FItemSelectColor: TColor;
  2086. FItemBrightColor: TColor;
  2087. FItemColor: TColor;
  2088. FItemSpaceColor: TColor;
  2089. FMouseIn: Boolean;
  2090. FFocusColor: TColor;
  2091. FFlatColor: TColor;
  2092. procedure SetGUIStyle(const Value: TListControlGUI);
  2093. procedure SetColors(const Index:Integer;const Value: TColor);
  2094. function GetMouseIn: boolean;
  2095. protected
  2096. procedure CalcSizeOfWoekRect(var R: TRect); override;
  2097. procedure OnVBarDrawControl(Cav: TCanvas; const Typ: TDrawScrollBar;
  2098. const R: TRect; const State: TButtonState);
  2099. procedure Paint; override;
  2100. procedure DrawItem(Cav: TCanvas; const Index: Integer;
  2101. const R: TRect; const State: TListItemStates);override;
  2102. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  2103. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  2104. property MouseIn : boolean read GetMouseIn;
  2105. property GUIStyle : TListControlGUI read FGUIStyle write SetGUIStyle default lcgFlat;
  2106. property GUISelectColor : TColor index 0 read FItemSelectColor write SetColors default DefaultItemSelectColor;
  2107. property GUIBorderColor : TColor index 1 read FItemBorderColor write SetColors default DefaultBorderColor;
  2108. property GUIBrightColor : TColor index 2 read FItemBrightColor write SetColors default DefaultItemBrightColor;
  2109. property GUIColor : TColor index 3 read FItemColor write SetColors default DefaultItemColor;
  2110. property GUISpaceColor : TColor index 4 read FItemSpaceColor write SetColors default DefaultItemSpaceColor;
  2111. property GUIFocusedColor : TColor index 5 read FFocusColor write SetColors default clWhite;
  2112. property GUIFlatColor : TColor index 6 read FFlatColor write SetColors default DefaultFlatColor;
  2113. public
  2114. constructor Create(AOwner: TComponent); override;
  2115. destructor Destroy; override;
  2116. end;
  2117. { TDefineGUIListBox }
  2118. TDefineGUIListBox = class(TDefineGUICtrlList)
  2119. private
  2120. FAutoItemHeight: boolean;
  2121. FItems: TDefineGUICtrlString;
  2122. procedure SetItems(const Value: TStrings);
  2123. function GetItems: TStrings;
  2124. procedure CMSHOWINGCHANGED(var msg: TMessage); message CM_SHOWINGCHANGED;
  2125. procedure CMFONTCHANGED(var msg: TMessage);message CM_FONTCHANGED;
  2126. procedure SetAutoItemHeight(const Value: Boolean);
  2127. protected
  2128. procedure DrawItem(Cav: TCanvas; const Index: Integer;
  2129. const R: TRect; const State: TListItemStates);override;
  2130. procedure UpdateItemheight;
  2131. property AutoItemHeight: boolean read FAutoItemHeight write SetAutoItemHeight;
  2132. property Items: TStrings read GetItems write SetItems;
  2133. property TabStop default True;
  2134. public
  2135. property Selected;
  2136. constructor Create(AOwner: TComponent); override;
  2137. destructor Destroy; override;
  2138. Function GetCount: integer;
  2139. end;
  2140. { TDefineTreeView }
  2141. TDefineTreeView = class(TVersionTreeView)
  2142. private
  2143. FParentColor: Boolean;
  2144. FFocusedColor: TColor;
  2145. FBorderColor: TColor;
  2146. FFlatColor: TColor;
  2147. FMouseIn: Boolean;
  2148. FInterDrawing: boolean;
  2149. procedure SetColors(Index: Integer; Value: TColor);
  2150. procedure SetParentColor(Value: Boolean);
  2151. function GetItemsCount: Integer;
  2152. protected
  2153. procedure RedrawBorder(const Clip: HRGN = 0);
  2154. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  2155. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  2156. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  2157. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  2158. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  2159. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  2160. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  2161. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  2162. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  2163. procedure Loaded; override;
  2164. property ColorFocused: TColor index 0 read FFocusedColor write SetColors default clWhite;
  2165. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  2166. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  2167. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  2168. property ParentFont default True;
  2169. property AutoSize default False;
  2170. property Ctl3D default False;
  2171. property BorderStyle default bsNone;
  2172. public
  2173. constructor Create(AOwner: TComponent); override;
  2174. destructor Destroy; override;
  2175. property ItemsCount: Integer read GetItemsCount;
  2176. end;
  2177. { TDefineListView }
  2178. TDrawTitleEvent = procedure (Cnvs: TCanvas; Column: TListColumn;
  2179. Pressed: Boolean; R: TRect) of object;
  2180. TDefineListView = class(TVersionListView)
  2181. private
  2182. FHeaderHandle: HWND;
  2183. FHeaderInstance: Pointer;
  2184. FDefHeaderProc: Pointer;
  2185. FActiveSection: Integer;
  2186. FHeaderDown: Boolean;
  2187. FParentColor: Boolean;
  2188. FFocusedColor: TColor;
  2189. FBorderColor: TColor;
  2190. FFlatColor: TColor;
  2191. FMouseIn: Boolean;
  2192. FOnDrawTitle: TDrawTitleEvent;
  2193. FTitleFaceColor: TColor;
  2194. FTitleCheckColor: TColor;
  2195. FGroundPic: TPicture;
  2196. FGroundHas: Boolean;
  2197. FOnDrawBackground: TLVCustomDrawEvent;
  2198. FGroundStretch: Boolean;
  2199. FAllCheck: Boolean;
  2200. FTransparent: Boolean;
  2201. FTransBit: TBitmap;
  2202. procedure SetColors(Index: Integer; Value: TColor);
  2203. procedure SetParentColor(Value: Boolean);
  2204. function GetColumnCount: Integer;
  2205. function GetItemsCount: Integer;
  2206. procedure SetGroundPic(const Value: TPicture);
  2207. procedure SetGroundHas(const Value: Boolean);
  2208. function GetHeaderHeight: Integer;
  2209. procedure SetGroundStretch(const Value: Boolean);
  2210. procedure SetAllCheck(const Value: Boolean);
  2211. function GetListCount: integer;
  2212. function GetCheckCount: integer;
  2213. procedure SetTransparent(const Value: Boolean);
  2214. protected
  2215. FCheckInBox: Boolean;
  2216. procedure RedrawBorder(const Clip: HRGN = 0);
  2217. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  2218. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  2219. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  2220. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  2221. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  2222. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  2223. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  2224. procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  2225. procedure CMDesignHitTest(var Message: TCMDesignHitTest); message CM_DESIGNHITTEST;
  2226. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  2227. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  2228. procedure HeaderWndProc(var Message: TMessage);
  2229. procedure DrawTitle(Cnvs: TCanvas; Column: TListColumn; Active, Pressed: Boolean; R: TRect);
  2230. procedure DrawHeader(DC: HDC);
  2231. procedure WndProc(var Message: TMessage); override;
  2232. procedure DrawBackground(Sender: TCustomListView; const ARect: TRect; var DefaultDraw: Boolean);
  2233. procedure DrawTransparent(Sender: TCustomListView; const ARect: TRect; var DefaultDraw: Boolean);
  2234. procedure Loaded; override;
  2235. function GetHeaderSectionRect(Index: Integer): TRect;
  2236. property HeaderHeight: Integer read GetHeaderHeight;
  2237. property ColorFocused: TColor index 0 read FFocusedColor write SetColors default clWhite;
  2238. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  2239. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  2240. property ColorTitleFace: TColor index 3 read FTitleFaceColor write SetColors default DefaultTitleFaceColor;
  2241. property ColorTitleCheck: TColor index 4 read FTitleCheckColor write SetColors default DefaultTitleCheckColor;
  2242. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  2243. property GroundHas: Boolean read FGroundHas write SetGroundHas default false;
  2244. property GroundPic: TPicture read FGroundPic write SetGroundPic;
  2245. property GroundStretch: Boolean read FGroundStretch write SetGroundStretch default false;
  2246. property OnDrawBackground: TLVCustomDrawEvent read FOnDrawBackground write FOnDrawBackground;
  2247. property OnDrawTitle: TDrawTitleEvent read FOnDrawTitle write FOnDrawTitle;
  2248. property Transparent: Boolean read FTransparent write SetTransparent default false;
  2249. property ParentFont default True;
  2250. property AutoSize default False;
  2251. property Ctl3D default False;
  2252. property BorderStyle default bsNone;
  2253. property FlatScrollBars default true;
  2254. public
  2255. constructor Create(AOwner: TComponent); override;
  2256. destructor Destroy; override;
  2257. property AllCheck: Boolean read FAllCheck write SetAllCheck default false;
  2258. property ColCount: Integer read GetColumnCount;
  2259. property Count: integer read GetListCount;
  2260. property CheckCount: integer read GetCheckCount;
  2261. property ItemCount: Integer read GetItemsCount;
  2262. end;
  2263. { TDefineGridDraw }
  2264. TDefineGridDraw = class(TVersionDrawGrid)
  2265. private
  2266. FParentColor: Boolean;
  2267. FFocusColor: TColor;
  2268. FBorderColor: TColor;
  2269. FFlatColor: TColor;
  2270. FMouseIn: Boolean;
  2271. FLinesColor: TColor;
  2272. procedure SetColors(Index: Integer; Value: TColor);
  2273. procedure SetParentColor(Value: Boolean);
  2274. function GetMouseIn: boolean;
  2275. protected
  2276. procedure RedrawBorder (const Clip: HRGN = 0);
  2277. procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED;
  2278. procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
  2279. procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
  2280. procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
  2281. procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
  2282. procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
  2283. procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
  2284. procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
  2285. procedure CMParentColorChanged(var Message: TWMNoParams); message CM_PARENTCOLORCHANGED;
  2286. procedure DrawCell(ACol, ARow: Longint; ARect: TRect;AState: TGridDrawState); override;
  2287. property MouseIn:boolean read GetMouseIn;
  2288. property ColorFocused: TColor index 0 read FFocusColor write SetColors default clWhite;
  2289. property ColorBorder: TColor index 1 read FBorderColor write SetColors default DefaultBorderColor;
  2290. property ColorFlat: TColor index 2 read FFlatColor write SetColors default DefaultFlatColor;
  2291. property ColorLines: TColor index 3 read FLinesColor write SetColors default DefaultBorderColor;
  2292. property ParentColor: Boolean read FParentColor write SetParentColor default false;
  2293. public
  2294. constructor Create(AOwner: TComponent); override;
  2295. end;
  2296. { TDefineGridString}
  2297. TDefineGridString= class;
  2298. TDefineGridStrings = class(TStrings)
  2299. private
  2300. FGrid: TDefineGridString;
  2301. FIndex: Integer;
  2302. procedure CalcXY(Index: Integer; var X, Y: Integer);
  2303. protected
  2304. function Get(Index: Integer): string; override;
  2305. function GetCount: Integer; override;
  2306. function GetObject(Index: Integer): TObject; override;
  2307. procedure Put(Index: Integer; const S: string); override;
  2308. procedure PutObject(Index: Integer; AObject: TObject); override;
  2309. procedure SetUpdateState(Updating: Boolean); override;
  2310. public
  2311. constructor Create(AGrid: TDefineGridString; AIndex: Longint);
  2312. function Add(const S: string): Integer; override;
  2313. procedure Assign(Source: TPersistent); override;
  2314. procedure Clear; override;
  2315. procedure Delete(Index: Integer); override;
  2316. procedure Insert(Index: Integer; const S: string); override;
  2317. end;
  2318. TDefineGridString= class(TDefineGridDraw)
  2319. private
  2320. FData: Pointer;
  2321. FRows: Pointer;
  2322. FCols: Pointer;
  2323. FUpdating: Boolean;
  2324. FNeedsUpdating: Boolean;
  2325. FEditUpdate: Integer;
  2326. procedure DisableEditUpdate;
  2327. procedure EnableEditUpdate;
  2328. procedure Initialize;
  2329. procedure Update(ACol, ARow: Integer); reintroduce;
  2330. procedure SetUpdateState(Updating: Boolean);
  2331. function GetCells(ACol, ARow: Integer): string;
  2332. function GetCols(Index: Integer): TStrings;
  2333. function GetObjects(ACol, ARow: Integer): TObject;
  2334. function GetRows(Index: Integer): TStrings;
  2335. procedure SetCells(ACol, ARow: Integer; const Value: string);
  2336. procedure SetCols(Index: Integer; Value: TStrings);
  2337. procedure SetObjects(ACol, ARow: Integer; Value: TObject);
  2338. procedure SetRows(Index: Integer; Value: TStrings);
  2339. function EnsureColRow(Index: Integer; IsCol: Boolean): TDefineGridStrings;
  2340. function EnsureDataRow(ARow: Integer): Pointer;
  2341. protected
  2342. procedure ColumnMoved(FromIndex, ToIndex: Longint); override;
  2343. procedure DrawCell(ACol, ARow: Longint; ARect: TRect;AState: TGridDrawState); override;
  2344. function GetEditText(ACol, ARow: Longint): string; override;
  2345. procedure SetEditText(ACol, ARow: Longint; const Value: string); override;
  2346. procedure RowMoved(FromIndex, ToIndex: Longint); override;
  2347. public
  2348. constructor Create(AOwner: TComponent); override;
  2349. destructor Destroy; override;
  2350. property Cells[ACol, ARow: Integer]: string read GetCells write SetCells;
  2351. property Cols[Index: Integer]: TStrings read GetCols write SetCols;
  2352. property Objects[ACol, ARow: Integer]: TObject read GetObjects write SetObjects;
  2353. property Rows[Index: Integer]: TStrings read GetRows write SetRows;
  2354. end;
  2355. { TDeinePages }
  2356. TDefinePages = class (TVersionPages)
  2357. private
  2358. FCanvas : TControlCanvas; // canvas for drawing on with tabOwnerDraw
  2359. FImageList : TImageList; // link to a TImageList component
  2360. FOnDrawItem : TPageDrawItemEvent; // Owner draw event
  2361. FOnGlyphMap : TGlyphMapEvent; // glyph mapping event
  2362. FBorderColor : TColor;
  2363. FHotTrackTab : Integer;
  2364. FBorderRect : TRect;
  2365. FTabPosition : TPagesPosition;
  2366. FOwnerDraw : Boolean;
  2367. FStyle : TPagesStyle;
  2368. FTabTextAlignment : TAlignment;
  2369. // function PageIndexToWin (AIndex : Integer) : Integer;
  2370. function WinIndexToPage (AIndex : Integer) : Integer;
  2371. procedure SetGlyphs (Value : TImageList);
  2372. function GetMultiline : boolean;
  2373. procedure CNDrawItem (var Msg : TWMDrawItem); message CN_DRAWITEM;
  2374. procedure WMAdjasment (var Msg : TMessage); message TCM_ADJUSTRECT;
  2375. // procedure WMNCPaint (var Message : TWMNCPaint); message WM_NCPAINT;
  2376. procedure WMNCCalcSize (var Message : TWMNCCalcSize); message WM_NCCALCSIZE;
  2377. procedure WMPaint (var Message : TWMPaint); message WM_PAINT;
  2378. procedure WMMouseMove (var Message : TWMMouseMove); message WM_MOUSEMOVE;
  2379. procedure WMSIZE (var Message : TWMSIZE); message WM_SIZE;
  2380. procedure MouseLeave (var Message : TMessage); message CM_MOUSELEAVE;
  2381. procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
  2382. procedure WMSysColorChange (var Message: TMessage); message WM_SYSCOLORCHANGE;
  2383. procedure GlyphsChanged (Sender : TObject);
  2384. procedure SetTabPosition (Value : TPagesPosition);
  2385. procedure SetTabTextAlignment (Value : TAlignment);
  2386. procedure SetBorderColor (Value : TColor);
  2387. procedure SetStyle (Value : TPagesStyle);
  2388. procedure SetOwnerDraw (AValue : Boolean);
  2389. protected
  2390. procedure CreateParams (var Params: TCreateParams); override;
  2391. procedure CreateWnd; override;
  2392. procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); virtual;
  2393. procedure DrawItemInside (AIndex : Integer; ACanvas : TCanvas; ARect : TRect); virtual;
  2394. procedure DrawBorder (ACanvas : TCanvas); virtual;
  2395. procedure DrawTopTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  2396. procedure DrawBottomTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  2397. procedure DrawLeftTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  2398. procedure DrawRightTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  2399. procedure DrawHotTrackTab (ATabIndex : Integer; AHotTrack : Boolean);
  2400. procedure Loaded; override;
  2401. // for owner draw
  2402. property Canvas : TControlCanvas read FCanvas write FCanvas;
  2403. // republish Multiline as read only
  2404. property MultiLine : boolean read GetMultiline;
  2405. // link to TImageList
  2406. property ImageList : TImageList Read FImageList write SetGlyphs;
  2407. // owner draw event
  2408. property OnDrawItem : TPageDrawItemEvent read FOnDrawItem write FOnDrawItem;
  2409. // glyph map event
  2410. property OnGlyphMap : TGlyphMapEvent read FOnGlyphMap write FOnGlyphMap;
  2411. property OwnerDraw : Boolean read FOwnerDraw write SetOwnerDraw default False;
  2412. property ColorBorder : TColor read FBorderColor write SetBorderColor default DefaultBorderColor;
  2413. property TabPosition : TPagesPosition read FTabPosition write SetTabPosition;
  2414. property TabTextAlignment : TAlignment read FTabTextAlignment write SetTabTextAlignment;
  2415. property Style : TPagesStyle read FStyle write SetStyle;
  2416. public
  2417. procedure UpdateGlyphs; virtual;
  2418. constructor Create (AOwner : TComponent); override;
  2419. destructor Destroy; override;
  2420. end;
  2421. TDefineSheetBGStyle = (bgsNone, bgsGradient, bgsTileImage, bgsStrechImage);
  2422. TDefineSheet = class (TVersionSheet)
  2423. private
  2424. FCanvas : TControlCanvas;
  2425. FColor : TColor;
  2426. FGradientStartColor : TColor;
  2427. FGradientEndColor : TColor;
  2428. FGradientFillDir : TFillDirection;
  2429. FImageIndex : Integer;
  2430. FShowTabHint : Boolean;
  2431. FTabHint : String;
  2432. FBGImage : TBitmap;
  2433. FBGStyle : TDefineSheetBGStyle;
  2434. procedure SetColor (AValue : TColor);
  2435. procedure WMNCPaint (var Message : TWMNCPaint); message WM_NCPAINT;
  2436. procedure WMPaint (var Message : TWMPaint); message WM_PAINT;
  2437. procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
  2438. procedure SetImageIndex (AIndex : Integer);
  2439. procedure SetBGImage (AValue : TBitmap);
  2440. procedure SetBGStyle (AValue : TDefineSheetBGStyle);
  2441. procedure SetGradientStartColor (AValue : TColor);
  2442. procedure SetGradientEndColor (AValue : TColor);
  2443. procedure SetGradientFillDir (AValue : TFillDirection);
  2444. public
  2445. constructor Create(AOwner: TComponent); override;
  2446. destructor Destroy; override;
  2447. published
  2448. property Color : TColor read FColor write SetColor;
  2449. property ImageIndex : Integer read FImageIndex write SetImageIndex default -1;
  2450. property ShowTabHint : Boolean read FShowTabHint write FShowTabHint default False;
  2451. property TabHint : String read FTabHint write FTabHint;
  2452. property BGImage : TBitmap read FBGImage write SetBGImage;
  2453. property BGStyle : TDefineSheetBGStyle read FBGStyle write SetBGStyle;
  2454. property GradientStartColor : TColor read FGradientStartColor write SetGradientStartColor;
  2455. property GradientEndColor : TColor read FGradientEndColor write SetGradientEndColor;
  2456. property GradientFillDir : TFillDirection read FGradientFillDir write SetGradientFillDir;
  2457. end;
  2458. { TDefineBarcode }
  2459. TDefineBarcode = class(TVersionControl)
  2460. private
  2461. fText : string;
  2462. FModul : integer;
  2463. FRatio : double;
  2464. FCodeType : TDefineBarcodeType;
  2465. FRotateType : TDefineBarcodeRotation;
  2466. fBarHeight : Integer;
  2467. fBorderWidth : Byte;
  2468. fBarColor : TColor;
  2469. fBarTop : Byte;
  2470. fTypName : String;
  2471. fColor : TColor;
  2472. FShowText : boolean;
  2473. FCheckSum : boolean;
  2474. fCheckOdd : Boolean;
  2475. fTransparent : boolean;
  2476. fAutoSize : Boolean;
  2477. procedure SetModul(const Value:Integer);
  2478. procedure SetRotateType(const Value: TDefineBarcodeRotation);
  2479. procedure SetRatio(const Value: double);
  2480. procedure SetCodeType(const Value: TDefineBarcodeType);
  2481. procedure SetText(const Value: string);
  2482. procedure SetBarHeight(const Value: Integer);
  2483. procedure SetBorderWidth(const Value: Byte);
  2484. procedure SetBarColor(const Value: TColor);
  2485. procedure SetBarTop(const Value: Byte);
  2486. procedure SetColor(const Value: TColor);
  2487. procedure FontChange(sender : TObject);
  2488. procedure SetBools(Index: Integer; Value: Boolean);
  2489. protected
  2490. fBitmap: TBitmap;
  2491. function Code_25ILeaved : string;
  2492. function Code_25ITrial : string;
  2493. function Code_25Matrix : string;
  2494. function Code_39 : string;
  2495. function Code_128 : string;
  2496. function Code_93 : string;
  2497. function Code_MSI : string;
  2498. function Code_PostNet : string;
  2499. function Code_CodaBar : string;
  2500. function Code_EAN8 : string;
  2501. function Code_EAN13 : string;
  2502. function Code_UPC_A : string;
  2503. function Code_UPC_EODD : string;
  2504. function Code_UPC_EVEN : string;
  2505. function Code_Supp5 : string;
  2506. function Code_Supp2 : string;
  2507. Function MakeData : string;
  2508. function MakeBarText : String;
  2509. function GetTypName : String;
  2510. function GetProLine : Integer;
  2511. function DoCheckSumming(const Data: string;OddCheck:Boolean=True): string;
  2512. function GetCheckLen(CodeType: TDefineBarcodeType; Data: String): String;
  2513. function SetLen(pI:byte): string;
  2514. function ClearNotText(Value: String): String;
  2515. function MakeModules : TDefineBarcodeModules;
  2516. procedure DrawBarcode;
  2517. procedure OneBarProps(Data: Char; var Width: Integer; var lt: TDefineBarcodeLines);
  2518. procedure GetABCED(var a, b, c, d, orgin: TPoint; xadd, Width, Height: Integer);
  2519. procedure DrawEAN13Text(Canvas: TCanvas; width,wBorder: Integer);
  2520. procedure DrawEAN8Text(Canvas: TCanvas; width, wBorder: Integer);
  2521. procedure DrawUPC_AText(Canvas: TCanvas; width, wBorder: Integer);
  2522. procedure DrawUPC_EText(Canvas: TCanvas; width, wBorder: Integer);
  2523. procedure Paint; override;
  2524. procedure WMSize (var Message: TWMSize); message WM_SIZE;
  2525. property Data : String read MakeData;
  2526. property BarText : String read MakeBarText;
  2527. property Modules : TDefineBarcodeModules read MakeModules;
  2528. property ProLine : Integer read GetProLine;
  2529. property BarCode: String read GetTypName write fTypName;
  2530. property Rotate: TDefineBarcodeRotation read FRotateType write SetRotateType;
  2531. property Modul: Integer read fModul write SetModul;
  2532. property Ratio: double read fRatio write SetRatio;
  2533. property CodeType: TDefineBarcodeType read FCodeType write SetCodeType default EAN13;
  2534. property Text: string read fText write SetText;
  2535. property LineHeight: Integer read fBarHeight write SetBarHeight;
  2536. property BorderWidth: Byte read fBorderWidth write SetBorderWidth;
  2537. property LineTop: Byte read fBarTop write SetBarTop;
  2538. property Color: TColor read FColor write SetColor default clWhite;
  2539. property LineColor: TColor read fBarColor write SetBarColor default clBlack;
  2540. property AutoSize: Boolean index 0 read fAutoSize write SetBools default True;
  2541. property Checksum: boolean index 1 read FCheckSum write SetBools default FALSE;
  2542. property CheckOdd: Boolean index 2 read fCheckOdd write SetBools default true;
  2543. property ShowText: boolean index 3 read FShowText write SetBools default True;
  2544. property Transparent: boolean index 4 read fTransparent write SetBools default false;
  2545. public
  2546. constructor Create(Owner:TComponent); override;
  2547. destructor destroy;override;
  2548. property Bitmap: TBitmap read fBitmap;
  2549. end;
  2550. { TFlatButton }
  2551. TFlatButton = class(TDefineButton)
  2552. published
  2553. property Transparent;
  2554. property TransBorder;
  2555. property HasFocusFrame;
  2556. property Default;
  2557. property AllowAllUp;
  2558. property ColorFocused;
  2559. property ColorDown;
  2560. property ColorBorder;
  2561. property ColorShadow;
  2562. property ColorFlat;
  2563. property GroupIndex;
  2564. property Action;
  2565. property Down;
  2566. property Caption;
  2567. property Enabled;
  2568. property Font;
  2569. property FoisChange;
  2570. property FoisColor;
  2571. property FoisStyle;
  2572. property Glyph;
  2573. property Layout;
  2574. property Margin;
  2575. property NumGlyphs;
  2576. property ParentFont;
  2577. property ParentColor;
  2578. property ParentShowHint;
  2579. property PopupMenu;
  2580. property ShowHint;
  2581. property TabStop;
  2582. property TabOrder;
  2583. property Spacing;
  2584. property ModalResult;
  2585. property Visible;
  2586. property OnClick;
  2587. property OnDblClick;
  2588. property OnMouseDown;
  2589. property OnMouseMove;
  2590. property OnMouseUp;
  2591. property OnMouseEnter;
  2592. property OnMouseLeave;
  2593. {$IFDEF DFS_DELPHI_4_UP}
  2594. property Anchors;
  2595. property BiDiMode;
  2596. property Constraints;
  2597. property DragKind;
  2598. property ParentBiDiMode;
  2599. property OnEndDock;
  2600. property OnStartDock;
  2601. {$ENDIF}
  2602. end;
  2603. { TFlatColorBox }
  2604. TFlatColorBox = class(TDefineColorBox)
  2605. published
  2606. property Color;
  2607. property ColorArrow;
  2608. property ColorArrowBackground;
  2609. property ColorBorder;
  2610. property ColorHighlight;
  2611. property ColorBoxWidth;
  2612. property ShowNames;
  2613. property Value;
  2614. property Language;
  2615. property Ticket;
  2616. property TicketPosition;
  2617. property TicketSpace;
  2618. property DragMode;
  2619. property DragCursor;
  2620. property DropDownCount;
  2621. property Enabled;
  2622. property Font;
  2623. property MaxLength;
  2624. property ParentFont;
  2625. property ParentShowHint;
  2626. property PopupMenu;
  2627. property ShowHint;
  2628. property ImeMode;
  2629. property ImeName;
  2630. property Sorted;
  2631. property TabOrder;
  2632. property TabStop;
  2633. property Visible;
  2634. property OnChange;
  2635. property OnClick;
  2636. property OnDblClick;
  2637. property OnDragDrop;
  2638. property OnDragOver;
  2639. property OnDropDown;
  2640. property OnEndDrag;
  2641. property OnEnter;
  2642. property OnExit;
  2643. property OnKeyDown;
  2644. property OnKeyPress;
  2645. property OnKeyUp;
  2646. property OnMeasureItem;
  2647. property OnStartDrag;
  2648. end;
  2649. { TFlatComboBox }
  2650. TFlatComboBox = class(TDefineComboBox)
  2651. published
  2652. property Ticket;
  2653. property TicketPosition;
  2654. property TicketSpace;
  2655. property CharCase;
  2656. property Style;
  2657. property ParentColor;
  2658. property ColorArrow;
  2659. property ColorArrowBackground;
  2660. property ColorBorder;
  2661. property ColorFlat;
  2662. property ColorFocued;
  2663. property DragMode;
  2664. property DragCursor;
  2665. property DropDownCount;
  2666. property Enabled;
  2667. property ReadOnly;
  2668. property Font;
  2669. property ItemHeight;
  2670. property Items;
  2671. property MaxLength;
  2672. property ParentFont;
  2673. property ParentShowHint;
  2674. property PopupMenu;
  2675. property ShowHint;
  2676. property Sorted;
  2677. property TabOrder;
  2678. property TabStop;
  2679. property ImeMode;
  2680. property ImeName;
  2681. property Text;
  2682. property Visible;
  2683. property ItemIndex;
  2684. property OnChange;
  2685. property OnClick;
  2686. property OnDblClick;
  2687. property OnDragDrop;
  2688. property OnDragOver;
  2689. property OnDrawItem;
  2690. property OnDropDown;
  2691. property OnEndDrag;
  2692. property OnEnter;
  2693. property OnExit;
  2694. property OnKeyDown;
  2695. property OnKeyPress;
  2696. property OnKeyUp;
  2697. property OnMeasureItem;
  2698. property OnStartDrag;
  2699. property Anchors;
  2700. property BiDiMode;
  2701. property Constraints;
  2702. property DragKind;
  2703. property ParentBiDiMode;
  2704. property OnEndDock;
  2705. property OnStartDock;
  2706. end;
  2707. { TFlatEdit }
  2708. TFlatEdit = class(TDefineEdit)
  2709. published
  2710. property Alignment;
  2711. property ColorFocused;
  2712. property ColorBorder;
  2713. property ColorFlat;
  2714. property ParentColor;
  2715. property CharCase;
  2716. property DragCursor;
  2717. property DragMode;
  2718. property Enabled;
  2719. property Font;
  2720. property HideSelection;
  2721. property MaxLength;
  2722. property OEMConvert;
  2723. property ParentFont;
  2724. property ParentShowHint;
  2725. property PasswordChar;
  2726. property PopupMenu;
  2727. property ReadOnly;
  2728. property ShowHint;
  2729. property TabOrder;
  2730. property TabStop;
  2731. property Text;
  2732. property Visible;
  2733. property ImeMode;
  2734. property ImeName;
  2735. property Ticket;
  2736. property TicketPosition;
  2737. property TicketSpace;
  2738. property OnChange;
  2739. property OnClick;
  2740. property OnDblClick;
  2741. property OnDragDrop;
  2742. property OnDragOver;
  2743. property OnEndDrag;
  2744. property OnEnter;
  2745. property OnExit;
  2746. property OnKeyDown;
  2747. property OnKeyPress;
  2748. property OnKeyUp;
  2749. property OnMouseDown;
  2750. property OnMouseMove;
  2751. property OnMouseUp;
  2752. property OnStartDrag;
  2753. end;
  2754. { TFlatMemo }
  2755. TFlatMemo = class(TDefineMemo)
  2756. published
  2757. property ColorFocused;
  2758. property ColorBorder;
  2759. property ColorFlat;
  2760. property ParentColor;
  2761. property Version;
  2762. property Align;
  2763. property Alignment;
  2764. property DragCursor;
  2765. property DragMode;
  2766. property Enabled;
  2767. property Font;
  2768. property HideSelection;
  2769. property MaxLength;
  2770. property OEMConvert;
  2771. property ParentFont;
  2772. property ParentShowHint;
  2773. property PopupMenu;
  2774. property ReadOnly;
  2775. property ShowHint;
  2776. property ScrollBars;
  2777. property TabOrder;
  2778. property TabStop;
  2779. property Visible;
  2780. property Lines;
  2781. property WantReturns;
  2782. property WantTabs;
  2783. property WordWrap;
  2784. property ImeMode;
  2785. property ImeName;
  2786. property OnChange;
  2787. property OnClick;
  2788. property OnDblClick;
  2789. property OnDragDrop;
  2790. property OnDragOver;
  2791. property OnEndDrag;
  2792. property OnEnter;
  2793. property OnExit;
  2794. property OnKeyDown;
  2795. property OnKeyPress;
  2796. property OnKeyUp;
  2797. property OnMouseDown;
  2798. property OnMouseMove;
  2799. property OnMouseUp;
  2800. property OnStartDrag;
  2801. end;
  2802. { TFlatPanel }
  2803. TFlatPanel = class(TDefinePanel)
  2804. published
  2805. property Constraints;
  2806. property Action;
  2807. property Transparent;
  2808. property TransBorder;
  2809. property Alignment;
  2810. property Locked;
  2811. property FullRepaint;
  2812. property ColorBorder;
  2813. property BackgropStartColor;
  2814. property BackgropStopColor;
  2815. property BackgropOrien;
  2816. property StyleFace;
  2817. property Color;
  2818. property Caption;
  2819. property Font;
  2820. property ParentColor;
  2821. property UseDockManager;
  2822. property Enabled;
  2823. property Visible;
  2824. property DockSite;
  2825. property Align;
  2826. property AutoSize;
  2827. property Cursor;
  2828. property Hint;
  2829. property ParentShowHint;
  2830. property ShowHint;
  2831. property PopupMenu;
  2832. property TabOrder;
  2833. property TabStop;
  2834. {$IFDEF DFS_DELPHI_4_UP}
  2835. property AutoSize;
  2836. property UseDockManager;
  2837. property Anchors;
  2838. property BiDiMode;
  2839. property Constraints;
  2840. property DragKind;
  2841. property DragMode;
  2842. property DragCursor;
  2843. property ParentBiDiMode;
  2844. property DockSite;
  2845. property OnEndDock;
  2846. property OnStartDock;
  2847. property OnCanResize;
  2848. property OnConstrainedResize;
  2849. property OnDockDrop;
  2850. property OnDockOver;
  2851. property OnGetSiteInfo;
  2852. property OnUnDock;
  2853. {$ENDIF}
  2854. {$IFDEF DFS_DELPHI_5_UP}
  2855. property OnContextPopup;
  2856. {$ENDIF}
  2857. property OnClick;
  2858. property OnDblClick;
  2859. property OnDragDrop;
  2860. property OnDragOver;
  2861. property OnEndDrag;
  2862. property OnEnter;
  2863. property OnExit;
  2864. property OnMouseDown;
  2865. property OnMouseMove;
  2866. property OnMouseUp;
  2867. property OnResize;
  2868. property OnStartDrag;
  2869. end;
  2870. { TFlatMaskEdit }
  2871. TFlatMaskEdit = class(TDefineMask)
  2872. published
  2873. property Ticket;
  2874. property TicketPosition;
  2875. property TicketSpace;
  2876. property ColorFocused;
  2877. property ColorBorder;
  2878. property ColorFlat;
  2879. property ParentColor;
  2880. property Alignment;
  2881. property CharCase;
  2882. property Color;
  2883. property DragCursor;
  2884. property DragMode;
  2885. property Enabled;
  2886. property EditMask;
  2887. property Font;
  2888. property HideSelection;
  2889. property MaxLength;
  2890. property OEMConvert;
  2891. property ParentFont;
  2892. property ParentShowHint;
  2893. property PasswordChar;
  2894. property PopupMenu;
  2895. property ImeMode;
  2896. property ImeName;
  2897. property ReadOnly;
  2898. property ShowHint;
  2899. property TabOrder;
  2900. property TabStop;
  2901. property Text;
  2902. property Visible;
  2903. property OnChange;
  2904. property OnClick;
  2905. property OnDblClick;
  2906. property OnDragDrop;
  2907. property OnDragOver;
  2908. property OnEndDrag;
  2909. property OnEnter;
  2910. property OnExit;
  2911. property OnKeyDown;
  2912. property OnKeyPress;
  2913. property OnKeyUp;
  2914. property OnMouseDown;
  2915. property OnMouseMove;
  2916. property OnMouseUp;
  2917. property OnStartDrag;
  2918. property OnValidate;
  2919. end;
  2920. { TFlatSplitter }
  2921. TFlatSplitter = class(TDefineSplitter)
  2922. published
  2923. property Color;
  2924. property ColorFocused;
  2925. property ColorBorder;
  2926. property MinSize;
  2927. property OnMoved;
  2928. property Align;
  2929. property Enabled;
  2930. property ParentColor;
  2931. property ParentShowHint;
  2932. property ShowHint;
  2933. property Visible;
  2934. end;
  2935. { TFlatSpeedButton }
  2936. TFlatSpeedButton = class(TDefineSpeed)
  2937. published
  2938. property Transparent;
  2939. property TransBorder;
  2940. property Version;
  2941. property AllowAllUp;
  2942. property ColorFocused;
  2943. property ColorDown;
  2944. property ColorBorder;
  2945. property ColorShadow;
  2946. property ColorFlat;
  2947. property GroupIndex;
  2948. property Down;
  2949. property Caption;
  2950. property Enabled;
  2951. property Font;
  2952. property FoisChange;
  2953. property FoisColor;
  2954. property FoisStyle;
  2955. property Glyph;
  2956. property Layout;
  2957. property Margin;
  2958. property NumGlyphs;
  2959. property ModalResult;
  2960. property ParentFont;
  2961. property ParentColor;
  2962. property ParentShowHint;
  2963. property PopupMenu;
  2964. property ShowHint;
  2965. property Spacing;
  2966. property Visible;
  2967. property OnClick;
  2968. property OnDblClick;
  2969. property OnMouseDown;
  2970. property OnMouseMove;
  2971. property OnMouseUp;
  2972. property OnMouseEnter;
  2973. property OnMouseLeave;
  2974. {$IFDEF DFS_DELPHI_4_UP}
  2975. property Action;
  2976. property Anchors;
  2977. property BiDiMode;
  2978. property Constraints;
  2979. property DragKind;
  2980. property ParentBiDiMode;
  2981. property OnEndDock;
  2982. property OnStartDock;
  2983. {$ENDIF}
  2984. end;
  2985. TFlatPucker = class(TDefinePucker)
  2986. published
  2987. property Action;
  2988. property FillGradient;
  2989. property ColorStart;
  2990. property ColorEnd;
  2991. property Enabled;
  2992. property FillDirection;
  2993. property TitleShow;
  2994. property Minimized;
  2995. property Maximized;
  2996. property Caption;
  2997. property TitleFont;
  2998. property TitleHeight;
  2999. property TitleAlignment;
  3000. property TitleShadowOnMoseEnter;
  3001. property TitleFillGradient;
  3002. property TitleColorStart;
  3003. property TitleColorEnd;
  3004. property TitleColor;
  3005. property TitleImage;
  3006. property TitleFillDirect;
  3007. property TitleImageAlign;
  3008. property TitleImageTransparent;
  3009. property TitleButtons;
  3010. property TitleBtnStyle;
  3011. property TitleBtnBorderColor;
  3012. property TitleBtnBGColor;
  3013. property TitleBtnBorderSize;
  3014. property Animation;
  3015. property DefaultHeight;
  3016. property Movable;
  3017. property Sizable;
  3018. property ShowBorder;
  3019. property ColorBorder;
  3020. property PanelCorner;
  3021. property BGImage;
  3022. property BGImageAlign;
  3023. property BGImageTransparent;
  3024. property Color;
  3025. property Align;
  3026. property Visible;
  3027. property TabOrder;
  3028. property TabStop;
  3029. property DragMode;
  3030. property OnResize;
  3031. property OnClick;
  3032. property OnDblClick;
  3033. property OnDragDrop;
  3034. property OnDragOver;
  3035. property OnEndDrag;
  3036. property OnMouseDown;
  3037. property OnMouseMove;
  3038. property OnMouseUp;
  3039. property OnStartDrag;
  3040. property OnEnter;
  3041. property OnExit;
  3042. property AfterMinimized;
  3043. property AfterMaximized;
  3044. property BeforeMove;
  3045. property AfterMove;
  3046. property AfterClose;
  3047. property OnTitleClick;
  3048. property OnTitleDblClick;
  3049. property OnTitleMouseDown;
  3050. property OnTitleMouseUp;
  3051. property OnTitleMouseEnter;
  3052. property OnTitleMouseExit;
  3053. property OnMouseEnter;
  3054. property OnMouseExit;
  3055. end;
  3056. { TFlatCheckBox }
  3057. TFlatCheckBox = class(TDefineCheckBox)
  3058. published
  3059. property Transparent;
  3060. //property AllowGrayed;
  3061. property Caption;
  3062. property Checked;
  3063. property ColorFocused;
  3064. property ColorDown;
  3065. property ColorChecked;
  3066. property Color;
  3067. property ColorBorder;
  3068. property Action;
  3069. property Enabled;
  3070. property Font;
  3071. property Layout;
  3072. property ParentColor;
  3073. property ParentFont;
  3074. property ShowHint;
  3075. property TabOrder;
  3076. property TabStop;
  3077. property Visible;
  3078. property OnClick;
  3079. property OnDblClick;
  3080. property OnDragDrop;
  3081. property OnDragOver;
  3082. property OnEndDrag;
  3083. property OnEnter;
  3084. property OnExit;
  3085. property OnKeyDown;
  3086. property OnKeyPress;
  3087. property OnKeyUp;
  3088. property OnMouseDown;
  3089. property OnMouseMove;
  3090. property OnMouseUp;
  3091. end;
  3092. { TFlatCheckListBox }
  3093. TFlatCheckListBox = class(TDefineListChecks)
  3094. published
  3095. property Skin;
  3096. property Caption;
  3097. property Sorted;
  3098. property Items;
  3099. property Align;
  3100. property Font;
  3101. property ParentFont;
  3102. property ParentShowHint;
  3103. property Enabled;
  3104. property Visible;
  3105. property PopupMenu;
  3106. property ShowHint;
  3107. property TabOrder;
  3108. property TabStop;
  3109. property ParentColor;
  3110. property OnClick;
  3111. property OnChange;
  3112. property OnClickCheck;
  3113. property OnMouseMove;
  3114. property OnMouseDown;
  3115. property OnMouseUp;
  3116. property OnDragDrop;
  3117. property OnDragOver;
  3118. property OnEndDock;
  3119. property OnEndDrag;
  3120. property OnEnter;
  3121. property OnExit;
  3122. property OnKeyDown;
  3123. property OnKeyPress;
  3124. property OnKeyUp;
  3125. property OnStartDock;
  3126. property OnStartDrag;
  3127. end;
  3128. { TDefineGroupBox }
  3129. TFlatGroupBox = class(TDefineGroupBox)
  3130. published
  3131. property Action;
  3132. property Transparent;
  3133. property Alignment;
  3134. property Align;
  3135. property Cursor;
  3136. property Caption;
  3137. property Font;
  3138. property ParentFont;
  3139. property Color;
  3140. property ParentColor;
  3141. property PopupMenu;
  3142. property ShowHint;
  3143. property ParentShowHint;
  3144. property Enabled;
  3145. property Visible;
  3146. property TabOrder;
  3147. property TabStop;
  3148. property Hint;
  3149. property HelpContext;
  3150. property ColorBorder;
  3151. property BackgropStartColor;
  3152. property BackgropStopColor;
  3153. property BackgropOrien;
  3154. property StyleFace;
  3155. property Border;
  3156. property Anchors;
  3157. property Constraints;
  3158. property DragKind;
  3159. property DragMode;
  3160. property DragCursor;
  3161. property ParentBiDiMode;
  3162. property DockSite;
  3163. property OnEndDock;
  3164. property OnStartDock;
  3165. property OnDockDrop;
  3166. property OnDockOver;
  3167. property OnGetSiteInfo;
  3168. property OnUnDock;
  3169. property OnClick;
  3170. property OnDblClick;
  3171. property OnDragDrop;
  3172. property OnDragOver;
  3173. property OnEndDrag;
  3174. property OnEnter;
  3175. property OnExit;
  3176. property OnMouseDown;
  3177. property OnMouseMove;
  3178. property OnMouseUp;
  3179. property OnResize;
  3180. property OnStartDrag;
  3181. end;
  3182. { TFlatRadioButton }
  3183. TFlatRadioButton = class(TDefineRadioButton)
  3184. published
  3185. property Action;
  3186. property Transparent;
  3187. property Version;
  3188. property Caption;
  3189. property Checked;
  3190. property ColorFocused;
  3191. property ColorDown;
  3192. property ColorChecked;
  3193. property ColorBorder;
  3194. property Color;
  3195. property Enabled;
  3196. property Font;
  3197. property GroupIndex;
  3198. property Layout;
  3199. property ParentColor;
  3200. property ParentFont;
  3201. property Anchors;
  3202. property Constraints;
  3203. property DragKind;
  3204. property ShowHint;
  3205. property TabOrder;
  3206. property TabStop;
  3207. property Visible;
  3208. property OnClick;
  3209. property OnDblClick;
  3210. property OnDragDrop;
  3211. property OnDragOver;
  3212. property OnEndDrag;
  3213. property OnEnter;
  3214. property OnExit;
  3215. property OnKeyDown;
  3216. property OnKeyPress;
  3217. property OnKeyUp;
  3218. property OnMouseDown;
  3219. property OnMouseMove;
  3220. property OnMouseUp;
  3221. property OnEndDock;
  3222. property OnStartDock;
  3223. end;
  3224. { TFlatRadioGroup }
  3225. TFlatRadioGroup = class(TDefineRadioGroup)
  3226. published
  3227. property Transparent;
  3228. property Alignment;
  3229. property Items;
  3230. property ItemIndex;
  3231. property Columns;
  3232. property Align;
  3233. property Cursor;
  3234. property Caption;
  3235. property Font;
  3236. property ParentFont;
  3237. property Color;
  3238. property ParentColor;
  3239. property PopupMenu;
  3240. property ShowHint;
  3241. property ParentShowHint;
  3242. property Enabled;
  3243. property Visible;
  3244. property TabOrder;
  3245. property TabStop;
  3246. property Hint;
  3247. property ColorBorder;
  3248. property BackgropStartColor;
  3249. property BackgropStopColor;
  3250. property BackgropOrien;
  3251. property StyleFace;
  3252. property Border;
  3253. property Anchors;
  3254. property Constraints;
  3255. property DragKind;
  3256. property DragMode;
  3257. property DragCursor;
  3258. property DockSite;
  3259. property OnEndDock;
  3260. property OnStartDock;
  3261. property OnDockDrop;
  3262. property OnDockOver;
  3263. property OnUnDock;
  3264. property OnClick;
  3265. property OnDblClick;
  3266. property OnDragDrop;
  3267. property OnDragOver;
  3268. property OnEndDrag;
  3269. property OnEnter;
  3270. property OnExit;
  3271. property OnMouseDown;
  3272. property OnMouseMove;
  3273. property OnMouseUp;
  3274. property OnStartDrag;
  3275. end;
  3276. { TFlatListBox }
  3277. TFlatListBox = class(TDefineListBox)
  3278. published
  3279. property Caption;
  3280. property Skin;
  3281. property Align;
  3282. property Items;
  3283. property MultiSelect;
  3284. property Sorted;
  3285. property Font;
  3286. property ParentFont;
  3287. property ParentShowHint;
  3288. property Enabled;
  3289. property Visible;
  3290. property PopupMenu;
  3291. property ShowHint;
  3292. property TabOrder;
  3293. property TabStop;
  3294. property OnClick;
  3295. property OnChange;
  3296. property OnDblClick;
  3297. property OnMouseMove;
  3298. property OnMouseDown;
  3299. property OnMouseUp;
  3300. property OnKeyDown;
  3301. property OnKeyPress;
  3302. property OnDragDrop;
  3303. property OnDragOver;
  3304. property OnEndDock;
  3305. property OnEndDrag;
  3306. property OnEnter;
  3307. property OnExit;
  3308. property OnKeyUp;
  3309. property OnStartDock;
  3310. property OnStartDrag;
  3311. end;
  3312. { TFlatListBoxExt }
  3313. TFlatListBoxExt = class(TDefineListBoxExt)
  3314. published
  3315. property ColorFocused;
  3316. property ColorBorder;
  3317. property ColorFlat;
  3318. property ParentColor;
  3319. property Style;
  3320. property AutoComplete;
  3321. property Align;
  3322. property Anchors;
  3323. property BiDiMode;
  3324. property Columns;
  3325. property Constraints;
  3326. property DragCursor;
  3327. property DragKind;
  3328. property DragMode;
  3329. property Enabled;
  3330. property ExtendedSelect;
  3331. property Font;
  3332. property ImeMode;
  3333. property ImeName;
  3334. property IntegralHeight;
  3335. property ItemHeight;
  3336. property Items;
  3337. property MultiSelect;
  3338. property ParentBiDiMode;
  3339. property ParentFont;
  3340. property ParentShowHint;
  3341. property PopupMenu;
  3342. property ScrollWidth;
  3343. property ShowHint;
  3344. property Sorted;
  3345. property TabOrder;
  3346. property TabStop;
  3347. property TabWidth;
  3348. property Visible;
  3349. property OnClick;
  3350. property OnContextPopup;
  3351. property OnData;
  3352. property OnDataFind;
  3353. property OnDataObject;
  3354. property OnDblClick;
  3355. property OnDragDrop;
  3356. property OnDragOver;
  3357. property OnDrawItem;
  3358. property OnEndDock;
  3359. property OnEndDrag;
  3360. property OnEnter;
  3361. property OnExit;
  3362. property OnKeyDown;
  3363. property OnKeyPress;
  3364. property OnKeyUp;
  3365. property OnMeasureItem;
  3366. property OnMouseDown;
  3367. property OnMouseMove;
  3368. property OnMouseUp;
  3369. property OnStartDock;
  3370. property OnStartDrag;
  3371. end;
  3372. { TFlatCheckListExt }
  3373. TFlatCheckListExt = class(TDefineCheckListExt)
  3374. published
  3375. property OnClickCheck;
  3376. property HeaderColor;
  3377. property HeaderBkColor;
  3378. property AllowGrayed;
  3379. property Flat;
  3380. property ColorFocused;
  3381. property ColorBorder;
  3382. property ColorFlat;
  3383. property ParentColor;
  3384. property Align;
  3385. property Anchors;
  3386. property AutoComplete;
  3387. property BiDiMode;
  3388. property Columns;
  3389. property Constraints;
  3390. property DragCursor;
  3391. property DragKind;
  3392. property DragMode;
  3393. property Enabled;
  3394. property Font;
  3395. property ImeMode;
  3396. property ImeName;
  3397. property IntegralHeight;
  3398. property ItemHeight;
  3399. property Items;
  3400. property ParentBiDiMode;
  3401. property ParentFont;
  3402. property ParentShowHint;
  3403. property PopupMenu;
  3404. property ShowHint;
  3405. property Sorted;
  3406. property Style;
  3407. property TabOrder;
  3408. property TabStop;
  3409. property TabWidth;
  3410. property Visible;
  3411. property OnClick;
  3412. property OnContextPopup;
  3413. property OnData;
  3414. property OnDataFind;
  3415. property OnDataObject;
  3416. property OnDblClick;
  3417. property OnDragDrop;
  3418. property OnDragOver;
  3419. property OnDrawItem;
  3420. property OnEndDock;
  3421. property OnEndDrag;
  3422. property OnEnter;
  3423. property OnExit;
  3424. property OnKeyDown;
  3425. property OnKeyPress;
  3426. property OnKeyUp;
  3427. property OnMeasureItem;
  3428. property OnMouseDown;
  3429. property OnMouseMove;
  3430. property OnMouseUp;
  3431. property OnStartDock;
  3432. property OnStartDrag;
  3433. end;
  3434. TFlatGauge = class(TDefineGauge)
  3435. published
  3436. property AdvColorBorder;
  3437. property Transparent;
  3438. property UseAdvColors;
  3439. property StyleFace;
  3440. property StyleOrien;
  3441. property StyleColorStart;
  3442. property StyleColorStop;
  3443. property Version;
  3444. property Color;
  3445. property ColorBorder;
  3446. property BarColor;
  3447. property Min;
  3448. property Max;
  3449. property Progress;
  3450. property ShowText;
  3451. property TextFront;
  3452. property TextAfter;
  3453. property Align;
  3454. property Enabled;
  3455. property Font;
  3456. property ParentColor;
  3457. property ParentFont;
  3458. property ParentShowHint;
  3459. property ShowHint;
  3460. property Visible;
  3461. property OnDragDrop;
  3462. property OnDragOver;
  3463. property OnEndDrag;
  3464. property OnMouseDown;
  3465. property OnMouseMove;
  3466. property OnMouseUp;
  3467. property OnStartDrag;
  3468. {$IFDEF DFS_COMPILER_4_UP}
  3469. property Anchors;
  3470. property BiDiMode;
  3471. property Constraints;
  3472. property DragKind;
  3473. property ParentBiDiMode;
  3474. property OnEndDock;
  3475. property OnStartDock;
  3476. {$ENDIF}
  3477. end;
  3478. TFlatProgressBar = class(TDefineProgressBar)
  3479. published
  3480. property Transparent;
  3481. property Align;
  3482. property Cursor;
  3483. property Color;
  3484. property ColorElement;
  3485. property ColorBorder;
  3486. property AdvColorBorder;
  3487. property UseAdvColors;
  3488. property Orientation;
  3489. property Enabled;
  3490. property ParentColor;
  3491. property Visible;
  3492. property Hint;
  3493. property ShowHint;
  3494. property PopupMenu;
  3495. property ParentShowHint;
  3496. property Min;
  3497. property Max;
  3498. property Position;
  3499. property Step;
  3500. property Smooth;
  3501. property OnDragDrop;
  3502. property OnDragOver;
  3503. property OnEndDrag;
  3504. property OnMouseDown;
  3505. property OnMouseMove;
  3506. property OnMouseUp;
  3507. property OnStartDrag;
  3508. {$IFDEF DFS_COMPILER_4_UP}
  3509. property Anchors;
  3510. property BiDiMode;
  3511. property Constraints;
  3512. property DragKind;
  3513. property ParentBiDiMode;
  3514. property OnEndDock;
  3515. property OnStartDock;
  3516. {$ENDIF}
  3517. end;
  3518. TFlatScrollbar = class(TDefineScrollbar)
  3519. published
  3520. property Min;
  3521. property Max;
  3522. property SmallChange;
  3523. property LargeChange;
  3524. property Position;
  3525. property Kind;
  3526. property OnScroll;
  3527. property ButtonHighlightColor;
  3528. property ButtonShadowColor;
  3529. property ButtonBorderColor;
  3530. property ButtonFocusedColor;
  3531. property ButtonDownColor;
  3532. property ButtonColor;
  3533. property ThumbHighlightColor;
  3534. property ThumbShadowColor;
  3535. property ThumbBorderColor;
  3536. property ThumbFocusedColor;
  3537. property ThumbDownColor;
  3538. property ThumbColor;
  3539. property Version;
  3540. property Align;
  3541. property Color;
  3542. property ParentColor;
  3543. property OnDragDrop;
  3544. property OnDragOver;
  3545. property OnEndDrag;
  3546. property OnEnter;
  3547. property OnExit;
  3548. property OnKeyDown;
  3549. property OnKeyUp;
  3550. property OnStartDrag;
  3551. end;
  3552. TFlatTitlebar = class(TDefineTitlebar)
  3553. published
  3554. property ActiveTextColor;
  3555. property InactiveTextColor;
  3556. property TitlebarColor;
  3557. property Align;
  3558. property Font;
  3559. property Caption;
  3560. property OnMouseDown;
  3561. property OnMouseMove;
  3562. property OnMouseUp;
  3563. property OnActivate;
  3564. property OnDeactivate;
  3565. end;
  3566. TFlatFloat = class(TDefineFloat)
  3567. published
  3568. property Digits;
  3569. property Precision;
  3570. property FloatFormat;
  3571. property EditorEnabled;
  3572. property Increment;
  3573. property MaxValue;
  3574. property MinValue;
  3575. property Value;
  3576. property Alignment;
  3577. property ColorFocused;
  3578. property ColorBorder;
  3579. property ColorFlat;
  3580. property AutoSelect;
  3581. property AutoSize;
  3582. property DragCursor;
  3583. property DragMode;
  3584. property Enabled;
  3585. property Font;
  3586. property Ticket;
  3587. property TicketPosition;
  3588. property TicketSpace;
  3589. property ParentColor;
  3590. property ParentFont;
  3591. property ParentShowHint;
  3592. property ImeMode;
  3593. property ImeName;
  3594. property PopupMenu;
  3595. property ReadOnly;
  3596. property ShowHint;
  3597. property TabOrder;
  3598. property TabStop;
  3599. property Visible;
  3600. property OnChange;
  3601. property OnClick;
  3602. property OnDblClick;
  3603. property OnDragDrop;
  3604. property OnDragOver;
  3605. property OnEndDrag;
  3606. property OnEnter;
  3607. property OnExit;
  3608. property OnKeyDown;
  3609. property OnKeyPress;
  3610. property OnKeyUp;
  3611. property OnMouseDown;
  3612. property OnMouseMove;
  3613. property OnMouseUp;
  3614. property OnStartDrag;
  3615. end;
  3616. TFlatInteger = class(TDefineInteger)
  3617. published
  3618. property Increment;
  3619. property MaxValue;
  3620. property MinValue;
  3621. property Value;
  3622. property EditorEnabled;
  3623. property Alignment;
  3624. property ColorFocused;
  3625. property ColorBorder;
  3626. property ColorFlat;
  3627. property AutoSelect;
  3628. property AutoSize;
  3629. property DragCursor;
  3630. property DragMode;
  3631. property Enabled;
  3632. property ImeMode;
  3633. property ImeName;
  3634. property Font;
  3635. property Ticket;
  3636. property TicketPosition;
  3637. property TicketSpace;
  3638. property ParentColor;
  3639. property ParentFont;
  3640. property ParentShowHint;
  3641. property PopupMenu;
  3642. property ReadOnly;
  3643. property ShowHint;
  3644. property TabOrder;
  3645. property TabStop;
  3646. property Visible;
  3647. property OnChange;
  3648. property OnClick;
  3649. property OnDblClick;
  3650. property OnDragDrop;
  3651. property OnDragOver;
  3652. property OnEndDrag;
  3653. property OnEnter;
  3654. property OnExit;
  3655. property OnKeyDown;
  3656. property OnKeyPress;
  3657. property OnKeyUp;
  3658. property OnMouseDown;
  3659. property OnMouseMove;
  3660. property OnMouseUp;
  3661. property OnStartDrag;
  3662. end;
  3663. TFlatIPEdit = class(TDefineIPEdit)
  3664. published
  3665. property IPAddress;
  3666. property Text;
  3667. property Ticket;
  3668. property TicketPosition;
  3669. property TicketSpace;
  3670. property ColorFocused;
  3671. property ColorBorder;
  3672. property ColorFlat;
  3673. property ParentColor;
  3674. property Alignment;
  3675. property AutoSelect;
  3676. property CharCase;
  3677. property Color;
  3678. property DragCursor;
  3679. property DragMode;
  3680. property Enabled;
  3681. property Font;
  3682. property HideSelection;
  3683. property OEMConvert;
  3684. property ParentFont;
  3685. property ParentShowHint;
  3686. property PopupMenu;
  3687. property ReadOnly;
  3688. property ShowHint;
  3689. property TabOrder;
  3690. property TabStop;
  3691. property Visible;
  3692. property OnChange;
  3693. property OnClick;
  3694. property OnDblClick;
  3695. property OnDragDrop;
  3696. property OnDragOver;
  3697. property OnEndDrag;
  3698. property OnEnter;
  3699. property OnExit;
  3700. property OnKeyDown;
  3701. property OnKeyPress;
  3702. property OnKeyUp;
  3703. property OnMouseDown;
  3704. property OnMouseMove;
  3705. property OnMouseUp;
  3706. property OnStartDrag;
  3707. property OnValidate;
  3708. end;
  3709. TFlatLabel = class(TDefineLabel)
  3710. published
  3711. property Ticket;
  3712. property TicketPosition;
  3713. property TicketSpace;
  3714. property Transparent;
  3715. property TransBorder;
  3716. property Alignment;
  3717. property Locked;
  3718. property FullRepaint;
  3719. property ColorBorder;
  3720. property BackgropStartColor;
  3721. property BackgropStopColor;
  3722. property BackgropOrien;
  3723. property StyleFace;
  3724. property Color;
  3725. property Caption;
  3726. property Font;
  3727. property ParentColor;
  3728. property UseDockManager;
  3729. property Enabled;
  3730. property Visible;
  3731. property Align;
  3732. property AutoSize;
  3733. property Cursor;
  3734. property Hint;
  3735. property ParentShowHint;
  3736. property ShowHint;
  3737. property PopupMenu;
  3738. property TabOrder;
  3739. property TabStop;
  3740. {$IFDEF DFS_DELPHI_4_UP}
  3741. property AutoSize;
  3742. property UseDockManager;
  3743. property Anchors;
  3744. property BiDiMode;
  3745. property Constraints;
  3746. property DragKind;
  3747. property DragMode;
  3748. property DragCursor;
  3749. property ParentBiDiMode;
  3750. property DockSite;
  3751. property OnEndDock;
  3752. property OnStartDock;
  3753. property OnCanResize;
  3754. property OnConstrainedResize;
  3755. property OnDockDrop;
  3756. property OnDockOver;
  3757. property OnGetSiteInfo;
  3758. property OnUnDock;
  3759. {$ENDIF}
  3760. {$IFDEF DFS_DELPHI_5_UP}
  3761. property OnContextPopup;
  3762. {$ENDIF}
  3763. property OnClick;
  3764. property OnDblClick;
  3765. property OnDragDrop;
  3766. property OnDragOver;
  3767. property OnEndDrag;
  3768. property OnEnter;
  3769. property OnExit;
  3770. property OnMouseDown;
  3771. property OnMouseMove;
  3772. property OnMouseUp;
  3773. property OnResize;
  3774. property OnStartDrag;
  3775. end;
  3776. { TFlatPages }
  3777. TFlatPages = class (TDefinePages)
  3778. published
  3779. property ImageList;
  3780. property OnDrawItem;
  3781. property OnGlyphMap;
  3782. property OwnerDraw;
  3783. property ColorBorder;
  3784. property TabPosition;
  3785. property TabTextAlignment;
  3786. property Style;
  3787. end;
  3788. { TFlatSheet }
  3789. TFlatSheet = class (TDefineSheet)
  3790. published
  3791. property Color;
  3792. property ImageIndex;
  3793. property ShowTabHint;
  3794. property TabHint;
  3795. property BGImage;
  3796. property BGStyle;
  3797. property GradientStartColor;
  3798. property GradientEndColor;
  3799. property GradientFillDir;
  3800. end;
  3801. { TFlatTreeView }
  3802. TFlatTreeView = class(TDefineTreeView)
  3803. published
  3804. property ColorFocused;
  3805. property ColorBorder;
  3806. property ColorFlat;
  3807. property ParentColor;
  3808. property Anchors;
  3809. property AutoExpand;
  3810. property BiDiMode;
  3811. property ChangeDelay;
  3812. property Constraints;
  3813. property DragKind;
  3814. property HotTrack;
  3815. property Images;
  3816. property Indent;
  3817. property MultiSelect;
  3818. property MultiSelectStyle;
  3819. property ParentBiDiMode;
  3820. property RightClickSelect;
  3821. property RowSelect;
  3822. property ShowButtons;
  3823. property ShowLines;
  3824. property ShowRoot;
  3825. property SortType;
  3826. property StateImages;
  3827. property ToolTips;
  3828. property Align;
  3829. property DragCursor;
  3830. property DragMode;
  3831. property Enabled;
  3832. property Font;
  3833. property HideSelection;
  3834. property ParentFont;
  3835. property ParentShowHint;
  3836. property PopupMenu;
  3837. property ReadOnly;
  3838. property ShowHint;
  3839. property TabOrder;
  3840. property TabStop;
  3841. property Visible;
  3842. property OnChange;
  3843. property OnClick;
  3844. property OnDblClick;
  3845. property OnDragDrop;
  3846. property OnDragOver;
  3847. property OnEndDrag;
  3848. property OnEnter;
  3849. property OnExit;
  3850. property OnKeyDown;
  3851. property OnKeyPress;
  3852. property OnKeyUp;
  3853. property OnMouseDown;
  3854. property OnMouseMove;
  3855. property OnMouseUp;
  3856. property OnStartDrag;
  3857. property OnAddition;
  3858. property OnAdvancedCustomDraw;
  3859. property OnAdvancedCustomDrawItem;
  3860. property OnChanging;
  3861. property OnCollapsed;
  3862. property OnCollapsing;
  3863. property OnCompare;
  3864. property OnContextPopup;
  3865. property OnCreateNodeClass;
  3866. property OnCustomDraw;
  3867. property OnCustomDrawItem;
  3868. property OnDeletion;
  3869. property OnEdited;
  3870. property OnEditing;
  3871. property OnEndDock;
  3872. property OnExpanding;
  3873. property OnExpanded;
  3874. property OnGetImageIndex;
  3875. property OnGetSelectedIndex;
  3876. property OnStartDock;
  3877. { Items must be published after OnGetImageIndex and OnGetSelectedIndex }
  3878. property Items;
  3879. end;
  3880. { TFlatListView }
  3881. TFlatListView = class(TDefineListView)
  3882. published
  3883. property ColorFocused;
  3884. property ColorBorder;
  3885. property ColorFlat;
  3886. property ColorTitleFace;
  3887. property ColorTitleCheck;
  3888. property GroundHas;
  3889. property GroundPic;
  3890. property GroundStretch;
  3891. property Action;
  3892. property Align;
  3893. property AllocBy;
  3894. property Anchors;
  3895. property Checkboxes;
  3896. property Columns;
  3897. property ColumnClick;
  3898. property Enabled;
  3899. property Font;
  3900. property FlatScrollBars;
  3901. property FullDrag;
  3902. property GridLines;
  3903. property HideSelection;
  3904. property HotTrack;
  3905. property HotTrackStyles;
  3906. property HoverTime;
  3907. property IconOptions;
  3908. property Items;
  3909. property LargeImages;
  3910. property MultiSelect;
  3911. property OwnerData;
  3912. property OwnerDraw;
  3913. property ReadOnly default False;
  3914. property RowSelect;
  3915. property ParentBiDiMode;
  3916. property ParentColor default False;
  3917. property ParentFont;
  3918. property ParentShowHint;
  3919. property PopupMenu;
  3920. property ShowColumnHeaders;
  3921. property ShowWorkAreas;
  3922. property ShowHint;
  3923. property SmallImages;
  3924. property SortType;
  3925. property StateImages;
  3926. property Transparent;
  3927. property TabOrder;
  3928. property TabStop default True;
  3929. property ViewStyle;
  3930. property Visible;
  3931. property OnAdvancedCustomDraw;
  3932. property OnAdvancedCustomDrawItem;
  3933. property OnAdvancedCustomDrawSubItem;
  3934. property OnDrawTitle;
  3935. property OnChange;
  3936. property OnChanging;
  3937. property OnClick;
  3938. property OnColumnClick;
  3939. property OnColumnDragged;
  3940. property OnColumnRightClick;
  3941. property OnCompare;
  3942. property OnContextPopup;
  3943. //property OnCustomDraw;
  3944. property OnDrawBackground;
  3945. property OnCustomDrawItem;
  3946. property OnCustomDrawSubItem;
  3947. property OnData;
  3948. property OnDataFind;
  3949. property OnDataHint;
  3950. property OnDataStateChange;
  3951. property OnDblClick;
  3952. property OnDeletion;
  3953. property OnDrawItem;
  3954. property OnEdited;
  3955. property OnEditing;
  3956. property OnEndDock;
  3957. property OnEndDrag;
  3958. property OnEnter;
  3959. property OnExit;
  3960. property OnGetImageIndex;
  3961. property OnGetSubItemImage;
  3962. property OnDragDrop;
  3963. property OnDragOver;
  3964. property OnInfoTip;
  3965. property OnInsert;
  3966. property OnKeyDown;
  3967. property OnKeyPress;
  3968. property OnKeyUp;
  3969. property OnMouseDown;
  3970. property OnMouseMove;
  3971. property OnMouseUp;
  3972. property OnResize;
  3973. property OnSelectItem;
  3974. property OnStartDock;
  3975. property OnStartDrag;
  3976. end;
  3977. TFlatGUIScrollBar = class(TDefineGUIScrollBar)
  3978. published
  3979. property OnDrawControl;
  3980. property OwnerDraw;
  3981. property OnEnabledChange;
  3982. property OnScroll;
  3983. property OnChange;
  3984. property Position;
  3985. property ScrollBarKind;
  3986. property LargeChange;
  3987. property SmallChange;
  3988. property Max;
  3989. property Min;
  3990. property PageSize;
  3991. property DragCursor;
  3992. property DragKind;
  3993. property DragMode;
  3994. property Enabled;
  3995. property Font;
  3996. property Align;
  3997. property Color;
  3998. property Caption;
  3999. property ParentBiDiMode;
  4000. property ParentFont;
  4001. property ParentShowHint;
  4002. property PopupMenu;
  4003. property ShowHint;
  4004. property Visible;
  4005. property OnClick;
  4006. property OnContextPopup;
  4007. property OnDragDrop;
  4008. property OnDragOver;
  4009. property OnEndDock;
  4010. property OnEndDrag;
  4011. property ParentColor;
  4012. property OnMouseDown;
  4013. property OnMouseMove;
  4014. property OnMouseUp;
  4015. property OnStartDock;
  4016. property OnStartDrag;
  4017. end;
  4018. { TFlatGUIListBox }
  4019. TFlatGUIListBox = class(TDefineGUIListBox)
  4020. published
  4021. property AutoItemHeight;
  4022. property Items;
  4023. property ItemHeight;
  4024. property TopIndex;
  4025. property Hint;
  4026. property TabOrder;
  4027. property TabStop;
  4028. property OwnerDraw;
  4029. property ActiveItem;
  4030. property ItemIndex;
  4031. property GUISelectColor;
  4032. property GUIBorderColor;
  4033. property GUIBrightColor;
  4034. property GUIColor;
  4035. property GUISpaceColor;
  4036. property GUIStyle;
  4037. property GUIFlatColor;
  4038. property GUIFocusedColor;
  4039. property MultiSelect;
  4040. property Count;
  4041. property DragCursor;
  4042. property DragKind;
  4043. property DragMode;
  4044. property Enabled;
  4045. property Font;
  4046. property Align;
  4047. property ParentBiDiMode;
  4048. property ParentFont;
  4049. property ParentShowHint;
  4050. property PopupMenu;
  4051. property ShowHint;
  4052. property Visible;
  4053. property OnClick;
  4054. property OnContextPopup;
  4055. property OnDragDrop;
  4056. property OnDragOver;
  4057. property OnEndDock;
  4058. property OnEndDrag;
  4059. property ParentColor;
  4060. property OnMouseDown;
  4061. property OnMouseMove;
  4062. property OnMouseUp;
  4063. property OnKeyDown;
  4064. property OnKeyPress;
  4065. property OnKeyUp;
  4066. property OnStartDock;
  4067. property OnStartDrag;
  4068. property OnDrawScrollBar;
  4069. property OnItemClick;
  4070. property OnItemDlbClick;
  4071. property OnItemDraw;
  4072. end;
  4073. { TDefineDrawGrid }
  4074. TFlatDrawGrid = class(TDefineGridDraw)
  4075. published
  4076. property ColorFocused;
  4077. property ColorBorder;
  4078. property ColorFlat;
  4079. property ColorLines;
  4080. property ParentColor;
  4081. property Align;
  4082. property Anchors;
  4083. property BiDiMode;
  4084. property ColCount;
  4085. property Constraints;
  4086. property DefaultColWidth;
  4087. property DefaultRowHeight;
  4088. property DefaultDrawing;
  4089. property DragCursor;
  4090. property DragKind;
  4091. property DragMode;
  4092. property Enabled;
  4093. property FixedColor;
  4094. property FixedCols;
  4095. property RowCount;
  4096. property FixedRows;
  4097. property Font;
  4098. property Options;
  4099. property ParentBiDiMode;
  4100. property ParentFont;
  4101. property ParentShowHint;
  4102. property PopupMenu;
  4103. property ScrollBars;
  4104. property ShowHint;
  4105. property TabOrder;
  4106. property Visible;
  4107. property VisibleColCount;
  4108. property VisibleRowCount;
  4109. property OnClick;
  4110. property OnColumnMoved;
  4111. property OnContextPopup;
  4112. property OnDblClick;
  4113. property OnDragDrop;
  4114. property OnDragOver;
  4115. property OnDrawCell;
  4116. property OnEndDock;
  4117. property OnEndDrag;
  4118. property OnEnter;
  4119. property OnExit;
  4120. property OnGetEditMask;
  4121. property OnGetEditText;
  4122. property OnKeyDown;
  4123. property OnKeyPress;
  4124. property OnKeyUp;
  4125. property OnMouseDown;
  4126. property OnMouseMove;
  4127. property OnMouseUp;
  4128. property OnMouseWheelDown;
  4129. property OnMouseWheelUp;
  4130. property OnRowMoved;
  4131. property OnSelectCell;
  4132. property OnSetEditText;
  4133. property OnStartDock;
  4134. property OnStartDrag;
  4135. property OnTopLeftChanged;
  4136. end;
  4137. { TFlatStringGrid }
  4138. TFlatStringGrid = class(TDefineGridString)
  4139. published
  4140. property ColorFocused;
  4141. property ColorBorder;
  4142. property ColorFlat;
  4143. property ColorLines;
  4144. property ParentColor;
  4145. property Align;
  4146. property Anchors;
  4147. property BiDiMode;
  4148. property ColCount;
  4149. property Constraints;
  4150. property DefaultColWidth;
  4151. property DefaultRowHeight;
  4152. property DefaultDrawing;
  4153. property DragCursor;
  4154. property DragKind;
  4155. property DragMode;
  4156. property Enabled;
  4157. property FixedColor;
  4158. property FixedCols;
  4159. property RowCount;
  4160. property FixedRows;
  4161. property Font;
  4162. property Options;
  4163. property ParentBiDiMode;
  4164. property ParentFont;
  4165. property ParentShowHint;
  4166. property PopupMenu;
  4167. property ScrollBars;
  4168. property ShowHint;
  4169. property TabOrder;
  4170. property Visible;
  4171. property VisibleColCount;
  4172. property VisibleRowCount;
  4173. property OnClick;
  4174. property OnColumnMoved;
  4175. property OnContextPopup;
  4176. property OnDblClick;
  4177. property OnDragDrop;
  4178. property OnDragOver;
  4179. property OnDrawCell;
  4180. property OnEndDock;
  4181. property OnEndDrag;
  4182. property OnEnter;
  4183. property OnExit;
  4184. property OnGetEditMask;
  4185. property OnGetEditText;
  4186. property OnKeyDown;
  4187. property OnKeyPress;
  4188. property OnKeyUp;
  4189. property OnMouseDown;
  4190. property OnMouseMove;
  4191. property OnMouseUp;
  4192. property OnMouseWheelDown;
  4193. property OnMouseWheelUp;
  4194. property OnRowMoved;
  4195. property OnSelectCell;
  4196. property OnSetEditText;
  4197. property OnStartDock;
  4198. property OnStartDrag;
  4199. property OnTopLeftChanged;
  4200. end;
  4201. TFlatBarcode = class(TDefineBarcode)
  4202. published
  4203. property BarCode;
  4204. property Rotate;
  4205. property Modul;
  4206. property Ratio;
  4207. property CodeType;
  4208. property Text;
  4209. property LineHeight;
  4210. property BorderWidth;
  4211. property LineTop;
  4212. property Color;
  4213. property LineColor;
  4214. property AutoSize;
  4215. property Checksum;
  4216. property CheckOdd;
  4217. property ShowText;
  4218. property Transparent;
  4219. property ShowHint;
  4220. property ParentFont;
  4221. property Font;
  4222. property Height;
  4223. property Width;
  4224. property Top;
  4225. property Left;
  4226. property OnClick;
  4227. property OnDblClick;
  4228. property OnMouseMove;
  4229. property OnMouseDown;
  4230. property OnMouseUp;
  4231. property OnKeyDown;
  4232. property OnKeyPress;
  4233. property OnDragDrop;
  4234. property OnDragOver;
  4235. property OnEndDock;
  4236. property OnEndDrag;
  4237. property OnEnter;
  4238. property OnExit;
  4239. property OnKeyUp;
  4240. property OnStartDock;
  4241. property OnStartDrag;
  4242. end;
  4243. implementation
  4244. {$R FlatCtrls.res}
  4245. uses Clipbrd, FlatCnsts;
  4246. { TDefineTicket }
  4247. constructor TDefineTicket.Create(AOwner: TComponent);
  4248. begin
  4249. inherited Create(AOwner);
  4250. Name := 'Ticket'; { do not localize }
  4251. SetSubComponent(True);
  4252. if Assigned(AOwner) then
  4253. Caption := '';//AOwner.Name;
  4254. AutoSize := True;
  4255. end;
  4256. procedure TDefineTicket.AdjustBounds;
  4257. begin
  4258. inherited AdjustBounds;
  4259. if Owner is TDefineEdit then begin
  4260. with Owner as TDefineEdit do begin
  4261. SetTicketPosition(TicketPosition);
  4262. end;
  4263. end;
  4264. if Owner is TDefineComboBox then begin
  4265. with Owner as TDefineComboBox do
  4266. SetTicketPosition(TicketPosition);
  4267. end;
  4268. if Owner is TDefineColorBox then begin
  4269. with Owner as TDefineColorBox do
  4270. SetTicketPosition(TicketPosition);
  4271. end;
  4272. end;
  4273. function TDefineTicket.GetHeight: Integer;
  4274. begin
  4275. Result := inherited Height;
  4276. end;
  4277. function TDefineTicket.GetLeft: Integer;
  4278. begin
  4279. Result := inherited Left;
  4280. end;
  4281. function TDefineTicket.GetTop: Integer;
  4282. begin
  4283. Result := inherited Top;
  4284. end;
  4285. function TDefineTicket.GetWidth: Integer;
  4286. begin
  4287. Result := inherited Width;
  4288. end;
  4289. procedure TDefineTicket.SetHeight(const Value: Integer);
  4290. begin
  4291. SetBounds(Left, Top, Width, Value);
  4292. end;
  4293. procedure TDefineTicket.SetWidth(const Value: Integer);
  4294. begin
  4295. SetBounds(Left, Top, Value, Height);
  4296. end;
  4297. { TDefineEdit }
  4298. procedure TDefineEdit.SetupInternalLabel;
  4299. begin
  4300. if not(csDesigning in ComponentState) then begin
  4301. fHintLabel := TLabel.Create(Self);
  4302. with fHintLabel do begin
  4303. Parent := self;
  4304. OnClick := LabelMouseEnter;
  4305. AutoSize := false;
  4306. Visible := false;
  4307. Transparent := True;
  4308. FocusControl := self;
  4309. Font.Assign(self.Font);
  4310. end;
  4311. end;
  4312. if (DefaultHasTicket)and(not Assigned(FTicket)) then
  4313. begin
  4314. FTicket := TDefineTicket.Create(self);
  4315. FTicket.FreeNotification(Self);
  4316. FTicket.AutoSize := True;
  4317. FTicket.Transparent := True;
  4318. FTicket.FocusControl := Self;
  4319. end;
  4320. end;
  4321. constructor TDefineEdit.Create(AOwner: TComponent);
  4322. begin
  4323. inherited Create(AOwner);
  4324. ControlStyle := ControlStyle - [csFramed];
  4325. ParentFont := True;
  4326. AutoSize := False;
  4327. Ctl3D := False;
  4328. BorderStyle := bsNone;
  4329. FFocusColor := clWhite;
  4330. FBorderColor := DefaultBorderColor;
  4331. FFlatColor := DefaultFlatColor;
  4332. FParentColor := True;
  4333. FAlignment := taLeftJustify;
  4334. FTicketPosition := poLeft;
  4335. FTicketSpace := 3;
  4336. SetupInternalLabel;
  4337. end;
  4338. destructor TDefineEdit.Destroy;
  4339. begin
  4340. if Assigned(fHintLabel) then fHintLabel.Free;
  4341. if Assigned(FTicket) then FTicket.Free;
  4342. inherited destroy;
  4343. end;
  4344. procedure TDefineEdit.RedrawBorder(const Clip: HRGN);
  4345. var
  4346. Attrib:TBorderAttrib;
  4347. begin
  4348. with Attrib do
  4349. begin
  4350. Ctrl := self;
  4351. FocusColor := ColorFocused;
  4352. BorderColor := ColorBorder;
  4353. FlatColor := ColorFlat;
  4354. MouseState := MouseIn;
  4355. FocusState := Focused;
  4356. DesignState := ComponentState;
  4357. HasBars := false;
  4358. BoldState := false;
  4359. end;
  4360. Color := DrawEditBorder(Attrib,Clip);
  4361. if (not(csDesigning in ComponentState))and(Assigned(fHintLabel)) then
  4362. begin
  4363. if not Focused then
  4364. fHintLabel.Visible := self.Text = ''
  4365. else
  4366. fHintLabel.Visible := False;
  4367. if fHintLabel.Visible then
  4368. begin
  4369. fHintLabel.Font.Assign(self.Font);
  4370. fHintLabel.Width := self.Width;
  4371. fHintLabel.Top := (self.Height-fHintLabel.Height-2) div 2;
  4372. fHintLabel.Left := 0;
  4373. fHintLabel.Caption := self.Hint;
  4374. end;
  4375. end;
  4376. end;
  4377. procedure TDefineEdit.CreateParams(var Params: TCreateParams);
  4378. begin
  4379. inherited CreateParams(Params);
  4380. with Params do begin
  4381. Params.Style := Params.Style or ES_MULTILINE or Aligns[FAlignment];
  4382. end;
  4383. end;
  4384. procedure TDefineEdit.KeyPress(var Key: Char);
  4385. begin
  4386. inherited KeyPress(Key);
  4387. if (Key = Char(VK_RETURN)) then
  4388. Key := #0;
  4389. end;
  4390. procedure TDefineEdit.SetParentColor(Value: Boolean);
  4391. begin
  4392. if Value <> FParentColor then
  4393. begin
  4394. FParentColor := Value;
  4395. if FParentColor then
  4396. begin
  4397. if Parent <> nil then
  4398. FFlatColor := TForm(Parent).Color;
  4399. RedrawBorder(0);
  4400. end;
  4401. end;
  4402. end;
  4403. procedure TDefineEdit.LabelMouseEnter(Sender: TObject);
  4404. begin
  4405. if (not(csDesigning in ComponentState))and(Assigned(fHintLabel)) then begin
  4406. fHintLabel.Visible := false;
  4407. self.SetFocus;
  4408. end;
  4409. end;
  4410. procedure TDefineEdit.SetTicketPosition(const Value: TTicketPosition);
  4411. begin
  4412. if Assigned(FTicket) then
  4413. begin
  4414. FTicketPosition := Value;
  4415. SetTicketPoint(Value,Self,Ticket,FTicketSpace);
  4416. end;
  4417. end;
  4418. procedure TDefineEdit.SetTicketSpace(const Value: Integer);
  4419. begin
  4420. if Assigned(FTicket) then
  4421. begin
  4422. FTicketSpace := Value;
  4423. SetTicketPosition(FTicketPosition);
  4424. end;
  4425. end;
  4426. procedure TDefineEdit.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  4427. begin
  4428. inherited SetBounds(ALeft, ATop, AWidth, AHeight);
  4429. SetTicketPosition(FTicketPosition);
  4430. end;
  4431. procedure TDefineEdit.SetParent(AParent: TWinControl);
  4432. begin
  4433. if Assigned(FTicket) then
  4434. begin
  4435. FTicket.Parent := AParent;
  4436. FTicket.Visible := Visible;
  4437. end;
  4438. inherited SetParent(AParent);
  4439. end;
  4440. procedure TDefineEdit.CMBidimodechanged(var Message: TMessage);
  4441. begin
  4442. inherited;
  4443. if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
  4444. end;
  4445. procedure TDefineEdit.CMVisiblechanged(var Message: TMessage);
  4446. begin
  4447. inherited;
  4448. if Assigned(FTicket) then FTicket.Visible := Visible;
  4449. end;
  4450. procedure TDefineEdit.SetName(const Value: TComponentName);
  4451. begin
  4452. if Assigned(FTicket) then
  4453. begin
  4454. if (csDesigning in ComponentState) and ((FTicket.GetTextLen = 0) or
  4455. (CompareText(FTicket.Caption, Name) = 0)) then
  4456. FTicket.Caption := Value;
  4457. end;
  4458. inherited SetName(Value);
  4459. if (csDesigning in ComponentState)and(Assigned(FTicket))and
  4460. ((GetTextLen = 0)or(CompareText(Text, Name) = 0)) then
  4461. Text := '';
  4462. end;
  4463. procedure TDefineEdit.Notification(AComponent: TComponent;
  4464. Operation: TOperation);
  4465. begin
  4466. inherited Notification(AComponent, Operation);
  4467. if (AComponent = FTicket) and (Operation = opRemove) then
  4468. FTicket := nil;
  4469. end;
  4470. procedure TDefineEdit.CMSysColorChange(var Message: TMessage);
  4471. begin
  4472. if (Parent <> nil)and(FParentColor) then
  4473. FFlatColor := TForm(Parent).Color;
  4474. RedrawBorder(0);
  4475. end;
  4476. procedure TDefineEdit.CMParentColorChanged(var Message: TWMNoParams);
  4477. begin
  4478. if (Parent <> nil)and(FParentColor) then
  4479. FFlatColor := TForm(Parent).Color;
  4480. RedrawBorder(0);
  4481. end;
  4482. procedure TDefineEdit.SetColors(Index: Integer; Value: TColor);
  4483. begin
  4484. case Index of
  4485. 0: FFocusColor := Value;
  4486. 1: FBorderColor := Value;
  4487. 2: begin
  4488. FFlatColor := Value;
  4489. FParentColor := False;
  4490. end;
  4491. end;
  4492. RedrawBorder(0);
  4493. end;
  4494. procedure TDefineEdit.CMMouseEnter(var Message: TMessage);
  4495. begin
  4496. inherited;
  4497. if (GetActiveWindow <> 0) then
  4498. begin
  4499. FMouseIn := True;
  4500. RedrawBorder(0);
  4501. end;
  4502. end;
  4503. procedure TDefineEdit.CMMouseLeave(var Message: TMessage);
  4504. begin
  4505. inherited;
  4506. if MouseIn then begin
  4507. FMouseIn := False;
  4508. RedrawBorder(0);
  4509. end;
  4510. end;
  4511. procedure TDefineEdit.NewAdjustHeight;
  4512. var
  4513. DC: HDC;
  4514. SaveFont: HFONT;
  4515. Metrics: TTextMetric;
  4516. begin
  4517. DC := GetDC(0);
  4518. SaveFont := SelectObject(DC, Font.Handle);
  4519. GetTextMetrics(DC, Metrics);
  4520. SelectObject(DC, SaveFont);
  4521. ReleaseDC(0, DC);
  4522. Height := Metrics.tmHeight + 6;
  4523. end;
  4524. procedure TDefineEdit.Loaded;
  4525. begin
  4526. inherited;
  4527. //if not(csDesigning in ComponentState) then
  4528. //begin
  4529. NewAdjustHeight;
  4530. //end;
  4531. end;
  4532. procedure TDefineEdit.CMTextChanged(var Message: TMessage);
  4533. begin
  4534. inherited;
  4535. if not(csDesigning in ComponentState) and Assigned(fHintLabel) then
  4536. begin
  4537. if fHintLabel.Visible then
  4538. fHintLabel.Visible := false;
  4539. if (not fHintLabel.Visible) and (Text = '') then
  4540. fHintLabel.Visible := True;
  4541. end;
  4542. end;
  4543. procedure TDefineEdit.CMEnabledChanged(var Message: TMessage);
  4544. const
  4545. EnableColors: array[Boolean] of TColor= (clBtnFace, clWindow);
  4546. begin
  4547. inherited;
  4548. Color := EnableColors[Enabled];
  4549. if assigned(FTicket) then FTicket.Enabled := Enabled;
  4550. if (not(csDesigning in ComponentState))and(assigned(fHintLabel)) then
  4551. fHintLabel.Enabled := Enabled;
  4552. RedrawBorder(0);
  4553. end;
  4554. procedure TDefineEdit.CMFontChanged(var Message: TMessage);
  4555. begin
  4556. inherited;
  4557. if not((csDesigning in ComponentState) and (csLoading in ComponentState)) then
  4558. NewAdjustHeight;
  4559. if (not(csDesigning in ComponentState))and(assigned(fHintLabel)) then
  4560. fHintLabel.Font.Assign(Font);
  4561. end;
  4562. procedure TDefineEdit.WMSetFocus(var Message: TWMSetFocus);
  4563. begin
  4564. inherited;
  4565. if not(csDesigning in ComponentState) then
  4566. begin
  4567. RedrawBorder(0);
  4568. SelectAll;
  4569. end;
  4570. end;
  4571. procedure TDefineEdit.WMKillFocus(var Message: TWMKillFocus);
  4572. begin
  4573. inherited;
  4574. if not(csDesigning in ComponentState) then
  4575. RedrawBorder(0);
  4576. end;
  4577. procedure TDefineEdit.WMNCCalcSize(var Message: TWMNCCalcSize);
  4578. begin
  4579. inherited;
  4580. InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
  4581. end;
  4582. procedure TDefineEdit.WMNCPaint(var Message: TMessage);
  4583. begin
  4584. inherited;
  4585. RedrawBorder(HRGN(Message.WParam));
  4586. end;
  4587. procedure TDefineEdit.SetAlignment(const Value: TAlignment);
  4588. begin
  4589. If FAlignment <> Value Then
  4590. begin
  4591. FAlignment := Value;
  4592. RecreateWnd;
  4593. end;
  4594. end;
  4595. function TDefineEdit.GetMouseIn: Boolean;
  4596. begin
  4597. Result := FMouseIn;
  4598. end;
  4599. procedure TDefineEdit.WMSize(var Message: TWMSize);
  4600. begin
  4601. inherited;
  4602. NewAdjustHeight;
  4603. end;
  4604. { TDefineInteger }
  4605. procedure ResetBounds(Self:TWinControl; Spin:TDefineSpin);
  4606. begin
  4607. with Self do begin
  4608. SetEditRect(Handle, Clientwidth, ClientHeight, Spin.Width);
  4609. Spin.SetBounds(Width - Spin.Width - 5, 0, Spin.Width, Height - 6);
  4610. end;
  4611. end;
  4612. constructor TDefineInteger.Create(AOwner: TComponent);
  4613. begin
  4614. inherited Create(AOwner);
  4615. ControlStyle := ControlStyle - [csSetCaption];
  4616. FButton := TDefineSpin.Create(Self);
  4617. FButton.Parent := Self;
  4618. FButton.Width := 32;
  4619. FButton.Height := 10;
  4620. FButton.Visible := True;
  4621. FButton.FocusControl := Self;
  4622. FButton.OnUpClick := UpClick;
  4623. FButton.OnDownClick := DownClick;
  4624. Text := '0';
  4625. FIncrement := 1;
  4626. FMaxValue := 0;
  4627. FMinValue := 0;
  4628. FEditorEnabled := True;
  4629. end;
  4630. destructor TDefineInteger.Destroy;
  4631. begin
  4632. FButton.Free;
  4633. FButton := nil;
  4634. inherited Destroy;
  4635. end;
  4636. procedure TDefineInteger.UpClick(Sender: TObject);
  4637. begin
  4638. if ReadOnly then
  4639. MessageBeep(0)
  4640. else
  4641. Value := Value + FIncrement;
  4642. end;
  4643. procedure TDefineInteger.DownClick (Sender: TObject);
  4644. begin
  4645. if ReadOnly then
  4646. MessageBeep(0)
  4647. else
  4648. Value := Value - FIncrement;
  4649. end;
  4650. procedure TDefineInteger.KeyDown(var Key: Word; Shift: TShiftState);
  4651. begin
  4652. case Key of
  4653. VK_UP: UpClick(Self);
  4654. VK_DOWN: DownClick(Self);
  4655. end;
  4656. inherited KeyDown(Key, Shift);
  4657. end;
  4658. function TDefineInteger.IsValidChar(Key: Char): Boolean;
  4659. begin
  4660. Result := (Key in ['0'..'9',#8,#13]);
  4661. if not FEditorEnabled and Result then
  4662. Result := False;
  4663. end;
  4664. procedure TDefineInteger.KeyPress(var Key: Char);
  4665. begin
  4666. if not IsValidChar(Key) then begin
  4667. Key := #0;
  4668. MessageBeep(0)
  4669. end;
  4670. if Key <> #0 then
  4671. inherited KeyPress(Key);
  4672. end;
  4673. procedure TDefineInteger.WMSize(var Message: TWMSize);
  4674. begin
  4675. inherited;
  4676. if Button <> nil then begin
  4677. ResetBounds(Self,Button);
  4678. end;
  4679. end;
  4680. function TDefineInteger.CheckValue(NewValue: LongInt): LongInt;
  4681. begin
  4682. Result := NewValue;
  4683. if (FMaxValue <> FMinValue) then
  4684. begin
  4685. if NewValue < FMinValue then
  4686. Result := FMinValue
  4687. else
  4688. if NewValue > FMaxValue then
  4689. Result := FMaxValue;
  4690. end;
  4691. end;
  4692. procedure TDefineInteger.WMPaste(var Message: TWMPaste);
  4693. begin
  4694. if not FEditorEnabled or ReadOnly then
  4695. Exit;
  4696. inherited;
  4697. end;
  4698. procedure TDefineInteger.WMCut(var Message: TWMPaste);
  4699. begin
  4700. if not FEditorEnabled or ReadOnly then
  4701. Exit;
  4702. inherited;
  4703. end;
  4704. procedure TDefineInteger.CMExit(var Message: TCMExit);
  4705. begin
  4706. inherited;
  4707. if Text = '' then
  4708. Value := 0;
  4709. if CheckValue(Value) <> Value then
  4710. SetValue(Value)
  4711. else
  4712. SetValue(Value);
  4713. end;
  4714. function TDefineInteger.GetValue: LongInt;
  4715. begin
  4716. if Text = '' then
  4717. Text := '0';
  4718. try
  4719. result := StrToInt(Text);
  4720. except
  4721. result := FMinValue;
  4722. end;
  4723. end;
  4724. procedure TDefineInteger.SetValue(NewValue: LongInt);
  4725. begin
  4726. Text := IntToStr(CheckValue(NewValue));
  4727. end;
  4728. procedure TDefineInteger.CMEnter(var Message: TCMGotFocus);
  4729. begin
  4730. if AutoSelect and not (csLButtonDown in ControlState) then
  4731. SelectAll;
  4732. inherited;
  4733. end;
  4734. procedure TDefineInteger.Loaded;
  4735. begin
  4736. ResetBounds(Self,Button);
  4737. inherited Loaded;
  4738. end;
  4739. procedure TDefineInteger.CreateWnd;
  4740. begin
  4741. inherited CreateWnd;
  4742. ResetBounds(Self,Button);
  4743. end;
  4744. procedure TDefineInteger.CMTextChanged(var Message: TMessage);
  4745. begin
  4746. inherited;
  4747. if Text = '' then begin
  4748. Text := '0';
  4749. end;
  4750. Value := CheckValue(StrToInt(Text));
  4751. end;
  4752. { TDefineFloat }
  4753. constructor TDefineFloat.Create(AOwner: TComponent);
  4754. begin
  4755. inherited Create(AOwner);
  4756. ControlStyle := ControlStyle - [csSetCaption];
  4757. FButton := TDefineSpin.Create(Self);
  4758. FButton.Parent := Self;
  4759. FButton.Width := 32;
  4760. FButton.Height := 10;
  4761. FButton.Visible := True;
  4762. FButton.FocusControl := Self;
  4763. FButton.OnUpClick := UpClick;
  4764. FButton.OnDownClick := DownClick;
  4765. Text := '0' + DecimalSeparator + '00';
  4766. FDigits := 2;
  4767. FPrecision := 9;
  4768. FIncrement := 0.5;
  4769. FEditorEnabled := True;
  4770. end;
  4771. destructor TDefineFloat.Destroy;
  4772. begin
  4773. FButton.Free;
  4774. FButton := nil;
  4775. inherited Destroy;
  4776. end;
  4777. procedure TDefineFloat.KeyDown(var Key: Word; Shift: TShiftState);
  4778. begin
  4779. case Key of
  4780. VK_UP: UpClick(Self);
  4781. VK_DOWN: DownClick(Self);
  4782. end;
  4783. inherited KeyDown(Key, Shift);
  4784. end;
  4785. procedure TDefineFloat.KeyPress(var Key: Char);
  4786. begin
  4787. if (not IsValidChar(Key))or((key='.') and (pos('.',Text)>0)) then begin
  4788. Key := #0;
  4789. MessageBeep(0)
  4790. end;
  4791. if Key <> #0 then
  4792. inherited KeyPress(Key);
  4793. end;
  4794. function TDefineFloat.IsValidChar(Key: Char): Boolean;
  4795. begin
  4796. Result := (Key in [DecimalSeparator, '0'..'9',#8,#13,#46]);
  4797. if not FEditorEnabled and Result then
  4798. Result := False;
  4799. end;
  4800. procedure TDefineFloat.WMSize(var Message: TWMSize);
  4801. begin
  4802. inherited;
  4803. if Button <> nil then begin
  4804. ResetBounds(Self,Button);
  4805. end;
  4806. end;
  4807. function TDefineFloat.CheckValue(Value: Extended): Extended;
  4808. begin
  4809. Result := Value;
  4810. if (FMaxValue <> FMinValue) then begin
  4811. if Value < FMinValue then
  4812. Result := FMinValue
  4813. else
  4814. if Value > FMaxValue then
  4815. Result := FMaxValue;
  4816. end;
  4817. end;
  4818. procedure TDefineFloat.UpClick(Sender: TObject);
  4819. begin
  4820. if ReadOnly then
  4821. MessageBeep(0)
  4822. else
  4823. Value := Value + FIncrement;
  4824. end;
  4825. procedure TDefineFloat.DownClick(Sender: TObject);
  4826. begin
  4827. if ReadOnly then
  4828. MessageBeep(0)
  4829. else
  4830. Value := Value - FIncrement;
  4831. end;
  4832. procedure TDefineFloat.WMPaste(var Message: TWMPaste);
  4833. begin
  4834. if not FEditorEnabled or ReadOnly then
  4835. Exit;
  4836. inherited;
  4837. end;
  4838. procedure TDefineFloat.WMCut(var Message: TWMPaste);
  4839. begin
  4840. if not FEditorEnabled or ReadOnly then
  4841. Exit;
  4842. inherited;
  4843. end;
  4844. procedure TDefineFloat.CMExit(var Message: TCMExit);
  4845. begin
  4846. inherited;
  4847. if (Text = '')or(Text = '¥')or(Text = '.') then
  4848. Value := 0;
  4849. if CheckValue(Value) <> Value then
  4850. SetValue(Value)
  4851. else
  4852. SetValue(Value);
  4853. end;
  4854. function TDefineFloat.GetValue: Extended;
  4855. var
  4856. s: string;
  4857. begin
  4858. try
  4859. s := Text;
  4860. while Pos(CurrencyString, S) > 0 do
  4861. Delete(S, Pos(CurrencyString, S), Length(CurrencyString));
  4862. while Pos(#32, S) > 0 do
  4863. Delete(S, Pos(#32, S), 1);
  4864. while Pos(ThousandSeparator, S) > 0 do
  4865. Delete(S, Pos(ThousandSeparator, S), Length(ThousandSeparator));
  4866. //Delete negative numbers in format Currency
  4867. if Pos('(', S) > 0 then
  4868. begin
  4869. Delete(S, Pos('(', S), 1);
  4870. if Pos(')', S) > 0 then
  4871. Delete(S, Pos(')', S), 1);
  4872. Result := StrToFloat(S)*-1;
  4873. end
  4874. else
  4875. Result := StrToFloat(S);
  4876. except
  4877. Result := FMinValue;
  4878. end;
  4879. end;
  4880. procedure TDefineFloat.SetFloatFormat(Value: TFloatFormat);
  4881. begin
  4882. FFloatFormat := Value;
  4883. Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
  4884. end;
  4885. procedure TDefineFloat.SetDigits(Value: Integer);
  4886. begin
  4887. FDigits := Value;
  4888. Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
  4889. end;
  4890. procedure TDefineFloat.SetPrecision(Value: Integer);
  4891. begin
  4892. FPrecision := Value;
  4893. Text := FloatToStrF(CheckValue(GetValue), FloatFormat, Precision, Digits);
  4894. end;
  4895. procedure TDefineFloat.SetValue(Value: Extended);
  4896. begin
  4897. Text := FloatToStrF(CheckValue(Value), FloatFormat, Precision, Digits);
  4898. end;
  4899. procedure TDefineFloat.CMEnter(var Message: TCMGotFocus);
  4900. begin
  4901. if AutoSelect and not (csLButtonDown in ControlState) then
  4902. SelectAll;
  4903. inherited;
  4904. end;
  4905. procedure TDefineFloat.Loaded;
  4906. begin
  4907. ResetBounds(Self,Button);
  4908. inherited Loaded;
  4909. end;
  4910. procedure TDefineFloat.CreateWnd;
  4911. begin
  4912. inherited CreateWnd;
  4913. ResetBounds(Self,Button);
  4914. end;
  4915. procedure TDefineFloat.CMTextChanged(var Message: TMessage);
  4916. begin
  4917. inherited;
  4918. if Text = '' then begin
  4919. Text := '0';
  4920. end;
  4921. Value := GetValue;
  4922. end;
  4923. { TDefineMemo }
  4924. constructor TDefineMemo.Create(AOwner: TComponent);
  4925. begin
  4926. inherited Create(AOwner);
  4927. ControlStyle := ControlStyle - [csFramed];
  4928. ParentFont := True;
  4929. AutoSize := False;
  4930. Ctl3D := False;
  4931. BorderStyle := bsNone;
  4932. FFocusColor := clWhite;
  4933. FBorderColor := DefaultBorderColor;
  4934. FFlatColor := DefaultFlatColor;
  4935. FParentColor := True;
  4936. FMouseIn := False;
  4937. end;
  4938. procedure TDefineMemo.RedrawBorder(const Clip: HRGN);
  4939. var
  4940. Attrib:TBorderAttrib;
  4941. begin
  4942. with Attrib do
  4943. begin
  4944. Ctrl := self;
  4945. FocusColor := ColorFocused;
  4946. BorderColor := ColorBorder;
  4947. FlatColor := ColorFlat;
  4948. MouseState := MouseIn;
  4949. FocusState := Focused;
  4950. DesignState := ComponentState;
  4951. HasBars := ScrollBars = ssBoth;
  4952. BoldState := false;
  4953. end;
  4954. Color := DrawEditBorder(Attrib,Clip);
  4955. end;
  4956. procedure TDefineMemo.SetParentColor(Value: Boolean);
  4957. begin
  4958. if Value <> FParentColor then
  4959. begin
  4960. FParentColor := Value;
  4961. if FParentColor then
  4962. begin
  4963. if Parent <> nil then
  4964. FFlatColor := TForm(Parent).Color;
  4965. RedrawBorder(0);
  4966. end;
  4967. end;
  4968. end;
  4969. procedure TDefineMemo.CMSysColorChange(var Message: TMessage);
  4970. begin
  4971. if (Parent <> nil)and(FParentColor) then
  4972. FFlatColor := TForm(Parent).Color;
  4973. RedrawBorder(0);
  4974. end;
  4975. procedure TDefineMemo.CMParentColorChanged(var Message: TWMNoParams);
  4976. begin
  4977. if (Parent <> nil)and(FParentColor) then
  4978. FFlatColor := TForm(Parent).Color;
  4979. RedrawBorder(0);
  4980. end;
  4981. procedure TDefineMemo.SetColors(Index: Integer; Value: TColor);
  4982. begin
  4983. case Index of
  4984. 0: FFocusColor := Value;
  4985. 1: FBorderColor := Value;
  4986. 2: begin
  4987. FFlatColor := Value;
  4988. FParentColor := False;
  4989. end;
  4990. end;
  4991. RedrawBorder(0);
  4992. end;
  4993. procedure TDefineMemo.CMMouseEnter(var Message: TMessage);
  4994. begin
  4995. inherited;
  4996. if (GetActiveWindow <> 0) then
  4997. begin
  4998. FMouseIn := True;
  4999. RedrawBorder(0);
  5000. end;
  5001. end;
  5002. procedure TDefineMemo.CMMouseLeave(var Message: TMessage);
  5003. begin
  5004. inherited;
  5005. if MouseIn then begin
  5006. FMouseIn := False;
  5007. RedrawBorder(0);
  5008. end;
  5009. end;
  5010. procedure TDefineMemo.CMEnabledChanged(var Message: TMessage);
  5011. const
  5012. EnableColors: array[Boolean] of TColor = (clBtnFace, clWindow);
  5013. begin
  5014. inherited;
  5015. Color := EnableColors[Enabled];
  5016. RedrawBorder(0);
  5017. end;
  5018. procedure TDefineMemo.WMSetFocus(var Message: TWMSetFocus);
  5019. begin
  5020. inherited;
  5021. if not(csDesigning in ComponentState) then
  5022. RedrawBorder(0);
  5023. end;
  5024. procedure TDefineMemo.WMKillFocus(var Message: TWMKillFocus);
  5025. begin
  5026. inherited;
  5027. if not(csDesigning in ComponentState) then
  5028. RedrawBorder(0);
  5029. end;
  5030. procedure TDefineMemo.WMNCCalcSize(var Message: TWMNCCalcSize);
  5031. begin
  5032. inherited;
  5033. InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
  5034. end;
  5035. procedure TDefineMemo.WMNCPaint(var Message: TMessage);
  5036. begin
  5037. inherited;
  5038. RedrawBorder(HRGN(Message.WParam));
  5039. end;
  5040. function TDefineMemo.GetMouseIn: Boolean;
  5041. begin
  5042. Result := FMouseIn;
  5043. end;
  5044. { TDefineIPEdit }
  5045. function TDefineIPEdit.Replace(Start, Len: Integer): integer;
  5046. var t,s:String;
  5047. begin
  5048. s := Text;
  5049. t := trim(copy(Text,Start-Len,Len));
  5050. if t <> '' then begin
  5051. if StrToInt(t)>255 then begin
  5052. delete(s,Start-Len,Len);
  5053. insert('255',s,Start-Len);
  5054. Text := s;
  5055. SelStart := Start-4;
  5056. SelLength := Len;
  5057. end;
  5058. end;
  5059. result := SelStart;
  5060. end;
  5061. procedure TDefineIPEdit.CMTextChanged(var Message: TMessage);
  5062. begin
  5063. inherited;
  5064. SetIPText(Text);
  5065. end;
  5066. constructor TDefineIPEdit.Create(AOwner: TComponent);
  5067. begin
  5068. inherited Create(AOwner);
  5069. EditMask := IPMaskStr;
  5070. Text := IPStart;
  5071. end;
  5072. function TDefineIPEdit.GetIPText: String;
  5073. begin
  5074. result := self.Text;
  5075. while Pos(#32,Result) > 0 do
  5076. delete(Result,Pos(#32,Result),1);
  5077. end;
  5078. procedure TDefineIPEdit.KeyPress(var Key: Char);
  5079. begin
  5080. inherited KeyPress(Key);
  5081. end;
  5082. procedure TDefineIPEdit.SetIPText(const Value: String);
  5083. var i:integer;
  5084. t:TIPChar;
  5085. s:string;
  5086. begin
  5087. if fIPAddress <> Value then begin
  5088. if Value <> '' then begin
  5089. s := '';
  5090. for i:=1 to Length(Value) do begin
  5091. if Value[i] in ['0'..'9','.'] then
  5092. s := s + Value[i];
  5093. end;
  5094. if Length(s)>0 then
  5095. begin
  5096. if s[Length(s)]<>'.' then
  5097. s:=s+'.';
  5098. IPEmpty(IPText);
  5099. i:=1;
  5100. while (pos('.',s)>0)and(i<=4) do begin
  5101. t:=Trim(Copy(s,1,Pos('.',s)-1));
  5102. if t <> '' then begin
  5103. if StrToInt(t) > 255 then
  5104. IPValue(IPText,I,'255')
  5105. else begin
  5106. case Length(t) of
  5107. 1:t := #32+t+#32;
  5108. 2:t := #32+t;
  5109. end;
  5110. IPValue(IPText,I,t);
  5111. end;
  5112. end;
  5113. s:=copy(s,Pos('.',s)+1,Length(s));
  5114. Inc(I);
  5115. end;
  5116. end;
  5117. fIPAddress := format('%s.%s.%s.%s',[IPText.NO1,IPText.NO2,IPText.NO3,IPText.NO4]);
  5118. end else begin
  5119. fIPAddress := IPStart;
  5120. end;
  5121. end;
  5122. Text := fIPAddress;
  5123. end;
  5124. procedure TDefineIPEdit.CMExit(var Message: TCMExit);
  5125. begin
  5126. if IsMasked and not (csDesigning in ComponentState) then
  5127. SetIPText(Text);
  5128. inherited;
  5129. end;
  5130. function TDefineIPEdit.GetInx: integer;
  5131. var inx:integer;
  5132. begin
  5133. GetSel(Result,inx);
  5134. end;
  5135. procedure TDefineIPEdit.KeyDown(var Key: Word; Shift: TShiftState);
  5136. begin
  5137. inherited KeyDown(Key, Shift);
  5138. end;
  5139. procedure TDefineIPEdit.KeyUp(var Key: Word; Shift: TShiftState);
  5140. begin
  5141. if IsMasked then begin
  5142. if SelStart <= 4 then
  5143. Replace( 4,3)
  5144. else if SelStart <= 8 then
  5145. Replace( 8,3)
  5146. else if SelStart <= 12 then
  5147. Replace(12,3)
  5148. else
  5149. Replace(16,3);
  5150. end;
  5151. inherited KeyUp(Key,Shift);
  5152. end;
  5153. { TDefineComboBox }
  5154. procedure TDefineComboBox.SetupInternalLabel;
  5155. begin
  5156. if DefaultHasTicket then begin
  5157. if Assigned(FTicket) then exit;
  5158. FTicket := TDefineTicket.Create(Self);
  5159. FTicket.FreeNotification(Self);
  5160. FTicket.Transparent := True;
  5161. FTicket.FocusControl := Self;
  5162. end;
  5163. end;
  5164. constructor TDefineComboBox.Create(AOwner: TComponent);
  5165. begin
  5166. inherited Create(AOwner);
  5167. ControlStyle := ControlStyle - [csFixedHeight] + [csOpaque];
  5168. TControlCanvas(Canvas).Control := self;
  5169. FButtonWidth := 16;
  5170. FSysBtnWidth := GetSystemMetrics(SM_CXVSCROLL);
  5171. FListInstance := MakeObjectInstance(ListWndProc);
  5172. FDefListProc := nil;
  5173. ItemHeight := 13;
  5174. FArrowColor := clBlack;
  5175. FArrowBackgroundColor := $00C5D6D9;
  5176. FFocusedColor := clWhite;
  5177. FFlatColor := DefaultFlatColor;
  5178. FParentColor := True;
  5179. FBorderColor := DefaultBorderColor;
  5180. FReadOnly := false;
  5181. FTicketPosition := poLeft;
  5182. FTicketSpace := 3;
  5183. SetBounds(0,0,120,20);
  5184. SetupInternalLabel;
  5185. end;
  5186. destructor TDefineComboBox.Destroy;
  5187. begin
  5188. FreeObjectInstance(FListInstance);
  5189. inherited Destroy;
  5190. end;
  5191. procedure TDefineComboBox.SetColors(Index: Integer; Value: TColor);
  5192. begin
  5193. case Index of
  5194. 0: FArrowColor := Value;
  5195. 1: FArrowBackgroundColor := Value;
  5196. 2: FBorderColor := Value;
  5197. 3: FFlatColor := Value;
  5198. 4: FFocusedColor := Value;
  5199. end;
  5200. if index = 3 then
  5201. FParentColor := False;
  5202. Invalidate;
  5203. end;
  5204. procedure TDefineComboBox.CMSysColorChange(var Message: TMessage);
  5205. begin
  5206. if FParentColor then begin
  5207. if Parent <> nil then
  5208. FFlatColor := TForm(Parent).Color;
  5209. end;
  5210. Invalidate;
  5211. end;
  5212. procedure TDefineComboBox.InvalidateSelection;
  5213. var
  5214. R: TRect;
  5215. begin
  5216. R := ClientRect;
  5217. InflateRect(R, -2, -3);
  5218. R.Left := R.Right - FButtonWidth - 8;
  5219. Dec(R.Right, FButtonWidth + 3);
  5220. if(GetFocus = Handle) and not DroppedDown then
  5221. Canvas.Brush.Color := clHighlight
  5222. else
  5223. Canvas.Brush.Color := Color;
  5224. Canvas.Brush.Style := bsSolid;
  5225. Canvas.FillRect(R);
  5226. if(GetFocus = Handle) and not DroppedDown then
  5227. begin
  5228. R := ClientRect;
  5229. InflateRect(R, -3, -3);
  5230. Dec(R.Right, FButtonWidth + 2);
  5231. Canvas.FrameRect(R);
  5232. Canvas.Brush.Color := clWindow;
  5233. end;
  5234. ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
  5235. end;
  5236. procedure TDefineComboBox.CMParentColorChanged(var Message: TWMNoParams);
  5237. begin
  5238. if FParentColor then begin
  5239. if Parent <> nil then
  5240. FFlatColor := TForm(Parent).Color;
  5241. end;
  5242. Invalidate;
  5243. end;
  5244. procedure TDefineComboBox.WndProc(var Message: TMessage);
  5245. begin
  5246. if (Message.Msg = WM_PARENTNOTIFY) then
  5247. case LoWord(Message.wParam) of
  5248. WM_CREATE:
  5249. if FDefListProc <> nil then
  5250. begin
  5251. SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FDefListProc));
  5252. FDefListProc := nil;
  5253. FChildHandle := Message.lParam;
  5254. end
  5255. else
  5256. if FChildHandle = 0 then
  5257. FChildHandle := Message.lParam
  5258. else
  5259. FListHandle := Message.lParam;
  5260. end
  5261. else
  5262. if (Message.Msg = WM_WINDOWPOSCHANGING) then
  5263. if Style in [csDropDown, csSimple] then
  5264. SetWindowPos( EditHandle, 0,
  5265. 0, 0, ClientWidth - FButtonWidth - 2 * 2 - 4, Height - 2 * 2 - 2,
  5266. SWP_NOMOVE + SWP_NOZORDER + SWP_NOACTIVATE + SWP_NOREDRAW);
  5267. inherited;
  5268. if Message.Msg = WM_CTLCOLORLISTBOX then
  5269. begin
  5270. SetBkColor(Message.wParam, ColorToRGB(Color));
  5271. Message.Result := CreateSolidBrush(ColorToRGB(Color));
  5272. end;
  5273. end;
  5274. procedure TDefineComboBox.ListWndProc(var Message: TMessage);
  5275. begin
  5276. case Message.Msg of
  5277. WM_WINDOWPOSCHANGING:
  5278. with TWMWindowPosMsg(Message).WindowPos^ do
  5279. begin
  5280. // size of the drop down list
  5281. if Style in [csDropDown, csDropDownList] then
  5282. cy := (GetFontHeight(Font)-2) * Min(DropDownCount, Items.Count) + 4
  5283. else
  5284. cy := (ItemHeight) * Min(DropDownCount, Items.Count) + 4;
  5285. if cy <= 4 then
  5286. cy := 10;
  5287. end;
  5288. else
  5289. with Message do
  5290. Result := CallWindowProc(FDefListProc, FListHandle, Msg, WParam, LParam);
  5291. end;
  5292. end;
  5293. procedure TDefineComboBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
  5294. begin
  5295. inherited;
  5296. if (ComboWnd = EditHandle) then
  5297. case Message.Msg of
  5298. WM_SETFOCUS, WM_KILLFOCUS:
  5299. SetSolidBorder;
  5300. end;
  5301. end;
  5302. procedure TDefineComboBox.WMSetFocus(var Message: TMessage);
  5303. begin
  5304. inherited;
  5305. if not (csDesigning in ComponentState) then
  5306. begin
  5307. SetSolidBorder;
  5308. Color := FFocusedColor;
  5309. if not (Style in [csSimple, csDropDown]) then
  5310. InvalidateSelection;
  5311. end;
  5312. end;
  5313. procedure TDefineComboBox.WMKillFocus(var Message: TMessage);
  5314. begin
  5315. inherited;
  5316. if not (csDesigning in ComponentState) then
  5317. begin
  5318. SetSolidBorder;
  5319. Color := FFlatColor;
  5320. if not (Style in [csSimple, csDropDown]) then
  5321. InvalidateSelection;
  5322. end;
  5323. end;
  5324. procedure TDefineComboBox.CMEnabledChanged(var Msg: TMessage);
  5325. begin
  5326. inherited;
  5327. Invalidate;
  5328. if Assigned(FTicket) then FTicket.Enabled := Enabled;
  5329. end;
  5330. procedure TDefineComboBox.CNCommand(var Message: TWMCommand);
  5331. var
  5332. R: TRect;
  5333. begin
  5334. inherited;
  5335. if Message.NotifyCode in [1, 9, CBN_DROPDOWN, CBN_SELCHANGE] then
  5336. begin
  5337. if not (Style in [csSimple, csDropDown]) then
  5338. InvalidateSelection;
  5339. end;
  5340. if (Message.NotifyCode in [CBN_CLOSEUP]) then
  5341. begin
  5342. R := GetButtonRect;
  5343. Dec(R.Left, 2);
  5344. InvalidateRect(Handle, @R, FALSE);
  5345. end;
  5346. end;
  5347. procedure TDefineComboBox.WMKeyDown(var Message: TMessage);
  5348. var
  5349. S: String;
  5350. begin
  5351. S := Text;
  5352. inherited;
  5353. if not (Style in [csSimple, csDropDown]) and(Text <> S) then
  5354. InvalidateSelection;
  5355. end;
  5356. procedure TDefineComboBox.WMPaint(var Message: TWMPaint);
  5357. var
  5358. R: TRect;
  5359. DC: HDC;
  5360. PS: TPaintStruct;
  5361. begin
  5362. DC := BeginPaint(Handle, PS);
  5363. try
  5364. R := PS.rcPaint;
  5365. if R.Right > Width - FButtonWidth - 4 then
  5366. R.Right := Width - FButtonWidth - 4;
  5367. FillRect(DC, R, Brush.Handle);
  5368. if RectInRect(GetButtonRect, PS.rcPaint) then
  5369. PaintButton;
  5370. ExcludeClipRect(DC, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
  5371. PaintWindow(DC);
  5372. if(Style = csDropDown) and DroppedDown then
  5373. begin
  5374. R := ClientRect;
  5375. InflateRect(R, -2, -2);
  5376. R.Right := Width - FButtonWidth - 3;
  5377. Canvas.Brush.Color := clWindow;
  5378. Canvas.FrameRect(R);
  5379. end
  5380. else
  5381. if Style <> csDropDown then
  5382. InvalidateSelection;
  5383. finally
  5384. EndPaint(Handle, PS);
  5385. end;
  5386. RedrawBorders;
  5387. Message.Result := 0;
  5388. end;
  5389. procedure TDefineComboBox.WMNCPaint(var Message: TMessage);
  5390. begin
  5391. inherited;
  5392. RedrawBorders;
  5393. end;
  5394. procedure TDefineComboBox.CMFontChanged(var Message: TMessage);
  5395. begin
  5396. inherited;
  5397. ItemHeight := 13;
  5398. RecreateWnd;
  5399. end;
  5400. function TDefineComboBox.GetButtonRect: TRect;
  5401. begin
  5402. GetWindowRect(Handle, Result);
  5403. OffsetRect(Result, -Result.Left, -Result.Top);
  5404. Inc(Result.Left, ClientWidth - FButtonWidth);
  5405. OffsetRect(Result, -1, 0);
  5406. end;
  5407. procedure TDefineComboBox.PaintButton;
  5408. var
  5409. R: TRect;
  5410. x, y: Integer;
  5411. begin
  5412. R := GetButtonRect;
  5413. InflateRect(R, 1, 0);
  5414. Canvas.Brush.Color := FArrowBackgroundColor;
  5415. Canvas.FillRect(R);
  5416. Canvas.Brush.Color := FBorderColor;
  5417. Canvas.FrameRect(R);
  5418. x :=(R.Right - R.Left) div 2 - 6 + R.Left;
  5419. if DroppedDown then
  5420. y :=(R.Bottom - R.Top) div 2 - 1 + R.Top
  5421. else
  5422. y :=(R.Bottom - R.Top) div 2 - 1 + R.Top;
  5423. if Enabled then
  5424. begin
  5425. Canvas.Brush.Color := FArrowColor;
  5426. Canvas.Pen.Color := FArrowColor;
  5427. if DroppedDown then
  5428. Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5429. else
  5430. Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5431. end
  5432. else
  5433. begin
  5434. Canvas.Brush.Color := clWhite;
  5435. Canvas.Pen.Color := clWhite;
  5436. Inc(x); Inc(y);
  5437. if DroppedDown then
  5438. Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5439. else
  5440. Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5441. Dec(x); Dec(y);
  5442. Canvas.Brush.Color := clGray;
  5443. Canvas.Pen.Color := clGray;
  5444. if DroppedDown then
  5445. Canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5446. else
  5447. Canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5448. end;
  5449. ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth, 0, ClientWidth, ClientHeight);
  5450. end;
  5451. procedure TDefineComboBox.PaintBorder;
  5452. var
  5453. DC: HDC;
  5454. R: TRect;
  5455. BtnFaceBrush, WindowBrush: HBRUSH;
  5456. begin
  5457. DC := GetWindowDC(Handle);
  5458. GetWindowRect(Handle, R);
  5459. OffsetRect(R, -R.Left, -R.Top);
  5460. Dec(R.Right, FButtonWidth + 1);
  5461. try
  5462. BtnFaceBrush := CreateSolidBrush(ColorToRGB(FBorderColor));
  5463. WindowBrush := CreateSolidBrush(ColorToRGB(Color));
  5464. if(not(csDesigning in ComponentState) and
  5465. (Focused or(MouseIn and not(Screen.ActiveControl is TDefineComboBox)))) then
  5466. Color := FFocusedColor
  5467. else
  5468. Color := FFlatColor;
  5469. FrameRect(DC, R, BtnFaceBrush);
  5470. InflateRect(R, -1, -1);
  5471. FrameRect(DC, R, WindowBrush);
  5472. InflateRect(R, -1, -1);
  5473. FrameRect(DC, R, WindowBrush);
  5474. finally
  5475. ReleaseDC(Handle, DC);
  5476. end;
  5477. DeleteObject(WindowBrush);
  5478. DeleteObject(BtnFaceBrush);
  5479. end;
  5480. function TDefineComboBox.GetSolidBorder: Boolean;
  5481. begin
  5482. Result :=((csDesigning in ComponentState) and Enabled) or
  5483. (not(csDesigning in ComponentState) and
  5484. (DroppedDown or(GetFocus = Handle) or(GetFocus = EditHandle)) );
  5485. end;
  5486. procedure TDefineComboBox.SetSolidBorder;
  5487. var
  5488. sb: Boolean;
  5489. begin
  5490. sb := GetSolidBorder;
  5491. if sb <> FSolidBorder then begin
  5492. FSolidBorder := sb;
  5493. RedrawBorders;
  5494. end;
  5495. end;
  5496. procedure TDefineComboBox.RedrawBorders;
  5497. begin
  5498. PaintBorder;
  5499. if Style <> csSimple then
  5500. PaintButton;
  5501. end;
  5502. procedure TDefineComboBox.CMBidimodechanged(var Message: TMessage);
  5503. begin
  5504. inherited;
  5505. if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
  5506. end;
  5507. procedure TDefineComboBox.CMVisiblechanged(var Message: TMessage);
  5508. begin
  5509. inherited;
  5510. if Assigned(FTicket) then FTicket.Visible := Visible;
  5511. end;
  5512. procedure TDefineComboBox.Notification(AComponent: TComponent;
  5513. Operation: TOperation);
  5514. begin
  5515. inherited Notification(AComponent, Operation);
  5516. if(AComponent = FTicket) and(Operation = opRemove) then
  5517. FTicket := nil;
  5518. end;
  5519. procedure TDefineComboBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  5520. begin
  5521. inherited SetBounds(ALeft, ATop, AWidth, AHeight);
  5522. SetTicketPosition(FTicketPosition);
  5523. end;
  5524. procedure TDefineComboBox.SetTicketPosition(const Value: TTicketPosition);
  5525. begin
  5526. if FTicket = nil then exit;
  5527. FTicketPosition := Value;
  5528. SetTicketPoint(Value,Self,Ticket,FTicketSpace);
  5529. end;
  5530. procedure TDefineComboBox.SetTicketSpace(const Value: Integer);
  5531. begin
  5532. if assigned(FTicket) then FTicketSpace := Value;
  5533. SetTicketPosition(FTicketPosition);
  5534. end;
  5535. procedure TDefineComboBox.SetName(const Value: TComponentName);
  5536. begin
  5537. if assigned(FTicket) then begin
  5538. if(csDesigning in ComponentState) and((FTicket.GetTextLen = 0) or
  5539. (CompareText(FTicket.Caption, Name) = 0)) then
  5540. FTicket.Caption := Value;
  5541. end;
  5542. inherited SetName(Value);
  5543. if csDesigning in ComponentState then
  5544. Text := '';
  5545. end;
  5546. procedure TDefineComboBox.SetParent(AParent: TWinControl);
  5547. begin
  5548. inherited SetParent(AParent);
  5549. if FTicket = nil then exit;
  5550. FTicket.Parent := AParent;
  5551. FTicket.Visible := True;
  5552. end;
  5553. procedure TDefineComboBox.SetParentColor(const Value: Boolean);
  5554. begin
  5555. if Value <> FParentColor then begin
  5556. FParentColor := Value;
  5557. if FParentColor then begin
  5558. if Parent <> nil then
  5559. FFlatColor := TForm(Parent).Color;
  5560. RedrawBorders;
  5561. end;
  5562. end;
  5563. end;
  5564. procedure TDefineComboBox.CMMouseEnter(var Message: TMessage);
  5565. begin
  5566. inherited;
  5567. if(GetActiveWindow <> 0) then
  5568. begin
  5569. FMouseIn := True;
  5570. RedrawBorders;
  5571. end;
  5572. end;
  5573. procedure TDefineComboBox.CMMouseLeave(var Message: TMessage);
  5574. begin
  5575. inherited;
  5576. if MouseIn then begin
  5577. FMouseIn := False;
  5578. RedrawBorders;
  5579. end;
  5580. end;
  5581. procedure TDefineComboBox.KeyPress(var Key: Char);
  5582. begin
  5583. if FReadOnly then begin
  5584. MessageBeep(0);
  5585. Key := #0;
  5586. end else inherited KeyPress(Key);
  5587. end;
  5588. procedure TDefineComboBox.SetReadOnly(const Value: boolean);
  5589. begin
  5590. if FReadOnly <> Value then begin
  5591. FReadOnly := Value;
  5592. if FEditHandle > 0 then
  5593. SendMessage(FEditHandle, EM_SETREADONLY, Ord(Value), 0);
  5594. end;
  5595. end;
  5596. procedure TDefineComboBox.CreateWnd;
  5597. begin
  5598. inherited CreateWnd;
  5599. if FEditHandle > 0 then
  5600. SendMessage(FEditHandle, EM_SETREADONLY, Ord(FReadOnly), 0);
  5601. end;
  5602. function TDefineComboBox.GetMouseIn: boolean;
  5603. begin
  5604. result := FMouseIn;
  5605. end;
  5606. { TDefineColorBox }
  5607. procedure TDefineColorBox.SetupInternalLabel;
  5608. begin
  5609. if DefaultHasTicket then begin
  5610. if Assigned(FTicket) then exit;
  5611. FTicket := TDefineTicket.Create(Self);
  5612. FTicket.FreeNotification(Self);
  5613. FTicket.Transparent := True;
  5614. FTicket.FocusControl := Self;
  5615. end;
  5616. end;
  5617. constructor TDefineColorBox.Create(AOwner: TComponent);
  5618. begin
  5619. inherited Create(AOwner);
  5620. ControlStyle := ControlStyle - [csFixedHeight] + [csOpaque];
  5621. TControlCanvas(Canvas).Control := Self;
  5622. FColorDlg := TColorDialog.Create(Self);
  5623. Style := csOwnerDrawFixed;
  5624. FButtonWidth := 16;
  5625. FSysBtnWidth := GetSystemMetrics(SM_CXVSCROLL);
  5626. FListInstance := MakeObjectInstance(ListWndProc);
  5627. FDefListProc := nil;
  5628. FArrowColor := clBlack;
  5629. FArrowBackgroundColor := $00C5D6D9;
  5630. FBorderColor := DefaultBorderColor;
  5631. FHighlightColor := clHighlight;
  5632. FShowNames := True;
  5633. FColorBoxWidth := 30;
  5634. FValue := clBlack;
  5635. FTicketPosition := poLeft;
  5636. FTicketSpace := 3;
  5637. fLanguage := lgChinese;
  5638. SetBounds(0,0,120,20);
  5639. SetupInternalLabel;
  5640. end;
  5641. destructor TDefineColorBox.Destroy;
  5642. begin
  5643. FColorDlg.Free;
  5644. FreeObjectInstance(FListInstance);
  5645. inherited;
  5646. end;
  5647. procedure TDefineColorBox.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  5648. begin
  5649. inherited SetBounds(ALeft, ATop, AWidth, AHeight);
  5650. SetTicketPosition(FTicketPosition);
  5651. end;
  5652. procedure TDefineColorBox.CMBidimodechanged(var Message: TMessage);
  5653. begin
  5654. inherited;
  5655. if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
  5656. end;
  5657. procedure TDefineColorBox.CMVisiblechanged(var Message: TMessage);
  5658. begin
  5659. inherited;
  5660. if Assigned(FTicket) then FTicket.Visible := Visible;
  5661. end;
  5662. procedure TDefineColorBox.Notification(AComponent: TComponent;
  5663. Operation: TOperation);
  5664. begin
  5665. inherited Notification(AComponent, Operation);
  5666. if(AComponent = FTicket) and(Operation = opRemove) then
  5667. FTicket := nil;
  5668. end;
  5669. procedure TDefineColorBox.SetName(const Value: TComponentName);
  5670. begin
  5671. if Assigned(FTicket) then begin
  5672. if(csDesigning in ComponentState) and((FTicket.GetTextLen = 0) or
  5673. (CompareText(FTicket.Caption, Name) = 0)) then begin
  5674. FTicket.Caption := Value;
  5675. case fLanguage of
  5676. lgChinese:FTicket.Caption := StdColorCN;
  5677. lgEnglish:FTicket.Caption := StdColorEN;
  5678. end;
  5679. end;
  5680. end;
  5681. inherited SetName(Value);
  5682. end;
  5683. procedure TDefineColorBox.SetParent(AParent: TWinControl);
  5684. begin
  5685. inherited SetParent(AParent);
  5686. if FTicket = nil then exit;
  5687. FTicket.Parent := AParent;
  5688. FTicket.Visible := True;
  5689. end;
  5690. procedure TDefineColorBox.SetLanguage(const Value: TLanguage);
  5691. var Item:Integer;
  5692. begin
  5693. if(fLanguage <> Value)and(Items.Count>=StdColorCount) then begin
  5694. fLanguage := Value;
  5695. for Item := Low(StdColors) to High(StdColors) do begin
  5696. case Value of
  5697. lgChinese : Items[Item] := StdColors[Item].cnName;
  5698. lgEnglish : Items[Item] := StdColors[Item].enName;
  5699. end;
  5700. end;
  5701. if Assigned(FTicket) then begin
  5702. case fLanguage of
  5703. lgChinese : FTicket.Caption := StdColorCN;
  5704. lgEnglish : FTicket.Caption := StdColorEN;
  5705. end;
  5706. end;
  5707. for Item := 0 to Pred(Items.Count) do
  5708. begin
  5709. if TColor(Items.Objects[Item]) = FValue then
  5710. begin
  5711. ItemIndex := Item;
  5712. Change;
  5713. Break;
  5714. end;
  5715. end;
  5716. end;
  5717. end;
  5718. procedure TDefineColorBox.SetTicketSpace(const Value: Integer);
  5719. begin
  5720. FTicketSpace := Value;
  5721. SetTicketPosition(FTicketPosition);
  5722. end;
  5723. procedure TDefineColorBox.SetTicketPosition(const Value: TTicketPosition);
  5724. begin
  5725. if FTicket = nil then exit;
  5726. FTicketPosition := Value;
  5727. SetTicketPoint(Value,Self,Ticket,FTicketSpace);;
  5728. end;
  5729. procedure TDefineColorBox.CreateWnd;
  5730. var
  5731. I: Integer;
  5732. ColorName: string;
  5733. begin
  5734. inherited CreateWnd;
  5735. Clear;
  5736. for I := Low(StdColors) to High(StdColors) do begin
  5737. case fLanguage of
  5738. lgChinese : ColorName := StdColors[I].cnName;
  5739. lgEnglish : ColorName := StdColors[I].enName;
  5740. end;
  5741. Items.AddObject(ColorName, TObject(StdColors[I].Value));
  5742. end;
  5743. ItemIndex := 0;
  5744. Change;
  5745. end;
  5746. procedure TDefineColorBox.SetColors(Index: Integer; Value: TColor);
  5747. begin
  5748. case Index of
  5749. 0: FArrowColor := Value;
  5750. 1: FArrowBackgroundColor := Value;
  5751. 2: FBorderColor := Value;
  5752. 3: FHighlightColor := Value;
  5753. end;
  5754. Invalidate;
  5755. end;
  5756. procedure TDefineColorBox.WndProc(var Message: TMessage);
  5757. begin
  5758. if(Message.Msg = WM_PARENTNOTIFY) then
  5759. case LoWord(Message.wParam) of
  5760. WM_CREATE:
  5761. if FDefListProc <> nil then
  5762. begin
  5763. SetWindowLong(FListHandle, GWL_WNDPROC, Longint(FDefListProc));
  5764. FDefListProc := nil;
  5765. FChildHandle := Message.lParam;
  5766. end
  5767. else
  5768. if FChildHandle = 0 then
  5769. FChildHandle := Message.lParam
  5770. else
  5771. FListHandle := Message.lParam;
  5772. end
  5773. else
  5774. if(Message.Msg = WM_WINDOWPOSCHANGING) then
  5775. if Style in [csDropDown, csSimple] then
  5776. SetWindowPos( EditHandle, 0,
  5777. 0, 0, ClientWidth - FButtonWidth - 2 * 2 - 4, Height - 2 * 2 - 2,
  5778. SWP_NOMOVE + SWP_NOZORDER + SWP_NOACTIVATE + SWP_NOREDRAW);
  5779. inherited;
  5780. if Message.Msg = WM_CTLCOLORLISTBOX then
  5781. begin
  5782. SetBkColor(Message.wParam, ColorToRGB(Color));
  5783. Message.Result := CreateSolidBrush(ColorToRGB(Color));
  5784. end;
  5785. end;
  5786. procedure TDefineColorBox.ListWndProc(var Message: TMessage);
  5787. begin
  5788. case Message.Msg of
  5789. WM_WINDOWPOSCHANGING:
  5790. with TWMWindowPosMsg(Message).WindowPos^ do
  5791. begin
  5792. // size of the drop down list
  5793. if Style in [csDropDown, csDropDownList] then
  5794. cy :=(GetFontHeight(Font)-2) * Min(DropDownCount, Items.Count) + 4
  5795. else
  5796. cy :=(ItemHeight) * Min(DropDownCount, Items.Count) + 4;
  5797. if cy <= 4 then
  5798. cy := 12;
  5799. end;
  5800. else
  5801. with Message do
  5802. Result := CallWindowProc(FDefListProc, FListHandle, Msg, WParam, LParam);
  5803. end;
  5804. end;
  5805. procedure TDefineColorBox.ComboWndProc(var Message: TMessage; ComboWnd: HWnd; ComboProc: Pointer);
  5806. begin
  5807. inherited;
  5808. if(ComboWnd = EditHandle) then
  5809. case Message.Msg of
  5810. WM_SETFOCUS, WM_KILLFOCUS:
  5811. SetSolidBorder;
  5812. end;
  5813. end;
  5814. procedure TDefineColorBox.WMSetFocus(var Message: TMessage);
  5815. begin
  5816. inherited;
  5817. if not(csDesigning in ComponentState) then
  5818. begin
  5819. SetSolidBorder;
  5820. if not(Style in [csSimple, csDropDown]) then
  5821. InvalidateSelection;
  5822. end;
  5823. end;
  5824. procedure TDefineColorBox.WMKillFocus(var Message: TMessage);
  5825. begin
  5826. inherited;
  5827. if not(csDesigning in ComponentState) then
  5828. begin
  5829. SetSolidBorder;
  5830. if not(Style in [csSimple, csDropDown]) then
  5831. InvalidateSelection;
  5832. end;
  5833. end;
  5834. procedure TDefineColorBox.CMEnabledChanged(var Msg: TMessage);
  5835. begin
  5836. inherited;
  5837. FTicket.Enabled := Enabled;
  5838. Invalidate;
  5839. end;
  5840. procedure TDefineColorBox.CNCommand(var Message: TWMCommand);
  5841. var
  5842. R: TRect;
  5843. begin
  5844. inherited;
  5845. if Message.NotifyCode in [1, 9, CBN_DROPDOWN, CBN_SELCHANGE] then
  5846. begin
  5847. if not(Style in [csSimple, csDropDown]) then
  5848. InvalidateSelection;
  5849. end;
  5850. if(Message.NotifyCode in [CBN_CLOSEUP]) then
  5851. begin
  5852. R := GetButtonRect;
  5853. Dec(R.Left, 2);
  5854. InvalidateRect(Handle, @R, FALSE);
  5855. end;
  5856. end;
  5857. procedure TDefineColorBox.WMKeyDown(var Message: TMessage);
  5858. var
  5859. S: String;
  5860. begin
  5861. S := Text;
  5862. inherited;
  5863. if not(Style in [csSimple, csDropDown]) and(Text <> S) then
  5864. InvalidateSelection;
  5865. end;
  5866. procedure TDefineColorBox.WMPaint(var Message: TWMPaint);
  5867. var
  5868. R: TRect;
  5869. DC: HDC;
  5870. PS: TPaintStruct;
  5871. begin
  5872. DC := BeginPaint(Handle, PS);
  5873. try
  5874. R := PS.rcPaint;
  5875. if R.Right > Width - FButtonWidth - 4 then
  5876. R.Right := Width - FButtonWidth - 4;
  5877. FillRect(DC, R, Brush.Handle);
  5878. if RectInRect(GetButtonRect, PS.rcPaint) then
  5879. PaintButton;
  5880. ExcludeClipRect(DC, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
  5881. PaintWindow(DC);
  5882. if(Style = csDropDown) and DroppedDown then
  5883. begin
  5884. R := ClientRect;
  5885. InflateRect(R, -2, -2);
  5886. R.Right := Width - FButtonWidth - 3;
  5887. Canvas.Brush.Color := clWindow;
  5888. Canvas.FrameRect(R);
  5889. end
  5890. else
  5891. if Style <> csDropDown then
  5892. InvalidateSelection;
  5893. finally
  5894. EndPaint(Handle, PS);
  5895. end;
  5896. RedrawBorders;
  5897. Message.Result := 0;
  5898. end;
  5899. procedure TDefineColorBox.WMNCPaint(var Message: TMessage);
  5900. begin
  5901. inherited;
  5902. RedrawBorders;
  5903. end;
  5904. procedure TDefineColorBox.CMFontChanged(var Message: TMessage);
  5905. begin
  5906. inherited;
  5907. ItemHeight := 13;
  5908. RecreateWnd;
  5909. end;
  5910. procedure TDefineColorBox.InvalidateSelection;
  5911. var
  5912. R: TRect;
  5913. begin
  5914. R := ClientRect;
  5915. InflateRect(R, -2, -3);
  5916. R.Left := R.Right - FButtonWidth - 8;
  5917. Dec(R.Right, FButtonWidth + 3);
  5918. if(GetFocus = Handle) and not DroppedDown then
  5919. Canvas.Brush.Color := FHighLightcolor
  5920. else
  5921. Canvas.Brush.Color := Color;
  5922. Canvas.Brush.Style := bsSolid;
  5923. Canvas.FillRect(R);
  5924. if(GetFocus = Handle) and not DroppedDown then
  5925. begin
  5926. R := ClientRect;
  5927. InflateRect(R, -3, -3);
  5928. Dec(R.Right, FButtonWidth + 2);
  5929. Canvas.FrameRect(R);
  5930. Canvas.Brush.Color := clWindow;
  5931. end;
  5932. ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth - 2, 0, ClientWidth, ClientHeight);
  5933. end;
  5934. function TDefineColorBox.GetButtonRect: TRect;
  5935. begin
  5936. GetWindowRect(Handle, Result);
  5937. OffsetRect(Result, -Result.Left, -Result.Top);
  5938. Inc(Result.Left, ClientWidth - FButtonWidth);
  5939. OffsetRect(Result, -1, 0);
  5940. end;
  5941. procedure TDefineColorBox.PaintButton;
  5942. var
  5943. R: TRect;
  5944. x, y: Integer;
  5945. begin
  5946. R := GetButtonRect;
  5947. InflateRect(R, 1, 0);
  5948. Canvas.Brush.Color := FArrowBackgroundColor;
  5949. Canvas.FillRect(R);
  5950. Canvas.Brush.Color := FBorderColor;
  5951. Canvas.FrameRect(R);
  5952. x :=(R.Right - R.Left) div 2 - 6 + R.Left;
  5953. if DroppedDown then
  5954. y :=(R.Bottom - R.Top) div 2 - 1 + R.Top
  5955. else
  5956. y :=(R.Bottom - R.Top) div 2 - 1 + R.Top;
  5957. if Enabled then begin
  5958. canvas.Brush.Color := FArrowColor;
  5959. canvas.Pen.Color := FArrowColor;
  5960. if DroppedDown then
  5961. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5962. else
  5963. canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5964. end else begin
  5965. canvas.Brush.Color := clWhite;
  5966. canvas.Pen.Color := clWhite;
  5967. Inc(x); Inc(y);
  5968. if DroppedDown then
  5969. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5970. else
  5971. canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5972. Dec(x); Dec(y);
  5973. canvas.Brush.Color := clGray;
  5974. canvas.Pen.Color := clGray;
  5975. if DroppedDown then
  5976. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)])
  5977. else
  5978. canvas.Polygon([Point(x + 4, y), Point(x + 8, y), Point(x + 6, y + 2)]);
  5979. end;
  5980. ExcludeClipRect(Canvas.Handle, ClientWidth - FSysBtnWidth, 0, ClientWidth, ClientHeight);
  5981. end;
  5982. procedure TDefineColorBox.PaintBorder;
  5983. var
  5984. DC: HDC;
  5985. R: TRect;
  5986. BtnFaceBrush, WindowBrush: HBRUSH;
  5987. begin
  5988. DC := GetWindowDC(Handle);
  5989. GetWindowRect(Handle, R);
  5990. OffsetRect(R, -R.Left, -R.Top);
  5991. Dec(R.Right, FButtonWidth + 1);
  5992. try
  5993. BtnFaceBrush := CreateSolidBrush(ColorToRGB(FBorderColor));
  5994. WindowBrush := CreateSolidBrush(ColorToRGB(Color));
  5995. FrameRect(DC, R, BtnFaceBrush);
  5996. InflateRect(R, -1, -1);
  5997. FrameRect(DC, R, WindowBrush);
  5998. InflateRect(R, -1, -1);
  5999. FrameRect(DC, R, WindowBrush);
  6000. finally
  6001. ReleaseDC(Handle, DC);
  6002. end;
  6003. DeleteObject(WindowBrush);
  6004. DeleteObject(BtnFaceBrush);
  6005. end;
  6006. function TDefineColorBox.GetSolidBorder: Boolean;
  6007. begin
  6008. Result :=((csDesigning in ComponentState) and Enabled) or
  6009. (not(csDesigning in ComponentState) and
  6010. (DroppedDown or(GetFocus = Handle) or(GetFocus = EditHandle)) );
  6011. end;
  6012. procedure TDefineColorBox.SetSolidBorder;
  6013. var
  6014. sb: Boolean;
  6015. begin
  6016. sb := GetSolidBorder;
  6017. if sb <> FSolidBorder then
  6018. begin
  6019. FSolidBorder := sb;
  6020. RedrawBorders;
  6021. end;
  6022. end;
  6023. procedure TDefineColorBox.RedrawBorders;
  6024. begin
  6025. PaintBorder;
  6026. if Style <> csSimple then PaintButton;
  6027. end;
  6028. procedure TDefineColorBox.SetShowNames(Value: Boolean);
  6029. begin
  6030. if Value <> FShowNames then
  6031. begin
  6032. FShowNames := Value;
  6033. Invalidate;
  6034. end;
  6035. end;
  6036. procedure TDefineColorBox.SetColorValue(Value: TColor);
  6037. var
  6038. Item: Integer;
  6039. CurrentColor: TColor;
  6040. begin
  6041. if(ItemIndex < 0) or(Value <> FValue) then
  6042. begin
  6043. for Item := 0 to Pred(Items.Count) do
  6044. begin
  6045. CurrentColor := TColor(Items.Objects[Item]);
  6046. if CurrentColor = Value then
  6047. begin
  6048. FValue := Value;
  6049. if ItemIndex <> Item then ItemIndex := Item;
  6050. Change;
  6051. Break;
  6052. end;
  6053. end;
  6054. end;
  6055. end;
  6056. procedure TDefineColorBox.SetColorBoxWidth(Value: Integer);
  6057. begin
  6058. if Value <> FColorBoxWidth then
  6059. begin
  6060. FColorBoxWidth := Value;
  6061. end;
  6062. Invalidate;
  6063. end;
  6064. procedure TDefineColorBox.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
  6065. var
  6066. ARect: TRect;
  6067. Text: array[0..255] of Char;
  6068. Safer: TColor;
  6069. begin
  6070. ARect := Rect;
  6071. with ARect do begin
  6072. Inc(Top, 1);
  6073. Inc(Left, 1);
  6074. Dec(Right, 1);
  6075. Dec(Bottom, 1);
  6076. if FShowNames then begin
  6077. Right := Left + FColorBoxWidth;
  6078. end else begin
  6079. Dec(Right, 5);
  6080. end;
  6081. end;
  6082. with Canvas do begin
  6083. Safer := Brush.Color;
  6084. if(odSelected in State) then begin
  6085. Brush.Color := FHighlightColor;
  6086. end else begin
  6087. Brush.Color := Color;
  6088. end;
  6089. FillRect(Rect);
  6090. Pen.Color := clBlack;
  6091. Rectangle(ARect);
  6092. Brush.Color := ColorToRgb(TColor(Items.Objects[Index]));
  6093. try
  6094. InflateRect(ARect, -1, -1);
  6095. FillRect(ARect)
  6096. finally
  6097. Brush.Color := Safer;
  6098. end;
  6099. if FShowNames then begin
  6100. StrPCopy(Text, Items[Index]);
  6101. Rect.Left := ARect.Right + 5;
  6102. Brush.Style := bsClear;
  6103. DrawText(Canvas.Handle, Text, StrLen(Text), Rect, DT_SINGLELINE or DT_VCENTER or DT_NOPREFIX);
  6104. Brush.Style := bsSolid;
  6105. end;
  6106. end;
  6107. end;
  6108. procedure TDefineColorBox.Click;
  6109. begin
  6110. if ItemIndex >= 0 then
  6111. begin
  6112. if(Items[ItemIndex] = StdCustomCN)or(Items[ItemIndex] = StdCustomEN) then
  6113. begin
  6114. if not FColorDlg.Execute then
  6115. Exit;
  6116. Items.Objects[ItemIndex] := TObject(FColorDlg.Color);
  6117. end;
  6118. Value := TColor(Items.Objects[ItemIndex]);
  6119. end;
  6120. inherited Click;
  6121. end;
  6122. function TDefineColorBox.AddColor(ColorName: String; Color: TColor): Boolean;
  6123. var
  6124. I: Integer;
  6125. begin
  6126. for I := 0 to Items.Count - 1 do begin
  6127. if UpperCase(ColorName) = UpperCase(Items[I]) then begin
  6128. Result := False;
  6129. Exit;
  6130. end;
  6131. end;
  6132. Items.InsertObject(Items.Count - 1, ColorName, TObject(Color));
  6133. Result := True;
  6134. end;
  6135. function TDefineColorBox.DeleteColorByName(ColorName: String): Boolean;
  6136. var
  6137. I: Integer;
  6138. begin
  6139. for I := 0 to Items.Count - 1 do begin
  6140. if UpperCase(ColorName) = UpperCase(Items[I]) then begin
  6141. Items.Delete(I);
  6142. Result := True;
  6143. Exit;
  6144. end;
  6145. end;
  6146. Result := False;
  6147. end;
  6148. function TDefineColorBox.DeleteColorByColor(Color: TColor): Boolean;
  6149. var
  6150. I: Integer;
  6151. begin
  6152. for I := 0 to Items.Count - 1 do begin
  6153. if Color = TColor(Items.Objects[I]) then begin
  6154. Items.Delete(I);
  6155. Result := True;
  6156. Exit;
  6157. end;
  6158. end;
  6159. Result := False;
  6160. end;
  6161. { TDefineSplitter }
  6162. constructor TDefineSplitter.Create(AOwner: TComponent);
  6163. begin
  6164. inherited Create(AOwner);
  6165. ControlStyle := ControlStyle + [csOpaque];
  6166. Align := alLeft;
  6167. Width := 5;
  6168. Cursor := crHSplit;
  6169. FMinSize := 30;
  6170. FStatus := ssOut;
  6171. ParentColor := true;
  6172. ColorFocused := $0053D2FF;
  6173. ColorBorder := $00555E66;
  6174. end;
  6175. procedure TDefineSplitter.AllocateLineDC;
  6176. begin
  6177. FLineDC := GetDCEx(Parent.Handle, 0, DCX_CACHE or DCX_CLIPSIBLINGS or DCX_LOCKWINDOWUPDATE);
  6178. end;
  6179. procedure TDefineSplitter.DrawLine;
  6180. var
  6181. P: TPoint;
  6182. begin
  6183. FLineVisible := not FLineVisible;
  6184. P := Point(Left, Top);
  6185. if Align in [alLeft, alRight] then
  6186. P.X := Left + FSplit
  6187. else
  6188. P.Y := Top + FSplit;
  6189. with P do
  6190. PatBlt(FLineDC, X, Y, Width, Height, PATINVERT);
  6191. end;
  6192. procedure TDefineSplitter.ReleaseLineDC;
  6193. begin
  6194. ReleaseDC(Parent.Handle, FLineDC);
  6195. end;
  6196. procedure TDefineSplitter.Paint;
  6197. var
  6198. memBitmap: TBitmap;
  6199. begin
  6200. memBitmap := TBitmap.Create; // create memory-bitmap to draw flicker-free
  6201. try
  6202. memBitmap.Height := ClientRect.Bottom;
  6203. memBitmap.Width := ClientRect.Right;
  6204. if FStatus = ssIn then
  6205. begin
  6206. memBitmap.Canvas.Brush.Color := FFocusedColor;
  6207. memBitmap.Canvas.FillRect(ClientRect);
  6208. DrawButtonBorder(memBitmap.Canvas, ClientRect, FBorderColor, 1);
  6209. end;
  6210. if FStatus = ssOut then
  6211. begin
  6212. memBitmap.Canvas.Brush.Color := Color;
  6213. memBitmap.Canvas.FillRect(ClientRect);
  6214. DrawButtonBorder(memBitmap.Canvas, ClientRect, FBorderColor, 1);
  6215. end;
  6216. canvas.CopyRect(ClientRect, memBitmap.canvas, ClientRect); // Copy bitmap to screen
  6217. finally
  6218. memBitmap.free; // delete the bitmap
  6219. end;
  6220. end;
  6221. procedure TDefineSplitter.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  6222. function FindControl: TControl;
  6223. var
  6224. P: TPoint;
  6225. I: Integer;
  6226. begin
  6227. Result := nil;
  6228. P := Point(Left, Top);
  6229. case Align of
  6230. alLeft: Dec(P.X);
  6231. alRight: Inc(P.X, Width);
  6232. alTop: Dec(P.Y);
  6233. alBottom: Inc(P.Y, Height);
  6234. else
  6235. Exit;
  6236. end;
  6237. for I := 0 to Parent.ControlCount - 1 do
  6238. begin
  6239. Result := Parent.Controls[I];
  6240. if PtInRect(Result.BoundsRect, P) then
  6241. Exit;
  6242. end;
  6243. Result := nil;
  6244. end;
  6245. var
  6246. I: Integer;
  6247. begin
  6248. inherited;
  6249. if Button = mbLeft then
  6250. begin
  6251. FControl := FindControl;
  6252. FDownPos := Point(X, Y);
  6253. if Assigned(FControl) then
  6254. begin
  6255. if Align in [alLeft, alRight] then
  6256. begin
  6257. FMaxSize := Parent.ClientWidth - FMinSize;
  6258. for I := 0 to Parent.ControlCount - 1 do
  6259. with Parent.Controls[I] do
  6260. if Align in [alLeft, alRight] then
  6261. Dec(FMaxSize, Width);
  6262. Inc(FMaxSize, FControl.Width);
  6263. end
  6264. else
  6265. begin
  6266. FMaxSize := Parent.ClientHeight - FMinSize;
  6267. for I := 0 to Parent.ControlCount - 1 do
  6268. with Parent.Controls[I] do
  6269. if Align in [alTop, alBottom] then Dec(FMaxSize, Height);
  6270. Inc(FMaxSize, FControl.Height);
  6271. end;
  6272. UpdateSize(X, Y);
  6273. AllocateLineDC;
  6274. with ValidParentForm(Self) do
  6275. if ActiveControl <> nil then
  6276. begin
  6277. FActiveControl := ActiveControl;
  6278. FOldKeyDown := TDefineHack(FActiveControl).OnKeyDown;
  6279. TDefineHack(FActiveControl).OnKeyDown := FocusKeyDown;
  6280. end;
  6281. DrawLine;
  6282. end;
  6283. end;
  6284. end;
  6285. procedure TDefineSplitter.UpdateSize(X, Y: Integer);
  6286. var
  6287. S: Integer;
  6288. begin
  6289. if Align in [alLeft, alRight] then
  6290. FSplit := X - FDownPos.X
  6291. else
  6292. FSplit := Y - FDownPos.Y;
  6293. S := 0;
  6294. case Align of
  6295. alLeft: S := FControl.Width + FSplit;
  6296. alRight: S := FControl.Width - FSplit;
  6297. alTop: S := FControl.Height + FSplit;
  6298. alBottom: S := FControl.Height - FSplit;
  6299. end;
  6300. FNewSize := S;
  6301. if S < FMinSize then
  6302. FNewSize := FMinSize
  6303. else
  6304. if S > FMaxSize then
  6305. FNewSize := FMaxSize;
  6306. if S <> FNewSize then
  6307. begin
  6308. if Align in [alRight, alBottom] then
  6309. S := S - FNewSize
  6310. else
  6311. S := FNewSize - S;
  6312. Inc(FSplit, S);
  6313. end;
  6314. end;
  6315. procedure TDefineSplitter.MouseMove(Shift: TShiftState; X, Y: Integer);
  6316. begin
  6317. inherited;
  6318. if Assigned(FControl) then
  6319. begin
  6320. DrawLine;
  6321. UpdateSize(X, Y);
  6322. DrawLine;
  6323. end;
  6324. end;
  6325. procedure TDefineSplitter.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  6326. begin
  6327. inherited;
  6328. if Assigned(FControl) then
  6329. begin
  6330. DrawLine;
  6331. case Align of
  6332. alLeft: FControl.Width := FNewSize;
  6333. alTop: FControl.Height := FNewSize;
  6334. alRight:
  6335. begin
  6336. Parent.DisableAlign;
  6337. try
  6338. FControl.Left := FControl.Left + (FControl.Width - FNewSize);
  6339. FControl.Width := FNewSize;
  6340. finally
  6341. Parent.EnableAlign;
  6342. end;
  6343. end;
  6344. alBottom:
  6345. begin
  6346. Parent.DisableAlign;
  6347. try
  6348. FControl.Top := FControl.Top + (FControl.Height - FNewSize);
  6349. FControl.Height := FNewSize;
  6350. finally
  6351. Parent.EnableAlign;
  6352. end;
  6353. end;
  6354. end;
  6355. StopSizing;
  6356. end;
  6357. end;
  6358. procedure TDefineSplitter.FocusKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  6359. begin
  6360. if Key = VK_ESCAPE then
  6361. StopSizing
  6362. else
  6363. if Assigned(FOldKeyDown) then
  6364. FOldKeyDown(Sender, Key, Shift);
  6365. end;
  6366. procedure TDefineSplitter.StopSizing;
  6367. begin
  6368. if Assigned(FControl) then
  6369. begin
  6370. if FLineVisible then DrawLine;
  6371. FControl := nil;
  6372. ReleaseLineDC;
  6373. if Assigned(FActiveControl) then
  6374. begin
  6375. TDefineHack(FActiveControl).OnKeyDown := FOldKeyDown;
  6376. FActiveControl := nil;
  6377. end;
  6378. end;
  6379. if Assigned(FOnMoved) then
  6380. FOnMoved(Self);
  6381. end;
  6382. procedure TDefineSplitter.CMEnter(var Message: TMessage);
  6383. begin
  6384. if FStatus <> ssIn then
  6385. begin
  6386. FStatus := ssIn;
  6387. Invalidate;
  6388. end;
  6389. end;
  6390. procedure TDefineSplitter.CMExit(var Message: TMessage);
  6391. begin
  6392. if FStatus <> ssOut then
  6393. begin
  6394. FStatus := ssOut;
  6395. Invalidate;
  6396. end;
  6397. end;
  6398. procedure TDefineSplitter.SetColors (Index: Integer; Value: TColor);
  6399. begin
  6400. case Index of
  6401. 0: FFocusedColor := Value;
  6402. 1: FBorderColor := Value;
  6403. end;
  6404. Invalidate;
  6405. end;
  6406. procedure TDefineSplitter.CMSysColorChange (var Message: TMessage);
  6407. begin
  6408. inherited;
  6409. if (ParentColor) and (Parent <> nil) then
  6410. Color := TForm(Parent).Color;
  6411. Invalidate;
  6412. end;
  6413. procedure TDefineSplitter.CMParentColorChanged (var Message: TWMNoParams);
  6414. begin
  6415. inherited;
  6416. if (ParentColor) and (Parent <> nil) then
  6417. Color := TForm(Parent).Color;
  6418. Invalidate;
  6419. end;
  6420. { TDefineMask }
  6421. constructor TDefineMask.Create(AOwner: TComponent);
  6422. begin
  6423. inherited Create(AOwner);
  6424. FMaskState := [];
  6425. FMaskBlank := DefaultBlank;
  6426. end;
  6427. procedure TDefineMask.KeyDown(var Key: Word; Shift: TShiftState);
  6428. begin
  6429. if not FSettingCursor then inherited KeyDown(Key, Shift);
  6430. if IsMasked and (Key <> 0) and not (ssAlt in Shift) then
  6431. begin
  6432. if (Key = VK_LEFT) or(Key = VK_RIGHT) then
  6433. begin
  6434. ArrowKeys(Key, Shift);
  6435. if not ((ssShift in Shift) or (ssCtrl in Shift)) then
  6436. Key := 0;
  6437. Exit;
  6438. end
  6439. else if (Key = VK_UP) or(Key = VK_DOWN) then
  6440. begin
  6441. Key := 0;
  6442. Exit;
  6443. end
  6444. else if (Key = VK_HOME) or(Key = VK_END) then
  6445. begin
  6446. HomeEndKeys(Key, Shift);
  6447. Key := 0;
  6448. Exit;
  6449. end
  6450. else if ((Key = VK_DELETE) and not (ssShift in Shift)) or
  6451. (Key = VK_BACK) then
  6452. begin
  6453. if EditCanModify then
  6454. DeleteKeys(Key);
  6455. Key := 0;
  6456. Exit;
  6457. end;
  6458. CheckCursor;
  6459. end;
  6460. end;
  6461. procedure TDefineMask.KeyUp(var Key: Word; Shift: TShiftState);
  6462. begin
  6463. if not FSettingCursor then inherited KeyUp(Key, Shift);
  6464. if IsMasked and (Key <> 0) then
  6465. begin
  6466. if ((Key = VK_LEFT) or(Key = VK_RIGHT)) and (ssCtrl in Shift) then
  6467. CheckCursor;
  6468. end;
  6469. end;
  6470. procedure TDefineMask.KeyPress(var Key: Char);
  6471. begin
  6472. inherited KeyPress(Key);
  6473. if IsMasked and (Key <> #0) and not (Char(Key) in [^V, ^X, ^C]) then
  6474. begin
  6475. CharKeys(Key);
  6476. Key := #0;
  6477. end;
  6478. end;
  6479. procedure TDefineMask.WMLButtonDown(var Message: TWMLButtonDown);
  6480. begin
  6481. inherited;
  6482. FBtnDownX := Message.XPos;
  6483. end;
  6484. procedure TDefineMask.WMLButtonUp(var Message: TWMLButtonUp);
  6485. var
  6486. SelStart, SelStop : Integer;
  6487. begin
  6488. inherited;
  6489. if (IsMasked) then
  6490. begin
  6491. GetSel(SelStart, SelStop);
  6492. FCaretPos := SelStart;
  6493. if (SelStart <> SelStop) and (Message.XPos > FBtnDownX) then
  6494. FCaretPos := SelStop;
  6495. CheckCursor;
  6496. end;
  6497. end;
  6498. procedure TDefineMask.WMSetFocus(var Message: TWMSetFocus);
  6499. begin
  6500. inherited;
  6501. if (IsMasked) then
  6502. CheckCursor;
  6503. end;
  6504. procedure TDefineMask.SetEditText(const Value: string);
  6505. begin
  6506. if GetEditText <> Value then
  6507. begin
  6508. SetTextBuf(PChar(Value));
  6509. CheckCursor;
  6510. end;
  6511. end;
  6512. function TDefineMask.GetEditText: string;
  6513. begin
  6514. Result := inherited Text;
  6515. end;
  6516. function TDefineMask.GetTextLen: Integer;
  6517. begin
  6518. Result := Length(Text);
  6519. end;
  6520. function TDefineMask.GetText: TMaskedText;
  6521. begin
  6522. if not IsMasked then
  6523. Result := inherited Text
  6524. else
  6525. begin
  6526. Result := RemoveEditFormat(EditText);
  6527. if FMaskSave then
  6528. Result := AddEditFormat(Result, False);
  6529. end;
  6530. end;
  6531. procedure TDefineMask.SetText(const Value: TMaskedText);
  6532. var
  6533. OldText: string;
  6534. Pos: Integer;
  6535. begin
  6536. if not IsMasked then
  6537. inherited Text := Value
  6538. else
  6539. begin
  6540. OldText := Value;
  6541. if FMaskSave then
  6542. OldText := PadInputLiterals(EditMask, OldText, FMaskBlank)
  6543. else
  6544. OldText := AddEditFormat(OldText, True);
  6545. if not (msDBSetText in FMaskState) and
  6546. (csDesigning in ComponentState) and
  6547. not (csLoading in ComponentState) and
  6548. not Validate(OldText, Pos) then
  6549. raise TDefineError.Create(SMaskErr);
  6550. EditText := OldText;
  6551. end;
  6552. end;
  6553. procedure TDefineMask.WMCut(var Message: TMessage);
  6554. begin
  6555. if not (IsMasked) then
  6556. inherited
  6557. else
  6558. begin
  6559. CopyToClipboard;
  6560. DeleteKeys(VK_DELETE);
  6561. end;
  6562. end;
  6563. procedure TDefineMask.WMPaste(var Message: TMessage);
  6564. var
  6565. Value: string;
  6566. Str: string;
  6567. SelStart, SelStop : Integer;
  6568. begin
  6569. if not (IsMasked) or ReadOnly then
  6570. inherited
  6571. else
  6572. begin
  6573. Clipboard.Open;
  6574. Value := Clipboard.AsText;
  6575. Clipboard.Close;
  6576. GetSel(SelStart, SelStop);
  6577. Str := EditText;
  6578. DeleteSelection(Str, SelStart, SelStop - SelStart);
  6579. EditText := Str;
  6580. SelStart := InputString(Str, Value, SelStart);
  6581. EditText := Str;
  6582. SetCursor(SelStart);
  6583. end;
  6584. end;
  6585. function TDefineMask.GetMasked: Boolean;
  6586. begin
  6587. Result := EditMask <> '';
  6588. end;
  6589. function TDefineMask.GetMaxChars: Integer;
  6590. begin
  6591. if IsMasked then
  6592. Result := FMaxChars
  6593. else
  6594. Result := inherited GetTextLen;
  6595. end;
  6596. procedure TDefineMask.ReformatText(const NewMask: string);
  6597. var
  6598. OldText: string;
  6599. begin
  6600. OldText := RemoveEditFormat(EditText);
  6601. FEditMask := NewMask;
  6602. FMaxChars := MaskOffsetToOffset(EditMask, Length(NewMask));
  6603. FMaskSave := MaskGetMaskSave(NewMask);
  6604. FMaskBlank := MaskGetMaskBlank(NewMask);
  6605. OldText := AddEditFormat(OldText, True);
  6606. EditText := OldText;
  6607. end;
  6608. procedure TDefineMask.SetEditMask(const Value: TEditMask);
  6609. var
  6610. SelStart, SelStop: Integer;
  6611. begin
  6612. if Value <> EditMask then
  6613. begin
  6614. if (csDesigning in ComponentState) and (Value <> '') and
  6615. not (csLoading in ComponentState) then
  6616. EditText := '';
  6617. if HandleAllocated then GetSel(SelStart, SelStop);
  6618. ReformatText(Value);
  6619. Exclude(FMaskState, msMasked);
  6620. if EditMask <> '' then Include(FMaskState, msMasked);
  6621. inherited MaxLength := 0;
  6622. if IsMasked and (FMaxChars > 0) then
  6623. inherited MaxLength := FMaxChars;
  6624. if HandleAllocated and (GetFocus = Handle) and
  6625. not (csDesigning in ComponentState) then
  6626. SetCursor(SelStart);
  6627. end;
  6628. end;
  6629. function TDefineMask.GetMaxLength: Integer;
  6630. begin
  6631. Result := inherited MaxLength;
  6632. end;
  6633. procedure TDefineMask.SetMaxLength(Value: Integer);
  6634. begin
  6635. if not IsMasked then
  6636. inherited MaxLength := Value
  6637. else
  6638. inherited MaxLength := FMaxChars;
  6639. end;
  6640. procedure TDefineMask.GetSel(var SelStart: Integer; var SelStop: Integer);
  6641. begin
  6642. SendMessage(Handle, EM_GETSEL, Integer(@SelStart), Integer(@SelStop));
  6643. end;
  6644. procedure TDefineMask.SetSel(SelStart: Integer; SelStop: Integer);
  6645. begin
  6646. SendMessage(Handle, EM_SETSEL, SelStart, SelStop);
  6647. end;
  6648. procedure TDefineMask.SetCursor(Pos: Integer);
  6649. const
  6650. ArrowKey: array[Boolean] of Word = (VK_LEFT, VK_RIGHT);
  6651. var
  6652. SelStart, SelStop: Integer;
  6653. KeyState: TKeyboardState;
  6654. NewKeyState: TKeyboardState;
  6655. I: Integer;
  6656. begin
  6657. if (Pos >= 1) and (ByteType(EditText, Pos) = mbLeadByte) then Dec(Pos);
  6658. SelStart := Pos;
  6659. if (IsMasked) then
  6660. begin
  6661. if SelStart < 0 then
  6662. SelStart := 0;
  6663. SelStop := SelStart + 1;
  6664. if (Length(EditText) > SelStop) and (EditText[SelStop] in LeadBytes) then
  6665. Inc(SelStop);
  6666. if SelStart >= FMaxChars then
  6667. begin
  6668. SelStart := FMaxChars;
  6669. SelStop := SelStart;
  6670. end;
  6671. SetSel(SelStop, SelStop);
  6672. if SelStart <> SelStop then
  6673. begin
  6674. GetKeyboardState(KeyState);
  6675. for I := Low(NewKeyState) to High(NewKeyState) do
  6676. NewKeyState[I] := 0;
  6677. NewKeyState [VK_SHIFT] := $81;
  6678. NewKeyState [ArrowKey[UseRightToLeftAlignment]] := $81;
  6679. SetKeyboardState(NewKeyState);
  6680. FSettingCursor := True;
  6681. try
  6682. SendMessage(Handle, WM_KEYDOWN, ArrowKey[UseRightToLeftAlignment], 1);
  6683. SendMessage(Handle, WM_KEYUP, ArrowKey[UseRightToLeftAlignment], 1);
  6684. finally
  6685. FSettingCursor := False;
  6686. end;
  6687. SetKeyboardState(KeyState);
  6688. end;
  6689. FCaretPos := SelStart;
  6690. end
  6691. else
  6692. begin
  6693. if SelStart < 0 then
  6694. SelStart := 0;
  6695. if SelStart >= Length(EditText) then
  6696. SelStart := Length(EditText);
  6697. SetSel(SelStart, SelStart);
  6698. end;
  6699. end;
  6700. procedure TDefineMask.CheckCursor;
  6701. var
  6702. SelStart, SelStop: Integer;
  6703. begin
  6704. if not HandleAllocated then Exit;
  6705. if (IsMasked) then
  6706. begin
  6707. GetSel(SelStart, SelStop);
  6708. if SelStart = SelStop then
  6709. SetCursor(SelStart);
  6710. end;
  6711. end;
  6712. procedure TDefineMask.Clear;
  6713. begin
  6714. Text := '';
  6715. end;
  6716. function TDefineMask.EditCanModify: Boolean;
  6717. begin
  6718. Result := True;
  6719. end;
  6720. procedure TDefineMask.Reset;
  6721. begin
  6722. if Modified then
  6723. begin
  6724. EditText := FOldValue;
  6725. Modified := False;
  6726. end;
  6727. end;
  6728. function TDefineMask.CharKeys(var CharCode: Char): Boolean;
  6729. var
  6730. SelStart, SelStop : Integer;
  6731. Txt: string;
  6732. CharMsg: TMsg;
  6733. begin
  6734. Result := False;
  6735. if Word(CharCode) = VK_ESCAPE then
  6736. begin
  6737. Reset;
  6738. Exit;
  6739. end;
  6740. if not EditCanModify or ReadOnly then Exit;
  6741. if (Word(CharCode) = VK_BACK) then Exit;
  6742. if (Word(CharCode) = VK_RETURN) then
  6743. begin
  6744. ValidateEdit;
  6745. Exit;
  6746. end;
  6747. GetSel(SelStart, SelStop);
  6748. if (SelStop - SelStart) > 1 then
  6749. begin
  6750. DeleteKeys(VK_DELETE);
  6751. SelStart := GetNextEditChar(SelStart);
  6752. SetCursor(SelStart);
  6753. end;
  6754. if (CharCode in LeadBytes) then
  6755. if PeekMessage(CharMsg, Handle, WM_CHAR, WM_CHAR, PM_REMOVE) then
  6756. if CharMsg.Message = WM_Quit then
  6757. PostQuitMessage(CharMsg.wparam);
  6758. Result := InputChar(CharCode, SelStart);
  6759. if Result then
  6760. begin
  6761. if (CharCode in LeadBytes) then
  6762. begin
  6763. Txt := CharCode + Char(CharMsg.wParam);
  6764. SetSel(SelStart, SelStart + 2);
  6765. end
  6766. else
  6767. Txt := CharCode;
  6768. SendMessage(Handle, EM_REPLACESEL, 0, LongInt(PChar(Txt)));
  6769. GetSel(SelStart, SelStop);
  6770. CursorInc(SelStart, 0);
  6771. end;
  6772. end;
  6773. procedure TDefineMask.ArrowKeys(CharCode: Word; Shift: TShiftState);
  6774. var
  6775. SelStart, SelStop : Integer;
  6776. begin
  6777. if (ssCtrl in Shift) then Exit;
  6778. GetSel(SelStart, SelStop);
  6779. if (ssShift in Shift) then
  6780. begin
  6781. if (CharCode = VK_RIGHT) then
  6782. begin
  6783. Inc(FCaretPos);
  6784. if (SelStop = SelStart + 1) then
  6785. begin
  6786. SetSel(SelStart, SelStop); {reset caret to end of string}
  6787. Inc(FCaretPos);
  6788. end;
  6789. if FCaretPos > FMaxChars then FCaretPos := FMaxChars;
  6790. end
  6791. else {if (CharCode = VK_LEFT) then}
  6792. begin
  6793. Dec(FCaretPos);
  6794. if (SelStop = SelStart + 2) and
  6795. (FCaretPos > SelStart) then
  6796. begin
  6797. SetSel(SelStart + 1, SelStart + 1); {reset caret to show up at start}
  6798. Dec(FCaretPos);
  6799. end;
  6800. if FCaretPos < 0 then FCaretPos := 0;
  6801. end;
  6802. end
  6803. else
  6804. begin
  6805. if (SelStop - SelStart) > 1 then
  6806. begin
  6807. if ((SelStop - SelStart) = 2) and (EditText[SelStart+1] in LeadBytes) then
  6808. begin
  6809. if (CharCode = VK_LEFT) then
  6810. CursorDec(SelStart)
  6811. else
  6812. CursorInc(SelStart, 2);
  6813. Exit;
  6814. end;
  6815. if SelStop = FCaretPos then
  6816. Dec(FCaretPos);
  6817. SetCursor(FCaretPos);
  6818. end
  6819. else if (CharCode = VK_LEFT) then
  6820. CursorDec(SelStart)
  6821. else { if (CharCode = VK_RIGHT) then }
  6822. begin
  6823. if SelStop = SelStart then
  6824. SetCursor(SelStart)
  6825. else
  6826. if EditText[SelStart+1] in LeadBytes then
  6827. CursorInc(SelStart, 2)
  6828. else
  6829. CursorInc(SelStart, 1);
  6830. end;
  6831. end;
  6832. end;
  6833. procedure TDefineMask.CursorInc(CursorPos: Integer; Incr: Integer);
  6834. var
  6835. NuPos: Integer;
  6836. begin
  6837. NuPos := CursorPos + Incr;
  6838. NuPos := GetNextEditChar(NuPos);
  6839. if IsLiteralChar(EditMask, nuPos) then
  6840. NuPos := CursorPos;
  6841. SetCursor(NuPos);
  6842. end;
  6843. procedure TDefineMask.CursorDec(CursorPos: Integer);
  6844. var
  6845. nuPos: Integer;
  6846. begin
  6847. nuPos := CursorPos;
  6848. Dec(nuPos);
  6849. nuPos := GetPriorEditChar(nuPos);
  6850. SetCursor(NuPos);
  6851. end;
  6852. function TDefineMask.GetFirstEditChar: Integer;
  6853. begin
  6854. Result := 0;
  6855. if IsMasked then
  6856. Result := GetNextEditChar(0);
  6857. end;
  6858. function TDefineMask.GetLastEditChar: Integer;
  6859. begin
  6860. Result := GetMaxChars;
  6861. if IsMasked then
  6862. Result := GetPriorEditChar(Result - 1);
  6863. end;
  6864. function TDefineMask.GetNextEditChar(Offset: Integer): Integer;
  6865. begin
  6866. Result := Offset;
  6867. while(Result < FMaxChars) and (IsLiteralChar(EditMask, Result)) do
  6868. Inc(Result);
  6869. end;
  6870. function TDefineMask.GetPriorEditChar(Offset: Integer): Integer;
  6871. begin
  6872. Result := Offset;
  6873. while(Result >= 0) and (IsLiteralChar(EditMask, Result)) do
  6874. Dec(Result);
  6875. if Result < 0 then
  6876. Result := GetNextEditChar(Result);
  6877. end;
  6878. procedure TDefineMask.HomeEndKeys(CharCode: Word; Shift: TShiftState);
  6879. var
  6880. SelStart, SelStop : Integer;
  6881. begin
  6882. GetSel(SelStart, SelStop);
  6883. if (CharCode = VK_HOME) then
  6884. begin
  6885. if (ssShift in Shift) then
  6886. begin
  6887. if (SelStart <> FCaretPos) and (SelStop <> (SelStart + 1)) then
  6888. SelStop := SelStart + 1;
  6889. SetSel(0, SelStop);
  6890. CheckCursor;
  6891. end
  6892. else
  6893. SetCursor(0);
  6894. FCaretPos := 0;
  6895. end
  6896. else
  6897. begin
  6898. if (ssShift in Shift) then
  6899. begin
  6900. if (SelStop <> FCaretPos) and (SelStop <> (SelStart + 1)) then
  6901. SelStart := SelStop - 1;
  6902. SetSel(SelStart, FMaxChars);
  6903. CheckCursor;
  6904. end
  6905. else
  6906. SetCursor(FMaxChars);
  6907. FCaretPos := FMaxChars;
  6908. end;
  6909. end;
  6910. procedure TDefineMask.DeleteKeys(CharCode: Word);
  6911. var
  6912. SelStart, SelStop : Integer;
  6913. NuSelStart: Integer;
  6914. Str: string;
  6915. begin
  6916. if ReadOnly then Exit;
  6917. GetSel(SelStart, SelStop);
  6918. if ((SelStop - SelStart) <= 1) and (CharCode = VK_BACK) then
  6919. begin
  6920. NuSelStart := SelStart;
  6921. CursorDec(SelStart);
  6922. GetSel(SelStart, SelStop);
  6923. if SelStart = NuSelStart then Exit;
  6924. end;
  6925. if (SelStop - SelStart) < 1 then Exit;
  6926. Str := EditText;
  6927. DeleteSelection(Str, SelStart, SelStop - SelStart);
  6928. Str := Copy(Str, SelStart+1, SelStop - SelStart);
  6929. SendMessage(Handle, EM_REPLACESEL, 0, LongInt(PChar(Str)));
  6930. if (SelStop - SelStart) <> 1 then
  6931. begin
  6932. SelStart := GetNextEditChar(SelStart);
  6933. SetCursor(SelStart);
  6934. end
  6935. else begin
  6936. GetSel(SelStart, SelStop);
  6937. SetCursor(SelStart - 1);
  6938. end;
  6939. end;
  6940. procedure TDefineMask.CMEnter(var Message: TCMEnter);
  6941. begin
  6942. if IsMasked and not (csDesigning in ComponentState) then
  6943. begin
  6944. if not (msReEnter in FMaskState) then
  6945. begin
  6946. FOldValue := EditText;
  6947. inherited;
  6948. end;
  6949. Exclude(FMaskState, msReEnter);
  6950. CheckCursor;
  6951. end
  6952. else
  6953. inherited;
  6954. end;
  6955. procedure TDefineMask.CMTextChanged(var Message: TMessage);
  6956. var
  6957. SelStart, SelStop : Integer;
  6958. Temp: Integer;
  6959. begin
  6960. inherited;
  6961. FOldValue := EditText;
  6962. if HandleAllocated then
  6963. begin
  6964. GetSel(SelStart, SelStop);
  6965. Temp := GetNextEditChar(SelStart);
  6966. if Temp <> SelStart then
  6967. SetCursor(Temp);
  6968. end;
  6969. end;
  6970. procedure TDefineMask.CMWantSpecialKey(var Message: TCMWantSpecialKey);
  6971. begin
  6972. inherited;
  6973. if (Message.CharCode = VK_ESCAPE) and IsMasked and Modified then
  6974. Message.Result := 1;
  6975. end;
  6976. procedure TDefineMask.CMExit(var Message: TCMExit);
  6977. begin
  6978. if IsMasked and not (csDesigning in ComponentState) then
  6979. begin
  6980. ValidateEdit;
  6981. CheckCursor;
  6982. end;
  6983. inherited;
  6984. end;
  6985. procedure TDefineMask.ValidateEdit;
  6986. var
  6987. Str: string;
  6988. Pos: Integer;
  6989. begin
  6990. Str := EditText;
  6991. if IsMasked and Modified then
  6992. begin
  6993. if not Validate(Str, Pos) then
  6994. begin
  6995. if not (csDesigning in ComponentState) then
  6996. begin
  6997. Include(FMaskState, msReEnter);
  6998. SetFocus;
  6999. end;
  7000. SetCursor(Pos);
  7001. ValidateError;
  7002. end;
  7003. end;
  7004. end;
  7005. procedure TDefineMask.ValidateError;
  7006. begin
  7007. MessageBeep(0);
  7008. raise TDefineError.Create(SMaskEditErr);
  7009. end;
  7010. function TDefineMask.AddEditFormat(const Value: string; Active: Boolean): string;
  7011. begin
  7012. if not Active then
  7013. Result := MaskDoFormatText(EditMask, Value, ' ')
  7014. else
  7015. Result := MaskDoFormatText(EditMask, Value, FMaskBlank);
  7016. end;
  7017. function TDefineMask.RemoveEditFormat(const Value: string): string;
  7018. var
  7019. I: Integer;
  7020. OldLen: Integer;
  7021. Offset, MaskOffset: Integer;
  7022. CType: TMaskCharType;
  7023. Dir: TMaskDirectives;
  7024. begin
  7025. Offset := 1;
  7026. Result := Value;
  7027. for MaskOffset := 1 to Length(EditMask) do
  7028. begin
  7029. CType := MaskGetCharType(EditMask, MaskOffset);
  7030. if CType in [mcLiteral, mcIntlLiteral] then
  7031. Result := Copy(Result, 1, Offset - 1) +
  7032. Copy(Result, Offset + 1, Length(Result) - Offset);
  7033. if CType in [mcMask, mcMaskOpt] then Inc(Offset);
  7034. end;
  7035. Dir := MaskGetCurrentDirectives(EditMask, 1);
  7036. if mdReverseDir in Dir then
  7037. begin
  7038. Offset := 1;
  7039. for I := 1 to Length(Result) do
  7040. begin
  7041. if Result[I] = FMaskBlank then
  7042. Inc(Offset)
  7043. else
  7044. break;
  7045. end;
  7046. if Offset <> 1 then
  7047. Result := Copy(Result, Offset, Length(Result) - Offset + 1);
  7048. end
  7049. else begin
  7050. OldLen := Length(Result);
  7051. for I := 1 to OldLen do
  7052. begin
  7053. if Result[OldLen - I + 1] = FMaskBlank then
  7054. SetLength(Result, Length(Result) - 1)
  7055. else Break;
  7056. end;
  7057. end;
  7058. if FMaskBlank <> ' ' then
  7059. begin
  7060. OldLen := Length(Result);
  7061. for I := 1 to OldLen do
  7062. begin
  7063. if Result[I] = FMaskBlank then
  7064. Result[I] := ' ';
  7065. if I > OldLen then Break;
  7066. end;
  7067. end;
  7068. end;
  7069. function TDefineMask.InputChar(var NewChar: Char; Offset: Integer): Boolean;
  7070. var
  7071. MaskOffset: Integer;
  7072. CType: TMaskCharType;
  7073. InChar: Char;
  7074. begin
  7075. Result := True;
  7076. if EditMask <> '' then
  7077. begin
  7078. Result := False;
  7079. MaskOffset := OffsetToMaskOffset(EditMask, Offset);
  7080. if MaskOffset >= 0 then
  7081. begin
  7082. CType := MaskGetCharType(EditMask, MaskOffset);
  7083. InChar := NewChar;
  7084. Result := DoInputChar(NewChar, MaskOffset);
  7085. if not Result and (CType in [mcMask, mcMaskOpt]) then
  7086. begin
  7087. MaskOffset := FindLiteralChar (MaskOffset, InChar);
  7088. if MaskOffset > 0 then
  7089. begin
  7090. MaskOffset := MaskOffsetToOffset(EditMask, MaskOffset);
  7091. SetCursor (MaskOffset);
  7092. Exit;
  7093. end;
  7094. end;
  7095. end;
  7096. end;
  7097. if not Result then
  7098. MessageBeep(0)
  7099. end;
  7100. function TDefineMask.DoInputChar(var NewChar: Char; MaskOffset: Integer): Boolean;
  7101. var
  7102. Dir: TMaskDirectives;
  7103. Str: string;
  7104. CType: TMaskCharType;
  7105. function IsKatakana(const Chr: Byte): Boolean;
  7106. begin
  7107. Result := (SysLocale.PriLangID = LANG_JAPANESE) and (Chr in [$A1..$DF]);
  7108. end;
  7109. function TestChar(NewChar: Char): Boolean;
  7110. var
  7111. Offset: Integer;
  7112. begin
  7113. Offset := MaskOffsetToOffset(EditMask, MaskOffset);
  7114. Result := not ((MaskOffset < Length(EditMask)) and
  7115. (UpCase(EditMask[MaskOffset]) = UpCase(EditMask[MaskOffset+1]))) or
  7116. (ByteType(EditText, Offset) = mbTrailByte) or
  7117. (ByteType(EditText, Offset+1) = mbLeadByte);
  7118. end;
  7119. begin
  7120. Result := True;
  7121. CType := MaskGetCharType(EditMask, MaskOffset);
  7122. if CType in [mcLiteral, mcIntlLiteral] then
  7123. NewChar := MaskIntlLiteralToChar(EditMask[MaskOffset])
  7124. else
  7125. begin
  7126. Dir := MaskGetCurrentDirectives(EditMask, MaskOffset);
  7127. case EditMask[MaskOffset] of
  7128. mMskNumeric, mMskNumericOpt:
  7129. begin
  7130. if not ((NewChar >= '0') and (NewChar <= '9')) then
  7131. Result := False;
  7132. end;
  7133. mMskNumSymOpt:
  7134. begin
  7135. if not (((NewChar >= '0') and (NewChar <= '9')) or
  7136. (NewChar = ' ') or(NewChar = '+') or(NewChar = '-')) then
  7137. Result := False;
  7138. end;
  7139. mMskAscii, mMskAsciiOpt:
  7140. begin
  7141. if (NewChar in LeadBytes) and TestChar(NewChar) then
  7142. begin
  7143. Result := False;
  7144. Exit;
  7145. end;
  7146. if IsCharAlpha(NewChar) then
  7147. begin
  7148. Str := ' ';
  7149. Str[1] := NewChar;
  7150. if (mdUpperCase in Dir) then
  7151. Str := AnsiUpperCase(Str)
  7152. else if mdLowerCase in Dir then
  7153. Str := AnsiLowerCase(Str);
  7154. NewChar := Str[1];
  7155. end;
  7156. end;
  7157. mMskAlpha, mMskAlphaOpt, mMskAlphaNum, mMskAlphaNumOpt:
  7158. begin
  7159. if (NewChar in LeadBytes) then
  7160. begin
  7161. if TestChar(NewChar) then
  7162. Result := False;
  7163. Exit;
  7164. end;
  7165. Str := ' ';
  7166. Str[1] := NewChar;
  7167. if IsKatakana(Byte(NewChar)) then
  7168. begin
  7169. NewChar := Str[1];
  7170. Exit;
  7171. end;
  7172. if not IsCharAlpha(NewChar) then
  7173. begin
  7174. Result := False;
  7175. if ((EditMask[MaskOffset] = mMskAlphaNum) or
  7176. (EditMask[MaskOffset] = mMskAlphaNumOpt)) and
  7177. (IsCharAlphaNumeric(NewChar)) then
  7178. Result := True;
  7179. end
  7180. else if mdUpperCase in Dir then
  7181. Str := AnsiUpperCase(Str)
  7182. else if mdLowerCase in Dir then
  7183. Str := AnsiLowerCase(Str);
  7184. NewChar := Str[1];
  7185. end;
  7186. end;
  7187. end;
  7188. end;
  7189. function TDefineMask.Validate(const Value: string; var Pos: Integer): Boolean;
  7190. var
  7191. Offset, MaskOffset: Integer;
  7192. CType: TMaskCharType;
  7193. begin
  7194. Result := True;
  7195. Offset := 1;
  7196. for MaskOffset := 1 to Length(EditMask) do
  7197. begin
  7198. CType := MaskGetCharType(EditMask, MaskOffset);
  7199. if CType in [mcLiteral, mcIntlLiteral, mcMaskOpt] then
  7200. Inc(Offset)
  7201. else if (CType = mcMask) and (Value <> '') then
  7202. begin
  7203. if (Value [Offset] = FMaskBlank) or
  7204. ((Value [Offset] = ' ') and (EditMask[MaskOffset] <> mMskAscii)) then
  7205. begin
  7206. Result := False;
  7207. Pos := Offset - 1;
  7208. Exit;
  7209. end;
  7210. Inc(Offset);
  7211. end;
  7212. end;
  7213. end;
  7214. function TDefineMask.DeleteSelection(var Value: string; Offset: Integer;
  7215. Len: Integer): Boolean;
  7216. var
  7217. EndDel: Integer;
  7218. StrOffset, MaskOffset, Temp: Integer;
  7219. CType: TMaskCharType;
  7220. begin
  7221. Result := True;
  7222. if Len = 0 then Exit;
  7223. StrOffset := Offset + 1;
  7224. EndDel := StrOffset + Len;
  7225. Temp := OffsetToMaskOffset(EditMask, Offset);
  7226. if Temp < 0 then Exit;
  7227. for MaskOffset := Temp to Length(EditMask) do
  7228. begin
  7229. CType := MaskGetCharType(EditMask, MaskOffset);
  7230. if CType in [mcLiteral, mcIntlLiteral] then
  7231. Inc(StrOffset)
  7232. else if CType in [mcMask, mcMaskOpt] then
  7233. begin
  7234. Value[StrOffset] := FMaskBlank;
  7235. Inc(StrOffset);
  7236. end;
  7237. if StrOffset >= EndDel then Break;
  7238. end;
  7239. end;
  7240. function TDefineMask.InputString(var Value: string; const NewValue: string;
  7241. Offset: Integer): Integer;
  7242. var
  7243. NewOffset, MaskOffset, Temp: Integer;
  7244. CType: TMaskCharType;
  7245. NewVal: string;
  7246. NewChar: Char;
  7247. begin
  7248. Result := Offset;
  7249. if NewValue = '' then Exit;
  7250. { replace chars with new chars, except literals }
  7251. NewOffset := 1;
  7252. NewVal := NewValue;
  7253. Temp := OffsetToMaskOffset(EditMask, Offset);
  7254. if Temp < 0 then Exit;
  7255. MaskOffset := Temp;
  7256. While MaskOffset <= Length(EditMask) do
  7257. begin
  7258. CType := MaskGetCharType(EditMask, MaskOffset);
  7259. if CType in [mcLiteral, mcIntlLiteral, mcMask, mcMaskOpt] then
  7260. begin
  7261. NewChar := NewVal[NewOffset];
  7262. if not (DoInputChar(NewChar, MaskOffset)) then
  7263. begin
  7264. if (NewChar in LeadBytes) then
  7265. NewVal[NewOffset + 1] := FMaskBlank;
  7266. NewChar := FMaskBlank;
  7267. end;
  7268. { if pasted text does not contain a literal in the right place,
  7269. insert one }
  7270. if not ((CType in [mcLiteral, mcIntlLiteral]) and
  7271. (NewChar <> NewVal[NewOffset])) then
  7272. begin
  7273. NewVal[NewOffset] := NewChar;
  7274. if (NewChar in LeadBytes) then
  7275. begin
  7276. Inc(NewOffset);
  7277. Inc(MaskOffset);
  7278. end;
  7279. end
  7280. else
  7281. NewVal := Copy(NewVal, 1, NewOffset-1) + NewChar +
  7282. Copy(NewVal, NewOffset, Length (NewVal));
  7283. Inc(NewOffset);
  7284. end;
  7285. if (NewOffset + Offset) > FMaxChars then Break;
  7286. if (NewOffset) > Length(NewVal) then Break;
  7287. Inc(MaskOffset);
  7288. end;
  7289. if (Offset + Length(NewVal)) < FMaxChars then
  7290. begin
  7291. if ByteType(Value, OffSet + Length(NewVal) + 1) = mbTrailByte then
  7292. begin
  7293. NewVal := NewVal + FMaskBlank;
  7294. Inc(NewOffset);
  7295. end;
  7296. Value := Copy(Value, 1, Offset) + NewVal +
  7297. Copy(Value, OffSet + Length(NewVal) + 1,
  7298. FMaxChars -(Offset + Length(NewVal)));
  7299. end
  7300. else
  7301. begin
  7302. Temp := Offset;
  7303. if (ByteType(NewVal, FMaxChars - Offset) = mbLeadByte) then
  7304. Inc(Temp);
  7305. Value := Copy(Value, 1, Offset) +
  7306. Copy(NewVal, 1, FMaxChars - Temp);
  7307. end;
  7308. Result := NewOffset + Offset - 1;
  7309. end;
  7310. function TDefineMask.FindLiteralChar(MaskOffset: Integer; InChar: Char): Integer;
  7311. var
  7312. CType: TMaskCharType;
  7313. LitChar: Char;
  7314. begin
  7315. Result := -1;
  7316. while MaskOffset < Length(EditMask) do
  7317. begin
  7318. Inc(MaskOffset);
  7319. CType := MaskGetCharType(EditMask, MaskOffset);
  7320. if CType in [mcLiteral, mcIntlLiteral] then
  7321. begin
  7322. LitChar := EditMask[MaskOffset];
  7323. if CType = mcIntlLiteral then
  7324. LitChar := MaskIntlLiteralToChar(LitChar);
  7325. if LitChar = InChar then
  7326. Result := MaskOffset;
  7327. Exit;
  7328. end;
  7329. end;
  7330. end;
  7331. { TDefinePucker}
  7332. constructor TDefinePucker.Create(AOwner: TComponent);
  7333. begin
  7334. inherited Create(AOwner);
  7335. ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  7336. csSetCaption, csOpaque, csDoubleClicks, csReplicatable];
  7337. { When themes are on in an application default to making
  7338. TDefinePanel's paint with their ParentBackground }
  7339. if ThemeServices.ThemesEnabled then
  7340. ControlStyle := ControlStyle + [csParentBackground] - [csOpaque];
  7341. FGradientFill := true;
  7342. FFullRepaint := True;
  7343. FStartColor := DefaultColorStart;
  7344. FEndColor := DefaultColorStop;
  7345. FFillDirection := fdLeftToRight;
  7346. FShadow := true;
  7347. FShadowDist := 5;
  7348. // Width := 180;
  7349. // Height := 100;
  7350. FShowHeader := True;
  7351. FDefaultHeight := 100;
  7352. FTitleHeight := 30;
  7353. FTitleAlignment := taCenter;
  7354. FTitleShadowOnMouseEnter := true;
  7355. FTitleGradient := true;
  7356. FTitleStartColor := DefaultTitleColorStart;
  7357. FTitleEndColor := DefaultTitleColorEnd;
  7358. FTitleColor := clWhite;
  7359. FTitleFillDirect := fdLeftToRight;
  7360. FTitleImage := TBitmap.Create;
  7361. FTitleCursor := crSystemHand;
  7362. FTitleImageTransparent := true;
  7363. FTitleImageAlign := tiaLeft;
  7364. FTitleFont := TFont.Create;
  7365. FTitleFont.Style := [fsBold];
  7366. FTitleFont.Color := clNavy;
  7367. FTitleFont.OnChange := OnTitleFontChange;
  7368. FTitleButtons := [tbMinimize];
  7369. FTitleButtonsStyle := tbsRectangle;
  7370. FTitleBtnBorderColor:= DefaultBorderColor;
  7371. FTitleBtnBGColor := DefaultBackdropColor;
  7372. FTitleBtnBorderSize := 1;
  7373. FMouseOnHeader := False;
  7374. FBorderSize := 1;
  7375. FShowBorder := True;
  7376. FBorderColor := DefaultBorderColor;
  7377. FPanelCorner := [];
  7378. FBGImage := TBitmap.Create;
  7379. FBGImageAlign := iaStretch;
  7380. FBGImageTransparent := true;
  7381. FOnTitleClick := nil;
  7382. FOnTitleDblClick := nil;
  7383. FOnTitleMouseDown := nil;
  7384. FOnTitleMouseUp := nil;
  7385. FOnTitleMouseEnter := nil;
  7386. FOnTitleMouseExit := nil;
  7387. FOnMouseEnter := nil;
  7388. FOnMouseExit := nil;
  7389. FAfterMinimized := nil;
  7390. FAfterMaximized := nil;
  7391. FBeforeMoving := nil;
  7392. FAfterMoving := nil;
  7393. FAfterClose := nil;
  7394. FMovable := False;
  7395. FSizable := False;
  7396. FMinimized := False;
  7397. FAnimation := True;
  7398. FMinimizing := False;
  7399. SetBounds(0,0,180,100);
  7400. end;
  7401. destructor TDefinePucker.Destroy;
  7402. begin
  7403. try FTitleFont.Free; except end;
  7404. try FBGImage.Free; except end;
  7405. try FTitleImage.Free; except end;
  7406. inherited;
  7407. end;
  7408. procedure TDefinePucker.DrawTitle(ACanvas : TCanvas; ATitleRect : TRect);
  7409. var
  7410. X, Y : Integer;
  7411. AGrayImage : TBitmap;
  7412. ATextFormat : Integer;
  7413. ATextRect : TRect;
  7414. ABtnOffset : Integer;
  7415. begin
  7416. if FTitleGradient then
  7417. GradientFillRect(ACanvas, ATitleRect, FTitleStartColor, FTitleEndColor, FTitleFillDirect, 50)
  7418. else
  7419. begin
  7420. ACanvas.Brush.Style := bsSolid;
  7421. ACanvas.Brush.Color := FTitleColor;
  7422. ACanvas.FillRect(ATitleRect);
  7423. end;
  7424. ATextRect := ATitleRect;
  7425. InflateRect(ATextRect, -2, -2);
  7426. ABtnOffset := ATextRect.Right;
  7427. if tbMinimize in FTitleButtons then ABtnOffset := FMinBtnRect.Left - 4 else
  7428. if tbMaximize in FTitleButtons then ABtnOffset := FMaxBtnRect.Left - 4 else
  7429. if tbClose in FTitleButtons then ABtnOffset := FCloseBtnRect.Left - 4;
  7430. if not FTitleImage.Empty then
  7431. begin
  7432. FTitleImage.TransparentMode := tmAuto;
  7433. FTitleImage.Transparent := False;
  7434. if(FTitleImageAlign in [tiaLeft, tiaRight, tiaCenter]) then
  7435. begin
  7436. case FTitleImageAlign of
  7437. tiaLeft:
  7438. begin
  7439. X := 2;
  7440. Y :=(ATitleRect.Bottom + ATitleRect.Top - FTitleImage.Height) div 2;
  7441. ATextRect.Left := ATextRect.Left + FTitleImage.Width + 8;
  7442. end;
  7443. tiaRight:
  7444. begin
  7445. X := ABtnOffset - FTitleImage.Width;
  7446. Y :=(ATitleRect.Bottom + ATitleRect.Top - FTitleImage.Height) div 2;
  7447. ABtnOffset := X - 4;
  7448. end;
  7449. else
  7450. // tiaCenter:
  7451. begin
  7452. X :=(ATitleRect.Right + ATitleRect.Left - FTitleImage.Width) div 2;
  7453. Y :=(ATitleRect.Bottom + ATitleRect.Top - FTitleImage.Height) div 2;
  7454. end;
  7455. end;
  7456. //Image Shadow
  7457. if FMouseOnHeader then
  7458. begin
  7459. AGrayImage := TBitmap.Create;
  7460. try
  7461. CopyBitmap(FTitleImage, AGrayImage);
  7462. AGrayImage.TransparentMode := tmAuto;
  7463. AGrayImage.Transparent := true;
  7464. ConvertBitmapToGrayscale(AGrayImage);
  7465. if FTitleImageTransparent then
  7466. DrawBitmapTransparent(ACanvas, X, Y, AGrayImage, AGrayImage.Canvas.Pixels [0,0])
  7467. else
  7468. ACanvas.Draw(X, Y, AGrayImage);
  7469. finally
  7470. AGrayImage.Free;
  7471. end;
  7472. end;
  7473. //Image
  7474. if FTitleImageTransparent then
  7475. DrawBitmapTransparent(ACanvas, X - Integer(FMouseOnHeader), Y - Integer(FMouseOnHeader),
  7476. FTitleImage, FTitleImage.Canvas.Pixels [0,0])
  7477. else
  7478. ACanvas.Draw(X - Integer(FMouseOnHeader), Y - Integer(FMouseOnHeader), FTitleImage);
  7479. end
  7480. else
  7481. begin
  7482. FTitleImage.TransparentMode := tmAuto;
  7483. FTitleImage.Transparent := FTitleImageTransparent;
  7484. case FTitleImageAlign of
  7485. tiaStretch:
  7486. ACanvas.StretchDraw(ATitleRect, FTitleImage);
  7487. tiaTile:
  7488. TileImage(ACanvas, ATitleRect, FTitleImage);
  7489. end;
  7490. end;
  7491. end;
  7492. if FCaption <> '' then
  7493. begin
  7494. ATextRect.Right := ABtnOffset;
  7495. ATextFormat := DT_VCENTER or DT_END_ELLIPSIS or DT_SINGLELINE;
  7496. ACanvas.Font.Assign(FTitleFont);
  7497. case FTitleAlignment of
  7498. taLeftJustify: ATextFormat := ATextFormat or DT_LEFT;
  7499. taRightJustify: ATextFormat := ATextFormat or DT_RIGHT;
  7500. taCenter: ATextFormat := ATextFormat or DT_CENTER;
  7501. end;
  7502. ACanvas.Brush.Style := bsClear;
  7503. //Shadow
  7504. ACanvas.Font.Color := clLtGray;
  7505. DrawText(ACanvas.Handle, PChar(FCaption), Length(FCaption), ATextRect, ATextFormat);
  7506. //Text
  7507. ACanvas.Font.Assign(FTitleFont);
  7508. OffsetRect(ATextRect, -1, -1);
  7509. if FMouseOnHeader then OffsetRect(ATextRect, -1, -1);
  7510. DrawText(ACanvas.Handle, PChar(FCaption), Length(FCaption), ATextRect, ATextFormat);
  7511. end;
  7512. end;
  7513. procedure TDefinePucker.DrawAllTitleButtons(ACanvas : TCanvas; ATitleRect : TRect);
  7514. const
  7515. XOffset : Integer = 22;
  7516. var
  7517. AButtonRect : TRect;
  7518. begin
  7519. if FTitleButtons = [] then Exit;
  7520. AButtonRect.Left := ATitleRect.Right - cTitleButtonSize - 2 + XOffset;
  7521. AButtonRect.Right := ATitleRect.Right - 2 + XOffset;
  7522. AButtonRect.Top :=(ATitleRect.Bottom + ATitleRect.Top) div 2 -(cTitleButtonSize div 2)+1;
  7523. AButtonRect.Bottom :=(ATitleRect.Bottom + ATitleRect.Top) div 2 +(cTitleButtonSize div 2);
  7524. if tbClose in FTitleButtons then
  7525. begin
  7526. AButtonRect.Left := AButtonRect.Left - XOffset;
  7527. AButtonRect.Right := AButtonRect.Right- XOffset;
  7528. FCloseBtnRect := AButtonRect;
  7529. DrawTitleButton(ACanvas, AButtonRect, tbClose);
  7530. end;
  7531. if tbMaximize in FTitleButtons then
  7532. begin
  7533. AButtonRect.Left := AButtonRect.Left - XOffset;
  7534. AButtonRect.Right := AButtonRect.Right- XOffset;
  7535. FMaxBtnRect := AButtonRect;
  7536. DrawTitleButton(ACanvas, AButtonRect, tbMaximize);
  7537. end;
  7538. if tbMinimize in FTitleButtons then
  7539. begin
  7540. AButtonRect.Left := AButtonRect.Left - XOffset;
  7541. AButtonRect.Right := AButtonRect.Right- XOffset;
  7542. FMinBtnRect := AButtonRect;
  7543. DrawTitleButton(ACanvas, AButtonRect, tbMinimize);
  7544. end;
  7545. end;
  7546. procedure TDefinePucker.DrawTitleButton(ACanvas : TCanvas; AButtonRect : TRect; ABtnType : TTitleButton);
  7547. var
  7548. XCenter, YCenter, Radius : Integer;
  7549. procedure DrawStyle(Canvas:TCanvas;Rect:TRect;Style:TTitleButtonsStyle);
  7550. begin
  7551. case Style of
  7552. tbsEllipse : Canvas.Ellipse(Rect);
  7553. tbsRectangle : Canvas.Rectangle(Rect);
  7554. end;
  7555. end;
  7556. begin
  7557. ACanvas.Pen.Color := MakeDarkColor(FTitleBtnBorderColor, 30);
  7558. ACanvas.Pen.Width := FTitleBtnBorderSize;
  7559. ACanvas.Brush.Color := MakeDarkColor(FTitleBtnBGColor, 30);
  7560. DrawStyle(ACanvas,AButtonRect,FTitleButtonsStyle);
  7561. XCenter :=(AButtonRect.Right + AButtonRect.Left) div 2;
  7562. YCenter :=(AButtonRect.Bottom + AButtonRect.Top) div 2;
  7563. if XCenter < YCenter then
  7564. Radius :=(XCenter - AButtonRect.Left)-4
  7565. else
  7566. Radius :=(YCenter - AButtonRect.Top)-4;
  7567. ACanvas.Pen.Width := 2;
  7568. if FMouseOnHeader and FShowHeader then
  7569. ACanvas.Pen.Color := $FF5C33
  7570. else
  7571. ACanvas.Pen.Color := $A53C00;
  7572. case ABtnType of
  7573. tbClose:
  7574. begin
  7575. ACanvas.Polyline([Point(XCenter - Radius + 2, YCenter - Radius + 2),
  7576. Point(XCenter + Radius - 2, YCenter + Radius - 2) ]);
  7577. ACanvas.Polyline([Point(XCenter + Radius - 2, YCenter - Radius + 2),
  7578. Point(XCenter - Radius + 2, YCenter + Radius - 2) ]);
  7579. end;
  7580. tbMaximize:
  7581. begin
  7582. ACanvas.Pen.Width := 1;
  7583. if FMaximized then
  7584. begin
  7585. ACanvas.Rectangle(XCenter - Radius + 1, YCenter - Radius + 1,
  7586. XCenter + Radius-1, YCenter + Radius-2);
  7587. ACanvas.Rectangle(XCenter - Radius + 3, YCenter - Radius + 3,
  7588. XCenter + Radius+1, YCenter + Radius);
  7589. end
  7590. else
  7591. begin
  7592. ACanvas.Rectangle(XCenter - Radius + 1, YCenter - Radius + 1,
  7593. XCenter + Radius, YCenter + Radius);
  7594. ACanvas.Rectangle(XCenter - Radius + 1, YCenter - Radius + 2,
  7595. XCenter + Radius, YCenter + Radius);
  7596. end;
  7597. end;
  7598. tbMinimize:
  7599. begin
  7600. if FMinimized then
  7601. begin
  7602. //Drawing down arrows
  7603. ACanvas.Polyline([Point(XCenter - Radius + 2, YCenter - Radius + 1),
  7604. Point(XCenter, YCenter-1),
  7605. Point(XCenter + Radius - 2, YCenter - Radius + 1) ]);
  7606. ACanvas.Polyline([Point(XCenter - Radius + 2, YCenter+1),
  7607. Point(XCenter, YCenter + Radius - 1),
  7608. Point(XCenter + Radius - 2, YCenter+1) ]);
  7609. end
  7610. else
  7611. begin
  7612. //Drawing up arrows
  7613. ACanvas.Polyline([Point(XCenter - Radius + 2, YCenter - 1),
  7614. Point(XCenter, YCenter - Radius + 1),
  7615. Point(XCenter + Radius - 2, YCenter - 1) ]);
  7616. ACanvas.Polyline([Point(XCenter - Radius + 2, YCenter + Radius - 1),
  7617. Point(XCenter, YCenter+1),
  7618. Point(XCenter + Radius - 2, YCenter + Radius - 1) ]);
  7619. end;
  7620. end;
  7621. end;
  7622. end;
  7623. procedure TDefinePucker.DrawBorder(ACanvas : TCanvas; ARect : TRect; AClient : Boolean);
  7624. var
  7625. APanelCorner : TPanelCorners;
  7626. begin
  7627. ACanvas.Brush.Style := BSCLEAR;
  7628. ACanvas.Pen.Color := FBorderColor;
  7629. ACanvas.Pen.Width := FBorderSize;
  7630. ACanvas.Rectangle(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom);
  7631. if FPanelCorner = [] then Exit;
  7632. APanelCorner := FPanelCorner;
  7633. if AClient then
  7634. APanelCorner := APanelCorner - [rcTopLeft, rcTopRight];
  7635. if(rcTopLeft in APanelCorner) and(rcTopRight in APanelCorner) and
  7636. (rcBottomLeft in APanelCorner) and(rcBottomRight in APanelCorner) then
  7637. begin
  7638. ACanvas.RoundRect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7639. APanelCorner := [];
  7640. end
  7641. else
  7642. if(rcTopLeft in APanelCorner) and(rcTopRight in APanelCorner) then
  7643. begin
  7644. ACanvas.RoundRect(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom + DefaultCornerRadius*2, DefaultCornerRadius, DefaultCornerRadius);
  7645. APanelCorner := APanelCorner - [rcTopLeft, rcTopRight];
  7646. end
  7647. else
  7648. if(rcBottomLeft in APanelCorner) and(rcBottomRight in APanelCorner) then
  7649. begin
  7650. ACanvas.RoundRect(ARect.Left, ARect.Top - DefaultCornerRadius*2, ARect.Right, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7651. APanelCorner := APanelCorner - [rcBottomLeft, rcBottomRight];
  7652. end
  7653. else
  7654. if(rcTopLeft in APanelCorner) and(rcBottomLeft in APanelCorner) then
  7655. begin
  7656. ACanvas.RoundRect(ARect.Left, ARect.Top, ARect.Right + DefaultCornerRadius*2, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7657. APanelCorner := APanelCorner - [rcTopLeft, rcBottomLeft];
  7658. end
  7659. else
  7660. if(rcTopRight in APanelCorner) and(rcBottomRight in APanelCorner) then
  7661. begin
  7662. ACanvas.RoundRect(ARect.Left - DefaultCornerRadius*2, ARect.Top, ARect.Right, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7663. APanelCorner := APanelCorner - [rcTopRight, rcBottomRight];
  7664. end;
  7665. if APanelCorner = [] then Exit;
  7666. if(rcTopLeft in APanelCorner) then
  7667. ACanvas.RoundRect(ARect.Left, ARect.Top, ARect.Right + DefaultCornerRadius*2, ARect.Bottom + DefaultCornerRadius*2, DefaultCornerRadius, DefaultCornerRadius);
  7668. if(rcTopRight in APanelCorner) then
  7669. ACanvas.RoundRect(ARect.Left - DefaultCornerRadius*2, ARect.Top, ARect.Right, ARect.Bottom + DefaultCornerRadius*2, DefaultCornerRadius, DefaultCornerRadius);
  7670. if(rcBottomLeft in APanelCorner) then
  7671. ACanvas.RoundRect(ARect.Left, ARect.Top - DefaultCornerRadius*2, ARect.Right + DefaultCornerRadius*2, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7672. if(rcBottomRight in APanelCorner) then
  7673. ACanvas.RoundRect(ARect.Left - DefaultCornerRadius*2, ARect.Top - DefaultCornerRadius*2, ARect.Right, ARect.Bottom, DefaultCornerRadius, DefaultCornerRadius);
  7674. end;
  7675. procedure TDefinePucker.DrawBGImage(ACanvas : TCanvas);
  7676. begin
  7677. FBGImage.TransparentMode := tmAuto;
  7678. FBGImage.Transparent := FBGImageTransparent;
  7679. case FBGImageAlign of
  7680. iaStretch:
  7681. begin
  7682. ACanvas.StretchDraw(ClientRect, FBGImage);
  7683. end;
  7684. iaCenter:
  7685. begin
  7686. ACanvas.Draw(
  7687. (ClientWidth - FBGImage.Width) div 2,
  7688. (ClientHeight - FBGImage.Height) div 2,
  7689. FBGImage);
  7690. end;
  7691. iaTile:
  7692. begin
  7693. TileImage(ACanvas, ClientRect, FBGImage);
  7694. end;
  7695. end;
  7696. end;
  7697. //Draw client area
  7698. procedure TDefinePucker.Paint;
  7699. var
  7700. TempCanvas : TBitmap;
  7701. begin
  7702. TempCanvas := TBitmap.Create;
  7703. try
  7704. TempCanvas.Width := ClientWidth;
  7705. TempCanvas.Height := ClientHeight;
  7706. if FGradientFill then begin
  7707. GradientFillRect(TempCanvas.Canvas, ClientRect, FStartColor, FEndColor, FFillDirection, 60);
  7708. end else Begin
  7709. TempCanvas.Canvas.Brush.Style := bsSolid;
  7710. TempCanvas.Canvas.Brush.Color := Color;
  7711. TempCanvas.Canvas.FillRect(ClientRect);
  7712. end;
  7713. if not FBGImage.Empty then DrawBGImage(TempCanvas.Canvas);
  7714. BitBlt(Canvas.Handle, 0, 0, TempCanvas.Width, TempCanvas.Height,TempCanvas.Canvas.Handle, 0, 0, SRCCOPY);
  7715. if FShowBorder then begin
  7716. SendMessage(Handle, WM_NCPAINT, wmNCPaintOnlyBorder, 0);
  7717. //SendMessage(Handle, WM_NCPAINT, 0, 0);
  7718. end;
  7719. finally
  7720. TempCanvas.Free;
  7721. end;
  7722. end;
  7723. //Calculate nonclient area
  7724. procedure TDefinePucker.WMNCCalcSize(var Message : TWMNCCalcSize);
  7725. begin
  7726. if FShowBorder then
  7727. begin
  7728. InflateRect(Message.CalcSize_Params^.rgrc[0], -FBorderSize, -FBorderSize);
  7729. if FShowHeader then
  7730. Inc(Message.CalcSize_Params^.rgrc[0].Top, FTitleHeight);
  7731. end
  7732. else
  7733. begin
  7734. if FShowHeader then
  7735. Inc(Message.CalcSize_Params^.rgrc[0].Top, FTitleHeight+1);
  7736. end;
  7737. inherited;
  7738. end;
  7739. procedure TDefinePucker.WMNCACTIVATE(var Message : TWMNCActivate);
  7740. begin
  7741. inherited;
  7742. end;
  7743. procedure TDefinePucker.NCHitTest(var Message : TWMNCHitTest);
  7744. var
  7745. WinRect : TRect;
  7746. ClientPoint : TPoint;
  7747. PanelPoint : TPoint;
  7748. ABottom : Integer;
  7749. ATitleHeight : Integer;
  7750. ABorderSize : Integer;
  7751. begin
  7752. inherited;
  7753. Message.Result := HTCLIENT;
  7754. GetWindowRect(Handle, WinRect);
  7755. ABottom := WinRect.Bottom;
  7756. if FShowHeader then ATitleHeight := FTitleHeight else ATitleHeight := 0;
  7757. if FShowBorder then
  7758. begin
  7759. ABorderSize := FBorderSize;
  7760. if ABorderSize < 5 then ABorderSize := 5;
  7761. end
  7762. else
  7763. ABorderSize := 0;
  7764. WinRect.Bottom := WinRect.Top + ATitleHeight;
  7765. ClientPoint := Point(Message.XPos, Message.YPos);
  7766. PanelPoint := ScreenToClient(ClientPoint);
  7767. if PtInRect(WinRect, Point(Message.XPos, Message.YPos)) then
  7768. Message.Result := HTOBJECT;
  7769. if FTitleShadowOnMouseEnter then
  7770. begin
  7771. if(not FMouseOnHeader) and((PtInRect(WinRect, Point(Message.XPos, Message.YPos)))) then
  7772. begin
  7773. FMouseOnHeader := true;
  7774. SendMessage(Handle, WM_NCPAINT, 0, 0);
  7775. if Assigned(FOnTitleMouseEnter) then FOnTitleMouseEnter(self);
  7776. end
  7777. else
  7778. if(not((PtInRect(WinRect, Point(Message.XPos, Message.YPos))))) and(FMouseOnHeader) then
  7779. begin
  7780. FMouseOnHeader := False;
  7781. SendMessage(Handle, WM_NCPAINT, 0, 0);
  7782. if Assigned(FOnTitleMouseExit) then FOnTitleMouseExit(self);
  7783. end;
  7784. end;
  7785. Inc(PanelPoint.y, FTitleHeight);
  7786. if tbClose in FTitleButtons then
  7787. begin
  7788. if PtInRect(FCloseBtnRect, PanelPoint) then
  7789. Message.Result := HTCLOSE;
  7790. end;
  7791. if tbMaximize in FTitleButtons then
  7792. begin
  7793. if PtInRect(FMaxBtnRect, PanelPoint) then
  7794. Message.Result := HTMAXBUTTON;
  7795. end;
  7796. if tbMinimize in FTitleButtons then
  7797. begin
  7798. if PtInRect(FMinBtnRect, PanelPoint) then
  7799. Message.Result := HTMINBUTTON;
  7800. end;
  7801. if(csDesigning in ComponentState) then Exit;
  7802. WinRect.Bottom := ABottom;
  7803. if FSizable and not FMinimized and not Maximized then
  7804. begin
  7805. if PtInRect(Rect(WinRect.Left, WinRect.Top, WinRect.Left + ABorderSize+5, WinRect.Top + ABorderSize + 5), ClientPoint) then
  7806. Message.Result := HTTOPLEFT
  7807. else
  7808. //Check mouse on TopRight border
  7809. if PtInRect(Rect(WinRect.Right - 5, WinRect.Top, WinRect.Right+1, WinRect.Top + 5), ClientPoint) then
  7810. Message.Result := HTTOPRIGHT
  7811. //Check mouse on BottomLeft border
  7812. else
  7813. if PtInRect(Rect(WinRect.Left, WinRect.Bottom - ABorderSize-5, WinRect.Left+5, WinRect.Bottom), ClientPoint) then
  7814. Message.Result := HTBOTTOMLEFT
  7815. //Check mouse on BottomRight border
  7816. else
  7817. if PtInRect(Rect(WinRect.Right-5, WinRect.Bottom - ABorderSize-5, WinRect.Right, WinRect.Bottom), ClientPoint) then
  7818. Message.Result := HTBOTTOMRIGHT
  7819. else
  7820. //Check mouse on Left border
  7821. if PtInRect(Rect(WinRect.Left, WinRect.Top + 5, WinRect.Left + ABorderSize, WinRect.Right - ABorderSize), ClientPoint) then
  7822. Message.Result := HTLEFT
  7823. else
  7824. //Check mouse on Right border
  7825. if PtInRect(Rect(WinRect.Right - ABorderSize, WinRect.Top + 5, WinRect.Right+1, WinRect.Bottom - 5), ClientPoint) then
  7826. Message.Result := HTRIGHT
  7827. else
  7828. //Check mouse on Top border
  7829. if PtInRect(Rect(WinRect.Left+5, WinRect.Top, WinRect.Right-5, WinRect.Top + ABorderSize), ClientPoint) then
  7830. Message.Result := HTTOP
  7831. //Check mouse on Bottom border
  7832. else
  7833. if PtInRect(Rect(WinRect.Left+5, WinRect.Bottom - ABorderSize, WinRect.Right-5, WinRect.Bottom), ClientPoint) then
  7834. Message.Result := HTBOTTOM;
  7835. end;
  7836. if FMovable and PtInRect(WinRect, ClientPoint) and
  7837. not(Message.Result in [HTCLOSE, HTMINBUTTON, HTMAXBUTTON]) then
  7838. begin
  7839. WinRect.Bottom := WinRect.Top + ATitleHeight;
  7840. InflateRect(WinRect, -ABorderSize, -ABorderSize);
  7841. if PtInRect(WinRect, ClientPoint) then Message.Result := HTCAPTION;
  7842. end;
  7843. end;
  7844. //Draw nonclient area
  7845. procedure TDefinePucker.WMNCPaint(var Message : TWMNCPaint);
  7846. var
  7847. UpdateRect : TRect;
  7848. HeaderRect : TRect;
  7849. DC : hDC;
  7850. NCCanvas : TCanvas;
  7851. TempCanvas : TBitmap;
  7852. begin
  7853. DC := GetWindowDC(Handle);
  7854. NCCanvas := TCanvas.Create;
  7855. try
  7856. NCCanvas.Handle := DC;
  7857. GetWindowRect(Handle, UpdateRect);
  7858. OffsetRect(UpdateRect, - UpdateRect.Left, - UpdateRect.Top);
  7859. HeaderRect := UpdateRect;
  7860. HeaderRect.Left := HeaderRect.Left - FBorderSize;
  7861. HeaderRect.Bottom := FTitleHeight + FBorderSize;
  7862. if FShowBorder then
  7863. begin
  7864. HeaderRect.Bottom := FTitleHeight + FBorderSize;
  7865. InflateRect(HeaderRect, -FBorderSize, 0);
  7866. end;
  7867. if(FShowHeader) and(Message.Unused{$IFNDEF DELPHI_6_UP}[0]{$ENDIF} <> wmNCPaintOnlyBorder) then
  7868. begin
  7869. TempCanvas := TBitmap.Create;
  7870. try
  7871. //Title Drawing
  7872. TempCanvas.Width := HeaderRect.Right - HeaderRect.Left;
  7873. TempCanvas.Height := HeaderRect.Bottom - HeaderRect.Top;
  7874. DrawTitle(TempCanvas.Canvas, HeaderRect);
  7875. //Title Butons Drawing
  7876. DrawAllTitleButtons(TempCanvas.Canvas, HeaderRect);
  7877. BitBlt(DC, HeaderRect.Left, HeaderRect.Top, TempCanvas.Width, TempCanvas.Height,
  7878. TempCanvas.Canvas.Handle, 0, 0, SRCCOPY);
  7879. finally
  7880. TempCanvas.Free;
  7881. end;
  7882. end;
  7883. if FShowBorder then
  7884. begin
  7885. //DrawBorder(NCCanvas, UpdateRect,(Message.Unused[0] = wmNCPaintOnlyBorder));
  7886. DrawBorder(NCCanvas, UpdateRect, False);
  7887. end;
  7888. finally
  7889. NCCanvas.Free;
  7890. ReleaseDC(Handle, DC);
  7891. end;
  7892. Message.Result := 0;
  7893. inherited;
  7894. end;
  7895. procedure TDefinePucker.WMSize(var Message : TMessage);
  7896. begin
  7897. FullRepaint :=(FGradientFill and FBGImage.Empty) or
  7898. ((not FBGImage.Empty) and(FBGImageAlign <> iaTile )) or
  7899. (FGradientFill and(not FBGImage.Empty) and(FBGImageAlign <> iaTile)) ;
  7900. SetShape(FPanelCorner);
  7901. inherited;
  7902. end;
  7903. procedure TDefinePucker.SetShape(ARounded : TPanelCorners);
  7904. var
  7905. WinRgn : hRgn;
  7906. WinRgn1 : hRgn;
  7907. WinRgn2 : hRgn;
  7908. Rectn : TRect;
  7909. RTop, RBottom : Integer;
  7910. AWidth, AHeight : Integer;
  7911. begin
  7912. WinRgn := 0;
  7913. GetWindowRect(Handle, Rectn);
  7914. OffsetRect(Rectn, -Rectn.Left, -Rectn.Top);
  7915. //Delete old window region
  7916. GetWindowRgn(Handle, WinRgn);
  7917. DeleteObject(WinRgn);
  7918. AWidth := Width;
  7919. AHeight := Height;
  7920. if ARounded <> [] then
  7921. begin
  7922. RTop := 0;
  7923. RBottom := AHeight;
  7924. if(rcTopLeft in ARounded) or(rcTopRight in ARounded) then RTop := DefaultCornerRadius div 2;
  7925. if(rcBottomLeft in ARounded) or(rcBottomRight in ARounded) then RBottom := AHeight - DefaultCornerRadius div 2;
  7926. WinRgn := CreateRectRgn(0, RTop, AWidth, RBottom);
  7927. //Create topleft rounded corner
  7928. if rcTopLeft in ARounded then
  7929. begin
  7930. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, DefaultCornerRadius div 2, DefaultCornerRadius, DefaultCornerRadius);
  7931. WinRgn2 := CreateEllipticRgn(0,0,DefaultCornerRadius+1,DefaultCornerRadius+1);
  7932. CombineRgn(WinRgn1, WinRgn1, WinRgn2, RGN_OR);
  7933. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7934. DeleteObject(WinRgn1);
  7935. DeleteObject(WinRgn2);
  7936. //Create result region
  7937. if rcTopRight in ARounded then
  7938. begin
  7939. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, 0, AWidth - DefaultCornerRadius div 2, DefaultCornerRadius);
  7940. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7941. end
  7942. else
  7943. begin
  7944. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, 0, AWidth, DefaultCornerRadius);
  7945. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7946. end;
  7947. DeleteObject(WinRgn1);
  7948. end;
  7949. //Create topright rounded corner
  7950. if rcTopRight in ARounded then
  7951. begin
  7952. WinRgn1 := CreateRectRgn(AWidth - DefaultCornerRadius, 0, AWidth - DefaultCornerRadius div 2, DefaultCornerRadius);
  7953. WinRgn2 := CreateEllipticRgn(AWidth - DefaultCornerRadius + 1, 0, AWidth+1, DefaultCornerRadius);
  7954. CombineRgn(WinRgn1, WinRgn1, WinRgn2, RGN_OR);
  7955. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7956. DeleteObject(WinRgn1);
  7957. DeleteObject(WinRgn2);
  7958. //Create result region
  7959. if rcTopLeft in ARounded then
  7960. begin
  7961. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, 0, AWidth - DefaultCornerRadius div 2, DefaultCornerRadius);
  7962. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7963. end
  7964. else
  7965. begin
  7966. WinRgn1 := CreateRectRgn(0, 0, AWidth - DefaultCornerRadius, DefaultCornerRadius);
  7967. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7968. end;
  7969. DeleteObject(WinRgn1);
  7970. end;
  7971. //Create bottomleft rounded corner
  7972. if rcBottomLeft in ARounded then
  7973. begin
  7974. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, AHeight - DefaultCornerRadius, DefaultCornerRadius, AHeight - DefaultCornerRadius div 2);
  7975. WinRgn2 := CreateEllipticRgn(0, AHeight - DefaultCornerRadius, DefaultCornerRadius,AHeight+1);
  7976. CombineRgn(WinRgn1, WinRgn1, WinRgn2, RGN_OR);
  7977. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7978. DeleteObject(WinRgn1);
  7979. DeleteObject(WinRgn2);
  7980. //Create result region
  7981. if rcBottomRight in ARounded then
  7982. begin
  7983. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, AHeight - DefaultCornerRadius div 2, AWidth - DefaultCornerRadius div 2, AHeight);
  7984. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7985. end
  7986. else
  7987. begin
  7988. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, AHeight - DefaultCornerRadius div 2, AWidth, AHeight);
  7989. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  7990. end;
  7991. DeleteObject(WinRgn1);
  7992. end;
  7993. //Create bottomright rounded corner
  7994. if rcBottomRight in ARounded then
  7995. begin
  7996. WinRgn1 := CreateRectRgn(AWidth - DefaultCornerRadius, AHeight - DefaultCornerRadius,
  7997. AWidth - DefaultCornerRadius div 2, AHeight);
  7998. WinRgn2 := CreateEllipticRgn(AWidth - DefaultCornerRadius + 1, AHeight-DefaultCornerRadius+1, AWidth+1, AHeight+1);
  7999. CombineRgn(WinRgn1, WinRgn1, WinRgn2, RGN_OR);
  8000. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  8001. DeleteObject(WinRgn1);
  8002. DeleteObject(WinRgn2);
  8003. //Create result region
  8004. if rcBottomLeft in ARounded then
  8005. begin
  8006. WinRgn1 := CreateRectRgn(DefaultCornerRadius div 2, AHeight - DefaultCornerRadius div 2, AWidth - DefaultCornerRadius div 2+1, AHeight);
  8007. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR)
  8008. end
  8009. else
  8010. begin
  8011. WinRgn1 := CreateRectRgn(0, AHeight - DefaultCornerRadius div 2, AWidth - DefaultCornerRadius div 2+1, AHeight);
  8012. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  8013. end;
  8014. DeleteObject(WinRgn1);
  8015. end;
  8016. end
  8017. else
  8018. WinRgn := CreateRectRgn(0, 0, AWidth, AHeight);
  8019. //////////////////////////////////////////////////////////////////////////////
  8020. //////////////// Creating top region for title bitmap //////////////////////
  8021. //////////////////////////////////////////////////////////////////////////////
  8022. {
  8023. if(not FTitleImage.Empty) and(FTitleImageAlign in [tiaLeft, tiaCenter, tiaRight]) and
  8024. (FTitleImage.Height > FTitleHeight) then
  8025. begin
  8026. if FTitleImageTransparent then
  8027. WinRgn1 := CreateRegionFromBitmap(FTitleImage,
  8028. FTitleImage.Canvas.Pixels [FTitleImage.Canvas.ClipRect.Left, FTitleImage.Canvas.ClipRect.Top],
  8029. 0)
  8030. else
  8031. WinRgn1 := CreateRegionFromBitmap(FTitleImage, clNone, 30);
  8032. //OffsetRgn(WinRgn1, 5, FTitleImage.Height - FTitleHeight + 5);
  8033. OffsetRgn(WinRgn, 0, FTitleImage.Height - FTitleHeight + 5);
  8034. CombineRgn(WinRgn, WinRgn, WinRgn1, RGN_OR);
  8035. DeleteObject(WinRgn1);
  8036. end; }
  8037. //////////////////////////////////////////////////////////////////////////////
  8038. SetWindowRgn(Handle, WinRgn, true);
  8039. end;
  8040. procedure TDefinePucker.ForceReDraw;
  8041. begin
  8042. SendMessage(Handle, WM_NCPAINT, 0, 0);
  8043. Invalidate;
  8044. end;
  8045. procedure TDefinePucker.Loaded;
  8046. begin
  8047. inherited;
  8048. if FPanelCorner <> [] then SetShape(FPanelCorner);
  8049. SendMessage(Handle, WM_NCPAINT, 0, 0);
  8050. if Minimized then
  8051. FHeight := DefaultHeight
  8052. else
  8053. FHeight := Height;
  8054. FOldBounds := BoundsRect;
  8055. if Align = alClient then
  8056. begin
  8057. FOldAlign := alNone;
  8058. FMaximized := true;
  8059. end
  8060. else
  8061. FMaximized := false;
  8062. end;
  8063. procedure TDefinePucker.MouseEnter(var Message : TMessage);
  8064. begin
  8065. inherited;
  8066. if Assigned(FOnMouseEnter) then FOnMouseEnter(self);
  8067. end;
  8068. procedure TDefinePucker.MouseLeave(var Message : TMessage);
  8069. begin
  8070. inherited;
  8071. if FMouseOnHeader then
  8072. begin
  8073. FMouseOnHeader := False;
  8074. FullRepaint := False;
  8075. SendMessage(Handle, WM_NCPAINT, 0, 0);
  8076. if Assigned(FOnTitleMouseExit) then FOnTitleMouseExit(self);
  8077. end;
  8078. if Assigned(FOnMouseExit) then FOnMouseExit(self);
  8079. end;
  8080. procedure TDefinePucker.NCMouseDown(var Message : TWMNCLBUTTONDOWN);
  8081. var
  8082. ATitleHeight : Integer;
  8083. begin
  8084. if not(Message.HitTest in [HTCLOSE, HTMINBUTTON, HTMAXBUTTON]) then
  8085. begin
  8086. if Message.HitTest = HTCAPTION then
  8087. begin
  8088. if Assigned(FBeforeMoving) then FBeforeMoving(self);
  8089. end;
  8090. inherited;
  8091. Invalidate;
  8092. if Message.HitTest in [HTTOP, HTLEFT, HTRIGHT, HTBOTTOM,
  8093. HTTOPLEFT, HTTOPRIGHT, HTBOTTOMLEFT, HTBOTTOMRIGHT] then
  8094. begin
  8095. Invalidate;
  8096. end;
  8097. if Message.HitTest = HTCAPTION then
  8098. begin
  8099. if Assigned(FAfterMoving) then FAfterMoving(self);
  8100. end;
  8101. try Parent.Realign; except end;
  8102. end;
  8103. ATitleHeight := 0;
  8104. if FShowHeader then ATitleHeight := FTitleHeight;
  8105. if FShowBorder then ATitleHeight := ATitleHeight + 1;
  8106. if Assigned(FOnTitleMouseDown) then
  8107. FOnTitleMouseDown(Self, mbLeft, [],
  8108. ScreenToClient(Point(Message.XCursor, Message.YCursor)).x,
  8109. ScreenToClient(Point(Message.XCursor, Message.YCursor)).y + ATitleHeight);
  8110. end;
  8111. procedure TDefinePucker.NCMouseUp(var Message : TWMNCLBUTTONUP);
  8112. var
  8113. ATitleHeight : Integer;
  8114. begin
  8115. inherited;
  8116. Parent.Realign;
  8117. if Assigned(FOnTitleClick) and
  8118. not(Message.HitTest in [HTCLOSE, HTMINBUTTON, HTMAXBUTTON]) then FOnTitleClick(Self);
  8119. ATitleHeight := 0;
  8120. if FShowHeader then ATitleHeight := FTitleHeight;
  8121. if FShowBorder then ATitleHeight := ATitleHeight + 1;
  8122. if Assigned(FOnTitleMouseUp) then
  8123. FOnTitleMouseUp(Self, mbLeft, [],
  8124. ScreenToClient(Point(Message.XCursor, Message.YCursor)).x,
  8125. ScreenToClient(Point(Message.XCursor, Message.YCursor)).y + ATitleHeight);
  8126. case Message.HitTest of
  8127. HTCLOSE:
  8128. begin
  8129. Visible := False;
  8130. if Assigned(FAfterClose) then FAfterClose(Self);
  8131. end;
  8132. HTMAXBUTTON:
  8133. begin
  8134. Maximized := not Maximized;
  8135. end;
  8136. HTMINBUTTON:
  8137. begin
  8138. Minimized := not Minimized;
  8139. end;
  8140. end;
  8141. end;
  8142. procedure TDefinePucker.NCMouseDblClick(var Message : TWMNCLButtonDblClk);
  8143. begin
  8144. if Assigned(FOnTitleDblClick) then FOnTitleDblClick(self);
  8145. if tbMinimize in FTitleButtons then Minimized := not Minimized else
  8146. if tbMaximize in FTitleButtons then Maximized := not Maximized;
  8147. end;
  8148. procedure TDefinePucker.SetFillDirection(AFillDirection : TFillDirection);
  8149. begin
  8150. if FFillDirection <> AFillDirection then begin
  8151. FFillDirection := AFillDirection;
  8152. ForceReDraw;
  8153. end;
  8154. end;
  8155. procedure TDefinePucker.SetCaption(AValue : String);
  8156. begin
  8157. if FCaption <> AValue then begin
  8158. FCaption := AValue;
  8159. ForceReDraw;
  8160. end;
  8161. end;
  8162. procedure TDefinePucker.SetTitleAlignment(AValue : TAlignment);
  8163. begin
  8164. if FTitleAlignment <> AValue then begin
  8165. FTitleAlignment := AValue;
  8166. ForceReDraw;
  8167. end;
  8168. end;
  8169. procedure TDefinePucker.SetTitleFillDirect(AValue : TFillDirection);
  8170. begin
  8171. if FTitleFillDirect <> AValue then begin
  8172. FTitleFillDirect := AValue;
  8173. ForceReDraw;
  8174. end;
  8175. end;
  8176. procedure TDefinePucker.SetTitleImage(AValue : TBitmap);
  8177. begin
  8178. if not FTitleImage.Empty then FTitleImage.FreeImage;
  8179. FTitleImage.Assign(AValue);
  8180. ForceReDraw;
  8181. end;
  8182. procedure TDefinePucker.SetTitleFont(AFont : TFont);
  8183. begin
  8184. FTitleFont.Assign(AFont);
  8185. ForceReDraw;
  8186. end;
  8187. procedure TDefinePucker.OnTitleFontChange(Sender : TObject);
  8188. begin
  8189. ForceReDraw;
  8190. end;
  8191. procedure TDefinePucker.SetTitleHeight(AHeight : Integer);
  8192. begin
  8193. if FTitleHeight <> AHeight then begin
  8194. FTitleHeight := AHeight;
  8195. ForceReDraw;
  8196. end;
  8197. end;
  8198. procedure TDefinePucker.SetBGImage(AImage : TBitmap);
  8199. begin
  8200. FBGImage.Assign(AImage);
  8201. ForceReDraw;
  8202. end;
  8203. procedure TDefinePucker.SetBGImageAlign(AImageAlign : TBGImageAlign);
  8204. begin
  8205. if FBGImageAlign <> AImageAlign then begin
  8206. FBGImageAlign := AImageAlign;
  8207. if(FBGImageAlign = iaTile) or(FBGImageAlign = iaStretch) then FGradientFill := False;
  8208. ForceReDraw;
  8209. end;
  8210. end;
  8211. procedure TDefinePucker.SetTitleImageAlign(AValue : TTitleImageAlign);
  8212. begin
  8213. if FTitleImageAlign <> AValue then begin
  8214. FTitleImageAlign := AValue;
  8215. ForceReDraw;
  8216. end;
  8217. end;
  8218. procedure TDefinePucker.SetPanelCorner(AValue : TPanelCorners);
  8219. begin
  8220. if FPanelCorner <> AValue then begin
  8221. FPanelCorner := AValue;
  8222. FullRepaint := true;
  8223. SetShape(FPanelCorner);
  8224. FullRepaint := False;
  8225. end;
  8226. end;
  8227. procedure TDefinePucker.SetMinimized(AValue : Boolean);
  8228. {/*****************************/*}
  8229. procedure Anime(NewSize : Integer);
  8230. var
  8231. I, Step, Iteration : Integer;
  8232. YStart, YEnd : Integer;
  8233. OldFRepaint : Boolean;
  8234. begin
  8235. //Animation
  8236. if FAnimation then
  8237. begin
  8238. Step := 0;
  8239. if Height > NewSize then
  8240. begin
  8241. YStart := newSize;
  8242. YEnd := Height;
  8243. end
  8244. else
  8245. begin
  8246. YStart := Height;
  8247. YEnd := newSize;
  8248. end;
  8249. Iteration :=(YEnd - YStart) div 10;
  8250. if Iteration = 0 then Iteration := 1;
  8251. OldFRepaint := FullRepaint;
  8252. FullRepaint := False;
  8253. For I := YStart to YEnd do
  8254. begin
  8255. if Step = Iteration then
  8256. begin
  8257. if Height < NewSize then Height := Height + Step
  8258. else Height := Height - Step;
  8259. Application.ProcessMessages;
  8260. Step := 0;
  8261. end;
  8262. Inc(Step);
  8263. end;
  8264. FullRepaint := OldFRepaint;
  8265. end;
  8266. end;
  8267. {/*****************************/*}
  8268. begin
  8269. if(FMinimized <> AValue) and(not FMinimizing ) then
  8270. begin
  8271. Maximized := False;
  8272. FMinimized := AValue;
  8273. if AValue then
  8274. begin
  8275. try
  8276. FMinimizing := True;
  8277. FHeight := Height;
  8278. if FAnimation then Anime(FTitleHeight + FBorderSize);
  8279. Height := FTitleHeight + FBorderSize;
  8280. finally
  8281. FMinimizing := False;
  8282. end;
  8283. end
  8284. else
  8285. begin
  8286. try
  8287. FMinimizing := true;
  8288. if Height = FHeight then FHeight := FDefaultHeight;
  8289. if FAnimation then Anime(FHeight);
  8290. Height := FHeight;
  8291. finally
  8292. FMinimizing := false;
  8293. end;
  8294. end;
  8295. Invalidate;
  8296. if Assigned(FAfterMinimized) then
  8297. FAfterMinimized(Self, FMinimized);
  8298. end;
  8299. end;
  8300. procedure TDefinePucker.SetMaximized(AValue : Boolean);
  8301. begin
  8302. if FMaximized <> AValue then
  8303. begin
  8304. FMaximized := AValue;
  8305. if FMaximized then
  8306. begin
  8307. FOldBounds := BoundsRect;
  8308. FOldAlign := Align;
  8309. Align := alClient;
  8310. end
  8311. else
  8312. begin
  8313. Align := FOldAlign;
  8314. BoundsRect := FOldBounds;
  8315. end;
  8316. Invalidate;
  8317. if Assigned(FAfterMaximized) then
  8318. FAfterMaximized(Self, FMaximized);
  8319. end;
  8320. end;
  8321. procedure TDefinePucker.SetTitleButtons(AValue : TTitleButtons);
  8322. begin
  8323. if FTitleButtons <> AValue then
  8324. begin
  8325. FTitleButtons := AValue;
  8326. if Parent <> nil then
  8327. begin
  8328. SendMessage(Handle, WM_NCPAINT, 0, 0);
  8329. SendMessage(Handle, WM_SIZE, 0, 0);
  8330. end;
  8331. end;
  8332. end;
  8333. procedure TDefinePucker.SetDefaultHeight(AValue : Integer);
  8334. begin
  8335. if AValue <> FDefaultHeight then
  8336. begin
  8337. FDefaultHeight := AValue;
  8338. if Minimized then FHeight := FDefaultHeight;
  8339. end;
  8340. end;
  8341. procedure TDefinePucker.CMIsToolControl(var Message: TMessage);
  8342. begin
  8343. Message.Result := 1;
  8344. end;
  8345. procedure TDefinePucker.CMTextChanged(var Message: TWmNoParams);
  8346. begin
  8347. inherited;
  8348. Invalidate;
  8349. end;
  8350. procedure TDefinePucker.CMEnabledChanged(var Message: TMessage);
  8351. begin
  8352. inherited;
  8353. Invalidate;
  8354. end;
  8355. procedure TDefinePucker.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  8356. var
  8357. Rect: TRect;
  8358. begin
  8359. if FullRepaint then
  8360. Invalidate
  8361. else
  8362. begin
  8363. Rect.Right := Width;
  8364. Rect.Bottom := Height;
  8365. if Message.WindowPos^.cx <> Rect.Right then
  8366. begin
  8367. Rect.Top := 0;
  8368. Rect.Left := Rect.Right - 2;
  8369. InvalidateRect(Handle, @Rect, True);
  8370. end;
  8371. if Message.WindowPos^.cy <> Rect.Bottom then
  8372. begin
  8373. Rect.Left := 0;
  8374. Rect.Top := Rect.Bottom - 2;
  8375. InvalidateRect(Handle, @Rect, True);
  8376. end;
  8377. end;
  8378. inherited;
  8379. end;
  8380. procedure TDefinePucker.SetTitleButtonsStyle(AValue: TTitleButtonsStyle);
  8381. begin
  8382. if FTitleButtonsStyle <> AValue then
  8383. begin
  8384. FTitleButtonsStyle := AValue;
  8385. Invalidate;
  8386. end;
  8387. end;
  8388. procedure TDefinePucker.SetTitleBtnBorderSize(AValue: Integer);
  8389. begin
  8390. if FTitleBtnBorderSize <> AValue then
  8391. begin
  8392. FTitleBtnBorderSize := AValue;
  8393. Invalidate;
  8394. end;
  8395. end;
  8396. procedure TDefinePucker.SetName(const Value: TComponentName);
  8397. begin
  8398. if (csDesigning in ComponentState)and((GetTextLen = 0)or
  8399. (CompareText(FCaption, Name) = 0)) then
  8400. FCaption := Value;
  8401. inherited SetName(Value);
  8402. end;
  8403. procedure TDefinePucker.SetColors(Index: Integer; Value: TColor);
  8404. begin
  8405. case Index of
  8406. 0 : FStartColor := Value;
  8407. 1 : FEndColor := Value;
  8408. 2 : FTitleStartColor := Value;
  8409. 3 : FTitleEndColor := Value;
  8410. 4 : FTitleColor := Value;
  8411. 5 : FTitleBtnBorderColor := Value;
  8412. 6 : FTitleBtnBGColor := Value;
  8413. 7 : FBorderColor := Value;
  8414. end;
  8415. Invalidate;
  8416. end;
  8417. procedure TDefinePucker.SetBools(Index: Integer; Value: Boolean);
  8418. begin
  8419. case Index of
  8420. 0:if FGradientFill <> Value then begin
  8421. FGradientFill := Value;
  8422. ForceReDraw;
  8423. end;
  8424. 1:if FFullRepaint <> Value then begin
  8425. FFullRepaint := Value;
  8426. ForceReDraw;
  8427. end;
  8428. 2:if FShowHeader <> Value then begin
  8429. FShowHeader := Value;
  8430. SendMessage(Handle, WM_SIZE, 0, 0);
  8431. end;
  8432. 3:SetMinimized(Value);
  8433. 4:SetMaximized(Value);
  8434. 5:if FTitleShadowOnMouseEnter <> Value then begin
  8435. FTitleShadowOnMouseEnter := Value;
  8436. end;
  8437. 6:if FTitleGradient <> Value then begin
  8438. FTitleGradient := Value;
  8439. ForceReDraw;
  8440. end;
  8441. 7:if FMovable <> Value then begin
  8442. FMovable := Value;
  8443. end;
  8444. 8:if FSizable <> Value then begin
  8445. FSizable := Value;
  8446. end;
  8447. 9:if FShowBorder <> Value then begin
  8448. FShowBorder := Value;
  8449. SetShape(FPanelCorner);
  8450. end;
  8451. 10:if FAnimation <> Value then begin
  8452. FAnimation := Value;
  8453. end;
  8454. 11:if FBGImageTransparent <> Value then begin
  8455. FBGImageTransparent := Value;
  8456. ForceReDraw;
  8457. end;
  8458. 12:if FTitleImageTransparent <> Value then begin
  8459. FTitleImageTransparent := Value;
  8460. ForceReDraw;
  8461. end;
  8462. end;
  8463. end;
  8464. { TDefineSpin }
  8465. constructor TDefineSpin.Create(AOwner: TComponent);
  8466. begin
  8467. inherited Create(AOwner);
  8468. ControlStyle := ControlStyle - [csAcceptsControls, csSetCaption] + [csFramed, csOpaque];
  8469. FUpButton := CreateButton;
  8470. FDownButton := CreateButton;
  8471. UpGlyph := nil;
  8472. DownGlyph := nil;
  8473. FFocusedButton := FUpButton;
  8474. SetBounds(0,0,20,10);
  8475. end;
  8476. function TDefineSpin.CreateButton: TDefineSpins;
  8477. begin
  8478. Result := TDefineSpins.Create(Self);
  8479. Result.FoisChange := false;
  8480. Result.OnClick := BtnClick;
  8481. Result.OnMouseDown := BtnMouseDown;
  8482. Result.Visible := True;
  8483. Result.Enabled := True;
  8484. Result.TimeBtnState := [tbAllowTimer];
  8485. Result.Parent := Self;
  8486. end;
  8487. procedure TDefineSpin.Notification (AComponent: TComponent; Operation: TOperation);
  8488. begin
  8489. inherited Notification(AComponent, Operation);
  8490. if (Operation = opRemove) and (AComponent = FFocusControl) then
  8491. FFocusControl := nil;
  8492. end;
  8493. procedure TDefineSpin.AdjustSize(var W, H: Integer);
  8494. begin
  8495. if (FUpButton = nil) or (csLoading in ComponentState) then Exit;
  8496. FUpButton.SetBounds(0, 0, 15, H);
  8497. FDownButton.SetBounds(16, 0, 15, H);
  8498. end;
  8499. procedure TDefineSpin.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  8500. var
  8501. W, H: Integer;
  8502. begin
  8503. W := AWidth;
  8504. H := AHeight;
  8505. AdjustSize (W, H);
  8506. inherited SetBounds(ALeft, ATop, W, H);
  8507. end;
  8508. procedure TDefineSpin.WMSize(var Message: TWMSize);
  8509. var
  8510. W, H: Integer;
  8511. begin
  8512. inherited;
  8513. // check for minimum size
  8514. W := Width;
  8515. H := Height;
  8516. AdjustSize (W, H);
  8517. if (W <> Width) or (H <> Height) then
  8518. inherited SetBounds(Left, Top, W, H);
  8519. Message.Result := 0;
  8520. end;
  8521. procedure TDefineSpin.WMSetFocus(var Message: TWMSetFocus);
  8522. begin
  8523. FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
  8524. FFocusedButton.Invalidate;
  8525. end;
  8526. procedure TDefineSpin.WMKillFocus(var Message: TWMKillFocus);
  8527. begin
  8528. FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
  8529. FFocusedButton.Invalidate;
  8530. end;
  8531. procedure TDefineSpin.KeyDown(var Key: Word; Shift: TShiftState);
  8532. begin
  8533. case Key of
  8534. VK_UP:
  8535. begin
  8536. SetFocusBtn(FUpButton);
  8537. FUpButton.Click;
  8538. end;
  8539. VK_DOWN:
  8540. begin
  8541. SetFocusBtn(FDownButton);
  8542. FDownButton.Click;
  8543. end;
  8544. VK_SPACE:
  8545. FFocusedButton.Click;
  8546. end;
  8547. end;
  8548. procedure TDefineSpin.BtnMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  8549. begin
  8550. if Button = mbLeft then
  8551. begin
  8552. SetFocusBtn (TDefineSpins(Sender));
  8553. if (FFocusControl <> nil) and FFocusControl.TabStop and
  8554. FFocusControl.CanFocus and (GetFocus <> FFocusControl.Handle) then
  8555. FFocusControl.SetFocus
  8556. else if TabStop and (GetFocus <> Handle) and CanFocus then
  8557. SetFocus;
  8558. end;
  8559. end;
  8560. procedure TDefineSpin.BtnClick(Sender: TObject);
  8561. begin
  8562. if Sender = FUpButton then
  8563. if Assigned(FOnUpClick) then
  8564. FOnUpClick(Self);
  8565. if Sender = FDownButton then
  8566. if Assigned(FOnDownClick) then
  8567. FOnDownClick(Self);
  8568. end;
  8569. procedure TDefineSpin.SetFocusBtn (Btn: TDefineSpins);
  8570. begin
  8571. if TabStop and CanFocus and (Btn <> FFocusedButton) then
  8572. begin
  8573. FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState - [tbFocusRect];
  8574. FFocusedButton := Btn;
  8575. if (GetFocus = Handle) then
  8576. begin
  8577. FFocusedButton.TimeBtnState := FFocusedButton.TimeBtnState + [tbFocusRect];
  8578. Invalidate;
  8579. end;
  8580. end;
  8581. end;
  8582. procedure TDefineSpin.WMGetDlgCode(var Message: TWMGetDlgCode);
  8583. begin
  8584. Message.Result := DLGC_WANTARROWS;
  8585. end;
  8586. procedure TDefineSpin.Loaded;
  8587. var
  8588. W, H: Integer;
  8589. begin
  8590. inherited Loaded;
  8591. W := Width;
  8592. H := Height;
  8593. AdjustSize (W, H);
  8594. if (W <> Width) or (H <> Height) then
  8595. inherited SetBounds(Left, Top, Width, Height);
  8596. end;
  8597. function TDefineSpin.GetUpGlyph: TBitmap;
  8598. begin
  8599. Result := FUpButton.Glyph;
  8600. end;
  8601. procedure TDefineSpin.SetUpGlyph(Value: TBitmap);
  8602. begin
  8603. if Value <> nil then
  8604. FUpButton.Glyph := Value
  8605. else
  8606. begin
  8607. FUpButton.Glyph.Handle := LoadBitmap(HInstance, 'Flat_Up');
  8608. FUpButton.NumGlyphs := 1;
  8609. FUpButton.Margin := 2;
  8610. FUpButton.Invalidate;
  8611. FUpButton.Layout := blGlyphTop;
  8612. end;
  8613. end;
  8614. function TDefineSpin.GetUpNumGlyphs: TNumGlyphs;
  8615. begin
  8616. Result := FUpButton.NumGlyphs;
  8617. end;
  8618. procedure TDefineSpin.SetUpNumGlyphs(Value: TNumGlyphs);
  8619. begin
  8620. FUpButton.NumGlyphs := Value;
  8621. end;
  8622. function TDefineSpin.GetDownGlyph: TBitmap;
  8623. begin
  8624. Result := FDownButton.Glyph;
  8625. end;
  8626. procedure TDefineSpin.SetDownGlyph(Value: TBitmap);
  8627. begin
  8628. if Value <> nil then
  8629. FDownButton.Glyph := Value
  8630. else
  8631. begin
  8632. FDownButton.Glyph.Handle := LoadBitmap(HInstance, 'Flat_Down');
  8633. FDownButton.NumGlyphs := 1;
  8634. FDownButton.Margin := 2;
  8635. FDownButton.Invalidate;
  8636. FDownButton.Layout := blGlyphBottom;
  8637. end;
  8638. end;
  8639. function TDefineSpin.GetDownNumGlyphs: TNumGlyphs;
  8640. begin
  8641. Result := FDownButton.NumGlyphs;
  8642. end;
  8643. procedure TDefineSpin.SetDownNumGlyphs(Value: TNumGlyphs);
  8644. begin
  8645. FDownButton.NumGlyphs := Value;
  8646. end;
  8647. { TDefineSpins }
  8648. constructor TDefineSpins.Create(AOwner: TComponent);
  8649. begin
  8650. inherited Create(AOwner);
  8651. Cursor := crHandPoint;
  8652. end;
  8653. destructor TDefineSpins.Destroy;
  8654. begin
  8655. if FRepeatTimer <> nil then
  8656. FRepeatTimer.Free;
  8657. inherited Destroy;
  8658. end;
  8659. procedure TDefineSpins.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  8660. begin
  8661. inherited MouseDown(Button, Shift, X, Y);
  8662. if tbAllowTimer in FTimeBtnState then
  8663. begin
  8664. if FRepeatTimer = nil then
  8665. FRepeatTimer := TTimer.Create(Self);
  8666. FRepeatTimer.OnTimer := TimerExpired;
  8667. FRepeatTimer.Interval := DefaultInitRepeatPause;
  8668. FRepeatTimer.Enabled := True;
  8669. end;
  8670. end;
  8671. procedure TDefineSpins.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  8672. begin
  8673. inherited MouseUp(Button, Shift, X, Y);
  8674. if FRepeatTimer <> nil then
  8675. FRepeatTimer.Enabled := False;
  8676. end;
  8677. procedure TDefineSpins.TimerExpired(Sender: TObject);
  8678. begin
  8679. FRepeatTimer.Interval := DefaultRepeatPause;
  8680. if (FState = bsDown) and MouseCapture then
  8681. begin
  8682. try
  8683. Click;
  8684. except
  8685. FRepeatTimer.Enabled := False;
  8686. raise;
  8687. end;
  8688. end;
  8689. end;
  8690. { TDefineSpeed }
  8691. constructor TDefineSpeed.Create(AOwner: TComponent);
  8692. begin
  8693. FGlyph := TBitmap.Create;
  8694. inherited Create(AOwner);
  8695. ControlStyle := [csCaptureMouse, csDoubleClicks];
  8696. ParentFont := True;
  8697. ParentColor := True;
  8698. fColorFocused := DefaultFocusedColor;
  8699. fColorDown := DefaultDownColor;
  8700. FColorBorder := DefaultBorderColor;
  8701. FColorShadow := DefaultShadowColor;
  8702. FState := bsUp;
  8703. fColorFlat := DefaultFlatColor;
  8704. FAutoColor := DefaultFoisColor;
  8705. FTransBorder := false;
  8706. FFoisChange := True;
  8707. FAutoStyle := [fsBold];
  8708. FSpacing := 4;
  8709. FMargin := -1;
  8710. FNumGlyphs := 1;
  8711. FLayout := blGlyphTop;
  8712. FModalResult := mrNone;
  8713. FTransparent := tmNone;
  8714. SetBounds(0, 0, 25, 25);
  8715. end;
  8716. destructor TDefineSpeed.Destroy;
  8717. begin
  8718. FGlyph.Free;
  8719. inherited Destroy;
  8720. end;
  8721. procedure TDefineSpeed.Paint;
  8722. var
  8723. FTransColor: TColor;
  8724. FImageList: TImageList;
  8725. sourceRect, destRect: TRect;
  8726. tempGlyph: TBitmap;
  8727. Offset: TPoint;
  8728. begin
  8729. // get the transparent color
  8730. FTransColor := FGlyph.Canvas.Pixels[0, FGlyph.Height - 1];
  8731. Canvas.Font := Self.Font;
  8732. if FState in [bsDown, bsExclusive] then
  8733. Offset := Point(1, 1)
  8734. else
  8735. Offset := Point(0, 0);
  8736. if MouseIn and FFoisChange then begin
  8737. canvas.Font.Color := FAutoColor;
  8738. canvas.Font.Style := FAutoStyle;
  8739. end;
  8740. CalcButtonLayout(Canvas, ClientRect, Offset, FLayout, FSpacing,
  8741. FMargin, FGlyph, FNumGlyphs, Caption, TextBounds, GlyphPos);
  8742. if not Enabled then
  8743. begin
  8744. FState := bsDisabled;
  8745. FDragging := False;
  8746. end
  8747. else
  8748. if FState = bsDisabled then
  8749. if FDown and (GroupIndex <> 0) then
  8750. FState := bsExclusive
  8751. else
  8752. FState := bsUp;
  8753. // DrawBackground
  8754. case FTransparent of
  8755. tmAlways:;
  8756. tmNone:
  8757. begin
  8758. case FState of
  8759. bsUp:
  8760. if MouseIn then
  8761. Canvas.Brush.Color := fColorFocused
  8762. else
  8763. Canvas.Brush.Color := fColorFlat;
  8764. bsDown:
  8765. Canvas.Brush.Color := fColorDown;
  8766. bsExclusive:
  8767. if MouseIn then
  8768. Canvas.Brush.Color := fColorFocused
  8769. else
  8770. Canvas.Brush.Color := fColorDown;
  8771. bsDisabled:
  8772. Canvas.Brush.Color := fColorFlat;
  8773. end;
  8774. Canvas.FillRect(ClientRect);
  8775. end;
  8776. tmNotFocused:
  8777. if MouseIn then
  8778. begin
  8779. case FState of
  8780. bsUp:
  8781. if MouseIn then
  8782. Canvas.Brush.Color := fColorFocused
  8783. else
  8784. Canvas.Brush.Color := Self.Color;
  8785. bsDown:
  8786. Canvas.Brush.Color := fColorDown;
  8787. bsExclusive:
  8788. if MouseIn then
  8789. Canvas.Brush.Color := fColorFocused
  8790. else
  8791. Canvas.Brush.Color := fColorDown;
  8792. bsDisabled:
  8793. Canvas.Brush.Color := Self.Color;
  8794. end;
  8795. Canvas.FillRect(ClientRect);
  8796. end;
  8797. end;
  8798. if not FTransBorder then begin // DrawBorder
  8799. case FState of
  8800. bsUp: if MouseIn then
  8801. DrawButtonBorder(canvas, ClientRect, FColorShadow, 1)
  8802. else
  8803. DrawButtonBorder(canvas, ClientRect, FColorBorder, 1);
  8804. bsDown, bsExclusive:
  8805. DrawButtonBorder(canvas, ClientRect, FColorShadow, 1);
  8806. bsDisabled:
  8807. DrawButtonBorder(canvas, ClientRect, FColorBorder, 1);
  8808. end;
  8809. end;
  8810. // DrawGlyph
  8811. if not FGlyph.Empty then
  8812. begin
  8813. tempGlyph := TBitmap.Create;
  8814. case FNumGlyphs of
  8815. 1: case FState of
  8816. bsUp: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  8817. bsDisabled: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  8818. bsDown: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  8819. bsExclusive: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  8820. end;
  8821. 2: case FState of
  8822. bsUp: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8823. bsDisabled: sourceRect := Rect(FGlyph.Width div FNumGlyphs, 0, FGlyph.Width, FGlyph.Height);
  8824. bsDown: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8825. bsExclusive: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8826. end;
  8827. 3: case FState of
  8828. bsUp: SourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8829. bsDisabled: SourceRect := Rect(FGlyph.width div FNumGlyphs, 0, (FGlyph.Width div FNumGlyphs) * 2, FGlyph.Height);
  8830. bsDown: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, FGlyph.Width, FGlyph.Height);
  8831. bsExclusive: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, FGlyph.Width, FGlyph.Height);
  8832. end;
  8833. 4: case FState of
  8834. bsUp: SourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8835. bsDisabled: SourceRect := Rect(FGlyph.width div FNumGlyphs, 0, (FGlyph.Width div FNumGlyphs) * 2, FGlyph.Height);
  8836. bsDown: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, (FGlyph.Width div FNumGlyphs) * 3, FGlyph.Height);
  8837. bsExclusive: SourceRect := Rect((FGlyph.width div FNumGlyphs) * 3, 0, FGlyph.Width, FGlyph.Height);
  8838. end;
  8839. end;
  8840. destRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8841. tempGlyph.Width := FGlyph.Width div FNumGlyphs;
  8842. tempGlyph.Height := FGlyph.Height;
  8843. tempGlyph.canvas.copyRect(destRect, FGlyph.canvas, sourcerect);
  8844. if (FNumGlyphs = 1) and (FState = bsDisabled) then
  8845. begin
  8846. tempGlyph := CreateDisabledBitmap(tempGlyph, clBlack, clBtnFace, clBtnHighlight, clBtnShadow, True);
  8847. FTransColor := tempGlyph.Canvas.Pixels[0, tempGlyph.Height - 1];
  8848. end;
  8849. FImageList := TImageList.CreateSize(FGlyph.Width div FNumGlyphs, FGlyph.Height);
  8850. try
  8851. FImageList.AddMasked(tempGlyph, FTransColor);
  8852. if MouseIn and FFoisChange then
  8853. FImageList.Draw(canvas, pred(glyphpos.x), pred(glyphpos.y), 0)
  8854. else
  8855. FImageList.Draw(canvas, glyphpos.x, glyphpos.y, 0);
  8856. //FImageList.Draw(canvas, glyphpos.x, glyphpos.y, 0);
  8857. finally
  8858. FImageList.Free;
  8859. end;
  8860. tempGlyph.free;
  8861. end;
  8862. // DrawText
  8863. Canvas.Brush.Style := bsClear;
  8864. if FState = bsDisabled then
  8865. begin
  8866. OffsetRect(TextBounds, 1, 1);
  8867. Canvas.Font.Color := clBtnHighlight;
  8868. DrawText(Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  8869. OffsetRect(TextBounds, -1, -1);
  8870. Canvas.Font.Color := clBtnShadow;
  8871. DrawText(Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  8872. end
  8873. else
  8874. DrawText(Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  8875. end;
  8876. procedure TDefineSpeed.UpdateTracking;
  8877. var
  8878. P: TPoint;
  8879. begin
  8880. if Enabled then
  8881. begin
  8882. GetCursorPos(P);
  8883. FMouseIn := not (FindDragTarget(P, True) = Self);
  8884. if FMouseIn then
  8885. MouseLeave
  8886. else
  8887. MouseEnter;
  8888. end;
  8889. end;
  8890. procedure TDefineSpeed.Loaded;
  8891. begin
  8892. inherited Loaded;
  8893. Invalidate;
  8894. end;
  8895. procedure TDefineSpeed.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  8896. begin
  8897. inherited MouseDown(Button, Shift, X, Y);
  8898. if(Button = mbLeft) and Enabled then
  8899. begin
  8900. if not FDown then
  8901. begin
  8902. FState := bsDown;
  8903. Invalidate;
  8904. end;
  8905. FDragging := True;
  8906. end;
  8907. end;
  8908. procedure TDefineSpeed.MouseMove (Shift: TShiftState; X, Y: Integer);
  8909. var
  8910. NewState: TButtonState;
  8911. begin
  8912. inherited;
  8913. if FDragging then
  8914. begin
  8915. if not FDown then
  8916. NewState := bsUp
  8917. else
  8918. NewState := bsExclusive;
  8919. if (X >= 0) and (X < ClientWidth) and (Y >= 0) and (Y <= ClientHeight) then
  8920. if FDown then
  8921. NewState := bsExclusive
  8922. else
  8923. NewState := bsDown;
  8924. if NewState <> FState then
  8925. begin
  8926. FState := NewState;
  8927. Invalidate;
  8928. end;
  8929. end;
  8930. end;
  8931. procedure TDefineSpeed.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  8932. var
  8933. DoClick: Boolean;
  8934. begin
  8935. inherited MouseUp(Button, Shift, X, Y);
  8936. if FDragging then
  8937. begin
  8938. FDragging := False;
  8939. DoClick := (X >= 0) and (X < ClientWidth) and (Y >= 0) and (Y <= ClientHeight);
  8940. if FGroupIndex = 0 then
  8941. begin
  8942. // Redraw face in-case mouse is captured
  8943. FState := bsUp;
  8944. FMouseIn := False;
  8945. if DoClick and not (FState in [bsExclusive, bsDown]) then
  8946. Invalidate;
  8947. end
  8948. else
  8949. if DoClick then
  8950. begin
  8951. SetDown(not FDown);
  8952. if FDown then Repaint;
  8953. end
  8954. else
  8955. begin
  8956. if FDown then FState := bsExclusive;
  8957. Repaint;
  8958. end;
  8959. if DoClick then Click else MouseLeave;
  8960. UpdateTracking;
  8961. end;
  8962. end;
  8963. procedure TDefineSpeed.Click;
  8964. begin
  8965. if Parent <> nil then
  8966. GetParentForm(self).ModalResult := FModalResult;
  8967. if Assigned(PopupMenu) then
  8968. PopupMenu.PopUp(ClientToScreen(Point(0, Height)).X,
  8969. ClientToScreen(Point(0, Height)).Y);
  8970. inherited Click;
  8971. end;
  8972. function TDefineSpeed.GetPalette: HPALETTE;
  8973. begin
  8974. Result := FGlyph.Palette;
  8975. end;
  8976. procedure TDefineSpeed.SetColors(Index: Integer; Value: TColor);
  8977. begin
  8978. case Index of
  8979. 0: fColorFocused := Value;
  8980. 1: fColorDown := Value;
  8981. 2: FColorBorder := Value;
  8982. 3: FColorShadow := Value;
  8983. 4: FColorFlat := Value;
  8984. 5: FAutoColor := Value;
  8985. end;
  8986. Invalidate;
  8987. end;
  8988. procedure TDefineSpeed.SetGlyph(Value: TBitmap);
  8989. begin
  8990. if value <> FGlyph then
  8991. begin
  8992. FGlyph.Assign(value);
  8993. if not FGlyph.Empty then
  8994. begin
  8995. if FGlyph.Width mod FGlyph.Height = 0 then
  8996. begin
  8997. FNumGlyphs := FGlyph.Width div FGlyph.Height;
  8998. if FNumGlyphs > 4 then FNumGlyphs := 1;
  8999. end;
  9000. end;
  9001. Invalidate;
  9002. end;
  9003. end;
  9004. procedure TDefineSpeed.SetNumGlyphs(Value: TNumGlyphs);
  9005. begin
  9006. if value <> FNumGlyphs then
  9007. begin
  9008. FNumGlyphs := value;
  9009. Invalidate;
  9010. end;
  9011. end;
  9012. procedure TDefineSpeed.UpdateExclusive;
  9013. var
  9014. Msg: TMessage;
  9015. begin
  9016. if (FGroupIndex <> 0) and (Parent <> nil) then
  9017. begin
  9018. Msg.Msg := CM_BUTTONPRESSED;
  9019. Msg.WParam := FGroupIndex;
  9020. Msg.LParam := Longint(Self);
  9021. Msg.Result := 0;
  9022. Parent.Broadcast(Msg);
  9023. end;
  9024. end;
  9025. procedure TDefineSpeed.SetDown(Value: Boolean);
  9026. begin
  9027. if FGroupIndex = 0 then Value := False;
  9028. if Value <> FDown then
  9029. begin
  9030. if FDown and (not FAllowAllUp) then Exit;
  9031. FDown := Value;
  9032. if Value then
  9033. begin
  9034. if FState = bsUp then Invalidate;
  9035. FState := bsExclusive
  9036. end
  9037. else
  9038. begin
  9039. FState := bsUp;
  9040. Repaint;
  9041. end;
  9042. if Value then UpdateExclusive;
  9043. end;
  9044. end;
  9045. procedure TDefineSpeed.SetGroupIndex(Value: Integer);
  9046. begin
  9047. if FGroupIndex <> Value then
  9048. begin
  9049. FGroupIndex := Value;
  9050. UpdateExclusive;
  9051. end;
  9052. end;
  9053. procedure TDefineSpeed.SetLayout(Value: TButtonLayout);
  9054. begin
  9055. if FLayout <> Value then
  9056. begin
  9057. FLayout := Value;
  9058. Invalidate;
  9059. end;
  9060. end;
  9061. procedure TDefineSpeed.SetMargin(Value: Integer);
  9062. begin
  9063. if(Value <> FMargin) and(Value >= -1) then
  9064. begin
  9065. FMargin := Value;
  9066. Invalidate;
  9067. end;
  9068. end;
  9069. procedure TDefineSpeed.SetSpacing(Value: Integer);
  9070. begin
  9071. if Value <> FSpacing then
  9072. begin
  9073. FSpacing := Value;
  9074. Invalidate;
  9075. end;
  9076. end;
  9077. procedure TDefineSpeed.SetAllowAllUp(Value: Boolean);
  9078. begin
  9079. if FAllowAllUp <> Value then
  9080. begin
  9081. FAllowAllUp := Value;
  9082. UpdateExclusive;
  9083. end;
  9084. end;
  9085. procedure TDefineSpeed.WMLButtonDblClk(var Message: TWMLButtonDown);
  9086. begin
  9087. inherited;
  9088. if FDown then DblClick;
  9089. end;
  9090. procedure TDefineSpeed.CMEnabledChanged(var Message: TMessage);
  9091. begin
  9092. inherited;
  9093. if not Enabled then
  9094. begin
  9095. FMouseIn := False;
  9096. FState := bsDisabled;
  9097. //RemoveMouseTimer;
  9098. end;
  9099. UpdateTracking;
  9100. Invalidate;
  9101. end;
  9102. procedure TDefineSpeed.CMButtonPressed(var Message: TMessage);
  9103. var
  9104. Sender: TDefineSpeed;
  9105. begin
  9106. if Message.WParam = FGroupIndex then
  9107. begin
  9108. Sender := TDefineSpeed(Message.LParam);
  9109. if Sender <> Self then
  9110. begin
  9111. if Sender.Down and FDown then
  9112. begin
  9113. FDown := False;
  9114. FState := bsUp;
  9115. Invalidate;
  9116. end;
  9117. FAllowAllUp := Sender.AllowAllUp;
  9118. end;
  9119. end;
  9120. end;
  9121. procedure TDefineSpeed.CMDialogChar(var Message: TCMDialogChar);
  9122. begin
  9123. with Message do
  9124. if IsAccel(CharCode, Caption) and Enabled then
  9125. begin
  9126. Click;
  9127. Result := 1;
  9128. end else
  9129. inherited;
  9130. end;
  9131. procedure TDefineSpeed.CMFontChanged(var Message: TMessage);
  9132. begin
  9133. Invalidate;
  9134. end;
  9135. procedure TDefineSpeed.CMTextChanged(var Message: TMessage);
  9136. begin
  9137. Invalidate;
  9138. end;
  9139. procedure TDefineSpeed.CMSysColorChange(var Message: TMessage);
  9140. begin
  9141. inherited;
  9142. if (Parent <> nil)and(ParentColor) then
  9143. Color := TDefineSpeed(Parent).Color;
  9144. Invalidate;
  9145. end;
  9146. procedure TDefineSpeed.CMParentColorChanged(var Message: TWMNoParams);
  9147. begin
  9148. inherited;
  9149. if (Parent <> nil)and(not ParentColor) then
  9150. Color := TDefineSpeed(Parent).Color;
  9151. Invalidate;
  9152. end;
  9153. procedure TDefineSpeed.MouseEnter;
  9154. begin
  9155. if Enabled and not MouseIn then
  9156. begin
  9157. FMouseIn := True;
  9158. Invalidate;
  9159. end;
  9160. end;
  9161. procedure TDefineSpeed.MouseLeave;
  9162. begin
  9163. if Enabled and MouseIn and not FDragging then
  9164. begin
  9165. FMouseIn := False;
  9166. Invalidate;
  9167. end;
  9168. end;
  9169. {$IFDEF DFS_DELPHI_4_UP}
  9170. procedure TDefineSpeed.ActionChange(Sender: TObject; CheckDefaults: Boolean);
  9171. procedure CopyImage(ImageList: TCustomImageList; Index: Integer);
  9172. begin
  9173. with Glyph do
  9174. begin
  9175. Width := ImageList.Width;
  9176. Height := ImageList.Height;
  9177. Canvas.Brush.Color := clFuchsia;//! for lack of a better color
  9178. Canvas.FillRect(Rect(0,0, Width, Height));
  9179. ImageList.Draw(Canvas, 0, 0, Index);
  9180. end;
  9181. end;
  9182. begin
  9183. inherited ActionChange(Sender, CheckDefaults);
  9184. if Sender is TCustomAction then
  9185. with TCustomAction(Sender) do
  9186. begin
  9187. { Copy image from action's imagelist }
  9188. if (Glyph.Empty) and (ActionList <> nil) and (ActionList.Images <> nil) and
  9189. (ImageIndex >= 0) and (ImageIndex < ActionList.Images.Count) then
  9190. CopyImage(ActionList.Images, ImageIndex);
  9191. end;
  9192. end;
  9193. {$ENDIF}
  9194. procedure TDefineSpeed.SetTransparent(const Value: TTransparentMode);
  9195. begin
  9196. if FTransparent <> Value then
  9197. begin
  9198. FTransparent := Value;
  9199. Invalidate;
  9200. end;
  9201. end;
  9202. procedure TDefineSpeed.CMMouseEnter(var Message: TMessage);
  9203. begin
  9204. inherited;
  9205. if Assigned(FOnMouseEnter) then
  9206. FOnMouseEnter(Self)
  9207. else if not(csDesigning in ComponentState) then
  9208. MouseEnter;
  9209. end;
  9210. procedure TDefineSpeed.CMMouseLeave(var Message: TMessage);
  9211. begin
  9212. inherited;
  9213. if Assigned(FOnMouseLeave) then
  9214. FOnMouseLeave(Self)
  9215. else if not(csDesigning in ComponentState) then
  9216. MouseLeave;
  9217. end;
  9218. procedure TDefineSpeed.SetFoisChange(const Value: Boolean);
  9219. begin
  9220. if FFoisChange <> Value then begin
  9221. FFoisChange := Value;
  9222. Invalidate;
  9223. end;
  9224. end;
  9225. procedure TDefineSpeed.SetAutoStyle(const Value: TFontStyles);
  9226. begin
  9227. if FAutoStyle <> Value then begin
  9228. FAutoStyle := Value;
  9229. Invalidate;
  9230. end;
  9231. end;
  9232. procedure TDefineSpeed.SetTransBorder(const Value: Boolean);
  9233. begin
  9234. if FTransBorder <> Value then begin
  9235. FTransBorder := Value;
  9236. Invalidate;
  9237. end;
  9238. end;
  9239. function TDefineSpeed.GetMouseIn: Boolean;
  9240. begin
  9241. Result := FMouseIn;
  9242. end;
  9243. { TDefineButton }
  9244. constructor TDefineButton.Create(AOwner: TComponent);
  9245. begin
  9246. FGlyph := TBitmap.Create;
  9247. inherited Create(AOwner);
  9248. ControlStyle := [csCaptureMouse, csOpaque, csDoubleClicks];
  9249. TabStop := true;
  9250. ParentFont := True;
  9251. ParentColor := True;
  9252. fColorFocused := DefaultFocusedColor;
  9253. fColorDown := DefaultDownColor;
  9254. FColorBorder := DefaultBorderColor;
  9255. FColorShadow := DefaultShadowColor;
  9256. FState := bsUp;
  9257. fColorFlat := DefaultFlatColor;
  9258. FAutoColor := DefaultFoisColor;
  9259. FTransBorder := false;
  9260. FFoisChange := True;
  9261. FAutoStyle := [fsBold];
  9262. FSpacing := 4;
  9263. FMargin := -1;
  9264. FNumGlyphs := 1;
  9265. FLayout := blGlyphTop;
  9266. FModalResult := mrNone;
  9267. FTransparent := tmNone;
  9268. fHasFocusFrame:= true;
  9269. SetBounds(0, 0, 100, 25);
  9270. end;
  9271. destructor TDefineButton.Destroy;
  9272. begin
  9273. FGlyph.Free;
  9274. inherited Destroy;
  9275. end;
  9276. procedure TDefineButton.Paint;
  9277. var
  9278. FTransColor: TColor;
  9279. FImageList: TImageList;
  9280. sourceRect, destRect, FocusRect: TRect;
  9281. tempGlyph, memBitmap: TBitmap;
  9282. Offset: TPoint;
  9283. begin
  9284. // get the transparent color
  9285. FTransColor := FGlyph.Canvas.Pixels[0, FGlyph.Height - 1];
  9286. memBitmap := TBitmap.Create; // create memory-bitmap to draw flicker-free
  9287. try
  9288. memBitmap.Height := ClientRect.Bottom;
  9289. memBitmap.Width := ClientRect.Right;
  9290. memBitmap.Canvas.Font := Self.Font;
  9291. if FState in [bsDown, bsExclusive] then
  9292. Offset := Point(1, 1)
  9293. else
  9294. Offset := Point(0, 0);
  9295. if MouseIn and FFoisChange then begin
  9296. memBitmap.canvas.Font.Color := FAutoColor;
  9297. memBitmap.canvas.Font.Style := FAutoStyle;
  9298. end;
  9299. CalcButtonLayout(memBitmap.Canvas, ClientRect, Offset, FLayout, FSpacing,
  9300. FMargin, FGlyph, FNumGlyphs, Caption, TextBounds, GlyphPos);
  9301. if not Enabled then
  9302. begin
  9303. FState := bsDisabled;
  9304. FDragging := False;
  9305. end
  9306. else
  9307. begin
  9308. if FState = bsDisabled then
  9309. begin
  9310. if FDown and (GroupIndex <> 0) then
  9311. FState := bsExclusive
  9312. else
  9313. FState := bsUp;
  9314. end;
  9315. end;
  9316. // DrawBackground
  9317. case FTransparent of
  9318. tmAlways:
  9319. DrawParentImage(Self, memBitmap.Canvas);
  9320. tmNone:
  9321. begin
  9322. case FState of
  9323. bsUp:
  9324. if MouseIn then
  9325. memBitmap.Canvas.Brush.Color := fColorFocused
  9326. else
  9327. memBitmap.Canvas.Brush.Color := fColorFlat;
  9328. bsDown:
  9329. memBitmap.Canvas.Brush.Color := fColorDown;
  9330. bsExclusive:
  9331. if MouseIn then
  9332. memBitmap.Canvas.Brush.Color := fColorFocused
  9333. else
  9334. memBitmap.Canvas.Brush.Color := fColorDown;
  9335. bsDisabled:
  9336. memBitmap.Canvas.Brush.Color := fColorFlat;
  9337. end;
  9338. memBitmap.Canvas.FillRect(ClientRect);
  9339. //memBitmap.Canvas.Polygon();
  9340. end;
  9341. tmNotFocused:
  9342. if MouseIn then
  9343. begin
  9344. case FState of
  9345. bsUp:
  9346. if MouseIn then
  9347. memBitmap.Canvas.Brush.Color := fColorFocused
  9348. else
  9349. memBitmap.Canvas.Brush.Color := fColorFlat;
  9350. bsDown:
  9351. memBitmap.Canvas.Brush.Color := fColorDown;
  9352. bsExclusive:
  9353. if MouseIn then
  9354. memBitmap.Canvas.Brush.Color := fColorFocused
  9355. else
  9356. memBitmap.Canvas.Brush.Color := fColorDown;
  9357. bsDisabled:
  9358. memBitmap.Canvas.Brush.Color := fColorFlat;
  9359. end;
  9360. memBitmap.Canvas.FillRect(ClientRect);
  9361. end
  9362. else
  9363. DrawParentImage(Self, memBitmap.Canvas);
  9364. end;
  9365. if not FTransBorder then begin // DrawBorder
  9366. case FState of
  9367. bsUp: if MouseIn then
  9368. DrawButtonBorder(memBitmap.canvas, ClientRect, FColorShadow, 1)
  9369. else if FDefault then
  9370. DrawButtonBorder(memBitmap.canvas, ClientRect, FColorBorder, 2)
  9371. else
  9372. DrawButtonBorder(memBitmap.canvas, ClientRect, FColorBorder, 1);
  9373. bsDown, bsExclusive:
  9374. DrawButtonBorder(memBitmap.canvas, ClientRect, FColorShadow, 1);
  9375. bsDisabled:
  9376. DrawButtonBorder(memBitmap.canvas, ClientRect, FColorBorder, 1);
  9377. end;
  9378. end;
  9379. if (MouseIn)and(fHasFocusFrame)and(Enabled) then begin
  9380. with ClientRect do begin
  9381. FocusRect := Rect(Left+2,Top+2,Right-2,Bottom-2);
  9382. end;
  9383. if not FTransBorder then
  9384. memBitmap.Canvas.DrawFocusRect(FocusRect);
  9385. end;
  9386. // DrawGlyph
  9387. if not FGlyph.Empty then
  9388. begin
  9389. tempGlyph := TBitmap.Create;
  9390. case FNumGlyphs of
  9391. 1: case FState of
  9392. bsUp: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  9393. bsDisabled: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  9394. bsDown: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  9395. bsExclusive: sourceRect := Rect(0, 0, FGlyph.Width, FGlyph.Height);
  9396. end;
  9397. 2: case FState of
  9398. bsUp: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9399. bsDisabled: sourceRect := Rect(FGlyph.Width div FNumGlyphs, 0, FGlyph.Width, FGlyph.Height);
  9400. bsDown: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9401. bsExclusive: sourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9402. end;
  9403. 3: case FState of
  9404. bsUp: SourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9405. bsDisabled: SourceRect := Rect(FGlyph.width div FNumGlyphs, 0, (FGlyph.Width div FNumGlyphs) * 2, FGlyph.Height);
  9406. bsDown: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, FGlyph.Width, FGlyph.Height);
  9407. bsExclusive: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, FGlyph.Width, FGlyph.Height);
  9408. end;
  9409. 4: case FState of
  9410. bsUp: SourceRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9411. bsDisabled: SourceRect := Rect(FGlyph.width div FNumGlyphs, 0, (FGlyph.Width div FNumGlyphs) * 2, FGlyph.Height);
  9412. bsDown: SourceRect := Rect((FGlyph.Width div FNumGlyphs) * 2, 0, (FGlyph.Width div FNumGlyphs) * 3, FGlyph.Height);
  9413. bsExclusive: SourceRect := Rect((FGlyph.width div FNumGlyphs) * 3, 0, FGlyph.Width, FGlyph.Height);
  9414. end;
  9415. end;
  9416. destRect := Rect(0, 0, FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9417. tempGlyph.Width := FGlyph.Width div FNumGlyphs;
  9418. tempGlyph.Height := FGlyph.Height;
  9419. tempGlyph.canvas.copyRect(destRect, FGlyph.canvas, sourcerect);
  9420. if (FNumGlyphs = 1) and (FState = bsDisabled) then
  9421. begin
  9422. tempGlyph := CreateDisabledBitmap(tempGlyph, clBlack, clBtnFace, clBtnHighlight, clBtnShadow, True);
  9423. FTransColor := tempGlyph.Canvas.Pixels[0, tempGlyph.Height - 1];
  9424. end;
  9425. FImageList := TImageList.CreateSize(FGlyph.Width div FNumGlyphs, FGlyph.Height);
  9426. try
  9427. FImageList.AddMasked(tempGlyph, FTransColor);
  9428. if MouseIn and FFoisChange then
  9429. FImageList.Draw(memBitmap.canvas, pred(glyphpos.x), pred(glyphpos.y), 0)
  9430. else
  9431. FImageList.Draw(memBitmap.canvas, glyphpos.x, glyphpos.y, 0);
  9432. finally
  9433. FImageList.Free;
  9434. end;
  9435. tempGlyph.free;
  9436. end;
  9437. // DrawText
  9438. memBitmap.Canvas.Brush.Style := bsClear;
  9439. if FState = bsDisabled then
  9440. begin
  9441. OffsetRect(TextBounds, 1, 1);
  9442. memBitmap.Canvas.Font.Color := clBtnHighlight;
  9443. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  9444. OffsetRect(TextBounds, -1, -1);
  9445. memBitmap.Canvas.Font.Color := clBtnShadow;
  9446. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  9447. end
  9448. else
  9449. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  9450. // Copy memBitmap to screen
  9451. canvas.CopyRect(ClientRect, memBitmap.canvas, ClientRect);
  9452. finally
  9453. memBitmap.free; // delete the bitmap
  9454. end;
  9455. end;
  9456. procedure TDefineButton.UpdateTracking;
  9457. var
  9458. P: TPoint;
  9459. begin
  9460. if Enabled then
  9461. begin
  9462. GetCursorPos(P);
  9463. FMouseIn := not (FindDragTarget(P, True) = Self);
  9464. if FMouseIn then
  9465. MouseLeave
  9466. else
  9467. MouseEnter;
  9468. end;
  9469. end;
  9470. procedure TDefineButton.Loaded;
  9471. begin
  9472. inherited Loaded;
  9473. Invalidate;
  9474. end;
  9475. procedure TDefineButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  9476. begin
  9477. inherited MouseDown(Button, Shift, X, Y);
  9478. if(Button = mbLeft) and Enabled then
  9479. begin
  9480. if not FDown then
  9481. begin
  9482. FState := bsDown;
  9483. Invalidate;
  9484. end;
  9485. FDragging := True;
  9486. SetFocus;
  9487. end;
  9488. end;
  9489. procedure TDefineButton.MouseMove(Shift: TShiftState; X, Y: Integer);
  9490. var
  9491. NewState: TButtonState;
  9492. begin
  9493. inherited;
  9494. if FDragging then
  9495. begin
  9496. if not FDown then
  9497. NewState := bsUp
  9498. else
  9499. NewState := bsExclusive;
  9500. if (X >= 0) and (X < ClientWidth) and (Y >= 0) and (Y <= ClientHeight) then
  9501. if FDown then
  9502. NewState := bsExclusive
  9503. else
  9504. NewState := bsDown;
  9505. if NewState <> FState then
  9506. begin
  9507. FState := NewState;
  9508. Invalidate;
  9509. end;
  9510. end;
  9511. end;
  9512. procedure TDefineButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  9513. var
  9514. DoClick: Boolean;
  9515. begin
  9516. inherited MouseUp(Button, Shift, X, Y);
  9517. if FDragging then
  9518. begin
  9519. FDragging := False;
  9520. DoClick := (X >= 0) and (X < ClientWidth) and (Y >= 0) and (Y <= ClientHeight);
  9521. if FGroupIndex = 0 then
  9522. begin
  9523. // Redraw face in-case mouse is captured
  9524. FState := bsUp;
  9525. FMouseIn := False;
  9526. if DoClick and not (FState in [bsExclusive, bsDown]) then
  9527. Invalidate;
  9528. end
  9529. else
  9530. if DoClick then
  9531. begin
  9532. SetDown(not FDown);
  9533. if FDown then Repaint;
  9534. end
  9535. else
  9536. begin
  9537. if FDown then FState := bsExclusive;
  9538. Repaint;
  9539. end;
  9540. if DoClick then Click else
  9541. MouseLeave;
  9542. UpdateTracking;
  9543. end;
  9544. end;
  9545. procedure TDefineButton.Click;
  9546. begin
  9547. if Parent <> nil then begin
  9548. GetParentForm(self).ModalResult := FModalResult;
  9549. SetDown(False);
  9550. end;
  9551. if Assigned(PopupMenu) then
  9552. PopupMenu.PopUp(ClientToScreen(Point(0, Height)).X,
  9553. ClientToScreen(Point(0, Height)).Y);
  9554. inherited Click;
  9555. end;
  9556. function TDefineButton.GetPalette: HPALETTE;
  9557. begin
  9558. Result := FGlyph.Palette;
  9559. end;
  9560. procedure TDefineButton.SetColors(Index: Integer; Value: TColor);
  9561. begin
  9562. case Index of
  9563. 0: fColorFocused := Value;
  9564. 1: fColorDown := Value;
  9565. 2: FColorBorder := Value;
  9566. 3: FColorShadow := Value;
  9567. 4: FColorFlat := Value;
  9568. 5: FAutoColor := Value;
  9569. end;
  9570. Invalidate;
  9571. end;
  9572. procedure TDefineButton.SetGlyph(Value: TBitmap);
  9573. begin
  9574. if value <> FGlyph then
  9575. begin
  9576. FGlyph.Assign(value);
  9577. if not FGlyph.Empty then
  9578. begin
  9579. if FGlyph.Width mod FGlyph.Height = 0 then
  9580. begin
  9581. FNumGlyphs := FGlyph.Width div FGlyph.Height;
  9582. if FNumGlyphs > 4 then FNumGlyphs := 1;
  9583. end;
  9584. end;
  9585. Invalidate;
  9586. end;
  9587. end;
  9588. procedure TDefineButton.SetNumGlyphs(Value: TNumGlyphs);
  9589. begin
  9590. if value <> FNumGlyphs then
  9591. begin
  9592. FNumGlyphs := value;
  9593. Invalidate;
  9594. end;
  9595. end;
  9596. procedure TDefineButton.UpdateExclusive;
  9597. var
  9598. Msg: TMessage;
  9599. begin
  9600. if (FGroupIndex <> 0) and (Parent <> nil) then
  9601. begin
  9602. Msg.Msg := CM_BUTTONPRESSED;
  9603. Msg.WParam := FGroupIndex;
  9604. Msg.LParam := Longint(Self);
  9605. Msg.Result := 0;
  9606. Parent.Broadcast(Msg);
  9607. end;
  9608. end;
  9609. procedure TDefineButton.SetDown(Value: Boolean);
  9610. begin
  9611. if FGroupIndex = 0 then Value := False;
  9612. if Value <> FDown then
  9613. begin
  9614. if FDown and (not FAllowAllUp) then Exit;
  9615. FDown := Value;
  9616. if Value then
  9617. begin
  9618. if FState = bsUp then Invalidate;
  9619. FState := bsExclusive
  9620. end
  9621. else
  9622. begin
  9623. FState := bsUp;
  9624. Repaint;
  9625. end;
  9626. if Value then UpdateExclusive;
  9627. end;
  9628. end;
  9629. procedure TDefineButton.SetGroupIndex(Value: Integer);
  9630. begin
  9631. if FGroupIndex <> Value then
  9632. begin
  9633. FGroupIndex := Value;
  9634. UpdateExclusive;
  9635. end;
  9636. end;
  9637. procedure TDefineButton.SetLayout(Value: TButtonLayout);
  9638. begin
  9639. if FLayout <> Value then
  9640. begin
  9641. FLayout := Value;
  9642. Invalidate;
  9643. end;
  9644. end;
  9645. procedure TDefineButton.SetMargin(Value: Integer);
  9646. begin
  9647. if(Value <> FMargin) and(Value >= -1) then
  9648. begin
  9649. FMargin := Value;
  9650. Invalidate;
  9651. end;
  9652. end;
  9653. procedure TDefineButton.SetSpacing(Value: Integer);
  9654. begin
  9655. if Value <> FSpacing then
  9656. begin
  9657. FSpacing := Value;
  9658. Invalidate;
  9659. end;
  9660. end;
  9661. procedure TDefineButton.SetAllowAllUp(Value: Boolean);
  9662. begin
  9663. if FAllowAllUp <> Value then
  9664. begin
  9665. FAllowAllUp := Value;
  9666. UpdateExclusive;
  9667. end;
  9668. end;
  9669. procedure TDefineButton.WMLButtonDblClk(var Message: TWMLButtonDown);
  9670. begin
  9671. inherited;
  9672. if FDown then DblClick;
  9673. end;
  9674. procedure TDefineButton.CMEnabledChanged(var Message: TMessage);
  9675. begin
  9676. inherited;
  9677. if not Enabled then begin
  9678. FMouseIn := False;
  9679. FState := bsDisabled;
  9680. // RemoveMouseTimer;
  9681. end;
  9682. UpdateTracking;
  9683. Invalidate;
  9684. end;
  9685. procedure TDefineButton.CMButtonPressed(var Message: TMessage);
  9686. var
  9687. Sender: TDefineButton;
  9688. begin
  9689. if Message.WParam = FGroupIndex then
  9690. begin
  9691. Sender := TDefineButton(Message.LParam);
  9692. if Sender <> Self then
  9693. begin
  9694. if Sender.Down and FDown then
  9695. begin
  9696. FDown := False;
  9697. FState := bsUp;
  9698. Invalidate;
  9699. end;
  9700. FAllowAllUp := Sender.AllowAllUp;
  9701. end;
  9702. end;
  9703. end;
  9704. procedure TDefineButton.CMDialogKey(var Message: TCMDialogKey);
  9705. begin
  9706. with Message do
  9707. if ((CharCode = VK_RETURN) and MouseIn) and
  9708. (KeyDataToShiftState(Message.KeyData) = []) and Enabled then
  9709. begin
  9710. Click;
  9711. Result := 1;
  9712. end else
  9713. inherited;
  9714. end;
  9715. procedure TDefineButton.CMDialogChar(var Message: TCMDialogChar);
  9716. begin
  9717. with Message do
  9718. if IsAccel(CharCode, Caption) and Enabled then begin
  9719. if GroupIndex <> 0 then
  9720. SetDown(true);
  9721. Click;
  9722. Result := 1;
  9723. end;
  9724. end;
  9725. procedure TDefineButton.CMFontChanged(var Message: TMessage);
  9726. begin
  9727. Invalidate;
  9728. end;
  9729. procedure TDefineButton.CMTextChanged(var Message: TMessage);
  9730. begin
  9731. Invalidate;
  9732. end;
  9733. procedure TDefineButton.CMSysColorChange(var Message: TMessage);
  9734. begin
  9735. inherited;
  9736. if (Parent <> nil)and(ParentColor) then
  9737. Color := TDefineButton(Parent).Color;
  9738. Invalidate;
  9739. end;
  9740. procedure TDefineButton.CMParentColorChanged(var Message: TWMNoParams);
  9741. begin
  9742. inherited;
  9743. if (Parent <> nil)and(not ParentColor) then
  9744. Color := TDefineButton(Parent).Color;
  9745. Invalidate;
  9746. end;
  9747. procedure TDefineButton.MouseEnter;
  9748. begin
  9749. if Enabled and not MouseIn then
  9750. begin
  9751. FMouseIn := True;
  9752. Invalidate;
  9753. end;
  9754. end;
  9755. procedure TDefineButton.MouseLeave;
  9756. begin
  9757. if Enabled and MouseIn and not FDragging then
  9758. begin
  9759. FMouseIn := False;
  9760. Invalidate;
  9761. end;
  9762. end;
  9763. procedure TDefineButton.SetDefault(const Value: Boolean);
  9764. var
  9765. {$IFDEF DFS_COMPILER_2}
  9766. Form: TForm;
  9767. {$ELSE}
  9768. Form: TCustomForm;
  9769. {$ENDIF}
  9770. begin
  9771. FDefault := Value;
  9772. if HandleAllocated then
  9773. begin
  9774. Form := GetParentForm(Self);
  9775. if Form <> nil then
  9776. Form.Perform(CM_FOCUSCHANGED, 0, Longint(Form.ActiveControl));
  9777. end;
  9778. Invalidate;
  9779. end;
  9780. procedure TDefineButton.WMKillFocus(var Message: TWMKillFocus);
  9781. begin
  9782. inherited;
  9783. MouseLeave;
  9784. end;
  9785. procedure TDefineButton.WMSetFocus(var Message: TWMSetFocus);
  9786. begin
  9787. inherited;
  9788. if Enabled then
  9789. begin
  9790. FMouseIn := True;
  9791. Invalidate;
  9792. end;
  9793. end;
  9794. procedure TDefineButton.WMKeyDown(var Message: TWMKeyDown);
  9795. var CharCode:Word;
  9796. begin
  9797. CharCode := Message.CharCode;
  9798. if CharCode = VK_SPACE then
  9799. begin
  9800. if GroupIndex = 0 then
  9801. FState := bsDown
  9802. else
  9803. SetDown(true);
  9804. Invalidate;
  9805. end;
  9806. end;
  9807. procedure TDefineButton.WMKeyUp(var Message: TWMKeyUp);
  9808. var CharCode:Word;
  9809. begin
  9810. CharCode := Message.CharCode;
  9811. if CharCode = VK_SPACE then begin
  9812. if GroupIndex = 0 then
  9813. FState := bsUp
  9814. else
  9815. SetDown(false);
  9816. Click;
  9817. Invalidate;
  9818. end;
  9819. end;
  9820. procedure TDefineButton.SetTransparent(const Value: TTransparentMode);
  9821. begin
  9822. if FTransparent <> Value then
  9823. begin
  9824. FTransparent := Value;
  9825. Invalidate;
  9826. end;
  9827. end;
  9828. procedure TDefineButton.WMMove(var Message: TWMMove);
  9829. begin
  9830. inherited;
  9831. if not (FTransparent = tmNone) then
  9832. Invalidate;
  9833. end;
  9834. procedure TDefineButton.WMSize(var Message: TWMSize);
  9835. begin
  9836. inherited;
  9837. if not (FTransparent = tmNone) then
  9838. Invalidate;
  9839. end;
  9840. procedure TDefineButton.CMMouseEnter(var Message: TMessage);
  9841. begin
  9842. inherited;
  9843. if Assigned(FOnMouseEnter) then
  9844. FOnMouseEnter(Self)
  9845. else if not(csDesigning in ComponentState) then
  9846. MouseEnter;
  9847. end;
  9848. procedure TDefineButton.CMMouseLeave(var Message: TMessage);
  9849. begin
  9850. inherited;
  9851. if Assigned(FOnMouseLeave) then
  9852. FOnMouseLeave(Self)
  9853. else if not(csDesigning in ComponentState) then
  9854. MouseLeave;
  9855. end;
  9856. procedure TDefineButton.SetName(const Value: TComponentName);
  9857. begin
  9858. inherited SetName(Value);
  9859. if (csDesigning in ComponentState)and((GetTextLen = 0)or
  9860. (CompareText(Caption, Name) = 0)) then
  9861. Caption := Value;
  9862. end;
  9863. procedure TDefineButton.SetTransBorder(const Value: Boolean);
  9864. begin
  9865. if FTransBorder <> Value then begin
  9866. FTransBorder := Value;
  9867. Invalidate;
  9868. end;
  9869. end;
  9870. procedure TDefineButton.SetFoisChange(const Value: Boolean);
  9871. begin
  9872. if FFoisChange <> Value then begin
  9873. FFoisChange := Value;
  9874. Invalidate;
  9875. end;
  9876. end;
  9877. procedure TDefineButton.SetAutoStyle(const Value: TFontStyles);
  9878. begin
  9879. if FAutoStyle <> Value then begin
  9880. FAutoStyle := Value;
  9881. Invalidate;
  9882. end;
  9883. end;
  9884. function TDefineButton.GetMouseIn: Boolean;
  9885. begin
  9886. Result := FMouseIn;
  9887. end;
  9888. { TDefinePanel }
  9889. constructor TDefinePanel.Create(AOwner: TComponent);
  9890. begin
  9891. inherited Create(AOwner);
  9892. ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  9893. csSetCaption, csOpaque, csDoubleClicks, csReplicatable];
  9894. { When themes are on in an application default to making
  9895. TDefinePanel's paint with their ParentBackground }
  9896. if ThemeServices.ThemesEnabled then
  9897. ControlStyle := ControlStyle + [csParentBackground] - [csOpaque];
  9898. ParentColor := True;
  9899. UseDockManager := True;
  9900. ParentFont := True;
  9901. Color := clBtnFace;
  9902. FColorBorder := DefaultBorderColor;
  9903. FFullRepaint := True;
  9904. FAlignment := taCenter;
  9905. FTransBorder := false;
  9906. FTransparent := false;
  9907. FStyleFace := fsDefault;
  9908. FBackgropStartColor := DefaultColorStart;
  9909. FBackgropStopColor := DefaultColorStop;
  9910. FBackgropOrien := fdLeftToRight;
  9911. SetBounds(0, 0, 185, 41);
  9912. end;
  9913. procedure TDefinePanel.SetColors(Index: Integer; Value: TColor);
  9914. begin
  9915. case Index of
  9916. 0: FColorBorder := Value;
  9917. 1: FBackgropStartColor := Value;
  9918. 2: FBackgropStopColor := Value;
  9919. end;
  9920. Invalidate;
  9921. end;
  9922. procedure TDefinePanel.Paint;
  9923. var
  9924. memBitmap: TBitmap;
  9925. TextBounds: TRect;
  9926. Format: UINT;
  9927. begin
  9928. TextBounds := ClientRect;
  9929. TextBounds.Left := TextBounds.Left + 3;
  9930. TextBounds.Right := TextBounds.Right - 3;
  9931. Format := DT_SINGLELINE or DT_VCENTER;
  9932. case Alignment of
  9933. taLeftJustify: Format := Format or DT_LEFT;
  9934. taCenter: Format := Format or DT_CENTER;
  9935. taRightJustify:Format := Format or DT_RIGHT;
  9936. end;
  9937. memBitmap := TBitmap.Create; // create memory-bitmap to draw flicker-free
  9938. try
  9939. memBitmap.Height := ClientRect.Bottom;
  9940. memBitmap.Width := ClientRect.Right;
  9941. if not ThemeServices.ThemesEnabled or not ParentBackground then
  9942. begin
  9943. memBitmap.Canvas.Brush.Color := Color;
  9944. memBitmap.Canvas.FillRect(TextBounds);
  9945. end;
  9946. // Draw Background
  9947. if FTransparent then
  9948. DrawParentImage(Self, memBitmap.Canvas)
  9949. else begin
  9950. if FStyleFace=fsDefault then begin
  9951. memBitmap.Canvas.Brush.Color := Self.Color;
  9952. memBitmap.Canvas.FillRect(ClientRect);
  9953. end else
  9954. //DrawBackdrop(memBitmap.Canvas,FBackgropStartColor,FBackgropStopColor,ClientRect,FBackgropOrien);
  9955. GradientFillRect(memBitmap.Canvas,ClientRect,FBackgropStartColor,FBackgropStopColor,FBackgropOrien,60);
  9956. end;
  9957. // Draw Border
  9958. if not FTransBorder then DrawButtonBorder(memBitmap.Canvas, ClientRect, FColorBorder, 1);
  9959. // Draw Text
  9960. memBitmap.Canvas.Font := Self.Font;
  9961. memBitmap.Canvas.Brush.Style := bsClear;
  9962. if not Enabled then begin
  9963. OffsetRect(TextBounds, 1, 1);
  9964. memBitmap.Canvas.Font.Color := clBtnHighlight;
  9965. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  9966. OffsetRect(TextBounds, -1, -1);
  9967. memBitmap.Canvas.Font.Color := clBtnShadow;
  9968. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  9969. end else
  9970. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  9971. // Copy memBitmap to screen
  9972. canvas.CopyRect(ClientRect, memBitmap.canvas, ClientRect);
  9973. finally
  9974. memBitmap.free; // delete the bitmap
  9975. end;
  9976. end;
  9977. procedure TDefinePanel.CMEnabledChanged(var Message: TMessage);
  9978. begin
  9979. inherited;
  9980. Invalidate;
  9981. end;
  9982. procedure TDefinePanel.CMTextChanged(var Message: TWmNoParams);
  9983. begin
  9984. inherited;
  9985. Invalidate;
  9986. end;
  9987. procedure TDefinePanel.SetTransparent(Value: Boolean);
  9988. begin
  9989. if FTransparent <> Value then begin
  9990. FTransparent := Value;
  9991. Invalidate;
  9992. end;
  9993. end;
  9994. procedure TDefinePanel.SetFillDirect(Value: TFillDirection);
  9995. begin
  9996. if FBackgropOrien <> Value then begin
  9997. FBackgropOrien := Value;
  9998. Invalidate;
  9999. end;
  10000. end;
  10001. procedure TDefinePanel.SetStyleFace(Value: TStyleFace);
  10002. begin
  10003. if FStyleFace <> Value then begin
  10004. FStyleFace := Value;
  10005. Invalidate;
  10006. end;
  10007. end;
  10008. procedure TDefinePanel.SetAlignment(Value: TAlignment);
  10009. begin
  10010. if FAlignment <> Value then begin
  10011. FAlignment := Value;
  10012. Invalidate;
  10013. end;
  10014. end;
  10015. procedure TDefinePanel.CMIsToolControl(var Message: TMessage);
  10016. begin
  10017. if not FLocked then Message.Result := 1;
  10018. end;
  10019. procedure TDefinePanel.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  10020. var
  10021. Rect: TRect;
  10022. begin
  10023. if FullRepaint or(Caption <> '') then
  10024. Invalidate
  10025. else
  10026. begin
  10027. Rect.Right := Width;
  10028. Rect.Bottom := Height;
  10029. if Message.WindowPos^.cx <> Rect.Right then
  10030. begin
  10031. Rect.Top := 0;
  10032. Rect.Left := Rect.Right - 2;
  10033. InvalidateRect(Handle, @Rect, True);
  10034. end;
  10035. if Message.WindowPos^.cy <> Rect.Bottom then
  10036. begin
  10037. Rect.Left := 0;
  10038. Rect.Top := Rect.Bottom - 2;
  10039. InvalidateRect(Handle, @Rect, True);
  10040. end;
  10041. end;
  10042. inherited;
  10043. end;
  10044. procedure TDefinePanel.CMDockClient(var Message: TCMDockClient);
  10045. var
  10046. R: TRect;
  10047. Dim: Integer;
  10048. begin
  10049. if AutoSize then
  10050. begin
  10051. FAutoSizeDocking := True;
  10052. try
  10053. R := Message.DockSource.DockRect;
  10054. case Align of
  10055. alLeft: if Width = 0 then Width := R.Right - R.Left;
  10056. alRight: if Width = 0 then
  10057. begin
  10058. Dim := R.Right - R.Left;
  10059. SetBounds(Left - Dim, Top, Dim, Height);
  10060. end;
  10061. alTop: if Height = 0 then Height := R.Bottom - R.Top;
  10062. alBottom: if Height = 0 then
  10063. begin
  10064. Dim := R.Bottom - R.Top;
  10065. SetBounds(Left, Top - Dim, Width, Dim);
  10066. end;
  10067. end;
  10068. inherited;
  10069. Exit;
  10070. finally
  10071. FAutoSizeDocking := False;
  10072. end;
  10073. end;
  10074. inherited;
  10075. end;
  10076. function TDefinePanel.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
  10077. begin
  10078. Result :=(not FAutoSizeDocking) and inherited CanAutoSize(NewWidth, NewHeight);
  10079. end;
  10080. function TDefinePanel.GetControlsAlignment: TAlignment;
  10081. begin
  10082. Result := FAlignment;
  10083. end;
  10084. procedure TDefinePanel.SetParentBackground(Value: Boolean);
  10085. begin
  10086. { TCustomPanel needs to not have csOpaque when painting
  10087. with the ParentBackground in Themed applications }
  10088. if Value then
  10089. ControlStyle := ControlStyle - [csOpaque]
  10090. else
  10091. ControlStyle := ControlStyle + [csOpaque];
  10092. FParentBackgroundSet := True;
  10093. inherited;
  10094. end;
  10095. procedure TDefinePanel.CreateParams(var Params: TCreateParams);
  10096. begin
  10097. inherited CreateParams(Params);
  10098. with Params do
  10099. begin
  10100. WindowClass.style := WindowClass.style and not(CS_HREDRAW or CS_VREDRAW);
  10101. end;
  10102. end;
  10103. procedure TDefinePanel.AdjustClientRect(var Rect: TRect);
  10104. begin
  10105. inherited AdjustClientRect(Rect);
  10106. Inc(Rect.Top);
  10107. Inc(Rect.Left);
  10108. Dec(Rect.Right);
  10109. Dec(Rect.Bottom);
  10110. InflateRect(Rect, -1, -1);
  10111. end;
  10112. procedure TDefinePanel.SetTransBorder(Value: boolean);
  10113. begin
  10114. if FTransBorder <> Value then begin
  10115. FTransBorder := Value;
  10116. Invalidate;
  10117. end;
  10118. end;
  10119. { TDefineLabel }
  10120. procedure TDefineLabel.CMEnabledChanged(var Message: TMessage);
  10121. begin
  10122. inherited;
  10123. if Assigned(FTicket) then FTicket.Enabled := Enabled;
  10124. end;
  10125. procedure TDefineLabel.SetTicketPosition(const Value: TTicketPosition);
  10126. begin
  10127. if FTicket = nil then exit;
  10128. FTicketPosition := Value;
  10129. SetTicketPoint(Value,Self,Ticket,FTicketSpace);
  10130. end;
  10131. procedure TDefineLabel.SetLabelSpacing(const Value: Integer);
  10132. begin
  10133. if Assigned(FTicket) then FTicketSpace := Value;
  10134. SetTicketPosition(FTicketPosition);
  10135. end;
  10136. procedure TDefineLabel.SetupInternalLabel;
  10137. begin
  10138. if DefaultHasTicket then begin
  10139. if Assigned(FTicket) then exit;
  10140. FTicket := TDefineTicket.Create(Self);
  10141. FTicket.FreeNotification(Self);
  10142. FTicket.Transparent := True;
  10143. FTicket.FocusControl := Self;
  10144. end;
  10145. end;
  10146. procedure TDefineLabel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
  10147. begin
  10148. inherited SetBounds(ALeft, ATop, AWidth, AHeight);
  10149. SetTicketPosition(FTicketPosition);
  10150. end;
  10151. procedure TDefineLabel.SetParent(AParent: TWinControl);
  10152. begin
  10153. inherited SetParent(AParent);
  10154. if FTicket = nil then exit;
  10155. FTicket.Parent := AParent;
  10156. FTicket.Visible := True;
  10157. end;
  10158. procedure TDefineLabel.CMBidimodechanged(var Message: TMessage);
  10159. begin
  10160. inherited;
  10161. if Assigned(FTicket) then FTicket.BiDiMode := BiDiMode;
  10162. end;
  10163. procedure TDefineLabel.CMVisiblechanged(var Message: TMessage);
  10164. begin
  10165. inherited;
  10166. if Assigned(FTicket) then FTicket.Visible := Visible;
  10167. end;
  10168. procedure TDefineLabel.SetName(const Value: TComponentName);
  10169. begin
  10170. if Assigned(FTicket) then begin
  10171. if(csDesigning in ComponentState) and((FTicket.GetTextLen = 0) or
  10172. (CompareText(FTicket.Caption, Name) = 0)) then
  10173. FTicket.Caption := Value;
  10174. end;
  10175. inherited SetName(Value);
  10176. if(csDesigning in ComponentState)and(Assigned(FTicket)) then
  10177. Caption := '';
  10178. end;
  10179. procedure TDefineLabel.Notification(AComponent: TComponent;
  10180. Operation: TOperation);
  10181. begin
  10182. inherited Notification(AComponent, Operation);
  10183. if(AComponent = FTicket) and(Operation = opRemove) then
  10184. FTicket := nil;
  10185. end;
  10186. procedure TDefineLabel.NewAdjustHeight;
  10187. var
  10188. DC: HDC;
  10189. SaveFont: HFONT;
  10190. Metrics: TTextMetric;
  10191. begin
  10192. DC := GetDC(0);
  10193. SaveFont := SelectObject(DC, Font.Handle);
  10194. GetTextMetrics(DC, Metrics);
  10195. SelectObject(DC, SaveFont);
  10196. ReleaseDC(0, DC);
  10197. Height := Metrics.tmHeight + 6;
  10198. end;
  10199. procedure TDefineLabel.Loaded;
  10200. begin
  10201. inherited;
  10202. //if not(csDesigning in ComponentState) then
  10203. //begin
  10204. NewAdjustHeight;
  10205. //end;
  10206. end;
  10207. constructor TDefineLabel.Create(AOwner: TComponent);
  10208. begin
  10209. inherited Create(AOwner);
  10210. FTicketPosition := poLeft;
  10211. FTicketSpace := 3;
  10212. SetBounds(0,0,121,20);
  10213. SetupInternalLabel;
  10214. end;
  10215. procedure TDefineLabel.CMFontChanged(var Message: TMessage);
  10216. begin
  10217. inherited;
  10218. if not((csDesigning in ComponentState) and (csLoading in ComponentState)) then
  10219. NewAdjustHeight;
  10220. end;
  10221. { TDefineCheckBox }
  10222. constructor TDefineCheckBox.Create(AOwner: TComponent);
  10223. begin
  10224. inherited Create(AOwner);
  10225. ControlStyle := [csSetCaption, csDoubleClicks];
  10226. ParentColor := False;
  10227. ParentFont := True;
  10228. TabStop := True;
  10229. Enabled := True;
  10230. Visible := True;
  10231. FTransparent := True;
  10232. Color := DefaultFlatColor;
  10233. FFocusedColor := DefaultBackdropColor;
  10234. FDownColor := DefaultBarColor;
  10235. FCheckedColor := DefaultCheckColor;
  10236. FBorderColor := DefaultBorderColor;
  10237. FLayout := lpLeft;
  10238. FChecked := false;
  10239. SetBounds(0, 0, 121, 15);
  10240. end;
  10241. procedure TDefineCheckBox.SetColors(Index: Integer; Value: TColor);
  10242. begin
  10243. case Index of
  10244. 0: FFocusedColor := Value;
  10245. 1: FDownColor := Value;
  10246. 2: FCheckedColor := Value;
  10247. 3: FBorderColor := Value;
  10248. end;
  10249. Invalidate;
  10250. end;
  10251. procedure TDefineCheckBox.SetLayout(Value: TLayoutPosition);
  10252. begin
  10253. FLayout := Value;
  10254. Invalidate;
  10255. end;
  10256. procedure TDefineCheckBox.SetChecked(Value: Boolean);
  10257. begin
  10258. if FChecked <> Value then
  10259. begin
  10260. FChecked := Value;
  10261. Click;
  10262. Invalidate;
  10263. if csDesigning in ComponentState then
  10264. if(GetParentForm(self) <> nil) and(GetParentForm(self).Designer <> nil) then
  10265. GetParentForm(self).Designer.Modified;
  10266. end;
  10267. end;
  10268. procedure TDefineCheckBox.CMEnabledChanged(var Message: TMessage);
  10269. begin
  10270. inherited;
  10271. if not Enabled then
  10272. begin
  10273. FMouseIn := False;
  10274. FMouseDown := False;
  10275. end;
  10276. Invalidate;
  10277. end;
  10278. procedure TDefineCheckBox.CMTextChanged(var Message: TWmNoParams);
  10279. begin
  10280. inherited;
  10281. Invalidate;
  10282. end;
  10283. procedure TDefineCheckBox.CMDialogChar(var Message: TCMDialogChar);
  10284. begin
  10285. with Message do
  10286. if IsAccel(Message.CharCode, Caption) and CanFocus then
  10287. begin
  10288. SetFocus;
  10289. if Focused then Click;
  10290. Result := 1;
  10291. end
  10292. else
  10293. if(CharCode = VK_SPACE) and Focused then
  10294. begin
  10295. SetFocus;
  10296. if Focused then Click;
  10297. Result := 1;
  10298. end
  10299. else
  10300. inherited;
  10301. end;
  10302. procedure TDefineCheckBox.CNCommand(var Message: TWMCommand);
  10303. begin
  10304. if Message.NotifyCode = BN_CLICKED then Click;
  10305. end;
  10306. procedure TDefineCheckBox.WMSetFocus(var Message: TWMSetFocus);
  10307. begin
  10308. inherited;
  10309. if not(csDesigning in ComponentState) and Enabled then
  10310. begin
  10311. Focused := True;
  10312. invalidate;
  10313. end;
  10314. end;
  10315. procedure TDefineCheckBox.WMKillFocus(var Message: TWMKillFocus);
  10316. begin
  10317. inherited;
  10318. if not(csDesigning in ComponentState) and Enabled then
  10319. begin
  10320. FMouseIn := False;
  10321. Focused := False;
  10322. invalidate;
  10323. end;
  10324. end;
  10325. procedure TDefineCheckBox.CMSysColorChange(var Message: TMessage);
  10326. begin
  10327. inherited;
  10328. if (Parent <> nil)and(ParentColor) then
  10329. begin
  10330. Color := TDefineCheckBox(Parent).Color;
  10331. end;
  10332. Invalidate;
  10333. end;
  10334. procedure TDefineCheckBox.CMParentColorChanged(var Message: TWMNoParams);
  10335. begin
  10336. inherited;
  10337. if (Parent <> nil)and(ParentColor) then
  10338. begin
  10339. Color := TDefineCheckBox(Parent).Color;
  10340. end;
  10341. Invalidate;
  10342. end;
  10343. procedure TDefineCheckBox.DoEnter;
  10344. begin
  10345. inherited DoEnter;
  10346. Focused := True;
  10347. invalidate;
  10348. end;
  10349. procedure TDefineCheckBox.DoExit;
  10350. begin
  10351. inherited DoExit;
  10352. Focused := False;
  10353. invalidate;
  10354. end;
  10355. procedure TDefineCheckBox.Paint;
  10356. var
  10357. TextBounds, CheckRect: TRect;
  10358. Format: UINT;
  10359. TextAs:Integer;
  10360. begin
  10361. with Canvas do
  10362. begin
  10363. Lock;
  10364. Font.Assign(self.Font);
  10365. if Layout = lpLeft then
  10366. Width := TextWidth(DelCapLink(Caption))+TextHeight('H')+5;
  10367. Height := TextHeight('H')+2;
  10368. if FTransparent then
  10369. DrawParentImage(Self, Canvas)
  10370. else
  10371. begin
  10372. Brush.Color := self.Color;
  10373. FillRect(ClientRect);
  10374. end;
  10375. //draw Background
  10376. with ClientRect do
  10377. begin
  10378. case FLayout of
  10379. lpLeft: CheckRect := Rect(1, HeightOf(ClientRect) div 2 - 7, 15, HeightOf(ClientRect) div 2 + 7);
  10380. lpRight: CheckRect := Rect(Width-15, HeightOf(ClientRect) div 2 - 7, Width-1, HeightOf(ClientRect) div 2 + 7);
  10381. end;
  10382. end;
  10383. Pen.style := psSolid;
  10384. Pen.width := 1;
  10385. if (Focused or MouseIn)and(not(csDesigning in ComponentState)) then
  10386. begin
  10387. if (not FMouseDown) then
  10388. begin
  10389. Brush.color := FFocusedColor;
  10390. Pen.color := FBorderColor;
  10391. end else begin
  10392. Brush.color := FDownColor;
  10393. Pen.color := FBorderColor;
  10394. end;
  10395. end else begin
  10396. Brush.color := self.Color;
  10397. Pen.color := FBorderColor;
  10398. end;
  10399. FillRect(CheckRect);
  10400. if Checked then
  10401. begin
  10402. if Enabled then
  10403. DrawInCheck(Canvas,CheckRect,FCheckedColor)
  10404. else
  10405. DrawInCheck(Canvas,CheckRect,clBtnShadow);
  10406. end;
  10407. //draw Border
  10408. Brush.color := FBorderColor;
  10409. FrameRect(CheckRect);
  10410. //draw text
  10411. Brush.Style := bsClear;
  10412. Format := DT_WORDBREAK;
  10413. with ClientRect do
  10414. begin
  10415. TextAs:=(RectHeight(ClientRect)+ CheckRect.top - TextHeight('W')) div 2;
  10416. case FLayout of
  10417. lpLeft: begin
  10418. TextBounds := Rect(Left + WidthOf(CheckRect)+2, Top + TextAs, Right + WidthOf(CheckRect), Bottom - TextAs);
  10419. Format := Format or DT_LEFT;
  10420. end;
  10421. lpRight: begin
  10422. TextBounds := Rect(Left + 1, Top + TextAs, Right - WidthOf(CheckRect)-2, Bottom - TextAs);
  10423. Format := Format or DT_RIGHT;
  10424. end;
  10425. end;
  10426. end;
  10427. if Enabled and Focused then begin
  10428. DrawFocusRect(ClientRect);
  10429. end;
  10430. if not Enabled then begin
  10431. OffsetRect(TextBounds, 1, 1);
  10432. Font.Color := clBtnHighlight;
  10433. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  10434. OffsetRect(TextBounds, -1, -1);
  10435. Font.Color := clBtnShadow;
  10436. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  10437. end
  10438. else
  10439. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  10440. unLock;
  10441. end;
  10442. end;
  10443. procedure TDefineCheckBox.SetTransparent(const Value: Boolean);
  10444. begin
  10445. if FTransparent <> Value then
  10446. begin
  10447. FTransparent := Value;
  10448. ParentColor := not Value;
  10449. Invalidate;
  10450. end;
  10451. end;
  10452. procedure TDefineCheckBox.WMMove(var Message: TWMMove);
  10453. begin
  10454. inherited;
  10455. if FTransparent then
  10456. Invalidate;
  10457. end;
  10458. procedure TDefineCheckBox.WMSize(var Message: TWMSize);
  10459. begin
  10460. inherited;
  10461. if FTransparent then
  10462. Invalidate;
  10463. end;
  10464. procedure TDefineCheckBox.CMMouseEnter(var Message: TMessage);
  10465. begin
  10466. inherited;
  10467. if not(csDesigning in ComponentState) and
  10468. (GetActiveWindow <> 0) and (not MouseIn) then
  10469. begin
  10470. FMouseIn := True;
  10471. Invalidate;
  10472. end;
  10473. end;
  10474. procedure TDefineCheckBox.CMMouseLeave(var Message: TMessage);
  10475. begin
  10476. inherited;
  10477. if MouseIn then begin
  10478. FMouseIn := false;
  10479. Invalidate;
  10480. end;
  10481. end;
  10482. procedure TDefineCheckBox.CMFontChanged(var Message: TMessage);
  10483. begin
  10484. inherited;
  10485. Invalidate;
  10486. end;
  10487. function TDefineCheckBox.GetMouseIn: Boolean;
  10488. begin
  10489. Result := FMouseIn;
  10490. end;
  10491. procedure TDefineCheckBox.Click;
  10492. begin
  10493. inherited Changed;
  10494. inherited Click;
  10495. end;
  10496. procedure TDefineCheckBox.WMLButtonDown(var Message: TWMLButtonDown);
  10497. begin
  10498. if Enabled then
  10499. begin
  10500. SetFocus;
  10501. FMouseDown := true;
  10502. FChecked := not FChecked;
  10503. invalidate;
  10504. end;
  10505. end;
  10506. procedure TDefineCheckBox.WMLButtonUP(var Message: TWMLButtonDown);
  10507. begin
  10508. if Enabled then
  10509. begin
  10510. FMouseDown := false;
  10511. invalidate;
  10512. end;
  10513. end;
  10514. { TDefineGroupBox }
  10515. constructor TDefineGroupBox.Create(AOwner: TComponent);
  10516. begin
  10517. inherited Create(AOwner);
  10518. ControlStyle := ControlStyle + [csAcceptsControls, csOpaque];
  10519. FBackgropStartColor := DefaultColorStart;
  10520. FBackgropStopColor := DefaultColorStop;
  10521. FBorderColor := DefaultBorderColor;
  10522. FBackgropOrien := fdLeftToRight;
  10523. FTransparent := false;
  10524. FStyleFace := fsDefault;
  10525. FBorder := brFull;
  10526. FAlignment := stLeft;
  10527. SetBounds(0, 0, 185, 105);
  10528. end;
  10529. procedure GetStyleGroupBox(Value:TAlignmentText; var Result:UINT);
  10530. begin
  10531. case Value of
  10532. stLeft : result := DT_TOP or DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  10533. stRight : result := DT_TOP or DT_RIGHT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  10534. stCenter : result := DT_TOP or DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  10535. end;
  10536. end;
  10537. procedure TDefineGroupBox.Paint;
  10538. var
  10539. memBitmap: TBitmap;
  10540. borderRect, TextRect: TRect;
  10541. textHeight, textWidth, TextLeft, TextRight: integer;
  10542. Format: UINT;
  10543. begin
  10544. borderRect := ClientRect;
  10545. GetStyleGroupBox(FAlignment,Format);
  10546. memBitmap := TBitmap.Create; // create memory-bitmap to draw flicker-free
  10547. try
  10548. memBitmap.Height := ClientRect.Bottom;
  10549. memBitmap.Width := ClientRect.Right;
  10550. memBitmap.Canvas.Font := Self.Font;
  10551. textHeight := memBitmap.Canvas.TextHeight(caption);
  10552. textWidth := memBitmap.Canvas.TextWidth(caption);
  10553. TextRect := Rect(ClientRect.Left + 10, ClientRect.Top, ClientRect.Right - 10, ClientRect.Top + textHeight);
  10554. // Draw Background
  10555. if FTransparent then
  10556. DrawParentImage(Self, memBitmap.Canvas)
  10557. else begin
  10558. if FStyleFace=fsDefault then begin
  10559. memBitmap.Canvas.Brush.Color := Self.Color;
  10560. memBitmap.Canvas.FillRect(ClientRect);
  10561. end else
  10562. //DrawBackdrop(memBitmap.Canvas,FBackgropStartColor,FBackgropStopColor,ClientRect,FBackgropOrien);
  10563. GradientFillRect(memBitmap.Canvas,ClientRect,FBackgropStartColor,FBackgropStopColor,FBackgropOrien,60);
  10564. end;
  10565. case FAlignment of
  10566. stLeft:
  10567. begin
  10568. TextLeft := ClientRect.left + 5;
  10569. TextRight:= ClientRect.left + 12 + textWidth;
  10570. end;
  10571. stRight:begin
  10572. TextLeft := ClientRect.Right - TextWidth - 15;
  10573. TextRight:= ClientRect.Right - 8;
  10574. end;
  10575. else//stCenter:
  10576. TextRight:= (RectWidth(ClientRect) + textWidth + 5) div 2;
  10577. TextLeft := (RectWidth(ClientRect) - textWidth - 12) div 2;
  10578. end;
  10579. // Draw Border
  10580. memBitmap.Canvas.Pen.Color := FBorderColor;
  10581. case FBorder of
  10582. brFull:
  10583. begin
  10584. memBitmap.Canvas.Polyline([Point(TextLeft, ClientRect.top +(textHeight div 2)),
  10585. Point(ClientRect.left, ClientRect.top +(textHeight div 2)),
  10586. Point(ClientRect.left, ClientRect.bottom-1), Point(ClientRect.right-1, ClientRect.bottom-1),
  10587. Point(ClientRect.right-1, ClientRect.top +(textHeight div 2)),
  10588. Point(TextRight, ClientRect.top +(textHeight div 2))]);
  10589. end;
  10590. brOnlyTopLine:
  10591. begin
  10592. memBitmap.Canvas.Polyline([Point(ClientRect.left + 5, ClientRect.top +(textHeight div 2)), Point(ClientRect.left, ClientRect.top +(Canvas.textHeight(caption) div 2))]);
  10593. memBitmap.Canvas.Polyline([Point(ClientRect.right-1, ClientRect.top +(textHeight div 2)), Point(ClientRect.left + 12 + textWidth, ClientRect.top +(textHeight div 2))]);
  10594. end;
  10595. end;
  10596. // Draw Text
  10597. memBitmap.Canvas.Brush.Style := bsClear;
  10598. if not Enabled then
  10599. begin
  10600. OffsetRect(TextRect, 1, 1);
  10601. memBitmap.Canvas.Font.Color := clBtnHighlight;
  10602. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextRect, Format);
  10603. OffsetRect(TextRect, -1, -1);
  10604. memBitmap.Canvas.Font.Color := clBtnShadow;
  10605. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextRect, Format);
  10606. end
  10607. else
  10608. DrawText(memBitmap.Canvas.Handle, PChar(Caption), Length(Caption), TextRect, Format);
  10609. // Copy memBitmap to screen
  10610. Canvas.CopyRect(ClientRect, memBitmap.Canvas, ClientRect);
  10611. finally
  10612. memBitmap.free; // delete the bitmap
  10613. end;
  10614. end;
  10615. procedure TDefineGroupBox.CMTextChanged(var Message: TWmNoParams);
  10616. begin
  10617. inherited;
  10618. Invalidate;
  10619. end;
  10620. procedure TDefineGroupBox.SetColors(const Index: Integer;
  10621. const Value: TColor);
  10622. begin
  10623. case Index of
  10624. 0: FBorderColor := Value;
  10625. 1: FBackgropStartColor := Value;
  10626. 2: FBackgropStopColor := Value;
  10627. end;
  10628. Invalidate;
  10629. end;
  10630. procedure TDefineGroupBox.SetBorder(const Value: TGroupBoxBorder);
  10631. begin
  10632. if FBorder <> Value then
  10633. begin
  10634. FBorder := Value;
  10635. Invalidate;
  10636. end;
  10637. end;
  10638. procedure TDefineGroupBox.SetFillDirect(const Value: TFillDirection);
  10639. begin
  10640. if FBackgropOrien <> Value then begin
  10641. FBackgropOrien := Value;
  10642. Invalidate;
  10643. end;
  10644. end;
  10645. procedure TDefineGroupBox.SetStyleFace(const Value: TStyleFace);
  10646. begin
  10647. if FStyleFace <> Value then begin
  10648. FStyleFace := Value;
  10649. Invalidate;
  10650. end;
  10651. end;
  10652. procedure TDefineGroupBox.CMParentColorChanged(var Message: TWMNoParams);
  10653. begin
  10654. inherited;
  10655. //FTransParent := not ParentColor;
  10656. if (Parent <> nil)and(ParentColor) then
  10657. begin
  10658. Color := TForm(Parent).Color;
  10659. end;
  10660. Invalidate;
  10661. end;
  10662. procedure TDefineGroupBox.CMSysColorChange(var Message: TMessage);
  10663. begin
  10664. inherited;
  10665. if (Parent <> nil)and(ParentColor) then
  10666. Color := TForm(Parent).Color;
  10667. Invalidate;
  10668. end;
  10669. procedure TDefineGroupBox.CMDialogChar(var Message: TCMDialogChar);
  10670. begin
  10671. with Message do
  10672. if IsAccel(Message.CharCode, Caption) and CanFocus then
  10673. begin
  10674. SetFocus;
  10675. Result := 1;
  10676. end;
  10677. end;
  10678. procedure TDefineGroupBox.CMEnabledChanged(var Message: TMessage);
  10679. begin
  10680. inherited;
  10681. Invalidate;
  10682. end;
  10683. procedure TDefineGroupBox.SetTransparent(const Value: Boolean);
  10684. begin
  10685. if FTransparent <> Value then
  10686. begin
  10687. FTransparent := Value;
  10688. //ParentColor := not Value;
  10689. Invalidate;
  10690. end;
  10691. end;
  10692. procedure TDefineGroupBox.WMMove(var Message: TWMMove);
  10693. begin
  10694. inherited;
  10695. if FTransparent then Invalidate;
  10696. end;
  10697. procedure TDefineGroupBox.WMSize(var Message: TWMSize);
  10698. begin
  10699. inherited;
  10700. if FTransparent then Invalidate;
  10701. end;
  10702. procedure TDefineGroupBox.SetAlignment(const Value: TAlignmentText);
  10703. begin
  10704. if FAlignment <> Value then
  10705. begin
  10706. FAlignment := Value;
  10707. Invalidate;
  10708. end;
  10709. end;
  10710. procedure TDefineGroupBox.AdjustClientRect(var Rect: TRect);
  10711. begin
  10712. inherited AdjustClientRect(Rect);
  10713. Canvas.Font := Font;
  10714. Inc(Rect.Top, Canvas.TextHeight('0'));
  10715. InflateRect(Rect, -1, -1);
  10716. if Ctl3d then InflateRect(Rect, -1, -1);
  10717. end;
  10718. { TDefineListBox }
  10719. var
  10720. ScrollTimer: TTimer = nil;
  10721. const
  10722. FTimerInterval = 600;
  10723. FScrollSpeed = 100;
  10724. procedure DrawScrollBar(control:TControl; Focused:boolean; canvas: TCanvas; BarsRect: TBarsRect; Style: TFlatSkin;
  10725. FirstItem, MaxItems, ItemsCount: Integer; Enabled: Boolean);
  10726. var
  10727. x, y: Integer;
  10728. procedure DrawImage;
  10729. begin
  10730. with Style, BarsRect do begin
  10731. if not BarUseBitmap then
  10732. begin
  10733. if UserFace = fsDefault then
  10734. begin
  10735. canvas.Brush.Color := BarColor;
  10736. canvas.FillRect(prevRect);
  10737. canvas.FillRect(downRect);
  10738. end else begin
  10739. DrawBackdrop(Canvas,BarStartColor,BarStopColor,prevRect,BarOrien);
  10740. case Style.BarOrien of
  10741. bsHorizontal:DrawBackdrop(Canvas,BarStartColor,BarStopColor,downRect,BarOrien); //水平
  10742. bsVertical :DrawBackdrop(Canvas,BarStopColor,BarStartColor,downRect,BarOrien); //垂直
  10743. end;
  10744. end;
  10745. end else begin
  10746. DrawBitmap(Canvas,prevRect,BarTopBitmap);
  10747. DrawBitmap(Canvas,downRect,BarDownBitmap);
  10748. end;
  10749. end;
  10750. end;
  10751. begin
  10752. // 画滚动条背景
  10753. with Style,BarsRect do begin
  10754. case Transparent of
  10755. tmAlways: DrawParentImage(control, Canvas);
  10756. tmNone: DrawImage;
  10757. tmNotFocused: if Focused then
  10758. DrawImage
  10759. else
  10760. DrawParentImage(control, Canvas);
  10761. end;
  10762. // 画滚动条边框
  10763. canvas.Brush.Color := BorderColor;
  10764. canvas.FrameRect(prevRect);
  10765. canvas.FrameRect(downRect);
  10766. // Draw the up arrow
  10767. x := (prevRect.Right - prevRect.Left) div 2 - 6;
  10768. y := prevRect.Top + 4;
  10769. if (firstItem <> 0) and Enabled then
  10770. begin
  10771. canvas.Brush.Color := BarArrowColor;
  10772. canvas.Pen.Color := BarArrowColor;
  10773. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)]);
  10774. end
  10775. else
  10776. begin
  10777. canvas.Brush.Color := clWhite;
  10778. canvas.Pen.Color := clWhite;
  10779. Inc(x); Inc(y);
  10780. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)]);
  10781. Dec(x); Dec(y);
  10782. canvas.Brush.Color := clGray;
  10783. canvas.Pen.Color := clGray;
  10784. canvas.Polygon([Point(x + 4, y + 2), Point(x + 8, y + 2), Point(x + 6, y)]);
  10785. end;
  10786. // Draw the down arrow
  10787. x := (downRect.Right - downRect.Left) div 2 - 6;
  10788. y := downRect.Bottom - 7;
  10789. if (firstItem + maxItems + 1 <= ItemsCount) and Enabled then
  10790. begin
  10791. canvas.Brush.Color := BarArrowColor;
  10792. canvas.Pen.Color := BarArrowColor;
  10793. canvas.Polygon([Point(X + 4, Y), Point(X + 8, Y), Point(X + 6, Y + 2)]);
  10794. end
  10795. else
  10796. begin
  10797. canvas.Brush.Color := clWhite;
  10798. canvas.Pen.Color := clWhite;
  10799. Inc(x); Inc(y);
  10800. canvas.Polygon([Point(X + 4, Y), Point(X + 8, Y), Point(X + 6, Y + 2)]);
  10801. Dec(x); Dec(y);
  10802. canvas.Brush.Color := clGray;
  10803. canvas.Pen.Color := clGray;
  10804. canvas.Polygon([Point(X + 4, Y), Point(X + 8, Y), Point(X + 6, Y + 2)]);
  10805. end;
  10806. end;
  10807. end;
  10808. function CurItemRect(CurPos:TPoint;CurRect:TRect;ItemHeight:integer):TRect;
  10809. begin
  10810. result := Rect(CurPos.x, CurPos.y, CurRect.Right - 3, CurPos.y + ItemHeight);
  10811. end;
  10812. procedure CreateRects(List:TList;MaxItems,ItemHeight:integer;CurPos:TPoint;CurRect:TRect);
  10813. var
  10814. ItemRect: ^TRect;
  10815. inx:integer;
  10816. begin
  10817. RemoveList(List);
  10818. for inx := 0 to MaxItems - 1 do
  10819. begin
  10820. New(ItemRect);
  10821. ItemRect^ := CurItemRect(CurPos,CurRect,ItemHeight);
  10822. List.Add(ItemRect);
  10823. CurPos := Point(CurPos.x, CurPos.y + ItemHeight + 2);
  10824. end;
  10825. end;
  10826. constructor TDefineListBox.Create(AOwner: TComponent);
  10827. begin
  10828. if ScrollTimer = nil then begin
  10829. ScrollTimer := TTimer.Create(nil);
  10830. ScrollTimer.Enabled := False;
  10831. ScrollTimer.Interval := FTimerInterval;
  10832. end;
  10833. inherited Create(AOwner);
  10834. ControlStyle := ControlStyle + [csOpaque];
  10835. SetBounds(0, 0, 140, 158);
  10836. ParentColor := True;
  10837. ParentFont := True;
  10838. Enabled := true;
  10839. Visible := true;
  10840. TabStop := True;
  10841. FStyle := TListStyle.Create;
  10842. FStyle.Parent := self;
  10843. FStyle.OnChange := StyleChange;
  10844. FItems := TStringList.Create;
  10845. //FItems := TListBoxStrings.Create;
  10846. //TListBoxStrings(FItems).ListBox := Self;
  10847. FItems.OnChange := StyleChange;
  10848. FRects := TList.Create;
  10849. FChecks := TList.Create;
  10850. FMultiSelect := false;
  10851. FSorted := false;
  10852. FirstItem := 0;
  10853. FItemIndex := -1;
  10854. FCaption := '';
  10855. end;
  10856. destructor TDefineListBox.Destroy;
  10857. begin
  10858. ScrollTimer.Free;
  10859. ScrollTimer := nil;
  10860. //释放 FRect
  10861. RemoveList(FRects, lsFree);
  10862. //释放 FChecks
  10863. RemoveList(FChecks, lsFree);
  10864. FItems.Free;
  10865. FStyle.Free;
  10866. inherited Destroy;
  10867. end;
  10868. procedure TDefineListBox.WMMouseWheel(var Message: TMessage);
  10869. var
  10870. fScrollLines: Integer;
  10871. begin
  10872. if not(csDesigning in ComponentState) then
  10873. begin
  10874. SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @fScrollLines, 0);
  10875. if(fScrollLines = 0) then
  10876. fScrollLines := MaxItems;
  10877. if ShortInt(Message.WParamHi) = -WHEEL_DELTA then
  10878. if FirstItem + MaxItems + fScrollLines <= FItems.Count then
  10879. Inc(FirstItem, fScrollLines)
  10880. else
  10881. if FItems.Count - MaxItems < 0 then
  10882. FirstItem := 0
  10883. else
  10884. FirstItem := FItems.Count - MaxItems
  10885. else
  10886. if ShortInt(Message.WParamHi) = WHEEL_DELTA then
  10887. if FirstItem - fScrollLines < 0 then
  10888. FirstItem := 0
  10889. else
  10890. dec(FirstItem, fScrollLines);
  10891. Invalidate;
  10892. end;
  10893. end;
  10894. function TDefineListBox.GetItemText: TCaption;
  10895. begin
  10896. if IndexInCount(FItemIndex,FItems.Count) then
  10897. result := FItems.Strings[FItemIndex]
  10898. else
  10899. result := '';
  10900. end;
  10901. function TDefineListBox.Find(Value: String; var Index: Integer): boolean;
  10902. begin
  10903. result := false;
  10904. index := -1;
  10905. while(index < Items.Count) and(not result) do begin
  10906. inc(Index);
  10907. if IndexInCount(Index,Items.Count) then
  10908. result := Items.Strings[index]=Value;
  10909. end;
  10910. end;
  10911. function TDefineListBox.FindChecked(Value:Integer; var index:integer):boolean;
  10912. var inx:integer;
  10913. tmp:^Integer;
  10914. begin
  10915. inx := 0;
  10916. result := false;
  10917. while (inx < FChecks.Count)and(not result) do
  10918. begin
  10919. tmp := FChecks.Items[inx];
  10920. result := Tmp^ = Value;
  10921. if result then index := inx else index := -1;
  10922. inc(inx);
  10923. end;
  10924. end;
  10925. procedure TDefineListBox.AddCheck(Index:integer);
  10926. var inx:^Integer;
  10927. x:integer;
  10928. begin
  10929. if not FindChecked(index,x) then begin
  10930. new(inx);
  10931. inx^:=Index;
  10932. FChecks.Add(inx);
  10933. end;
  10934. end;
  10935. procedure TDefineListBox.DeleteChecked(Index:Integer);
  10936. begin
  10937. Dispose(FChecks.Items[index]);
  10938. FChecks.Delete(index);
  10939. end;
  10940. procedure TDefineListBox.Click;
  10941. begin
  10942. inherited Click;
  10943. if not Focused then SetFocus;
  10944. if assigned(FOnClick) and IndexInCount(FItemIndex,FItems.Count) then begin
  10945. FOnClick(self,FItems.Strings[FItemIndex]);
  10946. end;
  10947. end;
  10948. procedure TDefineListBox.SetSorted(Value: Boolean);
  10949. begin
  10950. if Value <> FSorted then
  10951. begin
  10952. FSorted := Value;
  10953. FItems.Sorted := Value;
  10954. Invalidate;
  10955. end;
  10956. end;
  10957. procedure TDefineListBox.SetItems(Value: TStringList);
  10958. begin
  10959. FItems.Assign(Value);
  10960. end;
  10961. procedure TDefineListBox.SetItemsRect;
  10962. var
  10963. CurPos: TPoint;
  10964. curRect: TRect;
  10965. begin
  10966. CurRect := ClientRect;
  10967. with FStyle do begin
  10968. if TitleHas then begin
  10969. case TitlePosition of
  10970. tsTop : CurRect.Top := CurRect.Top + TitleHeight;
  10971. tsBottom: CurRect.Bottom := CurRect.Bottom - TitleHeight;
  10972. end;
  10973. end;
  10974. // set left/top PosR for the the first item
  10975. if ScrollBars then
  10976. CurPos := Point(CurRect.left + 3, CurRect.top + 3 + BarsHeight)
  10977. else
  10978. CurPos := Point(CurRect.left + 3, CurRect.top + 3);
  10979. // recreate all items-rect
  10980. CreateRects(FRects,MaxItems,ItemHeight,CurPos,CurRect);
  10981. end;
  10982. Invalidate;
  10983. end;
  10984. function TDefineListBox.GetSelected(Index: Integer): Boolean;
  10985. begin
  10986. Result := FindChecked(index, FItemIndex);
  10987. end;
  10988. procedure TDefineListBox.SetSelected(Index: Integer; Value: Boolean);
  10989. var inx:Integer;
  10990. begin
  10991. if MultiSelect then
  10992. begin
  10993. if FindChecked(Index , inx) and Value then
  10994. DeleteChecked(inx)
  10995. else
  10996. AddCheck(index);
  10997. end else begin
  10998. RemoveList(FChecks);
  10999. FChecks.Clear;
  11000. end;
  11001. Invalidate;
  11002. end;
  11003. function TDefineListBox.GetSelCount: Integer;
  11004. begin
  11005. if MultiSelect then
  11006. Result := FChecks.Count
  11007. else
  11008. Result := -1;
  11009. end;
  11010. procedure TDefineListBox.Paint;
  11011. var
  11012. memBitmap: TBitmap;
  11013. inxRect, inxItem, CurIndex: Integer;
  11014. itemRect: ^TRect;
  11015. Format, TitleFormat: UINT;
  11016. WorkRect, TitleRect:TRect;
  11017. BarsRect: TBarsRect;
  11018. curState: Boolean;
  11019. procedure DrawImage(Canvas:TCanvas;Skin:TListStyle;WorkRect,TitleRect:TRect;TitleHas:Boolean);
  11020. begin
  11021. with Skin do begin
  11022. //draw backgroud
  11023. if not BackUseBitmap then
  11024. begin
  11025. if (Enabled)and(Focused or MouseIn) then
  11026. BoxDrawBackDrop(Canvas,BackStartColor,BackStopColor,BackdropOrien,WorkRect,BackdropColor,UserFace)
  11027. else
  11028. BoxDrawBackDrop(Canvas,BackStartColor,BackStopColor,BackdropOrien,WorkRect,BackFocusColor,UserFace);
  11029. end
  11030. else
  11031. DrawBitmap(Canvas,WorkRect,BackBitmap);
  11032. //draw title backgroud
  11033. if TitleHas then
  11034. begin
  11035. if not TitleUseBitmap then
  11036. BoxDrawBackDrop(Canvas,TitleStartColor,TitleStopColor,TitleOrien,TitleRect,TitleColor,UserFace)
  11037. else
  11038. DrawBitmap(Canvas,TitleRect,TitleBitmap);
  11039. end;
  11040. end;
  11041. end;
  11042. begin
  11043. // create memory-bitmap to draw flicker-free
  11044. memBitmap := TBitmap.Create;
  11045. try
  11046. memBitmap.Height := ClientRect.Bottom;
  11047. memBitmap.Width := ClientRect.Right;
  11048. //控制区域
  11049. WorkRect := ClientRect;
  11050. TitleRect := ClientRect;
  11051. with FStyle do begin
  11052. if TitleHas then begin
  11053. case TitlePosition of
  11054. tsTop : begin
  11055. WorkRect.Top := WorkRect.Top + TitleHeight;
  11056. TitleRect.Bottom := TitleRect.Top + TitleHeight;
  11057. end;
  11058. tsBottom : begin
  11059. WorkRect.Bottom := WorkRect.Bottom - TitleHeight;
  11060. TitleRect.Top := TitleRect.Bottom - TitleHeight;
  11061. end;
  11062. end;
  11063. end;
  11064. with BarsRect do begin
  11065. if ScrollBars then begin
  11066. prevRect := Rect(WorkRect.Left, WorkRect.Top, WorkRect.Right, WorkRect.Top + BarsHeight);
  11067. downRect := Rect(WorkRect.Left, WorkRect.Bottom - BarsHeight, WorkRect.Right, WorkRect.Bottom);
  11068. workRect := Rect(workRect.Left, workRect.Top + BarsHeight, workRect.Right, workRect.Bottom - BarsHeight);
  11069. end;
  11070. end;
  11071. GetStyleText(ItemAlignment, Format);
  11072. GetStyleText(TitleAlignment,TitleFormat);
  11073. // Clear Background
  11074. case Transparent of
  11075. tmAlways: DrawParentImage(Self, memBitmap.Canvas);
  11076. tmNone: DrawImage(memBitmap.Canvas,FStyle,WorkRect,TitleRect,TitleHas);
  11077. tmNotFocused: if Focused then
  11078. DrawImage(memBitmap.Canvas,FStyle,WorkRect,TitleRect,TitleHas)
  11079. else
  11080. DrawParentImage(Self, memBitmap.Canvas);
  11081. end;
  11082. //Draw ScrollBars
  11083. if ScrollBars then begin
  11084. DrawScrollBar(self, Focused, memBitmap.Canvas, BarsRect, FStyle, FirstItem, MaxItems, FItems.Count, Enabled);
  11085. end;
  11086. // Draw Border
  11087. memBitmap.Canvas.Brush.Color := BorderColor;
  11088. memBitmap.Canvas.FrameRect(ClientRect);
  11089. // Draw Focused Frame
  11090. if(fItems.Count <=0)and(Focused) then
  11091. DrawFocusRect(memBitmap.Canvas,WorkRect,ItemHeight);
  11092. // draw titletext
  11093. if TitleHas then begin
  11094. MemBitmap.Canvas.Font.Assign(FStyle.TitleFont);
  11095. FlatDrawText(memBitmap.Canvas, Enabled, FCaption, TitleRect, TitleFormat);
  11096. end;
  11097. end;
  11098. // Initialize the counter for the Items
  11099. memBitmap.Canvas.Font.Assign(Self.Font);
  11100. inxItem := FirstItem;
  11101. // Draw Items
  11102. for inxRect := 0 to MaxItems - 1 do
  11103. begin
  11104. itemRect := FRects.Items[inxRect];
  11105. if(inxItem <= FItems.Count - 1) then
  11106. begin
  11107. // Item is selected
  11108. CurState := FindChecked(inxItem, CurIndex);
  11109. with FStyle do begin
  11110. // Draw ItemBorder
  11111. if ItemLineHas then
  11112. begin
  11113. memBitmap.Canvas.Brush.color := ItemLineColor;
  11114. memBitmap.Canvas.FrameRect(itemRect^);
  11115. end;
  11116. if inxItem = FItemIndex then
  11117. begin
  11118. // Fill ItemRect
  11119. BoxDrawBackDrop(memBitmap.Canvas,ItemStartColor,ItemStopColor,ItemOrien, itemRect^, ItemSelectColor,UserFace);
  11120. if Focused and (not MultiSelect) then
  11121. DrawFocusRect(memBitmap.Canvas,itemRect^,ItemHeight);
  11122. memBitmap.Canvas.Brush.color := ItemFrameColor;
  11123. memBitmap.Canvas.FrameRect(itemRect^);
  11124. end else if CurState then begin
  11125. BoxDrawBackDrop(memBitmap.Canvas,ItemStartColor,ItemStopColor,bsVertical, itemRect^, ItemSelectColor,UserFace);
  11126. end;
  11127. end;
  11128. // Draw ItemText
  11129. FlatDrawText(memBitmap.Canvas, Enabled, FItems[inxItem], itemRect^, Format);
  11130. // draw next Item
  11131. Inc(inxItem);
  11132. end;
  11133. end;
  11134. // Copy bitmap to screen
  11135. Canvas.CopyRect(ClientRect, memBitmap.Canvas, ClientRect);
  11136. finally
  11137. // delete the memory bitmap
  11138. memBitmap.free;
  11139. end;
  11140. end;
  11141. procedure TDefineListBox.SelectNotifyEvent;
  11142. begin
  11143. if assigned(FOnChange) and IndexInCount(FItemIndex,FItems.Count) then FOnChange(self,FItems.Strings[FItemIndex]);
  11144. if assigned(FOnClick) and IndexInCount(FItemIndex,FItems.Count) then FOnClick(self,FItems.Strings[FItemIndex]);
  11145. end;
  11146. procedure TDefineListBox.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  11147. var
  11148. curPos: TPoint;
  11149. inxRect: Integer;
  11150. curRect: ^TRect;
  11151. BarsRect: TBarsRect;
  11152. begin
  11153. GetCursorPos(curPos);
  11154. curPos := ScreenToClient(curPos);
  11155. with FStyle do
  11156. begin
  11157. if(FItems.Count > 0) and(Button = mbLeft) then
  11158. begin
  11159. for inxRect := 0 to FRects.Count - 1 do
  11160. begin
  11161. curRect := FRects.Items[inxRect];
  11162. if PtInRect(curRect^, curPos) then
  11163. begin
  11164. FItemIndex := FirstItem + inxRect;
  11165. SetSelected(FItemIndex,True);
  11166. SetFocus;
  11167. Invalidate;
  11168. Exit;
  11169. end;
  11170. end;
  11171. end;
  11172. if ScrollBars then
  11173. begin
  11174. GetBarPosition(ClientRect,TitleHas,TitlePosition,BarsRect,TitleHeight,BarsHeight);
  11175. if PtInRect(BarsRect.prevRect, curPos) then
  11176. begin
  11177. if (FirstItem - 1) < 0 then
  11178. FirstItem := 0
  11179. else
  11180. Dec(FirstItem);
  11181. SetFocus;
  11182. Invalidate;
  11183. scrollType := stUp;
  11184. if ScrollTimer.Enabled then
  11185. ScrollTimer.Enabled := False;
  11186. ScrollTimer.OnTimer := ScrollTimerHandler;
  11187. ScrollTimer.Enabled := True;
  11188. end;
  11189. if PtInRect(BarsRect.downRect, curPos) then
  11190. begin
  11191. if FirstItem + MaxItems + 1 <= FItems.Count then
  11192. Inc(FirstItem);
  11193. SetFocus;
  11194. Invalidate;
  11195. scrollType := stDown;
  11196. if ScrollTimer.Enabled then
  11197. ScrollTimer.Enabled := False;
  11198. ScrollTimer.OnTimer := ScrollTimerHandler;
  11199. ScrollTimer.Enabled := True;
  11200. end;
  11201. end;
  11202. end;
  11203. Inherited;
  11204. end;
  11205. procedure TDefineListBox.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  11206. begin
  11207. ScrollTimer.Enabled := False;
  11208. ScrollTimer.Interval := FTimerInterval;
  11209. inherited MouseUp(Button, Shift, X, Y);
  11210. end;
  11211. procedure TDefineListBox.ScrollTimerHandler(Sender: TObject);
  11212. begin
  11213. ScrollTimer.Interval := FScrollSpeed;
  11214. if scrollType = stUp then
  11215. if(FirstItem - 1) < 0 then
  11216. begin
  11217. FirstItem := 0;
  11218. ScrollTimer.Enabled := False;
  11219. end
  11220. else
  11221. Dec(FirstItem)
  11222. else
  11223. if FirstItem + MaxItems + 1 <= FItems.Count then
  11224. Inc(FirstItem)
  11225. else
  11226. ScrollTimer.Enabled := False;
  11227. Invalidate;
  11228. end;
  11229. procedure TDefineListBox.Loaded;
  11230. begin
  11231. inherited;
  11232. SetItemsRect;
  11233. end;
  11234. procedure TDefineListBox.WMSize(var Message: TWMSize);
  11235. var y,inx:integer;
  11236. begin
  11237. inherited;
  11238. with FStyle do begin
  11239. y := 2;
  11240. for inx := 1 to MaxItems do
  11241. y := y +(ItemHeight + 2);
  11242. y := y + 2;
  11243. if ScrollBars then
  11244. y := y + BarsHeight * 2;
  11245. if TitleHas then
  11246. y := y + TitleHeight;
  11247. if not(csLoading in ComponentState) then
  11248. SetBounds(Left,Top,Width,y);
  11249. end;
  11250. // Recalculate the itemRects
  11251. SetItemsRect;
  11252. end;
  11253. procedure TDefineListBox.WMMove(var Message: TWMMove);
  11254. begin
  11255. inherited;
  11256. if not(FStyle.Transparent = tmNone) then
  11257. Invalidate;
  11258. end;
  11259. procedure TDefineListBox.WMKillFocus(var Message: TWMKillFocus);
  11260. begin
  11261. inherited;
  11262. FMouseIn := False;
  11263. if IndexInCount(FItemIndex, FItems.Count) then
  11264. SetSelected(FItemIndex,False);
  11265. Invalidate;
  11266. end;
  11267. procedure TDefineListBox.WMSetFocus(var Message: TWMSetFocus);
  11268. begin
  11269. inherited;
  11270. if FItemIndex >= 0 then
  11271. SetSelected(FItemIndex,True)
  11272. else if FItems.Count > 0 then begin
  11273. FItemIndex := 0;
  11274. SetSelected(FItemIndex,True);
  11275. end;
  11276. Invalidate;
  11277. end;
  11278. procedure TDefineListBox.WMKeyDown(var Message: TWMKeyDown);
  11279. begin
  11280. case Message.CharCode of
  11281. VK_UP: begin
  11282. if(FirstItem - 1) < 0 then
  11283. FirstItem := 0
  11284. else
  11285. Dec(FirstItem);
  11286. if FItems.Count > 0 then begin
  11287. if FItemIndex > 0 then
  11288. Dec(FItemIndex)
  11289. else
  11290. FItemIndex := 0;
  11291. //SetSelected(FItemIndex,True);
  11292. SelectNotifyEvent;
  11293. end;
  11294. end;
  11295. VK_DOWN:begin
  11296. if FirstItem + MaxItems + 1 <= FItems.Count then
  11297. Inc(FirstItem);
  11298. if FItems.Count > 0 then begin
  11299. if FItemIndex < FItems.Count-1 then
  11300. Inc(FItemIndex)
  11301. else
  11302. FItemIndex := FItems.Count-1;
  11303. //SetSelected(FItemIndex,True);
  11304. SelectNotifyEvent;
  11305. end;
  11306. end;
  11307. VK_PRIOR:
  11308. if(FirstItem - MaxItems) < 0 then
  11309. FirstItem := 0
  11310. else
  11311. Dec(FirstItem, MaxItems);
  11312. VK_NEXT:
  11313. if FirstItem +(MaxItems * 2) <= FItems.Count then
  11314. Inc(FirstItem, MaxItems)
  11315. else
  11316. FirstItem := FItems.Count - MaxItems;
  11317. VK_SPACE: begin
  11318. SetSelected(FItemIndex,True);
  11319. SelectNotifyEvent;
  11320. end;
  11321. else
  11322. inherited;
  11323. end;
  11324. Invalidate;
  11325. end;
  11326. function TDefineListBox.GetItemIndex: Integer;
  11327. begin
  11328. Result := FItemIndex;
  11329. end;
  11330. procedure TDefineListBox.SetItemIndex(Value: Integer);
  11331. begin
  11332. if GetItemIndex <> Value then
  11333. begin
  11334. FItemIndex := Value;
  11335. Invalidate;
  11336. end;
  11337. end;
  11338. procedure TDefineListBox.SetMultiSelect(Value: Boolean);
  11339. begin
  11340. FMultiSelect := Value;
  11341. if Value then
  11342. FItemIndex := 0;
  11343. end;
  11344. procedure TDefineListBox.SetName(const Value: TComponentName);
  11345. begin
  11346. if(csDesigning in ComponentState) and((Length(FCaption) = 0) or
  11347. (CompareText(FCaption, Name) = 0)) then
  11348. FCaption := Value;
  11349. inherited SetName(Value);
  11350. end;
  11351. procedure TDefineListBox.SetListStyle(const Value: TListStyle);
  11352. begin
  11353. FStyle.Assign(Value);
  11354. end;
  11355. procedure TDefineListBox.StyleChange(Sender: TObject);
  11356. begin
  11357. SetItemsRect;
  11358. Invalidate;
  11359. end;
  11360. function TDefineListBox.GetMaxItems: Integer;
  11361. begin
  11362. result := ClientRect.Bottom - ClientRect.Top;
  11363. with FStyle do begin
  11364. if TitleHas then
  11365. result := result - TitleHeight;
  11366. if ScrollBars then
  11367. result := result - BarsHeight * 2;
  11368. result :=(result - 4) div(ItemHeight + 2);
  11369. end;
  11370. end;
  11371. procedure TDefineListBox.SetCaption(const Value: TCaption);
  11372. begin
  11373. if FCaption <> Value then
  11374. begin
  11375. FCaption := Value;
  11376. Invalidate;
  11377. end;
  11378. end;
  11379. procedure TDefineListBox.WMEnabledChanged(var Message: TMessage);
  11380. begin
  11381. inherited;
  11382. Invalidate;
  11383. end;
  11384. procedure TDefineListBox.Clear;
  11385. begin
  11386. RemoveList(FChecks);
  11387. RemoveList(FRects);
  11388. FItems.Clear;
  11389. end;
  11390. procedure TDefineListBox.CMParentFontChanged(var Message: TMessage);
  11391. begin
  11392. inherited;
  11393. if ParentFont and Assigned(FStyle) then
  11394. begin
  11395. if FStyle.ParentFont then
  11396. FStyle.TitleFont.Assign(Font);
  11397. end;
  11398. end;
  11399. procedure TDefineListBox.CMFontChanged(var Message: TMessage);
  11400. begin
  11401. inherited;
  11402. if Assigned(FStyle) then
  11403. begin
  11404. if FStyle.ParentFont then
  11405. FStyle.TitleFont.Assign(Font);
  11406. end;
  11407. end;
  11408. function TDefineListBox.GetItemCount: Integer;
  11409. begin
  11410. result := Items.Count;
  11411. end;
  11412. procedure TDefineListBox.CMMouseEnter(var Message: TMessage);
  11413. begin
  11414. inherited;
  11415. if not(csDesigning in ComponentState) and
  11416. (GetActiveWindow <> 0) and (not MouseIn) then
  11417. begin
  11418. FMouseIn := True;
  11419. Invalidate;
  11420. end;
  11421. end;
  11422. procedure TDefineListBox.CMMouseLeave(var Message: TMessage);
  11423. begin
  11424. inherited;
  11425. if MouseIn then begin
  11426. FMouseIn := false;
  11427. Invalidate;
  11428. end;
  11429. end;
  11430. function TDefineListBox.GetMouseIn: Boolean;
  11431. begin
  11432. Result := FMouseIn;
  11433. end;
  11434. { TDefineListChecks }
  11435. constructor TDefineListChecks.Create(AOwner: TComponent);
  11436. begin
  11437. if ScrollTimer = nil then begin
  11438. ScrollTimer := TTimer.Create(nil);
  11439. ScrollTimer.Enabled := False;
  11440. ScrollTimer.Interval := FTimerInterval;
  11441. end;
  11442. inherited Create(AOwner);
  11443. ControlStyle := ControlStyle + [csOpaque];
  11444. SetBounds(0, 0, 140, 158);
  11445. ParentColor := True;
  11446. ParentFont := True;
  11447. Enabled := true;
  11448. TabStop := True;
  11449. Visible := true;
  11450. FStyle := TCheckStyle.Create;
  11451. FStyle.Parent := self;
  11452. FStyle.OnChange := StyleChange;
  11453. FItems := TStringList.Create;
  11454. FItems.OnChange := StyleChange;
  11455. FRects := TList.Create;
  11456. FChecks := TList.Create;
  11457. FSorted := false;
  11458. FSelected := -1;
  11459. FirstItem := 0;
  11460. FCaption := '';
  11461. end;
  11462. destructor TDefineListChecks.Destroy;
  11463. begin
  11464. ScrollTimer.Free;
  11465. ScrollTimer := nil;
  11466. //释放 FRect
  11467. RemoveList(FRects, lsFree);
  11468. //释放 FChecks
  11469. RemoveList(FChecks, lsFree);
  11470. FItems.Free;
  11471. FStyle.Free;
  11472. inherited Destroy;
  11473. end;
  11474. procedure TDefineListChecks.WMMouseWheel(var Message: TMessage);
  11475. var
  11476. fScrollLines: Integer;
  11477. begin
  11478. if not(csDesigning in ComponentState) then
  11479. begin
  11480. SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, @fScrollLines, 0);
  11481. if(fScrollLines = 0) then
  11482. fScrollLines := MaxItems;
  11483. if ShortInt(Message.WParamHi) = -WHEEL_DELTA then
  11484. if FirstItem + MaxItems + fScrollLines <= FItems.Count then
  11485. Inc(FirstItem, fScrollLines)
  11486. else
  11487. if FItems.Count - MaxItems < 0 then
  11488. FirstItem := 0
  11489. else
  11490. FirstItem := FItems.Count - MaxItems
  11491. else
  11492. if ShortInt(Message.WParamHi) = WHEEL_DELTA then
  11493. if FirstItem - fScrollLines < 0 then
  11494. FirstItem := 0
  11495. else
  11496. dec(FirstItem, fScrollLines);
  11497. Invalidate;
  11498. end;
  11499. end;
  11500. procedure TDefineListChecks.SetSorted(Value: Boolean);
  11501. begin
  11502. if Value <> FSorted then
  11503. begin
  11504. FSorted := Value;
  11505. FItems.Sorted := Value;
  11506. Invalidate;
  11507. end;
  11508. end;
  11509. procedure TDefineListChecks.SetItems(Value: TStringList);
  11510. begin
  11511. FItems.Assign(Value);
  11512. end;
  11513. procedure TDefineListChecks.SetItemsRect;
  11514. var
  11515. CurPos: TPoint;
  11516. CurRect:TRect;
  11517. begin
  11518. CurRect := ClientRect;
  11519. with FStyle do begin
  11520. if TitleHas then begin
  11521. case TitlePosition of
  11522. tsTop : CurRect.Top := CurRect.Top + TitleHeight;
  11523. tsBottom: CurRect.Bottom := CurRect.Bottom - TitleHeight;
  11524. end;
  11525. end;
  11526. // set left/top PosR for the the first item
  11527. if ScrollBars then
  11528. CurPos := Point(CurRect.left + 3, CurRect.top + 3 + BarsHeight)
  11529. else
  11530. CurPos := Point(CurRect.left + 3, CurRect.top + 3);
  11531. // Recreate all Item - Rects
  11532. CreateRects(FRects,MaxItems,ItemHeight,CurPos,CurRect);
  11533. end;
  11534. Invalidate;
  11535. end;
  11536. function TDefineListChecks.GetChecked(Index: Integer): Boolean;
  11537. begin
  11538. Result := FindChecked(index, FSelected);
  11539. end;
  11540. procedure TDefineListChecks.SetChecked(Index: Integer; Value: Boolean);
  11541. var inx:integer;
  11542. begin
  11543. if FindChecked(Index,inx) and Value then
  11544. DeleteChecked(inx)
  11545. else begin
  11546. AddCheck(index);
  11547. end;
  11548. Invalidate;
  11549. end;
  11550. function TDefineListChecks.GetSelCount: Integer;
  11551. begin
  11552. result := FChecks.Count;
  11553. end;
  11554. procedure TDefineListChecks.DrawCheckRect(Canvas: TCanvas; StartRect: TRect; checked: Boolean);
  11555. var
  11556. CheckBox: TRect;
  11557. begin
  11558. DrawCheckBox(StartRect,FStyle.SelectPosition,FStyle.SelectSize,CheckBox);
  11559. with Canvas do begin
  11560. Pen.style := psSolid;
  11561. Pen.width := 1;
  11562. // 画背景
  11563. Brush.color := FStyle.BackdropColor;
  11564. FillRect(Checkbox);
  11565. // 画选定
  11566. if Checked then
  11567. begin
  11568. DrawInCheck(Canvas, CheckBox, FStyle.BorderColor);
  11569. end;
  11570. // 画边框
  11571. Brush.color := FStyle.BorderColor;
  11572. FrameRect(Checkbox);
  11573. end;
  11574. end;
  11575. procedure TDefineListChecks.Paint;
  11576. var
  11577. memBitmap: TBitmap;
  11578. inxRect, inxItem: Integer;
  11579. itemRect: ^TRect;
  11580. Format, TitleFormat: UINT;
  11581. WorkRect, TitleRect:TRect;
  11582. BarsRect: TBarsRect;
  11583. curIndex: integer;
  11584. curState: boolean;
  11585. procedure DrawImage(Canvas:TCanvas;Skin:TCheckStyle;WorkRect,TitleRect:TRect;TitleHas:Boolean);
  11586. begin
  11587. with Skin do begin
  11588. //draw backgroud
  11589. if not BackUseBitmap then
  11590. begin
  11591. if (Enabled)and(Focused or MouseIn) then
  11592. BoxDrawBackDrop(Canvas,BackStartColor,BackStopColor,BackdropOrien,WorkRect,BackdropColor,UserFace)
  11593. else
  11594. BoxDrawBackDrop(Canvas,BackStartColor,BackStopColor,BackdropOrien,WorkRect,BackFocusColor,UserFace);
  11595. end
  11596. else
  11597. DrawBitmap(Canvas,WorkRect,BackBitmap);
  11598. //draw title backgroud
  11599. if TitleHas then
  11600. begin
  11601. if not TitleUseBitmap then
  11602. BoxDrawBackDrop(Canvas,TitleStartColor,TitleStopColor,TitleOrien,TitleRect,TitleColor,UserFace)
  11603. else
  11604. DrawBitmap(Canvas,TitleRect,TitleBitmap);
  11605. end;
  11606. end;
  11607. end;
  11608. begin
  11609. // create memory-bitmap to draw flicker-free
  11610. memBitmap := TBitmap.Create;
  11611. try
  11612. memBitmap.Height := ClientRect.Bottom;
  11613. memBitmap.Width := ClientRect.Right;
  11614. //控制区域
  11615. WorkRect := ClientRect;
  11616. TitleRect := ClientRect;
  11617. with FStyle do begin
  11618. if TitleHas then begin
  11619. case TitlePosition of
  11620. tsTop : begin
  11621. WorkRect.Top := WorkRect.Top + TitleHeight;
  11622. TitleRect.Bottom := TitleRect.Top + TitleHeight;
  11623. end;
  11624. tsBottom : begin
  11625. WorkRect.Bottom := WorkRect.Bottom - TitleHeight;
  11626. TitleRect.Top := TitleRect.Bottom - TitleHeight;
  11627. end;
  11628. end;
  11629. end;
  11630. with BarsRect do begin
  11631. if ScrollBars then begin
  11632. prevRect := Rect(WorkRect.Left, WorkRect.Top, WorkRect.Right, WorkRect.Top + BarsHeight);
  11633. downRect := Rect(WorkRect.Left, WorkRect.Bottom - BarsHeight, WorkRect.Right, WorkRect.Bottom);
  11634. workRect := Rect(workRect.Left, workRect.Top + BarsHeight, workRect.Right, workRect.Bottom - BarsHeight);
  11635. end;
  11636. end;
  11637. //设置样式
  11638. GetStyleText(TitleAlignment, TitleFormat);
  11639. GetCheckBoxPosition(SelectPosition, Format);
  11640. // Clear Background
  11641. case Transparent of
  11642. tmAlways: DrawParentImage(Self, memBitmap.Canvas);
  11643. tmNone: DrawImage(memBitmap.Canvas,FStyle,WorkRect,TitleRect,TitleHas);
  11644. tmNotFocused: if Focused then
  11645. DrawImage(memBitmap.Canvas,FStyle,WorkRect,TitleRect,TitleHas)
  11646. else
  11647. DrawParentImage(Self, memBitmap.Canvas);
  11648. end;
  11649. // Draw ScrollBars
  11650. if ScrollBars then begin
  11651. DrawScrollBar(self, Focused, memBitmap.Canvas, BarsRect, FStyle, FirstItem, MaxItems, FItems.Count, Enabled);
  11652. end;
  11653. // Draw Border
  11654. memBitmap.Canvas.Brush.Color := BorderColor;
  11655. memBitmap.Canvas.FrameRect(ClientRect);
  11656. // Draw Focused Frame
  11657. if(fItems.Count <=0)and(Focused) then
  11658. DrawFocusRect(memBitmap.Canvas,WorkRect,ItemHeight);
  11659. // draw titletext
  11660. if TitleHas then begin
  11661. MemBitmap.Canvas.Font.Assign(FStyle.TitleFont);
  11662. FlatDrawText(memBitmap.Canvas, Enabled, FCaption, TitleRect, TitleFormat);
  11663. end;
  11664. end;
  11665. // Initialize the counter for the Items
  11666. memBitmap.Canvas.Font.Assign(Self.Font);
  11667. inxItem := FirstItem;
  11668. // Draw Items
  11669. for inxRect := 0 to MaxItems - 1 do
  11670. begin
  11671. itemRect := FRects.Items[inxRect];
  11672. if(inxItem <= FItems.Count - 1) then
  11673. begin
  11674. CurState := FindChecked(inxItem, CurIndex);
  11675. // Item is selected
  11676. with FStyle do begin
  11677. // Draw ItemBorder
  11678. if ItemLineHas then begin
  11679. memBitmap.Canvas.Brush.color := ItemLineColor;
  11680. memBitmap.Canvas.FrameRect(itemRect^);
  11681. end;
  11682. if inxItem = FSelected then begin
  11683. // Fill ItemRect
  11684. BoxDrawBackDrop(memBitmap.Canvas,ItemStartColor,ItemStopColor,ItemOrien,itemRect^, ItemSelectColor,UserFace);
  11685. // draw focused rect
  11686. if Focused then DrawFocusRect(memBitmap.Canvas,itemRect^,ItemHeight);
  11687. // Draw selected ItemBorder
  11688. memBitmap.Canvas.Brush.color := ItemFrameColor;
  11689. memBitmap.Canvas.FrameRect(itemRect^);
  11690. end else if CurState then begin
  11691. BoxDrawBackDrop(memBitmap.Canvas,SelectStartColor, SelectStopColor,SelectOrien, itemRect^, SelectCheckColor,UserFace);
  11692. end;
  11693. // Draw select box
  11694. DrawCheckRect(memBitmap.Canvas, itemRect^, CurState);
  11695. // Draw ItemText
  11696. case SelectPosition of
  11697. bpLeft : begin
  11698. itemRect^.Left := itemRect^.Left + SelectSize + 3;//16;
  11699. FlatDrawText(memBitmap.Canvas, Enabled, FItems[inxItem], itemRect^, Format);
  11700. itemRect^.Left := itemRect^.Left - SelectSize - 3;//16;
  11701. end;
  11702. bpRight : begin
  11703. itemRect^.Right := itemRect^.Right - SelectSize - 1;// 14;
  11704. FlatDrawText(memBitmap.Canvas, Enabled, FItems[inxItem], itemRect^, Format);
  11705. itemRect^.Right := itemRect^.Right + SelectSize + 1;//14;
  11706. end;
  11707. end;
  11708. end;
  11709. //end draw itemtext
  11710. Inc(inxItem);
  11711. end;
  11712. end;
  11713. // Copy bitmap to screen
  11714. Canvas.CopyRect(ClientRect, memBitmap.Canvas, ClientRect);
  11715. finally
  11716. // delete the memory bitmap
  11717. memBitmap.free;
  11718. end;
  11719. end;
  11720. function TDefineListChecks.FindChecked(Value:Integer; var index:integer):boolean;
  11721. var inx:integer;
  11722. tmp:^Integer;
  11723. begin
  11724. inx := 0;
  11725. result := false;
  11726. while (inx < FChecks.Count)and(not result) do
  11727. begin
  11728. tmp := FChecks.Items[inx];
  11729. result := Tmp^ = Value;
  11730. if result then index := inx else index := -1;
  11731. inc(inx);
  11732. end;
  11733. end;
  11734. procedure TDefineListChecks.AddCheck(Index:integer);
  11735. var inx:^Integer;
  11736. x:integer;
  11737. begin
  11738. if not FindChecked(index,x) then begin
  11739. new(inx);
  11740. inx^:=Index;
  11741. FChecks.Add(inx);
  11742. end;
  11743. end;
  11744. procedure TDefineListChecks.DeleteChecked(Index:Integer);
  11745. begin
  11746. dispose(FChecks.Items[index]);
  11747. FChecks.Delete(index);
  11748. end;
  11749. procedure TDefineListChecks.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  11750. var
  11751. curPos: TPoint;
  11752. inxRect,index: Integer;
  11753. curRect: ^TRect;
  11754. checkRect: TRect;
  11755. BarsRect: TBarsRect;
  11756. begin
  11757. GetCursorPos(curPos);
  11758. curPos := ScreenToClient(curPos);
  11759. with FStyle do begin
  11760. if(FItems.Count > 0) and(Button = mbLeft) then
  11761. begin
  11762. for inxRect := 0 to FRects.Count - 1 do
  11763. begin
  11764. curRect := FRects.Items[inxRect];
  11765. //获取点击区域
  11766. DrawCheckBox(curRect^, SelectPosition, SelectSize, checkRect);
  11767. //选中状态
  11768. if PtInRect(checkRect, curPos) then
  11769. begin
  11770. if FindChecked(FirstItem + inxRect, index) then
  11771. DeleteChecked(index)
  11772. else
  11773. AddCheck(FirstItem + inxRect);
  11774. SetFocus;
  11775. if Assigned(FOnClickCheck) then
  11776. FOnClickCheck(Self);
  11777. Invalidate;
  11778. Exit;
  11779. end else if PtInRect(curRect^, curPos) then begin
  11780. FSelected := FirstItem + inxRect;
  11781. SetFocus;
  11782. Invalidate;
  11783. Exit;
  11784. end;
  11785. end;
  11786. end;
  11787. if ScrollBars then
  11788. begin
  11789. GetBarPosition(ClientRect,TitleHas,TitlePosition,BarsRect,TitleHeight,BarsHeight);
  11790. if PtInRect(BarsRect.prevRect, curPos) then
  11791. begin
  11792. if(FirstItem - 1) < 0 then
  11793. FirstItem := 0
  11794. else
  11795. Dec(FirstItem);
  11796. SetFocus;
  11797. Invalidate;
  11798. scrollType := stUp;
  11799. if ScrollTimer.Enabled then
  11800. ScrollTimer.Enabled := False;
  11801. ScrollTimer.OnTimer := ScrollTimerHandler;
  11802. ScrollTimer.Enabled := True;
  11803. end;
  11804. if PtInRect(BarsRect.downRect, curPos) then
  11805. begin
  11806. if FirstItem + MaxItems + 1 <= FItems.Count then
  11807. Inc(FirstItem);
  11808. SetFocus;
  11809. Invalidate;
  11810. scrollType := stDown;
  11811. if ScrollTimer.Enabled then
  11812. ScrollTimer.Enabled := False;
  11813. ScrollTimer.OnTimer := ScrollTimerHandler;
  11814. ScrollTimer.Enabled := True;
  11815. end;
  11816. end;
  11817. end;
  11818. Inherited;
  11819. end;
  11820. procedure TDefineListChecks.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  11821. begin
  11822. ScrollTimer.Enabled := False;
  11823. ScrollTimer.Interval := FTimerInterval;
  11824. inherited MouseUp(Button, Shift, X, Y);
  11825. end;
  11826. procedure TDefineListChecks.ScrollTimerHandler(Sender: TObject);
  11827. begin
  11828. ScrollTimer.Interval := FScrollSpeed;
  11829. if scrollType = stUp then
  11830. if(FirstItem - 1) < 0 then
  11831. begin
  11832. FirstItem := 0;
  11833. ScrollTimer.Enabled := False;
  11834. end
  11835. else
  11836. Dec(FirstItem)
  11837. else
  11838. if FirstItem + MaxItems + 1 <= FItems.Count then
  11839. Inc(FirstItem)
  11840. else
  11841. ScrollTimer.Enabled := False;
  11842. Invalidate;
  11843. end;
  11844. procedure TDefineListChecks.Loaded;
  11845. begin
  11846. inherited;
  11847. SetItemsRect;
  11848. end;
  11849. procedure TDefineListChecks.WMSize(var Message: TWMSize);
  11850. var y,inx:integer;
  11851. begin
  11852. inherited;
  11853. with FStyle do begin
  11854. //reset clientrect size
  11855. y := 2;
  11856. for inx := 1 to MaxItems do
  11857. y := y +(ItemHeight + 2);
  11858. y := y + 2;
  11859. if ScrollBars then
  11860. y := y + BarsHeight * 2;
  11861. if TitleHas then
  11862. y := y + TitleHeight;
  11863. if not(csLoading in ComponentState) then
  11864. SetBounds(Left,Top,Width,y);
  11865. end;
  11866. // Recalculate the itemRects
  11867. SetItemsRect;
  11868. end;
  11869. procedure TDefineListChecks.WMMove(var Message: TWMMove);
  11870. begin
  11871. inherited;
  11872. if not(FStyle.Transparent = tmNone) then
  11873. Invalidate;
  11874. end;
  11875. procedure TDefineListChecks.Clear;
  11876. begin
  11877. RemoveList(FChecks);
  11878. RemoveList(FRects);
  11879. FItems.Clear;
  11880. FSelected := -1;
  11881. Invalidate;
  11882. end;
  11883. procedure TDefineListChecks.WMKillFocus(var Message: TWMKillFocus);
  11884. begin
  11885. inherited;
  11886. FCurSelected := FSelected;
  11887. FSelected := -1;
  11888. FMouseIn := False;
  11889. Invalidate;
  11890. end;
  11891. procedure TDefineListChecks.WMSetFocus(var Message: TWMSetFocus);
  11892. begin
  11893. inherited;
  11894. FSelected := FCurSelected;
  11895. Invalidate;
  11896. end;
  11897. procedure TDefineListChecks.SelectNotifyEvent;
  11898. begin
  11899. if assigned(FOnChange) and IndexInCount(FSelected,FItems.Count) then FOnChange(self,FItems.Strings[FSelected]);
  11900. if assigned(FOnClick) and IndexInCount(FSelected,FItems.Count) then FOnClick(self,FItems.Strings[FSelected]);
  11901. end;
  11902. procedure TDefineListChecks.WMKeyDown(var Message: TWMKeyDown);
  11903. var index:Integer;
  11904. begin
  11905. case Message.CharCode of
  11906. VK_UP: begin
  11907. if (FirstItem - 1) < 0 then
  11908. FirstItem := 0
  11909. else
  11910. Dec(FirstItem);
  11911. if FItems.Count > 0 then begin
  11912. if FSelected > 0 then
  11913. Dec(FSelected)
  11914. else
  11915. FSelected := 0;
  11916. SelectNotifyEvent;
  11917. end;
  11918. end;
  11919. VK_DOWN:begin
  11920. if FirstItem + MaxItems + 1 <= FItems.Count then
  11921. Inc(FirstItem);
  11922. if FItems.Count > 0 then begin
  11923. if FSelected < FItems.Count - 1 then
  11924. Inc(FSelected)
  11925. else
  11926. FSelected := FItems.Count - 1;
  11927. SelectNotifyEvent;
  11928. end;
  11929. end;
  11930. VK_PRIOR:
  11931. if (FirstItem - MaxItems) < 0 then
  11932. FirstItem := 0
  11933. else
  11934. Dec(FirstItem, MaxItems);
  11935. VK_NEXT:
  11936. if FirstItem +(MaxItems * 2) <= FItems.Count then
  11937. Inc(FirstItem, MaxItems)
  11938. else
  11939. FirstItem := FItems.Count - MaxItems;
  11940. VK_SPACE: begin
  11941. if FindChecked(FSelected, Index) then
  11942. DeleteChecked(Index)
  11943. else
  11944. AddCheck(FSelected);
  11945. SelectNotifyEvent;
  11946. end;
  11947. else
  11948. inherited;
  11949. end;
  11950. Invalidate;
  11951. end;
  11952. function TDefineListChecks.GetItemIndex: Integer;
  11953. begin
  11954. Result := FSelected;
  11955. end;
  11956. procedure TDefineListChecks.SetItemIndex(Value: Integer);
  11957. begin
  11958. if GetItemIndex <> Value then
  11959. begin
  11960. FSelected := Value;
  11961. Invalidate;
  11962. end;
  11963. end;
  11964. procedure TDefineListChecks.SetName(const Value: TComponentName);
  11965. begin
  11966. if(csDesigning in ComponentState) and((Length(FCaption) = 0) or
  11967. (CompareText(FCaption, Name) = 0)) then
  11968. FCaption := Value;
  11969. inherited SetName(Value);
  11970. end;
  11971. function TDefineListChecks.GetItemText: TCaption;
  11972. begin
  11973. if IndexInCount(FSelected,FItems.Count) then
  11974. result := FItems.Strings[FSelected]
  11975. else
  11976. result := '';
  11977. end;
  11978. function TDefineListChecks.Find(Value: String; var Index: Integer): boolean;
  11979. begin
  11980. result := false;
  11981. index := -1;
  11982. while(index < Items.Count) and(not result) do begin
  11983. inc(Index);
  11984. if IndexInCount(Index,Items.Count) then
  11985. result := UpperCase(Items.Strings[index])=UpperCase(Value);
  11986. end;
  11987. end;
  11988. procedure TDefineListChecks.Click;
  11989. begin
  11990. inherited Click;
  11991. if not Focused then SetFocus;
  11992. if assigned(FOnClick) and IndexInCount(FSelected,FItems.Count) then begin
  11993. FOnClick(self,FItems.Strings[FSelected]);
  11994. end;
  11995. end;
  11996. procedure TDefineListChecks.CheckAll;
  11997. var inx:Integer;
  11998. begin
  11999. if FItems.Count > 0 then begin
  12000. RemoveList(FChecks);
  12001. for inx := 0 to FItems.Count - 1 do
  12002. AddCheck(inx);
  12003. end;
  12004. SelectNotifyEvent;
  12005. end;
  12006. procedure TDefineListChecks.CheckCancel;
  12007. begin
  12008. RemoveList(FChecks);
  12009. SelectNotifyEvent;
  12010. end;
  12011. procedure TDefineListChecks.SetCheckStyle(const Value: TCheckStyle);
  12012. begin
  12013. FStyle.Assign(Value);
  12014. end;
  12015. procedure TDefineListChecks.StyleChange(Sender: TObject);
  12016. begin
  12017. SetItemsRect;
  12018. Invalidate;
  12019. end;
  12020. function TDefineListChecks.GetMaxItems: Integer;
  12021. begin
  12022. result:=ClientRect.Bottom - ClientRect.Top;
  12023. with FStyle do begin
  12024. if TitleHas then
  12025. result := result - TitleHeight;
  12026. if ScrollBars then
  12027. result := result - BarsHeight * 2;
  12028. result :=(result - 4) div(ItemHeight + 2);
  12029. end;
  12030. end;
  12031. procedure TDefineListChecks.KeyDown(var Key: Word; Shift: TShiftState);
  12032. begin
  12033. inherited KeyDown(Key,Shift);
  12034. if(ssCtrl in Shift)and Focused then begin
  12035. case key of
  12036. vk_selall :CheckAll;
  12037. vk_selcancel:CheckCancel;
  12038. end;
  12039. end;
  12040. end;
  12041. procedure TDefineListChecks.SetCaption(const Value: TCaption);
  12042. begin
  12043. if FCaption <> Value then begin
  12044. FCaption := Value;
  12045. Invalidate;
  12046. end;
  12047. end;
  12048. procedure TDefineListChecks.WMEnabledChanged(var Message: TMessage);
  12049. begin
  12050. inherited;
  12051. Invalidate;
  12052. end;
  12053. procedure TDefineListChecks.Delete(Index:Integer);
  12054. var inx:integer;
  12055. begin
  12056. if IndexInCount(index,FItems.Count) then
  12057. begin
  12058. if FindChecked(index,inx) then
  12059. DeleteChecked(inx);
  12060. FItems.Delete(index);
  12061. end;
  12062. end;
  12063. procedure TDefineListChecks.CMFontChanged(var Message: TMessage);
  12064. begin
  12065. inherited;
  12066. if Assigned(FStyle) then
  12067. begin
  12068. if FStyle.ParentFont then
  12069. FStyle.TitleFont.Assign(Font);
  12070. end;
  12071. end;
  12072. procedure TDefineListChecks.CMParentFontChanged(var Message: TMessage);
  12073. begin
  12074. inherited;
  12075. if ParentFont and Assigned(FStyle) then
  12076. begin
  12077. if FStyle.ParentFont then
  12078. FStyle.TitleFont.Assign(Font);
  12079. end;
  12080. end;
  12081. function TDefineListChecks.GetItemCount: Integer;
  12082. begin
  12083. result := Items.Count;
  12084. end;
  12085. { TDefineGroupButton }
  12086. type
  12087. TDefineGroupButton = class(TDefineRadioButton)
  12088. private
  12089. FInClick: Boolean;
  12090. procedure CNCommand(var Message: TWMCommand); message CN_COMMAND;
  12091. protected
  12092. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  12093. procedure KeyPress(var Key: Char); override;
  12094. public
  12095. constructor InternalCreate(RadioGroup: TDefineRadioGroup);
  12096. destructor Destroy; override;
  12097. end;
  12098. constructor TDefineGroupButton.InternalCreate(RadioGroup: TDefineRadioGroup);
  12099. begin
  12100. inherited Create(RadioGroup);
  12101. RadioGroup.FButtons.Add(Self);
  12102. Visible := False;
  12103. Enabled := RadioGroup.Enabled;
  12104. ParentShowHint := False;
  12105. OnClick := RadioGroup.ButtonClick;
  12106. Parent := RadioGroup;
  12107. end;
  12108. destructor TDefineGroupButton.Destroy;
  12109. begin
  12110. TDefineRadioGroup(Owner).FButtons.Remove(Self);
  12111. inherited Destroy;
  12112. end;
  12113. procedure TDefineGroupButton.CNCommand(var Message: TWMCommand);
  12114. begin
  12115. if not FInClick then
  12116. begin
  12117. FInClick := True;
  12118. try
  12119. if ((Message.NotifyCode = BN_CLICKED) or
  12120. (Message.NotifyCode = BN_DOUBLECLICKED)) and
  12121. TDefineRadioGroup(Parent).CanModify then
  12122. inherited;
  12123. except
  12124. Application.HandleException(Self);
  12125. end;
  12126. FInClick := False;
  12127. end;
  12128. end;
  12129. procedure TDefineGroupButton.KeyPress(var Key: Char);
  12130. begin
  12131. inherited KeyPress(Key);
  12132. TDefineRadioGroup(Parent).KeyPress(Key);
  12133. if (Key = #8) or (Key = ' ') then
  12134. begin
  12135. if not TDefineRadioGroup(Parent).CanModify then Key := #0;
  12136. end;
  12137. end;
  12138. procedure TDefineGroupButton.KeyDown(var Key: Word; Shift: TShiftState);
  12139. begin
  12140. inherited KeyDown(Key, Shift);
  12141. TDefineRadioGroup(Parent).KeyDown(Key, Shift);
  12142. end;
  12143. procedure TDefineListChecks.CMMouseEnter(var Message: TMessage);
  12144. begin
  12145. inherited;
  12146. if not(csDesigning in ComponentState) and
  12147. (GetActiveWindow <> 0) and (not MouseIn) then
  12148. begin
  12149. FMouseIn := True;
  12150. Invalidate;
  12151. end;
  12152. end;
  12153. procedure TDefineListChecks.CMMouseLeave(var Message: TMessage);
  12154. begin
  12155. inherited;
  12156. if MouseIn then begin
  12157. FMouseIn := false;
  12158. Invalidate;
  12159. end;
  12160. end;
  12161. function TDefineListChecks.GetMouseIn: Boolean;
  12162. begin
  12163. Result := FMouseIn;
  12164. end;
  12165. { TDefineRadioGroup }
  12166. constructor TDefineRadioGroup.Create(AOwner: TComponent);
  12167. begin
  12168. inherited Create(AOwner);
  12169. ControlStyle := [csSetCaption, csDoubleClicks, csParentBackground];
  12170. FButtons := TList.Create;
  12171. FItems := TStringList.Create;
  12172. TStringList(FItems).OnChange := ItemsChange;
  12173. FItemIndex := -1;
  12174. FColumns := 1;
  12175. end;
  12176. destructor TDefineRadioGroup.Destroy;
  12177. begin
  12178. SetButtonCount(0);
  12179. TStringList(FItems).OnChange := nil;
  12180. FItems.Free;
  12181. FButtons.Free;
  12182. inherited Destroy;
  12183. end;
  12184. procedure TDefineRadioGroup.ArrangeButtons;
  12185. var
  12186. ButtonsPerCol, ButtonWidth, ButtonHeight, TopMargin, I: Integer;
  12187. DC: HDC;
  12188. SaveFont: HFont;
  12189. Metrics: TTextMetric;
  12190. DeferHandle: THandle;
  12191. ALeft: Integer;
  12192. begin
  12193. if (FButtons.Count <> 0) and not FReading then
  12194. begin
  12195. DC := GetDC(0);
  12196. SaveFont := SelectObject(DC, Font.Handle);
  12197. GetTextMetrics(DC, Metrics);
  12198. SelectObject(DC, SaveFont);
  12199. ReleaseDC(0, DC);
  12200. ButtonsPerCol := (FButtons.Count + FColumns - 1) div FColumns;
  12201. ButtonWidth := (Width - 10) div FColumns;
  12202. I := Height - Metrics.tmHeight - 5;
  12203. ButtonHeight := I div ButtonsPerCol;
  12204. TopMargin := Metrics.tmHeight + 5 + (I mod ButtonsPerCol) div 2;
  12205. DeferHandle := BeginDeferWindowPos(FButtons.Count);
  12206. try
  12207. for I := 0 to FButtons.Count - 1 do
  12208. with TDefineGroupButton(FButtons[I]) do
  12209. begin
  12210. BiDiMode := Self.BiDiMode;
  12211. ALeft := (I div ButtonsPerCol) * ButtonWidth + 8;
  12212. if UseRightToLeftAlignment then
  12213. ALeft := Self.ClientWidth - ALeft - Width;
  12214. DeferHandle := DeferWindowPos(DeferHandle, Handle, 0,
  12215. ALeft,
  12216. (I mod ButtonsPerCol) * ButtonHeight + TopMargin,
  12217. Width, Height,
  12218. SWP_NOZORDER or SWP_NOACTIVATE);
  12219. Visible := True;
  12220. end;
  12221. finally
  12222. EndDeferWindowPos(DeferHandle);
  12223. end;
  12224. end;
  12225. end;
  12226. procedure TDefineRadioGroup.ButtonClick(Sender: TObject);
  12227. begin
  12228. if not FUpdating then
  12229. begin
  12230. FItemIndex := FButtons.IndexOf(Sender);
  12231. Changed;
  12232. Click;
  12233. end;
  12234. end;
  12235. procedure TDefineRadioGroup.ItemsChange(Sender: TObject);
  12236. begin
  12237. if not FReading then
  12238. begin
  12239. if FItemIndex >= FItems.Count then FItemIndex := FItems.Count - 1;
  12240. UpdateButtons;
  12241. end;
  12242. end;
  12243. procedure TDefineRadioGroup.Loaded;
  12244. begin
  12245. inherited Loaded;
  12246. ArrangeButtons;
  12247. end;
  12248. procedure TDefineRadioGroup.ReadState(Reader: TReader);
  12249. begin
  12250. FReading := True;
  12251. inherited ReadState(Reader);
  12252. FReading := False;
  12253. UpdateButtons;
  12254. end;
  12255. procedure TDefineRadioGroup.SetButtonCount(Value: Integer);
  12256. begin
  12257. while FButtons.Count < Value do TDefineGroupButton.InternalCreate(Self);
  12258. while FButtons.Count > Value do TDefineGroupButton(FButtons.Last).Free;
  12259. end;
  12260. procedure TDefineRadioGroup.SetColumns(Value: Integer);
  12261. begin
  12262. if Value < 1 then Value := 1;
  12263. if Value > 16 then Value := 16;
  12264. if FColumns <> Value then
  12265. begin
  12266. FColumns := Value;
  12267. ArrangeButtons;
  12268. Invalidate;
  12269. end;
  12270. end;
  12271. procedure TDefineRadioGroup.SetItemIndex(Value: Integer);
  12272. begin
  12273. if FReading then FItemIndex := Value else
  12274. begin
  12275. if Value < -1 then Value := -1;
  12276. if Value >= FButtons.Count then Value := FButtons.Count - 1;
  12277. if FItemIndex <> Value then
  12278. begin
  12279. if FItemIndex >= 0 then
  12280. TDefineGroupButton(FButtons[FItemIndex]).Checked := False;
  12281. FItemIndex := Value;
  12282. if FItemIndex >= 0 then
  12283. TDefineGroupButton(FButtons[FItemIndex]).Checked := True;
  12284. end;
  12285. end;
  12286. end;
  12287. procedure TDefineRadioGroup.SetItems(Value: TStrings);
  12288. begin
  12289. FItems.Assign(Value);
  12290. end;
  12291. procedure TDefineRadioGroup.UpdateButtons;
  12292. var
  12293. I: Integer;
  12294. begin
  12295. SetButtonCount(FItems.Count);
  12296. for I := 0 to FButtons.Count - 1 do
  12297. TDefineGroupButton(FButtons[I]).Caption := FItems[I];
  12298. if FItemIndex >= 0 then
  12299. begin
  12300. FUpdating := True;
  12301. TDefineGroupButton(FButtons[FItemIndex]).Checked := True;
  12302. FUpdating := False;
  12303. end;
  12304. ArrangeButtons;
  12305. Invalidate;
  12306. end;
  12307. procedure TDefineRadioGroup.CMEnabledChanged(var Message: TMessage);
  12308. var
  12309. I: Integer;
  12310. begin
  12311. inherited;
  12312. for I := 0 to FButtons.Count - 1 do
  12313. TDefineGroupButton(FButtons[I]).Enabled := Enabled;
  12314. end;
  12315. procedure TDefineRadioGroup.CMFontChanged(var Message: TMessage);
  12316. begin
  12317. inherited;
  12318. ArrangeButtons;
  12319. end;
  12320. procedure TDefineRadioGroup.WMSize(var Message: TWMSize);
  12321. begin
  12322. inherited;
  12323. ArrangeButtons;
  12324. end;
  12325. function TDefineRadioGroup.CanModify: Boolean;
  12326. begin
  12327. Result := True;
  12328. end;
  12329. function TDefineRadioGroup.GetButtons(Index: Integer): TDefineRadioButton;
  12330. begin
  12331. Result := TDefineRadioButton(FButtons[Index]);
  12332. end;
  12333. procedure TDefineRadioGroup.SetStyleFace(const Value: TStyleFace);
  12334. begin
  12335. inherited;
  12336. FTransparent := (FStyleFace <> fsCustom) and (not ParentColor);
  12337. end;
  12338. { TDefineRadioButton }
  12339. constructor TDefineRadioButton.Create(AOwner: TComponent);
  12340. begin
  12341. inherited Create(AOwner);
  12342. ControlStyle := [csSetCaption, csDoubleClicks];
  12343. ParentColor := False;
  12344. ParentFont := True;
  12345. Enabled := True;
  12346. Visible := True;
  12347. Color := DefaultFlatColor;
  12348. FFocusedColor := DefaultBackdropColor;
  12349. FDownColor := DefaultBarColor;
  12350. FCheckedColor := DefaultCheckColor;
  12351. FBorderColor := DefaultBorderColor;
  12352. FLayout := lpLeft;
  12353. FChecked := false;
  12354. FGroupIndex := 0;
  12355. FTransparent := True;
  12356. SetBounds(0, 0, 121, 15);
  12357. end;
  12358. procedure TDefineRadioButton.SetColors(Index: Integer; Value: TColor);
  12359. begin
  12360. case Index of
  12361. 0: FFocusedColor := Value;
  12362. 1: FDownColor := Value;
  12363. 2: FCheckedColor := Value;
  12364. 3: FBorderColor := Value;
  12365. end;
  12366. Invalidate;
  12367. end;
  12368. procedure TDefineRadioButton.SetLayout(Value: TLayoutPosition);
  12369. begin
  12370. if FLayout <> Value then
  12371. begin
  12372. FLayout := Value;
  12373. //AdjustBounds;
  12374. Invalidate;
  12375. end;
  12376. end;
  12377. procedure TDefineRadioButton.SetChecked(Value: Boolean);
  12378. var
  12379. I: Integer;
  12380. Sibling: TDefineRadioButton;
  12381. begin
  12382. if FChecked <> Value then
  12383. begin
  12384. TabStop := Value;
  12385. FChecked := Value;
  12386. if Value then
  12387. begin
  12388. if Parent <> nil then
  12389. for i := 0 to Parent.ControlCount-1 do
  12390. if Parent.Controls[i] is TDefineRadioButton then
  12391. begin
  12392. Sibling := TDefineRadioButton(Parent.Controls[i]);
  12393. if (Sibling <> Self) and (Sibling.GroupIndex = GroupIndex) then
  12394. with TDefineRadioButton(Sibling) do
  12395. begin
  12396. if Assigned(Action) and (Action is TCustomAction) and
  12397. TCustomAction(Action).AutoCheck then
  12398. TCustomAction(Action).Checked := False;
  12399. SetChecked(False);
  12400. end;
  12401. end;
  12402. Click;
  12403. if csDesigning in ComponentState then
  12404. if (GetParentForm(self) <> nil) and (GetParentForm(self).Designer <> nil) then
  12405. GetParentForm(self).Designer.Modified;
  12406. end;
  12407. invalidate;
  12408. end;
  12409. end;
  12410. procedure TDefineRadioButton.CMEnabledChanged(var Message: TMessage);
  12411. begin
  12412. inherited;
  12413. if not Enabled then
  12414. begin
  12415. FMouseIn := False;
  12416. FMouseDown := False;
  12417. end;
  12418. Invalidate;
  12419. end;
  12420. procedure TDefineRadioButton.CMTextChanged(var Message: TWmNoParams);
  12421. begin
  12422. inherited;
  12423. Invalidate;
  12424. end;
  12425. procedure TDefineRadioButton.CMDialogChar(var Message: TCMDialogChar);
  12426. begin
  12427. with Message do
  12428. if IsAccel(Message.CharCode, Caption) and CanFocus then
  12429. begin
  12430. SetFocus;
  12431. Result := 1;
  12432. end
  12433. else
  12434. inherited;
  12435. end;
  12436. procedure TDefineRadioButton.CNCommand(var Message: TWMCommand);
  12437. begin
  12438. if Message.NotifyCode = BN_CLICKED then Click;
  12439. end;
  12440. procedure TDefineRadioButton.WMSetFocus(var Message: TWMSetFocus);
  12441. begin
  12442. inherited;
  12443. if Enabled then
  12444. begin
  12445. FFocused := True;
  12446. FMouseIn := True;
  12447. if not FChecked then
  12448. SetChecked(True);
  12449. end;
  12450. invalidate;
  12451. end;
  12452. procedure TDefineRadioButton.WMKillFocus(var Message: TWMKillFocus);
  12453. begin
  12454. inherited;
  12455. if Enabled then
  12456. begin
  12457. FMouseIn := False;
  12458. FFocused := False;
  12459. end;
  12460. invalidate;
  12461. end;
  12462. procedure TDefineRadioButton.CMSysColorChange(var Message: TMessage);
  12463. begin
  12464. inherited;
  12465. if (Parent <> nil)and(ParentColor) then
  12466. begin
  12467. Color := TDefineRadioButton(Parent).Color;
  12468. end;
  12469. Invalidate;
  12470. end;
  12471. procedure TDefineRadioButton.CMParentColorChanged(var Message: TWMNoParams);
  12472. begin
  12473. inherited;
  12474. if (Parent <> nil)and(ParentColor) then
  12475. begin
  12476. Color := TDefineRadioButton(Parent).Color;
  12477. end;
  12478. Invalidate;
  12479. end;
  12480. procedure TDefineRadioButton.DoEnter;
  12481. begin
  12482. inherited DoEnter;
  12483. if FMouseDown and MouseIn then
  12484. FChecked := True;
  12485. FFocused := True;
  12486. invalidate;
  12487. end;
  12488. procedure TDefineRadioButton.DoExit;
  12489. begin
  12490. inherited DoExit;
  12491. FFocused := False;
  12492. FMouseIn := False;
  12493. invalidate;
  12494. end;
  12495. {
  12496. procedure TDefineRadioButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  12497. begin
  12498. if(Button = mbLeft) and Enabled then
  12499. begin
  12500. SetFocus;
  12501. FMouseDown := true;
  12502. invalidate;
  12503. end;
  12504. inherited MouseDown(Button, Shift, X, Y);
  12505. end;
  12506. procedure TDefineRadioButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  12507. begin
  12508. if(Button = mbLeft) and Enabled then
  12509. begin
  12510. FMouseDown := false;
  12511. if (X>=0) and (X<=Width) and (Y>=0) and (Y<=Height) and not Checked then
  12512. Checked := True;
  12513. invalidate;
  12514. end;
  12515. inherited MouseUp(Button, Shift, X, Y);
  12516. end;
  12517. }
  12518. procedure TDefineRadioButton.Paint;
  12519. var
  12520. TextBounds, RadioRect, SelectRect: TRect;
  12521. Format: UINT;
  12522. TextAs:Integer;
  12523. begin
  12524. with Canvas do
  12525. begin
  12526. Lock;
  12527. Font.Assign(self.Font);
  12528. if Layout = lpLeft then
  12529. Width := TextWidth(DelCapLink(Caption))+TextHeight('H')+5;
  12530. Height := TextHeight('H')+2;
  12531. if FTransparent then
  12532. DrawParentImage(Self, Canvas)
  12533. else
  12534. begin
  12535. Brush.Color := self.Color;
  12536. FillRect(ClientRect);
  12537. end;
  12538. //draw Background + Border
  12539. with ClientRect do
  12540. begin
  12541. case FLayout of
  12542. lpLeft:RadioRect := Rect(1, HeightOf(ClientRect) div 2 - 7, 15, HeightOf(ClientRect) div 2 + 7);
  12543. lpRight:RadioRect := Rect(Width-15, HeightOf(ClientRect) div 2 - 7, Width-1, HeightOf(ClientRect) div 2 + 7);
  12544. end;
  12545. end;
  12546. Pen.style := psSolid;
  12547. Brush.Style := bsClear;
  12548. Pen.width := 1;
  12549. if (Focused or MouseIn)and(not(csDesigning in ComponentState)) then
  12550. begin
  12551. if (not FMouseDown) then
  12552. begin
  12553. Brush.color := FFocusedColor;
  12554. Pen.color := FBorderColor;
  12555. end else begin
  12556. Brush.color := FDownColor;
  12557. Pen.color := FBorderColor;
  12558. end;
  12559. end else begin
  12560. Brush.color := self.Color;
  12561. Pen.color := FBorderColor;
  12562. end;
  12563. DrawEllipse(Handle, RadioRect);
  12564. if Checked then
  12565. begin
  12566. if Enabled then
  12567. begin
  12568. Brush.color := FCheckedColor;
  12569. Pen.color := FCheckedColor;
  12570. end else begin
  12571. Brush.color := clBtnShadow;
  12572. Pen.color := clBtnShadow;
  12573. end;
  12574. with RadioRect do
  12575. begin
  12576. SelectRect := Rect(Left + 3, Top + 3, Right - 3, Bottom - 3);
  12577. end;
  12578. DrawEllipse(Handle, SelectRect);
  12579. end;
  12580. //draw text
  12581. Format := DT_WORDBREAK;
  12582. Brush.Style := bsClear;
  12583. with ClientRect do
  12584. begin
  12585. TextAs:=(RectHeight(ClientRect) - TextHeight('H')) div 2;
  12586. case FLayout of
  12587. lpLeft: begin
  12588. TextBounds := Rect(Left + WidthOf(RadioRect)+2, Top + TextAs, Right + WidthOf(RadioRect), Bottom - TextAs);
  12589. Format := Format or DT_LEFT;
  12590. end;
  12591. lpRight: begin
  12592. TextBounds := Rect(Left + 1, Top + TextAs, Right - WidthOf(RadioRect)-2, Bottom - TextAs);
  12593. Format := Format or DT_RIGHT;
  12594. end;
  12595. end;
  12596. end;
  12597. if not Enabled then
  12598. begin
  12599. OffsetRect(TextBounds, 1, 1);
  12600. Font.Color := clBtnHighlight;
  12601. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  12602. OffsetRect(TextBounds, -1, -1);
  12603. Font.Color := clBtnShadow;
  12604. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  12605. end
  12606. else
  12607. DrawText(Handle, PChar(Caption), Length(Caption), TextBounds, Format);
  12608. UnLock;
  12609. end;
  12610. end;
  12611. procedure TDefineRadioButton.WMSize(var Message: TWMSize);
  12612. begin
  12613. inherited;
  12614. Invalidate;
  12615. end;
  12616. procedure TDefineRadioButton.WMMove(var Message: TWMMove);
  12617. begin
  12618. inherited;
  12619. Invalidate;
  12620. end;
  12621. procedure TDefineRadioButton.SetTransparent(const Value: Boolean);
  12622. begin
  12623. if FTransparent <> Value then
  12624. begin
  12625. FTransparent := Value;
  12626. ParentColor := not Value;
  12627. Invalidate;
  12628. end;
  12629. end;
  12630. procedure TDefineRadioButton.CMMouseEnter(var Message: TMessage);
  12631. begin
  12632. inherited;
  12633. if not(csDesigning in ComponentState) and
  12634. (GetActiveWindow <> 0) and (not MouseIn) then
  12635. begin
  12636. FMouseIn := True;
  12637. Invalidate;
  12638. end;
  12639. end;
  12640. procedure TDefineRadioButton.CMMouseLeave(var Message: TMessage);
  12641. begin
  12642. inherited;
  12643. if MouseIn then begin
  12644. FMouseIn := False;
  12645. end;
  12646. invalidate;
  12647. end;
  12648. procedure TDefineRadioButton.CMFontChanged(var Message: TMessage);
  12649. begin
  12650. inherited;
  12651. invalidate;
  12652. end;
  12653. function TDefineRadioButton.GetMouseIn: Boolean;
  12654. begin
  12655. Result := FMouseIn;
  12656. end;
  12657. procedure TDefineRadioButton.WMLButtonDown(var Message: TWMLButtonDown);
  12658. begin
  12659. if Enabled then
  12660. begin
  12661. SetFocus;
  12662. FChecked := True;
  12663. FMouseDown := true;
  12664. invalidate;
  12665. end;
  12666. end;
  12667. procedure TDefineRadioButton.WMLButtonUP(var Message: TWMLButtonDown);
  12668. begin
  12669. if Enabled then
  12670. begin
  12671. FMouseDown := false;
  12672. Invalidate;
  12673. end;
  12674. end;
  12675. { TDefineListBoxExt }
  12676. constructor TDefineListBoxExt.Create(AOwner: TComponent);
  12677. begin
  12678. inherited Create(AOwner);
  12679. ControlStyle := ControlStyle - [csOpaque];
  12680. ParentFont := True;
  12681. AutoSize := False;
  12682. Ctl3D := False;
  12683. BorderStyle := bsNone;
  12684. FFocusColor := clWhite;
  12685. FBorderColor := DefaultBorderColor;
  12686. FFlatColor := DefaultFlatColor;
  12687. FParentColor := True;
  12688. FMouseIn := False;
  12689. end;
  12690. procedure TDefineListBoxExt.RedrawBorder(const Clip: HRGN);
  12691. var
  12692. Attrib:TBorderAttrib;
  12693. begin
  12694. with Attrib do
  12695. begin
  12696. Ctrl := self;
  12697. BorderColor := ColorBorder;
  12698. if Enabled then begin
  12699. FocusColor := ColorFocused;
  12700. FlatColor := ColorFlat;
  12701. end else begin
  12702. FocusColor := clBtnFace;
  12703. FlatColor := clBtnFace;
  12704. end;
  12705. MouseState := MouseIn;
  12706. FocusState := Focused;
  12707. DesignState := ComponentState;
  12708. HasBars := false;
  12709. BoldState := false;
  12710. end;
  12711. Color := DrawEditBorder(Attrib,Clip);
  12712. end;
  12713. procedure TDefineListBoxExt.SetParentColor(Value: Boolean);
  12714. begin
  12715. if Value <> FParentColor then
  12716. begin
  12717. FParentColor := Value;
  12718. if FParentColor then
  12719. begin
  12720. if Parent <> nil then
  12721. FFlatColor := TForm(Parent).Color;
  12722. RedrawBorder;
  12723. end;
  12724. end;
  12725. end;
  12726. procedure TDefineListBoxExt.CMSysColorChange(var Message: TMessage);
  12727. begin
  12728. if (Parent <> nil)and(FParentColor) then
  12729. FFlatColor := TForm(Parent).Color;
  12730. RedrawBorder;
  12731. end;
  12732. procedure TDefineListBoxExt.CMParentColorChanged(var Message: TWMNoParams);
  12733. begin
  12734. if (Parent <> nil)and(FParentColor) then
  12735. FFlatColor := TForm(Parent).Color;
  12736. RedrawBorder;
  12737. end;
  12738. procedure TDefineListBoxExt.SetColors(Index: Integer; Value: TColor);
  12739. begin
  12740. case Index of
  12741. 0: FFocusColor := Value;
  12742. 1: FBorderColor := Value;
  12743. 2: begin
  12744. FFlatColor := Value;
  12745. FParentColor := False;
  12746. end;
  12747. end;
  12748. RedrawBorder;
  12749. end;
  12750. procedure TDefineListBoxExt.CMMouseEnter(var Message: TMessage);
  12751. begin
  12752. inherited;
  12753. if (GetActiveWindow <> 0) then
  12754. begin
  12755. FMouseIn := True;
  12756. RedrawBorder;
  12757. end;
  12758. end;
  12759. procedure TDefineListBoxExt.CMMouseLeave(var Message: TMessage);
  12760. begin
  12761. inherited;
  12762. if MouseIn then begin
  12763. FMouseIn := False;
  12764. RedrawBorder;
  12765. end;
  12766. end;
  12767. procedure TDefineListBoxExt.CMEnabledChanged(var Message: TMessage);
  12768. begin
  12769. inherited;
  12770. RedrawBorder;
  12771. end;
  12772. procedure TDefineListBoxExt.WMSetFocus(var Message: TWMSetFocus);
  12773. begin
  12774. inherited;
  12775. if not(csDesigning in ComponentState) then
  12776. RedrawBorder;
  12777. end;
  12778. procedure TDefineListBoxExt.WMKillFocus(var Message: TWMKillFocus);
  12779. begin
  12780. inherited;
  12781. if not(csDesigning in ComponentState) then
  12782. RedrawBorder;
  12783. end;
  12784. procedure TDefineListBoxExt.WMNCCalcSize(var Message: TWMNCCalcSize);
  12785. begin
  12786. inherited;
  12787. InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
  12788. end;
  12789. procedure TDefineListBoxExt.WMNCPaint(var Message: TMessage);
  12790. begin
  12791. inherited;
  12792. RedrawBorder(HRGN(Message.WParam));
  12793. end;
  12794. { TDefineCheckWrapper }
  12795. type
  12796. TDefineCheckWrapper = class
  12797. private
  12798. FData: LongInt;
  12799. FState: TCheckBoxState;
  12800. FDisabled: Boolean;
  12801. FHeader: Boolean;
  12802. procedure SetChecked(Check: Boolean);
  12803. function GetChecked: Boolean;
  12804. public
  12805. class function GetDefaultState: TCheckBoxState;
  12806. property Checked: Boolean read GetChecked write SetChecked;
  12807. property State: TCheckBoxState read FState write FState;
  12808. property Disabled: Boolean read FDisabled write FDisabled;
  12809. property Header: Boolean read FHeader write FHeader;
  12810. end;
  12811. var
  12812. FCheckWidth, FCheckHeight: Integer;
  12813. procedure GetCheckSize;
  12814. begin
  12815. with TBitmap.Create do
  12816. try
  12817. Handle := LoadBitmap(0, PChar(OBM_CHECKBOXES));
  12818. FCheckWidth := Width div 4;
  12819. FCheckHeight := Height div 3;
  12820. finally
  12821. Free;
  12822. end;
  12823. end;
  12824. function MakeSaveState(State: TCheckBoxState; Disabled: Boolean): TObject;
  12825. begin
  12826. Result := TObject((Byte(State) shl 16) or Byte(Disabled));
  12827. end;
  12828. function GetSaveState(AObject: TObject): TCheckBoxState;
  12829. begin
  12830. Result := TCheckBoxState(Integer(AObject) shr 16);
  12831. end;
  12832. function GetSaveDisabled(AObject: TObject): Boolean;
  12833. begin
  12834. Result := Boolean(Integer(AObject) and $FF);
  12835. end;
  12836. function TDefineListBoxExt.GetMouseIn: Boolean;
  12837. begin
  12838. Result := FMouseIn;
  12839. end;
  12840. { TDefineCheckWrapper }
  12841. procedure TDefineCheckWrapper .SetChecked(Check: Boolean);
  12842. begin
  12843. if Check then FState := cbChecked else FState := cbUnchecked;
  12844. end;
  12845. function TDefineCheckWrapper .GetChecked: Boolean;
  12846. begin
  12847. Result := FState = cbChecked;
  12848. end;
  12849. class function TDefineCheckWrapper .GetDefaultState: TCheckBoxState;
  12850. begin
  12851. Result := cbUnchecked;
  12852. end;
  12853. { TDefineCheckListExt }
  12854. constructor TDefineCheckListExt.Create(AOwner: TComponent);
  12855. begin
  12856. inherited Create(AOwner);
  12857. FFlat := True;
  12858. FHeaderColor := clInfoText;
  12859. FHeaderBkColor := clInfoBk;
  12860. end;
  12861. destructor TDefineCheckListExt.Destroy;
  12862. begin
  12863. FSaveStates.Free;
  12864. inherited;
  12865. end;
  12866. procedure TDefineCheckListExt.CreateWnd;
  12867. var
  12868. I: Integer;
  12869. Wrapper: TDefineCheckWrapper ;
  12870. SaveState: TObject;
  12871. begin
  12872. inherited CreateWnd;
  12873. if FSaveStates <> nil then
  12874. begin
  12875. for I := 0 to FSaveStates.Count - 1 do
  12876. begin
  12877. Wrapper := TDefineCheckWrapper (GetWrapper(I));
  12878. SaveState := FSaveStates[I];
  12879. Wrapper.FState := GetSaveState(SaveState);
  12880. Wrapper.FDisabled := GetSaveDisabled(SaveState);
  12881. end;
  12882. FreeAndNil(FSaveStates);
  12883. end;
  12884. ResetItemHeight;
  12885. end;
  12886. procedure TDefineCheckListExt.DestroyWnd;
  12887. var
  12888. I: Integer;
  12889. begin
  12890. if Items.Count > 0 then
  12891. begin
  12892. FSaveStates := TList.Create;
  12893. for I := 0 to Items.Count - 1 do
  12894. FSaveStates.Add(MakeSaveState(State[I], not ItemEnabled[I]));
  12895. end;
  12896. inherited DestroyWnd;
  12897. end;
  12898. procedure TDefineCheckListExt.CreateParams(var Params: TCreateParams);
  12899. begin
  12900. inherited;
  12901. with Params do
  12902. if Style and (LBS_OWNERDRAWFIXED or LBS_OWNERDRAWVARIABLE) = 0 then
  12903. Style := Style or LBS_OWNERDRAWFIXED;
  12904. end;
  12905. function TDefineCheckListExt.GetCheckWidth: Integer;
  12906. begin
  12907. Result := FCheckWidth + 2;
  12908. end;
  12909. procedure TDefineCheckListExt.CMFontChanged(var Message: TMessage);
  12910. begin
  12911. inherited;
  12912. ResetItemHeight;
  12913. end;
  12914. procedure TDefineCheckListExt.ResetItemHeight;
  12915. begin
  12916. if HandleAllocated and (Style = lbStandard) then
  12917. begin
  12918. Canvas.Font := Font;
  12919. FStandardItemHeight := Canvas.TextHeight('Wg');
  12920. Perform(LB_SETITEMHEIGHT, 0, FStandardItemHeight);
  12921. end;
  12922. end;
  12923. procedure TDefineCheckListExt.DrawItem(Index: Integer; Rect: TRect;
  12924. State: TOwnerDrawState);
  12925. var
  12926. R: TRect;
  12927. SaveEvent: TDrawItemEvent;
  12928. ACheckWidth: Integer;
  12929. Enable: Boolean;
  12930. begin
  12931. ACheckWidth := GetCheckWidth;
  12932. if Index < Items.Count then
  12933. begin
  12934. R := Rect;
  12935. Enable := Self.Enabled and GetItemEnabled(Index);
  12936. if not Header[Index] then
  12937. begin
  12938. if not UseRightToLeftAlignment then
  12939. begin
  12940. R.Right := Rect.Left;
  12941. R.Left := R.Right - ACheckWidth;
  12942. end
  12943. else
  12944. begin
  12945. R.Left := Rect.Right;
  12946. R.Right := R.Left + ACheckWidth;
  12947. end;
  12948. DrawCheck(R, GetState(Index), Enable);
  12949. end
  12950. else
  12951. begin
  12952. Canvas.Font.Color := FHeaderColor;
  12953. Canvas.Brush.Color := FHeaderBkColor;
  12954. end;
  12955. if not Enable then
  12956. Canvas.Font.Color := clGrayText;
  12957. end;
  12958. if (Style = lbStandard) and Assigned(OnDrawItem) then
  12959. begin
  12960. { Force lbStandard list to ignore OnDrawItem event. }
  12961. SaveEvent := OnDrawItem;
  12962. OnDrawItem := nil;
  12963. try
  12964. inherited;
  12965. finally
  12966. OnDrawItem := SaveEvent;
  12967. end;
  12968. end
  12969. else
  12970. inherited;
  12971. end;
  12972. procedure TDefineCheckListExt.CNDrawItem(var Message: TWMDrawItem);
  12973. begin
  12974. if Items.Count = 0 then exit;
  12975. with Message.DrawItemStruct^ do
  12976. if not Header[itemID] then
  12977. if not UseRightToLeftAlignment then
  12978. rcItem.Left := rcItem.Left + GetCheckWidth
  12979. else
  12980. rcItem.Right := rcItem.Right - GetCheckWidth;
  12981. inherited;
  12982. end;
  12983. procedure TDefineCheckListExt.DrawCheck(R: TRect; AState: TCheckBoxState; AEnabled: Boolean);
  12984. var
  12985. DrawState: Integer;
  12986. DrawRect: TRect;
  12987. OldBrushColor: TColor;
  12988. OldBrushStyle: TBrushStyle;
  12989. OldPenColor: TColor;
  12990. Rgn, SaveRgn: HRgn;
  12991. ElementDetails: TThemedElementDetails;
  12992. begin
  12993. SaveRgn := 0;
  12994. DrawRect.Left := R.Left + (R.Right - R.Left - FCheckWidth) div 2;
  12995. DrawRect.Top := R.Top + (R.Bottom - R.Top - FCheckHeight) div 2;
  12996. DrawRect.Right := DrawRect.Left + FCheckWidth;
  12997. DrawRect.Bottom := DrawRect.Top + FCheckHeight;
  12998. with Canvas do
  12999. begin
  13000. if Flat then
  13001. begin
  13002. { Remember current clipping region }
  13003. SaveRgn := CreateRectRgn(0,0,0,0);
  13004. GetClipRgn(Handle, SaveRgn);
  13005. { Clip 3d-style checkbox to prevent flicker }
  13006. with DrawRect do
  13007. Rgn := CreateRectRgn(Left + 2, Top + 2, Right - 2, Bottom - 2);
  13008. SelectClipRgn(Handle, Rgn);
  13009. DeleteObject(Rgn);
  13010. end;
  13011. if ThemeServices.ThemesEnabled then
  13012. begin
  13013. case AState of
  13014. cbChecked:
  13015. if AEnabled then
  13016. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxCheckedNormal)
  13017. else
  13018. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxCheckedDisabled);
  13019. cbUnchecked:
  13020. if AEnabled then
  13021. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxUncheckedNormal)
  13022. else
  13023. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxUncheckedDisabled)
  13024. else // cbGrayed
  13025. if AEnabled then
  13026. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxMixedNormal)
  13027. else
  13028. ElementDetails := ThemeServices.GetElementDetails(tbCheckBoxMixedDisabled);
  13029. end;
  13030. ThemeServices.DrawElement(Handle, ElementDetails, R);
  13031. end
  13032. else
  13033. begin
  13034. case AState of
  13035. cbChecked:
  13036. DrawState := DFCS_BUTTONCHECK or DFCS_CHECKED;
  13037. cbUnchecked:
  13038. DrawState := DFCS_BUTTONCHECK;
  13039. else // cbGrayed
  13040. DrawState := DFCS_BUTTON3STATE or DFCS_CHECKED;
  13041. end;
  13042. if not AEnabled then
  13043. DrawState := DrawState or DFCS_INACTIVE;
  13044. DrawFrameControl(Handle, DrawRect, DFC_BUTTON, DrawState);
  13045. end;
  13046. if Flat then
  13047. begin
  13048. SelectClipRgn(Handle, SaveRgn);
  13049. DeleteObject(SaveRgn);
  13050. { Draw flat rectangle in-place of clipped 3d checkbox above }
  13051. OldBrushStyle := Brush.Style;
  13052. OldBrushColor := Brush.Color;
  13053. OldPenColor := Pen.Color;
  13054. Brush.Style := bsClear;
  13055. Pen.Color := clBtnShadow;
  13056. SetBkMode(Canvas.Handle,TRANSPARENT);
  13057. with DrawRect do
  13058. Rectangle(Left + 1, Top + 1, Right - 1, Bottom - 1);
  13059. Brush.Style := OldBrushStyle;
  13060. Brush.Color := OldBrushColor;
  13061. Pen.Color := OldPenColor;
  13062. end;
  13063. end;
  13064. end;
  13065. procedure TDefineCheckListExt.SetChecked(Index: Integer; AChecked: Boolean);
  13066. begin
  13067. if AChecked <> GetChecked(Index) then
  13068. begin
  13069. TDefineCheckWrapper (GetWrapper(Index)).SetChecked(AChecked);
  13070. InvalidateCheck(Index);
  13071. end;
  13072. end;
  13073. procedure TDefineCheckListExt.SetItemEnabled(Index: Integer; const Value: Boolean);
  13074. begin
  13075. if Value <> GetItemEnabled(Index) then
  13076. begin
  13077. TDefineCheckWrapper (GetWrapper(Index)).Disabled := not Value;
  13078. InvalidateCheck(Index);
  13079. end;
  13080. end;
  13081. procedure TDefineCheckListExt.SetState(Index: Integer; AState: TCheckBoxState);
  13082. begin
  13083. if AState <> GetState(Index) then
  13084. begin
  13085. TDefineCheckWrapper (GetWrapper(Index)).State := AState;
  13086. InvalidateCheck(Index);
  13087. end;
  13088. end;
  13089. procedure TDefineCheckListExt.InvalidateCheck(Index: Integer);
  13090. var
  13091. R: TRect;
  13092. begin
  13093. if not Header[Index] then
  13094. begin
  13095. R := ItemRect(Index);
  13096. if not UseRightToLeftAlignment then
  13097. R.Right := R.Left + GetCheckWidth
  13098. else
  13099. R.Left := R.Right - GetCheckWidth;
  13100. InvalidateRect(Handle, @R, not (csOpaque in ControlStyle));
  13101. UpdateWindow(Handle);
  13102. end;
  13103. end;
  13104. function TDefineCheckListExt.GetChecked(Index: Integer): Boolean;
  13105. begin
  13106. if HaveWrapper(Index) then
  13107. Result := TDefineCheckWrapper (GetWrapper(Index)).GetChecked
  13108. else
  13109. Result := False;
  13110. end;
  13111. function TDefineCheckListExt.GetItemEnabled(Index: Integer): Boolean;
  13112. begin
  13113. if HaveWrapper(Index) then
  13114. Result := not TDefineCheckWrapper (GetWrapper(Index)).Disabled
  13115. else
  13116. Result := True;
  13117. end;
  13118. function TDefineCheckListExt.GetState(Index: Integer): TCheckBoxState;
  13119. begin
  13120. if HaveWrapper(Index) then
  13121. Result := TDefineCheckWrapper (GetWrapper(Index)).State
  13122. else
  13123. Result := TDefineCheckWrapper .GetDefaultState;
  13124. end;
  13125. procedure TDefineCheckListExt.KeyPress(var Key: Char);
  13126. begin
  13127. if (Key = ' ') then
  13128. ToggleClickCheck(ItemIndex);
  13129. inherited KeyPress(Key);
  13130. end;
  13131. procedure TDefineCheckListExt.MouseDown(Button: TMouseButton; Shift: TShiftState;
  13132. X, Y: Integer);
  13133. var
  13134. Index: Integer;
  13135. begin
  13136. inherited;
  13137. if Button = mbLeft then
  13138. begin
  13139. Index := ItemAtPos(Point(X,Y),True);
  13140. if (Index <> -1) and GetItemEnabled(Index) then
  13141. if not UseRightToLeftAlignment then
  13142. begin
  13143. if X - ItemRect(Index).Left < GetCheckWidth then
  13144. ToggleClickCheck(Index)
  13145. end
  13146. else
  13147. begin
  13148. Dec(X, ItemRect(Index).Right - GetCheckWidth);
  13149. if (X > 0) and (X < GetCheckWidth) then
  13150. ToggleClickCheck(Index)
  13151. end;
  13152. end;
  13153. end;
  13154. procedure TDefineCheckListExt.ToggleClickCheck;
  13155. var
  13156. State: TCheckBoxState;
  13157. begin
  13158. if (Index >= 0) and (Index < Items.Count) and GetItemEnabled(Index) then
  13159. begin
  13160. State := Self.State[Index];
  13161. case State of
  13162. cbUnchecked:
  13163. if AllowGrayed then State := cbGrayed else State := cbChecked;
  13164. cbChecked: State := cbUnchecked;
  13165. cbGrayed: State := cbChecked;
  13166. end;
  13167. Self.State[Index] := State;
  13168. ClickCheck;
  13169. end;
  13170. end;
  13171. procedure TDefineCheckListExt.ClickCheck;
  13172. begin
  13173. if Assigned(FOnClickCheck) then FOnClickCheck(Self);
  13174. end;
  13175. function TDefineCheckListExt.GetItemData(Index: Integer): LongInt;
  13176. begin
  13177. Result := 0;
  13178. if HaveWrapper(Index) then
  13179. Result := TDefineCheckWrapper (GetWrapper(Index)).FData;
  13180. end;
  13181. function TDefineCheckListExt.GetWrapper(Index: Integer): TObject;
  13182. begin
  13183. Result := ExtractWrapper(Index);
  13184. if Result = nil then
  13185. Result := CreateWrapper(Index);
  13186. end;
  13187. function TDefineCheckListExt.ExtractWrapper(Index: Integer): TObject;
  13188. begin
  13189. Result := TDefineCheckWrapper (inherited GetItemData(Index));
  13190. if LB_ERR = Integer(Result) then
  13191. raise EListError.CreateFmt(SListIndexError,[index]);
  13192. if (Result <> nil) and (not (Result is TDefineCheckWrapper )) then
  13193. Result := nil;
  13194. end;
  13195. function TDefineCheckListExt.InternalGetItemData(Index: Integer): LongInt;
  13196. begin
  13197. Result := inherited GetItemData(Index);
  13198. end;
  13199. procedure TDefineCheckListExt.InternalSetItemData(Index: Integer; AData: LongInt);
  13200. begin
  13201. inherited SetItemData(Index, AData);
  13202. end;
  13203. function TDefineCheckListExt.CreateWrapper(Index: Integer): TObject;
  13204. begin
  13205. Result := TDefineCheckWrapper .Create;
  13206. inherited SetItemData(Index, LongInt(Result));
  13207. end;
  13208. function TDefineCheckListExt.HaveWrapper(Index: Integer): Boolean;
  13209. begin
  13210. Result := ExtractWrapper(Index) <> nil;
  13211. end;
  13212. procedure TDefineCheckListExt.SetItemData(Index: Integer; AData: LongInt);
  13213. var
  13214. Wrapper: TDefineCheckWrapper ;
  13215. begin
  13216. if HaveWrapper(Index) or (AData <> 0) then
  13217. begin
  13218. Wrapper := TDefineCheckWrapper (GetWrapper(Index));
  13219. Wrapper.FData := AData;
  13220. end;
  13221. end;
  13222. procedure TDefineCheckListExt.ResetContent;
  13223. var
  13224. I: Integer;
  13225. begin
  13226. for I := 0 to Items.Count - 1 do
  13227. if HaveWrapper(I) then
  13228. GetWrapper(I).Free;
  13229. inherited;
  13230. end;
  13231. procedure TDefineCheckListExt.DeleteString(Index: Integer);
  13232. begin
  13233. if HaveWrapper(Index) then
  13234. GetWrapper(Index).Free;
  13235. inherited;
  13236. end;
  13237. procedure TDefineCheckListExt.SetFlat(Value: Boolean);
  13238. begin
  13239. if Value <> FFlat then
  13240. begin
  13241. FFlat := Value;
  13242. Invalidate;
  13243. end;
  13244. end;
  13245. procedure TDefineCheckListExt.WMDestroy(var Msg: TWMDestroy);
  13246. var
  13247. i: Integer;
  13248. begin
  13249. for i := 0 to Items.Count -1 do
  13250. ExtractWrapper(i).Free;
  13251. inherited;
  13252. end;
  13253. function TDefineCheckListExt.GetHeader(Index: Integer): Boolean;
  13254. begin
  13255. if HaveWrapper(Index) then
  13256. Result := TDefineCheckWrapper (GetWrapper(Index)).Header
  13257. else
  13258. Result := False;
  13259. end;
  13260. procedure TDefineCheckListExt.SetHeader(Index: Integer; const Value: Boolean);
  13261. begin
  13262. if Value <> GetHeader(Index) then
  13263. begin
  13264. TDefineCheckWrapper(GetWrapper(Index)).Header := Value;
  13265. InvalidateCheck(Index);
  13266. end;
  13267. end;
  13268. procedure TDefineCheckListExt.SetHeaderBkColor(const Value: TColor);
  13269. begin
  13270. if Value <> FHeaderBkColor then
  13271. begin
  13272. FHeaderBkColor := Value;
  13273. Invalidate;
  13274. end;
  13275. end;
  13276. procedure TDefineCheckListExt.SetHeaderColor(const Value: TColor);
  13277. begin
  13278. if Value <> HeaderColor then
  13279. begin
  13280. FHeaderColor := Value;
  13281. Invalidate;
  13282. end;
  13283. end;
  13284. procedure TDefineCheckListExt.CheckAll;
  13285. var inx:integer;
  13286. begin
  13287. for inx := 0 to Items.Count - 1 do
  13288. Checked[inx] := true;
  13289. end;
  13290. procedure TDefineCheckListExt.CheckCancel;
  13291. var inx:integer;
  13292. begin
  13293. for inx := 0 to Items.Count - 1 do
  13294. Checked[inx] := False;
  13295. end;
  13296. { TDefineProgressBar }
  13297. constructor TDefineProgressBar.Create (AOwner: TComponent);
  13298. begin
  13299. inherited Create(AOwner);
  13300. Height := 16;
  13301. Width := 147;
  13302. FElementWidth := 8;
  13303. FElementColor := $00996633;
  13304. FBorderColor := DefaultBorderColor;
  13305. ParentColor := True;
  13306. Orientation := pbHorizontal;
  13307. FStep := 10;
  13308. FMin := 0;
  13309. FMax := 100;
  13310. FUseAdvColors := false;
  13311. FAdvColorBorder := 50;
  13312. Transparent := false;
  13313. end;
  13314. procedure TDefineProgressBar.SetOrientation (Value: TProgressBarOrientation);
  13315. begin
  13316. if FOrientation <> Value then
  13317. begin
  13318. FOrientation := Value;
  13319. if (csLoading in ComponentState) then
  13320. begin
  13321. Repaint;
  13322. Exit;
  13323. end;
  13324. SetBounds(Left, Top, Height, Width);
  13325. Invalidate;
  13326. end;
  13327. end;
  13328. procedure TDefineProgressBar.SetMin (Value: Integer);
  13329. begin
  13330. if FMin <> Value then
  13331. begin
  13332. FMin := Value;
  13333. Invalidate;
  13334. end;
  13335. end;
  13336. procedure TDefineProgressBar.SetMax (Value: Integer);
  13337. begin
  13338. if FMax <> Value then
  13339. begin
  13340. if Value < FPosition then FPosition := Value;
  13341. FMax := Value;
  13342. Invalidate;
  13343. end;
  13344. end;
  13345. procedure TDefineProgressBar.SetPosition (Value: Integer);
  13346. begin
  13347. if Value > FMax then Value := FMax;
  13348. if Value < FMin then Value := FMin;
  13349. if Value > FPosition then
  13350. begin
  13351. FPosition := Value;
  13352. DrawElements;
  13353. end;
  13354. if Value < FPosition then
  13355. begin
  13356. FPosition := Value;
  13357. Invalidate;
  13358. end;
  13359. end;
  13360. procedure TDefineProgressBar.SetStep (Value: Integer);
  13361. begin
  13362. if FStep <> Value then
  13363. begin
  13364. FStep := Value;
  13365. Invalidate;
  13366. end;
  13367. end;
  13368. procedure TDefineProgressBar.StepIt;
  13369. begin
  13370. if (FPosition + FStep) > FMax then
  13371. FPosition := FMax
  13372. else
  13373. FPosition := FPosition + FStep;
  13374. DrawElements;
  13375. end;
  13376. procedure TDefineProgressBar.StepBy (Delta: Integer);
  13377. begin
  13378. if (FPosition + Delta) > FMax then
  13379. FPosition := FMax
  13380. else
  13381. FPosition := FPosition + Delta;
  13382. DrawElements;
  13383. end;
  13384. procedure TDefineProgressBar.SetColors (Index: Integer; Value: TColor);
  13385. begin
  13386. case Index of
  13387. 0: FElementColor := Value;
  13388. 1: FBorderColor := Value;
  13389. end;
  13390. Invalidate;
  13391. end;
  13392. procedure TDefineProgressBar.CalcAdvColors;
  13393. begin
  13394. if FUseAdvColors then
  13395. begin
  13396. FBorderColor := CalcAdvancedColor(Color, FBorderColor, FAdvColorBorder, darken);
  13397. end;
  13398. end;
  13399. procedure TDefineProgressBar.SetAdvColors (Index: Integer; Value: TAdvColors);
  13400. begin
  13401. case Index of
  13402. 0: FAdvColorBorder := Value;
  13403. end;
  13404. CalcAdvColors;
  13405. Invalidate;
  13406. end;
  13407. procedure TDefineProgressBar.SetUseAdvColors (Value: Boolean);
  13408. begin
  13409. if Value <> FUseAdvColors then
  13410. begin
  13411. FUseAdvColors := Value;
  13412. ParentColor := Value;
  13413. CalcAdvColors;
  13414. Invalidate;
  13415. end;
  13416. end;
  13417. procedure TDefineProgressBar.CMSysColorChange (var Message: TMessage);
  13418. begin
  13419. if FUseAdvColors then
  13420. begin
  13421. ParentColor := True;
  13422. CalcAdvColors;
  13423. end;
  13424. Invalidate;
  13425. end;
  13426. procedure TDefineProgressBar.CMParentColorChanged (var Message: TWMNoParams);
  13427. begin
  13428. inherited;
  13429. if FUseAdvColors then
  13430. begin
  13431. ParentColor := True;
  13432. CalcAdvColors;
  13433. end;
  13434. Invalidate;
  13435. end;
  13436. procedure TDefineProgressBar.SetSmooth(Value: Boolean);
  13437. begin
  13438. if Value <> FSmooth then
  13439. begin
  13440. FSmooth := Value;
  13441. Invalidate;
  13442. end;
  13443. end;
  13444. procedure TDefineProgressBar.SetTransparent(const Value: Boolean);
  13445. begin
  13446. if FTransparent <> Value then
  13447. begin
  13448. FTransparent := Value;
  13449. Invalidate;
  13450. end;
  13451. end;
  13452. {$IFDEF DFS_COMPILER_4_UP}
  13453. procedure TDefineProgressBar.SetBiDiMode(Value: TBiDiMode);
  13454. begin
  13455. inherited;
  13456. Invalidate;
  13457. end;
  13458. {$ENDIF}
  13459. procedure TDefineProgressBar.CheckBounds;
  13460. var
  13461. maxboxes: Word;
  13462. begin
  13463. if FOrientation = pbHorizontal then
  13464. begin
  13465. maxboxes := (Width - 3) div (FElementWidth + 1);
  13466. if Width < 12 then
  13467. Width := 12
  13468. else
  13469. Width := maxboxes * (FElementWidth + 1) + 3;
  13470. end
  13471. else
  13472. begin
  13473. maxboxes := (Height - 3) div (FElementWidth + 1);
  13474. if Height < 12 then
  13475. Height := 12
  13476. else
  13477. Height := maxboxes * (FElementWidth + 1) + 3;
  13478. end;
  13479. end;
  13480. procedure TDefineProgressBar.Paint;
  13481. var
  13482. PaintRect: TRect;
  13483. begin
  13484. if not Smooth then
  13485. CheckBounds;
  13486. PaintRect := ClientRect;
  13487. // Background
  13488. if not FTransparent then begin
  13489. canvas.Brush.Color := Self.Color;
  13490. canvas.Brush.Style := bsSolid;
  13491. canvas.FillRect(PaintRect);
  13492. end;
  13493. // Border
  13494. canvas.Brush.Color := FBorderColor;
  13495. Canvas.FrameRect(PaintRect);
  13496. // Elements
  13497. DrawElements;
  13498. end;
  13499. procedure TDefineProgressBar.DrawElements;
  13500. var
  13501. NumElements, NumToPaint: LongInt;
  13502. Painted: Byte;
  13503. ElementRect: TRect;
  13504. begin
  13505. with canvas do
  13506. begin
  13507. if not Smooth then begin
  13508. if FOrientation = pbHorizontal then
  13509. begin
  13510. NumElements := Trunc((ClientWidth - 3) div (FElementWidth + 1));
  13511. NumToPaint := Trunc((FPosition - FMin) / ((FMax - FMin) / NumElements) + 0.00000001);
  13512. if NumToPaint > NumElements then
  13513. NumToPaint := NumElements;
  13514. {$IFDEF DFS_COMPILER_4_UP}
  13515. if BidiMode = bdRightToLeft then
  13516. ElementRect := Rect(ClientRect.Right - 2 - FElementWidth, ClientRect.Top + 2, ClientRect.Right - 2, ClientRect.Bottom - 2)
  13517. else
  13518. ElementRect := Rect(ClientRect.Left + 2, ClientRect.Top + 2, ClientRect.Left + 2 + FElementWidth, ClientRect.Bottom - 2);
  13519. {$ELSE}
  13520. ElementRect := Rect(ClientRect.Left + 2, ClientRect.Top + 2, ClientRect.Left + 2 + FElementWidth, ClientRect.Bottom - 2);
  13521. {$ENDIF}
  13522. if NumToPaint > 0 then
  13523. begin
  13524. Brush.Color := FElementColor;
  13525. Brush.Style := bsSolid;
  13526. for Painted := 1 to NumToPaint do
  13527. begin
  13528. Canvas.FillRect(ElementRect);
  13529. {$IFDEF DFS_COMPILER_4_UP}
  13530. if BidiMode = bdRightToLeft then
  13531. begin
  13532. ElementRect.Left := ElementRect.Left - FElementWidth - 1;
  13533. ElementRect.Right := ElementRect.Right - FElementWidth - 1;
  13534. end
  13535. else
  13536. begin
  13537. ElementRect.Left := ElementRect.Left + FElementWidth + 1;
  13538. ElementRect.Right := ElementRect.Right + FElementWidth + 1;
  13539. end;
  13540. {$ELSE}
  13541. ElementRect.Left := ElementRect.Left + FElementWidth + 1;
  13542. ElementRect.Right := ElementRect.Right + FElementWidth + 1;
  13543. {$ENDIF}
  13544. end;
  13545. end;
  13546. end
  13547. else
  13548. begin
  13549. NumElements := Trunc((ClientHeight - 3) div (FElementWidth + 1));
  13550. NumToPaint := Trunc((FPosition - FMin) / ((FMax - FMin) / NumElements) + 0.00000001);
  13551. if NumToPaint > NumElements then
  13552. NumToPaint := NumElements;
  13553. ElementRect := Rect(ClientRect.Left + 2, ClientRect.Bottom - FElementWidth - 2, ClientRect.Right - 2, ClientRect.Bottom - 2);
  13554. if NumToPaint > 0 then
  13555. begin
  13556. Brush.Color := FElementColor;
  13557. Brush.Style := bsSolid;
  13558. for Painted := 1 to NumToPaint do
  13559. begin
  13560. Canvas.FillRect(ElementRect);
  13561. ElementRect.Top := ElementRect.Top - (FElementWidth + 1);
  13562. ElementRect.Bottom := ElementRect.Bottom - (FElementWidth + 1);
  13563. end;
  13564. end;
  13565. end;
  13566. end
  13567. else
  13568. begin
  13569. if (FOrientation = pbHorizontal) and (FPosition > 0) then
  13570. begin
  13571. Brush.Color := FElementColor;
  13572. Canvas.FillRect(Rect(2, 2, ClientRect.Left + 2 + ((FPosition * (ClientWidth - 4)) div (FMax - FMin)), ClientRect.Bottom - 2));
  13573. end
  13574. else
  13575. begin
  13576. Brush.Color := FElementColor;
  13577. Canvas.FillRect(Rect(2, ClientRect.Bottom - 2 - ((FPosition * (ClientHeight - 4)) div (FMax - FMin)), ClientRect.Right - 2, ClientRect.Bottom - 2));
  13578. end;
  13579. end;
  13580. end;
  13581. end;
  13582. { TDefineTitlebar }
  13583. constructor TDefineTitlebar.Create(AOwner: TComponent);
  13584. begin
  13585. inherited Create(AOwner);
  13586. Width := 100;
  13587. Height := 19;
  13588. ControlStyle := ControlStyle + [csAcceptsControls];
  13589. TitlebarColor := ecCaptionBackground;
  13590. ActiveTextColor := ecActiveCaption;
  13591. InactiveTextColor := ecInactiveCaption;
  13592. if csDesigning in ComponentState then
  13593. begin
  13594. FActive := True;
  13595. end;
  13596. end;
  13597. destructor TDefineTitlebar.Destroy;
  13598. begin
  13599. inherited Destroy;
  13600. end;
  13601. procedure TDefineTitlebar.Loaded;
  13602. var
  13603. Wnd: HWND;
  13604. begin
  13605. inherited Loaded;
  13606. if not (csDesigning in ComponentState) and (FForm <> nil) then
  13607. begin
  13608. if FForm <> nil then
  13609. begin
  13610. Wnd := FForm.Handle;
  13611. FWndProcInstance := MakeObjectInstance(FormWndProc);
  13612. FDefProc := SetWindowLong(Wnd,GWL_WNDPROC,LongInt(FWndProcInstance));
  13613. end;
  13614. end;
  13615. end;
  13616. procedure TDefineTitlebar.FormWndProc(var Message: TMessage);
  13617. begin
  13618. case Message.Msg of
  13619. WM_ACTIVATE: DoActivateMessage(TWMActivate(Message));
  13620. end;
  13621. Message.Result := CallWindowProc(Pointer(FDefProc),FForm.Handle,Message.Msg,Message.WParam, Message.LParam);
  13622. end;
  13623. procedure TDefineTitlebar.DoActivateMessage(var Message: TWMActivate);
  13624. begin
  13625. case Message.Active of
  13626. WA_ACTIVE: DoActivation;
  13627. WA_CLICKACTIVE: DoActivation;
  13628. WA_INACTIVE: DoDeactivation;
  13629. end;
  13630. end;
  13631. procedure TDefineTitlebar.DoActivation;
  13632. begin
  13633. FActive := True;
  13634. Invalidate;
  13635. if Assigned(FOnActivate) then FOnActivate(Self);
  13636. end;
  13637. procedure TDefineTitlebar.DoDeactivation;
  13638. begin
  13639. FActive := False;
  13640. Invalidate;
  13641. if Assigned(FOnDeactivate) then FOnDeactivate(Self);
  13642. end;
  13643. procedure TDefineTitlebar.Paint;
  13644. var
  13645. iCaptionWidth, iCaptionHeight, iX, iY: Integer;
  13646. begin
  13647. with Canvas do
  13648. begin
  13649. with ClientRect do
  13650. begin
  13651. Canvas.Font.Assign(Self.Font);
  13652. case FActive of
  13653. True: Canvas.Font.Color := FActiveTextColor;
  13654. False: Canvas.Font.Color := FInactiveTextColor;
  13655. end;
  13656. iCaptionWidth := TextWidth(Caption);
  13657. iCaptionHeight := TextHeight(Caption);
  13658. Brush.Color := TitlebarColor;
  13659. FillRect(ClientRect);
  13660. iX := Width div 2 - iCaptionWidth div 2;
  13661. iY := Height div 2 - iCaptionHeight div 2;
  13662. TextOut(iX,iY,Caption);
  13663. end;
  13664. end;
  13665. end;
  13666. procedure TDefineTitlebar.MouseMove;
  13667. begin
  13668. if FDown then
  13669. begin
  13670. TCustomForm(Owner).Left := TCustomForm(Owner).Left + X - FOldX;
  13671. TCustomForm(Owner).Top := TCustomForm(Owner).Top + Y - FOldY;
  13672. end;
  13673. end;
  13674. procedure TDefineTitlebar.MouseUp;
  13675. begin
  13676. FDown := False;
  13677. end;
  13678. procedure TDefineTitlebar.MouseDown;
  13679. begin
  13680. if (Button = mbleft) and not FDown then FDown := True;
  13681. FOldX := X;
  13682. FOldy := Y;
  13683. end;
  13684. procedure TDefineTitlebar.SetActiveTextColor(Value: TColor);
  13685. begin
  13686. if Value <> FActiveTextColor then
  13687. begin
  13688. FActiveTextColor := Value;
  13689. Invalidate;
  13690. end;
  13691. end;
  13692. procedure TDefineTitlebar.SetInactiveTextColor(Value: TColor);
  13693. begin
  13694. if Value <> FInactiveTextColor then
  13695. begin
  13696. FInactiveTextColor := Value;
  13697. Invalidate;
  13698. end;
  13699. end;
  13700. procedure TDefineTitlebar.SetTitlebarColor(Value: TColor);
  13701. begin
  13702. if Value <> FTitlebarColor then
  13703. begin
  13704. FTitlebarColor := Value;
  13705. Invalidate;
  13706. end;
  13707. end;
  13708. procedure TDefineTitlebar.SetParent(AParent: TWinControl);
  13709. begin
  13710. if (AParent <> nil) and not(AParent is TCustomForm) then
  13711. raise EInvalidOperation.Create(SParentForm);
  13712. FForm := TCustomForm(AParent);
  13713. inherited;
  13714. end;
  13715. procedure TDefineTitlebar.CMFontChanged (var Message: TMessage);
  13716. begin
  13717. Invalidate;
  13718. end;
  13719. procedure TDefineTitlebar.CMTextChanged (var Message: TMessage);
  13720. begin
  13721. Invalidate;
  13722. end;
  13723. { TDefineScrollbarTrackThumb }
  13724. constructor TDefineScrollbarThumb.Create(AOwner: TComponent);
  13725. begin
  13726. inherited Create(AOwner);
  13727. end;
  13728. procedure TDefineScrollbarThumb.MouseMove(Shift: TShiftState; X, Y: Integer);
  13729. var
  13730. iTop: Integer;
  13731. begin
  13732. if TDefineScrollbarTrack(Parent).Kind = sbVertical then
  13733. begin
  13734. FTopLimit := 0;
  13735. FBottomLimit := TDefineScrollbarTrack(Parent).Height;
  13736. if FDown = True then
  13737. begin
  13738. iTop := Top + Y - FOldY;
  13739. if iTop < FTopLimit then
  13740. begin
  13741. iTop := FTopLimit;
  13742. end;
  13743. if (iTop > FBottomLimit) or ((iTop + Height) > FBottomLimit) then
  13744. begin
  13745. iTop := FBottomLimit - Height;
  13746. end;
  13747. Top := iTop;
  13748. end;
  13749. end
  13750. else
  13751. begin
  13752. FTopLimit := 0;
  13753. FBottomLimit := TDefineScrollbarTrack(Parent).Width;
  13754. if FDown = True then
  13755. begin
  13756. iTop := Left + X - FOldX;
  13757. if iTop < FTopLimit then
  13758. begin
  13759. iTop := FTopLimit;
  13760. end;
  13761. if (iTop > FBottomLimit) or ((iTop + Width) > FBottomLimit) then
  13762. begin
  13763. iTop := FBottomLimit - Width;
  13764. end;
  13765. Left := iTop;
  13766. end;
  13767. end;
  13768. TDefineScrollbarTrack(Parent).FPosition := TDefineScrollbarTrack(Parent).PositionFromThumb;
  13769. TDefineScrollbarTrack(Parent).DoPositionChange;
  13770. inherited MouseMove(Shift,X,Y);
  13771. end;
  13772. procedure TDefineScrollbarThumb.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  13773. begin
  13774. FDown := False;
  13775. inherited MouseUp(Button,Shift,X,Y);
  13776. end;
  13777. procedure TDefineScrollbarThumb.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  13778. begin
  13779. if (Button = mbleft) and not FDown then FDown := True;
  13780. FOldX := X;
  13781. FOldy := Y;
  13782. inherited MouseDown(Button,Shift,X,Y);
  13783. end;
  13784. { TDefineScrollbarTrack }
  13785. constructor TDefineScrollbarTrack.Create(AOwner: TComponent);
  13786. begin
  13787. inherited Create(AOwner);
  13788. Color := ecLightKaki;
  13789. FThumb := TDefineScrollbarThumb.Create(Self);
  13790. FThumb.Color := ecLightBrown;
  13791. FThumb.ColorFocused := ecLightBrown;
  13792. FThumb.ColorDown := ecLightBrown;
  13793. FThumb.ColorBorder := ecLightBrown;
  13794. //FThumb.ColorHighLight := ecLightBrown;
  13795. FThumb.ColorShadow := ecLightBrown;
  13796. FThumb.Height := 17;
  13797. InsertControl(FThumb);
  13798. FMin := 0;
  13799. FMax := 100;
  13800. FSmallChange := 1;
  13801. FLargeChange := 1;
  13802. FPosition := 0;
  13803. FThumb.Top := ThumbFromPosition;
  13804. end;
  13805. destructor TDefineScrollbarTrack.Destroy;
  13806. begin
  13807. FThumb.Free;
  13808. inherited Destroy;
  13809. end;
  13810. procedure TDefineScrollbarTrack.Paint;
  13811. begin
  13812. with Canvas do
  13813. begin
  13814. Brush.Color := Color;
  13815. FillRect(ClientRect);
  13816. end;
  13817. end;
  13818. procedure TDefineScrollbarTrack.SetSmallChange(Value: Integer);
  13819. begin
  13820. if Value <> FSmallChange then
  13821. begin
  13822. FSmallChange := Value;
  13823. end;
  13824. end;
  13825. procedure TDefineScrollbarTrack.SetLargeChange(Value: Integer);
  13826. begin
  13827. if Value <> FLargeChange then
  13828. begin
  13829. FLargeChange := Value;
  13830. end;
  13831. end;
  13832. procedure TDefineScrollbarTrack.SetMin(Value: Integer);
  13833. begin
  13834. if Value <> FMin then
  13835. begin
  13836. FMin := Value;
  13837. FThumb.Top := ThumbFromPosition;
  13838. end;
  13839. end;
  13840. procedure TDefineScrollbarTrack.SetMax(Value: Integer);
  13841. begin
  13842. if Value <> FMax then
  13843. begin
  13844. FMax := Value;
  13845. FThumb.Top := ThumbFromPosition;
  13846. end;
  13847. end;
  13848. procedure TDefineScrollbarTrack.SetPosition(Value: Integer);
  13849. begin
  13850. FPosition := Value;
  13851. if Position > Max then
  13852. begin
  13853. Position := Max;
  13854. end;
  13855. if Position < Min then
  13856. begin
  13857. Position := Min;
  13858. end;
  13859. case FKind of
  13860. sbVertical: FThumb.Top := ThumbFromPosition;
  13861. sbHorizontal: FThumb.Left := ThumbFromPosition;
  13862. end;
  13863. end;
  13864. procedure TDefineScrollbarTrack.SetKind(Value: TScrollBarKind);
  13865. begin
  13866. if Value <> FKind then
  13867. begin
  13868. FKind:= Value;
  13869. case FKind of
  13870. sbVertical: FThumb.Height := 17;
  13871. sbHorizontal: FThumb.Width := 17;
  13872. end;
  13873. end;
  13874. Position := FPosition;
  13875. end;
  13876. procedure TDefineScrollbarTrack.WMSize(var Message: TMessage);
  13877. begin
  13878. if FKind = sbVertical then
  13879. begin
  13880. FThumb.Width := Width;
  13881. end
  13882. else
  13883. begin
  13884. FThumb.Height := Height;
  13885. end;
  13886. end;
  13887. function TDefineScrollbarTrack.ThumbFromPosition: Integer;
  13888. var
  13889. iHW, iMin, iMax, iPosition, iResult: Integer;
  13890. begin
  13891. iHW := 0;
  13892. case FKind of
  13893. sbVertical: iHW := Height - FThumb.Height;
  13894. sbHorizontal: iHW := Width - FThumb.Width;
  13895. end;
  13896. iMin := FMin;
  13897. iMax := FMax;
  13898. iPosition := FPosition;
  13899. iResult := Round((iHW / (iMax - iMin)) * iPosition);
  13900. Result := iResult;
  13901. end;
  13902. function TDefineScrollbarTrack.PositionFromThumb: Integer;
  13903. var
  13904. iHW, iMin, iMax, iPosition, iResult: Integer;
  13905. begin
  13906. iHW := 0;
  13907. case FKind of
  13908. sbVertical: iHW := Height - FThumb.Height;
  13909. sbHorizontal: iHW := Width - FThumb.Width;
  13910. end;
  13911. iMin := FMin;
  13912. iMax := FMax;
  13913. iPosition := 0;
  13914. case FKind of
  13915. sbVertical: iPosition := FThumb.Top;
  13916. sbHorizontal: iPosition := FThumb.Left;
  13917. end;
  13918. iResult := Round(iPosition / iHW * (iMax - iMin));
  13919. Result := iResult;
  13920. end;
  13921. procedure TDefineScrollbarTrack.DoPositionChange;
  13922. begin
  13923. TDefineScrollbar(Parent).FPosition := Position;
  13924. TDefineScrollbar(Parent).DoScroll;
  13925. end;
  13926. procedure TDefineScrollbarTrack.DoThumbHighlightColor(Value: TColor);
  13927. begin
  13928. //FThumb.ColorHighlight := Value;
  13929. end;
  13930. procedure TDefineScrollbarTrack.DoThumbShadowColor(Value: TColor);
  13931. begin
  13932. FThumb.ColorShadow := Value;
  13933. end;
  13934. procedure TDefineScrollbarTrack.DoThumbBorderColor(Value: TColor);
  13935. begin
  13936. FThumb.ColorBorder := Value;
  13937. end;
  13938. procedure TDefineScrollbarTrack.DoThumbFocusedColor(Value: TColor);
  13939. begin
  13940. FThumb.ColorFocused := Value;
  13941. end;
  13942. procedure TDefineScrollbarTrack.DoThumbDownColor(Value: TColor);
  13943. begin
  13944. FThumb.ColorDown := Value;
  13945. end;
  13946. procedure TDefineScrollbarTrack.DoThumbColor(Value: TColor);
  13947. begin
  13948. FThumb.Color := Value;
  13949. end;
  13950. procedure TDefineScrollbarTrack.DoHScroll(var Message: TWMScroll);
  13951. var
  13952. iPosition: Integer;
  13953. begin
  13954. case Message.ScrollCode of
  13955. SB_BOTTOM: Position := Max;
  13956. SB_LINELEFT: begin
  13957. iPosition := Position;
  13958. Dec(iPosition,SmallChange);
  13959. Position := iPosition;
  13960. end;
  13961. SB_LINERIGHT: begin
  13962. iPosition := Position;
  13963. Inc(iPosition,SmallChange);
  13964. Position := iPosition;
  13965. end;
  13966. SB_PAGELEFT: begin
  13967. iPosition := Position;
  13968. Dec(iPosition,LargeChange);
  13969. Position := iPosition;
  13970. end;
  13971. SB_PAGERIGHT: begin
  13972. iPosition := Position;
  13973. Inc(iPosition,LargeChange);
  13974. Position := iPosition;
  13975. end;
  13976. SB_THUMBPOSITION, SB_THUMBTRACK: Position := Message.Pos;
  13977. SB_TOP: Position := Min;
  13978. end;
  13979. Message.Result := 0;
  13980. end;
  13981. procedure TDefineScrollbarTrack.DoVScroll(var Message: TWMScroll);
  13982. var
  13983. iPosition: Integer;
  13984. begin
  13985. case Message.ScrollCode of
  13986. SB_BOTTOM: Position := Max;
  13987. SB_LINEUP: begin
  13988. iPosition := Position;
  13989. Dec(iPosition,SmallChange);
  13990. Position := iPosition;
  13991. end;
  13992. SB_LINEDOWN: begin
  13993. iPosition := Position;
  13994. Inc(iPosition,SmallChange);
  13995. Position := iPosition;
  13996. end;
  13997. SB_PAGEUP: begin
  13998. iPosition := Position;
  13999. Dec(iPosition,LargeChange);
  14000. Position := iPosition;
  14001. end;
  14002. SB_PAGEDOWN: begin
  14003. iPosition := Position;
  14004. Inc(iPosition,LargeChange);
  14005. Position := iPosition;
  14006. end;
  14007. SB_THUMBPOSITION, SB_THUMBTRACK: Position := Message.Pos;
  14008. SB_TOP: Position := Min;
  14009. end;
  14010. Message.Result := 0;
  14011. end;
  14012. procedure TDefineScrollbarTrack.DoEnableArrows(var Message: TMessage);
  14013. begin
  14014. if Message.WParam = ESB_DISABLE_BOTH then
  14015. begin
  14016. TDefineScrollbar(Parent).EnableBtnOne(False);
  14017. TDefineScrollbar(Parent).EnableBtnTwo(False);
  14018. end;
  14019. if Message.WParam = ESB_DISABLE_DOWN then
  14020. begin
  14021. if FKind = sbVertical then TDefineScrollbar(Parent).EnableBtnTwo(False);
  14022. end;
  14023. if Message.WParam = ESB_DISABLE_LTUP then
  14024. begin
  14025. TDefineScrollbar(Parent).EnableBtnOne(False);
  14026. end;
  14027. if Message.WParam = ESB_DISABLE_LEFT then
  14028. begin
  14029. if FKind = sbHorizontal then TDefineScrollbar(Parent).EnableBtnOne(False);
  14030. end;
  14031. if Message.WParam = ESB_DISABLE_RTDN then
  14032. begin
  14033. TDefineScrollbar(Parent).EnableBtnTwo(False);
  14034. end;
  14035. if Message.WParam = ESB_DISABLE_UP then
  14036. begin
  14037. if FKind = sbVertical then TDefineScrollbar(Parent).EnableBtnOne(False);
  14038. end;
  14039. if Message.WParam = ESB_ENABLE_BOTH then
  14040. begin
  14041. TDefineScrollbar(Parent).EnableBtnOne(True);
  14042. TDefineScrollbar(Parent).EnableBtnTwo(True);
  14043. end;
  14044. Message.Result := 1;
  14045. end;
  14046. procedure TDefineScrollbarTrack.DoGetPos(var Message: TMessage);
  14047. begin
  14048. Message.Result := Position;
  14049. end;
  14050. procedure TDefineScrollbarTrack.DoGetRange(var Message: TMessage);
  14051. begin
  14052. Message.WParam := Min;
  14053. Message.LParam := Max;
  14054. end;
  14055. procedure TDefineScrollbarTrack.DoSetPos(var Message: TMessage);
  14056. begin
  14057. Position := Message.WParam;
  14058. end;
  14059. procedure TDefineScrollbarTrack.DoSetRange(var Message: TMessage);
  14060. begin
  14061. Min := Message.WParam;
  14062. Max := Message.LParam;
  14063. end;
  14064. procedure TDefineScrollbarTrack.DoKeyDown(var Message: TWMKeyDown);
  14065. var
  14066. iPosition: Integer;
  14067. begin
  14068. iPosition := Position;
  14069. case Message.CharCode of
  14070. VK_PRIOR: Dec(iPosition,LargeChange);
  14071. VK_NEXT: Inc(iPosition,LargeChange);
  14072. VK_UP: if FKind = sbVertical then Dec(iPosition,SmallChange);
  14073. VK_DOWN: if FKind = sbVertical then Inc(iPosition,SmallChange);
  14074. VK_LEFT: if FKind = sbHorizontal then Dec(iPosition,SmallChange);
  14075. VK_RIGHT: if FKind = sbHorizontal then Inc(iPosition,SmallChange);
  14076. end;
  14077. Position := iPosition;
  14078. end;
  14079. { TDefineScrollbarButton }
  14080. constructor TDefineScrollbarButton.Create(AOwner: TComponent);
  14081. begin
  14082. inherited Create(AOwner);
  14083. end;
  14084. destructor TDefineScrollbarButton.Destroy;
  14085. begin
  14086. inherited Destroy;
  14087. end;
  14088. procedure TDefineScrollbarButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  14089. begin
  14090. inherited MouseDown(Button,Shift,X,Y);
  14091. FNewDown := True;
  14092. FTimer := TTimer.Create(Self);
  14093. FTimer.Interval := 10;
  14094. FTimer.OnTimer := DoTimer;
  14095. FTimer.Enabled := True;
  14096. end;
  14097. procedure TDefineScrollbarButton.MouseMove(Shift: TShiftState; X, Y: Integer);
  14098. begin
  14099. inherited MouseMove(Shift,X,Y);
  14100. end;
  14101. procedure TDefineScrollbarButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  14102. begin
  14103. inherited MouseUp(Button,Shift,X,Y);
  14104. FNewDown := False;
  14105. FTimer.Enabled := False;
  14106. FTimer.Free;
  14107. end;
  14108. procedure TDefineScrollbarButton.DoTimer(Sender: TObject);
  14109. begin
  14110. if FNewDown = True then
  14111. begin
  14112. if Assigned(FOnDown) then FOnDown(Self);
  14113. TDefineScrollbar(Parent).DoScroll;
  14114. end;
  14115. end;
  14116. { TDefineScrollbar }
  14117. constructor TDefineScrollbar.Create(AOwner: TComponent);
  14118. begin
  14119. inherited Create(AOwner);
  14120. Width := 200;
  14121. Height := 17;
  14122. Color := ecLightKaki;
  14123. FBtnOne := TDefineScrollbarButton.Create(Self);
  14124. FBtnOne.Color := ecLightKaki;
  14125. FBtnOne.ColorFocused := ecLightKaki;
  14126. FBtnOne.ColorDown := ecLightKaki;
  14127. FBtnOne.ColorBorder := ecLightKaki;
  14128. FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
  14129. FBtnOne.OnDown := BtnOneClick;
  14130. InsertControl(FBtnOne);
  14131. FBtnTwo := TDefineScrollbarButton.Create(Self);
  14132. FBtnTwo.Color := ecLightKaki;
  14133. FBtnTwo.ColorFocused := ecLightKaki;
  14134. FBtnTwo.ColorDown := ecLightKaki;
  14135. FBtnTwo.ColorBorder := ecLightKaki;
  14136. FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_ENABLED');
  14137. FBtnTwo.OnDown := BtnTwoClick;
  14138. InsertControl(FBtnTwo);
  14139. FTrack := TDefineScrollbarTrack.Create(Self);
  14140. FTrack.Color := ecLightKaki;
  14141. FTrack.SetBounds(0,0,Width,Height);
  14142. InsertControl(FTrack);
  14143. Kind := sbVertical;
  14144. Min := 0;
  14145. Max := 100;
  14146. Position := 0;
  14147. SmallChange := 1;
  14148. LargeChange := 1;
  14149. ButtonColor := ecScrollbar;
  14150. ButtonFocusedColor := ecScrollbar;
  14151. ButtonDownColor := ecScrollbar;
  14152. ButtonBorderColor := ecScrollbar;
  14153. ButtonHighlightColor := clWhite;
  14154. ButtonShadowColor := clBlack;
  14155. ThumbColor := ecScrollbarThumb;
  14156. ThumbFocusedColor := ecScrollbarThumb;
  14157. ThumbDownColor := ecScrollbarThumb;
  14158. ThumbBorderColor := ecScrollbarThumb;
  14159. ThumbHighlightColor := ecScrollbarThumb;
  14160. ThumbShadowColor := ecScrollbarThumb;
  14161. end;
  14162. destructor TDefineScrollbar.Destroy;
  14163. begin
  14164. FTrack.Free;
  14165. FBtnOne.Free;
  14166. FBtnTwo.Free;
  14167. inherited Destroy;
  14168. end;
  14169. procedure TDefineScrollbar.SetSmallChange(Value: Integer);
  14170. begin
  14171. if Value <> FSmallChange then
  14172. begin
  14173. FSmallChange := Value;
  14174. FTrack.SmallChange := FSmallChange;
  14175. end;
  14176. end;
  14177. procedure TDefineScrollbar.SetLargeChange(Value: Integer);
  14178. begin
  14179. if Value <> FLargeChange then
  14180. begin
  14181. FLargeChange := Value;
  14182. FTrack.LargeChange := FLargeChange;
  14183. end;
  14184. end;
  14185. procedure TDefineScrollbar.SetMin(Value: Integer);
  14186. begin
  14187. if Value <> FMin then
  14188. begin
  14189. FMin := Value;
  14190. FTrack.Min := FMin;
  14191. end;
  14192. end;
  14193. procedure TDefineScrollbar.SetMax(Value: Integer);
  14194. begin
  14195. if Value <> FMax then
  14196. begin
  14197. FMax := Value;
  14198. FTrack.Max := FMax;
  14199. end;
  14200. end;
  14201. procedure TDefineScrollbar.SetPosition(Value: Integer);
  14202. begin
  14203. FPosition := Value;
  14204. if Position < Min then
  14205. begin
  14206. Position := Min;
  14207. end;
  14208. if Position > Max then
  14209. begin
  14210. Position := Max;
  14211. end;
  14212. FTrack.Position := FPosition;
  14213. end;
  14214. procedure TDefineScrollbar.SetKind(Value: TScrollBarKind);
  14215. var
  14216. i: Integer;
  14217. begin
  14218. if FKind <> Value then
  14219. begin
  14220. FKind := Value;
  14221. FTrack.Kind := FKind;
  14222. if FKind = sbVertical then
  14223. begin
  14224. FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
  14225. FBtnOne.Refresh;
  14226. FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_ENABLED');
  14227. FBtnTwo.Refresh;
  14228. end
  14229. else
  14230. begin
  14231. FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_ENABLED');
  14232. FBtnOne.Refresh;
  14233. FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_RIGHT_ENABLED');
  14234. FBtnTwo.Refresh;
  14235. end;
  14236. if (csDesigning in ComponentState) and not (csLoading in ComponentState) then
  14237. begin
  14238. i := Width;
  14239. Width := Height;
  14240. Height := i;
  14241. end;
  14242. end;
  14243. end;
  14244. procedure TDefineScrollbar.SetButtonHighlightColor(Value: TColor);
  14245. begin
  14246. if Value <> FButtonHighlightColor then
  14247. begin
  14248. FButtonHighlightColor := Value;
  14249. //FBtnOne.ColorHighlight := ButtonHighlightColor;
  14250. //FBtnTwo.ColorHighlight := ButtonHighlightColor;
  14251. end;
  14252. end;
  14253. procedure TDefineScrollbar.SetButtonShadowColor(Value: TColor);
  14254. begin
  14255. if Value <> FButtonShadowColor then
  14256. begin
  14257. FButtonShadowColor := Value;
  14258. FBtnOne.ColorShadow := ButtonShadowColor;
  14259. FBtnTwo.ColorShadow := ButtonShadowColor;
  14260. end;
  14261. end;
  14262. procedure TDefineScrollbar.SetButtonBorderColor(Value: TColor);
  14263. begin
  14264. if Value <> FButtonBorderColor then
  14265. begin
  14266. FButtonBorderColor := Value;
  14267. FBtnOne.ColorBorder := ButtonBorderColor;
  14268. FBtnTwo.ColorBorder := ButtonBorderColor;
  14269. end;
  14270. end;
  14271. procedure TDefineScrollbar.SetButtonFocusedColor(Value: TColor);
  14272. begin
  14273. if Value <> FButtonFocusedColor then
  14274. begin
  14275. FButtonFocusedColor := Value;
  14276. FBtnOne.ColorFocused := ButtonFocusedColor;
  14277. FBtnTwo.ColorFocused := ButtonFocusedColor;
  14278. end;
  14279. end;
  14280. procedure TDefineScrollbar.SetButtonDownColor(Value: TColor);
  14281. begin
  14282. if Value <> FButtonDownColor then
  14283. begin
  14284. FButtonDownColor := Value;
  14285. FBtnOne.ColorDown := ButtonDownColor;
  14286. FBtnTwo.ColorDown := ButtonDownColor;
  14287. end;
  14288. end;
  14289. procedure TDefineScrollbar.SetButtonColor(Value: TColor);
  14290. begin
  14291. if Value <> FButtonColor then
  14292. begin
  14293. FButtonColor := Value;
  14294. FBtnOne.Color := ButtonColor;
  14295. FBtnTwo.Color := ButtonColor;
  14296. end;
  14297. end;
  14298. procedure TDefineScrollbar.SetThumbHighlightColor(Value: TColor);
  14299. begin
  14300. if Value <> FThumbHighlightColor then
  14301. begin
  14302. FThumbHighlightColor := Value;
  14303. FTrack.DoThumbHighlightColor(Value);
  14304. end;
  14305. end;
  14306. procedure TDefineScrollbar.SetThumbShadowColor(Value: TColor);
  14307. begin
  14308. if Value <> FThumbShadowColor then
  14309. begin
  14310. FThumbShadowColor := Value;
  14311. FTrack.DoThumbShadowColor(Value);
  14312. end;
  14313. end;
  14314. procedure TDefineScrollbar.SetThumbBorderColor(Value: TColor);
  14315. begin
  14316. if Value <> FThumbBorderColor then
  14317. begin
  14318. FThumbBorderColor := Value;
  14319. FTrack.DoThumbBorderColor(Value);
  14320. end;
  14321. end;
  14322. procedure TDefineScrollbar.SetThumbFocusedColor(Value: TColor);
  14323. begin
  14324. if Value <> FThumbFocusedColor then
  14325. begin
  14326. FThumbFocusedColor := Value;
  14327. FTrack.DoThumbFocusedColor(Value);
  14328. end;
  14329. end;
  14330. procedure TDefineScrollbar.SetThumbDownColor(Value: TColor);
  14331. begin
  14332. if Value <> FThumbDownColor then
  14333. begin
  14334. FThumbDownColor := Value;
  14335. FTrack.DoThumbDownColor(Value);
  14336. end;
  14337. end;
  14338. procedure TDefineScrollbar.SetThumbColor(Value: TColor);
  14339. begin
  14340. if Value <> FThumbColor then
  14341. begin
  14342. FThumbColor := Value;
  14343. FTrack.DoThumbColor(Value);
  14344. end;
  14345. end;
  14346. procedure TDefineScrollbar.BtnOneClick(Sender: TObject);
  14347. var
  14348. iPosition: Integer;
  14349. begin
  14350. iPosition := Position;
  14351. Dec(iPosition,SmallChange);
  14352. Position := iPosition;
  14353. end;
  14354. procedure TDefineScrollbar.BtnTwoClick(Sender: TObject);
  14355. var
  14356. iPosition: Integer;
  14357. begin
  14358. iPosition := Position;
  14359. Inc(iPosition,SmallChange);
  14360. Position := iPosition;
  14361. end;
  14362. procedure TDefineScrollbar.EnableBtnOne(Value: Boolean);
  14363. begin
  14364. if Value = True then
  14365. begin
  14366. FBtnOne.Enabled := True;
  14367. case FKind of
  14368. sbVertical: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_ENABLED');
  14369. sbHorizontal: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_ENABLED');
  14370. end;
  14371. end
  14372. else
  14373. begin
  14374. case FKind of
  14375. sbVertical: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_UP_DISABLED');
  14376. sbHorizontal: FBtnOne.Glyph.LoadFromResourceName(hInstance,'THUMB_LEFT_DISABLED');
  14377. end;
  14378. FBtnOne.Enabled := False;
  14379. end;
  14380. end;
  14381. procedure TDefineScrollbar.EnableBtnTwo(Value: Boolean);
  14382. begin
  14383. if Value = True then
  14384. begin
  14385. FBtnTwo.Enabled := True;
  14386. case FKind of
  14387. sbVertical: FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_ENABLED');
  14388. sbHorizontal: FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_RIGHT_ENABLED');
  14389. end;
  14390. end
  14391. else
  14392. begin
  14393. case FKind of
  14394. sbVertical: FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_DOWN_DISABLED');
  14395. sbHorizontal: FBtnTwo.Glyph.LoadFromResourceName(hInstance,'THUMB_RIGHT_DISABLED');
  14396. end;
  14397. FBtnTwo.Enabled := False;
  14398. end;
  14399. end;
  14400. procedure TDefineScrollbar.WMSize(var Message: TWMSize);
  14401. begin
  14402. if FKind = sbVertical then
  14403. begin
  14404. SetBounds(Left, Top, Width, Height);
  14405. FBtnOne.SetBounds(0,0,Width,17);
  14406. FBtnTwo.SetBounds(0,Height - 17,Width,17);
  14407. FTrack.SetBounds(0,17,Width,Height - 34);
  14408. end
  14409. else
  14410. begin
  14411. SetBounds(Left, Top, Width, Height);
  14412. FBtnOne.SetBounds(0,0,17,Height);
  14413. FBtnTwo.SetBounds(Width - 17,0,17,Height);
  14414. FTrack.SetBounds(17,0,Width - 34,Height);
  14415. end;
  14416. Position := FPosition;
  14417. end;
  14418. procedure TDefineScrollbar.DoScroll;
  14419. begin
  14420. if Assigned(FOnScroll) then FOnScroll(Self,Position);
  14421. end;
  14422. { These scrollbar messages are just passed onto the TDefineScrollbarTrack for handling }
  14423. procedure TDefineScrollbar.CNHScroll(var Message: TWMScroll);
  14424. begin
  14425. FTrack.DoHScroll(Message);
  14426. end;
  14427. procedure TDefineScrollbar.CNVScroll(var Message: TWMScroll);
  14428. begin
  14429. FTrack.DoVScroll(Message);
  14430. end;
  14431. procedure TDefineScrollbar.SBMEnableArrows(var Message: TMessage);
  14432. begin
  14433. FTrack.DoEnableArrows(Message);
  14434. end;
  14435. procedure TDefineScrollbar.SBMGetPos(var Message: TMessage);
  14436. begin
  14437. FTrack.DoGetPos(Message);
  14438. end;
  14439. procedure TDefineScrollbar.SBMGetRange(var Message: TMessage);
  14440. begin
  14441. FTrack.DoGetRange(Message);
  14442. end;
  14443. procedure TDefineScrollbar.SBMSetPos(var Message: TMessage);
  14444. begin
  14445. FTrack.DoSetPos(Message);
  14446. end;
  14447. procedure TDefineScrollbar.SBMSetRange(var Message: TMessage);
  14448. begin
  14449. FTrack.DoSetRange(Message);
  14450. end;
  14451. { This message handler handles keyboard events }
  14452. procedure TDefineScrollbar.WMKeyDown(var Message: TWMKeyDown);
  14453. begin
  14454. FTrack.DoKeyDown(Message); { Problems? }
  14455. end;
  14456. { TDefineGauge }
  14457. constructor TDefineGauge.Create(AOwner: TComponent);
  14458. begin
  14459. inherited Create (AOwner);
  14460. ControlStyle := ControlStyle + [csFramed, csOpaque];
  14461. SetBounds(0,0,145,25);
  14462. FMinValue := 0;
  14463. FMaxValue := 100;
  14464. FProgress := 25;
  14465. FShowText := True;
  14466. FBarColor := $00996633;
  14467. FBorderColor := DefaultBorderColor;
  14468. fStyleFace := DefaultStyleFace;
  14469. fStyleBars := DefaultStyleHorizontal;
  14470. fColorStart := DefaultColorStart;
  14471. fColorStop := DefaultColorStop;
  14472. ParentColor := true;
  14473. fTextAfter := '';
  14474. fTextFront := '';
  14475. end;
  14476. procedure TDefineGauge.Paint;
  14477. var
  14478. barRect, solvedRect: TRect;
  14479. PercentText: String;
  14480. PerInt,iDrawLen:Integer;
  14481. memBitmap: TBitmap;
  14482. begin
  14483. barRect := ClientRect;
  14484. memBitmap := TBitmap.Create;
  14485. try;
  14486. memBitmap.Width := ClientRect.Right;
  14487. memBitmap.Height:= ClientRect.Bottom;
  14488. // Clear Background
  14489. if not FTransparent then begin
  14490. memBitmap.Canvas.Brush.Color := Color;
  14491. memBitmap.Canvas.FillRect(barRect);
  14492. end;
  14493. // Draw Border
  14494. DrawButtonBorder(memBitmap.Canvas, ClientRect, FBorderColor, 1);
  14495. // Calculate the Rect
  14496. InflateRect(barRect, -3, -3);
  14497. iDrawLen := Trunc((barRect.right - barRect.left) / (FMaxValue - FMinValue) * FProgress);
  14498. {$IFDEF DFS_COMPILER_4_UP}
  14499. if BidiMode = bdRightToLeft then
  14500. solvedRect := Rect(barRect.right - iDrawLen, barRect.top, barRect.right, barRect.bottom)
  14501. else
  14502. solvedRect := Rect(barRect.left, barRect.top, barRect.left + iDrawLen, barRect.bottom);
  14503. {$ELSE}
  14504. solvedRect := Rect(barRect.left, barRect.top, barRect.left + iDrawLen, barRect.bottom);
  14505. {$ENDIF}
  14506. // Fill the Rect
  14507. if fStyleFace = fsDefault then begin
  14508. memBitmap.Canvas.Brush.Color := FBarColor;
  14509. memBitmap.Canvas.FillRect(solvedRect);
  14510. end else begin
  14511. DrawBackdrop(memBitmap.Canvas,fColorStart,fColorStop,solvedRect,fStyleBars);
  14512. end;
  14513. // Draw Text
  14514. if FShowText then begin
  14515. PerInt := Trunc(((FProgress-FMinValue)/(FMaxValue-FMinValue)) * 100);
  14516. PercentText := format('%s%3d%%%s',[fTextFront,PerInt,fTextAfter]);
  14517. memBitmap.Canvas.Font.Assign(Self.Font);
  14518. memBitmap.Canvas.Brush.Style := bsClear;
  14519. DrawText(memBitmap.Canvas.Handle, PChar(PercentText), Length(PercentText), barRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  14520. // bar is under caption
  14521. IntersectClipRect(memBitmap.canvas.handle, solvedrect.left, solvedrect.top, solvedrect.right, solvedrect.bottom);
  14522. memBitmap.Canvas.Font.Color := color;
  14523. DrawText(memBitmap.Canvas.Handle, PChar(PercentText), Length(PercentText), barRect, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
  14524. end;
  14525. canvas.Lock;
  14526. Canvas.CopyMode := cmSrcCopy;
  14527. canvas.CopyRect(ClientRect, memBitmap.canvas, ClientRect);
  14528. canvas.Unlock;
  14529. finally
  14530. memBitmap.Free;
  14531. end;
  14532. end;
  14533. procedure TDefineGauge.SetShowText(Value: Boolean);
  14534. begin
  14535. if FShowText <> Value then begin
  14536. FShowText := Value;
  14537. Repaint;
  14538. end;
  14539. end;
  14540. procedure TDefineGauge.SetMinValue(Value: Longint);
  14541. begin
  14542. if Value <> FMinValue then begin
  14543. if Value > FMaxValue then
  14544. FMinValue := FMaxValue
  14545. else
  14546. FMinValue := Value;
  14547. if FProgress < Value then FProgress := Value;
  14548. Repaint;
  14549. end;
  14550. end;
  14551. procedure TDefineGauge.SetMaxValue(Value: Longint);
  14552. begin
  14553. if Value <> FMaxValue then begin
  14554. if Value < FMinValue then
  14555. FMaxValue := FMinValue
  14556. else
  14557. FMaxValue := Value;
  14558. if FProgress > Value then FProgress := Value;
  14559. Repaint;
  14560. end;
  14561. end;
  14562. procedure TDefineGauge.SetProgress(Value: Longint);
  14563. begin
  14564. if Value < FMinValue then
  14565. Value := FMinValue
  14566. else
  14567. if Value > FMaxValue then
  14568. Value := FMaxValue;
  14569. if FProgress <> Value then begin
  14570. FProgress := Value;
  14571. Repaint;
  14572. end;
  14573. end;
  14574. procedure TDefineGauge.SetColors (Index: Integer; Value: TColor);
  14575. begin
  14576. case Index of
  14577. 0: FBorderColor := Value;
  14578. 1: FBarColor := Value;
  14579. 2: fColorStart := Value;
  14580. 3: fColorStop := Value;
  14581. end;
  14582. Invalidate;
  14583. end;
  14584. procedure TDefineGauge.CalcAdvColors;
  14585. begin
  14586. if FUseAdvColors then begin
  14587. FBorderColor := CalcAdvancedColor(Color, FBorderColor, FAdvColorBorder, darken);
  14588. end;
  14589. end;
  14590. procedure TDefineGauge.SetAdvColors (Index: Integer; Value: TAdvColors);
  14591. begin
  14592. case Index of
  14593. 0: FAdvColorBorder := Value;
  14594. end;
  14595. CalcAdvColors;
  14596. Invalidate;
  14597. end;
  14598. procedure TDefineGauge.SetUseAdvColors (Value: Boolean);
  14599. begin
  14600. if Value <> FUseAdvColors then begin
  14601. FUseAdvColors := Value;
  14602. ParentColor := Value;
  14603. CalcAdvColors;
  14604. Invalidate;
  14605. end;
  14606. end;
  14607. procedure TDefineGauge.CMSysColorChange (var Message: TMessage);
  14608. begin
  14609. if FUseAdvColors then begin
  14610. ParentColor := True;
  14611. CalcAdvColors;
  14612. end;
  14613. Invalidate;
  14614. end;
  14615. procedure TDefineGauge.CMParentColorChanged (var Message: TWMNoParams);
  14616. begin
  14617. inherited;
  14618. if FUseAdvColors then begin
  14619. ParentColor := True;
  14620. CalcAdvColors;
  14621. end;
  14622. Invalidate;
  14623. end;
  14624. procedure TDefineGauge.SetTransparent(const Value: Boolean);
  14625. begin
  14626. if FTransparent <> Value then
  14627. begin
  14628. FTransparent := Value;
  14629. Invalidate;
  14630. end;
  14631. end;
  14632. {$IFDEF DFS_COMPILER_4_UP}
  14633. procedure TDefineGauge.SetBiDiMode(Value: TBiDiMode);
  14634. begin
  14635. inherited;
  14636. Invalidate;
  14637. end;
  14638. {$ENDIF}
  14639. procedure TDefineGauge.SetTextAfter(const Value: TCaption);
  14640. begin
  14641. if fTextAfter <> Value then begin
  14642. fTextAfter := Value;
  14643. Invalidate;
  14644. end;
  14645. end;
  14646. procedure TDefineGauge.SetTextFront(const Value: TCaption);
  14647. begin
  14648. if fTextFront <> Value then begin
  14649. fTextFront := Value;
  14650. Invalidate;
  14651. end;
  14652. end;
  14653. procedure TDefineGauge.SetStyleOrien(const Value: TStyleOrien);
  14654. begin
  14655. if fStyleBars <> Value then begin
  14656. fStyleBars := Value;
  14657. Invalidate;
  14658. end;
  14659. end;
  14660. procedure TDefineGauge.SetStyleFace(const Value: TStyleFace);
  14661. begin
  14662. if fStyleFace <> Value then begin
  14663. fStyleFace := Value;
  14664. Invalidate;
  14665. end;
  14666. end;
  14667. { TDefineGUIScrollBar }
  14668. procedure TDefineGUIScrollBar.CMEnabledChanged(var Msg: TMessage);
  14669. begin
  14670. inherited;
  14671. if not Enabled then
  14672. begin
  14673. SetDownPos(spNone);
  14674. SetCurPos(spNone);
  14675. FreeTimer;
  14676. end;
  14677. UpdateHideState;
  14678. //注意 UpdateHideState 必须写在 FOnEnabledChange 前面:
  14679. if Assigned(FOnEnabledChange) then FOnEnabledChange(Self);
  14680. end;
  14681. procedure TDefineGUIScrollBar.CMMouseLeave(var Msg: TMessage);
  14682. begin
  14683. inherited;
  14684. // FreeTimer;
  14685. //为了配合 GetMousePos(FX,FY),设置这两个值:
  14686. SetCurPos(spNone);
  14687. end;
  14688. constructor TDefineGUIScrollBar.Create(AOwner: TComponent);
  14689. begin
  14690. inherited Create(AOwner);
  14691. FAutoHide := false;
  14692. FScrollcode := scSmall;
  14693. FScrollMode := smAdd;
  14694. FIsStartChange := true;
  14695. FPosition := 0;
  14696. FMin := 0;
  14697. FPageSize := 0;
  14698. FMax := 100;
  14699. width := 121;
  14700. FX := 0;
  14701. FY := FX;
  14702. WaitInterval := C_IntervalOfWait;
  14703. height := C_Win2000ScrllBarBtnSize; // = 16
  14704. FSmallChange := 1;
  14705. FLargeChange := 8;
  14706. // ControlStyle := ControlStyle + [csOpaque];
  14707. end;
  14708. destructor TDefineGUIScrollBar.Destroy;
  14709. begin
  14710. //保证 FTimer 的释放
  14711. freeTimer;
  14712. FOnDrawControl := nil;
  14713. FOnChange := nil;
  14714. fOnEnabledChange := nil;
  14715. FOnScroll := nil;
  14716. inherited;
  14717. end;
  14718. procedure TDefineGUIScrollBar.DoAutoScroll(Const aCode:TIScrollCode;
  14719. aScrollMode: TScrollMode);
  14720. begin
  14721. FScrollMode := aScrollMode;
  14722. FScrollCode := aCode;
  14723. FIsStartChange := true; //设置 StartChange 为 真
  14724. FreeTimer; //FreeTimer 里面假如 Assigned(FTimer) 那么 设置 StartChange 为假
  14725. if FIsStartChange then
  14726. begin
  14727. Scroll(aCode,aScrollMode);
  14728. FIsStartChange := false;
  14729. StartTimer(WaitInterval);
  14730. end
  14731. else
  14732. StartTimer(C_Interval);
  14733. end;
  14734. procedure TDefineGUIScrollBar.DoMouseDownPos(const Value: TScrollBarPos);
  14735. begin
  14736. paint; // invalidate 通过消息执行 paint 函数,速度慢于直接调用 paint
  14737. // 虽然直接调用 Paint 可能出现设备错误,但该事件触发于鼠标点击
  14738. // 中,所以 Canvas.handle 可以确定是可用的.
  14739. case Value of
  14740. spLeftBtn:
  14741. begin
  14742. DoAutoScroll(scSmall,smDec);
  14743. end;
  14744. spRightBtn:
  14745. begin
  14746. DoAutoScroll(scSmall,smAdd);
  14747. end;
  14748. spleftSpace:
  14749. begin
  14750. DoAutoScroll(scLarge,smDec);
  14751. end;
  14752. spRightSpace:
  14753. begin
  14754. DoAutoScroll(scLarge,smAdd);
  14755. end;
  14756. spTrack:
  14757. begin
  14758. end;
  14759. end;
  14760. end;
  14761. procedure TDefineGUIScrollBar.DoMouseEnterPos(const Value: TScrollBarPos);
  14762. begin
  14763. //如果鼠标点击对象然后离开对象,又再次回到对象:
  14764. case FDownPos of
  14765. spTrack,spNone:;
  14766. else
  14767. if FDownPos = Value then
  14768. StartTimer(C_Interval);
  14769. end;
  14770. paint;
  14771. end;
  14772. procedure TDefineGUIScrollBar.DoMouseLeavePos(const Value: TScrollBarPos);
  14773. begin
  14774. //如果鼠标点击对象,然后离开对象:
  14775. case FDownPos of
  14776. spTrack,spNone:;
  14777. else
  14778. if FDownPos = Value then
  14779. FreeTimer;
  14780. end;
  14781. paint;
  14782. end;
  14783. procedure TDefineGUIScrollBar.DoMouseUpPos(const Value: TScrollBarPos);
  14784. begin
  14785. //该 Invalidate 能让 Track 在移动之后回到正确位置,相当不错的代码:
  14786. invalidate;
  14787. end;
  14788. procedure TDefineGUIScrollBar.FreeTimer;
  14789. begin
  14790. if FTimer <> nil then
  14791. begin
  14792. FTimer.Enabled := false;
  14793. FreeAndNil(FTimer);
  14794. FIsStartChange := false;
  14795. end;
  14796. end;
  14797. function TDefineGUIScrollBar.GetMousePos(const X, Y: integer): TScrollBarPos;
  14798. var
  14799. p: TPoint;
  14800. begin
  14801. p := Point(x,y);
  14802. if PtInRect(FLeftBtn,p) then
  14803. result := spLeftBtn
  14804. else
  14805. if PtInRect(FSpaceLeft,p) then
  14806. result := spLeftSpace
  14807. else
  14808. if PtInRect(FTrackBtn,p) then
  14809. result := spTrack
  14810. else
  14811. if PtInRect(FSpaceRight,p) then
  14812. result := spRightSpace
  14813. else
  14814. if PtInRect(FRightBtn,p) then
  14815. result := spRightBtn
  14816. else result := spNone;
  14817. end;
  14818. function TDefineGUIScrollBar.GetSliderSize: integer;
  14819. begin
  14820. if isVertical then
  14821. result := FRightBtn.Top - FLeftBtn.Bottom
  14822. else result := FRightBtn.Left - FLeftBtn.Right;
  14823. end;
  14824. function TDefineGUIScrollBar.GetTrackPos: integer;
  14825. var
  14826. i: double;
  14827. p: double;
  14828. ValidSize: integer;
  14829. begin
  14830. p := FPosition - FMin;
  14831. ValidSize := GetValidSize;
  14832. if p > ValidSize then
  14833. p := ValidSize;
  14834. if ValidSize > 0 then
  14835. i := p / ValidSize
  14836. else i := 0;
  14837. result := Round((GetSliderSize - GetTrackSize) * i) ;
  14838. if IsVertical then
  14839. result := result + FLeftBtn.Bottom
  14840. else result := result + FLeftBtn.Right;
  14841. end;
  14842. function TDefineGUIScrollBar.GetTrackSize: integer;
  14843. var
  14844. i: integer;
  14845. p: Double;
  14846. begin
  14847. if FPageSize = 0 then
  14848. result := C_Win2000ScrllBarBtnSize
  14849. else //判断为了防止 TrackSize 超越了最大范围
  14850. if not Enabled or ((FMax - FMin + 1) <= FPageSize) then
  14851. result := 0
  14852. else
  14853. begin // FMin 永远小于或等于 FMax, 因此不怕发生除零错误.
  14854. // 加入判断只为了安全起见.毕竟 Fmax-FMin+1 这样的计算不会占用 486 CPU :)
  14855. i := GetSliderSize;
  14856. if (FMax - FMin + 1) > 0 then
  14857. p := FPageSize / (FMax - FMin + 1)
  14858. else p := 0;
  14859. result := Round(i * p);
  14860. if result < GetMinTrackSize then
  14861. result := GetMinTrackSize;
  14862. end;
  14863. end;
  14864. function TDefineGUIScrollBar.IsVertical: Boolean;
  14865. begin
  14866. result := FScrollBarKind = sbVertical;
  14867. end;
  14868. procedure TDefineGUIScrollBar.MouseDown(Button: TMouseButton; Shift: TShiftState;
  14869. x, y: integer);
  14870. begin
  14871. if Button = mbleft then
  14872. begin
  14873. FreeTimer;
  14874. FIsStartChange := true; //少许多余的代码,但是为了安全期间,不得不写.作用:确认状态
  14875. SetDownPos(FCurPos);
  14876. if FDownPos = spTrack then
  14877. begin
  14878. FX := x;
  14879. FY := y;
  14880. //保存 TrackPos
  14881. if IsVertical then
  14882. FTrackpos := FTrackBtn.Top
  14883. else FTrackPos := FTrackBtn.Left;
  14884. end;
  14885. end;
  14886. inherited MouseDown(button,Shift,x,y);
  14887. end;
  14888. procedure TDefineGUIScrollBar.MouseMove(Shift: TShiftState; x, y: integer);
  14889. begin
  14890. SetCurPos(GetMousePos(x,y));
  14891. if FDownPos = spTrack then
  14892. begin
  14893. if IsVertical then
  14894. AdjustTrack(FTrackPos + y - Fy)
  14895. else
  14896. AdjustTrack(FTrackPos + x - Fx);
  14897. end
  14898. else
  14899. begin
  14900. FX := x;
  14901. FY := y;
  14902. end;
  14903. inherited MouseMove(shift,x,y);
  14904. end;
  14905. procedure TDefineGUIScrollBar.MouseUp(Button: TMouseButton; Shift: TShiftState; x,
  14906. y: integer);
  14907. begin
  14908. if Button = mbleft then
  14909. begin
  14910. FreeTimer;
  14911. FIsStartChange := false; //少许多余的代码,但是为了安全期间,不得不写.作用:确认状态
  14912. SetDownPos(spNone);
  14913. SetCurPos(GetMousePos(x,y));
  14914. end;
  14915. inherited MouseUp(button,shift,x,y);
  14916. end;
  14917. procedure TDefineGUIScrollBar.OnTimer(Sender: TObject);
  14918. begin
  14919. //防止 Track 按钮经过移动之后进入鼠标位置:
  14920. if (FDownPos = spLeftSpace) or (FDownPos = spRightSpace) then
  14921. SetCurPos(GetMousePos(FX, FY));
  14922. if FDownPos = FCurPos then
  14923. Scroll(FScrollCode,FScrollMode);
  14924. if Assigned(FTimer) then
  14925. begin
  14926. if FTimer.Interval = WaitInterval then //等待间隔状态
  14927. begin
  14928. FTimer.Interval := C_Interval;
  14929. end;
  14930. end;
  14931. end;
  14932. procedure TDefineGUIScrollBar.Paint;
  14933. var
  14934. b: boolean;
  14935. begin
  14936. //此处不可修改,它将计算 ScrollBar 的整个界面的 Rect:
  14937. if FDownPos <> spTrack then
  14938. UpdateScrollBarGUI;
  14939. b := FOwnerDraw and Assigned(FOnDrawControl);
  14940. //画滑轮:
  14941. if b then
  14942. FOnDrawControl(Canvas,dsTrack,FTrackBtn,GetDrawStateBy(dsTrack))
  14943. else
  14944. DrawControl(dsTrack,FTrackBtn,GetDrawStateBy(dsTrack));
  14945. //画左边按钮:
  14946. if b then
  14947. FOnDrawControl(Canvas,dsLeftBtn,FLeftBtn,GetDrawStateBy(dsLeftBtn))
  14948. else
  14949. DrawControl(dsLeftBtn,FLeftBtn,GetDrawStateBy(dsLeftBtn));
  14950. //画右边按钮:
  14951. if b then
  14952. FOnDrawControl(canvas,dsRightBtn,FRightBtn,GetDrawStateBy(dsRightBtn))
  14953. else
  14954. DrawControl(dsRightBtn,FRightBtn,GetDrawStateBy(dsRightBtn));
  14955. //右边的空白地方:
  14956. if b then
  14957. FOnDrawControl(canvas,dsSpaceLeft, FSpaceLeft, GetDrawStateBy(dsSpaceLeft))
  14958. else
  14959. DrawControl(dsSpaceLeft, FSpaceLeft, GetDrawStateBy(dsSpaceLeft));
  14960. if b then
  14961. FOnDrawControl(canvas,dsSpaceRight, FSpaceRight, GetDrawStateBy(dsSpaceRight))
  14962. else
  14963. DrawControl(dsSpaceRight, FSpaceRight, GetDrawStateBy(dsSpaceRight));
  14964. end;
  14965. procedure TDefineGUIScrollBar.SetCurPos(const value: TScrollBarPos);
  14966. var
  14967. b: TScrollBarPos;
  14968. begin
  14969. if value <> FCurPos then
  14970. begin
  14971. b := FCurPos;
  14972. FCurPos := value;
  14973. DoMouseLeavePos(b);
  14974. DoMouseEnterPos(value);
  14975. end;
  14976. end;
  14977. procedure TDefineGUIScrollBar.SetDownPos(const Value: TScrollBarPos);
  14978. var
  14979. b: TScrollBarPos;
  14980. begin
  14981. if not CanShowTrack and (value = spRightSpace) then
  14982. begin //处理为了在 Track 不可见的时候,点击空白区域
  14983. FDownPos := spNone;
  14984. end
  14985. else
  14986. if value <> FDownPos then
  14987. begin
  14988. b := FDownPos;
  14989. FDownPos := Value;
  14990. DoMouseUpPos(b);
  14991. DoMouseDownPos(Value);
  14992. end;
  14993. end;
  14994. procedure TDefineGUIScrollBar.SetLargeChange(const Value: TScrollBarInc);
  14995. begin
  14996. FLargeChange := Value;
  14997. end;
  14998. procedure TDefineGUIScrollBar.SetMax(Value: Integer);
  14999. begin
  15000. if value < FMin then value := FMin;
  15001. if FMax <> Value then
  15002. begin
  15003. FMax := Value;
  15004. if PageSize > 0 then
  15005. begin
  15006. if FMax - FPageSize + 1 < FPosition then
  15007. SetPosition(FMax - FPageSize + 1);
  15008. end
  15009. else if FPosition > FMax then SetPosition(FMax);
  15010. UpdateEnabledState;
  15011. invalidate;
  15012. end;
  15013. end;
  15014. procedure TDefineGUIScrollBar.SetMin(Value: Integer);
  15015. begin
  15016. if Value > FMax then Value := FMax;
  15017. if Value <> FMin then
  15018. begin
  15019. FMin := Value;
  15020. if FPosition < FMin then SetPosition(FMin);
  15021. UpdateEnabledState;
  15022. Invalidate;
  15023. end;
  15024. end;
  15025. procedure TDefineGUIScrollBar.SetPageSize(const Value: integer);
  15026. begin
  15027. if (Value > -1) and (Value <> FPageSize) then
  15028. begin
  15029. FPageSize := Value;
  15030. UpdateEnabledState;
  15031. Invalidate;
  15032. end;
  15033. end;
  15034. procedure TDefineGUIScrollBar.SetScrollBarKind(const Value: TScrollBarKind);
  15035. begin
  15036. if FScrollBarKind <> Value then
  15037. begin
  15038. FScrollBarKind := Value;
  15039. //注意载入控件的时候可能发生重复设置:
  15040. if not (csloading in componentstate) then
  15041. SetBounds(left,top,height,width);
  15042. UpdateScrollBarGUI;
  15043. end;
  15044. end;
  15045. procedure TDefineGUIScrollBar.SetSmallChange(const Value: TScrollBarInc);
  15046. begin
  15047. FSmallChange := Value;
  15048. end;
  15049. procedure TDefineGUIScrollBar.StartTimer(const Interval: Cardinal);
  15050. begin
  15051. if FTimer = nil then FTimer := TTimer.Create(self)
  15052. else FTimer.OnTimer := nil;
  15053. FTimer.Interval := Interval;
  15054. FTimer.Enabled := true;
  15055. FTimer.OnTimer := OnTimer;
  15056. end;
  15057. procedure TDefineGUIScrollBar.UpdateScrollBarGUI;
  15058. var
  15059. i: integer;
  15060. begin
  15061. if FScrollBarKind = sbHorizontal then
  15062. begin
  15063. if Width > C_Win2000ScrllBarBtnSize * 2 then
  15064. begin
  15065. FLeftBtn := Rect(0, 0, C_Win2000ScrllBarBtnSize, Height);
  15066. FRightBtn := Rect(width - C_Win2000ScrllBarBtnSize, 0, width, Height);
  15067. end
  15068. else
  15069. begin
  15070. FLeftBtn := Rect(0, 0, width div 2, Height);
  15071. FRightBtn := Rect(width div 2, 0, width, Height);
  15072. end;
  15073. if CanShowTrack then
  15074. begin
  15075. i := GetTrackPos;
  15076. FTrackBtn.Left := i;
  15077. FTrackBtn.Right := i + GetTrackSize;
  15078. FTrackBtn.Top := 0;
  15079. FTrackBtn.Bottom := height;
  15080. FSpaceLeft := Rect(Fleftbtn.Right , 0, FTrackBtn.Left , Height);
  15081. FSpaceRight := Rect(FTrackBtn.Right , 0, FRightBtn.Left , Height);
  15082. end
  15083. else
  15084. begin
  15085. FTrackBtn := Rect(-1,-1,-1,-1);
  15086. FSpaceLeft := FTrackBtn;
  15087. if Width > C_Win2000ScrllBarBtnSize * 2 then
  15088. FSpaceRight := Rect(FLeftBtn.Right, 0, FRightBtn.Left , height)
  15089. else FSpaceRight := FTrackBtn;
  15090. end;
  15091. end
  15092. else
  15093. begin
  15094. if height > C_Win2000ScrllBarBtnSize * 2 then
  15095. begin
  15096. FLeftBtn := Rect(0, 0, width, C_Win2000ScrllBarBtnSize);
  15097. FRightBtn := Rect(0, height - C_Win2000ScrllBarBtnSize, width, height);
  15098. end
  15099. else
  15100. begin
  15101. FLeftBtn := Rect(0, 0, width, Height div 2);
  15102. FRightBtn := Rect(0, height div 2, width, height);
  15103. end;
  15104. if CanShowTrack then
  15105. begin
  15106. i := GetTrackPos;
  15107. FTrackBtn.Left := 0;
  15108. FTrackBtn.Top := i;
  15109. FTrackBtn.Right := width;
  15110. FTrackBtn.Bottom := i + GetTrackSize;
  15111. FSpaceLeft := Rect(0,FLeftBtn.Bottom, width ,FTrackBtn.Top);
  15112. FSpaceRight := Rect(0,FTrackBtn.Bottom , width , FRightBtn.Top);
  15113. end
  15114. else
  15115. begin
  15116. FTrackBtn := Rect(-1,-1,-1,-1);
  15117. FSpaceLeft := FTrackBtn;
  15118. if height > C_Win2000ScrllBarBtnSize * 2 then
  15119. FSpaceRight := Rect(0, FLeftBtn.Bottom, width , FRightBtn.top)
  15120. else FSpaceRight := FTrackBtn;
  15121. end;
  15122. end;
  15123. end;
  15124. procedure TDefineGUIScrollBar.SetPosition(Value: integer);
  15125. begin
  15126. if Value > FMax then value := FMax;
  15127. if Value < FMin then Value := FMin;
  15128. if FPosition <> value then
  15129. begin
  15130. FPosition := Value;
  15131. if FDownPos <> spTrack then
  15132. if parent <> nil then
  15133. begin
  15134. if Parent.Showing then paint
  15135. end
  15136. else Invalidate;
  15137. Changed;
  15138. end;
  15139. end;
  15140. procedure TDefineGUIScrollBar.Scroll(const Code: TIScrollCode;
  15141. const Mode: TScrollMode);
  15142. var
  15143. t, j: integer;
  15144. begin
  15145. case Code of
  15146. scSmall:
  15147. if mode = smAdd then
  15148. t := FPosition + FSmallChange
  15149. else t := FPosition - FSmallChange;
  15150. scLarge:
  15151. if mode = smAdd then
  15152. t := FPosition + FLargeChange
  15153. else t := FPosition - FLargeChange;
  15154. else
  15155. Exit;
  15156. end;
  15157. if t < FMin then t := FMin;
  15158. if t > FMax - FPageSize + 1 then t := FMax - FPageSize + 1;
  15159. if t > FMax then t := FMax;
  15160. if t <> FPosition then
  15161. begin
  15162. if t > FPosition then
  15163. j := t - FPosition
  15164. else j := FPosition - t;
  15165. SetPosition(t);
  15166. if assigned(FOnScroll) then FOnScroll(self, FIsStartChange, code, mode, j);
  15167. end;
  15168. end;
  15169. procedure TDefineGUIScrollBar.Changed;
  15170. begin
  15171. if assigned(FOnChange) then FOnChange(self);
  15172. end;
  15173. procedure TDefineGUIScrollBar.DoScroll(const aMode: TScrollMode; const StartChange: boolean;
  15174. const ScrollSize: integer);
  15175. var
  15176. i: integer;
  15177. j: integer;
  15178. begin
  15179. if aMode = smAdd then
  15180. i := FPosition + ScrollSize
  15181. else
  15182. i := Fposition - ScrollSize;
  15183. if i > FMax - FpageSize + 1 then i := FMax - FPageSize + 1;
  15184. if i > FMax then i := FMax;
  15185. if i < FMin then i := FMin;
  15186. if i <> FPosition then
  15187. begin
  15188. if i > FPosition then
  15189. j := i - FPosition
  15190. else j := FPosition - i;
  15191. SetPosition(i);
  15192. if Assigned(FOnScroll) then
  15193. FOnScroll(self, StartChange, scCustom, amode, j);
  15194. end;
  15195. end;
  15196. function TDefineGUIScrollBar.GetSliderRect: TRect;
  15197. begin
  15198. if IsVertical then
  15199. result := rect(0,FLeftBtn.Bottom, width, FRightBtn.Top)
  15200. else
  15201. result := Rect(FLeftBtn.Right, 0, FRightBtn.Left, height);
  15202. end;
  15203. procedure TDefineGUIScrollBar.AdjustTrack(Value: Integer);
  15204. procedure UpdateScrollbarSpace;
  15205. begin
  15206. if FScrollBarKind = sbHorizontal then
  15207. begin
  15208. FSpaceLeft := Rect(Fleftbtn.Right , 0, FTrackBtn.Left , Height);
  15209. FSpaceRight := Rect(FTrackBtn.Right , 0, FRightBtn.Left , Height);
  15210. end
  15211. else
  15212. begin
  15213. FSpaceLeft := Rect(0,FLeftBtn.Bottom, width ,FTrackBtn.Top);
  15214. FSpaceRight := Rect(0,FTrackBtn.Bottom , width , FRightBtn.Top);
  15215. end;
  15216. end;
  15217. var
  15218. size: integer;
  15219. percent:Double;
  15220. t: integer; //TempInteger
  15221. m: TScrollMode;
  15222. begin
  15223. size := GetCurTrackSize;
  15224. if IsVertical then
  15225. begin
  15226. if value <= FLeftBtn.Bottom then value := FLeftBtn.Bottom
  15227. else if value + Size >= FRightBtn.Top then value := FRightBtn.Top - Size;
  15228. FTrackBtn.Top := value;
  15229. FTrackBtn.Bottom := FTrackBtn.Top + Size;
  15230. //计算, 并且防止 除 零 错误:
  15231. if GetSliderSize - GetCurTrackSize <> 0 then
  15232. begin
  15233. percent := (FTrackBtn.Top - (FLeftBtn.Bottom)) / (GetSliderSize - GetCurTrackSize);
  15234. size := FMin + round(Percent * GetValidSize);
  15235. end
  15236. else size := 0; //注意的地方
  15237. end
  15238. else
  15239. begin
  15240. if value <= FLeftBtn.Right then value := FLeftBtn.Right
  15241. else if value + Size >= FRightBtn.Left then value := FRightBtn.Left - Size;
  15242. FTrackBtn.Left := value;
  15243. FTrackBtn.Right := FTrackBtn.left + Size;
  15244. //计算, 并且防止 除 零 错误:
  15245. if GetSliderSize - GetCurTrackSize <> 0 then
  15246. begin
  15247. percent := (FTrackBtn.left - (FLeftBtn.right)) / (GetSliderSize - GetCurTrackSize);
  15248. size := FMin + round(Percent * GetValidSize );
  15249. end
  15250. else size := 0; //注意的地方
  15251. end;
  15252. //注意这儿,必须更新和刷新空白区域
  15253. UpdateScrollbarSpace;
  15254. // Size Is New Position
  15255. if size <> Fposition then
  15256. begin
  15257. if size > FPosition then
  15258. begin
  15259. m := smAdd;
  15260. t := Size - FPosition;
  15261. end
  15262. else
  15263. begin
  15264. m := smDec;
  15265. t := FPosition - size;
  15266. end;
  15267. SetPosition(size);
  15268. if Assigned(FOnScroll) then
  15269. FOnScroll(self, FIsStartChange, scTrackMove, m, t);
  15270. FIsStartChange := false;
  15271. end;
  15272. invalidate;
  15273. end;
  15274. function TDefineGUIScrollBar.GetCurTrackSize: Integer;
  15275. begin
  15276. if IsVertical then
  15277. result := FTrackbtn.Bottom - FTrackBtn.Top
  15278. else result := FTrackBtn.Right - FTrackBtn.Left;
  15279. end;
  15280. function TDefineGUIScrollBar.GetDrawStateBy(const Typ: TDrawScrollBar): TButtonState;
  15281. begin
  15282. if not Enabled then result := bsDisabled
  15283. else
  15284. begin
  15285. case Typ of
  15286. dsLeftBtn:
  15287. begin
  15288. if FDownPos <> spNone then
  15289. begin
  15290. if (FDownPos = spLeftBtn) and (FCurPos = spLeftBtn) then
  15291. result := bsDown
  15292. else result := bsExclusive;
  15293. end
  15294. else
  15295. begin
  15296. if FCurPos = spLeftBtn then
  15297. result := bsUp
  15298. else result := bsExclusive;
  15299. end;
  15300. end;
  15301. dsRightBtn:
  15302. begin
  15303. if FDownPos <> spNone then
  15304. begin
  15305. if (FDownPos = spRightBtn) and (FCurPos = spRightBtn) then
  15306. result := bsDown
  15307. else result := bsExclusive;
  15308. end
  15309. else
  15310. begin
  15311. if FCurPos = spRightBtn then
  15312. result := bsUp
  15313. else result := bsExclusive;
  15314. end;
  15315. end;
  15316. dsTrack:
  15317. begin
  15318. if FDownPos <> spNone then
  15319. begin
  15320. if FDownPos = spTrack then
  15321. result := bsDown
  15322. else result := bsExclusive;
  15323. end
  15324. else
  15325. begin
  15326. if FCurPos = spTrack then
  15327. result := bsUp
  15328. else Result := bsExclusive;
  15329. end;
  15330. end;
  15331. dsSpaceLeft:
  15332. begin
  15333. if FDownPos <> spNone then
  15334. begin
  15335. if FDownPos = spLeftSpace then
  15336. result := bsDown
  15337. else result := bsExclusive;
  15338. end
  15339. else Result := bsExclusive;
  15340. end;
  15341. dsSpaceRight:
  15342. begin
  15343. if FDownPos <> spNone then
  15344. begin
  15345. if FDownPos = spRightSpace then
  15346. result := bsDown
  15347. else result := bsExclusive;
  15348. end
  15349. else Result := bsExclusive;
  15350. end;
  15351. else result := bsDisabled;
  15352. end;
  15353. end;
  15354. end;
  15355. procedure TDefineGUIScrollBar.DrawControl(const Typ: TDrawScrollBar;
  15356. const R: TRect; const State: TButtonState);
  15357. var
  15358. re: TREct;
  15359. i: integer;
  15360. begin
  15361. canvas.Brush.Color := color;
  15362. canvas.Brush.Style := bsSolid;
  15363. if (Typ = dsspaceright) or (Typ = dsspaceleft) then
  15364. begin
  15365. if State = bsdown then
  15366. canvas.brush.Color := clBlack;
  15367. canvas.FillRect(r) ;
  15368. end
  15369. else
  15370. begin
  15371. re := r;
  15372. if State = bsdown then i := BDR_SUNKENOUTER else
  15373. i := BDR_RAISEDINNER;
  15374. canvas.FillRect(r);
  15375. DrawEdge(Canvas.Handle,re, i, BF_RECT);
  15376. if State = bsdown then
  15377. InflateRect(re,-3,-3);
  15378. if Typ = dsLeftBtn then
  15379. begin
  15380. if IsVertical then
  15381. DrawArrows(canvas,daTop,re)
  15382. else DrawArrows(canvas,daLeft,re);
  15383. end
  15384. else
  15385. if Typ = dsRightBtn then
  15386. begin
  15387. if IsVertical then
  15388. DrawArrows(canvas,daBottom,re)
  15389. else DrawArrows(canvas,daRight,re);
  15390. end;
  15391. end;
  15392. end;
  15393. procedure TDefineGUIScrollBar.SetAutoHide(const Value: boolean);
  15394. begin
  15395. FAutoHide := Value;
  15396. UpdateHideState;
  15397. end;
  15398. procedure TDefineGUIScrollBar.UpdateHideState;
  15399. begin
  15400. Visible := not (FAutoHide and not Enabled);
  15401. end;
  15402. procedure TDefineGUIScrollBar.UpdateEnabledState;
  15403. begin
  15404. Enabled := (FMax - FMin >= FPageSize) ;
  15405. end;
  15406. function TDefineGUIScrollBar.GetValidSize: integer;
  15407. begin
  15408. result := FMax - FMin - FPageSize + 1;
  15409. if result > FMax then Result := FMax;
  15410. end;
  15411. Function TDefineGUIScrollBar.GetMinTrackSize: integer;
  15412. begin
  15413. result := C_Win2000ScrllBarBtnSize div 2 + 1;
  15414. end;
  15415. function TDefineGUIScrollBar.CanShowTrack: Boolean;
  15416. begin
  15417. if IsVertical then
  15418. result := height > C_Win2000ScrllBarBtnSize * 2 + GetTrackSize
  15419. else
  15420. result := Width > C_Win2000ScrllBarBtnSize * 2 + GetTrackSize;
  15421. end;
  15422. procedure TDefineGUIScrollBar.DrawArrows(Cav: TCanvas; const v: TDrawArrow;const R: TRect);
  15423. var
  15424. x, y: integer;
  15425. i: integer;
  15426. begin
  15427. x := r.Left + (r.Right - r.Left - 1) div 2;
  15428. y := r.Top + (r.Bottom - r.Top - 1) div 2;
  15429. i := 0;
  15430. case v of
  15431. daleft, daRight:
  15432. begin
  15433. if (r.Right - r.Left >= 11) and (r.Bottom - r.Top >= 8) then
  15434. i := 0
  15435. else
  15436. if (r.Right - r.Left >= 9) and (r.Bottom - r.Top >= 7) then
  15437. i := 1
  15438. else
  15439. if (r.Right - r.Left >= 7) and (r.Bottom - r.Top >= 6) then
  15440. i := 2
  15441. else i := -1;
  15442. end;
  15443. datop,dabottom:
  15444. begin
  15445. if (r.Right - r.Left >= 8) and (r.Bottom - r.Top >= 11) then
  15446. i := 0
  15447. else
  15448. if (r.Right - r.Left >= 7) and (r.Bottom - r.Top >= 9) then
  15449. i := 1
  15450. else
  15451. if (r.Right - r.Left >= 6) and (r.Bottom - r.Top >= 7) then
  15452. i := 2
  15453. else i := -1;
  15454. end;
  15455. end;
  15456. with Cav do
  15457. begin
  15458. Case i of
  15459. 0: // 画最大的:
  15460. begin
  15461. case v of
  15462. daleft:
  15463. begin
  15464. MoveTo(x-2,y);
  15465. LineTo(x+2,y);
  15466. MoveTo(x-1,y-1);
  15467. LineTo(x+1,y-1);
  15468. MoveTo(x-1,y+1);
  15469. LineTo(x+1,y+1);
  15470. MoveTo(x,y-2);
  15471. LineTo(x,y+3);
  15472. MoveTo(x+1,y-3);
  15473. LineTo(x+1,y+4);
  15474. end;
  15475. datop:
  15476. begin
  15477. MoveTo(x,y-2);
  15478. LineTo(x,y+2);
  15479. MoveTo(x-1,y-1);
  15480. LineTo(x+2,y-1);
  15481. Moveto(x-2,y);
  15482. LineTo(x+3,y);
  15483. Moveto(x-3,y+1);
  15484. LineTo(x+4,y+1);
  15485. end;
  15486. daRight:
  15487. begin
  15488. MoveTo(x-1,y);
  15489. LineTo(x+3,y);
  15490. MoveTo(x-1,y-3);
  15491. LineTo(x-1,y+4);
  15492. MoveTo(x,y-2);
  15493. LineTo(x,y+3);
  15494. MoveTo(x+1,y-1);
  15495. LineTo(x+1,y+2);
  15496. end;
  15497. dabottom:
  15498. begin
  15499. MoveTo(x,y-1);
  15500. LineTo(x,y+3);
  15501. MoveTo(x-1,y+1);
  15502. LineTo(x+2,y+1);
  15503. Moveto(x-2,y);
  15504. LineTo(x+3,y);
  15505. Moveto(x-3,y-1);
  15506. LineTo(x+4,y-1);
  15507. end;
  15508. end;
  15509. end; //画中等的
  15510. 1:
  15511. begin
  15512. case v of
  15513. daleft:
  15514. begin
  15515. MoveTo(x-1,y);
  15516. LineTo(x+2,y);
  15517. MoveTo(x,y-1);
  15518. LineTo(x,y+2);
  15519. MoveTo(x+1,y-2);
  15520. LineTo(x+1,y+3);
  15521. end;
  15522. datop:
  15523. begin
  15524. MoveTo(x,y-1);
  15525. LineTo(x,y+2);
  15526. MoveTo(x-1,y);
  15527. LineTo(x+2,y);
  15528. MoveTo(x-2,y+1);
  15529. LineTo(x+3,y+1);
  15530. end;
  15531. daRight:
  15532. begin
  15533. MoveTo(x-1,y);
  15534. LineTo(x+2,y);
  15535. MoveTo(x,y-1);
  15536. LineTo(x,y+2);
  15537. MoveTo(x-1,y-2);
  15538. LineTo(x-1,y+3);
  15539. end;
  15540. dabottom:
  15541. begin
  15542. MoveTo(x,y-1);
  15543. LineTo(x,y+2);
  15544. MoveTo(x-1,y);
  15545. LineTo(x+2,y);
  15546. MoveTo(x-2,y-1);
  15547. LineTo(x+3,y-1);
  15548. end;
  15549. end;
  15550. end;
  15551. 2: //画最小的:
  15552. begin
  15553. case v of
  15554. daleft:
  15555. begin
  15556. MoveTo(x-1,y);
  15557. LineTo(x+1,y);
  15558. MoveTo(x,y-1);
  15559. LineTo(x,y+2);
  15560. end;
  15561. datop:
  15562. begin
  15563. MoveTo(x,y-1);
  15564. LineTo(x,y+1);
  15565. MoveTo(x-1,y);
  15566. LineTo(x+2,y);
  15567. end;
  15568. daRight:
  15569. begin
  15570. MoveTo(x,y);
  15571. LineTo(x+2,y);
  15572. MoveTo(x,y-1);
  15573. LineTo(x,y+2);
  15574. end;
  15575. dabottom:
  15576. begin
  15577. MoveTo(x-1,y);
  15578. LineTo(x+2,y);
  15579. MoveTo(x,y);
  15580. LineTo(x,y+2);
  15581. end;
  15582. end;
  15583. end;
  15584. end;
  15585. end;
  15586. end;
  15587. { TDefineGUISelectList }
  15588. procedure TDefineGUISelectList.ChangeSelect(const Value: integer);
  15589. begin
  15590. if (value > -1) and (value < size ) then
  15591. Bits[Value] := not Bits[Value];
  15592. end;
  15593. procedure TDefineGUISelectList.Select(const Value: integer);
  15594. begin
  15595. if (value > -1) and (Value < Size) then
  15596. bits[Value] := true;
  15597. end;
  15598. procedure TDefineGUISelectList.SelectAll;
  15599. var
  15600. i: integer;
  15601. begin
  15602. for i := 0 to Size -1 do
  15603. Bits[i] := true;
  15604. end;
  15605. procedure TDefineGUISelectList.UnSelect(const Value: integer);
  15606. begin
  15607. if (value > -1) and (Value < Size) then
  15608. bits[Value] := false;
  15609. end;
  15610. procedure TDefineGUISelectList.UnSelectAll;
  15611. var
  15612. i: integer;
  15613. begin
  15614. for i := 0 to Size -1 do
  15615. Bits[i] := false;
  15616. end;
  15617. procedure TDefineGUISelectList.ChangeSelectSome(V1, V2: integer);
  15618. begin
  15619. if v1 > size -1 then v1 := size -1
  15620. else if v1 < 0 then V1 := 0;
  15621. if v2 > size -1 then v2 := size -1
  15622. else if v2 < 0 then V2 := 0;
  15623. for v1 := v2 to v1 do
  15624. bits[V1] := not Bits[V1];
  15625. end;
  15626. procedure TDefineGUISelectList.UnSelectSome(V1, V2: integer);
  15627. begin
  15628. if v1 > size -1 then v1 := size -1
  15629. else if v1 < 0 then V1 := 0;
  15630. if v2 > size -1 then v2 := size -1
  15631. else if v2 < 0 then V2 := 0;
  15632. if V1 > v2 then
  15633. begin
  15634. for v1 := v2 to v1 do
  15635. bits[V1] := false;
  15636. end
  15637. else
  15638. begin
  15639. for v1 := v1 to v2 do
  15640. bits[V1] := false;
  15641. end;
  15642. end;
  15643. procedure TDefineGUISelectList.SelectSome(V1, V2: integer);
  15644. begin
  15645. if v1 > size -1 then v1 := size -1
  15646. else if v1 < 0 then V1 := 0;
  15647. if v2 > size -1 then v2 := size -1
  15648. else if v2 < 0 then V2 := 0;
  15649. if V1 > v2 then
  15650. begin
  15651. for v1 := v2 to v1 do
  15652. bits[V1] := true;
  15653. end
  15654. else
  15655. begin
  15656. for v1 := v1 to v2 do
  15657. bits[V1] := true;
  15658. end;
  15659. end;
  15660. { TDefineGUICtrlSave } // =======================================================
  15661. procedure TDefineGUICtrlSave.CreateParams(var Params: TCreateParams);
  15662. begin
  15663. inherited CreateParams(Params);
  15664. with Params.WindowClass do
  15665. style := style and not (CS_HREDRAW or CS_VREDRAW);
  15666. end;
  15667. constructor TDefineGUICtrlSave.Create(AOwner: TComponent);
  15668. begin
  15669. inherited create(AOwner);
  15670. FSelectList := TDefineGUISelectList.Create;
  15671. FBakList := TDefineGUISelectList.Create;
  15672. FVbar := TDefineGUIScrollBar.Create(self);
  15673. with FVBar do
  15674. begin
  15675. FVBar.ParentColor := false;
  15676. Parent := self;
  15677. color := clBtnFace;
  15678. ScrollBarKind := sbVertical;
  15679. Min := 0;
  15680. Max := 0;
  15681. AutoHide := true;
  15682. OnScroll := OnVbarScroll;
  15683. WaitInterval := 150;
  15684. OnEnabledChange := OnVbarEnabledChange;
  15685. end;
  15686. FOwnerDraw := false;
  15687. FBmp := TBitmap.Create;
  15688. FActiveItem := -1;
  15689. width := 180;
  15690. height := 180;
  15691. FMousePage := cpNone;
  15692. FTopIndex := 0;
  15693. FWheel.WheelCount := 0;
  15694. FWheel.Wheeling := false;
  15695. TabStop := true; //不能忽略
  15696. FFocusItem := -1;
  15697. FItemHeight := 14;
  15698. FItemIndex := -1;
  15699. FRefreshing := false;
  15700. FMultiSelect := false;
  15701. FCount := 0;
  15702. UpdateWorkRect;
  15703. ControlStyle := ControlStyle + [csOpaque] ;
  15704. end;
  15705. destructor TDefineGUICtrlSave.Destroy;
  15706. begin
  15707. FOnItemClick := nil;
  15708. FOnItemDlbClick := nil;
  15709. FOnItemDraw := nil;
  15710. //******************************************************
  15711. if FBakList <> nil then
  15712. FreeAndNil(FBakList);
  15713. if FSelectList <> nil then
  15714. FreeAndNil(FSelectList);
  15715. if FVbar <> nil then
  15716. FreeAndNil(FVBar);
  15717. if FBmp <> nil then
  15718. FreeAndNil(FBmp);
  15719. inherited;
  15720. end;
  15721. procedure TDefineGUICtrlSave.UpdateTopIndex;
  15722. begin
  15723. if (Count + 1 - Topindex) < GetPageSize then
  15724. begin
  15725. Topindex := Topindex - 1;
  15726. end;
  15727. end;
  15728. procedure TDefineGUICtrlSave.Put(const Index: Integer);
  15729. begin
  15730. if not FRefreshing and ItemCanSee(index) then invalidate;
  15731. end;
  15732. procedure TDefineGUICtrlSave.Insert(Index: integer);
  15733. var
  15734. i: integer;
  15735. begin
  15736. if IsItem(index) then
  15737. begin
  15738. Count := FCount + 1;
  15739. for i := FCount -1 downto Index do
  15740. if Selected[i] then
  15741. begin
  15742. FSelectlist.UnSelect(i);
  15743. Fselectlist.Select(i + 1);
  15744. end;
  15745. if Index <= FDownItem then
  15746. inc(FDownItem);
  15747. if Index <= FItemIndex then
  15748. inc(FItemIndex);
  15749. if FFocusItem <= FItemIndex then inc(FFocusItem);
  15750. invalidate;
  15751. end;
  15752. end;
  15753. procedure TDefineGUICtrlSave.Move(const CurIndex, NewIndex: Integer);
  15754. procedure MoveFlagItem(var i: integer);
  15755. begin
  15756. if CurIndex < NewIndex then
  15757. begin
  15758. if i = CurIndex then
  15759. i := NewIndex
  15760. else
  15761. if (i > CurIndex) and (i <= NewIndex) then
  15762. Dec(i);
  15763. end
  15764. else
  15765. begin
  15766. if i = CurIndex then
  15767. i := NewIndex
  15768. else
  15769. if (i >= NewIndex) and (i < CurIndex) then
  15770. inc(i);
  15771. end;
  15772. end;
  15773. var
  15774. i: integer;
  15775. Cb: boolean;
  15776. begin
  15777. if isItem(CurIndex) and IsItem(NewIndex) and (CurIndex <> NewIndex) then
  15778. begin
  15779. Cb := GetSelected(CurIndex);
  15780. //必须增加这个, 在改变同时被移动的项目的 Select 状态的时候, CurIndex 被特殊处理:
  15781. FSelectList.UnSelect(CurIndex);
  15782. if CurIndex < NewIndex then
  15783. begin
  15784. for i := CurIndex + 1 to NewIndex do
  15785. if Selected[i] then
  15786. begin
  15787. FSelectList.select(i - 1);
  15788. FSelectList.UnSelect(i);
  15789. end;
  15790. end
  15791. else
  15792. begin
  15793. for i := CurIndex - 1 downto NewIndex do
  15794. if Selected[i] then
  15795. begin
  15796. FSelectlist.UnSelect(i);
  15797. Fselectlist.Select(i + 1);
  15798. end;
  15799. end;
  15800. FSelectList.Bits[NewIndex] := Cb;
  15801. MoveFlagItem(FitemIndex);
  15802. MoveFlagItem(FDownItem);
  15803. MoveFlagItem(FFocusItem);
  15804. invalidate;
  15805. end;
  15806. end;
  15807. procedure TDefineGUICtrlSave.Add;
  15808. var
  15809. b: boolean;
  15810. begin
  15811. b := Refreshing;
  15812. if not b then
  15813. begin
  15814. BeginUpdate;
  15815. try
  15816. count := count + 1;
  15817. if ItemCanSee(Count - 1) then
  15818. Invalidate;
  15819. finally EndUpdate; end;
  15820. end;
  15821. end;
  15822. procedure TDefineGUICtrlSave.Delete(Index: Integer);
  15823. var
  15824. i: integer;
  15825. begin
  15826. if IsItem(index) then
  15827. begin
  15828. if count > 0 then
  15829. begin
  15830. if FMultiSelect then
  15831. begin
  15832. if Selected[index] then
  15833. FSelectlist.UnSelect(index);
  15834. for i := index + 1 to FCount do
  15835. if Selected[i] then
  15836. begin
  15837. FSelectList.select(i - 1);
  15838. FSelectList.UnSelect(i);
  15839. end;
  15840. end
  15841. else FSelectlist.UnSelectAll;
  15842. Count := FCount -1;
  15843. UpdateTopIndex ;// 重要的代码
  15844. if index > 0 then
  15845. begin
  15846. if FDownItem >= index then
  15847. dec(FDOwnItem);
  15848. if FItemIndex >= index then
  15849. Dec(FItemIndex);
  15850. if FFocusItem >= index then
  15851. Dec(FFocusItem);
  15852. end;
  15853. if not FMultiSelect then
  15854. FSelectList.Select(FItemindex);
  15855. invalidate;
  15856. end;
  15857. end;
  15858. end;
  15859. function TDefineGUICtrlSave.GetSelected(const index: integer): Boolean;
  15860. begin
  15861. result := IsItem(index);
  15862. if result then
  15863. result := FSelectList.Bits[index];
  15864. end;
  15865. procedure TDefineGUICtrlSave.SetCount(const Value: Integer);
  15866. begin
  15867. if FCount <> value then
  15868. begin
  15869. FCount := Value;
  15870. FSelectList.Size := Value;
  15871. UpdateMax;
  15872. UpdatePageSizeOfVbar;
  15873. if not Refreshing then invalidate;
  15874. end;
  15875. end;
  15876. procedure TDefineGUICtrlSave.SetMultiSelect(const Value: boolean);
  15877. begin
  15878. FMultiSelect := Value;
  15879. end;
  15880. procedure TDefineGUICtrlSave.SetSelected(const index: integer;
  15881. const Value: Boolean);
  15882. begin
  15883. if IsItem(index) then
  15884. begin
  15885. if FMultiSelect then
  15886. begin
  15887. FSelectList.Bits[index] := value;
  15888. end
  15889. else
  15890. begin
  15891. if Value then
  15892. SetItemIndex(Index)
  15893. else FSelectList.UnSelect(index);
  15894. end;
  15895. end;
  15896. end;
  15897. procedure TDefineGUICtrlSave.UpdateMax;
  15898. begin
  15899. FVbar.Max := FCount;
  15900. end;
  15901. procedure TDefineGUICtrlSave.SetItemHeight(const Value: integer);
  15902. begin
  15903. if value < 1 then raise Exception.Create('Can not Set ItemHeight < 1.');
  15904. if FItemHeight <> value then
  15905. begin
  15906. FItemHeight := Value;
  15907. UpdatePageSizeOfVbar;
  15908. UpdateTopIndex;
  15909. if not Refreshing then Invalidate;
  15910. end;
  15911. end;
  15912. function TDefineGUICtrlSave.IsItem(const Index: Integer): boolean;
  15913. begin
  15914. result := (Index > -1) and (Count > Index);
  15915. end;
  15916. procedure TDefineGUICtrlSave.MouseEnterItem(const Index: integer);
  15917. begin
  15918. end;
  15919. procedure TDefineGUICtrlSave.MouseLeaveItem(const Index: integer);
  15920. begin
  15921. end;
  15922. procedure TDefineGUICtrlSave.Paint;
  15923. var
  15924. i: integer;
  15925. j: integer;
  15926. State: TListItemStates;
  15927. R: TRect;
  15928. begin
  15929. if not Refreshing then
  15930. begin
  15931. if Fcount > 0 then
  15932. begin
  15933. Fbmp.Width := FWorkRect.Right + 1;
  15934. FBmp.Height := FWorkRect.Bottom;
  15935. FBmp.Canvas.Brush.Color := Color;
  15936. FBmp.Canvas.FillRect(FWorkRect);
  15937. //want for Draw Item:
  15938. if Count - FTopIndex >= PageSize then
  15939. j := TopIndex + GetPageSize
  15940. else j := TopIndex + (Count - TopIndex);
  15941. if j >= FCount then j := FCount - 1;
  15942. //===================================================
  15943. for i := FTopIndex to j do
  15944. begin
  15945. //Rect:
  15946. r := GetItemRect(i);
  15947. //Item tate:
  15948. state := [];
  15949. if Selected[i] then State := state + [isSelected];
  15950. if i = FActiveItem then state := state + [isActive];
  15951. if (i = FFocusItem) and Focused then state := state + [isFocused];
  15952. if not Enabled then
  15953. begin
  15954. state := state + [isDisabled];
  15955. end
  15956. else if FMouseDown then
  15957. begin
  15958. if (FDownItem = i) and (i = FMouseItem) then
  15959. state := state + [isDown];
  15960. end
  15961. else if FMouseItem = i then State := state + [isUp];
  15962. // Run
  15963. if FOwnerDraw and Assigned(FOnItemDraw) then
  15964. FOnItemDraw(FBmp.canvas, i, r, State)
  15965. else
  15966. DrawItem(FBmp.canvas, i, r, State);
  15967. end;
  15968. BitBlt(canvas.Handle,FWorkRect.Left,FWorkRect.Top, FWorkRect.Right - FWorkRect.Left, FWorkRect.Bottom - FWorkRect.top,
  15969. FBmp.Canvas.Handle, FWorkRect.Left, FWorkRect.top,SRCCOPY);
  15970. end
  15971. else
  15972. begin
  15973. canvas.Brush.Color := Color;
  15974. canvas.FillRect(FWorkRect);
  15975. end;
  15976. end;
  15977. end;
  15978. function TDefineGUICtrlSave.ItemAtPoint(const X, Y: integer): integer;
  15979. begin
  15980. result := -1;
  15981. if (x >= FWorkRect.Left) and (x < FWorkRect.Right) then
  15982. begin
  15983. result := ItemAtY(y);
  15984. end;
  15985. end;
  15986. procedure TDefineGUICtrlSave.WMSIZE(var msg: TWMSIZE);
  15987. begin
  15988. inherited;
  15989. UpdateWorkRect;
  15990. UpdatePageSizeOfVbar;
  15991. UpdateTopIndex;
  15992. FVbar.LargeChange := PageSize;
  15993. invalidate;
  15994. end;
  15995. //这个子程序特别要注意;
  15996. //当双击一个控件之后,双击事件事先出发,然后又再触发 MouseDown 事件.
  15997. //这将导致 FMouseDown 不能正确释放.
  15998. //因此必须加入 ssDouble in Shift 的判断
  15999. procedure TDefineGUICtrlSave.MouseDown(Button: TMouseButton; Shift: TShiftState;
  16000. X, Y: Integer);
  16001. var
  16002. i: integer;
  16003. begin
  16004. if (Button = mbLeft) and not(ssDouble in Shift) then
  16005. begin
  16006. BeginUpdate;
  16007. i := ItemAtPoint(x, y);
  16008. try
  16009. if i > -1 then
  16010. begin
  16011. FDownShift := shift;
  16012. FMouseDown := true;
  16013. SetItemIndex(i);
  16014. //=================================
  16015. if FMultiSelect then
  16016. begin
  16017. //备份状态:
  16018. SaveBakSelectState;
  16019. if (ssShift in Shift) and (FDownItem > -1) then
  16020. begin
  16021. FSelectList.UnSelectAll;
  16022. FSelectList.SelectSome(i,FDownItem);
  16023. end
  16024. else
  16025. if ssCtrl in shift then
  16026. begin
  16027. //设置鼠标拖动动作类型:
  16028. FCtrlIsClear := FSelectlist.Bits[i];
  16029. FSelectList.ChangeSelect(i);
  16030. SetMouseDownItem(i);
  16031. end
  16032. else
  16033. begin
  16034. FSelectList.UnSelectAll;
  16035. FSelectList.Select(i);
  16036. SetMouseDownItem(i);
  16037. end;
  16038. end
  16039. else
  16040. SetMouseDownItem(i);
  16041. //===============================
  16042. //Link:
  16043. MouseDownItem(i);
  16044. end;
  16045. finally EndUpdate; if i > -1 then invalidate; end;
  16046. if not Focused then SetFocus; // SetFocus
  16047. end;
  16048. inherited MouseDown(Button, shift, x, y);;
  16049. end;
  16050. procedure TDefineGUICtrlSave.MouseMove(Shift: TShiftState; X, Y: Integer);
  16051. var
  16052. i: integer;
  16053. begin
  16054. if FMouseDown then SetMouseItem(ItemAtY(Y))
  16055. else SetMouseItem(ItemAtPoint(x, y));
  16056. //======================================
  16057. if FMouseDown then
  16058. begin
  16059. i := ItemAtY( y);
  16060. if (y < FWorkRect.Top) and (i < TopIndex) then
  16061. i := TopIndex
  16062. else
  16063. if (y > FWorkRect.Bottom) then
  16064. begin
  16065. i := TopIndex + GetPageSize - 1;
  16066. if (i >= count) and (count > 0) then i := count -1;
  16067. end;
  16068. if (i > -1) and (FMoveItem <> i) then
  16069. begin
  16070. SetItemIndex(i);
  16071. if FMultiSelect then
  16072. begin
  16073. if ssCtrl in FDownShift then
  16074. begin
  16075. LoadBakSelectState;
  16076. if FCtrlIsClear then
  16077. FSelectList.UnSelectSome(FDownItem, i)
  16078. else FSelectList.SelectSome(FDownItem, i);
  16079. end
  16080. else
  16081. begin
  16082. FSelectList.UnSelectAll;
  16083. FSelectList.SelectSome(FDownItem, i);
  16084. end;
  16085. end;
  16086. end;
  16087. FMoveItem := i;
  16088. if Y - FWorkRect.Top < 0 then //鼠标在上面位置
  16089. begin
  16090. if Y - FWorkRect.Top < -30 then
  16091. SetMouseChangePage(cpDecMax)
  16092. else
  16093. if Y - FWorkRect.Top < -15 then
  16094. SetMouseChangePage(cpDecNormal)
  16095. else
  16096. SetMouseChangePage(cpDecMin);
  16097. end
  16098. else
  16099. if Y > FWorkRect.Bottom then
  16100. begin
  16101. if Y - FWorkRect.Bottom > 30 then
  16102. SetMouseChangePage(cpAddMax)
  16103. else
  16104. if Y - FWorkRect.Bottom > 15 then
  16105. SetMouseChangePage(cpAddNormal)
  16106. else
  16107. SetMouseChangePage(cpAddMin);
  16108. end
  16109. else SetMouseChangePage(cpNone); //关闭
  16110. end;
  16111. inherited MouseMove(shift, x, y);
  16112. end;
  16113. procedure TDefineGUICtrlSave.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
  16114. Y: Integer);
  16115. begin
  16116. if Button = mbLeft then
  16117. begin
  16118. //注意关闭 Timer:
  16119. SetMouseChangePage(cpNone) ;
  16120. if FMultiSelect then
  16121. FBakList.Size := 0;
  16122. FDownShift := [];
  16123. FMouseDown := false;
  16124. //link:
  16125. if FMouseItem <> -1 then
  16126. MouseUpItem(FMouseItem);
  16127. if FMouseItem = FDownItem then
  16128. ItemClick(FDownItem);
  16129. end;
  16130. inherited MouseUp(button, shift, x, y);
  16131. end;
  16132. procedure TDefineGUICtrlSave.ItemClick(const Index: integer);
  16133. begin
  16134. if Assigned(FOnItemClick) then
  16135. FOnItemClick(self, Index);
  16136. end;
  16137. procedure TDefineGUICtrlSave.MouseDownItem(const Index: integer);
  16138. begin
  16139. end;
  16140. procedure TDefineGUICtrlSave.MouseUpItem(const Index: integer);
  16141. begin
  16142. end;
  16143. procedure TDefineGUICtrlSave.SetItemIndex(Value: integer);
  16144. begin
  16145. if value < -1 then value := -1
  16146. else if value >= FCount then value := FCount - 1;
  16147. if FItemIndex <> value then
  16148. begin
  16149. if not FMultiSelect then
  16150. begin
  16151. FSelectList.UnSelectALl;
  16152. FSelectList.Select(Value);
  16153. end;
  16154. FItemIndex := Value;
  16155. SetFocusItem(Value, false);
  16156. if not Refreshing then
  16157. begin
  16158. if not ItemCanSee(FItemIndex) then
  16159. ToSeeItem(FItemIndex)
  16160. else invalidate;
  16161. end;
  16162. end;
  16163. end;
  16164. procedure TDefineGUICtrlSave.ToSeeItem(Index: integer);
  16165. begin
  16166. if FCount > 0 then
  16167. begin
  16168. if index < 0 then index := 0
  16169. else if index >= FCount then index := FCount - 1;
  16170. if not ItemCanSee(index) then
  16171. begin
  16172. if Index < FTopIndex then
  16173. FVBar.DoScroll(smDec, True, TopIndex - index)
  16174. else
  16175. FVBar.DoScroll(smAdd, true, index - PageSize - FTopIndex + 1);
  16176. end;
  16177. end;
  16178. end;
  16179. function TDefineGUICtrlSave.ItemCanSee(const Index: integer): boolean;
  16180. begin
  16181. result := false;
  16182. if count > -1 then
  16183. begin
  16184. if IsNoStandardSize then
  16185. begin
  16186. result := (Index >= TopIndex) and
  16187. ((Index - GetTopIndex) * FItemHeight <
  16188. (FWorkRect.Bottom - FWorkRect.Top));
  16189. end
  16190. else
  16191. begin
  16192. result := (Index >= TopIndex) and
  16193. ((Index - GetTopIndex) * FItemHeight <
  16194. (FWorkRect.Bottom - FWorkRect.Top));
  16195. end;
  16196. end;
  16197. end;
  16198. function TDefineGUICtrlSave.ItemAtY(const y: integer): integer;
  16199. begin
  16200. result := -1;
  16201. if (y > FWorkRect.top) and (Y < FWorkRect.Bottom) then
  16202. result := FTopIndex + (y - FWorkRect.Top) div FItemHeight;
  16203. if result >= FCount then result := -1;
  16204. end;
  16205. function TDefineGUICtrlSave.GetTopIndex: integer;
  16206. begin
  16207. result := FTopIndex;
  16208. end;
  16209. procedure TDefineGUICtrlSave.SetTopIndex(Value: integer);
  16210. begin
  16211. if not VbarCanSee then value := 0
  16212. else
  16213. if (Count + 1 - value) < GetPageSize then
  16214. value := count - GetPageSize + 1;
  16215. if Value < 0 then value := 0;
  16216. if value <> FTopIndex then
  16217. begin
  16218. FTopIndex := value;
  16219. if FVbar.Position <> value then FVbar.Position := value;
  16220. if not Refreshing then Invalidate;
  16221. end;
  16222. end;
  16223. function TDefineGUICtrlSave.IsNoStandardSize: Boolean;
  16224. begin
  16225. result := (FWorkRect.Bottom - FWorkRect.Top) mod ItemHeight > 0;
  16226. end;
  16227. procedure TDefineGUICtrlSave.CMEnabledChanged(var Msg: TMessage);
  16228. begin
  16229. inherited;
  16230. if not Enabled then
  16231. begin
  16232. FMouseDown := false;
  16233. FDownItem := -1;
  16234. FMouseItem := -1;
  16235. end;
  16236. end;
  16237. procedure TDefineGUICtrlSave.CMMouseLeave(var Msg: TMessage);
  16238. begin
  16239. inherited;
  16240. end;
  16241. procedure TDefineGUICtrlSave.SetMouseItem(const Index: Integer);
  16242. var
  16243. b: integer;
  16244. begin
  16245. if FMouseItem <> Index then
  16246. begin
  16247. b := FMouseItem;
  16248. FMouseItem := Index;
  16249. if (b > -1) and (b < Count) then
  16250. MouseLeaveItem(b);
  16251. if (FMouseItem > -1) and (FMouseItem < Count) then
  16252. MouseEnterItem(FMouseItem);
  16253. end;
  16254. end;
  16255. procedure TDefineGUICtrlSave.SetFocusItem(const Value: integer; const DoRePaint:boolean);
  16256. begin
  16257. if Value <> FFocusItem then
  16258. begin
  16259. FFocusItem := Value;
  16260. if not Refreshing and DoRePaint then invalidate;
  16261. end;
  16262. end;
  16263. procedure TDefineGUICtrlSave.BeginUpdate;
  16264. begin
  16265. FRefreshing := true;
  16266. end;
  16267. procedure TDefineGUICtrlSave.EndUpdate;
  16268. begin
  16269. FRefreshing := false;
  16270. end;
  16271. procedure TDefineGUICtrlSave.SimpleSetItemIndex(Value: integer);
  16272. begin
  16273. if value < -1 then value := -1
  16274. else if value >= FCount then value := FCount - 1;
  16275. if FItemIndex <> value then
  16276. FItemIndex := Value;
  16277. end;
  16278. procedure TDefineGUICtrlSave.SetMouseDownItem(const Value: Integer);
  16279. begin
  16280. if Value <> FDownItem then
  16281. begin
  16282. FDownItem := Value;
  16283. if FDownItem < -1 then FDownItem := -1
  16284. else if FDownItem > FCount - 1 then FDownItem := FCount - 1;
  16285. end
  16286. end;
  16287. //减少闪烁:
  16288. procedure TDefineGUICtrlSave.WMEraseBkgnd(var Message: TWmEraseBkgnd);
  16289. begin
  16290. inherited;
  16291. // Message.Result := 1;
  16292. end;
  16293. procedure TDefineGUICtrlSave.LoadBakSelectState;
  16294. var
  16295. i: integer;
  16296. begin
  16297. FSelectList.Size := FBakList.Size;
  16298. if FBakList.Size > 0 then
  16299. for i := 0 to FBakList.size -1 do
  16300. FSelectList.Bits[i] := FBakList.Bits[i];
  16301. end;
  16302. procedure TDefineGUICtrlSave.SaveBakSelectState;
  16303. var
  16304. i: integer;
  16305. begin
  16306. FBakList.Size := FSelectList.Size;
  16307. if FBakList.Size > 0 then
  16308. for i := 0 to FSelectList.size -1 do
  16309. FBakList.Bits[i] := FSelectList.Bits[i];
  16310. end;
  16311. procedure TDefineGUICtrlSave.DrawItem(Cav: TCanvas; const Index: Integer;
  16312. const R: TRect; const State: TListItemStates);
  16313. begin
  16314. end;
  16315. function TDefineGUICtrlSave.GetItemRectEx(const virtualTopIndex, index: integer): TRect;
  16316. var
  16317. i: integer;
  16318. begin
  16319. result := Rect(0,0,0,0);
  16320. if (Index >= virtualTopIndex) and (index < FCount) and (virtualTopIndex > -1) and
  16321. (virtualTopIndex < FCount) then
  16322. begin
  16323. i := FWorkRect.Top + FItemHeight * (Index - virtualTopIndex);
  16324. result := Rect(FWorkRect.Left, i,FWorkRect.Right, i + FItemHeight);
  16325. end;
  16326. end;
  16327. function TDefineGUICtrlSave.GetPageSize: integer;
  16328. begin
  16329. result := (FWorkRect.Bottom - FWorkRect.Top) div FItemHeight;
  16330. if IsNoStandardSize then
  16331. Result := result + 1;
  16332. end;
  16333. procedure TDefineGUICtrlSave.SetActiveItem(const Value: integer);
  16334. begin
  16335. FActiveItem := Value;
  16336. end;
  16337. function TDefineGUICtrlSave.GetItemRect(const Index: integer): TRect;
  16338. var
  16339. i: integer;
  16340. begin
  16341. result := Rect(0,0,0,0);
  16342. if IsItem(index) then
  16343. begin
  16344. i := FWorkRect.Top + FItemHeight * (Index - TopIndex);
  16345. result := Rect(FWorkRect.Left, i,FWorkRect.Right, i + FItemHeight);
  16346. end;
  16347. end;
  16348. procedure TDefineGUICtrlSave.OnVbarScroll(Sender: TObject;
  16349. const StartChange: boolean; Code: TIScrollCode; Mode: TScrollMode;
  16350. const ChangeValue: integer);
  16351. var
  16352. i: integer;
  16353. begin
  16354. if Mode = smAdd then
  16355. i := ChangeValue
  16356. else i := - ChangeValue;
  16357. //Code = scTrackMove
  16358. if StartChange then
  16359. begin
  16360. if code = scTrackMove then
  16361. begin
  16362. TopIndex := FTopIndex + i;
  16363. end
  16364. else AdjustSee(i);
  16365. end
  16366. else TopIndex := FTopIndex + i;
  16367. //正在使用鼠标改变页面:
  16368. case FMousePage of
  16369. cpAddMin, cpAddNormal, cpAddMax:
  16370. begin
  16371. if FMultiSelect then
  16372. begin
  16373. if ssCtrl in FDownShift then
  16374. begin
  16375. LoadBakSelectState;
  16376. if FCtrlIsClear then
  16377. FSelectList.UnSelectSome(FDownItem, FTopIndex + PageSize - 1)
  16378. else FSelectList.SelectSome(FDownItem, FTopIndex + PageSize - 1);
  16379. end
  16380. else
  16381. begin
  16382. FSelectList.UnSelectAll;
  16383. FSelectList.SelectSome(FDownItem, FTopIndex + PageSize - 1);
  16384. end;
  16385. end;
  16386. SetItemIndex(FTopIndex + PageSize - 1);
  16387. end;
  16388. cpDecMin, cpDecNormal, cpDecMax:
  16389. begin
  16390. if FMultiSelect then
  16391. begin
  16392. if ssCtrl in FDownShift then
  16393. begin
  16394. LoadBakSelectState;
  16395. if FCtrlIsClear then
  16396. FSelectList.UnSelectSome(FDownItem, FTopIndex)
  16397. else FSelectList.SelectSome(FDownItem, FTopIndex);
  16398. end
  16399. else
  16400. begin
  16401. FSelectList.UnSelectAll;
  16402. FSelectList.SelectSome(FDownItem, FTopIndex);
  16403. end;
  16404. end;
  16405. SetItemIndex(FTopIndex);
  16406. end;
  16407. end;
  16408. end;
  16409. procedure TDefineGUICtrlSave.WMKILLFOCUS(var Message: TMessage);
  16410. begin
  16411. if FMultiSelect then
  16412. FBakList.Size := 0;
  16413. FDownShift := [];
  16414. FMouseDown := false;
  16415. if not Refreshing then invalidate;
  16416. inherited;
  16417. end;
  16418. procedure TDefineGUICtrlSave.WMSETFOCUS(var message: TMessage);
  16419. begin
  16420. inherited;
  16421. if not Refreshing then invalidate;
  16422. end;
  16423. procedure TDefineGUICtrlSave.WMGetDlgCode(var Message: TWMGetDlgCode);
  16424. begin
  16425. inherited; // DLGC_WANTARROWS 让 KeyDown 事件支持系统按键
  16426. Message.Result := Message.Result or DLGC_WANTARROWS;
  16427. end;
  16428. procedure TDefineGUICtrlSave.WMMouseWheel(var Message: TWMMouseWheel);
  16429. begin
  16430. if FMousePage = cpNone then
  16431. begin
  16432. FWheel.WheelCount := FWheel.WheelCount + 1;
  16433. FWheel.IsAdd := message.WheelDelta < 0;
  16434. if FWheel.IsAdd then
  16435. FVBar.DoScroll(smadd,true, FWheel.WheelCount * 3)
  16436. else FVBar.DoScroll(smdec, true,FWheel.WheelCount * 3);
  16437. if not FWheel.Wheeling then
  16438. begin
  16439. FWheel.Wheeling := true;
  16440. StartTimer(C_WheelWaitTimerID, C_WheelWait);
  16441. end;
  16442. end;
  16443. inherited;
  16444. end;
  16445. procedure TDefineGUICtrlSave.CloseTimer(const ID: integer);
  16446. begin
  16447. KillTimer(handle, ID);
  16448. end;
  16449. procedure TDefineGUICtrlSave.StartTimer(const ID, interval: integer);
  16450. begin
  16451. SetTimer(handle, ID, interval,nil);
  16452. end;
  16453. procedure TDefineGUICtrlSave.OnTimer(var Msg: TWMTimer);
  16454. begin
  16455. //鼠标滑轮改变页面事件:
  16456. if msg.TimerID = C_WheelWaitTimerID then
  16457. begin
  16458. CloseTimer(C_WheelWaitTimerID);
  16459. FWheel.Wheeling := false;
  16460. FWheel.WheelCount := 0;
  16461. End
  16462. else //鼠标改变页面事件:
  16463. if msg.TimerID = C_MouseChangePageTimerID then
  16464. begin
  16465. case FMousePage of
  16466. cpNone: CloseTimer(C_MouseChangePageTimerID) ;
  16467. cpAddMin, cpAddNormal, cpAddMax:
  16468. FVbar.DoScroll(smAdd,false,1)
  16469. else
  16470. FVbar.DoScroll(smDec,false,1)
  16471. end;
  16472. end;
  16473. end;
  16474. procedure TDefineGUICtrlSave.SetMouseChangePage(const Value: TMouseChangePage);
  16475. function GetInterval(const value: TMouseChangePage): Integer;
  16476. begin
  16477. result := -1;
  16478. case value of
  16479. cpAddMin, cpDecMin: result := 100;
  16480. cpAddNormal , cpDecNormal: result := 50;
  16481. cpAddMax, cpDecMax: result := 10;
  16482. end;
  16483. end;
  16484. begin
  16485. if value <> FMousePage then
  16486. begin
  16487. if FMousePage = cpNone then
  16488. begin
  16489. case value of //这儿需要修改:
  16490. cpAddMin, cpAddNormal, cpAddMax:
  16491. begin
  16492. FVBar.DoScroll(smAdd, true, 1);
  16493. end;
  16494. cpDecMin, cpDecNormal, cpDecMax:
  16495. begin
  16496. FVBar.DoScroll(smDec, true, 1);
  16497. end;
  16498. end;
  16499. end;
  16500. FMousePage := Value;
  16501. if value = cpNone then
  16502. CloseTimer(C_MouseChangePageTimerID)
  16503. else SetTimer(handle, C_MouseChangePageTimerID, GetInterval(value), nil);
  16504. end;
  16505. end;
  16506. procedure TDefineGUICtrlSave.DrawBitMap(bmp: TBitmap; BeginItem,
  16507. EndItem: integer);
  16508. var
  16509. i: integer;
  16510. r: TRect;
  16511. state:TListItemStates;
  16512. begin
  16513. if BeginItem < 0 then BeginItem := 0;
  16514. if EndItem >= FCount then EndItem := FCount - 1;
  16515. if BeginItem < EndItem then
  16516. begin
  16517. bmp.Width := FWorkRect.Right + 1;
  16518. bmp.Height := (EndItem - BeginItem + 2) * ItemHeight;
  16519. FBmp.Canvas.Brush.Color := Color;
  16520. FBmp.Canvas.FillRect(Rect(0, 0, FBmp.Width, Fbmp.Height));
  16521. for i := BeginItem to EndItem do
  16522. begin
  16523. R := GetItemRectEx(BeginItem,i);
  16524. //Item tate:
  16525. state := [];
  16526. if Selected[i] then State := state + [isSelected];
  16527. if i = FActiveItem then state := state + [isActive];
  16528. if (i = FFocusItem) and Focused then state := state + [isFocused];
  16529. if not Enabled then
  16530. begin
  16531. state := state + [isDisabled];
  16532. end
  16533. else if FMouseDown then
  16534. begin
  16535. if (FDownItem = i) and (i = FMouseItem) then
  16536. state := state + [isDown];
  16537. end
  16538. else if FMouseItem = i then State := state + [isUp];
  16539. // Run
  16540. if FOwnerDraw and Assigned(FOnItemDraw) then
  16541. FOnItemDraw(bmp.canvas, i, r, State)
  16542. else
  16543. DrawItem(bmp.canvas, i, r, State);
  16544. end;
  16545. end;
  16546. end;
  16547. procedure TDefineGUICtrlSave.CMFONTCHANGED(var msg: TMessage);
  16548. begin
  16549. inherited;
  16550. FBmp.Canvas.Font.Assign(Font);
  16551. canvas.Font.Assign(font);
  16552. end;
  16553. procedure TDefineGUICtrlSave.AdjustSee(value: integer);
  16554. var
  16555. i: integer;
  16556. begin
  16557. if (FCount > 0) and showing then
  16558. begin
  16559. value := TopIndex + value;
  16560. if value < 0 then value := 0
  16561. else if value >= FCount then value := FCount - 1;
  16562. //如果页面可视范围小于 Itemheight 那么直接转移到该项目,不作动画:
  16563. if ItemHeight <= (GetPageSize * ItemHeight) then
  16564. begin
  16565. //注意此处, While 语句为了截去过长的 Item 数量.
  16566. i := value;
  16567. if i > TopIndex then
  16568. begin
  16569. while ItemHeight * (i - TopIndex) > (FWorkRect.Bottom - FWorkRect.Top) do
  16570. Dec(i);
  16571. end
  16572. else
  16573. begin
  16574. while ItemHeight * (TopIndex - i) > (FWorkRect.Bottom - FWorkRect.Top) do
  16575. inc(i);
  16576. end;
  16577. if value > TopIndex then
  16578. begin
  16579. DrawBitMap(FBMP, TopIndex, i + PageSize);
  16580. CopyBit((i - TopIndex) * ItemHeight,0 ,FBmp.Canvas.Handle, true );
  16581. end
  16582. else
  16583. if value < topindex then
  16584. begin
  16585. DrawBitMap(FBmp, i, TopIndex + PageSize);
  16586. CopyBit((TopIndex - i) * ItemHeight ,
  16587. 0,FBmp.Canvas.Handle , false );
  16588. end;
  16589. end;
  16590. TopIndex := value;
  16591. end;
  16592. end;
  16593. function TDefineGUICtrlSave.VbarCanSee: boolean;
  16594. begin
  16595. result := FVbar.Visible;
  16596. end;
  16597. //复制,滚动动画 DC
  16598. procedure TDefineGUICtrlSave.CopyBit(const EndY, startY: Integer;const Source: HDC; forward: boolean);
  16599. var
  16600. i: integer;
  16601. int: integer;
  16602. j: integer;
  16603. k: double;
  16604. begin
  16605. // Sleep 时间间隔:
  16606. int := C_MaxInterval div (EndY - StartY);
  16607. //如果时间间隔小于 整体动画时间 除以 最大动画贞数量,那么调整它
  16608. if int < (C_MaxInterval div C_SleepMaxCount) then
  16609. int := (C_MaxInterval div C_SleepMaxCount);
  16610. // 设置 k 为 每一贞滚动的象素:
  16611. k := (EndY - startY) / C_SleepMaxCount;
  16612. if k < 1 then k := 1;
  16613. //设置 j 为滚动贞数量,如果 j 大于 最大贞数量,那么设置为最大贞数量:
  16614. if Endy - startY > C_SleepMaxCount then
  16615. j := C_SleepMaxCount
  16616. else j := EndY - startY ;
  16617. if forward then
  16618. begin
  16619. for i := startY to startY + j do
  16620. begin
  16621. BitBlt(canvas.Handle,FWorkRect.Left,FWorkRect.Top, FWorkRect.Right - FWorkRect.Left, FWorkRect.Bottom - FWorkRect.top,
  16622. Source, FWorkRect.Left, FWorkRect.top + trunc(i * k),SRCCOPY);
  16623. Sleep(int);
  16624. end;
  16625. end
  16626. else
  16627. begin
  16628. for i := (starty + j) downto Starty do
  16629. begin
  16630. BitBlt(canvas.Handle, FWorkRect.Left,FWorkRect.Top, FWorkRect.Right - FWorkRect.Left, FWorkRect.Bottom - FWorkRect.Top,
  16631. Source, FWorkRect.Left ,FWorkRect.top + trunc(i * k) ,SRCCOPY);
  16632. Sleep(int);
  16633. end;
  16634. end;
  16635. end;
  16636. //请注意,这儿描述了 KeyDown 事件中需要注意的地方:
  16637. //KeyDown 事件中附带的 Temp 子程序是为了处理"键盘改变页面"的时候,
  16638. //决定是否显示动画的.
  16639. //最重要的地方是这儿:
  16640. //因为 Temp 是计算参数是否小于 Count 来决定是否执行自身代码的,
  16641. //所以,如果在非标准项目可视状态下,必须自己增加一个 FVbar 的 Position,
  16642. //以让最后一个项目,也就是只显示了一半的项目显示出来
  16643. //在 KeyDown 子程序中的很多地方都标注了 "补丁" 字样,那里就是需要注意的地方.
  16644. procedure TDefineGUICtrlSave.KeyDown(var Key: word; Shift: TShiftState);
  16645. procedure Temp(index: integer);
  16646. var old: integer;
  16647. begin
  16648. if index < 0 then index := 0
  16649. else if index >= FCount then index := FCount - 1;
  16650. if index <> ItemIndex then
  16651. begin
  16652. if not MultiSelect then
  16653. begin
  16654. FSelectList.UnSelectAll;
  16655. FSelectList.Select(index);
  16656. end;
  16657. old := FItemIndex;
  16658. FItemIndex := index;
  16659. SetFocusItem(index, false);
  16660. if index > old then
  16661. FVBar.DoScroll(smAdd, false , index - PageSize - TopIndex + 1)
  16662. else
  16663. FVbar.DoScroll(smDec, false, FTopIndex - index);
  16664. end;
  16665. end;
  16666. var
  16667. OldIndex: integer;
  16668. begin
  16669. OldIndex := FItemIndex;
  16670. case Key of
  16671. VK_UP, VK_LEFT:
  16672. begin
  16673. if (FItemIndex > 0) and (Count > 0) then
  16674. begin
  16675. if ItemCanSee(FItemIndex - 1) then
  16676. SetItemIndex(FItemIndex - 1)
  16677. else
  16678. begin
  16679. if FKeyPage <> kfup then
  16680. begin
  16681. Fkeypage := kfup;
  16682. SetItemIndex(FItemIndex - 1);
  16683. end
  16684. else
  16685. begin
  16686. temp(FItemIndex - 1);
  16687. end;
  16688. end;
  16689. if FMultiSelect then
  16690. begin
  16691. if (ssShift in Shift) then
  16692. begin
  16693. if FDownItem > -1 then
  16694. FSelectlist.SelectSome(FItemIndex,FDownItem)
  16695. else
  16696. FDownItem := FItemIndex;
  16697. end
  16698. else
  16699. begin
  16700. FDownItem := FItemIndex;
  16701. FSelectList.UnSelectAll;
  16702. FSelectList.Select(FItemIndex);
  16703. end;
  16704. Invalidate;
  16705. end;
  16706. end;
  16707. end;
  16708. VK_DOWN, VK_RIGHT:
  16709. begin
  16710. if (Count > 0) then
  16711. begin
  16712. if ItemCanSee(FItemIndex + 1) then
  16713. SetItemIndex(FItemIndex + 1)
  16714. else
  16715. begin
  16716. if FKeyPage <> kfDown then
  16717. begin
  16718. Fkeypage := kfDown;
  16719. if (FItemIndex + 1 = Count) and IsNoStandardSize then
  16720. FVBar.DoScroll(smAdd, true, 1)
  16721. else
  16722. SetItemIndex(FItemIndex + 1);
  16723. end
  16724. else
  16725. begin
  16726. temp(FItemIndex + 1);
  16727. end;
  16728. end;
  16729. if FMultiSelect then
  16730. begin
  16731. if (ssShift in Shift) then
  16732. begin
  16733. if FDownItem > -1 then
  16734. FSelectlist.SelectSome(FItemIndex,FDownItem)
  16735. else
  16736. FDownItem := FItemIndex;
  16737. end
  16738. else
  16739. begin
  16740. FDownItem := FItemIndex;
  16741. FSelectList.UnSelectAll;
  16742. FSelectList.Select(FItemIndex);
  16743. end;
  16744. Invalidate;
  16745. end;
  16746. //补丁:
  16747. if (FItemIndex = FCount - 1) then
  16748. FVBar.DoScroll(smAdd, true, 1);
  16749. end;
  16750. end;
  16751. VK_PRIOR:
  16752. if FVBar.Enabled then
  16753. begin
  16754. if ItemCanSee(FItemIndex - (PageSize - 1)) then
  16755. SetItemIndex(FItemIndex - (PageSize - 1))
  16756. else
  16757. begin
  16758. if FKeyPage <> kfPRIOR then
  16759. begin
  16760. Fkeypage := kfPRIOR;
  16761. SetItemIndex(FItemIndex - (PageSize - 1));
  16762. end
  16763. else
  16764. begin
  16765. temp(FItemIndex - (PageSize - 1));
  16766. end;
  16767. end;
  16768. if (ssShift in Shift) and FMultiSelect then
  16769. begin
  16770. if FDownItem > -1 then
  16771. FSelectList.SelectSome(FItemIndex,FDownItem)
  16772. else FDownItem := FItemIndex;
  16773. end
  16774. else
  16775. begin
  16776. FDownItem := FItemIndex;
  16777. FSelectList.UnSelectAll;
  16778. FSelectList.Select(FItemIndex);
  16779. end;
  16780. invalidate;
  16781. end;
  16782. VK_NEXT:
  16783. if FVBar.Enabled then
  16784. begin
  16785. if ItemCanSee(FItemIndex + PageSize) then
  16786. SetItemIndex(FItemIndex + PageSize)
  16787. else
  16788. begin
  16789. if FKeyPage <> kfNext then
  16790. begin
  16791. Fkeypage := kfNext;
  16792. SetItemIndex(FItemIndex + PageSize);
  16793. end
  16794. else
  16795. begin
  16796. temp(FItemIndex + PageSize);
  16797. end;
  16798. end;
  16799. if (ssShift in Shift) and FMultiSelect then
  16800. begin
  16801. if FDownItem > -1 then
  16802. FSelectList.SelectSome(FItemIndex,FDownItem)
  16803. else FDownItem := FItemIndex;
  16804. end
  16805. else
  16806. begin
  16807. FDownItem := FItemIndex;
  16808. FSelectList.UnSelectAll;
  16809. FSelectList.Select(FItemIndex);
  16810. end;
  16811. //补丁:
  16812. if (FItemIndex = FCount - 1) then
  16813. FVBar.DoScroll(smAdd, true, 1);
  16814. invalidate;
  16815. end;
  16816. VK_END:
  16817. if FCount > 0 then
  16818. begin
  16819. SetItemIndex(FCount -1);
  16820. if FMultiSelect and (ssShift in Shift) then
  16821. begin
  16822. if FDownItem > -1 then
  16823. FSelectList.SelectSome(FItemIndex,FDownItem)
  16824. else FDownItem := FItemIndex;
  16825. end
  16826. else
  16827. begin
  16828. FDownItem := FCount - 1;
  16829. FSelectList.UnSelectAll;
  16830. FSelectList.Select(FItemIndex);
  16831. invalidate;
  16832. end;
  16833. //补丁:
  16834. FVBar.DoScroll(smAdd, true, 1);
  16835. end;
  16836. VK_HOME:
  16837. if FCount > 0 then
  16838. begin
  16839. SetItemIndex(0);
  16840. if FMultiSelect and (ssShift in Shift) then
  16841. begin
  16842. if FDownItem > -1 then
  16843. FSelectList.SelectSome(FItemIndex,FDownItem)
  16844. else FDownItem := FItemIndex;
  16845. end
  16846. else
  16847. begin
  16848. FDownItem := 0;
  16849. FSelectList.UnSelectAll;
  16850. FSelectList.Select(FItemIndex);
  16851. invalidate;
  16852. end;
  16853. end;
  16854. end;
  16855. if OldIndex <> FItemIndex then
  16856. Click;
  16857. inherited;
  16858. end;
  16859. procedure TDefineGUICtrlSave.KeyUp(var Key: Word; shift: TShiftState);
  16860. begin
  16861. //复原 FKeyChangePage State
  16862. case Key of
  16863. VK_UP,
  16864. VK_LEFT,
  16865. VK_DOWN,
  16866. VK_RIGHT,
  16867. VK_PRIOR,
  16868. VK_NEXT: FKeyPage := kfNone;
  16869. end;
  16870. inherited;
  16871. end;
  16872. procedure TDefineGUICtrlSave.CalcSizeOfWoekRect(var R: TRect);
  16873. begin
  16874. end;
  16875. procedure TDefineGUICtrlSave.UpdateWorkRect;
  16876. begin
  16877. FVBar.Left := width - FVbar.Width;
  16878. FWorkRect := Rect(0, 0, FVBar.Left , height);
  16879. if not FVBar.Enabled then
  16880. FWorkRect.Right := width;
  16881. CalcSizeOfWoekRect(Fworkrect);
  16882. if FWorkRect.Bottom < FWorkRect.Top then
  16883. FWorkRect.Bottom := FWorkRect.Top;
  16884. if FWorkRect.Right < FWorkRect.Left then
  16885. FWorkRect.Right := FWorkRect.Left;
  16886. FVBar.Left := FWorkRect.Right;
  16887. FVBar.Top := FWorkRect.Top;
  16888. FVBar.Height := FWorkRect.Bottom - FWorkRect.Top;
  16889. end;
  16890. procedure TDefineGUICtrlSave.DblClick;
  16891. begin
  16892. inherited;
  16893. if FMouseItem = FDownItem then
  16894. If Assigned(FOnItemDlbClick) then
  16895. FOnItemDlbClick(self,FDownItem);
  16896. end;
  16897. procedure TDefineGUICtrlSave.OnVbarEnabledChange(Sender: TObject);
  16898. begin
  16899. UpdateWorkRect;
  16900. end;
  16901. procedure TDefineGUICtrlSave.Clear;
  16902. begin
  16903. FDownItem := -1;
  16904. FMouseItem := -1;
  16905. FItemIndex := -1;
  16906. FFocusItem := -1;
  16907. Count := 0;
  16908. invalidate;
  16909. end;
  16910. procedure TDefineGUICtrlSave.UpdatePageSizeOfVbar;
  16911. var
  16912. i: integer;
  16913. begin
  16914. i := PageSize ;
  16915. if i > 0 then FVbar.PageSize := i
  16916. else FVBar.pageSize := 0;
  16917. end;
  16918. procedure TDefineGUICtrlSave.SetOwnerDraw(const Value: Boolean);
  16919. begin
  16920. if Value <> FOwnerDraw then
  16921. begin
  16922. FOwnerDraw := Value;
  16923. FVbar.OwnerDraw := value;
  16924. invalidate;
  16925. end;
  16926. end;
  16927. function TDefineGUICtrlSave.GetOnDrawScrollBar: TScrollDrawEvent;
  16928. begin
  16929. result := FVbar.OnDrawControl;
  16930. end;
  16931. procedure TDefineGUICtrlSave.SetOnDrawScrollBar(const Value: TScrollDrawEvent);
  16932. begin
  16933. FVBar.OnDrawControl := value;
  16934. end;
  16935. { TDefineGUIListBoxString } //*********************************************
  16936. function TDefineGUICtrlString.AddObject(const S: string; AObject: TObject): Integer;
  16937. begin
  16938. inherited AddObject(s, AObject);
  16939. FControl.Add;
  16940. result := FControl.Count;
  16941. end;
  16942. procedure TDefineGUICtrlString.Clear;
  16943. begin
  16944. inherited Clear;
  16945. FControl.clear;
  16946. end;
  16947. procedure TDefineGUICtrlString.Delete(Index: Integer);
  16948. begin
  16949. inherited Delete(index);
  16950. if not FMoving then FControl.Delete(Index);
  16951. end;
  16952. procedure TDefineGUICtrlString.InsertObject(Index: Integer; const S: string;
  16953. AObject: TObject);
  16954. begin
  16955. inherited InsertObject(index, s, AObject);
  16956. if not FMoving then FControl.Insert(index);
  16957. end;
  16958. procedure TDefineGUICtrlString.Move(CurIndex, NewIndex: Integer);
  16959. begin
  16960. FMoving := true;
  16961. try
  16962. inherited MOVE(CurIndex, NewIndex);
  16963. //这儿首先调用 Inherited Move ;
  16964. //当 CurIndex 等参数发生错误的时候,FControl.Move 就不会继续执行:
  16965. FControl.Move(CurIndex, NewIndex);
  16966. finally FMoving := false; end;
  16967. end;
  16968. procedure TDefineGUICtrlString.Put(Index: Integer; const S: string);
  16969. begin
  16970. inherited Put(index,s);
  16971. FControl.Put(index);
  16972. end;
  16973. procedure TDefineGUICtrlString.SetListControl(const aListControl: TDefineGUICtrlList);
  16974. begin
  16975. FControl := aListControl;
  16976. end;
  16977. procedure TDefineGUICtrlString.SetTextStr(const Value: string);
  16978. begin
  16979. inherited;
  16980. FControl.TopIndex := 0;
  16981. end;
  16982. { TDefineGUIListBox } //*****************************************************
  16983. procedure TDefineGUIListBox.CMFONTCHANGED(var msg: TMessage);
  16984. begin
  16985. inherited;
  16986. UpdateItemheight;
  16987. end;
  16988. constructor TDefineGUIListBox.Create(AOwner: TComponent);
  16989. begin
  16990. inherited Create(AOwner);
  16991. FAutoItemHeight := true;
  16992. Color := clWhite;
  16993. FItems := TDefineGUICtrlString.Create ;
  16994. FItems.SetListControl(Self);
  16995. end;
  16996. destructor TDefineGUIListBox.Destroy;
  16997. begin
  16998. if FItems <> nil then
  16999. FreeAndNil(FItems);
  17000. inherited;
  17001. end;
  17002. procedure TDefineGUIListBox.DrawItem(Cav: TCanvas; const Index: Integer;
  17003. const R: TRect; const State: TListItemStates);
  17004. Function GetChanged(Clr:TColor):TColor;
  17005. var
  17006. r,g,b:integer;
  17007. begin
  17008. clr := ColorToRGB(clr);
  17009. r := Clr and $000000FF;
  17010. g := (Clr and $0000FF00) shr 8;
  17011. b := (Clr and $00FF0000) shr 16;
  17012. r := 255 - r;
  17013. g := 255 - g;
  17014. b := 255 - b;
  17015. Result := RGB(r, g, b);
  17016. end;
  17017. var
  17018. flags: Cardinal;
  17019. nr: TRect;
  17020. begin
  17021. inherited ;
  17022. if GUIStyle <> lcgNone then
  17023. nr := rect(r.Left+ 1,r.Top + 1,r.Right -1,r.Bottom -1)
  17024. else
  17025. nr := r;
  17026. if isDisabled in state then
  17027. Cav.Font.Color := clGradientInactiveCaption
  17028. else
  17029. if (isSelected in State) and (GUIStyle = lcgNone) then
  17030. Cav.Font.Color := GetChanged(Cav.Font.Color)
  17031. else
  17032. if GUIStyle = lcglowered then begin
  17033. if isfocused in State then
  17034. cav.Font.Color := $0000C8FF
  17035. else
  17036. if isactive in State then
  17037. cav.Font.Color := $003C9DFF
  17038. else
  17039. Cav.Font.Color := $00B5BBC4
  17040. end
  17041. else
  17042. Cav.Font.Color := font.Color;
  17043. Flags := DT_SINGLELINE or DT_VCENTER or DT_Left or DT_END_ELLIPSIS;
  17044. DrawText(Cav.Handle,PChar(FItems[index]),length(FItems[index]),nr,flags);
  17045. if (isFocused in state) and (GUIStyle = lcgNone) then Cav.DrawFocusRect(r);
  17046. end;
  17047. function TDefineGUIListBox.GetItems: TStrings;
  17048. begin
  17049. result := FItems;
  17050. end;
  17051. procedure TDefineGUIListBox.SetAutoItemHeight(const Value: Boolean);
  17052. begin
  17053. if FAutoItemHeight <> Value then
  17054. begin
  17055. FAutoItemHeight := Value;
  17056. UpdateItemheight;
  17057. end;
  17058. end;
  17059. procedure TDefineGUIListBox.SetItems(const Value: TStrings);
  17060. begin
  17061. if FItems <> value then
  17062. begin
  17063. FItems.Assign(Value);
  17064. topindex := 0;
  17065. end;
  17066. end;
  17067. procedure TDefineGUIListBox.UpdateItemheight;
  17068. var
  17069. i: integer;
  17070. begin
  17071. // 增加 showing 判断,用于避免控件在没有 Parent 的时候执行 TextHeight ,而
  17072. //导致的错误
  17073. if FAutoItemHeight and showing then
  17074. begin
  17075. Canvas.Font.Assign(Font);
  17076. i := canvas.TextHeight('H');
  17077. if GUIStyle = lcgFlat then
  17078. inc(i,4)
  17079. else
  17080. if GUIStyle = lcglowered then
  17081. inc(i, 4);
  17082. SetItemHeight(i);
  17083. if not Refreshing then invalidate;
  17084. end;
  17085. end;
  17086. procedure TDefineGUIListBox.CMSHOWINGCHANGED(var msg: TMessage);
  17087. begin
  17088. inherited;
  17089. UpdateItemheight;
  17090. end;
  17091. function TDefineGUIListBox.GetCount: integer;
  17092. begin
  17093. result := count;
  17094. end;
  17095. { TDefineGUICtrlList } //*****************************************
  17096. procedure TDefineGUICtrlList.CalcSizeOfWoekRect(var R: TRect);
  17097. begin
  17098. case FGUIStyle of
  17099. lcgFlat:
  17100. r := Rect(r.Left + 2,r.Top + 2, r.Right - 2,r.Bottom -2);
  17101. lcgLowered,
  17102. lcgNone:
  17103. r := Rect(r.Left + 1,r.Top + 1, r.Right - 1,r.Bottom -1);
  17104. end;
  17105. end;
  17106. procedure TDefineGUICtrlList.CMMouseEnter(var Message: TMessage);
  17107. begin
  17108. inherited;
  17109. if (GetActiveWindow <> 0) then
  17110. begin
  17111. FMouseIn := True;
  17112. Invalidate;
  17113. end;
  17114. end;
  17115. procedure TDefineGUICtrlList.CMMouseLeave(var Message: TMessage);
  17116. begin
  17117. inherited;
  17118. if MouseIn then begin
  17119. FMouseIn := False;
  17120. Invalidate;
  17121. end;
  17122. end;
  17123. constructor TDefineGUICtrlList.Create(AOwner: TComponent);
  17124. begin
  17125. inherited Create(AOwner);
  17126. FItemSelectColor := DefaultItemSelectColor;
  17127. FItemBorderColor := DefaultBorderColor;
  17128. FItemBrightColor := DefaultItemBrightColor;
  17129. FItemColor := DefaultItemColor;
  17130. FItemSpaceColor := DefaultItemSpaceColor;
  17131. FFocusColor := clWhite;
  17132. FFlatColor := DefaultFlatColor;
  17133. FGUIStyle := lcgFlat;
  17134. VBar.OnDrawControl := OnVBarDrawControl;
  17135. VBar.OwnerDraw := true;
  17136. end;
  17137. destructor TDefineGUICtrlList.Destroy;
  17138. begin
  17139. VBar.OnDrawControl := nil;
  17140. inherited Destroy;
  17141. end;
  17142. procedure TDefineGUICtrlList.DrawItem(Cav: TCanvas; const Index: Integer;
  17143. const R: TRect; const State: TListItemStates);
  17144. var
  17145. re: Trect;
  17146. begin
  17147. case FGUIStyle of
  17148. lcgLowered:
  17149. begin
  17150. re := R;
  17151. cav.Pen.Style := psSolid;
  17152. if isselected in state then begin
  17153. cav.Brush.Color := fItemSelectColor;
  17154. cav.FillRect(R);
  17155. Frame3D(Cav,re,fItemBrightColor, FItemBorderColor,1);
  17156. end else if isactive in state then begin
  17157. cav.Brush.Color := fItemSelectColor;
  17158. cav.FillRect(R);
  17159. Frame3D(Cav,re,cav.Brush.Color, FItemBorderColor,1);
  17160. end else begin
  17161. cav.Brush.Color := fItemColor;
  17162. cav.FillRect(R);
  17163. Frame3D(Cav,re,fItemBrightColor,FItemBorderColor,1);
  17164. end;
  17165. end;
  17166. lcgFlat:
  17167. begin
  17168. if isselected in State then begin
  17169. Cav.Pen.Style := psSolid;
  17170. cav.Brush.Color := fItemSelectColor;
  17171. cav.Pen.Color := fItemBorderColor;
  17172. cav.Rectangle(R);
  17173. end else if isActive in state then begin
  17174. Cav.Pen.Style := psSolid;
  17175. cav.Brush.Color := $009CDEF7;
  17176. cav.Pen.Color := $008396A0;
  17177. cav.Rectangle(R);
  17178. end else begin
  17179. Cav.Pen.Style := psclear;
  17180. cav.Brush.Color := color;
  17181. cav.FillRect(R);
  17182. end;
  17183. end;
  17184. lcgNone:
  17185. begin
  17186. if isSelected in State then
  17187. cav.Brush.Color := clActiveCaption
  17188. else Cav.Brush.Color := color;
  17189. Cav.FillRect(R);
  17190. end;
  17191. end;
  17192. end;
  17193. function TDefineGUICtrlList.GetMouseIn: boolean;
  17194. begin
  17195. result := FMouseIn;
  17196. end;
  17197. procedure TDefineGUICtrlList.OnVBarDrawControl(Cav: TCanvas;
  17198. const Typ: TDrawScrollBar; const R: TRect; const State: TButtonState);
  17199. var
  17200. i: integer;
  17201. re: Trect;
  17202. begin
  17203. re := R;
  17204. case FGUIStyle of
  17205. lcgLowered: begin
  17206. Cav.Brush.Style := bsSolid;
  17207. if (Typ = dsspaceright) or (Typ = dsspaceleft) then begin
  17208. if State = bsdown then
  17209. Cav.Brush.Color := $006E6E6E
  17210. else
  17211. cav.Brush.Color := $00B5BBC4 ;
  17212. Cav.FillRect(R)
  17213. end else begin
  17214. if (state = bsup) or (state = bsDown) then
  17215. cav.Brush.Color := fItemSelectColor
  17216. else
  17217. cav.Brush.Color := fItemColor;
  17218. cav.FillRect(R);
  17219. if state = bsdown then
  17220. Frame3D(cav,re,FItemBorderColor,FItemBorderColor,1)
  17221. else
  17222. Frame3D(cav,re,fItemBrightColor,FItemBorderColor,1);
  17223. Cav.Pen.Style := psSolid;
  17224. cav.Pen.Color := $00B5BBC4;
  17225. if Typ = dsLeftBtn then begin
  17226. if FVBar.IsVertical then
  17227. FVBar.DrawArrows(cav,daTop,re)
  17228. else
  17229. FVBar.DrawArrows(cav,daLeft,re);
  17230. end else if Typ = dsRightBtn then begin
  17231. if FVBar.IsVertical then
  17232. FVBar.DrawArrows(cav,daBottom,re)
  17233. else
  17234. FVBar.DrawArrows(cav,daRight,re);
  17235. end else begin
  17236. Cav.Pixels[R.Right div 2-3,R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17237. Cav.Pixels[R.Right div 2, R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17238. Cav.Pixels[R.Right div 2+3,R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17239. end;
  17240. end;
  17241. end;
  17242. lcgFlat: begin
  17243. cav.Brush.Color := FVBar.color;
  17244. cav.Brush.Style := bsSolid;
  17245. cav.Pen.Style := psSolid;
  17246. if (Typ = dsSpaceRight) or (Typ = dsSpaceLeft) then begin
  17247. if State = bsdown then
  17248. Cav.Brush.Color := clBackground;
  17249. Cav.FillRect(R);
  17250. cav.Pen.Color := $00C9C2C2;
  17251. if Vbar.IsVertical then begin
  17252. cav.MoveTo(R.Left,R.Top);
  17253. cav.LineTo(R.Left,R.Bottom);
  17254. cav.MoveTo(R.Right-1,R.Top);
  17255. cav.LineTo(R.Right-1,R.Bottom);
  17256. end;
  17257. end else begin
  17258. if state = bsdown then begin
  17259. Cav.Pen.Color := fItemBorderColor ;
  17260. cav.Brush.Color := fItemSpaceColor;
  17261. end else if State = bsup then begin
  17262. cav.Pen.Color := clMoneyGreen ;
  17263. cav.Brush.Color := fItemSpaceColor;
  17264. end else
  17265. cav.Pen.Color := fItemBorderColor;
  17266. cav.Rectangle(R);
  17267. end;
  17268. if state <> bsExclusive then
  17269. Cav.Pen.Color := clInfoBk;
  17270. cav.Pen.Style := psSolid;
  17271. if Typ = dsLeftBtn then begin
  17272. if FVBar.IsVertical then
  17273. FVBar.DrawArrows(cav,daTop,re)
  17274. else
  17275. FVBar.DrawArrows(cav,daLeft,re);
  17276. end else if Typ = dsRightBtn then begin
  17277. if FVBar.IsVertical then
  17278. FVBar.DrawArrows(cav,daBottom,re)
  17279. else
  17280. FVBar.DrawArrows(cav,daRight,re);
  17281. end else if (Typ = dsTrack) then begin
  17282. Cav.Pixels[R.Right div 2-3,R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17283. Cav.Pixels[R.Right div 2, R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17284. Cav.Pixels[R.Right div 2+3,R.Top + ((R.Bottom - R.Top) div 2)] := cav.Pen.Color;
  17285. end;
  17286. end;
  17287. lcgNone: begin
  17288. cav.Brush.Color := FVBar.color;
  17289. cav.Brush.Style := bsSolid;
  17290. if (Typ = dsspaceright) or (Typ = dsspaceleft) then begin
  17291. if State = bsdown then
  17292. cav.brush.Color := clBlack;
  17293. cav.FillRect(R) ;
  17294. end else begin
  17295. if State = bsdown then
  17296. i := BDR_SUNKENOUTER
  17297. else
  17298. i := BDR_RAISEDINNER;
  17299. cav.FillRect(R);
  17300. DrawEdge(cav.Handle,re, i, BF_RECT);
  17301. if State = bsdown then
  17302. InflateRect(re,-3,-3);
  17303. cav.Pen.Color := clblack;
  17304. if Typ = dsLeftBtn then begin
  17305. if FVBar.IsVertical then
  17306. FVBar.DrawArrows(cav,daTop,re)
  17307. else
  17308. FVBar.DrawArrows(cav,daLeft,re);
  17309. end else if Typ = dsrightbtn then begin
  17310. if FVBar.IsVertical then
  17311. FVBar.DrawArrows(cav,daBottom,re)
  17312. else
  17313. FVBar.DrawArrows(cav,daRight,re);
  17314. end;
  17315. end;
  17316. end;
  17317. end;
  17318. end;
  17319. procedure TDefineGUICtrlList.Paint;
  17320. var re: TRect;
  17321. begin
  17322. inherited Paint; //继承
  17323. re := ClientRect;
  17324. if (not(csDesigning in ComponentState) and
  17325. (Focused or(MouseIn and not(Screen.ActiveControl is TDefineGUICtrlList)))) then
  17326. Color := GUIFocusedColor
  17327. else
  17328. Color := GUIFlatColor;
  17329. case FGUIStyle of
  17330. lcgFlat:
  17331. begin
  17332. re := clientrect;
  17333. canvas.Brush.Color := fItemBorderColor;
  17334. FrameRect(canvas.Handle,ClientRect,canvas.brush.Handle);
  17335. canvas.Brush.Color := color;
  17336. re := Rect(re.Left + 1, re.Top + 1, re.Right - 1,re.Bottom - 1);
  17337. FrameRect(canvas.Handle,re,canvas.brush.Handle);
  17338. end;
  17339. lcgLowered:
  17340. begin
  17341. canvas.Brush.color := FItemBorderColor;
  17342. FrameRect(canvas.Handle,ClientRect,canvas.brush.Handle);
  17343. end;
  17344. lcgNone:
  17345. begin
  17346. DrawEdge(canvas.Handle,re, BDR_SUNKENOUTER, BF_RECT);
  17347. end;
  17348. end;
  17349. end;
  17350. procedure TDefineGUICtrlList.SetColors(const Index: Integer; const Value: TColor);
  17351. begin
  17352. case Index of
  17353. 0:FItemSelectColor := Value;
  17354. 1:FItemBorderColor := Value;
  17355. 2:FItemBrightColor := Value;
  17356. 3:FItemColor := Value;
  17357. 4:FItemSpaceColor := Value;
  17358. 5:FFocusColor := Value;
  17359. 6:FFlatColor := Value;
  17360. end;
  17361. Invalidate;
  17362. end;
  17363. procedure TDefineGUICtrlList.SetGUIStyle(const Value: TListControlGUI);
  17364. begin
  17365. if FGUIStyle <> Value then begin
  17366. FGUIStyle := value;
  17367. UpdateWorkRect;
  17368. Perform(CM_SHOWINGCHANGED,0,0); // 触发事件 ListBox UpdateItemHeight
  17369. invalidate;
  17370. end;
  17371. end;
  17372. { TDefineTreeView }
  17373. constructor TDefineTreeView.Create(AOwner: TComponent);
  17374. begin
  17375. inherited Create(AOwner);
  17376. ControlStyle := ControlStyle - [csOpaque];
  17377. ParentFont := True;
  17378. AutoSize := False;
  17379. Ctl3D := False;
  17380. BorderStyle := bsNone;
  17381. Width := 185;
  17382. Height := 89;
  17383. FFocusedColor := clWhite;
  17384. FBorderColor := DefaultBorderColor;
  17385. FFlatColor := DefaultFlatColor;
  17386. FParentColor := True;
  17387. FInterDrawing := False;
  17388. end;
  17389. destructor TDefineTreeView.Destroy;
  17390. begin
  17391. inherited Destroy;
  17392. end;
  17393. procedure TDefineTreeView.SetParentColor(Value: Boolean);
  17394. begin
  17395. if Value <> FParentColor then
  17396. begin
  17397. FParentColor := Value;
  17398. if FParentColor then
  17399. begin
  17400. if Parent <> nil then
  17401. FFlatColor := TForm(Parent).Color;
  17402. RedrawBorder;
  17403. end;
  17404. end;
  17405. end;
  17406. procedure TDefineTreeView.CMSysColorChange(var Message: TMessage);
  17407. begin
  17408. if FParentColor then
  17409. begin
  17410. if Parent <> nil then
  17411. FFlatColor := TForm(Parent).Color;
  17412. end;
  17413. RedrawBorder;
  17414. end;
  17415. procedure TDefineTreeView.CMParentColorChanged(var Message: TWMNoParams);
  17416. begin
  17417. if FParentColor then
  17418. begin
  17419. if Parent <> nil then
  17420. FFlatColor := TForm(Parent).Color;
  17421. end;
  17422. RedrawBorder;
  17423. end;
  17424. procedure TDefineTreeView.SetColors(Index: Integer; Value: TColor);
  17425. begin
  17426. case Index of
  17427. 0: FFocusedColor := Value;
  17428. 1: FBorderColor := Value;
  17429. 2: begin
  17430. FFlatColor := Value;
  17431. FParentColor := False;
  17432. end;
  17433. end;
  17434. RedrawBorder;
  17435. end;
  17436. procedure TDefineTreeView.CMMouseEnter(var Message: TMessage);
  17437. begin
  17438. inherited;
  17439. if (GetActiveWindow <> 0) then
  17440. begin
  17441. FMouseIn := True;
  17442. RedrawBorder;
  17443. end;
  17444. end;
  17445. procedure TDefineTreeView.CMMouseLeave(var Message: TMessage);
  17446. begin
  17447. inherited;
  17448. FMouseIn := False;
  17449. RedrawBorder;
  17450. end;
  17451. procedure TDefineTreeView.CMEnabledChanged(var Message: TMessage);
  17452. begin
  17453. inherited;
  17454. RedrawBorder;
  17455. end;
  17456. procedure TDefineTreeView.WMSetFocus(var Message: TWMSetFocus);
  17457. begin
  17458. inherited;
  17459. if not(csDesigning in ComponentState) then
  17460. RedrawBorder;
  17461. end;
  17462. procedure TDefineTreeView.WMKillFocus(var Message: TWMKillFocus);
  17463. begin
  17464. inherited;
  17465. if not(csDesigning in ComponentState) then
  17466. RedrawBorder;
  17467. end;
  17468. procedure TDefineTreeView.WMNCCalcSize(var Message: TWMNCCalcSize);
  17469. begin
  17470. inherited;
  17471. InflateRect(Message.CalcSize_Params^.rgrc[0], -1, -1);
  17472. end;
  17473. procedure TDefineTreeView.WMNCPaint(var Message: TMessage);
  17474. begin
  17475. inherited;
  17476. RedrawBorder(HRGN(Message.WParam));
  17477. end;
  17478. procedure TDefineTreeView.RedrawBorder(const Clip: HRGN = 0);
  17479. var ViewBorder:TBorderAttrib;
  17480. begin
  17481. with ViewBorder do
  17482. begin
  17483. Ctrl := Self;
  17484. BorderColor := ColorBorder;
  17485. if Enabled then
  17486. begin
  17487. FlatColor := ColorFlat;
  17488. FocusColor := ColorFocused;
  17489. end
  17490. else
  17491. begin
  17492. FlatColor := clSilver;
  17493. FocusColor := clSilver;
  17494. end;
  17495. MouseState := FMouseIn;
  17496. DesignState := ComponentState;
  17497. FocusState := Focused;
  17498. HasBars := False;
  17499. end;
  17500. Color := DrawViewBorder(ViewBorder);
  17501. end;
  17502. function TDefineTreeView.GetItemsCount: Integer;
  17503. begin
  17504. result := inherited Items.Count;
  17505. end;
  17506. procedure TDefineTreeView.Loaded;
  17507. begin
  17508. inherited;
  17509. end;
  17510. { TDefineListView }
  17511. constructor TDefineListView.Create(AOwner: TComponent);
  17512. begin
  17513. FHeaderInstance := MakeObjectInstance(HeaderWndProc);
  17514. FGroundPic := TPicture.Create;
  17515. FTransBit := TBitmap.Create;
  17516. inherited Create(AOwner);
  17517. ParentFont := True;
  17518. AutoSize := False;
  17519. Ctl3D := False;
  17520. BorderStyle := bsNone;
  17521. FlatScrollBars := True;
  17522. Width := 185;
  17523. Height := 89;
  17524. FFocusedColor := clWhite;
  17525. FBorderColor := DefaultBorderColor;
  17526. FFlatColor := DefaultFlatColor;
  17527. FTitleFaceColor := DefaultTitleFaceColor;
  17528. FTitleCheckColor := DefaultTitleCheckColor;
  17529. FParentColor := True;
  17530. FGroundHas := False;
  17531. FGroundStretch := False;
  17532. FAllCheck := False;
  17533. FTransparent := False;
  17534. FHeaderHandle := 0;
  17535. FDefHeaderProc := nil;
  17536. end;
  17537. destructor TDefineListView.Destroy;
  17538. begin
  17539. if FHeaderHandle <> 0 then
  17540. SetWindowLong(FHeaderHandle, GWL_WNDPROC, LongInt(FDefHeaderProc));
  17541. FreeObjectInstance(FHeaderInstance);
  17542. FHeaderHandle := 0;
  17543. FDefHeaderProc := nil;
  17544. FGroundPic.Free;
  17545. FGroundPic := nil;
  17546. FTransBit.Free;
  17547. FTransBit := nil;
  17548. OnCustomDraw := nil;
  17549. inherited Destroy;
  17550. end;
  17551. procedure TDefineListView.DrawTitle(Cnvs: TCanvas; Column: TListColumn; Active, Pressed: Boolean; R: TRect);
  17552. var
  17553. BR, RA, CR: TRect;
  17554. S: String;
  17555. B: TBitMap;
  17556. TX, TY, GX, GY: Integer;
  17557. begin
  17558. if (RectWidth(R) <= 0) or (RectHeight(R) <= 0) then Exit;
  17559. S := Column.Caption;
  17560. B := TBitMap.Create;
  17561. try
  17562. B.Width := RectWidth(R)+1;
  17563. B.Height := RectHeight(R);
  17564. BR := Rect(0, 0, B.Width, B.Height);
  17565. with B.Canvas do
  17566. begin
  17567. if Pressed then begin
  17568. if (not FCheckInBox)and(ColumnClick) then
  17569. Brush.Color := BS_XP_BTNDOWNCOLOR
  17570. else
  17571. Brush.Color := FTitleFaceColor;
  17572. if not(Column.Index = 0) then
  17573. Inc(Br.Left);
  17574. Dec(Br.Right);
  17575. end else if Active then begin
  17576. if (not FCheckInBox)and(ColumnClick) then
  17577. Brush.Color := BS_XP_BTNACTIVECOLOR
  17578. else
  17579. Brush.Color := FTitleFaceColor;
  17580. end else begin
  17581. DrawFrame(B.Canvas, BR, FTitleFaceColor, FTitleFaceColor, 1);
  17582. Brush.Color := FTitleFaceColor;// clBtnFace;
  17583. end;
  17584. FillRect(BR);
  17585. if (Column.Index = 0)and(CheckBoxes) then
  17586. begin
  17587. RA := RECT(0,0,HeaderHeight,HeaderHeight);
  17588. FillRect(RA);
  17589. CR := RECT(RA.Left+1,RA.Top+1,RA.Right-1,RA.Bottom-1);
  17590. // 画选定
  17591. if AllCheck then
  17592. begin
  17593. DrawInCheck(B.Canvas,CR,FTitleCheckColor);
  17594. end;
  17595. BR := RECT(RA.Right+2,BR.Top,BR.Right,BR.Bottom);
  17596. end;
  17597. Frame3d(B.Canvas, CR, FTitleCheckColor, FTitleCheckColor, 2);
  17598. Brush.Style := bsClear;
  17599. Font.Assign(Self.Font);
  17600. Font.Color := clBtnText;
  17601. end;
  17602. if Assigned(FOnDrawTitle) then
  17603. FOnDrawTitle(B.Canvas, Column, Pressed, Rect(0, 0, B.Width, B.Height))
  17604. else with B.Canvas do begin
  17605. Brush.Style := bsClear;
  17606. Inc(BR.Left, 2); Dec(BR.Right, 2);
  17607. if (SmallImages <> nil) and (Column.ImageIndex >= 0) and
  17608. (Column.ImageIndex < SmallImages.Count) then
  17609. begin
  17610. CorrectTextbyWidth(B.Canvas, S, RectWidth(BR) - 4 - SmallImages.Width);
  17611. GX := BR.Left;
  17612. if S = Column.Caption then
  17613. case Column.Alignment of
  17614. taRightJustify: GX := BR.Right - TextWidth(S) - SmallImages.Width - 4;
  17615. taCenter: GX := BR.Left + RectWidth(BR) div 2 - (TextWidth(S) + SmallImages.Width + 4) div 2;
  17616. end;
  17617. TX := GX + SmallImages.Width + 4;
  17618. TY := BR.Top + (RectHeight(BR) - TextHeight(S)) div 2;
  17619. GY := BR.Top + (RectHeight(BR) - SmallImages.Height) div 2;
  17620. SmallImages.Draw(B.Canvas, GX, GY, Column.ImageIndex, True);
  17621. end else begin
  17622. CorrectTextbyWidth(B.Canvas, S, RectWidth(BR));
  17623. TX := BR.Left;
  17624. TY := BR.Top + (RectHeight(BR) - TextHeight(S)) div 2;
  17625. case Column.Alignment of
  17626. taRightJustify: TX := BR.Right - TextWidth(S);
  17627. taCenter: TX := (RectWidth(BR) - TextWidth(S) + 4) div 2;
  17628. end;
  17629. end;
  17630. TextRect(BR, TX, TY, S);
  17631. end;
  17632. Cnvs.Draw(R.Left, R.Top, B);
  17633. finally
  17634. B.Free;
  17635. end;
  17636. end;
  17637. function TDefineListView.GetHeaderSectionRect(Index: Integer): TRect;
  17638. var
  17639. SectionOrder: array of Integer;
  17640. R: TRect;
  17641. begin
  17642. if Self.FullDrag then
  17643. begin
  17644. SetLength(SectionOrder, Columns.Count);
  17645. Header_GetOrderArray(FHeaderHandle, Columns.Count, PInteger(SectionOrder));
  17646. Header_GETITEMRECT(FHeaderHandle, SectionOrder[Index] , @R);
  17647. end else
  17648. Header_GETITEMRECT(FHeaderHandle, Index, @R);
  17649. Result := R;
  17650. end;
  17651. procedure TDefineListView.DrawHeader(DC: HDC);
  17652. var
  17653. Cnvs: TControlCanvas;
  17654. i, RightOffset, HeaderCount: Integer;
  17655. R, BGR, HR: TRect;
  17656. PS: TPaintStruct;
  17657. begin
  17658. Cnvs := TControlCanvas.Create;
  17659. try
  17660. Cnvs.Handle := BeginPaint(FHeaderHandle, PS);
  17661. HeaderCount := Header_GetItemCount(FHeaderHandle);
  17662. RightOffset := 0;
  17663. for i := 0 to HeaderCount - 1 do begin
  17664. R := GetHeaderSectionRect(i);
  17665. DrawTitle(Cnvs, Columns[i], False, (FActiveSection = I) and FHeaderDown, R);
  17666. if RightOffset < R.Right then RightOffset := R.Right;
  17667. end;
  17668. GetWindowRect(FHeaderHandle, HR);
  17669. BGR := Rect(RightOffset+1, 0, RectWidth(HR), RectHeight(HR));
  17670. if BGR.Left < BGR.Right then begin
  17671. Cnvs.Brush.Color := FTitleFaceColor;//clBtnFace;
  17672. Cnvs.FillRect(BGR);
  17673. DrawFrame(Cnvs, BGR, FTitleFaceColor, FTitleFaceColor, 1);
  17674. end;;
  17675. finally
  17676. Cnvs.Free;
  17677. EndPaint(FHeaderHandle, PS)
  17678. end;
  17679. end;
  17680. procedure TDefineListView.HeaderWndProc(var Message: TMessage);
  17681. var
  17682. X, Y: Integer;
  17683. procedure GetSectionFromPoint(P: TPoint);
  17684. var
  17685. i: Integer;
  17686. R,RA,BR: TRect;
  17687. begin
  17688. FActiveSection := -1;
  17689. RA := RECT(0,0,HeaderHeight,HeaderHeight);
  17690. for i := 0 to Columns.Count - 1 do
  17691. begin
  17692. R := GetHeaderSectionRect(i);
  17693. FCheckInBox := False;
  17694. if i = 0 then
  17695. begin
  17696. BR := Rect(RA.Right,R.Top,R.Right,R.Bottom);
  17697. if PtInRect(RA, Point(X, Y)) then
  17698. begin
  17699. FActiveSection := i;
  17700. FCheckInBox := True;
  17701. Break;
  17702. end
  17703. else if PtInRect(BR, Point(X, Y)) then
  17704. begin
  17705. FActiveSection := i;
  17706. Break;
  17707. end;
  17708. end else begin
  17709. if PtInRect(R, Point(X, Y)) then
  17710. begin
  17711. FActiveSection := i;
  17712. Break;
  17713. end;
  17714. end;
  17715. end;
  17716. end;
  17717. var
  17718. Info: THDHitTestInfo;
  17719. begin
  17720. with Message do begin
  17721. case Msg of
  17722. WM_WINDOWPOSCHANGING :
  17723. begin
  17724. with TWMWINDOWPOSCHANGING(Message) do
  17725. WindowPos.cx := WindowPos.cx + 4;
  17726. end;
  17727. WM_PAINT:DrawHeader(TWMPAINT(Message).DC);
  17728. WM_ERASEBKGND : result := 1;
  17729. else
  17730. Result := CallWindowProc(FDefHeaderProc, FHeaderHandle, Msg, WParam, LParam);
  17731. end;
  17732. case Msg of
  17733. WM_LBUTTONDOWN:
  17734. begin
  17735. X := TWMLBUTTONDOWN(Message).XPos;
  17736. Y := TWMLBUTTONDOWN(Message).YPos;
  17737. GetSectionFromPoint(Point(X, Y));
  17738. Info.Point.X := X;
  17739. Info.Point.Y := Y;
  17740. SendMessage(FHeaderHandle, HDM_HITTEST, 0, Integer(@Info));
  17741. FHeaderDown := not (Info.Flags = HHT_ONDIVIDER);
  17742. if FCheckInBox then SetAllCheck(not FAllCheck);
  17743. RedrawWindow(FHeaderHandle, nil, 0, RDW_INVALIDATE);
  17744. end;
  17745. WM_LBUTTONUP:
  17746. begin
  17747. FHeaderDown := False;
  17748. FActiveSection := -1;
  17749. RedrawWindow(FHeaderHandle, nil, 0, RDW_INVALIDATE);
  17750. end;
  17751. end;
  17752. end;
  17753. end;
  17754. procedure TDefineListView.WndProc(var Message: TMessage);
  17755. var WndClass: String;
  17756. begin
  17757. case Message.Msg of
  17758. WM_PARENTNOTIFY:
  17759. with TWMPARENTNOTIFY(Message) do
  17760. begin
  17761. SetLength(WndClass, 80);
  17762. SetLength(WndClass, GetClassName(ChildWnd, PChar(WndClass), Length(WndClass)));
  17763. if (Event = WM_CREATE) and (FHeaderHandle <> 0) and ShowColumnHeaders and
  17764. (WndClass = 'SysHeader32') then
  17765. begin
  17766. SetWindowLong(FHeaderHandle, GWL_WNDPROC, LongInt(FDefHeaderProc));
  17767. FHeaderHandle := 0;
  17768. end;
  17769. if (Event = WM_CREATE) and (FHeaderHandle = 0) and ShowColumnHeaders and
  17770. (WndClass = 'SysHeader32') then
  17771. begin
  17772. FHeaderHandle := ChildWnd;
  17773. FDefHeaderProc := Pointer(GetWindowLong(FHeaderHandle, GWL_WNDPROC));
  17774. SetWindowLong(FHeaderHandle, GWL_WNDPROC, LongInt(FHeaderInstance));
  17775. end;
  17776. end;
  17777. WM_MOUSEWHEEL,
  17778. WM_HSCROLL,
  17779. WM_VSCROLL: if (GroundHas)or(Transparent) then InvalidateRect(Handle, nil, False);
  17780. WM_KEYDOWN:
  17781. Case Message.WParam of
  17782. VK_Left,
  17783. VK_Right,
  17784. VK_UP,
  17785. VK_Down : if (GroundHas)or(Transparent) then InvalidateRect(Handle, nil, False);
  17786. end;
  17787. end;
  17788. inherited;
  17789. end;
  17790. procedure TDefineListView.RedrawBorder(const Clip: HRGN = 0);
  17791. var ViewBorder:TBorderAttrib;
  17792. clColor:TColor;
  17793. begin
  17794. with ViewBorder do
  17795. begin
  17796. Ctrl := Self;
  17797. BorderColor := ColorBorder;
  17798. if Enabled then
  17799. begin
  17800. FlatColor := ColorFlat;
  17801. FocusColor := ColorFocused;
  17802. end
  17803. else
  17804. begin
  17805. FlatColor := clSilver;
  17806. FocusColor := clSilver;
  17807. end;
  17808. MouseState := FMouseIn;
  17809. DesignState := ComponentState;
  17810. FocusState := Focused;
  17811. HasBars := False;
  17812. end;
  17813. clColor := DrawViewBorder(ViewBorder);
  17814. if ((GroundPic.Graphic <> nil) and GroundHas)or
  17815. (Transparent)or
  17816. (Assigned(OnCustomDraw)) then
  17817. Color := clNone
  17818. else
  17819. Color := clColor;
  17820. end;
  17821. procedure TDefineListView.SetParentColor(Value: Boolean);
  17822. begin
  17823. if Value <> FParentColor then
  17824. begin
  17825. FParentColor := Value;
  17826. if (FParentColor)and(Parent <> nil) then
  17827. FFlatColor := TForm(Parent).Color;
  17828. RedrawBorder;
  17829. end;
  17830. end;
  17831. procedure TDefineListView.CMSysColorChange(var Message: TMessage);
  17832. begin
  17833. if (FParentColor)and(Parent <> nil) then
  17834. FFlatColor := TForm(Parent).Color;
  17835. RedrawBorder;
  17836. end;
  17837. procedure TDefineListView.CMParentColorChanged(var Message: TWMNoParams);
  17838. begin
  17839. if (FParentColor)and(Parent <> nil) then
  17840. FFlatColor := TForm(Parent).Color;
  17841. RedrawBorder;
  17842. end;
  17843. procedure TDefineListView.SetColors(Index: Integer; Value: TColor);
  17844. begin
  17845. case Index of
  17846. 0: FFocusedColor := Value;
  17847. 1: FBorderColor := Value;
  17848. 2: begin
  17849. FFlatColor := Value;
  17850. FParentColor := False;
  17851. end;
  17852. 3: if FTitleFaceColor <> Value then
  17853. begin
  17854. FTitleFaceColor := Value;
  17855. RedrawWindow(FHeaderHandle, nil, 0, RDW_INVALIDATE);
  17856. end;
  17857. 4: if FTitleCheckColor <> Value then
  17858. begin
  17859. FTitleCheckColor := Value;
  17860. RedrawWindow(FHeaderHandle, nil, 0, RDW_INVALIDATE);
  17861. end;
  17862. end;
  17863. RedrawBorder;
  17864. end;
  17865. procedure TDefineListView.CMMouseEnter(var Message: TMessage);
  17866. begin
  17867. inherited;
  17868. if (GetActiveWindow <> 0) then
  17869. begin
  17870. FMouseIn := True;
  17871. RedrawBorder;
  17872. end;
  17873. end;
  17874. procedure TDefineListView.CMMouseLeave(var Message: TMessage);
  17875. begin
  17876. inherited;
  17877. FMouseIn := False;
  17878. RedrawBorder;
  17879. end;
  17880. procedure TDefineListView.CMEnabledChanged(var Message: TMessage);
  17881. begin
  17882. inherited;
  17883. RedrawBorder;
  17884. end;
  17885. procedure TDefineListView.WMSetFocus(var Message: TWMSetFocus);
  17886. begin
  17887. inherited;
  17888. if not(csDesigning in ComponentState) then
  17889. RedrawBorder;
  17890. end;
  17891. procedure TDefineListView.WMKillFocus(var Message: TWMKillFocus);
  17892. begin
  17893. inherited;
  17894. if not(csDesigning in ComponentState) then
  17895. RedrawBorder;
  17896. end;
  17897. procedure TDefineListView.WMNCCalcSize(var Message: TWMNCCalcSize);
  17898. begin
  17899. inherited;
  17900. InflateRect(Message.CalcSize_Params^.rgrc[0], -1, -1);
  17901. end;
  17902. procedure TDefineListView.WMNCPaint(var Message: TMessage);
  17903. begin
  17904. inherited;
  17905. RedrawBorder(HRGN(Message.WParam));
  17906. end;
  17907. function TDefineListView.GetColumnCount: Integer;
  17908. begin
  17909. result := inherited Columns.Count;
  17910. end;
  17911. function TDefineListView.GetItemsCount: Integer;
  17912. begin
  17913. result := inherited Items.Count;
  17914. end;
  17915. procedure TDefineListView.SetGroundPic(const Value: TPicture);
  17916. begin
  17917. FGroundPic.Assign(Value);
  17918. if FGroundPic.Graphic = nil then
  17919. FGroundHas := false;
  17920. RedrawBorder;
  17921. Invalidate;
  17922. end;
  17923. procedure TDefineListView.DrawBackground(Sender: TCustomListView; const ARect: TRect; var DefaultDraw: Boolean);
  17924. var
  17925. x,y:integer;
  17926. R:TRect;
  17927. begin
  17928. if GroundPic.Graphic <> nil then
  17929. begin
  17930. with Canvas, ClientRect do
  17931. begin
  17932. Lock;
  17933. R := Rect(Left, Top + HeaderHeight, Right, Bottom);
  17934. if not GroundStretch then
  17935. begin
  17936. x:=0; y:=HeaderHeight;
  17937. while x < Width do
  17938. begin
  17939. while y < Height do
  17940. begin
  17941. Draw(x, y, GroundPic.Graphic);
  17942. y := y + GroundPic.Height;
  17943. end;
  17944. x := x + GroundPic.Width;
  17945. y := HeaderHeight;
  17946. end;
  17947. end else begin
  17948. StretchDraw(R, GroundPic.Graphic);
  17949. end;
  17950. SetBkMode(Handle, bkModeTRANSPARENT);
  17951. Unlock;
  17952. end;
  17953. Perform(LVM_SETTEXTBKCOLOR, 0, LongInt(CLR_NONE));
  17954. ListView_SetBKColor(Handle, CLR_NONE);
  17955. end;
  17956. end;
  17957. procedure TDefineListView.SetGroundHas(const Value: Boolean);
  17958. begin
  17959. FGroundHas := Value;
  17960. if FGroundHas and (FGroundPic.Graphic <> nil) then begin
  17961. FTransparent := false;
  17962. OnCustomDraw := DrawBackground;
  17963. end else if not(csDesigning in ComponentState) then
  17964. OnCustomDraw := FOnDrawBackground
  17965. else begin
  17966. OnCustomDraw := Nil;
  17967. end;
  17968. RedrawBorder;
  17969. Invalidate;
  17970. end;
  17971. procedure TDefineListView.Loaded;
  17972. begin
  17973. inherited;
  17974. if (GroundHas)and(GroundPic.Graphic <> nil) then
  17975. OnCustomDraw := DrawBackground
  17976. else if Transparent then
  17977. OnCustomDraw := DrawTransparent
  17978. else
  17979. OnCustomDraw := OnDrawBackground;
  17980. end;
  17981. function TDefineListView.GetHeaderHeight: Integer;
  17982. begin
  17983. result := RectHeight(GetHeaderSectionRect(0));
  17984. if not (ShowColumnHeaders and (ViewStyle = vsReport)) then
  17985. result := 0;
  17986. end;
  17987. procedure TDefineListView.SetGroundStretch(const Value: Boolean);
  17988. begin
  17989. if FGroundStretch <> value then
  17990. begin
  17991. FGroundStretch := Value;
  17992. RedrawBorder;
  17993. Invalidate;
  17994. end;
  17995. end;
  17996. procedure TDefineListView.WMPaint(var Message: TWMPaint);
  17997. begin
  17998. inherited;
  17999. RedrawWindow(FHeaderHandle, nil, 0, RDW_INVALIDATE);
  18000. end;
  18001. procedure TDefineListView.SetAllCheck(const Value: Boolean);
  18002. var
  18003. inx : integer;
  18004. begin
  18005. if FAllCheck <> Value then
  18006. begin
  18007. FAllCheck := Value;
  18008. for inx:=0 to Items.Count - 1 do
  18009. Items.Item[inx].Checked := FAllCheck;
  18010. end;
  18011. end;
  18012. function TDefineListView.GetListCount: integer;
  18013. begin
  18014. result := Items.Count;
  18015. end;
  18016. function TDefineListView.GetCheckCount: integer;
  18017. var inx:integer;
  18018. begin
  18019. result := 0;
  18020. for inx := 0 to Items.Count - 1 do
  18021. begin
  18022. if Items.Item[inx].Checked then
  18023. result := result + 1;
  18024. end;
  18025. end;
  18026. procedure TDefineListView.SetTransparent(const Value: Boolean);
  18027. begin
  18028. FTransparent := Value;
  18029. if FTransparent then begin
  18030. FGroundHas := False;
  18031. OnCustomDraw := DrawTransparent;
  18032. end else if not(csDesigning in ComponentState) then
  18033. OnCustomDraw := FOnDrawBackground
  18034. else begin
  18035. OnCustomDraw := Nil;
  18036. end;
  18037. RedrawBorder;
  18038. Invalidate;
  18039. end;
  18040. procedure TDefineListView.DrawTransparent(Sender: TCustomListView; const ARect: TRect; var DefaultDraw: Boolean);
  18041. begin
  18042. FTransBit.Height := ClientRect.Bottom;
  18043. FTransBit.Width := ClientRect.Right;
  18044. DrawParentImage(Self, FTransBit.Canvas);
  18045. with Canvas do
  18046. begin
  18047. Lock;
  18048. Draw(0, 0, FTransBit);
  18049. SetBkMode(Handle, bkModeTRANSPARENT);
  18050. Unlock;
  18051. end;
  18052. Perform(LVM_SETTEXTBKCOLOR, 0, LongInt(CLR_NONE));
  18053. ListView_SetBKColor(Handle, CLR_NONE);
  18054. end;
  18055. procedure TDefineListView.CMDesignHitTest(var Message: TCMDesignHitTest);
  18056. begin
  18057. inherited;
  18058. case Message.Msg of
  18059. WM_SIZE,WM_PARENTNOTIFY:
  18060. begin
  18061. RedrawBorder;
  18062. Invalidate;
  18063. end;
  18064. end;
  18065. end;
  18066. { TDefineGridDraw }
  18067. function TDefineGridDraw.GetMouseIn: boolean;
  18068. begin
  18069. result := FMouseIn;
  18070. end;
  18071. constructor TDefineGridDraw.Create(AOwner: TComponent);
  18072. begin
  18073. inherited Create(AOwner);
  18074. BorderStyle := bsNone;
  18075. FFocusColor := clWhite;
  18076. FBorderColor := DefaultBorderColor;
  18077. FLinesColor := DefaultBorderColor;
  18078. FFlatColor := DefaultFlatColor;
  18079. FParentColor := True;
  18080. FMouseIn := False;
  18081. end;
  18082. procedure TDefineGridDraw.RedrawBorder(const Clip: HRGN);
  18083. var
  18084. Attrib:TBorderAttrib;
  18085. begin
  18086. with Attrib do
  18087. begin
  18088. Ctrl := self;
  18089. FocusColor := ColorFocused;
  18090. BorderColor := ColorBorder;
  18091. FlatColor := ColorFlat;
  18092. FocusState := Focused;
  18093. MouseState := FMouseIn;
  18094. DesignState := ComponentState;
  18095. HasBars := ScrollBars = ssBoth;
  18096. BoldState := True;
  18097. end;
  18098. Color := DrawEditBorder(Attrib,Clip);
  18099. end;
  18100. procedure TDefineGridDraw.SetParentColor(Value: Boolean);
  18101. begin
  18102. if Value <> FParentColor then
  18103. begin
  18104. FParentColor := Value;
  18105. if FParentColor then
  18106. begin
  18107. if Parent <> nil then
  18108. FFlatColor := TForm(Parent).Color;
  18109. RedrawBorder;
  18110. end;
  18111. end;
  18112. end;
  18113. procedure TDefineGridDraw.CMSysColorChange(var Message: TMessage);
  18114. begin
  18115. if (Parent <> nil)and(FParentColor) then
  18116. FFlatColor := TForm(Parent).Color;
  18117. RedrawBorder;
  18118. end;
  18119. procedure TDefineGridDraw.CMParentColorChanged(var Message: TWMNoParams);
  18120. begin
  18121. if (Parent <> nil)and(FParentColor) then
  18122. FFlatColor := TForm(Parent).Color;
  18123. RedrawBorder;
  18124. end;
  18125. procedure TDefineGridDraw.SetColors(Index: Integer; Value: TColor);
  18126. begin
  18127. case Index of
  18128. 0: FFocusColor := Value;
  18129. 1: FBorderColor := Value;
  18130. 2: begin
  18131. FFlatColor := Value;
  18132. FParentColor := False;
  18133. end;
  18134. 3: FLinesColor := Value;
  18135. end;
  18136. Repaint;
  18137. RedrawBorder;
  18138. end;
  18139. procedure TDefineGridDraw.CMMouseEnter(var Message: TMessage);
  18140. begin
  18141. inherited;
  18142. if (GetActiveWindow <> 0) then
  18143. begin
  18144. FMouseIn := True;
  18145. RedrawBorder;
  18146. end;
  18147. end;
  18148. procedure TDefineGridDraw.CMMouseLeave(var Message: TMessage);
  18149. begin
  18150. inherited;
  18151. FMouseIn := False;
  18152. RedrawBorder;
  18153. end;
  18154. procedure TDefineGridDraw.CMEnabledChanged(var Message: TMessage);
  18155. const
  18156. EnableColors: array[Boolean] of TColor = (clBtnFace, clWindow);
  18157. begin
  18158. inherited;
  18159. Color := EnableColors[Enabled];
  18160. RedrawBorder;
  18161. end;
  18162. procedure TDefineGridDraw.WMSetFocus(var Message: TWMSetFocus);
  18163. begin
  18164. inherited;
  18165. if not(csDesigning in ComponentState) then
  18166. RedrawBorder;
  18167. end;
  18168. procedure TDefineGridDraw.WMKillFocus(var Message: TWMKillFocus);
  18169. begin
  18170. inherited;
  18171. if not(csDesigning in ComponentState) then
  18172. RedrawBorder;
  18173. end;
  18174. procedure TDefineGridDraw.WMNCCalcSize(var Message: TWMNCCalcSize);
  18175. begin
  18176. inherited;
  18177. InflateRect(Message.CalcSize_Params^.rgrc[0], -3, -3);
  18178. end;
  18179. procedure TDefineGridDraw.WMNCPaint(var Message: TMessage);
  18180. begin
  18181. inherited;
  18182. RedrawBorder(HRGN(Message.WParam));
  18183. end;
  18184. procedure TDefineGridDraw.DrawCell(ACol, ARow: Integer; ARect: TRect;
  18185. AState: TGridDrawState);
  18186. var FRect:TRect;
  18187. begin
  18188. inherited;
  18189. {//绘制数据区的表格边框
  18190. with ARect, Canvas do
  18191. begin
  18192. if (ACol = 0)or(ARow = 0) then
  18193. begin
  18194. if ARow > 0 then begin
  18195. FRect := Rect(Left-1,Top-1,Right,Bottom+2);
  18196. DrawFrame(Canvas, FRect, FLinesColor, FLinesColor, 1)
  18197. end else if ACol > 0 then begin
  18198. FRect := Rect(Left-2,Top,Right+1,Bottom+1);
  18199. DrawFrame(Canvas, FRect, FLinesColor, FLinesColor, 1)
  18200. end else begin
  18201. FRect := Rect(Left,Top,Right+1,Bottom+1);
  18202. DrawButtonBorder(Canvas,FRect,FLinesColor,1)
  18203. end;
  18204. end else begin
  18205. //FRect := Rect(Left-1,Top-1,Right+1,Bottom+1);
  18206. //DrawButtonBorder(Canvas,FRect,FLinesColor,1);
  18207. InflateRect(FRect, -1, -1);
  18208. FRect := Rect(Left-2,Top-2,Right+2,Bottom+2);
  18209. //选择线型颜色。。。
  18210. Brush.Color:=FLinesColor;
  18211. //对表格进行绘制
  18212. InflateRect(FRect, -1, -1);
  18213. FrameRect(FRect);
  18214. end;
  18215. end; }
  18216. //绘制数据区的表格边框
  18217. with ARect, Canvas do
  18218. begin
  18219. FRect := Rect(Left-2,Top-2,Right+2,Bottom+2);
  18220. //选择线型颜色。。。
  18221. Brush.Color:=FLinesColor;
  18222. //对表格进行绘制
  18223. InflateRect(FRect, -1, -1);
  18224. FrameRect(FRect);
  18225. end;
  18226. end;
  18227. { TDefineGridString}
  18228. { StrItem management for TStringSparseList }
  18229. type
  18230. PStrItem = ^TStrItem;
  18231. TStrItem = record
  18232. FObject: TObject;
  18233. FString: string;
  18234. end;
  18235. function NewStrItem(const AString: string; AObject: TObject): PStrItem;
  18236. begin
  18237. New(Result);
  18238. Result^.FObject := AObject;
  18239. Result^.FString := AString;
  18240. end;
  18241. procedure DisposeStrItem(P: PStrItem);
  18242. begin
  18243. Dispose(P);
  18244. end;
  18245. type
  18246. { TDefineGridSparseArray class}
  18247. { Used by TSparseList. Based on Sparse1Array, but has Pointer elements
  18248. and Integer index, just like TPointerList/TList, and less indirection }
  18249. { Apply function for the applicator:
  18250. TheIndex Index of item in array
  18251. TheItem Value of item (i.e pointer element) in section
  18252. Returns: 0 if success, else error code. }
  18253. TSPAApply = function(TheIndex: Integer; TheItem: Pointer): Integer;
  18254. TSecDir = array[0..4095] of Pointer; { Enough for up to 12 bits of sec }
  18255. PSecDir = ^TSecDir;
  18256. TSPAQuantum = (SPASmall, SPALarge); { Section size }
  18257. TDefineGridSparseArray = class(TObject)
  18258. private
  18259. secDir: PSecDir;
  18260. slotsInDir: Word;
  18261. indexMask, secShift: Word;
  18262. FHighBound: Integer;
  18263. FSectionSize: Word;
  18264. cachedIndex: Integer;
  18265. cachedPointer: Pointer;
  18266. { Return item[i], nil if slot outside defined section. }
  18267. function GetAt(Index: Integer): Pointer;
  18268. { Return address of item[i], creating slot if necessary. }
  18269. function MakeAt(Index: Integer): PPointer;
  18270. { Store item at item[i], creating slot if necessary. }
  18271. procedure PutAt(Index: Integer; Item: Pointer);
  18272. public
  18273. constructor Create(Quantum: TSPAQuantum);
  18274. destructor Destroy; override;
  18275. { Traverse SPA, calling apply function for each defined non-nil
  18276. item. The traversal terminates if the apply function returns
  18277. a value other than 0. }
  18278. { NOTE: must be static method so that we can take its address in
  18279. TSparseList.ForAll }
  18280. function ForAll(ApplyFunction: Pointer {TSPAApply}): Integer;
  18281. { Ratchet down HighBound after a deletion }
  18282. procedure ResetHighBound;
  18283. property HighBound: Integer read FHighBound;
  18284. property SectionSize: Word read FSectionSize;
  18285. property Items[Index: Integer]: Pointer read GetAt write PutAt; default;
  18286. end;
  18287. { TDefineGridSparseList class }
  18288. TDefineGridSparseList = class(TObject)
  18289. private
  18290. FList: TDefineGridSparseArray;
  18291. FCount: Integer; { 1 + HighBound, adjusted for Insert/Delete }
  18292. FQuantum: TSPAQuantum;
  18293. procedure NewList(Quantum: TSPAQuantum);
  18294. protected
  18295. function Get(Index: Integer): Pointer;
  18296. procedure Put(Index: Integer; Item: Pointer);
  18297. public
  18298. constructor Create(Quantum: TSPAQuantum);
  18299. destructor Destroy; override;
  18300. procedure Clear;
  18301. procedure Delete(Index: Integer);
  18302. procedure Exchange(Index1, Index2: Integer);
  18303. function ForAll(ApplyFunction: Pointer {TSPAApply}): Integer;
  18304. procedure Insert(Index: Integer; Item: Pointer);
  18305. procedure Move(CurIndex, NewIndex: Integer);
  18306. property Count: Integer read FCount;
  18307. property Items[Index: Integer]: Pointer read Get write Put; default;
  18308. end;
  18309. { TDefineGridSparseLists class }
  18310. TDefineGridSparseLists = class(TStrings)
  18311. private
  18312. FList: TDefineGridSparseList; { of StrItems }
  18313. FOnChange: TNotifyEvent;
  18314. protected
  18315. function Get(Index: Integer): String; override;
  18316. function GetCount: Integer; override;
  18317. function GetObject(Index: Integer): TObject; override;
  18318. procedure Put(Index: Integer; const S: String); override;
  18319. procedure PutObject(Index: Integer; AObject: TObject); override;
  18320. procedure Changed;
  18321. public
  18322. constructor Create(Quantum: TSPAQuantum);
  18323. destructor Destroy; override;
  18324. procedure ReadData(Reader: TReader);
  18325. procedure WriteData(Writer: TWriter);
  18326. procedure DefineProperties(Filer: TFiler); override;
  18327. procedure Delete(Index: Integer); override;
  18328. procedure Exchange(Index1, Index2: Integer); override;
  18329. procedure Insert(Index: Integer; const S: String); override;
  18330. procedure Clear; override;
  18331. property List: TDefineGridSparseList read FList;
  18332. property OnChange: TNotifyEvent read FOnChange write FOnChange;
  18333. end;
  18334. { TDefineGridSparseArray }
  18335. const
  18336. SPAIndexMask: array[TSPAQuantum] of Byte = (15, 255);
  18337. SPASecShift: array[TSPAQuantum] of Byte = (4, 8);
  18338. { Expand Section Directory to cover at least `newSlots' slots. Returns: Possibly
  18339. updated pointer to the Section Directory. }
  18340. function ExpandDir(secDir: PSecDir; var slotsInDir: Word;
  18341. newSlots: Word): PSecDir;
  18342. begin
  18343. Result := secDir;
  18344. ReallocMem(Result, newSlots * SizeOf(Pointer));
  18345. FillChar(Result^[slotsInDir], (newSlots - slotsInDir) * SizeOf(Pointer), 0);
  18346. slotsInDir := newSlots;
  18347. end;
  18348. { Allocate a section and set all its items to nil. Returns: Pointer to start of
  18349. section. }
  18350. function MakeSec(SecIndex: Integer; SectionSize: Word): Pointer;
  18351. var
  18352. SecP: Pointer;
  18353. Size: Word;
  18354. begin
  18355. Size := SectionSize * SizeOf(Pointer);
  18356. GetMem(secP, size);
  18357. FillChar(secP^, size, 0);
  18358. MakeSec := SecP
  18359. end;
  18360. constructor TDefineGridSparseArray.Create(Quantum: TSPAQuantum);
  18361. begin
  18362. SecDir := nil;
  18363. SlotsInDir := 0;
  18364. FHighBound := -1;
  18365. FSectionSize := Word(SPAIndexMask[Quantum]) + 1;
  18366. IndexMask := Word(SPAIndexMask[Quantum]);
  18367. SecShift := Word(SPASecShift[Quantum]);
  18368. CachedIndex := -1;
  18369. end;
  18370. destructor TDefineGridSparseArray.Destroy;
  18371. var
  18372. i: Integer;
  18373. size: Word;
  18374. begin
  18375. { Scan section directory and free each section that exists. }
  18376. i := 0;
  18377. size := FSectionSize * SizeOf(Pointer);
  18378. while i < slotsInDir do begin
  18379. if secDir^[i] <> nil then
  18380. FreeMem(secDir^[i], size);
  18381. Inc(i)
  18382. end;
  18383. { Free section directory. }
  18384. if secDir <> nil then
  18385. FreeMem(secDir, slotsInDir * SizeOf(Pointer));
  18386. end;
  18387. function TDefineGridSparseArray.GetAt(Index: Integer): Pointer;
  18388. var
  18389. byteP: PChar;
  18390. secIndex: Cardinal;
  18391. begin
  18392. { Index into Section Directory using high order part of
  18393. index. Get pointer to Section. If not null, index into
  18394. Section using low order part of index. }
  18395. if Index = cachedIndex then
  18396. Result := cachedPointer
  18397. else begin
  18398. secIndex := Index shr secShift;
  18399. if secIndex >= slotsInDir then
  18400. byteP := nil
  18401. else begin
  18402. byteP := secDir^[secIndex];
  18403. if byteP <> nil then begin
  18404. Inc(byteP, (Index and indexMask) * SizeOf(Pointer));
  18405. end
  18406. end;
  18407. if byteP = nil then Result := nil else Result := PPointer(byteP)^;
  18408. cachedIndex := Index;
  18409. cachedPointer := Result;
  18410. end
  18411. end;
  18412. function TDefineGridSparseArray.MakeAt(Index: Integer): PPointer;
  18413. var
  18414. dirP: PSecDir;
  18415. p: Pointer;
  18416. byteP: PChar;
  18417. secIndex: Word;
  18418. begin
  18419. { Expand Section Directory if necessary. }
  18420. secIndex := Index shr secShift; { Unsigned shift }
  18421. if secIndex >= slotsInDir then
  18422. dirP := expandDir(secDir, slotsInDir, secIndex + 1)
  18423. else
  18424. dirP := secDir;
  18425. { Index into Section Directory using high order part of
  18426. index. Get pointer to Section. If null, create new
  18427. Section. Index into Section using low order part of index. }
  18428. secDir := dirP;
  18429. p := dirP^[secIndex];
  18430. if p = nil then begin
  18431. p := makeSec(secIndex, FSectionSize);
  18432. dirP^[secIndex] := p
  18433. end;
  18434. byteP := p;
  18435. Inc(byteP, (Index and indexMask) * SizeOf(Pointer));
  18436. if Index > FHighBound then
  18437. FHighBound := Index;
  18438. Result := PPointer(byteP);
  18439. cachedIndex := -1
  18440. end;
  18441. procedure TDefineGridSparseArray.PutAt(Index: Integer; Item: Pointer);
  18442. begin
  18443. if (Item <> nil) or (GetAt(Index) <> nil) then
  18444. begin
  18445. MakeAt(Index)^ := Item;
  18446. if Item = nil then
  18447. ResetHighBound
  18448. end
  18449. end;
  18450. function TDefineGridSparseArray.ForAll(ApplyFunction: Pointer {TSPAApply}):
  18451. Integer;
  18452. var
  18453. itemP: PChar; { Pointer to item in section }
  18454. item: Pointer;
  18455. i, callerBP: Cardinal;
  18456. j, index: Integer;
  18457. begin
  18458. { Scan section directory and scan each section that exists,
  18459. calling the apply function for each non-nil item.
  18460. The apply function must be a far local function in the scope of
  18461. the procedure P calling ForAll. The trick of setting up the stack
  18462. frame (taken from TurboVision's TCollection.ForEach) allows the
  18463. apply function access to P's arguments and local variables and,
  18464. if P is a method, the instance variables and methods of P's class }
  18465. Result := 0;
  18466. i := 0;
  18467. asm
  18468. mov eax,[ebp] { Set up stack frame for local }
  18469. mov callerBP,eax
  18470. end;
  18471. while (i < slotsInDir) and (Result = 0) do begin
  18472. itemP := secDir^[i];
  18473. if itemP <> nil then begin
  18474. j := 0;
  18475. index := i shl SecShift;
  18476. while (j < FSectionSize) and (Result = 0) do begin
  18477. item := PPointer(itemP)^;
  18478. if item <> nil then
  18479. { ret := ApplyFunction(index, item.Ptr); }
  18480. asm
  18481. mov eax,index
  18482. mov edx,item
  18483. push callerBP
  18484. call ApplyFunction
  18485. pop ecx
  18486. mov @Result,eax
  18487. end;
  18488. Inc(itemP, SizeOf(Pointer));
  18489. Inc(j);
  18490. Inc(index)
  18491. end
  18492. end;
  18493. Inc(i)
  18494. end;
  18495. end;
  18496. procedure TDefineGridSparseArray.ResetHighBound;
  18497. var
  18498. NewHighBound: Integer;
  18499. function Detector(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18500. begin
  18501. if TheIndex > FHighBound then
  18502. Result := 1
  18503. else
  18504. begin
  18505. Result := 0;
  18506. if TheItem <> nil then NewHighBound := TheIndex
  18507. end
  18508. end;
  18509. begin
  18510. NewHighBound := -1;
  18511. ForAll(@Detector);
  18512. FHighBound := NewHighBound
  18513. end;
  18514. { TDefineGridSparseList }
  18515. constructor TDefineGridSparseList.Create(Quantum: TSPAQuantum);
  18516. begin
  18517. NewList(Quantum)
  18518. end;
  18519. destructor TDefineGridSparseList.Destroy;
  18520. begin
  18521. if FList <> nil then FList.Destroy
  18522. end;
  18523. procedure TDefineGridSparseList.Clear;
  18524. begin
  18525. FList.Destroy;
  18526. NewList(FQuantum);
  18527. FCount := 0
  18528. end;
  18529. procedure TDefineGridSparseList.Delete(Index: Integer);
  18530. var
  18531. I: Integer;
  18532. begin
  18533. if (Index < 0) or (Index >= FCount) then Exit;
  18534. for I := Index to FCount - 1 do
  18535. FList[I] := FList[I + 1];
  18536. FList[FCount] := nil;
  18537. Dec(FCount);
  18538. end;
  18539. procedure TDefineGridSparseList.Exchange(Index1, Index2: Integer);
  18540. var
  18541. temp: Pointer;
  18542. begin
  18543. temp := Get(Index1);
  18544. Put(Index1, Get(Index2));
  18545. Put(Index2, temp);
  18546. end;
  18547. { Jump to TDefineGridSparseArray.ForAll so that it looks like it was called
  18548. from our caller, so that the BP trick works. }
  18549. function TDefineGridSparseList.ForAll(ApplyFunction: Pointer {TSPAApply}): Integer; assembler;
  18550. asm
  18551. MOV EAX,[EAX].TDefineGridSparseList.FList
  18552. JMP TDefineGridSparseArray.ForAll
  18553. end;
  18554. function TDefineGridSparseList.Get(Index: Integer): Pointer;
  18555. begin
  18556. if Index < 0 then TList.Error(SListIndexError, Index);
  18557. Result := FList[Index]
  18558. end;
  18559. procedure TDefineGridSparseList.Insert(Index: Integer; Item: Pointer);
  18560. var
  18561. i: Integer;
  18562. begin
  18563. if Index < 0 then TList.Error(SListIndexError, Index);
  18564. I := FCount;
  18565. while I > Index do
  18566. begin
  18567. FList[i] := FList[i - 1];
  18568. Dec(i)
  18569. end;
  18570. FList[Index] := Item;
  18571. if Index > FCount then FCount := Index;
  18572. Inc(FCount)
  18573. end;
  18574. procedure TDefineGridSparseList.Move(CurIndex, NewIndex: Integer);
  18575. var
  18576. Item: Pointer;
  18577. begin
  18578. if CurIndex <> NewIndex then
  18579. begin
  18580. Item := Get(CurIndex);
  18581. Delete(CurIndex);
  18582. Insert(NewIndex, Item);
  18583. end;
  18584. end;
  18585. procedure TDefineGridSparseList.NewList(Quantum: TSPAQuantum);
  18586. begin
  18587. FQuantum := Quantum;
  18588. FList := TDefineGridSparseArray.Create(Quantum)
  18589. end;
  18590. procedure TDefineGridSparseList.Put(Index: Integer; Item: Pointer);
  18591. begin
  18592. if Index < 0 then TList.Error(SListIndexError, Index);
  18593. FList[Index] := Item;
  18594. FCount := FList.HighBound + 1
  18595. end;
  18596. { TDefineGridSparseLists }
  18597. constructor TDefineGridSparseLists.Create(Quantum: TSPAQuantum);
  18598. begin
  18599. inherited Create;
  18600. FList := TDefineGridSparseList.Create(Quantum)
  18601. end;
  18602. destructor TDefineGridSparseLists.Destroy;
  18603. begin
  18604. if FList <> nil then begin
  18605. Clear;
  18606. FList.Destroy
  18607. end
  18608. end;
  18609. procedure TDefineGridSparseLists.ReadData(Reader: TReader);
  18610. var
  18611. i: Integer;
  18612. begin
  18613. with Reader do begin
  18614. i := Integer(ReadInteger);
  18615. while i > 0 do begin
  18616. InsertObject(Integer(ReadInteger), ReadString, nil);
  18617. Dec(i)
  18618. end
  18619. end
  18620. end;
  18621. procedure TDefineGridSparseLists.WriteData(Writer: TWriter);
  18622. var
  18623. itemCount: Integer;
  18624. function CountItem(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18625. begin
  18626. Inc(itemCount);
  18627. Result := 0
  18628. end;
  18629. function StoreItem(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18630. begin
  18631. with Writer do
  18632. begin
  18633. WriteInteger(TheIndex); { Item index }
  18634. WriteString(PStrItem(TheItem)^.FString);
  18635. end;
  18636. Result := 0
  18637. end;
  18638. begin
  18639. with Writer do
  18640. begin
  18641. itemCount := 0;
  18642. FList.ForAll(@CountItem);
  18643. WriteInteger(itemCount);
  18644. FList.ForAll(@StoreItem);
  18645. end
  18646. end;
  18647. procedure TDefineGridSparseLists.DefineProperties(Filer: TFiler);
  18648. begin
  18649. Filer.DefineProperty('List', ReadData, WriteData, True);
  18650. end;
  18651. function TDefineGridSparseLists.Get(Index: Integer): String;
  18652. var
  18653. p: PStrItem;
  18654. begin
  18655. p := PStrItem(FList[Index]);
  18656. if p = nil then Result := '' else Result := p^.FString
  18657. end;
  18658. function TDefineGridSparseLists.GetCount: Integer;
  18659. begin
  18660. Result := FList.Count
  18661. end;
  18662. function TDefineGridSparseLists.GetObject(Index: Integer): TObject;
  18663. var
  18664. p: PStrItem;
  18665. begin
  18666. p := PStrItem(FList[Index]);
  18667. if p = nil then Result := nil else Result := p^.FObject
  18668. end;
  18669. procedure TDefineGridSparseLists.Put(Index: Integer; const S: String);
  18670. var
  18671. p: PStrItem;
  18672. obj: TObject;
  18673. begin
  18674. p := PStrItem(FList[Index]);
  18675. if p = nil then obj := nil else obj := p^.FObject;
  18676. if (S = '') and (obj = nil) then { Nothing left to store }
  18677. FList[Index] := nil
  18678. else
  18679. FList[Index] := NewStrItem(S, obj);
  18680. if p <> nil then DisposeStrItem(p);
  18681. Changed
  18682. end;
  18683. procedure TDefineGridSparseLists.PutObject(Index: Integer; AObject: TObject);
  18684. var
  18685. p: PStrItem;
  18686. begin
  18687. p := PStrItem(FList[Index]);
  18688. if p <> nil then
  18689. p^.FObject := AObject
  18690. else if AObject <> nil then
  18691. FList[Index] := NewStrItem('',AObject);
  18692. Changed
  18693. end;
  18694. procedure TDefineGridSparseLists.Changed;
  18695. begin
  18696. if Assigned(FOnChange) then FOnChange(Self)
  18697. end;
  18698. procedure TDefineGridSparseLists.Delete(Index: Integer);
  18699. var
  18700. p: PStrItem;
  18701. begin
  18702. p := PStrItem(FList[Index]);
  18703. if p <> nil then DisposeStrItem(p);
  18704. FList.Delete(Index);
  18705. Changed
  18706. end;
  18707. procedure TDefineGridSparseLists.Exchange(Index1, Index2: Integer);
  18708. begin
  18709. FList.Exchange(Index1, Index2);
  18710. end;
  18711. procedure TDefineGridSparseLists.Insert(Index: Integer; const S: String);
  18712. begin
  18713. FList.Insert(Index, NewStrItem(S, nil));
  18714. Changed
  18715. end;
  18716. procedure TDefineGridSparseLists.Clear;
  18717. function ClearItem(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18718. begin
  18719. DisposeStrItem(PStrItem(TheItem)); { Item guaranteed non-nil }
  18720. Result := 0
  18721. end;
  18722. begin
  18723. FList.ForAll(@ClearItem);
  18724. FList.Clear;
  18725. Changed
  18726. end;
  18727. { TDefineGridStrings }
  18728. { AIndex < 0 is a column (for column -AIndex - 1)
  18729. AIndex > 0 is a row (for row AIndex - 1)
  18730. AIndex = 0 denotes an empty row or column }
  18731. constructor TDefineGridStrings.Create(AGrid: TDefineGridString; AIndex: Longint);
  18732. begin
  18733. inherited Create;
  18734. FGrid := AGrid;
  18735. FIndex := AIndex;
  18736. end;
  18737. procedure TDefineGridStrings.Assign(Source: TPersistent);
  18738. var
  18739. I, Max: Integer;
  18740. begin
  18741. if Source is TStrings then
  18742. begin
  18743. BeginUpdate;
  18744. Max := TStrings(Source).Count - 1;
  18745. if Max >= Count then Max := Count - 1;
  18746. try
  18747. for I := 0 to Max do
  18748. begin
  18749. Put(I, TStrings(Source).Strings[I]);
  18750. PutObject(I, TStrings(Source).Objects[I]);
  18751. end;
  18752. finally
  18753. EndUpdate;
  18754. end;
  18755. Exit;
  18756. end;
  18757. inherited Assign(Source);
  18758. end;
  18759. procedure TDefineGridStrings.CalcXY(Index: Integer; var X, Y: Integer);
  18760. begin
  18761. if FIndex = 0 then
  18762. begin
  18763. X := -1; Y := -1;
  18764. end else if FIndex > 0 then
  18765. begin
  18766. X := Index;
  18767. Y := FIndex - 1;
  18768. end else
  18769. begin
  18770. X := -FIndex - 1;
  18771. Y := Index;
  18772. end;
  18773. end;
  18774. { Changes the meaning of Add to mean copy to the first empty string }
  18775. function TDefineGridStrings.Add(const S: string): Integer;
  18776. var
  18777. I: Integer;
  18778. begin
  18779. for I := 0 to Count - 1 do
  18780. if Strings[I] = '' then
  18781. begin
  18782. if S = '' then
  18783. Strings[I] := ' '
  18784. else
  18785. Strings[I] := S;
  18786. Result := I;
  18787. Exit;
  18788. end;
  18789. Result := -1;
  18790. end;
  18791. procedure TDefineGridStrings.Clear;
  18792. var
  18793. SSList: TDefineGridSparseLists;
  18794. I: Integer;
  18795. function BlankStr(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18796. begin
  18797. Objects[TheIndex] := nil;
  18798. Strings[TheIndex] := '';
  18799. Result := 0;
  18800. end;
  18801. begin
  18802. if FIndex > 0 then
  18803. begin
  18804. SSList := TDefineGridSparseLists(TDefineGridSparseList(FGrid.FData)[FIndex - 1]);
  18805. if SSList <> nil then SSList.List.ForAll(@BlankStr);
  18806. end
  18807. else if FIndex < 0 then
  18808. for I := Count - 1 downto 0 do
  18809. begin
  18810. Objects[I] := nil;
  18811. Strings[I] := '';
  18812. end;
  18813. end;
  18814. procedure InvalidOp(const id: string);
  18815. begin
  18816. raise EInvalidGridOperation.Create(id);
  18817. end;
  18818. procedure TDefineGridStrings.Delete(Index: Integer);
  18819. begin
  18820. InvalidOp(sInvalidStringGridOp);
  18821. end;
  18822. function TDefineGridStrings.Get(Index: Integer): string;
  18823. var
  18824. X, Y: Integer;
  18825. begin
  18826. CalcXY(Index, X, Y);
  18827. if X < 0 then Result := '' else Result := FGrid.Cells[X, Y];
  18828. end;
  18829. function TDefineGridStrings.GetCount: Integer;
  18830. begin
  18831. { Count of a row is the column count, and vice versa }
  18832. if FIndex = 0 then Result := 0
  18833. else if FIndex > 0 then Result := Integer(FGrid.ColCount)
  18834. else Result := Integer(FGrid.RowCount);
  18835. end;
  18836. function TDefineGridStrings.GetObject(Index: Integer): TObject;
  18837. var
  18838. X, Y: Integer;
  18839. begin
  18840. CalcXY(Index, X, Y);
  18841. if X < 0 then Result := nil else Result := FGrid.Objects[X, Y];
  18842. end;
  18843. procedure TDefineGridStrings.Insert(Index: Integer; const S: string);
  18844. begin
  18845. InvalidOp(sInvalidStringGridOp);
  18846. end;
  18847. procedure TDefineGridStrings.Put(Index: Integer; const S: string);
  18848. var
  18849. X, Y: Integer;
  18850. begin
  18851. CalcXY(Index, X, Y);
  18852. FGrid.Cells[X, Y] := S;
  18853. end;
  18854. procedure TDefineGridStrings.PutObject(Index: Integer; AObject: TObject);
  18855. var
  18856. X, Y: Integer;
  18857. begin
  18858. CalcXY(Index, X, Y);
  18859. FGrid.Objects[X, Y] := AObject;
  18860. end;
  18861. procedure TDefineGridStrings.SetUpdateState(Updating: Boolean);
  18862. begin
  18863. FGrid.SetUpdateState(Updating);
  18864. end;
  18865. { TStringGrid }
  18866. constructor TDefineGridString.Create(AOwner: TComponent);
  18867. begin
  18868. inherited Create(AOwner);
  18869. Initialize;
  18870. end;
  18871. destructor TDefineGridString.Destroy;
  18872. function FreeItem(TheIndex: Integer; TheItem: Pointer): Integer; far;
  18873. begin
  18874. TObject(TheItem).Free;
  18875. Result := 0;
  18876. end;
  18877. begin
  18878. if FRows <> nil then
  18879. begin
  18880. TDefineGridSparseList(FRows).ForAll(@FreeItem);
  18881. TDefineGridSparseList(FRows).Free;
  18882. end;
  18883. if FCols <> nil then
  18884. begin
  18885. TDefineGridSparseList(FCols).ForAll(@FreeItem);
  18886. TDefineGridSparseList(FCols).Free;
  18887. end;
  18888. if FData <> nil then
  18889. begin
  18890. TDefineGridSparseList(FData).ForAll(@FreeItem);
  18891. TDefineGridSparseList(FData).Free;
  18892. end;
  18893. inherited Destroy;
  18894. end;
  18895. procedure TDefineGridString.ColumnMoved(FromIndex, ToIndex: Longint);
  18896. function MoveColData(Index: Integer; ARow: TDefineGridSparseLists): Integer; far;
  18897. begin
  18898. ARow.Move(FromIndex, ToIndex);
  18899. Result := 0;
  18900. end;
  18901. begin
  18902. TDefineGridSparseList(FData).ForAll(@MoveColData);
  18903. Invalidate;
  18904. inherited ColumnMoved(FromIndex, ToIndex);
  18905. end;
  18906. procedure TDefineGridString.RowMoved(FromIndex, ToIndex: Longint);
  18907. begin
  18908. TDefineGridSparseList(FData).Move(FromIndex, ToIndex);
  18909. Invalidate;
  18910. inherited RowMoved(FromIndex, ToIndex);
  18911. end;
  18912. function TDefineGridString.GetEditText(ACol, ARow: Longint): string;
  18913. begin
  18914. Result := Cells[ACol, ARow];
  18915. if Assigned(OnGetEditText) then OnGetEditText(Self, ACol, ARow, Result);
  18916. end;
  18917. procedure TDefineGridString.SetEditText(ACol, ARow: Longint; const Value: string);
  18918. begin
  18919. DisableEditUpdate;
  18920. try
  18921. if Value <> Cells[ACol, ARow] then Cells[ACol, ARow] := Value;
  18922. finally
  18923. EnableEditUpdate;
  18924. end;
  18925. inherited SetEditText(ACol, ARow, Value);
  18926. end;
  18927. procedure TDefineGridString.DrawCell(ACol, ARow: Longint; ARect: TRect;
  18928. AState: TGridDrawState);
  18929. begin
  18930. if DefaultDrawing then
  18931. Canvas.TextRect(ARect, ARect.Left+2, ARect.Top+2, Cells[ACol, ARow]);
  18932. inherited DrawCell(ACol, ARow, ARect, AState);
  18933. end;
  18934. procedure TDefineGridString.DisableEditUpdate;
  18935. begin
  18936. Inc(FEditUpdate);
  18937. end;
  18938. procedure TDefineGridString.EnableEditUpdate;
  18939. begin
  18940. Dec(FEditUpdate);
  18941. end;
  18942. procedure TDefineGridString.Initialize;
  18943. var
  18944. quantum: TSPAQuantum;
  18945. begin
  18946. if FCols = nil then
  18947. begin
  18948. if ColCount > 512 then quantum := SPALarge else quantum := SPASmall;
  18949. FCols := TDefineGridSparseList.Create(quantum);
  18950. end;
  18951. if RowCount > 256 then quantum := SPALarge else quantum := SPASmall;
  18952. if FRows = nil then FRows := TDefineGridSparseList.Create(quantum);
  18953. if FData = nil then FData := TDefineGridSparseList.Create(quantum);
  18954. end;
  18955. procedure TDefineGridString.SetUpdateState(Updating: Boolean);
  18956. begin
  18957. FUpdating := Updating;
  18958. if not Updating and FNeedsUpdating then
  18959. begin
  18960. InvalidateGrid;
  18961. FNeedsUpdating := False;
  18962. end;
  18963. end;
  18964. procedure TDefineGridString.Update(ACol, ARow: Integer);
  18965. begin
  18966. if not FUpdating then InvalidateCell(ACol, ARow)
  18967. else FNeedsUpdating := True;
  18968. if (ACol = Col) and (ARow = Row) and (FEditUpdate = 0) then InvalidateEditor;
  18969. end;
  18970. function TDefineGridString.EnsureColRow(Index: Integer; IsCol: Boolean): TDefineGridStrings;
  18971. var
  18972. RCIndex: Integer;
  18973. PList: ^TDefineGridSparseList;
  18974. begin
  18975. if IsCol then PList := @FCols else PList := @FRows;
  18976. Result := TDefineGridStrings(PList^[Index]);
  18977. if Result = nil then
  18978. begin
  18979. if IsCol then RCIndex := -Index - 1 else RCIndex := Index + 1;
  18980. Result := TDefineGridStrings.Create(Self, RCIndex);
  18981. PList^[Index] := Result;
  18982. end;
  18983. end;
  18984. function TDefineGridString.EnsureDataRow(ARow: Integer): Pointer;
  18985. var
  18986. quantum: TSPAQuantum;
  18987. begin
  18988. Result := TDefineGridSparseLists(TDefineGridSparseList(FData)[ARow]);
  18989. if Result = nil then
  18990. begin
  18991. if ColCount > 512 then quantum := SPALarge else quantum := SPASmall;
  18992. Result := TDefineGridSparseLists.Create(quantum);
  18993. TDefineGridSparseList(FData)[ARow] := Result;
  18994. end;
  18995. end;
  18996. function TDefineGridString.GetCells(ACol, ARow: Integer): string;
  18997. var
  18998. ssl: TDefineGridSparseLists;
  18999. begin
  19000. ssl := TDefineGridSparseLists(TDefineGridSparseList(FData)[ARow]);
  19001. if ssl = nil then Result := '' else Result := ssl[ACol];
  19002. end;
  19003. function TDefineGridString.GetCols(Index: Integer): TStrings;
  19004. begin
  19005. Result := EnsureColRow(Index, True);
  19006. end;
  19007. function TDefineGridString.GetObjects(ACol, ARow: Integer): TObject;
  19008. var
  19009. ssl: TDefineGridSparseLists;
  19010. begin
  19011. ssl := TDefineGridSparseLists(TDefineGridSparseList(FData)[ARow]);
  19012. if ssl = nil then Result := nil else Result := ssl.Objects[ACol];
  19013. end;
  19014. function TDefineGridString.GetRows(Index: Integer): TStrings;
  19015. begin
  19016. Result := EnsureColRow(Index, False);
  19017. end;
  19018. procedure TDefineGridString.SetCells(ACol, ARow: Integer; const Value: string);
  19019. begin
  19020. TDefineGridStrings(EnsureDataRow(ARow))[ACol] := Value;
  19021. EnsureColRow(ACol, True);
  19022. EnsureColRow(ARow, False);
  19023. Update(ACol, ARow);
  19024. end;
  19025. procedure TDefineGridString.SetCols(Index: Integer; Value: TStrings);
  19026. begin
  19027. EnsureColRow(Index, True).Assign(Value);
  19028. end;
  19029. procedure TDefineGridString.SetObjects(ACol, ARow: Integer; Value: TObject);
  19030. begin
  19031. TDefineGridStrings(EnsureDataRow(ARow)).Objects[ACol] := Value;
  19032. EnsureColRow(ACol, True);
  19033. EnsureColRow(ARow, False);
  19034. Update(ACol, ARow);
  19035. end;
  19036. procedure TDefineGridString.SetRows(Index: Integer; Value: TStrings);
  19037. begin
  19038. EnsureColRow(Index, False).Assign(Value);
  19039. end;
  19040. const
  19041. DefaultTabWidth = 100;
  19042. function Max (Value1, Value2 : Integer) : Integer;
  19043. begin
  19044. If Value1 > Value2 then Result := Value1 else Result := Value2;
  19045. end;
  19046. function Min (Value1, Value2 : Integer) : Integer;
  19047. begin
  19048. If Value1 < Value2 then Result := Value1 else Result := Value2;
  19049. end;
  19050. function MakeDarkColor (AColor : TColor; ADarkRate : Integer) : TColor;
  19051. var
  19052. R, G, B : Integer;
  19053. begin
  19054. R := GetRValue (ColorToRGB (AColor)) - ADarkRate;
  19055. G := GetGValue (ColorToRGB (AColor)) - ADarkRate;
  19056. B := GetBValue (ColorToRGB (AColor)) - ADarkRate;
  19057. if R < 0 then R := 0;
  19058. if G < 0 then G := 0;
  19059. if B < 0 then B := 0;
  19060. if R > 255 then R := 255;
  19061. if G > 255 then G := 255;
  19062. if B > 255 then B := 255;
  19063. Result := TColor (RGB (R, G, B));
  19064. end;
  19065. function HeightOf(R: TRect): Integer;
  19066. begin
  19067. Result := R.Bottom - R.Top;
  19068. end;
  19069. function WidthOf(R: TRect): Integer;
  19070. begin
  19071. Result := R.Right - R.Left;
  19072. end;
  19073. procedure TileImage(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
  19074. var
  19075. X, Y: Integer;
  19076. SaveIndex: Integer;
  19077. begin
  19078. if (Image.Width = 0) or (Image.Height = 0) then Exit;
  19079. SaveIndex := SaveDC(Canvas.Handle);
  19080. try
  19081. with Rect do
  19082. IntersectClipRect(Canvas.Handle, Left, Top, Right, Bottom);
  19083. for X := 0 to (WidthOf(Rect) div Image.Width) do
  19084. for Y := 0 to (HeightOf(Rect) div Image.Height) do
  19085. Canvas.Draw(Rect.Left + X * Image.Width,
  19086. Rect.Top + Y * Image.Height, Image);
  19087. finally
  19088. RestoreDC(Canvas.Handle, SaveIndex);
  19089. end;
  19090. end;
  19091. procedure GradientSimpleFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  19092. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  19093. var
  19094. StartRGB: array[0..2] of Byte; { Start RGB values }
  19095. RGBDelta: array[0..2] of Integer; { Difference between start and end RGB values }
  19096. ColorBand: TRect; { Color band rectangular coordinates }
  19097. I, Delta: Integer;
  19098. Brush: HBrush;
  19099. begin
  19100. if IsRectEmpty(ARect) then Exit;
  19101. if Colors < 2 then begin
  19102. Brush := CreateSolidBrush(ColorToRGB(StartColor));
  19103. FillRect(Canvas.Handle, ARect, Brush);
  19104. DeleteObject(Brush);
  19105. Exit;
  19106. end;
  19107. StartColor := ColorToRGB(StartColor);
  19108. EndColor := ColorToRGB(EndColor);
  19109. case Direction of
  19110. fdTopToBottom, fdLeftToRight: begin
  19111. { Set the Red, Green and Blue colors }
  19112. StartRGB[0] := GetRValue(StartColor);
  19113. StartRGB[1] := GetGValue(StartColor);
  19114. StartRGB[2] := GetBValue(StartColor);
  19115. { Calculate the difference between begin and end RGB values }
  19116. RGBDelta[0] := GetRValue(EndColor) - StartRGB[0];
  19117. RGBDelta[1] := GetGValue(EndColor) - StartRGB[1];
  19118. RGBDelta[2] := GetBValue(EndColor) - StartRGB[2];
  19119. end;
  19120. fdBottomToTop, fdRightToLeft: begin
  19121. { Set the Red, Green and Blue colors }
  19122. { Reverse of TopToBottom and LeftToRight directions }
  19123. StartRGB[0] := GetRValue(EndColor);
  19124. StartRGB[1] := GetGValue(EndColor);
  19125. StartRGB[2] := GetBValue(EndColor);
  19126. { Calculate the difference between begin and end RGB values }
  19127. { Reverse of TopToBottom and LeftToRight directions }
  19128. RGBDelta[0] := GetRValue(StartColor) - StartRGB[0];
  19129. RGBDelta[1] := GetGValue(StartColor) - StartRGB[1];
  19130. RGBDelta[2] := GetBValue(StartColor) - StartRGB[2];
  19131. end;
  19132. end; {case}
  19133. { Calculate the color band's coordinates }
  19134. ColorBand := ARect;
  19135. if Direction in [fdTopToBottom, fdBottomToTop] then begin
  19136. Colors := Max(2, Min(Colors, HeightOf(ARect)));
  19137. Delta := HeightOf(ARect) div Colors;
  19138. end
  19139. else begin
  19140. Colors := Max(2, Min(Colors, WidthOf(ARect)));
  19141. Delta := WidthOf(ARect) div Colors;
  19142. end;
  19143. with Canvas.Pen do begin { Set the pen style and mode }
  19144. Style := psSolid;
  19145. Mode := pmCopy;
  19146. end;
  19147. { Perform the fill }
  19148. if Delta > 0 then begin
  19149. for I := 0 to Colors do begin
  19150. case Direction of
  19151. { Calculate the color band's top and bottom coordinates }
  19152. fdTopToBottom, fdBottomToTop: begin
  19153. ColorBand.Top := ARect.Top + I * Delta;
  19154. ColorBand.Bottom := ColorBand.Top + Delta;
  19155. end;
  19156. { Calculate the color band's left and right coordinates }
  19157. fdLeftToRight, fdRightToLeft: begin
  19158. ColorBand.Left := ARect.Left + I * Delta;
  19159. ColorBand.Right := ColorBand.Left + Delta;
  19160. end;
  19161. end; {case}
  19162. { Calculate the color band's color }
  19163. Brush := CreateSolidBrush(RGB(
  19164. StartRGB[0] + MulDiv(I, RGBDelta[0], Colors - 1),
  19165. StartRGB[1] + MulDiv(I, RGBDelta[1], Colors - 1),
  19166. StartRGB[2] + MulDiv(I, RGBDelta[2], Colors - 1)));
  19167. FillRect(Canvas.Handle, ColorBand, Brush);
  19168. DeleteObject(Brush);
  19169. end;
  19170. end;
  19171. if Direction in [fdTopToBottom, fdBottomToTop] then
  19172. Delta := HeightOf(ARect) mod Colors
  19173. else Delta := WidthOf(ARect) mod Colors;
  19174. if Delta > 0 then begin
  19175. case Direction of
  19176. { Calculate the color band's top and bottom coordinates }
  19177. fdTopToBottom, fdBottomToTop: begin
  19178. ColorBand.Top := ARect.Bottom - Delta;
  19179. ColorBand.Bottom := ColorBand.Top + Delta;
  19180. end;
  19181. { Calculate the color band's left and right coordinates }
  19182. fdLeftToRight, fdRightToLeft: begin
  19183. ColorBand.Left := ARect.Right - Delta;
  19184. ColorBand.Right := ColorBand.Left + Delta;
  19185. end;
  19186. end; {case}
  19187. case Direction of
  19188. fdTopToBottom, fdLeftToRight:
  19189. Brush := CreateSolidBrush(EndColor);
  19190. else {fdBottomToTop, fdRightToLeft }
  19191. Brush := CreateSolidBrush(StartColor);
  19192. end;
  19193. FillRect(Canvas.Handle, ColorBand, Brush);
  19194. DeleteObject(Brush);
  19195. end;
  19196. end;
  19197. procedure GradientXPFillRect (ACanvas : TCanvas; ARect : TRect; LightColor : TColor; DarkColor : TColor; Colors : Byte);
  19198. const
  19199. cLightColorOffset : Integer = 30;
  19200. cMainBarOffset : Integer = 6;
  19201. var
  19202. DRect : TRect;
  19203. I : Integer;
  19204. begin
  19205. if IsRectEmpty(ARect) then Exit;
  19206. ACanvas.Brush.Color := DarkColor;
  19207. ACanvas.FrameRect (ARect);
  19208. //InflateRect (ARect, -1, -1);
  19209. //Main center rect
  19210. DRect := ARect;
  19211. DRect.Left := DRect.Left + cMainBarOffset;
  19212. DRect.Top := DRect.Top + cMainBarOffset;
  19213. DRect.Bottom := DRect.Bottom - cMainBarOffset;
  19214. GradientSimpleFillRect (ACanvas, DRect, DarkColor, LightColor, fdTopToBottom, Colors);
  19215. //Bottom rect
  19216. DRect := ARect;
  19217. DRect.Left := DRect.Left + cMainBarOffset;
  19218. DRect.Top := ARect.Bottom - cMainBarOffset;
  19219. GradientSimpleFillRect (ACanvas, DRect, LightColor, DarkColor, fdTopToBottom, Colors);
  19220. //Second left rect
  19221. DRect := ARect;
  19222. DRect := Rect (ARect.Left + cMainBarOffset div 4, 0, ARect.Left + cMainBarOffset, 1);
  19223. For I := ARect.Top + cMainBarOffset to ARect.Bottom do
  19224. begin
  19225. DRect.Top := I;
  19226. DRect.Bottom := I+1;
  19227. GradientSimpleFillRect (ACanvas, DRect, ACanvas.Pixels [DRect.Left-1, DRect.Top],
  19228. ACanvas.Pixels [DRect.Right + 1, DRect.Top], fdLeftToRight, 8);
  19229. end;
  19230. //Top light rect
  19231. DRect := ARect;
  19232. DRect.Left := DRect.Left + cMainBarOffset;
  19233. DRect.Bottom := DRect.Top + cMainBarOffset div 4;
  19234. GradientSimpleFillRect (ACanvas, DRect, MakeDarkColor (LightColor, -cLightColorOffset), LightColor, fdTopToBottom, 8);
  19235. //Second top rect
  19236. DRect := ARect;
  19237. DRect.Left := DRect.Left + cMainBarOffset;
  19238. DRect.Top := DRect.Top + cMainBarOffset div 4;
  19239. DRect.Bottom := ARect.Top + cMainBarOffset;
  19240. GradientSimpleFillRect (ACanvas, DRect, LightColor, DarkColor, fdTopToBottom, 8);
  19241. //Left light rect
  19242. DRect := ARect;
  19243. DRect.Top := DRect.Top + cMainBarOffset;
  19244. DRect.Right := DRect.Left + cMainBarOffset div 4;
  19245. GradientSimpleFillRect (ACanvas, DRect, MakeDarkColor (LightColor, -cLightColorOffset), LightColor, fdLeftToRight, 8);
  19246. //Second left rect
  19247. DRect := ARect;
  19248. DRect := Rect (ARect.Left + cMainBarOffset div 4, 0, ARect.Left + cMainBarOffset, 1);
  19249. For I := ARect.Top + cMainBarOffset to ARect.Bottom do
  19250. begin
  19251. DRect.Top := I;
  19252. DRect.Bottom := I+1;
  19253. GradientSimpleFillRect (ACanvas, DRect, ACanvas.Pixels [DRect.Left-1, DRect.Top],
  19254. ACanvas.Pixels [DRect.Right + 1, DRect.Top], fdLeftToRight, 8);
  19255. end;
  19256. For I := 0 to cMainBarOffset do
  19257. begin
  19258. ACanvas.Pen.Color := ACanvas.Pixels [ARect.Left + I, ARect.Top + cMainBarOffset+1];
  19259. ACanvas.MoveTo (ARect.Left + I, ARect.Top + cMainBarOffset);
  19260. ACanvas.LineTo (ARect.Left + I, ARect.Top + I);
  19261. ACanvas.LineTo (ARect.Left + cMainBarOffset, ARect.Top + I);
  19262. end;
  19263. end;
  19264. procedure GradientFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  19265. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  19266. var
  19267. BRect : TRect;
  19268. begin
  19269. case Direction of
  19270. fdCenterToVerti:
  19271. begin
  19272. BRect := ARect;
  19273. BRect.Bottom := BRect.Top + HeightOf (ARect) div 2;
  19274. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdTopToBottom, Colors);
  19275. BRect.Top := (BRect.Top + HeightOf (ARect) div 2);
  19276. BRect.Bottom := ARect.Bottom;
  19277. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdBottomToTop, Colors);
  19278. end;
  19279. fdCenterToHoriz:
  19280. begin
  19281. BRect := ARect;
  19282. BRect.Right := BRect.Left + WidthOf (ARect) div 2;
  19283. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdLeftToRight, Colors);
  19284. BRect.Left := (BRect.Left + WidthOf (ARect) div 2);
  19285. BRect.Right := ARect.Right;
  19286. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdRightToLeft, Colors);
  19287. end;
  19288. fdXPFace:
  19289. begin
  19290. GradientXPFillRect (Canvas, ARect, StartColor, EndColor, Colors);
  19291. end
  19292. else
  19293. GradientSimpleFillRect(Canvas, ARect, StartColor, EndColor, Direction, Colors);
  19294. end;
  19295. end;
  19296. // constructor must create a TControlCanvas for the owner draw style
  19297. constructor TDefinePages.Create (AOwner : TComponent);
  19298. begin
  19299. inherited Create (AOwner);
  19300. FCanvas := TControlCanvas.Create;
  19301. FBorderColor := DefaultBorderColor;
  19302. FTabPosition := tpTop;
  19303. FHotTrackTab := -1;
  19304. ShowHint := true;
  19305. FStyle := pcsFlatStyle;
  19306. FTabTextAlignment := taCenter;
  19307. FOwnerDraw := False;
  19308. end;
  19309. // remove link with glyphs and free the canvas
  19310. destructor TDefinePages.Destroy;
  19311. begin
  19312. try
  19313. FCanvas.Free;
  19314. except
  19315. end;
  19316. if Assigned (FImageList) then
  19317. try
  19318. FImageList.OnChange := nil;
  19319. except
  19320. end;
  19321. inherited Destroy;
  19322. end;
  19323. // CreateParams called to set the additional style bits
  19324. procedure TDefinePages.CreateParams(var Params: TCreateParams);
  19325. begin
  19326. inherited CreateParams (Params);
  19327. with Params do
  19328. begin
  19329. case FStyle of
  19330. pcsTabs: Style:= Style or TCS_TABS;
  19331. pcsButtons: Style:= Style or TCS_BUTTONS;
  19332. pcsFlatButtons: Style := Style or TCS_BUTTONS or TCS_FLATBUTTONS;
  19333. pcsFlatStyle: begin end;
  19334. end;
  19335. if FOwnerDraw then Style := Style or TCS_OWNERDRAWFIXED;
  19336. case FTabPosition of
  19337. tpTop:
  19338. begin
  19339. //Style := Style and (not TCS_VERTICAL) and (not TCS_BOTTOM);
  19340. end;
  19341. tpBottom:
  19342. begin
  19343. Style := Style or TCS_BOTTOM;
  19344. end;
  19345. tpLeft:
  19346. begin
  19347. Style := Style or TCS_VERTICAL;
  19348. end;
  19349. tpRight:
  19350. begin
  19351. Style := Style or TCS_VERTICAL or TCS_RIGHT;
  19352. end;
  19353. end;
  19354. end;
  19355. end;
  19356. // CreateWnd also must set links to the glyphs
  19357. procedure TDefinePages.CreateWnd;
  19358. begin
  19359. inherited CreateWnd;
  19360. if Assigned (FImageList) then SetGlyphs (FImageList);
  19361. end;
  19362. // if the glyphs should change then update the tabs
  19363. procedure TDefinePages.GlyphsChanged (Sender : TObject);
  19364. begin
  19365. if Assigned (FImageList) then UpdateGlyphs;
  19366. end;
  19367. // multiline property redefined as readonly, this makes it
  19368. // disappear from the object inspector
  19369. function TDefinePages.GetMultiline : boolean;
  19370. begin
  19371. Result := inherited Multiline
  19372. end;
  19373. // link the tabs to the glyph list
  19374. // nil parameter removes link
  19375. procedure TDefinePages.SetGlyphs (Value : TImageList);
  19376. var
  19377. I : Integer;
  19378. begin
  19379. FImageList := Value;
  19380. if Assigned(FImageList) then
  19381. begin
  19382. SendMessage (Handle, TCM_SETIMAGELIST, 0, FImageList.Handle);
  19383. For I := 0 to PageCount - 1 do begin
  19384. if Pages[i]<>Nil then
  19385. (Pages[I] as TDefineSheet).ImageIndex := I;
  19386. end;
  19387. FImageList.OnChange := GlyphsChanged
  19388. end
  19389. else
  19390. begin
  19391. SendMessage (Handle, TCM_SETIMAGELIST, 0, 0);
  19392. For I := 0 to PageCount - 1 do begin
  19393. if Pages[i]<>Nil then
  19394. (Pages[I] as TDefineSheet).ImageIndex := -1;
  19395. end;
  19396. end;
  19397. UpdateGlyphs;
  19398. SendMessage (Handle, WM_SIZE, 0, 0);
  19399. end;
  19400. // determine properties whenever the tab styles are changed
  19401. procedure TDefinePages.SetOwnerDraw (AValue : Boolean);
  19402. begin
  19403. if FOwnerDraw <> AValue then
  19404. begin
  19405. FOwnerDraw := AValue;
  19406. ReCreateWnd;
  19407. SendMessage (Handle, WM_SIZE, 0, 0);
  19408. if (Self.PageCount > 0) and (ActivePage <> nil) then
  19409. ActivePage.Invalidate;
  19410. end
  19411. end;
  19412. // update the glyphs linked to the tab
  19413. procedure TDefinePages.UpdateGlyphs;
  19414. var
  19415. TCItem : TTCItem;
  19416. Control,
  19417. Loop : integer;
  19418. begin
  19419. if FImageList <> nil then
  19420. begin
  19421. for Loop := 0 to pred(PageCount) do
  19422. begin
  19423. TCItem.Mask := TCIF_IMAGE;
  19424. TCItem.iImage := Loop;
  19425. Control := Loop;
  19426. // OnGlyphMap allows the user to reselect the glyph linked to a
  19427. // particular tab
  19428. if Assigned (FOnGlyphMap) then
  19429. FOnGlyphMap (Self, Control, TCItem.iImage);
  19430. if SendMessage (Handle, TCM_SETITEM, Control, longint(@TCItem)) = 0 then;
  19431. //raise EListError.Create ('TDefinePages error in setting tab glyph')
  19432. end
  19433. end
  19434. end;
  19435. // called when Owner Draw style is selected:
  19436. // retrieve the component style, set up the canvas and
  19437. // call the DrawItem method
  19438. procedure TDefinePages.CNDrawItem (var Msg : TWMDrawItem);
  19439. var
  19440. State: TOwnerDrawState;
  19441. begin
  19442. with Msg.DrawItemStruct^ do
  19443. begin
  19444. //State := TOwnerDrawState (WordRec (LongRec (itemState).Lo).Lo);
  19445. //!!
  19446. FCanvas.Handle := hDC;
  19447. FCanvas.Font := Font;
  19448. FCanvas.Brush := Brush;
  19449. if integer (itemID) >= 0 then
  19450. DrawItem (itemID, rcItem, State)
  19451. else
  19452. FCanvas.FillRect (rcItem);
  19453. FCanvas.Handle := 0
  19454. end;
  19455. end;
  19456. // default DrawItem method
  19457. procedure TDefinePages.DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);
  19458. begin
  19459. if Assigned(FOnDrawItem) then
  19460. FOnDrawItem (Self, Index, FCanvas, Rect, State)
  19461. else begin
  19462. //FCanvas.FillRect (Rect);
  19463. GradientFillRect (FCanvas, Rect, clWhite, RGB (220,220,220), fdCenterToVerti, (Rect.Bottom - Rect.Top) div 2);
  19464. FCanvas.Brush.Style := BSCLEAR;
  19465. if odSelected in State then
  19466. FCanvas.TextOut (Rect.Left + 16, Rect.Top + (Rect.Bottom - Rect.Top - FCanvas.TextHeight ('A')) div 2, Tabs[Index])
  19467. else
  19468. FCanvas.TextOut (Rect.Left + 12, Rect.Top + (Rect.Bottom - Rect.Top - FCanvas.TextHeight ('A')) div 2, Tabs[Index])
  19469. end
  19470. end;
  19471. procedure TDefinePages.WMAdjasment (var Msg : TMessage);
  19472. begin
  19473. inherited;
  19474. if Msg.WParam = 0 then
  19475. begin
  19476. InflateRect(PRect(Msg.LParam)^, 3, 3);
  19477. Dec(PRect(Msg.LParam)^.Top, 1);
  19478. end;
  19479. end;
  19480. {procedure TDefinePages.WMNCPaint (var Message : TWMNCPaint);
  19481. var
  19482. NCCanvas : TCanvas;
  19483. begin
  19484. inherited;
  19485. NCCanvas := TCanvas.Create;
  19486. try
  19487. NCCanvas.Handle := GetWindowDC (Handle);
  19488. NCCanvas.Brush.Color := clRed;
  19489. NCCanvas.Brush.Style := bsClear;
  19490. NCCanvas.Pen.Color := clSilver;
  19491. NCCanvas.Rectangle (0, 30, Width-1, Height-1);
  19492. finally
  19493. NCCanvas.Free;
  19494. end;
  19495. end;}
  19496. procedure TDefinePages.DrawHotTrackTab (ATabIndex : Integer; AHotTrack : Boolean);
  19497. var
  19498. ItemRect : TRect;
  19499. DrawRect : TRect;
  19500. StartColor : TColor;
  19501. EndColor : TColor;
  19502. begin
  19503. if SendMessage (Handle, TCM_GETITEMRECT, ATabIndex, LongInt (@ItemRect)) <> 0 then
  19504. begin
  19505. DrawRect := ItemRect;
  19506. StartColor := $2C8BE6;
  19507. EndColor := $3CC7FF;
  19508. case TabPosition of
  19509. tpTop: begin
  19510. DrawRect.Left := ItemRect.Left + 2;
  19511. DrawRect.Right := ItemRect.Right - 3;
  19512. DrawRect.Bottom := ItemRect.Top + 1;
  19513. if AHotTrack then
  19514. begin
  19515. StartColor := $2C8BE6;
  19516. EndColor := $3CC7FF;
  19517. end
  19518. else
  19519. begin
  19520. StartColor := FBorderColor;
  19521. EndColor := MakeDarkColor((Pages[ATabIndex] as TDefineSheet).Color, 5);
  19522. end;
  19523. end;
  19524. tpBottom: begin
  19525. DrawRect.Top := ItemRect.Bottom - 3;
  19526. DrawRect.Bottom := ItemRect.Bottom - 2;
  19527. DrawRect.Left := ItemRect.Left + 2;
  19528. DrawRect.Right := ItemRect.Right - 3;
  19529. if AHotTrack then
  19530. begin
  19531. StartColor := $3CC7FF;
  19532. EndColor := $2C8BE6;
  19533. end
  19534. else
  19535. begin
  19536. StartColor := MakeDarkColor ((Pages[ATabIndex] as TDefineSheet).Color, 20);
  19537. EndColor := FBorderColor;
  19538. end;
  19539. end;
  19540. tpLeft: begin
  19541. DrawRect.Left := ItemRect.Left;
  19542. DrawRect.Top := ItemRect.Top+2;
  19543. DrawRect.Bottom := ItemRect.Bottom - 3;
  19544. DrawRect.Right := ItemRect.Left+1;
  19545. if AHotTrack then
  19546. begin
  19547. StartColor := $3CC7FF;
  19548. EndColor := $2C8BE6;
  19549. end
  19550. else
  19551. begin
  19552. StartColor := FBorderColor;
  19553. EndColor := MakeDarkColor ((Pages[ATabIndex] as TDefineSheet).Color, 20);
  19554. end;
  19555. end;
  19556. tpRight: begin
  19557. DrawRect.Left := ItemRect.Right-1;
  19558. DrawRect.Top := ItemRect.Top+2;
  19559. DrawRect.Bottom := ItemRect.Bottom - 3;
  19560. DrawRect.Right := ItemRect.Right;
  19561. if AHotTrack then
  19562. begin
  19563. StartColor := $3CC7FF;
  19564. EndColor := $2C8BE6;
  19565. end
  19566. else
  19567. begin
  19568. StartColor := FBorderColor;
  19569. EndColor := MakeDarkColor ((Pages[ATabIndex] as TDefineSheet).Color, 20);
  19570. end;
  19571. end;
  19572. end;
  19573. FCanvas.Handle := GetWindowDC (Handle);
  19574. case TabPosition of
  19575. tpTop, tpBottom:
  19576. begin
  19577. FCanvas.Pen.Color := StartColor;
  19578. FCanvas.MoveTo (DrawRect.Left, DrawRect.Top );
  19579. FCanvas.LineTo (DrawRect.Right, DrawRect.Top );
  19580. FCanvas.Pen.Color := EndColor;
  19581. FCanvas.MoveTo (DrawRect.Left, DrawRect.Bottom);
  19582. FCanvas.LineTo (DrawRect.Right, DrawRect.Bottom);
  19583. end;
  19584. tpLeft,tpRight:
  19585. begin
  19586. FCanvas.Pen.Color := StartColor;
  19587. FCanvas.MoveTo (DrawRect.Left, DrawRect.Top );
  19588. FCanvas.LineTo (DrawRect.Left, DrawRect.Bottom);
  19589. FCanvas.Pen.Color := EndColor;
  19590. FCanvas.MoveTo (DrawRect.Right, DrawRect.Top);
  19591. FCanvas.LineTo (DrawRect.Right, DrawRect.Bottom);
  19592. end;
  19593. end;
  19594. end;
  19595. end;
  19596. procedure TDefinePages.DrawItemInside(AIndex : Integer; ACanvas : TCanvas; ARect : TRect);
  19597. var
  19598. dX : Integer;
  19599. ACaption : String;
  19600. AFormat : Integer;
  19601. DrawRect : TRect;
  19602. begin
  19603. ACanvas.Brush.Style := BSCLEAR;
  19604. ACanvas.Font.Assign (Self.Pages[AIndex].Font);
  19605. If Assigned (FImageList) then dX := FImageList.Width + 6 else dX := 0;
  19606. DrawRect := ARect;
  19607. InflateRect (DrawRect, -2, -2);
  19608. DrawRect.Left := DrawRect.Left + dX;
  19609. ACaption := Self.Pages[AIndex].Caption;
  19610. AFormat := DT_VCENTER or DT_END_ELLIPSIS or DT_SINGLELINE;
  19611. case FTabTextAlignment of
  19612. taLeftJustify: AFormat := AFormat or DT_LEFT;
  19613. taRightJustify: AFormat := AFormat or DT_RIGHT;
  19614. taCenter: AFormat := AFormat or DT_CENTER;
  19615. end;
  19616. ACanvas.Font.Color := MakeDarkColor((TDefineSheet(Self.Pages[AIndex]).Color), 30);
  19617. OffsetRect (DrawRect, 1, 1);
  19618. DrawText (ACanvas.Handle, PChar (ACaption), Length(ACaption), DrawRect, AFormat);
  19619. ACanvas.Font.Color := Self.Pages[AIndex].Font.Color;
  19620. OffsetRect (DrawRect, -1,-1);
  19621. DrawText (ACanvas.Handle, PChar (ACaption), Length(ACaption), DrawRect, AFormat);
  19622. if Assigned (FImageList) then
  19623. begin
  19624. FImageList.Draw (ACanvas, ARect.Left + 3,
  19625. (ARect.Top + ARect.Bottom - FImageList.Height) div 2,
  19626. (Self.Pages[AIndex] as TDefineSheet).ImageIndex);
  19627. end;
  19628. end;
  19629. //============================================================================//
  19630. //===================== Tabs drawing procedures =============================//
  19631. //============================================================================//
  19632. //====================== Draw top tabs =============================//
  19633. procedure TDefinePages.DrawTopTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  19634. var
  19635. AActiveTab : Boolean;
  19636. ATabColor : TColor;
  19637. begin
  19638. Dec (TabRect.Bottom,2);
  19639. AActiveTab := (SendMessage (Handle, TCM_GETCURSEL, 0, 0) = AVisibleIndex);
  19640. ATabColor := (Self.Pages [AIndex] as TDefineSheet).Color;
  19641. if AActiveTab then
  19642. begin
  19643. Dec (TabRect.Top, 2);
  19644. Dec (TabRect.Left, 2);
  19645. Inc (TabRect.Right, 1);
  19646. end
  19647. else
  19648. begin
  19649. Dec (TabRect.Right);
  19650. Dec (TabRect.Bottom);
  19651. ATabColor := MakeDarkColor (ATabColor, 5);
  19652. end;
  19653. Inc (TabRect.Bottom, 1);
  19654. ACanvas.Brush.Color := ATabColor;
  19655. ACanvas.Pen.Color := FBorderColor;
  19656. ACanvas.Rectangle (TabRect.Left, TabRect.Top + 6, TabRect.Right, TabRect.Bottom);
  19657. ACanvas.RoundRect (TabRect.Left, TabRect.Top, TabRect.Right, TabRect.Bottom - 7, 6, 6);
  19658. ACanvas.FillRect (Rect (TabRect.Left+1, TabRect.Top + 5, TabRect.Right-1, TabRect.Bottom));
  19659. if AActiveTab then
  19660. begin
  19661. ACanvas.Brush.Color := ATabColor;
  19662. ACanvas.Pen.Color := ATabColor;
  19663. ACanvas.Rectangle (TabRect.Left+1, TabRect.Bottom-1, TabRect.Right-1, TabRect.Bottom+2);
  19664. if HotTrack then
  19665. begin
  19666. FCanvas.Pen.Color := $2C8BE6;
  19667. FCanvas.MoveTo (TabRect.Left + 2, TabRect.Top );
  19668. FCanvas.LineTo (TabRect.Right - 2, TabRect.Top );
  19669. FCanvas.Pen.Color := $3CC7FF;
  19670. FCanvas.MoveTo (TabRect.Left + 2, TabRect.Top + 1);
  19671. FCanvas.LineTo (TabRect.Right - 2, TabRect.Top + 1);
  19672. end;
  19673. end
  19674. else
  19675. begin
  19676. //Draw tab vertical right shadow line
  19677. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19678. ACanvas.Brush.Color := ATabColor;
  19679. ACanvas.MoveTo (TabRect.Right-2, TabRect.Top+2);
  19680. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-1);
  19681. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19682. ACanvas.MoveTo (TabRect.Right-3, TabRect.Top+4);
  19683. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-2);
  19684. //Draw tab horizontal bottom shadow line
  19685. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19686. ACanvas.Brush.Color := ATabColor;
  19687. ACanvas.MoveTo (TabRect.Left+2, TabRect.Bottom-1);
  19688. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-1);
  19689. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19690. ACanvas.MoveTo (TabRect.Left + 3, TabRect.Bottom - 2);
  19691. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-2);
  19692. end;
  19693. //Draw text and image
  19694. DrawItemInside (AIndex, ACanvas, TabRect);
  19695. end;
  19696. //====================== Draw bottom tabs =============================//
  19697. procedure TDefinePages.DrawBottomTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  19698. var
  19699. AActiveTab : Boolean;
  19700. ATabColor : TColor;
  19701. begin
  19702. Dec (TabRect.Bottom,2);
  19703. AActiveTab := (SendMessage (Handle, TCM_GETCURSEL, 0, 0) = AVisibleIndex);
  19704. ATabColor := (Self.Pages [AIndex] as TDefineSheet).Color;
  19705. if AActiveTab then
  19706. begin
  19707. Inc (TabRect.Bottom, 1);
  19708. Dec (TabRect.Left, 2);
  19709. Inc (TabRect.Right, 1);
  19710. end
  19711. else
  19712. begin
  19713. Dec (TabRect.Right);
  19714. Inc (TabRect.Top);
  19715. ATabColor := MakeDarkColor (ATabColor, 5);
  19716. end;
  19717. Inc (TabRect.Bottom, 1);
  19718. ACanvas.Brush.Color := ATabColor;
  19719. ACanvas.Pen.Color := FBorderColor;
  19720. ACanvas.Rectangle (TabRect.Left, TabRect.Top, TabRect.Right, TabRect.Bottom - 6);
  19721. ACanvas.RoundRect (TabRect.Left, TabRect.Top+6, TabRect.Right, TabRect.Bottom, 6, 6);
  19722. ACanvas.FillRect (Rect (TabRect.Left+1, TabRect.Top+6, TabRect.Right-1, TabRect.Bottom-3));
  19723. if AActiveTab then
  19724. begin
  19725. ACanvas.Brush.Color := ATabColor;
  19726. ACanvas.Pen.Color := ATabColor;
  19727. ACanvas.Rectangle (TabRect.Left+1, TabRect.Top-1, TabRect.Right-1, TabRect.Top+2);
  19728. if HotTrack then
  19729. begin
  19730. FCanvas.Pen.Color := $2C8BE6;
  19731. FCanvas.MoveTo (TabRect.Left + 2, TabRect.Bottom -1);
  19732. FCanvas.LineTo (TabRect.Right - 2, TabRect.Bottom -1);
  19733. FCanvas.Pen.Color := $3CC7FF;
  19734. FCanvas.MoveTo (TabRect.Left + 2, TabRect.Bottom);
  19735. FCanvas.LineTo (TabRect.Right - 2, TabRect.Bottom);
  19736. end;
  19737. end
  19738. else
  19739. begin
  19740. //Draw tab vertical right shadow line
  19741. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19742. ACanvas.Brush.Color := ATabColor;
  19743. ACanvas.MoveTo (TabRect.Right-2, TabRect.Top+2);
  19744. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-2);
  19745. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19746. ACanvas.MoveTo (TabRect.Right-3, TabRect.Top+4);
  19747. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-3);
  19748. //Draw tab horizontal bottom shadow line
  19749. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19750. ACanvas.Brush.Color := ATabColor;
  19751. ACanvas.MoveTo (TabRect.Left+2, TabRect.Bottom-2);
  19752. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-2);
  19753. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19754. ACanvas.MoveTo (TabRect.Left + 3, TabRect.Bottom - 3);
  19755. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-3);
  19756. end;
  19757. //Draw text and image
  19758. DrawItemInside (AIndex, ACanvas, TabRect);
  19759. end;
  19760. //====================== Draw left tabs =============================//
  19761. procedure TDefinePages.DrawLeftTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  19762. var
  19763. AActiveTab : Boolean;
  19764. ATabColor : TColor;
  19765. begin
  19766. Dec (TabRect.Bottom,2);
  19767. AActiveTab := (SendMessage (Handle, TCM_GETCURSEL, 0, 0) = AVisibleIndex);
  19768. ATabColor := (Self.Pages [AIndex] as TDefineSheet).Color;
  19769. if AActiveTab then
  19770. begin
  19771. Dec (TabRect.Left, 2);
  19772. Dec (TabRect.Top, 1);
  19773. Inc (TabRect.Bottom, 1);
  19774. end
  19775. else
  19776. begin
  19777. Dec (TabRect.Right);
  19778. ATabColor := MakeDarkColor (ATabColor, 5);
  19779. end;
  19780. Inc (TabRect.Bottom, 1);
  19781. ACanvas.Brush.Color := ATabColor;
  19782. ACanvas.Pen.Color := FBorderColor;
  19783. ACanvas.Rectangle (TabRect.Left+6, TabRect.Top, TabRect.Right, TabRect.Bottom);
  19784. ACanvas.RoundRect (TabRect.Left, TabRect.Top, TabRect.Left+8, TabRect.Bottom, 6, 6);
  19785. ACanvas.FillRect (Rect (TabRect.Left+5, TabRect.Top + 1, TabRect.Right-1, TabRect.Bottom-1));
  19786. if AActiveTab then
  19787. begin
  19788. if HotTrack then
  19789. begin
  19790. FCanvas.Pen.Color := $2C8BE6;
  19791. FCanvas.MoveTo (TabRect.Left, TabRect.Top + 2);
  19792. FCanvas.LineTo (TabRect.Left, TabRect.Bottom -2);
  19793. FCanvas.Pen.Color := $3CC7FF;
  19794. FCanvas.MoveTo (TabRect.Left + 1, TabRect.Top + 1);
  19795. FCanvas.LineTo (TabRect.Left + 1, TabRect.Bottom - 1);
  19796. end;
  19797. end
  19798. else
  19799. begin
  19800. //Draw tab vertical right shadow line
  19801. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19802. ACanvas.Brush.Color := ATabColor;
  19803. ACanvas.MoveTo (TabRect.Right-2, TabRect.Top+2);
  19804. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-1);
  19805. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19806. ACanvas.MoveTo (TabRect.Right-3, TabRect.Top+4);
  19807. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-2);
  19808. //Draw tab horizontal bottom shadow line
  19809. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19810. ACanvas.Brush.Color := ATabColor;
  19811. ACanvas.MoveTo (TabRect.Left+2, TabRect.Bottom-2);
  19812. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-2);
  19813. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19814. ACanvas.MoveTo (TabRect.Left + 3, TabRect.Bottom - 3);
  19815. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-4);
  19816. end;
  19817. //Draw text and image
  19818. DrawItemInside (AIndex, ACanvas, TabRect);
  19819. end;
  19820. //====================== Draw right tabs =============================//
  19821. procedure TDefinePages.DrawRightTab (TabRect : TRect; ACanvas : TCanvas; AIndex, AVisibleIndex : Integer);
  19822. var
  19823. AActiveTab : Boolean;
  19824. ATabColor : TColor;
  19825. begin
  19826. Dec (TabRect.Bottom,2);
  19827. AActiveTab := (SendMessage (Handle, TCM_GETCURSEL, 0, 0) = AVisibleIndex);
  19828. ATabColor := (Self.Pages [AIndex] as TDefineSheet).Color;
  19829. if AActiveTab then
  19830. begin
  19831. Inc (TabRect.Right, 2);
  19832. Dec (TabRect.Top, 1);
  19833. Inc (TabRect.Bottom, 1);
  19834. end
  19835. else
  19836. begin
  19837. Inc (TabRect.Left);
  19838. ATabColor := MakeDarkColor (ATabColor, 5);
  19839. end;
  19840. Inc (TabRect.Bottom, 1);
  19841. ACanvas.Brush.Color := ATabColor;
  19842. ACanvas.Pen.Color := FBorderColor;
  19843. ACanvas.Rectangle (TabRect.Left, TabRect.Top, TabRect.Right-6, TabRect.Bottom);
  19844. ACanvas.RoundRect (TabRect.Right-8, TabRect.Top, TabRect.Right, TabRect.Bottom, 6, 6);
  19845. ACanvas.FillRect (Rect (TabRect.Right-8, TabRect.Top + 1, TabRect.Right-3, TabRect.Bottom-1));
  19846. if AActiveTab then
  19847. begin
  19848. if HotTrack then
  19849. begin
  19850. FCanvas.Pen.Color := $2C8BE6;
  19851. FCanvas.MoveTo (TabRect.Right-2, TabRect.Top + 2);
  19852. FCanvas.LineTo (TabRect.Right-2, TabRect.Bottom -2);
  19853. FCanvas.Pen.Color := $3CC7FF;
  19854. FCanvas.MoveTo (TabRect.Right-1, TabRect.Top + 1);
  19855. FCanvas.LineTo (TabRect.Right-1, TabRect.Bottom - 1);
  19856. end;
  19857. end
  19858. else
  19859. begin
  19860. //Draw tab vertical right shadow line
  19861. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19862. ACanvas.Brush.Color := ATabColor;
  19863. ACanvas.MoveTo (TabRect.Right-2, TabRect.Top+2);
  19864. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-1);
  19865. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19866. ACanvas.MoveTo (TabRect.Right-3, TabRect.Top+4);
  19867. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-2);
  19868. //Draw tab horizontal bottom shadow line
  19869. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 20);
  19870. ACanvas.Brush.Color := ATabColor;
  19871. ACanvas.MoveTo (TabRect.Left+2, TabRect.Bottom-2);
  19872. ACanvas.LineTo (TabRect.Right-2, TabRect.Bottom-2);
  19873. ACanvas.Pen.Color := MakeDarkColor (ATabColor, 10);
  19874. ACanvas.MoveTo (TabRect.Left + 3, TabRect.Bottom - 3);
  19875. ACanvas.LineTo (TabRect.Right-3, TabRect.Bottom-4);
  19876. end;
  19877. //Draw text and image
  19878. DrawItemInside (AIndex, ACanvas, TabRect);
  19879. end;
  19880. //============================================================================//
  19881. //=================== End tabs drawing procedures ===========================//
  19882. //============================================================================//
  19883. procedure TDefinePages.DrawBorder (ACanvas : TCanvas);
  19884. begin
  19885. FCanvas.Brush.Style := BSCLEAR;
  19886. FCanvas.Pen.Color := FBorderColor;
  19887. FCanvas.Rectangle (FBorderRect.Left, FBorderRect.Top, FBorderRect.Right, FBorderRect.Bottom);
  19888. end;
  19889. procedure TDefinePages.WMPaint (var Message : TWMPaint);
  19890. var
  19891. DC : hDC;
  19892. PS : TPaintStruct;
  19893. ItemRect : TRect;
  19894. I : Integer;
  19895. Index : Integer;
  19896. begin
  19897. if FStyle <> pcsFlatStyle then
  19898. begin
  19899. inherited;
  19900. Exit;
  19901. end;
  19902. if Message.DC = 0 then DC := BeginPaint(Handle, PS) else DC := Message.DC;
  19903. try
  19904. FCanvas.Handle := DC;
  19905. DrawBorder (FCanvas);
  19906. if Self.PageCount > 0 then
  19907. begin
  19908. Index := 0;
  19909. For I := 0 to Self.PageCount - 1 do
  19910. begin
  19911. if Pages [I].TabVisible then
  19912. begin
  19913. SendMessage (Handle, TCM_GETITEMRECT, Index, LongInt (@ItemRect));
  19914. if (FOwnerDraw) and (Assigned (OnDrawItem)) then
  19915. begin
  19916. OnDrawItem (Self, I, FCanvas, ItemRect, []);
  19917. end
  19918. else
  19919. begin
  19920. Case TabPosition of
  19921. tpTop: DrawTopTab (ItemRect, FCanvas, I, Index);
  19922. tpBottom: DrawBottomTab (ItemRect, FCanvas, I, Index);
  19923. tpLeft: DrawLeftTab (ItemRect, FCanvas, I, Index);
  19924. tpRight: DrawRightTab (ItemRect, FCanvas, I, Index);
  19925. end;
  19926. end;
  19927. Inc (Index);
  19928. end;
  19929. end;
  19930. end;
  19931. finally
  19932. if Message.DC = 0 then EndPaint(Handle, PS);
  19933. end;
  19934. end;
  19935. procedure TDefinePages.WMSIZE (var Message : TWMSIZE);
  19936. begin
  19937. inherited;
  19938. FBorderRect := Self.BoundsRect;
  19939. OffsetRect (FBorderRect, -FBorderRect.Left, -FBorderRect.Top);
  19940. SendMessage (Handle, TCM_ADJUSTRECT, 0, LongInt (@FBorderRect));
  19941. InflateRect (FBorderRect, 1, 1);
  19942. Inc (FBorderRect.Top);
  19943. end;
  19944. procedure TDefinePages.WMMouseMove (var Message : TWMMouseMove);
  19945. var
  19946. HitTest : TTCHitTestInfo;
  19947. AActiveTab : Integer;
  19948. begin
  19949. if FStyle <> pcsFlatStyle then
  19950. begin
  19951. inherited;
  19952. Exit;
  19953. end;
  19954. If not HotTrack then exit;
  19955. HitTest.pt := Point (Message.XPos, Message.YPos);
  19956. AActiveTab := SendMessage (Handle, TCM_HITTEST, 0, LongInt (@HitTest));
  19957. if AActiveTab <> FHotTrackTab then
  19958. begin
  19959. if (FHotTrackTab <> SendMessage (Handle, TCM_GETCURSEL, 0, 0)) then
  19960. DrawHotTrackTab (FHotTrackTab, False);
  19961. FHotTrackTab := AActiveTab;
  19962. if (FHotTrackTab <> -1) and (FHotTrackTab <> SendMessage (Handle, TCM_GETCURSEL, 0, 0)) then
  19963. DrawHotTrackTab (FHotTrackTab, True);
  19964. end;
  19965. end;
  19966. procedure TDefinePages.MouseLeave (var Message : TMessage);
  19967. begin
  19968. If HotTrack and (FHotTrackTab <> -1) and (FHotTrackTab <> SendMessage (Handle, TCM_GETCURSEL, 0, 0)) then
  19969. begin
  19970. DrawHotTrackTab (FHotTrackTab, False);
  19971. FHotTrackTab := -1;
  19972. end;
  19973. end;
  19974. procedure TDefinePages.WMNCCalcSize (var Message : TWMNCCalcSize);
  19975. begin
  19976. inherited;
  19977. end;
  19978. procedure TDefinePages.CMHintShow(var Message: TMessage);
  19979. var
  19980. Tab : TDefineSheet;
  19981. ItemRect : TRect;
  19982. HitTest : TTCHitTestInfo;
  19983. AActiveTab : Integer;
  19984. AWinActiveTab : Integer;
  19985. begin
  19986. inherited;
  19987. if TCMHintShow (Message).Result=1 then exit; // CanShow = false?
  19988. with TCMHintShow(Message).HintInfo^ do
  19989. begin
  19990. if TControl(Self) <> HintControl then exit;
  19991. HitTest.pt := Point (CursorPos.X, CursorPos.Y);
  19992. AWinActiveTab := SendMessage (Handle, TCM_HITTEST, 0, LongInt (@HitTest));
  19993. AActiveTab := WinIndexToPage (AWinActiveTab);
  19994. if (AActiveTab >= 0) and (AActiveTab < Self.PageCount) then
  19995. begin
  19996. Tab := (Self.Pages [AActiveTab] as TDefineSheet);
  19997. if not (Assigned(Tab) and (Tab.ShowTabHint) and (Tab.TabHint <> '')) then Exit;
  19998. end
  19999. else
  20000. Exit;
  20001. HintStr := GetShortHint(Tab.TabHint);
  20002. SendMessage (Handle, TCM_GETITEMRECT, AWinActiveTab, LongInt (@ItemRect));
  20003. CursorRect := ItemRect;
  20004. end; //with
  20005. end;
  20006. {function TDefinePages.PageIndexToWin (AIndex : Integer) : Integer;
  20007. var
  20008. I : Integer;
  20009. begin
  20010. Result := -1;
  20011. if (Self.PageCount <= 0) or (AIndex >= Self.PageCount) then Exit;
  20012. if not Self.Pages[AIndex].TabVisible then Exit;
  20013. For I := 0 to AIndex do
  20014. if Self.Pages[I].TabVisible then Inc (Result);
  20015. end; }
  20016. function TDefinePages.WinIndexToPage (AIndex : Integer) : Integer;
  20017. var
  20018. I : Integer;
  20019. begin
  20020. Result := -1;
  20021. if (Self.PageCount <= 0) or (AIndex >= Self.PageCount) then Exit;
  20022. I := 0;
  20023. Result := 0;
  20024. While (I <= AIndex) and (Result < Self.PageCount) do
  20025. begin
  20026. if Self.Pages[Result].TabVisible then Inc (I);
  20027. Inc (Result);
  20028. end;
  20029. Dec (Result);
  20030. end;
  20031. procedure TDefinePages.WMSysColorChange (var Message: TMessage);
  20032. begin
  20033. invalidate;
  20034. inherited;
  20035. end;
  20036. procedure TDefinePages.Loaded;
  20037. begin
  20038. inherited;
  20039. SendMessage (Handle, WM_SIZE, 0, 0);
  20040. end;
  20041. procedure TDefinePages.SetBorderColor (Value : TColor);
  20042. begin
  20043. if FBorderColor <> Value then
  20044. begin
  20045. FBorderColor := Value;
  20046. Invalidate;
  20047. end;
  20048. end;
  20049. procedure TDefinePages.SetTabPosition (Value : TPagesPosition);
  20050. begin
  20051. if FTabPosition <> Value then
  20052. begin
  20053. if (FStyle in [pcsButtons, pcsFlatButtons]) and (Value <> tpTop) then
  20054. raise Exception.Create ('Tab position incompatible with current tab style');
  20055. FTabPosition := Value;
  20056. RecreateWnd;
  20057. SendMessage (Handle, WM_SIZE, 0, 0);
  20058. if (Self.PageCount > 0) and (ActivePage <> nil) then
  20059. ActivePage.Invalidate;
  20060. end;
  20061. end;
  20062. procedure TDefinePages.SetTabTextAlignment (Value : TAlignment);
  20063. begin
  20064. if Value <> FTabTextAlignment then
  20065. begin
  20066. FTabTextAlignment := Value;
  20067. Invalidate;
  20068. end;
  20069. end;
  20070. procedure TDefinePages.SetStyle (Value : TPagesStyle);
  20071. begin
  20072. if FStyle <> Value then
  20073. begin
  20074. if (Value in [pcsButtons, pcsFlatButtons]) then TabPosition := tpTop;
  20075. FStyle := Value;
  20076. RecreateWnd;
  20077. SendMessage (Handle, WM_SIZE, 0, 0);
  20078. if (Self.PageCount > 0) and (ActivePage <> nil) then
  20079. ActivePage.Invalidate;
  20080. end;
  20081. end;
  20082. ////////////////////////////////////////////////////////////////////////////////
  20083. constructor TDefineSheet.Create(AOwner: TComponent);
  20084. begin
  20085. inherited Create(AOwner);
  20086. FColor := clBtnFace;
  20087. FImageIndex := -1;
  20088. FShowTabHint := False;
  20089. FTabHint := '';
  20090. FCanvas := TControlCanvas.Create;
  20091. FBGImage := TBitmap.Create;
  20092. FBGStyle := bgsNone;
  20093. FGradientStartColor := clWhite;
  20094. FGradientEndColor := clSilver;
  20095. FGradientFillDir := fdTopToBottom;
  20096. end;
  20097. destructor TDefineSheet.Destroy;
  20098. begin
  20099. try FCanvas.Free;
  20100. except
  20101. end;
  20102. try FBGImage.Free;
  20103. except
  20104. end;
  20105. inherited Destroy;
  20106. end;
  20107. procedure TDefineSheet.SetBGImage (AValue : TBitmap);
  20108. begin
  20109. FBGImage.Assign (AValue);
  20110. Invalidate;
  20111. if (FBGImage.Empty) and (FBGStyle in [bgsTileImage, bgsStrechImage]) then
  20112. FBGStyle := bgsNone;
  20113. end;
  20114. procedure TDefineSheet.SetBGStyle (AValue : TDefineSheetBGStyle);
  20115. begin
  20116. if FBGStyle <> AValue then
  20117. begin
  20118. FBGStyle := AValue;
  20119. Invalidate;
  20120. end;
  20121. end;
  20122. procedure TDefineSheet.SetColor (AValue : TColor);
  20123. begin
  20124. if FColor <> AValue then
  20125. begin
  20126. FColor := AValue;
  20127. Invalidate;
  20128. if Assigned (PageControl) then
  20129. try
  20130. PageControl.Invalidate;
  20131. except
  20132. end;
  20133. end;
  20134. end;
  20135. procedure TDefineSheet.SetGradientStartColor (AValue : TColor);
  20136. begin
  20137. if FGradientStartColor <> AValue then
  20138. begin
  20139. FGradientStartColor := AValue;
  20140. Invalidate;
  20141. end;
  20142. end;
  20143. procedure TDefineSheet.SetGradientEndColor (AValue : TColor);
  20144. begin
  20145. if FGradientEndColor <> AValue then
  20146. begin
  20147. FGradientEndColor := AValue;
  20148. Invalidate;
  20149. end;
  20150. end;
  20151. procedure TDefineSheet.SetGradientFillDir (AValue : TFillDirection);
  20152. begin
  20153. if FGradientFillDir <> AValue then
  20154. begin
  20155. FGradientFillDir := AValue;
  20156. Invalidate;
  20157. end;
  20158. end;
  20159. procedure TDefineSheet.WMPaint (var Message : TWMPaint);
  20160. begin
  20161. Brush.Color := FColor;
  20162. inherited;
  20163. end;
  20164. procedure TDefineSheet.WMEraseBkgnd (var Message : TWMEraseBkgnd);
  20165. var
  20166. DC : hDC;
  20167. PS : TPaintStruct;
  20168. begin
  20169. if Message.DC = 0 then DC := BeginPaint(Handle, PS) else DC := Message.DC;
  20170. try
  20171. FCanvas.Handle := DC;
  20172. Brush.Color := FColor;
  20173. case FBGStyle of
  20174. bgsNone: begin
  20175. FCanvas.Brush.Color := FColor;
  20176. FCanvas.FillRect (ClientRect);
  20177. end;
  20178. bgsGradient:
  20179. begin
  20180. GradientFillRect (FCanvas, ClientRect, FGradientStartColor, FGradientEndColor, FGradientFillDir, 60);
  20181. end;
  20182. bgsTileImage:
  20183. if not FBGImage.Empty then
  20184. begin
  20185. TileImage(FCanvas, ClientRect, FBGImage);
  20186. end
  20187. else
  20188. begin
  20189. FCanvas.Brush.Color := FColor;
  20190. FCanvas.FillRect (ClientRect);
  20191. end;
  20192. bgsStrechImage:
  20193. if not FBGImage.Empty then
  20194. begin
  20195. FCanvas.StretchDraw (ClientRect, FBGImage);
  20196. end
  20197. else
  20198. begin
  20199. FCanvas.Brush.Color := FColor;
  20200. FCanvas.FillRect (ClientRect);
  20201. end;
  20202. end;
  20203. finally
  20204. if Message.DC = 0 then EndPaint(Handle, PS);
  20205. end;
  20206. end;
  20207. procedure TDefineSheet.WMNCPaint (var Message : TWMNCPaint);
  20208. begin
  20209. Brush.Color := FColor;
  20210. inherited;
  20211. end;
  20212. procedure TDefineSheet.SetImageIndex (AIndex : Integer);
  20213. var
  20214. Item : TTCItem;
  20215. begin
  20216. if AIndex < -1 then AIndex := -1;
  20217. if (FImageIndex <> AIndex) and Assigned (PageControl) then
  20218. begin
  20219. FImageIndex := AIndex;
  20220. Item.iImage := FImageIndex;
  20221. Item.mask := TCIF_IMAGE;
  20222. SendMessage (PageControl.Handle, TCM_SETITEM, PageIndex, LongInt (@Item));
  20223. end;
  20224. end;
  20225. { TDefineBarcode }
  20226. const
  20227. StartA = '211412';
  20228. StartB = '211214';
  20229. StartC = '211232';
  20230. Stop = '2331112';
  20231. {Pattern for Barcode EAN Charset A} {L1 S1 L2 S2}
  20232. BARCode_EAN_A:array['0'..'9'] of string =
  20233. (('2605'), { 0 } ('1615'), { 1 } ('1516'), { 2 } ('0805'), { 3 }
  20234. ('0526'), { 4 } ('0625'), { 5 } ('0508'), { 6 } ('0706'), { 7 }
  20235. ('0607'), { 8 } ('2506'));{ 9 }
  20236. BARCode_EAN_B:array['0'..'9'] of string =
  20237. (('0517'), { 0 } ('0616'), { 1 } ('1606'), { 2 } ('0535'), { 3 }
  20238. ('1705'), { 4 } ('0715'), { 5 } ('3505'), { 6 } ('1525'), { 7 }
  20239. ('2515'), { 8 } ('1507'));{ 9 }
  20240. {Pattern for Barcode EAN Charset C} {S1 L1 S2 L2}
  20241. BARCode_EAN_C:array['0'..'9'] of string =
  20242. (('7150' ), { 0 }('6160' ), { 1 } ('6061' ), { 2 }('5350' ), { 3 }
  20243. ('5071' ), { 4 }('5170' ), { 5 } ('5053' ), { 6 }('5251' ), { 7 }
  20244. ('5152' ), { 8 }('7051' ));{ 9 }
  20245. BARCode_ParityEAN13:array[0..9, 1..6] of char =
  20246. (('A', 'A', 'A', 'A', 'A', 'A'), { 0 } ('A', 'A', 'B', 'A', 'B', 'B'), { 1 }
  20247. ('A', 'A', 'B', 'B', 'A', 'B'), { 2 } ('A', 'A', 'B', 'B', 'B', 'A'), { 3 }
  20248. ('A', 'B', 'A', 'A', 'B', 'B'), { 4 } ('A', 'B', 'B', 'A', 'A', 'B'), { 5 }
  20249. ('A', 'B', 'B', 'B', 'A', 'A'), { 6 } ('A', 'B', 'A', 'B', 'A', 'B'), { 7 }
  20250. ('A', 'B', 'A', 'B', 'B', 'A'), { 8 } ('A', 'B', 'B', 'A', 'B', 'A'));{ 9 }
  20251. BARCode_UPC_E:array['0'..'9', 1..6] of char =
  20252. (('E', 'E', 'E', 'O', 'O', 'O' ), { 0 } ('E', 'E', 'O', 'E', 'O', 'O' ), { 1 }
  20253. ('E', 'E', 'O', 'O', 'E', 'O' ), { 2 } ('E', 'E', 'O', 'O', 'O', 'E' ), { 3 }
  20254. ('E', 'O', 'E', 'E', 'O', 'O' ), { 4 } ('E', 'O', 'O', 'E', 'E', 'O' ), { 5 }
  20255. ('E', 'O', 'O', 'O', 'E', 'E' ), { 6 } ('E', 'O', 'E', 'O', 'E', 'O' ), { 7 }
  20256. ('E', 'O', 'E', 'O', 'O', 'E' ), { 8 } ('E', 'O', 'O', 'E', 'O', 'E' )); { 9 }
  20257. BARCode_PostNet:array['0'..'9'] of string[10] =
  20258. (('5151A1A1A1'),{0} ('A1A1A15151'),{1} ('A1A151A151'),{2}
  20259. ('A1A15151A1'),{3} ('A151A1A151'),{4} ('A151A151A1'),{5}
  20260. ('A15151A1A1'),{6} ('51A1A1A151'),{7} ('51A1A151A1'),{8}
  20261. ('51A151A1A1'));{9}
  20262. BARCode_MSI:array['0'..'9'] of string[8] =
  20263. (('51515151'),{0} ('51515160'),{1} ('51516051'),{2}
  20264. ('51516060'),{3} ('51605151'),{4} ('51605160'),{5}
  20265. ('51606051'),{6} ('51606060'),{7} ('60515151'),{8}
  20266. ('60515160'));{9}
  20267. BARCode_25:array['0'..'9', 1..5] of char =
  20268. (('0', '0', '1', '1', '0'),{0} ('1', '0', '0', '0', '1'),{1}
  20269. ('0', '1', '0', '0', '1'),{2} ('1', '1', '0', '0', '0'),{3}
  20270. ('0', '0', '1', '0', '1'),{4} ('1', '0', '1', '0', '0'),{5}
  20271. ('0', '1', '1', '0', '0'),{6} ('0', '0', '0', '1', '1'),{7}
  20272. ('1', '0', '0', '1', '0'),{8} ('0', '1', '0', '1', '0'));{9}
  20273. BARCode_Codabar: array[0..19] of TCodabar =
  20274. ((c:'1'; data:'5050615'), (c:'2'; data:'5051506'), (c:'3'; data:'6150505'),
  20275. (c:'4'; data:'5060515'), (c:'5'; data:'6050515'), (c:'6'; data:'5150506'),
  20276. (c:'7'; data:'5150605'), (c:'8'; data:'5160505'), (c:'9'; data:'6051505'),
  20277. (c:'0'; data:'5050516'), (c:'-'; data:'5051605'), (c:'$'; data:'5061505'),
  20278. (c:':'; data:'6050606'), (c:'/'; data:'6060506'), (c:'.'; data:'6060605'),
  20279. (c:'+'; data:'5060606'), (c:'A'; data:'5061515'), (c:'B'; data:'5151506'), //'5151506' '5061515'
  20280. (c:'C'; data:'5051516'), (c:'D'; data:'5051615'));
  20281. BARCode_39x : array[0..127] of string[2] =
  20282. (('%U'), ('$A'), ('$B'), ('$C'), ('$D'), ('$E'), ('$F'), ('$G'),
  20283. ('$H'), ('$I'), ('$J'), ('$K'), ('$L'), ('$M'), ('$N'), ('$O'),
  20284. ('$P'), ('$Q'), ('$R'), ('$S'), ('$T'), ('$U'), ('$V'), ('$W'),
  20285. ('$X'), ('$Y'), ('$Z'), ('%A'), ('%B'), ('%C'), ('%D'), ('%E'),
  20286. (' ' ), ('/A'), ('/B'), ('/C'), ('/D'), ('/E'), ('/F'), ('/G'),
  20287. ('/H'), ('/I'), ('/J'), ('/K'), ('/L'), ('/M'), ('/N'), ('/O'),
  20288. ('0' ), ('1' ), ('2' ), ('3' ), ('4' ), ('5' ), ('6' ), ('7' ),
  20289. ('8' ), ('9' ), ('/Z'), ('%F'), ('%G'), ('%H'), ('%I'), ('%J'),
  20290. ('%V'), ('A' ), ('B' ), ('C' ), ('D' ), ('E' ), ('F' ), ('G' ),
  20291. ('H' ), ('I' ), ('J' ), ('K' ), ('L' ), ('M' ), ('N' ), ('O' ),
  20292. ('P' ), ('Q' ), ('R' ), ('S' ), ('T' ), ('U' ), ('V' ), ('W' ),
  20293. ('X' ), ('Y' ), ('Z' ), ('%K'), ('%L'), ('%M'), ('%N'), ('%O'),
  20294. ('%W'), ('+A'), ('+B'), ('+C'), ('+D'), ('+E'), ('+F'), ('+G'),
  20295. ('+H'), ('+I'), ('+J'), ('+K'), ('+L'), ('+M'), ('+N'), ('+O'),
  20296. ('+P'), ('+Q'), ('+R'), ('+S'), ('+T'), ('+U'), ('+V'), ('+W'),
  20297. ('+X'), ('+Y'), ('+Z'), ('%P'), ('%Q'), ('%R'), ('%S'), ('%T'));
  20298. BARCode_93x : array[0..127] of string[2] =
  20299. ((']U'), ('[A'), ('[B'), ('[C'), ('[D'), ('[E'), ('[F'), ('[G'),
  20300. ('[H'), ('[I'), ('[J'), ('[K'), ('[L'), ('[M'), ('[N'), ('[O'),
  20301. ('[P'), ('[Q'), ('[R'), ('[S'), ('[T'), ('[U'), ('[V'), ('[W'),
  20302. ('[X'), ('[Y'), ('[Z'), (']A'), (']B'), (']C'), (']D'), (']E'),
  20303. (' ' ), ('{A'), ('{B'), ('{C'), ('{D'), ('{E'), ('{F'), ('{G'),
  20304. ('{H'), ('{I'), ('{J'), ('{K'), ('{L'), ('{M'), ('{N'), ('{O'),
  20305. ('0' ), ('1' ), ('2' ), ('3' ), ('4' ), ('5' ), ('6' ), ('7' ),
  20306. ('8' ), ('9' ), ('{Z'), (']F'), (']G'), (']H'), (']I'), (']J'),
  20307. (']V'), ('A' ), ('B' ), ('C' ), ('D' ), ('E' ), ('F' ), ('G' ),
  20308. ('H' ), ('I' ), ('J' ), ('K' ), ('L' ), ('M' ), ('N' ), ('O' ),
  20309. ('P' ), ('Q' ), ('R' ), ('S' ), ('T' ), ('U' ), ('V' ), ('W' ),
  20310. ('X' ), ('Y' ), ('Z' ), (']K'), (']L'), (']M'), (']N'), (']O'),
  20311. (']W'), ('}A'), ('}B'), ('}C'), ('}D'), ('}E'), ('}F'), ('}G'),
  20312. ('}H'), ('}I'), ('}J'), ('}K'), ('}L'), ('}M'), ('}N'), ('}O'),
  20313. ('}P'), ('}Q'), ('}R'), ('}S'), ('}T'), ('}U'), ('}V'), ('}W'),
  20314. ('}X'), ('}Y'), ('}Z'), (']P'), (']Q'), (']R'), (']S'), (']T'));
  20315. BARCode_93: array[0..46] of TCode93 =
  20316. ((c:'0'; data:'131112'), (c:'1'; data:'111213'), (c:'2'; data:'111312'),
  20317. (c:'3'; data:'111411'), (c:'4'; data:'121113'), (c:'5'; data:'121212'),
  20318. (c:'6'; data:'121311'), (c:'7'; data:'111114'), (c:'8'; data:'131211'),
  20319. (c:'9'; data:'141111'), (c:'A'; data:'211113'), (c:'B'; data:'211212'),
  20320. (c:'C'; data:'211311'), (c:'D'; data:'221112'), (c:'E'; data:'221211'),
  20321. (c:'F'; data:'231111'), (c:'G'; data:'112113'), (c:'H'; data:'112212'),
  20322. (c:'I'; data:'112311'), (c:'J'; data:'122112'), (c:'K'; data:'132111'),
  20323. (c:'L'; data:'111123'), (c:'M'; data:'111222'), (c:'N'; data:'111321'),
  20324. (c:'O'; data:'121122'), (c:'P'; data:'131121'), (c:'Q'; data:'212112'),
  20325. (c:'R'; data:'212211'), (c:'S'; data:'211122'), (c:'T'; data:'211221'),
  20326. (c:'U'; data:'221121'), (c:'V'; data:'222111'), (c:'W'; data:'112122'),
  20327. (c:'X'; data:'112221'), (c:'Y'; data:'122121'), (c:'Z'; data:'123111'),
  20328. (c:'-'; data:'121131'), (c:'.'; data:'311112'), (c:' '; data:'311211'),
  20329. (c:'$'; data:'321111'), (c:'/'; data:'112131'), (c:'+'; data:'113121'),
  20330. (c:'%'; data:'211131'),
  20331. (c:'['; data:'121221'), // only used for Extended Code 93
  20332. (c:']'; data:'312111'), // only used for Extended Code 93
  20333. (c:'{'; data:'311121'), // only used for Extended Code 93
  20334. (c:'}'; data:'122211')); // only used for Extended Code 93
  20335. BARCode_39: array[0..43] of TCode39 =
  20336. ((c:'0'; data:'505160605'; chk:0 ), (c:'1'; data:'605150506'; chk:1 ),
  20337. (c:'2'; data:'506150506'; chk:2 ), (c:'3'; data:'606150505'; chk:3 ),
  20338. (c:'4'; data:'505160506'; chk:4 ), (c:'5'; data:'605160505'; chk:5 ),
  20339. (c:'6'; data:'506160505'; chk:6 ), (c:'7'; data:'505150606'; chk:7 ),
  20340. (c:'8'; data:'605150605'; chk:8 ), (c:'9'; data:'506150605'; chk:9 ),
  20341. (c:'A'; data:'605051506'; chk:10), (c:'B'; data:'506051506'; chk:11),
  20342. (c:'C'; data:'606051505'; chk:12), (c:'D'; data:'505061506'; chk:13),
  20343. (c:'E'; data:'605061505'; chk:14), (c:'F'; data:'506061505'; chk:15),
  20344. (c:'G'; data:'505051606'; chk:16), (c:'H'; data:'605051605'; chk:17),
  20345. (c:'I'; data:'506051600'; chk:18), (c:'J'; data:'505061605'; chk:19),
  20346. (c:'K'; data:'605050516'; chk:20), (c:'L'; data:'506050516'; chk:21),
  20347. (c:'M'; data:'606050515'; chk:22), (c:'N'; data:'505060516'; chk:23),
  20348. (c:'O'; data:'605060515'; chk:24), (c:'P'; data:'506060515'; chk:25),
  20349. (c:'Q'; data:'505050616'; chk:26), (c:'R'; data:'605050615'; chk:27),
  20350. (c:'S'; data:'506050615'; chk:28), (c:'T'; data:'505060615'; chk:29),
  20351. (c:'U'; data:'615050506'; chk:30), (c:'V'; data:'516050506'; chk:31),
  20352. (c:'W'; data:'616050505'; chk:32), (c:'X'; data:'515060506'; chk:33),
  20353. (c:'Y'; data:'615060505'; chk:34), (c:'Z'; data:'516060505'; chk:35),
  20354. (c:'-'; data:'515050606'; chk:36), (c:'.'; data:'615050605'; chk:37),
  20355. (c:' '; data:'516050605'; chk:38), (c:'*'; data:'515060605'; chk:0 ),
  20356. (c:'$'; data:'515151505'; chk:39), (c:'/'; data:'515150515'; chk:40),
  20357. (c:'+'; data:'515051515'; chk:41), (c:'%'; data:'505151515'; chk:42));
  20358. BARCode_128: array[0..102] of TCode128 =
  20359. ((a:' '; b:' '; c:'00'; data:'212222'; ),
  20360. (a:'!'; b:'!'; c:'01'; data:'222122'; ),
  20361. (a:'"'; b:'"'; c:'02'; data:'222221'; ),
  20362. (a:'#'; b:'#'; c:'03'; data:'121223'; ),
  20363. (a:'$'; b:'$'; c:'04'; data:'121322'; ),
  20364. (a:'%'; b:'%'; c:'05'; data:'131222'; ),
  20365. (a:'&'; b:'&'; c:'06'; data:'122213'; ),
  20366. (a:'''';b:'''';c:'07'; data:'122312'; ),
  20367. (a:'('; b:'('; c:'08'; data:'132212'; ),
  20368. (a:')'; b:')'; c:'09'; data:'221213'; ),
  20369. (a:'*'; b:'*'; c:'10'; data:'221312'; ),
  20370. (a:'+'; b:'+'; c:'11'; data:'231212'; ),
  20371. (a:'?'; b:'?'; c:'12'; data:'112232'; ),
  20372. (a:'-'; b:'-'; c:'13'; data:'122132'; ),
  20373. (a:'.'; b:'.'; c:'14'; data:'122231'; ),
  20374. (a:'/'; b:'/'; c:'15'; data:'113222'; ),
  20375. (a:'0'; b:'0'; c:'16'; data:'123122'; ),
  20376. (a:'1'; b:'1'; c:'17'; data:'123221'; ),
  20377. (a:'2'; b:'2'; c:'18'; data:'223211'; ),
  20378. (a:'3'; b:'3'; c:'19'; data:'221132'; ),
  20379. (a:'4'; b:'4'; c:'20'; data:'221231'; ),
  20380. (a:'5'; b:'5'; c:'21'; data:'213212'; ),
  20381. (a:'6'; b:'6'; c:'22'; data:'223112'; ),
  20382. (a:'7'; b:'7'; c:'23'; data:'312131'; ),
  20383. (a:'8'; b:'8'; c:'24'; data:'311222'; ),
  20384. (a:'9'; b:'9'; c:'25'; data:'321122'; ),
  20385. (a:':'; b:':'; c:'26'; data:'321221'; ),
  20386. (a:';'; b:';'; c:'27'; data:'312212'; ),
  20387. (a:'<'; b:'<'; c:'28'; data:'322112'; ),
  20388. (a:'='; b:'='; c:'29'; data:'322211'; ),
  20389. (a:'>'; b:'>'; c:'30'; data:'212123'; ),
  20390. (a:'?'; b:'?'; c:'31'; data:'212321'; ),
  20391. (a:'@'; b:'@'; c:'32'; data:'232121'; ),
  20392. (a:'A'; b:'A'; c:'33'; data:'111323'; ),
  20393. (a:'B'; b:'B'; c:'34'; data:'131123'; ),
  20394. (a:'C'; b:'C'; c:'35'; data:'131321'; ),
  20395. (a:'D'; b:'D'; c:'36'; data:'112313'; ),
  20396. (a:'E'; b:'E'; c:'37'; data:'132113'; ),
  20397. (a:'F'; b:'F'; c:'38'; data:'132311'; ),
  20398. (a:'G'; b:'G'; c:'39'; data:'211313'; ),
  20399. (a:'H'; b:'H'; c:'40'; data:'231113'; ),
  20400. (a:'I'; b:'I'; c:'41'; data:'231311'; ),
  20401. (a:'J'; b:'J'; c:'42'; data:'112133'; ),
  20402. (a:'K'; b:'K'; c:'43'; data:'112331'; ),
  20403. (a:'L'; b:'L'; c:'44'; data:'132131'; ),
  20404. (a:'M'; b:'M'; c:'45'; data:'113123'; ),
  20405. (a:'N'; b:'N'; c:'46'; data:'113321'; ),
  20406. (a:'O'; b:'O'; c:'47'; data:'133121'; ),
  20407. (a:'P'; b:'P'; c:'48'; data:'313121'; ),
  20408. (a:'Q'; b:'Q'; c:'49'; data:'211331'; ),
  20409. (a:'R'; b:'R'; c:'50'; data:'231131'; ),
  20410. (a:'S'; b:'S'; c:'51'; data:'213113'; ),
  20411. (a:'T'; b:'T'; c:'52'; data:'213311'; ),
  20412. (a:'U'; b:'U'; c:'53'; data:'213131'; ),
  20413. (a:'V'; b:'V'; c:'54'; data:'311123'; ),
  20414. (a:'W'; b:'W'; c:'55'; data:'311321'; ),
  20415. (a:'X'; b:'X'; c:'56'; data:'331121'; ),
  20416. (a:'Y'; b:'Y'; c:'57'; data:'312113'; ),
  20417. (a:'Z'; b:'Z'; c:'58'; data:'312311'; ),
  20418. (a:'['; b:'['; c:'59'; data:'332111'; ),
  20419. (a:'\'; b:'\'; c:'60'; data:'314111'; ),
  20420. (a:']'; b:']'; c:'61'; data:'221411'; ),
  20421. (a:'^'; b:'^'; c:'62'; data:'431111'; ),
  20422. (a:'_'; b:'_'; c:'63'; data:'111224'; ),
  20423. (a:' '; b:'`'; c:'64'; data:'111422'; ),
  20424. (a:' '; b:'a'; c:'65'; data:'121124'; ),
  20425. (a:' '; b:'b'; c:'66'; data:'121421'; ),
  20426. (a:' '; b:'c'; c:'67'; data:'141122'; ),
  20427. (a:' '; b:'d'; c:'68'; data:'141221'; ),
  20428. (a:' '; b:'e'; c:'69'; data:'112214'; ),
  20429. (a:' '; b:'f'; c:'70'; data:'112412'; ),
  20430. (a:' '; b:'g'; c:'71'; data:'122114'; ),
  20431. (a:' '; b:'h'; c:'72'; data:'122411'; ),
  20432. (a:' '; b:'i'; c:'73'; data:'142112'; ),
  20433. (a:' '; b:'j'; c:'74'; data:'142211'; ),
  20434. (a:' '; b:'k'; c:'75'; data:'241211'; ),
  20435. (a:' '; b:'l'; c:'76'; data:'221114'; ),
  20436. (a:' '; b:'m'; c:'77'; data:'413111'; ),
  20437. (a:' '; b:'n'; c:'78'; data:'241112'; ),
  20438. (a:' '; b:'o'; c:'79'; data:'134111'; ),
  20439. (a:' '; b:'p'; c:'80'; data:'111242'; ),
  20440. (a:' '; b:'q'; c:'81'; data:'121142'; ),
  20441. (a:' '; b:'r'; c:'82'; data:'121241'; ),
  20442. (a:' '; b:'s'; c:'83'; data:'114212'; ),
  20443. (a:' '; b:'t'; c:'84'; data:'124112'; ),
  20444. (a:' '; b:'u'; c:'85'; data:'124211'; ),
  20445. (a:' '; b:'v'; c:'86'; data:'411212'; ),
  20446. (a:' '; b:'w'; c:'87'; data:'421112'; ),
  20447. (a:' '; b:'x'; c:'88'; data:'421211'; ),
  20448. (a:' '; b:'y'; c:'89'; data:'212141'; ),
  20449. (a:' '; b:'z'; c:'90'; data:'214121'; ),
  20450. (a:' '; b:'{'; c:'91'; data:'412121'; ),
  20451. (a:' '; b:'|'; c:'92'; data:'111143'; ),
  20452. (a:' '; b:'}'; c:'93'; data:'111341'; ),
  20453. (a:' '; b:'~'; c:'94'; data:'131141'; ),
  20454. (a:' '; b:' '; c:'95'; data:'114113'; ),
  20455. (a:' '; b:' '; c:'96'; data:'114311'; ),
  20456. (a:' '; b:' '; c:'97'; data:'411113'; ),
  20457. (a:' '; b:' '; c:'98'; data:'411311'; ),
  20458. (a:' '; b:' '; c:'99'; data:'113141'; ),
  20459. (a:' '; b:' '; c:' '; data:'114131'; ),
  20460. (a:' '; b:' '; c:' '; data:'311141'; ),
  20461. (a:' '; b:' '; c:' '; data:'411131'; ));
  20462. BCData:array[Code25IL..UPC_S5] of TBCData =
  20463. ((Name:'Code InterLeaved 2.5'; num:True),
  20464. (Name:'Code Industrial 2.5'; num:True),
  20465. (Name:'Code Matrix 2.5'; num:True),
  20466. (Name:'Code 39'; num:False),
  20467. (Name:'Code 39 Extended'; num:False),
  20468. (Name:'Code 128A'; num:False),
  20469. (Name:'Code 128B'; num:False),
  20470. (Name:'Code 128C'; num:True),
  20471. (Name:'Code 93'; num:False),
  20472. (Name:'Code 93 Extended'; num:False),
  20473. (Name:'Code MSI'; num:True),
  20474. (Name:'Code PostNet'; num:True),
  20475. (Name:'Codabar'; num:False),
  20476. (Name:'EAN-8'; num:True),
  20477. (Name:'EAN-13'; num:True),
  20478. (Name:'EAN-128A'; num:False),
  20479. (Name:'EAN-128B'; num:False),
  20480. (Name:'EAN-128C'; num:True),
  20481. (Name:'UPC-A'; num:True),
  20482. (Name:'UPC-EODD'; num:True),
  20483. (Name:'UPC-EVEN'; num:True),
  20484. (Name:'UPC-Supp2'; num:True),
  20485. (Name:'UPC-Supp5'; num:True));
  20486. {assist function}
  20487. function getSupp(Nr : String) : String;
  20488. var i,fak,sum : Integer;
  20489. tmp : String;
  20490. begin
  20491. sum := 0;
  20492. tmp := copy(nr,1,Length(Nr)-1);
  20493. fak := Length(tmp);
  20494. for i:=1 to length(tmp) do
  20495. begin
  20496. if (fak mod 2) = 0 then
  20497. sum := sum + (StrToInt(tmp[i])*9)
  20498. else
  20499. sum := sum + (StrToInt(tmp[i])*3);
  20500. dec(fak);
  20501. end;
  20502. sum:=((sum mod 10) mod 10) mod 10;
  20503. result := tmp+IntToStr(sum);
  20504. end;
  20505. {$ifndef WIN32}
  20506. function Trim(const S: string): string; export;
  20507. { Removes leading and trailing whitespace from s}
  20508. var
  20509. I, L: Integer;
  20510. begin
  20511. L := Length(S);
  20512. I := 1;
  20513. while (I <= L) and (S[I] <= ' ') do Inc(I);
  20514. if I > L then Result := '' else
  20515. begin
  20516. while S[L] <= ' ' do Dec(L);
  20517. Result := Copy(S, I, L - I + 1);
  20518. end;
  20519. end;
  20520. {$endif}
  20521. function Convert(s:string): string;
  20522. var i, v : integer;
  20523. t : string;
  20524. begin
  20525. t := '';
  20526. for i:=1 to Length(s) do
  20527. begin
  20528. v := ord(s[i]) - 1;
  20529. if odd(i) then
  20530. Inc(v, 5);
  20531. t := t + Chr(v);
  20532. end;
  20533. Convert := t;
  20534. end;
  20535. function Quersumme(x:integer):integer;
  20536. var sum:integer;
  20537. begin
  20538. sum := 0;
  20539. while x > 0 do
  20540. begin
  20541. sum := sum + (x mod 10);
  20542. x := x div 10;
  20543. end;
  20544. result := sum;
  20545. end;
  20546. constructor TDefineBarcode.Create(Owner:TComponent);
  20547. begin
  20548. fBitmap := TBitmap.Create;
  20549. inherited Create(owner);
  20550. Font.OnChange := FontChange;
  20551. Height := 50;
  20552. Width := 100;
  20553. fBarColor := clBlack;
  20554. fColor := clWhite;
  20555. fRotateType := raNone;
  20556. fAutoSize := true;
  20557. fRatio := 2.0;
  20558. fModul := 1;
  20559. fCodeType := EAN13;
  20560. fBarHeight := 35;
  20561. fBorderWidth := 5;
  20562. fBarTop := 5;
  20563. fCheckSum := FALSE;
  20564. fShowText := True;
  20565. fTransparent := false;
  20566. fCheckOdd := true;
  20567. fText := '0123456789';
  20568. end;
  20569. destructor TDefineBarcode.destroy;
  20570. begin
  20571. fBitmap.Free;
  20572. inherited Destroy;
  20573. end;
  20574. function TDefineBarcode.SetLen(pI: byte): string;
  20575. begin
  20576. Result := fText;
  20577. while Length(Result) < pI do
  20578. Result:=Result+'0';
  20579. end;
  20580. function TDefineBarcode.DoCheckSumming(const Data: string;OddCheck:Boolean=True): string;
  20581. var i,sum,s : Integer;
  20582. begin
  20583. sum := 0;
  20584. for i:=1 to Length(data) do
  20585. begin
  20586. s := StrToInt(Data[i]);
  20587. if OddCheck then
  20588. begin
  20589. if odd(i) then
  20590. sum := sum + s
  20591. else
  20592. sum := sum + s*3;
  20593. end
  20594. else
  20595. begin
  20596. if odd(i) then
  20597. sum := sum + s*3
  20598. else
  20599. sum := sum + s;
  20600. end;
  20601. end;
  20602. if (sum mod 10) = 0 then
  20603. result := data+'0'
  20604. else
  20605. result := data+IntToStr(10-(sum mod 10));
  20606. end;
  20607. function TDefineBarcode.GetCheckLen(CodeType:TDefineBarcodeType;Data:String): string;
  20608. begin
  20609. result := Data;
  20610. case CodeType of
  20611. EAN13:Begin
  20612. if Length(Result)>12 then
  20613. result := Copy(Result,1,12)
  20614. else
  20615. result := SetLen(12);
  20616. result := DoCheckSumming(Result,fCheckOdd);
  20617. end;
  20618. EAN8:begin
  20619. if Length(Result)>7 then
  20620. result := Copy(Result,1,7)
  20621. else
  20622. result := SetLen(7);
  20623. result := DoCheckSumming(result,fCheckOdd);
  20624. end;
  20625. UPC_A:begin
  20626. if Length(Result)>11 then
  20627. result := Copy(Result,1,11)
  20628. else
  20629. result := SetLen(11);
  20630. result := DoCheckSumming(result,fCheckOdd);
  20631. end;
  20632. UPC_EODD,UPC_EVEN:
  20633. begin
  20634. if Length(Result)>6 then
  20635. result := Copy(Result,1,6)
  20636. else
  20637. result := SetLen(6);
  20638. result := DoCheckSumming(result,fCheckOdd);
  20639. end;
  20640. UPC_S2:
  20641. begin
  20642. if Length(Result)>2 then
  20643. result := Copy(Result,1,2)
  20644. else
  20645. result := SetLen(2);
  20646. result := getSupp(copy(Result,1,2)+'0');
  20647. end;
  20648. UPC_S5:
  20649. begin
  20650. if Length(Result)>5 then
  20651. result := Copy(Result,1,5)
  20652. else
  20653. result := SetLen(5);
  20654. result := getSupp(copy(Result,1,5)+'0');
  20655. end;
  20656. end;
  20657. end;
  20658. function TDefineBarcode.ClearNotText(Value:String): string;
  20659. var inx:Integer;TempValue: string;
  20660. begin
  20661. result := '';
  20662. case CodeType of
  20663. Code25IL, Code25IT, Code25Mx,
  20664. CodeMSI, PostNet, EAN13, EAN8,
  20665. UPC_A, UPC_EODD, UPC_EVEN, UPC_S2,
  20666. Code128C,EAN128A,EAN128B,EAN128C,
  20667. UPC_S5: begin
  20668. TempValue := UpperCase(Value);
  20669. for inx:=1 to Length(TempValue) do
  20670. if TempValue[Inx] in ['0'..'9'] then
  20671. result := result + TempValue[Inx];
  20672. result := GetCheckLen(CodeType,result);
  20673. end;
  20674. Codabar:begin
  20675. TempValue := UpperCase(Value);
  20676. for inx:=1 to Length(TempValue) do
  20677. if TempValue[Inx] in ['0'..'9','A'..'B','-','$',':','/','.','+'] then
  20678. Result := result + TempValue[Inx];
  20679. end;
  20680. Code39, Code93:
  20681. Begin
  20682. result := UpperCase(Value);
  20683. end;
  20684. Code93Ext:
  20685. Begin
  20686. for inx:=0 to Length(Value) do
  20687. begin
  20688. if ord(Value[inx]) <= 127 then
  20689. result := result + BARCode_93x[ord(Value[inx])];
  20690. end;
  20691. end;
  20692. Code39Ext:
  20693. begin
  20694. for inx:=0 to Length(Value) do
  20695. begin
  20696. if ord(value[inx]) <= 127 then
  20697. result := result + BARCode_39x[ord(value[inx])];
  20698. end;
  20699. end;
  20700. else
  20701. result := Value;
  20702. end;
  20703. end;
  20704. function TDefineBarcode.MakeBarText: String;
  20705. begin
  20706. result := ClearNotText(fText);
  20707. end;
  20708. function TDefineBarcode.Code_25ILeaved: string;
  20709. var i, j: integer;
  20710. c : char;
  20711. begin
  20712. result := result + '5050'; // Startcode
  20713. for i:=1 to Length(BarText) div 2 do
  20714. begin
  20715. for j:= 1 to 5 do
  20716. begin
  20717. if BARCode_25[BarText[i*2-1], j] = '1' then
  20718. c := '6'
  20719. else
  20720. c := '5';
  20721. result := result + c;
  20722. if BARCode_25[BarText[i*2], j] = '1' then
  20723. c := '1'
  20724. else
  20725. c := '0';
  20726. result := result + c;
  20727. end;
  20728. end;
  20729. result := result + '605'; // Stopcode
  20730. end;
  20731. function TDefineBarcode.Code_25ITrial: string;
  20732. var i, j: integer;
  20733. begin
  20734. result := result + '606050'; // Startcode
  20735. for i:=1 to Length(BarText) do
  20736. begin
  20737. for j:= 1 to 5 do
  20738. begin
  20739. if BARCode_25[BarText[i], j] = '1' then
  20740. result := result + '60'
  20741. else
  20742. result := result + '50';
  20743. end;
  20744. end;
  20745. result := result + '605060'; // Stopcode
  20746. end;
  20747. function TDefineBarcode.Code_25Matrix: string;
  20748. var i, j: integer;c :char;
  20749. begin
  20750. result := result + '705050'; // Startcode
  20751. for i:=1 to Length(BarText) do
  20752. begin
  20753. for j:= 1 to 5 do
  20754. begin
  20755. if BARCode_25[BarText[i], j] = '1' then
  20756. c := '1'
  20757. else
  20758. c := '0';
  20759. if odd(j) then
  20760. c := chr(ord(c)+5);
  20761. result := result + c;
  20762. end;
  20763. result := result + '0'; // L點ke zwischen den Zeichen
  20764. end;
  20765. result := result + '70505'; // Stopcode
  20766. end;
  20767. function TDefineBarcode.Code_39: string;
  20768. function FindIdx(z:char):integer;
  20769. var i:integer;
  20770. begin
  20771. for i:=0 to High(BARCode_39) do
  20772. begin
  20773. if z = BARCode_39[i].c then
  20774. begin
  20775. result := i;
  20776. exit;
  20777. end;
  20778. end;
  20779. result := -1;
  20780. end;
  20781. var i, idx , checksum:integer;
  20782. begin
  20783. checksum := 0;// Startcode
  20784. result := BARCode_39[FindIdx('*')].data + '0';
  20785. for i:=1 to Length(BarText) do
  20786. begin
  20787. idx := FindIdx(BarText[i]);
  20788. if idx < 0 then
  20789. continue;
  20790. result := result + BARCode_39[idx].data + '0';
  20791. Inc(checksum, BARCode_39[idx].chk);
  20792. end;// Calculate Checksum Data
  20793. if FCheckSum then
  20794. begin
  20795. checksum := checksum mod 43;
  20796. for i:=0 to High(BARCode_39) do
  20797. if checksum = BARCode_39[i].chk then
  20798. begin
  20799. result := result + BARCode_39[i].data + '0';
  20800. break;
  20801. end;
  20802. end;// Stopcode
  20803. result := result + BARCode_39[FindIdx('*')].data;
  20804. end;
  20805. {Code 128}
  20806. function TDefineBarcode.Code_128: string;
  20807. function Find_Code128AB(c:char):integer; // find Code 128 Codeset A or B
  20808. var i:integer; v:char;
  20809. begin
  20810. for i:=0 to High(BARCode_128) do
  20811. begin
  20812. if FCodeType = Code128A then
  20813. v := BARCode_128[i].a
  20814. else
  20815. v := BARCode_128[i].b;
  20816. if c = v then
  20817. begin
  20818. result := i;
  20819. exit;
  20820. end;
  20821. end;
  20822. result := -1;
  20823. end;
  20824. function Find_Code128C(c:String):integer; // find Code 128 Codeset C
  20825. var i:integer;
  20826. begin
  20827. for i:=0 to High(BARCode_128) do
  20828. begin
  20829. if c = BARCode_128[i].C then
  20830. begin
  20831. result := i;
  20832. exit;
  20833. end;
  20834. end;
  20835. result := -1;
  20836. end;
  20837. var i, idx , j: integer;
  20838. startcode,Tmp: string;
  20839. checksum : integer;
  20840. codeword_pos : integer;
  20841. begin
  20842. checksum := 103;
  20843. case CodeType of
  20844. Code128A,EAN128A: begin checksum := 103; startcode:= StartA; end;
  20845. Code128B,EAN128B: begin checksum := 104; startcode:= StartB; end;
  20846. Code128C,EAN128C: begin checksum := 105; startcode:= StartC; end;
  20847. end;
  20848. result := Convert(startcode); // Startcode
  20849. codeword_pos := 1;
  20850. Tmp := BarText;
  20851. case CodeType of
  20852. EAN128A,
  20853. EAN128B,
  20854. EAN128C:
  20855. begin
  20856. result := result + Convert(BARCode_128[102].data);
  20857. inc(checksum, 102*codeword_pos);
  20858. Inc(codeword_pos);
  20859. if FCheckSum then Tmp:=DoCheckSumming(Tmp);
  20860. end;
  20861. end;
  20862. if (CodeType = Code128C) or (CodeType = EAN128C) then
  20863. begin
  20864. if ODD(Length(Tmp)) then //check Length(Tmp) for ODD or EVEN;//
  20865. Tmp:='0'+Tmp;
  20866. for i:=1 to (Length(Tmp) div 2) do
  20867. begin
  20868. j:=(i-1)*2+1;
  20869. idx:=Find_Code128C(copy(Tmp,j,2));
  20870. if idx < 0 then
  20871. idx := Find_Code128C('00');
  20872. result := result + Convert(BARCode_128[idx].data);
  20873. Inc(checksum, idx*codeword_pos);
  20874. Inc(codeword_pos);
  20875. end;
  20876. end
  20877. else
  20878. for i:=1 to Length(Tmp) do
  20879. begin
  20880. idx := Find_Code128AB(Tmp[i]);
  20881. if idx < 0 then
  20882. idx := Find_Code128AB(' ');
  20883. result := result + Convert(BARCode_128[idx].data);
  20884. Inc(checksum, idx*i);
  20885. end;
  20886. checksum := checksum mod 103;
  20887. result := result + Convert(BARCode_128[checksum].data);
  20888. result := result + Convert(Stop); {Stopcode}
  20889. end;
  20890. function TDefineBarcode.Code_93: string;
  20891. function Find_Code93(c:char):integer;// find Code 93
  20892. var i:integer;
  20893. begin
  20894. for i:=0 to High(BARCode_93) do
  20895. begin
  20896. if c = BARCode_93[i].c then
  20897. begin
  20898. result := i;
  20899. exit;
  20900. end;
  20901. end;
  20902. result := -1;
  20903. end;
  20904. var i, idx : integer;
  20905. checkC, checkK, // Checksums
  20906. weightC, weightK : integer;
  20907. begin
  20908. result := Convert('111141');
  20909. for i:=1 to Length(BarText) do
  20910. begin
  20911. idx := Find_Code93(BarText[i]);
  20912. if idx < 0 then
  20913. raise Exception.CreateFmt('%s:Code93 bad Data <%s>', [self.ClassName,BarText]);
  20914. result := result + Convert(BARCode_93[idx].data);
  20915. end;
  20916. checkC := 0;
  20917. checkK := 0;
  20918. weightC := 1;
  20919. weightK := 2;
  20920. for i:=Length(BarText) downto 1 do
  20921. begin
  20922. idx := Find_Code93(BarText[i]);
  20923. Inc(checkC, idx*weightC);
  20924. Inc(checkK, idx*weightK);
  20925. Inc(weightC);
  20926. if weightC > 20 then weightC := 1;
  20927. Inc(weightK);
  20928. if weightK > 15 then weightC := 1;
  20929. end;
  20930. Inc(checkK, checkC);
  20931. checkC := checkC mod 47;
  20932. checkK := checkK mod 47;
  20933. result := result + Convert(BARCode_93[checkC].data) +
  20934. Convert(BARCode_93[checkK].data);
  20935. result := result + Convert('1111411'); // Stopcode
  20936. end;
  20937. function TDefineBarcode.Code_MSI: string;
  20938. var i,check_even, check_odd, checksum:integer;
  20939. begin
  20940. result := '60'; // Startcode
  20941. check_even := 0;
  20942. check_odd := 0;
  20943. for i:=1 to Length(BarText) do
  20944. begin
  20945. if odd(i-1) then
  20946. check_odd := check_odd*10+ord(BarText[i])
  20947. else
  20948. check_even := check_even+ord(BarText[i]);
  20949. result := result + BARCode_MSI[BarText[i]];
  20950. end;
  20951. checksum := quersumme(check_odd*2) + check_even;
  20952. checksum := checksum mod 10;
  20953. if checksum > 0 then
  20954. checksum := 10-checksum;
  20955. result := result + BARCode_MSI[chr(ord('0')+checksum)];
  20956. result := result + '515'; // Stopcode
  20957. end;
  20958. function TDefineBarcode.Code_PostNet: string;
  20959. var i:integer;
  20960. begin
  20961. result := '51';
  20962. for i:=1 to Length(BarText) do
  20963. begin
  20964. result := result + BARCode_PostNet[BarText[i]];
  20965. end;
  20966. result := result + '5';
  20967. end;
  20968. function TDefineBarcode.Code_CodaBar: string;
  20969. function Find_Codabar(c:char):integer;
  20970. var i:integer;
  20971. begin
  20972. for i:=0 to High(BARCode_Codabar) do
  20973. begin
  20974. if c = BARCode_Codabar[i].c then
  20975. begin
  20976. result := i;
  20977. exit;
  20978. end;
  20979. end;
  20980. result := -1;
  20981. end;
  20982. var i, idx : integer;
  20983. begin
  20984. result := BARCode_Codabar[Find_Codabar('A')].data + '0';
  20985. for i:=1 to Length(BarText) do
  20986. begin
  20987. idx := Find_Codabar(BarText[i]);
  20988. result := result + BARCode_Codabar[idx].data + '0';
  20989. end;
  20990. result := result + BARCode_Codabar[Find_Codabar('B')].data;
  20991. // result := result + BARCode_Codabar[Find_Codabar('A')].data;
  20992. end;
  20993. function TDefineBarcode.Code_EAN13: string;
  20994. var I, LK: integer;
  20995. tmp : String;
  20996. begin
  20997. LK := StrToInt(BarText[1]);
  20998. tmp := copy(BarText,2,12);
  20999. result := '505';{Startcode}
  21000. for i:=1 to 6 do
  21001. begin
  21002. case BARCode_ParityEAN13[LK,i] of
  21003. 'A' : result := result + BARCode_EAN_A[tmp[i]];
  21004. 'B' : result := result + BARCode_EAN_B[tmp[i]] ;
  21005. 'C' : result := result + BARCode_EAN_C[tmp[i]] ;
  21006. end;
  21007. end;
  21008. result := result + '05050';{Center Guard Pattern}
  21009. for i:=7 to 12 do
  21010. result := result + BARCode_EAN_C[tmp[i]] ;
  21011. result := result + '505';{Stopcode}
  21012. end;
  21013. function TDefineBarcode.Code_EAN8: string;
  21014. var i : integer;
  21015. begin
  21016. result := '505';{Startcode}
  21017. for i:=1 to 4 do
  21018. result := result + BARCode_EAN_A[BarText[i]] ;
  21019. result := result + '05050';{Center Guard Pattern}
  21020. for i:=5 to 8 do
  21021. result := result + BARCode_EAN_C[BarText[i]] ;
  21022. result := result + '505';{Stopcode}
  21023. end;
  21024. function TDefineBarcode.Code_Supp2: string;
  21025. var i,j : integer;
  21026. mS : String;
  21027. begin
  21028. i:=StrToInt(Copy(BarText,1,2));
  21029. case i mod 4 of
  21030. 3: mS:='EE';
  21031. 2: mS:='EO';
  21032. 1: mS:='OE';
  21033. 0: mS:='OO';
  21034. end;
  21035. result := '506';{Startcode}
  21036. for i:=1 to 2 do
  21037. begin
  21038. if mS[i]='E' then
  21039. begin
  21040. for j:= 1 to 4 do
  21041. result := result + BARCode_EAN_C[BarText[i],5-j];
  21042. end
  21043. else
  21044. begin
  21045. result := result + BARCode_EAN_A[BarText[i]];
  21046. end;
  21047. if i<2 then
  21048. result:=result+'05'; // character delineator
  21049. end;
  21050. end;
  21051. function TDefineBarcode.Code_Supp5: string;
  21052. var i,j : integer;
  21053. c : char;
  21054. begin
  21055. c:=BarText[6];
  21056. result := '506';{Startcode}
  21057. for i:=1 to 5 do
  21058. begin
  21059. if BARCode_UPC_E[c,(6-5)+i]='E' then
  21060. begin
  21061. for j:= 1 to 4 do result := result + BARCode_EAN_C[BarText[i],5-j];
  21062. end
  21063. else
  21064. begin
  21065. result := result + BARCode_EAN_A[BarText[i]];
  21066. end;
  21067. if i<5 then result:=result+'05'; // character delineator
  21068. end;
  21069. end;
  21070. function TDefineBarcode.Code_UPC_A: string;
  21071. var i : integer;
  21072. begin
  21073. result := '505';{Startcode}
  21074. for i:=1 to 6 do
  21075. result := result + BARCode_EAN_A[BarText[i]];
  21076. result := result + '05050';{Trennzeichen}
  21077. for i:=7 to 12 do
  21078. result := result + BARCode_EAN_C[BarText[i]];
  21079. result := result + '505';{Stopcode}
  21080. end;
  21081. function TDefineBarcode.Code_UPC_EODD: string;
  21082. var i,j : integer;
  21083. c : char;
  21084. begin
  21085. c:=BarText[7];
  21086. result := '505';{Startcode}
  21087. for i:=1 to 6 do
  21088. begin
  21089. if BARCode_UPC_E[c,i]='E' then
  21090. begin
  21091. for j:= 1 to 4 do
  21092. result := result + BARCode_EAN_C[BarText[i],5-j];
  21093. end
  21094. else
  21095. begin
  21096. result := result + BARCode_EAN_A[BarText[i]];
  21097. end;
  21098. end;
  21099. result := result + '0505';{Stopcode}
  21100. end;
  21101. function TDefineBarcode.Code_UPC_EVEN: string;
  21102. var i,j : integer;
  21103. c : char;
  21104. begin
  21105. c:=BarText[7];
  21106. result := '505';{Startcode}
  21107. for i:=1 to 6 do
  21108. begin
  21109. if BARCode_UPC_E[c,i]='E' then
  21110. begin
  21111. result := result + BARCode_EAN_A[BarText[i]];
  21112. end
  21113. else
  21114. begin
  21115. for j:= 1 to 4 do
  21116. result := result + BARCode_EAN_C[BarText[i],5-j];
  21117. end;
  21118. end;
  21119. result := result + '0505';{Stopcode}
  21120. end;
  21121. procedure TDefineBarcode.GetABCED(Var a,b,c,d,orgin:TPoint;xadd,Width,Height:Integer);
  21122. begin
  21123. a.x := xadd;
  21124. a.y := Orgin.y;//0
  21125. b.x := xadd;
  21126. b.y := Orgin.y+height;
  21127. c.x := xadd+width-1;
  21128. c.y := Orgin.y+height;
  21129. d.x := xadd+width-1;
  21130. d.y := Orgin.y;//0
  21131. end;
  21132. function TDefineBarcode.MakeData;
  21133. begin
  21134. case CodeType of
  21135. Code25IL : result := Code_25ILeaved;
  21136. Code25IT : result := Code_25ITrial;
  21137. Code25Mx : result := Code_25Matrix;
  21138. Code39,
  21139. Code39Ext : result := Code_39;
  21140. Code93,
  21141. Code93Ext : result := Code_93;
  21142. CodeMSI : result := Code_MSI;
  21143. PostNet : result := Code_PostNet;
  21144. CodaBar : result := Code_CodaBar;
  21145. EAN8 : Result := Code_EAN8;
  21146. EAN13 : Result := Code_EAN13;
  21147. UPC_A : Result := Code_UPC_A;
  21148. UPC_EODD : Result := Code_UPC_EODD;
  21149. UPC_EVEN : Result := Code_UPC_EVEN;
  21150. UPC_S2 : Result := Code_Supp2;
  21151. UPC_S5 : Result := Code_Supp5;
  21152. else
  21153. result := Code_128; //for Code128A,Code128B,Code128C;EAN128A,EAN128B,EAN128C
  21154. end;
  21155. end;
  21156. function TDefineBarcode.MakeModules:TDefineBarcodeModules;
  21157. begin
  21158. case CodeType of
  21159. Code25IL, Code25IT, Code39,
  21160. Code39Ext, Codabar, EAN8, EAN13,
  21161. UPC_A, UPC_EODD, UPC_EVEN, UPC_S2,
  21162. UPC_S5:begin
  21163. if fRatio <> 2.0 then
  21164. fRatio := 2.0;
  21165. end;
  21166. Code25Mx :begin
  21167. if fRatio < 2.25 then
  21168. fRatio := 2.25;
  21169. if fRatio > 3.0 then
  21170. fRatio := 3.0;
  21171. end;
  21172. Code128A, Code128B, Code128C,
  21173. EAN128A, EAN128B, EAN128C,
  21174. Code93,Code93Ext, CodeMSI,
  21175. PostNet:;
  21176. end;
  21177. Result[0] := fModul;
  21178. Result[1] := Round(fModul*fRatio);
  21179. Result[2] := Result[1] * 3 div 2;
  21180. Result[3] := Result[1] * 2;
  21181. end;
  21182. {Print the Barcode data :0-3 white Line;5-8 black Line;A-D black Line (2/5 in Height)}
  21183. procedure TDefineBarcode.OneBarProps(Data:Char;Var Width:Integer;var lt:TDefineBarcodeLines);
  21184. begin
  21185. case data of
  21186. '0': begin width := Modules[0]; lt := ltWhite; end;
  21187. '1': begin width := Modules[1]; lt := ltWhite; end;
  21188. '2': begin width := Modules[2]; lt := ltWhite; end;
  21189. '3': begin width := Modules[3]; lt := ltWhite; end;
  21190. '5': begin width := Modules[0]; lt := ltBlack; end;
  21191. '6': begin width := Modules[1]; lt := ltBlack; end;
  21192. '7': begin width := Modules[2]; lt := ltBlack; end;
  21193. '8': begin width := Modules[3]; lt := ltBlack; end;
  21194. 'A': begin width := Modules[0]; lt := ltBlack_half; end;
  21195. 'B': begin width := Modules[1]; lt := ltBlack_half; end;
  21196. 'C': begin width := Modules[2]; lt := ltBlack_half; end;
  21197. 'D': begin width := Modules[3]; lt := ltBlack_half; end;
  21198. end;
  21199. end;
  21200. procedure TDefineBarcode.DrawUPC_AText(Canvas:TCanvas;width,wBorder:Integer);
  21201. var x,y,tCenter:Integer;
  21202. Rect:TRect;
  21203. str:String;
  21204. begin
  21205. with Canvas do
  21206. begin
  21207. x := wBorder - TextWidth('1')-2;
  21208. y := fBarHeight+fBarTop-(TextHeight('A') div 2);
  21209. str := BarText[1];
  21210. Rect.Left := x;
  21211. Rect.Top := y;
  21212. Rect.Right := x+TextWidth(Str);
  21213. Rect.Bottom := y+TextHeight(Str);
  21214. TextRect(Rect,x,y,Str);
  21215. Str := Copy(BarText,2,5);
  21216. x := wBorder + ProLine;
  21217. Rect.Left := x;
  21218. Rect.Top := y;
  21219. Rect.Right := (width-ProLine) div 2;
  21220. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21221. TextRect(Rect,tCenter,y,Str);
  21222. str := Copy(BarText,7,5);
  21223. x := (Width + ProLine)div 2;
  21224. Rect.Left := x;
  21225. Rect.Top := y;
  21226. Rect.Right := width - wBorder - ProLine;
  21227. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21228. TextRect(Rect,tCenter,y,Str);
  21229. str := BarText[12];
  21230. x := Width - wBorder;
  21231. Rect.Left := x;
  21232. Rect.Top := y;
  21233. Rect.Right := width;
  21234. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21235. TextRect(Rect,tCenter,y,Str);
  21236. end;
  21237. end;
  21238. procedure TDefineBarcode.DrawEAN8Text(Canvas:TCanvas;width,wBorder:Integer);
  21239. var x,y,tCenter:Integer;
  21240. Rect:TRect;
  21241. str:String;
  21242. begin
  21243. with Canvas do
  21244. begin
  21245. y := fBarHeight+fBarTop-(TextHeight('A') div 2);
  21246. str := copy(BarText,1,4);
  21247. x := wBorder + ProLine;
  21248. Rect.Left := x;
  21249. Rect.Top := y;
  21250. Rect.Right := (width-ProLine) div 2;
  21251. Rect.Bottom := y+TextHeight(Str);
  21252. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21253. TextRect(Rect,tCenter,y,Str);
  21254. str := copy(BarText,5,4);
  21255. x := (Width + ProLine)div 2;
  21256. Rect.Left := x;
  21257. Rect.Top := y;
  21258. Rect.Right := width - wBorder - ProLine;
  21259. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21260. TextRect(Rect,tCenter,y,Str);
  21261. end;
  21262. end;
  21263. procedure TDefineBarcode.DrawUPC_EText(Canvas:TCanvas;width,wBorder:Integer);
  21264. var x,y,tCenter:Integer;
  21265. Rect:TRect;
  21266. str:String;
  21267. begin
  21268. with Canvas do
  21269. begin
  21270. y := fBarHeight+fBarTop-(TextHeight('A') div 2);
  21271. str := copy(BarText,1,6);
  21272. x := wBorder + ProLine;
  21273. Rect.Left := x;
  21274. Rect.Top := y;
  21275. Rect.Right := width - wBorder - ProLine;
  21276. Rect.Bottom := y+TextHeight(Str);
  21277. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21278. TextRect(Rect,tCenter,y,Str);
  21279. end;
  21280. end;
  21281. procedure TDefineBarcode.DrawEAN13Text(Canvas:TCanvas;width,wBorder:Integer);
  21282. var x,y,tCenter:Integer;
  21283. Rect:TRect;
  21284. str:String;
  21285. begin
  21286. with Canvas do
  21287. begin
  21288. x := wBorder - TextWidth('1')-2;
  21289. y := fBarHeight+fBarTop-(TextHeight('A') div 2);
  21290. str := BarText[1];
  21291. Rect.Left := x;
  21292. Rect.Top := y;
  21293. Rect.Right := x+TextWidth(Str);
  21294. Rect.Bottom := y+TextHeight(Str);
  21295. TextRect(Rect,x,y,Str);
  21296. Str := Copy(BarText,2,6);
  21297. x := wBorder + ProLine;
  21298. Rect.Left := x;
  21299. Rect.Top := y;
  21300. Rect.Right := (width-ProLine) div 2;
  21301. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21302. TextRect(Rect,tCenter,y,Str);
  21303. str := Copy(BarText,8,6);
  21304. x := (Width + ProLine)div 2;
  21305. Rect.Left := x;
  21306. Rect.Top := y;
  21307. Rect.Right := width - wBorder - ProLine;
  21308. tCenter := (Rect.Right + x - TextWidth(str)) div 2;
  21309. TextRect(Rect,tCenter,y,Str);
  21310. end;
  21311. end;
  21312. procedure TDefineBarcode.DrawBarcode;
  21313. var tCenter,i,xadd, x, y:Integer;
  21314. lt : TDefineBarcodeLines;
  21315. fwidth, fheight,wBorder:integer;
  21316. a,b,c,d, orgin : TPoint;
  21317. bmpMem:TBitmap;
  21318. Rect:TRect;
  21319. str:String;
  21320. begin
  21321. bmpMem:= TBitmap.Create;
  21322. try
  21323. with bmpMem.Canvas do
  21324. begin
  21325. Font.Assign(self.Font);
  21326. wBorder := TextWidth('1')*2 + fBorderWidth div 2;
  21327. case CodeType of
  21328. EAN13,EAN8,UPC_A,UPC_EODD,UPC_EVEN:
  21329. xadd := wBorder
  21330. else
  21331. xadd := fBorderWidth;
  21332. end;
  21333. orgin.x := xadd;//Left;
  21334. orgin.y := fBarTop;//Top 0;
  21335. bmpMem.Width := xadd;
  21336. bmpMem.Height := fBarHeight+fBarTop;
  21337. brush.Style := bsClear;
  21338. Brush.Color := Color;
  21339. FillRect(ClipRect);
  21340. Pen.Width := 1;
  21341. for i:=1 to Length(data) do
  21342. begin
  21343. OneBarProps(Data[i],fWidth,lt);
  21344. Pen.Color := fBarColor;//clWhite;
  21345. brush.Style := bsClear;
  21346. Brush.Color := Color;
  21347. if (lt = ltBlack) or (lt = ltBlack_half) then
  21348. Brush.Color := fBarColor;//clBlack
  21349. if lt = ltBlack_half then
  21350. fheight := bmpMem.Height * 2 div 5
  21351. else
  21352. fheight := bmpMem.Height;
  21353. GetABCED(a,b,c,d,orgin,xadd,fWidth,fHeight);
  21354. Polygon([a,b,c,d]);
  21355. xadd := xadd + fwidth;
  21356. bmpMem.Width := xadd;
  21357. end;//结束画直线
  21358. Brush.Color := Color;
  21359. Rect := ClipRect;
  21360. Rect.Bottom := fBarTop;
  21361. FillRect(Rect);
  21362. Rect := ClipRect;
  21363. Rect.Right := fBorderWidth;
  21364. FillRect(Rect);
  21365. if fShowText then
  21366. begin
  21367. if (CodeType = EAN13)or(CodeType = EAN8)or
  21368. (CodeType = UPC_A)or(CodeType = UPC_EODD)or
  21369. (CodeType = UPC_EVEN) then
  21370. begin
  21371. bmpMem.Height := bmpMem.Height + TextHeight('A') div 2;
  21372. bmpMem.Width := xadd + wBorder;
  21373. case CodeType of
  21374. EAN13 : DrawEAN13Text(bmpMem.Canvas,bmpMem.Width,wBorder);
  21375. EAN8 : DrawEAN8Text(bmpMem.Canvas,bmpMem.Width,wBorder);
  21376. UPC_A : DrawUPC_AText(bmpMem.Canvas,bmpMem.Width,wBorder);
  21377. else //UPC_EODD,UPC_EVEN;
  21378. DrawUPC_EText(bmpMem.Canvas,bmpMem.Width,wBorder);
  21379. end;
  21380. end
  21381. else
  21382. begin
  21383. bmpMem.Height := bmpMem.Height + TextHeight('A');
  21384. bmpMem.Width := xadd + fBorderWidth;
  21385. if bmpMem.Width > TextWidth(BarText) then
  21386. tCenter:=(bmpMem.width-TextWidth(BarText))div 2
  21387. else
  21388. tCenter:=0;
  21389. case CodeType of
  21390. Code93Ext,
  21391. Code39Ext:Str := Copy(BarText,3,Length(BarText)-2);
  21392. else
  21393. Str := BarText;
  21394. end;
  21395. TextOut(tCenter, fBarHeight+fBarTop, Str);
  21396. end;
  21397. end
  21398. else
  21399. begin
  21400. bmpMem.Width := xadd + fBorderWidth;
  21401. Rect := ClipRect;
  21402. Rect.Top := Rect.Bottom - fBarTop;
  21403. FillRect(Rect);
  21404. end;
  21405. case fRotateType of
  21406. raNone:fBitmap.Assign(bmpMem);
  21407. ra270:begin
  21408. fBitmap.width := bmpMem.Height;
  21409. fBitmap.Height := bmpMem.Width;
  21410. for x:=0 to bmpMem.Height-1 do
  21411. for y:=0 to bmpMem.Width-1 do
  21412. fBitmap.canvas.Pixels[(-x+bmpMem.Height),y]:=Pixels[y,x];
  21413. end;
  21414. ra180:begin
  21415. fBitmap.width := bmpMem.Width;
  21416. fBitmap.Height := bmpMem.Height;
  21417. for x:=0 to bmpMem.Height-1 do
  21418. for y:=0 to bmpMem.Width-1 do
  21419. fBitmap.canvas.Pixels[(bmpMem.Width-y),(bmpMem.Height-x)]:=Pixels[y,x];
  21420. end;
  21421. ra090:begin
  21422. fBitmap.width := bmpMem.Height;
  21423. fBitmap.Height := bmpMem.Width;
  21424. for x:=0 to bmpMem.Height-1 do
  21425. for y:=0 to bmpMem.Width-1 do
  21426. fBitmap.canvas.Pixels[x,(bmpMem.Width-y)]:=Pixels[y,x];
  21427. end;
  21428. end;
  21429. end;
  21430. finally
  21431. bmpMem.free;
  21432. end;
  21433. end;
  21434. {Print the Barcode data :0-3 white Line;5-8 black Line;A-D black Line (2/5 in Height)}
  21435. procedure TDefineBarcode.Paint;
  21436. begin
  21437. DrawBarcode;
  21438. inherited Paint;
  21439. if AutoSize then
  21440. begin
  21441. Width := fBitmap.Width;
  21442. Height := fBitmap.Height;
  21443. end;
  21444. fBitmap.Transparent := fTransparent;
  21445. if FTransparent then
  21446. begin
  21447. DrawparentImage(self, Canvas);
  21448. end;
  21449. Canvas.StretchDraw(ClientRect,fBitmap);
  21450. end;
  21451. procedure TDefineBarcode.SetRotateType(const Value: TDefineBarcodeRotation);
  21452. begin
  21453. if FRotateType <> value then
  21454. begin
  21455. FRotateType := Value;
  21456. Invalidate;
  21457. end;
  21458. end;
  21459. function TDefineBarcode.GetTypName: String;
  21460. begin
  21461. result := BCData[CodeType].Name;
  21462. end;
  21463. function TDefineBarcode.GetProLine: Integer;
  21464. var Inx,w:Integer;
  21465. TempStr:String;
  21466. lt : TDefineBarcodeLines;
  21467. begin
  21468. Result := 0;
  21469. TempStr := '505';
  21470. for Inx := 1 to Length(TempStr) do
  21471. begin
  21472. OneBarProps(TempStr[Inx],w,lt);
  21473. Inc(Result,W);
  21474. end;
  21475. end;
  21476. procedure TDefineBarcode.SetText(const Value: string);
  21477. begin
  21478. if fText <> Value then
  21479. begin
  21480. fText := Value;
  21481. Invalidate;
  21482. end;
  21483. end;
  21484. procedure TDefineBarcode.SetBarHeight(const Value: Integer);
  21485. begin
  21486. if fBarHeight <> Value then
  21487. begin
  21488. fBarHeight := Value;
  21489. Invalidate;
  21490. end;
  21491. end;
  21492. procedure TDefineBarcode.SetBorderWidth(const Value: Byte);
  21493. begin
  21494. if fBorderWidth <> Value then
  21495. begin
  21496. fBorderWidth := Value;
  21497. Invalidate;
  21498. end;
  21499. end;
  21500. procedure TDefineBarcode.SetBarColor(const Value: TColor);
  21501. begin
  21502. if fBarColor <> Value then
  21503. begin
  21504. fBarColor := Value;
  21505. Invalidate;
  21506. end;
  21507. end;
  21508. procedure TDefineBarcode.SetRatio(const Value: double);
  21509. begin
  21510. if FRatio <> Value then
  21511. begin
  21512. FRatio := Value;
  21513. Invalidate;
  21514. end;
  21515. end;
  21516. procedure TDefineBarcode.SetCodeType(const Value: TDefineBarcodeType);
  21517. begin
  21518. if FCodeType <> Value then
  21519. begin
  21520. FCodeType := Value;
  21521. Invalidate;
  21522. end;
  21523. end;
  21524. procedure TDefineBarcode.SetModul(const Value:Integer);
  21525. begin
  21526. if (Value >= 1) and (Value < 50) then
  21527. begin
  21528. fModul := Value;
  21529. Invalidate;
  21530. end;
  21531. end;
  21532. procedure TDefineBarcode.SetBarTop(const Value: Byte);
  21533. begin
  21534. if fBarTop <> Value then
  21535. begin
  21536. fBarTop := Value;
  21537. Invalidate;
  21538. end;
  21539. end;
  21540. procedure TDefineBarcode.SetColor(const Value: TColor);
  21541. begin
  21542. if FColor <> Value then
  21543. begin
  21544. FColor := Value;
  21545. Invalidate;
  21546. end;
  21547. end;
  21548. procedure TDefineBarcode.FontChange(sender: TObject);
  21549. begin
  21550. Invalidate;
  21551. end;
  21552. procedure TDefineBarcode.WMSize(var Message: TWMSize);
  21553. begin
  21554. inherited;
  21555. Invalidate;
  21556. end;
  21557. procedure TDefineBarcode.SetBools(Index: Integer; Value: Boolean);
  21558. begin
  21559. case index of
  21560. 0: fAutoSize := Value;
  21561. 1: FCheckSum := Value;
  21562. 2: fCheckOdd := Value;
  21563. 3: FShowText := Value;
  21564. 4: fTransparent := Value;
  21565. end;
  21566. invalidate;
  21567. end;
  21568. initialization
  21569. GetCheckSize;
  21570. end.