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_dbaccess.hxx"
30 #ifndef DBAUI_TITLE_WINDOW_HXX
31 #include "AppTitleWindow.hxx"
32 #endif
33 #ifndef _DBAUI_MODULE_DBU_HXX_
34 #include "moduledbu.hxx"
35 #endif
36 #include "memory"
37 #ifndef _SV_SVAPP_HXX //autogen
38 #include <vcl/svapp.hxx>
39 #endif
40 #ifndef _TOOLS_DEBUG_HXX
41 #include <tools/debug.hxx>
42 #endif
43 
44 namespace dbaui
45 {
46 
47 DBG_NAME(OTitleWindow)
48 OTitleWindow::OTitleWindow(Window* _pParent,sal_uInt16 _nTitleId,WinBits _nBits,sal_Bool _bShift)
49 : Window(_pParent,_nBits | WB_DIALOGCONTROL)
50 , m_aSpace1(this)
51 , m_aSpace2(this)
52 , m_aTitle(this)
53 , m_pChild(NULL)
54 , m_bShift(_bShift)
55 {
56     DBG_CTOR(OTitleWindow,NULL);
57 
58 	setTitle(_nTitleId);
59 	SetBorderStyle(WINDOW_BORDER_MONO);
60 	ImplInitSettings( sal_True, sal_True, sal_True );
61 
62 	Window* pWindows [] = { &m_aSpace1, &m_aSpace2, &m_aTitle };
63 	for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
64 		pWindows[i]->Show();
65 }
66 // -----------------------------------------------------------------------------
67 OTitleWindow::~OTitleWindow()
68 {
69 	if ( m_pChild )
70 	{
71 		m_pChild->Hide();
72 		::std::auto_ptr<Window> aTemp(m_pChild);
73 		m_pChild = NULL;
74 	}
75 
76     DBG_DTOR(OTitleWindow,NULL);
77 }
78 // -----------------------------------------------------------------------------
79 void OTitleWindow::setChildWindow(Window* _pChild)
80 {
81 	m_pChild = _pChild;
82 }
83 #define SPACE_BORDER	1
84 // -----------------------------------------------------------------------------
85 void OTitleWindow::Resize()
86 {
87 	//////////////////////////////////////////////////////////////////////
88 	// Abmessungen parent window
89 	Size aOutputSize( GetOutputSize() );
90 	long nOutputWidth	= aOutputSize.Width();
91 	long nOutputHeight	= aOutputSize.Height();
92 
93 	Size aTextSize = LogicToPixel( Size( 6, 3 ), MAP_APPFONT );
94 	sal_Int32 nXOffset = aTextSize.Width();
95 	sal_Int32 nYOffset = aTextSize.Height();
96 	sal_Int32 nHeight = GetTextHeight() + 2*nYOffset;
97 
98 	m_aSpace1.SetPosSizePixel(	Point(SPACE_BORDER, SPACE_BORDER ),
99 								Size(nXOffset , nHeight - SPACE_BORDER) );
100 	m_aSpace2.SetPosSizePixel(	Point(nXOffset + SPACE_BORDER, SPACE_BORDER ),
101 								Size(nOutputWidth - nXOffset - 2*SPACE_BORDER, nYOffset) );
102 	m_aTitle.SetPosSizePixel(	Point(nXOffset + SPACE_BORDER, nYOffset + SPACE_BORDER),
103 								Size(nOutputWidth - nXOffset - 2*SPACE_BORDER, nHeight - nYOffset - SPACE_BORDER) );
104 	if ( m_pChild )
105 	{
106 		m_pChild->SetPosSizePixel(	Point(m_bShift ? (nXOffset+SPACE_BORDER) : sal_Int32(SPACE_BORDER), nHeight + nXOffset + SPACE_BORDER),
107 									Size(nOutputWidth - ( m_bShift ? (2*nXOffset - 2*SPACE_BORDER) : sal_Int32(SPACE_BORDER) ), nOutputHeight - nHeight - 2*nXOffset - 2*SPACE_BORDER) );
108 	}
109 }
110 // -----------------------------------------------------------------------------
111 void OTitleWindow::setTitle(sal_uInt16 _nTitleId)
112 {
113 	if ( _nTitleId != 0 )
114 	{
115 		m_aTitle.SetText(ModuleRes(_nTitleId));
116 	}
117 }
118 // -----------------------------------------------------------------------------
119 void OTitleWindow::GetFocus()
120 {
121 	Window::GetFocus();
122 	if ( m_pChild )
123 		m_pChild->GrabFocus();
124 }
125 // -----------------------------------------------------------------------------
126 long OTitleWindow::GetWidthPixel() const
127 {
128     Size aTextSize = LogicToPixel( Size( 12, 0 ), MAP_APPFONT );
129     sal_Int32 nWidth = GetTextWidth(m_aTitle.GetText()) + 2*aTextSize.Width();
130 
131 	return nWidth;
132 }
133 // -----------------------------------------------------------------------
134 void OTitleWindow::DataChanged( const DataChangedEvent& rDCEvt )
135 {
136 	Window::DataChanged( rDCEvt );
137 
138 	if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
139 		(rDCEvt.GetType() == DATACHANGED_DISPLAY) ||
140 		(rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
141 		((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
142 		(rDCEvt.GetFlags() & SETTINGS_STYLE)) )
143 	{
144 		ImplInitSettings( sal_True, sal_True, sal_True );
145 		Invalidate();
146 	}
147 }
148 //-----------------------------------------------------------------------------
149 void OTitleWindow::ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground )
150 {
151 	AllSettings aAllSettings = GetSettings();
152 	StyleSettings aStyle = aAllSettings.GetStyleSettings();
153 	aStyle.SetMonoColor(aStyle.GetActiveBorderColor());//GetMenuBorderColor());
154 	aAllSettings.SetStyleSettings(aStyle);
155 	SetSettings(aAllSettings);
156 
157 	const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
158 	if( bFont )
159 	{
160 		Font aFont;
161 		aFont = rStyleSettings.GetFieldFont();
162 		aFont.SetColor( rStyleSettings.GetWindowTextColor() );
163 		SetPointFont( aFont );
164 	}
165 
166 	if( bForeground || bFont )
167 	{
168 		SetTextColor( rStyleSettings.GetFieldTextColor() );
169 		SetTextFillColor();
170 	}
171 
172 	if( bBackground )
173 		SetBackground( rStyleSettings.GetFieldColor() );
174 
175 
176 	Window* pWindows [] = { &m_aSpace1, &m_aSpace2, &m_aTitle};
177 	for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
178 	{
179 		Font aFont = pWindows[i]->GetFont();
180 		aFont.SetWeight(WEIGHT_BOLD);
181 		pWindows[i]->SetFont(aFont);
182 		pWindows[i]->SetTextColor( aStyle.GetLightColor() );
183 		pWindows[i]->SetBackground( Wallpaper( aStyle.GetShadowColor() ) );
184 	}
185 }
186 // .............................................................
187 } // namespace dbaui
188 // .............................................................
189