home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 October / Chip_2001-10_cd1.bin / zkuste / delphi / kompon / d123456 / CHEMPLOT.ZIP / TPlot / Plotmenu.pas < prev    next >
Pascal/Delphi Source File  |  2001-07-05  |  22KB  |  648 lines

  1. unit Plotmenu;
  2.  
  3. {$I Plot.inc}
  4.  
  5. {-----------------------------------------------------------------------------
  6. The contents of this file are subject to the Q Public License
  7. ("QPL"); you may not use this file except in compliance
  8. with the QPL. You may obtain a copy of the QPL from 
  9. the file QPL.html in this distribution, derived from:
  10.  
  11. http://www.trolltech.com/products/download/freelicense/license.html
  12.  
  13. The QPL prohibits development of proprietary software. 
  14. There is a Professional Version of this software available for this. 
  15. Contact sales@chemware.hypermart.net for more information.
  16.  
  17. Software distributed under the QPL is distributed on an "AS IS" basis,
  18. WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the QPL for
  19. the specific language governing rights and limitations under the QPL.
  20.  
  21. The Original Code is: Axis.pas, released 12 September 2000.
  22.  
  23. The Initial Developer of the Original Code is Mat Ballard.
  24. Portions created by Mat Ballard are Copyright (C) 1999 Mat Ballard.
  25. Portions created by Microsoft are Copyright (C) 1998, 1999 Microsoft Corp.
  26. All Rights Reserved.
  27.  
  28. Contributor(s): Mat Ballard                 e-mail: mat.ballard@chemware.hypermart.net.
  29.  
  30. Last Modified: 02/25/2000
  31. Current Version: 2.00
  32.  
  33. You may retrieve the latest version of this file from:
  34.  
  35.         http://Chemware.hypermart.net/
  36.  
  37. This work was created with the Project JEDI VCL guidelines:
  38.  
  39.         http://www.delphi-jedi.org/Jedi:VCLVCL
  40.  
  41. in mind. 
  42.  
  43. Purpose:
  44. The purpose of this module is to provide the developer using TPlot a quick
  45. method of rapidly implementing menu access to the TPlot functions.
  46.  
  47. It will be augmented by a TPlotAction module at a later stage.
  48.  
  49. Known Issues:
  50.     - Since TPlotMenu is useless without TPlot, there is only the one
  51.       registration unit: TPlot_Reg.pas.
  52.     - Is INVISIBLE in D1 Runtime - works perfectly in the designer, but
  53.       no menu is present in running applications. If anyone wants to help fix
  54.       this, please do so and let me know the answer.
  55. -----------------------------------------------------------------------------}
  56.  
  57. interface
  58.  
  59. uses
  60.   Classes, SysUtils,
  61. {$IFDEF WINDOWS}
  62.   Menus,
  63. {$ENDIF}
  64. {$IFDEF WIN32}
  65.   Menus,
  66. {$ENDIF}
  67. {$IFDEF LINUX}
  68.   QMenus,
  69. {$ENDIF}
  70.  
  71.   Misc, Plot, Plotdefs;
  72.  
  73. const
  74.   TPLOTMENU_VERSION = 200;
  75.  
  76.   FILE_TAG = 1000;
  77.   HELP_TAG = 1095;
  78.   ABOUT_TAG = 1096;
  79.   REOPEN_TAG = 1097;
  80.   EXIT_DIV_TAG = 1098;
  81.   EXIT_TAG = 1099;
  82.  
  83.   mnuReopen = 2;
  84.  
  85. type
  86.   TPlotMenu = class(TMainMenu)
  87.   private
  88. {The plot to which this menu is linked:}
  89.     FPlot: TPlot;
  90. {and the limit of the number of those files:}
  91.     FHistoryLimit: Byte;
  92. {Creates the menus after the Plot property is set:}
  93.     procedure CreateMenus;
  94. {Creates the Reopen menu item and Submenu and adds it to the File menu:}
  95.     procedure CreateReopenSubMenu;
  96. {Gets the History List as a string:}
  97.     function GetHistory: String;
  98.   protected
  99.     {function GetPlot(Target: TObject): TPlot; virtual;}
  100.     procedure HandleClick(Sender: TObject);
  101. {The default event handler for all menu items. It forwards the event to TPlot
  102.  by calling the latter's HandleClick method, which then passes it onto the
  103.  appropriate handler method.}
  104.  
  105. {$IFNDEF DELPHI1}
  106.     procedure HandleClunk(Sender: TObject);
  107. {Called when the menu is clicked on, it sets the Enabled property of all menuitems.}
  108. {$ENDIF}
  109.  
  110.     procedure HandleFileClick(Sender: TObject);
  111. {Called when the a Reopen File menuitem is clicked on.}
  112.     procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  113. {Implementation of the standard Notification method for linked components.}
  114.     procedure SetPlot(Value: TPlot);
  115. {Sets the pointer to the parental TPlot, creates the menus and their OnClicks}    
  116.   public
  117.     property History: String read GetHistory stored FALSE;
  118. {A History List, CRLF delimited, of previously closed files.
  119.  Just use it as:
  120.    MyStringList.Create;
  121.    MyStringList.Text := PlotMenu1.History;}
  122.  
  123.     constructor Create(AOwner: TComponent); override;
  124. {The standard constructor.}
  125.     destructor Destroy; override;
  126. {The standard destructor.}
  127.  
  128.     procedure ApplyOptions(Value: TPopupOptions);
  129.  
  130.     procedure AddHistory(Value: String);
  131. {Adds one more file to the History List.}
  132.     function MenuExists(ATag: Integer; ACaption: String): Boolean;
  133. {Does AMenu already exist in Self ?}
  134. {}
  135. {The basis for comparison is both the Tag and Caption}
  136.     procedure SetUpOnClicks;
  137. {This assigns the HandleClick and HandleClunk methods to all menu items with
  138.  relevant Tags and that are already unassigned.}
  139.   published
  140.     property HistoryLimit: Byte read FHistoryLimit write FHistoryLimit;
  141. {The limit of the number of files in the History List.}
  142.     property Plot: TPlot read FPlot write SetPlot;
  143. {The plot to which TPlotMenu is linked.}
  144.   end;
  145.  
  146. implementation
  147.  
  148. {Constructor and Destructor ---------------------------------------------------}
  149. {------------------------------------------------------------------------------
  150.   Constructor: TPlotMenu.Create
  151.   Description: standard Constructor
  152.        Author: Mat Ballard
  153.  Date created: 04/25/2000
  154. Date modified: 04/25/2000 by Mat Ballard
  155.       Purpose: sets the Plot Property
  156.  Known Issues:
  157.  ------------------------------------------------------------------------------}
  158. constructor TPlotMenu.Create(AOwner: TComponent);
  159. begin
  160.   inherited Create(AOwner);
  161.   FPlot := nil;
  162.   FHistoryLimit := 10;
  163. end;
  164.  
  165. {------------------------------------------------------------------------------
  166.    Destructor: TPlotMenu.Destroy
  167.   Description: standard Destructor
  168.        Author: Mat Ballard
  169.  Date created: 04/25/2000
  170. Date modified: 04/25/2000 by Mat Ballard
  171.       Purpose: frees the Plot Property
  172.  Known Issues:
  173.  ------------------------------------------------------------------------------}
  174. destructor TPlotMenu.Destroy;
  175. begin
  176.   if FPlot <> nil then
  177. {$IFDEF DELPHI1}
  178.     FPlot.Notification(Self, opRemove);
  179. {$ELSE}
  180.     FPlot.FreeNotification(Self);
  181. {$ENDIF}
  182.   FPlot := nil;
  183.   inherited Destroy;
  184. end;
  185.  
  186. {Get functions and Set procedures ---------------------------------------------}
  187. {------------------------------------------------------------------------------
  188.     Procedure: TPlotMenu.AddHistory
  189.   Description: Adds one more file to the History List
  190.        Author: Mat Ballard
  191.  Date created: 09/01/2000
  192. Date modified: 09/01/2000 by Mat Ballard
  193.       Purpose: History List management
  194.  Known Issues:
  195.  ------------------------------------------------------------------------------}
  196. procedure TPlotMenu.AddHistory(Value: String);
  197. var
  198.   i: Integer;
  199.   pReopen: TMenuItem;
  200.   TempMenuItem: TMenuItem;
  201. begin
  202.   if (csDestroying in ComponentState) then exit;
  203.   if (Length(Value) = 0) then exit;
  204.  
  205.   pReopen := Self.Items[0].Items[mnuReopen];
  206.   if (pReopen = nil) then
  207.     exit;
  208.  
  209. {$IFNDEF DELPHI1}
  210.   for i := 0 to pReopen.Count-1 do
  211.   begin
  212.     if (pReopen.Items[i].Hint = Value) then
  213.     begin
  214. {Change the order of existing entries:}
  215.       pReopen.Items[i].MenuIndex := 0;
  216.       exit;
  217.     end;
  218.   end;
  219. {$ENDIF}
  220.  
  221.   TempMenuItem := TMenuItem.Create(Self);
  222. {Note: we store the full pathname in the Hint because D5 mangles the Caption:
  223.  the AutoHotKeys property does not work ! Also looks neater !}
  224.   TempMenuItem.Caption := ExtractFileName(Value);
  225.   TempMenuItem.Hint := Value;
  226.   TempMenuItem.OnClick := HandleFileClick;
  227.   pReopen.Insert(0, TempMenuItem);
  228.  
  229.   while (pReopen.Count > FHistoryLimit) do
  230.     pReopen.Delete(pReopen.Count-1);
  231.  
  232.   pReopen.Enabled := TRUE;
  233. end;
  234.  
  235. {------------------------------------------------------------------------------
  236.     Procedure: TPlotMenu.GetHistory
  237.   Description: Gets the History List as a string.
  238.        Author: Mat Ballard
  239.  Date created: 08/13/2000
  240. Date modified: 08/13/2000 by Mat Ballard
  241.       Purpose: History List management
  242.  Known Issues:
  243.  ------------------------------------------------------------------------------}
  244. function TPlotMenu.GetHistory: String;
  245. var
  246.   i: Integer;
  247.   TheString: String;
  248.   pReopen: TMenuItem;
  249. begin
  250.   TheString := '';
  251.   pReopen := Self.Items[0].Items[mnuReopen];
  252.  
  253.   for i := 0 to pReopen.Count-1 do
  254.     TheString := TheString + pReopen.Items[i].Caption;
  255.  
  256.   GetHistory := TheString;
  257. end;
  258.  
  259. {------------------------------------------------------------------------------
  260.     Procedure: TPlotMenu.SetPlot
  261.   Description: standard property Set procedure
  262.        Author: Mat Ballard
  263.  Date created: 04/25/2000
  264. Date modified: 04/25/2000 by Mat Ballard
  265.       Purpose: sets the Plot Property
  266.  Known Issues:
  267.  ------------------------------------------------------------------------------}
  268. procedure TPlotMenu.SetPlot(Value: TPlot);
  269. begin
  270.   if Value <> FPlot then
  271.   begin
  272.     if (Value = nil) then
  273.     begin
  274.       FPlot := Value;
  275.       FPlot.SetPlotMenu(TMainMenu(nil));
  276.     end
  277.     else
  278.     begin
  279.       FPlot := Value;
  280. {$IFDEF DELPHI1}
  281.       Value.Notification(Self, opInsert); {???}
  282. {$ELSE}
  283.       Value.FreeNotification(Self);
  284. {$ENDIF}
  285.       CreateMenus;
  286.       SetUpOnClicks;
  287.       CreateReopenSubMenu;
  288.       FPlot.SetPlotMenu(TMainMenu(Self));
  289.     end;
  290.   end;
  291. end;
  292.  
  293. {General methods --------------------------------------------------------------}
  294. {------------------------------------------------------------------------------
  295.     Procedure: TCustomPlot.CreateMenus
  296.   Description: creates popup menus that are accessible by right-click
  297.        Author: Mat Ballard
  298.  Date created: 12/1/1999
  299. Date modified: 04/20/2000 by Mat Ballard
  300.       Purpose: modularize user-interface code
  301.  Known Issues: this was a bitch to get right !
  302.  ------------------------------------------------------------------------------}
  303. procedure TPlotMenu.CreateMenus;
  304. var
  305.   i,
  306.   j,
  307.   HelpMenuIndex: Word;
  308. {This following is just a dummy matrix of menu items used to create sub-menus,
  309.  then removed and the menuitems freed.}
  310.   TempMenu: array [0..31] of array [0..0] of TMenuItem;
  311.   TempMenuItem: TMenuItem;
  312. begin
  313. {don't create menus when the Plot property is streamed in:}
  314.   if (csLoading in ComponentState) then exit;
  315.  
  316. {who needs more than 32 menus ?!}
  317.   if (FPlot.PlotPopupMenu.Items.Count > 32) then raise
  318.     EComponentError.CreateFmt(sCreateMenus1, [FPlot.PlotPopupMenu.Items.Count]);
  319.  
  320. {create the sub-menus:}
  321.   for i := 0 to FPlot.PlotPopupMenu.Items.Count-1 do
  322.   begin
  323. {we create a temporary menu array to add the submenu, and then later remove it:}
  324.     TempMenu[i][0] := TMenuItem.Create(Self);
  325. {don't re-create a menu if it already exists:}
  326.     if (not MenuExists(
  327.       FPlot.PlotPopupMenu.Items[i].Tag,
  328.       FPlot.PlotPopupMenu.Items[i].Caption)) then
  329.     begin
  330.       TempMenuItem := NewSubMenu(
  331.         FPlot.PlotPopupMenu.Items[i].Caption,
  332.         0,
  333.         FPlot.PlotPopupMenu.Items[i].Name,
  334.         TempMenu[i]);
  335.       TempMenuItem.Tag := FPlot.PlotPopupMenu.Items[i].Tag;
  336.       Self.Items.Add(TempMenuItem);
  337.     end;
  338. {create the menus in each sub-menu:}
  339.     for j := 0 to FPlot.PlotPopupMenu.Items[i].Count-1 do
  340.     begin
  341.       if (not MenuExists(
  342.         FPlot.PlotPopupMenu.Items[i].Items[j].Tag,
  343.         FPlot.PlotPopupMenu.Items[i].Items[j].Caption)) then
  344.       begin
  345.         TempMenuItem := TMenuItem.Create(Self);
  346.         TempMenuItem.Caption := FPlot.PlotPopupMenu.Items[i].Items[j].Caption;
  347.         TempMenuItem.Name := FPlot.PlotPopupMenu.Items[i].Items[j].Name;
  348.         TempMenuItem.Tag := FPlot.PlotPopupMenu.Items[i].Items[j].Tag;
  349.         TempMenuItem.Hint := FPlot.PlotPopupMenu.Items[i].Items[j].Hint;
  350. {$IFDEF COMPILER4_UP}
  351.         TempMenuItem.ImageIndex := FPlot.PlotPopupMenu.Items[i].Items[j].ImageIndex;
  352. {$ENDIF}
  353. {add the TempMenuItem to the popup:}
  354.         Self.Items[i].Add(TempMenuItem);
  355.       end;
  356.     end; {j over menu items}
  357. {remove the temporary menu array used to create the submenu:}
  358.     if (Self.Items[i].Items[0].Caption = '') then
  359.     begin
  360.       Self.Items[i].Remove(TempMenu[i][0]);
  361. {then free it:}
  362.       TempMenu[i][0].Free;
  363.     end;
  364.   end; {i over submenus}
  365.  
  366. {don't re-create a menu if it already exists:}
  367.   if (Self.Items.Count = FPlot.PlotPopupMenu.Items.Count) then
  368.   begin
  369.     HelpMenuIndex := FPlot.PlotPopupMenu.Items.Count;
  370. {we now add a "Help" menu:}
  371. {first, we create a temporary menu array to add the submenu, and then later remove it:}
  372.     TempMenu[HelpMenuIndex][0] := TMenuItem.Create(Self);
  373.     TempMenuItem := NewSubMenu(
  374.       sHelp,
  375.       0,
  376.       'HelpMenu',
  377.       TempMenu[HelpMenuIndex]);
  378.     TempMenuItem.Tag := HELP_TAG;
  379.     Self.Items.Add(TempMenuItem);
  380. {create the "About" menu item:}
  381.     TempMenuItem := TMenuItem.Create(Self);
  382.     TempMenuItem.Caption := '&' + sAbout + '...';
  383.     TempMenuItem.Name := 'AboutMenu';
  384.     TempMenuItem.Tag := ABOUT_TAG;
  385.     TempMenuItem.Hint := sAuthor;
  386. {add the TempMenuItem to the popup:}
  387.     Self.Items[HelpMenuIndex].Add(TempMenuItem);
  388.  
  389. {remove the temporary menu array used to create the submenu:}
  390.     if (Self.Items[HelpMenuIndex].Items[0].Caption = '') then
  391.     begin
  392.       Self.Items[HelpMenuIndex].Remove(TempMenu[HelpMenuIndex][0]);
  393. {then free it:}
  394.       TempMenu[HelpMenuIndex][0].Free;
  395.     end;
  396.   end;
  397.  
  398. {Add a divider to the File menu:}
  399.   if (not MenuExists(EXIT_DIV_TAG, '-')) then
  400.   begin
  401.     TempMenuItem := TMenuItem.Create(Self);
  402.     TempMenuItem.Caption := '-';
  403.     TempMenuItem.Tag := EXIT_DIV_TAG;
  404.     Self.Items[0].Add(TempMenuItem);
  405.   end;
  406.  
  407. {Add an "Exit" to the File menu:}
  408.   if (not MenuExists(EXIT_TAG, 'E&xit')) then
  409.   begin
  410.     TempMenuItem := TMenuItem.Create(Self);
  411.     TempMenuItem.Caption := sExit;
  412.     TempMenuItem.Tag := EXIT_TAG;
  413.     TempMenuItem.Name := 'ExitMenuItem';
  414.     Self.Items[0].Add(TempMenuItem);
  415.   end;
  416. end;
  417.  
  418. {------------------------------------------------------------------------------
  419.     Procedure: TCustomPlot.CreateReopenSubMenu
  420.   Description: creates popup menus that are accessible by right-click
  421.        Author: Mat Ballard
  422.  Date created: 12/1/1999
  423. Date modified: 04/20/2000 by Mat Ballard
  424.       Purpose: modularize user-interface code
  425.  Known Issues: this was a bitch to get right !
  426.  ------------------------------------------------------------------------------}
  427. procedure TPlotMenu.CreateReopenSubMenu;
  428. var
  429. {This following is just a dummy matrix of menu items used to create sub-menus,
  430.  then removed and the menuitems freed.}
  431.   TempMenu: array [0..0] of TMenuItem;
  432.   TempMenuItem: TMenuItem;
  433. begin
  434. {don't create menus when the Plot property is streamed in:}
  435.   if (csLoading in ComponentState) then exit;
  436.  
  437. {don't re-create a menu if it already exists:}
  438.   if ((Self.Items[0].Items[mnuReopen].Tag = REOPEN_TAG) and
  439.       (Self.Items[0].Items[mnuReopen].Caption = sReopen)) then
  440.     exit;
  441.  
  442. {we create a temporary menu array to add the submenu, and then later remove it:}
  443.   TempMenu[0] := TMenuItem.Create(Self);
  444.   TempMenu[0].Visible := FALSE;
  445.   TempMenuItem := NewSubMenu(
  446.     sReopen,
  447.     0,
  448.     'ReopenSubMenu',
  449.     TempMenu);
  450.  
  451.   TempMenuItem.Tag := REOPEN_TAG;
  452. {disable the "Reopen" menu because it has no entries:}
  453. {$IFNDEF SHOWALLMENUS}
  454.   TempMenuItem.Enabled := FALSE;
  455. {$ENDIF}
  456.  
  457.   Self.Items[0].Insert(mnuReopen, TempMenuItem);
  458. {remove the temporary menu array used to create the submenu:}
  459.   Self.Items[0].Items[mnuReopen].Remove(TempMenu[0]);
  460. {then free it:}
  461.   TempMenu[0].Free;
  462. end;
  463.  
  464. {------------------------------------------------------------------------------
  465.     Procedure: TPlotMenu.SetUpOnClicks
  466.   Description: points all appropriate OnClick event handlers at the TPlot.HandleClick method
  467.        Author: Mat Ballard
  468.  Date created: 04/25/2000
  469. Date modified: 04/25/2000 by Mat Ballard
  470.       Purpose: responding to user menu clicks
  471.  Known Issues: have to call this manually (after setting Plot property)
  472.  ------------------------------------------------------------------------------}
  473. procedure TPlotMenu.SetUpOnClicks;
  474. var
  475.   i,
  476.   j: Integer;
  477. begin
  478.   for i := 0 to Self.Items.Count-1 do
  479.   begin
  480. {don't change any existing assignments:}
  481. {$IFNDEF DELPHI1}
  482.     if ((Self.Items[i].Tag >= FILE_TAG) and
  483.         (Self.Items[i].Tag < EXIT_TAG)) then
  484.       if (not Assigned(Self.Items[i].OnClick)) then
  485.         Self.Items[i].OnClick := HandleClunk;
  486. {$ENDIF}
  487.  
  488.     for j := 0 to Self.Items[i].Count-1 do
  489.     begin
  490. {gotta have a valid tag:}
  491.       if ((Self.Items[i].Items[j].Tag >= FILE_TAG) and
  492.           (Self.Items[i].Items[j].Tag < EXIT_TAG)) then
  493.       begin
  494. {separators don't have OnClicks}
  495.         if (Self.Items[i].Items[j].Caption <> '-') then
  496. {don't change any existing assignments:}
  497. {$IFDEF COMPILER2_UP}
  498.           if (not Assigned(Self.Items[i].Items[j].OnClick)) then
  499. {$ENDIF}
  500.             Self.Items[i].Items[j].OnClick := HandleClick;
  501.       end;
  502.     end;
  503.   end;
  504. end;
  505.  
  506. {------------------------------------------------------------------------------
  507.     Procedure: TPlotMenu.HandleClick
  508.   Description: Click Event handler for all menus
  509.        Author: Mat Ballard
  510.  Date created: 04/25/2000
  511. Date modified: 04/25/2000 by Mat Ballard
  512.       Purpose: responds to user clicks of the menus by firing the TPlot method
  513.  Known Issues:
  514.  ------------------------------------------------------------------------------}
  515. procedure TPlotMenu.HandleClick(Sender: TObject);
  516. begin
  517.   if (FPlot = nil) then exit;
  518.   if (TMenuItem(Sender).Tag < HELP_TAG) then
  519.     FPlot.HandleClick(Self, TMenuItem(Sender).Tag)
  520.   else if (TMenuItem(Sender).Tag = ABOUT_TAG) then
  521.     FPlot.ShowAbout;
  522. end;
  523.  
  524. {$IFNDEF DELPHI1}
  525. {------------------------------------------------------------------------------
  526.     Procedure: TPlotMenu.HandleClunk
  527.   Description: Click Event handler for all menus
  528.        Author: Mat Ballard
  529.  Date created: 04/25/2000
  530. Date modified: 04/25/2000 by Mat Ballard
  531.       Purpose: responds to user clicks of the menus by setting the menuitem state (Enabled property)
  532.  Known Issues:
  533.  ------------------------------------------------------------------------------}
  534. procedure TPlotMenu.HandleClunk(Sender: TObject);
  535. begin
  536.   if (FPlot = nil) then exit;
  537.   FPlot.DetermineMenuEnabledness(Self);
  538. end;
  539. {$ENDIF}
  540.  
  541. {------------------------------------------------------------------------------
  542.     Procedure: TPlotMenu.HandleFileClick
  543.   Description: Click Event handler for all Reopen file menus
  544.        Author: Mat Ballard
  545.  Date created: 04/25/2000
  546. Date modified: 04/25/2000 by Mat Ballard
  547.       Purpose: responds to user clicks of the FilaName menus by firing the
  548.                TPlot.Open method
  549.  Known Issues:
  550.  ------------------------------------------------------------------------------}
  551. procedure TPlotMenu.HandleFileClick(Sender: TObject);
  552. begin
  553.   if (FPlot = nil) then exit;
  554.  
  555.   FPlot.OpenFile(TMenuItem(Sender).Hint);
  556. end;
  557.  
  558. {------------------------------------------------------------------------------
  559.     Procedure: TPlotMenu.Notification
  560.   Description: handles changes in Plot property
  561.        Author: Mat Ballard
  562.  Date created: 04/25/2000
  563. Date modified: 04/25/2000 by Mat Ballard
  564.       Purpose: Notifies TPlot that it is no longer loved
  565.  Known Issues:
  566.  ------------------------------------------------------------------------------}
  567. procedure TPlotMenu.Notification(AComponent: TComponent;
  568.   Operation: TOperation);
  569. begin
  570.   inherited Notification(AComponent, Operation);
  571.   if (Operation = opRemove) and (AComponent = Plot) then
  572.   begin
  573.     FPlot := nil;
  574.   end;
  575. end;
  576.  
  577. {------------------------------------------------------------------------------
  578.      Function: TPlotMenu.MenuExists
  579.   Description: Does this menu exist ? Based on Tag and Caption
  580.        Author: Mat Ballard
  581.  Date created: 04/25/2000
  582. Date modified: 04/25/2000 by Mat Ballard
  583.       Purpose: do we need to add a menu item ?
  584.  Return Value: Boolean;
  585.  Known Issues:
  586.  ------------------------------------------------------------------------------}
  587. function TPlotMenu.MenuExists(ATag: Integer; ACaption: String): Boolean;
  588. var
  589.   i,
  590.   j: Integer;
  591. begin
  592.   for i := 0 to Self.Items.Count-1 do
  593.   begin
  594. {the menus:}
  595.     if ((Self.Items[i].Tag = ATag) and
  596.         (Self.Items[i].Caption = ACaption)) then
  597.     begin
  598.       MenuExists := TRUE;
  599.       exit;
  600.     end;
  601.     for j := 0 to Self.Items[i].Count-1 do
  602.     begin
  603. {the submenus:}
  604.       if ((Self.Items[i].Items[j].Tag = ATag) and
  605.           (Self.Items[i].Items[j].Caption = ACaption)) then
  606.       begin
  607.         MenuExists := TRUE;
  608.         exit;
  609.       end;
  610.     end;
  611.   end;
  612.   MenuExists := FALSE;
  613. end;
  614.  
  615. {------------------------------------------------------------------------------
  616.     Procedure: TPlotMenu.ApplyOptions
  617.   Description: handles changes Plot.Options property that control menu visibility
  618.        Author: Mat Ballard
  619.  Date created: 04/25/2000
  620. Date modified: 04/25/2000 by Mat Ballard
  621.       Purpose: UI management
  622.  Known Issues:
  623.  ------------------------------------------------------------------------------}
  624. procedure TPlotMenu.ApplyOptions(Value: TPopupOptions);
  625. var
  626.   i: Integer;
  627. begin
  628.   for i := 0 to Ord(High(TMainMenus)) do
  629.     Self.Items[i].Visible :=
  630.       (TMainMenus(i) in Value.Menu);
  631.   for i := 0 to Ord(High(TFileMenus)) do
  632.     Self.Items[Ord(mnuFile)].Items[i].Visible :=
  633.       (TFileMenus(i) in Value.File_);
  634.   for i := 0 to Ord(High(TEditMenus)) do
  635.     Self.Items[Ord(mnuEdit)].Items[i].Visible :=
  636.       (TEditMenus(i) in Value.Edit);
  637.   for i := 0 to Ord(High(TViewMenus)) do
  638.     Self.Items[Ord(mnuView)].Items[i].Visible :=
  639.       (TViewMenus(i) in Value.View);
  640.   for i := 0 to Ord(High(TCalcMenus)) do
  641.     Self.Items[Ord(mnuCalc)].Items[i].Visible :=
  642.       (TCalcMenus(i) in Value.Calc);
  643. end;
  644.  
  645.  
  646.  
  647. end.
  648.