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