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"
25 #include "frontends/Gui.h"
26 #include "frontends/Selection.h"
28 #include <qapplication.h>
29 #include <qclipboard.h>
30 #include <qdragobject.h>
32 #include <qmainwindow.h>
40 #include <Carbon/Carbon.h>
46 namespace os = lyx::support::os;
49 lyx::frontend::QWorkArea * wa_ptr = 0;
55 QWorkArea::QWorkArea(LyXView & owner, int, int)
56 : QWidget(qApp->mainWidget()), owner_(owner), painter_(*this)
58 scrollbar_ = new QScrollBar(QScrollBar::Vertical, this);
59 content_ = new QContentPane(this);
61 (static_cast<QMainWindow*>(qApp->mainWidget()))->setCentralWidget(this);
63 setFocusProxy(content_);
68 // It is said that this helps reduce flicker
69 content_->setBackgroundMode(NoBackground);
71 QHBoxLayout * vl = new QHBoxLayout(this);
72 vl->addWidget(content_, 5);
73 vl->addWidget(scrollbar_, 0);
82 QWorkArea::~QWorkArea()
87 void QWorkArea::setScrollbarParams(int h, int pos, int line_h)
89 scrollbar_->setTracking(false);
90 // do what cursor movement does (some grey)
93 int max = std::max(0, h - height());
95 scrollbar_->setRange(0, max);
96 content_->trackScrollbar(false);
97 scrollbar_->setValue(pos);
98 content_->trackScrollbar(true);
99 scrollbar_->setLineStep(line_h);
100 scrollbar_->setPageStep(height());
102 scrollbar_->setTracking(true);
105 } // namespace frontend
110 bool lyxX11EventFilter(XEvent * xev)
113 case SelectionRequest:
114 lyxerr[Debug::GUI] << "X requested selection." << endl;
116 lyx::docstring const sel = wa_ptr->view().view()->requestSelection();
118 wa_ptr->view().gui().selection().put(sel);
122 lyxerr[Debug::GUI] << "Lost selection." << endl;
124 wa_ptr->view().view()->clearSelection();
133 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
135 DescType returnedType;
137 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
138 typeWildCard, &returnedType, nil, 0,
141 case errAEDescNotFound:
144 return errAEEventNotHandled;
151 pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
152 AppleEvent* /*reply*/, long /*refCon*/)
155 AEDescList documentList;
156 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
161 err = checkAppleEventForMissingParams(*inEvent);
164 err = AECountItems(&documentList, &documentCount);
165 for (long documentIndex = 1;
166 err == noErr && documentIndex <= documentCount;
168 DescType returnedType;
173 err = AESizeOfNthItem(&documentList, documentIndex,
174 &returnedType, &actualSize);
176 err = AEGetNthPtr(&documentList, documentIndex,
178 &returnedType, (Ptr)&ref,
179 sizeof(FSRef), &actualSize);
181 FSRefMakePath(&ref, (UInt8*)qstr_buf,
183 s_arg=QString::fromUtf8(qstr_buf);
184 wa_ptr->view().view()->workAreaDispatch(
185 FuncRequest(LFUN_FILE_OPEN,
192 AEDisposeDesc(&documentList);
201 void QWorkArea::haveSelection(bool own)
203 wa_ptr = const_cast<QWorkArea*>(this);
205 if (!QApplication::clipboard()->supportsSelection())
209 QApplication::clipboard()->setSelectionMode(true);
210 QApplication::clipboard()->setText(QString());
212 // We don't need to do anything if own = false, as this case is
217 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
219 event->accept(QUriDrag::canDecode(event));
223 void QWorkArea::dropEvent(QDropEvent * event)
227 if (QUriDrag::decodeLocalFiles(event, files)) {
228 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
230 for (QStringList::Iterator i = files.begin();
231 i != files.end(); ++i) {
232 string const file = os::internal_path(fromqstr(*i));
233 view().view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
238 } // namespace frontend