File indexing completed on 2024-04-14 05:39:55

0001 /*****************************************************************************
0002  *   Copyright 2003 - 2010 Craig Drummond <craig.p.drummond@gmail.com>       *
0003  *   Copyright 2013 - 2015 Yichao Yu <yyc1992@gmail.com>                     *
0004  *                                                                           *
0005  *   This program is free software; you can redistribute it and/or modify    *
0006  *   it under the terms of the GNU Lesser General Public License as          *
0007  *   published by the Free Software Foundation; either version 2.1 of the    *
0008  *   License, or (at your option) version 3, or any later version accepted   *
0009  *   by the membership of KDE e.V. (or its successor approved by the         *
0010  *   membership of KDE e.V.), which shall act as a proxy defined in          *
0011  *   Section 6 of version 3 of the license.                                  *
0012  *                                                                           *
0013  *   This program is distributed in the hope that it will be useful,         *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       *
0016  *   Lesser General Public License for more details.                         *
0017  *                                                                           *
0018  *   You should have received a copy of the GNU Lesser General Public        *
0019  *   License along with this library. If not,                                *
0020  *   see <http://www.gnu.org/licenses/>.                                     *
0021  *****************************************************************************/
0022 
0023 #include "entry.h"
0024 
0025 #include <qtcurve-utils/gtkprops.h>
0026 
0027 namespace QtCurve {
0028 namespace Entry {
0029 
0030 static GtkWidget *lastMo = nullptr;
0031 
0032 static void
0033 cleanup(GtkWidget *widget)
0034 {
0035     if (lastMo == widget) {
0036         lastMo = nullptr;
0037     }
0038     if (GTK_IS_ENTRY(widget)) {
0039         GtkWidgetProps props(widget);
0040         props->entryEnter.disconn();
0041         props->entryLeave.disconn();
0042         props->entryDestroy.disconn();
0043         props->entryUnrealize.disconn();
0044         props->entryStyleSet.disconn();
0045         props->entryHacked = false;
0046     }
0047 }
0048 
0049 static gboolean
0050 styleSet(GtkWidget *widget, GtkStyle*, void*)
0051 {
0052     cleanup(widget);
0053     return false;
0054 }
0055 
0056 static gboolean
0057 destroy(GtkWidget *widget, GdkEvent*, void*)
0058 {
0059     cleanup(widget);
0060     return false;
0061 }
0062 
0063 static gboolean
0064 enter(GtkWidget *widget, GdkEventCrossing*, void*)
0065 {
0066     if (GTK_IS_ENTRY(widget)) {
0067         lastMo = widget;
0068         gtk_widget_queue_draw(widget);
0069     }
0070     return false;
0071 }
0072 
0073 static gboolean
0074 leave(GtkWidget *widget, GdkEventCrossing*, void*)
0075 {
0076     if (GTK_IS_ENTRY(widget)) {
0077         lastMo = nullptr;
0078         gtk_widget_queue_draw(widget);
0079     }
0080     return false;
0081 }
0082 
0083 bool
0084 isLastMo(GtkWidget *widget)
0085 {
0086     return lastMo && widget == lastMo;
0087 }
0088 
0089 void
0090 setup(GtkWidget *widget)
0091 {
0092     GtkWidgetProps props(widget);
0093     if (GTK_IS_ENTRY(widget) && !props->entryHacked) {
0094         props->entryHacked = true;
0095         props->entryEnter.conn("enter-notify-event", enter);
0096         props->entryLeave.conn("leave-notify-event", leave);
0097         props->entryDestroy.conn("destroy-event", destroy);
0098         props->entryUnrealize.conn("unrealize", destroy);
0099         props->entryStyleSet.conn("style-set", styleSet);
0100     }
0101 }
0102 
0103 }
0104 }