* remove all classes that where only used in pdf writer from InterfaceUtils

* get rid of three of them, i don't know why they where implemented in the first place

* fix broken scrollbar adjustment
* cleanup DocInfoWindow.h and DocInfoWindow.cpp
* make the window resizable and get rid of the tabview



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26690 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2008-07-30 20:32:10 +00:00
parent b99521f213
commit 1bf69d91a3
8 changed files with 721 additions and 808 deletions
+49 -98
View File
@@ -26,136 +26,87 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#ifndef _INTERFACE_UTILS_H #ifndef _INTERFACE_UTILS_H
#define _INTERFACE_UTILS_H #define _INTERFACE_UTILS_H
#include <InterfaceKit.h>
#include <AppDefs.h>
#include <MessageFilter.h> #include <MessageFilter.h>
#include <Window.h>
class BHandler;
class BMessage;
class EscapeMessageFilter : public BMessageFilter class EscapeMessageFilter : public BMessageFilter
{ {
private:
BWindow *fWindow;
int32 fWhat;
public: public:
EscapeMessageFilter(BWindow *window, int32 what); EscapeMessageFilter(BWindow *window, int32 what);
filter_result Filter(BMessage *msg, BHandler **target); filter_result Filter(BMessage *msg, BHandler **target);
private:
BWindow* fWindow;
int32 fWhat;
}; };
class HWindow : public BWindow class HWindow : public BWindow
{ {
protected:
void Init(uint32 escape_msg);
public:
typedef BWindow inherited; typedef BWindow inherited;
public:
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 ~HWindow() {}
HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace = B_CURRENT_WORKSPACE, uint32 escape_msg = B_QUIT_REQUESTED); virtual void MessageReceived(BMessage* m);
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 AboutRequested();
virtual const char* AboutText() const { return NULL; }
virtual void MessageReceived(BMessage* m); protected:
virtual void AboutRequested(); void Init(uint32 escape_msg);
virtual const char* AboutText() const { return NULL; }
}; };
class BlockingWindow : public HWindow class BlockingWindow : public HWindow
{ {
typedef HWindow inherited;
public: 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,
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); window_type type, uint32 flags,
~BlockingWindow(); 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);
virtual ~BlockingWindow();
bool QuitRequested(); virtual bool QuitRequested();
// Quit() is called by child class with result code // Quit() is called by child class with result code
void Quit(status_t result); void Quit(status_t result);
// Show window and wait for it to quit, returns result code // Show window and wait for it to quit, returns result code
virtual status_t Go(); virtual status_t Go();
// Or quit window e.g. something went wrong in constructor // Or quit window e.g. something went wrong in constructor
void Quit(); virtual void Quit();
// Sets the result that is returned when the user closes the window. // Sets the result that is returned when the user closes the window.
// Default is B_OK. // Default is B_OK.
void SetUserQuitResult(status_t result); void SetUserQuitResult(status_t result);
typedef HWindow inherited;
private: private:
void Init(const char* title); void Init(const char* title);
status_t fUserQuitResult; private:
bool fReadyToQuit; status_t fUserQuitResult;
sem_id fExitSem; bool fReadyToQuit;
status_t* fResult; 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 #endif
@@ -27,231 +27,95 @@ THE SOFTWARE.
*/ */
#include <InterfaceKit.h>
#include <SupportKit.h>
#include "DocInfoWindow.h" #include "DocInfoWindow.h"
#include "InterfaceUtils.h" #include "PrintUtils.h"
#include <Box.h>
#include <Button.h>
#include <Menu.h>
#include <MenuItem.h>
#include <MenuField.h>
#include <Message.h>
#include <Screen.h>
#include <ScrollView.h>
#include <TabView.h>
#include <TextControl.h>
#include <ctype.h> #include <ctype.h>
#if HAVE_FULLVERSION_PDF_LIB
// pdflib 5.x supports password protection and permissions in the commercial version only!
static const PermissionLabels gPermissionLabels[] = {
PermissionLabels("Prevent printing the file.", "noprint"),
PermissionLabels("Prevent making any changes.", "nomodify"),
PermissionLabels("Prevent copying or extracting text or graphics.", "nocopy"),
PermissionLabels("Prevent adding or changing comments or form fields.", "noannots"),
PermissionLabels("Prevent form field filling.", "noforms"),
PermissionLabels("Prevent extracting text of graphics.", "noaccessible"),
PermissionLabels("Prevent inserting, deleting, or rotating pages and creating bookmarks and thumbnails, even if nomodify hasn't been specified", "noassemble"),
PermissionLabels("Prevent high-resolution printing.", "nohiresprint")
};
// Implementation of Permissions // #pragma mark -- DocInfoWindow
Permissions::Permissions() {
fNofPermissions = sizeof(gPermissionLabels)/sizeof(PermissionLabels);
fPermissions = new Permission[fNofPermissions];
for (int i = 0; i < fNofPermissions; i ++) {
fPermissions[i].SetLabels(&gPermissionLabels[i]);
}
}
void Permissions::Decode(const char* s) { DocInfoWindow::DocInfoWindow(BMessage *docInfo)
for (int i = 0; i < fNofPermissions; i ++) { : HWindow(BRect(0, 0, 400, 250), "Document Information", B_TITLED_WINDOW_LOOK,
bool allowed = strstr(s, At(i)->GetPDFName()) == NULL; B_MODAL_APP_WINDOW_FEEL, B_NOT_MINIMIZABLE),
At(i)->SetAllowed(allowed); fDocInfo(docInfo)
}
}
void Permissions::Encode(BString* s) {
bool first = true;
s->Truncate(0);
for (int i = 0; i < fNofPermissions; i ++) {
if (!At(i)->IsAllowed()) {
if (first) {
first = false;
} else {
s->Append(" ");
}
s->Append(At(i)->GetPDFName());
}
}
}
#endif
// --------------------------------------------------
DocInfoWindow::DocInfoWindow(BMessage *doc_info)
: HWindow(BRect(0,0,400,220), "Document Information", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_RESIZABLE | B_NOT_MINIMIZABLE |
B_NOT_ZOOMABLE)
{ {
// ---- Ok, build a default page setup user interface BRect bounds(Bounds());
BRect r; BView *background = new BView(bounds, "bachground", B_FOLLOW_ALL, B_WILL_DRAW);
// BBox *panel; background->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BTabView *tabView; AddChild(background);
BString permissions;
fDocInfo = doc_info; bounds.InsetBy(10.0, 10.0);
BButton *button = new BButton(bounds, "ok", "OK", new BMessage(OK_MSG),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
background->AddChild(button);
button->ResizeToPreferred();
button->MoveTo(bounds.right - button->Bounds().Width(),
bounds.bottom - button->Bounds().Height());
BRect buttonFrame(button->Frame());
button = new BButton(buttonFrame, "cancel", "Cancel", new BMessage(CANCEL_MSG),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
background->AddChild(button);
button->ResizeToPreferred();
button->MoveTo(buttonFrame.left - (button->Bounds().Width() + 10.0),
buttonFrame.top);
bounds.bottom = buttonFrame.top - 10.0;
#if HAVE_FULLVERSION_PDF_LIB #if HAVE_FULLVERSION_PDF_LIB
if (DocInfo()->FindString("permissions", &permissions) == B_OK) { BString permissions;
if (_DocInfo()->FindString("permissions", &permissions) == B_OK)
fPermissions.Decode(permissions.String()); fPermissions.Decode(permissions.String());
}
BTabView *tabView = new BTabView(bounds, "tabView");
_SetupDocInfoView(_CreateTabPanel(tabView, "Information"));
_SetupPasswordView(_CreateTabPanel(tabView, "Password"));
_SetupPermissionsView(_CreateTabPanel(tabView, "Permissions"));
background->AddChild(tabView);
#else
BBox* panel = new BBox(bounds, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER);
_SetupDocInfoView(panel);
background->AddChild(panel);
#endif #endif
r = Bounds(); if (fTable->ChildAt(0))
tabView = new BTabView(r, "tab_view"); fTable->ChildAt(0)->MakeFocus();
SetupDocInfoView(CreateTabPanel(tabView, "Information")); BRect winFrame(Frame());
#if HAVE_FULLVERSION_PDF_LIB BRect screenFrame(BScreen().Frame());
SetupPasswordView(CreateTabPanel(tabView, "Password")); MoveTo((screenFrame.right - winFrame.right) / 2,
SetupPermissionsView(CreateTabPanel(tabView, "Permissions")); (screenFrame.bottom - winFrame.bottom) / 2);
#endif
AddChild(tabView); SetSizeLimits(400.0, 10000.0, 250.0, 10000.0);
MoveTo(320, 320);
if (fTable->ChildAt(0)) fTable->ChildAt(0)->MakeFocus();
}
BBox*
DocInfoWindow::CreateTabPanel(BTabView* tabView, const char* label) {
BRect r(tabView->Bounds());
r.bottom -= tabView->TabHeight();
// create tab panel
BBox* panel = new BBox(r, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
B_PLAIN_BORDER);;
// add panel to tab
BTab* tab = new BTab();
tabView->AddTab(panel, tab);
tab->SetLabel(label);
return panel;
} }
void void
DocInfoWindow::SetupButtons(BBox* panel) { DocInfoWindow::Quit()
BButton *button; {
float x, y, w, h; _EmptyKeyList();
BRect r(panel->Bounds()); inherited::Quit();
// add a "OK" button, and make it default
button = new BButton(r, NULL, "OK", new BMessage(OK_MSG),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->ResizeToPreferred();
button->GetPreferredSize(&w, &h);
x = r.right - w - 8;
y = r.bottom - h - 8;
button->MoveTo(x, y);
panel->AddChild(button);
// add a "Cancel button
button = new BButton(r, NULL, "Cancel", new BMessage(CANCEL_MSG),
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
button->GetPreferredSize(&w, &h);
button->ResizeToPreferred();
button->MoveTo(x - w - 8, y);
panel->AddChild(button);
// add a separator line...
BBox * line = new BBox(BRect(r.left, y - 9, r.right, y - 8), NULL,
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM );
panel->AddChild(line);
}
void
DocInfoWindow::SetupDocInfoView(BBox* panel) {
// BButton *button;
// float x, y, w, h;
BRect r(panel->Bounds());
// add list of keys
fKeyList = new BMenu("Delete Key");
BMenuField *menu = new BMenuField(BRect(0, 0, 90, 10), "delete", "", fKeyList);
menu->SetDivider(0);
panel->AddChild(menu);
// add table for text controls (document info key and value)
fTable = new Table(BRect(r.left+5, r.top+5, r.right-5-B_V_SCROLL_BAR_WIDTH, r.bottom-5-B_H_SCROLL_BAR_HEIGHT-30-20), "table", B_FOLLOW_ALL, B_WILL_DRAW);
fTable->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
// add table to ScrollView
fTableScrollView = new BScrollView("scroll_table", fTable, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true);
panel->AddChild(fTableScrollView);
// position list of keys
menu->MoveTo(5, fTableScrollView->Frame().bottom+2);
BMenu* defaultKeys = new BMenu("Default Keys");
defaultKeys->AddItem(new BMenuItem("Title", new BMessage(DEFAULT_KEY_MSG)));
defaultKeys->AddItem(new BMenuItem("Author", new BMessage(DEFAULT_KEY_MSG)));
defaultKeys->AddItem(new BMenuItem("Subject", new BMessage(DEFAULT_KEY_MSG)));
defaultKeys->AddItem(new BMenuItem("Keywords", new BMessage(DEFAULT_KEY_MSG)));
defaultKeys->AddItem(new BMenuItem("Creator", new BMessage(DEFAULT_KEY_MSG)));
// PDFlib sets these itselves:
// defaultKeys->AddItem(new BMenuItem("Producer", new BMessage(DEFAULT_KEY_MSG)));
// defaultKeys->AddItem(new BMenuItem("CreationDate", new BMessage(DEFAULT_KEY_MSG)));
// Not meaningful to set the modification date at creation time!
// defaultKeys->AddItem(new BMenuItem("ModDate", new BMessage(DEFAULT_KEY_MSG)));
BMenuField *keys = new BMenuField(BRect(0, 0, 90, 10), "add", "", defaultKeys);
keys->SetDivider(0);
panel->AddChild(keys);
keys->MoveTo(menu->Frame().right + 5, menu->Frame().top);
// add add key text control
BTextControl *add = new BTextControl(BRect(0, 0, 180, 20), "add", "Add Key:", "", new BMessage(ADD_KEY_MSG));
add->SetDivider(60);
panel->AddChild(add);
add->MoveTo(keys->Frame().right + 5, keys->Frame().top);
// fill table
BMessage doc_info;
fDocInfo->FindMessage("doc_info", &doc_info);
BuildTable(&doc_info);
SetupButtons(panel);
} }
#if HAVE_FULLVERSION_PDF_LIB
BTextControl*
DocInfoWindow::AddPasswordControl(BRect r, BView* panel, const char* name, const char* label) {
BString s;
BTextControl* text;
if (DocInfo()->FindString(name, &s) != B_OK) s = "";
text = new BTextControl(r, name, label, "", NULL);
text->TextView()->HideTyping(true);
text->TextView()->SetText(s.String());
panel->AddChild(text);
return text;
}
// --------------------------------------------------
void
DocInfoWindow::SetupPasswordView(BBox* panel) {
BRect r(panel->Bounds());
BRect r1(5, 5, r.Width()-10, 25);
BString label;
fMasterPassword = AddPasswordControl(r1, panel, "master_password", "Master Password:");
r1.OffsetBy(0, fMasterPassword->Bounds().Height());
fUserPassword = AddPasswordControl(r1, panel, "user_password", "User Password:");
float w = max_c(panel->StringWidth(fMasterPassword->Label()), panel->StringWidth(fUserPassword->Label()));
fMasterPassword->SetDivider(w);
fUserPassword->SetDivider(w);
SetupButtons(panel);
}
void
DocInfoWindow::SetupPermissionsView(BBox* panel) {
SetupButtons(panel);
}
#endif
// --------------------------------------------------
bool bool
DocInfoWindow::QuitRequested() DocInfoWindow::QuitRequested()
{ {
@@ -259,66 +123,125 @@ DocInfoWindow::QuitRequested()
} }
// --------------------------------------------------
void
DocInfoWindow::Quit()
{
EmptyKeyList();
inherited::Quit();
}
// --------------------------------------------------
void void
DocInfoWindow::MessageReceived(BMessage *msg) DocInfoWindow::MessageReceived(BMessage *msg)
{ {
switch (msg->what){ switch (msg->what) {
case OK_MSG: { case OK_MSG: {
BMessage doc_info; BMessage doc_info;
ReadFieldsFromTable(&doc_info); _ReadFieldsFromTable(doc_info);
DocInfo()->RemoveName("doc_info"); _DocInfo()->RemoveName("doc_info");
DocInfo()->AddMessage("doc_info", &doc_info); _DocInfo()->AddMessage("doc_info", &doc_info);
#if HAVE_FULLVERSION_PDF_LIB #if HAVE_FULLVERSION_PDF_LIB
ReadPasswords(); _ReadPasswords();
ReadPermissions(); _ReadPermissions();
#endif #endif
Quit(); Quit();
} } break;
break;
case CANCEL_MSG: Quit(); case CANCEL_MSG: {
break; Quit();
} break;
case ADD_KEY_MSG: {
case DEFAULT_KEY_MSG: case DEFAULT_KEY_MSG:
case ADD_KEY_MSG: AddKey(msg, msg->what == ADD_KEY_MSG); _AddKey(msg, msg->what == ADD_KEY_MSG);
break; } break;
case REMOVE_KEY_MSG: RemoveKey(msg); case REMOVE_KEY_MSG: {
break; _RemoveKey(msg);
} break;
default: default: {
inherited::MessageReceived(msg); inherited::MessageReceived(msg);
break; } break;
} }
} }
// --------------------------------------------------
void
DocInfoWindow::BuildTable(BMessage *docInfo)
{
BRect r;
float y;
float w;
float rowHeight;
#ifndef B_BEOS_VERSION_DANO
char *name;
#else
const char *name;
#endif
uint32 type;
int32 count;
EmptyKeyList(); void
DocInfoWindow::FrameResized(float newWidth, float newHeight)
{
BTextControl *textControl = dynamic_cast<BTextControl*> (fTable->ChildAt(0));
if (textControl) {
float width, height;
textControl->GetPreferredSize(&width, &height);
int32 count = fKeyList->CountItems();
float fieldsHeight = (height * count) + (2 * count);
_AdjustScrollBar(height, fieldsHeight);
while (textControl) {
textControl->SetDivider(width / 2.0);
textControl = dynamic_cast<BTextControl*> (textControl->NextSibling());
}
}
}
void
DocInfoWindow::_SetupDocInfoView(BBox* panel)
{
BRect bounds(panel->Bounds());
#if HAVE_FULLVERSION_PDF_LIB
bounds.InsetBy(10.0, 10.0);
#endif
// add list of keys
fKeyList = new BMenu("Delete Key");
BMenuField *menu = new BMenuField(bounds, "delete", "", fKeyList,
B_FOLLOW_BOTTOM);
panel->AddChild(menu);
menu->ResizeToPreferred();
menu->SetDivider(0);
menu->MoveTo(bounds.left, bounds.bottom - menu->Bounds().Height());
const char* title[6] = { "Title", "Author", "Subject", "Keywords", "Creator",
NULL }; // PDFlib sets these: "Producer", "CreationDate", not "ModDate"
BMenu* defaultKeys = new BMenu("Default Keys");
for (int32 i = 0; title[i] != NULL; ++i)
defaultKeys->AddItem(new BMenuItem(title[i], new BMessage(DEFAULT_KEY_MSG)));
BRect frame(menu->Frame());
menu = new BMenuField(frame, "add", "", defaultKeys, B_FOLLOW_BOTTOM);
panel->AddChild(menu);
menu->ResizeToPreferred();
menu->SetDivider(0);
menu->MoveBy(frame.Width() + 10.0, 0.0);
frame = menu->Frame();
frame.left = frame.right + 10.0;
frame.right = bounds.right;
BTextControl *add = new BTextControl(frame, "add", "Add Key:", "",
new BMessage(ADD_KEY_MSG), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
panel->AddChild(add);
add->ResizeToPreferred();
add->SetDivider(be_plain_font->StringWidth("Add Key: "));
bounds.bottom = frame.top - 10.0;
bounds.right -= B_V_SCROLL_BAR_WIDTH;
bounds.InsetBy(2.0, 2.0);
fTable = new BView(bounds, "table", B_FOLLOW_ALL, B_WILL_DRAW);
fTable->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
fTableScrollView = new BScrollView("scroll_table", fTable, B_FOLLOW_ALL, 0,
false, true);
panel->AddChild(fTableScrollView);
BMessage docInfo;
fDocInfo->FindMessage("doc_info", &docInfo);
// fill table
_BuildTable(docInfo);
}
void
DocInfoWindow::_BuildTable(const BMessage& docInfo)
{
_EmptyKeyList();
while (fTable->ChildAt(0)) { while (fTable->ChildAt(0)) {
BView *child = fTable->ChildAt(0); BView *child = fTable->ChildAt(0);
fTable->RemoveChild(child); fTable->RemoveChild(child);
@@ -327,148 +250,283 @@ DocInfoWindow::BuildTable(BMessage *docInfo)
fTable->ScrollTo(0, 0); fTable->ScrollTo(0, 0);
r = fTable->Bounds(); #ifdef B_BEOS_VERSION_DANO
y = 5; const
w = r.Width() - 10;
for (int32 i = 0; docInfo->GetInfo(B_STRING_TYPE, i, &name, &type, &count) == B_OK; i++) {
if (type == B_STRING_TYPE) {
BString value;
if (docInfo->FindString(name, &value) == B_OK) {
BString s;
TextControl* v = new TextControl(BRect(0, 0, w, 20), name, name, value.String(), new BMessage(), B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
float w;
fTable->AddChild(v);
v->GetPreferredSize(&w, &rowHeight);
v->MoveTo(5, y);
y += rowHeight + 2;
fKeyList->AddItem(new BMenuItem(name, new BMessage(REMOVE_KEY_MSG)));
}
}
}
BScrollBar *sb = fTableScrollView->ScrollBar(B_VERTICAL);
if (sb) {
float th = fTable->Bounds().Height()+1;
float h = y - th;
if (h > 0) {
sb->SetProportion(th / (float)y);
sb->SetRange(0, h);
sb->SetSteps(rowHeight + 2 + 2, th);
} else {
sb->SetRange(0, 0);
}
}
}
#if HAVE_FULLVERSION_PDF_LIB
// --------------------------------------------------
void
DocInfoWindow::ReadPasswords()
{
AddString(DocInfo(), "master_password", fMasterPassword->TextView()->Text());
AddString(DocInfo(), "user_password", fUserPassword->TextView()->Text());
}
// --------------------------------------------------
void
DocInfoWindow::ReadPermissions()
{
BString permissions;
fPermissions.Encode(&permissions);
AddString(DocInfo(), "permissions", permissions.String());
}
#endif #endif
char *name;
uint32 type;
int32 count;
float rowHeight = 20.0;
float fieldsHeight = 2.0;
float width = fTable->Bounds().Width() - 4.0;
for (int32 i = 0; docInfo.GetInfo(B_STRING_TYPE, i, &name, &type, &count)
== B_OK; i++) {
if (type != B_STRING_TYPE)
continue;
// -------------------------------------------------- BString value;
void BTextControl* textControl;
DocInfoWindow::ReadFieldsFromTable(BMessage* doc_info) if (docInfo.FindString(name, &value) == B_OK) {
{ BRect rect(2.0, fieldsHeight, width, rowHeight);
BView* child; textControl = _AddFieldToTable(rect, name, value.String());
BMessage m;
for (int32 i = 0; (child = fTable->ChildAt(i)) != NULL; i++) { rowHeight = textControl->Bounds().Height();
TextControl* t = dynamic_cast<TextControl*>(child); fieldsHeight += rowHeight + 2.0;
if (t) {
m.AddString(t->Label(), t->Text());
} }
} }
*doc_info = m;
_AdjustScrollBar(rowHeight, fieldsHeight);
} }
// -------------------------------------------------- BTextControl*
bool DocInfoWindow::_AddFieldToTable(BRect rect, const char* name, const char* value)
DocInfoWindow::IsValidKey(const char* key)
{ {
if (*key == 0) return false; BTextControl *textControl = new BTextControl(rect, name, name, value, NULL,
B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_NAVIGABLE);
fTable->AddChild(textControl);
textControl->ResizeToPreferred();
fKeyList->AddItem(new BMenuItem(name, new BMessage(REMOVE_KEY_MSG)));
return textControl;
}
void
DocInfoWindow::_AdjustScrollBar(float controlHeight, float fieldsHeight)
{
BScrollBar *sb = fTableScrollView->ScrollBar(B_VERTICAL);
if (!sb)
return;
sb->SetRange(0.0, 0.0);
float tableHeight = fTable->Bounds().Height();
if ((fieldsHeight - tableHeight) > 0.0) {
sb->SetProportion(tableHeight / fieldsHeight);
sb->SetRange(0.0, fieldsHeight - tableHeight);
sb->SetSteps(controlHeight + 2.0, tableHeight);
}
}
void
DocInfoWindow::_ReadFieldsFromTable(BMessage& docInfo)
{
docInfo.MakeEmpty();
BView* child;
for (int32 i = 0; (child = fTable->ChildAt(i)) != NULL; i++) {
BTextControl* textControl = dynamic_cast<BTextControl*>(child);
if (textControl)
docInfo.AddString(textControl->Label(), textControl->Text());
}
}
void
DocInfoWindow::_RemoveKey(BMessage *msg)
{
void *p;
if (msg->FindPointer("source", &p) != B_OK)
return;
BMenuItem *item = reinterpret_cast<BMenuItem*>(p);
if (!item)
return;
BMessage docInfo;
_ReadFieldsFromTable(docInfo);
const char *label = item->Label();
if (docInfo.HasString(label)) {
docInfo.RemoveName(label);
_BuildTable(docInfo);
}
}
bool
DocInfoWindow::_IsKeyValid(const char* key) const
{
if (*key == 0)
return false;
while (*key) { while (*key) {
if (isspace(*key) || iscntrl(*key)) break; if (isspace(*key) || iscntrl(*key))
key ++; break;
key++;
} }
return *key == 0; return *key == 0;
} }
// --------------------------------------------------
void void
DocInfoWindow::AddKey(BMessage *msg, bool textControl) DocInfoWindow::_AddKey(BMessage *msg, bool textControl)
{ {
void *p; void *p;
BTextControl *text; if (msg->FindPointer("source", &p) != B_OK || p == NULL)
BMenuItem *item; return;
BString key;
BMessage docInfo; const char* key = NULL;
if (msg->FindPointer("source", &p) != B_OK || p == NULL) return;
if (textControl) { if (textControl) {
text = reinterpret_cast<BTextControl*>(p); BTextControl *text = reinterpret_cast<BTextControl*>(p);
key = text->Text(); key = text->Text();
} else { } else {
item = reinterpret_cast<BMenuItem*>(p); BMenuItem *item = reinterpret_cast<BMenuItem*>(p);
key = item->Label(); key = item->Label();
} }
// key is valid and is not in list already if (!_IsKeyValid(key))
if (IsValidKey(key.String())) { return;
BMessage docInfo;
ReadFieldsFromTable(&docInfo);
if (!docInfo.HasString(key.String())) {
docInfo.AddString(key.String(), "");
BuildTable(&docInfo);
}
}
}
// --------------------------------------------------
void
DocInfoWindow::RemoveKey(BMessage *msg)
{
void *p;
BMenuItem *item;
BString key;
BMessage docInfo; BMessage docInfo;
if (msg->FindPointer("source", &p) != B_OK) return; _ReadFieldsFromTable(docInfo);
item = reinterpret_cast<BMenuItem*>(p);
if (!item) return;
key = item->Label();
ReadFieldsFromTable(&docInfo); if (!docInfo.HasString(key)) {
if (docInfo.HasString(key.String())) { // key is valid and is not in list already
docInfo.RemoveName(key.String()); docInfo.AddString(key, "");
BuildTable(&docInfo);
float width = fTable->Bounds().Width() - 4.0;
BTextControl *textControl =
_AddFieldToTable(BRect(2.0, 0.0, width, 20.0), key, "");
float rowHeight = textControl->Bounds().Height();
int32 count = fKeyList->CountItems();
float fieldsHeight = (rowHeight * count) + (2 * count);
textControl->MoveTo(2.0, fieldsHeight - rowHeight);
_AdjustScrollBar(rowHeight, fieldsHeight);
} }
} }
// --------------------------------------------------
void void
DocInfoWindow::EmptyKeyList() DocInfoWindow::_EmptyKeyList()
{ {
while (fKeyList->ItemAt(0)) { while (fKeyList->CountItems() > 0L)
BMenuItem *i = fKeyList->ItemAt(0); delete fKeyList->RemoveItem(0L);
fKeyList->RemoveItem(i); }
delete i;
#if HAVE_FULLVERSION_PDF_LIB
void
DocInfoWindow::_SetupPasswordView(BBox* panel)
{
BRect bounds(panel->Bounds().InsetByCopy(10.0, 10.0));
fMasterPassword = _AddPasswordControl(bounds, panel, "master_password",
"Master Password:");
bounds.OffsetBy(0, fMasterPassword->Bounds().Height());
fUserPassword = _AddPasswordControl(bounds, panel, "user_password",
"User Password:");
float divider = max_c(panel->StringWidth("Master Password:"),
panel->StringWidth("User Password:"));
fMasterPassword->SetDivider(divider);
fUserPassword->SetDivider(divider);
}
void
DocInfoWindow::_SetupPermissionsView(BBox* panel)
{
(void)panel;
}
BBox*
DocInfoWindow::_CreateTabPanel(BTabView* tabView, const char* label)
{
BRect rect(tabView->Bounds().InsetByCopy(3.0, 15.0));
rect.OffsetTo(B_ORIGIN);
BBox* panel = new BBox(rect, "top_panel", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER);
BTab* tab = new BTab();
tabView->AddTab(panel, tab);
tab->SetLabel(label);
return panel;
}
BTextControl*
DocInfoWindow::_AddPasswordControl(BRect r, BView* panel, const char* name,
const char* label)
{
BString text;
_DocInfo()->FindString(name, &text);
BTextControl* textControl = new BTextControl(r, name, label, "", NULL,
B_FOLLOW_LEFT_RIGHT);
panel->AddChild(textControl);
textControl->ResizeToPreferred();
textControl->TextView()->HideTyping(true);
textControl->TextView()->SetText(text.String());
return textControl;
}
void
DocInfoWindow::_ReadPasswords()
{
SetString(_DocInfo(), "master_password", fMasterPassword->TextView()->Text());
SetString(_DocInfo(), "user_password", fUserPassword->TextView()->Text());
}
void
DocInfoWindow::_ReadPermissions()
{
BString permissions;
fPermissions.Encode(permissions);
SetString(_DocInfo(), "permissions", permissions.String());
}
// #pragma mark -- Permissions
// pdflib 5.x supports password protection and permissions in the commercial version only!
static const PermissionLabels gPermissionLabels[] = {
PermissionLabels("Prevent printing the file.", "noprint"),
PermissionLabels("Prevent making any changes.", "nomodify"),
PermissionLabels("Prevent copying or extracting text or graphics.", "nocopy"),
PermissionLabels("Prevent adding or changing comments or form fields.", "noannots"),
PermissionLabels("Prevent form field filling.", "noforms"),
PermissionLabels("Prevent extracting text of graphics.", "noaccessible"),
PermissionLabels("Prevent inserting, deleting, or rotating pages and creating "
"bookmarks and thumbnails, even if nomodify hasn't been specified", "noassemble"),
PermissionLabels("Prevent high-resolution printing.", "nohiresprint")
};
Permissions::Permissions()
{
fNofPermissions = sizeof(gPermissionLabels) / sizeof(PermissionLabels);
fPermissions = new Permission[fNofPermissions];
for (int32 i = 0; i < fNofPermissions; i++)
fPermissions[i].SetLabels(&gPermissionLabels[i]);
}
void Permissions::Decode(const char* s)
{
for (int32 i = 0; i < fNofPermissions; i++)
At(i)->SetAllowed((strstr(s, At(i)->GetPDFName()) == NULL));
}
void Permissions::Encode(BString& permissions)
{
permissions.Truncate(0);
for (int32 i = 0; i < fNofPermissions; i++) {
if (!At(i)->IsAllowed())
permissions.Append(At(i)->GetPDFName()).Append(" ");
} }
} }
#endif // HAVE_FULLVERSION_PDF_LIB
@@ -28,122 +28,137 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. THE SOFTWARE.
*/ */
#ifndef DOCINFOWINDOW_H #ifndef DOCINFOWINDOW_H
#define DOCINFOWINDOW_H #define DOCINFOWINDOW_H
#include <InterfaceKit.h>
#include <Message.h>
#include <Messenger.h>
#include <File.h>
#include <FindDirectory.h>
#include <Path.h>
#include <String.h>
#include "InterfaceUtils.h" #include "InterfaceUtils.h"
#include "PrintUtils.h"
#include <String.h>
class BBox;
class BMenu;
class BScrollView;
class BTabView;
class BTextControl;
class BView;
#define HAVE_FULLVERSION_PDF_LIB 0 #define HAVE_FULLVERSION_PDF_LIB 0
#if HAVE_FULLVERSION_PDF_LIB
class PermissionLabels {
private:
const char* fName;
const char* fPDFName;
#if HAVE_FULLVERSION_PDF_LIB
class PermissionLabels {
public: public:
PermissionLabels(const char* name, const char* pdfName) : fName(name), fPDFName(pdfName) { } PermissionLabels(const char* name, const char* pdfName)
// accessors : fName(name), fPDFName(pdfName) { }
const char* GetName() const { return fName; }
const char* GetPDFName() const { return fName; } const char* GetName() const { return fName; }
const char* GetPDFName() const { return fName; }
private:
const char* fName;
const char* fPDFName;
}; };
class Permission {
private:
const PermissionLabels* fLabels;
bool fAllowed;
class Permission {
public: public:
Permission() : fLabels(NULL), fAllowed(true) { } Permission()
// accessors : fLabels(NULL), fAllowed(true) { }
const char* GetName() const { return fLabels->GetName(); }
const char* GetPDFName() const { return fLabels->GetPDFName(); } const char* GetName() const { return fLabels->GetName(); }
bool IsAllowed() const { return fAllowed; } const char* GetPDFName() const { return fLabels->GetPDFName(); }
// setter bool IsAllowed() const { return fAllowed; }
void SetLabels(const PermissionLabels* labels) { fLabels = labels; }
void SetAllowed(bool allowed) { fAllowed = allowed; } void SetLabels(const PermissionLabels* labels) { fLabels = labels; }
void SetAllowed(bool allowed) { fAllowed = allowed; }
private:
const PermissionLabels* fLabels;
bool fAllowed;
}; };
class Permissions { class Permissions {
private:
Permission* fPermissions;
int fNofPermissions;
public: public:
Permissions(); Permissions();
// accessors // accessors
Permission* At(int i) { return &fPermissions[i]; } Permission* At(int32 i) { return &fPermissions[i]; }
int Length() const { return fNofPermissions; } int32 Length() const { return fNofPermissions; }
// decode/encode pdflib permission string // decode/encode pdflib permission string
void Decode(const char* s); void Decode(const char* s);
void Encode(BString* s); void Encode(BString& permissions);
private:
Permission* fPermissions;
int32 fNofPermissions;
}; };
#endif
#endif // HAVE_FULLVERSION_PDF_LIB
class DocInfoWindow : public HWindow class DocInfoWindow : public HWindow
{ {
typedef HWindow inherited;
public: public:
// Constructors, destructors, operators... DocInfoWindow(BMessage *doc_info);
DocInfoWindow(BMessage *doc_info); virtual void Quit();
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
virtual void FrameResized(float newWidth, float newHeight);
typedef HWindow inherited;
// public constantes
enum { enum {
OK_MSG = 'ok__', OK_MSG = 'ok__',
CANCEL_MSG = 'cncl', CANCEL_MSG = 'cncl',
ADD_KEY_MSG = 'add_', ADD_KEY_MSG = 'add_',
REMOVE_KEY_MSG = 'rmov', REMOVE_KEY_MSG = 'rmov',
DEFAULT_KEY_MSG = 'dflt', DEFAULT_KEY_MSG = 'dflt',
}; };
// Virtual function overrides private:
public: BMessage* _DocInfo() { return fDocInfo; }
virtual void MessageReceived(BMessage *msg); void _SetupDocInfoView(BBox* panel);
virtual bool QuitRequested(); void _BuildTable(const BMessage& fromDocInfo);
virtual void Quit(); void _AdjustScrollBar(float controlHeight,
float fieldsHeight);
BTextControl* _AddFieldToTable(BRect rect, const char* name,
const char* value);
void _ReadFieldsFromTable(BMessage& docInfo);
void _RemoveKey(BMessage* msg);
bool _IsKeyValid(const char *key) const;
void _AddKey(BMessage* msg, bool textControl);
void _EmptyKeyList();
#if HAVE_FULLVERSION_PDF_LIB
void _SetupPasswordView(BBox* panel);
void _SetupPermissionsView(BBox* panel);
BBox* _CreateTabPanel(BTabView* tabView, const char* label);
BTextControl* _AddPasswordControl(BRect r, BView* panel,
const char* name, const char* label);
void _ReadPasswords();
void _ReadPermissions();
#endif // HAVE_FULLVERSION_PDF_LIB
private: private:
BMessage *fDocInfo; // owned by parent window BMessage* fDocInfo; // owned by parent window
BView *fTable; BView* fTable;
BScrollView *fTableScrollView; BScrollView* fTableScrollView;
BMenu *fKeyList; BMenu* fKeyList;
#if HAVE_FULLVERSION_PDF_LIB
BTextControl *fMasterPassword;
BTextControl *fUserPassword;
Permissions fPermissions;
#endif
BMessage* DocInfo() { return fDocInfo; }
BBox* CreateTabPanel(BTabView* tabView, const char* label);
void SetupButtons(BBox* panel);
void SetupDocInfoView(BBox* panel);
#if HAVE_FULLVERSION_PDF_LIB #if HAVE_FULLVERSION_PDF_LIB
BTextControl* AddPasswordControl(BRect r, BView* panel, const char* name, const char* label); BTextControl* fMasterPassword;
void SetupPasswordView(BBox* panel); BTextControl* fUserPassword;
void SetupPermissionsView(BBox* panel); Permissions fPermissions;
#endif #endif // HAVE_FULLVERSION_PDF_LIB
void BuildTable(BMessage *fromDocInfo);
void ReadFieldsFromTable(BMessage* doc_info);
#if HAVE_FULLVERSION_PDF_LIB
void ReadPasswords();
void ReadPermissions();
#endif
void EmptyKeyList();
bool IsValidKey(const char *key);
void AddKey(BMessage* msg, bool textControl);
void RemoveKey(BMessage* msg);
}; };
#endif #endif
@@ -78,6 +78,27 @@ static const char* FontName(font_encoding enc) {
} }
} }
// #pragma mark -- of DragListView
DragListView::DragListView(BRect frame, const char *name,
list_view_type type,
uint32 resizingMode, uint32 flags)
: BListView(frame, name, type, resizingMode, flags)
{
}
bool
DragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
BMessage m;
DragMessage(&m, ItemFrame(index), this);
return true;
}
/** /**
* Constuctor * Constuctor
* *
@@ -47,6 +47,18 @@ THE SOFTWARE.
#include "ColumnListView.h" #include "ColumnListView.h"
#endif #endif
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);
};
class FontsWindow : public HWindow class FontsWindow : public HWindow
{ {
public: public:
@@ -17,6 +17,8 @@
#include <Application.h> #include <Application.h>
#include <Button.h> #include <Button.h>
#include <Debug.h> #include <Debug.h>
#include <Region.h>
#include <Screen.h>
#include <String.h> #include <String.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <StringView.h> #include <StringView.h>
@@ -20,6 +20,7 @@
#include <File.h> #include <File.h>
#include <Node.h> #include <Node.h>
#include <Message.h> #include <Message.h>
#include <PrintJob.h>
#include <stdio.h> #include <stdio.h>
+59 -206
View File
@@ -27,11 +27,21 @@ THE SOFTWARE.
*/ */
#include <string.h>
#include <Debug.h>
#include "InterfaceUtils.h" #include "InterfaceUtils.h"
#include <Alert.h>
#include <Debug.h>
#include <Message.h>
#include <TextView.h>
#include <string.h>
// #pragma mark -- EscapeMessageFilter
EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what) EscapeMessageFilter::EscapeMessageFilter(BWindow *window, int32 what)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD') : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD')
, fWindow(window), , fWindow(window),
@@ -44,34 +54,34 @@ filter_result
EscapeMessageFilter::Filter(BMessage *msg, BHandler **target) EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
{ {
int32 key; int32 key;
// notify window with message fWhat if Escape key is hit filter_result result = B_DISPATCH_MESSAGE;
if (B_OK == msg->FindInt32("key", &key) && key == 1) { if (msg->FindInt32("key", &key) == B_OK && key == 1) {
fWindow->PostMessage(fWhat); fWindow->PostMessage(fWhat);
return B_SKIP_MESSAGE; result = B_SKIP_MESSAGE;
} }
return B_DISPATCH_MESSAGE; return result;
} }
// Implementation of HWindow // #pragma mark -- HWindow
// --------------------------------------------------
HWindow::HWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace, uint32 escape_msg) HWindow::HWindow(BRect frame, const char *title, window_type type, uint32 flags,
uint32 workspace, uint32 escape_msg)
: BWindow(frame, title, type, flags, workspace) : BWindow(frame, title, type, flags, workspace)
{ {
Init(escape_msg); Init(escape_msg);
} }
// -------------------------------------------------- HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel,
HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg) uint32 flags, uint32 workspace, uint32 escape_msg)
: BWindow(frame, title, look, feel, flags, workspace) : BWindow(frame, title, look, feel, flags, workspace)
{ {
Init(escape_msg); Init(escape_msg);
} }
// --------------------------------------------------
void void
HWindow::Init(uint32 escape_msg) HWindow::Init(uint32 escape_msg)
{ {
@@ -80,7 +90,6 @@ HWindow::Init(uint32 escape_msg)
} }
// --------------------------------------------------
void void
HWindow::MessageReceived(BMessage* msg) HWindow::MessageReceived(BMessage* msg)
{ {
@@ -91,14 +100,13 @@ HWindow::MessageReceived(BMessage* msg)
} }
} }
// --------------------------------------------------
void void
HWindow::AboutRequested() HWindow::AboutRequested()
{ {
const char* aboutText = AboutText(); const char* aboutText = AboutText();
if (aboutText == NULL) { if (aboutText == NULL)
return; return;
}
BAlert *about = new BAlert("About", aboutText, "Cool"); BAlert *about = new BAlert("About", aboutText, "Cool");
BTextView *v = about->TextView(); BTextView *v = about->TextView();
@@ -127,25 +135,31 @@ HWindow::AboutRequested()
} }
// Implementation of BlockingWindow // #pragma mark -- BlockingWindow
BlockingWindow::BlockingWindow(BRect frame, const char *title, window_type type, uint32 flags, uint32 workspace, uint32 escape_msg)
BlockingWindow::BlockingWindow(BRect frame, const char *title, window_type type,
uint32 flags, uint32 workspace, uint32 escape_msg)
: HWindow(frame, title, type, flags, workspace) : HWindow(frame, title, type, flags, workspace)
{ {
Init(title); Init(title);
} }
BlockingWindow::BlockingWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg)
BlockingWindow::BlockingWindow(BRect frame, const char *title, window_look look,
window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg)
: HWindow(frame, title, look, feel, flags, workspace) : HWindow(frame, title, look, feel, flags, workspace)
{ {
Init(title); Init(title);
} }
BlockingWindow::~BlockingWindow() BlockingWindow::~BlockingWindow()
{ {
delete_sem(fExitSem); delete_sem(fExitSem);
} }
void void
BlockingWindow::Init(const char* title) BlockingWindow::Init(const char* title)
{ {
@@ -155,45 +169,55 @@ BlockingWindow::Init(const char* title)
fReadyToQuit = false; fReadyToQuit = false;
} }
bool bool
BlockingWindow::QuitRequested() { BlockingWindow::QuitRequested()
if (fReadyToQuit) { {
if (fReadyToQuit)
return true; return true;
} else {
// user requested to quit the window // user requested to quit the window
*fResult = fUserQuitResult; *fResult = fUserQuitResult;
release_sem(fExitSem); release_sem(fExitSem);
return false; return false;
}
} }
void void
BlockingWindow::Quit() { BlockingWindow::Quit()
{
fReadyToQuit = false; // finally allow window to quit fReadyToQuit = false; // finally allow window to quit
inherited::Quit(); // and quit it inherited::Quit(); // and quit it
} }
void void
BlockingWindow::Quit(status_t result) { BlockingWindow::Quit(status_t result)
if (fResult) { {
if (fResult)
*fResult = result; *fResult = result;
}
release_sem(fExitSem); release_sem(fExitSem);
} }
void void
BlockingWindow::SetUserQuitResult(status_t result) { BlockingWindow::SetUserQuitResult(status_t result)
{
fUserQuitResult = result; fUserQuitResult = result;
} }
status_t status_t
BlockingWindow::Go() { BlockingWindow::Go()
{
status_t result = B_ERROR; status_t result = B_ERROR;
fResult = &result; fResult = &result;
Show(); Show();
acquire_sem(fExitSem); acquire_sem(fExitSem);
// here the window still exists, because QuitRequested returns false if fReadyToQuit is false // here the window still exists, because QuitRequested returns false if
// now we can quit the window and am sure that the window thread dies before this thread // fReadyToQuit is false, now we can quit the window and am sure that the
// window thread dies before this thread
if (Lock()) { if (Lock()) {
Quit(); Quit();
} else { } else {
@@ -202,174 +226,3 @@ BlockingWindow::Go() {
// here the window does not exist, good to have the result in a local variable // here the window does not exist, good to have the result in a local variable
return result; return result;
} }
// Impelementation of TextView
// --------------------------------------------------
TextView::TextView(BRect frame,
const char *name,
BRect textRect,
uint32 rmask,
uint32 flags)
: BTextView(frame, name, textRect, rmask, flags)
{
}
// --------------------------------------------------
TextView::TextView(BRect frame,
const char *name,
BRect textRect,
const BFont *font, const rgb_color *color,
uint32 rmask,
uint32 flags)
: BTextView(frame, name, textRect, font, color, rmask, flags)
{
}
// --------------------------------------------------
void
TextView::KeyDown(const char *bytes, int32 numBytes)
{
if (numBytes == 1 && *bytes == B_TAB) {
BView::KeyDown(bytes, numBytes);
return;
}
inherited::KeyDown(bytes, numBytes);
}
// --------------------------------------------------
void
TextView::Draw(BRect update)
{
inherited::Draw(update);
if (IsFocus()) {
// stroke focus rectangle
SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
StrokeRect(Bounds());
}
}
// --------------------------------------------------
void
TextView::MakeFocus(bool focus)
{
Invalidate();
inherited::MakeFocus(focus);
// notify TextControl
BView* parent = Parent(); // BBox
if (focus && parent) {
parent = parent->Parent(); // TextControl
TextControl* control = dynamic_cast<TextControl*>(parent);
if (control) control->FocusSetTo(this);
}
}
// Impelementation of TextControl
// --------------------------------------------------
TextControl::TextControl(BRect frame,
const char *name,
const char *label,
const char *initial_text,
BMessage *message,
uint32 rmask,
uint32 flags)
: BView(frame, name, rmask, flags)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BRect r(0, 0, frame.Width() / 2 -1, frame.Height());
fLabel = new BStringView(r, "", label);
BRect f(r);
f.OffsetTo(frame.Width() / 2 + 1, 0);
// box around TextView
BBox *box = new BBox(f, "", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW);
f.OffsetTo(0, 0);
f.InsetBy(1,1);
r.InsetBy(2,2);
fText = new TextView(f, "", r, rmask, flags | B_NAVIGABLE);
fText->SetWordWrap(false);
fText->DisallowChar('\n');
fText->Insert(initial_text);
AddChild(fLabel);
AddChild(box);
box->AddChild(fText);
}
// --------------------------------------------------
void
TextControl::ConvertToParent(BView* parent, BView* child, BRect &rect)
{
do {
child->ConvertToParent(&rect);
child = child->Parent();
} while (child != NULL && child != parent);
}
// --------------------------------------------------
void
TextControl::FocusSetTo(BView *child)
{
BRect r;
BView* parent = Parent(); // Table
if (parent) {
ConvertToParent(parent, child, r);
parent->ScrollTo(0, r.top);
}
}
// Impelementation of Implementation of Table
// --------------------------------------------------
Table::Table(BRect frame, const char *name, uint32 rmode, uint32 flags)
: BView(frame, name, rmode, flags)
{
}
// --------------------------------------------------
void
Table::ScrollTo(BPoint p)
{
float h = Frame().Height()+1;
if (Parent()) {
BScrollView* scrollView = dynamic_cast<BScrollView*>(Parent());
if (scrollView) {
BScrollBar *sb = scrollView->ScrollBar(B_VERTICAL);
float min, max;
sb->GetRange(&min, &max);
if (p.y < (h/2)) p.y = 0;
else if (p.y > max) p.y = max;
}
}
inherited::ScrollTo(p);
}
// Impelementation of DragListView
// --------------------------------------------------
DragListView::DragListView(BRect frame, const char *name,
list_view_type type,
uint32 resizingMode, uint32 flags)
: BListView(frame, name, type, resizingMode, flags)
{
}
// --------------------------------------------------
bool DragListView::InitiateDrag(BPoint point, int32 index, bool wasSelected)
{
BMessage m;
DragMessage(&m, ItemFrame(index), this);
return true;
}