]> git.lyx.org Git - features.git/blob - src/frontends/gtk/GuiApplication.C
9b3db098510b875b3b9a63446ee3c76b0707ba77
[features.git] / src / frontends / gtk / GuiApplication.C
1 /**
2  * \file qt4/GuiApplication.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 // Too hard to make concept checks work with this file
16 #ifdef _GLIBCXX_CONCEPT_CHECKS
17 #undef _GLIBCXX_CONCEPT_CHECKS
18 #endif
19 #ifdef _GLIBCPP_CONCEPT_CHECKS
20 #undef _GLIBCPP_CONCEPT_CHECKS
21 #endif
22
23 #include "GuiApplication.h"
24
25 #include "GView.h"
26 #include "GuiWorkArea.h"
27 #include "GtkmmX.h"
28
29 #include "BufferView.h"
30
31 #include "graphics/LoaderQueue.h"
32
33 #include "support/lstrings.h"
34 #include "support/os.h"
35 #include "support/package.h"
36
37 #include "lyx_main.h"
38 #include "lyxrc.h"
39 #include "debug.h"
40
41 #include <gtkmm.h>
42
43 #include "LyXGdkImage.h"
44
45
46 using lyx::support::subst;
47
48 using std::string;
49 using std::endl;
50
51
52 namespace {
53
54 /// estimate DPI from X server
55 int getDPI()
56 {
57         //TODO use GDK instead
58         Screen * scr = ScreenOfDisplay(getDisplay(), getScreen());
59         return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) +
60                 (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2);
61 }
62
63 } // namespace anon
64
65
66 namespace lyx {
67 namespace frontend {
68
69 GuiApplication::GuiApplication(int & argc, char ** argv)
70         : Gtk::Main(argc, argv), Application(argc, argv)
71 {
72         using namespace lyx::graphics;
73         Image::newImage = boost::bind(&LyXGdkImage::newImage);
74         Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats);
75
76         // needs to be done before reading lyxrc
77         lyxrc.dpi = getDPI();
78
79         LoaderQueue::setPriority(10,100);
80 }
81
82
83 Clipboard& GuiApplication::clipboard()
84 {
85         return clipboard_;
86 }
87
88
89 Selection& GuiApplication::selection()
90 {
91         return selection_;
92 }
93
94
95 int const GuiApplication::exec()
96 {
97         run();
98         return EXIT_SUCCESS;
99 }
100
101
102 void GuiApplication::exit(int /*status*/)
103 {
104         // FIXME: Don't ignore status
105         guiApp->quit();
106 }
107
108
109 // FIXME: this whole method needs to be moved to Application.
110 LyXView & GuiApplication::createView(unsigned int width,
111                                                                           unsigned int height,
112                                                                           int posx, int posy,
113                                                                           bool maximize)
114 {
115         // FIXME: for now we assume that there is only one LyXView with id = 0.
116         /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0);
117         //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
118
119         int view_id = gui().newView(width, height);
120         GView & view = static_cast<GView &>(gui().view(view_id));
121
122         lyxfunc_.reset(new LyXFunc(&view));
123
124         LyX::ref().addLyXView(&view);
125
126         view.show();
127         view.init();
128
129         return view;
130 }
131
132 } // namespace frontend
133 } // namespace lyx