2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* fscrollview.h - Widget FScrollView (a scrolling area with on-demand *
|
|
|
|
* scroll bars) *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-01-20 21:40:00 +01:00
|
|
|
* Copyright 2017-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* 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 *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* 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-01-02 08:07:46 +01:00
|
|
|
|
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 ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▏
|
|
|
|
* ▲
|
|
|
|
* │
|
|
|
|
* ▕▔▔▔▔▔▔▔▔▔▔▔▔▔▏
|
|
|
|
* ▕ FScrollView ▏
|
|
|
|
* ▕▁▁▁▁▁▁▁▁▁▁▁▁▁▏
|
|
|
|
*/
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#ifndef FSCROLLVIEW_H
|
|
|
|
#define FSCROLLVIEW_H
|
2017-01-02 08:07:46 +01: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>
|
2018-12-28 22:57:43 +01:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fscrollbar.h"
|
|
|
|
#include "final/fwidget.h"
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FScrollView
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
class FScrollView : public FWidget
|
|
|
|
{
|
2017-09-11 03:06:02 +02:00
|
|
|
public:
|
|
|
|
// Using-declaration
|
|
|
|
using FWidget::setGeometry;
|
2019-08-18 21:36:10 +02:00
|
|
|
using FWidget::print;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Constructor
|
2018-12-10 01:48:26 +01:00
|
|
|
explicit FScrollView (FWidget* = nullptr);
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2018-12-09 22:04:55 +01:00
|
|
|
// Disable copy constructor
|
|
|
|
FScrollView (const FScrollView&) = delete;
|
2018-12-24 18:11:16 +01:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Destructor
|
2020-02-19 21:59:13 +01:00
|
|
|
~FScrollView() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2020-04-15 23:44:08 +02:00
|
|
|
// Disable copy assignment operator (=)
|
2018-12-09 22:04:55 +01:00
|
|
|
FScrollView& operator = (const FScrollView&) = delete;
|
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Accessors
|
2020-10-04 00:59:21 +02:00
|
|
|
FString getClassName() const override;
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t getViewportWidth() const;
|
|
|
|
std::size_t getViewportHeight() const;
|
2020-10-04 00:59:21 +02:00
|
|
|
FSize getViewportSize() const;
|
2018-12-31 06:18:39 +01:00
|
|
|
std::size_t getScrollWidth() const;
|
|
|
|
std::size_t getScrollHeight() const;
|
2020-10-04 00:59:21 +02:00
|
|
|
FSize getScrollSize() const;
|
|
|
|
FPoint getScrollPos() const;
|
2018-12-31 06:18:39 +01:00
|
|
|
int getScrollX() const;
|
|
|
|
int getScrollY() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Mutator
|
2018-12-31 06:18:39 +01:00
|
|
|
virtual void setScrollWidth (std::size_t);
|
|
|
|
virtual void setScrollHeight (std::size_t);
|
2019-01-21 03:42:18 +01:00
|
|
|
virtual void setScrollSize (const FSize&);
|
2019-08-06 23:45:28 +02:00
|
|
|
void setX (int, bool = true) override;
|
|
|
|
void setY (int, bool = true) override;
|
|
|
|
void setPos (const FPoint&, bool = true) override;
|
|
|
|
void setWidth (std::size_t, bool = true) override;
|
|
|
|
void setHeight (std::size_t, bool = true) override;
|
|
|
|
void setSize (const FSize&, bool = true) override;
|
|
|
|
void setGeometry ( const FPoint&, const FSize&
|
2018-12-31 06:18:39 +01:00
|
|
|
, bool = true ) override;
|
2020-04-18 13:33:42 +02:00
|
|
|
bool setCursorPos (const FPoint&) override;
|
|
|
|
void setPrintPos (const FPoint&) override;
|
2018-12-31 06:18:39 +01:00
|
|
|
bool setViewportPrint (bool);
|
|
|
|
bool setViewportPrint();
|
|
|
|
bool unsetViewportPrint();
|
2020-05-30 23:27:42 +02:00
|
|
|
void resetColors() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
bool setBorder (bool);
|
|
|
|
bool setBorder();
|
|
|
|
bool unsetBorder();
|
|
|
|
void setHorizontalScrollBarMode (fc::scrollBarMode);
|
|
|
|
void setVerticalScrollBarMode (fc::scrollBarMode);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Inquiries
|
2020-05-02 00:07:35 +02:00
|
|
|
bool hasBorder() const;
|
|
|
|
bool isViewportPrint() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
// Methods
|
2019-08-06 23:45:28 +02:00
|
|
|
void clearArea (int = ' ') override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void scrollToX (int);
|
|
|
|
void scrollToY (int);
|
|
|
|
void scrollTo (const FPoint&);
|
|
|
|
void scrollTo (int, int);
|
|
|
|
void scrollBy (int, int);
|
2019-08-18 21:36:10 +02:00
|
|
|
void print (const FPoint&) override;
|
2019-08-06 23:45:28 +02:00
|
|
|
void draw() override;
|
2019-08-11 20:07:39 +02:00
|
|
|
void drawBorder() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Event handlers
|
2019-08-06 23:45:28 +02:00
|
|
|
void onKeyPress (FKeyEvent*) override;
|
|
|
|
void onWheel (FWheelEvent*) override;
|
|
|
|
void onFocusIn (FFocusEvent*) override;
|
|
|
|
void onChildFocusIn (FFocusEvent*) override;
|
|
|
|
void onChildFocusOut (FFocusEvent*) override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
// Using-declaration
|
|
|
|
using FVTerm::clearArea;
|
|
|
|
|
|
|
|
// Accessor
|
2019-10-08 04:37:19 +02:00
|
|
|
FTermArea* getPrintArea() override;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-10-06 22:35:00 +02:00
|
|
|
// Methods
|
2019-08-06 23:45:28 +02:00
|
|
|
void adjustSize() override;
|
2018-12-31 06:18:39 +01:00
|
|
|
void copy2area();
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
private:
|
2019-10-05 23:20:07 +02:00
|
|
|
// Typedefs
|
2020-10-08 05:55:32 +02:00
|
|
|
typedef std::unordered_map<int, std::function<void()>> KeyMap;
|
2019-10-05 23:20:07 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
// Constants
|
2018-12-26 23:41:49 +01:00
|
|
|
static constexpr int vertical_border_spacing = 2;
|
|
|
|
static constexpr int horizontal_border_spacing = 2;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Accessors
|
2020-10-04 02:55:15 +02:00
|
|
|
FPoint getViewportCursorPos() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Methods
|
2020-07-06 19:32:01 +02:00
|
|
|
void init();
|
2019-10-05 23:20:07 +02:00
|
|
|
void mapKeyFunctions();
|
2020-07-12 15:25:21 +02:00
|
|
|
void calculateScrollbarPos() const;
|
2020-09-18 17:13:52 +02:00
|
|
|
template <typename Callback>
|
2019-01-16 16:00:15 +01:00
|
|
|
void initScrollbar ( FScrollbarPtr&
|
|
|
|
, fc::orientation
|
2019-10-01 23:14:00 +02:00
|
|
|
, Callback );
|
2020-07-12 15:25:21 +02:00
|
|
|
void setHorizontalScrollBarVisibility() const;
|
|
|
|
void setVerticalScrollBarVisibility() const;
|
2020-07-12 17:00:16 +02:00
|
|
|
void setViewportCursor() const;
|
2017-09-11 03:06:02 +02:00
|
|
|
|
|
|
|
// Callback methods
|
2020-08-13 23:58:32 +02:00
|
|
|
void cb_vbarChange (const FWidget*);
|
|
|
|
void cb_hbarChange (const FWidget*);
|
2017-09-11 03:06:02 +02:00
|
|
|
|
2019-09-04 23:57:31 +02:00
|
|
|
// Data members
|
2019-10-05 23:20:07 +02:00
|
|
|
FRect scroll_geometry{1, 1, 1, 1};
|
|
|
|
FRect viewport_geometry{};
|
2019-10-08 04:37:19 +02:00
|
|
|
FTermArea* viewport{nullptr}; // virtual scroll content
|
2019-10-05 23:20:07 +02:00
|
|
|
FScrollbarPtr vbar{nullptr};
|
|
|
|
FScrollbarPtr hbar{nullptr};
|
2020-10-08 05:55:32 +02:00
|
|
|
KeyMap key_map{};
|
2019-10-05 23:20:07 +02:00
|
|
|
uInt8 nf_offset{0};
|
|
|
|
bool use_own_print_area{false};
|
|
|
|
bool update_scrollbar{true};
|
2020-03-22 21:53:27 +01:00
|
|
|
fc::scrollBarMode v_mode{fc::Auto}; // fc:Auto, fc::Hidden or fc::Scroll
|
|
|
|
fc::scrollBarMode h_mode{fc::Auto};
|
2017-01-02 08:07:46 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// FScrollView inline functions
|
|
|
|
//----------------------------------------------------------------------
|
2020-10-04 00:59:21 +02:00
|
|
|
inline FString FScrollView::getClassName() const
|
2017-01-02 08:07:46 +01:00
|
|
|
{ return "FScrollView"; }
|
|
|
|
|
2017-01-22 23:04:40 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FScrollView::getViewportWidth() const
|
|
|
|
{ return getWidth() - vertical_border_spacing - std::size_t(nf_offset); }
|
2017-01-22 23:04:40 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FScrollView::getViewportHeight() const
|
2017-01-22 23:04:40 +01:00
|
|
|
{ return getHeight() - horizontal_border_spacing; }
|
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-10-04 00:59:21 +02:00
|
|
|
inline FSize FScrollView::getViewportSize() const
|
2019-01-21 03:42:18 +01:00
|
|
|
{ return FSize(getViewportWidth(), getViewportHeight()); }
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FScrollView::getScrollWidth() const
|
2017-01-26 00:31:07 +01:00
|
|
|
{ return scroll_geometry.getWidth(); }
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2018-10-14 06:25:33 +02:00
|
|
|
inline std::size_t FScrollView::getScrollHeight() const
|
2017-01-26 00:31:07 +01:00
|
|
|
{ return scroll_geometry.getHeight(); }
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2019-01-21 03:42:18 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-10-04 00:59:21 +02:00
|
|
|
inline FSize FScrollView::getScrollSize() const
|
2019-01-21 03:42:18 +01:00
|
|
|
{ return scroll_geometry.getSize(); }
|
|
|
|
|
2017-01-02 08:07:46 +01:00
|
|
|
//----------------------------------------------------------------------
|
2020-10-04 00:59:21 +02:00
|
|
|
inline FPoint FScrollView::getScrollPos() const
|
2017-01-26 00:31:07 +01:00
|
|
|
{ return viewport_geometry.getPos(); }
|
2017-01-02 08:07:46 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2017-01-07 22:09:09 +01:00
|
|
|
inline int FScrollView::getScrollX() const
|
2017-01-26 00:31:07 +01:00
|
|
|
{ return viewport_geometry.getX(); }
|
2017-01-07 22:09:09 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline int FScrollView::getScrollY() const
|
2017-01-26 00:31:07 +01:00
|
|
|
{ return viewport_geometry.getY(); }
|
2017-01-07 22:09:09 +01:00
|
|
|
|
2017-02-18 23:37:10 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FScrollView::setViewportPrint()
|
|
|
|
{ return setViewportPrint(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FScrollView::unsetViewportPrint()
|
|
|
|
{ return setViewportPrint(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FScrollView::setBorder()
|
|
|
|
{ return setBorder(true); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline bool FScrollView::unsetBorder()
|
|
|
|
{ return setBorder(false); }
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FScrollView::hasBorder() const
|
|
|
|
{ return ! getFlags().no_border; }
|
2017-02-18 23:37:10 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2020-05-02 00:07:35 +02:00
|
|
|
inline bool FScrollView::isViewportPrint() const
|
2017-02-18 23:37:10 +01:00
|
|
|
{ return ! use_own_print_area; }
|
|
|
|
|
2017-01-07 22:09:09 +01:00
|
|
|
//----------------------------------------------------------------------
|
2017-08-12 20:10:27 +02:00
|
|
|
inline void FScrollView::scrollTo (const FPoint& pos)
|
2017-01-07 22:09:09 +01:00
|
|
|
{ scrollTo(pos.getX(), pos.getY()); }
|
|
|
|
|
2019-08-18 21:36:10 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
inline void FScrollView::print (const FPoint& pos)
|
|
|
|
{
|
|
|
|
if ( use_own_print_area )
|
|
|
|
FWidget::setPrintPos(pos);
|
|
|
|
else
|
|
|
|
setPrintPos(pos);
|
|
|
|
}
|
|
|
|
|
2019-10-01 23:14:00 +02:00
|
|
|
//----------------------------------------------------------------------
|
2020-09-18 17:13:52 +02:00
|
|
|
template <typename Callback>
|
2019-10-01 23:14:00 +02:00
|
|
|
inline void FScrollView::initScrollbar ( FScrollbarPtr& bar
|
|
|
|
, fc::orientation o
|
|
|
|
, Callback cb_handler )
|
|
|
|
{
|
|
|
|
finalcut::initScrollbar (bar, o, this, cb_handler);
|
2019-10-08 04:37:19 +02:00
|
|
|
FTermArea* area = getPrintArea();
|
2019-10-01 23:14:00 +02:00
|
|
|
bar->setPrintArea(area);
|
|
|
|
}
|
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
} // namespace finalcut
|
2017-01-02 08:07:46 +01:00
|
|
|
|
2017-04-09 20:08:53 +02:00
|
|
|
#endif // FSCROLLVIEW_H
|