xref: /trunk/main/sfx2/source/bastyp/frmhtml.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_sfx2.hxx"
30 
31 #include <tools/list.hxx>
32 #include <tools/table.hxx>
33 #include <svtools/htmltokn.h>
34 #include <svtools/asynclink.hxx>
35 
36 #define _SVSTDARR_USHORTS
37 #define _SVSTDARR_ULONGS
38 #include <svl/svstdarr.hxx>
39 
40 #include <sfx2/sfx.hrc>
41 
42 #include <sfx2/frmhtml.hxx>
43 #include <sfx2/docfile.hxx>
44 #include <sfx2/viewfrm.hxx>
45 #include <sfx2/evntconf.hxx>
46 #include <sfx2/request.hxx>
47 #include <sfx2/fcontnr.hxx>
48 #include "sfxtypes.hxx"
49 
50 #define SFX_HTMLFRMSIZE_REL 0x0001
51 #define SFX_HTMLFRMSIZE_PERCENT 0x0002
52 
53 static sal_Char __READONLY_DATA sHTML_SC_yes[] =    "YES";
54 static sal_Char __READONLY_DATA sHTML_SC_no[] =     "NO";
55 static sal_Char __READONLY_DATA sHTML_SC_auto[] =   "AUTO";
56 
57 #define HTML_O_READONLY "READONLY"
58 #define HTML_O_EDIT     "EDIT"
59 
60 static HTMLOptionEnum __READONLY_DATA aScollingTable[] =
61 {
62     { sHTML_SC_yes,     ScrollingYes    },
63     { sHTML_SC_no,      ScrollingNo     },
64     { sHTML_SC_auto,    ScrollingAuto   },
65     { 0,                0               }
66 };
67 
68 void SfxFrameHTMLParser::ParseFrameOptions( SfxFrameDescriptor *pFrame, const HTMLOptions *pOptions, const String& rBaseURL )
69 {
70     // die Optionen holen und setzen
71     Size aMargin( pFrame->GetMargin() );
72 
73     // MIB 15.7.97: Netscape scheint marginwidth auf 0 zu setzen, sobald
74     // marginheight gesetzt wird und umgekehrt. Machen wir jetzt wegen
75     // bug #41665# auch so.
76     // Netscape l"a\st aber ein direktes Setzen auf 0 nicht zu, IE4.0 schon.
77     // Den Bug machen wir nicht mit!
78     sal_Bool bMarginWidth = sal_False, bMarginHeight = sal_False;
79 
80     sal_uInt16 nArrLen = pOptions->Count();
81     for ( sal_uInt16 i=0; i<nArrLen; i++ )
82     {
83         const HTMLOption *pOption = (*pOptions)[i];
84         switch( pOption->GetToken() )
85         {
86         case HTML_O_BORDERCOLOR:
87             {
88                 Color aColor;
89                 pOption->GetColor( aColor );
90                 pFrame->SetWallpaper( Wallpaper( aColor ) );
91                 break;
92             }
93         case HTML_O_SRC:
94             pFrame->SetURL(
95                 String(
96                     INetURLObject::GetAbsURL(
97                         rBaseURL, pOption->GetString())) );
98             break;
99         case HTML_O_NAME:
100             pFrame->SetName( pOption->GetString() );
101             break;
102         case HTML_O_MARGINWIDTH:
103             aMargin.Width() = pOption->GetNumber();
104 
105 //          if( aMargin.Width() < 1 )
106 //              aMargin.Width() = 1;
107             if( !bMarginHeight )
108                 aMargin.Height() = 0;
109             bMarginWidth = sal_True;
110             break;
111         case HTML_O_MARGINHEIGHT:
112             aMargin.Height() = pOption->GetNumber();
113 
114 //          if( aMargin.Height() < 1 )
115 //              aMargin.Height() = 1;
116             if( !bMarginWidth )
117                 aMargin.Width() = 0;
118             bMarginHeight = sal_True;
119             break;
120         case HTML_O_SCROLLING:
121             pFrame->SetScrollingMode(
122                 (ScrollingMode)pOption->GetEnum( aScollingTable,
123                                                  ScrollingAuto ) );
124             break;
125         case HTML_O_FRAMEBORDER:
126         {
127             String aStr = pOption->GetString();
128             sal_Bool bBorder = sal_True;
129             if ( aStr.EqualsIgnoreCaseAscii("NO") ||
130                  aStr.EqualsIgnoreCaseAscii("0") )
131                 bBorder = sal_False;
132             pFrame->SetFrameBorder( bBorder );
133             break;
134         }
135         case HTML_O_NORESIZE:
136             pFrame->SetResizable( sal_False );
137             break;
138         default:
139             if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
140                                                         HTML_O_READONLY ) )
141             {
142                 String aStr = pOption->GetString();
143                 sal_Bool bReadonly = sal_True;
144                 if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
145                     bReadonly = sal_False;
146                 pFrame->SetReadOnly( bReadonly );
147             }
148             else if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
149                                                         HTML_O_EDIT ) )
150             {
151                 String aStr = pOption->GetString();
152                 sal_Bool bEdit = sal_True;
153                 if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
154                     bEdit = sal_False;
155                 pFrame->SetEditable( bEdit );
156             }
157 
158             break;
159         }
160     }
161 
162     pFrame->SetMargin( aMargin );
163 }
164