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