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_dbaccess.hxx" 26 27 #ifndef DBAUI_TABLEFIELDDESCRIPTION_HXX 28 #include "TableFieldDescWin.hxx" 29 #endif 30 #ifndef _TOOLS_DEBUG_HXX 31 #include <tools/debug.hxx> 32 #endif 33 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX 34 #include "FieldDescriptions.hxx" 35 #endif 36 #ifndef _DBU_TBL_HRC_ 37 #include "dbu_tbl.hrc" 38 #endif 39 #ifndef DBAUI_FIELDDESCRIPTIONS_HXX 40 #include "FieldDescriptions.hxx" 41 #endif 42 #ifndef DBAUI_TABLEDESIGNHELPBAR_HXX 43 #include "TableDesignHelpBar.hxx" 44 #endif 45 #ifndef _SV_FIXED_HXX 46 #include <vcl/fixed.hxx> 47 #endif 48 #ifndef _DBA_DBACCESS_HELPID_HRC_ 49 #include "dbaccess_helpid.hrc" 50 #endif 51 #ifndef _DBAUI_MODULE_DBU_HXX_ 52 #include "moduledbu.hxx" 53 #endif 54 #include <memory> 55 56 #define STANDARD_MARGIN 6 57 #define DETAILS_HEADER_HEIGHT 25 58 #define CONTROL_SPACING_X 18 // 6 59 #define CONTROL_SPACING_Y 5 60 #define CONTROL_HEIGHT 20 61 #define CONTROL_WIDTH_1 140 // 100 62 #define CONTROL_WIDTH_2 100 // 60 63 #define CONTROL_WIDTH_3 250 64 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5) 65 #define DETAILS_OPT_PAGE_WIDTH (CONTROL_WIDTH_1 + CONTROL_SPACING_X + CONTROL_WIDTH_4 + 50) 66 #define DETAILS_OPT_PAGE_HEIGHT ((CONTROL_HEIGHT + CONTROL_SPACING_Y) * 5) 67 #define DETAILS_MIN_HELP_WIDTH 100 68 #define DETAILS_OPT_HELP_WIDTH 200 69 #define DETAILS_MIN_HELP_HEIGHT 50 70 #define DETAILS_OPT_HELP_HEIGHT 100 71 72 73 using namespace dbaui; 74 //================================================================== 75 // class OTableFieldDescWin 76 //================================================================== 77 DBG_NAME(OTableFieldDescWin) 78 //------------------------------------------------------------------------------ 79 OTableFieldDescWin::OTableFieldDescWin( Window* pParent) 80 :TabPage(pParent, WB_3DLOOK) 81 { 82 DBG_CTOR(OTableFieldDescWin,NULL); 83 ////////////////////////////////////////////////////////////////////// 84 // Header 85 m_pHeader = new FixedText( this, WB_CENTER | WB_INFO ); // | WB_3DLOOK 86 m_pHeader->SetText( String(ModuleRes(STR_TAB_PROPERTIES)) ); 87 m_pHeader->Show(); 88 89 ////////////////////////////////////////////////////////////////////// 90 // HelpBar 91 m_pHelpBar = new OTableDesignHelpBar( this ); 92 m_pHelpBar->SetHelpId(HID_TAB_DESIGN_HELP_TEXT_FRAME); 93 m_pHelpBar->Show(); 94 95 m_pGenPage = new OFieldDescGenWin( this, m_pHelpBar ); 96 getGenPage()->SetHelpId( HID_TABLE_DESIGN_TABPAGE_GENERAL ); 97 getGenPage()->Show(); 98 } 99 100 //------------------------------------------------------------------------------ 101 OTableFieldDescWin::~OTableFieldDescWin() 102 { 103 DBG_DTOR(OTableFieldDescWin,NULL); 104 ////////////////////////////////////////////////////////////////////// 105 // Childs zerstoeren 106 m_pHelpBar->Hide(); 107 getGenPage()->Hide(); 108 m_pHeader->Hide(); 109 110 { 111 ::std::auto_ptr<Window> aTemp(m_pGenPage); 112 m_pGenPage = NULL; 113 } 114 { 115 ::std::auto_ptr<Window> aTemp(m_pHeader); 116 m_pHeader = NULL; 117 } 118 { 119 ::std::auto_ptr<Window> aTemp(m_pHelpBar); 120 m_pHelpBar = NULL; 121 } 122 } 123 124 //------------------------------------------------------------------------------ 125 void OTableFieldDescWin::Init() 126 { 127 DBG_ASSERT(getGenPage() != NULL, "OTableFieldDescWin::Init : ups ... no GenericPage ... this will crash ..."); 128 getGenPage()->Init(); 129 } 130 131 //------------------------------------------------------------------------------ 132 void OTableFieldDescWin::SetReadOnly( sal_Bool bRead ) 133 { 134 DBG_CHKTHIS(OTableFieldDescWin,NULL); 135 getGenPage()->SetReadOnly( bRead ); 136 } 137 138 //------------------------------------------------------------------------------ 139 void OTableFieldDescWin::DisplayData( OFieldDescription* pFieldDescr ) 140 { 141 DBG_CHKTHIS(OTableFieldDescWin,NULL); 142 getGenPage()->DisplayData( pFieldDescr ); 143 } 144 145 //------------------------------------------------------------------------------ 146 void OTableFieldDescWin::SaveData( OFieldDescription* pFieldDescr ) 147 { 148 DBG_CHKTHIS(OTableFieldDescWin,NULL); 149 getGenPage()->SaveData( pFieldDescr ); 150 } 151 152 //------------------------------------------------------------------------------ 153 void OTableFieldDescWin::Paint( const Rectangle& /*rRect*/ ) 154 { 155 DBG_CHKTHIS(OTableFieldDescWin,NULL); 156 ////////////////////////////////////////////////////////////////////// 157 // 3D-Linie am oberen Fensterrand 158 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 159 160 SetLineColor( rStyleSettings.GetLightColor() ); 161 DrawLine( Point(0,0), Point(GetSizePixel().Width(),0) ); 162 163 ////////////////////////////////////////////////////////////////////// 164 // 3D-Linie zum Abtrennen des Headers 165 DrawLine( Point(3, DETAILS_HEADER_HEIGHT), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT) ); 166 SetLineColor( rStyleSettings.GetShadowColor() ); 167 DrawLine( Point(3, DETAILS_HEADER_HEIGHT-1), Point(GetSizePixel().Width()-6, DETAILS_HEADER_HEIGHT-1) ); 168 } 169 170 //------------------------------------------------------------------------------ 171 void OTableFieldDescWin::Resize() 172 { 173 DBG_CHKTHIS(OTableFieldDescWin,NULL); 174 ////////////////////////////////////////////////////////////////////// 175 // Abmessungen parent window 176 Size aOutputSize( GetOutputSizePixel() ); 177 long nOutputWidth = aOutputSize.Width(); 178 long nOutputHeight = aOutputSize.Height(); 179 180 // da die GenPage scrollen kann, ich selber aber nicht, positioniere ich das HelpFenster, wenn ich zu schmal werde, 181 // _unter_ der Genpage, nicht rechts daneben. Zuvor versuche ich aber noch, es etwas schmaler zu machen 182 183 long nHelpX, nHelpY; 184 long nHelpWidth, nHelpHeight; 185 long nPageWidth, nPageHeight; 186 187 // passen beide nebeneinander (Rand + Page + Rand + Help) ? 188 if (STANDARD_MARGIN + DETAILS_OPT_PAGE_WIDTH + STANDARD_MARGIN + DETAILS_MIN_HELP_WIDTH <= nOutputWidth) 189 { // ja -> dann ist die Frage, ob man der Hilfe ihre Optimal-Breite geben kann 190 nHelpWidth = DETAILS_OPT_HELP_WIDTH; 191 nPageWidth = nOutputWidth - nHelpWidth - STANDARD_MARGIN - STANDARD_MARGIN; 192 if (nPageWidth < DETAILS_OPT_PAGE_WIDTH) 193 { // dann doch lieber die Hilfe von ihrer optimalen in Richtung auf die minimale Groesse 194 long nTransfer = DETAILS_OPT_PAGE_WIDTH - nPageWidth; 195 nPageWidth += nTransfer; 196 nHelpWidth -= nTransfer; 197 } 198 nHelpX = nOutputWidth - nHelpWidth; 199 // die Hoehen sind dann einfach ... 200 nHelpY = DETAILS_HEADER_HEIGHT + 1; 201 nHelpHeight = nOutputHeight - nHelpY; 202 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN; 203 } 204 else 205 { // nebeneinander geht nicht, also untereinander (Rand + Header + Page + Help) 206 if (STANDARD_MARGIN + DETAILS_HEADER_HEIGHT + DETAILS_OPT_PAGE_HEIGHT + DETAILS_MIN_HELP_HEIGHT <= nOutputHeight) 207 { // es reicht zumindest, um beide untereinander (Page optimal, Help minimal) unterzubringen 208 nHelpHeight = DETAILS_OPT_HELP_HEIGHT; 209 nPageHeight = nOutputHeight - nHelpHeight - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN; 210 if (nPageHeight < DETAILS_OPT_PAGE_HEIGHT) 211 { // wie oben : Page optimal, Hilfe soviel wie eben bleibt (das ist groesser/gleich ihrem Minimum) 212 long nTransfer = DETAILS_OPT_PAGE_HEIGHT - nPageHeight; 213 nPageHeight += nTransfer; 214 nHelpHeight -= nTransfer; 215 } 216 nHelpY = nOutputHeight - nHelpHeight; 217 // und ueber die ganze Breite 218 nHelpX = 0; // ohne Margin, da das HelpCtrl einen eigenen hat 219 nHelpWidth = nOutputWidth; // dito 220 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN; 221 } 222 else 223 { // dummerweise reicht es nicht mal, um Page optimal und Help minimal zu zeigen 224 nHelpX = nHelpY = nHelpWidth = nHelpHeight = 0; // -> kein Help-Fenster 225 nPageWidth = nOutputWidth - STANDARD_MARGIN - STANDARD_MARGIN; 226 nPageHeight = nOutputHeight - STANDARD_MARGIN - DETAILS_HEADER_HEIGHT - STANDARD_MARGIN; 227 } 228 } 229 230 m_pHeader->SetPosSizePixel( Point(0, STANDARD_MARGIN), Size(nOutputWidth, 15) ); 231 232 getGenPage()->SetPosSizePixel(Point ( STANDARD_MARGIN, 233 STANDARD_MARGIN + DETAILS_HEADER_HEIGHT 234 ), 235 Size ( nPageWidth, 236 nPageHeight 237 ) 238 ); 239 if (nHelpHeight) 240 { 241 m_pHelpBar->Show(); 242 m_pHelpBar->SetPosSizePixel(Point ( nHelpX, 243 nHelpY 244 ), 245 Size ( nHelpWidth, 246 nHelpHeight 247 ) 248 ); 249 } 250 else 251 { 252 m_pHelpBar->Hide(); 253 } 254 Invalidate(); 255 } 256 // ----------------------------------------------------------------------------- 257 IClipboardTest* OTableFieldDescWin::getActiveChild() const 258 { 259 IClipboardTest* pTest = NULL; 260 switch(m_eChildFocus) 261 { 262 case DESCRIPTION: 263 pTest = getGenPage(); 264 break; 265 default: 266 pTest = getHelpBar(); 267 break; 268 } 269 return pTest; 270 } 271 // ----------------------------------------------------------------------------- 272 sal_Bool OTableFieldDescWin::isCopyAllowed() 273 { 274 return getActiveChild() && getActiveChild()->isCopyAllowed(); 275 } 276 // ----------------------------------------------------------------------------- 277 sal_Bool OTableFieldDescWin::isCutAllowed() 278 { 279 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isCutAllowed()); 280 } 281 // ----------------------------------------------------------------------------- 282 sal_Bool OTableFieldDescWin::isPasteAllowed() 283 { 284 return (getGenPage() && getGenPage()->HasChildPathFocus() && getGenPage()->isPasteAllowed()); 285 } 286 // ----------------------------------------------------------------------------- 287 void OTableFieldDescWin::cut() 288 { 289 if ( getGenPage() && getGenPage()->HasChildPathFocus() ) 290 getGenPage()->cut(); 291 } 292 // ----------------------------------------------------------------------------- 293 void OTableFieldDescWin::copy() 294 { 295 if ( getActiveChild() ) 296 getActiveChild()->copy(); 297 } 298 // ----------------------------------------------------------------------------- 299 void OTableFieldDescWin::paste() 300 { 301 if ( getGenPage() && getGenPage()->HasChildPathFocus() ) 302 getGenPage()->paste(); 303 } 304 // ----------------------------------------------------------------------------- 305 void OTableFieldDescWin::GetFocus() 306 { 307 if ( getGenPage() ) 308 getGenPage()->GetFocus(); 309 } 310 // ----------------------------------------------------------------------------- 311 void OTableFieldDescWin::LoseFocus() 312 { 313 if ( getGenPage() ) 314 getGenPage()->LoseFocus(); 315 } 316 // ----------------------------------------------------------------------------- 317 long OTableFieldDescWin::PreNotify( NotifyEvent& rNEvt ) 318 { 319 sal_Bool bHandled = sal_False; 320 switch(rNEvt.GetType()) 321 { 322 case EVENT_GETFOCUS: 323 if( getGenPage() && getGenPage()->HasChildPathFocus() ) 324 m_eChildFocus = DESCRIPTION; 325 else 326 m_eChildFocus = HELP; 327 break; 328 } 329 330 return bHandled ? 1L : TabPage::PreNotify(rNEvt); 331 } 332 333 334