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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OFileDialog.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 <OFileDialog.hpp>
  40.  
  41.  
  42. OFileDialog::OFileDialog(HWND hParent, HWND hOwner)
  43.   : OStdDialog(hParent, hOwner)
  44. {
  45.  memset(&fileDialog, 0, sizeof(FILEDLG));
  46.  fileDialog.cbSize = sizeof(FILEDLG);
  47. }
  48.  
  49. OFileDialog::~OFileDialog()
  50.   {}
  51.  
  52. PSZ OFileDialog::isOfType() const
  53. {
  54.  return("OFileDialog");
  55. }
  56.  
  57.  
  58. PSZ OFileDialog::open(PSZ title,
  59.                       PSZ initialPath,
  60.                       PSZ fileMask,
  61.                       OFileDialog::styles style)
  62. {
  63.  if (lastPath)
  64.    strcpy(fileDialog.szFullFile, lastPath);
  65.  
  66.  if (initialPath)
  67.    strcpy(fileDialog.szFullFile, initialPath);
  68.  
  69.  if (fileMask) {
  70.    strcat(fileDialog.szFullFile, "\\");
  71.    strcat(fileDialog.szFullFile, fileMask); }
  72.  
  73.  fileDialog.fl          = FDS_OPEN_DIALOG | style;
  74.  fileDialog.pszTitle    = title;
  75.  fileDialog.pszOKButton = "~OK";
  76.  
  77.  if (!WinFileDlg(parent, owner, (PFILEDLG)&fileDialog))
  78.    throw OPMException(OCL::error(OCL_OFILEDLG_SHOW), 0);
  79.  
  80.  if (fileDialog.lReturn == DID_OK)
  81.   {
  82.    lastFile << fileDialog.szFullFile;
  83.    lastPath << fileDialog.szFullFile;
  84.    lastPath.rightCut('\\');
  85.    return(lastFile);
  86.   }
  87.  else
  88.   return(NULL);
  89. }
  90.  
  91.  
  92. PSZ OFileDialog::saveAs(PSZ title,
  93.                         PSZ initialPath,
  94.                         PSZ initialFileName,
  95.                         OFileDialog::styles style)
  96. {
  97.  if (lastPath)
  98.    strcpy(fileDialog.szFullFile, lastPath);
  99.  
  100.  if (initialPath)
  101.    strcpy(fileDialog.szFullFile, initialPath);
  102.  
  103.  strcat(fileDialog.szFullFile, "\\");
  104.  if (initialFileName)
  105.    strcat(fileDialog.szFullFile, initialFileName);
  106.  
  107.  fileDialog.fl          = FDS_SAVEAS_DIALOG | style;
  108.  fileDialog.pszTitle    = title;
  109.  
  110.  if (!WinFileDlg(parent, owner, (PFILEDLG)&fileDialog))
  111.    throw OPMException(OCL::error(OCL_OFILEDLG_SHOW), 0);
  112.  
  113.  if (fileDialog.lReturn == DID_OK)
  114.   {
  115.    lastFile << fileDialog.szFullFile;
  116.    lastPath << fileDialog.szFullFile;
  117.    lastPath.rightCut('\\');
  118.    return(lastFile);
  119.   }
  120.  else
  121.   return(NULL);
  122. }
  123.  
  124.  
  125. // end of source
  126.