1 /*****************************************************************************
2 * selection.cpp - QStarDict, a StarDict clone written with using Qt *
3 * Copyright (C) 2007 Alexander Rodin *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License along *
16 * with this program; if not, write to the Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
18 *****************************************************************************/
20 #include "selection.h"
28 QString currentSelection()
33 char szWindowText[256];
35 if (! GetCursorPos(&Point))
38 if( ! (hWindow = WindowFromPoint(Point)))
41 SendMessage(hWindow, WM_GETTEXT, 256, (LPARAM)szWindowText);
42 SendMessage(hWindow, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
44 return QString::fromLocal8Bit(szWindowText);
51 #include <QApplication>
57 inline QString currentSelection()
58 { return QApplication::clipboard()->text(QClipboard::Selection); }
67 Selection::Selection(QObject *parent)
74 void Selection::setScan(bool scan)
82 m_lastState = currentSelection();
83 m_timerId = startTimer(300);
89 void Selection::timerEvent(QTimerEvent*)
91 if (m_lastState != currentSelection())
93 m_lastState = currentSelection();
94 emit changed(m_lastState);
100 // vim: tabstop=4 softtabstop=4 shiftwidth=4 expandtab cindent textwidth=120 formatoptions=tc