FlatUtils.pas 87 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967
  1. unit FlatUtils;
  2. interface
  3. {$I FlatStyle.inc}
  4. uses Windows, Classes, Graphics, Messages, Controls, Forms,
  5. StdCtrls, ComCtrls, SysUtils, DBGrids, Grids, ExtCtrls;
  6. const
  7. FileVersion = '4.55.0.0';
  8. FileCopyright = '? 1998-2010';
  9. FileFinish = '2010-02-06';
  10. CompilePlat = {$IFDEF VER80} 'Delphi 1.0'{$ENDIF}
  11. {$IFDEF VER90} 'Delphi 2.0'{$ENDIF}
  12. {$IFDEF VER100} 'Delphi 3.0'{$ENDIF}
  13. {$IFDEF VER120} 'Delphi 4.0'{$ENDIF}
  14. {$IFDEF VER130} 'Delphi 5.0'{$ENDIF}
  15. {$IFDEF VER140} 'Delphi 6.0'{$ENDIF}
  16. {$IFDEF VER150} 'Delphi 7.0'{$ENDIF}
  17. {$IFDEF VER160} 'Delphi 8.0'{$ENDIF}
  18. {$IFDEF VER170} 'Delphi 2005'{$ENDIF}
  19. {$IFDEF VER180} 'Delphi 2006'{$ENDIF}
  20. {$IFDEF VER190} 'Delphi 2007'{$ENDIF}
  21. {$IFDEF VER200} 'Delphi 2009'{$ENDIF}
  22. {$IFDEF VER93} 'C++Builder 1.0'{$ENDIF}
  23. {$IFDEF VER110} 'C++Builder 3.0'{$ENDIF}
  24. {$IFDEF VER125} 'C++Builder 4.0'{$ENDIF};
  25. //定义 控件标签 开关 值:True为显示,False为禁止
  26. DefaultHasTicket = True;
  27. {以下定义 MessageMyBox函数的Flags标识}
  28. SB_INF_BASE= MB_ICONINFORMATION;{SB_INF_BASE For Information Hint}
  29. SB_WAR_BASE= MB_ICONWARNING;{SB_WAR_BASE For Warning Hint}
  30. SB_ERR_BASE= MB_ICONERROR; {SB_ERR_BASE For Error Hint}
  31. SB_QUE_BASE= MB_ICONQUESTION; {SB_QUE_BASE For Stop Hint}
  32. {define mb_inconinformtion}
  33. mbIAll = SB_INF_BASE+MB_ABORTRETRYIGNORE;
  34. mbIOk = SB_INF_BASE+MB_OK;
  35. mbIOC = SB_INF_BASE+MB_OKCANCEL;
  36. mbIRC = SB_INF_BASE+MB_RETRYCANCEL;
  37. mbIYN = SB_INF_BASE+MB_YESNO;
  38. mbIYNC = SB_INF_BASE+MB_YESNOCANCEL;
  39. {define mb_inconwarning}
  40. mbWAll = SB_WAR_BASE+MB_ABORTRETRYIGNORE;
  41. mbWOk = SB_WAR_BASE+MB_OK;
  42. mbWOC = SB_WAR_BASE+MB_OKCANCEL;
  43. mbWRC = SB_WAR_BASE+MB_RETRYCANCEL;
  44. mbWYN = SB_WAR_BASE+MB_YESNO;
  45. mbWYNC = SB_WAR_BASE+MB_YESNOCANCEL;
  46. {define mb_inconerror}
  47. mbEAll = SB_ERR_BASE+MB_ABORTRETRYIGNORE;
  48. mbEOk = SB_ERR_BASE+MB_OK;
  49. mbEOC = SB_ERR_BASE+MB_OKCANCEL;
  50. mbERC = SB_ERR_BASE+MB_RETRYCANCEL;
  51. mbEYN = SB_ERR_BASE+MB_YESNO;
  52. mbEYNC = SB_ERR_BASE+MB_YESNOCANCEL;
  53. {define mb_inconstop}
  54. mbQAll = SB_QUE_BASE+MB_ABORTRETRYIGNORE;
  55. mbQOk = SB_QUE_BASE+MB_OK;
  56. mbQOC = SB_QUE_BASE+MB_OKCANCEL;
  57. mbQRC = SB_QUE_BASE+MB_RETRYCANCEL;
  58. mbQYN = SB_QUE_BASE+MB_YESNO;
  59. mbQYNC = SB_QUE_BASE+MB_YESNOCANCEL;
  60. { pause before repeat timer (ms) }
  61. FlatInitRepeatPause = 400;
  62. { pause before hint window displays (ms)}
  63. FlatRepeatPause = 100;
  64. //以下定义FlatGuiListBox常量
  65. //鼠标滚轮改变 TopIndex 大小:
  66. C_MouseWheelSize = 3;
  67. C_WheelWait = 80;
  68. //时间 ID: //基层 TimerID
  69. C_BaseTimerID = 1024 * 512;
  70. //鼠标滑轮等待时间 ID:
  71. C_WheelWaitTimerID = C_BaseTimerID + 1;
  72. //鼠标拖动改变页面时间 ID
  73. C_MouseChangePageTimerID = C_BaseTimerID + 2;
  74. //以下两个常量控制着动画速度:
  75. //最大 Sleep 数量:
  76. C_SleepMaxCount = 20;
  77. //系统等待时间:
  78. C_MaxInterval = 200;
  79. { ScrollBar }
  80. C_Win2000ScrllBarBtnSize = 16;
  81. C_IntervalOfWait = 500;
  82. C_Interval = 50;
  83. DefaultInitRepeatPause = 400; { pause before repeat timer (ms) }
  84. DefaultRepeatPause = 100; { pause before hint window displays (ms)}
  85. const
  86. TCS_SCROLLOPPOSITE = $0001; // assumes multiline tab
  87. TCS_MULTISELECT = $0004; // allow multi-select in button mode
  88. TCS_FORCEICONLEFT = $0010;
  89. TCS_FORCELABELLEFT = $0020;
  90. TCS_HOTTRACK = $0040;
  91. TCS_RIGHT = $0002;
  92. TCS_VERTICAL = $0080;
  93. TCS_TABS = $0000;
  94. TCS_BUTTONS = $0100;
  95. TCS_FLATBUTTONS = $0008;
  96. TCS_OWNERDRAWFIXED = $2000;
  97. TCS_BOTTOM = $0002;
  98. TCS_SINGLELINE = $0000;
  99. TCS_MULTILINE = $0200;
  100. TCS_RIGHTJUSTIFY = $0000;
  101. TCS_FIXEDWIDTH = $0400;
  102. TCS_RAGGEDRIGHT = $0800;
  103. TCS_FOCUSONBUTTONDOWN = $1000;
  104. TCS_TOOLTIPS = $4000;
  105. TCS_FOCUSNEVER = $8000;
  106. TCS_EX_FLATSEPARATORS = $00000001;
  107. TCS_EX_REGISTERDROP = $00000002;
  108. TCM_FIRST = $1300; { Tab control messages }
  109. TCM_GETIMAGELIST = TCM_FIRST + 2;
  110. TCM_SETIMAGELIST = TCM_FIRST + 3;
  111. TCM_GETITEMCOUNT = TCM_FIRST + 4;
  112. TCM_DELETEITEM = TCM_FIRST + 8;
  113. TCM_DELETEALLITEMS = TCM_FIRST + 9;
  114. TCM_GETITEMRECT = TCM_FIRST + 10;
  115. TCM_GETCURSEL = TCM_FIRST + 11;
  116. TCM_SETCURSEL = TCM_FIRST + 12;
  117. TCM_HITTEST = TCM_FIRST + 13;
  118. TCM_SETITEMEXTRA = TCM_FIRST + 14;
  119. TCM_ADJUSTRECT = TCM_FIRST + 40;
  120. TCM_SETITEMSIZE = TCM_FIRST + 41;
  121. TCM_REMOVEIMAGE = TCM_FIRST + 42;
  122. TCM_SETPADDING = TCM_FIRST + 43;
  123. TCM_GETROWCOUNT = TCM_FIRST + 44;
  124. TCM_GETTOOLTIPS = TCM_FIRST + 45;
  125. TCM_SETTOOLTIPS = TCM_FIRST + 46;
  126. TCM_GETCURFOCUS = TCM_FIRST + 47;
  127. TCM_SETCURFOCUS = TCM_FIRST + 48;
  128. TCM_SETMINTABWIDTH = TCM_FIRST + 49;
  129. TCM_DESELECTALL = TCM_FIRST + 50;
  130. TCM_HIGHLIGHTITEM = TCM_FIRST + 51;
  131. TCM_SETEXTENDEDSTYLE = TCM_FIRST + 52; // optional wParam == mask
  132. TCM_GETEXTENDEDSTYLE = TCM_FIRST + 53;
  133. TCIF_TEXT = $0001;
  134. TCIF_IMAGE = $0002;
  135. TCIF_RTLREADING = $0004;
  136. TCIF_PARAM = $0008;
  137. TCIF_STATE = $0010;
  138. TCIS_BUTTONPRESSED = $0001;
  139. TCIS_HIGHLIGHTED = $0002;
  140. TCM_GETITEMA = TCM_FIRST + 5;
  141. TCM_SETITEMA = TCM_FIRST + 6;
  142. TCM_INSERTITEMA = TCM_FIRST + 7;
  143. TCM_GETITEMW = TCM_FIRST + 60;
  144. TCM_SETITEMW = TCM_FIRST + 61;
  145. TCM_INSERTITEMW = TCM_FIRST + 62;
  146. TCM_GETITEM = TCM_GETITEMA;
  147. TCM_SETITEM = TCM_SETITEMA;
  148. TCM_INSERTITEM = TCM_INSERTITEMA;
  149. // tab styles - search win32 api help for TCS_ for info on each style
  150. type
  151. TPagesPosition = (tpTop, tpBottom, tpLeft, tpRight);
  152. TPagesStyle = (pcsTabs, pcsButtons, pcsFlatButtons, pcsFlatStyle);
  153. tagTCITEMA = packed record
  154. mask: UINT;
  155. dwState: UINT;
  156. dwStateMask: UINT;
  157. pszText: PAnsiChar;
  158. cchTextMax: Integer;
  159. iImage: Integer;
  160. lParam: LPARAM;
  161. end;
  162. tagTCITEMW = packed record
  163. mask: UINT;
  164. dwState: UINT;
  165. dwStateMask: UINT;
  166. pszText: PWideChar;
  167. cchTextMax: Integer;
  168. iImage: Integer;
  169. lParam: LPARAM;
  170. end;
  171. TTCItemA = tagTCITEMA;
  172. TTCItemW = tagTCITEMW;
  173. TTCItem = TTCItemA;
  174. const
  175. TCHT_NOWHERE = $0001;
  176. TCHT_ONITEMICON = $0002;
  177. TCHT_ONITEMLABEL = $0004;
  178. TCHT_ONITEM = TCHT_ONITEMICON or TCHT_ONITEMLABEL;
  179. type
  180. PTCHitTestInfo = ^TTCHitTestInfo;
  181. tagTCHITTESTINFO = packed record
  182. pt: TPoint;
  183. flags: UINT;
  184. end;
  185. _TC_HITTESTINFO = tagTCHITTESTINFO;
  186. TTCHitTestInfo = tagTCHITTESTINFO;
  187. TC_HITTESTINFO = tagTCHITTESTINFO;
  188. tagTCKEYDOWN = packed record
  189. hdr: TNMHDR;
  190. wVKey: Word;
  191. flags: UINT;
  192. end;
  193. _TC_KEYDOWN = tagTCKEYDOWN;
  194. TTCKeyDown = tagTCKEYDOWN;
  195. TC_KEYDOWN = tagTCKEYDOWN;
  196. // event to allow different mapping of glyphs from the imagelist component
  197. type
  198. TGlyphMapEvent = procedure(Control: TWinControl; PageIndex : integer; var GlyphIndex : integer) of object;
  199. TPageDrawItemEvent = procedure(Control: TWinControl; Index: Integer; ACanvas : TControlCanvas;
  200. ARect: TRect; State: TOwnerDrawState) of object;
  201. type
  202. TButtonLayout = (blGlyphLeft, blGlyphRight, blGlyphTop, blGlyphBottom);
  203. TButtonState = (bsUp, bsDisabled, bsDown, bsExclusive);
  204. TButtonStyle = (bsAutoDetect, bsWin31, bsNew);
  205. TWaterAlign = (wpLeft,wpCenter,wpRight);
  206. TFlatDISModal = (tmAboriginal, tmStretch, tmNormal, tmCenter);
  207. {Define TDefainePanelEx type}
  208. TBGImageAlign = (iaCenter, iaStretch, iaTile); //Background image align type
  209. TTitleImageAlign = (tiaCenter, tiaLeft, tiaRight, tiaStretch, tiaTile); //Title image align type
  210. TTitleButton = (tbClose, tbMinimize, tbMaximize); //Title buttons
  211. TTitleButtons = Set of TTitleButton;
  212. //Rounded corner type
  213. TPanelCorner = (rcTopLeft, rcTopRight, rcBottomLeft, rcBottomRight);
  214. TPanelCorners = Set of TPanelCorner;
  215. TFlatDBBStyle = set of (myAllowTimer, myFocusRect);
  216. TFillDirection = (fdBottomToTop,fdCenterToVerti,fdCenterToHoriz,fdLeftToRight,fdRightToLeft,fdTopToBottom,fdXPFace);
  217. TFlatDBBName = (vbFirst,vbPrior,vbNext,vbLast,vbNew,vbDelete,vbEdit,vbSave,vbCancel,vbRefresh);
  218. TFlatDBBTSet = set of TFlatDBBName;
  219. EFlatBroClick = procedure (Sender: TObject; Button: TFlatDBBName) of object;
  220. TNumGlyphs = 1..4;
  221. TAdvColors = 0..100;
  222. //以下定义FlatGuiListBox类型
  223. //自定义的 ScrollCode 枚举
  224. TIScrollCode = (scLarge, scSmall, scTrackMove, scCustom);
  225. //绘制枚举:
  226. TDrawScrollBar = (dsLeftBtn, dsRightBtn, dsTrack, dsSpaceLeft, dsSpaceRight);
  227. TDrawArrow = (daLeft, daTop, daRight, daBottom);
  228. //ScrollBar 整个结构的枚举:
  229. TScrollBarPos = (spNone, spLeftBtn, spRightBtn, spTrack, spLeftSpace, spRightSpace);
  230. //滑动方向枚举:
  231. TScrollMode = (smAdd,smDec);
  232. TScrollEvent = procedure(Sender: TObject; const StartChange:boolean; Code:TIScrollCode; Mode:TScrollMode; const ChangeValue: integer) of Object;
  233. TScrollDrawEvent = procedure(Cav: TCanvas; const Typ: TDrawScrollBar; const R: TRect; const State: TButtonState) of Object;
  234. //滑轮记录:
  235. TListControlWheel = record
  236. Wheeling,
  237. IsAdd: boolean;
  238. WheelCount: integer;
  239. end;
  240. //键盘改变页面枚举
  241. TKeyFirst = (kfNone,kfUp,kfDown,kfPrior,kfNext);
  242. //鼠标改变页面枚举
  243. TMouseChangePage = (cpNone,cpAddMin,cpAddNormal,cpAddMax,cpDecMin,cpDecNormal,cpDecMax);
  244. TListItemEvent = procedure(Sender: TObject; const Index: integer) of Object;
  245. TListItemState = (isActive, isSelected, isDown, isUp,isDisabled, isFocused);
  246. TListItemStates = set of TListItemState;
  247. TListItemDrawEvent = procedure(Cav: TCanvas; const Index: Integer;
  248. const R: TRect; const State: TListItemStates) of object;
  249. TListControlGUI = (lcgLowered, lcgFlat, lcgNone);
  250. //定义颜色语言结构
  251. TColorItems = packed record
  252. Value: TColor;
  253. cnName, enName: PAnsiChar;
  254. end;
  255. TIPChar = string[3];
  256. //定义IP分段函数
  257. TIP = packed Record
  258. NO1, NO2, NO3, NO4:TIPChar;
  259. end;
  260. TBarsRect = packed record
  261. PrevRect:TRect;
  262. DownRect:TRect;
  263. end;
  264. TWaterColor = packed record
  265. Value: TColor;
  266. enName: PAnsiChar;
  267. end;
  268. TBorderAttrib = packed record
  269. Ctrl: TWinControl;
  270. BorderColor: TColor;
  271. FlatColor: TColor;
  272. FocusColor: TColor;
  273. MouseState: Boolean;
  274. DesignState: TComponentState;
  275. FocusState: boolean;
  276. HasBars: boolean;
  277. BoldState:Boolean;
  278. end;
  279. TOtherParam = packed record
  280. Color: TColor;
  281. Name: TFontName;
  282. Pitch: TFontPitch;
  283. Size: Integer;
  284. Style: TFontStyles;
  285. Row: Integer;
  286. Draw3D: Boolean;
  287. Align: TWaterAlign;
  288. end;
  289. TScrollType = (stUp, stDown);
  290. TColorCalcType = (lighten, darken);
  291. TLayoutPosition = (lpLeft, lpRight);
  292. TFlatTabPosition = (fpTop, fpBottom);
  293. TArrowPos = (NE, NW, SE, SW);
  294. TGroupBoxBorder = (brFull, brOnlyTopLine);
  295. TTransparentMode = (tmAlways, tmNotFocused, tmNone);
  296. TLanguage = (lgChinese, lgEnglish);
  297. TStyleOrien = (bsHorizontal, bsVertical);
  298. TStyleFace = (fsDefault, fsCustom);
  299. TAlignmentText = (stLeft, stCenter, stRight);
  300. TCheckPosition = (bpLeft, bpRight);
  301. TTitlePosition = (tsTop, tsBottom);
  302. TTicketPosition = (poLeft, poTop, poRight, poBottom);
  303. TSplitterStatus = (ssIn, ssOut);
  304. TListState = (lsClear,lsFree);
  305. TTitleButtonsStyle = (tbsEllipse,tbsRectangle);
  306. TAnimationLayout = (alAcross, alDown);
  307. //define Events procedure
  308. TNotifyChange = procedure(Sender: TObject; Text:TCaption) of object;
  309. TNotifyClick = procedure(Sender: TObject; Text:TCaption) of object;
  310. TValidateEvent = Procedure(Sender: TObject) of Object;
  311. TOnFrameChange = procedure(Sender: TObject; FrameNumber: Integer) of object;
  312. { 玻璃渐变API的声明 }
  313. PTriVertex = ^TTriVertex;
  314. TTriVertex = packed record
  315. x: Longint;
  316. y: Longint;
  317. Red: WORD;
  318. Green: WORD;
  319. Blue: WORD;
  320. Alpha: WORD;
  321. end;
  322. {
  323. TSystemTime = record
  324.  wYear: Word;
  325.  wMonth: Word;
  326.  wDayOfWeek: Word;
  327.  wDay: Word;
  328.  wHour: Word;
  329.  wMinute: Word;
  330.  wSecond: Word;
  331.  wMilliseconds: Word;
  332. end;
  333. }
  334. //TTriVertex = _TTriVertex;
  335. {渐变方向: 从左到右,从上到下}
  336. TGradDirection = (gdLeftRight, gdTopBottom);
  337. TGradWay = (gwLRWay, gwTBWay);
  338. { 玻璃效果的颜色配置 }
  339. TGlassColorCfg = record
  340. OBorder, //外框,如果为clNone将不绘制
  341. IBorder, //内框,如果为clNone将不绘制
  342. G1Start, //上半部分渐变的开始颜色
  343. G1End, //上半部分渐变的结束颜色
  344. G2Start, //下半部分渐变的开始颜色
  345. G2End: TColor; //下半部分渐变的结束颜色
  346. Style: TGradDirection;//定义方向
  347. Way: TGradWay;//定义反转
  348. end;
  349. {TDefineRLE}
  350. LongType = record
  351. case Word of
  352. 0: (Ptr: Pointer);
  353. 1: (Long: LongInt);
  354. 2: (Lo: Word; Hi: Word);
  355. end;
  356. type
  357. TDefineBarcodeLines = (ltWhite,ltBlack, ltblack_half);
  358. //定义条形码类型
  359. TDefineBarcodeType =(Code25IL, Code25IT, Code25Mx, Code39,
  360. Code39Ext, Code128A, Code128B, Code128C,
  361. Code93, Code93Ext, CodeMSI, PostNet, Codabar,
  362. EAN8, EAN13, EAN128A, EAN128B, EAN128C,
  363. UPC_A, UPC_EODD, UPC_EVEN, UPC_S2, UPC_S5);
  364. TDefineBarcodeRotation =(raNone,ra090,ra180,ra270);
  365. TDefineBarcodeModules = array[0..3] of ShortInt;
  366. TCode93 = record
  367. c : char;
  368. data : array[0..5] of char;
  369. end;
  370. TCode39 = record
  371. c : char;
  372. data : array[0..9] of char;
  373. chk: shortint;
  374. end;
  375. TCode128 = record
  376. a, b : char;
  377. c : string[2];
  378. data : string[6];
  379. end;
  380. TCodabar = record
  381. c : char;
  382. data : array[0..6] of char;
  383. end;
  384. TBCData = record
  385. Name:string; { Name of Barcode }
  386. num :Boolean; { numeric data only }
  387. end;
  388. const
  389. //定义Style属性的初始化值
  390. DefaultBarColor = TColor($00C5D6D9);
  391. DefaultBorderColor = TColor($0061A588);
  392. DefaultShadowColor = TColor($00C6C600);
  393. DefaultFlatColor = TColor($00E1EAEB);
  394. DefaultTitleFaceColor = TColor($0000CECE);
  395. DefaultTitleCheckColor = TColor($00FF8000);
  396. DefaultFocusedColor = TColor($00FBBE99);
  397. DefaultCheckBorderColor = TColor($008396A0);
  398. DefaultCheckColor = TColor($00FF0080);
  399. DefaultDownColor = TColor($00C5D6D9);
  400. DefaultColorStart = TColor($00FBF1ED);
  401. DefaultColorStop = TColor($00F7DFD6);
  402. DefaultTitleColorStart = TColor($00FFFFFF);
  403. DefaultTitleColorEnd = TColor($00F0BDAA);
  404. DefaultFoisColor = TColor($00E10000);
  405. DefaultItemSelectColor = TColor($00EED2C1);
  406. DefaultItemBrightColor = TColor($004F4F4F);
  407. DefaultItemColor = TColor($00404040);
  408. DefaultItemSpaceColor = TColor($00D6924E);
  409. DefaultItemRectColor = clWhite;
  410. DefaultBackdropColor = clWhite;
  411. DefaultCheckBackColor = clWhite;
  412. DefaultCheckSelectColor = clPurple;
  413. DefaultSelectStartColor = clBlack;
  414. DefaultSelectStopColor = clWhite;
  415. DefaultItemColorStart = clOlive;
  416. DefaultTitleColor = clBtnFace;
  417. DefaultItemLineColor = clGray;
  418. DefaultItemColorStop = clWhite;
  419. DefaultStyleVertical = bsVertical;
  420. DefaultStyleHorizontal = bsHorizontal;
  421. DefaultStyleFace = fsDefault;
  422. DefaultItemHeight = 17;
  423. DefaultBarsHeight = 12;
  424. DefaultTitleHeight = 18;
  425. DefaultCornerRadius:Integer = 10;
  426. //定义键盘控制
  427. vk_selall = $41;//全选 Ctrl+A
  428. vk_selcancel = $5A;//取消全选 Ctrl+Z
  429. //定义颜色语言默认
  430. clCustom = TColor($4080FF);
  431. StdColorCount = 18;
  432. bkModeTRANSPARENT = 1;
  433. StdCustomCN = '自定';
  434. StdCustomEN = 'Custom';
  435. StdColorCN = '颜色:';
  436. StdColorEN = 'Color:';
  437. StdColors: array [0..StdColorCount] of TColorItems = (
  438. {00}(Value:clBlack; cnName:'黑色'; enName:'Black' ),
  439. {01}(Value:clWhite; cnName:'白色'; enName:'White' ),
  440. {02}(Value:clYellow; cnName:'黄色'; enName:'Yellow' ),
  441. {03}(Value:clRed; cnName:'红色'; enName:'Red' ),
  442. {04}(Value:clFuchsia; cnName:'紫红'; enName:'Fuchsia'),
  443. {05}(Value:clMaroon; cnName:'栗色'; enName:'Maroon' ),
  444. {06}(Value:clGreen; cnName:'绿色'; enName:'Green' ),
  445. {07}(Value:clAqua; cnName:'浅绿'; enName:'Aqua' ),
  446. {08}(Value:clMoneyGreen; cnName:'金绿'; enName:'MoneyGreen'),
  447. {09}(Value:clBlue; cnName:'蓝色'; enName:'Blue' ),
  448. {10}(Value:clTeal; cnName:'深蓝'; enName:'Teal' ),
  449. {11}(Value:clSkyBlue; cnName:'天蓝'; enName:'SkyBlue'),
  450. {12}(Value:clOlive; cnName:'橄榄'; enName:'Olive' ),
  451. {13}(Value:clNavy; cnName:'藏青'; enName:'Navy' ),
  452. {14}(Value:clPurple; cnName:'紫色'; enName:'Purple' ),
  453. {15}(Value:clGray; cnName:'灰色'; enName:'Gray' ),
  454. {16}(Value:clSilver; cnName:'银灰'; enName:'Silver' ),
  455. {17}(Value:clLime; cnName:'青色'; enName:'Lime' ),
  456. {18}(Value:clCustom; cnName:'自定'; enName:'Custom'));
  457. //定义 输入类控件 的输入位置
  458. Aligns:array[TAlignment] of word =(ES_LEFT,ES_RIGHT,ES_CENTER);
  459. ecDarkBlue = TColor($00996633);
  460. ecBlue = TColor($00CF9030);
  461. ecLightBlue = TColor($00CFB78F);
  462. ecDarkRed = TColor($00302794);
  463. ecRed = TColor($005F58B0);
  464. ecLightRed = TColor($006963B6);
  465. ecDarkGreen = TColor($00385937);
  466. ecGreen = TColor($00518150);
  467. ecLightGreen = TColor($0093CAB1);
  468. ecDarkYellow = TColor($004EB6CF);
  469. ecYellow = TColor($0057D1FF);
  470. ecLightYellow = TColor($00B3F8FF);
  471. ecDarkBrown = TColor($00394D4D);
  472. ecBrown = TColor($00555E66);
  473. ecLightBrown = TColor($00829AA2);
  474. ecDarkKaki = TColor($00D3D3D3);
  475. ecKaki = TColor($00C8D7D7);
  476. ecLightKaki = TColor($00E0E9EF);
  477. { Encarta & FlatStyle Interface Color Constants }
  478. ecBtnHighlight = clWhite;
  479. ecBtnShadow = clBlack;
  480. ecBtnFace = ecLightKaki;
  481. ecBtnFaceDown = ecKaki;
  482. ecFocused = clWhite;
  483. ecScrollbar = ecLightKaki;
  484. ecScrollbarThumb = ecLightBrown;
  485. ecBackground = clWhite;
  486. ecHint = ecYellow;
  487. ecHintArrow = clBlack;
  488. ecDot = clBlack;
  489. ecTick = clBlack;
  490. ecMenuBorder = ecDarkBrown;
  491. ecMenu = clBlack;
  492. ecMenuSelected = ecDarkYellow;
  493. ecProgressBlock = ecBlue;
  494. ecUnselectedTab = ecBlue;
  495. ecSelection = clNavy;
  496. ecCaptionBackground = clBlack;
  497. ecActiveCaption = clWhite;
  498. ecInactiveCaption = ecLightBrown;
  499. BS_XP_BTNFRAMECOLOR = 8388608;
  500. BS_XP_BTNACTIVECOLOR = 13811126;
  501. BS_XP_BTNDOWNCOLOR = 11899781;
  502. //define ipmaskedit
  503. IPMaskStr = '999\.999\.999\.999;1;'#32;
  504. IPStart = '0.0.0.0';
  505. //定义水波字幕控制脚本
  506. TitleStart = '<Title>';
  507. TitleEnd = '</Title>';
  508. TitleSize = '[Size:';
  509. TitleName = '[Name:';
  510. TitleStyle = '[Style:';
  511. TitleColor = '[Color:';
  512. TitleLow = '[Row:';
  513. TitlePitch = '[Pitch:';
  514. TitleDraw3D = '[Draw3D:';
  515. TitleAlign = '[Align:';
  516. WaterColor: array [0..17] of TWaterColor = (
  517. {00}(Value:clBlack; enName:'clBlack' ),
  518. {01}(Value:clWhite; enName:'clWhite' ),
  519. {02}(Value:clYellow; enName:'clYellow' ),
  520. {03}(Value:clRed; enName:'clRed' ),
  521. {04}(Value:clFuchsia; enName:'clFuchsia'),
  522. {05}(Value:clMaroon; enName:'clMaroon' ),
  523. {06}(Value:clGreen; enName:'clGreen' ),
  524. {07}(Value:clAqua; enName:'clAqua' ),
  525. {08}(Value:clMoneyGreen; enName:'clMoneyGreen'),
  526. {09}(Value:clBlue; enName:'clBlue' ),
  527. {10}(Value:clTeal; enName:'clTeal' ),
  528. {11}(Value:clSkyBlue; enName:'clSkyBlue'),
  529. {12}(Value:clOlive; enName:'clOlive' ),
  530. {13}(Value:clNavy; enName:'clNavy' ),
  531. {14}(Value:clPurple; enName:'clPurple' ),
  532. {15}(Value:clGray; enName:'clGray' ),
  533. {16}(Value:clSilver; enName:'clSilver' ),
  534. {17}(Value:clLime; enName:'clLime' ));
  535. {Define FlatPanelEx}
  536. crSystemHand : TCursor = 10;
  537. wmNCPaintOnlyBorder : LongInt = 666;
  538. cTitleButtonSize : Integer = 20;
  539. PaletteMask = $02000000;
  540. { 默认颜色配置,蓝色玻璃 }
  541. DefGlassColorCfg: TGlassColorCfg = (
  542. OBorder: clBlack;
  543. IBorder: $00E1D0AA;
  544. G1Start: $00D1AE7A;
  545. G1End : $00B98835;
  546. G2Start: $00975F00;
  547. G2End : $00C6A46A;
  548. Style : gdTopBottom;
  549. Way : gwLRWay);
  550. //define components main version infomation
  551. type
  552. { TVersionControl }
  553. TVersionControl = Class(TCustomControl)
  554. private
  555. FVersion: String;
  556. function GetVersion: String;
  557. published
  558. property Version: String read GetVersion write FVersion;
  559. property Font;
  560. end;
  561. { TVersionCtrl }
  562. TVersionCtrlExt = Class(TCustomControl)
  563. private
  564. FVersion: String;
  565. function GetVersion: String;
  566. published
  567. property Version: String read GetVersion write FVersion;
  568. end;
  569. { TVersionPages }
  570. TVersionPages = Class(TPageControl)
  571. private
  572. FVersion: String;
  573. function GetVersion: String;
  574. published
  575. property Version: String read GetVersion write FVersion;
  576. end;
  577. { TVersionSheet }
  578. TVersionSheet = Class(TTabSheet)
  579. private
  580. FVersion: String;
  581. function GetVersion: String;
  582. published
  583. property Version: String read GetVersion write FVersion;
  584. end;
  585. { TVersionComboBox }
  586. TVersionComboBox = Class(TCustomComboBox)
  587. private
  588. FVersion: String;
  589. function GetVersion: String;
  590. published
  591. property Version: String read GetVersion write FVersion;
  592. end;
  593. { TVersionGraphic }
  594. TVersionGraphic = class(TGraphicControl)
  595. private
  596. FVersion: String;
  597. function GetVersion: String;
  598. published
  599. property Version: String read GetVersion write FVersion;
  600. end;
  601. { TVersionTreeView }
  602. TVersionTreeView = class(TCustomTreeView)
  603. private
  604. FVersion: String;
  605. function GetVersion: String;
  606. published
  607. property Version: String read GetVersion write FVersion;
  608. end;
  609. { TVersionListView }
  610. TVersionListView = class(TCustomListView)
  611. private
  612. FVersion: String;
  613. function GetVersion: String;
  614. published
  615. property Version: String read GetVersion write FVersion;
  616. end;
  617. { TVersionMemo }
  618. TVersionMemo = class(TCustomMemo)
  619. private
  620. FVersion: String;
  621. function GetVersion: String;
  622. published
  623. property Version: String read GetVersion write FVersion;
  624. end;
  625. { TVersionEdit }
  626. TVersionEdit = class(TCustomEdit)
  627. private
  628. FVersion: String;
  629. function GetVersion: String;
  630. published
  631. property Version: String read GetVersion write FVersion;
  632. end;
  633. { TVersionComponent }
  634. TVersionComponent = class(TComponent)
  635. private
  636. FVersion: String;
  637. function GetVersion: String;
  638. published
  639. property Version: String read GetVersion write FVersion;
  640. end;
  641. { TVersionListBoxExt }
  642. TVersionListBoxExt = class(TCustomListBox)
  643. private
  644. FVersion: String;
  645. function GetVersion: String;
  646. published
  647. property Version: String read GetVersion write FVersion;
  648. end;
  649. { TVersionDBGrid }
  650. TVersionDBGrid = class(TDBGrid)
  651. private
  652. FVersion: String;
  653. function GetVersion: String;
  654. published
  655. property Version: String read GetVersion write FVersion;
  656. end;
  657. { TVersionDrawGrid }
  658. TVersionDrawGrid = class(TCustomDrawGrid)
  659. private
  660. FVersion: String;
  661. function GetVersion: String;
  662. published
  663. property Version: String read GetVersion write FVersion;
  664. end;
  665. { TVersionObject }
  666. TVersionObject = class(TObject)
  667. private
  668. FVersion: String;
  669. function GetVersion: String;
  670. published
  671. property Version: String read GetVersion write FVersion;
  672. end;
  673. {TDefineRLE}
  674. TDefineRLE = class(TVersionObject)
  675. private
  676. t, s: Pointer;
  677. function PackSeg(Source, Target: Pointer; SourceSize: Word): Word;
  678. function UnPackSeg(Source, Target: Pointer; SourceSize: Word): Word;
  679. protected
  680. public
  681. Constructor Create;
  682. Destructor Destroy; override;
  683. function Pack(Source, Target: Pointer; SourceSize: LongInt): LongInt; { Return TargetSize }
  684. function UnPack(Source, Target: Pointer; SourceSize: LongInt): LongInt; {Return TargetSize }
  685. function PackString(Source: String): String;
  686. function UnPackString(Source: String): String;
  687. function PackFile(SourceFileName, TargetFileName: String): Boolean; { Return FALSE if IOError }
  688. function UnPackFile(SourceFileName, TargetFileName: String): Boolean; { Return FALSE if IOError }
  689. end;
  690. //定义 重画控件边界函数
  691. function DrawEditBorder(Border:TBorderAttrib; const Clip: HRGN=0):TColor;
  692. procedure DrawButtonBorder(Canvas: TCanvas;Rect: TRect; Color: TColor; Width: Integer);
  693. function DrawViewBorder(ViewBorder: TBorderAttrib;const oVal:Byte=1):TColor;
  694. procedure DrawInCheck(Canvas:TCanvas; Rect:TRect; Color:TColor);
  695. procedure DrawFrame(Canvas: TCanvas; var Rect: TRect; BorderColor, FaceColor: TColor; Width: Integer);
  696. //定义 重画透明背景
  697. procedure DrawTransBitBlt(Cnv: TCanvas; x, y: Integer; Bmp: TBitmap; clTransparent: TColor);
  698. //定义 画父背景图像
  699. procedure DrawParentImage(Control: TControl; Dest: TCanvas;const DefaultTop:integer=0);
  700. procedure DrawParentImageSub(Control: TControl; Dest: TCanvas;const DefaultHeigth:integer=0);
  701. function CreateDisabledBitmap(FOriginal: TBitmap; OutlineColor, BackColor, HighlightColor, ShadowColor: TColor;
  702. DrawHighlight: Boolean): TBitmap;
  703. function CalcAdvancedColor(ParentColor, OriginalColor: TColor; Percent: Byte; ColorType: TColorCalcType): TColor;
  704. procedure CalcButtonLayout(Canvas: TCanvas; const Client: TRect; const Offset: TPoint; Layout: TButtonLayout;
  705. Spacing, Margin: Integer; FGlyph: TBitmap; FNumGlyphs: Integer;
  706. const Caption: string; var TextBounds: TRect; var GlyphPos: TPoint);
  707. function Min(const A, B: Integer): Integer;
  708. function Max(const A, B: Integer): Integer;
  709. function GetFontMetrics(Font: TFont): TTextMetric;
  710. function GetFontHeight(Font: TFont): Integer;
  711. function RectInRect(R1, R2: TRect): Boolean;
  712. procedure DrawBackdrop(Canvas:TCanvas; StartColor, StopColor: TColor; CanRect:TRect;Style:TStyleOrien);
  713. function IndexInCount(Index,Count:Integer):boolean;
  714. procedure DrawFocusRect(Canvas:TCanvas;FocusRect:TRect;Height:Integer);
  715. procedure SetTicketPoint(Value:TTicketPosition;Self,Ticket:TControl;TicketSpace:Integer);
  716. procedure GetStyleText(Value:TAlignmentText; var Result:UINT);
  717. procedure GetCheckBoxPosition(Value:TCheckPosition; var Result:UINT);
  718. procedure DrawCheckBox(BoxRect:TRect; Position:TCheckPosition; Size:Integer; Var CheckRect:TRect);
  719. procedure GetBarPosition(ClientRect:TRect;TitleHas:boolean;TitlePosition:TTitlePosition;
  720. Var BarsRect:TBarsRect; TitleHeight, BarHeight:Integer);
  721. procedure BoxDrawBackDrop(Canvas:TCanvas;ColorStart,ColorStop:TColor;Style:TStyleOrien;
  722. ClientRect:TRect;ItemColor:TColor;Face:TStyleFace);
  723. procedure DrawBitmap(Canvas:TCanvas; DrawRect:TRect; Source:TBitmap);
  724. procedure FlatDrawText(Canvas: TCanvas; Enabled: Boolean; Caption: TCaption; DrawRect:TRect; Format:uint);
  725. function CheckValue(Value,MaxValue,MinValue: LongInt): LongInt;
  726. function RectWidth(R: TRect): Integer;
  727. function RectHeight(R: TRect): Integer;
  728. function DrawEllipse(Handle: HDC; Rect: TRect): BOOL;
  729. function RectToCenter(var R: TRect; Bounds: TRect): TRect;
  730. procedure CorrectTextbyWidth(C: TCanvas; var S: String; W: Integer);
  731. //定义 IP控制函数
  732. procedure IPEmpty(Var IP:TIP);
  733. procedure IPValue(Var IP:TIP;Inx:Word;Value:TIPChar);
  734. //定义 释放指针列表函数
  735. procedure RemoveList(List:TList; State:TListState=lsClear);
  736. //定义 重设列表区域函数
  737. procedure SetEditRect(Handle:HWnd; ClientWidth,ClientHeight,Width:Integer);
  738. //定义 水波字幕解析函数
  739. procedure GetTitleParam(Var Font: TOtherParam; Var Title:String);
  740. function GetParamColor(Value:String):TColor;
  741. function GetParamDraw3D(Value:String): Boolean;
  742. function GetParamStyle(Value:String): TFontStyles;
  743. function GetParamValue(Var Value:String; Param:String):String;
  744. function HeightOf(R: TRect): Integer;
  745. function WidthOf(R: TRect): Integer;
  746. function DelCapLink(Caption:String):String;
  747. //define TDefinePanelEx
  748. //Gradint filling functions
  749. procedure GradientFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  750. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  751. procedure GradientXPFillRect(ACanvas : TCanvas; ARect : TRect; LightColor : TColor;
  752. DarkColor : TColor; Colors : Byte);
  753. procedure GradientSimpleFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  754. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  755. procedure CopyBitmap(const Source : TBitmap; Dest : TBitmap);
  756. procedure ConvertBitmapToGrayscale(const Bmp: TBitmap);
  757. procedure DrawBitmapTransparent(Dest: TCanvas; DstX, DstY: Integer;
  758. Bitmap: TBitmap; TransparentColor: TColor);
  759. procedure TileImage(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
  760. function MakeDarkColor(AColor : TColor; ADarkRate : Integer) : TColor;
  761. //define ShowDialog api
  762. function ShowBox(const Text:String; const Flags: Longint=mbEOK): Integer;
  763. function ShowBoxExt(const Text:String; Title:String; const Flags: Longint=mbEOK): Integer;
  764. procedure ShowDialog(const Msg: string; const BtnCap:String='&Exit');
  765. procedure ShowDialogFmt(const Msg: string; const Args: array of const; const BtnCap:String='&Exit');
  766. //退出软件出现的对话框FormClose在关闭窗体中设置
  767. procedure ShowExitDialog(ShowTitle:String);
  768. //玻璃绘制函数
  769. function GradientFill(DC: HDC; Vertex: PTriVertex; NumVertex: ULONG;
  770. Mesh: Pointer; NumMesh, Mode: ULONG): BOOL; stdcall;
  771. { 颜色值转RGB }
  772. procedure GetRGB(C: TColor; out R, G, B: Integer);
  773. { 渐变函数 }
  774. procedure FillGradient(const Canvas: TCanvas; const ARect: TRect;
  775. const StartColor, EndColor: TColor; const Direction: TGradDirection);
  776. { 玻璃效果绘制函数 }
  777. procedure DrawGlassFace(Canvas: TCanvas; ARect: TRect; ColorCfg: TGlassColorCfg);
  778. { 自定义消息处理函数 }
  779. procedure ProcessMessages;
  780. { 获取WINDOWS系统临时目录 }
  781. function GetTempDirectory: String;
  782. //define Colors range
  783. var HSLRange: integer = 240;
  784. implementation
  785. procedure ShowExitDialog(ShowTitle:String);
  786. var Title:String;
  787. begin
  788. Title := ShowTitle+#13#13+'你真的想退出(Y/N)? 请三思.......';
  789. if ShowBox(Title,mbIYN)=mrYes then
  790. Application.Terminate
  791. else
  792. Application.Run;
  793. end;
  794. { 获取WINDOWS系统临时目录 }
  795. function GetTempDirectory: String;
  796. var TempDir: array[0..255] of Char;
  797. begin
  798. GetTempPath(255, TempDir);
  799. Result := StrPas(TempDir);
  800. if Result[Length(Result)] <> '\' then
  801. result := result + '\';
  802. end;
  803. { 自定义消息处理函数 }
  804. procedure ProcessMessages;
  805. var Msg:TMsg;
  806. {--------------------------------------}
  807. function ProcessMessage(Msg:TMsg):BOOL;
  808. begin
  809. result := false;
  810. if PeekMessage(Msg,0,0,0,PM_REMOVE) then
  811. begin
  812. result := True;
  813. TranslateMessage(Msg);
  814. DispatchMessage(Msg);
  815. end;
  816. end;
  817. {--------------------------------------}
  818. begin
  819. while ProcessMessage(Msg) do {loop};
  820. end;
  821. //玻璃绘制函数
  822. function GradientFill; external msimg32;
  823. //自定义对话框
  824. procedure ShowDialog(const Msg: string; const BtnCap:String='&Exit');
  825. const OkMax = 160;
  826. var Form: TForm;
  827. Dlg: TPoint;
  828. OkLeft, OkTop, OkWidth, OkHeight: Integer;
  829. function GetAveCharSize(Canvas: TCanvas): TPoint;
  830. var I: Integer;
  831. Buffer: array[0..51] of Char;
  832. begin
  833. for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
  834. for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
  835. GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
  836. Result.X := Result.X div 52;
  837. end;
  838. begin
  839. Form := TForm.Create(Application);
  840. with Form do
  841. try
  842. Font.Size := 9;
  843. Font.Name := '宋体';
  844. Canvas.Font := Font;
  845. Dlg := GetAveCharSize(Canvas);
  846. BorderStyle := bsDialog;
  847. Caption := Application.Title;
  848. ClientWidth := MulDiv(OkMax, Dlg.X, 4);
  849. Position := poScreenCenter;
  850. with TImage.Create(Form) do begin
  851. Parent := Form;
  852. AutoSize := true;
  853. Left := 4;
  854. Top := 4;
  855. Picture.Icon.Assign(Application.Icon);
  856. end;
  857. OkTop := MulDiv(8, Dlg.Y, 8);
  858. OkLeft := MulDiv(30, Dlg.X, 4);
  859. OkWidth := MulDiv(OkMax-OkLeft+8, Dlg.X, 4);
  860. with TLabel.Create(Form) do begin
  861. Parent := Form;
  862. Caption := Msg;
  863. Left := OkLeft;
  864. Top := OkTop;
  865. Constraints.MaxWidth := OkWidth;
  866. WordWrap := True;
  867. end;
  868. OkTop := OkLeft + OkTop;
  869. OkLeft := MulDiv(60, Dlg.X, 4);
  870. OkWidth := MulDiv(40, Dlg.X, 4);
  871. OkHeight := MulDiv(15, Dlg.Y, 8);
  872. with TButton.Create(Form) do begin
  873. Parent := Form;
  874. Caption := BtnCap;
  875. ModalResult := mrOk;
  876. Default := True;
  877. SetBounds(OkLeft, OkTop, OkWidth, OkHeight);
  878. end;
  879. ClientHeight:= OkTop+OkHeight+10;
  880. ShowModal;
  881. finally
  882. Form.Free;
  883. end;
  884. end;
  885. procedure ShowDialogFmt(const Msg: string; const Args: array of const; const BtnCap:String='&Exit');
  886. begin
  887. ShowDialog(Format(Msg,Args),BtnCap);
  888. end;
  889. procedure GetRGB(C: TColor; out R, G, B: Integer);
  890. begin
  891. if Integer(C) < 0 then C := GetSysColor(C and $000000FF);
  892. R := C and $FF;
  893. G := C shr 8 and $FF;
  894. B := C shr 16 and $FF;
  895. end;
  896. procedure FillGradient(const Canvas: TCanvas; const ARect: TRect;
  897. const StartColor, EndColor: TColor; const Direction: TGradDirection);
  898. var
  899. Vert: array[0..1] of TTriVertex;
  900. gRect: TGradientRect;
  901. nMode: Cardinal;
  902. R, G, B: Integer;
  903. begin
  904. Vert[0].x := ARect.Left;
  905. Vert[0].y := ARect.Top;
  906. GetRGB(StartColor, R, G, B);
  907. Vert[0].Red := R shl 8;
  908. Vert[0].Green := G shl 8;
  909. Vert[0].Blue := B shl 8;
  910. Vert[0].Alpha := 0;
  911. Vert[1].x := ARect.Right;
  912. Vert[1].y := ARect.Bottom;
  913. GetRGB(EndColor, R, G, B);
  914. Vert[1].Red := R shl 8;
  915. Vert[1].Green := G shl 8;
  916. Vert[1].Blue := B shl 8;
  917. Vert[1].Alpha := 0;
  918. gRect.UpperLeft := 0;
  919. gRect.LowerRight := 1;
  920. if Direction = gdLeftRight then
  921. nMode := GRADIENT_FILL_RECT_H
  922. else
  923. nMode := GRADIENT_FILL_RECT_V;
  924. GradientFill(Canvas.Handle, @Vert[0], 2, @gRect, 1, nMode);
  925. //GradientFill(Canvas.Handle, @Vert, 2, @gRect, 1, nMode);
  926. end;
  927. procedure DrawGlassFace(Canvas: TCanvas; ARect: TRect; ColorCfg: TGlassColorCfg);
  928. var R: TRect; OffSet:Integer;
  929. begin
  930. Canvas.Brush.Style := bsClear;
  931. with ColorCfg do begin
  932. if OBorder <> clNone then begin
  933. //外框
  934. Canvas.Pen.Color := OBorder;
  935. Canvas.Rectangle(ARect);
  936. end;
  937. if IBorder <> clNone then begin
  938. //内框
  939. InflateRect(ARect, -1, -1);
  940. Canvas.Pen.Color := IBorder;
  941. Canvas.Rectangle(ARect);
  942. end;
  943. //上下渐变效果
  944. InflateRect(ARect, -1, -1);
  945. OffSet := Round((ARect.Bottom-ARect.Top)*Ord(Way));
  946. R := Rect(ARect.Left, ARect.Top, ARect.Right,ARect.Top+OffSet);
  947. FillGradient(Canvas, R, G1Start, G1End, Style); //gdLeftRight gdTopBottom
  948. R := Rect(R.Left, R.Bottom, R.Right, ARect.Bottom);
  949. FillGradient(Canvas, R, G2Start, G2End, Style); //gdLeftRight gdTopBottom
  950. end;
  951. end;
  952. //自定义提示函数
  953. function MSGTitle(Flags:Longint):PChar;
  954. begin
  955. case Flags of
  956. {define mb_inconinformtion}
  957. mbIAll, mbIOk, mbIOC, mbIRC, mbIYN, mbIYNC:Result := '提示';
  958. {define mb_inconwarning}
  959. mbWAll, mbWOk, mbWOC, mbWRC, mbWYN, mbWYNC:Result := '警告';
  960. {define mb_inconerror}
  961. mbEAll, mbEOk, mbEOC, mbERC, mbEYN, mbEYNC:Result := '错误';
  962. {define mb_inconstop}
  963. mbQAll, mbQOk, mbQOC, mbQRC, mbQYN, mbQYNC:Result := '停止';
  964. end;
  965. end;
  966. //自定义提示函数
  967. function ShowBox(const Text:String; const Flags: Longint=mbEOK): Integer;
  968. begin
  969. result := Application.MessageBox(PChar(Text),MSGTitle(Flags),Flags);
  970. end;
  971. //自定义提示函数
  972. function ShowBoxExt(const Text:String; Title:String; const Flags: Longint=mbEOK): Integer;
  973. begin
  974. result := Application.MessageBox(PChar(Text),PChar(Title),Flags);
  975. end;
  976. //删除快捷连接符&
  977. function DelCapLink(Caption:String):String;
  978. begin
  979. result := Caption;
  980. if Pos('&', Caption) <> 0 then Delete(result, Pos('&', result), 1);
  981. end;
  982. //计算顶与底之间的距离(高度)
  983. function HeightOf(R: TRect): Integer;
  984. begin
  985. Result := R.Bottom - R.Top;
  986. end;
  987. //计算左右之间的距离(宽度)
  988. function WidthOf(R: TRect): Integer;
  989. begin
  990. Result := R.Right - R.Left;
  991. end;
  992. //在指定的区域内画图
  993. procedure TileImage(Canvas: TCanvas; Rect: TRect; Image: TGraphic);
  994. var
  995. X, Y: Integer;
  996. SaveIndex: Integer;
  997. begin
  998. if(Image.Width = 0) or(Image.Height = 0) then Exit;
  999. SaveIndex := SaveDC(Canvas.Handle);
  1000. try
  1001. with Rect do
  1002. IntersectClipRect(Canvas.Handle, Left, Top, Right, Bottom);
  1003. for X := 0 to(WidthOf(Rect) div Image.Width) do
  1004. for Y := 0 to(HeightOf(Rect) div Image.Height) do
  1005. Canvas.Draw(Rect.Left + X * Image.Width,
  1006. Rect.Top + Y * Image.Height, Image);
  1007. finally
  1008. RestoreDC(Canvas.Handle, SaveIndex);
  1009. end;
  1010. end;
  1011. //锁定颜色范围
  1012. function MakeDarkColor(AColor : TColor; ADarkRate : Integer) : TColor;
  1013. var
  1014. R, G, B : Integer;
  1015. begin
  1016. R := GetRValue(ColorToRGB(AColor)) - ADarkRate;
  1017. G := GetGValue(ColorToRGB(AColor)) - ADarkRate;
  1018. B := GetBValue(ColorToRGB(AColor)) - ADarkRate;
  1019. if R < 0 then R := 0;
  1020. if G < 0 then G := 0;
  1021. if B < 0 then B := 0;
  1022. if R > 255 then R := 255;
  1023. if G > 255 then G := 255;
  1024. if B > 255 then B := 255;
  1025. Result := TColor(RGB(R, G, B));
  1026. end;
  1027. function PaletteColor(Color: TColor): Longint;
  1028. begin
  1029. Result := ColorToRGB(Color) or PaletteMask;
  1030. end;
  1031. //对图像进行放缩
  1032. procedure StretchBltTransparent(DstDC: HDC; DstX, DstY, DstW, DstH: Integer;
  1033. SrcDC: HDC; SrcX, SrcY, SrcW, SrcH: Integer; Palette: HPalette;
  1034. TransparentColor: TColorRef);
  1035. var
  1036. Color: TColorRef;
  1037. bmAndBack, bmAndObject, bmAndMem, bmSave: HBitmap;
  1038. bmBackOld, bmObjectOld, bmMemOld, bmSaveOld: HBitmap;
  1039. MemDC, BackDC, ObjectDC, SaveDC: HDC;
  1040. palDst, palMem, palSave, palObj: HPalette;
  1041. begin
  1042. { Create some DCs to hold temporary data }
  1043. BackDC := CreateCompatibleDC(DstDC);
  1044. ObjectDC := CreateCompatibleDC(DstDC);
  1045. MemDC := CreateCompatibleDC(DstDC);
  1046. SaveDC := CreateCompatibleDC(DstDC);
  1047. { Create a bitmap for each DC }
  1048. bmAndObject := CreateBitmap(SrcW, SrcH, 1, 1, nil);
  1049. bmAndBack := CreateBitmap(SrcW, SrcH, 1, 1, nil);
  1050. bmAndMem := CreateCompatibleBitmap(DstDC, DstW, DstH);
  1051. bmSave := CreateCompatibleBitmap(DstDC, SrcW, SrcH);
  1052. { Each DC must select a bitmap object to store pixel data }
  1053. bmBackOld := SelectObject(BackDC, bmAndBack);
  1054. bmObjectOld := SelectObject(ObjectDC, bmAndObject);
  1055. bmMemOld := SelectObject(MemDC, bmAndMem);
  1056. bmSaveOld := SelectObject(SaveDC, bmSave);
  1057. { Select palette }
  1058. palDst := 0; palMem := 0; palSave := 0; palObj := 0;
  1059. if Palette <> 0 then begin
  1060. palDst := SelectPalette(DstDC, Palette, True);
  1061. RealizePalette(DstDC);
  1062. palSave := SelectPalette(SaveDC, Palette, False);
  1063. RealizePalette(SaveDC);
  1064. palObj := SelectPalette(ObjectDC, Palette, False);
  1065. RealizePalette(ObjectDC);
  1066. palMem := SelectPalette(MemDC, Palette, True);
  1067. RealizePalette(MemDC);
  1068. end;
  1069. { Set proper mapping mode }
  1070. SetMapMode(SrcDC, GetMapMode(DstDC));
  1071. SetMapMode(SaveDC, GetMapMode(DstDC));
  1072. { Save the bitmap sent here }
  1073. BitBlt(SaveDC, 0, 0, SrcW, SrcH, SrcDC, SrcX, SrcY, SRCCOPY);
  1074. { Set the background color of the source DC to the color, }
  1075. { contained in the parts of the bitmap that should be transparent }
  1076. Color := SetBkColor(SaveDC, PaletteColor(TransparentColor));
  1077. { Create the object mask for the bitmap by performing a BitBlt() }
  1078. { from the source bitmap to a monochrome bitmap }
  1079. BitBlt(ObjectDC, 0, 0, SrcW, SrcH, SaveDC, 0, 0, SRCCOPY);
  1080. { Set the background color of the source DC back to the original }
  1081. SetBkColor(SaveDC, Color);
  1082. { Create the inverse of the object mask }
  1083. BitBlt(BackDC, 0, 0, SrcW, SrcH, ObjectDC, 0, 0, NOTSRCCOPY);
  1084. { Copy the background of the main DC to the destination }
  1085. BitBlt(MemDC, 0, 0, DstW, DstH, DstDC, DstX, DstY, SRCCOPY);
  1086. { Mask out the places where the bitmap will be placed }
  1087. StretchBlt(MemDC, 0, 0, DstW, DstH, ObjectDC, 0, 0, SrcW, SrcH, SRCAND);
  1088. { Mask out the transparent colored pixels on the bitmap }
  1089. BitBlt(SaveDC, 0, 0, SrcW, SrcH, BackDC, 0, 0, SRCAND);
  1090. { XOR the bitmap with the background on the destination DC }
  1091. StretchBlt(MemDC, 0, 0, DstW, DstH, SaveDC, 0, 0, SrcW, SrcH, SRCPAINT);
  1092. { Copy the destination to the screen }
  1093. BitBlt(DstDC, DstX, DstY, DstW, DstH, MemDC, 0, 0,
  1094. SRCCOPY);
  1095. { Restore palette }
  1096. if Palette <> 0 then begin
  1097. SelectPalette(MemDC, palMem, False);
  1098. SelectPalette(ObjectDC, palObj, False);
  1099. SelectPalette(SaveDC, palSave, False);
  1100. SelectPalette(DstDC, palDst, True);
  1101. end;
  1102. { Delete the memory bitmaps }
  1103. DeleteObject(SelectObject(BackDC, bmBackOld));
  1104. DeleteObject(SelectObject(ObjectDC, bmObjectOld));
  1105. DeleteObject(SelectObject(MemDC, bmMemOld));
  1106. DeleteObject(SelectObject(SaveDC, bmSaveOld));
  1107. { Delete the memory DCs }
  1108. DeleteDC(MemDC);
  1109. DeleteDC(BackDC);
  1110. DeleteDC(ObjectDC);
  1111. DeleteDC(SaveDC);
  1112. end;
  1113. procedure StretchBitmapTransparent(Dest: TCanvas; Bitmap: TBitmap;
  1114. TransparentColor: TColor; DstX, DstY, DstW, DstH, SrcX, SrcY,
  1115. SrcW, SrcH: Integer);
  1116. var
  1117. CanvasChanging: TNotifyEvent;
  1118. begin
  1119. if DstW <= 0 then DstW := Bitmap.Width;
  1120. if DstH <= 0 then DstH := Bitmap.Height;
  1121. if(SrcW <= 0) or(SrcH <= 0) then begin
  1122. SrcX := 0; SrcY := 0;
  1123. SrcW := Bitmap.Width;
  1124. SrcH := Bitmap.Height;
  1125. end;
  1126. if not Bitmap.Monochrome then
  1127. SetStretchBltMode(Dest.Handle, STRETCH_DELETESCANS);
  1128. CanvasChanging := Bitmap.Canvas.OnChanging;
  1129. {$IFDEF VER100}
  1130. Bitmap.Canvas.Lock;
  1131. {$ENDIF}
  1132. try
  1133. Bitmap.Canvas.OnChanging := nil;
  1134. if TransparentColor = clNone then begin
  1135. StretchBlt(Dest.Handle, DstX, DstY, DstW, DstH, Bitmap.Canvas.Handle,
  1136. SrcX, SrcY, SrcW, SrcH, Dest.CopyMode);
  1137. end
  1138. else begin
  1139. {$IFDEF VER100}
  1140. if TransparentColor = clDefault then
  1141. TransparentColor := Bitmap.Canvas.Pixels[0, Bitmap.Height - 1];
  1142. {$ENDIF}
  1143. if Bitmap.Monochrome then TransparentColor := clWhite
  1144. else TransparentColor := ColorToRGB(TransparentColor);
  1145. StretchBltTransparent(Dest.Handle, DstX, DstY, DstW, DstH,
  1146. Bitmap.Canvas.Handle, SrcX, SrcY, SrcW, SrcH, Bitmap.Palette,
  1147. TransparentColor);
  1148. end;
  1149. finally
  1150. Bitmap.Canvas.OnChanging := CanvasChanging;
  1151. {$IFDEF VER100}
  1152. Bitmap.Canvas.Unlock;
  1153. {$ENDIF}
  1154. end;
  1155. end;
  1156. procedure StretchBitmapRectTransparent(Dest: TCanvas; DstX, DstY,
  1157. DstW, DstH: Integer; SrcRect: TRect; Bitmap: TBitmap;
  1158. TransparentColor: TColor);
  1159. begin
  1160. with SrcRect do
  1161. StretchBitmapTransparent(Dest, Bitmap, TransparentColor,
  1162. DstX, DstY, DstW, DstH, Left, Top, Right - Left, Bottom - Top);
  1163. end;
  1164. procedure DrawBitmapRectTransparent(Dest: TCanvas; DstX, DstY: Integer;
  1165. SrcRect: TRect; Bitmap: TBitmap; TransparentColor: TColor);
  1166. begin
  1167. with SrcRect do
  1168. StretchBitmapTransparent(Dest, Bitmap, TransparentColor,
  1169. DstX, DstY, Right - Left, Bottom - Top, Left, Top, Right - Left,
  1170. Bottom - Top);
  1171. end;
  1172. procedure DrawBitmapTransparent(Dest: TCanvas; DstX, DstY: Integer;
  1173. Bitmap: TBitmap; TransparentColor: TColor);
  1174. begin
  1175. StretchBitmapTransparent(Dest, Bitmap, TransparentColor, DstX, DstY,
  1176. Bitmap.Width, Bitmap.Height, 0, 0, Bitmap.Width, Bitmap.Height);
  1177. end;
  1178. procedure ConvertBitmapToGrayscale(const Bmp: TBitmap);
  1179. {From: Pascal Enz, pascal.enz@datacomm.ch }
  1180. type
  1181. TRGBArray = array[0..32767] of TRGBTriple;
  1182. PRGBArray = ^TRGBArray;
  1183. var
  1184. x, y, Gray: Integer;
  1185. Row: PRGBArray;
  1186. begin
  1187. Bmp.PixelFormat := pf24Bit;
  1188. for y := 0 to Bmp.Height - 1 do
  1189. begin
  1190. Row := Bmp.ScanLine[y];
  1191. for x := 0 to Bmp.Width - 1 do
  1192. begin
  1193. Gray :=(Row[x].rgbtRed + Row[x].rgbtGreen + Row[x].rgbtBlue) div 3;
  1194. Row[x].rgbtRed := Gray;
  1195. Row[x].rgbtGreen := Gray;
  1196. Row[x].rgbtBlue := Gray;
  1197. end;
  1198. end;
  1199. end;
  1200. procedure CopyBitmap(const Source : TBitmap; Dest : TBitmap);
  1201. begin
  1202. try Dest.FreeImage;
  1203. except
  1204. end;
  1205. Dest.Width := Source.Width;
  1206. Dest.Height := Source.Height;
  1207. Dest.PixelFormat := Source.PixelFormat;
  1208. BitBlt(Dest.Canvas.Handle, Dest.Canvas.ClipRect.Left, Dest.Canvas.ClipRect.Top, Dest.Width, Dest.Height,
  1209. Source.Canvas.Handle, 0, 0, SRCCOPY);
  1210. end;
  1211. procedure GradientSimpleFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  1212. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  1213. var
  1214. StartRGB: array[0..2] of Byte; { Start RGB values }
  1215. RGBDelta: array[0..2] of Integer; { Difference between start and end RGB values }
  1216. ColorBand: TRect; { Color band rectangular coordinates }
  1217. I, Delta: Integer;
  1218. Brush: HBrush;
  1219. begin
  1220. if IsRectEmpty(ARect) then Exit;
  1221. if Colors < 2 then begin
  1222. Brush := CreateSolidBrush(ColorToRGB(StartColor));
  1223. FillRect(Canvas.Handle, ARect, Brush);
  1224. DeleteObject(Brush);
  1225. Exit;
  1226. end;
  1227. StartColor := ColorToRGB(StartColor);
  1228. EndColor := ColorToRGB(EndColor);
  1229. case Direction of
  1230. fdTopToBottom, fdLeftToRight: begin
  1231. { Set the Red, Green and Blue colors }
  1232. StartRGB[0] := GetRValue(StartColor);
  1233. StartRGB[1] := GetGValue(StartColor);
  1234. StartRGB[2] := GetBValue(StartColor);
  1235. { Calculate the difference between begin and end RGB values }
  1236. RGBDelta[0] := GetRValue(EndColor) - StartRGB[0];
  1237. RGBDelta[1] := GetGValue(EndColor) - StartRGB[1];
  1238. RGBDelta[2] := GetBValue(EndColor) - StartRGB[2];
  1239. end;
  1240. fdBottomToTop, fdRightToLeft: begin
  1241. { Set the Red, Green and Blue colors }
  1242. { Reverse of TopToBottom and LeftToRight directions }
  1243. StartRGB[0] := GetRValue(EndColor);
  1244. StartRGB[1] := GetGValue(EndColor);
  1245. StartRGB[2] := GetBValue(EndColor);
  1246. { Calculate the difference between begin and end RGB values }
  1247. { Reverse of TopToBottom and LeftToRight directions }
  1248. RGBDelta[0] := GetRValue(StartColor) - StartRGB[0];
  1249. RGBDelta[1] := GetGValue(StartColor) - StartRGB[1];
  1250. RGBDelta[2] := GetBValue(StartColor) - StartRGB[2];
  1251. end;
  1252. end; {case}
  1253. { Calculate the color band's coordinates }
  1254. ColorBand := ARect;
  1255. if Direction in [fdTopToBottom, fdBottomToTop] then begin
  1256. Colors := Max(2, Min(Colors, HeightOf(ARect)));
  1257. Delta := HeightOf(ARect) div Colors;
  1258. end
  1259. else begin
  1260. Colors := Max(2, Min(Colors, WidthOf(ARect)));
  1261. Delta := WidthOf(ARect) div Colors;
  1262. end;
  1263. with Canvas.Pen do begin { Set the pen style and mode }
  1264. Style := psSolid;
  1265. Mode := pmCopy;
  1266. end;
  1267. { Perform the fill }
  1268. if Delta > 0 then begin
  1269. for I := 0 to Colors do begin
  1270. case Direction of
  1271. { Calculate the color band's top and bottom coordinates }
  1272. fdTopToBottom, fdBottomToTop: begin
  1273. ColorBand.Top := ARect.Top + I * Delta;
  1274. ColorBand.Bottom := ColorBand.Top + Delta;
  1275. end;
  1276. { Calculate the color band's left and right coordinates }
  1277. fdLeftToRight, fdRightToLeft: begin
  1278. ColorBand.Left := ARect.Left + I * Delta;
  1279. ColorBand.Right := ColorBand.Left + Delta;
  1280. end;
  1281. end; {case}
  1282. { Calculate the color band's color }
  1283. Brush := CreateSolidBrush(RGB(
  1284. StartRGB[0] + MulDiv(I, RGBDelta[0], Colors - 1),
  1285. StartRGB[1] + MulDiv(I, RGBDelta[1], Colors - 1),
  1286. StartRGB[2] + MulDiv(I, RGBDelta[2], Colors - 1)));
  1287. FillRect(Canvas.Handle, ColorBand, Brush);
  1288. DeleteObject(Brush);
  1289. end;
  1290. end;
  1291. if Direction in [fdTopToBottom, fdBottomToTop] then
  1292. Delta := HeightOf(ARect) mod Colors
  1293. else Delta := WidthOf(ARect) mod Colors;
  1294. if Delta > 0 then begin
  1295. case Direction of
  1296. { Calculate the color band's top and bottom coordinates }
  1297. fdTopToBottom, fdBottomToTop: begin
  1298. ColorBand.Top := ARect.Bottom - Delta;
  1299. ColorBand.Bottom := ColorBand.Top + Delta;
  1300. end;
  1301. { Calculate the color band's left and right coordinates }
  1302. fdLeftToRight, fdRightToLeft: begin
  1303. ColorBand.Left := ARect.Right - Delta;
  1304. ColorBand.Right := ColorBand.Left + Delta;
  1305. end;
  1306. end; {case}
  1307. case Direction of
  1308. fdTopToBottom, fdLeftToRight:
  1309. Brush := CreateSolidBrush(EndColor);
  1310. else {fdBottomToTop, fdRightToLeft }
  1311. Brush := CreateSolidBrush(StartColor);
  1312. end;
  1313. FillRect(Canvas.Handle, ColorBand, Brush);
  1314. DeleteObject(Brush);
  1315. end;
  1316. end;
  1317. procedure GradientXPFillRect(ACanvas : TCanvas; ARect : TRect; LightColor : TColor; DarkColor : TColor; Colors : Byte);
  1318. const
  1319. cLightColorOffset : Integer = 30;
  1320. cMainBarOffset : Integer = 6;
  1321. var
  1322. DRect : TRect;
  1323. I : Integer;
  1324. begin
  1325. if IsRectEmpty(ARect) then Exit;
  1326. ACanvas.Brush.Color := DarkColor;
  1327. ACanvas.FrameRect(ARect);
  1328. //InflateRect(ARect, -1, -1);
  1329. //Main center rect
  1330. DRect := ARect;
  1331. DRect.Left := DRect.Left + cMainBarOffset;
  1332. DRect.Top := DRect.Top + cMainBarOffset;
  1333. DRect.Bottom := DRect.Bottom - cMainBarOffset;
  1334. GradientSimpleFillRect(ACanvas, DRect, DarkColor, LightColor, fdTopToBottom, Colors);
  1335. //Bottom rect
  1336. DRect := ARect;
  1337. DRect.Left := DRect.Left + cMainBarOffset;
  1338. DRect.Top := ARect.Bottom - cMainBarOffset;
  1339. GradientSimpleFillRect(ACanvas, DRect, LightColor, DarkColor, fdTopToBottom, Colors);
  1340. //Second left rect
  1341. DRect := ARect;
  1342. DRect := Rect(ARect.Left + cMainBarOffset div 4, 0, ARect.Left + cMainBarOffset, 1);
  1343. For I := ARect.Top + cMainBarOffset to ARect.Bottom do
  1344. begin
  1345. DRect.Top := I;
  1346. DRect.Bottom := I+1;
  1347. GradientSimpleFillRect(ACanvas, DRect, ACanvas.Pixels [DRect.Left-1, DRect.Top],
  1348. ACanvas.Pixels [DRect.Right + 1, DRect.Top], fdLeftToRight, 8);
  1349. end;
  1350. //Top light rect
  1351. DRect := ARect;
  1352. DRect.Left := DRect.Left + cMainBarOffset;
  1353. DRect.Bottom := DRect.Top + cMainBarOffset div 4;
  1354. GradientSimpleFillRect(ACanvas, DRect, MakeDarkColor(LightColor, -cLightColorOffset), LightColor, fdTopToBottom, 8);
  1355. //Second top rect
  1356. DRect := ARect;
  1357. DRect.Left := DRect.Left + cMainBarOffset;
  1358. DRect.Top := DRect.Top + cMainBarOffset div 4;
  1359. DRect.Bottom := ARect.Top + cMainBarOffset;
  1360. GradientSimpleFillRect(ACanvas, DRect, LightColor, DarkColor, fdTopToBottom, 8);
  1361. //Left light rect
  1362. DRect := ARect;
  1363. DRect.Top := DRect.Top + cMainBarOffset;
  1364. DRect.Right := DRect.Left + cMainBarOffset div 4;
  1365. GradientSimpleFillRect(ACanvas, DRect, MakeDarkColor(LightColor, -cLightColorOffset), LightColor, fdLeftToRight, 8);
  1366. //Second left rect
  1367. DRect := ARect;
  1368. DRect := Rect(ARect.Left + cMainBarOffset div 4, 0, ARect.Left + cMainBarOffset, 1);
  1369. For I := ARect.Top + cMainBarOffset to ARect.Bottom do
  1370. begin
  1371. DRect.Top := I;
  1372. DRect.Bottom := I+1;
  1373. GradientSimpleFillRect(ACanvas, DRect, ACanvas.Pixels [DRect.Left-1, DRect.Top],
  1374. ACanvas.Pixels [DRect.Right + 1, DRect.Top], fdLeftToRight, 8);
  1375. end;
  1376. For I := 0 to cMainBarOffset do
  1377. begin
  1378. ACanvas.Pen.Color := ACanvas.Pixels [ARect.Left + I, ARect.Top + cMainBarOffset+1];
  1379. ACanvas.MoveTo(ARect.Left + I, ARect.Top + cMainBarOffset);
  1380. ACanvas.LineTo(ARect.Left + I, ARect.Top + I);
  1381. ACanvas.LineTo(ARect.Left + cMainBarOffset, ARect.Top + I);
  1382. end;
  1383. end;
  1384. procedure GradientFillRect(Canvas: TCanvas; ARect: TRect; StartColor,
  1385. EndColor: TColor; Direction: TFillDirection; Colors: Byte);
  1386. var
  1387. BRect : TRect;
  1388. begin
  1389. case Direction of
  1390. fdCenterToVerti:
  1391. begin
  1392. BRect := ARect;
  1393. BRect.Bottom := BRect.Top + HeightOf(ARect) div 2;
  1394. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdTopToBottom, Colors);
  1395. BRect.Top :=(BRect.Top + HeightOf(ARect) div 2);
  1396. BRect.Bottom := ARect.Bottom;
  1397. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdBottomToTop, Colors);
  1398. end;
  1399. fdCenterToHoriz:
  1400. begin
  1401. BRect := ARect;
  1402. BRect.Right := BRect.Left + WidthOf(ARect) div 2;
  1403. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdLeftToRight, Colors);
  1404. BRect.Left :=(BRect.Left + WidthOf(ARect) div 2);
  1405. BRect.Right := ARect.Right;
  1406. GradientSimpleFillRect(Canvas, BRect, StartColor, EndColor, fdRightToLeft, Colors);
  1407. end;
  1408. fdXPFace:
  1409. begin
  1410. GradientXPFillRect(Canvas, ARect, StartColor, EndColor, Colors);
  1411. end
  1412. else
  1413. GradientSimpleFillRect(Canvas, ARect, StartColor, EndColor, Direction, Colors);
  1414. end;
  1415. end;
  1416. procedure DrawFrame(Canvas: TCanvas; var Rect: TRect; BorderColor, FaceColor: TColor;
  1417. Width: Integer);
  1418. procedure DoRect;
  1419. begin
  1420. with Canvas, Rect do
  1421. begin
  1422. Pen.Color := BorderColor;
  1423. MoveTo(Left,Top);
  1424. LineTo(Left,Bottom);
  1425. Pen.Color := FaceColor;
  1426. MoveTo(Left,Bottom);
  1427. LineTo(Right,Bottom);
  1428. MoveTo(Left,Top);
  1429. LineTo(Right,Top);
  1430. end;
  1431. end;
  1432. begin
  1433. Canvas.Pen.Width := 1;
  1434. inc(Rect.Left);
  1435. Dec(Rect.Bottom); Dec(Rect.Right);
  1436. while Width > 0 do
  1437. begin
  1438. Dec(Width);
  1439. DoRect;
  1440. InflateRect(Rect, -1, -1);
  1441. end;
  1442. Inc(Rect.Bottom); Inc(Rect.Right);
  1443. dec(Rect.Left);
  1444. end;
  1445. procedure DrawInCheck(Canvas:TCanvas; Rect:TRect; Color:TColor);
  1446. var x,y,yTop:Word;
  1447. begin
  1448. with Canvas, Rect do
  1449. begin
  1450. yTop :=(Right - Left - 12) div 2;
  1451. x := Left + yTop;
  1452. y := Top + yTop;
  1453. Pen.Color := Color;
  1454. PenPos := Point(x+2, y+5);
  1455. LineTo(x+4,y+7);
  1456. PenPos := Point(x+4, y+7);
  1457. LineTo(x+10,y+1);
  1458. PenPos := Point(x+2, y+6);
  1459. LineTo(x+4,y+8);
  1460. PenPos := Point(x+4, y+8);
  1461. LineTo(x+10,y+2);
  1462. PenPos := Point(x+2, y+7);
  1463. LineTo(x+4,y+9);
  1464. PenPos := Point(x+4, y+9);
  1465. LineTo(x+10,y+3);
  1466. end;
  1467. end;
  1468. function DrawEditBorder(Border:TBorderAttrib; const Clip: HRGN=0):TColor;
  1469. var
  1470. DC: HDC;
  1471. R, BarRect: TRect;
  1472. FaceBrush, WindowBrush, FocusBrush: HBRUSH;
  1473. begin
  1474. with Border do
  1475. begin
  1476. DC := GetWindowDC(Ctrl.Handle);
  1477. try
  1478. GetWindowRect(Ctrl.Handle, R);
  1479. OffsetRect(R, -R.Left, -R.Top);
  1480. FaceBrush := CreateSolidBrush(ColorToRGB(BorderColor));
  1481. WindowBrush := CreateSolidBrush(ColorToRGB(FlatColor));
  1482. FocusBrush := CreateSolidBrush(ColorToRGB(FocusColor));
  1483. BarRect := Rect(R.Right - 20, R.Bottom - 20, R.Right - 3, R.Bottom - 3);
  1484. FrameRect(DC, R, FaceBrush);
  1485. if BoldState then begin
  1486. InflateRect(R, -1, -1);
  1487. FrameRect(DC, R, FaceBrush);
  1488. end;
  1489. if(not(csDesigning in DesignState) and(FocusState or MouseState)) then
  1490. begin // Focus
  1491. result := FocusColor;
  1492. InflateRect(R, -1, -1);
  1493. FrameRect(DC, R, FocusBrush);
  1494. InflateRect(R, -1, -1);
  1495. FrameRect(DC, R, FocusBrush);
  1496. if HasBars then FillRect(DC, BarRect , FocusBrush);
  1497. end else begin // non Focus
  1498. result := FlatColor;
  1499. InflateRect(R, -1, -1);
  1500. FrameRect(DC, R, WindowBrush);
  1501. InflateRect(R, -1, -1);
  1502. FrameRect(DC, R, WindowBrush);
  1503. if HasBars then FillRect(DC, BarRect, WindowBrush);
  1504. end;
  1505. finally
  1506. ReleaseDC(Ctrl.Handle, DC);
  1507. end;
  1508. DeleteObject(WindowBrush);
  1509. DeleteObject(FaceBrush);
  1510. DeleteObject(FocusBrush);
  1511. end;
  1512. end;
  1513. procedure DrawButtonBorder(Canvas: TCanvas; Rect: TRect; Color: TColor; Width: Integer);
  1514. procedure DoRect(Cans:TCanvas; R:TRect);
  1515. var
  1516. TopRight, BottomLeft: TPoint;
  1517. begin
  1518. with Cans, R do begin
  1519. TopRight.X := Right;
  1520. TopRight.Y := Top;
  1521. BottomLeft.X := Left;
  1522. BottomLeft.Y := Bottom;
  1523. Pen.Color := Color;
  1524. PolyLine([BottomLeft, TopLeft, TopRight]);
  1525. //Pen.Color := Color;
  1526. Dec(BottomLeft.X);
  1527. PolyLine([TopRight, BottomRight, BottomLeft]);
  1528. {Pen.Color := Color;
  1529. RoundRect(Rect.Left,Rect.Top,rect.Right,Rect.Bottom,2,2);}
  1530. end;
  1531. end;
  1532. begin
  1533. Canvas.Pen.Width := 1;
  1534. Dec(Rect.Bottom);
  1535. Dec(Rect.Right);
  1536. while Width > 0 do begin
  1537. Dec(Width);
  1538. DoRect(Canvas,Rect);
  1539. InflateRect(Rect, -1, -1);
  1540. end;
  1541. Inc(Rect.Bottom);
  1542. Inc(Rect.Right);
  1543. end;
  1544. function DrawViewBorder(ViewBorder: TBorderAttrib;const oVal:Byte=1):TColor;
  1545. var
  1546. R: TRect;
  1547. memBmp:TControlCanvas;
  1548. begin
  1549. memBmp:=TControlCanvas.Create;
  1550. try
  1551. with ViewBorder do
  1552. begin
  1553. memBmp.Handle := GetWindowDC(Ctrl.Handle);
  1554. GetWindowRect(Ctrl.Handle, R);
  1555. OffsetRect(R, -R.Left, -R.Top);
  1556. if(not(csDesigning in DesignState) and(FocusState or MouseState)) then
  1557. begin
  1558. result := FocusColor;
  1559. end
  1560. else
  1561. begin
  1562. result := FlatColor;
  1563. end;
  1564. dec(r.Left, oVal);
  1565. dec(r.Top, oVal);
  1566. inc(r.Right, oVal);
  1567. inc(r.Bottom, oVal);
  1568. InflateRect(R, -oVal, -oVal);
  1569. DrawButtonBorder(memBmp, R, BorderColor, oVal);
  1570. end;
  1571. finally
  1572. memBmp.FreeHandle;
  1573. memBmp.Free;
  1574. end;
  1575. end;
  1576. function GetParamValue(Var Value:String; Param:String):String;
  1577. var
  1578. FontS, FontL, Spliter : Integer;
  1579. SubValue:String;
  1580. function Find(Value:String;cur:Integer):integer;
  1581. var inx:integer;
  1582. begin
  1583. result := cur;
  1584. for inx := Cur to Length(Value) do
  1585. if Value[inx]=']' then
  1586. begin
  1587. result := inx;
  1588. exit;
  1589. end;
  1590. end;
  1591. begin
  1592. if Pos(Param,Value) > 0 then
  1593. begin
  1594. FontS := Pos(Param,Value);
  1595. FontL := FontS + Length(Param);
  1596. Spliter := Find(Value,FontS);
  1597. Result := Trim(Copy(Value,FontL,Spliter-FontL));
  1598. SubValue := format('%s%s]',[Param,Result]);
  1599. Delete(Value,Pos(SubValue,Value),Length(SubValue));
  1600. end else begin
  1601. Result := '';
  1602. end;
  1603. end;
  1604. function GetParamStyle(Value:String): TFontStyles;
  1605. begin
  1606. Result := [];
  1607. if(Pos('BOLD', Value) > 0)or(Pos('0', Value)>0) then
  1608. result := Result + [fsBold];
  1609. if(Pos('ITALIC', Value) > 0)or(Pos('1', Value)>0) then
  1610. result := Result + [fsItalic];
  1611. if(Pos('UNDERLINE', Value) > 0)or(Pos('2', Value)>0) then
  1612. result := Result + [fsUnderline];
  1613. if(Pos('STRIKEOUT', Value) > 0)or(Pos('3', Value)>0) then
  1614. result := Result + [fsStrikeOut];
  1615. end;
  1616. function GetParamPitch(Value:String): TFontPitch;
  1617. begin
  1618. Result := fpDefault;
  1619. if(Pos('VARIABLE', Value) > 0)or(Pos('1', Value)>0) then
  1620. result := fpVariable;
  1621. if(Pos('Fixed', Value) > 0)or(Pos('2', Value)>0) then
  1622. result := fpFixed;
  1623. end;
  1624. function GetParamDraw3D(Value:String): Boolean;
  1625. begin
  1626. Result := False;
  1627. if(Pos('True', Value) > 0)or(Pos('1', Value)>0) then
  1628. result := True;
  1629. end;
  1630. function GetParamColor(Value:String):TColor;
  1631. var
  1632. inx : Word;
  1633. State: Boolean;
  1634. begin
  1635. for inx := Low(WaterColor) to High(WaterColor) do
  1636. begin
  1637. State := UpperCase(WaterColor[inx].enName) = UpperCase(Value);
  1638. if State then
  1639. begin
  1640. result := WaterColor[inx].Value;
  1641. exit;
  1642. end;
  1643. end;
  1644. if not State then
  1645. result := TColor(StrToInt(Value))
  1646. else
  1647. Result := clBlack;
  1648. end;
  1649. function GetParamAlign(Value:String):TWaterAlign;
  1650. begin
  1651. result := wpCenter;
  1652. if(Pos('ALIGN', Value) > 0)or(Pos('0', Value)>0) then
  1653. result := wpLeft;
  1654. if(Pos('ALIGN', Value) > 0)or(Pos('2', Value)>0) then
  1655. result := wpRight;
  1656. end;
  1657. procedure GetTitleParam(Var Font: TOtherParam; Var Title:String);
  1658. var
  1659. Value, Param:String;
  1660. FontS,FontE,Inx:Integer;
  1661. begin
  1662. Value := Title;
  1663. FontS := Pos(UpperCase(TitleStart), UpperCase(Value));
  1664. FontE := Pos(UpperCase(TitleEnd), UpperCase(Value));
  1665. Inx := FontS + Length(TitleStart);
  1666. Title := Copy(Value, Inx, FontE - Length(TitleEnd));
  1667. if(FontS > 0) and(FontE > 0) then
  1668. begin
  1669. Inx := FontE + Length(TitleEnd);
  1670. Value := UpperCase(Copy(Value, Inx, Length(Value)));
  1671. //解析 字体的大小
  1672. Param := GetParamValue(Value, UpperCase(TitleSize));
  1673. if Param <> '' then
  1674. Font.Size := StrToInt(Param)
  1675. else
  1676. Font.Size := 8;
  1677. //解析 字体的名称
  1678. Param := GetParamValue(Value, UpperCase(TitleName));
  1679. if Param <> '' then
  1680. Font.Name := Param
  1681. else
  1682. Font.Name := 'MS Sans Serif';
  1683. //解析 字体的样式
  1684. Param := GetParamValue(Value, UpperCase(TitleStyle));
  1685. if Param <> '' then
  1686. Font.Style := GetParamStyle(Param)
  1687. else
  1688. Font.Style := [];
  1689. //解析 字体的颜色
  1690. Param := GetParamValue(Value, UpperCase(TitleColor));
  1691. if Param <> '' then
  1692. Font.Color := GetParamColor(Param)
  1693. else
  1694. Font.Color := clWindowText;
  1695. //解析 行距
  1696. Param := GetParamValue(Value, UpperCase(TitleLow));
  1697. if Param <> '' then
  1698. Font.Row := StrToInt(Param)
  1699. else
  1700. Font.Row := 0;
  1701. Param := GetParamValue(Value, UpperCase(TitlePitch));
  1702. if Param <> '' then
  1703. Font.Pitch := GetParamPitch(Param)
  1704. else
  1705. Font.Pitch := fpDefault;
  1706. Param := GetParamValue(Value, UpperCase(TitleDraw3D));
  1707. if Param <> '' then
  1708. Font.Draw3D := GetParamDraw3D(Param)
  1709. else
  1710. Font.Draw3D := False;
  1711. Param := GetParamValue(Value, UpperCase(TitleAlign));
  1712. if Param <> '' then
  1713. Font.Align := GetParamAlign(Param)
  1714. else
  1715. Font.Align := wpCenter;
  1716. end else begin
  1717. Title := '';
  1718. end;
  1719. end;
  1720. procedure SetEditRect(Handle:HWnd; ClientWidth,ClientHeight,Width:Integer);
  1721. var
  1722. Loc: TRect;
  1723. begin
  1724. SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
  1725. Loc := Rect(0, 0, ClientWidth - Width - 3, ClientHeight);
  1726. SendMessage(Handle, EM_SETRECTNP, 0, LongInt(@Loc));
  1727. SendMessage(Handle, EM_GETRECT, 0, LongInt(@Loc));
  1728. end;
  1729. procedure RemoveList(List:TList; State:TListState=lsClear);
  1730. var inx:integer;
  1731. begin
  1732. //NO.1 free all the memory pointer
  1733. for inx:=0 to List.Count - 1 do
  1734. Dispose(List.Items[inx]);
  1735. //NO.2 user select lsClear or lsFree to List;
  1736. case State of
  1737. lsClear : List.Clear;
  1738. lsFree : List.Free;
  1739. end;
  1740. end;
  1741. procedure IPEmpty(Var IP:TIP);
  1742. begin
  1743. IP.NO1 := ' 0 ';
  1744. IP.NO2 := ' 0 ';
  1745. IP.NO3 := ' 0 ';
  1746. IP.NO4 := ' 0 ';
  1747. end;
  1748. procedure IPValue(Var IP:TIP;Inx:Word;Value:TIPChar);
  1749. begin
  1750. case inx of
  1751. 1:IP.NO1 := Value;
  1752. 2:IP.NO2 := Value;
  1753. 3:IP.NO3 := Value;
  1754. 4:IP.NO4 := Value;
  1755. end
  1756. end;
  1757. procedure CorrectTextbyWidth(C: TCanvas; var S: String; W: Integer);
  1758. var
  1759. j: Integer;
  1760. begin
  1761. j := Length(S);
  1762. with C do
  1763. begin
  1764. if TextWidth(S) > w
  1765. then
  1766. begin
  1767. repeat
  1768. Delete(S, j, 1);
  1769. Dec(j);
  1770. until(TextWidth(S + '...') <= w) or(S = '');
  1771. S := S + '...';
  1772. end;
  1773. end;
  1774. end;
  1775. function RectToCenter(var R: TRect; Bounds: TRect): TRect;
  1776. var
  1777. OffsetLeft,OffsetTop:Integer;
  1778. begin
  1779. OffSetLeft :=(RectWidth(Bounds) - RectWidth(R)) div 2;
  1780. OffsetTop :=(RectHeight(Bounds) - RectHeight(R)) div 2;
  1781. OffsetRect(R, -R.Left, -R.Top);
  1782. OffsetRect(R, OffsetLeft, OffsetTop);
  1783. OffsetRect(R, Bounds.Left, Bounds.Top);
  1784. Result := R;
  1785. end;
  1786. function RectWidth(R: TRect): Integer;
  1787. begin
  1788. Result := R.Right - R.Left;
  1789. end;
  1790. function RectHeight(R: TRect): Integer;
  1791. begin
  1792. Result := R.Bottom - R.Top;
  1793. end;
  1794. function CheckValue(Value,MaxValue,MinValue: LongInt): LongInt;
  1795. begin
  1796. Result := Value;
  1797. if(MaxValue <> MinValue) then
  1798. begin
  1799. if Value < MinValue then
  1800. Result := MinValue
  1801. else
  1802. if Value > MaxValue then
  1803. Result := MaxValue;
  1804. end;
  1805. end;
  1806. procedure FlatDrawText(Canvas: TCanvas; Enabled: Boolean; Caption: TCaption; DrawRect:TRect; Format:uint);
  1807. begin
  1808. with Canvas do begin
  1809. brush.style := bsClear;
  1810. InflateRect(DrawRect, -4, 0);
  1811. if Enabled then begin
  1812. DrawText(Handle, PChar(Caption), Length(Caption), DrawRect, Format);
  1813. end else begin
  1814. OffsetRect(DrawRect, 1, 1);
  1815. Font.Color := clBtnHighlight;
  1816. DrawText(Handle, PChar(Caption), Length(Caption), DrawRect, Format);
  1817. OffsetRect(DrawRect, -1, -1);
  1818. Font.Color := clBtnShadow;
  1819. DrawText(Handle, PChar(Caption), Length(Caption), DrawRect, Format);
  1820. end;
  1821. InflateRect(DrawRect, +4, 0);
  1822. end;
  1823. end;
  1824. procedure DrawBitmap(Canvas:TCanvas; DrawRect:TRect; Source:TBitmap);
  1825. begin
  1826. Canvas.StretchDraw(DrawRect, Source);
  1827. end;
  1828. procedure BoxDrawBackdrop(Canvas:TCanvas;ColorStart,ColorStop:TColor;Style:TStyleOrien;
  1829. ClientRect:TRect;ItemColor:TColor;Face:TStyleFace);
  1830. begin
  1831. if Face = fsDefault then begin
  1832. canvas.Brush.Color := ItemColor;
  1833. canvas.FillRect(ClientRect);
  1834. end else begin
  1835. DrawBackdrop(canvas,ColorStart,ColorStop,ClientRect,Style)
  1836. end;
  1837. end;
  1838. procedure GetBarPosition(ClientRect:TRect;TitleHas:boolean;TitlePosition:TTitlePosition;
  1839. Var BarsRect:TBarsRect; TitleHeight, BarHeight:Integer);
  1840. begin
  1841. with BarsRect do begin
  1842. prevRect := ClientRect;
  1843. downRect := ClientRect;
  1844. if TitleHas then begin
  1845. case TitlePosition of
  1846. tsTop :begin
  1847. prevRect.Top := prevRect.Top + TitleHeight;
  1848. prevRect.Bottom := prevRect.Top + BarHeight;
  1849. downRect.Top := downRect.Bottom - BarHeight;
  1850. end;
  1851. tsBottom:begin
  1852. prevRect.Bottom := prevRect.Top + BarHeight;
  1853. downRect.Bottom := downRect.Bottom - TitleHeight;
  1854. downRect.Top := downRect.Bottom - BarHeight;
  1855. end;
  1856. end;
  1857. end else begin
  1858. prevRect.Bottom := prevRect.Top + BarHeight;
  1859. downRect.Top := downRect.Bottom - BarHeight;
  1860. end;
  1861. end;
  1862. end;
  1863. function Max(const A, B: Integer): Integer;
  1864. begin
  1865. if A > B then
  1866. Result := A
  1867. else
  1868. Result := B;
  1869. end;
  1870. procedure DrawCheckBox(BoxRect:TRect; Position:TCheckPosition; Size:Integer; Var CheckRect:TRect);
  1871. var
  1872. RectPos:TPoint;
  1873. xLeft,yTop,y:integer;
  1874. begin
  1875. y :=(BoxRect.Bottom - BoxRect.Top - Size) div 2;
  1876. if Position = bpLeft then begin
  1877. RectPos := Point(BoxRect.Left, BoxRect.Top);
  1878. CheckRect := Rect(RectPos.x + 3, RectPos.y + y, RectPos.x + Size, RectPos.y + Size + y);
  1879. end else begin
  1880. RectPos := Point(BoxRect.Right, BoxRect.Top);
  1881. CheckRect := Rect(RectPos.x - Size - 3 , RectPos.y + y, RectPos.x - Size- 6, RectPos.y + Size + y);
  1882. end;
  1883. xLeft := CheckRect.Bottom-CheckRect.Top;
  1884. yTop := CheckRect.Right -CheckRect.Left;
  1885. CheckRect.Right := CheckRect.Left + Max(xLeft,yTop);
  1886. end;
  1887. procedure GetStyleText(Value:TAlignmentText; var Result:UINT);
  1888. begin
  1889. case Value of
  1890. stLeft : result := DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  1891. stRight : result := DT_RIGHT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  1892. stCenter : result := DT_CENTER or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  1893. end;
  1894. end;
  1895. procedure GetCheckBoxPosition(Value:TCheckPosition; var Result:UINT);
  1896. begin
  1897. case Value of
  1898. bpLeft : result := DT_LEFT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  1899. bpRight : result := DT_RIGHT or DT_VCENTER or DT_SINGLELINE or DT_NOPREFIX;
  1900. end;
  1901. end;
  1902. procedure SetTicketPoint(Value:TTicketPosition;Self,Ticket:TControl;TicketSpace:Integer);
  1903. var result : TPoint;
  1904. begin
  1905. case Value of
  1906. poTop: result := Point(Self.Left, Self.Top - Ticket.Height - TicketSpace);
  1907. poBottom: result := Point(Self.Left, Self.Top + Self.Height + TicketSpace);
  1908. poLeft : result := Point(Self.Left - Ticket.Width - TicketSpace, Self.Top +((Self.Height - Ticket.Height) div 2));
  1909. poRight: result := Point(Self.Left + Self.Width + TicketSpace, Self.Top +((Self.Height - Ticket.Height) div 2));
  1910. end;
  1911. Ticket.SetBounds(result.x, result.y, Ticket.Width, Ticket.Height);
  1912. end;
  1913. procedure DrawFocusRect(Canvas:TCanvas;FocusRect:TRect;Height:Integer);
  1914. begin
  1915. FocusRect := Rect(FocusRect.left + 2, FocusRect.top + 2, FocusRect.Right - 2, FocusRect.top + Height - 2);
  1916. Canvas.DrawFocusRect(FocusRect);
  1917. end;
  1918. function IndexInCount(Index,Count:Integer):boolean;
  1919. begin
  1920. result :=(Index >= 0) and(Index < Count);
  1921. end;
  1922. procedure DrawBackdrop(Canvas:TCanvas; StartColor, StopColor: TColor; CanRect:TRect;Style:TStyleOrien);
  1923. var
  1924. iCounter, iBuffer, iFillStep: integer;
  1925. bR1, bG1, bB1, bR2, bG2, bB2: byte;
  1926. aColor1, aColor2: LongInt;
  1927. dCurR, dCurG, dCurB, dRStep, dGStep, dBStep: double;
  1928. iDrawLen, iDrawPos: integer;
  1929. rCans : TRect;
  1930. iLeft, iTop, iRight, iBottom: integer;
  1931. begin
  1932. iLeft := CanRect.Left;
  1933. iTop := CanRect.Top;
  1934. iRight := CanRect.Right;
  1935. iBottom := CanRect.Bottom;
  1936. aColor1 := ColorToRGB(StartColor);
  1937. bR1 := GetRValue(aColor1);
  1938. bG1 := GetGValue(aColor1);
  1939. bB1 := GetBValue(aColor1);
  1940. aColor2 := ColorToRGB(StopColor);
  1941. bR2 := GetRValue(aColor2);
  1942. bG2 := GetGValue(aColor2);
  1943. bB2 := GetBValue(aColor2);
  1944. dCurR := bR1;
  1945. dCurG := bG1;
  1946. dCurB := bB1;
  1947. dRStep :=(bR2-bR1) / 31;
  1948. dGStep :=(bG2-bG1) / 31;
  1949. dBStep :=(bB2-bB1) / 31;
  1950. if Style = bsHorizontal then
  1951. iDrawLen :=(iRight - iLeft)
  1952. else
  1953. iDrawLen :=(iBottom - iTop);
  1954. iFillStep :=(iDrawLen div 31) + 1;
  1955. for iCounter := 0 to 31 do begin
  1956. iBuffer := iCounter * iDrawLen div 31;
  1957. Canvas.Brush.Color := RGB(trunc(dCurR), trunc(dCurG), trunc(dCurB));
  1958. dCurR := dCurR + dRStep;
  1959. dCurG := dCurG + dGStep;
  1960. dCurB := dCurB + dBStep;
  1961. if Style = bsHorizontal then begin
  1962. iDrawPos := iLeft + iBuffer + iFillStep;
  1963. if iDrawPos > iRight then iDrawPos := iRight;
  1964. rCans := Rect(iLeft + iBuffer, iTop, iDrawPos, iBottom);
  1965. end else begin
  1966. iDrawPos := iTop + iBuffer + iFillStep;
  1967. if iDrawPos > iBottom then iDrawPos := iBottom;
  1968. rCans := Rect(iLeft, iTop + iBuffer, iRight, iDrawPos);
  1969. end;
  1970. Canvas.FillRect(rCans);
  1971. end;
  1972. end;
  1973. procedure DrawTransBitBlt(Cnv: TCanvas; x, y: Integer; Bmp: TBitmap; clTransparent: TColor);
  1974. var
  1975. bmpXOR, bmpAND, bmpINV, bmpTAG: TBitmap;
  1976. oldcol: Longint;
  1977. begin
  1978. bmpAND := TBitmap.Create;
  1979. bmpINV := TBitmap.Create;
  1980. bmpXOR := TBitmap.Create;
  1981. bmpTAG := TBitmap.Create;
  1982. try
  1983. bmpAND.Width := Bmp.Width;
  1984. bmpAND.Height := Bmp.Height;
  1985. bmpAND.Monochrome := True;
  1986. oldcol := SetBkColor(Bmp.Canvas.Handle, ColorToRGB(clTransparent));
  1987. BitBlt(bmpAND.Canvas.Handle, 0, 0, Bmp.Width ,Bmp.Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
  1988. SetBkColor(Bmp.Canvas.Handle, oldcol);
  1989. bmpINV.Width := Bmp.Width;
  1990. bmpINV.Height := Bmp.Height;
  1991. bmpINV.Monochrome := True;
  1992. BitBlt(bmpINV.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, bmpAND.Canvas.Handle, 0, 0, NOTSRCCOPY);
  1993. bmpXOR.Width := Bmp.Width;
  1994. bmpXOR.Height := Bmp.Height;
  1995. BitBlt(bmpXOR.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, Bmp.Canvas.Handle, 0, 0, SRCCOPY);
  1996. BitBlt(bmpXOR.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, bmpINV.Canvas.Handle, 0, 0, SRCAND);
  1997. bmpTAG.Width := Bmp.Width;
  1998. bmpTAG.Height := Bmp.Height;
  1999. BitBlt(bmpTAG.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, Cnv.Handle, x, y, SRCCOPY);
  2000. BitBlt(bmpTAG.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, bmpAND.Canvas.Handle, 0, 0, SRCAND);
  2001. BitBlt(bmpTAG.Canvas.Handle, 0, 0,Bmp.Width,Bmp.Height, bmpXOR.Canvas.Handle, 0, 0, SRCINVERT);
  2002. BitBlt(Cnv.Handle, x, y, Bmp.Width, Bmp.Height, bmpTAG.Canvas.Handle, 0, 0, SRCCOPY);
  2003. finally
  2004. bmpXOR.Free;
  2005. bmpAND.Free;
  2006. bmpINV.Free;
  2007. bmpTAG.Free;
  2008. end;
  2009. end;
  2010. procedure DrawParentImageSub(Control: TControl; Dest: TCanvas;const DefaultHeigth:integer=0);
  2011. var
  2012. SaveIndex: Integer;
  2013. DC: HDC;
  2014. Position: TPoint;
  2015. begin
  2016. with Control do
  2017. begin
  2018. if Parent = nil then Exit;
  2019. DC := Dest.Handle;
  2020. SaveIndex := SaveDC(DC);
  2021. {$IFDEF DFS_COMPILER_2}
  2022. GetViewportOrgEx(DC, @Position);
  2023. {$ELSE}
  2024. GetViewportOrgEx(DC, Position);
  2025. {$ENDIF}
  2026. SetViewportOrgEx(DC, Position.X - Left, Position.Y - Top, nil);
  2027. IntersectClipRect(DC, 0, 0, Parent.ClientWidth, DefaultHeigth);
  2028. Parent.Perform(WM_ERASEBKGND, DC, 0);
  2029. Parent.Perform(WM_PAINT, DC, 0);
  2030. RestoreDC(DC, SaveIndex);
  2031. end;
  2032. end;
  2033. procedure DrawParentImage(Control: TControl; Dest: TCanvas;const DefaultTop:integer=0);
  2034. var
  2035. SaveIndex: Integer;
  2036. DC: HDC;
  2037. Position: TPoint;
  2038. begin
  2039. with Control do
  2040. begin
  2041. if Parent = nil then Exit;
  2042. DC := Dest.Handle;
  2043. SaveIndex := SaveDC(DC);
  2044. {$IFDEF DFS_COMPILER_2}
  2045. GetViewportOrgEx(DC, @Position);
  2046. {$ELSE}
  2047. GetViewportOrgEx(DC, Position);
  2048. {$ENDIF}
  2049. SetViewportOrgEx(DC, Position.X - Left, Position.Y - Top, nil);
  2050. IntersectClipRect(DC, 0, DefaultTop, Parent.ClientWidth, Parent.ClientHeight);
  2051. Parent.Perform(WM_ERASEBKGND, DC, 0);
  2052. Parent.Perform(WM_PAINT, DC, 0);
  2053. RestoreDC(DC, SaveIndex);
  2054. end;
  2055. end;
  2056. function DrawEllipse(Handle: HDC; Rect:TRect): BOOL;
  2057. begin
  2058. result := Ellipse(Handle, Rect.Left, Rect.Top, Rect.Right, Rect.Bottom);
  2059. end;
  2060. function CreateDisabledBitmap(FOriginal: TBitmap; OutlineColor, BackColor, HighlightColor, ShadowColor: TColor; DrawHighlight: Boolean): TBitmap;
  2061. const
  2062. ROP_DSPDxax = $00E20746;
  2063. var
  2064. MonoBmp: TBitmap;
  2065. IRect: TRect;
  2066. begin
  2067. IRect := Rect(0, 0, FOriginal.Width, FOriginal.Height);
  2068. Result := TBitmap.Create;
  2069. try
  2070. Result.Width := FOriginal.Width;
  2071. Result.Height := FOriginal.Height;
  2072. MonoBmp := TBitmap.Create;
  2073. try
  2074. with MonoBmp do begin
  2075. Width := FOriginal.Width;
  2076. Height := FOriginal.Height;
  2077. Canvas.CopyRect(IRect, FOriginal.Canvas, IRect);
  2078. {$IFDEF DFS_DELPHI_3_UP}
  2079. HandleType := bmDDB;
  2080. {$ENDIF}
  2081. Canvas.Brush.Color := OutlineColor;
  2082. if Monochrome then begin
  2083. Canvas.Font.Color := clWhite;
  2084. Monochrome := False;
  2085. Canvas.Brush.Color := clWhite;
  2086. end;
  2087. Monochrome := True;
  2088. end;
  2089. with Result.Canvas do begin
  2090. Brush.Color := BackColor;
  2091. FillRect(IRect);
  2092. if DrawHighlight then begin
  2093. Brush.Color := HighlightColor;
  2094. SetTextColor(Handle, clBlack);
  2095. SetBkColor(Handle, clWhite);
  2096. BitBlt(Handle, 1, 1, IRect.Right - IRect.Left, IRect.Bottom - IRect.Top, MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
  2097. end;
  2098. Brush.Color := ShadowColor;
  2099. SetTextColor(Handle, clBlack);
  2100. SetBkColor(Handle, clWhite);
  2101. BitBlt(Handle, 0, 0, IRect.Right - IRect.Left, IRect.Bottom - IRect.Top, MonoBmp.Canvas.Handle, 0, 0, ROP_DSPDxax);
  2102. end;
  2103. finally
  2104. MonoBmp.Free;
  2105. end;
  2106. except
  2107. Result.Free;
  2108. raise;
  2109. end;
  2110. end;
  2111. function HSLtoRGB(H, S, L: double): TColor;
  2112. var
  2113. M1, M2: double;
  2114. function HueToColourValue(Hue: double) : byte;
  2115. var
  2116. V : double;
  2117. begin
  2118. if Hue < 0 then
  2119. Hue := Hue + 1
  2120. else
  2121. if Hue > 1 then
  2122. Hue := Hue - 1;
  2123. if 6 * Hue < 1 then
  2124. V := M1 +(M2 - M1) * Hue * 6
  2125. else
  2126. if 2 * Hue < 1 then
  2127. V := M2
  2128. else
  2129. if 3 * Hue < 2 then
  2130. V := M1 +(M2 - M1) *(2/3 - Hue) * 6
  2131. else
  2132. V := M1;
  2133. Result := round(255 * V)
  2134. end;
  2135. var
  2136. R, G, B: byte;
  2137. begin
  2138. if S = 0 then
  2139. begin
  2140. R := round(255 * L);
  2141. G := R;
  2142. B := R
  2143. end else begin
  2144. if L <= 0.5 then
  2145. M2 := L *(1 + S)
  2146. else
  2147. M2 := L + S - L * S;
  2148. M1 := 2 * L - M2;
  2149. R := HueToColourValue(H + 1/3);
  2150. G := HueToColourValue(H);
  2151. B := HueToColourValue(H - 1/3)
  2152. end;
  2153. Result := RGB(R, G, B)
  2154. end;
  2155. function HSLRangeToRGB(H, S, L : integer): TColor;
  2156. begin
  2157. Result := HSLToRGB(H /(HSLRange-1), S / HSLRange, L / HSLRange)
  2158. end;
  2159. // Convert RGB value(0-255 range) into HSL value(0-1 values)
  2160. procedure RGBtoHSL(RGB: TColor; var H, S, L : double);
  2161. function Max(a, b : double): double;
  2162. begin
  2163. if a > b then
  2164. Result := a
  2165. else
  2166. Result := b
  2167. end;
  2168. function Min(a, b : double): double;
  2169. begin
  2170. if a < b then
  2171. Result := a
  2172. else
  2173. Result := b
  2174. end;
  2175. var
  2176. R, G, B, D, Cmax, Cmin: double;
  2177. begin
  2178. R := GetRValue(RGB) / 255;
  2179. G := GetGValue(RGB) / 255;
  2180. B := GetBValue(RGB) / 255;
  2181. Cmax := Max(R, Max(G, B));
  2182. Cmin := Min(R, Min(G, B));
  2183. // calculate luminosity
  2184. L :=(Cmax + Cmin) / 2;
  2185. if Cmax = Cmin then // it's grey
  2186. begin
  2187. H := 0; // it's actually undefined
  2188. S := 0
  2189. end else begin
  2190. D := Cmax - Cmin;
  2191. // calculate Saturation
  2192. if L < 0.5 then
  2193. S := D /(Cmax + Cmin)
  2194. else
  2195. S := D /(2 - Cmax - Cmin);
  2196. // calculate Hue
  2197. if R = Cmax then
  2198. H :=(G - B) / D
  2199. else
  2200. if G = Cmax then
  2201. H := 2 +(B - R) /D
  2202. else
  2203. H := 4 +(R - G) / D;
  2204. H := H / 6;
  2205. if H < 0 then
  2206. H := H + 1
  2207. end
  2208. end;
  2209. procedure RGBtoHSLRange(RGB: TColor; var H, S, L : integer);
  2210. var
  2211. Hd, Sd, Ld: double;
  2212. begin
  2213. RGBtoHSL(RGB, Hd, Sd, Ld);
  2214. H := round(Hd *(HSLRange-1));
  2215. S := round(Sd * HSLRange);
  2216. L := round(Ld * HSLRange);
  2217. end;
  2218. function CalcAdvancedColor(ParentColor, OriginalColor: TColor; Percent: Byte; ColorType: TColorCalcType): TColor;
  2219. var
  2220. H, S, L: integer;
  2221. begin
  2222. if Percent <> 0 then
  2223. begin
  2224. RGBtoHSLRange(ColorToRGB(ParentColor), H, S, L);
  2225. inc(L, 10);
  2226. if ColorType = lighten then
  2227. if L + Percent > 100 then
  2228. L := 100
  2229. else
  2230. inc(L, Percent)
  2231. else
  2232. if L - Percent < 0 then
  2233. L := 0
  2234. else
  2235. dec(L, Percent);
  2236. Result := HSLRangeToRGB(H, S, L);
  2237. end
  2238. else
  2239. Result := OriginalColor;
  2240. end;
  2241. procedure CalcButtonLayout(Canvas: TCanvas; const Client: TRect; const Offset: TPoint; Layout: TButtonLayout;
  2242. Spacing, Margin: Integer; FGlyph: TBitmap; FNumGlyphs: Integer;
  2243. const Caption: string; var TextBounds: TRect; var GlyphPos: TPoint);
  2244. var
  2245. TextPos: TPoint;
  2246. ClientSize, GlyphSize, TextSize: TPoint;
  2247. TotalSize: TPoint;
  2248. begin
  2249. // calculate the item sizes
  2250. ClientSize := Point(Client.Right - Client.Left, Client.Bottom - Client.Top);
  2251. if FGlyph <> nil then
  2252. GlyphSize := Point(FGlyph.Width div FNumGlyphs, FGlyph.Height)
  2253. else
  2254. GlyphSize := Point(0, 0);
  2255. if Length(Caption) > 0 then
  2256. begin
  2257. TextBounds := Rect(0, 0, Client.Right - Client.Left, 0);
  2258. DrawText(Canvas.Handle, PChar(Caption), Length(Caption), TextBounds, DT_CALCRECT or DT_SINGLELINE);
  2259. TextSize := Point(TextBounds.Right - TextBounds.Left, TextBounds.Bottom - TextBounds.Top);
  2260. end
  2261. else
  2262. begin
  2263. TextBounds := Rect(0, 0, 0, 0);
  2264. TextSize := Point(0, 0);
  2265. end;
  2266. // If the layout has the glyph on the right or the left, then both the
  2267. // text and the glyph are centered vertically. If the glyph is on the top
  2268. // or the bottom, then both the text and the glyph are centered horizontally.
  2269. if Layout in [blGlyphLeft, blGlyphRight] then
  2270. begin
  2271. GlyphPos.Y :=(ClientSize.Y - GlyphSize.Y + 1) div 2;
  2272. TextPos.Y :=(ClientSize.Y - TextSize.Y + 1) div 2;
  2273. end
  2274. else
  2275. begin
  2276. GlyphPos.X :=(ClientSize.X - GlyphSize.X + 1) div 2;
  2277. TextPos.X :=(ClientSize.X - TextSize.X + 1) div 2;
  2278. end;
  2279. // if there is no text or no bitmap, then Spacing is irrelevant
  2280. if(TextSize.X = 0) or(GlyphSize.X = 0) then
  2281. Spacing := 0;
  2282. // adjust Margin and Spacing
  2283. if Margin = -1 then
  2284. begin
  2285. if Spacing = -1 then
  2286. begin
  2287. TotalSize := Point(GlyphSize.X + TextSize.X, GlyphSize.Y + TextSize.Y);
  2288. if Layout in [blGlyphLeft, blGlyphRight] then
  2289. Margin :=(ClientSize.X - TotalSize.X) div 3
  2290. else
  2291. Margin :=(ClientSize.Y - TotalSize.Y) div 3;
  2292. Spacing := Margin;
  2293. end
  2294. else
  2295. begin
  2296. TotalSize := Point(GlyphSize.X + Spacing + TextSize.X, GlyphSize.Y + Spacing + TextSize.Y);
  2297. if Layout in [blGlyphLeft, blGlyphRight] then
  2298. Margin :=(ClientSize.X - TotalSize.X + 1) div 2
  2299. else
  2300. Margin :=(ClientSize.Y - TotalSize.Y + 1) div 2;
  2301. end;
  2302. end
  2303. else
  2304. begin
  2305. if Spacing = -1 then
  2306. begin
  2307. TotalSize := Point(ClientSize.X -(Margin + GlyphSize.X), ClientSize.Y -(Margin + GlyphSize.Y));
  2308. if Layout in [blGlyphLeft, blGlyphRight] then
  2309. Spacing :=(TotalSize.X - TextSize.X) div 2
  2310. else
  2311. Spacing :=(TotalSize.Y - TextSize.Y) div 2;
  2312. end;
  2313. end;
  2314. case Layout of
  2315. blGlyphLeft:
  2316. begin
  2317. GlyphPos.X := Margin;
  2318. TextPos.X := GlyphPos.X + GlyphSize.X + Spacing;
  2319. end;
  2320. blGlyphRight:
  2321. begin
  2322. GlyphPos.X := ClientSize.X - Margin - GlyphSize.X;
  2323. TextPos.X := GlyphPos.X - Spacing - TextSize.X;
  2324. end;
  2325. blGlyphTop:
  2326. begin
  2327. GlyphPos.Y := Margin;
  2328. TextPos.Y := GlyphPos.Y + GlyphSize.Y + Spacing;
  2329. end;
  2330. blGlyphBottom:
  2331. begin
  2332. GlyphPos.Y := ClientSize.Y - Margin - GlyphSize.Y;
  2333. TextPos.Y := GlyphPos.Y - Spacing - TextSize.Y;
  2334. end;
  2335. end;
  2336. // fixup the result variables
  2337. with GlyphPos do
  2338. begin
  2339. Inc(X, Client.Left + Offset.X);
  2340. Inc(Y, Client.Top + Offset.Y);
  2341. end;
  2342. OffsetRect(TextBounds, TextPos.X + Client.Left + Offset.X, TextPos.Y + Client.Top + Offset.X);
  2343. end;
  2344. function Min(const A, B: Integer): Integer;
  2345. begin
  2346. if A > B then
  2347. Result := B
  2348. else
  2349. Result := A;
  2350. end;
  2351. function GetFontMetrics(Font: TFont): TTextMetric;
  2352. var
  2353. DC: HDC;
  2354. SaveFont: HFont;
  2355. begin
  2356. DC := GetDC(0);
  2357. SaveFont := SelectObject(DC, Font.Handle);
  2358. GetTextMetrics(DC, Result);
  2359. SelectObject(DC, SaveFont);
  2360. ReleaseDC(0, DC);
  2361. end;
  2362. function GetFontHeight(Font: TFont): Integer;
  2363. begin
  2364. with GetFontMetrics(Font) do
  2365. Result := Round(tmHeight + tmHeight / 8);
  2366. end;
  2367. function RectInRect(R1, R2: TRect): Boolean;
  2368. begin
  2369. Result := IntersectRect(R1, R1, R2);
  2370. end;
  2371. function CheckByte(Value:Byte):Byte;
  2372. begin
  2373. result := Value;
  2374. if Value <= Low(Byte) then
  2375. result := 1;
  2376. if Value >= High(Byte) then
  2377. result := High(Byte);
  2378. end;
  2379. { TVersionControl }
  2380. function TVersionControl.GetVersion: String;
  2381. begin
  2382. Result := FileVersion;
  2383. end;
  2384. { TVersionComboBox }
  2385. function TVersionComboBox.GetVersion: String;
  2386. begin
  2387. Result := FileVersion;
  2388. end;
  2389. { TVersionGraphic }
  2390. function TVersionGraphic.GetVersion: String;
  2391. begin
  2392. Result := FileVersion;
  2393. end;
  2394. { TVersionTreeView }
  2395. function TVersionTreeView.GetVersion: String;
  2396. begin
  2397. Result := FileVersion;
  2398. end;
  2399. { TVersionComponent }
  2400. function TVersionComponent.GetVersion: String;
  2401. begin
  2402. Result := FileVersion;
  2403. end;
  2404. { TVersionListView }
  2405. function TVersionListView.GetVersion: String;
  2406. begin
  2407. Result := FileVersion;
  2408. end;
  2409. { TVersionMemo }
  2410. function TVersionMemo.GetVersion: String;
  2411. begin
  2412. Result := FileVersion;
  2413. end;
  2414. { TVersionEdit }
  2415. function TVersionEdit.GetVersion: String;
  2416. begin
  2417. Result := FileVersion;
  2418. end;
  2419. { TVersionListBoxExt }
  2420. function TVersionListBoxExt.GetVersion: String;
  2421. begin
  2422. Result := FileVersion;
  2423. end;
  2424. { TVersionDBGrid }
  2425. function TVersionDBGrid.GetVersion: String;
  2426. begin
  2427. Result := FileVersion;
  2428. end;
  2429. { TVersionDrawGrid }
  2430. function TVersionDrawGrid.GetVersion: String;
  2431. begin
  2432. Result := FileVersion;
  2433. end;
  2434. { TVersionPages }
  2435. function TVersionPages.GetVersion: String;
  2436. begin
  2437. Result := FileVersion;
  2438. end;
  2439. { TVersionSheet }
  2440. function TVersionSheet.GetVersion: String;
  2441. begin
  2442. Result := FileVersion;
  2443. end;
  2444. { TVersionCtrlExt }
  2445. function TVersionCtrlExt.GetVersion: String;
  2446. begin
  2447. Result := FileVersion;
  2448. end;
  2449. { TVersionObject }
  2450. function TVersionObject.GetVersion: String;
  2451. begin
  2452. Result := FileVersion;
  2453. end;
  2454. { TDefineRLE }
  2455. constructor TDefineRLE.Create;
  2456. begin
  2457. inherited Create;
  2458. GetMem(s, $FFFF);
  2459. GetMem(t, $FFFF);
  2460. end;
  2461. destructor TDefineRLE.Destroy;
  2462. begin
  2463. FreeMem(t);
  2464. FreeMem(s);
  2465. inherited Destroy;
  2466. end;
  2467. function TDefineRLE.Pack(Source, Target: Pointer; SourceSize: Integer): LongInt;
  2468. var
  2469. w, tmp: Word;
  2470. Sourc, Targ: LongType;
  2471. begin
  2472. { // Move
  2473. Move(Source^, Target^, SourceSize);
  2474. Result:= SourceSize;
  2475. Exit;{}
  2476. // RLE Compress
  2477. Sourc.Ptr := Source;
  2478. Targ.Ptr := Target;
  2479. Result := 0;
  2480. while SourceSize <> 0 do
  2481. begin
  2482. if SourceSize > $FFFA then tmp := $FFFA
  2483. else tmp := SourceSize;
  2484. dec(SourceSize, tmp);
  2485. move(Sourc.Ptr^, s^, tmp);
  2486. w := PackSeg(s, t, tmp);
  2487. inc(Sourc.Long, tmp);
  2488. Move(w, Targ.Ptr^, 2);
  2489. inc(Targ.Long, 2);
  2490. Move(t^, Targ.Ptr^, w);
  2491. inc(Targ.Long, w);
  2492. Result := Result + w + 2;
  2493. end;
  2494. end;
  2495. function TDefineRLE.PackFile(SourceFileName, TargetFileName: String): Boolean;
  2496. var
  2497. Source, Target: Pointer;
  2498. SourceFile, TargetFile: File;
  2499. RequiredMaxSize, TargetFSize, FSize: LongInt;
  2500. begin
  2501. AssignFile(SourceFile, SourceFileName);
  2502. Reset(SourceFile, 1);
  2503. FSize := FileSize(SourceFile);
  2504. RequiredMaxSize := FSize + (FSize div $FFFF + 1) * 2;
  2505. GetMem(Source, RequiredMaxSize);
  2506. GetMem(Target, RequiredMaxSize);
  2507. BlockRead(SourceFile, Source^, FSize);
  2508. CloseFile(SourceFile);
  2509. TargetFSize := Pack(Source, Target, FSize);
  2510. AssignFile(TargetFile, TargetFileName);
  2511. Rewrite(TargetFile, 1);
  2512. { Also, you may put header }
  2513. BlockWrite(TargetFile, FSize, SizeOf(FSize)); { Original file size (Only from 3.0) }
  2514. BlockWrite(TargetFile, Target^, TargetFSize);
  2515. CloseFile(TargetFile);
  2516. FreeMem(Target, RequiredMaxSize);
  2517. FreeMem(Source, RequiredMaxSize);
  2518. Result := IOResult = 0;
  2519. end;
  2520. function TDefineRLE.PackSeg(Source, Target: Pointer; SourceSize: Word): Word;
  2521. begin
  2522. asm
  2523. push esi
  2524. push edi
  2525. push eax
  2526. push ebx
  2527. push ecx
  2528. push edx
  2529. cld
  2530. xor ecx, ecx
  2531. mov cx, SourceSize
  2532. mov edi, Target
  2533. mov esi, Source
  2534. add esi, ecx
  2535. dec esi
  2536. lodsb
  2537. inc eax
  2538. mov [esi], al
  2539. mov ebx, edi
  2540. add ebx, ecx
  2541. inc ebx
  2542. mov esi, Source
  2543. add ecx, esi
  2544. add edi, 2
  2545. @CyclePack:
  2546. cmp ecx, esi
  2547. je @Konec
  2548. lodsw
  2549. stosb
  2550. dec esi
  2551. cmp al, ah
  2552. jne @CyclePack
  2553. cmp ax, [esi+1]
  2554. jne @CyclePack
  2555. cmp al, [esi+3]
  2556. jne @CyclePack
  2557. sub ebx, 2
  2558. push edi
  2559. sub edi, Target
  2560. mov [ebx], di
  2561. pop edi
  2562. mov edx, esi
  2563. add esi, 3
  2564. @Nimnul:
  2565. inc esi
  2566. cmp al, [esi]
  2567. je @Nimnul
  2568. mov eax, esi
  2569. sub eax, edx
  2570. or ah, ah
  2571. jz @M256
  2572. mov byte ptr [edi], 0
  2573. inc edi
  2574. stosw
  2575. jmp @CyclePack
  2576. @M256:
  2577. stosb
  2578. jmp @CyclePack
  2579. @Konec:
  2580. push ebx
  2581. mov ebx, Target
  2582. mov eax, edi
  2583. sub eax, ebx
  2584. mov [ebx], ax
  2585. pop ebx
  2586. inc ecx
  2587. cmp ebx, ecx
  2588. je @Lock1
  2589. mov esi, ebx
  2590. sub ebx, Target
  2591. sub ecx, Source
  2592. sub ecx, ebx
  2593. rep movsb
  2594. @Lock1:
  2595. sub edi, Target
  2596. mov Result, di
  2597. pop edx
  2598. pop ecx
  2599. pop ebx
  2600. pop eax
  2601. pop edi
  2602. pop esi
  2603. end;
  2604. end;
  2605. function TDefineRLE.PackString(Source: String): String;
  2606. var
  2607. PC, PC2: PChar;
  2608. SS, TS: Integer;
  2609. begin
  2610. SS := Length(Source);
  2611. GetMem(PC, SS);
  2612. GetMem(PC2, SS + 8); // If line can't be packed its size can be longer
  2613. Move(Source[1], PC^, SS);
  2614. TS := Pack(PC, PC2, SS);
  2615. SetLength(Result, TS + 4);
  2616. Move(SS, Result[1], 4);
  2617. Move(PC2^, Result[5], TS);
  2618. FreeMem(PC2);
  2619. FreeMem(PC);
  2620. end;
  2621. function TDefineRLE.UnPack(Source, Target: Pointer; SourceSize: Integer): LongInt;
  2622. var
  2623. Increment, i: LongInt;
  2624. tmp: Word;
  2625. Swap: LongType;
  2626. begin
  2627. { // Move
  2628. Move(Source^, Target^, SourceSize);
  2629. Result:= SourceSize;
  2630. Exit;{}
  2631. // RLE Decompress
  2632. Increment := 0;
  2633. Result := 0;
  2634. while SourceSize <> 0 do
  2635. begin
  2636. Swap.Ptr := Source;
  2637. inc(Swap.Long, Increment);
  2638. Move(Swap.Ptr^, tmp, 2);
  2639. inc(Swap.Long, 2);
  2640. dec(SourceSize, tmp + 2);
  2641. i := UnPackSeg(Swap.Ptr, t, tmp);
  2642. Swap.Ptr := Target;
  2643. inc(Swap.Long, Result);
  2644. inc(Result, i);
  2645. Move(t^, Swap.Ptr^, i);
  2646. inc(Increment, tmp + 2);
  2647. end;
  2648. end;
  2649. function TDefineRLE.UnPackFile(SourceFileName, TargetFileName: String): Boolean;
  2650. var
  2651. Source, Target: Pointer;
  2652. SourceFile, TargetFile: File;
  2653. OriginalFileSize, FSize: LongInt;
  2654. begin
  2655. AssignFile(SourceFile, SourceFileName);
  2656. Reset(SourceFile, 1);
  2657. FSize := FileSize(SourceFile) - SizeOf(OriginalFileSize);
  2658. { Read header ? }
  2659. BlockRead(SourceFile, OriginalFileSize, SizeOf(OriginalFileSize));
  2660. GetMem(Source, FSize);
  2661. GetMem(Target, OriginalFileSize);
  2662. BlockRead(SourceFile, Source^, FSize);
  2663. CloseFile(SourceFile);
  2664. UnPack(Source, Target, FSize);
  2665. AssignFile(TargetFile, TargetFileName);
  2666. Rewrite(TargetFile, 1);
  2667. BlockWrite(TargetFile, Target^, OriginalFileSize);
  2668. CloseFile(TargetFile);
  2669. FreeMem(Target, OriginalFileSize);
  2670. FreeMem(Source, FSize);
  2671. Result := IOResult = 0;
  2672. end;
  2673. function TDefineRLE.UnPackSeg(Source, Target: Pointer; SourceSize: Word): Word;
  2674. begin
  2675. asm
  2676. push esi
  2677. push edi
  2678. push eax
  2679. push ebx
  2680. push ecx
  2681. push edx
  2682. cld
  2683. mov esi, Source
  2684. mov edi, Target
  2685. mov ebx, esi
  2686. xor edx, edx
  2687. mov dx, SourceSize
  2688. add ebx, edx
  2689. mov dx, word ptr [esi]
  2690. add edx, esi
  2691. add esi, 2
  2692. @UnPackCycle:
  2693. cmp edx, ebx
  2694. je @Konec2
  2695. sub ebx, 2
  2696. xor ecx, ecx
  2697. mov cx, word ptr [ebx]
  2698. add ecx, Source
  2699. sub ecx, esi
  2700. dec ecx
  2701. rep movsb
  2702. lodsb
  2703. mov cl, byte ptr [esi]
  2704. inc esi
  2705. or cl, cl
  2706. jnz @Low1
  2707. xor ecx, ecx
  2708. mov cx, word ptr [esi]
  2709. add esi, 2
  2710. @Low1:
  2711. inc ecx
  2712. rep stosb
  2713. jmp @UnPackCycle
  2714. @Konec2:
  2715. mov ecx, edx
  2716. sub ecx, esi
  2717. rep movsb
  2718. sub edi, Target
  2719. mov Result, di
  2720. pop edx
  2721. pop ecx
  2722. pop ebx
  2723. pop eax
  2724. pop edi
  2725. pop esi
  2726. end;
  2727. end;
  2728. function TDefineRLE.UnPackString(Source: String): String;
  2729. var
  2730. PC, PC2: PChar;
  2731. SS, TS: Integer;
  2732. begin
  2733. SS := Length(Source) - 4;
  2734. GetMem(PC, SS);
  2735. Move(Source[1], TS, 4);
  2736. GetMem(PC2, TS);
  2737. Move(Source[5], PC^, SS);
  2738. TS := UnPack(PC, PC2, SS);
  2739. SetLength(Result, TS);
  2740. Move(PC2^, Result[1], TS);
  2741. FreeMem(PC2);
  2742. FreeMem(PC);
  2743. end;
  2744. end.