Make UEFI boot-platform build again
[haiku.git] / headers / libs / print / libprint / PrintUtils.h
blob674290ffad0cd006c2bdde1ee67874fb5b52f716
1 /*
3 PDF Writer printer driver.
5 Copyright (c) 2001, 2002 OpenBeOS.
6 Copyright (c) 2005 - 2008 Haiku.
8 Authors:
9 Philippe Houdoin
10 Simon Gauvin
11 Michael Pfeiffer
13 Permission is hereby granted, free of charge, to any person obtaining a copy of
14 this software and associated documentation files (the "Software"), to deal in
15 the Software without restriction, including without limitation the rights to
16 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17 of the Software, and to permit persons to whom the Software is furnished to do
18 so, subject to the following conditions:
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29 THE SOFTWARE.
33 #ifndef _PRINT_UTILS_H_
34 #define _PRINT_UTILS_H_
37 #include <List.h>
38 #include <MessageFilter.h>
39 #include <String.h>
40 #include <Rect.h>
43 class BHandler;
44 class BMessage;
45 class BWindow;
48 #define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80)
51 BRect ScaleRect(const BRect& rect, float scale);
54 // set or replace a value in a BMessage
55 void SetBool(BMessage* msg, const char* name, bool value);
56 void SetFloat(BMessage* msg, const char* name, float value);
57 void SetInt32(BMessage* msg, const char* name, int32 value);
58 void SetString(BMessage* msg, const char* name, const char* value);
59 void SetRect(BMessage* msg, const char* name, const BRect& rect);
60 void SetString(BMessage* msg, const char* name, const BString& value);
61 void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL,
62 const char* includeList[] = NULL, bool overwrite = true);
65 template <class T>
66 class TList {
67 private:
68 BList fList;
69 typedef int (*sort_func)(const void*, const void*);
71 public:
72 virtual ~TList();
73 void MakeEmpty();
74 int32 CountItems() const;
75 T* ItemAt(int32 index) const;
76 void AddItem(T* p);
77 T* RemoveItem(int i);
78 T* Items();
79 void SortItems(int (*comp)(const T**, const T**));
82 // TList
83 template<class T>
84 TList<T>::~TList() {
85 MakeEmpty();
89 template<class T>
90 void TList<T>::MakeEmpty() {
91 const int32 n = CountItems();
92 for (int i = 0; i < n; i++) {
93 delete ItemAt(i);
95 fList.MakeEmpty();
99 template<class T>
100 int32 TList<T>::CountItems() const {
101 return fList.CountItems();
105 template<class T>
106 T* TList<T>::ItemAt(int32 index) const {
107 return (T*)fList.ItemAt(index);
111 template<class T>
112 void TList<T>::AddItem(T* p) {
113 fList.AddItem(p);
116 template<class T>
117 T* TList<T>::RemoveItem(int i) {
118 return (T*)fList.RemoveItem(i);
122 template<class T>
123 T* TList<T>::Items() {
124 return (T*)fList.Items();
128 template<class T>
129 void TList<T>::SortItems(int (*comp)(const T**, const T**)) {
130 sort_func sort = (sort_func)comp;
131 fList.SortItems(sort);
134 #endif // _PRINT_UTILS_H_