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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1992, 1994 by Borland International, All Rights Reserved
  4. //
  5. //   Implementation of TInputDialog.  User string input dialog box
  6. //----------------------------------------------------------------------------
  7. #pragma hdrignore SECTION
  8. #include <owl/owlpch.h>
  9. #include <owl/inputdia.h>
  10. #include <string.h>
  11. #include <owl/edit.h>
  12. #include <owl/validate.h>
  13.  
  14. #if !defined(SECTION) || SECTION == 1
  15.  
  16. TInputDialog::TInputDialog(TWindow*        parent,
  17.                            const char far* title,
  18.                            const char far* prompt,
  19.                            char far*       buffer,
  20.                            int             bufferSize,
  21.                            TModule*        module,
  22.                            TValidator*     validator)
  23. :
  24.   TWindow(parent, title, module),
  25.   TDialog(parent, IDD_INPUTDIALOG, module)
  26. {
  27.   PRECONDITION(buffer);
  28.   SetCaption(title);
  29.   Prompt = strnewdup(prompt);
  30.   Buffer = buffer;
  31.   BufferSize = bufferSize;
  32.   if (validator)
  33.     new TEdit(this,ID_INPUT)->SetValidator(validator);
  34. }
  35.  
  36. TInputDialog::~TInputDialog()
  37. {
  38.   delete [] Prompt;
  39. }
  40.  
  41. //
  42. // sets and gets the values of the items (controls) of the input dialog
  43. //
  44. void
  45. TInputDialog::TransferData(TTransferDirection direction)
  46. {
  47.   if (direction == tdSetData) {
  48.     SetDlgItemText(ID_PROMPT, Prompt);
  49.     SetDlgItemText(ID_INPUT, Buffer);
  50.   }
  51.   else if (direction == tdGetData) {
  52.     GetDlgItemText(ID_INPUT, Buffer, BufferSize);
  53.   }
  54. }
  55.  
  56. //
  57. // sets the values of the items(controls) of the input dialog
  58. //
  59. void
  60. TInputDialog::SetupWindow()
  61. {
  62.   TDialog::SetupWindow();
  63.   SendDlgItemMessage(ID_INPUT, EM_LIMITTEXT, BufferSize - 1, 0);
  64. }
  65.  
  66. #endif
  67. #if !defined(SECTION) || SECTION == 2
  68.  
  69. IMPLEMENT_STREAMABLE2(TInputDialog, TDialog, TWindow);
  70.  
  71. //
  72. // reads an instance of TInputDialog from the passed ipstream
  73. //
  74. void*
  75. TInputDialog::Streamer::Read(ipstream& is, uint32 /*version*/) const
  76. {
  77.   ReadBaseObject((TDialog*)GetObject(), is);
  78.   GetObject()->Prompt = is.freadString();
  79.   return GetObject();
  80. }
  81.  
  82. //
  83. // writes the TInputDialog to the passed opstream
  84. //
  85. void
  86. TInputDialog::Streamer::Write(opstream& os) const
  87. {
  88.   WriteBaseObject((TDialog*)GetObject(), os);
  89.   os.fwriteString(GetObject()->Prompt);
  90. }
  91.  
  92.  
  93. #endif
  94.