]> git.lyx.org Git - lyx.git/blob - src/funcrequest.C
6192a79f57ab7bce0e1e29cdb241497963fff500
[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
26
27 FuncRequest::FuncRequest()
28         : view_(0), action(LFUN_UNKNOWN_ACTION), x(0), y(0), button_(mouse_button::none)
29 {}
30
31
32 FuncRequest::FuncRequest(kb_action act)
33         : view_(0), action(act), x(0), y(0), button_(mouse_button::none)
34 {}
35
36
37 FuncRequest::FuncRequest(kb_action act, string const & arg)
38         : view_(0), action(act), argument(arg), x(0), y(0), button_(mouse_button::none)
39 {}
40
41
42 FuncRequest::FuncRequest
43                 (kb_action act, int ax, int ay, mouse_button::state button)
44         : view_(0), action(act), x(ax), y(ay), button_(button)
45 {}
46
47
48 FuncRequest::FuncRequest(BufferView * view, kb_action act)
49         : view_(view), action(act), x(0), y(0), button_(mouse_button::none)
50 {}
51
52
53 FuncRequest::FuncRequest(BufferView * view, kb_action act, string const & arg)
54         : view_(view), action(act), argument(arg), x(0),  y(0), button_(mouse_button::none)
55 {}
56
57
58 FuncRequest::FuncRequest
59                 (BufferView * view, kb_action act, int ax, int ay, mouse_button::state but)
60         : view_(view), action(act), x(ax), y(ay), button_(but)
61 {}
62
63
64 FuncRequest::FuncRequest(FuncRequest const & cmd, string const & arg)
65         : view_(cmd.view_), action(cmd.action), argument(arg),
66           x(cmd.x), y(cmd.y), button_(cmd.button_)
67 {}
68
69
70 FuncRequest::FuncRequest(FuncRequest const & cmd, BufferView * view)
71         : view_(view), action(cmd.action), argument(cmd.argument),
72           x(cmd.x), y(cmd.y), button_(cmd.button_)
73 {}
74
75
76 BufferView * FuncRequest::view() const
77 {
78         return view_;
79 }
80
81
82 void FuncRequest::setView(BufferView * view)
83 {
84         view_ = view;
85 }
86
87
88 mouse_button::state FuncRequest::button() const
89 {
90         return button_;
91 }
92
93
94 void FuncRequest::message(string const & msg) const
95 {
96         if (view_)
97                 view_->owner()->getLyXFunc().setMessage(msg);
98         else
99                 lyxerr  << "Dropping message '" << msg << "'" << endl;
100 }
101
102
103 void FuncRequest::errorMessage(string const & msg) const
104 {
105         if (view_)
106                 view_->owner()->getLyXFunc().setErrorMessage(msg);
107         else
108                 lyxerr  << "Dropping error message '" << msg << "'" << endl;
109 }
110
111
112 void split(vector<string> & args, string str)
113 {
114         istringstream is(str);
115         while (is) {
116                 char c;
117                 string s;
118                 is >> c;
119                 if (c == '"')
120                         getline(is, s, '"');
121                 else {
122                         is.putback(c);
123                         is >> s;
124                 }
125                 args.push_back(s);
126         }
127 }
128
129
130 string FuncRequest::getArg(unsigned int i) const
131 {
132         vector<string> args;
133         split(args, argument);
134         return i < args.size() ? args[i] : string();
135 }