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>
44 namespace os = lyx::support::os;
47 lyx::frontend::QWorkArea * wa_ptr = 0;
53 QWorkArea::QWorkArea(LyXView & owner, int, int)
54 : QWidget(qApp->mainWidget()), owner_(owner), painter_(*this)
56 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
57 content_ = new QContentPane(this);
59 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
61 setFocusProxy(content_);
66 // It is said that this helps reduce flicker
67 content_->setBackgroundMode(NoBackground);
69 QHBoxLayout * vl = new QHBoxLayout(this);
70 vl->addWidget(content_, 5);
71 vl->addWidget(scrollbar_, 0);
80 QWorkArea::~QWorkArea()
85 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
87 scrollbar_->setTracking(false);
88 // do what cursor movement does (some grey)
91 int max = std::max(0, h - height());
93 scrollbar_->setRange(0, max);
94 content_->trackScrollbar(false);
95 scrollbar_->setValue(pos);
96 content_->trackScrollbar(true);
97 scrollbar_->setLineStep(line_h);
98 scrollbar_->setPageStep(height());
100 scrollbar_->setTracking(true);
103 } // namespace frontend
108 bool lyxX11EventFilter(XEvent * xev)
111 case SelectionRequest:
112 lyxerr[Debug::GUI] << "X requested selection." << endl;
114 wa_ptr->view().view()->selectionRequested();
117 lyxerr[Debug::GUI] << "Lost selection." << endl;
119 wa_ptr->view().view()->selectionLost();
128 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
130 DescType returnedType;
132 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
133 typeWildCard, &returnedType, nil, 0,
136 case errAEDescNotFound:
139 return errAEEventNotHandled;
146 pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
147 AppleEvent* /*reply*/, long /*refCon*/)
150 AEDescList documentList;
151 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
156 err = checkAppleEventForMissingParams(*inEvent);
159 err = AECountItems(&documentList, &documentCount);
160 for (long documentIndex = 1;
161 err == noErr && documentIndex <= documentCount;
163 DescType returnedType;
168 err = AESizeOfNthItem(&documentList, documentIndex,
169 &returnedType, &actualSize);
171 err = AEGetNthPtr(&documentList, documentIndex,
173 &returnedType, (Ptr)&ref,
174 sizeof(FSRef), &actualSize);
176 FSRefMakePath(&ref, (UInt8*)qstr_buf,
178 s_arg=QString::fromUtf8(qstr_buf);
179 wa_ptr->view().view()->workAreaDispatch(
180 FuncRequest(LFUN_FILE_OPEN,
187 AEDisposeDesc(&documentList);
196 void QWorkArea::haveSelection(bool own)
198 wa_ptr = const_cast<QWorkArea*>(this);
200 if (!QApplication::clipboard()->supportsSelection())
204 QApplication::clipboard()->setSelectionMode(true);
205 QApplication::clipboard()->setText(QString());
207 // We don't need to do anything if own = false, as this case is
212 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
214 event->accept(QUriDrag::canDecode(event));
218 void QWorkArea::dropEvent(QDropEvent * event)
222 if (QUriDrag::decodeLocalFiles(event, files)) {
223 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
225 for (QStringList::Iterator i = files.begin();
226 i != files.end(); ++i) {
227 string const file = os::internal_path(fromqstr(*i));
228 view().view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
233 } // namespace frontend