1 /* 2 3 PDF Writer printer driver. 4 5 Copyright (c) 2001, 2002 OpenBeOS. 6 Copyright (c) 2005 - 2008 Haiku. 7 8 Authors: 9 Philippe Houdoin 10 Simon Gauvin 11 Michael Pfeiffer 12 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: 19 20 The above copyright notice and this permission notice shall be included in all 21 copies or substantial portions of the Software. 22 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. 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 43 class BHandler; 44 class BMessage; 45 class BWindow; 46 47 48 #define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80) 49 50 51 BRect ScaleRect(const BRect& rect, float scale); 52 53 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); 63 64 65 template <class T> 66 class TList { 67 private: 68 BList fList; 69 typedef int (*sort_func)(const void*, const void*); 70 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**)); 80 }; 81 82 // TList 83 template<class T> 84 TList<T>::~TList() { 85 MakeEmpty(); 86 } 87 88 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); 94 } 95 fList.MakeEmpty(); 96 } 97 98 99 template<class T> 100 int32 TList<T>::CountItems() const { 101 return fList.CountItems(); 102 } 103 104 105 template<class T> 106 T* TList<T>::ItemAt(int32 index) const { 107 return (T*)fList.ItemAt(index); 108 } 109 110 111 template<class T> 112 void TList<T>::AddItem(T* p) { 113 fList.AddItem(p); 114 } 115 116 template<class T> 117 T* TList<T>::RemoveItem(int i) { 118 return (T*)fList.RemoveItem(i); 119 } 120 121 122 template<class T> 123 T* TList<T>::Items() { 124 return (T*)fList.Items(); 125 } 126 127 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); 132 } 133 134 #endif // _PRINT_UTILS_H_ 135