home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c083 / 11.ddi / OWLSRC.PAK / FINDREPL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-02  |  4.2 KB  |  167 lines

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