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

  1. // Dialog Tools
  2. // (c) FiveWin IDE
  3.  
  4. #include "FiveWin.ch"
  5.  
  6. //----------------------------------------------------------------------------//
  7.  
  8. function DlgNew()
  9.  
  10.    DlgOpen( cGetNewFileName( "dialogs\DIALOG", "scr" ) )
  11.  
  12. return nil
  13.  
  14. //----------------------------------------------------------------------------//
  15.  
  16. function DlgOpen( cDlgName )
  17.  
  18.    local oWndDlg, oIco, oBar, oBrw, oBmp, oControl
  19.    local cAlias
  20.  
  21.    DEFAULT cDlgName := cGetFile( "FiveWin IDE Dialog ( *.scr ) | *.scr",;
  22.                                  "Select a Dialog" )
  23.  
  24.    DEFINE ICON oIco RESOURCE "Dialog"
  25.  
  26.    if Empty( cDlgName )
  27.       MsgInfo( "I can't find that file!" )
  28.       return nil
  29.    endif
  30.  
  31.    if File( cDlgName )
  32.       USE ( cDlgName ) NEW SHARED
  33.       cAlias = Alias()
  34.  
  35.       if RecCount() > 0
  36.          DEFINE WINDOW oWndDlg PIXEL ;
  37.             FROM ( cAlias )->Top, ( cAlias )->Left TO ;
  38.                  ( cAlias )->Top  + ( cAlias )->Height - 1,;
  39.                  ( cAlias )->Left + ( cAlias )->Width - 1 ;
  40.             TITLE "Dialog: " + cNoExt( cNoPath( cDlgName ) ) MDICHILD ;
  41.             ICON oIco COLOR ( cAlias )->ClrFore, ( cAlias )->ClrBack
  42.       endif
  43.    else
  44.       DEFINE WINDOW oWndDlg FROM 2, 15 TO 20, 65 ;
  45.          TITLE "Dialog: " + cNoExt( cNoPath( cDlgName ) ) MDICHILD ;
  46.          ICON oIco
  47.    endif
  48.  
  49.    DEFINE BUTTONBAR oBar OF oWndDlg
  50.  
  51.    DEFINE BUTTON OF oBar RESOURCE "Static" ;
  52.       ACTION LabelAdd( oBmp, .t., cAlias )
  53.  
  54.    DEFINE BUTTON OF oBar RESOURCE "Btn1" ;
  55.       ACTION BtnAdd( oBmp, .t., cAlias )
  56.  
  57.    DEFINE BUTTON OF oBar RESOURCE "Check" ;
  58.       ACTION CheckAdd( oBmp, .t., cAlias )
  59.  
  60.    DEFINE BUTTON OF oBar RESOURCE "ListBox" ;
  61.       ACTION LbxAdd( oBmp, .t., cAlias )
  62.  
  63.    DEFINE BUTTON OF oBar RESOURCE "Get" ;
  64.       ACTION GetAdd( oBmp, .t., cAlias )
  65.  
  66.    DEFINE BUTTON OF oBar RESOURCE "Radio" ;
  67.       ACTION RadioAdd( oBmp, .t., cAlias )
  68.  
  69.    DEFINE BUTTON OF oBar RESOURCE "Shade" ;
  70.       ACTION ShadeAdd( oBmp, .t., cAlias )
  71.  
  72.    DEFINE BUTTON OF oBar RESOURCE "Bitmap"
  73.  
  74.    DEFINE BUTTON GROUP OF oBar RESOURCE "Clr" ;
  75.       ACTION oBmp:SelColor()
  76.  
  77.    DEFINE BUTTON OF oBar RESOURCE "PRG" ;
  78.       ACTION ( oBmp:cGenPRG( "Dlg.prg" ), PrgOpen( "Dlg.prg" ) )
  79.  
  80.    DEFINE BUTTON GROUP OF oBar RESOURCE "ToDisk" ;
  81.       ACTION lDlgSave( oWndDlg, cDlgName )
  82.  
  83.    @ 0, 0 BITMAP oBmp OF oWndDlg
  84.  
  85.    oBmp:SetColor( oWndDlg:nClrText, oWndDlg:nClrPane )
  86.    oWndDlg:SetControl( oBmp )
  87.  
  88.    if ! Empty( cAlias )
  89.       while ! EoF()
  90.          do case
  91.             case AllTrim( ( cAlias )->Control ) == "TSAY"
  92.                  LabelAdd( oBmp, .f., cAlias )
  93.  
  94.             case AllTrim( ( cAlias )->Control ) == "TBUTTON"
  95.                  BtnAdd( oBmp, .f., cAlias )
  96.  
  97.             case AllTrim( ( cAlias )->Control ) == "TGET"
  98.                  GetAdd( oBmp, .f., cAlias )
  99.  
  100.             case AllTrim( ( cAlias )->Control ) == "TCHECKBOX"
  101.                  CheckAdd( oBmp, .f., cAlias )
  102.  
  103.             case AllTrim( ( cAlias )->Control ) == "TLISTBOX"
  104.                  LbxAdd( oBmp, .f., cAlias )
  105.          endcase
  106.          SKIP
  107.       end
  108.       USE
  109.    endif
  110.  
  111.    ACTIVATE WINDOW oWndDlg ;
  112.       VALID lDlgSave( oWndDlg, cDlgName )
  113.  
  114. return nil
  115.  
  116. //----------------------------------------------------------------------------//
  117.  
  118. static function LabelAdd( oWnd, lNew, cAlias )
  119.  
  120.    local oSay
  121.    local cLabel
  122.  
  123.    DEFAULT lNew := .t.
  124.  
  125.    if lNew
  126.       @ 2, 2 SAY oSay PROMPT "&Label" DESIGN SIZE 70, 28 OF oWnd
  127.    else
  128.       cLabel = AllTrim( ( cAlias )->Caption )
  129.       @ ( cAlias )->Top, ( cAlias )->Left SAY oSay PROMPT cLabel ;
  130.          DESIGN SIZE ( cAlias )->Width, ( cAlias )->Height PIXEL OF oWnd ;
  131.          COLOR ( cAlias )->ClrFore, ( cAlias )->ClrBack ;
  132.          FONT BuildFont( cAlias )
  133.    endif
  134.  
  135.    oSay:bRClicked = { || ThisInspect( oSay ) }
  136.  
  137. return nil
  138.  
  139. //----------------------------------------------------------------------------//
  140.  
  141. static function BtnAdd( oWnd, lNew, cAlias )
  142.  
  143.    local oBtn
  144.  
  145.    if lNew
  146.       @ 2, 2 BUTTON oBtn PROMPT "&Button" SIZE 80, 27 DESIGN OF oWnd
  147.    else
  148.       @ ( cAlias )->Top, ( cAlias )->Left BUTTON oBtn ;
  149.          PROMPT AllTrim( ( cAlias )->Caption ) ;
  150.          DESIGN SIZE ( cAlias )->Width, ( cAlias )->Height PIXEL OF oWnd ;
  151.          FONT BuildFont( cAlias )
  152.    endif
  153.  
  154.    oBtn:bRClicked = { || ThisInspect( oBtn ) }
  155.  
  156. return nil
  157.  
  158. //----------------------------------------------------------------------------//
  159.  
  160. static function CheckAdd( oWnd, lNew, cAlias )
  161.  
  162.    local oCheck
  163.    local lStatus := .f.
  164.  
  165.    if lNew
  166.       @ 2, 2 CHECKBOX oCheck VAR lStatus PROMPT "&CheckBox" ;
  167.          SIZE 115, 24 DESIGN OF oWnd
  168.    else
  169.       @ ( cAlias )->Top, ( cAlias )->Left CHECKBOX oCheck ;
  170.          VAR lStatus PROMPT AllTrim( ( cAlias )->Caption ) ;
  171.          DESIGN SIZE ( cAlias )->Width, ( cAlias )->Height PIXEL OF oWnd ;
  172.          COLOR ( cAlias )->ClrFore, ( cAlias )->ClrBack ;
  173.          FONT BuildFont( cAlias )
  174.    endif
  175.  
  176.    oCheck:Set3DLook()
  177.  
  178.    oCheck:bRClicked = { || ThisInspect( oCheck ) }
  179.  
  180. return oCheck
  181.  
  182. //----------------------------------------------------------------------------//
  183.  
  184. static function LbxAdd( oWnd, lNew, cAlias )
  185.  
  186.    local oLbx
  187.    local cItem := "One"
  188.  
  189.    if lNew
  190.       @ 2, 2 LISTBOX oLbx VAR cItem ITEMS { "One", "Two", "Three" } ;
  191.         SIZE 100, 100 DESIGN OF oWnd
  192.    else
  193.       @ ( cAlias )->Top, ( cAlias )->Left LISTBOX oLbx VAR cItem ;
  194.          ITEMS { "One", "Two", "Three", "", "", "" } ;
  195.          SIZE ( cAlias )->Width, ( cAlias )->Height PIXEL DESIGN OF oWnd ;
  196.          COLOR ( cAlias )->ClrFore, ( cAlias )->ClrBack ;
  197.          FONT BuildFont( cAlias )
  198.    endif
  199.  
  200.    oLbx:Set3DLook()
  201.    oLbx:bRClicked = { || ThisInspect( oLbx ) }
  202.  
  203. return oLbx
  204.  
  205. //----------------------------------------------------------------------------//
  206.  
  207. static function GetAdd( oWnd, lNew, cAlias )
  208.  
  209.    local oGet
  210.    local cItem := Space( 15 )
  211.  
  212.    if lNew
  213.       @ 2, 2 GET oGet VAR cItem SIZE 115, 24 DESIGN OF oWnd
  214.    else
  215.       @ ( cAlias )->Top, ( cAlias )->Left GET oGet VAR cItem ;
  216.          SIZE ( cAlias )->Width, ( cAlias )->Height PIXEL DESIGN OF oWnd ;
  217.          COLOR ( cAlias )->ClrFore, ( cAlias )->ClrBack ;
  218.          FONT BuildFont( cAlias )
  219.    endif
  220.  
  221.    oGet:Set3DLook()
  222.    oGet:bRClicked = { || ThisInspect( oGet ) }
  223.  
  224. return oGet
  225.  
  226. //----------------------------------------------------------------------------//
  227.  
  228. static function RadioAdd( oWnd, lNew, cAlias )
  229.  
  230.    local nItem := 1
  231.    local oRadio
  232.  
  233.    @ 2, 2 RADIO oRadio VAR nItem PROMPT "&One", "Two", "&Three" OF oWnd
  234.  
  235.    oRadio:Set3DLook()
  236.  
  237.    // oRadio:bRClicked = { || ThisInspect( oRadio ) }
  238.  
  239. return oRadio
  240.  
  241. //----------------------------------------------------------------------------//
  242.  
  243. static function ShadeAdd( oWnd, lNew, cAlias )
  244.  
  245.    local nItem := 1
  246.    local oRadio
  247.  
  248.    // @ 2, 2 SAY oRadio VAR nItem PROMPT "&One", "Two", "&Three" OF oWnd
  249.  
  250.    // oRadio:Set3DLook()
  251.  
  252.    // oRadio:bRClicked = { || ThisInspect( oRadio ) }
  253.  
  254. return oRadio
  255.  
  256. //----------------------------------------------------------------------------//
  257.  
  258. static function lDlgSave( oWnd, cDlgName )
  259.  
  260.    local n
  261.    local aPoint, aControls := oWnd:oControl:aControls
  262.    local cAlias
  263.  
  264.    if ! MsgYesNo( "Do you wish to save this Dialog ?" )
  265.       return .t.
  266.    endif
  267.  
  268.    if File( cDlgName )
  269.       if ! MsgYesno( "A file with that name already exists." + ;
  270.                      "Do you want to overwrite it ?" )
  271.          return .t.
  272.       endif
  273.    endif
  274.  
  275.    DbCreate( cDlgName, { { "CONTROL",  "C", 15, 0 },;
  276.                          { "CAPTION",  "C", 40, 0 },;
  277.                          { "ID",       "N",  4, 0 },;
  278.                          { "TOP",      "N",  4, 0 },;
  279.                          { "LEFT",     "N",  4, 0 },;
  280.                          { "WIDTH",    "N",  4, 0 },;
  281.                          { "HEIGHT",   "N",  4, 0 },;
  282.                          { "STYLE",    "N", 15, 0 },;
  283.                          { "CLRFORE",  "N",  8, 0 },;
  284.                          { "CLRBACK",  "N",  8, 0 },;
  285.                          { "FNTNAME",  "C", 15, 0 },;
  286.                          { "FNTWIDTH", "N",  4, 0 },;
  287.                          { "FNTHEIGHT","N",  4, 0 },;
  288.                          { "FNTBOLD",  "L",  1, 0 },;
  289.                          { "FNTITALIC","L",  1, 0 } } )
  290.    USE ( cDlgName ) NEW
  291.    ZAP
  292.    cAlias = Alias()
  293.  
  294.    oWnd:CoorsUpdate()
  295.    ScreenToClient( oWnd:oWnd:oWndClient:hWnd,;
  296.                    aPoint := { oWnd:nTop, oWnd:nLeft } )
  297.  
  298.    APPEND BLANK
  299.    ( cAlias )->Control = "TDIALOG"
  300.    ( cAlias )->Caption = oWnd:cTitle
  301.    ( cAlias )->Top     = aPoint[ 1 ]
  302.    ( cAlias )->Left    = aPoint[ 2 ]
  303.    ( cAlias )->Width   = oWnd:nRight - oWnd:nLeft
  304.    ( cAlias )->Height  = oWnd:nBottom - oWnd:nTop
  305.    ( cAlias )->Style   = nValToN( oWnd:nStyle )
  306.    ( cAlias )->ClrFore = oWnd:oControl:nClrText
  307.    ( cAlias )->ClrBack = oWnd:oControl:nClrPane
  308.  
  309.    if aControls != nil
  310.       for n = 1 to Len( aControls )
  311.          aControls[ n ]:CoorsUpdate()
  312.          ScreenToClient( oWnd:oControl:hWnd,;
  313.             aPoint := { aControls[ n ]:nTop, aControls[ n ]:nLeft } )
  314.  
  315.          APPEND BLANK
  316.          ( cAlias )->Control   = aControls[ n ]:ClassName()
  317.          ( cAlias )->Caption   = aControls[ n ]:cCaption
  318.          ( cAlias )->Top       = aPoint[ 1 ]
  319.          ( cAlias )->Left      = aPoint[ 2 ]
  320.          ( cAlias )->Width     = aControls[ n ]:nRight - aControls[ n ]:nLeft - 1
  321.          ( cAlias )->Height    = aControls[ n ]:nBottom - aControls[ n ]:nTop - 1
  322.          ( cAlias )->Style     = nValToN( aControls[ n ]:nStyle )
  323.          ( cAlias )->ClrFore   = nValToN( aControls[ n ]:nClrText )
  324.          ( cAlias )->ClrBack   = nValToN( aControls[ n ]:nClrPane )
  325.          ( cAlias )->FntName   = cValToChar( aControls[ n ]:oFont:cFaceName )
  326.          ( cAlias )->FntWidth  = nValToN( aControls[ n ]:oFont:nWidth )
  327.          ( cAlias )->FntHeight = nValToN( aControls[ n ]:oFont:nHeight )
  328.          ( cAlias )->FntBold   = lValToL( aControls[ n ]:oFont:lBold )
  329.          ( cAlias )->FntItalic = lValToL( aControls[ n ]:oFont:lItalic )
  330.       next
  331.    endif
  332.    USE
  333.  
  334. return .t.    // Close the Window
  335.  
  336. //----------------------------------------------------------------------------//
  337.  
  338. static function nValToN( uVal ) ; return If( ValType( uVal ) != "N", 0, uVal )
  339. static function lValToL( uVal ) ; return If( ValType( uVal ) != "L", .f., uVal )
  340.  
  341. //----------------------------------------------------------------------------//
  342.  
  343. static function BuildFont( cAlias )
  344.  
  345.    local oFont
  346.  
  347.    if ! Empty( ( cAlias )->FntName )
  348.       oFont = TFont():New( AllTrim( ( cAlias )->FntName ),;
  349.                            ( cAlias )->FntWidth,;
  350.                            ( cAlias )->FntHeight,;
  351.                            .f., ( cAlias )->FntBold,,,,;
  352.                            ( cAlias )->FntItalic )
  353.    endif
  354.  
  355. return oFont
  356.  
  357. //----------------------------------------------------------------------------//
  358.