FB II Compiler

PG PRO

Debugging

Memory

System

Mathematics

Resources

Disk I/O

Windows

Controls

Menus

Mouse

Keyboard

Text

Fonts

Drawing

Sound

Clipboard

Printing

Communication

ASM

Made with FB

PG PRO

Use copy & paste with modal windows


I have done. But I don't know it works on English environment.
Please replace "Edit Menu.FLTR".
INCLUDE FILE _aplIncl
GLOBALS "Runtime.GLBL"
COMPILE 0,_pGproject_dimmedVarsOnly
END GLOBALS
'-----------------------------------------
GOTO "Edit Menu.FLTR"
'-----------------------------------------
DEF FN pGfindMenu(theTitle$) USING GLBLfindMenu&
_EMUndoItem      = 1
_EMCutItem       = 3
_EMCopyItem      = 4
_EMPasteItem     = 5
_EMClearItem     = 6
_EMSelectAllItem = 7

'=================
LOCAL FN EMenableUndo
  '---------------------------------------
  ' Save current field for later undo.
  '---------------------------------------
  DIM theField,t$,editMenu

  theField = WINDOW(_EFnum)
  DEF DISPOSEH(gUndoHndl&)
  LONG IF theField
    LONG IF WINDOW(_EFTextLen)
      t$ = STR#(_baseID - 3,1)
      editMenu   = FN pGfindMenu(t$)
      GET FIELD gUndoHndl&,theField
      gUndoStart = WINDOW(_selStart)
      gUndoEnd   = WINDOW(_selEnd)
    END IF
  END IF
END FN

'=================
LOCAL FN EMautoMenu
  '---------------------------------------
  ' Decide when to set up undo.
  '---------------------------------------
  DIM mHndl&,t$,theItem$

  mHndl& = FN GETMHANDLE(gWhichMenu)
  LONG IF mHndl&
    t$ = mHndl&..menuData$
    SELECT t$                                     'Font,Size,Style
      CASE STR#(_baseID - 4,1),STR#(_baseID - 4,2),STR#(_baseID - 4,3)
        FN EMenableUndo
        gUndoable = _zTrue
      CASE STR#(_baseID - 3,1)
        CALL GETITEM(mHndl&,gWhichItem,theItem$)
        SELECT theItem$
          CASE STR#(_baseID - 3,2)                '"Undo"
            EDIT FIELD WINDOW(_EFnum),&gUndoHndl&
            SETSELECT gUndoStart,gUndoEnd
            gUndoable = _false
          CASE STR#(_baseID - 3,3)                '"Select All"
            LONG IF WINDOW(_EFnum)
              SETSELECT 0,WINDOW(_EFTextLen)
            END IF
        END SELECT
    END SELECT
  END IF
END FN

