Some printing related improvements:
* libprint based drivers can now show a preview window and show progress window while printing contributed in part by Hartmut Reh. * Libprint and PCL6 driver bug fixes. * Code clean-up (removed code duplications, coding style, copyright text) Builds under Linux. Not tested under BeOS. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19882 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -36,8 +36,8 @@
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifndef BEUTILS_H
|
||||
#define BEUTILS_H
|
||||
#ifndef _BE_UTILS_H
|
||||
#define _BE_UTILS_H
|
||||
|
||||
#include <FindDirectory.h>
|
||||
#include <Path.h>
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
// mimetype from sender
|
||||
bool MimeTypeForSender(BMessage* sender, BString& mime);
|
||||
// adds fields to message or replaces existing fields
|
||||
void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL);
|
||||
void AddFields(BMessage* to, const BMessage* from, const char* excludeList[] = NULL, const char* includeList[] = NULL, bool overwrite = true);
|
||||
// load bitmap from application resources
|
||||
BBitmap* LoadBitmap(const char* name, uint32 type_code = B_TRANSLATOR_BITMAP);
|
||||
// convert bitmap to picture; view must be attached to a window!
|
||||
|
||||
@@ -27,6 +27,9 @@ THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _PRINT_JOB_READER_H
|
||||
#define _PRINT_JOB_READER_H
|
||||
|
||||
#include <File.h>
|
||||
#include <Message.h>
|
||||
|
||||
@@ -80,3 +83,5 @@ public:
|
||||
status_t GetPage(int no, PrintJobPage& pjp);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@ THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef PRINT_TRANSPORT_H
|
||||
#define PRINT_TRANSPORT_H
|
||||
#ifndef _PRINT_TRANSPORT_H
|
||||
#define _PRINT_TRANSPORT_H
|
||||
|
||||
#include <image.h>
|
||||
#include <DataIO.h>
|
||||
|
||||
@@ -27,8 +27,8 @@ THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef PRINT_TRANSPORT_ADD_ON_H
|
||||
#define PRINT_TRANSPORT_ADD_ON_H
|
||||
#ifndef _PRINT_TRANSPORT_ADD_ON_H
|
||||
#define _PRINT_TRANSPORT_ADD_ON_H
|
||||
|
||||
#include <image.h>
|
||||
#include <DataIO.h>
|
||||
@@ -38,4 +38,5 @@ THE SOFTWARE.
|
||||
// to be implemented by the transport add-on
|
||||
extern "C" BDataIO* instantiate_transport(BDirectory* printer, BMessage* msg);
|
||||
|
||||
#endif PRINT_TRANSPORT_ADD_ON_H
|
||||
#endif
|
||||
|
||||
|
||||
@@ -82,4 +82,4 @@ public:
|
||||
virtual void SetFontFace(int32 flags);
|
||||
};
|
||||
|
||||
#endif _TEMPLATE_H
|
||||
#endif // _TEMPLATE_H
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "PrintProcess.h"
|
||||
#include "SpoolMetaData.h"
|
||||
#include "Transport.h"
|
||||
#include "StatusWindow.h"
|
||||
|
||||
class BView;
|
||||
class BBitmap;
|
||||
@@ -26,7 +27,11 @@ class GraphicsDriver {
|
||||
public:
|
||||
GraphicsDriver(BMessage *, PrinterData *, const PrinterCap *);
|
||||
virtual ~GraphicsDriver();
|
||||
const JobData *getJobData(BFile *spoolFile);
|
||||
BMessage *takeJob(BFile *spool, uint32 flags = 0);
|
||||
static BPoint getScale(int32 nup, BRect physicalRect, float scaling);
|
||||
static BPoint getOffset(int32 nup, int index, JobData::Orientation orientation, const BPoint *scale,
|
||||
BRect scaledPhysicalRect, BRect scaledPrintableRect, BRect physicalRect);
|
||||
|
||||
protected:
|
||||
virtual bool startDoc();
|
||||
@@ -58,7 +63,7 @@ protected:
|
||||
GraphicsDriver &operator = (const GraphicsDriver &);
|
||||
|
||||
private:
|
||||
void setupData(BFile *file, long page_count);
|
||||
bool setupData(BFile *file);
|
||||
void setupBitmap();
|
||||
void cleanupData();
|
||||
void cleanupBitmap();
|
||||
@@ -91,6 +96,9 @@ private:
|
||||
int fPixelDepth;
|
||||
int fBandCount;
|
||||
int fInternalCopies;
|
||||
|
||||
uint32 fPageCount;
|
||||
StatusWindow *fStatusWindow;
|
||||
};
|
||||
|
||||
inline const JobData *GraphicsDriver::getJobData() const
|
||||
|
||||
@@ -206,7 +206,10 @@ public:
|
||||
*/
|
||||
enum Color {
|
||||
kMonochrome = 1,
|
||||
kColor
|
||||
kColor,
|
||||
// Some PCL6 printers do not support compressed data
|
||||
// in color mode.
|
||||
kColorCompressionDisabled
|
||||
};
|
||||
|
||||
enum Settings {
|
||||
@@ -221,6 +224,7 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
bool fShowPreview;
|
||||
Paper fPaper;
|
||||
int32 fXRes;
|
||||
int32 fYRes;
|
||||
@@ -261,6 +265,9 @@ public:
|
||||
void load(BMessage *msg, const PrinterCap *cap, Settings settings);
|
||||
void save(BMessage *msg = NULL);
|
||||
|
||||
bool getShowPreview() const { return fShowPreview; }
|
||||
void setShowPreview(bool showPreview) { fShowPreview = showPreview; }
|
||||
|
||||
Paper getPaper() const { return fPaper; }
|
||||
void setPaper(Paper paper) { fPaper = paper; }
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ public:
|
||||
JobSetupView(BRect frame, JobData *job_data, PrinterData *printer_data, const PrinterCap *printer_cap);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void MessageReceived(BMessage *msg);
|
||||
bool UpdateJobData();
|
||||
bool UpdateJobData(bool showPreview);
|
||||
|
||||
private:
|
||||
void UpdateButtonEnabledState();
|
||||
|
||||
@@ -1,29 +1,139 @@
|
||||
/*
|
||||
* Preview.h
|
||||
* Copyright 1999-2000 Y.Takagi. All Rights Reserved.
|
||||
*/
|
||||
|
||||
//#define USE_PREVIEW_FOR_DEBUG
|
||||
Preview
|
||||
|
||||
#ifdef USE_PREVIEW_FOR_DEBUG
|
||||
#ifndef __PREVIEW_H
|
||||
#define __PREVIEW_H
|
||||
Copyright (c) 2002, 2003 OpenBeOS.
|
||||
Copyright (c) 2005 Haiku.
|
||||
|
||||
#include <Window.h>
|
||||
Author:
|
||||
Michael Pfeiffer
|
||||
Hartmut Reh
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
class PreviewWindow : public BWindow {
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include "PrintJobReader.h"
|
||||
#include "InterfaceUtils.h"
|
||||
|
||||
class PreviewPage {
|
||||
int32 fPage;
|
||||
int32 fNumberOfPictures;
|
||||
BPicture* fPictures;
|
||||
BPoint* fPoints;
|
||||
BRect* fRects;
|
||||
status_t fStatus;
|
||||
|
||||
public:
|
||||
PreviewWindow(BRect, const char *, BBitmap *);
|
||||
virtual bool QuitRequested();
|
||||
int Go();
|
||||
|
||||
protected:
|
||||
PreviewWindow(const PreviewWindow &);
|
||||
PreviewWindow &operator = (const PreviewWindow &);
|
||||
|
||||
private:
|
||||
long fSemaphore;
|
||||
PreviewPage(int32 page, PrintJobPage* pjp);
|
||||
~PreviewPage();
|
||||
status_t InitCheck() const;
|
||||
|
||||
int32 Page() const { return fPage; }
|
||||
void Draw(BView* view);
|
||||
};
|
||||
|
||||
class PreviewView : public BView {
|
||||
int32 fPage;
|
||||
int32 fZoom;
|
||||
PrintJobReader fReader;
|
||||
int32 fNumberOfPagesPerPage;
|
||||
int32 fNumberOfPages; // physical pages
|
||||
bool fReverse;
|
||||
BRect fPageRect;
|
||||
JobData::Orientation fOrientation;
|
||||
JobData::PageSelection fPageSelection;
|
||||
PreviewPage* fCachedPage;
|
||||
|
||||
float ZoomFactor() const;
|
||||
BRect PageRect() const;
|
||||
BRect PrintableRect() const;
|
||||
int32 GetPageNumber(int32 index) const;
|
||||
|
||||
public:
|
||||
PreviewView(BFile* jobFile, BRect rect);
|
||||
~PreviewView();
|
||||
status_t InitCheck() const;
|
||||
|
||||
BRect ViewRect() const;
|
||||
|
||||
bool IsPageLoaded(int32 page) const;
|
||||
bool IsPageValid() const;
|
||||
void LoadPage(int32 page);
|
||||
void DrawPageFrame(BRect r);
|
||||
void DrawPage(BRect r);
|
||||
void Draw(BRect r);
|
||||
void FrameResized(float width, float height);
|
||||
|
||||
void FixScrollbars();
|
||||
|
||||
bool ShowsFirstPage() const;
|
||||
bool ShowsLastPage() const;
|
||||
int CurrentPage() const { return fPage + 1; }
|
||||
int NumberOfPages() const;
|
||||
void ShowNextPage();
|
||||
void ShowPrevPage();
|
||||
void ShowFirstPage();
|
||||
void ShowLastPage();
|
||||
void ShowFindPage(int page);
|
||||
|
||||
bool CanZoomIn() const;
|
||||
bool CanZoomOut() const;
|
||||
void ZoomIn();
|
||||
void ZoomOut();
|
||||
};
|
||||
|
||||
class PreviewWindow : public BlockingWindow {
|
||||
BButton *fFirst;
|
||||
BButton *fNext;
|
||||
BButton *fPrev;
|
||||
BButton *fLast;
|
||||
BButton *fZoomIn;
|
||||
BButton *fZoomOut;
|
||||
BTextControl *fPageNumber;
|
||||
BStringView *fPageText;
|
||||
PreviewView *fPreview;
|
||||
BScrollView *fPreviewScroller;
|
||||
float fButtonBarHeight;
|
||||
|
||||
enum {
|
||||
MSG_FIRST_PAGE = 'pwfp',
|
||||
MSG_NEXT_PAGE = 'pwnp',
|
||||
MSG_PREV_PAGE = 'pwpp',
|
||||
MSG_LAST_PAGE = 'pwlp',
|
||||
MSG_FIND_PAGE = 'pwsp',
|
||||
MSG_ZOOM_IN = 'pwzi',
|
||||
MSG_ZOOM_OUT = 'pwzo',
|
||||
MSG_PRINT_JOB = 'pwpj',
|
||||
MSG_CANCEL_JOB = 'pwcj',
|
||||
};
|
||||
|
||||
void ResizeToPage(bool allowShrinking = false);
|
||||
void UpdateControls();
|
||||
|
||||
typedef BlockingWindow inherited;
|
||||
|
||||
public:
|
||||
PreviewWindow(BFile* jobFile, bool showOkAndCancelButtons = false);
|
||||
status_t InitCheck() const { return fPreview->InitCheck(); }
|
||||
void MessageReceived(BMessage* m);
|
||||
status_t Go();
|
||||
};
|
||||
|
||||
#endif /* __PREVIEW_H */
|
||||
#endif /* USE_PREVIEW_FOR_DEBUG */
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
StatusWindow.h
|
||||
Copyright 2005 Dr.H.Reh. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef STATUS_WINDOW_H
|
||||
#define STATUS_WINDOW_H
|
||||
|
||||
#ifndef _WINDOW_H
|
||||
#include <Window.h>
|
||||
#endif
|
||||
|
||||
#include <String.h>
|
||||
|
||||
|
||||
class StatusWindow : public BWindow
|
||||
{
|
||||
public:
|
||||
StatusWindow(bool oddPages, bool evenPages,
|
||||
uint32 firstPage, uint32 numPages,
|
||||
uint32 docCopies, uint32 nup);
|
||||
~StatusWindow(void);
|
||||
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
void ResetStatusBar(void);
|
||||
bool UpdateStatusBar(uint32 page, uint32 copy);
|
||||
void SetPageCopies(uint32 copies);
|
||||
|
||||
private:
|
||||
BView *fStatusView;
|
||||
BStatusBar *fStatusBar;
|
||||
BButton *fCancelButton;
|
||||
BButton *fHideButton;
|
||||
bool fCancelBar;
|
||||
bool fDocumentCopy;
|
||||
uint32 fNops;
|
||||
uint32 fFirstPage;
|
||||
uint32 fCopies;
|
||||
uint32 fDocCopies;
|
||||
float fStatusDelta;
|
||||
float fDelta;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,148 @@
|
||||
/*
|
||||
|
||||
InterfaceUtils.cpp
|
||||
|
||||
Copyright (c) 2002 OpenBeOS.
|
||||
|
||||
Author:
|
||||
Michael Pfeiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _INTERFACE_UTILS_H
|
||||
#define _INTERFACE_UTILS_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
|
||||
// --------------------------------------------------
|
||||
class HWindow : public BWindow
|
||||
{
|
||||
protected:
|
||||
void Init(uint32 escape_msg);
|
||||
|
||||
public:
|
||||
typedef BWindow inherited;
|
||||
|
||||
HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED);
|
||||
HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED);
|
||||
|
||||
virtual void MessageReceived(BMessage* m);
|
||||
virtual void AboutRequested();
|
||||
virtual const char* AboutText() const { return NULL; }
|
||||
};
|
||||
|
||||
// --------------------------------------------------
|
||||
class BlockingWindow : public HWindow
|
||||
{
|
||||
public:
|
||||
BlockingWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED);
|
||||
BlockingWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED);
|
||||
~BlockingWindow();
|
||||
|
||||
bool QuitRequested();
|
||||
// Quit() is called by child class with result code
|
||||
void Quit(status_t result);
|
||||
// Show window and wait for it to quit, returns result code
|
||||
virtual status_t Go();
|
||||
// Or quit window e.g. something went wrong in constructor
|
||||
void Quit();
|
||||
// Sets the result that is returned when the user closes the window.
|
||||
// Default is B_OK.
|
||||
void SetUserQuitResult(status_t result);
|
||||
|
||||
typedef HWindow inherited;
|
||||
|
||||
private:
|
||||
void Init(const char* title);
|
||||
|
||||
status_t fUserQuitResult;
|
||||
bool fReadyToQuit;
|
||||
sem_id fExitSem;
|
||||
status_t* fResult;
|
||||
};
|
||||
|
||||
// --------------------------------------------------
|
||||
class TextView : public BTextView
|
||||
{
|
||||
public:
|
||||
typedef BTextView inherited;
|
||||
|
||||
TextView(BRect frame,
|
||||
const char *name,
|
||||
BRect textRect,
|
||||
uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
|
||||
TextView(BRect frame,
|
||||
const char *name,
|
||||
BRect textRect,
|
||||
const BFont *font, const rgb_color *color,
|
||||
uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
|
||||
void KeyDown(const char *bytes, int32 numBytes);
|
||||
void MakeFocus(bool focus = true);
|
||||
void Draw(BRect r);
|
||||
};
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
class TextControl : public BView
|
||||
{
|
||||
BStringView *fLabel;
|
||||
TextView *fText;
|
||||
public:
|
||||
TextControl(BRect frame,
|
||||
const char *name,
|
||||
const char *label,
|
||||
const char *initial_text,
|
||||
BMessage *message,
|
||||
uint32 rmask = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||
const char *Label() { return fLabel->Text(); }
|
||||
const char *Text() { return fText->Text(); }
|
||||
void MakeFocus(bool focus = true) { fText->MakeFocus(focus); }
|
||||
void ConvertToParent(BView* parent, BView* child, BRect &rect);
|
||||
void FocusSetTo(BView* child);
|
||||
};
|
||||
|
||||
|
||||
// --------------------------------------------------
|
||||
class Table : public BView
|
||||
{
|
||||
public:
|
||||
typedef BView inherited;
|
||||
|
||||
Table(BRect frame, const char *name, uint32 rmode, uint32 flags);
|
||||
void ScrollTo(BPoint p);
|
||||
};
|
||||
|
||||
class DragListView : public BListView
|
||||
{
|
||||
public:
|
||||
DragListView(BRect frame, const char *name,
|
||||
list_view_type type = B_SINGLE_SELECTION_LIST,
|
||||
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS);
|
||||
bool InitiateDrag(BPoint point, int32 index, bool wasSelected);
|
||||
};
|
||||
|
||||
#endif
|
||||
+3
-3
@@ -118,8 +118,8 @@ THE SOFTWARE.
|
||||
kUnitPoint, 1 point/point
|
||||
*/
|
||||
|
||||
#ifndef MARGIN_VIEW_H
|
||||
#define MARGIN_VIEW_H
|
||||
#ifndef _MARGIN_VIEW_H
|
||||
#define _MARGIN_VIEW_H
|
||||
|
||||
#include <InterfaceKit.h>
|
||||
#include <Looper.h>
|
||||
@@ -222,4 +222,4 @@ public:
|
||||
void MessageReceived(BMessage *msg);
|
||||
};
|
||||
|
||||
#endif //MARGIN_VIEW_H
|
||||
#endif // _MARGIN_VIEW_H
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
|
||||
PDF Writer printer driver.
|
||||
|
||||
Copyright (c) 2001, 2002 OpenBeOS.
|
||||
Copyright (c) 2005 Haiku.
|
||||
|
||||
Authors:
|
||||
Philippe Houdoin
|
||||
Simon Gauvin
|
||||
Michael Pfeiffer
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _UTILS_H
|
||||
#define _UTILS_H
|
||||
|
||||
#include <Window.h>
|
||||
#include <Message.h>
|
||||
#include <MessageFilter.h>
|
||||
|
||||
|
||||
void AddString(BMessage* m, const char* name, const char* value);
|
||||
|
||||
// set or replace a value in a BMessage
|
||||
void SetRect(BMessage* msg, const char* name, BRect rect);
|
||||
void SetFloat(BMessage* msg, const char* name, float value);
|
||||
void SetInt32(BMessage* msg, const char* name, int32 value);
|
||||
|
||||
class EscapeMessageFilter : public BMessageFilter
|
||||
{
|
||||
private:
|
||||
BWindow *fWindow;
|
||||
int32 fWhat;
|
||||
|
||||
public:
|
||||
EscapeMessageFilter(BWindow *window, int32 what);
|
||||
filter_result Filter(BMessage *msg, BHandler **target);
|
||||
};
|
||||
|
||||
|
||||
#define BEGINS_CHAR(byte) ((byte & 0xc0) != 0x80)
|
||||
|
||||
|
||||
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**));
|
||||
};
|
||||
|
||||
// TList
|
||||
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
|
||||
Reference in New Issue
Block a user