home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 16 / CD_ASCQ_16_0994.iso / news / 4611 / fw16d.ins / IDE / SOURCE / DOC.PRG < prev    next >
Text File  |  1994-06-06  |  10KB  |  322 lines

  1. // (c) FiveWin - Documentation Tools
  2.  
  3. #include "FiveWin.ch"
  4.  
  5. //----------------------------------------------------------------------------//
  6.  
  7. function DocNew()
  8.  
  9.    local cDocName := cGetNewFileName( "docs\doc", "doc" )
  10.  
  11.    DbCreate( cDocName, { { "PAGE",     "N",  3, 0 },;
  12.                          { "ITEM",     "N",  4, 0 },;
  13.                          { "DESCRIPT", "C", 50, 0 },;
  14.                          { "NOTES",    "M", 10, 0 },;
  15.                          { "TITLE",    "C", 50, 0 },;
  16.                          { "KEYWORD",  "C", 50, 0 },;
  17.                          { "TOPIC",    "C", 50, 0 },;
  18.                          { "JUMPTO",   "N",  3, 0 },;
  19.                          { "POPUP",    "L",  1, 0 },;
  20.                          { "BITMAP",   "C", 50, 0 } } )
  21.    DocOpen( cDocName )
  22.  
  23. return nil
  24.  
  25. //----------------------------------------------------------------------------//
  26.  
  27. function DocOpen( cDocName )
  28.  
  29.    local oWndDoc, oBar, oBrw, oIco
  30.    local oWnd := GetWndMain(), oWndAreas := GetWndAreas()
  31.    local cAlias, nPage := 1
  32.  
  33.    field Page, Item, Descript, Notes
  34.  
  35.    DEFAULT cDocName := cGetFile( "FiveWin Documentation (*.doc) | docs\*.doc",;
  36.                                  "Select a Documentation file" )
  37.  
  38.    if ! Empty( cDocName )
  39.  
  40.       USE ( cDocName ) NEW SHARED
  41.  
  42.       if RecCount() == 0
  43.          APPEND BLANK
  44.          Page     := 1
  45.          Item     := 1
  46.          Descript := "New item"
  47.       endif
  48.  
  49.       INDEX ON StrZero( Page, 3 ) + StrZero( Item, 4 ) ;
  50.          TO ( cNoExt( cDocName ) )
  51.       SET INDEX TO ( cNoExt( cDocName ) )
  52.       GO TOP
  53.  
  54.       cAlias = Alias()
  55.  
  56.       DEFINE ICON oIco RESOURCE "Doc"
  57.  
  58.       DEFINE WINDOW oWndDoc FROM 1, 1 TO 23, 33 ;
  59.          TITLE "Documentation: " + cNoExt( cNoPath( cDocName ) ) ;
  60.          ICON  oIco MDICHILD OF oWnd
  61.  
  62.       DEFINE BUTTONBAR oBar OF oWndDoc
  63.  
  64.       DEFINE BUTTON RESOURCE "New" OF oBar ;
  65.          MESSAGE "Add a new page" ;
  66.          ACTION nPage := nPageNew( oBrw, nPage )
  67.  
  68.       DEFINE BUTTON RESOURCE "NewItem" OF oBar ;
  69.          MESSAGE "Add a new item" ;
  70.          ACTION ItemNew( oBrw, nPage )
  71.  
  72.       DEFINE BUTTON RESOURCE "Edit" OF oBar ;
  73.          MESSAGE "Edit this item page" ;
  74.          ACTION  ItemEdit( oBrw )
  75.  
  76.       DEFINE BUTTON RESOURCE "PrevPage" OF oBar ;
  77.          MESSAGE "Go previous page" ACTION nPage := nPagePrev( oBrw, nPage )
  78.  
  79.       DEFINE BUTTON RESOURCE "NextPage" OF oBar ;
  80.          MESSAGE "Go next page" ACTION nPage := nPageNext( oBrw, nPage )
  81.  
  82.       DEFINE BUTTON RESOURCE "NG" GROUP OF oBar ;
  83.          MESSAGE "Create Norton Guide documentation"
  84.  
  85.       DEFINE BUTTON RESOURCE "HLP" OF oBar ;
  86.          MESSAGE "Create Windows Help documentation" ;
  87.          ACTION GenRTF( oBrw, cNoExt( cDocName ) )
  88.  
  89.       DEFINE BUTTON RESOURCE "Exec" OF oBar ;
  90.          MESSAGE "Test documentation" ;
  91.          ACTION If( File( cNoPath( cNoExt( cDocName ) ) + ".hlp" ),;
  92.                 WinHelp( cNoPath( cNoExt( cDocName ) ) + ".hlp" ),)
  93.  
  94.       @ 0, 0 LISTBOX oBrw FIELDS Str( ( Alias() )->Page, 3 ),;
  95.                                  xPadL( Str( ( Alias() )->Item, 4 ), 25 ),;
  96.                                  ( Alias() )->Descript ;
  97.                           FIELDSIZES 30, 35, 300 ;
  98.                           HEADERS "Pag", "Item", "Description" ;
  99.          OF oWndDoc ;
  100.          ON CHANGE If( oWndAreas != nil, oWndAreas:oControl:Refresh(),) ;
  101.          SELECT StrZero( Page, 3 ) + StrZero(  1, 4 ) ;
  102.          FOR StrZero( nPage, 3 ) + StrZero(    1, 4 ) ;
  103.          TO  StrZero( nPage, 3 ) + StrZero( 9999, 4 ) ;
  104.          SIZE 400, 400
  105.          // Indexed filter !!!
  106.  
  107.       oWndDoc:SetControl( oBrw )
  108.  
  109.       ACTIVATE WINDOW oWndDoc ;
  110.          VALID oBrw:lCloseArea()
  111.  
  112.       if oWndAreas != nil
  113.          oWndAreas:oControl:Refresh()  // We updates the info on the WorkAreas
  114.       endif                            // Inspector
  115.  
  116.    endif
  117.  
  118. return nil
  119.  
  120. //----------------------------------------------------------------------------//
  121.  
  122. static function ItemNew( oBrw, nPage )
  123.  
  124.    local nItem
  125.  
  126.    oBrw:GoBottom()
  127.    nItem = ( oBrw:cAlias )->Item
  128.  
  129.    ( oBrw:cAlias )->( DbAppend() )
  130.  
  131.    if ( oBrw:cAlias )->( RLock() )
  132.       ( oBrw:cAlias )->Page = nPage
  133.       ( oBrw:cAlias )->Item = nItem + 1
  134.       ( oBrw:cAlias )->Descript = "New Item"
  135.       UNLOCK
  136.       oBrw:SetFilter( "StrZero( Page, 3 ) + StrZero( 1, 4 )",;
  137.                       StrZero( nPage, 3 ) + StrZero( 1, 4 ),;
  138.                       StrZero( nPage, 3 ) + StrZero( 9999, 4 ) )
  139.       oBrw:GoTop()
  140.       oBrw:Refresh()
  141.    else
  142.       MsgAlert( "DataBase in use, please try again" )
  143.    endif
  144.  
  145. return nil
  146.  
  147. //----------------------------------------------------------------------------//
  148.  
  149. static function nPageNew( oBrw, nPage )
  150.  
  151.    nPage++
  152.  
  153.    ( oBrw:cAlias )->( DbAppend() )
  154.  
  155.    if ( oBrw:cAlias )->( RLock() )
  156.       ( oBrw:cAlias )->Page = nPage
  157.       ( oBrw:cAlias )->Item = 1
  158.       ( oBrw:cAlias )->Descript = "New Item"
  159.       UNLOCK
  160.       oBrw:SetFilter( "StrZero( Page, 3 ) + StrZero( 1, 4 )",;
  161.                       StrZero( nPage, 3 ) + StrZero( 1, 4 ),;
  162.                       StrZero( nPage, 3 ) + StrZero( 9999, 4 ) )
  163.       oBrw:GoTop()
  164.       oBrw:Refresh()
  165.    else
  166.       MsgAlert( "DataBase in use, please try again" )
  167.    endif
  168.  
  169. return nPage
  170.  
  171. //----------------------------------------------------------------------------//
  172.  
  173. static function nPagePrev( oBrw, nPage )
  174.  
  175.    if nPage > 1
  176.       nPage--
  177.       oBrw:SetFilter( "StrZero( Page, 3 ) + StrZero( 1, 4 )",;
  178.                       StrZero( nPage, 3 ) + StrZero( 1, 4 ),;
  179.                       StrZero( nPage, 3 ) + StrZero( 9999, 4 ) )
  180.       oBrw:GoTop()
  181.       oBrw:Refresh()
  182.    endif
  183.  
  184. return nPage
  185.  
  186. //----------------------------------------------------------------------------//
  187.  
  188. static function nPageNext( oBrw, nPage )
  189.  
  190.    local nRecNo := RecNo()
  191.  
  192.    GO BOTTOM
  193.    if ! ( oBrw:cAlias )->Page >= nPage + 1
  194.       GO nRecNo
  195.       return nPage
  196.    endif
  197.    GO nRecNo
  198.  
  199.    nPage++
  200.    oBrw:SetFilter( "StrZero( Page, 3 ) + StrZero( 1, 4 )",;
  201.                    StrZero( nPage, 3 ) + StrZero( 1, 4 ),;
  202.                    StrZero( nPage, 3 ) + StrZero( 9999, 4 ) )
  203.    oBrw:GoTop()
  204.    oBrw:Refresh()
  205.  
  206. return nPage
  207.  
  208. //----------------------------------------------------------------------------//
  209.  
  210. static function ItemEdit( oBrw )
  211.  
  212.    local oDlg, oBmp
  213.    local cAlias    := oBrw:cAlias
  214.    local nPage     := ( cAlias )->Page
  215.    local nItem     := ( cAlias )->Item
  216.    local cDescript := ( cAlias )->Descript
  217.    local nJumpTo   := ( cAlias )->JumpTo
  218.    local lPopup    := ( cAlias )->Popup
  219.    local cBitmap   := ( cAlias )->Bitmap
  220.    local cNotes    := ( cAlias )->Notes
  221.  
  222.    DEFINE DIALOG oDlg RESOURCE "DocItem"
  223.  
  224.    REDEFINE GET nPage ID 110 OF oDlg
  225.  
  226.    REDEFINE GET nItem ID 120 OF oDlg
  227.  
  228.    REDEFINE GET nJumpTo ID 130 OF oDlg
  229.  
  230.    REDEFINE GET cDescript ID 150 OF oDlg
  231.  
  232.    REDEFINE GET oBmp VAR cBitmap ID 180 OF oDlg
  233.  
  234.    REDEFINE BUTTON ID 190 OF oDlg ;
  235.       ACTION ( cBitmap := cGetFile( "Windows Bitmap (*.bmp) |" + cBitmap,;
  236.                "Select a bitmap" ), oBmp:Refresh() )
  237.  
  238.    REDEFINE CHECKBOX lPopup ID 210 OF oDlg
  239.  
  240.    REDEFINE GET cNotes MULTILINE ID 200 OF oDlg
  241.  
  242.    ACTIVATE DIALOG oDlg CENTERED
  243.  
  244.    if oDlg:nResult == IDOK
  245.       if ( cAlias )->( RLock() )
  246.          ( cAlias )->Page     := nPage
  247.          ( cAlias )->Item     := nItem
  248.          ( cAlias )->JumpTo   := nJumpTo
  249.          ( cAlias )->Descript := cDescript
  250.          ( cAlias )->Bitmap   := cBitmap
  251.          ( cAlias )->Popup    := lPopup
  252.          ( cAlias )->Notes    := cNotes
  253.          ( cAlias )->( DbUnLock() )
  254.          oBrw:Refresh()
  255.       endif
  256.    endif
  257.  
  258.    oBrw:SetFocus()
  259.  
  260. return nil
  261.  
  262. //----------------------------------------------------------------------------//
  263.  
  264. static function GenRTF( oBrw, cDocName )
  265.  
  266.    local cAlias    := oBrw:cAlias
  267.    local nRecNo    := ( cAlias )->( RecNo() )
  268.    local nPage     := 1
  269.    local oRTF
  270.  
  271.    oRTF = TRtfFile():New( cDocName + ".rtf" )
  272.  
  273.    ( cAlias )->( DbGoTop() )
  274.  
  275.    oRTF:WriteId( StrZero( ( cAlias )->Page, 4 ) + ;
  276.                  StrZero( ( cAlias )->Item, 4 ) )
  277.  
  278.    while ! ( cAlias )->( EoF() )
  279.       if ( cAlias )->Page != nPage
  280.          nPage = ( cAlias )->Page
  281.          oRTF:NewPage()
  282.          oRTF:WriteId( StrZero( ( cAlias )->Page, 4 ) + ;
  283.                        StrZero( ( cAlias )->Item, 4 ) )
  284.       endif
  285.       oRtf:WriteShort( ( cAlias )->Descript,;
  286.                        If( ! Empty( ( cAlias )->Notes ),;
  287.                        StrZero( ( cAlias )->Page, 4 ) + ;
  288.                        StrZero( ( cAlias )->Item, 4 ) + "L",;
  289.                        If( ! Empty( ( cAlias )->JumpTo ),;
  290.                        StrZero( ( cAlias )->JumpTo, 4 ) + "0001", "" ) ),;
  291.                        ( cAlias )->Popup, ( cAlias )->Bitmap )
  292.       ( cAlias )->( DbSkip() )
  293.    end
  294.  
  295.    ( cAlias )->( DbGoTop() )
  296.  
  297.    while ! ( cAlias )->( EoF() )
  298.       if ( cAlias )->Page != nPage
  299.          nPage = ( cAlias )->Page
  300.          oRTF:NewPage()
  301.       endif
  302.       if ! Empty( ( cAlias )->Notes )
  303.          oRtf:WriteId( StrZero( ( cAlias )->Page, 4 ) + ;
  304.                        StrZero( ( cAlias )->Item, 4 ) + "L" )
  305.          oRtf:WriteLong( ( cAlias )->Notes )
  306.          oRTF:NewPage()
  307.       endif
  308.       ( cAlias )->( DbSkip() )
  309.    end
  310.  
  311.    ( cAlias )->( DbGoTo( nRecNo ) )
  312.    oRtf:End()
  313.  
  314.    MsgInfo( "RTF file " + cDocName + ".rtf successfully generated!" )
  315.    WinExec( "pifs\hc.pif " + cDocName + ".hpj" )
  316.  
  317.    oBrw:SetFocus()
  318.  
  319. return nil
  320.  
  321. //----------------------------------------------------------------------------//
  322.