'=================
LOCAL FN EMfixEditMenu
  '---------------------------------------
  ' Enable/disable edit menu items.
  '---------------------------------------
  DIM selAllItem,lastItem,editMenu,mHndl&
  DIM itemCount,thisItem,theField,x,t$
  DIM selAllItem$
  selAllItem       = 0
  lastItem         = _EMClearItem
  t$               = STR#(_baseID - 3,1)
  editMenu         = FN pGfindMenu(t$)
  mHndl&           = FN GETMHANDLE(editMenu)
  LONG IF mHndl&

    itemCount      = FN COUNTMITEMS(mHndl&)

    ' See if menu contains "Select All"

    selAllItem$    = STR#(_baseID - 3,3)
    selAllItem$    = UCASE$(selAllItem$)
    FOR thisItem   = 1 TO itemCount
      CALL GETITEM(mHndl&,thisItem,t$)
      LONG IF UCASE$(t$) = selAllItem$
        selAllItem = thisItem
        thisItem   = itemCount
      END IF
    NEXT
    '
    LONG IF gActiveWnd%
      IF selAllItem THEN MENU editMenu,selAllItem,_disable

      ' DA is currently in front

      LONG IF SYSTEM(_aplActive) = 0
        t$ = STR#(_baseID - 3,2)
        MENU editMenu,_EMUndoItem,_enable,t$
        'MENU editMenu,_EMUndoItem ,_enable,"Undo"
        MENU editMenu,_EMCutItem  ,_enable
        MENU editMenu,_EMCopyItem ,_enable
        MENU editMenu,_EMPasteItem,_enable
        MENU editMenu,_EMClearItem,_enable
      XELSE

        ' This application is currently in front

        LONG IF WINDOW(_activeWnd) = 0 OR gUndoHndl& = 0 OR gUndoable = 0
          t$ = STR#(_baseID - 3,4)
          MENU editMenu,_EMUndoItem,_disable,t$
        XELSE
          t$ = STR#(_baseID - 3,2)
          MENU editMenu,_EMUndoItem,_enable,t$
        END IF
        FOR x = _EMCutItem TO _EMClearItem
          MENU editMenu,x,0
        NEXT

        ' Check for text/picture on clipboard

        theField = WINDOW(_EFnum)
        LONG IF theField
          LONG IF WINDOW(_textClip)
            MENU editMenu,_EMPasteItem,_enable
          END IF
          LONG IF WINDOW(_EFTextLen)
            LONG IF WINDOW(_selStart) <> WINDOW(_selEnd)
              MENU editMenu,_EMCutItem   ,_enable
              MENU editMenu,_EMCopyItem  ,_enable
              MENU editMenu,_EMClearItem ,_enable
            END IF
            IF selAllItem THEN MENU editMenu,selAllItem,_enable
          END IF
        END IF
      END IF
    XELSE
      t$ = STR#(_baseID - 3,4)
      MENU editMenu,_EMUndoItem ,_disable,t$
      MENU editMenu,_EMCutItem  ,_disable
      MENU editMenu,_EMCopyItem ,_disable
      MENU editMenu,_EMPasteItem,_disable
      MENU editMenu,_EMClearItem,_disable
      '
      IF selAllItem THEN MENU editMenu,selAllItem,_disable
    END IF
  END IF
END FN

LOCAL FN SetModalMenus(inModal)
  DIM Storage&
  DIM i,theMenu,editMenu,t$
  DIM mhndl&,BitPtr&,EditMenuBits&

  t$       = STR#(_baseID - 3,1)
  editMenu = FN pGfindMenu(t$)
  '
  Storage& = LINE "Storage" + 4
  FOR i = 0 TO 15
    theMenu = i : IF theMenu = 0 THEN theMenu = _AppleResMenu
    mhndl& = FN GETMHANDLE(theMenu)
    LONG IF mhndl&
      BitPtr& = [mhndl&]+_Menuenable + 3
      LONG IF inModal
        POKE Storage& + i,PEEK(BitPtr&)           'Save Old state
        LONG IF i <> editMenu                     'Edit Menu?
          POKE BitPtr&,PEEK(BitPtr&) AND &FE      'Disable Menu
        XELSE
          EditMenuBits& = [BitPtr&-3]             'Menu Enable Bits
          & LINE "Storage"-4 , EditMenuBits&      'Save edit menu Items
          LONG IF WINDOW(_EFnum)                  'Has Edit Filed?
            & BitPtr&-3 ,&F9                      'Enable Edit menu
          XELSE
            & BitPtr&-3 ,&FE                      'Disable Edit menu
          END IF
        END IF
      XELSE
        LONG IF i <> editMenu                     'Edit Menu?
          POKE BitPtr&,PEEK(Storage& + i)         'Restore Old State
        XELSE
          & BitPtr&-3,[LINE "Storage"-4]          'Restore edit menu Items
        END IF
      END IF
    END IF
  NEXT
  CALL DRAWMENUBAR
END FN

