home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2006 September / SAN CD 9-2006 CD-ROM 16.iso / pc / Software / Network Telescope Control / NTC-Setup.Exe / Source / ntc_server_form.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2006-03-24  |  20.2 KB  |  842 lines

  1. unit ntc_server_form;
  2. {
  3.     Copyright (C) 2004 - 2006 Andrew Sprott
  4.  
  5.     http://astronomy.crysania.co.uk
  6.     astro@trefach.co.uk
  7.  
  8.     This program is free software; you can redistribute it and/or
  9.     modify it under the terms of the GNU General Public License
  10.     as published by the Free Software Foundation; either version 2
  11.     of the License, or (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  21. }
  22.  
  23. interface
  24.  
  25. uses
  26.     Windows,
  27.     Messages,
  28.     SysUtils,
  29.     Classes,
  30.     Graphics,
  31.     Controls,
  32.     Forms,
  33.     ShellAPI,
  34.     StdCtrls,
  35.     Buttons,
  36.     inifiles,
  37.     ComCtrls,
  38.     Menus,
  39.     ExtCtrls,
  40.     Mask,
  41.     Dialogs,
  42.     CheckLst,
  43.  
  44.     ntc_server_button;
  45.  
  46. const
  47.     server_index=0;
  48.     north=0;
  49.     south=1;
  50.     east=2;
  51.     west=3;
  52.     { messages }
  53.     no_response='No response from server';
  54.     lost_connection='lost connection with server';
  55.     stop_error='NTC failed to stop the scope, '+
  56.                          'it could be that there is a error '+
  57.                          'or the network connection has failed';
  58.     { events }
  59.     event_0=0;
  60.     { precision }
  61.     high_precision_text='high precision';
  62.     low_precision_text='low precision';
  63.     { scope types }
  64.     no_scope=0;
  65.     lx200_type=1;
  66.     autostar_type=2;
  67.     celestron_type=3;
  68.     first_scope_type=lx200_type;
  69.     last_scope_type=celestron_type;
  70.     default_scope_type=lx200_type;
  71.     { interface }
  72.     button_width=57;
  73.     max_menu_items=10;
  74.  
  75. type
  76.     p_dimensions_record=^dimensions_record;
  77.     dimensions_record=record
  78.         vdu_index,
  79.         old_vdu_index,
  80.         screen_left,
  81.         screen_top,
  82.         last_screen_height,
  83.         last_screen_width,
  84.         current_height,
  85.         current_width,
  86.         form_top,
  87.         form_left:integer;
  88.     end;
  89.  
  90.     response_type_set=(
  91.         exit_ok,
  92.         exit_void,
  93.         exit_fail);
  94.     response_type=set of response_type_set;
  95.  
  96.     Tscope = class(TForm)
  97.         controller_pages: TPageControl;
  98.  
  99.         {Utility and form functions}
  100.         procedure formcreate(
  101.             Sender:TObject);
  102.  
  103.         procedure kill(
  104.                     Sender:TObject;
  105.             var CanClose:Boolean);
  106.  
  107.         { configuration }
  108.         procedure get_dimensions(
  109.             form:tform;
  110.             dimensions:p_dimensions_record;
  111.             section:string;
  112.             ini_file:tinifile);
  113.  
  114.         procedure write_dimensions(
  115.             dimensions:p_dimensions_record;
  116.             left,
  117.             top:integer;
  118.             section:string;
  119.             ini_file:tinifile);
  120.  
  121.         procedure load_settings;
  122.         procedure save_settings;
  123.  
  124.         { events }
  125.         procedure control_button_click(
  126.             Sender: TObject);
  127.  
  128.         procedure FormShow(
  129.             Sender: TObject);
  130.  
  131.         procedure find_vdu(
  132.             form:tform;
  133.             dimensions:p_dimensions_record);
  134.  
  135.         procedure form_activate(
  136.             form:tform;
  137.             dimensions:p_dimensions_record);
  138.  
  139.         procedure check_activate(
  140.             Sender: TObject);
  141.  
  142.         procedure change_page;
  143.  
  144.         procedure page_change(
  145.             Sender: TObject);
  146.  
  147.         { menu item event handlers }
  148.         procedure sticky_handler(
  149.             sender:tobject);
  150.  
  151.         procedure buttonContextPopup(
  152.                     Sender: TObject;
  153.                     MousePos: TPoint;
  154.             var Handled: Boolean);
  155.  
  156.     private
  157.         { Private declarations }
  158.         previous_page,
  159.         current_page:ttabsheet;
  160.         active_page:integer;
  161.         { menu handling }
  162.         menu_items:array[1..max_menu_items] of TMenuItem;
  163.         context_menu:tpopupmenu;
  164.         im:integer;
  165.         { menu handler parameters }
  166.         button:tscope_button;
  167.  
  168.     public
  169.         { Public declarations }
  170.         { configuration }
  171.         dimensions:dimensions_record;
  172.  
  173.         { events }
  174.         procedure show_hide(
  175.             sender:tobject;
  176.             v:boolean);
  177.  
  178.     end;
  179.  
  180. { global variables }
  181. var
  182.     scope:Tscope;
  183.     application_path:string;
  184.     { configuration }
  185.     ini_file:tinifile;
  186.  
  187. implementation
  188.  
  189. {$R *.DFM}
  190. uses
  191.     ntc_server_network,
  192.     ntc_server_comms,
  193.     ntc_server_control,
  194.     ntc_server_focus,
  195.     ntc_server_info,
  196.     ntc_server_config,
  197.     ntc_server_observer,
  198.     ntc_server_object,
  199.     ntc_server_tracking,
  200.     ntc_server_about,
  201.     ntc_server_search,
  202.     ntc_server_sun,
  203.     ntc_server_moon,
  204.     ntc_server_planets,
  205.     ntc_server_catalogs;
  206.  
  207.     { -------------
  208.         form handling
  209.         ------------- }
  210.  
  211. procedure Tscope.formcreate(
  212.     Sender:TObject);
  213. begin
  214.     application_path:=extractfilepath(paramstr(0));
  215.     helpfile:=application_path+'ntc.hlp';
  216.     previous_page:=nil;
  217.     load_settings;
  218.     controller_pages.activepage:=current_page;
  219. end;
  220.  
  221. procedure Tscope.kill(
  222.             Sender:TObject;
  223.     var CanClose:Boolean);
  224. begin
  225.     save_settings;
  226.     current_object.free;
  227.     scope_observer.free;
  228.     scope_config.free;
  229.     scope_comms.kill;
  230.     scope_comms.free;
  231.     scope_control.free;
  232.     scope_search.free;
  233.     scope_focus.free;
  234.     scope_network.kill;
  235.     scope_network.free;
  236.     scope_info.free;
  237.     scope_tracking.free;
  238.     scope_about.free;
  239.     scope_sun.free;
  240.     scope_moon.free;
  241.     scope_planets.free;
  242.     scope_catalogs.free;
  243.     canclose:=true;
  244. end;
  245.  
  246.     { --------------------
  247.         configuration backup
  248.         -------------------- }
  249.  
  250. procedure Tscope.find_vdu(
  251.     form:tform;
  252.     dimensions:p_dimensions_record);
  253. var
  254.     i,lw,lh:integer;
  255.     done,vdu_changed:boolean;
  256.  
  257.     procedure switch_monitor;
  258.     begin
  259.         with dimensions^,screen.monitors[vdu_index] do
  260.             begin
  261.                 if screen_left<0 then
  262.                     begin
  263.                         if form_left>=0 then
  264.                             form_left:=form_left+screen_left+left
  265.                         else
  266.                             form_left:=abs(form_left-screen_left)+left;
  267.                     end
  268.                 else
  269.                     form_left:=form_left-screen_left+left;
  270.                 if screen_top<0 then
  271.                     begin
  272.                         if form_top>=0 then
  273.                             form_top:=form_top+screen_top+top
  274.                         else
  275.                             form_top:=abs(form_top-screen_top)+top;
  276.                     end
  277.                 else
  278.                     form_top:=form_top-screen_top+top;
  279.                 screen_left:=left;
  280.                 screen_top:=top;
  281.             end;
  282.     end;
  283.  
  284. begin
  285.     with screen,dimensions^ do
  286.         begin
  287.             vdu_changed:=false;
  288.             if vdu_index>=0 then
  289.                 begin
  290.                     i:=0;
  291.                     if (old_vdu_index>=0) and (old_vdu_index<monitorcount) then
  292.                         begin
  293.                             if old_vdu_index<>vdu_index then
  294.                                 begin
  295.                                     vdu_index:=old_vdu_index;
  296.                                     switch_monitor;
  297.                                 end;
  298.                             old_vdu_index:=-1;
  299.                         end;
  300.                     done:=false;
  301.                     while not done do
  302.                          if i<monitorcount then
  303.                          with monitors[i] do
  304.                         begin
  305.                             if (form_left<left) or
  306.                                  (form_left>left+width) or
  307.                                  (form_top<top) or
  308.                                  (form_top>top+height) then
  309.                                 inc(i)
  310.                             else
  311.                                 begin
  312.                                     if i<>vdu_index then
  313.                                         vdu_index:=i;
  314.                                     done:=true;
  315.                                 end;
  316.                         end
  317.                     else
  318.                         begin
  319.                             done:=true;
  320.                             vdu_changed:=true;
  321.                             vdu_index:=-1;
  322.                         end;
  323.                 end;
  324.             if vdu_index<0 then
  325.                 begin
  326.                     i:=0;
  327.                     while (i<monitorcount) and not monitors[i].Primary do
  328.                         inc(i);
  329.                     if i<monitorcount then
  330.                         vdu_index:=i
  331.                     else
  332.                         vdu_index:=0;
  333.                     vdu_changed:=true;
  334.                 end;
  335.             with monitors[vdu_index] do
  336.                 begin
  337.                     if vdu_changed then
  338.                         switch_monitor;
  339.                     lw:=current_width;
  340.                     lh:=current_height;
  341.                     if (lw<>width) or (lh<>height) then
  342.                         begin
  343.                             current_width:=width;
  344.                             current_height:=height;
  345.                             form_left:=trunc(form_left/last_screen_width*current_width);
  346.                             if form_left+form.width>left+current_width then
  347.                                 form_left:=left+current_width-form.Width;
  348.                             if form_left<left then
  349.                                 form_left:=left;
  350.                             form_top:=trunc(form_top/last_screen_height*current_height);
  351.                             if form_top+form.height>top+current_height then
  352.                                 form_top:=top+current_height-form.height;
  353.                             if form_top<top then
  354.                                 form_top:=top;
  355.                             last_screen_width:=current_width;
  356.                             last_screen_height:=current_height;
  357.                         end
  358.                     else
  359.                         begin
  360.                             current_width:=width;
  361.                             current_height:=height;
  362.                         end;
  363.                 end;
  364.         end;
  365. end;
  366.  
  367. procedure tscope.get_dimensions(
  368.     form:tform;
  369.     dimensions:p_dimensions_record;
  370.     section:string;
  371.     ini_file:tinifile);
  372. begin
  373.     with ini_file,dimensions^ do
  374.         begin
  375.             vdu_index:=readinteger(section,'monitor',-1);
  376.             old_vdu_index:=readinteger(section,'another_monitor',-1);
  377.             form_top:=readinteger(section,'top',form_top);
  378.             form_left:=readinteger(section,'left',form_left);
  379.             screen_left:=readinteger(section,'screen_left',0);
  380.             screen_top:=readinteger(section,'screen_top',0);
  381.             last_screen_width:=readinteger(section,'screen_width',-1);
  382.             current_width:=last_screen_width;
  383.             last_screen_height:=readinteger(section,'screen_height',-1);
  384.             current_height:=last_screen_height;
  385.             find_vdu(form,dimensions);
  386.         end;
  387. end;
  388.  
  389. procedure tscope.write_dimensions(
  390.     dimensions:p_dimensions_record;
  391.     left,
  392.     top:integer;
  393.     section:string;
  394.     ini_file:tinifile);
  395. var
  396.     i:integer;
  397. begin
  398.     with ini_file,screen,dimensions^ do
  399.         begin
  400.             for i:=0 to monitorcount-1 do
  401.                  if monitors[i].primary and (vdu_index<>i) then
  402.                 old_vdu_index:=vdu_index;
  403.             writeinteger(section,'another_monitor',old_vdu_index);
  404.             writeinteger(section,'monitor',vdu_index);
  405.             writeinteger(section,'left',left);
  406.             writeinteger(section,'top',top);
  407.             writeinteger(section,'screen_width',current_width);
  408.             writeinteger(section,'screen_height',current_height);
  409.             writeinteger(section,'screen_left',monitors[vdu_index].left);
  410.             writeinteger(section,'screen_top',monitors[vdu_index].top);
  411.         end;
  412. end;
  413.  
  414. procedure tscope.load_settings;
  415. var
  416.     l,m,ip,ib,t:integer;
  417.     p,b,bn:string;
  418.     pd,bd,h,s:boolean;
  419.     ts:ttabsheet;
  420.  
  421.     procedure add_control_page(
  422.         page_name:string);
  423.     begin
  424.         with controller_pages do
  425.             begin
  426.                 ts:=ttabsheet.create(self);
  427.                 with ts do
  428.                     begin
  429.                         pagecontrol:=controller_pages;
  430.                         caption:=page_name;
  431.                         l:=0;
  432.                     end;
  433.             end;
  434.     end;
  435.  
  436.     procedure add_button(
  437.         scope_control_object:scope_button_type;
  438.         button_name:string;
  439.         hidden,
  440.         stuck:boolean);
  441.     begin
  442.         with ts,tscope_button.create(ts) do
  443.             begin
  444.                 visible:=false;
  445.                 caption:=button_name;
  446.                 left:=l;
  447.                 width:=button_width;
  448.                 inc(l,button_width);
  449.                 if l>m then
  450.                     m:=l;
  451.                 top:=0;
  452.                 height:=25;
  453.                 parent:=ts;
  454.                 button_hidden:=hidden;
  455.                 if button_hidden then
  456.                     button_stuck:=false
  457.                 else
  458.                     begin
  459.                         button_stuck:=stuck;
  460.                         if stuck then
  461.                             font.style:=[fsbold]
  462.                         else
  463.                             font.style:=[];
  464.                     end;
  465.                 control_type:=scope_control_object;
  466.                 onclick:=control_button_click;
  467.                 oncontextpopup:=buttonContextPopup;
  468.                 visible:=true;
  469.             end;
  470.     end;
  471.  
  472.     procedure add_menu(
  473.         i:integer;
  474.         s:string;
  475.         h:tnotifyevent);
  476.     begin
  477.         if im>max_menu_items then
  478.             scope_network.update_status_log_check('too many menus : '+inttostr(im))
  479.         else
  480.             begin
  481.                 menu_items[im]:=nil;
  482.                 menu_items[im]:=tmenuitem.create(self);
  483.                 with menu_items[im] do
  484.                     begin
  485.                         caption:=s;
  486.                         checked:=false;
  487.                         onclick:=h;
  488.                     end;
  489.                 context_menu.items.add(menu_items[im]);
  490.             end;
  491.         inc(im);
  492.     end;
  493.  
  494. begin
  495.     ini_file:=tinifile.create(application_path+'server.ini');
  496.     { menus }
  497.     context_menu:=tpopupmenu.create(self);
  498.     im:=1;
  499.     add_menu(im,'Sticky Control',sticky_handler);
  500.     { control panel }
  501.     m:=0;
  502.     current_page:=nil;
  503.     with controller_pages,ini_file do
  504.          if readinteger('main','num_control_panels',0)>0 then
  505.         begin
  506.             active_page:=readinteger('main','active_page',0);
  507.             ip:=1;
  508.             pd:=false;
  509.             while not pd do
  510.                 begin
  511.                     p:=readstring('main','panel_'+inttostr(ip),'');
  512.                     if p<>'' then
  513.                         begin
  514.                             add_control_page(p);
  515.                             if active_page=ip then
  516.                                 current_page:=ts;
  517.                             p:='panel_'+inttostr(ip);
  518.                             ib:=1;
  519.                             bd:=false;
  520.                             while not bd do
  521.                                 begin
  522.                                     b:='button_'+inttostr(ib)+'_';
  523.                                     bn:=readstring(p,b+'name','');
  524.                                     if bn<>'' then
  525.                                         begin
  526.                                             t:=readinteger(p,b+'module',0);
  527.                                             h:=readbool(p,b+'hidden',true);
  528.                                             s:=readbool(p,b+'stuck',false);
  529.                                             if t>0 then
  530.                                                 begin
  531.                                                     case t of
  532.                                                         s_info:add_button(s_info,bn,h,s);
  533.                                                         s_comms:add_button(s_comms,bn,h,s);
  534.                                                         s_focus:add_button(s_focus,bn,h,s);
  535.                                                         s_about:add_button(s_about,bn,h,s);
  536.                                                         s_config:add_button(s_config,bn,h,s);
  537.                                                         s_object:add_button(s_object,bn,h,s);
  538.                                                         s_search:add_button(s_search,bn,h,s);
  539.                                                         s_control:add_button(s_control,bn,h,s);
  540.                                                         s_network:add_button(s_network,bn,h,s);
  541.                                                         s_observer:add_button(s_observer,bn,h,s);
  542.                                                         s_tracking:add_button(s_tracking,bn,h,s);
  543.                                                         s_sun:add_button(s_sun,bn,h,s);
  544.                                                         s_moon:add_button(s_moon,bn,h,s);
  545.                                                         s_planets:add_button(s_planets,bn,h,s);
  546.                                                         s_catalogs:add_button(s_catalogs,bn,h,s);
  547.                                                     end;
  548.                                                 end;
  549.                                         end
  550.                                     else
  551.                                         bd:=true;
  552.                                     inc(ib);
  553.                                 end;
  554.                         end
  555.                     else
  556.                         pd:=true;
  557.                     inc(ip);
  558.                 end;
  559.             if current_page=nil then
  560.                 begin
  561.                     current_page:=controller_pages.activepage;
  562.                     active_page:=controller_pages.ActivePageIndex+1;
  563.                 end
  564.             else
  565.                 controller_pages.activepage:=current_page;
  566.         end
  567.     else
  568.         begin
  569.             add_control_page('Setup');
  570.             add_button(s_comms,'Comms',true,false);
  571.             add_button(s_about,'About',true,false);
  572.             add_button(s_config,'Config',true,false);
  573.             add_button(s_network,'Network',true,false);
  574.             add_button(s_observer,'Locale',true,false);
  575.             add_control_page('Control');
  576.             add_button(s_info,'Info',true,false);
  577.             add_button(s_focus,'Focus',true,false);
  578.             add_button(s_search,'Search',true,false);
  579.             add_button(s_control,'Control',true,false);
  580.             add_button(s_tracking,'Track',true,false);
  581.             current_page:=controller_pages.ActivePage;
  582.             active_page:=controller_pages.ActivePageIndex+1;
  583.             add_control_page('Objects');
  584.             add_button(s_sun,'Sun',true,false);
  585.             add_button(s_moon,'Moon',true,false);
  586.             add_button(s_planets,'Planets',true,false);
  587.             add_button(s_catalogs,'Catalogs',true,false);
  588.         end;
  589.     scope.clientwidth:=m;
  590.     { form }
  591.     get_dimensions(scope,@dimensions,'main',ini_file);
  592.     ini_file.Free;
  593. end;
  594.  
  595. procedure tscope.save_settings;
  596. var
  597.     i,j:integer;
  598.     ps,bs:string;
  599. begin
  600.     ini_file:=tinifile.create(application_path+'server.ini');
  601.     scope_network.save_settings;
  602.     scope_control.save_settings;
  603.     scope_focus.save_settings;
  604.     scope_info.save_settings;
  605.     scope_comms.save_settings;
  606.     scope_config.save_settings;
  607.     scope_observer.save_settings;
  608.     scope_tracking.save_settings;
  609.     scope_search.save_settings;
  610.     scope_sun.save_settings;
  611.     scope_moon.save_settings;
  612.     scope_planets.save_settings;
  613.     scope_catalogs.save_settings;
  614.     scope_about.save_settings;
  615.     with ini_file do
  616.         begin
  617.             { control panel }
  618.             with controller_pages do
  619.                 begin
  620.                     for i:=0 to pagecount-1 do
  621.                         begin
  622.                             ps:='panel_'+inttostr(i+1);
  623.                             writestring('main',ps,pages[i].caption);
  624.                             for j:=0 to pages[i].ControlCount-1 do
  625.                                  with pages[i],tscope_button(Controls[j]) do
  626.                                 begin
  627.                                     bs:='button_'+inttostr(j+1)+'_';
  628.                                     WriteString(ps,bs+'name',caption);
  629.                                     writestring(ps,bs+'module',inttostr(control_type));
  630.                                     writebool(ps,bs+'hidden',button_hidden);
  631.                                     writebool(ps,bs+'stuck',button_stuck);
  632.                                 end;
  633.                         end;
  634.                     writestring('main','num_control_panels',inttostr(pagecount));
  635.                 end;
  636.             writeinteger('main','active_page',active_page);
  637.             { form }
  638.             find_vdu(scope,@dimensions);
  639.             write_dimensions(@dimensions,left,top,'main',ini_file);
  640.         end;
  641.     ini_file.free;
  642. end;
  643.  
  644.     { ------
  645.         events
  646.         ------ }
  647.  
  648. procedure Tscope.FormShow(
  649.     Sender: TObject);
  650. begin
  651.     with dimensions do
  652.         begin
  653.             top:=form_top;
  654.             left:=form_left;
  655.         end;
  656.     change_page;
  657. end;
  658.  
  659. procedure Tscope.form_activate(
  660.     form:tform;
  661.     dimensions:p_dimensions_record);
  662. var
  663.     w,h:integer;
  664. begin
  665.     with form,dimensions^ do
  666.         begin
  667.             find_vdu(form,dimensions);
  668.             w:=screen.monitors[vdu_index].width;
  669.             h:=screen.monitors[vdu_index].Height;
  670.             if (w<>current_width) or
  671.                  (h<>current_height) then
  672.                 begin
  673.                     last_screen_width:=current_width;
  674.                     last_screen_height:=current_height;
  675.                     current_width:=w;
  676.                     current_height:=h;
  677.                     scope_network.adjust;
  678.                     scope_control.adjust;
  679.                     scope_about.adjust;
  680.                     scope_focus.adjust;
  681.                     scope_info.adjust;
  682.                     scope_config.adjust;
  683.                     scope_comms.adjust;
  684.                     scope_observer.adjust;
  685.                     scope_sun.adjust;
  686.                     scope_moon.adjust;
  687.                     scope_planets.adjust;
  688.                     scope_catalogs.adjust;
  689.                     form_top:=trunc(form_top/last_screen_height*current_height);
  690.                     form_left:=trunc(form_left/last_screen_width*current_width);
  691.                     top:=form_top;
  692.                     left:=form_left;
  693.                     scope.show;
  694.                 end;
  695.         end;
  696. end;
  697.  
  698. procedure Tscope.check_activate(
  699.     Sender: TObject);
  700. begin
  701.     form_activate(scope,@dimensions);
  702. end;
  703.  
  704. procedure Tscope.show_hide(
  705.     sender:tobject;
  706.     v:boolean);
  707. begin
  708.     with tscope_button(sender) do
  709.          if not v then
  710.         begin
  711.             if button_stuck then
  712.                 font.style:=[];
  713.             button_stuck:=false;
  714.             button_hidden:=true;
  715.         end
  716.     else
  717.         button_hidden:=false;
  718. end;
  719.  
  720. procedure Tscope.control_button_click(
  721.     Sender: TObject);
  722. begin
  723.     with tscope_button(sender) do
  724.         begin
  725.             case control_type of
  726.                 s_info:scope_info.check_visible_and_show_hide(sender);
  727.                 s_config:scope_config.check_visible_and_show_hide(sender);
  728.                 s_comms:scope_comms.check_visible_and_show_hide(sender);
  729.                 s_focus:scope_focus.check_visible_and_show_hide(sender);
  730.                 s_about:scope_about.check_visible_and_show_hide(sender);
  731.                 s_network:scope_network.check_visible_and_show_hide(sender);
  732.                 s_search:scope_search.check_visible_and_show_hide(sender);
  733.                 s_control:scope_control.check_visible_and_show_hide(sender);
  734.                 s_tracking:scope_tracking.check_visible_and_show_hide(sender);
  735.                 s_observer:scope_observer.check_visible_and_show_hide(sender);
  736.                 s_sun:scope_sun.check_visible_and_show_hide(sender);
  737.                 s_moon:scope_moon.check_visible_and_show_hide(sender);
  738.                 s_planets:scope_planets.check_visible_and_show_hide(sender);
  739.                 s_catalogs:scope_catalogs.check_visible_and_show_hide(sender);
  740.             end;
  741.         end;
  742. end;
  743.  
  744. procedure tscope.change_page;
  745. var
  746.     i:integer;
  747. begin
  748.     previous_page:=current_page;
  749.     if previous_page<>nil then
  750.          with previous_page do
  751.          for i:=0 to controlcount-1 do
  752.          with tscope_button(controls[i]) do
  753.         begin
  754.             if not button_stuck then
  755.                  case control_type of
  756.                 s_info:scope_info.hide_form;
  757.                 s_comms:scope_comms.hide_form;
  758.                 s_about:scope_about.hide_form;
  759.                 s_focus:scope_focus.hide_form;
  760.                 s_config:scope_config.hide_form;
  761.                 s_network:scope_network.hide_form;
  762.                 s_search:scope_search.hide_form;
  763.                 s_control:scope_control.hide_form;
  764.                 s_observer:scope_observer.hide_form;
  765.                 s_tracking:scope_tracking.hide_form;
  766.                 s_sun:scope_sun.hide_form;
  767.                 s_moon:scope_moon.hide_form;
  768.                 s_planets:scope_planets.hide_form;
  769.                 s_catalogs:scope_catalogs.hide_form;
  770.             end;
  771.         end;
  772.     current_page:=controller_pages.ActivePage;
  773.     with current_page do
  774.          for i:=0 to controlcount-1 do
  775.          with tscope_button(controls[i]) do
  776.         begin
  777.             if not button_hidden then
  778.                  case control_type of
  779.                 s_info:scope_info.show_form;
  780.                 s_comms:scope_comms.show_form;
  781.                 s_about:scope_about.show_form;
  782.                 s_focus:scope_focus.show_form;
  783.                 s_config:scope_config.show_form;
  784.                 s_network:scope_network.show_form;
  785.                 s_search:scope_search.show_form;
  786.                 s_control:scope_control.show_form;
  787.                 s_observer:scope_observer.show_form;
  788.                 s_tracking:scope_tracking.show_form;
  789.                 s_sun:scope_sun.show_form;
  790.                 s_moon:scope_moon.show_form;
  791.                 s_planets:scope_planets.show_form;
  792.                 s_catalogs:scope_catalogs.show_form;
  793.             end;
  794.         end;
  795.     active_page:=controller_pages.ActivePageIndex+1;
  796. end;
  797.  
  798. procedure Tscope.page_change(
  799.     Sender: TObject);
  800. begin
  801.     change_page;
  802. end;
  803.  
  804.     { -------------------
  805.         menu event handlers
  806.         ------------------- }
  807.  
  808. { menu handlers }
  809. procedure tscope.sticky_handler(
  810.     sender:tobject);
  811. begin
  812.     with tmenuitem(sender) do
  813.         begin
  814.             with button do
  815.                 begin
  816.                     button_stuck:=not button_stuck;
  817.                     if button_stuck then
  818.                         font.Style:=[fsbold]
  819.                     else
  820.                         font.style:=[];
  821.                 end;
  822.         end;
  823. end;
  824.  
  825. procedure tscope.buttonContextPopup(
  826.             Sender: TObject;
  827.             MousePos: TPoint;
  828.     var Handled: Boolean);
  829. begin
  830.     { setup up parameters }
  831.     button:=sender as tscope_button;
  832.     { call popup menu }
  833.     handled:=true;
  834.     with button do
  835.          context_menu.popup(
  836.         scope.left+current_page.left+parent.left+left+mousepos.x,
  837.         scope.top+current_page.top+parent.top+top+mousepos.y);
  838. end;
  839.  
  840. end.
  841.  
  842.