home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / powervww / pvdialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-05  |  19.5 KB  |  1,080 lines

  1. //  ____________________________________________________
  2. // |                                                    |
  3. // |  Project:     POWER VIEW INTERFACE                 |
  4. // |  File:        PVDIALOG.CPP                         |
  5. // |  Compiler:    WPP386 (10.6)                        |
  6. // |                                                    |
  7. // |  Subject:     Dialog boxes support implementation  |
  8. // |                                                    |
  9. // |  Author:      Emil Dotchevski                      |
  10. // |____________________________________________________|
  11. //
  12. // E-mail: zajo@geocities.com
  13. // URL:    http://www.geocities.com/SiliconValley/Bay/3577
  14.  
  15. #define uses_app
  16. #define uses_desk
  17. #define uses_dialog
  18. #define uses_icons
  19. #define uses_lbox
  20.  
  21. #include "PVuses.h"
  22.  
  23. #define _ALIGN_LEFT     1
  24. #define _ALIGN_RIGHT    2
  25. #define _ALIGN_CENTER   3
  26.  
  27. struct Tfill
  28. {
  29.   int x;
  30.   int y;
  31.   int max_xl;
  32.   int max_yl;
  33.   boolean fill;
  34. };
  35.  
  36. struct Tmark
  37. {
  38.   int x;
  39.   int y;
  40. };
  41.  
  42. static Tmark mrk = { 0, 0 };
  43. static Tmark mrk0 = { 0, 0 };
  44. static Tmark mrk1 = { 0, 0 };
  45. static Tmark mrk2 = { 0, 0 };
  46. static Tmark mrk3 = { 0, 0 };
  47. static Tmark mrk4 = { 0, 0 };
  48. static Tmark mrk5 = { 0, 0 };
  49. static Tmark mrk6 = { 0, 0 };
  50. static Tmark mrk7 = { 0, 0 };
  51. static Tmark mrk8 = { 0, 0 };
  52. static Tmark mrk9 = { 0, 0 };
  53.  
  54. static int hspc, vspc;
  55. static Tfill local;
  56. static Tfill stack[0x10];
  57. static uint sp = 0;
  58. static Tset rights;
  59. static Tset centers;
  60. static Tdialog *dlg;
  61.  
  62. //Tdialog publics:
  63.  
  64. Tdialog::Tdialog( char *t, int _xl, int _yl ):
  65.   Twindow( t, _xl, _yl )
  66. {
  67.   set_flags( ifSELECTABLE+ifICONIZEABLE+ifRESIZEABLE+ifTILEABLE, 0 );
  68.   set_flags( ifSTAY, __stay() );
  69.   set_state( isON_TOP, 1 );
  70.   dlg_handler = NULL;
  71.   dlg_validator = NULL;
  72.   xl_min = 1; yl_min = 1;
  73.   !commands;
  74.   commands>>cmWIN_RESTORE;
  75.   dlg_saved = dlg;
  76. }
  77.  
  78. boolean Tdialog::valid( uint stop_st )
  79. {
  80.   boolean v;
  81.  
  82.   v = 1;
  83.   if( stop_st==cmDONE ) stop_st=cmCANCEL;
  84.   if( stop_st!=cmCANCEL && stop_st!=cmVALID )
  85.     handle_command( NULL, cmDLG_RECORD_HISTORY );
  86.   v = Twindow::valid( stop_st );
  87.   if( dlg_validator!=NULL && v ) v = dlg_validator( stop_st );
  88.   if( stop_st == cmVALID ) return v;
  89.   if( v )
  90.     if( stop_st != cmCANCEL )
  91.       ok_item();
  92.     else
  93.       cancel_item();
  94.   else
  95.     modal_broadcast( cmDLG_RESET );
  96.   if( !v ) redraw();
  97.   item_acted = NULL;
  98.   return v;
  99. }
  100.  
  101. uint Tdialog::exec( void )
  102. {
  103.   uint ex;
  104.  
  105.   if( last == NULL ) return cmCANCEL;
  106.   tab_next( -1 );
  107.   handle_command( NULL, cmDLG_RESET );
  108.   if( first_focused != NULL ) put_command( first_focused, cmFOCUS );
  109.   item_acted = NULL;
  110.   ex = Twindow::exec();
  111.   if( ex==cmDONE ) ex = cmCANCEL;
  112.   return ex;
  113. }
  114.  
  115. //Tdialog protected:
  116.  
  117. boolean Tdialog::isit_4u( Tevent &ev )
  118. {
  119.   Twindow::isit_4u( ev );
  120.   return 1;
  121. }
  122.  
  123. void Tdialog::event_handler( Tevent &ev )
  124. {
  125.   if( ev.code==evCOMMAND && ev.destination==this && ev.CMD_CODE==cmDONE &&
  126.       valid(cmDONE) && (!state(isSELECTED) || release_focus()) && state(isMODAL) )
  127.   {
  128.     stop(cmDONE);
  129.     handled(ev);
  130.     return;
  131.   }
  132.   if( Twindow::isit_4u(ev) ) Twindow::event_handler( ev );
  133.   if( ev.code==evCOMMAND && ev.CMD_CODE==cmDLG_RECORD_HISTORY ) handled( ev );
  134.   if( ev.code<evCOMMAND && item_acted!=NULL && dlg_handler!=NULL )
  135.   {
  136.     dlg_handler( item_acted );
  137.     item_acted = NULL;
  138.   }
  139. }
  140.  
  141. //DIALOG ITEMS ARRANGING
  142.  
  143. /*
  144.   Description:
  145.     Construct a new dialog box with given title.
  146.   Entry:
  147.     t - title of the dialog box.
  148.   Exit:
  149.     Return pointer to the dialog box.
  150. */
  151. Tdialog *dialog( char *t )
  152. {
  153.   dlg = NEW( Tdialog( t, 5, 3 ) );
  154.   extern_dialog( dlg );
  155.   return dlg;
  156. }
  157.  
  158. /*
  159.   Description:
  160.     Initialize externaly constructed dialog box for items setup.
  161.   Entry:
  162.     p - pointer to the dialog box.
  163. */
  164. void extern_dialog( Tdialog *p )
  165. {
  166.   dlg = p;
  167.   local.x = 2;
  168.   local.y = 2;
  169.   local.max_xl = 0;
  170.   local.max_yl = 0;
  171.   local.fill = 0;
  172.   hspc = 0; vspc = 0;
  173.   sp = 0;
  174.   push();
  175.   dlg->first_focused = NULL;
  176.   _focused();
  177.   ~centers; ~rights;
  178. }
  179.  
  180. /*
  181.   Description:
  182.     Update internal parameters after inserting an item in the dialog box.
  183.   Entry:
  184.     item_xl, item_yl: item's bounds
  185. */
  186. static void item_in( int item_xl, int item_yl )
  187. {
  188.   int xx, yy, rx, ry;
  189.   char align;
  190.  
  191.   xx = local.x+item_xl; if( xx > dlg->xl ) rx = xx; else rx = dlg->xl;
  192.   yy = local.y+item_yl; if( yy > dlg->yl ) ry = yy; else ry = dlg->yl;
  193.   if( local.max_xl < xx ) local.max_xl = xx;
  194.   if( local.max_yl < yy ) local.max_yl = yy;
  195.   dlg->resize( rx, ry );
  196.   _aleft(); align = __align();
  197.   if( align == _ALIGN_CENTER ) centers << local.y;
  198.   if( align == _ALIGN_RIGHT ) rights << local.y;
  199.   if( local.fill ) local.x = xx + hspc; else local.y = yy + vspc;
  200. }
  201.  
  202. /*
  203.   Description:
  204.     Insert an item in the dialog box. Item must be constructed.
  205.   Entry:
  206.     item             - pointer to the item to insert;
  207.     item_xl, item_yl - requested item's bounds.
  208. */
  209. void put_item( Titem *item, int item_xl, int item_yl )
  210. {
  211.   int x, y;
  212.  
  213.   x = local.x; y = local.y;
  214.   item_in( item_xl, item_yl );
  215.   dlg->put_in( item, x, y );
  216.   item->set_flags( ifSTAY, __stay() );
  217.   if( __focused() && item->flags( ifSELECTABLE ) ) dlg->first_focused = item;
  218. }
  219.  
  220. /*
  221.   Description:
  222.     Specify how many horizontal text positions to leave between two items.
  223.   Entry:
  224.     s - requested text positions.
  225. */
  226. void hspacing( int s )
  227. {
  228.   hspc = s;
  229. }
  230.  
  231. /*
  232.   Description:
  233.     Specify how many vertical text positions to leave between two items.
  234.   Entry:
  235.     s - requested text positions.
  236. */
  237. void vspacing( int s )
  238. {
  239.   vspc = s;
  240. }
  241.  
  242. /*
  243.   Description:
  244.     Specify horizontal items arrange.
  245. */
  246. void hor( void )
  247. {
  248.   local.fill = 1;
  249. }
  250.  
  251. /*
  252.   Description:
  253.     Specify vertical items arrange.
  254. */
  255. void ver( void )
  256. {
  257.   local.fill = 0;
  258. }
  259.  
  260. /*
  261.   Description:
  262.     Return TRUE if hor, FALSE if ver.
  263. */
  264. boolean fill( void )
  265. {
  266.   return local.fill;
  267. }
  268.  
  269. /*
  270.   Description:
  271.     Move internal cursor to a new line.
  272. */
  273. void nl( void )
  274. {
  275.   local.x = stack[sp - 1].x;
  276.   local.y = local.max_yl + vspc;
  277. }
  278.  
  279. /*
  280.   Description:
  281.     Move internal cursor to a new column.
  282. */
  283. void nc( void )
  284. {
  285.   local.x = local.max_xl + hspc;
  286.   local.y = stack[sp - 1].y;
  287. }
  288.  
  289. /*
  290.   Description:
  291.     Place in the internal stack current dialog context. After that a call to
  292.     nl, nc, etc. will work in a new local region.
  293. */
  294. void push( void )
  295. {
  296.   stack[sp++] = local;
  297.   local.max_xl = 0;
  298.   local.max_yl = 0;
  299. }
  300.  
  301. /*
  302.   Description:
  303.     Insert all the items arranged since the push like one big item in the
  304.     previously saved dialog context.
  305. */
  306. void pop( void )
  307. {
  308.   int mx, my;
  309.  
  310.   mx = local.max_xl;
  311.   my = local.max_yl;
  312.   local = stack[--sp];
  313.   item_in( mx - local.x, my - local.y );
  314. }
  315.  
  316. static Titem *dlg_frame;
  317.  
  318. /*
  319.   Description:
  320.     Start of frame w/ title. All items that are arranged until endfr will
  321.     be framed out.
  322. */
  323. Titem *frame( char *t )
  324. {
  325.   dlg_frame = dlg->frame( t );
  326.   push();
  327.   local.x++;
  328.   local.y++;
  329.   push();
  330.   return dlg_frame;
  331. }
  332.  
  333. /*
  334.   Description:
  335.     Start of frame w/o title. All items that are arranged until endfr will
  336.     be framed out.
  337. */
  338. Titem *frame( void )
  339. {
  340.   return frame( "" );
  341. }
  342.  
  343. /*
  344.   Description:
  345.     End of frame. All items that are arranged since frame will
  346.     be framed out.
  347. */
  348. void endfr( void )
  349. {
  350.   pop();
  351.   dlg->endfr();
  352.   local = stack[--sp];
  353.   item_in( dlg_frame->xl + 1, dlg_frame->yl );
  354. }
  355.  
  356. /*
  357.   Description:
  358.     Move internal cursor one text position to the right.
  359. */
  360. void hspace( void )
  361. {
  362.   local.x++;
  363. }
  364.  
  365. /*
  366.   Description:
  367.     Move internal cursor one text position to the bottom.
  368. */
  369. void vspace( void )
  370. {
  371.   local.y++;
  372. }
  373.  
  374. /*
  375.   Description:
  376.     Move internal cursor one text position to the right or one text position
  377.     to the bottom depending on the current arrange style.
  378. */
  379. void space( void )
  380. {
  381.   if( local.fill )
  382.     local.x++;
  383.   else
  384.     local.y++;
  385. }
  386.  
  387. /*
  388.   Description:
  389.     Move internal cursor multiply text position to the right.
  390.   Entry:
  391.     tb - number of text positions.
  392. */
  393. void hspaces( int tb )
  394. {
  395.   local.x += tb;
  396. }
  397.  
  398. /*
  399.   Description:
  400.     Move internal cursor multiply text position to the bottom.
  401.   Entry:
  402.     tb - number of text positions.
  403. */
  404. void vspaces( int tb )
  405. {
  406.   local.y += tb;
  407. }
  408.  
  409. /*
  410.   Description:
  411.     Move internal cursor multiply text positions to the right or multiply
  412.     text positions to the bottom depending on the current arrange style.
  413.   Entry:
  414.     tb - number of text positions.
  415. */
  416. void spaces( int tb )
  417. {
  418.   if( local.fill )
  419.     local.x += tb;
  420.   else
  421.     local.y += tb;
  422. }
  423.  
  424. /*
  425.   Description:
  426.     Remember internal cursor current position.
  427. */
  428. void mark( void )
  429. {
  430.   mrk.x = local.x;
  431.   mrk.y = local.y;
  432. }
  433.  
  434. void mark0( void )
  435. {
  436.   mrk0.x = local.x;
  437.   mrk0.y = local.y;
  438. }
  439.  
  440. void mark1( void )
  441. {
  442.   mrk1.x = local.x;
  443.   mrk1.y = local.y;
  444. }
  445.  
  446. void mark2( void )
  447. {
  448.   mrk2.x = local.x;
  449.   mrk2.y = local.y;
  450. }
  451.  
  452. void mark3( void )
  453. {
  454.   mrk3.x = local.x;
  455.   mrk3.y = local.y;
  456. }
  457.  
  458. void mark4( void )
  459. {
  460.   mrk4.x = local.x;
  461.   mrk4.y = local.y;
  462. }
  463.  
  464. void mark5( void )
  465. {
  466.   mrk5.x = local.x;
  467.   mrk5.y = local.y;
  468. }
  469.  
  470. void mark6( void )
  471. {
  472.   mrk6.x = local.x;
  473.   mrk6.y = local.y;
  474. }
  475.  
  476. void mark7( void )
  477. {
  478.   mrk7.x = local.x;
  479.   mrk7.y = local.y;
  480. }
  481.  
  482. void mark8( void )
  483. {
  484.   mrk8.x = local.x;
  485.   mrk8.y = local.y;
  486. }
  487.  
  488. void mark9( void )
  489. {
  490.   mrk9.x = local.x;
  491.   mrk9.y = local.y;
  492. }
  493.  
  494. /*
  495.   Description:
  496.     Retrieve saved internal cursor position.
  497. */
  498. void gmrk( void )
  499. {
  500.   local.x = mrk.x;
  501.   local.y = mrk.y;
  502. }
  503.  
  504. void gmrk0( void )
  505. {
  506.   local.x = mrk0.x;
  507.   local.y = mrk0.y;
  508. }
  509.  
  510. void gmrk1( void )
  511. {
  512.   local.x = mrk1.x;
  513.   local.y = mrk1.y;
  514. }
  515.  
  516. void gmrk2( void )
  517. {
  518.   local.x = mrk2.x;
  519.   local.y = mrk2.y;
  520. }
  521.  
  522. void gmrk3( void )
  523. {
  524.   local.x = mrk3.x;
  525.   local.y = mrk3.y;
  526. }
  527.  
  528. void gmrk4( void )
  529. {
  530.   local.x = mrk4.x;
  531.   local.y = mrk4.y;
  532. }
  533.  
  534. void gmrk5( void )
  535. {
  536.   local.x = mrk5.x;
  537.   local.y = mrk5.y;
  538. }
  539.  
  540. void gmrk6( void )
  541. {
  542.   local.x = mrk6.x;
  543.   local.y = mrk6.y;
  544. }
  545.  
  546. void gmrk7( void )
  547. {
  548.   local.x = mrk7.x;
  549.   local.y = mrk7.y;
  550. }
  551.  
  552. void gmrk8( void )
  553. {
  554.   local.x = mrk8.x;
  555.   local.y = mrk8.y;
  556. }
  557.  
  558. void gmrk9( void )
  559. {
  560.   local.x = mrk9.x;
  561.   local.y = mrk9.y;
  562. }
  563.  
  564. /*
  565.   Description:
  566.     Retrieve column of saved internal cursor position.
  567. */
  568. void gmrc( void )
  569. {
  570.   local.x = mrk.x;
  571. }
  572.  
  573. void gmrc0( void )
  574. {
  575.   local.x = mrk0.x;
  576. }
  577.  
  578. void gmrc1( void )
  579. {
  580.   local.x = mrk1.x;
  581. }
  582.  
  583. void gmrc2( void )
  584. {
  585.   local.x = mrk2.x;
  586. }
  587.  
  588. void gmrc3( void )
  589. {
  590.   local.x = mrk3.x;
  591. }
  592.  
  593. void gmrc4( void )
  594. {
  595.   local.x = mrk4.x;
  596. }
  597.  
  598. void gmrc5( void )
  599. {
  600.   local.x = mrk5.x;
  601. }
  602.  
  603. void gmrc6( void )
  604. {
  605.   local.x = mrk6.x;
  606. }
  607.  
  608. void gmrc7( void )
  609. {
  610.   local.x = mrk7.x;
  611. }
  612.  
  613. void gmrc8( void )
  614. {
  615.   local.x = mrk8.x;
  616. }
  617.  
  618. void gmrc9( void )
  619. {
  620.   local.x = mrk9.x;
  621. }
  622.  
  623. /*
  624.   Description:
  625.     Retrieve line of saved internal cursor position.
  626. */
  627. void gmrl( void )
  628. {
  629.   local.y = mrk.y;
  630. }
  631.  
  632. void gmrl0( void )
  633. {
  634.   local.y = mrk0.y;
  635. }
  636.  
  637. void gmrl1( void )
  638. {
  639.   local.y = mrk1.y;
  640. }
  641.  
  642. void gmrl2( void )
  643. {
  644.   local.y = mrk2.y;
  645. }
  646.  
  647. void gmrl3( void )
  648. {
  649.   local.y = mrk3.y;
  650. }
  651.  
  652. void gmrl4( void )
  653. {
  654.   local.y = mrk4.y;
  655. }
  656.  
  657. void gmrl5( void )
  658. {
  659.   local.y = mrk5.y;
  660. }
  661.  
  662. void gmrl6( void )
  663. {
  664.   local.y = mrk6.y;
  665. }
  666.  
  667. void gmrl7( void )
  668. {
  669.   local.y = mrk7.y;
  670. }
  671.  
  672. void gmrl8( void )
  673. {
  674.   local.y = mrk8.y;
  675. }
  676.  
  677. void gmrl9( void )
  678. {
  679.   local.y = mrk9.y;
  680. }
  681.  
  682. //DIALOG EXECUTING
  683.  
  684. /*
  685.   Description:
  686.     Resize arranged dialog to hold all the controls.
  687. */
  688. void end_of_dialog( void )
  689. {
  690.   int xx, xmin, xmax, n;
  691.   int i;
  692.   Titem *p;
  693.  
  694.   dlg->resize( dlg->xl + 1, dlg->yl + 1 );
  695.   for( i = 0; i < 256; i++ )
  696.     if( ( i & centers ) || ( i & rights ) )
  697.     {
  698.       xmin = 1000; xmax = -1000;
  699.       p = dlg->first();
  700.       while( p != NULL )
  701.       {
  702.         if( ( p->y == i ) && p->flags( ifVISIBLE ) )
  703.         {
  704.           if( ( n = p->x + p->bound_x ) < xmin ) xmin = n;
  705.           xx = n + p->bound_xl;
  706.           if( xx > xmax ) xmax = xx;
  707.         }
  708.         p = p->nextl();
  709.       }
  710.       xx = ( dlg->xl - xmax + xmin );
  711.       if( i & centers ) xx >>= 1; else xx -= 2;
  712.       xx -= xmin;
  713.       p = dlg->first();
  714.       while( p != NULL )
  715.       {
  716.         if( ( p->y == i ) && p->flags( ifVISIBLE ) )
  717.           p->drag( p->x + xx, p->y );
  718.         p = p->nextl();
  719.       }
  720.     }
  721. }
  722.  
  723. void done_dialog( void )
  724. {
  725.   Tdialog *_dlg = dlg;
  726.   dlg = dlg->dlg_saved;
  727.   if( !_dlg->flags( ifSTAY ) ) DELETE( _dlg );
  728. }
  729.  
  730. /*
  731.   Description:
  732.     Execute just arranged dialog box.
  733.   Exit:
  734.     Return dialog exit code - usualy this is the command of the button that
  735.     has been pressed.
  736. */
  737. uint run( void )
  738. {
  739.   end_of_dialog();
  740.   uint result = exec_dialog( dlg );
  741.   done_dialog();
  742.   return result;
  743. }
  744.  
  745. /*
  746.   Description:
  747.     Insert an 'OK' button at the bottom of the dialog box and call run.
  748. */
  749. void bok( void )
  750. {
  751.   hor(); nl(); vspace(); _acenter();
  752. #ifdef CYR
  753.   kbutton( " Ä'¬Ñ⌐ " );
  754. #else
  755.   kbutton( "  OK  " );
  756. #endif
  757.   run();
  758. }
  759.  
  760. /*
  761.   Description:
  762.     Insert 'OK' and 'Cancel' buttons at the bottom of the dialog box
  763.     and call run.
  764.   Exit:
  765.     Return boolean: TRUE - ok, FALSE - cancel.
  766. */
  767. boolean bkc( void )
  768. {
  769.   hor(); nl(); vspace(); hspc = 1; _acenter();
  770. #ifdef CYR
  771.   kbutton( " Ä'¬Ñ⌐ " );
  772.   cbutton( " Ä▓¬áº " );
  773. #else
  774.   kbutton( "  OK  " );
  775.   cbutton( "Cancel" );
  776. #endif
  777.   return run() == cmOK;
  778. }
  779.  
  780. /*
  781.   Description:
  782.     Insert 'OK', 'Cancel' and 'Help' buttons at the bottom of the dialog box
  783.     and call run.
  784.   Exit:
  785.     Return boolean: TRUE - ok, FALSE - cancel.
  786. */
  787. boolean bkch( void )
  788. {
  789.   hor(); vspc = 0; hspc = 1; nl(); vspace(); _acenter();
  790. #ifdef CYR
  791.   kbutton( " Ä'¬Ñ⌐ " );
  792.   cbutton( " Ä▓¬áº " );
  793.   hbutton( " Å«¼«╣ " );
  794. #else
  795.   kbutton( "  OK  " );
  796.   cbutton( "Cancel" );
  797.   hbutton( " Help " );
  798. #endif
  799.   return run() == cmOK;
  800. }
  801.  
  802. /*
  803.   Description:
  804.     Insert 'Yes' and 'No' buttons at the bottom of the dialog box
  805.     and call run.
  806.   Exit:
  807.     Return boolean: TRUE - yes, FALSE - no.
  808. */
  809. boolean byn( void )
  810. {
  811.   hor(); nl(); vspace(); hspc = 1; _acenter();
  812. #ifdef CYR
  813.   button( "  |~äá  ", cmYES );
  814.   dcbutton( "  |~ìÑ  ", cmNO );
  815. #else
  816.   button( " |~Yes  ", cmYES );
  817.   dcbutton( "  |~No  ", cmNO );
  818. #endif
  819.   return run() == cmYES;
  820. }
  821.  
  822. /*
  823.   Description:
  824.     Insert 'Yes', 'No' and 'Help' buttons at the bottom of the dialog box
  825.     and call run.
  826.   Exit:
  827.     Return boolean: TRUE - yes, FALSE - no.
  828. */
  829. boolean bynh( void )
  830. {
  831.   hor(); nl(); vspace(); hspc = 1; _acenter();
  832. #ifdef CYR
  833.   button( "  |~äá  ", cmYES );
  834.   dcbutton( "  |~ìÑ  ", cmNO );
  835.   hbutton(  " Å«¼«╣ " );
  836. #else
  837.   button( " |~Yes  ", cmYES );
  838.   dcbutton( "  |~No  ", cmNO );
  839.   hbutton( " Help " );
  840. #endif
  841.   return run() == cmYES;
  842. }
  843.  
  844. /*
  845.   Description:
  846.     Insert 'Yes', 'No' and 'Cancel' buttons at the bottom of the dialog box
  847.     and call run.
  848.   Exit:
  849.     Return dialog exit code - command of the button that has been pressed.
  850. */
  851. uint bync( void )
  852. {
  853.   hor(); nl(); vspace(); hspc = 1; _acenter();
  854. #ifdef CYR
  855.   button( "  |~äá  ", cmYES );
  856.   dcbutton( "  |~ìÑ  ", cmNO );
  857.   cbutton( " Ä▓¬áº " );
  858. #else
  859.   button( " |~Yes  ", cmYES );
  860.   dcbutton( "  |~No  ", cmNO );
  861.   cbutton( "Cancel" );
  862. #endif
  863.   return run();
  864. }
  865.  
  866. /*
  867.   Description:
  868.     Insert 'Yes', 'No', 'Cancel' and 'Help' buttons at the bottom of the
  869.     dialog box and call run.
  870.   Exit:
  871.     Return dialog exit code - command of the button that has been pressed.
  872. */
  873. uint bynch( void )
  874. {
  875.   hor(); nl(); vspace(); hspc = 1; _acenter();
  876. #ifdef CYR
  877.   button( "  |~äá  ", cmYES );
  878.   dcbutton( "  |~ìÑ  ", cmNO );
  879.   cbutton( " Ä▓¬áº " );
  880.   hbutton( " Å«¼«╣ " );
  881. #else
  882.   button( " |~Yes  ", cmYES );
  883.   dcbutton( "  |~No  ", cmNO );
  884.   cbutton( "Cancel" );
  885.   hbutton( " Help " );
  886. #endif
  887.   return run();
  888. }
  889.  
  890. /*
  891.   Description:
  892.     Insert 'Retry' and 'Abort' buttons at the bottom of the dialog box
  893.     and call run.
  894.   Exit:
  895.     Return boolean: TRUE - retry, FALSE - abort.
  896. */
  897. boolean bra( void )
  898. {
  899.   hor(); nl(); vspace(); hspc = 1; _acenter();
  900. #ifdef CYR
  901.   kbutton( "|~ì«ó «»¿▓" );
  902.   cbutton( " |~Ä▓¬áº " );
  903. #else
  904.   kbutton( "|~Retry" );
  905.   cbutton( "|~Abort" );
  906. #endif
  907.   return run() == cmOK;
  908. }
  909.  
  910. /*
  911.   Description:
  912.     Insert 'Retry', 'Abort' and 'Help' buttons at the bottom of the dialog
  913.     box and call run.
  914.   Exit:
  915.     Return boolean: TRUE - retry, FALSE - abort.
  916. */
  917. boolean brah( void )
  918. {
  919.   hor(); nl(); vspace(); hspc = 1; _acenter();
  920. #ifdef CYR
  921.   kbutton( "|~ì«ó «»¿▓" );
  922.   cbutton( " |~Ä▓¬áº " );
  923.   hbutton( " Å«¼«╣ " );
  924. #else
  925.   kbutton( "|~Retry" );
  926.   cbutton( "|~Abort" );
  927.   hbutton( " Help " );
  928. #endif
  929.   return run() == cmOK;
  930. }
  931.  
  932. //DIALOG HANDLING
  933.  
  934. /*
  935.   Description:
  936.     Specify dialog handler proc. It must be a void function expecting a
  937.     pointer as parameter. This handler will be called whenever an item in
  938.     the dialog box has been changed, allowing the handler to control some
  939.     of the items.
  940.   Entry:
  941.     p - address of the handler proc for current dialog box.
  942. */
  943. void handler( Tdlg_handler p )
  944. {
  945.   dlg->dlg_handler = p;
  946. }
  947.  
  948. /*
  949.   Description:
  950.     Specify dialog validation proc. It must be a function expecting a
  951.     uint as a parameter (validation code, usually this is command of the
  952.     button that has been pressed) and returning boolean - allow or not
  953.     dialog box to be terminated.
  954.   Entry:
  955.     p - address of the validation proc for current dialog box.
  956. */
  957. void validator( Tdlg_validator p )
  958. {
  959.   dlg->dlg_validator = p;
  960. }
  961.  
  962. /*
  963.   Description:
  964.     Called from a dialog handler proc or from dialog validator proc. This
  965.     instructs the dialog box to focus specified item.
  966.   Entry:
  967.     p - address of the item to be focused.
  968. */
  969. void focus( Titem *p )
  970. {
  971.   p->focus();
  972. }
  973.  
  974. /*
  975.   Description:
  976.     Called from a dialog handler proc or from dialog validator proc. This
  977.     instructs the dialog box to enable or to disable specified item.
  978.   Entry:
  979.     p - address of the item to be enabled/disabled.
  980.     f - TRUE: enable, FALSE: disable item.
  981. */
  982. void set_enable( Titem *p, boolean f )
  983. {
  984.   p->set_state( isDISABLED, !f );
  985. }
  986.  
  987. /*
  988.   Description:
  989.     Return a pointer to the currently selected item.
  990. */
  991. Titem *current( void )
  992. {
  993.   return dlg->current;
  994. }
  995.  
  996. //PREFIXES
  997.  
  998. char align_ = 0;
  999. boolean focused_ = 0;
  1000. boolean stay_ = 0;
  1001.  
  1002. /*
  1003.   Description:
  1004.     Specify left alignement for dialog items. Call just before constructing
  1005.     such items.
  1006. */
  1007. void _aleft( void )
  1008. {
  1009.   if( !align_ ) align_ = _ALIGN_LEFT;
  1010. }
  1011.  
  1012. /*
  1013.   Description:
  1014.     Specify right alignement for dialog items. Call just before constructing
  1015.     such items.
  1016. */
  1017. void _aright( void )
  1018. {
  1019.   if( !align_ ) align_ = _ALIGN_RIGHT;
  1020. }
  1021.  
  1022. /*
  1023.   Description:
  1024.     Specify center alignement for dialog items. Call just before constructing
  1025.     such items.
  1026. */
  1027. void _acenter( void )
  1028. {
  1029.   if( !align_ ) align_ = _ALIGN_CENTER;
  1030. }
  1031.  
  1032. char __align( void )
  1033. {
  1034.   char result = _ALIGN_LEFT;
  1035.  
  1036.   if( align_ ) result = align_;
  1037.   align_ = 0;
  1038.   return result;
  1039. }
  1040.  
  1041. /*
  1042.   Description:
  1043.     Specify the following item that constructs to be focused when dialog box
  1044.     executes.
  1045. */
  1046. void _focused( void )
  1047. {
  1048.   focused_ = 1;
  1049. }
  1050.  
  1051. boolean __focused( void )
  1052. {
  1053.   boolean result;
  1054.  
  1055.   result = focused_;
  1056.   focused_ = 0;
  1057.   return result;
  1058. }
  1059.  
  1060. /*
  1061.   Description:
  1062.     Specify the following item that constructs not to be disposed when
  1063.     dialog box terminates. You must dispose it later by calling its
  1064.     destructor, as follows:
  1065.     dispose( item,done )
  1066. */
  1067. void _stay( void )
  1068. {
  1069.   stay_ = 1;
  1070. }
  1071.  
  1072. boolean __stay( void )
  1073. {
  1074.   boolean result;
  1075.  
  1076.   result = stay_;
  1077.   stay_ = 0;
  1078.   return result;
  1079. }
  1080.