Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <tools/rc.h>
21 :
22 : #include <vcl/window.hxx>
23 : #include <vcl/svapp.hxx>
24 :
25 : #include "window.h"
26 :
27 5794 : static OString ImplAutoHelpID( ResMgr* pResMgr )
28 : {
29 5794 : OString aRet;
30 :
31 5794 : if( pResMgr && Application::IsAutoHelpIdEnabled() )
32 5794 : aRet = pResMgr->GetAutoHelpId();
33 :
34 5794 : return aRet;
35 : }
36 :
37 : namespace vcl {
38 :
39 5794 : WinBits Window::ImplInitRes( const ResId& rResId )
40 : {
41 5794 : GetRes( rResId );
42 :
43 5794 : char* pRes = static_cast<char*>(GetClassRes());
44 5794 : pRes += 8;
45 5794 : sal_uInt32 nStyle = (sal_uInt32)GetLongRes( static_cast<void*>(pRes) );
46 5794 : rResId.SetWinBits( nStyle );
47 5794 : return nStyle;
48 : }
49 :
50 5794 : WindowResHeader Window::ImplLoadResHeader( const ResId& rResId )
51 : {
52 5794 : WindowResHeader aHeader;
53 :
54 5794 : aHeader.nObjMask = ReadLongRes();
55 :
56 : // we need to calculate auto helpids before the resource gets closed
57 : // if the resource only contains flags, it will be closed before we try to read a help id
58 : // so we always create an auto help id that might be overwritten later
59 : // HelpId
60 5794 : aHeader.aHelpId = ImplAutoHelpID( rResId.GetResMgr() );
61 :
62 : // ResourceStyle
63 5794 : aHeader.nRSStyle = ReadLongRes();
64 : // WinBits
65 5794 : ReadLongRes();
66 :
67 5794 : if( aHeader.nObjMask & WINDOW_HELPID )
68 525 : aHeader.aHelpId = ReadByteStringRes();
69 :
70 5794 : return aHeader;
71 : }
72 :
73 5794 : void Window::ImplLoadRes( const ResId& rResId )
74 : {
75 5794 : WindowResHeader aHeader = ImplLoadResHeader( rResId );
76 :
77 5794 : SetHelpId( aHeader.aHelpId );
78 :
79 5794 : sal_uLong nObjMask = aHeader.nObjMask;
80 :
81 5794 : bool bPos = false;
82 5794 : bool bSize = false;
83 5794 : Point aPos;
84 5794 : Size aSize;
85 :
86 5794 : if ( nObjMask & (WINDOW_XYMAPMODE | WINDOW_X | WINDOW_Y) )
87 : {
88 : // use size as per resource
89 2671 : MapUnit ePosMap = MAP_PIXEL;
90 :
91 2671 : bPos = true;
92 :
93 2671 : if ( nObjMask & WINDOW_XYMAPMODE )
94 2671 : ePosMap = (MapUnit)ReadLongRes();
95 2671 : if ( nObjMask & WINDOW_X )
96 2671 : aPos.X() = ImplLogicUnitToPixelX( ReadLongRes(), ePosMap );
97 2671 : if ( nObjMask & WINDOW_Y )
98 2671 : aPos.Y() = ImplLogicUnitToPixelY( ReadLongRes(), ePosMap );
99 : }
100 :
101 5794 : if ( nObjMask & (WINDOW_WHMAPMODE | WINDOW_WIDTH | WINDOW_HEIGHT) )
102 : {
103 : // use size as per resource
104 3177 : MapUnit eSizeMap = MAP_PIXEL;
105 :
106 3177 : bSize = true;
107 :
108 3177 : if ( nObjMask & WINDOW_WHMAPMODE )
109 3177 : eSizeMap = (MapUnit)ReadLongRes();
110 3177 : if ( nObjMask & WINDOW_WIDTH )
111 3177 : aSize.Width() = ImplLogicUnitToPixelX( ReadLongRes(), eSizeMap );
112 3177 : if ( nObjMask & WINDOW_HEIGHT )
113 3177 : aSize.Height() = ImplLogicUnitToPixelY( ReadLongRes(), eSizeMap );
114 : }
115 :
116 5794 : sal_uLong nRSStyle = aHeader.nRSStyle;
117 :
118 : // looks bad due to optimization
119 5794 : if ( nRSStyle & RSWND_CLIENTSIZE )
120 : {
121 8 : if ( bPos )
122 0 : SetPosPixel( aPos );
123 8 : if ( bSize )
124 8 : SetOutputSizePixel( aSize );
125 : }
126 5786 : else if ( bPos && bSize )
127 2671 : SetPosSizePixel( aPos, aSize );
128 3115 : else if ( bPos )
129 0 : SetPosPixel( aPos );
130 3115 : else if ( bSize )
131 498 : SetSizePixel( aSize );
132 :
133 5794 : if ( nRSStyle & RSWND_DISABLED )
134 0 : Enable( false );
135 :
136 5794 : if ( nObjMask & WINDOW_TEXT )
137 2628 : SetText( ReadStringRes() );
138 5794 : if ( nObjMask & WINDOW_HELPTEXT )
139 : {
140 0 : SetHelpText( ReadStringRes() );
141 0 : mpWindowImpl->mbHelpTextDynamic = true;
142 : }
143 5794 : if ( nObjMask & WINDOW_QUICKTEXT )
144 1 : SetQuickHelpText( ReadStringRes() );
145 5794 : if ( nObjMask & WINDOW_EXTRALONG )
146 : {
147 0 : sal_uIntPtr nRes = ReadLongRes();
148 0 : SetData( reinterpret_cast<void*>(nRes) );
149 : }
150 5794 : if ( nObjMask & WINDOW_UNIQUEID )
151 0 : SetUniqueId( ReadByteStringRes() );
152 :
153 5794 : if ( nObjMask & WINDOW_BORDER_STYLE )
154 : {
155 0 : sal_uInt16 nBorderStyle = (sal_uInt16)ReadLongRes();
156 0 : SetBorderStyle( static_cast<WindowBorderStyle>(nBorderStyle) );
157 5794 : }
158 5794 : }
159 :
160 : } /* namespace vcl */
161 :
|