From 019b920a3fc13b1ddda0577c2ec90b512d9a1ca3 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Fri, 10 Apr 2026 04:11:30 +0300
Subject: tdeui/kcharselect: better event handling

KCharSelectTable: Use content/viewport*Event handlers provided by
TQScrollView instead of directly overriding basic TQWidget's event
handlers. This way we won't be off by a few pixels of frame/margin.

Also a funcional change: if mouse will be pressed/released outside of
the table the event will be ignored (i.e passed to parent) and no
signals will be sent. e.g in kcharselect program no symbol will be added
to the output field.

Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 tdeui/kcharselect.cpp | 53 +++++++++++++++++++++++++++++++++++++++++++++------
 tdeui/kcharselect.h   | 19 +++++++++++++-----
 2 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/tdeui/kcharselect.cpp b/tdeui/kcharselect.cpp
index 09c478594..da72c02bb 100644
--- a/tdeui/kcharselect.cpp
+++ b/tdeui/kcharselect.cpp
@@ -197,15 +197,24 @@ TQSize KCharSelectTable::sizeHint() const
 }
 
 //==================================================================
-void KCharSelectTable::resizeEvent( TQResizeEvent * e )
+// BCI: remove me
+void KCharSelectTable::resizeEvent( TQResizeEvent *e )
 {
-    const int new_w   = (e->size().width()  - 2*(margin()+frameWidth())) / numCols();
-    const int new_h   = (e->size().height() - 2*(margin()+frameWidth())) / numRows();
+    TQGridView::resizeEvent(e);
+}
+
+//==================================================================
+void KCharSelectTable::viewportResizeEvent( TQResizeEvent * e )
+{
+    const int new_w   = e->size().width()  / numCols();
+    const int new_h   = e->size().height() / numRows();
 
     if( new_w !=  cellWidth())
         setCellWidth( new_w );
     if( new_h !=  cellHeight())
         setCellHeight( new_h );
+
+    TQGridView::viewportResizeEvent(e);
 }
 
 //==================================================================
@@ -266,11 +275,39 @@ void KCharSelectTable::paintCell( class TQPainter* p, int row, int col )
 }
 
 //==================================================================
+// BCI: remove me
 void KCharSelectTable::mouseMoveEvent( TQMouseEvent *e )
 {
-    // TODO: instead of handling our events we should handle content/viewport events by
-    // reimplementing content*Event functions from TQScrollView. Otherwise we will be off by
-    // at lest the size of frame/margin                         // <2026-04-08 Fat-Zer>
+    TQGridView::mouseMoveEvent(e);
+}
+
+//==================================================================
+void KCharSelectTable::contentsMousePressEvent( TQMouseEvent *e )
+{
+    contentsMouseMoveEvent(e);
+}
+
+//==================================================================
+void KCharSelectTable::contentsMouseDoubleClickEvent ( TQMouseEvent *e )
+{
+    contentsMouseMoveEvent(e);
+    emit doubleClicked();
+}
+
+//==================================================================
+void KCharSelectTable::contentsMouseReleaseEvent( TQMouseEvent *e )
+{
+    contentsMouseMoveEvent( e );
+
+    if( e->isAccepted() ) {
+        emit activated( chr() );
+        emit activated();
+    }
+}
+
+//==================================================================
+void KCharSelectTable::contentsMouseMoveEvent( TQMouseEvent *e )
+{
     const int row = rowAt( e->y() );
     const int col = columnAt( e->x() );
     if ( row >= 0 && row < numRows() && col >= 0 && col < numCols() ) {
@@ -295,6 +332,10 @@ void KCharSelectTable::mouseMoveEvent( TQMouseEvent *e )
 
 	emit focusItemChanged( focusItem );
 	emit focusItemChanged();
+
+        e->accept();
+    } else {
+        e->ignore();
     }
 }
 
diff --git a/tdeui/kcharselect.h b/tdeui/kcharselect.h
index 72245bcb5..db817e8ac 100644
--- a/tdeui/kcharselect.h
+++ b/tdeui/kcharselect.h
@@ -56,12 +56,12 @@ public:
     ~KCharSelectTable();
 
     virtual TQSize sizeHint() const;
-    virtual void resizeEvent( TQResizeEvent * );
+    virtual void resizeEvent( TQResizeEvent * ); //< BCI: remove me
 
     virtual void setFont( const TQString &_font );
     virtual void setChar( const TQChar &_chr );
     virtual void setTableNum( int _tableNum );
-
+    // BCI: add const
     virtual TQChar chr() { return vChr; }
 
     TQString font() const { return vFont; }
@@ -70,13 +70,22 @@ public:
 protected:
     virtual void paintCell( class TQPainter *p, int row, int col );
 
-    virtual void mousePressEvent( TQMouseEvent *e ) {  mouseMoveEvent( e ); }
-    virtual void mouseDoubleClickEvent ( TQMouseEvent *e ){  mouseMoveEvent( e ); emit doubleClicked();}
-    virtual void mouseReleaseEvent( TQMouseEvent *e ) { mouseMoveEvent( e ); emit activated( chr() ); emit activated(); }
+    // BCI: remove non-"contents*" mouse*Event handlers
+    virtual void mousePressEvent( TQMouseEvent *e ) { TQGridView::mousePressEvent(e); }
+    virtual void mouseDoubleClickEvent ( TQMouseEvent *e ){ TQGridView::mouseDoubleClickEvent(e); }
+    virtual void mouseReleaseEvent( TQMouseEvent *e ) { TQGridView::mouseReleaseEvent(e); }
     virtual void mouseMoveEvent( TQMouseEvent *e );
 
     virtual void keyPressEvent( TQKeyEvent *e );
 
+    virtual void viewportResizeEvent( TQResizeEvent *e );
+
+    virtual void contentsMousePressEvent( TQMouseEvent *e );
+    virtual void contentsMouseDoubleClickEvent ( TQMouseEvent *e );
+    virtual void contentsMouseReleaseEvent( TQMouseEvent *e );
+    virtual void contentsMouseMoveEvent( TQMouseEvent *e );
+
+
     void gotoLeft();
     void gotoRight();
     void gotoUp();
-- 
cgit v1.2.3

