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