'=================
LOCAL
"EM:EditMenuItemStateStorage"
MACHLG 0,0
"Storage"
"EM:IsModal"
MACHLG 0,0
"EM:MenuStateStorage"
MACHLG 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
LOCAL FN EMcheckScrapSize
  '---------------------------------------
  ' Make sure text paste does not exceed
  ' the 32K limit of TextEdit.
  '---------------------------------------
  DIM theSize&,offSet&,editMenu,t$
  DIM wPtr&
  DIM Flags&;0,IsModal%,lastWnd%
  DIM char
  DIM menuLong&
  DIM NewWnd,NowModal

  Flags&  = [LINE "Storage"]
  SELECT CASE gWhat%
    CASE _ActivateEvt,_UpdatEvt,_Nullevt          '**** Null Events ****
      NewWnd% = WINDOW (_ActiveWnd)
      LONG IF lastWnd% <> NewWnd%                 ' active window has changed?
        lastWnd% = NewWnd%
        LONG IF NewWnd% = _NIL                    ' there is no window
          IsModal% = _false                       ' trun off modal handling
          FN SetModalMenus(IsModal%)              ' restore menus
        XELSE
          GET WINDOW NewWnd%,wPtr&
          NowModal% = (wPtr&.wRefCon& AND &8000) <> 0
          LONG IF NowModal% <> IsModal%           ' modal, normal switch has occured?
            IsModal% = NowModal%
            FN SetModalMenus(IsModal%)            ' switch menu mode
          END IF
        END IF
        '
        & LINE "Storage",Flags&
      END IF
    CASE _Keydwnevt,_AutoKeyEvt                   ' key inputs
      LONG IF IsModal%                            ' modal?
        LONG IF EVENT% AND _CmdKey%               ' cmd key pressed?
          char = PEEK(EVENT+_EvtMessage+3)        ' chk the key
          LONG IF char <> _"."                    ' if not period, continue
            ' i have no idea to handle undo routine in modal mode.
            ' does anybody have good idea?
            DEF DISPOSEH (gUndoHndl&)             ' dispose undo
            FN EMfixEditMenu                      ' fix menu
            menuLong& = FN MENUKEY(char)          ' key to menu evnt
            LONG IF menuLong&                     ' not nil?
              % EVENT , 16                        ' store as menu evnt
              & EVENT + _Evtmouse, menuLong&
            XELSE
              % EVENT , 0                         ' make it null evnt
            END IF
          END IF
        END IF
      END IF
    CASE _Mbutdwnevt
      LONG IF IsModal%
        LONG IF FN FINDWINDOW(gWhereY%,wPtr&) = _inMenuBar' menu bar clickd?
          DEF DISPOSEH (gUndoHndl&)
          FN EMfixEditMenu
          menuLong& = FN MENUSELECT(gWhereY%)
          LONG IF menuLong&
            % EVENT , 16
            & EVENT + _Evtmouse, menuLong&
          XELSE
            % EVENT , 0
          END IF
        END IF
      END IF
    CASE 16
      t$ = STR#(_baseID - 3,1)
      editMenu = FN pGfindMenu(t$)
      LONG IF gWhereY = editMenu
        LONG IF gWhereX = _EMPasteItem
          theSize& = FN GETSCRAP(0,_"TEXT",offSet&)
          LONG IF theSize& + WINDOW(_EFTextLen) > 32750&
            % EVENT,0
            EVENT% = 7
            DIALOG = _showErr                     ' ouch, fld overflow
          END IF
        END IF
      END IF
  END SELECT
END FN

'=================
"Edit Menu.FLTR"
'=================
SELECT gLongAction&
  CASE _menuLong       : FN EMautoMenu
  CASE _mShutdown      : DEF DISPOSEH (gUndoHndl&)
  CASE _oAdjustMenu    : FN EMfixEditMenu
  CASE _oEvents,_oNull : FN EMcheckScrapSize
  CASE _wActivate      : FN EMenableUndo
  CASE _fActivate      : FN EMenableUndo : gUndoable = _false
  CASE _fChange        : FN EMenableUndo : gUndoable = _zTrue
  CASE _fKeypress                        : gUndoable = _zTrue
    LONG IF WINDOW(_selStart) < WINDOW(_selEnd)
      FN EMenableUndo
    END IF
    LONG IF WINDOW(_EFTextLen) > 32750&
      gKey$   = ""
      gAction = 0
      EVENT%  = 8
      DIALOG  = _showErr
    END IF
END SELECT
'=================
IF 0 THEN RETURN
Osamu Shigematsu