Alaska Software Inc. - XbpHtmlViewer
Username: Password:
AuthorTopic: XbpHtmlViewer
Altiy Zemlytskiy XbpHtmlViewer
on Tue, 17 Sep 2013 15:12:39 +0300
<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <font face="Courier New, Courier, monospace">Hi all,<br>
      <br>
      <br>
      I use XbpHtmlViewer to open html page with javascript functions
      inside. Is there are any possibility to run these functions for
      this page from xBase or firing the events on the page? <br>
      Any good idea? Many thanks<br>
      <br>
    </font>
    <div class="moz-signature">-- <br>
      Best regards,
      Altiy</div>
  </body>
</html>
Jose Antonio Diego KerejeRe: XbpHtmlViewer
on Tue, 17 Sep 2013 17:46:01 +0200
Hi Altiy,

> I use XbpHtmlViewer to open html page with javascript functions inside. Is
> there are any possibility to run these functions for this page from xBase
> or firing the events on the page?
> Any good idea? Many thanks

I imagine there will be more orthodox ways, but meanwhile, you can take a
look at this code. A few years ago I did some tests to integrate FCKEditor
(the old name of CKEditor) in an Xbase++ application, and
"pseudo-communicate" with their api.

I hope you serve as a starting point.

Regards. Diego

**********************************
CLASS FCKeditor FROM XbpHTMLviewer
**********************************
PROTECTED:
   VAR _cData

   INLINE METHOD GetFckCommand( cValue )
   *************************************
      LOCAL oChildNodes:= ::document:getElementById( 'eButtons' )
      LOCAL oPT, nCont, nFin, bError, oNodo

      IF oChildNodes <> nil
         oPT:= oChildNodes
            oChildNodes := oPT:childNodes
            nFin        := oChildNodes:length
         oPT:destroy()

         bError:= ErrorBlock( {|e| Break( e ) } )

         FOR nCont:= 1 TO nFin STEP 2
            BEGIN SEQUENCE
               oNodo:= oChildNodes:item( nCont - 1 )
               IF Upper( cValue ) <> Upper( oNodo:value )
                  oNodo:destroy()
                  oNodo:= nil
               ENDIF
            ENDSEQUENCE
            IF oNodo <> nil
               EXIT
            ENDIF
         NEXT
         ErrorBlock( bError )
         oChildNodes:destroy()
      ENDIF
   RETURN oNodo

EXPORTED:
   VAR cUrl

   INLINE METHOD destroy
   *********************
      ::_cData:= ::cUrl:= nil
      ::navigate( URL_ABOUTBLANK,,, .F. )
   RETURN ::XbpHTMLviewer:destroy()

   INLINE METHOD init( oOwner, oParent, aPos, aSize, aPP, lVisible )
   *****************************************************************
      ::cUrl:=  URL_ABOUTBLANK
      ::XbpHTMLviewer:init( oOwner, oParent, aPos, aSize, aPP, lVisible )
   RETURN self

   INLINE METHOD create( oOwner, oParent, aPos, aSize, aPP, lVisible )
   *******************************************************************
      ::XbpHTMLviewer:create( oOwner, oParent, aPos, aSize, aPP,
lVisible ):navigate( ::cURL )

      doWhileToNavigateComplete()

      DO WHILE ! ::document:title == 'FCKeditor_Complete'
         Sleep( 20 )
      ENDDO
      ::fitWindow()
   RETURN self

   INLINE METHOD ResetIsDirty
   **************************
      LOCAL oFckCommand:= ::getFckCommand( 'ResetIsDirty()' )
      LOCAL lSuccess   := oFckCommand <> nil

      IF lSuccess
         oFckCommand:click()
         oFckCommand:destroy()
      ENDIF
   RETURN lSuccess

   INLINE METHOD GetData
   *********************
      LOCAL oFckCommand:= ::getFckCommand( 'GetContents()' )
      LOCAL cContents

      IF oFckCommand <> nil
         oFckCommand:click()
         Sleep( 20 )
         oFckCommand:destroy()
         cContents:= ::document:title
      ELSE
         cContents:= ''
      ENDIF
   RETURN cContents

   INLINE METHOD SetData( cData )
   ******************************
      LOCAL oFckCommand:= ::getFckCommand( 'SetContents()' )
      LOCAL lSuccess

      IF oFckCommand <> nil
         ::document:title:= cData
         oFckCommand:click()
         oFckCommand:destroy()
         lSuccess:= .T.
      ELSE
         lSuccess:= .F.
      ENDIF
   RETURN lSuccess

   INLINE METHOD Changed
   *********************
      LOCAL oFckCommand:= ::getFckCommand( 'CheckIsDirty()' )
      LOCAL lChanged

      IF oFckCommand <> nil
         oFckCommand:click()
         Sleep( 30 )
         oFckCommand:destroy()
         lChanged:= ( ::document:title == 'true' )
      ELSE
         lChanged:= .F.
      ENDIF
   RETURN lChanged

   INLINE METHOD fitWindow
   ***********************
      LOCAL oFckCommand:= ::getFckCommand( 'FitWindow()' )

      IF oFckCommand <> nil
         oFckCommand:click()
         oFckCommand:destroy()
      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
