summaryrefslogtreecommitdiff
path: root/include/tools/helpers.hxx
blob: 858ec4f7fc509fd5f3caff6e7c1e4b0ef6c2a6db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
#ifndef INCLUDED_TOOLS_HELPERS_HXX
#define INCLUDED_TOOLS_HELPERS_HXX

#include <sal/config.h>

#include <cassert>
#include <type_traits>

template<typename T>
inline
typename std::enable_if<
             std::is_signed<T>::value || std::is_floating_point<T>::value, long >::type
MinMax(T nVal, long nMin, long nMax)
{
    assert(nMin <= nMax);
    return nVal >= nMin
        ? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
}

template<typename T>
inline
typename std::enable_if<
             std::is_unsigned<T>::value, long >::type
MinMax(T nVal, long nMin, long nMax)
{
    assert(nMin <= nMax);
    return nMax < 0
        ? nMax
        : ((nMin < 0 || nVal >= static_cast<unsigned long>(nMin))
           ? (nVal <= static_cast<unsigned long>(nMax)
              ? static_cast<long>(nVal) : nMax)
           : nMin);
}

inline long AlignedWidth4Bytes( long nWidthBits )
{
    return ( ( nWidthBits + 31 ) >> 5 ) << 2;
}

inline long FRound( double fVal )
{
    return fVal > 0.0 ? static_cast<long>( fVal + 0.5 ) : -static_cast<long>( -fVal + 0.5 );
}

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
form/tabwin.cxx?id=e00032ba6a2ddd4c08ae6f03b1982d3c099d288e'>add toId/fromId to tidy up some ugly castingCaolán McNamara Change-Id: I70f34ac5e9b5d2f2d6c0375e823908eaa2e540b2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/129487 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> 2021-06-18tdf#130428 remove unnecessary usage of SfxItemState::UNKNOWNArmin Le Grand (Allotropia) Rename ::StateChanged methods using SfxItemState to allow better analysis of SfxItemState/SfxPoolItem usage(s), discussion see tdf#130428 comment 30 Change-Id: I736be0160ad7a9b7882c1c8a4cc05d9396ee3305 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117366 Tested-by: Jenkins Reviewed-by: Armin Le Grand <Armin.Le.Grand@me.com> 2021-02-15loplugin:referencecasting in svxNoel Change-Id: I072ba9da976cefd61f4a916e70b0601439e8a123 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110818 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2020-10-26switching long to a 64-bit type on 64-bit windowsNoel (*) create a rewriting plugin to do most of the work, heavily based on the fakebool plugin (*) but there are still a number of "long"s in the codebase that will need to be done by hand (*) the plugin needs lots of handholding, due to needing to add #include and update macros Change-Id: I8184d7000ca482c0469514bb73178c3a1123b1e9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104203 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2020-03-13Revert "loplugin:constfields in svx"Noel Grandin This reverts commit 1a6397030381a45f27ab7a2a02e6e6d0f9987c84. Change-Id: Iaa706bb4ea3144ef57ab359b982400abc589b97e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90454 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2020-02-28weld calc navigatorCaolán McNamara note: non-standard dnd via parent so the treeview triggers the dnd but doesn't itself strictly speaking drive the dnd, see copying a range from the navigator where the calc main edit window shows the outline where the copy of the range from the calc main window will go Change-Id: Ideecbe779e3d9bb5b392357a93ec25f625180ba8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89597 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> 2020-02-24tdf#42949 Fix IWYU warnings in svx/source/[f-m]*/*cxxGabor Kelemen Found with bin/find-unneeded-includes Only removal proposals are dealt with here. Change-Id: I103c5c7f1a74e8c3a021a91c7a96ebc87cb19efd Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89263 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com> 2020-01-23weld SvxFontWorkDialogCaolán McNamara Change-Id: If9da7ad6a834d22f1bcab8d41ce7fe1f80168946 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/84774 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> 2019-12-26use more TOOLS_WARN_EXCEPTIONNoel Grandin so we get more useful log messages when stuff goes wrong Change-Id: Ia55db7ab1a4d79b0f281673fbbb06c61745fa89e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/85829 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2019-12-02remove some unneeded includesCaolán McNamara Change-Id: I57e3159b99eadd072dde4871d0ccc37d570cfc05 Reviewed-on: https://gerrit.libreoffice.org/84164 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-12-01weld FmFieldWinCaolán McNamara needs drag source support fixes a leak of ColumnInfo data as well Change-Id: I671834726aed3fd4de096b56baaa592f51a9e73e Reviewed-on: https://gerrit.libreoffice.org/84147 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-08-17tdf#125340 transport preferred dialog parent down the migration dialogCaolán McNamara Change-Id: Icb7bab35eac3ae08fb82d73f559ef161dd1820c3 Reviewed-on: https://gerrit.libreoffice.org/77606 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com> 2019-08-15loplugin:sequenceloop in svtools..svxNoel Grandin Change-Id: I81b54f6db69491492b2bc16f48b2296ad96e137d Reviewed-on: https://gerrit.libreoffice.org/77529 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> 2019-07-09Simplify Sequence iterations in svxArkadiy Illarionov Use range-based loops, STL and comphelper functions Change-Id: If6d190cf72b8653c1c3fbe9a6a6e47f10f1a6765 Reviewed-on: https://gerrit.libreoffice.org/75255 Tested-by: Jenkins Reviewed-by: Arkadiy Illarionov <qarkai@gmail.com>