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

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.8  $
  6. //
  7. // Implementation of TChooseFontDialog, a Choose Font Common Dialog class
  8. //----------------------------------------------------------------------------
  9. #include <owl/pch.h>
  10. #if !defined(OWL_CHOOSEFO_H)
  11. # include <owl/choosefo.h>
  12. #endif
  13. #if !defined(ctlFirst)
  14. # include <dlgs.h>
  15. #endif
  16.  
  17. OWL_DIAGINFO;
  18. DIAG_DECLARE_GROUP(OwlCommDialog);  // diagnostic group for common dialogs
  19.  
  20. DEFINE_RESPONSE_TABLE1(TChooseFontDialog, TCommonDialog)
  21. END_RESPONSE_TABLE;
  22.  
  23. IMPLEMENT_CASTABLE(TChooseFontDialog);
  24.  
  25. //
  26. // Initialize the ChooseFont data members.
  27. //
  28. TChooseFontDialog::TChooseFontDialog(TWindow*        parent,
  29.                                      TData&          data,
  30.                                      TResId          templateId,
  31.                                      const char far* title,
  32.                                      TModule*        module)
  33. :
  34.   TCommonDialog(parent, title, module),
  35.   Data(data)
  36. {
  37.   memset(&Cf, 0, sizeof(CHOOSEFONT));
  38.   Cf.lStructSize = sizeof(CHOOSEFONT);
  39.   Cf.hwndOwner = Parent ? Parent->GetHandle() : 0;
  40.   Cf.hInstance = *GetModule();
  41.   Cf.Flags = CF_ENABLEHOOK | Data.Flags;
  42.   if (templateId) {
  43.     Cf.lpTemplateName = templateId;
  44.     Cf.Flags |= CF_ENABLETEMPLATE;
  45.   }
  46.   else
  47.     Cf.Flags &= ~CF_ENABLETEMPLATE;
  48.   Cf.lpfnHook = 0;
  49.  
  50.   Cf.hDC = Data.DC;
  51.   Cf.lpLogFont = &Data.LogFont;
  52.   Cf.iPointSize = Data.PointSize;
  53.   Cf.rgbColors = Data.Color;
  54.   Cf.lpszStyle = Data.Style;
  55.   Cf.nFontType = Data.FontType;
  56.   Cf.nSizeMin = Data.SizeMin;
  57.   Cf.nSizeMax = Data.SizeMax;
  58.  
  59.   TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseFontDialog constructed @" << (void*)this);
  60. }
  61.  
  62.  
  63. //
  64. // Destructor for this object does nothing in the non-diagnostic versions
  65. // of the library.
  66. // In the diagnostic version, it produces a trace message.
  67. //
  68. TChooseFontDialog::~TChooseFontDialog()
  69. {
  70.   TRACEX(OwlCommDialog, OWL_CDLEVEL, "TChooseFontDialog destructed @" << (void*)this);
  71. }
  72.  
  73.  
  74. //
  75. // Override the virtual DialogFunction.
  76. // It does no additional processing.
  77. //
  78. bool
  79. TChooseFontDialog::DialogFunction(uint msg, TParam1 param1, TParam2 param2)
  80. {
  81.   return TCommonDialog::DialogFunction(msg, param1, param2);
  82. }
  83.  
  84. //
  85. // Execute the dialog to retrieve the font selected by the user.
  86. //
  87. int
  88. TChooseFontDialog::DoExecute()
  89. {
  90.   Cf.lpfnHook = LPCFHOOKPROC(StdDlgProc);
  91.   int ret = ::ChooseFont(&Cf);
  92.   if (ret) {
  93.     Data.Flags = Cf.Flags;
  94.     Data.Error = 0;
  95.     Data.PointSize = Cf.iPointSize;
  96.     Data.Color = Cf.rgbColors;
  97.     Data.Style = Cf.lpszStyle;
  98.     Data.FontType = Cf.nFontType;
  99.   }
  100.   else {
  101.     Data.Error = ::CommDlgExtendedError();
  102.   }
  103.   return ret ? IDOK : IDCANCEL;
  104. }
  105.