Bumped copyright dates for 2013
[barry.git] / desktop / src / util.h
blob36656449c3493da7912ea623ace84ed4818e6975
1 ///
2 /// \file util.h
3 /// Utility functions specific to Barry Desktop
4 ///
6 /*
7 Copyright (C) 2009-2013, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRYDESKTOP_UTIL_H__
23 #define __BARRYDESKTOP_UTIL_H__
25 #include <wx/wx.h>
26 #include <barry/barry.h>
28 #define BUTTON_STATE_NORMAL 0
29 #define BUTTON_STATE_FOCUS 1
30 #define BUTTON_STATE_PUSHED 2
32 // exception class for DrawButtonLabel() function below
33 class DrawButtonLabelError : public std::runtime_error
35 public:
36 DrawButtonLabelError(const std::string &msg)
37 : std::runtime_error(msg)
42 template <class IteratorT, class StrFn>
43 int GetMaxWidth(wxWindow *win, IteratorT begin, IteratorT end, StrFn sfn)
45 int max_width = 0;
46 for( ; begin != end(); ++begin ) {
47 int this_width = 0;
48 int this_height = 0;
49 win->GetTextExtent(wxString(sfn(*begin).c_str(), wxConvUTF8),
50 &this_width, &this_height);
52 max_width = std::max(max_width, this_width);
55 return max_width;
58 const wxArrayString& GetButtonLabels();
59 std::string GetBaseFilename(const std::string &filename);
60 wxString GetImageFilename(const wxString &filename);
61 wxString GetButtonFilename(int id, int state);
62 wxString GetButtonLabel(int id);
63 bool IsButtonEnabled(int id);
64 class wxDatePickerCtrl;
65 void MakeDateRecent(bool checked, wxDatePickerCtrl *picker);
67 bool IsParsable(const std::string &dbname);
68 bool IsBuildable(const std::string &dbname);
70 void DrawButtonLabelDC(wxDC &dc, const wxBitmap &bmp, const wxString &label,
71 wxFont &font, const wxColour &textfg,
72 int left, int top, int right, int bottom);
74 // Determine parsable classes via template specialization
75 template <class RecordT>
76 inline bool IsParsable()
78 return false;
80 #undef HANDLE_PARSER
81 #define HANDLE_PARSER(dbname) \
82 template <> \
83 inline bool IsParsable<Barry::dbname>() \
84 { \
85 return true; \
87 ALL_KNOWN_PARSER_TYPES
89 // Determine buildable classes via template specialization
90 template <class RecordT>
91 inline bool IsBuildable()
93 return false;
95 #undef HANDLE_BUILDER
96 #define HANDLE_BUILDER(dbname) \
97 template <> \
98 inline bool IsBuildable<Barry::dbname>() \
99 { \
100 return true; \
102 ALL_KNOWN_BUILDER_TYPES
104 #endif