]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/helper_funcs.h
fix tooltips in toolbar
[lyx.git] / src / frontends / controllers / helper_funcs.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  *
5  *           LyX, The Document Processor
6  *
7  *           Copyright 2001 The LyX Team.
8  *
9  * ======================================================
10  *
11  * \file ControlCitation.h
12  * \author Angus Leeming <a.leeming@ic.ac.uk>
13  */
14
15 #ifndef HELPERFUNCS_H
16 #define HELPERFUNCS_H
17
18 #include <utility> // pair
19
20 #ifdef __GNUG__
21 #pragma interface
22 #endif
23
24 class LyXView;
25
26 /** Launch a file dialog and return the chosen file.
27     filename: a suggested filename.
28     title: the title of the dialog.
29     pattern: *.ps etc.
30     dir1 = (name, dir), dir2 = (name, dir): extra buttons on the dialog.
31 */
32 string const browseFile(LyXView *lv, string const & filename,
33                         string const & title,
34                         string const & pattern,
35                         std::pair<string,string> const & dir1 = std::make_pair(string(), string()),
36                         std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
37
38
39 /* Wrapper around browseFile which tries to provide a filename
40    relative to relpath.  If the relative path is of the form "foo.txt"
41    or "bar/foo.txt", then it is returned as relative. OTOH, if it is
42    of the form "../baz/foo.txt", an absolute path is returned. This is
43    intended to be useful for insets which encapsulate files/
44 */
45 string const browseRelFile(LyXView *lv, string const & filename,
46                            string const & refpath,
47                            string const & title,
48                            string const & pattern,
49                            std::pair<string,string> const & dir1 = std::make_pair(string(), string()),
50                            std::pair<string,string> const & dir2 = std::make_pair(string(), string()));
51
52
53 /// Returns a vector of units that can be used to create a valid LaTeX length.
54 std::vector<string> const getLatexUnits();
55
56
57 /** Functions to extract vectors of the first and second elems from a
58     vector<pair<A,B> >
59 */
60
61 namespace hide {
62
63 template<class Pair>
64 struct firster {
65         typedef typename Pair::first_type first_type;
66         first_type const & operator()(Pair const & p) { return p.first; }
67 };
68
69 template<class Pair>
70 struct seconder {
71         typedef typename Pair::second_type second_type;
72         second_type const & operator()(Pair const & p) { return p.second; }
73 };
74
75 }
76
77 ///
78 template<class Pair>
79 std::vector<typename Pair::first_type> const
80 getFirst(std::vector<Pair> const & pr)
81 {
82         std::vector<typename Pair::first_type> tmp(pr.size());
83         std::transform(pr.begin(), pr.end(), tmp.begin(),
84                        hide::firster<Pair>());
85         return tmp;
86 }
87
88 ///
89 template<class Pair>
90 std::vector<typename Pair::second_type> const
91 getSecond(std::vector<Pair> const & pr)
92 {
93         std::vector<typename Pair::second_type> tmp(pr.size());
94         std::transform(pr.begin(), pr.end(), tmp.begin(),
95                        hide::seconder<Pair>());
96         return tmp;
97 }
98
99
100 #endif // HELPERFUNCS_H