2 * \file qt3/GuiApplication.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "frontends/LyXView.h"
16 #include "frontends/WorkArea.h"
18 #include "GuiApplication.h"
21 #include "GuiWorkArea.h"
22 #include "qt_helpers.h"
25 #include "BufferView.h"
27 // FIXME: this is needed for now because LyXFunc is still constructed
29 #include "frontends/Application_pimpl.h"
31 #include "graphics/LoaderQueue.h"
33 #include "support/lstrings.h"
34 #include "support/os.h"
35 #include "support/package.h"
41 #include <qapplication.h>
42 #include <qclipboard.h>
43 #include <qeventloop.h>
45 #include <qpaintdevicemetrics.h>
46 #include <qtextcodec.h>
47 #include <qtranslator.h>
53 #include <boost/bind.hpp>
55 using lyx::support::subst;
61 extern void initEncodings();
63 ///////////////////////////////////////////////////////////////
64 // You can find other X11 and MACX specific stuff
65 // at the end of this file...
66 ///////////////////////////////////////////////////////////////
73 QPaintDeviceMetrics pdm(&w);
74 return int(0.5 * (pdm.logicalDpiX() + pdm.logicalDpiY()));
83 GuiApplication::GuiApplication(int & argc, char ** argv)
84 : QApplication(argc, argv), Application(argc, argv)
87 // doubleClickInterval() is 400 ms on X11 witch is just too long.
88 // On Windows and Mac OS X, the operating system's value is used.
89 // On Microsoft Windows, calling this function sets the double
90 // click interval for all applications. So we don't!
91 QApplication::setDoubleClickInterval(300);
95 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
96 NewAEEventHandlerUPP(handleOpenDocuments),
100 #if QT_VERSION >= 0x030200
101 // install translation file for Qt built-in dialogs
102 // These are only installed since Qt 3.2.x
103 QTranslator qt_trans(0);
104 if (qt_trans.load(QString("qt_") + QTextCodec::locale(),
105 qInstallPathTranslations())) {
106 qApp->installTranslator(&qt_trans);
107 // even if the language calls for RtL, don't do that
108 qApp->setReverseLayout(false);
110 << "Successfully installed Qt translations for locale "
111 << QTextCodec::locale() << std::endl;
114 << "Could not find Qt translations for locale "
115 << QTextCodec::locale() << std::endl;
119 // These translations are meant to break Qt/Mac menu merging
120 // algorithm on some entries. It lists the menu names that
121 // should not be moved to the LyX menu
122 QTranslator aqua_trans(0);
123 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setting", 0,
125 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Config", 0,
127 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Options", 0,
129 aqua_trans.insert(QTranslatorMessage("QMenuBar", "Setup", 0,
132 qApp->installTranslator(&aqua_trans);
135 using namespace lyx::graphics;
137 Image::newImage = boost::bind(&QLImage::newImage);
138 Image::loadableFormats = boost::bind(&QLImage::loadableFormats);
140 // needs to be done before reading lyxrc
141 lyxrc.dpi = getDPI();
143 LoaderQueue::setPriority(10,100);
147 Clipboard& GuiApplication::clipboard()
153 Selection& GuiApplication::selection()
159 int const GuiApplication::exec()
161 return QApplication::exec();
165 void GuiApplication::exit(int status)
167 QApplication::exit(status);
171 // FIXME: this whole method needs to be moved to Application.
172 LyXView & GuiApplication::createView(unsigned int width,
177 // this can't be done before because it needs the Languages object
180 int view_id = gui().newView(width, height);
181 QtView & view = static_cast<QtView &> (gui().view(view_id));
183 pimpl_->lyxfunc_.reset(new LyXFunc(&view));
185 // FIXME: for now we assume that there is only one LyXView with id = 0.
186 /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
187 //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
189 LyX::ref().addLyXView(&view);
193 // FIXME: put this initialisation code in GuiView accessible via
194 // a pure virtual method in LyXView.
196 // only true when the -geometry option was NOT used
197 if (width != 0 && height != 0) {
198 view.initFloatingGeometry(QRect(posx, posy, width, height));
199 view.resize(width, height);
200 if (posx != -1 && posy != -1)
201 view.move(posx, posy);
204 view.setWindowState(Qt::WindowMaximized);
212 ////////////////////////////////////////////////////////////////////////
213 // X11 specific stuff goes here...
215 bool GuiApplication::x11EventFilter(XEvent * xev)
218 case SelectionRequest:
219 lyxerr[Debug::GUI] << "X requested selection." << endl;
221 lyx::docstring const sel = buffer_view_->requestSelection();
227 lyxerr[Debug::GUI] << "Lost selection." << endl;
229 buffer_view_->clearSelection();
237 ////////////////////////////////////////////////////////////////////////
238 // Mac OSX specific stuff goes here...
243 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
245 DescType returnedType;
247 OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
248 typeWildCard, &returnedType, nil, 0,
251 case errAEDescNotFound:
254 return errAEEventNotHandled;
262 OSErr GuiApplication::handleOpenDocuments(const AppleEvent* inEvent,
263 AppleEvent* /*reply*/, long /*refCon*/)
266 AEDescList documentList;
267 OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
272 err = checkAppleEventForMissingParams(*inEvent);
275 err = AECountItems(&documentList, &documentCount);
276 for (long documentIndex = 1;
277 err == noErr && documentIndex <= documentCount;
279 DescType returnedType;
284 err = AESizeOfNthItem(&documentList, documentIndex,
285 &returnedType, &actualSize);
287 err = AEGetNthPtr(&documentList, documentIndex,
289 &returnedType, (Ptr)&ref,
290 sizeof(FSRef), &actualSize);
292 FSRefMakePath(&ref, (UInt8*)qstr_buf,
294 s_arg=QString::fromUtf8(qstr_buf);
295 // buffer_view_->workAreaDispatch(
296 // FuncRequest(LFUN_FILE_OPEN,
297 // fromqstr(s_arg)));
303 AEDisposeDesc(&documentList);
308 bool GuiApplication::macEventFilter(EventRef event)
310 if (GetEventClass(event) == kEventClassAppleEvent) {
311 EventRecord eventrec;
312 ConvertEventRefToEventRecord(event, &eventrec);
313 AEProcessAppleEvent(&eventrec);
322 } // namespace frontend