ENDCLASS


Documenta.html
Altiy Zemlytskiy Re: XbpHtmlViewer
on Tue, 17 Sep 2013 18:49:18 +0300
Many thanks, Diego, will check
> Hi Altiy,
>
>> I use XbpHtmlViewer to open html page with javascript functions 
>> inside. Is
>> there are any possibility to run these functions for this page from 
>> xBase
>> or firing the events on the page?
>> Any good idea? Many thanks
>
> I imagine there will be more orthodox ways, but meanwhile, you can take a
> look at this code. A few years ago I did some tests to integrate 
> FCKEditor
> (the old name of CKEditor) in an Xbase++ application, and
> "pseudo-communicate" with their api.
>
> I hope you serve as a starting point.
>
> Regards. Diego
>
> **********************************
> CLASS FCKeditor FROM XbpHTMLviewer
> **********************************
> PROTECTED:
>   VAR _cData
>
>   INLINE METHOD GetFckCommand( cValue )
>   *************************************
>      LOCAL oChildNodes:= ::document:getElementById( 'eButtons' )
>      LOCAL oPT, nCont, nFin, bError, oNodo
>
>      IF oChildNodes <> nil
>         oPT:= oChildNodes
>            oChildNodes := oPT:childNodes
>            nFin        := oChildNodes:length
>         oPT:destroy()
>
>         bError:= ErrorBlock( {|e| Break( e ) } )
>
>         FOR nCont:= 1 TO nFin STEP 2
>            BEGIN SEQUENCE
>               oNodo:= oChildNodes:item( nCont - 1 )
>               IF Upper( cValue ) <> Upper( oNodo:value )
>                  oNodo:destroy()
>                  oNodo:= nil
>               ENDIF
>            ENDSEQUENCE
>            IF oNodo <> nil
>               EXIT
>            ENDIF
>         NEXT
>         ErrorBlock( bError )
>         oChildNodes:destroy()
>      ENDIF
>   RETURN oNodo
>
> EXPORTED:
>   VAR cUrl
>
>   INLINE METHOD destroy
>   *********************
>      ::_cData:= ::cUrl:= nil
>      ::navigate( URL_ABOUTBLANK,,, .F. )
>   RETURN ::XbpHTMLviewer:destroy()
>
>   INLINE METHOD init( oOwner, oParent, aPos, aSize, aPP, lVisible )
> *****************************************************************
>      ::cUrl:=  URL_ABOUTBLANK
>      ::XbpHTMLviewer:init( oOwner, oParent, aPos, aSize, aPP, lVisible )
>   RETURN self
>
>   INLINE METHOD create( oOwner, oParent, aPos, aSize, aPP, lVisible )
> *******************************************************************
>      ::XbpHTMLviewer:create( oOwner, oParent, aPos, aSize, aPP,
> lVisible ):navigate( ::cURL )
>
>      doWhileToNavigateComplete()
>
>      DO WHILE ! ::document:title == 'FCKeditor_Complete'
>         Sleep( 20 )
>      ENDDO
>      ::fitWindow()
>   RETURN self
>
>   INLINE METHOD ResetIsDirty
>   **************************
>      LOCAL oFckCommand:= ::getFckCommand( 'ResetIsDirty()' )
>      LOCAL lSuccess   := oFckCommand <> nil
>
>      IF lSuccess
>         oFckCommand:click()
>         oFckCommand:destroy()
>      ENDIF
>   RETURN lSuccess
>
>   INLINE METHOD GetData
>   *********************
>      LOCAL oFckCommand:= ::getFckCommand( 'GetContents()' )
>      LOCAL cContents
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         Sleep( 20 )
>         oFckCommand:destroy()
>         cContents:= ::document:title
>      ELSE
>         cContents:= ''
>      ENDIF
>   RETURN cContents
>
>   INLINE METHOD SetData( cData )
>   ******************************
>      LOCAL oFckCommand:= ::getFckCommand( 'SetContents()' )
>      LOCAL lSuccess
>
>      IF oFckCommand <> nil
>         ::document:title:= cData
>         oFckCommand:click()
>         oFckCommand:destroy()
>         lSuccess:= .T.
>      ELSE
>         lSuccess:= .F.
>      ENDIF
>   RETURN lSuccess
>
>   INLINE METHOD Changed
>   *********************
>      LOCAL oFckCommand:= ::getFckCommand( 'CheckIsDirty()' )
>      LOCAL lChanged
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         Sleep( 30 )
>         oFckCommand:destroy()
>         lChanged:= ( ::document:title == 'true' )
>      ELSE
>         lChanged:= .F.
>      ENDIF
>   RETURN lChanged
>
>   INLINE METHOD fitWindow
>   ***********************
>      LOCAL oFckCommand:= ::getFckCommand( 'FitWindow()' )
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         oFckCommand:destroy()
>      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
> ENDCLASS


