Avoid potential negative array index access to cached text.
[LibreOffice.git] / framework / source / uiconfiguration / ImageList.hxx
blobedd0789ed1464b753f748346ceac82793d7de6b7
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 .
20 #pragma once
22 #include <vcl/image.hxx>
24 #include <string_view>
25 #include <unordered_map>
26 #include <vector>
28 // Images identified by either name, or by id
29 struct ImageAryData
31 OUString maName;
32 sal_uInt16 mnId;
33 Image maImage;
37 class ImageList
39 public:
40 explicit ImageList();
41 ImageList( const std::vector<OUString>& rNameVector,
42 const OUString& rPrefix);
44 void InsertFromHorizontalStrip( const BitmapEx &rBitmapEx,
45 const std::vector< OUString > &rNameVector );
46 BitmapEx GetAsHorizontalStrip() const;
47 sal_uInt16 GetImageCount() const;
49 void AddImage( const OUString& rImageName, const Image& rImage );
51 void ReplaceImage( const OUString& rImageName, const Image& rImage );
53 void RemoveImage( sal_uInt16 nId );
55 Image GetImage( const OUString& rImageName ) const;
57 sal_uInt16 GetImagePos( std::u16string_view rImageName ) const;
59 sal_uInt16 GetImageId( sal_uInt16 nPos ) const;
61 const OUString & GetImageName( sal_uInt16 nPos ) const;
62 void GetImageNames( ::std::vector< OUString >& rNames ) const;
64 private:
66 std::vector< std::unique_ptr<ImageAryData> > maImages;
67 std::unordered_map< OUString, ImageAryData * > maNameHash;
68 OUString maPrefix;
70 sal_uInt16 ImplGetImageId( const OUString& rImageName ) const;
71 void ImplAddImage( std::u16string_view aPrefix, const OUString &aName, sal_uInt16 nId, const Image &aImage );
72 void ImplRemoveImage( sal_uInt16 nPos );
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */