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 "frontends/LyXView.h"
14 #include "BufferView.h"
16 #include "QWorkArea.h"
18 #include "lcolorcache.h"
19 #include "qt_helpers.h"
22 #include "funcrequest.h"
24 #include "support/os.h"
26 #include <qapplication.h>
27 #include <qclipboard.h>
28 #include <qdragobject.h>
30 #include <qmainwindow.h>
38 #include <Carbon/Carbon.h>
41 #include <support/lstrings.h>
43 using lyx::support::internalLineEnding;
44 using lyx::support::externalLineEnding;
48 namespace os = lyx::support::os;
51 lyx::frontend::QWorkArea * wa_ptr = 0;
57 QWorkArea::QWorkArea(LyXView & owner, int, int)
58 : QWidget(qApp->mainWidget()), owner_(owner), painter_(*this)
60 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
61 content_ = new QContentPane(this);
63 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
65 setFocusProxy(content_);
70 // It is said that this helps reduce flicker
71 content_->setBackgroundMode(NoBackground);
73 QHBoxLayout * vl = new QHBoxLayout(this);
74 vl->addWidget(content_, 5);
75 vl->addWidget(scrollbar_, 0);
84 QWorkArea::~QWorkArea()
89 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
91 // do what cursor movement does (some grey)
94 int max = std::max(0, h - height());
96 scrollbar_->setRange(0, max);
97 content_->trackScrollbar(false);
98 scrollbar_->setValue(pos);
99 content_->trackScrollbar(true);
100 scrollbar_->setLineStep(line_h);
101 scrollbar_->setPageStep(height());
104 } // namespace frontend
109 bool lyxX11EventFilter(XEvent * xev)
112 case SelectionRequest:
113 lyxerr[Debug::GUI] << "X requested selection." << endl;
115 wa_ptr->view().view()->selectionRequested();
118 lyxerr[Debug::GUI] << "Lost selection." << endl;
120 wa_ptr->view().view()->selectionLost();
129 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
131 DescType returnedType;
133 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
134 typeWildCard, &returnedType, nil, 0,
137 case errAEDescNotFound:
140 return errAEEventNotHandled;
147 pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
148 AppleEvent* /*reply*/, long /*refCon*/)
151 AEDescList documentList;
152 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
157 err = checkAppleEventForMissingParams(*inEvent);
160 err = AECountItems(&documentList, &documentCount);
161 for (long documentIndex = 1;
162 err == noErr && documentIndex <= documentCount;
164 DescType returnedType;
169 err = AESizeOfNthItem(&documentList, documentIndex,
170 &returnedType, &actualSize);
172 err = AEGetNthPtr(&documentList, documentIndex,
174 &returnedType, (Ptr)&ref,
175 sizeof(FSRef), &actualSize);
177 FSRefMakePath(&ref, (UInt8*)qstr_buf,
179 s_arg=QString::fromUtf8(qstr_buf);
180 wa_ptr->view().view()->workAreaDispatch(
181 FuncRequest(LFUN_FILE_OPEN,
188 AEDisposeDesc(&documentList);
197 void QWorkArea::haveSelection(bool own)
199 wa_ptr = const_cast<QWorkArea*>(this);
201 if (!QApplication::clipboard()->supportsSelection())
205 QApplication::clipboard()->setSelectionMode(true);
206 QApplication::clipboard()->setText(QString());
208 // We don't need to do anything if own = false, as this case is
213 string const QWorkArea::getClipboard() const
215 QApplication::clipboard()->setSelectionMode(true);
216 QString str = QApplication::clipboard()->text();
219 return internalLineEnding(fromqstr(str));
223 void QWorkArea::putClipboard(string const & str)
225 QApplication::clipboard()->setSelectionMode(true);
226 QApplication::clipboard()->setText(toqstr(externalLineEnding(str)));
230 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
232 event->accept(QUriDrag::canDecode(event));
236 void QWorkArea::dropEvent(QDropEvent * event)
240 if (QUriDrag::decodeLocalFiles(event, files)) {
241 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
243 for (QStringList::Iterator i = files.begin();
244 i != files.end(); ++i) {
245 string const file = os::internal_path(fromqstr(*i));
246 view().view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
251 } // namespace frontend