/*
    Copyright (c) 2026 Christian Schoenebeck

    This file is part of "gigedit" and released under the terms of the
    GNU General Public License version 2.
*/

#ifndef GE_TREE_VIEW_H
#define GE_TREE_VIEW_H

#include "compat.h"
#include <gtkmm/treeview.h>

/** @brief Adjust behaviour of stock Gtk::TreeView for Gigedit.
 *
 * Overrides mouse click event handling: fast double click only triggers
 * signal_row_activated() (i.e. custom double-click handlers) instead of
 * starting to edit selected cell. A slow double click OTOH starts editing the
 * cell. Very slow double clicks are entirely ignored (i.e. won't start editing
 * either).
 *
 * Overrides keyboard stroke event handling: Enter and Return only trigger
 * signal_row_activated() custom handlers instead of starting to edit selected
 * cell. Space key OTOH still trigers start of editing.
 */
class GETreeView : public Gtk::TreeView {
    typedef Gtk::TreeView Super;
public:
    using Gtk::TreeView::TreeView; // inherit all constructors

    int getColumnIndex(Gtk::TreeViewColumn* pColumn);
protected:
    bool on_button_press_event(GdkEventButton* event) override;
    bool on_key_press_event(GdkEventKey* event) override;
private:
    guint32 m_latestClickTime = 0;
    Gtk::TreeModel::Path m_latestPath;
    int m_latestColumn = -1;
};

#endif // GE_TREE_VIEW_H
