/ windows / pvfiles.cpp
pvfiles.cpp
  1  /*******************************************************************************
  2   * pvfiles.cpp
  3   *
  4   * This module contains ASCII file related code.
  5   *
  6   * Author: Christopher J. Cason.
  7   *
  8   * ---------------------------------------------------------------------------
  9   * Persistence of Vision Ray Tracer ('POV-Ray') version 3.7.
 10   * Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd.
 11   *
 12   * POV-Ray is free software: you can redistribute it and/or modify
 13   * it under the terms of the GNU Affero General Public License as
 14   * published by the Free Software Foundation, either version 3 of the
 15   * License, or (at your option) any later version.
 16   *
 17   * POV-Ray is distributed in the hope that it will be useful,
 18   * but WITHOUT ANY WARRANTY; without even the implied warranty of
 19   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 20   * GNU Affero General Public License for more details.
 21   *
 22   * You should have received a copy of the GNU Affero General Public License
 23   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 24   * ---------------------------------------------------------------------------
 25   * POV-Ray is based on the popular DKB raytracer version 2.12.
 26   * DKBTrace was originally written by David K. Buck.
 27   * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
 28   * ---------------------------------------------------------------------------
 29   * $File: //depot/public/povray/3.x/windows/pvfiles.cpp $
 30   * $Revision: #1 $
 31   * $Change: 6069 $
 32   * $DateTime: 2013/11/06 11:59:40 $
 33   * $Author: chrisc $
 34   *******************************************************************************/
 35  
 36  #define POVWIN_FILE
 37  #define _WIN32_IE COMMONCTRL_VERSION
 38  
 39  #include <setjmp.h>
 40  #include <string.h>
 41  
 42  #include <windows.h>
 43  
 44  #include "pvengine.h"
 45  #include "resource.h"
 46  #include "pvlegal.h"
 47  #include "pvdemo.h"
 48  
 49  // this must be the last file included
 50  #include "syspovdebug.h"
 51  
 52  namespace povwin
 53  {
 54  
 55  extern int              message_ychar ;
 56  extern char             ourPath [] ;
 57  
 58  void fill_listbox (HWND hwnd)
 59  {
 60    char        *p = povlegal_text ;
 61    char        str [1024] = "" ;
 62    char        *s = str ;
 63  
 64    while (*p)
 65    {
 66      if (*p == '\n')
 67      {
 68        *s = '\0' ;
 69        SendMessage (hwnd, LB_ADDSTRING, 0, (LPARAM) str) ;
 70        s = str ;
 71        p++ ;
 72        continue ;
 73      }
 74      *s++ = *p++ ;
 75    }
 76    *s = '\0' ;
 77    SendMessage (hwnd, LB_ADDSTRING, 0, (LPARAM) str) ;
 78  }
 79  
 80  void save_povlegal (void)
 81  {
 82    char        filename [_MAX_PATH + 64] ;
 83    FILE        *outF ;
 84  
 85    sprintf (filename, "%sagpl-3.0.txt", DocumentsPath) ;
 86    if ((outF = fopen (filename, "wt")) == NULL)
 87    {
 88      PovMessageBox ("Cannot create agpl-3.0.txt", "Cannot save document") ;
 89      return ;
 90    }
 91    if (fwrite (povlegal_text, 1, sizeof (povlegal_text) - 1, outF) != sizeof (povlegal_text) - 1)
 92    {
 93      PovMessageBox ("Cannot write to agpl-3.0.txt", "Cannot save document") ;
 94      fclose (outF) ;
 95      return ;
 96    }
 97    fclose (outF) ;
 98    sprintf (filename, "The POV-Ray license was written to the file %sagpl-3.0.txt", DocumentsPath) ;
 99    PovMessageBox (filename, "agpl-3.0.txt saved") ;
100  }
101  
102  INT_PTR CALLBACK PovLegalDialogProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
103  {
104    DRAWITEMSTRUCT        *d ;
105    MEASUREITEMSTRUCT     *m ;
106    static HBRUSH         hbr ;
107  
108    switch (message)
109    {
110      case WM_INITDIALOG :
111           resize_listbox_dialog (hDlg, IDC_LISTBOX, 79) ;
112           CenterWindowRelative ((HWND) lParam, hDlg, true, true) ;
113           SetWindowText (hDlg, "POV-Ray License") ;
114  //       hbr = CreateSolidBrush (GetSysColor (COLOR_BTNFACE)) ;
115           fill_listbox (GetDlgItem (hDlg, IDC_LISTBOX)) ;
116           return (true) ;
117  
118      case WM_CTLCOLORBTN:
119      case WM_CTLCOLORDLG:
120      case WM_CTLCOLOREDIT:
121      case WM_CTLCOLORLISTBOX:
122      case WM_CTLCOLORSCROLLBAR:
123      case WM_CTLCOLORSTATIC:
124           return (DefWindowProc (hDlg, message, wParam, lParam)) ;
125  
126      case WM_COMMAND :
127           switch (LOWORD (wParam))
128           {
129             case IDOK :
130  //              DeleteObject (hbr) ;
131                  EndDialog (hDlg, true) ;
132                  return (true) ;
133  
134             default :
135                  return (true) ;
136           }
137  
138      case WM_MEASUREITEM :
139           if (wParam == IDC_LISTBOX)
140           {
141             m = (MEASUREITEMSTRUCT *) lParam ;
142             m->itemHeight = message_ychar ;
143             return (true) ;
144           }
145           else
146             return (false) ;
147  
148      case WM_DRAWITEM :
149           if (wParam == IDC_LISTBOX)
150           {
151             d = (DRAWITEMSTRUCT *) lParam ;
152             d->itemState &= ~ODS_SELECTED ;
153             draw_ordinary_listbox (d, false) ;
154             return (true) ;
155           }
156           else
157             return (false) ;
158    }
159    return (false) ;
160  }
161  
162  char *save_demo_file (char *s1, char *s2)
163  {
164    char        **p = povdemo_scene ;
165    FILE        *outF ;
166  
167    GetTempPath (_MAX_PATH - 16, s1) ;
168    appendPathSeparator (s1) ;
169    strcpy (s2, s1) ;
170    strcat (s1, "POVDEMO.$$1") ;
171    strcat (s2, "POVDEMO.$$2") ;
172    if ((outF = fopen (s1, "wt")) == NULL)
173    {
174      PovMessageBox ("Cannot create temporary file", "Cannot run demo") ;
175      return (NULL) ;
176    }
177    while (*p)
178    {
179      if (fprintf (outF, "%s\n", *p++) == EOF)
180      {
181        PovMessageBox ("Cannot write to temporary file", "Cannot run demo") ;
182        fclose (outF) ;
183        _unlink (s1) ;
184        return (NULL) ;
185      }
186    }
187    fclose (outF) ;
188    p = povdemo_ini ;
189    if ((outF = fopen (s2, "wt")) == NULL)
190    {
191      PovMessageBox ("Cannot create temporary file", "Cannot run demo") ;
192      _unlink (s1) ;
193      return (NULL) ;
194    }
195    while (*p)
196    {
197      if (fprintf (outF, "%s\n", *p++) == EOF)
198      {
199        PovMessageBox ("Cannot write to temporary file", "Cannot run demo") ;
200        fclose (outF) ;
201        _unlink (s1) ;
202        _unlink (s2) ;
203        return (NULL) ;
204      }
205    }
206    fclose (outF) ;
207    return (s1) ;
208  }
209  
210  }