- if (!FileExists(WXSTRINGCAST file))
- return FALSE;
-
- m_fileName = file;
-
- Clear();
-
-// ifstream input(WXSTRINGCAST file, ios::nocreate | ios::in);
- ifstream input(WXSTRINGCAST file, ios::in);
-
- if (!input.bad())
- {
- // Previously a SETSEL/REPLACESEL call-pair were done to insert
- // line by line into the control. Apart from being very slow this
- // was limited to 32K of text by the external interface presenting
- // positions as signed shorts. Now load in one chunk...
- // Note use of 'farmalloc' as in Borland 3.1 'size_t' is 16-bits...
-
- struct stat stat_buf;
- if (stat(file, &stat_buf) < 0)
- return FALSE;
-// char *tmp_buffer = (char*)farmalloc(stat_buf.st_size+1);
- // This may need to be a bigger buffer than the file size suggests,
- // if it's a UNIX file. Give it an extra 1000 just in case.
- char *tmp_buffer = (char*)farmalloc((size_t)(stat_buf.st_size+1+1000));
- long no_lines = 0;
- long pos = 0;
- while (!input.eof() && input.peek() != EOF)
- {
- input.getline(wxBuffer, 500);
- int len = strlen(wxBuffer);
- wxBuffer[len] = 13;
- wxBuffer[len+1] = 10;
- wxBuffer[len+2] = 0;
- strcpy(tmp_buffer+pos, wxBuffer);
- pos += strlen(wxBuffer);
- no_lines++;
- }
-
-// SendMessage((HWND) GetHWND(), WM_SETTEXT, 0, (LPARAM)tmp_buffer);
- SetWindowText((HWND) GetHWND(), tmp_buffer);
- SendMessage((HWND) GetHWND(), EM_SETMODIFY, FALSE, 0L);
- farfree(tmp_buffer);
-
- return TRUE;
- }
- return FALSE;
-}
-
-// If file is null, try saved file name first
-// Returns TRUE if succeeds.
-bool wxTextCtrl::SaveFile(const wxString& file)
-{
- wxString theFile(file);
- if (theFile == "")
- theFile = m_fileName;
- if (theFile == "")
- return FALSE;
- m_fileName = theFile;
-
- ofstream output((char*) (const char*) theFile);
- if (output.bad())
- return FALSE;
-
- // This will only save 64K max
- unsigned long nbytes = SendMessage((HWND) GetHWND(), WM_GETTEXTLENGTH, 0, 0);
- char *tmp_buffer = (char*)farmalloc((size_t)(nbytes+1));
- SendMessage((HWND) GetHWND(), WM_GETTEXT, (WPARAM)(nbytes+1), (LPARAM)tmp_buffer);
- char *pstr = tmp_buffer;
-
- // Convert \r\n to just \n
- while (*pstr)
- {
- if (*pstr != '\r')
- output << *pstr;
- pstr++;
- }
-
- farfree(tmp_buffer);
- SendMessage((HWND) GetHWND(), EM_SETMODIFY, FALSE, 0L);
-
- return TRUE;
-}
-
-void wxTextCtrl::WriteText(const wxString& text)
-{
- // Covert \n to \r\n
- int len = text.Length();
- char *newtext = new char[(len*2)+1];
- int i = 0;
- int j = 0;
- while (i < len)