1/* 2 3PDF Writer printer driver. 4 5Copyright (c) 2002 OpenBeOS. 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#ifndef DOCINFOWINDOW_H 32#define DOCINFOWINDOW_H 33 34 35#include "BlockingWindow.h" 36 37 38#include <String.h> 39 40 41class BBox; 42class BMenu; 43class BScrollView; 44class BTabView; 45class BTextControl; 46class BView; 47 48 49#define HAVE_FULLVERSION_PDF_LIB 0 50 51 52#if HAVE_FULLVERSION_PDF_LIB 53 54class PermissionLabels { 55public: 56 PermissionLabels(const char* name, const char* pdfName) 57 : fName(name), fPDFName(pdfName) { } 58 59 const char* GetName() const { return fName; } 60 const char* GetPDFName() const { return fName; } 61 62private: 63 const char* fName; 64 const char* fPDFName; 65}; 66 67 68class Permission { 69public: 70 Permission() 71 : fLabels(NULL), fAllowed(true) { } 72 73 const char* GetName() const { return fLabels->GetName(); } 74 const char* GetPDFName() const { return fLabels->GetPDFName(); } 75 bool IsAllowed() const { return fAllowed; } 76 77 void SetLabels(const PermissionLabels* labels) { fLabels = labels; } 78 void SetAllowed(bool allowed) { fAllowed = allowed; } 79 80private: 81 const PermissionLabels* fLabels; 82 bool fAllowed; 83}; 84 85class Permissions { 86public: 87 Permissions(); 88 89 // accessors 90 Permission* At(int32 i) { return &fPermissions[i]; } 91 int32 Length() const { return fNofPermissions; } 92 93 // decode/encode pdflib permission string 94 void Decode(const char* s); 95 void Encode(BString& permissions); 96 97private: 98 Permission* fPermissions; 99 int32 fNofPermissions; 100}; 101 102#endif // HAVE_FULLVERSION_PDF_LIB 103 104 105class DocInfoWindow : public HWindow 106{ 107 typedef HWindow inherited; 108public: 109 DocInfoWindow(BMessage *doc_info); 110 111 virtual void Quit(); 112 virtual bool QuitRequested(); 113 virtual void MessageReceived(BMessage *message); 114 virtual void FrameResized(float newWidth, float newHeight); 115 116 enum { 117 OK_MSG = 'ok__', 118 CANCEL_MSG = 'cncl', 119 ADD_KEY_MSG = 'add_', 120 REMOVE_KEY_MSG = 'rmov', 121 DEFAULT_KEY_MSG = 'dflt', 122 }; 123 124private: 125 BMessage* _DocInfo() { return fDocInfo; } 126 void _SetupDocInfoView(BBox* panel); 127 void _BuildTable(const BMessage& fromDocInfo); 128 void _AdjustScrollBar(float controlHeight, 129 float fieldsHeight); 130 BTextControl* _AddFieldToTable(BRect rect, const char* name, 131 const char* value); 132 void _ReadFieldsFromTable(BMessage& docInfo); 133 134 void _RemoveKey(BMessage* msg); 135 bool _IsKeyValid(const char *key) const; 136 void _AddKey(BMessage* msg, bool textControl); 137 138 void _EmptyKeyList(); 139 140#if HAVE_FULLVERSION_PDF_LIB 141 void _SetupPasswordView(BBox* panel); 142 void _SetupPermissionsView(BBox* panel); 143 BBox* _CreateTabPanel(BTabView* tabView, const char* label); 144 BTextControl* _AddPasswordControl(BRect r, BView* panel, 145 const char* name, const char* label); 146 147 void _ReadPasswords(); 148 void _ReadPermissions(); 149#endif // HAVE_FULLVERSION_PDF_LIB 150 151private: 152 BMessage* fDocInfo; // owned by parent window 153 BView* fTable; 154 BScrollView* fTableScrollView; 155 BMenu* fKeyList; 156 157#if HAVE_FULLVERSION_PDF_LIB 158 BTextControl* fMasterPassword; 159 BTextControl* fUserPassword; 160 Permissions fPermissions; 161#endif // HAVE_FULLVERSION_PDF_LIB 162}; 163 164#endif 165