home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / FINDREPL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  4.8 KB  |  198 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of FindReplace- abstract, Find-, Replace- common Dialog
  6. //   classes
  7. //----------------------------------------------------------------------------
  8. #pragma hdrignore SECTION
  9. #include <owl/owlpch.h>
  10. #include <owl/findrepl.h>
  11. #if !defined(ctlFirst)
  12. # include <dlgs.h>
  13. #endif
  14.  
  15. #if !defined(SECTION) || SECTION == 1
  16.  
  17. TFindReplaceDialog::TData::TData(uint32 flags, int buffSize)
  18. :
  19.   Flags(flags), BuffSize(buffSize), Error(0)
  20. {
  21.   FindWhat = new char[BuffSize];
  22.   ReplaceWith = new char[BuffSize];
  23.   *FindWhat = *ReplaceWith = 0;
  24. }
  25.  
  26. TFindReplaceDialog::TData::TData(const TData& src)
  27. :
  28.   Flags(src.Flags),
  29.   BuffSize(src.BuffSize),
  30.   Error(0)
  31. {
  32.   FindWhat = strnewdup(src.FindWhat, BuffSize);
  33.   ReplaceWith = strnewdup(src.ReplaceWith, BuffSize);
  34. }
  35.  
  36.  
  37. TFindReplaceDialog::TData::~TData()
  38. {
  39.   delete [] FindWhat;
  40.   delete [] ReplaceWith;
  41. }
  42.  
  43. TFindReplaceDialog::TData&
  44. TFindReplaceDialog::TData::operator =(const TData& src)
  45. {
  46.   Flags = src.Flags;
  47.   BuffSize = src.BuffSize;
  48.   Error = 0;
  49.  
  50.   delete [] FindWhat;
  51.   FindWhat = strnewdup(src.FindWhat, BuffSize);
  52.  
  53.   delete [] ReplaceWith;
  54.   ReplaceWith = strnewdup(src.ReplaceWith, BuffSize);
  55.  
  56.   return *this;
  57. }
  58.  
  59.  
  60. //----------------------------------------------------------------------------
  61.  
  62. DEFINE_RESPONSE_TABLE1(TFindReplaceDialog, TCommonDialog)
  63.   EV_WM_NCDESTROY,
  64. END_RESPONSE_TABLE;
  65.  
  66. IMPLEMENT_CASTABLE(TFindReplaceDialog);
  67.  
  68. void
  69. TFindReplaceDialog::Init(TResId templateId)
  70. {
  71.   memset(&fr, 0, sizeof(FINDREPLACE));
  72.   fr.lStructSize = sizeof(FINDREPLACE);
  73.   fr.hwndOwner = Parent ? Parent->HWindow : 0;
  74.   fr.hInstance = *GetModule();
  75.   Data.Flags &= ~(FR_FINDNEXT|FR_REPLACE|FR_REPLACEALL|FR_DIALOGTERM);
  76.   fr.Flags = FR_ENABLEHOOK | Data.Flags;
  77.   if (templateId) {
  78.     fr.lpTemplateName = templateId;
  79.     fr.Flags |= FR_ENABLETEMPLATE;
  80.   }
  81.   else
  82.     fr.Flags &= ~FR_ENABLETEMPLATE;
  83.  
  84.   fr.lpstrFindWhat = Data.FindWhat;
  85.   fr.wFindWhatLen = (uint16)Data.BuffSize;
  86.   fr.lpstrReplaceWith = Data.ReplaceWith;
  87.   fr.wReplaceWithLen = (uint16)Data.BuffSize;
  88. }
  89.  
  90. TFindReplaceDialog::TFindReplaceDialog(TWindow*        parent,
  91.                                        TData&          data,
  92.                                        TResId          templateId,
  93.                                        const char far* title,
  94.                                        TModule*        module)
  95. :
  96.   TCommonDialog(parent, title, module),
  97.   Data(data)
  98. {
  99.   Init(templateId);
  100. }
  101.  
  102. HWND
  103. TFindReplaceDialog::DoCreate()
  104. {
  105.   return 0;
  106. }
  107.  
  108. bool
  109. TFindReplaceDialog::DialogFunction(uint msg, WPARAM wParam, LPARAM lParam)
  110. {
  111.   return TCommonDialog::DialogFunction(msg, wParam, lParam);
  112. }
  113.  
  114. //
  115. // Make sure flags get copied over before we go
  116. //
  117. void
  118. TFindReplaceDialog::EvNCDestroy()
  119. {
  120.   Data.Flags = fr.Flags;
  121.   TWindow::EvNCDestroy();
  122. }
  123.  
  124. void
  125. TFindReplaceDialog::UpdateData(LPARAM lParam)
  126. {
  127.   if (lParam)
  128.     Data.Flags = ((LPFINDREPLACE)lParam)->Flags;
  129.   else
  130.     Data.Flags = fr.Flags;
  131. }
  132.  
  133. //----------------------------------------------------------------------------
  134.  
  135. IMPLEMENT_CASTABLE(TFindDialog);
  136.  
  137. TFindDialog::TFindDialog(TWindow*        parent,
  138.                          TData&          data,
  139.                          TResId          templateId,
  140.                          const char far* title,
  141.                          TModule*        module)
  142.   : TFindReplaceDialog(parent, data, templateId, title, module)
  143. {
  144. }
  145.  
  146. HWND
  147. TFindDialog::DoCreate()
  148. {
  149.   (DLGPROC)fr.lpfnHook = (DLGPROC)(FARPROC)StdDlgProcInstance;
  150.   return ::FindText(&fr);
  151. }
  152.  
  153. //----------------------------------------------------------------------------
  154.  
  155. IMPLEMENT_CASTABLE(TReplaceDialog);
  156.  
  157. TReplaceDialog::TReplaceDialog(TWindow*        parent,
  158.                                TData&          data,
  159.                                TResId          templateId,
  160.                                const char far* title,
  161.                                TModule*        module)
  162.   : TFindReplaceDialog(parent, data, templateId, title, module)
  163. {
  164. }
  165.  
  166. HWND
  167. TReplaceDialog::DoCreate()
  168. {
  169.   (DLGPROC)fr.lpfnHook = (DLGPROC)(FARPROC)StdDlgProcInstance;
  170.   return ::ReplaceText(&fr);
  171. }
  172.  
  173. #endif
  174. #if !defined(SECTION) || SECTION == 2
  175. //Keep streaming out if not used
  176.  
  177. void
  178. TFindReplaceDialog::TData::Read(ipstream& is)
  179. {
  180.   is >> Flags;
  181.   is >> BuffSize;
  182.   FindWhat = new char[BuffSize];
  183.   ReplaceWith = new char[BuffSize];
  184.   is.readBytes(FindWhat, BuffSize);
  185.   is.readBytes(ReplaceWith, BuffSize);
  186. }
  187.  
  188. void
  189. TFindReplaceDialog::TData::Write(opstream& os)
  190. {
  191.   os << Flags;
  192.   os << BuffSize;
  193.   os.writeBytes(FindWhat, BuffSize);
  194.   os.writeBytes(ReplaceWith, BuffSize);
  195. }
  196.  
  197. #endif
  198.