Best regards, Altiy
Altiy Zemlytskiy Re: XbpHtmlViewer
on Tue, 01 Oct 2013 10:18:19 +0300
Hi Diego,

Many thanks for your hint, everything fine. I just can't run something 
like oFckCommand:click(), nothing happens  If I click to button by 
mouse, everything work, Am I doing something wrong ot have to set 
special IE settings? Many thnaks in advance
> Hi Altiy,
>
>> I use XbpHtmlViewer to open html page with javascript functions 
>> inside. Is
>> there are any possibility to run these functions for this page from 
>> xBase
>> or firing the events on the page?
>> Any good idea? Many thanks
>
> I imagine there will be more orthodox ways, but meanwhile, you can take a
> look at this code. A few years ago I did some tests to integrate 
> FCKEditor
> (the old name of CKEditor) in an Xbase++ application, and
> "pseudo-communicate" with their api.
>
> I hope you serve as a starting point.
>
> Regards. Diego
>
> **********************************
> CLASS FCKeditor FROM XbpHTMLviewer
> **********************************
> PROTECTED:
>   VAR _cData
>
>   INLINE METHOD GetFckCommand( cValue )
>   *************************************
>      LOCAL oChildNodes:= ::document:getElementById( 'eButtons' )
>      LOCAL oPT, nCont, nFin, bError, oNodo
>
>      IF oChildNodes <> nil
>         oPT:= oChildNodes
>            oChildNodes := oPT:childNodes
>            nFin        := oChildNodes:length
>         oPT:destroy()
>
>         bError:= ErrorBlock( {|e| Break( e ) } )
>
>         FOR nCont:= 1 TO nFin STEP 2
>            BEGIN SEQUENCE
>               oNodo:= oChildNodes:item( nCont - 1 )
>               IF Upper( cValue ) <> Upper( oNodo:value )
>                  oNodo:destroy()
>                  oNodo:= nil
>               ENDIF
>            ENDSEQUENCE
>            IF oNodo <> nil
>               EXIT
>            ENDIF
>         NEXT
>         ErrorBlock( bError )
>         oChildNodes:destroy()
>      ENDIF
>   RETURN oNodo
>
> EXPORTED:
>   VAR cUrl
>
>   INLINE METHOD destroy
>   *********************
>      ::_cData:= ::cUrl:= nil
>      ::navigate( URL_ABOUTBLANK,,, .F. )
>   RETURN ::XbpHTMLviewer:destroy()
>
>   INLINE METHOD init( oOwner, oParent, aPos, aSize, aPP, lVisible )
> *****************************************************************
>      ::cUrl:=  URL_ABOUTBLANK
>      ::XbpHTMLviewer:init( oOwner, oParent, aPos, aSize, aPP, lVisible )
>   RETURN self
>
>   INLINE METHOD create( oOwner, oParent, aPos, aSize, aPP, lVisible )
> *******************************************************************
>      ::XbpHTMLviewer:create( oOwner, oParent, aPos, aSize, aPP,
> lVisible ):navigate( ::cURL )
>
>      doWhileToNavigateComplete()
>
>      DO WHILE ! ::document:title == 'FCKeditor_Complete'
>         Sleep( 20 )
>      ENDDO
>      ::fitWindow()
>   RETURN self
>
>   INLINE METHOD ResetIsDirty
>   **************************
>      LOCAL oFckCommand:= ::getFckCommand( 'ResetIsDirty()' )
>      LOCAL lSuccess   := oFckCommand <> nil
>
>      IF lSuccess
>         oFckCommand:click()
>         oFckCommand:destroy()
>      ENDIF
>   RETURN lSuccess
>
>   INLINE METHOD GetData
>   *********************
>      LOCAL oFckCommand:= ::getFckCommand( 'GetContents()' )
>      LOCAL cContents
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         Sleep( 20 )
>         oFckCommand:destroy()
>         cContents:= ::document:title
>      ELSE
>         cContents:= ''
>      ENDIF
>   RETURN cContents
>
>   INLINE METHOD SetData( cData )
>   ******************************
>      LOCAL oFckCommand:= ::getFckCommand( 'SetContents()' )
>      LOCAL lSuccess
>
>      IF oFckCommand <> nil
>         ::document:title:= cData
>         oFckCommand:click()
>         oFckCommand:destroy()
>         lSuccess:= .T.
>      ELSE
>         lSuccess:= .F.
>      ENDIF
>   RETURN lSuccess
>
>   INLINE METHOD Changed
>   *********************
>      LOCAL oFckCommand:= ::getFckCommand( 'CheckIsDirty()' )
>      LOCAL lChanged
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         Sleep( 30 )
>         oFckCommand:destroy()
>         lChanged:= ( ::document:title == 'true' )
>      ELSE
>         lChanged:= .F.
>      ENDIF
>   RETURN lChanged
>
>   INLINE METHOD fitWindow
>   ***********************
>      LOCAL oFckCommand:= ::getFckCommand( 'FitWindow()' )
>
>      IF oFckCommand <> nil
>         oFckCommand:click()
>         oFckCommand:destroy()
>      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
> ENDCLASS


