#ifndef _PRINT_UTILS_H_
#define _PRINT_UTILS_H_
#include <List.h>
#include <MessageFilter.h>
#include <String.h>
#include <Rect.h>
class BHandler;
class BMessage;
class BWindow;
#define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80)
BRect ScaleRect(const BRect& rect, float scale);
void SetBool(BMessage* msg, const char* name, bool value);
void SetFloat(BMessage* msg, const char* name, float value);
void SetInt32(BMessage* msg, const char* name, int32 value);
void SetString(BMessage* msg, const char* name, const char* value);
void SetRect(BMessage* msg, const char* name, const BRect& rect);
void SetString(BMessage* msg, const char* name, const BString& value);
void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL,
const char* includeList[] = NULL, bool overwrite = true);
template <class T>
class TList {
private:
BList fList;
typedef int (*sort_func)(const void*, const void*);
public:
virtual ~TList();
void MakeEmpty();
int32 CountItems() const;
T* ItemAt(int32 index) const;
void AddItem(T* p);
T* RemoveItem(int i);
T* Items();
void SortItems(int (*comp)(const T**, const T**));
};
template<class T>
TList<T>::~TList() {
MakeEmpty();
}
template<class T>
void TList<T>::MakeEmpty() {
const int32 n = CountItems();
for (int i = 0; i < n; i++) {
delete ItemAt(i);
}
fList.MakeEmpty();
}
template<class T>
int32 TList<T>::CountItems() const {
return fList.CountItems();
}
template<class T>
T* TList<T>::ItemAt(int32 index) const {
return (T*)fList.ItemAt(index);
}
template<class T>
void TList<T>::AddItem(T* p) {
fList.AddItem(p);
}
template<class T>
T* TList<T>::RemoveItem(int i) {
return (T*)fList.RemoveItem(i);
}
template<class T>
T* TList<T>::Items() {
return (T*)fList.Items();
}
template<class T>
void TList<T>::SortItems(int (*comp)(const T**, const T**)) {
sort_func sort = (sort_func)comp;
fList.SortItems(sort);
}
#endif