*************************************
CLASS MyHTMLViewer FROM XbpHTMLViewer
*************************************
PROTECTED:
   VAR oBarCCN
   VAR oSubMenu
   VAR _interface
   VAR _document

EXPORTED:
   VAR oBotonEdit
   VAR oBotonNew

   INLINE METHOD destroy
   *********************
      ::oBarCCN:= ::oSubMenu:= ::oBotonEdit:= ::oBotonNew:= nil
      ::XbpHTMLViewer:destroy()

      IF Valtype( ::_document ) = 'O'
         ::_document:unSubscribeEvent( DISPID_ONCONTEXTMENU )
         ::_document:destroy()
         ::_document:= ::_interface:= nil
      ENDIF
   RETURN self

  INLINE METHOD documentComplete( cUrl )
  **************************************
    IF ! ::busy .AND. Valtype( ::document ) = 'O' .AND. ::document:interface <> ::_interface
        IF Valtype( ::_document ) = 'O'
           ::_document:unSubscribeEvent( DISPID_ONCONTEXTMENU )
           ::_document:destroy()
           ::_document:= nil
        ENDIF
        ::_interface:= ::document:interface
        ::_document := ::document:dynamicCast( ActiveXObject() )     
        ::_document:subscribeEvent( DISPID_ONCONTEXTMENU, {|| ::ContextMenuHandler() } )
     ENDIF
  RETURN self

  INLINE METHOD InheritPresParams
  *******************************
     LOCAL bError  := ErrorBlock( {|e| Break( e ) } )
     LOCAL lSuccess:= .F.

     BEGIN SEQUENCE
        lSuccess:= ::XbpHTMLViewer:InheritPresParams()
     ENDSEQUENCE

     ErrorBlock( bError )
  RETURN lSuccess

  INLINE METHOD ContextMenuHandler
  ********************************
     LOCAL oPT1, oPT2, aPos, aRect

     oPT1:= ::document:parentWindow
        oPT2:= oPT1:event
        oPT2:returnValue := .F.
        oPT2:destroy()
        oPT1:destroy()

     IF ::oSubMenu <> nil
        ::oSubMenu:destroy()
     ENDIF

     ::oSubMenu:= XbpMenu():new():create( self )
        ::oSubMenu:addItem( { MNU_COPY,      {|| ::execWB( OLECMDID_COPY,         OLECMDEXECOPT_PROMPTUSER, 0, 0 ) } } )
        ::oSubMenu:addItem( { MNU_SELECTALL, {|| ::execWB( OLECMDID_SELECTALL,    OLECMDEXECOPT_PROMPTUSER, 0, 0 ) } } )
        ::oSubMenu:addItem( { MNU_PRINT1,    {|| ::execWB( OLECMDID_PRINT,        OLECMDEXECOPT_PROMPTUSER, 0, 0 ) } } )
        ::oSubMenu:addItem( { MNU_PRINT2,    {|| ::execWB( OLECMDID_PRINTPREVIEW, OLECMDEXECOPT_PROMPTUSER, 0, 0 ) } } )

     oPT1:= ::document:selection
     IF oPT1:type = 'None'
        ::oSubMenu:disableItem( 1 )
     ENDIF
     oPT1:destroy()

     aPos := GetPointerPos()
     aRect:= GetDeskTopRect()

     IF aRect[ 1 ] <> 0
        aPos[ 1 ] -= AppDesktop():currentSize()[ 1 ] - aRect[ 3 ] + aRect[ 1 ]
     ENDIF
     IF aRect[ 2 ] = 0
       aPos[ 2 ] -= AppDesktop():currentSize()[ 2 ] - aRect[ 4 ] 
     ENDIF
     ::oSubMenu:popup( self, aPos )
  RETURN .T.
ENDCLASS
