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