2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* flistbox.h - Widget FListBox and FListBoxItem *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2019-01-05 22:58:06 +01:00
|
|
|
e Copyright 2014-2019 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The Final Cut is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU Lesser General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 3 of *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2017-10-02 07:32:33 +02:00
|
|
|
|
|
|
|
/* Inheritance diagram
|
|
|
|
* ═══════════════════
|
|
|
|
*
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTerm ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏ ▕▔▔▔▔▔▔▔▔▔▏
|
2017-10-29 14:27:50 +01:00
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▏1 *▕▔▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FListBox ▏- - - -▕ FListBoxItem ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FLISTBOX_H
|
|
|
|
#define FLISTBOX_H
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-10-31 00:41:59 +01:00
|
|
|
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
|
|
|
|
#error "Only <final/final.h> can be included directly."
|
|
|
|
#endif
|
|
|
|
|
2019-10-05 23:20:07 +02:00
|
|
|
#include <unordered_map>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
#include "final/fscrollbar.h"
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwidget.h"
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-07-21 23:31:21 +02:00
|
|
|
// class forward declaration
|
|
|
|
class FScrollbar;
|
|
|
|
class FString;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBoxItem
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FListBoxItem
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Constructors
|
|
|
|
FListBoxItem ();
|
|
|
|
FListBoxItem (const FListBoxItem&); // copy constructor
|
2018-12-27 00:14:46 +01:00
|
|
|
explicit FListBoxItem (const FString&, FDataPtr = nullptr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Destructor
|
|
|
|
virtual ~FListBoxItem();
|
|
|
|
|
|
|
|
// Assignment operator (=)
|
|
|
|
FListBoxItem& operator = (const FListBoxItem&);
|
|
|
|
|
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
virtual const FString getClassName() const;
|
|
|
|
virtual FString& getText();
|
|
|
|
virtual FDataPtr getData() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2019-10-05 23:20:07 +02:00
|
|
|
void setText (const FString&);
|
|
|
|
void setData (FDataPtr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2017-09-21 07:22:08 +02:00
|
|
|
// Methods
|
2019-10-05 23:20:07 +02:00
|
|
|
void clear();
|
2017-09-21 07:22:08 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
private:
|
2019-10-05 23:20:07 +02:00
|
|
|
// Data members
|
|
|
|
FString text{};
|
|
|
|
FDataPtr data_pointer{nullptr};
|
|
|
|
fc::brackets_type brackets{fc::NoBrackets};
|
|
|
|
bool selected{false};
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Friend classes
|
|
|
|
friend class FListBox;
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
// FListBoxItem inline functions
|
2018-12-31 06:18:39 +01:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FListBoxItem::getClassName() const
|
2018-12-31 06:18:39 +01:00
|
|
|
{ return "FListBoxItem"; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-04-23 18:54:46 +02:00
|
|
|
inline FString& FListBoxItem::getText()
|
2015-09-22 04:18:20 +02:00
|
|
|
{ return text; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-24 23:16:05 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
inline FDataPtr FListBoxItem::getData() const
|
2017-02-24 23:16:05 +01:00
|
|
|
{ return data_pointer; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-03-17 22:59:06 +01:00
|
|
|
inline void FListBoxItem::setText (const FString& txt)
|
2019-08-25 22:16:00 +02:00
|
|
|
{ text.setString(txt); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-02-24 00:30:07 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-12-27 00:14:46 +01:00
|
|
|
inline void FListBoxItem::setData (FDataPtr data)
|
2017-02-24 00:30:07 +01:00
|
|
|
{ data_pointer = data; }
|
|
|
|
|
2017-09-21 07:22:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBoxItem::clear()
|
|
|
|
{ text.clear(); }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FListBox
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FListBox : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
2019-11-16 15:16:44 +01:00
|
|
|
// Typedef
|
|
|
|
typedef std::vector<FListBoxItem> listBoxItems;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FListBox (FWidget* = nullptr);
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Iterator, typename InsertConverter>
|
2018-12-10 01:48:26 +01:00
|
|
|
FListBox (Iterator, Iterator, InsertConverter, FWidget* = nullptr);
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Container, typename LazyConverter>
|
2018-12-10 01:48:26 +01:00
|
|
|
FListBox (Container, LazyConverter, FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FListBox (const FListBox&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2019-12-16 11:14:24 +01:00
|
|
|
virtual ~FListBox();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
FListBox& operator = (const FListBox&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2019-10-05 23:20:07 +02:00
|
|
|
const FString getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t getCount() const;
|
2019-12-16 11:14:24 +01:00
|
|
|
FListBoxItem& getItem (std::size_t);
|
|
|
|
const FListBoxItem& getItem (std::size_t) const;
|
|
|
|
FListBoxItem& getItem (listBoxItems::iterator);
|
|
|
|
const FListBoxItem& getItem (listBoxItems::const_iterator) const;
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t currentItem() const;
|
|
|
|
FString& getText();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2018-12-31 06:18:39 +01:00
|
|
|
void setCurrentItem (std::size_t);
|
|
|
|
void setCurrentItem (listBoxItems::iterator);
|
|
|
|
void selectItem (std::size_t);
|
|
|
|
void selectItem (listBoxItems::iterator);
|
|
|
|
void unselectItem (std::size_t);
|
|
|
|
void unselectItem (listBoxItems::iterator);
|
|
|
|
void showInsideBrackets (std::size_t, fc::brackets_type);
|
|
|
|
void showNoBrackets (std::size_t);
|
|
|
|
void showNoBrackets (listBoxItems::iterator);
|
2019-08-06 23:45:28 +02:00
|
|
|
void setGeometry ( const FPoint&, const FSize&
|
2018-12-31 06:18:39 +01:00
|
|
|
, bool = true ) override;
|
|
|
|
void setMultiSelection (bool);
|
|
|
|
void setMultiSelection ();
|
|
|
|
void unsetMultiSelection ();
|
2019-08-06 23:45:28 +02:00
|
|
|
bool setDisable() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void setText (const FString&);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiries
|
2018-12-31 06:18:39 +01:00
|
|
|
bool isSelected (std::size_t);
|
|
|
|
bool isSelected (listBoxItems::iterator) const;
|
|
|
|
bool isMultiSelection() const;
|
|
|
|
bool hasBrackets (std::size_t);
|
|
|
|
bool hasBrackets (listBoxItems::iterator) const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2019-08-06 23:45:28 +02:00
|
|
|
void hide() override;
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Iterator, typename InsertConverter>
|
2018-12-31 06:18:39 +01:00
|
|
|
void insert (Iterator, Iterator, InsertConverter);
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Container, typename LazyConverter>
|
2018-12-31 06:18:39 +01:00
|
|
|
void insert (Container, LazyConverter);
|
|
|
|
void insert (FListBoxItem);
|
2019-01-05 22:58:06 +01:00
|
|
|
template <typename T>
|
|
|
|
void insert ( const std::initializer_list<T>& list
|
|
|
|
, fc::brackets_type = fc::NoBrackets
|
|
|
|
, bool = false
|
|
|
|
, FDataPtr = nullptr );
|
2018-12-28 22:57:43 +01:00
|
|
|
template <typename ItemT>
|
2018-12-31 06:18:39 +01:00
|
|
|
void insert ( const ItemT&
|
|
|
|
, fc::brackets_type = fc::NoBrackets
|
|
|
|
, bool = false
|
|
|
|
, FDataPtr = nullptr );
|
|
|
|
void remove (std::size_t);
|
2019-04-27 00:38:15 +02:00
|
|
|
void reserve (std::size_t);
|
2018-12-31 06:18:39 +01:00
|
|
|
void clear();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onKeyPress (FKeyEvent*) override;
|
|
|
|
void onMouseDown (FMouseEvent*) override;
|
|
|
|
void onMouseUp (FMouseEvent*) override;
|
|
|
|
void onMouseMove (FMouseEvent*) override;
|
|
|
|
void onMouseDoubleClick (FMouseEvent*) override;
|
|
|
|
void onWheel (FWheelEvent*) override;
|
|
|
|
void onTimer (FTimerEvent*) override;
|
|
|
|
void onFocusIn (FFocusEvent*) override;
|
|
|
|
void onFocusOut (FFocusEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void adjustYOffset (std::size_t);
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
2019-10-05 23:20:07 +02:00
|
|
|
// Typedefs
|
|
|
|
typedef std::unordered_map<int, std::function<void()>> keyMap;
|
|
|
|
typedef std::unordered_map<int, std::function<bool()>> keyMapResult;
|
|
|
|
typedef std::function<void(FListBoxItem&, FDataPtr, int)> lazyInsert;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Enumeration
|
|
|
|
enum convert_type
|
|
|
|
{
|
|
|
|
no_convert = 0,
|
|
|
|
direct_convert = 1,
|
|
|
|
lazy_convert = 2
|
|
|
|
};
|
|
|
|
|
|
|
|
// Accessors
|
2018-12-31 06:18:39 +01:00
|
|
|
static FString& getString (listBoxItems::iterator);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
// Inquiry
|
|
|
|
bool isHorizontallyScrollable();
|
|
|
|
bool isVerticallyScrollable();
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void init();
|
2019-10-05 23:20:07 +02:00
|
|
|
void mapKeyFunctions();
|
|
|
|
void processKeyAction (FKeyEvent*);
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2019-08-11 20:07:39 +02:00
|
|
|
void drawBorder() override;
|
2019-08-11 18:15:57 +02:00
|
|
|
void drawScrollbars();
|
2018-12-31 06:18:39 +01:00
|
|
|
void drawHeadline();
|
|
|
|
void drawList();
|
|
|
|
void drawListLine (int, listBoxItems::iterator, bool);
|
|
|
|
void printLeftBracket (fc::brackets_type);
|
|
|
|
void printRightBracket (fc::brackets_type);
|
|
|
|
void drawListBracketsLine (int, listBoxItems::iterator, bool);
|
|
|
|
void setLineAttributes (int, bool, bool, bool&);
|
|
|
|
void unsetAttributes();
|
|
|
|
void updateDrawing (bool, bool);
|
|
|
|
void recalculateHorizontalBar (std::size_t, bool);
|
|
|
|
void recalculateVerticalBar (std::size_t);
|
|
|
|
void getWidgetFocus();
|
|
|
|
void multiSelection (std::size_t);
|
|
|
|
void multiSelectionUpTo (std::size_t);
|
|
|
|
void wheelUp (int);
|
|
|
|
void wheelDown (int);
|
|
|
|
bool dragScrollUp();
|
|
|
|
bool dragScrollDown();
|
|
|
|
void dragUp (int);
|
|
|
|
void dragDown (int);
|
|
|
|
void stopDragScroll();
|
|
|
|
void prevListItem (int);
|
|
|
|
void nextListItem (int);
|
|
|
|
void scrollToX (int);
|
|
|
|
void scrollToY (int);
|
|
|
|
void scrollLeft (int);
|
|
|
|
void scrollRight (int);
|
2019-09-28 03:13:06 +02:00
|
|
|
void scrollLeft();
|
|
|
|
void scrollRight();
|
|
|
|
void onePosUp();
|
|
|
|
void onePosDown();
|
|
|
|
void onePageUp();
|
|
|
|
void onePageDown();
|
|
|
|
void firstPos();
|
|
|
|
void lastPos();
|
|
|
|
bool skipIncrementalSearch();
|
|
|
|
void acceptSelection();
|
|
|
|
bool spacebarProcessing();
|
|
|
|
bool changeSelectionAndPosition();
|
|
|
|
bool deletePreviousCharacter();
|
2018-12-31 06:18:39 +01:00
|
|
|
bool keyIncSearchInput (FKey);
|
|
|
|
void processClick();
|
|
|
|
void processSelect();
|
|
|
|
void processChanged();
|
|
|
|
void lazyConvert (listBoxItems::iterator, int);
|
2018-10-14 06:25:33 +02:00
|
|
|
listBoxItems::iterator index2iterator (std::size_t);
|
2019-12-16 11:14:24 +01:00
|
|
|
listBoxItems::const_iterator index2iterator (std::size_t index) const;
|
2017-09-11 03:06:02 +02:00
|
|
|
// Callback methods
|
2018-12-31 06:18:39 +01:00
|
|
|
void cb_VBarChange (FWidget*, FDataPtr);
|
|
|
|
void cb_HBarChange (FWidget*, FDataPtr);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Function Pointer
|
2019-10-05 23:20:07 +02:00
|
|
|
lazyInsert lazy_inserter{};
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-31 06:18:39 +01:00
|
|
|
listBoxItems itemlist{};
|
|
|
|
FDataPtr source_container{nullptr};
|
|
|
|
FScrollbarPtr vbar{nullptr};
|
|
|
|
FScrollbarPtr hbar{nullptr};
|
|
|
|
FString text{};
|
|
|
|
FString inc_search{};
|
2019-10-05 23:20:07 +02:00
|
|
|
keyMap key_map{};
|
|
|
|
keyMapResult key_map_result{};
|
2019-09-08 02:04:24 +02:00
|
|
|
convert_type conv_type{FListBox::no_convert};
|
2018-12-31 06:18:39 +01:00
|
|
|
fc::dragScroll drag_scroll{fc::noScroll};
|
|
|
|
int scroll_repeat{100};
|
|
|
|
int scroll_distance{1};
|
|
|
|
int last_current{-1};
|
|
|
|
int secect_from_item{-1};
|
|
|
|
int xoffset{0};
|
|
|
|
int yoffset{0};
|
|
|
|
int last_yoffset{-1};
|
2019-09-08 02:04:24 +02:00
|
|
|
std::size_t current{0};
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t nf_offset{0};
|
|
|
|
std::size_t max_line_width{0};
|
2019-09-08 02:04:24 +02:00
|
|
|
bool multi_select{false};
|
|
|
|
bool mouse_select{false};
|
|
|
|
bool scroll_timer{false};
|
2019-12-16 11:14:24 +01:00
|
|
|
bool click_on_list{false};
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// FListBox inline functions
|
2017-04-23 18:54:46 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Iterator, typename InsertConverter>
|
2017-04-23 18:54:46 +02:00
|
|
|
inline FListBox::FListBox ( Iterator first
|
|
|
|
, Iterator last
|
|
|
|
, InsertConverter convert
|
|
|
|
, FWidget* parent )
|
|
|
|
: FWidget(parent)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
|
|
|
|
while ( first != last )
|
|
|
|
{
|
|
|
|
insert(convert(first), fc::NoBrackets, false, &(*first));
|
|
|
|
++first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 22:47:13 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Container, typename LazyConverter>
|
2017-05-19 22:47:13 +02:00
|
|
|
inline FListBox::FListBox ( Container container
|
|
|
|
, LazyConverter convert
|
|
|
|
, FWidget* parent )
|
|
|
|
: FWidget(parent)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
insert (container, convert);
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FListBox::getClassName() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return "FListBox"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FListBox::getCount() const
|
|
|
|
{ return itemlist.size(); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-12-16 11:14:24 +01:00
|
|
|
inline FListBoxItem& FListBox::getItem (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
|
|
|
listBoxItems::iterator iter = index2iterator(index - 1);
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2019-12-16 11:14:24 +01:00
|
|
|
inline const FListBoxItem& FListBox::getItem (std::size_t index) const
|
|
|
|
{
|
|
|
|
listBoxItems::const_iterator iter = index2iterator(index - 1);
|
|
|
|
return *iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FListBoxItem& FListBox::getItem (listBoxItems::iterator iter)
|
|
|
|
{ return *iter; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline const FListBoxItem& FListBox::getItem (listBoxItems::const_iterator iter) const
|
2017-04-23 18:54:46 +02:00
|
|
|
{ return *iter; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FListBox::currentItem() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return current; }
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FString& FListBox::getText()
|
|
|
|
{ return text; }
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline void FListBox::selectItem (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{ index2iterator(index - 1)->selected = true; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::selectItem (listBoxItems::iterator iter)
|
|
|
|
{ iter->selected = true; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline void FListBox::unselectItem (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{ index2iterator(index - 1)->selected = false; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::unselectItem (listBoxItems::iterator iter)
|
|
|
|
{ iter->selected = false; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline void FListBox::showNoBrackets (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{ index2iterator(index - 1)->brackets = fc::NoBrackets; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-04-23 18:54:46 +02:00
|
|
|
inline void FListBox::showNoBrackets (listBoxItems::iterator iter)
|
|
|
|
{ iter->brackets = fc::NoBrackets; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-12-22 23:50:10 +01:00
|
|
|
inline void FListBox::setMultiSelection (bool enable)
|
|
|
|
{ multi_select = enable; }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::setMultiSelection()
|
|
|
|
{ setMultiSelection(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::unsetMultiSelection()
|
|
|
|
{ setMultiSelection(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::setDisable()
|
|
|
|
{ return setEnable(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline bool FListBox::isSelected (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{ return index2iterator(index - 1)->selected; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::isSelected (listBoxItems::iterator iter) const
|
|
|
|
{ return iter->selected; }
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::isMultiSelection() const
|
|
|
|
{ return multi_select; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline bool FListBox::hasBrackets(std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{ return bool(index2iterator(index - 1)->brackets > 0); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::hasBrackets(listBoxItems::iterator iter) const
|
|
|
|
{ return bool(iter->brackets > 0); }
|
|
|
|
|
2019-04-27 00:38:15 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FListBox::reserve (std::size_t new_cap)
|
|
|
|
{ itemlist.reserve(new_cap); }
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Iterator, typename InsertConverter>
|
2017-04-23 18:54:46 +02:00
|
|
|
inline void FListBox::insert ( Iterator first
|
|
|
|
, Iterator last
|
|
|
|
, InsertConverter convert )
|
|
|
|
{
|
2017-05-19 22:16:50 +02:00
|
|
|
conv_type = direct_convert;
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
while ( first != last )
|
|
|
|
{
|
|
|
|
insert (convert(first), fc::NoBrackets, false, &(*first));
|
|
|
|
++first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 22:16:50 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-20 22:50:35 +02:00
|
|
|
template <typename Container, typename LazyConverter>
|
2017-05-19 22:16:50 +02:00
|
|
|
void FListBox::insert (Container container, LazyConverter convert)
|
|
|
|
{
|
|
|
|
conv_type = lazy_convert;
|
|
|
|
source_container = container;
|
2019-10-05 23:20:07 +02:00
|
|
|
lazy_inserter = convert;
|
2018-01-05 00:49:00 +01:00
|
|
|
std::size_t size = container->size();
|
2017-05-19 22:16:50 +02:00
|
|
|
|
|
|
|
if ( size > 0 )
|
2017-09-15 01:31:02 +02:00
|
|
|
itemlist.resize(size);
|
2017-05-20 22:43:55 +02:00
|
|
|
|
2018-10-20 22:50:35 +02:00
|
|
|
recalculateVerticalBar(size);
|
2017-05-19 22:16:50 +02:00
|
|
|
}
|
|
|
|
|
2019-01-05 22:58:06 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename T>
|
|
|
|
void FListBox::insert ( const std::initializer_list<T>& list
|
|
|
|
, fc::brackets_type b
|
|
|
|
, bool s
|
|
|
|
, FDataPtr d )
|
|
|
|
{
|
|
|
|
for (auto& item : list)
|
|
|
|
{
|
|
|
|
FListBoxItem listItem (FString() << item, d);
|
|
|
|
listItem.brackets = b;
|
|
|
|
listItem.selected = s;
|
|
|
|
insert (listItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-28 22:57:43 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename ItemT>
|
|
|
|
void FListBox::insert ( const ItemT& item
|
|
|
|
, fc::brackets_type b
|
|
|
|
, bool s
|
|
|
|
, FDataPtr d )
|
|
|
|
{
|
|
|
|
FListBoxItem listItem (FString() << item, d);
|
|
|
|
listItem.brackets = b;
|
|
|
|
listItem.selected = s;
|
|
|
|
insert (listItem);
|
|
|
|
}
|
|
|
|
|
2019-01-09 20:05:29 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::isHorizontallyScrollable()
|
2019-09-09 19:13:38 +02:00
|
|
|
{ return bool( max_line_width + 1 >= getClientWidth() ); }
|
2019-01-09 20:05:29 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FListBox::isVerticallyScrollable()
|
|
|
|
{ return bool( getCount() > getClientHeight() ); }
|
|
|
|
|
2017-04-23 18:54:46 +02:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-24 00:16:45 +02:00
|
|
|
inline FListBox::listBoxItems::iterator \
|
|
|
|
FListBox::index2iterator (std::size_t index)
|
2017-04-23 18:54:46 +02:00
|
|
|
{
|
2017-09-15 01:31:02 +02:00
|
|
|
listBoxItems::iterator iter = itemlist.begin();
|
2017-04-23 18:54:46 +02:00
|
|
|
std::advance (iter, index);
|
|
|
|
return iter;
|
|
|
|
}
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FListBox::listBoxItems::const_iterator \
|
|
|
|
FListBox::index2iterator (std::size_t index) const
|
|
|
|
{
|
|
|
|
listBoxItems::const_iterator iter = itemlist.begin();
|
|
|
|
std::advance (iter, index);
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FLISTBOX_H
|