3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "QWorkArea.h"
15 #include "lcolorcache.h"
16 #include "qt_helpers.h"
19 #include "funcrequest.h"
22 #include <qapplication.h>
23 #include <qclipboard.h>
24 #include <qdragobject.h>
26 #include <qmainwindow.h>
34 #include <Carbon/Carbon.h>
41 QWorkArea const * wa_ptr = 0;
44 QWorkArea::QWorkArea(LyXView &, int, int)
45 : WorkArea(), QWidget(qApp->mainWidget()), painter_(*this)
47 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
48 content_ = new QContentPane(this);
50 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
52 setFocusProxy(content_);
57 content_->setBackgroundColor(lcolorcache.get(LColor::background));
59 QHBoxLayout * vl = new QHBoxLayout(this);
60 vl->addWidget(content_, 5);
61 vl->addWidget(scrollbar_, 0);
70 QWorkArea::~QWorkArea()
75 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
77 // do what cursor movement does (some grey)
80 int max = std::max(0, h - height());
82 scrollbar_->setRange(0, max);
83 content_->trackScrollbar(false);
84 scrollbar_->setValue(pos);
85 content_->trackScrollbar(true);
86 scrollbar_->setLineStep(line_h);
87 scrollbar_->setPageStep(height());
91 bool lyxX11EventFilter(XEvent * xev)
94 case SelectionRequest:
95 lyxerr[Debug::GUI] << "X requested selection." << endl;
97 wa_ptr->selectionRequested();
100 lyxerr[Debug::GUI] << "Lost selection." << endl;
102 wa_ptr->selectionLost();
111 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
113 DescType returnedType;
115 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
116 typeWildCard, &returnedType, nil, 0,
119 case errAEDescNotFound:
122 return errAEEventNotHandled;
129 pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
130 AppleEvent* /*reply*/, long /*refCon*/)
133 AEDescList documentList;
134 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
139 err = checkAppleEventForMissingParams(*inEvent);
142 err = AECountItems(&documentList, &documentCount);
143 for (long documentIndex = 1;
144 err == noErr && documentIndex <= documentCount;
146 DescType returnedType;
151 err = AESizeOfNthItem(&documentList, documentIndex,
152 &returnedType, &actualSize);
154 err = AEGetNthPtr(&documentList, documentIndex,
156 &returnedType, (Ptr)&ref,
157 sizeof(FSRef), &actualSize);
159 FSRefMakePath(&ref, (UInt8*)qstr_buf,
161 s_arg=QString::fromUtf8(qstr_buf);
163 FuncRequest(LFUN_FILE_OPEN,
170 AEDisposeDesc(&documentList);
175 void QWorkArea::haveSelection(bool own) const
179 #if QT_VERSION >= 300
180 if (!QApplication::clipboard()->supportsSelection())
184 QApplication::clipboard()->setSelectionMode(true);
185 QApplication::clipboard()->setText(QString());
187 // We don't need to do anything if own = false, as this case is
193 string const QWorkArea::getClipboard() const
195 #if QT_VERSION >= 300
196 QApplication::clipboard()->setSelectionMode(true);
198 QString str = QApplication::clipboard()->text();
201 return fromqstr(str);
205 void QWorkArea::putClipboard(string const & str) const
207 #if QT_VERSION >= 300
208 QApplication::clipboard()->setSelectionMode(true);
210 QApplication::clipboard()->setText(toqstr(str));
214 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
216 event->accept(QUriDrag::canDecode(event));
220 void QWorkArea::dropEvent(QDropEvent* event)
224 if (QUriDrag::decodeLocalFiles(event, files)) {
225 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
227 for (QStringList::Iterator i = files.begin();
229 dispatch(FuncRequest(LFUN_FILE_OPEN, fromqstr(*i)));