2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ftextview.h - Widget FTextView (a multiline text viewer) *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-01-20 21:40:00 +01:00
|
|
|
* Copyright 2014-2020 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
|
|
|
* ▕ FVTerm ▏ ▕ FObject ▏
|
2017-10-02 07:32:33 +02:00
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏ ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲ ▲
|
|
|
|
* │ │
|
|
|
|
* └─────┬─────┘
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FWidget ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FTextView ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FTEXTVIEW_H
|
|
|
|
#define FTEXTVIEW_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 <string>
|
|
|
|
#include <unordered_map>
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fwidget.h"
|
2015-05-23 13:35:12 +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 FString;
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FTextView
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FTextView : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declarations
|
|
|
|
using FWidget::setGeometry;
|
|
|
|
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FTextView (FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FTextView (const FTextView&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2018-09-24 04:02:35 +02:00
|
|
|
virtual ~FTextView();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable assignment operator (=)
|
|
|
|
FTextView& operator = (const FTextView&) = delete;
|
|
|
|
|
2019-09-29 22:28:58 +02:00
|
|
|
// Overloaded operators
|
|
|
|
FTextView& operator = (const FString&);
|
|
|
|
template <typename typeT>
|
|
|
|
FTextView& operator << (const typeT&);
|
|
|
|
FTextView& operator << (fc::SpecialCharacter);
|
|
|
|
FTextView& operator << (const std::string&);
|
|
|
|
|
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 getColumns() const;
|
|
|
|
std::size_t getRows() const;
|
|
|
|
const FString getText() const;
|
|
|
|
const FStringList& getLines() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutators
|
2019-12-23 03:53:32 +01:00
|
|
|
void setSize (const FSize&, bool = true) override;
|
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 setText (const FString&);
|
|
|
|
void scrollToX (int);
|
|
|
|
void scrollToY (int);
|
|
|
|
void scrollTo (const FPoint&);
|
|
|
|
void scrollTo (int, int);
|
|
|
|
void scrollBy (int, int);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2019-08-06 23:45:28 +02:00
|
|
|
void hide() override;
|
2019-01-05 22:58:06 +01:00
|
|
|
template<typename T>
|
|
|
|
void append (const std::initializer_list<T>&);
|
2018-12-31 06:18:39 +01:00
|
|
|
void append (const FString&);
|
2019-01-05 22:58:06 +01:00
|
|
|
template<typename T>
|
|
|
|
void insert (const std::initializer_list<T>&, int);
|
2018-12-31 06:18:39 +01:00
|
|
|
void insert (const FString&, int);
|
|
|
|
void replaceRange (const FString&, int, int);
|
|
|
|
void deleteRange (int, int);
|
|
|
|
void deleteLine (int);
|
|
|
|
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 onWheel (FWheelEvent*) override;
|
|
|
|
void onFocusIn (FFocusEvent*) override;
|
|
|
|
void onFocusOut (FFocusEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Method
|
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;
|
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
// Accessors
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t getTextHeight();
|
|
|
|
std::size_t getTextWidth();
|
2018-02-17 19:12:48 +01:00
|
|
|
|
2018-12-29 19:01:47 +01:00
|
|
|
// Inquiry
|
2018-12-31 06:18:39 +01:00
|
|
|
bool isHorizontallyScrollable();
|
|
|
|
bool isVerticallyScrollable();
|
2018-12-29 19:01:47 +01:00
|
|
|
|
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();
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2019-10-01 23:14:00 +02:00
|
|
|
void drawBorder() override;
|
2019-09-29 22:28:58 +02:00
|
|
|
void drawScrollbars();
|
2018-12-31 06:18:39 +01:00
|
|
|
void drawText();
|
2019-10-01 23:14:00 +02:00
|
|
|
bool useFDialogBorder();
|
2019-09-28 03:13:06 +02:00
|
|
|
bool isPrintable (wchar_t);
|
2018-12-31 06:18:39 +01:00
|
|
|
void processChanged();
|
2019-12-23 03:53:32 +01:00
|
|
|
void changeOnResize();
|
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
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2018-12-03 03:22:36 +01:00
|
|
|
FStringList data{};
|
2018-12-20 01:41:04 +01:00
|
|
|
FScrollbarPtr vbar{nullptr};
|
|
|
|
FScrollbarPtr hbar{nullptr};
|
2019-10-05 23:20:07 +02:00
|
|
|
keyMap key_map{};
|
2018-12-03 03:22:36 +01:00
|
|
|
bool update_scrollbar{true};
|
|
|
|
int xoffset{0};
|
|
|
|
int yoffset{0};
|
|
|
|
int nf_offset{0};
|
|
|
|
std::size_t maxLineWidth{0};
|
2015-05-23 13:35:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// FListBox inline functions
|
2019-09-29 22:28:58 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-14 01:44:24 +02:00
|
|
|
inline FTextView& FTextView::operator = (const FString& s)
|
2019-09-29 22:28:58 +02:00
|
|
|
{
|
|
|
|
setText(s);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template <typename typeT>
|
|
|
|
inline FTextView& FTextView::operator << (const typeT& s)
|
|
|
|
{
|
|
|
|
std::wostringstream outstream;
|
|
|
|
outstream << s;
|
|
|
|
|
|
|
|
if ( ! outstream.str().empty() )
|
|
|
|
append (outstream.str());
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FTextView& FTextView::operator << (fc::SpecialCharacter c)
|
|
|
|
{
|
|
|
|
append (static_cast<wchar_t>(c)); // Required under Solaris
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline FTextView& FTextView::operator << (const std::string& string)
|
|
|
|
{
|
|
|
|
append (string);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2019-10-05 23:20:07 +02:00
|
|
|
inline const FString FTextView::getClassName() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return "FTextView"; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FTextView::getColumns() const
|
2015-05-23 13:35:12 +02:00
|
|
|
{ return maxLineWidth; }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FTextView::getRows() const
|
|
|
|
{ return std::size_t(data.size()); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-09-20 16:56:20 +02:00
|
|
|
inline const FStringList& FTextView::getLines() const
|
2016-11-02 00:37:58 +01:00
|
|
|
{ return data; }
|
|
|
|
|
2018-02-17 19:12:48 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FTextView::scrollTo (const FPoint& pos)
|
|
|
|
{ scrollTo(pos.getX(), pos.getY()); }
|
|
|
|
|
2019-01-05 22:58:06 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template<typename T>
|
|
|
|
void FTextView::append (const std::initializer_list<T>& list)
|
|
|
|
{
|
|
|
|
for (auto& str : list)
|
|
|
|
insert(str, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
template<typename T>
|
|
|
|
void FTextView::insert (const std::initializer_list<T>& list, int pos)
|
|
|
|
{
|
|
|
|
for (auto& str : list)
|
|
|
|
{
|
|
|
|
insert(str, pos);
|
|
|
|
pos++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-23 13:35:12 +02:00
|
|
|
//----------------------------------------------------------------------
|
2017-09-17 01:50:41 +02:00
|
|
|
inline void FTextView::deleteRange (int from, int to)
|
|
|
|
{ replaceRange (FString(), from, to); }
|
2015-05-23 13:35:12 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FTextView::deleteLine (int pos)
|
|
|
|
{ deleteRange (pos, pos); }
|
|
|
|
|
2018-12-29 19:01:47 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FTextView::isHorizontallyScrollable()
|
|
|
|
{ return bool( maxLineWidth > getTextWidth() ); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FTextView::isVerticallyScrollable()
|
|
|
|
{ return bool( getRows() > getTextHeight() ); }
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FTEXTVIEW_H
|