wfigmngr.m
上传用户:haiyisale
上传日期:2013-01-09
资源大小:3246k
文件大小:38k
源码类别:

波变换

开发平台:

Matlab

  1. function varargout = wfigmngr(option,varargin)
  2. %WFIGMNGR Wavelet Toolbox Utilities for creating figures.
  3. %   VARARGOUT = WFIGMNGR(OPTION,VARARGIN)
  4. %   M. Misiti, Y. Misiti, G. Oppenheim, J.M. Poggi 01-May-96.
  5. %   Last Revision: 12-Nov-2003.
  6. %   Copyright 1995-2004 The MathWorks, Inc.
  7. %   $Revision: 1.21.4.2 $
  8. % Tool Memory Block.
  9. %-------------------
  10. n_toolMemB  = 'Tool_Params';
  11. % Tag property of objects.
  12. %------------------------
  13. tag_m_files = 'M_Files';
  14. tag_m_view  = 'M_View';
  15. tag_m_dynv  = 'M_Zoom';
  16. % Tag property of objects.
  17. %-------------------------
  18. tag_cmd_frame = 'Cmd_Frame';
  19. % Test inputs.
  20. %-------------
  21. if nargin==0
  22.     fig = gcf;
  23.     option  = 'extfig';
  24.     diffarg = 0;
  25. elseif ~ischar(option)
  26.     fig     = option;
  27.     option  = 'extfig';
  28.     diffarg = 0;
  29. elseif strcmp(option,'extfig')
  30.     diffarg = 1;
  31.     if nargin<2 , fig = gcf; else , fig = varargin{1}; end    
  32. end
  33. switch option
  34.     case 'getmenus'
  35.         %***********************************************************%
  36.         %** OPTION = 'getmenus' : get the handles of main menus.  **%
  37.         %***********************************************************%
  38.         fig   = varargin{1};
  39.         lst_Main = findall(fig,'type','uimenu','Parent',fig);
  40. m_files  = findall(lst_Main,'tag',tag_m_files);
  41. nbIn = length(varargin);
  42. if nbIn==1
  43.             varargout{1} = m_files;
  44.             varargout{2} = lst_Main;
  45. return
  46. end
  47. % Search in menu Files First.
  48. %----------------------------
  49. lst_m = findall(m_files,'type','uimenu','Parent',m_files);
  50. varargout = cell(1,nbIn-1);
  51. for k = 2:nbIn
  52.     menuName = lower(varargin{k});
  53. switch menuName
  54.   case 'file'
  55.   varargout{k-1} = m_files;
  56.   case {'load','save','close'}
  57.   varargout{k-1} = findmenu(lst_m,menuName);
  58.   case {'help'}
  59.   varargout{k-1} = findmenu(lst_Main,menuName);
  60.   case {'view'}
  61.   varargout{k-1} = findall(fig,'type','uimenu','tag',tag_m_view);   
  62. end
  63. end
  64.     case 'init'
  65.         %*************************************************************%
  66.         %** OPTION = 'init' :  init a figure - with default values  **%
  67.         %*************************************************************%
  68.         % varargin contains figure properties.
  69.         %-------------------------------------      
  70.         % Get Globals.
  71.         %-------------
  72.         [...
  73.         Def_FigColor,Def_DefColor,                      ...
  74.         Def_AxeXColor,Def_AxeYColor,Def_AxeZColor,      ...
  75.         Def_AxeFontSize,Def_TxtColor,Def_TxtFontSize,   ...
  76.         Def_UicFtWeight,Def_AxeFtWeight,Def_TxtFtWeight,...
  77.         Def_FraBkColor] = ...
  78.             mextglob('get',...
  79.                 'Def_FigColor','Def_DefColor',...
  80.                 'Def_AxeXColor','Def_AxeYColor','Def_AxeZColor',        ...
  81.                 'Def_AxeFontSize','Def_TxtColor','Def_TxtFontSize',     ...
  82.                 'Def_UicFtWeight','Def_AxeFtWeight','Def_TxtFtWeight',  ...
  83.                 'Def_FraBkColor'                                        ...
  84.                 );
  85.         varargout{1} = colordef('new',Def_DefColor);
  86.         figProperties = {...
  87.             'MenuBar','none',...
  88.             'DefaultUicontrolBackgroundcolor',Def_FraBkColor,...
  89.             'DefaultUicontrolFontWeight',Def_UicFtWeight,...
  90.             'DefaultAxesFontWeight',Def_AxeFtWeight,...
  91.             'DefaultTextFontWeight',Def_TxtFtWeight,...
  92.             'Color',Def_FigColor,...
  93.             'NumberTitle','Off',...
  94.             'DefaultAxesFontSize',Def_AxeFontSize,...
  95.             'DefaultAxesXColor',Def_AxeXColor,...
  96.             'DefaultAxesYColor',Def_AxeYColor,...
  97.             'DefaultAxesZColor',Def_AxeZColor,...
  98.             'DefaultTextColor',Def_TxtColor,...
  99.             'DefaultTextFontSize',Def_TxtFontSize,...
  100.             'Name','',...
  101.             'Visible','On',...
  102.             'Position',get(0,'DefaultFigurePosition'),...
  103.             'Unit',get(0,'defaultfigureUnit'),...
  104.             varargin{:} ...
  105.             };
  106.         set(varargout{1}, figProperties{:});
  107.         s = dbstack; defineWfigPROP(varargout{1},s)
  108.     case 'attach_close'
  109.         %******************************************************%
  110.         %** OPTION = 'attach_close' :  attach close function **%
  111.         %******************************************************%
  112.         % in2 = fig
  113.         % in3 = funct name (optional)
  114.         % in4 = conditional closing (optional)
  115.         %-------------------------------------
  116.         fig     = varargin{1};
  117.         lst     = findall(fig,'type','uimenu','Parent',fig);
  118.         m_files = findall(lst,'tag',tag_m_files);
  119.         lst     = findall(m_files,'type','uimenu','Parent',m_files);
  120.         m_close = findmenu(lst,'close');
  121.         set(m_close,'Interruptible','on');
  122.         str1 = '';
  123.         str2 = get(m_close,'callback');
  124.         str3 = ['wfigmngr(''close'',' sprintf('%20.15f',fig) ');'];
  125.         if nargin>2
  126.             funcNam = varargin{2};       
  127.             str1 = [funcNam '(''close'',' sprintf('%20.15f',fig) ');'];
  128.             if nargin>3
  129.                 str1 = ['ansVal = ' str1];
  130.                 str2 = ['if ansVal>-1 ' str2 ' end; clear ansVal'];
  131.             end
  132.         end
  133.         varargout{1} = [str3,str1,str2];
  134.         set(m_close,'Callback',varargout{1});
  135.         set(fig,'CloseRequestFcn',varargout{1})
  136.     case 'close'
  137.         fig = varargin{1};
  138.         figChild = wfigmngr('getWinPROP',fig,'FigChild');
  139.         figChild = figChild(ishandle(figChild));
  140.         for k = 1:length(figChild)
  141.             try , eval(get(figChild(k),'CloseRequestFcn')); end
  142.         end
  143.     case 'extfig'
  144.         %******************************************%
  145.         %** OPTION = 'extfig' :figure extension  **%
  146.         %******************************************%
  147. createMenus(fig,varargin{2:end});
  148.     case 'create'
  149.         %******************************************%
  150.         %** OPTION = 'create' :  create a window **%
  151.         %******************************************%
  152.         % in2 = win_name
  153.         % in3 = color (1...8)
  154.         % in4 = extmode (number or strmat)
  155.         %   
  156.         % in5 = closemode (strmat)
  157.         %   if size(in5,1) = 2 , conditional close
  158.         %-----------------------------------------
  159.         % in6 = flag dynvisu   (optional)
  160.         % in7 = flag close btn (optional)
  161.         % in8 = flag txttitl   (optional)
  162.         %-----------------------------------------
  163.         % out1 = win_hld
  164.         % out2 = frame_hdl
  165.         % out3 = graphic_area
  166.         % out4 = pus_close
  167.         %-------------------------
  168.         nbin = length(varargin);
  169.         
  170.         % Defaults Values
  171.         %-----------------
  172.         figName     = '';
  173.         valColor    = '';
  174.         extMode     = '';
  175.         closeMode   = '';
  176.         flgDynV     = 1;
  177.         flgCloseBtn = 1;
  178.         flgTitle    = 1;
  179.         switch nbin
  180.             case 1 , figName = varargin{1};
  181.             case 2 , [figName,valColor] = deal(varargin{:});
  182.             case 3 , [figName,valColor,extMode] = deal(varargin{:});
  183.             case 4 , [figName,valColor,extMode,closeMode] = deal(varargin{:});
  184.             case 5 , [figName,valColor,extMode,closeMode,...
  185.                       flgDynV] = deal(varargin{:});
  186.             case 6 , [figName,valColor,extMode,closeMode,...
  187.                       flgDynV,flgCloseBtn] = deal(varargin{:});
  188.             case 7 , [figName,valColor,extMode,closeMode,...
  189.                       flgDynV,flgCloseBtn,flgTitle] = deal(varargin{:});
  190.         end
  191.         % Get Globals.
  192.         %-------------
  193.         [...
  194.         Def_Btn_Height,X_Graph_Ratio,X_Spacing,Y_Spacing,...
  195.         Def_TxtBkColor,Def_FraBkColor] = ...
  196.             mextglob('get',...
  197.                 'Def_Btn_Height','X_Graph_Ratio', ...
  198.                 'X_Spacing','Y_Spacing',          ...
  199.                 'Def_TxtBkColor','Def_FraBkColor' ...
  200.                 );
  201.         % Creating extended figure.
  202.         %--------------------------
  203.         win_units = 'pixels';
  204.         [pos_win,win_width,win_height,cmd_width] = wfigmngr('figsizes');
  205.         win_hld   = wfigmngr('init', ...
  206.                         'Name',figName,...
  207.                         'Unit',win_units,...
  208.                         'Position',pos_win...
  209.                         );
  210.         % Figure Extension (add menus).
  211.         %-----------------------------
  212.         if ~isempty(extMode) , wfigmngr('extfig',win_hld,extMode); end
  213.         s = dbstack; defineWfigPROP(win_hld,s,'replace')
  214.         if ~isempty(closeMode)
  215.             namefunc = deblank(closeMode(1,:));
  216.             if size(closeMode,1)==2
  217.                cba_close = wfigmngr('attach_close',win_hld,namefunc,'cond');
  218.             else
  219.                cba_close = wfigmngr('attach_close',win_hld,namefunc);      
  220.             end
  221.         else
  222.             cba_close = wfigmngr('attach_close',win_hld);   
  223.         end
  224.         x_frame   = pos_win(3)-cmd_width+1;
  225.         pos_frame = [x_frame,0,cmd_width,pos_win(4)+5];
  226.         frame_hdl = uicontrol(...
  227.                               'Parent',win_hld,               ...
  228.                               'Style','frame',                ...
  229.                               'Unit',win_units,               ...
  230.                               'Position',pos_frame,           ...
  231.                               'Backgroundcolor',Def_FraBkColor, ...
  232.                               'Tag',tag_cmd_frame             ...
  233.                               );
  234.         drawnow;
  235.         if flgDynV
  236.             % Dynamic visualization tool.
  237.             %----------------------------
  238.             pos_dyn_visu = dynvtool('create',win_hld,X_Graph_Ratio);
  239.             ylow = pos_dyn_visu(4);
  240.             pos_gra = [0,pos_dyn_visu(4),x_frame,pos_win(4)-ylow];
  241.         else
  242.             pos_gra = [0,0,x_frame,pos_win(4)];
  243.         end
  244.         if flgCloseBtn
  245.            % Close Button.
  246.            %--------------
  247.             push_width  = (cmd_width-4*X_Spacing)/2;
  248.             xl = x_frame+(cmd_width-7*push_width/4)/2;
  249.             yl = pos_frame(2)+2*Y_Spacing;
  250.             wi = 7*push_width/4;
  251.             scrSize = get(0,'ScreenSize');
  252.             if scrSize(4)<700
  253.                 he = Def_Btn_Height;
  254.             else
  255.                 he = 3*Def_Btn_Height/2;
  256.             end
  257.             pos_close = [xl , yl , wi , he];
  258.             pus_close = uicontrol(...
  259.                                   'Parent',win_hld,    ...
  260.                                   'Style','Pushbutton',...
  261.                                   'Unit',win_units,    ...
  262.                                   'Position',pos_close,...
  263.                                   'String',xlate('Close'),    ...
  264.                                   'Interruptible','on',...
  265.                                   'Userdata',0,        ...
  266.                                   'Callback',cba_close,...
  267.                                   'TooltipString',xlate('Close window')...
  268.                                   );
  269.         else
  270.             pus_close = [];
  271.         end
  272.         wfigmngr('storeValue',win_hld,'pus_close',pus_close);
  273.         if flgTitle
  274.             % Figure Title.
  275.             %--------------
  276.             wfigtitl('set',win_hld,X_Graph_Ratio,'','off',Def_TxtBkColor);
  277.             pos_gra(4) = pos_gra(4)-Def_Btn_Height;
  278.         end
  279.         % Waiting Text construction.
  280.         %---------------------------
  281.         wwaiting('create',win_hld,X_Graph_Ratio);
  282.         switch nargout
  283.             case 1 , varargout = {win_hld};
  284.             case 4 , varargout = {win_hld,frame_hdl,pos_gra,pus_close};
  285.             case 8
  286.                 varargout = {...
  287.                              win_hld,pos_win,win_units, ...
  288.                              sprintf('%.0f',win_hld),...
  289.                              frame_hdl,pos_frame,pos_gra,pus_close...
  290.                              };
  291.         end
  292.         drawnow
  293.     case 'normalize'
  294.         %************************************************%
  295.         %** OPTION = 'normalize' :  normalize a window **%
  296.         %************************************************%
  297.         % in2 = win_hdl
  298.         % in3 = pos_gra (optional)
  299.         %--------------------------
  300.         % out1 = pos_gra (optional)
  301.         fig = varargin{1};
  302.         pos_win = get(fig,'Position');
  303.         if nargin>2
  304.             varargout{1} = varargin{2}./[pos_win(3:4),pos_win(3:4)];
  305.         end
  306.         hdl = [wfindobj(fig,'units','pixels');wfindobj(fig,'units','data')];
  307.         set(hdl,'units','normalized');
  308.         % Resizing the Figure.
  309.         %---------------------
  310.         if isappdata(0,'ResizeRatioWTBX_Fig')
  311.             RatScrPixPerInch = getappdata(0,'ResizeRatioWTBX_Fig');
  312.             if ~isequal(RatScrPixPerInch,1.0)
  313.                 pos_winNOR = get(fig,'Position');
  314.                 pos_winNEW = RatScrPixPerInch*pos_winNOR;
  315.                 DeltaDIM = pos_winNEW-pos_winNOR;
  316.                 pos_win = [pos_winNOR(1:2)-DeltaDIM(3:4),pos_winNEW(3:4)];
  317.                 set(fig,'Position',pos_win);
  318.             end
  319.         end
  320.     case 'handlevis'
  321.         %***************************************************************%
  322.         %** OPTION = 'handlevis' :  set HandleVisibility for a window **%
  323.         %***************************************************************%
  324.         % in2 = win_hdl
  325.         % in3 = handleVisibility value
  326.         %------------------------------
  327.         fig    = varargin{1};
  328.         flgVis = lower(varargin{2});
  329.         switch flgVis
  330.           case {'on','off','callback'}
  331.             set(fig,'HandleVisibility',flgVis);
  332.           otherwise
  333.             errargt(mfilename,'Invalid Value for HandleVisibility','msg');
  334.             error('*')
  335.         end
  336.     case 'get_activeHDL'
  337.         % in2 = win_hdl
  338.         % in3 = type
  339.         %---------------
  340.         fig  = varargin{1};
  341.         type = varargin{2};
  342.         switch type
  343.             case 'uimenu'
  344.                 m0 = findall(get(fig,'children'),'flat','type','uimenu');
  345.                 m1 = findall(m0,'tag',tag_m_files);
  346.                 m0(m0==m1) = [];
  347.                 c1 = findall(m1,'Parent',m1);
  348.                 p1 = get(c1,'Position');
  349.                 p1 = cat(1,p1{:});
  350.                 [nul,I1] = sort(p1);
  351.                 n  = length(I1);
  352.                 I1 = I1(n-2:n);
  353.                 varargout{1} = [findall(m0) ; m1; c1(I1)];
  354.             case 'close'
  355.                 cba  = get(fig,'CloseRequestFcn');
  356.                 varargout{1} = wfindobj(fig,'style','pushbutton','callback',cba);
  357.                 varargout{2} = wfindobj(fig,'type','uimenu','callback',cba);
  358.         end
  359.     case 'figsizes'
  360.         % Get Globals.
  361.         %-------------
  362.         [ShiftTop_Fig, ...
  363.          Def_Btn_Height,Def_Btn_Width,Pop_Min_Width, ...
  364.          X_Graph_Ratio,X_Spacing,Y_Spacing ] = ...
  365.            mextglob('get',...
  366.                'ShiftTop_Fig', ...
  367.                'Def_Btn_Height','Def_Btn_Width','Pop_Min_Width', ...
  368.                'X_Graph_Ratio','X_Spacing','Y_Spacing'           ...
  369.                );
  370.         win_height  = 21*Def_Btn_Height+45*Y_Spacing;
  371.         cmd_width   = Def_Btn_Width+2*Pop_Min_Width+6*X_Spacing;
  372.         win_width   = round(cmd_width/(1-X_Graph_Ratio));
  373.         Screen_Size = get(0,'ScreenSize');
  374.         left_win    = Screen_Size(3)-5-win_width;
  375.         down_win    = Screen_Size(4)-win_height-ShiftTop_Fig;
  376.         pos_win     = [left_win,down_win,win_width,win_height];                 
  377.         varargout   = {pos_win , win_width , win_height , cmd_width};
  378.     case 'dynv'
  379.         %**************************************%
  380.         %** OPTION = 'dynv' :  dynv ON /OFF  **%
  381.         %**************************************%
  382.         % in2 = fig
  383.         %------------------------------------------
  384.         fig    = varargin{1};
  385.         menu   = gcbo;
  386.         oldVal = get(menu,'checked');
  387.         switch oldVal
  388.           case 'on'  , newVal = 'off';
  389.           case 'off' , newVal = 'on';
  390.         end
  391.         set(menu,'Checked',newVal);
  392.         dynvtool('visible',fig,newVal)
  393. case {'storeValue','storevalue'}
  394.         % varargin{2} = name
  395.         % varargin{3} = value
  396.         %--------------------
  397.         fig  = varargin{1};
  398.         memB = wfigmngr('rmb',fig);
  399.         memB.(varargin{2}) = varargin{3};
  400.         wfigmngr('wmb',fig,memB);
  401.         if nargout>0 , varargout = {memB}; end
  402.     case {'getValue','getvalue'}
  403.         fig  = varargin{1};
  404.         memB = wfigmngr('rmb',fig);
  405.         try   , varargout{1} = memB.(varargin{2});
  406.         catch , varargout{1} = [];
  407.         end
  408.     case 'getWinPROP'
  409.         fig = varargin{1};
  410.         nbarg = length(varargin);
  411.         wfigPROP = wtbxappdata('get',fig,'WfigPROP');        
  412.         if nbarg<2 , varargout{1} = wfigPROP; return; end
  413.         notEmpty = ~isempty(wfigPROP);             
  414.         for k = 2:nbarg
  415.            outType = lower(varargin{k});
  416.            switch outType
  417.              case {'makefun','calledfun'}
  418.                if notEmpty
  419.                    varargout{k-1} = wfigPROP.MakeFun;
  420.                else
  421.                    varargout{k-1} = wdumfun;
  422.                end
  423.              case 'figparent'
  424.                if notEmpty
  425.                    varargout{k-1} = wfigPROP.FigParent;
  426.                else
  427.                    varargout{k-1} = [];
  428.                end
  429.              case 'figchild'
  430.                if notEmpty
  431.                    varargout{k-1} = wfigPROP.FigChild;
  432.                else
  433.                    varargout{k-1} = [];
  434.                end
  435.            end
  436.         end
  437.     case 'get'
  438.         fig  = varargin{1};
  439.         nbarg = length(varargin);
  440.         if nbarg<2 , return; end
  441.         for k = 2:nbarg
  442.            outType = lower(varargin{k});
  443.            switch outType
  444.              case 'pos_close'
  445.                pus_close = wfigmngr('getValue',fig,'pus_close');
  446.                if isempty(pus_close)
  447.                    varargout{k-1} = [];
  448.                else
  449.                    varargout{k-1} = get(pus_close,'Position');
  450.                end
  451.              case {'cmd_width','fra_width'}
  452.                [Def_Btn_Width,Pop_Min_Width,X_Spacing] = ...
  453.                   mextglob('get','Def_Btn_Width','Pop_Min_Width','X_Spacing');
  454.                if isequal(outType,'fra_width'), nbx = 3; else nbx = 6; end
  455.                varargout{k-1} = Def_Btn_Width+2*Pop_Min_Width+nbx*X_Spacing;               
  456.            end
  457.         end
  458.     case 'cmb'
  459.         %***********************************************%
  460.         %** OPTION = 'cmb' - create Tool Memory Block **%
  461.         %***********************************************%
  462.         fig = varargin{1};
  463.         wmemtool('ini',fig,n_toolMemB,1);
  464.     case 'wmb'
  465.         %**********************************************%
  466.         %** OPTION = 'wmb' - write Tool Memory Block **%
  467.         %**********************************************%
  468.         fig = varargin{1};
  469.         varargout{1} = wmemtool('wmb',fig,n_toolMemB,1,varargin{2});
  470.     case 'rmb'
  471.         %*********************************************%
  472.         %** OPTION = 'rmb' - read Tool Memory Block **%
  473.         %*********************************************%
  474.         fig = varargin{1};
  475.         varargout{1} = wmemtool('rmb',fig,n_toolMemB,1);
  476.     case 'suppressMenu'
  477.         fig = varargin{1};
  478. nbIn = length(varargin);
  479. k = 2;
  480. while k<nbIn
  481. menuLetter = varargin{k};
  482.     itemToSuppress = varargin{k+1};
  483.     h = getMainMenuHdl(fig,menuLetter);
  484.     suppressMenu(h,itemToSuppress);
  485. k = k+2;
  486. end
  487. case 'add_CCM_Menu'
  488.         fig  = varargin{1};
  489.         m_view = wfigmngr('getmenus',fig,'view');
  490.         m_disp = uimenu(m_view,...
  491. 'Label','Coefficient Coloration Mode', ...
  492. 'Separator','On' ...
  493. );
  494.         m_sub(1) = uimenu(m_disp,...
  495. 'Label','Absolute Mode','Checked','On','Tag','CCM');
  496.         m_sub(2) = uimenu(m_disp,...
  497. 'Label','Normal Mode','Checked','Off','Tag','CCM');
  498. set(m_sub,'Userdata',m_sub,'Callback',@cb_Default_Color_Mode);
  499. case 'get_CCM_Menu'
  500.         fig  = varargin{1};
  501.         m_view = wfigmngr('getmenus',fig,'view');
  502. if isequal(m_view,0) , varargout{1} = 1; return; end
  503. m_chk = findall(m_view,'checked','On','Tag','CCM');
  504. lab = get(m_chk,'label');
  505. switch lower(lab(1))
  506. case 'n' , varargout{1} = 0;
  507. case 'a' , varargout{1} = 1;
  508. end
  509.         
  510.     case 'modify_FigChild'
  511.         fig = varargin{1};
  512.         wfigPROP = wtbxappdata('get',fig,'WfigPROP');
  513.         wfigPROP.FigChild = unique([wfigPROP.FigChild,varargin{2}]);
  514.         idx = ~ishandle(wfigPROP.FigChild);
  515.         wfigPROP.FigChild(idx) = [];
  516.         wtbxappdata('set',fig,'WfigPROP',wfigPROP);
  517.         
  518. otherwise
  519.         errargt(mfilename,'Unknown Option','msg');
  520.         error('*');
  521. end
  522. %=======================================================================%
  523. %=======================================================================%
  524. %   CREATION AND MANAGEMENT OF THE MENUS %
  525. %=======================================================================%
  526. %=======================================================================%
  527. function createMenus(fig,varargin)
  528. % Tag(s)
  529. %------
  530. tag_m_files = 'M_Files';
  531. tag_m_view  = 'M_View';
  532. % Get Default StandardMenus.
  533. %---------------------------
  534. % DefaultStandardMenus = GetDefaultFigureMenus;;
  535. % DefaultStandardMenus = {'F','E','V','I','T','W','H'};
  536. %---------------------------------------------------
  537. % We suppress the "Edit" menu in all windows ...
  538. %---------------------------------------------------
  539. Kept_StandardMenus = {'V','I','T','W','H'};  
  540. nbin = length(varargin);
  541. switch nbin
  542. case 0
  543. win_type = 'None';
  544. StandardMenus = Kept_StandardMenus;
  545. WTBXMenus     = {};
  546. otherwise
  547. win_type = varargin{1};
  548. if isstr(win_type)
  549. switch win_type
  550. case {'ExtMainFig_WTBX','ExtFig_WH'}
  551. WTBXMenus     = {'F'};
  552. StandardMenus = {'W','H'};
  553. case {'ExtFig_DynV'}
  554. WTBXMenus     = {'F'};
  555. StandardMenus = {'W'};
  556. case {'ExtFig_More'}
  557. WTBXMenus     = {};
  558. StandardMenus = {'W','H'};
  559. case {'ExtFig_Tool','ExtFig_Tool_1','ExtFig_Tool_2',...
  560.                   'ExtFig_Tool_3','ExtFig_GUIDE', ...
  561.   'ExtFig_CompDeno','ExtFig_WDisp','ExtFig_ThrSet'}
  562. WTBXMenus     = {'F','O'};
  563. StandardMenus = Kept_StandardMenus;
  564. case {'ExtFig_HistStat'}
  565. WTBXMenus     = {'F'};
  566. StandardMenus = Kept_StandardMenus;
  567.                 
  568.             case {'ExtFig_Demos'}
  569. WTBXMenus     = {'F'};
  570. StandardMenus = Kept_StandardMenus;
  571.                 
  572.             case {'Empty','ExtFig_NoMenu'}
  573. WTBXMenus     = {};
  574. StandardMenus = {};
  575. end
  576. elseif iscell(win_type)
  577. if length(win_type)>1
  578. params = win_type(2:end);
  579. else
  580. params = {};
  581. end
  582. win_type = win_type{1};
  583. else
  584. win_type = 'ExtFig_Gen';  
  585. StandardMenus = varargin{end-1};
  586. if ~iscell(StandardMenus)
  587. StandardMenus = num2cell(StandardMenus);
  588. end
  589. WTBXMenus = varargin{end};
  590. if ~iscell(WTBXMenus)
  591. WTBXMenus = num2cell(WTBXMenus);
  592. end
  593. end
  594. end
  595. if isempty(find(wfindobj('figure')==fig)) , fig = gcf; end
  596. s = dbstack; defineWfigPROP(fig,s)
  597. % Adding Menus.
  598. %==============
  599. if ~isempty(WTBXMenus) | ~isempty(StandardMenus)
  600. showHiddenVal = get(0,'ShowHiddenHandles');
  601. set(0,'ShowHiddenHandles','on');
  602. fig_TEMPO = figure('visible','off');
  603. lst_Menus = [];
  604. % Add Files Menu.
  605. %----------------
  606. ind = find(strncmpi(WTBXMenus,'F',1));
  607. if ~isempty(ind)
  608. h = addMenuFilesWTBX(fig,win_type,tag_m_files);
  609. lst_Menus = [h ; lst_Menus];
  610. end
  611. % Add Standard Menus.
  612. %--------------------
  613. if ~isempty(StandardMenus)
  614. addMenu = {};
  615. for k = 1:length(Kept_StandardMenus)
  616. letter = Kept_StandardMenus{k};
  617. ind = find(strncmpi(StandardMenus,letter,1));
  618. if ~isempty(ind) , addMenu = {addMenu{:},['&' letter]}; end
  619. end
  620. h = addStandardMenus(fig,fig_TEMPO,addMenu{:});
  621. lst_Menus = [lst_Menus ; h];
  622. end
  623. switch win_type 
  624. case {'ExtMainFig_WTBX','ExtFig_WH','ExtFig_DynV',   ...
  625.   'ExtFig_Tool','ExtFig_Tool_1','ExtFig_Tool_2', ...
  626.               'ExtFig_Tool_3','ExtFig_GUIDE', ...
  627.       'ExtFig_ThrSet','ExtFig_WDisp','ExtFig_More','ExtFig_Gen', ...
  628.   'ExtFig_CompDeno','ExtFig_HistStat', ...
  629.               'ExtFig_Demos' ...
  630.   }
  631. % If necessary modify some Menus.
  632. %--------------------------------
  633. lstLabels = get(lst_Menus,'label');
  634. % Modify View Menu.
  635. %------------------
  636. ind = strmatch('&V',lstLabels);
  637. if ~isempty(ind)
  638. m_View = lst_Menus(ind);
  639. set(m_View,'Tag',tag_m_view);
  640. add_DynV_Tool = 0;
  641. if ~isempty(WTBXMenus)
  642. ok_DynV = find(strncmpi(WTBXMenus,'O',1));
  643. if ~isempty(ok_DynV) , add_DynV_Tool = 1; end
  644. end
  645. setMenuView(m_View,add_DynV_Tool);
  646. end
  647. % Modify Insert Menu.
  648. %--------------------
  649. ind = strmatch('&I',lstLabels);
  650. if ~isempty(ind) , setMenuInsert(lst_Menus(ind)); end
  651. % Modify Tools Menu.
  652. %------------------
  653. ind = strmatch('&T',lstLabels);
  654. if ~isempty(ind) , setMenuTools(lst_Menus(ind)); end
  655. % Modify Help Menu.
  656. %------------------
  657. ind = strmatch('&H',lstLabels);
  658. if ~isempty(ind)
  659.                 wfighelp('set',lst_Menus(ind),win_type);
  660.             end
  661. end
  662. delete(fig_TEMPO)
  663. set(0,'ShowHiddenHandles',showHiddenVal);
  664. end
  665. % Set Default 'WindowButtonMotionFcn'.
  666. %-------------------------------------
  667. set(fig,'WindowButtonMotionFcn','wtmotion');
  668. % Prevent extrat plots.
  669. set(fig,'HandleVisibility','Callback')
  670. % End Of WTBMENUS
  671. %=======================================================================%
  672. %====================  ADDING and SETTING MENUS ========================%
  673. %---------------------------------------------------------------------%
  674. function h = addMenuFilesWTBX(fig,win_type,tag_m_files)
  675. % Configuration of standard "Files" menu (reverse order).
  676. %--------------------------------------------------------
  677. lab_child = {... 
  678.     '&Print...', % num = 1
  679.     'Print Pre&view...', % num = 2
  680.     'Print Set&up...',     % num = 3
  681.     'Pa&ge Setup...', % num = 4
  682.     'Pre&ferences...', % num = 5
  683.     'E&xport...', % num = 6 ('&Export')
  684.     'Save &As...', % num = 7
  685.     '&Save', % num = 8
  686.     '&Close', % num = 9
  687.     '&Open...', % num = 10
  688.     '&New Figure' % num = 11
  689. };
  690. % Modification of some labels.
  691. %-----------------------------
  692. lab_child{7} = 'Figure &As...';
  693. lab_child{8} = '&Figure'; 
  694. cb_child = {...
  695. 'printdlg(gcbf)',                                                                      
  696. 'printpreview(gcbf)',                                                                  
  697. 'printdlg(''-setup'')',                                                                 
  698. 'pagesetupdlg(gcbf)',                                                                  
  699. 'preferences',                                                                         
  700. 'filemenufcn(gcbf,''FileExport'')',                                                      
  701. 'filemenufcn(gcbf,''FileSaveAs'')',                                                      
  702. 'filemenufcn(gcbf,''FileSave'')',                                                        
  703. 'close(gcbf)',                                                                         
  704. 'filemenufcn(gcbf,''FileOpen'')',                                                        
  705. 'figure' 
  706. };
  707. h = uimenu(fig,...
  708. 'Label','&File',  ...
  709. 'Position',1,     ...
  710. 'Tag',tag_m_files ...
  711. );
  712. switch win_type
  713. case {'ExtFig_Tool'}
  714. ok_Load = 1; ok_Save = 1;
  715. case {'ExtFig_Tool_1'}
  716. ok_Load = 1; ok_Save = 0;
  717. case {'ExtFig_Tool_2',...
  718.   'ExtFig_CompDeno'}
  719. ok_Load = 0; ok_Save = 1;
  720. case {'ExtFig_Tool_3','ExtFig_GUIDE', ...
  721.   'ExtFig_HistStat','ExtFig_ThrSet','ExtFig_WDisp'}
  722. ok_Load = 0; ok_Save = 0;
  723. otherwise
  724. ok_Load = 0; ok_Save = 0;
  725. end
  726. % Add Load Menu.
  727. %---------------
  728. if ok_Load
  729. m_load = uimenu(h,'Label','&Load','Position',1);
  730. end
  731. % Add Save Menu and SubMenus.
  732. %----------------------------
  733. if ok_Save
  734. if ok_Load , pos = 2; else , pos = 1; end
  735. m_save = uimenu(h,'Label','&Save','Position',pos);
  736.     flag_sub_Save = 0;
  737. if flag_sub_Save
  738. idx_child = [7,8];
  739. switch win_type
  740. case {'ExtFig_HistStat','ExtFig_WDisp','ExtFig_ThrSet'}
  741. sep_child = {'Off','Off'};
  742. otherwise
  743. sep_child = {'On','Off'};
  744. end
  745. addChildren(m_save, ...
  746. lab_child(idx_child),sep_child,cb_child(idx_child));
  747. end
  748. end
  749. % Add Open & Export Menus.
  750. %-------------------------
  751. flag_Open_Export = 1;
  752. if flag_Open_Export
  753.     switch win_type
  754. case {'ExtFig_Tool','ExtFig_Tool_1','ExtFig_Tool_2', ...
  755.               'ExtFig_Tool_3','ExtFig_GUIDE', ...
  756.   'ExtFig_WH','ExtFig_ThrSet','ExtFig_WDisp', ...
  757.   'ExtFig_CompDeno','ExtFig_HistStat','ExtFig_Demos'}
  758. idx_child = [6];
  759. switch win_type
  760. case {'ExtFig_HistStat','ExtFig_ThrSet','ExtFig_WDisp','ExtFig_Demos'}
  761. sep_child = {'Off'};
  762. otherwise
  763. sep_child = {'On'};
  764. end
  765. if isequal(win_type,'ExtFig_WH'), sep_child{1} = 'Off'; end
  766. addChildren(h, ...
  767. lab_child(idx_child),sep_child,cb_child(idx_child));
  768.     end
  769. end
  770. % Add Print Menus.
  771. %-----------------
  772. switch win_type
  773. case 'ExtMainFig_WTBX'
  774. idx_child = [5,1];
  775. sep_child = {'Off','Off','Off'};
  776. sep_close = 'On';
  777. m_Parent = h;
  778. case {'ExtFig_Tool','ExtFig_Tool_1','ExtFig_Tool_2', ...
  779.           'ExtFig_Tool_3','ExtFig_GUIDE', ...
  780.   'ExtFig_WH','ExtFig_WDisp','ExtFig_CompDeno','ExtFig_HistStat', ...
  781.   'ExtFig_ThrSet','ExtFig_Demos'}
  782. idx_child = [4,3,2,1];
  783. sep_child = {'Off','Off','Off','Off'};
  784. sep_close = 'On';
  785. m_Parent = uimenu(h, ...
  786. 'Label','&Print Tools', ...
  787. 'Separator','On' ...
  788. );
  789. otherwise
  790. sep_close = 'Off';
  791. idx_child = []; sep_child = []; 
  792. m_Parent = h;
  793. end
  794. addChildren(m_Parent, ...
  795. lab_child(idx_child),sep_child,cb_child(idx_child));
  796. % Add Close Menu.
  797. %----------------
  798. cb_Close = ['try , delete(' sprintf('%20.15f',fig) '); end;'];
  799. uimenu(h,...
  800.         'Label','&Close',      ...
  801.         'Separator',sep_close, ...
  802.         'CallBack',cb_Close    ...
  803.         );
  804. %---------------------------------------------------------------------%
  805. function addChildren(par,lab_child,sep_child,cb_child)
  806. for k = 1:length(lab_child)
  807. uimenu(par,...
  808. 'Label',lab_child{k},     ...
  809. 'Separator',sep_child{k}, ...
  810. 'CallBack',cb_child{k}    ...
  811. );
  812. end
  813. %---------------------------------------------------------------------%
  814. function liste = addStandardMenus(fig,fig_TEMPO,varargin)
  815. LstMenusInFig  = findall(get(fig,'Children'),'flat','type','uimenu');
  816. lstLabelsInFig = get(LstMenusInFig,'label');
  817. lstMenus  = findall(get(fig_TEMPO,'Children'),'flat','type','uimenu');
  818. lstLabels = get(lstMenus,'label');
  819. liste = [];
  820. for k=1:length(varargin)
  821.     lab = varargin{k};
  822.     ind = strmatch(lab,lstLabelsInFig);
  823.     if isempty(ind)
  824.         ind = strmatch(lab,lstLabels);
  825.         if ~isempty(ind)
  826.             liste = [liste ; lstMenus(ind)];
  827.         end
  828.     end
  829. end
  830. if ~isempty(liste) , liste = copyMenu(liste,fig); end
  831. %---------------------------------------------------------------------%
  832. %================== GENERAL SETTINGS FOR MAIN MENUS ====================%
  833. %---------------------------------------------------------------------%
  834. function setMenuView(h,Add_DynV_Tool)
  835. % Tag and Label for DynVTool.
  836. %----------------------------
  837. tag_m_dynv = 'M_Zoom';
  838. lab_m_dynv = 'Dynamical Visualization Tool';
  839. % Get information and ...
  840. %------------------------
  841. c = get(h,'Children');
  842. lab = get(c,'Label');
  843. idx_Cam = [strmatch('&C',lab)];
  844. idx_Fig = [strmatch('&F',lab)];
  845. set(c(idx_Fig),'Checked','Off','Callback',@cb_FigToolBar);
  846. if ~Add_DynV_Tool
  847. m_dynv = findmenu(c,lab_m_dynv);
  848. if m_dynv~=0 , Add_DynV_Tool = 0; end
  849. end
  850. % Suppress Camera Toolbar.
  851. %-------------------------
  852. if ~isempty(idx_Cam) , delete(c(idx_Cam)); end
  853. % Add DynVTool if necessary.
  854. %---------------------------
  855. if Add_DynV_Tool
  856. uimenu(h,...
  857.            'Label',lab_m_dynv, ...
  858.    'Separator','On',   ...
  859.            'Checked','on',     ...
  860.            'callback',@cb_DynVTool, ...
  861.            'tag',tag_m_dynv    ...
  862.            );
  863. end
  864. %---------------------------------------------------------------------%
  865. function cb_FigToolBar(hco,eventStruct)
  866. menu = gcbo;
  867. oldVal = get(menu,'checked');
  868. switch oldVal
  869.   case 'on'  , newVal = 'off';
  870.   case 'off' , newVal = 'on';
  871. end
  872. set(menu,'Checked',newVal);
  873. domymenu('menubar','toggletoolbar',gcbf) 
  874. %---------------------------------------------------------------------%
  875. function cb_DynVTool(hco,eventStruct)
  876. menu = gcbo;
  877. oldVal = get(menu,'checked');
  878. switch oldVal
  879.   case 'on'  , newVal = 'off';
  880.   case 'off' , newVal = 'on';
  881. end
  882. set(menu,'Checked',newVal);
  883. dynvtool('visible',gcbf,newVal)    
  884. %---------------------------------------------------------------------%
  885. function setMenuInsert(h)
  886. c = get(h,'Children');
  887. lab = get(c,'Label');
  888. ind = [
  889. strmatch('&C',lab); strmatch('&L',lab);   ...  
  890. strmatch('&A',lab); findSubSTR('&i',lab); ...
  891. ];
  892. if ~isempty(ind) , delete(c(ind)); end
  893. %---------------------------------------------------------------------%
  894. function setMenuTools(h)
  895. c = get(h,'Children');
  896. lab = get(c,'Label');
  897. ind = [
  898. strmatch('&E',lab);   findSubSTR('&C',lab);    ...
  899. findSubSTR('&M',lab); findSubSTR('&x',lab); findSubSTR('&s',lab); ...
  900. strmatch('&B',lab);   strmatch('&D',lab);...
  901. ];
  902. if ~isempty(ind) , delete(c(ind)); end
  903. %---------------------------------------------------------------------%
  904. function cb_Default_Color_Mode(hco,eventStruct) % Menu Preference
  905. ud = get(hco,'Userdata');
  906. idx = find(ud==hco);
  907. set(ud(idx),'Checked','On');
  908. set(ud(3-idx),'Checked','Off');
  909. %---------------------------------------------------------------------%
  910. %=======================================================================%
  911. %=================== MODIFICATIONS FOR MAIN MENUS ======================%
  912. %---------------------------------------------------------------------%
  913. function suppressMenu(h,toSuppress)
  914. c = get(h,'Children');
  915. lab = lower(get(c,'Label'));
  916. toSuppress = lower(toSuppress);
  917. ind = [];
  918. for k = 1:length(toSuppress)
  919. item = toSuppress{k};
  920. indItem = [];
  921. for j = 1:length(lab)
  922. S = lab{j};
  923. dum = findstr(S,item);
  924. if ~isempty(dum) , indItem = j; break; end
  925. end
  926. ind = [ind ; indItem];
  927. end
  928. if ~isempty(ind) , delete(c(ind)); end
  929. %---------------------------------------------------------------------%
  930. %=======================================================================%
  931. %========================= TOOLS FOR  MENUS ============================%
  932. %---------------------------------------------------------------------%
  933. function [DefaultStandardMenus,NBStandardMenus] = GetDefaultFigureMenus
  934. % Use only once for a new version to find menu items.
  935. %-----------------------------------------------------------------
  936. % {'F','E','V','I','T','W','H'} for MATLAB Version 6.0.0.88 (R12)
  937. %-----------------------------------------------------------------
  938. showHiddenVal = get(0,'ShowHiddenHandles');
  939. set(0,'ShowHiddenHandles','on');
  940. fig_TEMPO = figure('visible','off');
  941. lstMenus  = findall(get(fig_TEMPO,'Children'),'flat','type','uimenu');
  942. lstLabels = get(lstMenus,'label');
  943. NBStandardMenus = length(lstLabels);
  944. DefaultStandardMenus = cell(1,NBStandardMenus);
  945. for k=1:NBStandardMenus
  946.     DefaultStandardMenus{k} = lstLabels{k}(2);
  947. end
  948. DefaultStandardMenus = fliplr(DefaultStandardMenus);
  949. delete(fig_TEMPO);
  950. set(0,'ShowHiddenHandles',showHiddenVal);
  951. %---------------------------------------------------------------------%
  952. function h = getMainMenuHdl(fig,item)
  953. lstMenus  = findall(get(fig,'Children'),'flat','type','uimenu');
  954. lstLabels = get(lstMenus,'label');
  955. for k=1:length(lstMenus)
  956.     if isequal(lstLabels{k}(2),item) , h = lstMenus(k); break; end
  957. end
  958. %---------------------------------------------------------------------%
  959. function h = findmenu(lst,item)
  960. %FINDMENU Find menu item.
  961. %   h = findmenu(lst,item)
  962. %   h is the handle of the uimenu which label is item.
  963. %   The search is restricted to the list lst.
  964. %   If no uimenu is found, 0 is returned.
  965. h = 0;
  966. item = lower(item(find(item~=32  & item~='&')));
  967. for k = 1:length(lst)
  968.     lab = get(lst(k),'label');
  969.     lab = lower(lab(find(lab~=' ' & lab~='&')));
  970.     if isequal(lab,item) , h = lst(k); break; end
  971. end
  972. %---------------------------------------------------------------------%
  973. function ind = findSubSTR(sub,S)
  974. ind = [];
  975. for k = 1:length(S)
  976. dum = findstr(S{k},sub);
  977. if ~isempty(dum) , ind = k; break; end
  978. end
  979. %---------------------------------------------------------------------%
  980. function liste = copyMenu(liste,cible)
  981. for k=1:length(liste)
  982.     m = liste(k);
  983.     c = findall(m,'type','uimenu','parent',m);
  984.     c = flipud(c);
  985.     m = copyobj(m,cible);
  986.     if ~isempty(c) , copyMenu(c,m); end
  987.     liste(k) = m;
  988. end
  989. set(liste,'HandleVisibility','on');
  990. %---------------------------------------------------------------------%
  991. %=======================================================================%
  992. %=======================================================================%
  993. %=======================================================================%
  994. %---------------------------------------------------------------------%
  995. function defineWfigPROP(fig,s,flag)
  996. wfigPROP = wtbxappdata('get',fig,'WfigPROP');
  997. if ~isempty(wfigPROP) & (nargin<3) , return; end
  998. switch length(s)
  999.   case 0 ,    return
  1000.   case 1 ,    ind = 1;
  1001.   otherwise , ind = 2;
  1002. end
  1003. [path,name,ext,ver] = fileparts(s(ind).name);
  1004. figParent = gcbf;
  1005. wfigPROP  = struct('MakeFun',name,'FigParent',figParent,'FigChild',[]);
  1006. wtbxappdata('set',fig,'WfigPROP',wfigPROP);
  1007. if ~isempty(figParent)
  1008.     wfigPROP = wtbxappdata('get',figParent,'WfigPROP');
  1009.     if ~isempty(wfigPROP)
  1010.         wfigPROP.FigChild = unique([wfigPROP.FigChild,fig]);
  1011.         idx = ~ishandle(wfigPROP.FigChild);
  1012.         wfigPROP.FigChild(idx) = [];
  1013.         wtbxappdata('set',figParent,'WfigPROP',wfigPROP);
  1014.     end
  1015. end
  1016. %---------------------------------------------------------------------%
  1017. %=======================================================================%