ChartWinControl.cs 109 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088
  1. using MuchInfo.Chart.Data.EnumTypes;
  2. namespace IndexFormula.Finance.Win
  3. {
  4. using IndexFormula.Finance;
  5. using IndexFormula.Finance.DataProvider;
  6. using System;
  7. using System.Collections;
  8. using System.ComponentModel;
  9. using System.Diagnostics;
  10. using System.Drawing;
  11. using System.Drawing.Imaging;
  12. using System.Drawing.Printing;
  13. using System.Globalization;
  14. using System.IO;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. public class ChartWinControl : UserControl, IObjectCanvas
  18. {
  19. private bool adjustData = true;
  20. private double afterBars = 0.1;
  21. private string areaPercent = "3;1;1;1;1";
  22. private FormulaChart chart;
  23. private IndexFormula.Finance.ChartDragMode chartDragMode = IndexFormula.Finance.ChartDragMode.Axis;
  24. private ContextMenu cmMain;
  25. public ContextMenu cmRight;
  26. private double columnWidth = 4.0;
  27. private Container components = null;
  28. private Graphics ControlGraphics;
  29. private MouseAction crossCursorMouseMode = MouseAction.MouseMove;
  30. private Bitmap CrossMemBmp;
  31. private Graphics CrossMemBmpG;
  32. private DataCycle currentDataCycle = DataCycle.Day;
  33. private DataManagerBase CurrentDataManager;
  34. private Cursor defaultCursor = null;
  35. private const string defaultFavoriteCycles = "MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1";
  36. private string defaultFormulas;
  37. private static Color defaultZoomBackColor = Color.FromArgb(0x20, Color.Green);
  38. private bool designing;
  39. private ChartDragInfo DragInfo;
  40. private EventHandler ehFavoriteIndicator;
  41. private bool EnableResize;
  42. private bool EnableXScale;
  43. private bool EnableYScale;
  44. private DateTime endTime;
  45. private string favoriteCycles = "MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1";
  46. private ArrayList favoriteFormulas;
  47. private bool fixedTime;
  48. private Rectangle fixedZoomRect = Rectangle.Empty;
  49. private DataManagerBase historyDataManager;
  50. private DataManagerBase intraDataManager;
  51. private ExchangeIntraday intradayInfo = ExchangeIntraday.US;
  52. private int LastCursorPos;
  53. private FormulaHitInfo LastHitInfo;
  54. private IDataProvider LastProvider;
  55. private int LastX;
  56. private int LastY;
  57. private IndexFormula.Finance.LatestValueType latestValueType = IndexFormula.Finance.LatestValueType.All;
  58. private double maxColumnWidth = 500.0;
  59. private double maxPrice;
  60. private Bitmap MemBmp;
  61. private bool memoryCrossCursor;
  62. private MenuItem miAddFormula;
  63. private MenuItem miAdjust;
  64. private MenuItem miAxisType;
  65. private MenuItem miCalculator;
  66. private MenuItem miChart;
  67. private MenuItem miChartCopy;
  68. private MenuItem miChartEdit;
  69. private MenuItem miCloseFormula;
  70. private MenuItem miCopy;
  71. private MenuItem miCrossCursor;
  72. private MenuItem miCycle;
  73. private MenuItem miEdit;
  74. private MenuItem miFavorite;
  75. private MenuItem miFormulaManager;
  76. private MenuItem miIndicator;
  77. private MenuItem miLog;
  78. private double minColumnWidth = 0.01;
  79. private MenuItem miNormal;
  80. private double minPrice;
  81. private MenuItem miSkin;
  82. private MenuItem miSp1;
  83. private MenuItem miSp2;
  84. private MenuItem miSp4;
  85. private MenuItem miStatistic;
  86. private MenuItem miStatisticWindow;
  87. private MenuItem miView;
  88. private FormulaHitInfo MouseDownInfo;
  89. private IndexFormula.Finance.Win.MouseWheelMode mouseWheelMode = IndexFormula.Finance.Win.MouseWheelMode.Scroll;
  90. private Color mouseZoomBackColor = defaultZoomBackColor;
  91. private Bitmap MouseZoomBmp;
  92. private Graphics MouseZoomBmpG;
  93. private IndexFormula.Finance.Win.MouseZoomMode mouseZoomMode = IndexFormula.Finance.Win.MouseZoomMode.Rect;
  94. private RectangleF MouseZoomRect;
  95. private bool nativeContextMenu = true;
  96. private bool needAutoScaleY = true;
  97. private bool needDrawCursor;
  98. private bool needDrawLastBarOnly = false;
  99. private bool needRebind;
  100. private bool needRedraw;
  101. private bool needRefresh;
  102. private bool needResetCursorPos;
  103. private bool needSetDefaultFormulas;
  104. public static IndexFormula.Finance.Win.OnSelectFormula OnSelectFormula = new IndexFormula.Finance.Win.OnSelectFormula(ChartWinControl.DefaultSelectFormula);
  105. public static OnSelectString OnSelectMethod = new OnSelectString(ChartWinControl.DefaultSelectMethod);
  106. public static OnSelectString OnSelectSymbol = null;
  107. private int Page;
  108. private PrintPreviewDialog previewDialog;
  109. private PrintDialog printDialog;
  110. private PrintDocument printDocument;
  111. private bool resetYAfterXChanged = true;
  112. private IndexFormula.Finance.ScaleType scaleType = IndexFormula.Finance.ScaleType.Default;
  113. private MouseAction selectFormulaMouseMode = MouseAction.MouseDown;
  114. private PageSetupDialog setupDialog;
  115. private bool showCrossCursor = true;
  116. private bool showCursorLabel = true;
  117. private ShowLineMode showHorizontalGrid;
  118. private bool showIndicatorValues = true;
  119. private bool showOverlayValues = true;
  120. private bool showStatistic = true;
  121. private bool showTopLine = true;
  122. private ShowLineMode showVerticalGrid;
  123. private string skin = "RedWhite";
  124. private DateTime startTime;
  125. public StatisticControl StatisticWindow = null;
  126. private IndexFormula.Finance.StickRenderType stickRenderType = IndexFormula.Finance.StickRenderType.Default;
  127. private int stockBars = 150;
  128. private IndexFormula.Finance.StockRenderType stockRenderType = IndexFormula.Finance.StockRenderType.Default;
  129. private string symbol = "MSFT";
  130. public FormulaUserSkin UserSkin = new FormulaUserSkin();
  131. private IndexFormula.Finance.ValueTextMode valueTextMode = IndexFormula.Finance.ValueTextMode.Default;
  132. private ZoomCenterPosition zoomPosition = ZoomCenterPosition.Center;
  133. [Description("Occurs after apply skin"), Category("Stock Chart")]
  134. public event EventHandler AfterApplySkin;
  135. [Description("Occurs after data bind"), Category("Stock Chart")]
  136. public event IndexFormula.Finance.Win.AfterBindData AfterBindData;
  137. [Category("Stock Chart"), Description("Occurs after data cycle changed")]
  138. public event EventHandler AfterCycleChange;
  139. [Description("Occurs after mouse move"), Category("Stock Chart")]
  140. public event IndexFormula.Finance.Win.AfterMouseMove AfterMouseMove;
  141. [Description("Occurs before apply skin"), Category("Stock Chart")]
  142. public event ApplySkinHandler BeforeApplySkin;
  143. [Description("Occurs before data cycle changed"), Category("Stock Chart")]
  144. public event EventHandler BeforeCycleChange;
  145. [Description("Occurs when cursor pos changed"), Category("Stock Chart")]
  146. public event IndexFormula.Finance.Win.CursorPosChanged CursorPosChanged;
  147. [Category("Stock Chart"), Description("Occurs when stock data or data cycle changed")]
  148. public event EventHandler DataChanged;
  149. [Category("Stock Chart"), Description("Occurs when paint extra informations on the chart, it was used by Easy Stock Object")]
  150. public event NativePaintHandler ExtraPaint;
  151. [Category("Stock Chart"), Description("Occurs when paint the chart on native canvas")]
  152. public event NativePaintHandler NativePaint;
  153. [Description("Occurs when the value of ShowStatistic Changed"), Category("Stock Chart")]
  154. public event EventHandler ShowStatisticChanged;
  155. [Category("Stock Chart"), Description("Occurs when stock view changed")]
  156. public event ViewChangedHandler ViewChanged;
  157. public ChartWinControl()
  158. {
  159. this.InitializeComponent();
  160. SetLanguage.SetcurrentLanguage(ChartLanguageType.SimplifiedChinese);
  161. this.Page = 10;
  162. this.LastCursorPos = -1;
  163. this.favoriteFormulas = new ArrayList();
  164. this.EnableYScale = true;
  165. this.EnableXScale = true;
  166. this.EnableResize = true;
  167. this.chart = new FormulaChart();
  168. this.chart.BitmapCache = true;
  169. this.chart.LatestValueType = this.LatestValueType;
  170. base.MouseWheel += new MouseEventHandler(this.ChartWinControl_MouseWheel);
  171. this.AfterApplySkin = (EventHandler)Delegate.Combine(this.AfterApplySkin, new EventHandler(this.ChartWinControl_AfterApplySkin));
  172. this.chart.NativePaint += new NativePaintHandler(this.Chart_NativePaint);
  173. this.chart.ExtraPaint += new NativePaintHandler(this.Chart_ExtraPaint);
  174. this.chart.ViewChanged += new ViewChangedHandler(this.Chart_ViewChanged);
  175. this.chart.AddArea("MAIN", 3.0);
  176. this.FavoriteFormulas = "VOLMA;RSI;CCI;OBV;ATR;FastSTO;SlowSTO;ROC;TRIX;WR;AD;CMF;PPO;StochRSI;ULT;BBWidth;PVO";
  177. this.CursorPosChanged = (IndexFormula.Finance.Win.CursorPosChanged)Delegate.Combine(this.CursorPosChanged, new IndexFormula.Finance.Win.CursorPosChanged(this.ShowStatisticWindow));
  178. this.ehFavoriteIndicator = new EventHandler(this.mmFavorite_SelectedIndexChanged);
  179. this.CreateCycleMenu();
  180. this.StatisticWindow.OnHide += new EventHandler(this.StatisticWindow_OnHide);
  181. }
  182. private void ApplySkin()
  183. {
  184. FormulaSkin skinByName = FormulaSkin.GetSkinByName(this.skin);
  185. this.ApplySkin(skinByName);
  186. }
  187. public void ApplySkin(FormulaSkin fs)
  188. {
  189. if (fs != null)
  190. {
  191. if (this.BeforeApplySkin != null)
  192. {
  193. this.BeforeApplySkin(this, fs);
  194. }
  195. this.chart.SetSkin(fs);
  196. this.chart[0].Back.TopPen.Width = this.ShowTopLine ? 2 : 0;
  197. this.chart[0].AxisY.Back.TopPen.Width = this.ShowTopLine ? 2 : 0;
  198. if (this.AfterApplySkin != null)
  199. {
  200. this.AfterApplySkin(this, new EventArgs());
  201. }
  202. foreach (FormulaArea area in this.chart.Areas)
  203. {
  204. area.RemoveAutoMultiplyForStockYAxis();
  205. }
  206. }
  207. }
  208. private void AreasToDefaultFormulas()
  209. {
  210. this.defaultFormulas = string.Join(";", this.chart.AreaToStrings());
  211. }
  212. public void AutoAdjustYAxis()
  213. {
  214. foreach (FormulaArea area in this.chart.Areas)
  215. {
  216. foreach (FormulaAxisY sy in area.AxisYs)
  217. {
  218. this.AutoAdjustYAxis(sy);
  219. }
  220. }
  221. }
  222. public void AutoAdjustYAxis(FormulaAxisY fay)
  223. {
  224. this.MinPrice = 0.0;
  225. fay.AutoScale = true;
  226. this.NeedRedraw();
  227. }
  228. public void AutoScaleAxisY()
  229. {
  230. foreach (FormulaArea area in this.chart.Areas)
  231. {
  232. foreach (FormulaAxisY sy in area.AxisYs)
  233. {
  234. sy.AutoScale = true;
  235. }
  236. }
  237. this.NeedRebind();
  238. }
  239. public bool BindData()
  240. {
  241. bool flag = true;
  242. if ((this.HistoryDataManager != null) && (this.IntraDataManager != null))
  243. {
  244. CommonDataProvider cdp = null;
  245. if (this.currentDataCycle.CycleBase >= DataCycleBase.DAY)
  246. {
  247. this.CurrentDataManager = this.HistoryDataManager;
  248. }
  249. else
  250. {
  251. this.CurrentDataManager = this.IntraDataManager;
  252. this.CurrentDataManager.IsFix = this.fixedTime;
  253. this.chart.FixedTime = this.fixedTime;
  254. }
  255. if (this.CurrentDataManager.VirtualFetch)
  256. {
  257. this.CurrentDataManager.StartTime = this.startTime;
  258. this.CurrentDataManager.EndTime = this.endTime;
  259. }
  260. flag = false;
  261. try
  262. {
  263. cdp = (CommonDataProvider)this.CurrentDataManager[this.symbol];
  264. if (this.AfterBindData != null)
  265. {
  266. this.AfterBindData(this, new BindDataEventArgs(cdp, this.CurrentDataManager));
  267. }
  268. flag = cdp != null;
  269. }
  270. catch
  271. {
  272. }
  273. if (cdp != null)
  274. {
  275. this.chart.SetDataProviderNoBind(cdp);
  276. }
  277. else
  278. {
  279. this.endTime = DateTime.MinValue;
  280. }
  281. if (this.fixedTime && (cdp != null))
  282. {
  283. cdp.IntradayInfo = this.IntradayInfo;
  284. }
  285. if ((this.chart.DataProvider != null) && (this.chart.DataProvider is CommonDataProvider))
  286. {
  287. if (this.HasData())
  288. {
  289. if (this.chart.DataProvider.DataCycle.ToString() != this.currentDataCycle.ToString())
  290. {
  291. this.ColumnWidth = 5.0;
  292. this.StartBar = 0;
  293. this.chart.DataProvider.DataCycle = this.currentDataCycle;
  294. }
  295. if (this.DataChanged != null)
  296. {
  297. this.DataChanged(this, new EventArgs());
  298. }
  299. }
  300. (this.chart.DataProvider as CommonDataProvider).Adjusted = this.adjustData;
  301. }
  302. this.chart.SetAreaPercent(this.areaPercent);
  303. this.chart.Bind();
  304. this.ApplySkin();
  305. }
  306. return flag;
  307. }
  308. private void BuildFavoriteMenu()
  309. {
  310. this.cmRight.MenuItems.Remove(this.miFavorite);
  311. this.miFavorite = new MenuItem("&Favorite Indicators");
  312. this.cmRight.MenuItems.Add(0, this.miFavorite);
  313. foreach (string str in this.favoriteFormulas)
  314. {
  315. this.miFavorite.MenuItems.Add(str, this.ehFavoriteIndicator);
  316. }
  317. }
  318. private void CancelMouseZoom()
  319. {
  320. if (this.MouseZoomBmp != null)
  321. {
  322. this.DragInfo = null;
  323. this.MouseZoomBmp = null;
  324. this.MouseZoomRect = Rectangle.Empty;
  325. }
  326. }
  327. private void ChangeCursorPos()
  328. {
  329. if (((this.chart != null) && (this.chart.DataProvider != null)) && ((this.LastCursorPos != this.chart.CursorPos) || (this.LastProvider != this.chart.DataProvider)))
  330. {
  331. IDataProvider dataProvider = this.chart.DataProvider;
  332. if ((this.chart.CursorPos >= 0) && (this.chart.CursorPos < dataProvider.Count))
  333. {
  334. this.LastProvider = this.chart.DataProvider;
  335. this.LastCursorPos = this.chart.CursorPos;
  336. if (this.CursorPosChanged != null)
  337. {
  338. this.CursorPosChanged(this, this.chart, this.LastCursorPos, dataProvider);
  339. }
  340. }
  341. }
  342. }
  343. private void Chart_ExtraPaint(object sender, NativePaintArgs e)
  344. {
  345. if (this.ExtraPaint != null)
  346. {
  347. this.ExtraPaint(this, e);
  348. }
  349. }
  350. private void Chart_NativePaint(object sender, NativePaintArgs e)
  351. {
  352. if (this.NativePaint != null)
  353. {
  354. this.NativePaint(this, e);
  355. }
  356. }
  357. private void Chart_ViewChanged(object sender, ViewChangedArgs e)
  358. {
  359. if (this.ViewChanged != null)
  360. {
  361. this.ViewChanged(this, e);
  362. }
  363. }
  364. private void ChartWinControl_AfterApplySkin(object sender, EventArgs e)
  365. {
  366. this.chart.ExtendYAxis(TwoYAxisType.AreaSame);
  367. }
  368. private void ChartWinControl_DoubleClick(object sender, EventArgs e)
  369. {
  370. if (this.MouseDownInfo.HitType == FormulaHitType.htAxisY)
  371. {
  372. this.AutoAdjustYAxis(this.MouseDownInfo.AxisY);
  373. }
  374. }
  375. private void ChartWinControl_Enter(object sender, EventArgs e)
  376. {
  377. base.Invalidate();
  378. }
  379. private void ChartWinControl_KeyDown(object sender, KeyEventArgs e)
  380. {
  381. int start;
  382. int cursorPos;
  383. if (this.chart != null)
  384. {
  385. start = this.chart.Start;
  386. cursorPos = this.chart.CursorPos;
  387. int num3 = e.Control ? this.Page : 1;
  388. switch (e.KeyCode)
  389. {
  390. case Keys.End:
  391. this.chart.AdjustCursorByPos(this.ControlGraphics, 0x7fffffff, this.chart.Start);
  392. e.Handled = true;
  393. goto Label_0221;
  394. case Keys.Home:
  395. this.chart.AdjustCursorByPos(this.ControlGraphics, 0, this.chart.Start);
  396. e.Handled = true;
  397. goto Label_0221;
  398. case Keys.Left:
  399. this.chart.AdjustCursorByPos(this.ControlGraphics, this.chart.CursorPos - num3, this.chart.Start + (e.Shift ? num3 : 0));
  400. e.Handled = true;
  401. goto Label_0221;
  402. case Keys.Up:
  403. case Keys.Add:
  404. if (e.Control)
  405. {
  406. this.NextArea(-1);
  407. e.Handled = true;
  408. }
  409. else
  410. {
  411. this.ScaleChart(0.05);
  412. }
  413. goto Label_0221;
  414. case Keys.Right:
  415. this.chart.AdjustCursorByPos(this.ControlGraphics, this.chart.CursorPos + num3, this.chart.Start - (e.Shift ? num3 : 0));
  416. e.Handled = true;
  417. goto Label_0221;
  418. case Keys.Down:
  419. case Keys.Subtract:
  420. if (e.Control)
  421. {
  422. this.NextArea(1);
  423. e.Handled = true;
  424. }
  425. else
  426. {
  427. this.ScaleChart(-0.05);
  428. }
  429. goto Label_0221;
  430. case Keys.Escape:
  431. this.CancelMouseZoom();
  432. base.Invalidate();
  433. break;
  434. case Keys.Multiply:
  435. this.NextFormula(1);
  436. e.Handled = true;
  437. goto Label_0221;
  438. case Keys.Divide:
  439. this.NextFormula(-1);
  440. e.Handled = true;
  441. goto Label_0221;
  442. case Keys.F7:
  443. case Keys.F8:
  444. this.NextCycle(1 - ((e.KeyCode == Keys.F8) ? 0 : 2));
  445. e.Handled = true;
  446. goto Label_0221;
  447. }
  448. }
  449. return;
  450. Label_0221:
  451. if (e.Handled)
  452. {
  453. this.ChangeCursorPos();
  454. }
  455. if ((cursorPos != this.chart.CursorPos) && (start != this.chart.Start))
  456. {
  457. this.NeedRedraw();
  458. }
  459. if (this.needRedraw)
  460. {
  461. if (start != this.chart.Start)
  462. {
  463. this.MoveChartXBars(3, 1, start - this.chart.Start);
  464. }
  465. this.needDrawCursor = true;
  466. }
  467. else
  468. {
  469. this.DrawCursorByPos(this.ControlGraphics);
  470. }
  471. }
  472. private void ChartWinControl_MouseDown(object sender, MouseEventArgs e)
  473. {
  474. this.MouseDownInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  475. if (this.MouseDownInfo.Area != null)
  476. {
  477. this.chart.SelectedArea = this.MouseDownInfo.Area;
  478. if ((this.selectFormulaMouseMode == MouseAction.MouseDown) && !this.Designing)
  479. {
  480. this.chart.SetSelectedData(this.MouseDownInfo);
  481. }
  482. if (((e.Button != MouseButtons.Right) && (this.CrossCursorMouseMode == MouseAction.MouseDown)) && !this.Designing)
  483. {
  484. this.MouseCrossCursor(this.ControlGraphics, this.MouseDownInfo);
  485. }
  486. this.NeedRedraw();
  487. }
  488. if ((e.Button == MouseButtons.Right) && !this.Designing)
  489. {
  490. if (this.MouseZoomBmp != null)
  491. {
  492. this.CancelMouseZoom();
  493. }
  494. else if (base.Visible)
  495. {
  496. ContextMenu cmRight = this.cmRight;
  497. if (!this.nativeContextMenu)
  498. {
  499. cmRight = this.ContextMenu;
  500. }
  501. if (cmRight != null)
  502. {
  503. cmRight.Show(this, new Point(e.X, e.Y));
  504. }
  505. }
  506. }
  507. else if (!this.Designing)
  508. {
  509. this.DragInfo = new ChartDragInfo(this.chart, this.MouseDownInfo);
  510. if (((this.MouseDownInfo.HitType == FormulaHitType.htArea) && (this.mouseZoomMode != IndexFormula.Finance.Win.MouseZoomMode.None)) && !this.FixedTime)
  511. {
  512. this.LastX = e.X;
  513. this.LastY = e.Y;
  514. this.MemBmp = this.GetBitmap(false, true);
  515. this.MouseZoomBmp = new Bitmap(this.MemBmp.Width, this.MemBmp.Height, PixelFormat.Format32bppPArgb);
  516. this.MouseZoomBmpG = Graphics.FromImage(this.MouseZoomBmp);
  517. this.HideCursor();
  518. }
  519. }
  520. }
  521. private void ChartWinControl_MouseLeave(object sender, EventArgs e)
  522. {
  523. if ((this.chart != null) && (this.CrossCursorMouseMode == MouseAction.MouseMove))
  524. {
  525. this.HideCursor();
  526. }
  527. }
  528. private void ChartWinControl_MouseMove(object sender, MouseEventArgs e)
  529. {
  530. try
  531. {
  532. if (this.Designing)
  533. {
  534. return;
  535. }
  536. int totalPart = 3 - ((this.ChartDragMode == IndexFormula.Finance.ChartDragMode.Chart) ? 1 : 0);
  537. if ((this.LastX == e.X) && (this.LastY == e.Y))
  538. {
  539. return;
  540. }
  541. FormulaHitInfo hitInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  542. if (this.DragInfo != null)
  543. {
  544. float deltaY = this.DragInfo.HitInfo.Y - hitInfo.Y;
  545. float deltaX = this.DragInfo.HitInfo.X - hitInfo.X;
  546. FormulaArea fa = this.DragInfo.HitInfo.Area;
  547. if (this.MouseZoomBmp != null)
  548. {
  549. RectangleF fixedZoomRect;
  550. RectangleF ef2;
  551. if (this.FixedZoomRect != Rectangle.Empty)
  552. {
  553. fixedZoomRect = this.FixedZoomRect;
  554. fixedZoomRect.Offset((float)e.X, (float)e.Y);
  555. ef2 = this.FixedZoomRect;
  556. ef2.Offset((float)this.LastX, (float)this.LastY);
  557. }
  558. else
  559. {
  560. fixedZoomRect = this.GetRect(this.DragInfo.HitInfo.X, this.DragInfo.HitInfo.Y, (float)e.X, (float)e.Y);
  561. ef2 = this.GetRect(this.DragInfo.HitInfo.X, this.DragInfo.HitInfo.Y, (float)this.LastX, (float)this.LastY);
  562. }
  563. this.MouseZoomRect = RectangleF.Union(fixedZoomRect, ef2);
  564. this.MouseZoomBmpG.DrawImage(this.MemBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  565. Rectangle rect = Rectangle.Truncate(fixedZoomRect);
  566. rect.Width--;
  567. rect.Height--;
  568. this.MouseZoomBmpG.DrawRectangle(Pens.Black, rect);
  569. if (this.mouseZoomBackColor.A != 0)
  570. {
  571. this.MouseZoomBmpG.FillRectangle(new SolidBrush(this.mouseZoomBackColor), rect);
  572. }
  573. this.ControlGraphics.DrawImage(this.MouseZoomBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  574. }
  575. else if (this.EnableResize && (this.DragInfo.HitInfo.HitType == FormulaHitType.htSize))
  576. {
  577. for (int i = 0; i < this.chart.Areas.Count; i++)
  578. {
  579. this.chart.Areas[i].HeightPercent = this.DragInfo.AreaHeight[i];
  580. }
  581. int index = this.chart.Areas.IndexOf(fa);
  582. if (index < (this.chart.Areas.Count - 1))
  583. {
  584. FormulaArea area2 = this.chart.Areas[index + 1];
  585. double num6 = this.DragInfo.AreaHeight[index] - deltaY;
  586. double num7 = this.DragInfo.AreaHeight[index + 1] + deltaY;
  587. if (num6 < 40.0)
  588. {
  589. num7 -= 40.0 - num6;
  590. num6 = 40.0;
  591. }
  592. if (num7 < 40.0)
  593. {
  594. num6 -= 40.0 - num7;
  595. num7 = 40.0;
  596. }
  597. fa.HeightPercent = num6;
  598. area2.HeightPercent = num7;
  599. this.NeedRedraw(fa);
  600. this.NeedRedraw(area2);
  601. }
  602. this.areaPercent = this.chart.GetAreaPercent();
  603. }
  604. else if (this.ChartDragMode != IndexFormula.Finance.ChartDragMode.None)
  605. {
  606. if ((this.EnableXScale && !this.chart.FixedTime) && (this.DragInfo.HitInfo.HitType == FormulaHitType.htAxisX))
  607. {
  608. this.MoveChartX(fa, totalPart, this.DragInfo.HitInfo.XPart(totalPart), deltaX);
  609. }
  610. else if (this.EnableYScale && (this.DragInfo.HitInfo.HitType == FormulaHitType.htAxisY))
  611. {
  612. this.MoveChartY(fa, totalPart, this.DragInfo.HitInfo.YPart(totalPart), deltaY);
  613. }
  614. else if ((this.ChartDragMode == IndexFormula.Finance.ChartDragMode.Chart) && (this.DragInfo.HitInfo.HitType == FormulaHitType.htArea))
  615. {
  616. if (!this.chart.FixedTime)
  617. {
  618. this.MoveChartX(fa, 3, 1, deltaX);
  619. }
  620. this.MoveChartY(fa, 3, 1, deltaY);
  621. }
  622. }
  623. }
  624. else
  625. {
  626. if (this.CrossCursorMouseMode == MouseAction.MouseMove)
  627. {
  628. this.MouseCrossCursor(this.ControlGraphics, hitInfo);
  629. }
  630. if ((this.selectFormulaMouseMode == MouseAction.MouseMove) && !object.Equals(this.chart.GetSelectedData(), hitInfo.Data))
  631. {
  632. this.chart.SetSelectedData(hitInfo);
  633. this.NeedRedraw();
  634. }
  635. if (hitInfo.Area != null)
  636. {
  637. switch (hitInfo.HitType)
  638. {
  639. case FormulaHitType.htSize:
  640. if (this.EnableResize)
  641. {
  642. this.Cursor = Cursors.HSplit;
  643. }
  644. goto Label_05D3;
  645. case FormulaHitType.htAxisX:
  646. {
  647. if ((!this.EnableXScale || this.chart.FixedTime) || (this.ChartDragMode == IndexFormula.Finance.ChartDragMode.None))
  648. {
  649. goto Label_0518;
  650. }
  651. int num8 = hitInfo.XPart(totalPart);
  652. if ((num8 != 0) && (num8 != (totalPart - 1)))
  653. {
  654. break;
  655. }
  656. this.Cursor = Cursors.SizeWE;
  657. goto Label_05D3;
  658. }
  659. case FormulaHitType.htAxisY:
  660. {
  661. if (!this.EnableYScale || (this.ChartDragMode == IndexFormula.Finance.ChartDragMode.None))
  662. {
  663. goto Label_0568;
  664. }
  665. int num9 = hitInfo.YPart(totalPart);
  666. if ((num9 != 0) && (num9 != (totalPart - 1)))
  667. {
  668. goto Label_055B;
  669. }
  670. this.Cursor = Cursors.SizeNS;
  671. goto Label_05D3;
  672. }
  673. case FormulaHitType.htArea:
  674. if (this.selectFormulaMouseMode == MouseAction.None)
  675. {
  676. goto Label_05B7;
  677. }
  678. if (hitInfo.Formula == null)
  679. {
  680. goto Label_05A9;
  681. }
  682. this.Cursor = Cursors.Hand;
  683. goto Label_05D3;
  684. default:
  685. this.Cursor = this.DefaultCursor;
  686. goto Label_05D3;
  687. }
  688. this.Cursor = Cursors.Hand;
  689. }
  690. }
  691. goto Label_05D3;
  692. Label_0518:
  693. this.Cursor = this.DefaultCursor;
  694. goto Label_05D3;
  695. Label_055B:
  696. this.Cursor = Cursors.Hand;
  697. goto Label_05D3;
  698. Label_0568:
  699. this.Cursor = this.DefaultCursor;
  700. goto Label_05D3;
  701. Label_05A9:
  702. this.Cursor = this.DefaultCursor;
  703. goto Label_05D3;
  704. Label_05B7:
  705. this.Cursor = this.DefaultCursor;
  706. Label_05D3:
  707. this.LastX = e.X;
  708. this.LastY = e.Y;
  709. if (this.AfterMouseMove != null)
  710. {
  711. this.AfterMouseMove(this, e, hitInfo);
  712. }
  713. }
  714. catch
  715. {
  716. }
  717. }
  718. private void ChartWinControl_MouseUp(object sender, MouseEventArgs e)
  719. {
  720. if (this.DragInfo != null)
  721. {
  722. this.DragInfo = null;
  723. base.Invalidate();
  724. }
  725. if (this.MouseZoomBmp != null)
  726. {
  727. if (((e.Button == MouseButtons.Left) && !this.MouseZoomRect.IsEmpty) && (this.MouseZoomRect.Width > 100f))
  728. {
  729. FormulaHitInfo hitInfo = this.chart.GetHitInfo(this.MouseZoomRect.X, this.MouseZoomRect.Y);
  730. FormulaHitInfo info2 = this.chart.GetHitInfo(this.MouseZoomRect.Right, this.MouseZoomRect.Bottom);
  731. int cursorPos = hitInfo.CursorPos;
  732. int num2 = info2.CursorPos;
  733. if (this.chart.DataProvider != null)
  734. {
  735. double[] numArray = this.chart.DataProvider["DATE"];
  736. if (cursorPos < numArray.Length)
  737. {
  738. this.StartTime = this.chart.IndexToDate(hitInfo.CursorPos);
  739. this.EndTime = this.chart.IndexToDate(info2.CursorPos);
  740. }
  741. }
  742. }
  743. this.MouseZoomBmp = null;
  744. this.MouseZoomRect = Rectangle.Empty;
  745. }
  746. }
  747. private void ChartWinControl_MouseWheel(object sender, MouseEventArgs e)
  748. {
  749. if (((this.mouseWheelMode != IndexFormula.Finance.Win.MouseWheelMode.None) && (this.chart != null)) && !this.FixedTime)
  750. {
  751. int moveBars = Math.Sign(e.Delta) * (((Control.ModifierKeys & Keys.Alt) != Keys.None) ? 1 : 12);
  752. if (this.mouseWheelMode == IndexFormula.Finance.Win.MouseWheelMode.Scroll)
  753. {
  754. this.MoveChartXBars(3, 1, moveBars);
  755. }
  756. else
  757. {
  758. this.ScaleChart(((double)moveBars) / 100.0);
  759. }
  760. this.needResetCursorPos = true;
  761. this.needDrawCursor = false;
  762. this.LastHitInfo = this.chart.GetHitInfo((float)e.X, (float)e.Y);
  763. }
  764. }
  765. private void ChartWinControl_Paint(object sender, PaintEventArgs e)
  766. {
  767. if (this.chart != null)
  768. {
  769. this.StatisticWindow.Visible = this.showStatistic && this.StatisticWindow.HasData();
  770. if (this.needSetDefaultFormulas)
  771. {
  772. this.DefaultFormulasToAreas();
  773. this.needSetDefaultFormulas = false;
  774. }
  775. if (this.needRefresh)
  776. {
  777. this.RecreateFormula();
  778. }
  779. bool flag = true;
  780. if (this.needRebind)
  781. {
  782. flag = this.BindData();
  783. }
  784. if (this.needRedraw && flag)
  785. {
  786. if (this.chart.FixedTime && (this.CurrentDataManager != null))
  787. {
  788. this.chart.StartTime = this.startTime;
  789. this.chart.EndTime = this.endTime;
  790. }
  791. else if (this.chart.DataProvider != null)
  792. {
  793. double[] numArray = this.chart.DataProvider["DATE"];
  794. if (this.endTime == DateTime.MinValue)
  795. {
  796. if (numArray.Length > 0)
  797. {
  798. this.chart.EndTime = DateTime.FromOADate(numArray[numArray.Length - 1]);
  799. this.chart.StartTime = DateTime.FromOADate(numArray[Math.Max(0, numArray.Length - this.stockBars)]);
  800. this.EndTime = this.chart.EndTime;
  801. this.StartTime = this.chart.StartTime;
  802. }
  803. }
  804. else
  805. {
  806. int num2;
  807. int num = this.chart.DateToIndex(this.endTime);
  808. if (this.afterBars < 1.0)
  809. {
  810. num2 = (int)((numArray.Length - 1) * (1.0 + this.afterBars));
  811. }
  812. else
  813. {
  814. num2 = (numArray.Length - 1) + ((int)this.afterBars);
  815. }
  816. if (num > num2)
  817. {
  818. this.endTime = this.chart.IndexToDate(num2);
  819. }
  820. this.chart.StartTime = this.startTime;
  821. this.chart.EndTime = this.endTime;
  822. }
  823. }
  824. FormulaArea mainArea = this.chart.MainArea;
  825. if (mainArea != null)
  826. {
  827. if (this.minPrice > 0.0)
  828. {
  829. mainArea.AxisY.MinY = this.minPrice;
  830. mainArea.AxisY.MaxY = this.maxPrice;
  831. mainArea.AxisY.AutoScale = false;
  832. }
  833. if (this.stockRenderType != IndexFormula.Finance.StockRenderType.Default)
  834. {
  835. mainArea.StockRenderType = this.stockRenderType;
  836. }
  837. if (this.HasData() && (this.scaleType != IndexFormula.Finance.ScaleType.Default))
  838. {
  839. mainArea.AxisY.Scale = this.scaleType;
  840. }
  841. }
  842. this.chart.ValueTextMode = this.valueTextMode;
  843. if (this.stickRenderType != IndexFormula.Finance.StickRenderType.Default)
  844. {
  845. this.chart.StickRenderType = this.stickRenderType;
  846. }
  847. this.chart.LatestValueType = this.latestValueType;
  848. this.chart.ShowCursorLabel = this.showCursorLabel;
  849. if (this.showVerticalGrid != ShowLineMode.Default)
  850. {
  851. if (this.showVerticalGrid == ShowLineMode.HidePrice)
  852. {
  853. mainArea.AxisY.MajorTick.ShowLine = false;
  854. }
  855. else
  856. {
  857. foreach (FormulaArea area2 in this.chart.Areas)
  858. {
  859. area2.AxisY.MajorTick.ShowLine = this.showVerticalGrid == ShowLineMode.Show;
  860. }
  861. }
  862. }
  863. if (this.showHorizontalGrid != ShowLineMode.Default)
  864. {
  865. if (this.showHorizontalGrid == ShowLineMode.HidePrice)
  866. {
  867. mainArea.AxisX.MajorTick.ShowLine = false;
  868. }
  869. else
  870. {
  871. foreach (FormulaArea area3 in this.chart.Areas)
  872. {
  873. area3.AxisX.MajorTick.ShowLine = this.showHorizontalGrid == ShowLineMode.Show;
  874. }
  875. }
  876. }
  877. this.chart.NeedRedraw = true;
  878. this.chart.ExtraNeedRedraw = true;
  879. }
  880. if (this.needResetCursorPos)
  881. {
  882. this.SetCursorPos();
  883. this.ChangeCursorPos();
  884. this.needResetCursorPos = false;
  885. }
  886. this.RenderChart(e.Graphics);
  887. this.needRedraw = false;
  888. this.needRebind = false;
  889. this.needRefresh = false;
  890. }
  891. }
  892. private void ChartWinControl_SizeChanged(object sender, EventArgs e)
  893. {
  894. this.ControlGraphics = base.CreateGraphics();
  895. if (this.chart != null)
  896. {
  897. Rectangle clientRectangle = base.ClientRectangle;
  898. this.chart.Rect = clientRectangle;
  899. }
  900. else
  901. {
  902. this.ControlGraphics.Clear(this.BackColor);
  903. }
  904. this.NeedRedraw();
  905. }
  906. public void CloseArea(FormulaArea fa)
  907. {
  908. int index = this.chart.Areas.IndexOf(fa);
  909. if ((index >= 0) && (this.chart.Areas.Count > 1))
  910. {
  911. this.chart.Areas.RemoveAt(index);
  912. this.areaPercent = this.chart.GetAreaPercent();
  913. this.SaveChartProperties();
  914. this.NeedRebind();
  915. }
  916. }
  917. private void cmRight_Popup(object sender, EventArgs e)
  918. {
  919. this.miStatisticWindow.Checked = this.ShowStatistic;
  920. this.miAdjust.Checked = this.AdjustData;
  921. FormulaArea selectedArea = this.chart.SelectedArea;
  922. if (selectedArea != null)
  923. {
  924. this.miFavorite.Enabled = !selectedArea.IsMain();
  925. if (selectedArea.Formulas.Count > 0)
  926. {
  927. foreach (MenuItem item in this.miFavorite.MenuItems)
  928. {
  929. item.Checked = string.Compare(item.Text, selectedArea.Formulas[0].Name, true) == 0;
  930. }
  931. }
  932. }
  933. }
  934. public void CopyAreaToClipboard(string Separatar)
  935. {
  936. Clipboard.SetDataObject(this.chart.GetAreaTextData(Separatar, true));
  937. }
  938. public void CopyToClipboard(string Separatar)
  939. {
  940. Clipboard.SetDataObject(this.chart.GetChartTextData(Separatar, true));
  941. }
  942. private void CreateCycleMenu()
  943. {
  944. if (this.favoriteCycles != null)
  945. {
  946. this.miCycle.MenuItems.Clear();
  947. foreach (string str in this.favoriteCycles.Split(new char[] { ';' }))
  948. {
  949. this.miCycle.MenuItems.Add(str, new EventHandler(this.miCycle_SelectedIndexChanged));
  950. }
  951. }
  952. }
  953. private void DefaultFormulasToAreas()
  954. {
  955. if (this.defaultFormulas != null)
  956. {
  957. this.chart.Areas.Clear();
  958. this.chart.StringsToArea(this.defaultFormulas.Split(new char[] { ';' }));
  959. }
  960. }
  961. private static string DefaultSelectFormula(string Default, string[] FilterPrefixes, bool SelectLine)
  962. {
  963. return new SelectFormula().Select(Default, FilterPrefixes, SelectLine);
  964. }
  965. private static string DefaultSelectMethod(string Default)
  966. {
  967. return new SelectMethod().Select(Default);
  968. }
  969. protected override void Dispose(bool disposing)
  970. {
  971. if (disposing && (this.components != null))
  972. {
  973. this.components.Dispose();
  974. }
  975. base.Dispose(disposing);
  976. }
  977. public static string DoSelectFormula(string Default, string[] FilterPrefixes, bool SelectLine)
  978. {
  979. if (OnSelectFormula != null)
  980. {
  981. return OnSelectFormula(Default, FilterPrefixes, SelectLine);
  982. }
  983. return Default;
  984. }
  985. public static string DoSelectSymbol(string Default)
  986. {
  987. if (OnSelectSymbol != null)
  988. {
  989. return OnSelectSymbol(Default);
  990. }
  991. return Default;
  992. }
  993. private void DrawCursor(Graphics g)
  994. {
  995. this.chart.DrawCursor(g, this.LastHitInfo.X, this.LastHitInfo.Y, false);
  996. }
  997. private void DrawCursorByPos(Graphics g)
  998. {
  999. this.DrawCursorByPos(g, float.NaN);
  1000. }
  1001. private void DrawCursorByPos(Graphics g, float DefaultY)
  1002. {
  1003. float num;
  1004. float num2;
  1005. this.chart.GetXYFromPos(out num, out num2);
  1006. this.LastHitInfo = this.chart.GetHitInfo(num, num2);
  1007. if (!float.IsNaN(DefaultY))
  1008. {
  1009. this.LastHitInfo.Y = DefaultY;
  1010. }
  1011. if ((this.LastHitInfo.HitType == FormulaHitType.htArea) && (g != null))
  1012. {
  1013. this.DrawCursor(g);
  1014. }
  1015. else
  1016. {
  1017. this.LastHitInfo.X = -1f;
  1018. }
  1019. }
  1020. public void DrawCursorByTime(DateTime t)
  1021. {
  1022. int num = this.chart.DateToIndex(t.ToOADate());
  1023. if (num != this.chart.CursorPos)
  1024. {
  1025. this.chart.CursorPos = num;
  1026. this.DrawCursorByPos(this.ControlGraphics, -1f);
  1027. this.ChangeCursorPos();
  1028. }
  1029. }
  1030. public void EditFormula()
  1031. {
  1032. FormulaArea selectedArea = this.chart.SelectedArea;
  1033. if ((selectedArea != null) && (selectedArea.Formulas.Count > 0))
  1034. {
  1035. FormulaBase fb = null;
  1036. if (selectedArea.SelectedFormula != null)
  1037. {
  1038. fb = selectedArea.SelectedFormula;
  1039. }
  1040. else
  1041. {
  1042. fb = selectedArea.Formulas[0];
  1043. }
  1044. if (EditFormula(fb))
  1045. {
  1046. return;
  1047. }
  1048. }
  1049. MessageBox.Show("Can't edit the source code of this formula");
  1050. }
  1051. public void EditFormula(FormulaArea fa)
  1052. {
  1053. if (fa != null)
  1054. {
  1055. FormulaManager manager = new FormulaManager();
  1056. if (manager.ShowForm(fa, fa.SelectedFormula) == DialogResult.OK)
  1057. {
  1058. this.SetAreaByName(fa, manager.CurrentFormulas);
  1059. }
  1060. }
  1061. else
  1062. {
  1063. this.EditOverlay();
  1064. }
  1065. }
  1066. public static bool EditFormula(FormulaBase fb)
  1067. {
  1068. string formulaFile = PluginManager.GetFormulaFile(fb);
  1069. if (formulaFile != null)
  1070. {
  1071. string directoryName = Path.GetDirectoryName(formulaFile);
  1072. formulaFile = Path.GetFileNameWithoutExtension(formulaFile).Replace('_', '.');
  1073. formulaFile = directoryName + @"\" + formulaFile;
  1074. if (File.Exists(formulaFile))
  1075. {
  1076. OpenFormulaSourceEditor(formulaFile, fb.GetType().ToString());
  1077. return true;
  1078. }
  1079. }
  1080. return false;
  1081. }
  1082. public void EditOverlay()
  1083. {
  1084. }
  1085. private void ExpandDefaultFormulas(int Count)
  1086. {
  1087. double percent = this.chart.Areas[0].HeightPercent / 3.0;
  1088. if (percent < 1.0)
  1089. {
  1090. percent = 1.0;
  1091. }
  1092. while (Count > this.chart.Areas.Count)
  1093. {
  1094. this.chart.AddArea("VOLMA", percent);
  1095. }
  1096. }
  1097. public MenuItem GetAreaMenu(int Count)
  1098. {
  1099. this.miIndicator.MenuItems.Clear();
  1100. for (int i = 0; i < Count; i++)
  1101. {
  1102. this.miIndicator.MenuItems.Add(new MenuItem(string.Concat(new object[] { "&", i + 1, " area", (i > 0) ? "s" : "" }), new EventHandler(this.miIndicator_SelectedIndexChanged), (Shortcut)(0x40031 + i)));
  1103. }
  1104. return this.miIndicator;
  1105. }
  1106. public MenuItem GetAxisMenu()
  1107. {
  1108. return this.miAxisType;
  1109. }
  1110. public Bitmap GetBitmap(bool ShowStatistic, bool ShowExtra)
  1111. {
  1112. this.chart.ExtraNeedRedraw = ShowExtra;
  1113. Bitmap memBitmap = this.chart.GetMemBitmap();
  1114. Bitmap image = new Bitmap(memBitmap);
  1115. Graphics g = Graphics.FromImage(image);
  1116. g.DrawImage(memBitmap, 0, 0);
  1117. g.DrawLine(Pens.Black, 0, 0, image.Width, 0);
  1118. if (ShowStatistic)
  1119. {
  1120. this.StatisticWindow.PaintTo(g);
  1121. }
  1122. return image;
  1123. }
  1124. public MenuItem GetChartMenu()
  1125. {
  1126. return this.GetChartMenu(true, true, true, true);
  1127. }
  1128. public MenuItem GetChartMenu(bool Skin, bool Cycle, bool Area, bool Axis)
  1129. {
  1130. this.miChart.MenuItems.Clear();
  1131. if (Skin)
  1132. {
  1133. this.miChart.MenuItems.Add(this.GetSkinMenu());
  1134. }
  1135. if (Cycle)
  1136. {
  1137. this.miChart.MenuItems.Add(this.miCycle);
  1138. }
  1139. if (Area)
  1140. {
  1141. this.miChart.MenuItems.Add(this.GetAreaMenu(9));
  1142. }
  1143. if (Axis)
  1144. {
  1145. this.miChart.MenuItems.Add(this.GetAxisMenu());
  1146. }
  1147. return this.miChart;
  1148. }
  1149. public DateTime GetCurrentTime()
  1150. {
  1151. return this.chart.IndexToDate();
  1152. }
  1153. public MenuItem GetEditMenu()
  1154. {
  1155. return this.miChartEdit;
  1156. }
  1157. private RectangleF GetRect(float x1, float y1, float x2, float y2)
  1158. {
  1159. return new RectangleF(Math.Min(x1, x2), Math.Min(y1, y2), Math.Abs((float)(x2 - x1)), Math.Abs((float)(y2 - y1)));
  1160. }
  1161. public MenuItem GetSkinMenu()
  1162. {
  1163. string[] buildInSkins = FormulaSkin.GetBuildInSkins();
  1164. this.miSkin.MenuItems.Clear();
  1165. foreach (string str in buildInSkins)
  1166. {
  1167. this.miSkin.MenuItems.Add(str, new EventHandler(this.mmSkin_SelectedIndexChanged));
  1168. }
  1169. return this.miSkin;
  1170. }
  1171. public MenuItem GetViewMenu()
  1172. {
  1173. return this.miView;
  1174. }
  1175. public void HandleKeyEvent(object sender, KeyEventArgs e)
  1176. {
  1177. if (base.ContainsFocus)
  1178. {
  1179. this.OnKeyDown(e);
  1180. }
  1181. }
  1182. private bool HasData()
  1183. {
  1184. return ((this.chart != null) && (this.chart.DataProvider != null));
  1185. }
  1186. private void HideCursor()
  1187. {
  1188. this.chart.HideCursor(this.ControlGraphics);
  1189. }
  1190. private void InitializeComponent()
  1191. {
  1192. this.cmRight = new ContextMenu();
  1193. this.miAddFormula = new MenuItem();
  1194. this.miCloseFormula = new MenuItem();
  1195. this.miFormulaManager = new MenuItem();
  1196. this.miEdit = new MenuItem();
  1197. this.miFavorite = new MenuItem();
  1198. this.miSp4 = new MenuItem();
  1199. this.miStatisticWindow = new MenuItem();
  1200. this.miAdjust = new MenuItem();
  1201. this.miSp2 = new MenuItem();
  1202. this.miCopy = new MenuItem();
  1203. this.cmMain = new ContextMenu();
  1204. this.miChart = new MenuItem();
  1205. this.miSkin = new MenuItem();
  1206. this.miCycle = new MenuItem();
  1207. this.miIndicator = new MenuItem();
  1208. this.miAxisType = new MenuItem();
  1209. this.miNormal = new MenuItem();
  1210. this.miLog = new MenuItem();
  1211. this.miView = new MenuItem();
  1212. this.miCrossCursor = new MenuItem();
  1213. this.miStatistic = new MenuItem();
  1214. this.miSp1 = new MenuItem();
  1215. this.miCalculator = new MenuItem();
  1216. this.miChartEdit = new MenuItem();
  1217. this.miChartCopy = new MenuItem();
  1218. this.StatisticWindow = new StatisticControl();
  1219. base.SuspendLayout();
  1220. this.cmRight.MenuItems.AddRange(new MenuItem[] { this.miAddFormula, this.miCloseFormula, this.miFormulaManager, this.miEdit, this.miFavorite, this.miSp4, this.miStatisticWindow, this.miAdjust, this.miSp2, this.miCopy });
  1221. this.cmRight.Popup += new EventHandler(this.cmRight_Popup);
  1222. this.miAddFormula.Index = 0;
  1223. this.miAddFormula.Text = "&Add New Formula Area";
  1224. this.miAddFormula.Click += new EventHandler(this.miAddFormula_Click);
  1225. this.miCloseFormula.Index = 1;
  1226. this.miCloseFormula.MergeOrder = 10;
  1227. this.miCloseFormula.Text = "Close Selected Formula";
  1228. this.miCloseFormula.Click += new EventHandler(this.miCloseFormula_Click);
  1229. this.miFormulaManager.Index = 2;
  1230. this.miFormulaManager.MergeOrder = 20;
  1231. this.miFormulaManager.Text = "E&dit Formula";
  1232. this.miFormulaManager.Click += new EventHandler(this.miFormulaEditor_Click);
  1233. this.miEdit.Index = 3;
  1234. this.miEdit.MergeOrder = 30;
  1235. this.miEdit.Shortcut = Shortcut.CtrlE;
  1236. this.miEdit.Text = "&Edit Formula Source Code";
  1237. this.miEdit.Click += new EventHandler(this.miEdit_Click);
  1238. this.miFavorite.Index = 4;
  1239. this.miFavorite.MergeOrder = 40;
  1240. this.miFavorite.Text = "&Favorite Indicators";
  1241. this.miSp4.Index = 5;
  1242. this.miSp4.MergeOrder = 50;
  1243. this.miSp4.Text = "-";
  1244. this.miStatisticWindow.Index = 6;
  1245. this.miStatisticWindow.MergeOrder = 80;
  1246. this.miStatisticWindow.Text = "Show &statistic window";
  1247. this.miStatisticWindow.Click += new EventHandler(this.miStatisticWindow_Click);
  1248. this.miAdjust.Index = 7;
  1249. this.miAdjust.MergeOrder = 90;
  1250. this.miAdjust.Text = "&Adjust Data";
  1251. this.miAdjust.Click += new EventHandler(this.miAdjust_Click);
  1252. this.miSp2.Index = 8;
  1253. this.miSp2.MergeOrder = 100;
  1254. this.miSp2.Text = "-";
  1255. this.miCopy.Index = 9;
  1256. this.miCopy.MergeOrder = 110;
  1257. this.miCopy.Shortcut = Shortcut.CtrlC;
  1258. this.miCopy.Text = "&Copy";
  1259. this.miCopy.Click += new EventHandler(this.miCopy_Click);
  1260. this.cmMain.MenuItems.AddRange(new MenuItem[] { this.miChart, this.miView, this.miChartEdit });
  1261. this.miChart.Index = 0;
  1262. this.miChart.MenuItems.AddRange(new MenuItem[] { this.miSkin, this.miCycle, this.miIndicator, this.miAxisType });
  1263. this.miChart.Text = "&Chart";
  1264. this.miSkin.Index = 0;
  1265. this.miSkin.Text = "&Skin";
  1266. this.miCycle.Index = 1;
  1267. this.miCycle.Text = "&Cycle";
  1268. this.miCycle.Click += new EventHandler(this.miCycle_Popup);
  1269. this.miIndicator.Index = 2;
  1270. this.miIndicator.Text = "&Indicator Areas";
  1271. this.miAxisType.Index = 3;
  1272. this.miAxisType.MenuItems.AddRange(new MenuItem[] { this.miNormal, this.miLog });
  1273. this.miAxisType.Text = "&Axis Type";
  1274. this.miNormal.Index = 0;
  1275. this.miNormal.RadioCheck = true;
  1276. this.miNormal.Shortcut = Shortcut.CtrlN;
  1277. this.miNormal.Text = "Normal";
  1278. this.miNormal.Click += new EventHandler(this.miNormalAxis_Click);
  1279. this.miLog.Index = 1;
  1280. this.miLog.MergeOrder = 1;
  1281. this.miLog.RadioCheck = true;
  1282. this.miLog.Shortcut = Shortcut.CtrlL;
  1283. this.miLog.Text = "Logarithm";
  1284. this.miLog.Click += new EventHandler(this.miNormalAxis_Click);
  1285. this.miView.Index = 1;
  1286. this.miView.MenuItems.AddRange(new MenuItem[] { this.miCrossCursor, this.miStatistic, this.miSp1, this.miCalculator });
  1287. this.miView.Text = "&View";
  1288. this.miView.Popup += new EventHandler(this.miView_Popup);
  1289. this.miCrossCursor.Checked = true;
  1290. this.miCrossCursor.Index = 0;
  1291. this.miCrossCursor.Text = "Cross Cursor";
  1292. this.miCrossCursor.Click += new EventHandler(this.miCrossCursor_Click);
  1293. this.miStatistic.Index = 1;
  1294. this.miStatistic.Text = "Statistic Window";
  1295. this.miStatistic.Click += new EventHandler(this.miStatistic_Click);
  1296. this.miSp1.Index = 2;
  1297. this.miSp1.Text = "-";
  1298. this.miCalculator.Index = 3;
  1299. this.miCalculator.Shortcut = Shortcut.CtrlJ;
  1300. this.miCalculator.Text = "&Calculator";
  1301. this.miCalculator.Click += new EventHandler(this.miCalculator_Click);
  1302. this.miChartEdit.Index = 2;
  1303. this.miChartEdit.MenuItems.AddRange(new MenuItem[] { this.miChartCopy });
  1304. this.miChartEdit.Text = "&Edit";
  1305. this.miChartCopy.Index = 0;
  1306. this.miChartCopy.Text = "&Copy";
  1307. this.miChartCopy.Click += new EventHandler(this.miChartCopy_Click);
  1308. this.StatisticWindow.Anchor = AnchorStyles.Left | AnchorStyles.Bottom;
  1309. this.StatisticWindow.BackColor = SystemColors.Info;
  1310. this.StatisticWindow.Cursor = Cursors.Arrow;
  1311. this.StatisticWindow.ForeColor = Color.Black;
  1312. this.StatisticWindow.Location = new Point(-1000, 0x38);
  1313. this.StatisticWindow.Name = "StatisticWindow";
  1314. this.StatisticWindow.Size = new Size(0xc0, 0x128);
  1315. this.StatisticWindow.TabIndex = 0;
  1316. this.StatisticWindow.Visible = false;
  1317. base.CausesValidation = false;
  1318. base.Controls.Add(this.StatisticWindow);
  1319. base.Name = "ChartWinControl";
  1320. base.Size = new Size(0x248, 0x1c0);
  1321. base.SizeChanged += new EventHandler(this.ChartWinControl_SizeChanged);
  1322. base.Enter += new EventHandler(this.ChartWinControl_Enter);
  1323. base.MouseUp += new MouseEventHandler(this.ChartWinControl_MouseUp);
  1324. base.Paint += new PaintEventHandler(this.ChartWinControl_Paint);
  1325. base.KeyDown += new KeyEventHandler(this.ChartWinControl_KeyDown);
  1326. base.DoubleClick += new EventHandler(this.ChartWinControl_DoubleClick);
  1327. base.MouseMove += new MouseEventHandler(this.ChartWinControl_MouseMove);
  1328. base.MouseLeave += new EventHandler(this.ChartWinControl_MouseLeave);
  1329. base.MouseDown += new MouseEventHandler(this.ChartWinControl_MouseDown);
  1330. base.ResumeLayout(false);
  1331. }
  1332. public void InsertNewFormula()
  1333. {
  1334. this.InsertNewFormula("");
  1335. }
  1336. public void InsertNewFormula(string Default)
  1337. {
  1338. FormulaArea fa = new FormulaArea(this.chart);
  1339. FormulaManager manager = new FormulaManager();
  1340. manager.CurrentFormulas = Default;
  1341. if (manager.ShowForm() == DialogResult.OK)
  1342. {
  1343. fa.HeightPercent = this.chart[0].HeightPercent / 3.0;
  1344. this.chart.Areas.Add(fa);
  1345. this.SetAreaByName(fa, manager.CurrentFormulas);
  1346. this.NeedRebind();
  1347. }
  1348. }
  1349. private void InvalidateHitInfo(FormulaHitInfo fhi)
  1350. {
  1351. Region region = new Region(new RectangleF(fhi.X - 1f, 0f, 2f, (float)this.chart.Rect.Height));
  1352. region.Union(new RectangleF(0f, fhi.Y - 1f, (float)this.chart.Rect.Width, 2f));
  1353. foreach (FormulaArea area in this.chart.Areas)
  1354. {
  1355. RectangleF lastCursorRect = area.AxisX.LastCursorRect;
  1356. region.Union(new RectangleF(fhi.X - lastCursorRect.Width, lastCursorRect.Y, lastCursorRect.Width * 2f, lastCursorRect.Height));
  1357. region.Union(new RectangleF((float)area.Rect.X, (float)area.Rect.Y, (float)area.Rect.Width, 20f));
  1358. foreach (FormulaAxisY sy in area.AxisYs)
  1359. {
  1360. lastCursorRect = sy.LastCursorRect;
  1361. if (!lastCursorRect.IsEmpty)
  1362. {
  1363. region.Union(new RectangleF(lastCursorRect.X, fhi.Y, lastCursorRect.Width, lastCursorRect.Height));
  1364. }
  1365. }
  1366. }
  1367. base.Invalidate(region);
  1368. }
  1369. public void MergeRightMenu(ContextMenu cm)
  1370. {
  1371. this.cmRight.MergeMenu(cm);
  1372. }
  1373. private void miAddFormula_Click(object sender, EventArgs e)
  1374. {
  1375. this.InsertNewFormula();
  1376. }
  1377. private void miAdjust_Click(object sender, EventArgs e)
  1378. {
  1379. this.AdjustData = !this.AdjustData;
  1380. }
  1381. private void miCalculator_Click(object sender, EventArgs e)
  1382. {
  1383. Process.Start("Calc.exe");
  1384. }
  1385. private void miChartCopy_Click(object sender, EventArgs e)
  1386. {
  1387. this.CopyToClipboard(",");
  1388. }
  1389. private void miCloseFormula_Click(object sender, EventArgs e)
  1390. {
  1391. this.CloseArea(this.chart.SelectedArea);
  1392. }
  1393. private void miCopy_Click(object sender, EventArgs e)
  1394. {
  1395. this.CopyAreaToClipboard(",");
  1396. }
  1397. private void miCrossCursor_Click(object sender, EventArgs e)
  1398. {
  1399. this.ShowCrossCursor = !this.ShowCrossCursor;
  1400. }
  1401. private void miCycle_Popup(object sender, EventArgs e)
  1402. {
  1403. foreach (MenuItem item in this.miCycle.MenuItems)
  1404. {
  1405. item.Checked = item.Text == this.currentDataCycle.ToString();
  1406. }
  1407. }
  1408. private void miCycle_SelectedIndexChanged(object sender, EventArgs e)
  1409. {
  1410. this.EndTime = DateTime.MinValue;
  1411. this.CurrentDataCycle = DataCycle.Parse((sender as MenuItem).Text);
  1412. }
  1413. private void miEdit_Click(object sender, EventArgs e)
  1414. {
  1415. this.EditFormula();
  1416. }
  1417. private void miFormulaEditor_Click(object sender, EventArgs e)
  1418. {
  1419. this.EditFormula(this.chart.SelectedArea);
  1420. }
  1421. private void miIndicator_SelectedIndexChanged(object sender, EventArgs e)
  1422. {
  1423. this.AreaCount = (sender as MenuItem).Index + 1;
  1424. }
  1425. private void miNormalAxis_Click(object sender, EventArgs e)
  1426. {
  1427. foreach (MenuItem item in this.miAxisType.MenuItems)
  1428. {
  1429. item.Checked = false;
  1430. }
  1431. MenuItem item2 = sender as MenuItem;
  1432. item2.Checked = true;
  1433. this.ScaleType = (IndexFormula.Finance.ScaleType)item2.MergeOrder;
  1434. }
  1435. private void miOverlay_Click(object sender, EventArgs e)
  1436. {
  1437. this.EditOverlay();
  1438. }
  1439. private void miStatistic_Click(object sender, EventArgs e)
  1440. {
  1441. this.ShowStatistic = !this.ShowStatistic;
  1442. }
  1443. private void miStatisticWindow_Click(object sender, EventArgs e)
  1444. {
  1445. this.ShowStatistic = !this.ShowStatistic;
  1446. }
  1447. private void miView_Popup(object sender, EventArgs e)
  1448. {
  1449. this.miStatistic.Checked = this.ShowStatistic;
  1450. }
  1451. private void mmFavorite_SelectedIndexChanged(object sender, EventArgs e)
  1452. {
  1453. FormulaArea selectedArea = this.chart.SelectedArea;
  1454. if ((selectedArea != null) && !selectedArea.IsMain())
  1455. {
  1456. this.SetAreaByName(selectedArea, (sender as MenuItem).Text);
  1457. }
  1458. }
  1459. private void mmSkin_SelectedIndexChanged(object sender, EventArgs e)
  1460. {
  1461. foreach (MenuItem item in this.miSkin.MenuItems)
  1462. {
  1463. item.Checked = false;
  1464. }
  1465. MenuItem item2 = (MenuItem)sender;
  1466. item2.Checked = true;
  1467. string text = item2.Text;
  1468. this.Skin = text;
  1469. }
  1470. private void MouseCrossCursor(Graphics g, FormulaHitInfo HitInfo)
  1471. {
  1472. if (!this.Designing)
  1473. {
  1474. if (HitInfo.HitType == FormulaHitType.htArea)
  1475. {
  1476. this.chart.CursorPos = HitInfo.CursorPos;
  1477. if (this.memoryCrossCursor)
  1478. {
  1479. this.InvalidateHitInfo(this.LastHitInfo);
  1480. this.InvalidateHitInfo(HitInfo);
  1481. }
  1482. else
  1483. {
  1484. this.chart.DrawCursor(g, HitInfo.X, HitInfo.Y, false);
  1485. }
  1486. this.ChangeCursorPos();
  1487. this.LastHitInfo = HitInfo;
  1488. }
  1489. else
  1490. {
  1491. this.HideCursor();
  1492. this.LastHitInfo.X = 0f;
  1493. }
  1494. }
  1495. }
  1496. public void MoveArea(FormulaArea fa, int NewIndex)
  1497. {
  1498. int index = this.chart.Areas.IndexOf(fa);
  1499. if (index >= 0)
  1500. {
  1501. if (NewIndex > index)
  1502. {
  1503. NewIndex--;
  1504. }
  1505. if (NewIndex >= 0)
  1506. {
  1507. this.chart.Areas.RemoveAt(index);
  1508. if (NewIndex > this.chart.Areas.Count)
  1509. {
  1510. NewIndex = this.chart.Areas.Count;
  1511. }
  1512. this.chart.Areas.Insert(NewIndex, fa);
  1513. this.areaPercent = this.chart.GetAreaPercent();
  1514. this.SaveChartProperties();
  1515. this.NeedRebind();
  1516. }
  1517. }
  1518. }
  1519. public void MoveAreaDown(FormulaArea fa)
  1520. {
  1521. int index = this.chart.Areas.IndexOf(fa);
  1522. this.MoveArea(fa, index + 2);
  1523. }
  1524. public void MoveAreaUp(FormulaArea fa)
  1525. {
  1526. int index = this.chart.Areas.IndexOf(fa);
  1527. this.MoveArea(fa, index - 1);
  1528. }
  1529. private void MoveChartX(FormulaArea fa, int TotalPart, int CurrentPart, float DeltaX)
  1530. {
  1531. if (DeltaX != 0f)
  1532. {
  1533. if (this.EndTime == DateTime.MinValue)
  1534. {
  1535. this.EndTime = this.chart.EndTime;
  1536. this.StartTime = this.chart.StartTime;
  1537. }
  1538. int num = this.chart.DateToIndex(this.chart.EndTime, -1);
  1539. int num2 = this.chart.DateToIndex(this.chart.StartTime);
  1540. double num3 = (num - num2) + 1;
  1541. int moveBars = (int)((num3 * DeltaX) / ((double)fa.Rect.Width));
  1542. this.MoveChartXBars(TotalPart, CurrentPart, this.DragInfo.StartTime, this.DragInfo.EndTime, moveBars);
  1543. }
  1544. }
  1545. public void MoveChartXBars(int MoveBars)
  1546. {
  1547. this.MoveChartXBars(3, 1, MoveBars);
  1548. }
  1549. private void MoveChartXBars(int TotalPart, int CurrentPart, int MoveBars)
  1550. {
  1551. this.MoveChartXBars(TotalPart, CurrentPart, this.chart.StartTime, this.chart.EndTime, MoveBars);
  1552. }
  1553. private void MoveChartXBars(int TotalPart, int CurrentPart, DateTime StartTime, DateTime EndTime, int MoveBars)
  1554. {
  1555. if ((this.chart != null) && (this.chart.DataProvider != null))
  1556. {
  1557. double[] numArray = this.chart.DataProvider["DATE"];
  1558. DateTime startTime = this.StartTime;
  1559. DateTime endTime = this.EndTime;
  1560. bool flag = false;
  1561. if (CurrentPart > 0)
  1562. {
  1563. int i = this.chart.DateToIndex(EndTime, -1) + MoveBars;
  1564. if (i < 0)
  1565. {
  1566. i = 0;
  1567. flag = true;
  1568. }
  1569. if (this.chart.CursorPos > i)
  1570. {
  1571. this.chart.CursorPos = i;
  1572. this.ChangeCursorPos();
  1573. }
  1574. this.EndTime = this.chart.IndexToDate(i);
  1575. }
  1576. if (CurrentPart < (TotalPart - 1))
  1577. {
  1578. int num2 = this.chart.DateToIndex(StartTime) + MoveBars;
  1579. if (num2 >= (numArray.Length - 1))
  1580. {
  1581. num2 = numArray.Length - 2;
  1582. flag = true;
  1583. }
  1584. if (num2 < 0)
  1585. {
  1586. num2 = 0;
  1587. }
  1588. if (this.chart.CursorPos < num2)
  1589. {
  1590. this.chart.CursorPos = num2;
  1591. this.ChangeCursorPos();
  1592. }
  1593. this.StartTime = this.chart.IndexToDate(num2);
  1594. }
  1595. if (flag && (CurrentPart == 1))
  1596. {
  1597. this.StartTime = startTime;
  1598. this.EndTime = endTime;
  1599. }
  1600. if (this.resetYAfterXChanged)
  1601. {
  1602. FormulaArea mainArea = this.chart.MainArea;
  1603. if (mainArea != null)
  1604. {
  1605. this.minPrice = 0.0;
  1606. mainArea.AxisY.AutoScale = true;
  1607. }
  1608. }
  1609. if ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch)
  1610. {
  1611. this.NeedRebind();
  1612. }
  1613. }
  1614. }
  1615. private void MoveChartY(FormulaArea fa, int Part, int CurrentPart, float DeltaY)
  1616. {
  1617. if (DeltaY != 0f)
  1618. {
  1619. FormulaAxisY axisY = this.DragInfo.HitInfo.AxisY;
  1620. if (axisY == null)
  1621. {
  1622. axisY = fa.AxisY;
  1623. }
  1624. axisY.AutoScale = false;
  1625. double num = ((this.DragInfo.AreaMaxY - this.DragInfo.AreaMinY) / ((double)fa.Rect.Height)) * DeltaY;
  1626. if (CurrentPart > 0)
  1627. {
  1628. axisY.MinY = this.DragInfo.AreaMinY - num;
  1629. }
  1630. if (CurrentPart < (Part - 1))
  1631. {
  1632. axisY.MaxY = this.DragInfo.AreaMaxY - num;
  1633. }
  1634. this.minPrice = 0.0;
  1635. this.maxPrice = 0.0;
  1636. this.NeedRedraw(fa);
  1637. }
  1638. }
  1639. public void NeedRebind()
  1640. {
  1641. this.NeedRebind(true);
  1642. }
  1643. public void NeedRebind(bool AutoScaleY)
  1644. {
  1645. this.NeedRebind(AutoScaleY, false);
  1646. }
  1647. private void NeedRebind(bool AutoScaleY, bool DrawLastBarOnly)
  1648. {
  1649. this.needAutoScaleY = AutoScaleY;
  1650. this.needDrawLastBarOnly = DrawLastBarOnly;
  1651. this.needRedraw = true;
  1652. this.needRebind = true;
  1653. base.Invalidate();
  1654. }
  1655. public void NeedRedraw()
  1656. {
  1657. this.NeedRedraw(null);
  1658. }
  1659. public void NeedRedraw(FormulaArea fa)
  1660. {
  1661. this.needRedraw = true;
  1662. if (fa != null)
  1663. {
  1664. Rectangle rect = fa.Rect;
  1665. rect.Inflate(1, 1);
  1666. base.Invalidate(rect);
  1667. }
  1668. else
  1669. {
  1670. base.Invalidate();
  1671. }
  1672. }
  1673. public void NeedRefresh()
  1674. {
  1675. this.needRedraw = true;
  1676. this.needRebind = true;
  1677. this.needRefresh = true;
  1678. base.Invalidate();
  1679. }
  1680. private void NextArea(int Delta)
  1681. {
  1682. int num = ((this.chart.Areas.IndexOf(this.chart.SelectedArea) + Delta) + this.chart.Areas.Count) % this.chart.Areas.Count;
  1683. if (num < this.chart.Areas.Count)
  1684. {
  1685. this.chart.SelectedArea = this.chart[num];
  1686. }
  1687. this.NeedRedraw();
  1688. }
  1689. private void NextCycle(int Delta)
  1690. {
  1691. if ((this.favoriteCycles != null) && (this.favoriteCycles != ""))
  1692. {
  1693. ArrayList list = new ArrayList();
  1694. list.AddRange(this.favoriteCycles.Split(new char[] { ';' }));
  1695. int index = list.IndexOf(this.CurrentDataCycle.ToString());
  1696. if (index < 0)
  1697. {
  1698. index = 0;
  1699. }
  1700. index = ((index + Delta) + list.Count) % list.Count;
  1701. if (!this.fixedTime)
  1702. {
  1703. this.EndTime = DateTime.MinValue;
  1704. }
  1705. this.CurrentDataCycle = DataCycle.Parse(list[index].ToString());
  1706. }
  1707. }
  1708. private void NextFormula(int Delta)
  1709. {
  1710. int index = this.chart.Areas.IndexOf(this.chart.SelectedArea);
  1711. if (index < 0)
  1712. {
  1713. index = this.chart.Areas.Count - 1;
  1714. }
  1715. if (index >= 0)
  1716. {
  1717. FormulaArea area = this.chart[index];
  1718. if (!area.IsMain())
  1719. {
  1720. string str = area.FormulaToString('#');
  1721. int length = str.IndexOf('(');
  1722. if (length >= 0)
  1723. {
  1724. str = str.Substring(0, length);
  1725. }
  1726. int num3 = -1;
  1727. for (int i = 0; i < this.favoriteFormulas.Count; i++)
  1728. {
  1729. if (string.Compare(str, (string)this.favoriteFormulas[i], true) == 0)
  1730. {
  1731. num3 = i;
  1732. }
  1733. }
  1734. if (num3 < 0)
  1735. {
  1736. num3 = 0;
  1737. }
  1738. num3 = ((num3 + Delta) + this.favoriteFormulas.Count) % this.favoriteFormulas.Count;
  1739. this.SetAreaByName(index, (string)this.favoriteFormulas[num3]);
  1740. this.NeedRebind();
  1741. }
  1742. }
  1743. }
  1744. protected override void OnPaintBackground(PaintEventArgs pevent)
  1745. {
  1746. if ((this.chart == null) || (this.chart.DataProvider == null))
  1747. {
  1748. base.OnPaintBackground(pevent);
  1749. }
  1750. }
  1751. public static void OpenFormulaSourceEditor()
  1752. {
  1753. OpenFormulaSourceEditor("", "");
  1754. }
  1755. public static void OpenFormulaSourceEditor(string Filename, string Formula)
  1756. {
  1757. FormulaSourceEditor.Open(Filename, Formula);
  1758. }
  1759. public void Print()
  1760. {
  1761. this.SetupPrinting();
  1762. if (this.printDialog.ShowDialog() == DialogResult.OK)
  1763. {
  1764. this.printDocument.Print();
  1765. }
  1766. }
  1767. private void printDocument_PrintPage(object sender, PrintPageEventArgs e)
  1768. {
  1769. Bitmap image = this.GetBitmap(true, true);
  1770. e.Graphics.DrawImage(image, e.MarginBounds, new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
  1771. }
  1772. public void PrintPreview()
  1773. {
  1774. this.SetupPrinting();
  1775. this.previewDialog.ShowDialog();
  1776. }
  1777. public void PrintSetup()
  1778. {
  1779. this.SetupPrinting();
  1780. this.setupDialog.ShowDialog();
  1781. }
  1782. private void RebindLastBar()
  1783. {
  1784. this.needDrawLastBarOnly = true;
  1785. this.BindData();
  1786. this.RenderChart(this.ControlGraphics);
  1787. }
  1788. private void RecreateFormula()
  1789. {
  1790. if (this.chart != null)
  1791. {
  1792. foreach (FormulaArea area in this.chart.Areas)
  1793. {
  1794. this.RecreateFormula(area);
  1795. }
  1796. }
  1797. this.SaveChartProperties();
  1798. }
  1799. private void RecreateFormula(FormulaArea fa)
  1800. {
  1801. string[] ss = fa.FormulaToStrings();
  1802. fa.Formulas.Clear();
  1803. fa.StringsToFormula(ss);
  1804. }
  1805. public void RenderChart(Graphics g)
  1806. {
  1807. Graphics graphics = g;
  1808. if (this.memoryCrossCursor)
  1809. {
  1810. Rectangle rect = this.chart.Rect;
  1811. if (((this.CrossMemBmp == null) || (this.CrossMemBmp.Width != rect.Width)) || (this.CrossMemBmp.Height != rect.Height))
  1812. {
  1813. this.CrossMemBmp = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppPArgb);
  1814. this.CrossMemBmpG = Graphics.FromImage(this.CrossMemBmp);
  1815. }
  1816. Region r = null;
  1817. if (this.needDrawLastBarOnly && this.needRebind)
  1818. {
  1819. r = new Region();
  1820. r.MakeEmpty();
  1821. }
  1822. g = this.CrossMemBmpG;
  1823. g.SetClip(graphics);
  1824. this.chart.Render(g, r);
  1825. graphics.SetClip(g);
  1826. if (this.LastHitInfo.X != 0f)
  1827. {
  1828. if (this.needRebind)
  1829. {
  1830. this.SetCursorPos();
  1831. }
  1832. if (this.needDrawCursor)
  1833. {
  1834. this.DrawCursorByPos(g);
  1835. this.needDrawCursor = false;
  1836. }
  1837. else
  1838. {
  1839. this.DrawCursor(g);
  1840. }
  1841. }
  1842. }
  1843. else
  1844. {
  1845. this.chart.Render(g);
  1846. if (this.needDrawCursor)
  1847. {
  1848. this.chart.DrawCursor(g);
  1849. this.needDrawCursor = false;
  1850. }
  1851. else if ((this.crossCursorMouseMode == MouseAction.MouseDown) && (this.LastHitInfo.X != 0f))
  1852. {
  1853. this.LastHitInfo = this.chart.GetHitInfo(this.LastHitInfo.X, this.LastHitInfo.Y);
  1854. this.MouseCrossCursor(this.ControlGraphics, this.LastHitInfo);
  1855. }
  1856. }
  1857. if (this.MouseZoomBmp != null)
  1858. {
  1859. g.DrawImage(this.MouseZoomBmp, this.MouseZoomRect, this.MouseZoomRect, GraphicsUnit.Pixel);
  1860. }
  1861. if (this.memoryCrossCursor)
  1862. {
  1863. graphics.DrawImage(this.CrossMemBmp, 0, 0);
  1864. }
  1865. }
  1866. public void Reset(int columnWidth)
  1867. {
  1868. this.EndTime = DateTime.MinValue;
  1869. this.StockBars = base.Width / columnWidth;
  1870. this.AutoScaleAxisY();
  1871. }
  1872. public void SaveChartProperties()
  1873. {
  1874. this.AreasToDefaultFormulas();
  1875. this.areaPercent = this.chart.GetAreaPercent();
  1876. }
  1877. public void ScaleChart(double ScaleFactor)
  1878. {
  1879. if ((this.chart != null) && !this.chart.FixedTime)
  1880. {
  1881. int moveBars = (int)((this.chart.GetTotalBars() * ScaleFactor) + 0.5);
  1882. if (moveBars == 0)
  1883. {
  1884. if (ScaleFactor > 0.0)
  1885. {
  1886. moveBars = 1;
  1887. }
  1888. else
  1889. {
  1890. moveBars = -1;
  1891. }
  1892. }
  1893. int num3 = -moveBars;
  1894. if (this.zoomPosition == ZoomCenterPosition.Left)
  1895. {
  1896. moveBars = 0;
  1897. }
  1898. if (this.zoomPosition == ZoomCenterPosition.Right)
  1899. {
  1900. num3 = 0;
  1901. }
  1902. this.MoveChartXBars(3, 0, moveBars);
  1903. this.MoveChartXBars(3, 2, num3);
  1904. }
  1905. }
  1906. public void SetAreaByName(string FormulaName)
  1907. {
  1908. FormulaArea selectedArea = this.chart.SelectedArea;
  1909. if (selectedArea == null)
  1910. {
  1911. selectedArea = this.chart.Areas[this.chart.Areas.Count - 1];
  1912. }
  1913. this.SetAreaByName(selectedArea, FormulaName);
  1914. }
  1915. public void SetAreaByName(FormulaArea fa, string FormulaName)
  1916. {
  1917. if (fa != null)
  1918. {
  1919. int index = this.chart.Areas.IndexOf(fa);
  1920. if (index >= 0)
  1921. {
  1922. string s = fa.FormulaToString('#');
  1923. try
  1924. {
  1925. this.SetDefaultFormulas(index, FormulaName);
  1926. }
  1927. catch
  1928. {
  1929. this.SetDefaultFormulas(index, s);
  1930. throw;
  1931. }
  1932. this.SaveChartProperties();
  1933. this.NeedRebind();
  1934. }
  1935. }
  1936. }
  1937. public void SetAreaByName(int AreaIndex, string FormulaName)
  1938. {
  1939. if ((AreaIndex >= 0) && (AreaIndex < this.chart.Areas.Count))
  1940. {
  1941. this.SetAreaByName(this.chart.Areas[AreaIndex], FormulaName);
  1942. }
  1943. }
  1944. private void SetAreaCount(int Count)
  1945. {
  1946. if (this.chart.Areas.Count != Count)
  1947. {
  1948. while (this.chart.Areas.Count > Count)
  1949. {
  1950. this.chart.Areas.RemoveAt(Count);
  1951. }
  1952. int num = this.chart.Areas.Count;
  1953. this.ExpandDefaultFormulas(Count);
  1954. double num2 = 1.0;
  1955. if (this.chart.Areas.Count > 0)
  1956. {
  1957. num2 = this.chart[0].HeightPercent / 3.0;
  1958. }
  1959. for (int i = num; i < this.chart.Areas.Count; i++)
  1960. {
  1961. this.chart[i].HeightPercent = num2;
  1962. }
  1963. this.areaPercent = this.chart.GetAreaPercent();
  1964. this.NeedRebind();
  1965. }
  1966. this.UseDefaultFormulas(false);
  1967. }
  1968. private void SetCursorPos()
  1969. {
  1970. this.chart.CursorPos = this.LastHitInfo.CursorPos;
  1971. }
  1972. private void SetDefaultFormulas(int Index, string s)
  1973. {
  1974. this.ExpandDefaultFormulas(Index);
  1975. this.chart[Index].Formulas.Clear();
  1976. this.chart[Index].StringToFormula(s, '#');
  1977. }
  1978. private void SetupPrinting()
  1979. {
  1980. if (this.printDialog == null)
  1981. {
  1982. this.printDialog = new PrintDialog();
  1983. this.printDocument = new PrintDocument();
  1984. this.previewDialog = new PrintPreviewDialog();
  1985. this.setupDialog = new PageSetupDialog();
  1986. this.printDocument.DefaultPageSettings.Landscape = true;
  1987. this.printDocument.DefaultPageSettings.Margins = new Margins(30, 30, 30, 30);
  1988. this.printDialog.Document = this.printDocument;
  1989. this.printDocument.PrintPage += new PrintPageEventHandler(this.printDocument_PrintPage);
  1990. this.previewDialog.Document = this.printDocument;
  1991. this.setupDialog.Document = this.printDocument;
  1992. }
  1993. }
  1994. public void ShowAllBars()
  1995. {
  1996. if ((this.chart != null) && (this.chart.DataProvider != null))
  1997. {
  1998. double[] numArray = this.chart.DataProvider["DATE"];
  1999. if (numArray.Length > 0)
  2000. {
  2001. this.StartTime = DateTime.FromOADate(numArray[0]);
  2002. this.EndTime = DateTime.FromOADate(numArray[numArray.Length - 1]);
  2003. }
  2004. }
  2005. }
  2006. private void ShowStatisticWindow(object Sender, FormulaChart Chart, int Pos, IDataProvider idp)
  2007. {
  2008. if (this.ShowStatistic)
  2009. {
  2010. if (this.StatisticWindow.Left < 0)
  2011. {
  2012. this.StatisticWindow.Left = 10;
  2013. }
  2014. string format = "f2";
  2015. if ((Chart.MainArea != null) && Chart.MainArea.IsMain())
  2016. {
  2017. format = Chart.MainArea.AxisY.Format;
  2018. }
  2019. double d = idp["DATE"][Chart.CursorPos];
  2020. double num2 = idp["OPEN"][Chart.CursorPos];
  2021. double num3 = idp["HIGH"][Chart.CursorPos];
  2022. double num4 = idp["LOW"][Chart.CursorPos];
  2023. double num5 = idp["CLOSE"][Chart.CursorPos];
  2024. double num6 = idp["VOLUME"][Chart.CursorPos];
  2025. string str2 = "";
  2026. string str3 = "";
  2027. string str4 = "";
  2028. if (Chart.CursorPos > 0)
  2029. {
  2030. double num7 = idp["CLOSE"][Chart.CursorPos - 1];
  2031. if (num7 != double.NaN)
  2032. {
  2033. str2 = FormulaHelper.FormatDouble(num7, format);
  2034. str3 = (num5 - num7).ToString("f2");
  2035. str4 = ((num5 - num7) / num7).ToString("p2");
  2036. }
  2037. }
  2038. StringBuilder builder = new StringBuilder();
  2039. builder.Append("Symbol=" + idp.GetStringData("Code") + ";");
  2040. builder.Append("Date=" + DateTime.FromOADate(d).ToString(Chart.XCursorFormat, DateTimeFormatInfo.InvariantInfo) + ";");
  2041. builder.Append("Current=" + FormulaHelper.FormatDouble(num5, format) + ";");
  2042. builder.Append("Last=" + str2 + ";");
  2043. builder.Append("Open=" + FormulaHelper.FormatDouble(num2, format) + ";");
  2044. builder.Append("High=" + FormulaHelper.FormatDouble(num3, format) + ";");
  2045. builder.Append("Low=" + FormulaHelper.FormatDouble(num4, format) + ";");
  2046. builder.Append("Close=" + FormulaHelper.FormatDouble(num5, format) + ";");
  2047. builder.Append("Volume=" + num6.ToString() + ";");
  2048. builder.Append("Change=" + str3 + ";");
  2049. builder.Append("Percent=" + str4 + ";");
  2050. if (this.ShowIndicatorValues)
  2051. {
  2052. try
  2053. {
  2054. for (int i = this.showOverlayValues ? 0 : 1; i < Chart.Areas.Count; i++)
  2055. {
  2056. int num9 = 0;
  2057. int num10 = 0;
  2058. foreach (FormulaData data in Chart[i].FormulaDataArray)
  2059. {
  2060. string displayName;
  2061. if (num10 == 0)
  2062. {
  2063. displayName = Chart[i].Formulas[num9].DisplayName;
  2064. }
  2065. else
  2066. {
  2067. displayName = "";
  2068. }
  2069. if (data.ValueTextMode != IndexFormula.Finance.ValueTextMode.None)
  2070. {
  2071. string str6 = (displayName + data.Name).Trim();
  2072. if (str6 != "")
  2073. {
  2074. builder.Append(str6 + "=" + FormulaHelper.FormatDouble(data[Chart.CursorPos], Chart[i].AxisYs[data.AxisYIndex].Format) + ";");
  2075. }
  2076. }
  2077. num10++;
  2078. if (num10 == Chart[i].Packages[num9].Count)
  2079. {
  2080. num9++;
  2081. num10 = 0;
  2082. }
  2083. }
  2084. }
  2085. }
  2086. catch
  2087. {
  2088. }
  2089. }
  2090. this.StatisticWindow.RefreshData(builder.ToString());
  2091. this.LastProvider = Chart.DataProvider;
  2092. this.LastCursorPos = Chart.CursorPos;
  2093. }
  2094. }
  2095. private string[] Split(string s, char separator)
  2096. {
  2097. ArrayList list = new ArrayList();
  2098. int num = 0;
  2099. int startIndex = 0;
  2100. for (int i = 0; i < s.Length; i++)
  2101. {
  2102. if (s[i] == '(')
  2103. {
  2104. num++;
  2105. }
  2106. else if (s[i] == ')')
  2107. {
  2108. num--;
  2109. }
  2110. if ((num == 0) && (s[i] == separator))
  2111. {
  2112. list.Add(s.Substring(startIndex, i - startIndex));
  2113. startIndex = i + 1;
  2114. }
  2115. }
  2116. return (string[])list.ToArray(typeof(string));
  2117. }
  2118. private void StatisticWindow_OnHide(object sender, EventArgs e)
  2119. {
  2120. this.ShowStatistic = this.StatisticWindow.Visible;
  2121. }
  2122. public void UseDefaultFormulas(bool b)
  2123. {
  2124. this.needSetDefaultFormulas = b;
  2125. }
  2126. [Category("Stock Chart"), DefaultValue(true), Description("Adjust the data automatically when there is price split")]
  2127. public bool AdjustData
  2128. {
  2129. get
  2130. {
  2131. return this.adjustData;
  2132. }
  2133. set
  2134. {
  2135. this.adjustData = value;
  2136. this.NeedRebind();
  2137. }
  2138. }
  2139. [DefaultValue((double)0.1), Category("Stock Chart Time"), Description("How many right space after the last bar of the chart. If the value between 0 and 1, it means the percentage of the bar.")]
  2140. public double AfterBars
  2141. {
  2142. get
  2143. {
  2144. return this.afterBars;
  2145. }
  2146. set
  2147. {
  2148. this.afterBars = value;
  2149. }
  2150. }
  2151. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Browsable(false)]
  2152. public int AreaCount
  2153. {
  2154. get
  2155. {
  2156. return this.chart.Areas.Count;
  2157. }
  2158. set
  2159. {
  2160. this.SetAreaCount(value);
  2161. }
  2162. }
  2163. [Category("Stock Chart"), DefaultValue("3;1;1;1;1"), Description("Height percentage of each area,separated by semi colon.")]
  2164. public string AreaPercent
  2165. {
  2166. get
  2167. {
  2168. return this.areaPercent;
  2169. }
  2170. set
  2171. {
  2172. this.areaPercent = value;
  2173. }
  2174. }
  2175. [Browsable(false)]
  2176. public string Caption
  2177. {
  2178. get
  2179. {
  2180. IDataProvider dataProvider = this.chart.DataProvider;
  2181. string stringData = dataProvider.GetStringData("Code");
  2182. string str2 = dataProvider.GetStringData("Name");
  2183. if (str2 != null)
  2184. {
  2185. stringData = stringData + "(" + str2 + ")";
  2186. }
  2187. string str3 = dataProvider.GetStringData("Exchange");
  2188. if (str3 != null)
  2189. {
  2190. stringData = stringData + "@" + str3;
  2191. }
  2192. return (stringData + " - " + this.CurrentDataCycle);
  2193. }
  2194. }
  2195. [Browsable(false)]
  2196. public FormulaChart Chart
  2197. {
  2198. get
  2199. {
  2200. return this.chart;
  2201. }
  2202. }
  2203. [DefaultValue(1), Description("Behaver when drag the chart"), Category("Stock Chart")]
  2204. public IndexFormula.Finance.ChartDragMode ChartDragMode
  2205. {
  2206. get
  2207. {
  2208. return this.chartDragMode;
  2209. }
  2210. set
  2211. {
  2212. this.chartDragMode = value;
  2213. }
  2214. }
  2215. [Browsable(false), DefaultValue((double)4.0), Category("Stock Chart Time")]
  2216. public double ColumnWidth
  2217. {
  2218. get
  2219. {
  2220. return this.columnWidth;
  2221. }
  2222. set
  2223. {
  2224. this.columnWidth = value;
  2225. }
  2226. }
  2227. [DefaultValue(1), Category("Stock Chart"), Description("How to show the cross cursor according mouse action, mouse move or mouse down")]
  2228. public MouseAction CrossCursorMouseMode
  2229. {
  2230. get
  2231. {
  2232. return this.crossCursorMouseMode;
  2233. }
  2234. set
  2235. {
  2236. this.crossCursorMouseMode = value;
  2237. }
  2238. }
  2239. [Description("Data Cycle"), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), DefaultValue(typeof(DataCycle), "DAY1"), Category("Stock Chart")]
  2240. public DataCycle CurrentDataCycle
  2241. {
  2242. get
  2243. {
  2244. return this.currentDataCycle;
  2245. }
  2246. set
  2247. {
  2248. if (this.currentDataCycle != value)
  2249. {
  2250. if (this.BeforeCycleChange != null)
  2251. {
  2252. this.BeforeCycleChange(this, new EventArgs());
  2253. }
  2254. if ((value.CycleBase >= DataCycleBase.DAY) && this.chart.FixedTime)
  2255. {
  2256. this.fixedTime = false;
  2257. this.chart.FixedTime = false;
  2258. }
  2259. this.NeedRebind();
  2260. this.currentDataCycle = value;
  2261. if (this.AfterCycleChange != null)
  2262. {
  2263. this.AfterCycleChange(this, new EventArgs());
  2264. }
  2265. }
  2266. }
  2267. }
  2268. [Browsable(false)]
  2269. public DataManagerBase DataManager
  2270. {
  2271. set
  2272. {
  2273. this.HistoryDataManager = value;
  2274. this.IntraDataManager = value;
  2275. }
  2276. }
  2277. [Description("Default cursor"), DefaultValue((string)null), Category("Stock Chart")]
  2278. public Cursor DefaultCursor
  2279. {
  2280. get
  2281. {
  2282. return this.defaultCursor;
  2283. }
  2284. set
  2285. {
  2286. this.defaultCursor = value;
  2287. }
  2288. }
  2289. [Category("Stock Chart"), DefaultValue("VOLMA;RSI(14)#RSI(28);MACD;SlowSTO")]
  2290. public string DefaultFormulas
  2291. {
  2292. get
  2293. {
  2294. return this.defaultFormulas;
  2295. }
  2296. set
  2297. {
  2298. this.defaultFormulas = value;
  2299. this.needSetDefaultFormulas = true;
  2300. this.NeedRebind();
  2301. }
  2302. }
  2303. [Browsable(false)]
  2304. public Control DesignerControl
  2305. {
  2306. get
  2307. {
  2308. return this;
  2309. }
  2310. }
  2311. [Browsable(false)]
  2312. public bool Designing
  2313. {
  2314. get
  2315. {
  2316. return this.designing;
  2317. }
  2318. set
  2319. {
  2320. this.designing = value;
  2321. }
  2322. }
  2323. [Description("End time of the chart, if leave this field empty, will use StockBars instead"), DefaultValue(typeof(DateTime), "1-1-1"), Category("Stock Chart Time")]
  2324. public DateTime EndTime
  2325. {
  2326. get
  2327. {
  2328. return this.endTime;
  2329. }
  2330. set
  2331. {
  2332. this.endTime = value;
  2333. if (this.fixedTime || ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch))
  2334. {
  2335. this.NeedRebind();
  2336. }
  2337. else
  2338. {
  2339. this.NeedRedraw();
  2340. }
  2341. if (this.memoryCrossCursor)
  2342. {
  2343. this.needDrawCursor = true;
  2344. }
  2345. }
  2346. }
  2347. [Category("Stock Chart"), DefaultValue("MINUTE1;MINUTE5;MINUTE15;MINUTE30;HOUR1;DAY1;WEEK1;MONTH1;YEAR1")]
  2348. public string FavoriteCycles
  2349. {
  2350. get
  2351. {
  2352. return this.favoriteCycles;
  2353. }
  2354. set
  2355. {
  2356. this.favoriteCycles = value;
  2357. this.CreateCycleMenu();
  2358. }
  2359. }
  2360. [Category("Stock Chart")]
  2361. public string FavoriteFormulas
  2362. {
  2363. get
  2364. {
  2365. return string.Join(";", (string[])this.favoriteFormulas.ToArray(typeof(string)));
  2366. }
  2367. set
  2368. {
  2369. if ((value != null) && (value != ""))
  2370. {
  2371. this.favoriteFormulas.Clear();
  2372. this.favoriteFormulas.AddRange(value.Split(new char[] { ';' }));
  2373. this.BuildFavoriteMenu();
  2374. }
  2375. }
  2376. }
  2377. [DefaultValue(false), Category("Stock Chart"), Description("Fixed time frame between StartTime and EndTime, used for intraday chart")]
  2378. public bool FixedTime
  2379. {
  2380. get
  2381. {
  2382. return this.fixedTime;
  2383. }
  2384. set
  2385. {
  2386. this.fixedTime = value;
  2387. this.NeedRebind();
  2388. }
  2389. }
  2390. [Category("Stock Chart Mouse Zoom"), Description("Rectangle for fixed zoom box. Empty box will draw the zoom box by hand. Center fixed zoom box (-150,-150,300,300), TopLeft fixed zoom box (0,0,300,300)"), DefaultValue(typeof(Rectangle), "0, 0, 0, 0")]
  2391. public Rectangle FixedZoomRect
  2392. {
  2393. get
  2394. {
  2395. return this.fixedZoomRect;
  2396. }
  2397. set
  2398. {
  2399. this.fixedZoomRect = value;
  2400. }
  2401. }
  2402. [DefaultValue((string)null), Browsable(false)]
  2403. public DataManagerBase HistoryDataManager
  2404. {
  2405. get
  2406. {
  2407. return this.historyDataManager;
  2408. }
  2409. set
  2410. {
  2411. if (value != this.historyDataManager)
  2412. {
  2413. this.historyDataManager = value;
  2414. this.NeedRebind();
  2415. }
  2416. }
  2417. }
  2418. [Browsable(false), DefaultValue((string)null)]
  2419. public DataManagerBase IntraDataManager
  2420. {
  2421. get
  2422. {
  2423. return this.intraDataManager;
  2424. }
  2425. set
  2426. {
  2427. if (value != this.intraDataManager)
  2428. {
  2429. this.intraDataManager = value;
  2430. this.NeedRebind();
  2431. }
  2432. }
  2433. }
  2434. [Description("Intraday exchange informations"), Browsable(false)]
  2435. public ExchangeIntraday IntradayInfo
  2436. {
  2437. get
  2438. {
  2439. return this.intradayInfo;
  2440. }
  2441. set
  2442. {
  2443. this.intradayInfo = value;
  2444. this.NeedRebind();
  2445. }
  2446. }
  2447. [Browsable(false)]
  2448. public bool IsDragging
  2449. {
  2450. get
  2451. {
  2452. return (this.DragInfo != null);
  2453. }
  2454. }
  2455. [Category("Stock Chart"), DefaultValue(2), Description("How to show the latest value in the axis-Y")]
  2456. public IndexFormula.Finance.LatestValueType LatestValueType
  2457. {
  2458. get
  2459. {
  2460. return this.latestValueType;
  2461. }
  2462. set
  2463. {
  2464. this.latestValueType = value;
  2465. this.NeedRedraw();
  2466. }
  2467. }
  2468. [DefaultValue((double)500.0), Category("Stock Chart")]
  2469. public double MaxColumnWidth
  2470. {
  2471. get
  2472. {
  2473. return this.maxColumnWidth;
  2474. }
  2475. set
  2476. {
  2477. this.maxColumnWidth = value;
  2478. }
  2479. }
  2480. [Browsable(false)]
  2481. public double MaxPrice
  2482. {
  2483. get
  2484. {
  2485. return this.maxPrice;
  2486. }
  2487. set
  2488. {
  2489. this.maxPrice = value;
  2490. }
  2491. }
  2492. [DefaultValue(false), Description("Draw cross cursor in memory , this will prevent flicker"), Category("Stock Chart")]
  2493. public bool MemoryCrossCursor
  2494. {
  2495. get
  2496. {
  2497. return this.memoryCrossCursor;
  2498. }
  2499. set
  2500. {
  2501. this.memoryCrossCursor = value;
  2502. }
  2503. }
  2504. [Category("Stock Chart"), DefaultValue((double)0.01)]
  2505. public double MinColumnWidth
  2506. {
  2507. get
  2508. {
  2509. return this.minColumnWidth;
  2510. }
  2511. set
  2512. {
  2513. this.minColumnWidth = value;
  2514. }
  2515. }
  2516. [Browsable(false)]
  2517. public double MinPrice
  2518. {
  2519. get
  2520. {
  2521. return this.minPrice;
  2522. }
  2523. set
  2524. {
  2525. this.minPrice = value;
  2526. }
  2527. }
  2528. [Description("Use mouse wheel to scroll or zoom the chart"), DefaultValue(1), Category("Stock Chart")]
  2529. public IndexFormula.Finance.Win.MouseWheelMode MouseWheelMode
  2530. {
  2531. get
  2532. {
  2533. return this.mouseWheelMode;
  2534. }
  2535. set
  2536. {
  2537. this.mouseWheelMode = value;
  2538. }
  2539. }
  2540. [DefaultValue(typeof(Color), "32, 0, 128, 0"), Description("The background color of the mouse zoom"), Category("Stock Chart Mouse Zoom")]
  2541. public Color MouseZoomBackColor
  2542. {
  2543. get
  2544. {
  2545. return this.mouseZoomBackColor;
  2546. }
  2547. set
  2548. {
  2549. this.mouseZoomBackColor = value;
  2550. }
  2551. }
  2552. [Description("Use mouse to zoom the chart"), DefaultValue(1), Category("Stock Chart Mouse Zoom")]
  2553. public IndexFormula.Finance.Win.MouseZoomMode MouseZoomMode
  2554. {
  2555. get
  2556. {
  2557. return this.mouseZoomMode;
  2558. }
  2559. set
  2560. {
  2561. this.mouseZoomMode = value;
  2562. }
  2563. }
  2564. [Description("Use native context menu"), Category("Stock Chart"), DefaultValue(true)]
  2565. public bool NativeContextMenu
  2566. {
  2567. get
  2568. {
  2569. return this.nativeContextMenu;
  2570. }
  2571. set
  2572. {
  2573. this.nativeContextMenu = value;
  2574. }
  2575. }
  2576. [Description("If you specify this, will add these text in the price area,Sample format:Prev Close:{LC}O:{OPEN}H:{HIGH}L:{LOW}C:{CLOSE}V:{VOLUME}Chg:{Change} {D:yyyy-MM-dd}"), Category("Stock Chart")]
  2577. public string PriceLabelFormat
  2578. {
  2579. get
  2580. {
  2581. return this.chart.PriceLabelFormat;
  2582. }
  2583. set
  2584. {
  2585. this.chart.PriceLabelFormat = value;
  2586. }
  2587. }
  2588. [Category("Stock Chart"), DefaultValue(true), Description("Reset Y-axis to auto scale when X-axis changed.")]
  2589. public bool ResetYAfterXChanged
  2590. {
  2591. get
  2592. {
  2593. return this.resetYAfterXChanged;
  2594. }
  2595. set
  2596. {
  2597. this.resetYAfterXChanged = value;
  2598. }
  2599. }
  2600. [DefaultValue(3), Category("Stock Chart"), Description("Get or set the scale type of main stock area")]
  2601. public IndexFormula.Finance.ScaleType ScaleType
  2602. {
  2603. get
  2604. {
  2605. return this.scaleType;
  2606. }
  2607. set
  2608. {
  2609. this.scaleType = value;
  2610. this.NeedRedraw();
  2611. }
  2612. }
  2613. [DefaultValue(2), Description("How to select a formula through mouse"), Category("Stock Chart")]
  2614. public MouseAction SelectFormulaMouseMode
  2615. {
  2616. get
  2617. {
  2618. return this.selectFormulaMouseMode;
  2619. }
  2620. set
  2621. {
  2622. this.selectFormulaMouseMode = value;
  2623. }
  2624. }
  2625. [DefaultValue(true), Description("Show cross cursor on the chart"), Category("Stock Chart")]
  2626. public bool ShowCrossCursor
  2627. {
  2628. get
  2629. {
  2630. return this.showCrossCursor;
  2631. }
  2632. set
  2633. {
  2634. this.showCrossCursor = value;
  2635. this.miCrossCursor.Checked = value;
  2636. this.chart.ShowHLine = value;
  2637. this.chart.ShowVLine = value;
  2638. if (!value)
  2639. {
  2640. base.Invalidate();
  2641. }
  2642. }
  2643. }
  2644. [DefaultValue(true), Category("Stock Chart")]
  2645. public bool ShowCursorLabel
  2646. {
  2647. get
  2648. {
  2649. return this.showCursorLabel;
  2650. }
  2651. set
  2652. {
  2653. this.showCursorLabel = value;
  2654. this.NeedRebind();
  2655. }
  2656. }
  2657. [Category("Stock Chart"), Description("How to show the horizontal grid line"), DefaultValue(0)]
  2658. public ShowLineMode ShowHorizontalGrid
  2659. {
  2660. get
  2661. {
  2662. return this.showHorizontalGrid;
  2663. }
  2664. set
  2665. {
  2666. this.showHorizontalGrid = value;
  2667. this.NeedRedraw();
  2668. }
  2669. }
  2670. [DefaultValue(true), Category("Stock Chart"), Description("Show indicator values in the statistic window")]
  2671. public bool ShowIndicatorValues
  2672. {
  2673. get
  2674. {
  2675. return this.showIndicatorValues;
  2676. }
  2677. set
  2678. {
  2679. this.showIndicatorValues = value;
  2680. }
  2681. }
  2682. [DefaultValue(true), Description("Show overlay values in the statistic window"), Category("Stock Chart")]
  2683. public bool ShowOverlayValues
  2684. {
  2685. get
  2686. {
  2687. return this.showOverlayValues;
  2688. }
  2689. set
  2690. {
  2691. this.showOverlayValues = value;
  2692. }
  2693. }
  2694. [Category("Stock Chart"), DefaultValue(true), Description("Show statistic windows on the chart")]
  2695. public bool ShowStatistic
  2696. {
  2697. get
  2698. {
  2699. return this.showStatistic;
  2700. }
  2701. set
  2702. {
  2703. bool flag = (this.showStatistic != value) && (this.ShowStatisticChanged != null);
  2704. this.showStatistic = value;
  2705. if (flag)
  2706. {
  2707. this.ShowStatisticChanged(this, new EventArgs());
  2708. }
  2709. }
  2710. }
  2711. [Description("Draw a line on top of the chart control"), Category("Stock Chart"), DefaultValue(true)]
  2712. public bool ShowTopLine
  2713. {
  2714. get
  2715. {
  2716. return this.showTopLine;
  2717. }
  2718. set
  2719. {
  2720. this.showTopLine = value;
  2721. }
  2722. }
  2723. [Description("How to show the vertical grid line"), DefaultValue(0), Category("Stock Chart")]
  2724. public ShowLineMode ShowVerticalGrid
  2725. {
  2726. get
  2727. {
  2728. return this.showVerticalGrid;
  2729. }
  2730. set
  2731. {
  2732. this.showVerticalGrid = value;
  2733. this.NeedRedraw();
  2734. }
  2735. }
  2736. [TypeConverter(typeof(SkinConverter)), Category("Stock Chart"), DefaultValue("RedWhite")]
  2737. public string Skin
  2738. {
  2739. get
  2740. {
  2741. return this.skin;
  2742. }
  2743. set
  2744. {
  2745. this.skin = value;
  2746. this.NeedRebind();
  2747. }
  2748. }
  2749. [Browsable(false), DefaultValue(0), Category("Stock Chart Time")]
  2750. public int StartBar
  2751. {
  2752. get
  2753. {
  2754. return this.chart.Start;
  2755. }
  2756. set
  2757. {
  2758. if (value < 0)
  2759. {
  2760. value = 0;
  2761. }
  2762. this.chart.Start = value;
  2763. if (!this.chart.FixedTime)
  2764. {
  2765. this.chart.StartTime = DateTime.MinValue;
  2766. this.chart.EndTime = DateTime.MaxValue;
  2767. }
  2768. this.NeedRedraw();
  2769. }
  2770. }
  2771. [Category("Stock Chart Time"), Description("Start time of the chart"), DefaultValue(typeof(DateTime), "1-1-1")]
  2772. public DateTime StartTime
  2773. {
  2774. get
  2775. {
  2776. return this.startTime;
  2777. }
  2778. set
  2779. {
  2780. this.startTime = value;
  2781. if (this.fixedTime || ((this.CurrentDataManager != null) && this.CurrentDataManager.VirtualFetch))
  2782. {
  2783. this.NeedRebind();
  2784. }
  2785. else
  2786. {
  2787. this.NeedRedraw();
  2788. }
  2789. if (this.memoryCrossCursor)
  2790. {
  2791. this.needDrawCursor = true;
  2792. }
  2793. }
  2794. }
  2795. [DefaultValue(4), Description("Stick render type is used for Volumn Stick,Color Stick and Stick Line"), Category("Stock Chart")]
  2796. public IndexFormula.Finance.StickRenderType StickRenderType
  2797. {
  2798. get
  2799. {
  2800. return this.stickRenderType;
  2801. }
  2802. set
  2803. {
  2804. this.stickRenderType = value;
  2805. this.NeedRebind();
  2806. }
  2807. }
  2808. [Category("Stock Chart Time"), Description("This will take effect when EndTime is empty."), DefaultValue(150)]
  2809. public int StockBars
  2810. {
  2811. get
  2812. {
  2813. return this.stockBars;
  2814. }
  2815. set
  2816. {
  2817. if (value < 1)
  2818. {
  2819. value = 1;
  2820. }
  2821. this.stockBars = value;
  2822. this.NeedRedraw();
  2823. this.EndTime = DateTime.MinValue;
  2824. }
  2825. }
  2826. [Description("Stock chart render type"), Category("Stock Chart"), DefaultValue(4)]
  2827. public IndexFormula.Finance.StockRenderType StockRenderType
  2828. {
  2829. get
  2830. {
  2831. return this.stockRenderType;
  2832. }
  2833. set
  2834. {
  2835. this.stockRenderType = value;
  2836. this.NeedRebind();
  2837. }
  2838. }
  2839. [DefaultValue("MSFT"), Description("Stock Symbol"), Category("Stock Chart")]
  2840. public string Symbol
  2841. {
  2842. get
  2843. {
  2844. return this.symbol;
  2845. }
  2846. set
  2847. {
  2848. if (value != this.symbol)
  2849. {
  2850. this.symbol = value;
  2851. this.NeedRebind();
  2852. }
  2853. }
  2854. }
  2855. [Description("How to draw the value text"), DefaultValue(4), Category("Stock Chart")]
  2856. public IndexFormula.Finance.ValueTextMode ValueTextMode
  2857. {
  2858. get
  2859. {
  2860. return this.valueTextMode;
  2861. }
  2862. set
  2863. {
  2864. this.valueTextMode = value;
  2865. this.NeedRebind();
  2866. }
  2867. }
  2868. [Category("Stock Chart Mouse Zoom"), DefaultValue(0), Description("Position of the zoom center")]
  2869. public ZoomCenterPosition ZoomPosition
  2870. {
  2871. get
  2872. {
  2873. return this.zoomPosition;
  2874. }
  2875. set
  2876. {
  2877. this.zoomPosition = value;
  2878. }
  2879. }
  2880. }
  2881. }