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 scrollbar_->setTracking(false);
92 // do what cursor movement does (some grey)
95 int max = std::max(0, h - height());
97 scrollbar_->setRange(0, max);
98 content_->trackScrollbar(false);
99 scrollbar_->setValue(pos);
100 content_->trackScrollbar(true);
101 scrollbar_->setLineStep(line_h);
102 scrollbar_->setPageStep(height());
104 scrollbar_->setTracking(true);
107 } // namespace frontend
112 bool lyxX11EventFilter(XEvent * xev)
115 case SelectionRequest:
116 lyxerr[Debug::GUI] << "X requested selection." << endl;
118 wa_ptr->view().view()->selectionRequested();
121 lyxerr[Debug::GUI] << "Lost selection." << endl;
123 wa_ptr->view().view()->selectionLost();
132 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
134 DescType returnedType;
136 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
137 typeWildCard, &returnedType, nil, 0,
140 case errAEDescNotFound:
143 return errAEEventNotHandled;
150 pascal OSErr handleOpenDocuments(const AppleEvent* inEvent,
151 AppleEvent* /*reply*/, long /*refCon*/)
154 AEDescList documentList;
155 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
160 err = checkAppleEventForMissingParams(*inEvent);
163 err = AECountItems(&documentList, &documentCount);
164 for (long documentIndex = 1;
165 err == noErr && documentIndex <= documentCount;
167 DescType returnedType;
172 err = AESizeOfNthItem(&documentList, documentIndex,
173 &returnedType, &actualSize);
175 err = AEGetNthPtr(&documentList, documentIndex,
177 &returnedType, (Ptr)&ref,
178 sizeof(FSRef), &actualSize);
180 FSRefMakePath(&ref, (UInt8*)qstr_buf,
182 s_arg=QString::fromUtf8(qstr_buf);
183 wa_ptr->view().view()->workAreaDispatch(
184 FuncRequest(LFUN_FILE_OPEN,
191 AEDisposeDesc(&documentList);
200 void QWorkArea::haveSelection(bool own)
202 wa_ptr = const_cast<QWorkArea*>(this);
204 if (!QApplication::clipboard()->supportsSelection())
208 QApplication::clipboard()->setSelectionMode(true);
209 QApplication::clipboard()->setText(QString());
211 // We don't need to do anything if own = false, as this case is
216 void QWorkArea::dragEnterEvent(QDragEnterEvent * event)
218 event->accept(QUriDrag::canDecode(event));
222 void QWorkArea::dropEvent(QDropEvent * event)
226 if (QUriDrag::decodeLocalFiles(event, files)) {
227 lyxerr[Debug::GUI] << "QWorkArea::dropEvent: got URIs!"
229 for (QStringList::Iterator i = files.begin();
230 i != files.end(); ++i) {
231 string const file = os::internal_path(fromqstr(*i));
232 view().view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
237 } // namespace frontend