home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 September / Chip_2001-09_cd1.bin / zkuste / delphi / kolekce / d12345 / CHEMPLOT.ZIP / TPlot / Plotmenu.pas < prev    next >
Pascal/Delphi Source File  |  2001-05-03  |  21KB  |  641 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.   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('TPlotMenu.CreateMenus: I cannot handle more than %d Sub-menus !',
  319.       [FPlot.PlotPopupMenu.Items.Count]);
  320.  
  321. {create the sub-menus:}
  322.   for i := 0 to FPlot.PlotPopupMenu.Items.Count-1 do
  323.   begin
  324. {we create a temporary menu array to add the submenu, and then later remove it:}
  325.     TempMenu[i][0] := TMenuItem.Create(Self);
  326. {don't re-create a menu if it already exists:}
  327.     if (not MenuExists(
  328.       FPlot.PlotPopupMenu.Items[i].Tag,
  329.       FPlot.PlotPopupMenu.Items[i].Caption)) then
  330.     begin
  331.       TempMenuItem := NewSubMenu(
  332.         FPlot.PlotPopupMenu.Items[i].Caption,
  333.         0,
  334.         FPlot.PlotPopupMenu.Items[i].Name,
  335.         TempMenu[i]);
  336.       TempMenuItem.Tag := FPlot.PlotPopupMenu.Items[i].Tag;
  337.       Self.Items.Add(TempMenuItem);
  338.     end;
  339. {create the menus in each sub-menu:}
  340.     for j := 0 to FPlot.PlotPopupMenu.Items[i].Count-1 do
  341.     begin
  342.       if (not MenuExists(
  343.         FPlot.PlotPopupMenu.Items[i].Items[j].Tag,
  344.         FPlot.PlotPopupMenu.Items[i].Items[j].Caption)) then
  345.       begin
  346.         TempMenuItem := TMenuItem.Create(Self);
  347.         TempMenuItem.Caption := FPlot.PlotPopupMenu.Items[i].Items[j].Caption;
  348.         TempMenuItem.Name := FPlot.PlotPopupMenu.Items[i].Items[j].Name;
  349.         TempMenuItem.Tag := FPlot.PlotPopupMenu.Items[i].Items[j].Tag;
  350.         TempMenuItem.Hint := FPlot.PlotPopupMenu.Items[i].Items[j].Hint;
  351. {$IFDEF COMPILER4_UP}
  352.         TempMenuItem.ImageIndex := FPlot.PlotPopupMenu.Items[i].Items[j].ImageIndex;
  353. {$ENDIF}
  354. {add the TempMenuItem to the popup:}
  355.         Self.Items[i].Add(TempMenuItem);
  356.       end;
  357.     end; {j over menu items}
  358. {remove the temporary menu array used to create the submenu:}
  359.     if (Self.Items[i].Items[0].Caption = '') then
  360.     begin
  361.       Self.Items[i].Remove(TempMenu[i][0]);
  362. {then free it:}
  363.       TempMenu[i][0].Free;
  364.     end;
  365.   end; {i over submenus}
  366.  
  367. {don't re-create a menu if it already exists:}
  368.   if (Self.Items.Count = FPlot.PlotPopupMenu.Items.Count) then
  369.   begin
  370.     HelpMenuIndex := FPlot.PlotPopupMenu.Items.Count;
  371. {we now add a "Help" menu:}
  372. {first, we create a temporary menu array to add the submenu, and then later remove it:}
  373.     TempMenu[HelpMenuIndex][0] := TMenuItem.Create(Self);
  374.     TempMenuItem := NewSubMenu(
  375.       'Help',
  376.       0,
  377.       'HelpMenu',
  378.       TempMenu[HelpMenuIndex]);
  379.     TempMenuItem.Tag := HELP_TAG;
  380.     Self.Items.Add(TempMenuItem);
  381. {create the "About" menu item:}
  382.     TempMenuItem := TMenuItem.Create(Self);
  383.     TempMenuItem.Caption := 'About ...';
  384.     TempMenuItem.Name := 'AboutMenu';
  385.     TempMenuItem.Tag := ABOUT_TAG;
  386.     TempMenuItem.Hint := 'WhoDunnit ?';
  387. {add the TempMenuItem to the popup:}
  388.     Self.Items[HelpMenuIndex].Add(TempMenuItem);
  389.  
  390. {remove the temporary menu array used to create the submenu:}
  391.     if (Self.Items[HelpMenuIndex].Items[0].Caption = '') then
  392.     begin
  393.       Self.Items[HelpMenuIndex].Remove(TempMenu[HelpMenuIndex][0]);
  394. {then free it:}
  395.       TempMenu[HelpMenuIndex][0].Free;
  396.     end;
  397.   end;
  398.  
  399. {Add a divider to the File menu:}
  400.   if (not MenuExists(EXIT_DIV_TAG, '-')) then
  401.   begin
  402.     TempMenuItem := TMenuItem.Create(Self);
  403.     TempMenuItem.Caption := '-';
  404.     TempMenuItem.Tag := EXIT_DIV_TAG;
  405.     Self.Items[0].Add(TempMenuItem);
  406.   end;
  407.  
  408. {Add an "Exit" to the File menu:}
  409.   if (not MenuExists(EXIT_TAG, 'E&xit')) then
  410.   begin
  411.     TempMenuItem := TMenuItem.Create(Self);
  412.     TempMenuItem.Caption := 'E&xit';
  413.     TempMenuItem.Tag := EXIT_TAG;
  414.     TempMenuItem.Name := 'ExitMenuItem';
  415.     Self.Items[0].Add(TempMenuItem);
  416.   end;
  417. end;
  418.  
  419. {------------------------------------------------------------------------------
  420.     Procedure: TCustomPlot.CreateReopenSubMenu
  421.   Description: creates popup menus that are accessible by right-click
  422.        Author: Mat Ballard
  423.  Date created: 12/1/1999
  424. Date modified: 04/20/2000 by Mat Ballard
  425.       Purpose: modularize user-interface code
  426.  Known Issues: this was a bitch to get right !
  427.  ------------------------------------------------------------------------------}
  428. procedure TPlotMenu.CreateReopenSubMenu;
  429. var
  430. {This following is just a dummy matrix of menu items used to create sub-menus,
  431.  then removed and the menuitems freed.}
  432.   TempMenu: array [0..0] of TMenuItem;
  433.   TempMenuItem: TMenuItem;
  434. begin
  435. {don't create menus when the Plot property is streamed in:}
  436.   if (csLoading in ComponentState) then exit;
  437.  
  438. {don't re-create a menu if it already exists:}
  439.   if ((Self.Items[0].Items[mnuReopen].Tag = REOPEN_TAG) and
  440.       (Self.Items[0].Items[mnuReopen].Caption = '&Reopen')) then
  441.     exit;
  442.  
  443. {we create a temporary menu array to add the submenu, and then later remove it:}
  444.   TempMenu[0] := TMenuItem.Create(Self);
  445.   TempMenu[0].Visible := FALSE;
  446.   TempMenuItem := NewSubMenu(
  447.     '&Reopen',
  448.     0,
  449.     'ReopenSubMenu',
  450.     TempMenu);
  451.  
  452.   TempMenuItem.Tag := REOPEN_TAG;
  453. {disable the "Reopen" menu because it has no entries:}
  454. {$IFNDEF SHOWALLMENUS}
  455.   TempMenuItem.Enabled := FALSE;
  456. {$ENDIF}
  457.  
  458.   Self.Items[0].Insert(mnuReopen, TempMenuItem);
  459. {remove the temporary menu array used to create the submenu:}
  460.   Self.Items[0].Items[mnuReopen].Remove(TempMenu[0]);
  461. {then free it:}
  462.   TempMenu[0].Free;
  463. end;
  464.  
  465. {------------------------------------------------------------------------------
  466.     Procedure: TPlotMenu.SetUpOnClicks
  467.   Description: points all appropriate OnClick event handlers at the TPlot.HandleClick method
  468.        Author: Mat Ballard
  469.  Date created: 04/25/2000
  470. Date modified: 04/25/2000 by Mat Ballard
  471.       Purpose: responding to user menu clicks
  472.  Known Issues: have to call this manually (after setting Plot property)
  473.  ------------------------------------------------------------------------------}
  474. procedure TPlotMenu.SetUpOnClicks;
  475. var
  476.   i,
  477.   j: Integer;
  478. begin
  479.   for i := 0 to Self.Items.Count-1 do
  480.   begin
  481. {don't change any existing assignments:}
  482. {$IFNDEF DELPHI1}
  483.     if ((Self.Items[i].Tag >= FILE_TAG) and
  484.         (Self.Items[i].Tag < EXIT_TAG)) then
  485.       if (not Assigned(Self.Items[i].OnClick)) then
  486.         Self.Items[i].OnClick := HandleClunk;
  487. {$ENDIF}
  488.  
  489.     for j := 0 to Self.Items[i].Count-1 do
  490.     begin
  491. {gotta have a valid tag:}
  492.       if ((Self.Items[i].Items[j].Tag >= FILE_TAG) and
  493.           (Self.Items[i].Items[j].Tag < EXIT_TAG)) then
  494.       begin
  495. {separators don't have OnClicks}
  496.         if (Self.Items[i].Items[j].Caption <> '-') then
  497. {don't change any existing assignments:}
  498. {$IFDEF COMPILER2_UP}
  499.           if (not Assigned(Self.Items[i].Items[j].OnClick)) then
  500. {$ENDIF}
  501.             Self.Items[i].Items[j].OnClick := HandleClick;
  502.       end;
  503.     end;
  504.   end;
  505. end;
  506.  
  507. {------------------------------------------------------------------------------
  508.     Procedure: TPlotMenu.HandleClick
  509.   Description: Click Event handler for all menus
  510.        Author: Mat Ballard
  511.  Date created: 04/25/2000
  512. Date modified: 04/25/2000 by Mat Ballard
  513.       Purpose: responds to user clicks of the menus by firing the TPlot method
  514.  Known Issues:
  515.  ------------------------------------------------------------------------------}
  516. procedure TPlotMenu.HandleClick(Sender: TObject);
  517. begin
  518.   if (FPlot = nil) then exit;
  519.   if (TMenuItem(Sender).Tag < HELP_TAG) then
  520.     FPlot.HandleClick(Self, TMenuItem(Sender).Tag)
  521.   else if (TMenuItem(Sender).Tag = ABOUT_TAG) then
  522.     FPlot.ShowAbout;
  523. end;
  524.  
  525. {$IFNDEF DELPHI1}
  526. {------------------------------------------------------------------------------
  527.     Procedure: TPlotMenu.HandleClunk
  528.   Description: Click Event handler for all menus
  529.        Author: Mat Ballard
  530.  Date created: 04/25/2000
  531. Date modified: 04/25/2000 by Mat Ballard
  532.       Purpose: responds to user clicks of the menus by setting the menuitem state (Enabled property)
  533.  Known Issues:
  534.  ------------------------------------------------------------------------------}
  535. procedure TPlotMenu.HandleClunk(Sender: TObject);
  536. begin
  537.   if (FPlot = nil) then exit;
  538.   FPlot.DetermineMenuEnabledness(Self);
  539. end;
  540. {$ENDIF}
  541.  
  542. {------------------------------------------------------------------------------
  543.     Procedure: TPlotMenu.HandleFileClick
  544.   Description: Click Event handler for all Reopen file menus
  545.        Author: Mat Ballard
  546.  Date created: 04/25/2000
  547. Date modified: 04/25/2000 by Mat Ballard
  548.       Purpose: responds to user clicks of the FilaName menus by firing the
  549.                TPlot.Open method
  550.  Known Issues:
  551.  ------------------------------------------------------------------------------}
  552. procedure TPlotMenu.HandleFileClick(Sender: TObject);
  553. begin
  554.   if (FPlot = nil) then exit;
  555.  
  556.   FPlot.OpenFile(TMenuItem(Sender).Hint);
  557. end;
  558.  
  559. {------------------------------------------------------------------------------
  560.     Procedure: TPlotMenu.Notification
  561.   Description: handles changes in Plot property
  562.        Author: Mat Ballard
  563.  Date created: 04/25/2000
  564. Date modified: 04/25/2000 by Mat Ballard
  565.       Purpose: Notifies TPlot that it is no longer loved
  566.  Known Issues:
  567.  ------------------------------------------------------------------------------}
  568. { Note deletion of attached Plot component }
  569. procedure TPlotMenu.Notification(AComponent: TComponent;
  570.   Operation: TOperation);
  571. begin
  572.   inherited Notification(AComponent, Operation);
  573.   if (Operation = opRemove) and (AComponent = Plot) then
  574.   begin
  575.     FPlot := nil;
  576.   end;
  577. end;
  578.  
  579. {------------------------------------------------------------------------------
  580.      Function: TPlotMenu.MenuExists
  581.   Description: Does this menu exist ? Based on Tag and Caption
  582.        Author: Mat Ballard
  583.  Date created: 04/25/2000
  584. Date modified: 04/25/2000 by Mat Ballard
  585.       Purpose: do we need to add a menu item ?
  586.  Return Value: Boolean;
  587.  Known Issues:
  588.  ------------------------------------------------------------------------------}
  589. function TPlotMenu.MenuExists(ATag: Integer; ACaption: String): Boolean;
  590. var
  591.   i,
  592.   j: Integer;
  593. begin
  594.   for i := 0 to Self.Items.Count-1 do
  595.   begin
  596. {the menus:}
  597.     if ((Self.Items[i].Tag = ATag) and
  598.         (Self.Items[i].Caption = ACaption)) then
  599.     begin
  600.       MenuExists := TRUE;
  601.       exit;
  602.     end;
  603.     for j := 0 to Self.Items[i].Count-1 do
  604.     begin
  605. {the submenus:}
  606.       if ((Self.Items[i].Items[j].Tag = ATag) and
  607.           (Self.Items[i].Items[j].Caption = ACaption)) then
  608.       begin
  609.         MenuExists := TRUE;
  610.         exit;
  611.       end;
  612.     end;
  613.   end;
  614.   MenuExists := FALSE;
  615. end;
  616.  
  617. procedure TPlotMenu.ApplyOptions(Value: TPopupOptions);
  618. var
  619.   i: Integer;
  620. begin
  621.   for i := 0 to Ord(High(TMainMenus)) do
  622.     Self.Items[i].Visible :=
  623.       (TMainMenus(i) in Value.Menu);
  624.   for i := 0 to Ord(High(TFileMenus)) do
  625.     Self.Items[Ord(mnuFile)].Items[i].Visible :=
  626.       (TFileMenus(i) in Value.File_);
  627.   for i := 0 to Ord(High(TEditMenus)) do
  628.     Self.Items[Ord(mnuEdit)].Items[i].Visible :=
  629.       (TEditMenus(i) in Value.Edit);
  630.   for i := 0 to Ord(High(TViewMenus)) do
  631.     Self.Items[Ord(mnuView)].Items[i].Visible :=
  632.       (TViewMenus(i) in Value.View);
  633.   for i := 0 to Ord(High(TCalcMenus)) do
  634.     Self.Items[Ord(mnuCalc)].Items[i].Visible :=
  635.       (TCalcMenus(i) in Value.Calc);
  636. end;
  637.  
  638.  
  639.  
  640. end.
  641.