Best regards, Altiy
Jose Antonio Diego KerejeRe: XbpHtmlViewer
on Tue, 01 Oct 2013 14:58:05 +0200
I did not want to make an example, but ...

Regards. Diego


JavaScript.zip
Jose Antonio Diego KerejeRe: XbpHtmlViewer
on Tue, 01 Oct 2013 15:01:01 +0200
A small correction in the code...


JavaScript.zip
Altiy Zemlytskiy Re: XbpHtmlViewer
on Tue, 01 Oct 2013 16:11:32 +0300
Hi Diego,

many thanks!!! Really works, will check my code, it looked the same, 
but... I think it is because my class is inherited from XbpHtmlViewer or 
something else

Many thanks again!

> A small correction in the code...


Best regards, Altiy
Altiy Zemlytskiy Re: XbpHtmlViewer
on Wed, 02 Oct 2013 18:05:46 +0300
Hi Diego,

many thanks again for your hint. The problem really was with inherited class

::XbpHTMLViewer:document:getElementById('collapseAll'):onClick() works, but
::document:getElementById('collapseAll'):onClick() does not work as 
calling inherited class object, strange but no big deal

Thanks again

Best regards, Altiy
Jose Antonio Diego KerejeRe: XbpHtmlViewer
on Wed, 02 Oct 2013 17:28:41 +0200
Hi Altiy,

> many thanks again for your hint. The problem really was with inherited 
> class

I'm glad that works for you.

> ::XbpHTMLViewer:document:getElementById('collapseAll'):onClick() works, 
> but
> ::document:getElementById('collapseAll'):onClick() does not work as 
> calling inherited class object, strange but no big deal

Strange ...  Anyway, I would use the click() method, and not the onClik() 
event.
And it should work both ways: with and without ::XbpHTMLviewer reference.

Regards. Diego