home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OFontDialog.cpp < prev    next >
C/C++ Source or Header  |  1997-01-27  |  3KB  |  100 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OFontDialog.cpp
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/ODialog.cpp 1.50 1996/08/11 23:49:13 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OApp.hpp>
  40. #include <OFontDialog.hpp>
  41.  
  42.  
  43. OFontDialog::OFontDialog(HWND hParent, HWND hOwner)
  44.   : OStdDialog(hParent, hOwner)
  45. {
  46.  if (!OApp::currentOApp)
  47.    throw OPMException(OCL::error(OCL_OAPP_NO_OAPP), 0);
  48. }
  49.  
  50. OFontDialog::~OFontDialog()
  51. {
  52. }
  53.  
  54. PSZ OFontDialog::isOfType() const
  55. {
  56.  return("OFontDialog");
  57. }
  58.  
  59.  
  60. PSZ OFontDialog::getFont(PSZ title, PSZ previewText)
  61. {
  62.  FONTDLG      fontDlg;
  63.  FONTMETRICS  fontMetrics;
  64.  OString      Buffer(100);
  65.  OString      szFamily(FACESIZE);
  66.  
  67.  memset(&fontDlg, 0, sizeof(fontDlg));
  68.  fontDlg.cbSize         = sizeof(FONTDLG);
  69.  fontDlg.hpsScreen      = WinGetScreenPS(HWND_DESKTOP);
  70.  fontDlg.pszTitle       = title;
  71.  fontDlg.pszPreview     = previewText;
  72.  fontDlg.pszFamilyname  = szFamily.getText();
  73.  fontDlg.fl             = FNTS_BITMAPONLY | FNTS_CENTER;
  74.  fontDlg.flFlags        = FNTF_NOVIEWPRINTERFONTS;
  75.  fontDlg.clrFore        = CLR_BLACK;
  76.  fontDlg.clrBack        = CLR_WHITE;
  77.  fontDlg.usFamilyBufLen = FACESIZE;
  78.  
  79.  WinFontDlg(parent, owner, &fontDlg);
  80.  WinReleasePS(fontDlg.hpsScreen);
  81.  
  82.  switch(fontDlg.lReturn)
  83.   {
  84.    case DID_CANCEL:
  85.      WinReleasePS(fontDlg.hpsScreen);
  86.      return(NULL); 
  87.  
  88.    case DID_OK:
  89.      sprintf(Buffer.getText(), "%ld.%s",
  90.              fontDlg.fxPointSize/65536,
  91.              fontDlg.pszFamilyname);
  92.      font << Buffer;
  93.      return(font.getText());
  94.   }
  95.  
  96.  return(NULL);  // we should never get here
  97. }
  98.  
  99. // end of source
  100.