]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
ws changes only
[lyx.git] / src / funcrequest.C
1 /**
2  * \file funcrequest.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "funcrequest.h"
14 #include "BufferView.h"
15 #include "lyxfunc.h" // only for setMessage()
16 #include "frontends/LyXView.h"
17 #include "debug.h"
18 #include "support/std_sstream.h"
19
20 using std::endl;
21 using std::getline;
22
23 using std::istringstream;
24 using std::vector;
25 using std::string;
26
27
28 FuncRequest::FuncRequest()
29         : view_(0), action(LFUN_NOACTION), x(0), y(0), button_(mouse_button::none)
30 {}
31
32
33 FuncRequest::FuncRequest(kb_action act)
34         : view_(0), action(act), x(0), y(0), button_(mouse_button::none)
35 {}
36
37
38 FuncRequest::FuncRequest(kb_action act, string const & arg)
39         : view_(0), action(act), argument(arg), x(0), y(0), button_(mouse_button::none)
40 {}
41
42
43 FuncRequest::FuncRequest
44                 (kb_action act, int ax, int ay, mouse_button::state button)
45         : view_(0), action(act), x(ax), y(ay), button_(button)
46 {}
47
48
49 FuncRequest::FuncRequest(BufferView * view, kb_action act)
50         : view_(view), action(act), x(0), y(0), button_(mouse_button::none)
51 {}
52
53
54 FuncRequest::FuncRequest(BufferView * view, kb_action act, string const & arg)
55         : view_(view), action(act), argument(arg), x(0),  y(0), button_(mouse_button::none)
56 {}
57
58
59 FuncRequest::FuncRequest
60                 (BufferView * view, kb_action act, int ax, int ay, mouse_button::state but)
61         : view_(view), action(act), x(ax), y(ay), button_(but)
62 {}
63
64
65 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg)
66         : view_(cmd.view_), action(cmd.action), argument(arg),
67           x(cmd.x), y(cmd.y), button_(cmd.button_)
68 {}
69
70
71 FuncRequest::FuncRequest(FuncRequest const & cmd, BufferView * view)
72         : view_(view), action(cmd.action), argument(cmd.argument),
73           x(cmd.x), y(cmd.y), button_(cmd.button_)
74 {}
75
76
77 BufferView * FuncRequest::view() const
78 {
79         return view_;
80 }
81
82
83 void FuncRequest::setView(BufferView * view)
84 {
85         view_ = view;
86 }
87
88
89 mouse_button::state FuncRequest::button() const
90 {
91         return button_;
92 }
93
94
95 void FuncRequest::message(string const & msg) const
96 {
97         if (view_)
98                 view_->owner()->getLyXFunc().setMessage(msg);
99         else
100                 lyxerr  << "Dropping message '" << msg << "'" << endl;
101 }
102
103
104 void FuncRequest::errorMessage(string const & msg) const
105 {
106         if (view_)
107                 view_->owner()->getLyXFunc().setErrorMessage(msg);
108         else
109                 lyxerr  << "Dropping error message '" << msg << "'" << endl;
110 }
111
112
113 void split(vector<string> & args, string str)
114 {
115         istringstream is(str);
116         while (is) {
117                 char c;
118                 string s;
119                 is >> c;
120                 if (c == '"')
121                         getline(is, s, '"');
122                 else {
123                         is.putback(c);
124                         is >> s;
125                 }
126                 args.push_back(s);
127         }
128 }
129
130
131 string FuncRequest::getArg(unsigned int i) const
132 {
133         vector<string> args;
134         split(args, argument);
135         return i < args.size() ? args[i] : string();
136 }