finalcut/src/include/final/ftextview.h

191 lines
6.5 KiB
C
Raw Normal View History

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 *
* *
* Copyright 2014-2018 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/>. *
***********************************************************************/
/* Inheritance diagram
*
*
*
* FTerm
*
*
*
*
* FVTerm FObject
*
*
*
*
*
*
* FWidget
*
*
*
*
* FTextView
*
*/
2015-05-23 13:35:12 +02:00
#ifndef FTEXTVIEW_H
#define FTEXTVIEW_H
2015-05-23 13:35:12 +02:00
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
2017-09-11 03:06:02 +02:00
#include <vector>
#include "final/fapplication.h"
#include "final/fscrollbar.h"
#include "final/fstatusbar.h"
#include "final/fstring.h"
#include "final/fwidget.h"
2015-05-23 13:35:12 +02:00
namespace finalcut
{
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
// class FTextView
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FTextView : public FWidget
{
2017-09-11 03:06:02 +02:00
public:
// Using-declarations
using FWidget::setGeometry;
// Constructor
explicit FTextView (FWidget* = 0);
// Disable copy constructor
FTextView (const FTextView&) = delete;
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
// Disable assignment operator (=)
FTextView& operator = (const FTextView&) = delete;
2017-09-11 03:06:02 +02:00
// Accessors
const char* getClassName() const;
std::size_t getColumns() const;
std::size_t getRows() const;
2017-09-11 03:06:02 +02:00
const FString getText() const;
2017-09-20 16:56:20 +02:00
const FStringList& getLines() const;
2017-09-11 03:06:02 +02:00
// Mutators
2018-10-24 00:16:45 +02:00
virtual void setGeometry ( int, int
, std::size_t, std::size_t
, bool = true );
2017-09-11 03:06:02 +02:00
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
2018-09-24 04:02:35 +02:00
virtual void hide();
2017-09-11 03:06:02 +02:00
void append (const FString&);
void insert (const FString&, int);
void replaceRange (const FString&, int, int);
void deleteRange (int, int);
void deleteLine (int);
void clear();
// Event handlers
2018-09-24 04:02:35 +02:00
virtual void onKeyPress (FKeyEvent*);
virtual void onMouseDown (FMouseEvent*);
virtual void onMouseUp (FMouseEvent*);
virtual void onMouseMove (FMouseEvent*);
virtual void onWheel (FWheelEvent*);
virtual void onFocusIn (FFocusEvent*);
virtual void onFocusOut (FFocusEvent*);
2017-09-11 03:06:02 +02:00
protected:
// Method
2018-09-24 04:02:35 +02:00
virtual void adjustSize();
2017-09-11 03:06:02 +02:00
private:
// Accessors
std::size_t getTextHeight();
std::size_t getTextWidth();
2017-09-11 03:06:02 +02:00
// Methods
2017-09-20 16:56:20 +02:00
void init();
2018-09-24 04:02:35 +02:00
virtual void draw();
2017-09-20 16:56:20 +02:00
void drawText();
void processChanged();
void drawHBar();
void drawVBar();
2017-09-11 03:06:02 +02:00
// Callback methods
2017-09-20 16:56:20 +02:00
void cb_VBarChange (FWidget*, data_ptr);
void cb_HBarChange (FWidget*, data_ptr);
2017-09-11 03:06:02 +02:00
// Data Members
FStringList data{};
FScrollbar* vbar{0};
FScrollbar* hbar{0};
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
};
#pragma pack(pop)
// FListBox inline functions
//----------------------------------------------------------------------
inline const char* FTextView::getClassName() const
{ return "FTextView"; }
//----------------------------------------------------------------------
inline std::size_t FTextView::getColumns() const
2015-05-23 13:35:12 +02:00
{ return maxLineWidth; }
//----------------------------------------------------------------------
inline std::size_t FTextView::getRows() const
{ return std::size_t(data.size()); }
2015-05-23 13:35:12 +02:00
//----------------------------------------------------------------------
2017-09-20 16:56:20 +02:00
inline const FStringList& FTextView::getLines() const
{ return data; }
//----------------------------------------------------------------------
inline void FTextView::scrollTo (const FPoint& pos)
{ scrollTo(pos.getX(), pos.getY()); }
2015-05-23 13:35:12 +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); }
} // namespace finalcut
#endif // FTEXTVIEW_H