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