update dev300-m58
[ooovba.git] / automation / source / miniapp / editwin.cxx
blobb4de56ab6c8cd133ef7d0cdc341ff5a17ea1bc35
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editwin.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_automation.hxx"
34 #include "editwin.hxx"
35 #include <tools/stream.hxx>
36 #ifndef _MSGBOX_HXX //autogen
37 #include <vcl/msgbox.hxx>
38 #endif
41 BOOL GHEditWindow::Close()
43 if (aInhalt.IsModified())
46 delete(this);
47 return TRUE;
50 void GHEditWindow::Resize()
52 aInhalt.SetPosSizePixel(Point(1,1),GetOutputSizePixel());
55 GHEditWindow::GHEditWindow(Window * pParent, String aName, WinBits iWstyle)
56 : FloatingWindow(pParent)
57 , aInhalt(this,iWstyle)
59 SetOutputSizePixel( Size( 120,80 ) );
60 Show();
61 Resize();
62 aInhalt.Show();
63 SetText(aName);
66 void GHEditWindow::Clear()
68 aInhalt.SetText(String());
71 void GHEditWindow::AddText( String aNew, BOOL bMoveToEnd)
73 String aOld = aInhalt.GetText();
75 aOld += aNew;
76 aOld.ConvertLineEnd();
77 aInhalt.SetText(aOld);
78 if (bMoveToEnd)
79 aInhalt.SetSelection(Selection(SELECTION_MAX,SELECTION_MAX));
83 EditFileWindow::EditFileWindow(Window * pParent, String aName, WinBits iWstyle)
84 : GHEditWindow(pParent, aName, iWstyle)
85 , aFileName(aName)
87 LoadFile();
90 void EditFileWindow::LoadFile()
93 SvFileStream Stream;
94 String All,Line;
96 Stream.Open(aFileName, STREAM_STD_READ);
98 if (!Stream.IsOpen())
100 AddText(CUniString("could not open ").Append(aFileName).AppendAscii("\n"));
101 aFileName.Erase();
102 return;
105 while (!Stream.IsEof())
108 Stream.ReadByteStringLine( Line, RTL_TEXTENCODING_UTF8 );
110 All += Line;
111 All += '\n';
115 All.ConvertLineEnd();
117 AddText(All,FALSE);
121 BOOL EditFileWindow::Close()
124 if (aInhalt.IsModified() && QueryBox(this,WB_DEF_YES | WB_YES_NO_CANCEL, String(aFileName).AppendAscii("\nhas been changed.\n\nSave file?")).Execute())
128 return GHEditWindow::Close();