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