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