Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / brwbox / brwhead.cxx
blob86ed55d0dfce2a76e0b16130498e676d1372ffa4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svtools/brwhead.hxx>
22 #include <svtools/brwbox.hxx>
23 #include <vcl/commandevent.hxx>
26 BrowserHeader::BrowserHeader( BrowseBox* pParent, WinBits nWinBits )
27 :HeaderBar( pParent, nWinBits )
28 ,_pBrowseBox( pParent )
30 tools::Long nHeight = pParent->IsZoom() ? pParent->CalcZoom(pParent->GetTitleHeight()) : pParent->GetTitleHeight();
32 SetPosSizePixel( Point( 0, 0),
33 Size( pParent->GetOutputSizePixel().Width(),
34 nHeight ) );
35 Show();
39 BrowserHeader::~BrowserHeader()
41 disposeOnce();
44 void BrowserHeader::dispose()
46 _pBrowseBox.clear();
47 HeaderBar::dispose();
51 void BrowserHeader::Command( const CommandEvent& rCEvt )
53 if ( !GetCurItemId() && CommandEventId::ContextMenu == rCEvt.GetCommand() )
55 Point aPos( rCEvt.GetMousePosPixel() );
56 if ( _pBrowseBox->IsFrozen(0) )
57 aPos.AdjustX(_pBrowseBox->GetColumnWidth(0) );
58 _pBrowseBox->GetDataWindow().Command( CommandEvent(
59 Point( aPos.X(), aPos.Y() - GetSizePixel().Height() ),
60 CommandEventId::ContextMenu, rCEvt.IsMouseEvent() ) );
65 void BrowserHeader::EndDrag()
67 // call before other actions, it looks more nice in most cases
68 HeaderBar::EndDrag();
69 PaintImmediately();
71 // not aborted?
72 sal_uInt16 nId = GetCurItemId();
73 if ( !nId )
74 return;
76 // handle column?
77 if ( nId == USHRT_MAX-1 )
78 nId = 0;
80 if ( !IsItemMode() )
82 // column resize
83 _pBrowseBox->SetColumnWidth( nId, GetItemSize( nId ) );
84 _pBrowseBox->ColumnResized( nId );
85 SetItemSize( nId, _pBrowseBox->GetColumnWidth( nId ) );
87 else
89 // column drag
90 // did the position actually change?
91 // take the handle column into account
92 sal_uInt16 nOldPos = _pBrowseBox->GetColumnPos(nId),
93 nNewPos = GetItemPos( nId );
95 if (_pBrowseBox->GetColumnId(0) == BrowseBox::HandleColumnId)
96 nNewPos++;
98 if (nOldPos != nNewPos)
100 _pBrowseBox->SetColumnPos( nId, nNewPos );
101 _pBrowseBox->ColumnMoved( nId );
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */