Module cSigCJContextMenu.pkg

     1//==============================================================================
     2// Project      : SigCj - VDF Classes for Codejock
     3// File         : cSigCJContextMenu.pkg
     4// Description  : VDF Class for Codejock control
     5//
     6// Revision     : $Rev: 688 $
     7//                $Date: 2011-03-17 08:23:41 -0400 (Thu, 17 Mar 2011) $
     8//                $Author: martin $ Martin Pincott
     9// 
    10// Requirements : Visual DataFlex 12.1+
    11//                Codejock SuitePro - Version 12.0.0+
    12//
    13// Copyright    : (c) 2008 VDF SIG UK
    14//                Visual DataFlex Special Interest Group UK.
    15//                http://www.vdfsig.co.uk/
    16//                dev@vdfsig.co.uk
    17//
    18//                This file is part of SigCj.
    19//
    20//                SigCj is free software: you can redistribute it and/or modify
    21//                it under the terms of the GNU Lesser General Public License 
    22//                as published by the Free Software Foundation, either version 
    23//                2.1 of the License, or (at your option) any later version.
    24//
    25//                SigCj is distributed in the hope that it will be useful, but 
    26//                WITHOUT ANY WARRANTY; without even the implied warranty of
    27//                MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    28//                GNU Lesser General Public License for more details.
    29//
    30//                If you have the complete SigCj workspace then a copy of the  
    31//                GNU Lesser General Public License is in the Docs folder. If  
    32//                not, see <http://www.gnu.org/licenses/>.
    33//    
    34//==============================================================================
    35
    36Use cCJCommandBarSystem.pkg
    37Use cSigCJMenuItem.pkg
    38Use cSigCJMethods_Mixin.pkg
    39
    40{ DesignerClass = cDTCJContextMenu }
    41Class cSigCJContextMenu is a cCJContextMenu
    42    Import_Class_Protocol cSigCJMethods_Mixin
    43    
    44    Procedure Construct_Object
    45        Forward Send Construct_Object
    46
    47        // Define new Properties:
    48        { DesignTime=False }
    49        Property String[][] psaMenuItem
    50
    51    End_Procedure
    52
    53    Procedure End_Construct_Object
    54        Forward Send End_Construct_Object
    55
    56        Send OnAdd_MenuItems
    57    End_Procedure // End_Construct_Object
    58    
    59    // Hook 
    60    Procedure OnAdd_MenuItems
    61    End_Procedure
    62
    63    // Create and augment procedures and functions
    64    Procedure Popup
    65        Send OnPopup
    66        Forward Send Popup
    67    End_Procedure
    68    
    69    // Hook 
    70    Procedure OnPopup
    71    End_Procedure    
    72    
    73    { DesignTime=False }
    74    Procedure Add_MenuItem String sCaption String sMessage Boolean bBeginGroup_Optional String sImage_Optional
    75        Handle     hoMenuItem
    76	    String	sImage
    77        Boolean bBeginGroup
    78        
    79        Move False to bBeginGroup
    80        If (num_arguments >= 3) ;
    81            Move bBeginGroup_Optional to bBeginGroup
    82            
    83        Move "" to sImage
    84        If (num_arguments >= 4) ;
    85            Move sImage_Optional to sImage            
    86
    87        Get phAdd_MenuItem sCaption sMessage bBeginGroup sImage to hoMenuItem
    88    End_Procedure //Add_MenuItem String sCaption String sMessage Boolean bBeginGroup_Optional String sImage_Optional
    89
    90
    91    { DesignTime=False }
    92    Function phAdd_MenuItem String sCaption String sMessage Boolean bBeginGroup String sImage Returns Handle 
    93        Integer    iArraySize iCount
    94        Handle     hoMenuItem
    95        String[][] saMenuItem
    96        
    97        Get psaMenuItem to saMenuItem
    98        Move (SizeOfArray(saMenuItem)) to iArraySize
    99
   100        // Check to see if menu item has already been loaded
   101        // if so just return the handle of the menu item
   102        For iCount from 0 to (iArraySize-1)
   103            If (Trim(sCaption) = saMenuItem[iCount][0]) Begin
   104                Function_Return saMenuItem[iCount][1]        
   105            End
   106        Loop
   107
   108        Get Create U_cSigCJMenuItem to hoMenuItem
   109        If (Trim(sImage)   <> "") Set psImage   of hoMenuItem to (Trim(sImage))
   110        If (Trim(sCaption) <> "") Set psCaption of hoMenuItem to (Trim(sCaption))
   111        If (Trim(sMessage) <> "") Set psMessage of hoMenuItem to (Trim(sMessage))
   112        If (bBeginGroup)          Set pbControlBeginGroup of hoMenuItem to True
   113        
   114        Move (Trim(sCaption)) to saMenuItem[iArraySize][0]
   115        Move hoMenuItem       to saMenuItem[iArraySize][1]
   116        
   117        Set psaMenuItem to saMenuItem
   118        Function_Return hoMenuItem 
   119    End_Function    //-- pAdd_MenuItem
   120    
   121    
   122    { DesignTime=False }
   123    Procedure Set Enabled String sCaption Boolean bState
   124        Integer    iArraySize iCount iIndex
   125        Handle     hoMenuItem
   126        String[][] saMenuItem
   127        String     sMenuItem
   128        
   129        Get psaMenuItem to saMenuItem
   130        Move (SizeOfArray(saMenuItem)) to iArraySize
   131        
   132        For iCount from 0 to (iArraySize-1)
   133            Move saMenuItem[iCount][0] to sMenuItem
   134            Move saMenuItem[iCount][1] to hoMenuItem
   135            If (sMenuItem = sCaption) Begin
   136                // Showln hoMenuItem " ... " sMenuItem
   137                Set pbEnabled of hoMenuItem to bState
   138            End    
   139        Loop
   140    End_Procedure
   141    
   142    { DesignTime=False }
   143    Procedure Set Checked String sCaption Boolean bState
   144        Integer    iArraySize iCount iIndex
   145        Handle     hoMenuItem
   146        String[][] saMenuItem
   147        String     sMenuItem
   148        
   149        Get psaMenuItem to saMenuItem
   150        Move (SizeOfArray(saMenuItem)) to iArraySize
   151        
   152        For iCount from 0 to (iArraySize-1)
   153            Move saMenuItem[iCount][0] to sMenuItem
   154            Move saMenuItem[iCount][1] to hoMenuItem
   155            If (sMenuItem = sCaption) Begin
   156                // Showln hoMenuItem " ... " sMenuItem
   157                Set pbChecked of hoMenuItem to bState
   158            End    
   159        Loop
   160    End_Procedure
   161    
   162    { DesignTime=False }
   163    Procedure Set Visible String sCaption Boolean bState
   164        Integer    iArraySize iCount iIndex
   165        Handle     hoMenuItem
   166        String[][] saMenuItem
   167        String     sMenuItem
   168        
   169        Get psaMenuItem to saMenuItem
   170        Move (SizeOfArray(saMenuItem)) to iArraySize
   171        
   172        For iCount from 0 to (iArraySize-1)
   173            Move saMenuItem[iCount][0] to sMenuItem
   174            Move saMenuItem[iCount][1] to hoMenuItem
   175            If (sMenuItem = sCaption) Begin
   176                // Showln hoMenuItem " ... " sMenuItem
   177                Set pbVisible of hoMenuItem to bState
   178            End    
   179        Loop
   180    End_Procedure
   181
   182    //Almost a copy of the standard DAW PopUp method
   183    Procedure DropDown Integer iLoc Integer iWidth
   184        Handle hoCommandBars
   185        Integer iId
   186
   187        Get CommandBarSystemObject to hoCommandBars
   188        If (hoCommandBars=0) Begin
   189            Error DFERR_PROGRAM "Context menu not attached to commandbars"
   190            Procedure_Return
   191        End
   192        
   193        // this will create the context menu and return it attached.
   194        Send CreatePopupComInstance 
   195
   196        Set ComWidth to iWidth
   197        Get ComShowPopup OLE_VT_Empty (low(iLoc)) (hi(iLoc)) to iID
   198        // This releases all actions (which will still exist on the COM side)
   199        // and controls (controls should already be released on both DF and COM side)
   200        Broadcast Recursive_up Send ReleaseComObject
   201        Send ReleaseComObject // after popup CJ deletes the controls, so we release this
   202    End_Procedure
   203
   204End_Class
   205
   206//==============================================================================
   207//End of Package - cSigCJContextMenu.pkg
   208//==============================================================================
   209