]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/Application.C
* MSVC Compilation fix: #warning is not supported.
[lyx.git] / src / frontends / qt4 / Application.C
1 /**
2  * \file qt4/Application.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "GuiWorkArea.h"
16 #include "Application.h"
17
18 #include "qt_helpers.h"
19 #include "BufferView.h"
20 #include "debug.h"
21 #include "support/lstrings.h"
22
23 #include <QApplication>
24 #include <QEventLoop>
25 #include <QTranslator>
26 #include <QTextCodec>
27 #include <QClipboard>
28
29 #ifdef Q_WS_X11
30 #include <X11/Xlib.h>
31 #endif
32
33 using lyx::support::subst;
34
35 using std::string;
36 using std::endl;
37
38 ///////////////////////////////////////////////////////////////
39 // You can find other X11 and MACX specific stuff
40 // at the end of this file...
41 ///////////////////////////////////////////////////////////////
42
43 namespace lyx {
44 namespace frontend {
45
46 Application::Application(int & argc, char ** argv)
47         : QApplication(argc, argv), buffer_view_(0)
48 {
49 #ifdef Q_WS_X11
50         // doubleClickInterval() is 400 ms on X11 witch is just too long.
51         // On Windows and Mac OS X, the operating system's value is used.
52         // On Microsoft Windows, calling this function sets the double
53         // click interval for all applications. So we don't!
54         QApplication::setDoubleClickInterval(300);
55 #endif
56
57 #ifdef Q_WS_MACX
58         AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
59                               NewAEEventHandlerUPP(handleOpenDocuments),
60                               0, false);
61 #endif
62 }
63
64
65 void Application::setBufferView(BufferView * buffer_view)
66 {
67         buffer_view_ = buffer_view;
68 }
69
70
71 ////////////////////////////////////////////////////////////////////////
72 // X11 specific stuff goes here...
73 #ifdef Q_WS_X11
74 bool Application::x11EventFilter(XEvent * xev)
75 {
76         switch (xev->type) {
77         case SelectionRequest:
78                 lyxerr[Debug::GUI] << "X requested selection." << endl;
79                 if (buffer_view_)
80                         buffer_view_->selectionRequested();
81                 break;
82         case SelectionClear:
83                 lyxerr[Debug::GUI] << "Lost selection." << endl;
84                 if (buffer_view_)
85                         buffer_view_->selectionLost();
86                 break;
87         }
88         return false;
89 }
90 #endif
91
92
93 ////////////////////////////////////////////////////////////////////////
94 // Mac OSX specific stuff goes here...
95
96 #ifdef Q_WS_MACX
97 namespace{
98 OSErr checkAppleEventForMissingParams(const AppleEvent& theAppleEvent)
99  {
100         DescType returnedType;
101         Size actualSize;
102         OSErr err = AEGetAttributePtr(&theAppleEvent, keyMissedKeywordAttr,
103                                       typeWildCard, &returnedType, nil, 0,
104                                       &actualSize);
105         switch (err) {
106         case errAEDescNotFound:
107                 return noErr;
108         case noErr:
109                 return errAEEventNotHandled;
110         default:
111                 return err;
112         }
113  }
114 } // namespace
115
116 OSErr Application::handleOpenDocuments(const AppleEvent* inEvent,
117                                        AppleEvent* /*reply*/, long /*refCon*/)
118 {
119         QString s_arg;
120         AEDescList documentList;
121         OSErr err = AEGetParamDesc(inEvent, keyDirectObject, typeAEList,
122                                    &documentList);
123         if (err != noErr)
124                 return err;
125
126         err = checkAppleEventForMissingParams(*inEvent);
127         if (err == noErr) {
128                 long documentCount;
129                 err = AECountItems(&documentList, &documentCount);
130                 for (long documentIndex = 1;
131                      err == noErr && documentIndex <= documentCount;
132                      documentIndex++) {
133                         DescType returnedType;
134                         Size actualSize;
135                         AEKeyword keyword;
136                         FSRef ref;
137                         char qstr_buf[1024];
138                         err = AESizeOfNthItem(&documentList, documentIndex,
139                                               &returnedType, &actualSize);
140                         if (err == noErr) {
141                                 err = AEGetNthPtr(&documentList, documentIndex,
142                                                   typeFSRef, &keyword,
143                                                   &returnedType, (Ptr)&ref,
144                                                   sizeof(FSRef), &actualSize);
145                                 if (err == noErr) {
146                                         FSRefMakePath(&ref, (UInt8*)qstr_buf,
147                                                       1024);
148                                         s_arg=QString::fromUtf8(qstr_buf);
149 //                                      buffer_view_->workAreaDispatch(
150 //                                              FuncRequest(LFUN_FILE_OPEN,
151 //                                                          fromqstr(s_arg)));
152                                         break;
153                                 }
154                         }
155                 } // for ...
156         }
157         AEDisposeDesc(&documentList);
158
159         return err;
160 }
161
162 bool Application::macEventFilter(EventRef event)
163 {
164         if (GetEventClass(event) == kEventClassAppleEvent) {
165                 EventRecord eventrec;
166                 ConvertEventRefToEventRecord(event, &eventrec);
167                 AEProcessAppleEvent(&eventrec);
168
169                 return false;
170         }
171         return false;
172 }
173
174 #endif  // Q_WS_MACX
175
176 } // namespace frontend
177 } // namespace lyx