1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svtools.hxx"
30 #include <svtools/fileurlbox.hxx>
31 #include <osl/file.h>
32 #include "svl/filenotation.hxx"
33 
34 //.........................................................................
35 namespace svt
36 {
37 //.........................................................................
38 
39 	//=====================================================================
40 	//= FileURLBox
41 	//=====================================================================
42 	//---------------------------------------------------------------------
43 	FileURLBox::FileURLBox(Window* _pParent)
44 		:SvtURLBox(_pParent, INET_PROT_FILE)
45 	{
46 		DisableHistory();
47 	}
48 
49 	//---------------------------------------------------------------------
50 	FileURLBox::FileURLBox( Window* _pParent, WinBits _nStyle )
51 		:SvtURLBox( _pParent, _nStyle, INET_PROT_FILE )
52 	{
53 		DisableHistory();
54 	}
55 
56 	//---------------------------------------------------------------------
57 	FileURLBox::FileURLBox(Window* _pParent, const ResId& _rId)
58 		:SvtURLBox(_pParent, _rId, INET_PROT_FILE)
59 	{
60 		DisableHistory();
61 	}
62 
63 	//---------------------------------------------------------------------
64     void FileURLBox::DisplayURL( const String& _rURL )
65     {
66         String sOldText = GetText();
67 
68         OFileNotation aTransformer( _rURL, OFileNotation::N_URL );
69         String sNewText = aTransformer.get( OFileNotation::N_SYSTEM );
70 		SetText( sNewText );
71 
72         if ( sOldText != sNewText )
73             Modify();
74 
75         UpdatePickList();
76     }
77 
78 	//---------------------------------------------------------------------
79 	long FileURLBox::PreNotify( NotifyEvent& _rNEvt )
80 	{
81         switch ( _rNEvt.GetType() )
82         {
83         case EVENT_KEYINPUT:
84 		    if  (   ( GetSubEdit() == _rNEvt.GetWindow()                         )
85                 &&  ( KEY_RETURN == _rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
86                 &&  ( IsInDropDown()                                             )
87                 )
88 				m_sPreservedText = GetURL();
89             break;
90 
91         case EVENT_LOSEFOCUS:
92             if ( IsWindowOrChild( _rNEvt.GetWindow() ) )
93                 DisplayURL( GetText() );
94             break;
95         }
96 
97 		return SvtURLBox::PreNotify(_rNEvt);
98 	}
99 
100 	//---------------------------------------------------------------------
101 	long FileURLBox::Notify( NotifyEvent& _rNEvt )
102 	{
103         switch ( _rNEvt.GetType() )
104         {
105         case EVENT_KEYINPUT:
106     		if  (   ( GetSubEdit() == _rNEvt.GetWindow()                         )
107                 &&  ( KEY_RETURN == _rNEvt.GetKeyEvent()->GetKeyCode().GetCode() )
108                 &&  ( IsInDropDown()                                             )
109                 )
110 			{
111 				long nReturn = SvtURLBox::Notify(_rNEvt);
112                 DisplayURL( m_sPreservedText );
113 				return nReturn;
114 			}
115             break;
116         }
117 
118 		return SvtURLBox::Notify(_rNEvt);
119 	}
120 
121 //.........................................................................
122 }	// namespace svt
123 //.........................................................................
124 
125