xref: /AOO41X/main/sfx2/source/bastyp/frmhtml.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 #include <tools/list.hxx>
28 #include <tools/table.hxx>
29 #include <svtools/htmltokn.h>
30 #include <svtools/asynclink.hxx>
31 
32 #define _SVSTDARR_USHORTS
33 #define _SVSTDARR_ULONGS
34 #include <svl/svstdarr.hxx>
35 
36 #include <sfx2/sfx.hrc>
37 
38 #include <sfx2/frmhtml.hxx>
39 #include <sfx2/docfile.hxx>
40 #include <sfx2/viewfrm.hxx>
41 #include <sfx2/evntconf.hxx>
42 #include <sfx2/request.hxx>
43 #include <sfx2/fcontnr.hxx>
44 #include "sfxtypes.hxx"
45 
46 #define SFX_HTMLFRMSIZE_REL 0x0001
47 #define SFX_HTMLFRMSIZE_PERCENT 0x0002
48 
49 static sal_Char __READONLY_DATA sHTML_SC_yes[] =    "YES";
50 static sal_Char __READONLY_DATA sHTML_SC_no[] =     "NO";
51 static sal_Char __READONLY_DATA sHTML_SC_auto[] =   "AUTO";
52 
53 #define HTML_O_READONLY "READONLY"
54 #define HTML_O_EDIT     "EDIT"
55 
56 static HTMLOptionEnum __READONLY_DATA aScollingTable[] =
57 {
58     { sHTML_SC_yes,     ScrollingYes    },
59     { sHTML_SC_no,      ScrollingNo     },
60     { sHTML_SC_auto,    ScrollingAuto   },
61     { 0,                0               }
62 };
63 
ParseFrameOptions(SfxFrameDescriptor * pFrame,const HTMLOptions * pOptions,const String & rBaseURL)64 void SfxFrameHTMLParser::ParseFrameOptions( SfxFrameDescriptor *pFrame, const HTMLOptions *pOptions, const String& rBaseURL )
65 {
66     // die Optionen holen und setzen
67     Size aMargin( pFrame->GetMargin() );
68 
69     // MIB 15.7.97: Netscape scheint marginwidth auf 0 zu setzen, sobald
70     // marginheight gesetzt wird und umgekehrt. Machen wir jetzt wegen
71     // bug #41665# auch so.
72     // Netscape l"a\st aber ein direktes Setzen auf 0 nicht zu, IE4.0 schon.
73     // Den Bug machen wir nicht mit!
74     sal_Bool bMarginWidth = sal_False, bMarginHeight = sal_False;
75 
76     sal_uInt16 nArrLen = pOptions->Count();
77     for ( sal_uInt16 i=0; i<nArrLen; i++ )
78     {
79         const HTMLOption *pOption = (*pOptions)[i];
80         switch( pOption->GetToken() )
81         {
82         case HTML_O_BORDERCOLOR:
83             {
84                 Color aColor;
85                 pOption->GetColor( aColor );
86                 pFrame->SetWallpaper( Wallpaper( aColor ) );
87                 break;
88             }
89         case HTML_O_SRC:
90             pFrame->SetURL(
91                 String(
92                     INetURLObject::GetAbsURL(
93                         rBaseURL, pOption->GetString())) );
94             break;
95         case HTML_O_NAME:
96             pFrame->SetName( pOption->GetString() );
97             break;
98         case HTML_O_MARGINWIDTH:
99             aMargin.Width() = pOption->GetNumber();
100 
101 //          if( aMargin.Width() < 1 )
102 //              aMargin.Width() = 1;
103             if( !bMarginHeight )
104                 aMargin.Height() = 0;
105             bMarginWidth = sal_True;
106             break;
107         case HTML_O_MARGINHEIGHT:
108             aMargin.Height() = pOption->GetNumber();
109 
110 //          if( aMargin.Height() < 1 )
111 //              aMargin.Height() = 1;
112             if( !bMarginWidth )
113                 aMargin.Width() = 0;
114             bMarginHeight = sal_True;
115             break;
116         case HTML_O_SCROLLING:
117             pFrame->SetScrollingMode(
118                 (ScrollingMode)pOption->GetEnum( aScollingTable,
119                                                  ScrollingAuto ) );
120             break;
121         case HTML_O_FRAMEBORDER:
122         {
123             String aStr = pOption->GetString();
124             sal_Bool bBorder = sal_True;
125             if ( aStr.EqualsIgnoreCaseAscii("NO") ||
126                  aStr.EqualsIgnoreCaseAscii("0") )
127                 bBorder = sal_False;
128             pFrame->SetFrameBorder( bBorder );
129             break;
130         }
131         case HTML_O_NORESIZE:
132             pFrame->SetResizable( sal_False );
133             break;
134         default:
135             if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
136                                                         HTML_O_READONLY ) )
137             {
138                 String aStr = pOption->GetString();
139                 sal_Bool bReadonly = sal_True;
140                 if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
141                     bReadonly = sal_False;
142                 pFrame->SetReadOnly( bReadonly );
143             }
144             else if ( pOption->GetTokenString().EqualsIgnoreCaseAscii(
145                                                         HTML_O_EDIT ) )
146             {
147                 String aStr = pOption->GetString();
148                 sal_Bool bEdit = sal_True;
149                 if ( aStr.EqualsIgnoreCaseAscii("FALSE") )
150                     bEdit = sal_False;
151                 pFrame->SetEditable( bEdit );
152             }
153 
154             break;
155         }
156     }
157 
158     pFrame->SetMargin( aMargin );
159 }
160