]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt2/QWorkArea.C
Get rid of the static_casts.
[lyx.git] / src / frontends / qt2 / QWorkArea.C
index 8cb8dde4dd60a1ccd965c9acbb9604dee2209582..b5971a214ad1f9887acffcdb2f77427b0f5e5dd3 100644 (file)
@@ -1,66 +1,65 @@
 /**
  * \file QWorkArea.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author John Levon <moz@compsoc.man.ac.uk>
+ * \author John Levon
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "debug.h"
 #include "LyXView.h"
-#include "lyxrc.h" // lyxrc.show_banner
 #include "version.h" // lyx_version
 
 #include "support/filetools.h" // LibFileSearch
 #include "support/lstrings.h"
 #include "support/LAssert.h"
 
-#include <cmath>
-#include <cctype>
-
 #include "QWorkArea.h"
+#include "qt_helpers.h"
+#include "lcolorcache.h"
+
 #include <qapplication.h>
-#include <qevent.h> 
+#include <qevent.h>
 #include <qpainter.h>
 #include <qmainwindow.h>
 #include <qlayout.h>
+#include <qclipboard.h>
+
+#ifdef Q_WS_X11
+#include <X11/Xlib.h>
+#endif
+
+#include <cmath>
+#include <cctype>
+
 using std::endl;
 using std::abs;
 using std::hex;
 
+
 QWorkArea::QWorkArea(int, int, int, int)
        : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
 {
-       // Add a splash screen to the centre of the work area
-       string const splash_file = (lyxrc.show_banner) ?
-               LibFileSearch("images", "banner", "xpm") : string();
-
-       if (!splash_file.empty()) {
-               // FIXME
-       }
-
        scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
        content_ = new QContentPane(this);
 
        (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
+
+       setFocusProxy(content_);
+
        content_->show();
 
-       content_->setBackgroundColor(lcolor.getX11Name(LColor::background).c_str());
+       content_->setBackgroundColor(lcolorcache.get(LColor::background));
 
        QHBoxLayout * vl = new QHBoxLayout(this);
        vl->addWidget(content_, 5);
        vl->addWidget(scrollbar_, 0);
+
        show();
 }
 
@@ -74,31 +73,72 @@ void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
 {
        // do what cursor movement does (some grey)
        h += height() / 4;
-       int max = h - height();
-       if (max < 0)
-               max = 0;
+
+       int max = std::max(0, h - height());
+
        scrollbar_->setRange(0, max);
        scrollbar_->setValue(pos);
        scrollbar_->setLineStep(line_h);
        scrollbar_->setPageStep(height());
 }
 
+namespace {
+QWorkArea const * wa_ptr = 0;
+}
 
-void QWorkArea::haveSelection(bool ) const
+#ifdef Q_WS_X11
+bool lyxX11EventFilter(XEvent * xev)
 {
-       // FIXME 
+       switch (xev->type) {
+       case SelectionRequest:
+               lyxerr[Debug::GUI] << "X requested selection." << endl;
+               if (wa_ptr)
+                       wa_ptr->selectionRequested();
+               break;
+       case SelectionClear:
+               lyxerr[Debug::GUI] << "Lost selection." << endl;
+               if (wa_ptr)
+                       wa_ptr->selectionLost();
+               break;
+       }
+       return false;
 }
+#endif
 
-string const QWorkArea::getClipboard() const 
+void QWorkArea::haveSelection(bool own) const
 {
-       // FIXME 
-       return "nothing"; 
+       wa_ptr = this;
+
+#if QT_VERSION >= 300
+       if (!QApplication::clipboard()->supportsSelection())
+               return;
+
+       if (own) {
+               QApplication::clipboard()->setSelectionMode(true);
+               QApplication::clipboard()->setText(QString());
+       }
+       // We don't need to do anything if own = false, as this case is
+       // handled by QT.
+#endif
+}
+
+
+string const QWorkArea::getClipboard() const
+{
+#if QT_VERSION >= 300
+       QApplication::clipboard()->setSelectionMode(true);
+#endif
+       QString str = QApplication::clipboard()->text();
+       if (str.isNull())
+               return string();
+       return fromqstr(str);
 }
 
-       
-void QWorkArea::putClipboard(string const &) const
+
+void QWorkArea::putClipboard(string const & str) const
 {
-       // FIXME
+#if QT_VERSION >= 300
+       QApplication::clipboard()->setSelectionMode(true);
+#endif
+       QApplication::clipboard()->setText(toqstr(str));
 }