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