home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 10 / ioProg_10.iso / soft / optima / samples.z / ViewHelper.wxc < prev    next >
Encoding:
Text File  |  1996-05-08  |  9.7 KB  |  404 lines

  1. Save Format v1.3
  2. @begin ClassFile "ViewHelper"
  3.  Exported 0;
  4.  
  5.  @begin UserFunction "ViewHelper( WForm * form, ViewCreateFunction create )"
  6.   GencodeSrcLine 17;
  7.   FunctionName "ViewHelper::ViewHelper( WForm * form, ViewCreateFunction create )";
  8.  @end;
  9.  
  10.  @begin UserFunction "Prototype for ViewHelper( WForm * form, ViewCreateFunction create )"
  11.   Private 1;
  12.   GencodeSrcLine 35;
  13.   FunctionName "ViewHelper::Prototype for ViewHelper( WForm * form, ViewCreateFunction create )";
  14.  @end;
  15.  
  16.  @begin UserFunction "~ViewHelper()"
  17.   GencodeSrcLine 26;
  18.   FunctionName "ViewHelper::~ViewHelper()";
  19.  @end;
  20.  
  21.  @begin UserFunction "Prototype for ~ViewHelper()"
  22.   Private 1;
  23.   GencodeSrcLine 37;
  24.   FunctionName "ViewHelper::Prototype for ~ViewHelper()";
  25.  @end;
  26.  
  27.  @begin UserFunction "Open( WForm * parent )"
  28.   GencodeSrcLine 30;
  29.   FunctionName "ViewHelper::Open( WForm * parent )";
  30.  @end;
  31.  
  32.  @begin UserFunction "Prototype for Open( WForm * parent )"
  33.   Private 1;
  34.   GencodeSrcLine 39;
  35.   FunctionName "ViewHelper::Prototype for Open( WForm * parent )";
  36.  @end;
  37.  
  38.  @begin UserFunction "Create( WListView * listView, WQuery * query )"
  39.   GencodeSrcLine 52;
  40.   FunctionName "ViewHelper::Create( WListView * listView, WQuery * query )";
  41.  @end;
  42.  
  43.  @begin UserFunction "Prototype for Create( WListView * listView, WQuery * query )"
  44.   Private 1;
  45.   GencodeSrcLine 41;
  46.   FunctionName "ViewHelper::Prototype for Create( WListView * listView, WQuery * query )";
  47.  @end;
  48.  
  49.  @begin UserFunction "SortList( WInt column )"
  50.   GencodeSrcLine 90;
  51.   FunctionName "ViewHelper::SortList( WInt column )";
  52.  @end;
  53.  
  54.  @begin UserFunction "Prototype for SortList( WInt column )"
  55.   Private 1;
  56.   GencodeSrcLine 43;
  57.   FunctionName "ViewHelper::Prototype for SortList( WInt column )";
  58.  @end;
  59.  
  60.  @begin UserFunction "Destroy( void )"
  61.   GencodeSrcLine 96;
  62.   FunctionName "ViewHelper::Destroy( void )";
  63.  @end;
  64.  
  65.  @begin UserFunction "Prototype for Destroy( void )"
  66.   Private 1;
  67.   GencodeSrcLine 45;
  68.   FunctionName "ViewHelper::Prototype for Destroy( void )";
  69.  @end;
  70.  
  71.  @begin UserFunction "Refresh( void )"
  72.   GencodeSrcLine 119;
  73.   FunctionName "ViewHelper::Refresh( void )";
  74.  @end;
  75.  
  76.  @begin UserFunction "Prototype for Refresh( void )"
  77.   Private 1;
  78.   GencodeSrcLine 47;
  79.   FunctionName "ViewHelper::Prototype for Refresh( void )";
  80.  @end;
  81.  
  82.  @begin UserFunction "ToggleSortOrder( void )"
  83.   GencodeSrcLine 131;
  84.   FunctionName "ViewHelper::ToggleSortOrder( void )";
  85.  @end;
  86.  
  87.  @begin UserFunction "Prototype for ToggleSortOrder( void )"
  88.   Private 1;
  89.   GencodeSrcLine 49;
  90.   FunctionName "ViewHelper::Prototype for ToggleSortOrder( void )";
  91.  @end;
  92.  
  93.  @begin UserFunction "sortList( void )"
  94.   Private 1;
  95.   GencodeSrcLine 137;
  96.   FunctionName "ViewHelper::sortList( void )";
  97.  @end;
  98.  
  99.  @begin UserFunction "Prototype for sortList( void )"
  100.   Private 1;
  101.   GencodeSrcLine 51;
  102.   FunctionName "ViewHelper::Prototype for sortList( void )";
  103.  @end;
  104.  
  105.  @begin HPPPrefixBlock
  106. @begin-code HPPPrefix
  107.  
  108. // Declarations added here will be included at the top of the .HPP file
  109.  
  110. // Define a member function pointer to handle calling the form Create method
  111.  
  112. typedef WBool WCMDEF (WForm::*ViewCreateFunction)( WForm * parent );
  113.  
  114. @end-code;
  115.   GencodeSrcLine 11;
  116.  @end;
  117.  
  118.  @begin CPPPrefixBlock
  119. @begin-code CPPPrefix
  120.  
  121. // Code added here will be included at the top of the .CPP file
  122.  
  123. //  Include definitions for resources.
  124. #include "WRes.h"
  125.  
  126. #define     VH_PINNED   0
  127.  
  128. @end-code;
  129.   GencodeSrcLine 11;
  130.  @end;
  131.  
  132.  @begin ClassContentsBlock
  133. @begin-code ClassContents
  134.  
  135.     public:
  136.         // add your public instance data here
  137.     private:
  138.         // add your private instance data here
  139.         ViewCreateFunction  _create;    // The form's Create function.
  140.         WForm *             _form;      // The form we are helping
  141.         WListView *         _listView;
  142.         WBool               _open;
  143.         WQuery *            _query;
  144.         WString             _querySQL;  // Query for list without ORDER BY
  145.         WInt                _sortColumn;
  146.         WBool               _sortAscending;
  147.  
  148.     protected:
  149.         // add your protected instance data here
  150.  
  151. @end-code;
  152.   GencodeSrcLine 20;
  153.  @end;
  154.  
  155. @begin-code GeneratedClassContents
  156.  
  157.  
  158. @end-code;
  159.  
  160. @begin-code Code "ViewHelper::ViewHelper( WForm * form, ViewCreateFunction create )"
  161.  
  162. ViewHelper::ViewHelper( WForm * form, ViewCreateFunction create )
  163. {
  164.     WASSERT( form != NULL );
  165.     _form = form;
  166.     _create = create;
  167.     _open = FALSE;
  168.     _sortColumn = 1;
  169.     _sortAscending = TRUE;
  170. }
  171.  
  172. @end-code;
  173.  
  174. @begin-code Code "ViewHelper::Prototype for ViewHelper( WForm * form, ViewCreateFunction create )"
  175.  
  176.     public:
  177.         ViewHelper( WForm * form, ViewCreateFunction create );
  178.  
  179. @end-code;
  180.  
  181. @begin-code Code "ViewHelper::~ViewHelper()"
  182.  
  183. ViewHelper::~ViewHelper()
  184. {
  185.     
  186. }
  187.  
  188. @end-code;
  189.  
  190. @begin-code Code "ViewHelper::Prototype for ~ViewHelper()"
  191.  
  192.     public:
  193.         ~ViewHelper();
  194.  
  195. @end-code;
  196.  
  197. @begin-code Code "ViewHelper::Open( WForm * parent )"
  198.  
  199. // Open
  200.  
  201. // Load or show the form.
  202.  
  203. // Note: We cannot directly call form->Create() because the form's Create
  204. // routine is not a virtual function.  Instead we pass the address of the 
  205. // correct create function to use in the ViewHelper constructor, and
  206. // use the special C++ syntax "->*" to call it here.
  207.  
  208. WBool ViewHelper::Open( WForm * parent )
  209. {
  210.     if( !_open ) {
  211.         parent->SetCursor( WCursor(WSCWait), TRUE );
  212.         _open = (_form->*_create)( parent );    
  213.         parent->SetCursor( WCursor(), TRUE );    
  214.     }
  215.     else { 
  216.         _form->SetWindowState( WWindowStateNormal );
  217.         _form->Activate();
  218.     }
  219.     return( _open );
  220. }
  221.  
  222. @end-code;
  223.  
  224. @begin-code Code "ViewHelper::Prototype for Open( WForm * parent )"
  225.  
  226.     public:
  227.         WBool Open( WForm * parent );
  228.  
  229. @end-code;
  230.  
  231. @begin-code Code "ViewHelper::Create( WListView * listView, WQuery * query )"
  232.  
  233. WBool ViewHelper::Create( WListView * listView, WQuery * query )
  234. {
  235.     WForm *                 parent;
  236.     WRect                   rect;
  237.     WStatusBar *            status;
  238.  
  239.     WASSERT( listView != NULL );
  240.     WASSERT( query != NULL );
  241.     _listView = listView;
  242.     _query = query;
  243.  
  244.     parent = (WForm *)_form->GetParent();
  245.  
  246.     #if VH_PINNED
  247.         //  Pinning the window to its parent causes the window to move when the 
  248.         //  parent window is moved.
  249.         parent->AddPinnedWindow( _form );
  250.     #endif
  251.     
  252.     // Make the list view fill and track the effective client area of
  253.     // the form.  The effective (adjusted) client area accounts for such
  254.     // things as menus, tool bars, and a status area.
  255.     _form->SetClientWindow( _listView );
  256.     rect = _form->GetClientRectangle();
  257.     _form->AdjustClientRectangle( rect );
  258.  
  259.     // Set Text for status bar
  260.     status = _form->GetStatusBar();
  261.     status->SetText( "Double click or right-mouse click on the first column." );
  262.     
  263.     // Save the query without an Order By clause
  264.     _querySQL = _query->GetSQL();
  265.     
  266.     // Submit the query with an Order By clause.
  267.     SortList( 1 );
  268.  
  269.     return FALSE;
  270. }
  271.  
  272. @end-code;
  273.  
  274. @begin-code Code "ViewHelper::Prototype for Create( WListView * listView, WQuery * query )"
  275.  
  276.     public:
  277.         WBool Create( WListView * listView, WQuery * query );
  278.  
  279. @end-code;
  280.  
  281. @begin-code Code "ViewHelper::SortList( WInt column )"
  282.  
  283. void ViewHelper::SortList( WInt column )
  284. {
  285.     WASSERT( column >= 1 );
  286.     _sortColumn = column;
  287.     sortList();
  288. }
  289.  
  290. @end-code;
  291.  
  292. @begin-code Code "ViewHelper::Prototype for SortList( WInt column )"
  293.  
  294.     public:
  295.         void SortList( WInt column );
  296.  
  297. @end-code;
  298.  
  299. @begin-code Code "ViewHelper::Destroy( void )"
  300.  
  301. // Destroy
  302.  
  303. // Handle the form Destroy event.
  304.  
  305. WBool ViewHelper::Destroy( void )
  306. {
  307.     WForm *             parent;
  308.     
  309.     _form->SetClientWindow( NULL );
  310.         
  311.     parent = (WForm *)_form->GetParent();
  312.     
  313.     #if VH_PINNED
  314.         parent->RemovePinnedWindow( _form );
  315.     #endif
  316.     
  317.     parent->Activate();
  318.     parent->SetFocus();
  319.  
  320.     _open = FALSE;
  321.     
  322.     return FALSE;
  323. }
  324.  
  325. @end-code;
  326.  
  327. @begin-code Code "ViewHelper::Prototype for Destroy( void )"
  328.  
  329.     public:
  330.         WBool Destroy( void );
  331.  
  332. @end-code;
  333.  
  334. @begin-code Code "ViewHelper::Refresh( void )"
  335.  
  336. void ViewHelper::Refresh( void )
  337. {
  338.     #if 0
  339.         // Refresh refetches the locally held rows.  It is very fast but will not resort
  340.         // items etc.
  341.         _query->Refresh();
  342.     #else
  343.         // Resubmit re-executes the query.  This will take longer but it resorts the rows
  344.         _query->Resubmit();
  345.         _query->MoveNext();
  346.     #endif
  347. }
  348.  
  349. @end-code;
  350.  
  351. @begin-code Code "ViewHelper::Prototype for Refresh( void )"
  352.  
  353.     public:
  354.         void Refresh( void );
  355.  
  356. @end-code;
  357.  
  358. @begin-code Code "ViewHelper::ToggleSortOrder( void )"
  359.  
  360. WString ViewHelper::ToggleSortOrder( void )
  361. {
  362.     _sortAscending = !_sortAscending;
  363.     sortList();
  364.     return( _sortAscending ? "&Sort Descending" : "&Sort Ascending" );
  365. }
  366.  
  367. @end-code;
  368.  
  369. @begin-code Code "ViewHelper::Prototype for ToggleSortOrder( void )"
  370.  
  371.     public:
  372.         WString ToggleSortOrder( void );
  373.  
  374. @end-code;
  375.  
  376. @begin-code Code "ViewHelper::sortList( void )"
  377.  
  378. void ViewHelper::sortList( void )
  379. {
  380.     WString     orderedQuery;
  381.     
  382.     _form->SetCursor( WCursor(WSCWait), TRUE );
  383.     orderedQuery.Sprintf( "%s ORDER BY %d", _querySQL.GetText(), _sortColumn );
  384.     if( !_sortAscending ) {
  385.         orderedQuery.Concat( " DESC" );
  386.     }
  387.     _listView->SetPainting( false );
  388.     _query->SetSQL( orderedQuery );
  389.     _query->Open();
  390.     _query->MoveFirst();
  391.     _listView->SetPainting( true );
  392.     _form->SetCursor( WCursor(), TRUE );
  393. }
  394.  
  395. @end-code;
  396.  
  397. @begin-code Code "ViewHelper::Prototype for sortList( void )"
  398.  
  399.     private:
  400.         void sortList( void );
  401.  
  402. @end-code;
  403. @end;
  404.