home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / SRCBDTO.PAK / STRINGS.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  9.1 KB  |  410 lines

  1. //-----------------------------------------------------------------------------
  2. // Visual Database Tools
  3. // Copyright (c) 1996 by Borland International, All Rights Reserved
  4. //
  5. // strings.cpp
  6. // TStrings wrapper class
  7. //-----------------------------------------------------------------------------
  8.  
  9. #include <vdbt\bdto.h>
  10.  
  11. #pragma hdrstop
  12.  
  13. #include "wrapit.h"
  14. #include "misc.h"
  15.  
  16. //-----------------------------------------------------------------------------
  17.  
  18. static void _export STDAPICALLTYPE StringsNotifyEventCallback( int32 data, PITStrings strings )
  19. {
  20.     if (data)
  21.     {
  22.         PTStrings ezStrings = WrapPITStrings( strings );
  23.  
  24.         TStringsNotifySource* source = (TStringsNotifySource*) data;
  25.         (*source)( *ezStrings );
  26.  
  27.         if (ezStrings)
  28.             delete ezStrings;
  29.     }
  30. }
  31.  
  32. void TStrings::AttachOnChange( const TBdtEventSourceBase&, bool attach )
  33. {
  34.     if (strings)
  35.     {
  36.         AttachedOnChange = attach;
  37.         if (attach)
  38.             strings->AttachOnChange( StringsNotifyEventCallback, (int32) &OnChangeSource );
  39.         else
  40.             strings->DetachOnChange( StringsNotifyEventCallback, (int32) &OnChangeSource );
  41.     }
  42. }
  43.  
  44. void TStrings::AttachOnChanging( const TBdtEventSourceBase&, bool attach )
  45. {
  46.     if (strings)
  47.     {
  48.         AttachedOnChanging = attach;
  49.         if (attach)
  50.             strings->AttachOnChanging( StringsNotifyEventCallback, (int32) &OnChangingSource );
  51.         else
  52.             strings->DetachOnChanging( StringsNotifyEventCallback, (int32) &OnChangingSource );
  53.     }
  54. }
  55.  
  56. void TStrings::DetachEvents( void )
  57. {
  58.     if (strings)
  59.     {
  60.         if (AttachedOnChange)
  61.             strings->DetachOnChange( StringsNotifyEventCallback, (int32) &OnChangeSource );
  62.         if (AttachedOnChanging)
  63.             strings->DetachOnChanging( StringsNotifyEventCallback, (int32) &OnChangingSource );
  64.     }
  65. }
  66.  
  67. void TStrings::ReattachEvents( void )
  68. {
  69.     if (strings)
  70.     {
  71.         if (AttachedOnChange)
  72.             strings->AttachOnChange( StringsNotifyEventCallback, (int32) &OnChangeSource );
  73.         if (AttachedOnChanging)
  74.             strings->AttachOnChanging( StringsNotifyEventCallback, (int32) &OnChangingSource );
  75.     }
  76. }
  77.  
  78. //-----------------------------------------------------------------------------
  79.  
  80. void TStrings::SetTStrings( PIUnknown p )
  81. {
  82.     strings = 0;
  83.     if (p)
  84.         p->QueryInterface( IID_ITStrings, (void**) &strings );
  85.     ReattachEvents();
  86. }
  87.  
  88. void TStrings::ClearTStrings( void )
  89. {
  90.     DetachEvents();
  91.     if (strings)
  92.     {
  93.         strings->Release();
  94.         strings = 0;
  95.     }
  96. }
  97.  
  98. TStrings::TStrings( const string& p ) :
  99.     TBDTObject(),
  100.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChange ) ),
  101.     AttachedOnChange( false ),
  102.     OnChangingSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChanging ) ),
  103.     AttachedOnChanging( false )
  104. {
  105.     strings = CreateITStrings();
  106.     TBDTObject::SetPIT( strings );
  107.  
  108.     if (strings)
  109.         strings->put_Text( AnyString(p).GetPITAnyString() );
  110. }
  111.  
  112. TStrings::TStrings( void ) :
  113.     TBDTObject(),
  114.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChange ) ),
  115.     AttachedOnChange( false ),
  116.     OnChangingSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChanging ) ),
  117.     AttachedOnChanging( false )
  118. {
  119.     strings = CreateITStrings();
  120.     TBDTObject::SetPIT( strings );
  121. }
  122.  
  123. TStrings::TStrings( PITStrings p ) :
  124.     TBDTObject( p ),
  125.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChange ) ),
  126.     AttachedOnChange( false ),
  127.     OnChangingSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChanging ) ),
  128.     AttachedOnChanging( false )
  129. {
  130.     SetTStrings( p );
  131. }
  132.  
  133. TStrings::TStrings( const TStrings& p ) :
  134.     TBDTObject( p ),
  135.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChange ) ),
  136.     AttachedOnChange( false ),
  137.     OnChangingSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChanging ) ),
  138.     AttachedOnChanging( false )
  139. {
  140.     SetTStrings( p.strings );
  141. }
  142.  
  143. TStrings::TStrings( PTStrings p ) :
  144.     TBDTObject( p ),
  145.     OnChangeSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChange ) ),
  146.     AttachedOnChange( false ),
  147.     OnChangingSource( SrcAttach_MFUNCTOR( *this, &TStrings::AttachOnChanging ) ),
  148.     AttachedOnChanging( false )
  149. {
  150.     SetTStrings( p ? p->strings : 0 );
  151. }
  152.  
  153. TStrings& TStrings::operator=( PITStrings p )
  154. {
  155.     TBDTObject::operator=(p);
  156.     ClearTStrings();
  157.     SetTStrings( p );
  158.     return *this;
  159. }
  160.  
  161. TStrings& TStrings::operator=( const TStrings& p )
  162. {
  163.     if (this != &p)
  164.     {
  165.         TBDTObject::operator=(p);
  166.         ClearTStrings();
  167.         SetTStrings( p.strings );
  168.     }
  169.     return *this;
  170. }
  171.  
  172. int TStrings::operator==( const TStrings& p ) const
  173. {
  174.     if (this == &p)
  175.         return true;
  176.     if (strings == p.strings)
  177.         return true;
  178.     return false;
  179. }
  180.  
  181. int TStrings::operator!=( const TStrings& p ) const
  182. {
  183.     return ! operator==(p);
  184. }
  185.  
  186. TStrings::~TStrings()
  187. {
  188.     ClearTStrings();
  189. }
  190.  
  191. void TStrings::SetPIT( PIUnknown p )
  192. {
  193.     ClearTStrings();
  194.     SetTStrings( p );
  195.     TBDTObject::SetPIT( p );
  196. }
  197.  
  198. int TStrings::Add( const string& s )
  199. {
  200.     if (strings)
  201.         return strings->Add( AnyString(s).GetPITAnyString() );
  202.     return 0;
  203. }
  204.  
  205. int TStrings::AddObject( const string& s, LPVOID object )
  206. {
  207.     if (strings)
  208.         return strings->AddObject( AnyString(s).GetPITAnyString(), object );
  209.     return 0;
  210. }
  211.  
  212. void TStrings::AddStrings( TStrings& s )
  213. {
  214.     if (strings)
  215.         strings->AddStrings( s.strings );
  216. }
  217.  
  218. void TStrings::BeginUpdate( void )
  219. {
  220.     if (strings)
  221.         strings->BeginUpdate();
  222. }
  223.  
  224. void TStrings::Clear( void )
  225. {
  226.     if (strings)
  227.         strings->Clear();
  228. }
  229.  
  230. void TStrings::Delete( int index )
  231. {
  232.     if (strings)
  233.         strings->Delete( index );
  234. }
  235.  
  236. void TStrings::EndUpdate( void )
  237. {
  238.     if (strings)
  239.         strings->EndUpdate();
  240. }
  241.  
  242. bool TStrings::Equals( TStrings& s )
  243. {
  244.     if (strings)
  245.         return MakeBool( strings->Equals( s.strings ) );
  246.     return false;
  247. }
  248.  
  249. void TStrings::Exchange( int index1, int index2 )
  250. {
  251.     if (strings)
  252.         strings->Exchange( index1, index2 );
  253. }
  254.  
  255. bool TStrings::Find( const string& s, int& index )
  256. {
  257.     if (strings)
  258.         return MakeBool( strings->Find( AnyString(s).GetPITAnyString(), &index ) );
  259.     return false;
  260. }
  261.  
  262. int TStrings::IndexOf( const string& s )
  263. {
  264.     if (strings)
  265.         return strings->IndexOf( AnyString(s).GetPITAnyString() );
  266.     return 0;
  267. }
  268.  
  269. int TStrings::IndexOfObject( LPVOID object )
  270. {
  271.     if (strings)
  272.         return strings->IndexOfObject( object );
  273.     return 0;
  274. }
  275.  
  276. void TStrings::Insert( int index, const string& s )
  277. {
  278.     if (strings)
  279.         strings->Insert( index, AnyString(s).GetPITAnyString() );
  280. }
  281.  
  282. void TStrings::InsertObject( int index, const string& s, LPVOID object )
  283. {
  284.     if (strings)
  285.         strings->InsertObject( index, AnyString(s).GetPITAnyString(), object );
  286. }
  287.  
  288. void TStrings::LoadFromFile( const string& filename )
  289. {
  290.     if (strings)
  291.         strings->LoadFromFile( AnyString(filename).GetPITAnyString() );
  292. }
  293.  
  294. void TStrings::LoadFromStream( TMemoryStream& stream )
  295. {
  296.     if (strings)
  297.         strings->LoadFromStream( stream.GetPITMemoryStream() );
  298. }
  299.  
  300. void TStrings::Move( int curIndex, int newIndex )
  301. {
  302.     if (strings)
  303.         strings->Move( curIndex, newIndex );
  304. }
  305.  
  306. void TStrings::SaveToFile( const string& filename )
  307. {
  308.     if (strings)
  309.         strings->SaveToFile( AnyString(filename).GetPITAnyString() );
  310. }
  311.  
  312. void TStrings::SaveToStream( TMemoryStream& stream )
  313. {
  314.     if (strings)
  315.         strings->SaveToStream( stream.GetPITMemoryStream() );
  316. }
  317.  
  318. void TStrings::Sort( void )
  319. {
  320.     if (strings)
  321.         strings->Sort();
  322. }
  323.  
  324. DEFINE_BDTO_PROP_RO( TStrings, int, Count );
  325. DEFINE_BDTO_ARRAYPROP_RW( TStrings, LPVOID, Objects, int );
  326. DEFINE_BDTO_ARRAYOBJECTPROP_RW( TStrings, string, Values, string& );
  327. DEFINE_BDTO_ARRAYOBJECTPROP_RW( TStrings, string, Strings, int );
  328. DEFINE_BDTO_OBJECTPROP_RW( TStrings, string, Text );
  329. DEFINE_BDTO_PROP_RW( TStrings, TDuplicates, Duplicates );
  330. DEFINE_BDTO_PROP_RW( TStrings, bool, Sorted );
  331.  
  332. void TStrings::GetCount( int& c )
  333. {
  334.     if (strings)
  335.         c = strings->get_Count();
  336. }
  337.  
  338. void TStrings::GetObjects( int index, LPVOID& object )
  339. {
  340.     if (strings)
  341.         object = strings->get_Objects( index );
  342. }
  343.  
  344. void TStrings::SetObjects( int index, LPVOID object )
  345. {
  346.     if (strings)
  347.         strings->put_Objects( index, object );
  348. }
  349.  
  350. void TStrings::GetValues( string& name, string& s )
  351. {
  352.     if (strings)
  353.         AnyString( strings->get_Values( AnyString(name).GetPITAnyString() ) ).GetString( s );
  354. }
  355.  
  356. void TStrings::SetValues( string& name, const string& value )
  357. {
  358.     if (strings)
  359.         strings->put_Values( AnyString(name).GetPITAnyString(), AnyString(value).GetPITAnyString() );
  360. }
  361.  
  362. void TStrings::GetStrings( int index, string& s )
  363. {
  364.     if (strings)
  365.         AnyString( strings->get_Strings( index ) ).GetString( s );
  366. }
  367.  
  368. void TStrings::SetStrings( int index, const string& s )
  369. {
  370.     if (strings)
  371.         strings->put_Strings( index, AnyString(s).GetPITAnyString() );
  372. }
  373.  
  374.  
  375. void TStrings::GetText( string& s )
  376. {
  377.     if (strings)
  378.         AnyString( strings->get_Text() ).GetString( s );
  379. }
  380.  
  381. void TStrings::SetText( const string& text )
  382. {
  383.     if (strings)
  384.         strings->put_Text( AnyString(text).GetPITAnyString() );
  385. }
  386.  
  387. void TStrings::GetDuplicates( TDuplicates& d )
  388. {
  389.     if (strings)
  390.         d = strings->get_Duplicates();
  391. }
  392.  
  393. void TStrings::SetDuplicates( TDuplicates d )
  394. {
  395.     if (strings)
  396.         strings->put_Duplicates( d );
  397. }
  398.  
  399. void TStrings::GetSorted( bool& s )
  400. {
  401.     if (strings)
  402.         s = MakeBool( strings->get_Sorted() );
  403. }
  404.  
  405. void TStrings::SetSorted( bool s )
  406. {
  407.     if (strings)
  408.         strings->put_Sorted( MakeVariantBool( s ) );
  409. }
  410.