* 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

View File

@ -26,136 +26,87 @@ 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>
#include <AppDefs.h>
#include <MessageFilter.h>
#include <Window.h>
class BHandler;
class BMessage;
class EscapeMessageFilter : public BMessageFilter
{
private:
BWindow *fWindow;
int32 fWhat;
public:
EscapeMessageFilter(BWindow *window, int32 what);
filter_result Filter(BMessage *msg, BHandler **target);
EscapeMessageFilter(BWindow *window, int32 what);
filter_result Filter(BMessage *msg, BHandler **target);
private:
BWindow* fWindow;
int32 fWhat;
};
class HWindow : public BWindow
{
protected:
void Init(uint32 escape_msg);
public:
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);
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; }
virtual void MessageReceived(BMessage* m);
virtual void AboutRequested();
virtual const char* AboutText() const { return NULL; }
protected:
void Init(uint32 escape_msg);
};
class BlockingWindow : public HWindow
{
typedef HWindow inherited;
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();
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);
virtual ~BlockingWindow();
virtual bool QuitRequested();
// 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
virtual status_t Go();
virtual status_t Go();
// 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.
// Default is B_OK.
void SetUserQuitResult(status_t result);
typedef HWindow inherited;
void SetUserQuitResult(status_t result);
private:
void Init(const char* title);
status_t fUserQuitResult;
bool fReadyToQuit;
sem_id fExitSem;
status_t* fResult;
};
void Init(const char* title);
// --------------------------------------------------
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);
private:
status_t fUserQuitResult;
bool fReadyToQuit;
sem_id fExitSem;
status_t* fResult;
};
#endif

View File

@ -27,13 +27,470 @@ THE SOFTWARE.
*/
#include <InterfaceKit.h>
#include <SupportKit.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>
// #pragma mark -- DocInfoWindow
DocInfoWindow::DocInfoWindow(BMessage *docInfo)
: HWindow(BRect(0, 0, 400, 250), "Document Information", B_TITLED_WINDOW_LOOK,
B_MODAL_APP_WINDOW_FEEL, B_NOT_MINIMIZABLE),
fDocInfo(docInfo)
{
BRect bounds(Bounds());
BView *background = new BView(bounds, "bachground", B_FOLLOW_ALL, B_WILL_DRAW);
background->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
AddChild(background);
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
BString permissions;
if (_DocInfo()->FindString("permissions", &permissions) == B_OK)
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
if (fTable->ChildAt(0))
fTable->ChildAt(0)->MakeFocus();
BRect winFrame(Frame());
BRect screenFrame(BScreen().Frame());
MoveTo((screenFrame.right - winFrame.right) / 2,
(screenFrame.bottom - winFrame.bottom) / 2);
SetSizeLimits(400.0, 10000.0, 250.0, 10000.0);
}
void
DocInfoWindow::Quit()
{
_EmptyKeyList();
inherited::Quit();
}
bool
DocInfoWindow::QuitRequested()
{
return true;
}
void
DocInfoWindow::MessageReceived(BMessage *msg)
{
switch (msg->what) {
case OK_MSG: {
BMessage doc_info;
_ReadFieldsFromTable(doc_info);
_DocInfo()->RemoveName("doc_info");
_DocInfo()->AddMessage("doc_info", &doc_info);
#if HAVE_FULLVERSION_PDF_LIB
_ReadPasswords();
_ReadPermissions();
#endif
Quit();
} break;
case CANCEL_MSG: {
Quit();
} break;
case ADD_KEY_MSG: {
case DEFAULT_KEY_MSG:
_AddKey(msg, msg->what == ADD_KEY_MSG);
} break;
case REMOVE_KEY_MSG: {
_RemoveKey(msg);
} break;
default: {
inherited::MessageReceived(msg);
} break;
}
}
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)) {
BView *child = fTable->ChildAt(0);
fTable->RemoveChild(child);
delete child;
}
fTable->ScrollTo(0, 0);
#ifdef B_BEOS_VERSION_DANO
const
#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;
BTextControl* textControl;
if (docInfo.FindString(name, &value) == B_OK) {
BRect rect(2.0, fieldsHeight, width, rowHeight);
textControl = _AddFieldToTable(rect, name, value.String());
rowHeight = textControl->Bounds().Height();
fieldsHeight += rowHeight + 2.0;
}
}
_AdjustScrollBar(rowHeight, fieldsHeight);
}
BTextControl*
DocInfoWindow::_AddFieldToTable(BRect rect, const char* name, const char* value)
{
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) {
if (isspace(*key) || iscntrl(*key))
break;
key++;
}
return *key == 0;
}
void
DocInfoWindow::_AddKey(BMessage *msg, bool textControl)
{
void *p;
if (msg->FindPointer("source", &p) != B_OK || p == NULL)
return;
const char* key = NULL;
if (textControl) {
BTextControl *text = reinterpret_cast<BTextControl*>(p);
key = text->Text();
} else {
BMenuItem *item = reinterpret_cast<BMenuItem*>(p);
key = item->Label();
}
if (!_IsKeyValid(key))
return;
BMessage docInfo;
_ReadFieldsFromTable(docInfo);
if (!docInfo.HasString(key)) {
// key is valid and is not in list already
docInfo.AddString(key, "");
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
DocInfoWindow::_EmptyKeyList()
{
while (fKeyList->CountItems() > 0L)
delete fKeyList->RemoveItem(0L);
}
#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"),
@ -42,433 +499,34 @@ static const PermissionLabels gPermissionLabels[] = {
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 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
Permissions::Permissions() {
fNofPermissions = sizeof(gPermissionLabels)/sizeof(PermissionLabels);
Permissions::Permissions()
{
fNofPermissions = sizeof(gPermissionLabels) / sizeof(PermissionLabels);
fPermissions = new Permission[fNofPermissions];
for (int i = 0; i < fNofPermissions; i ++) {
for (int32 i = 0; i < fNofPermissions; i++)
fPermissions[i].SetLabels(&gPermissionLabels[i]);
}
}
void Permissions::Decode(const char* s) {
for (int i = 0; i < fNofPermissions; i ++) {
bool allowed = strstr(s, At(i)->GetPDFName()) == NULL;
At(i)->SetAllowed(allowed);
}
}
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)
void Permissions::Decode(const char* s)
{
// ---- Ok, build a default page setup user interface
BRect r;
// BBox *panel;
BTabView *tabView;
BString permissions;
fDocInfo = doc_info;
#if HAVE_FULLVERSION_PDF_LIB
if (DocInfo()->FindString("permissions", &permissions) == B_OK) {
fPermissions.Decode(permissions.String());
}
#endif
r = Bounds();
tabView = new BTabView(r, "tab_view");
SetupDocInfoView(CreateTabPanel(tabView, "Information"));
#if HAVE_FULLVERSION_PDF_LIB
SetupPasswordView(CreateTabPanel(tabView, "Password"));
SetupPermissionsView(CreateTabPanel(tabView, "Permissions"));
#endif
AddChild(tabView);
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;
for (int32 i = 0; i < fNofPermissions; i++)
At(i)->SetAllowed((strstr(s, At(i)->GetPDFName()) == NULL));
}
void
DocInfoWindow::SetupButtons(BBox* panel) {
BButton *button;
float x, y, w, h;
BRect r(panel->Bounds());
// 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
DocInfoWindow::QuitRequested()
void Permissions::Encode(BString& permissions)
{
return true;
}
// --------------------------------------------------
void
DocInfoWindow::Quit()
{
EmptyKeyList();
inherited::Quit();
}
// --------------------------------------------------
void
DocInfoWindow::MessageReceived(BMessage *msg)
{
switch (msg->what){
case OK_MSG: {
BMessage doc_info;
ReadFieldsFromTable(&doc_info);
DocInfo()->RemoveName("doc_info");
DocInfo()->AddMessage("doc_info", &doc_info);
#if HAVE_FULLVERSION_PDF_LIB
ReadPasswords();
ReadPermissions();
#endif
Quit();
}
break;
case CANCEL_MSG: Quit();
break;
case DEFAULT_KEY_MSG:
case ADD_KEY_MSG: AddKey(msg, msg->what == ADD_KEY_MSG);
break;
case REMOVE_KEY_MSG: RemoveKey(msg);
break;
default:
inherited::MessageReceived(msg);
break;
permissions.Truncate(0);
for (int32 i = 0; i < fNofPermissions; i++) {
if (!At(i)->IsAllowed())
permissions.Append(At(i)->GetPDFName()).Append(" ");
}
}
// --------------------------------------------------
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();
while (fTable->ChildAt(0)) {
BView *child = fTable->ChildAt(0);
fTable->RemoveChild(child);
delete child;
}
fTable->ScrollTo(0, 0);
r = fTable->Bounds();
y = 5;
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
// --------------------------------------------------
void
DocInfoWindow::ReadFieldsFromTable(BMessage* doc_info)
{
BView* child;
BMessage m;
for (int32 i = 0; (child = fTable->ChildAt(i)) != NULL; i++) {
TextControl* t = dynamic_cast<TextControl*>(child);
if (t) {
m.AddString(t->Label(), t->Text());
}
}
*doc_info = m;
}
// --------------------------------------------------
bool
DocInfoWindow::IsValidKey(const char* key)
{
if (*key == 0) return false;
while (*key) {
if (isspace(*key) || iscntrl(*key)) break;
key ++;
}
return *key == 0;
}
// --------------------------------------------------
void
DocInfoWindow::AddKey(BMessage *msg, bool textControl)
{
void *p;
BTextControl *text;
BMenuItem *item;
BString key;
BMessage docInfo;
if (msg->FindPointer("source", &p) != B_OK || p == NULL) return;
if (textControl) {
text = reinterpret_cast<BTextControl*>(p);
key = text->Text();
} else {
item = reinterpret_cast<BMenuItem*>(p);
key = item->Label();
}
// key is valid and is not in list already
if (IsValidKey(key.String())) {
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;
if (msg->FindPointer("source", &p) != B_OK) return;
item = reinterpret_cast<BMenuItem*>(p);
if (!item) return;
key = item->Label();
ReadFieldsFromTable(&docInfo);
if (docInfo.HasString(key.String())) {
docInfo.RemoveName(key.String());
BuildTable(&docInfo);
}
}
// --------------------------------------------------
void
DocInfoWindow::EmptyKeyList()
{
while (fKeyList->ItemAt(0)) {
BMenuItem *i = fKeyList->ItemAt(0);
fKeyList->RemoveItem(i);
delete i;
}
}
#endif // HAVE_FULLVERSION_PDF_LIB

View File

@ -28,122 +28,137 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef 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 "PrintUtils.h"
#include <String.h>
class BBox;
class BMenu;
class BScrollView;
class BTabView;
class BTextControl;
class BView;
#define HAVE_FULLVERSION_PDF_LIB 0
#if HAVE_FULLVERSION_PDF_LIB
class PermissionLabels {
private:
const char* fName;
const char* fPDFName;
public:
PermissionLabels(const char* name, const char* pdfName) : fName(name), fPDFName(pdfName) { }
// accessors
const char* GetName() const { return fName; }
const char* GetPDFName() const { return fName; }
PermissionLabels(const char* name, const char* pdfName)
: fName(name), fPDFName(pdfName) { }
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;
public:
Permission() : fLabels(NULL), fAllowed(true) { }
// accessors
const char* GetName() const { return fLabels->GetName(); }
const char* GetPDFName() const { return fLabels->GetPDFName(); }
bool IsAllowed() const { return fAllowed; }
// setter
void SetLabels(const PermissionLabels* labels) { fLabels = labels; }
void SetAllowed(bool allowed) { fAllowed = allowed; }
Permission()
: fLabels(NULL), fAllowed(true) { }
const char* GetName() const { return fLabels->GetName(); }
const char* GetPDFName() const { return fLabels->GetPDFName(); }
bool IsAllowed() const { return fAllowed; }
void SetLabels(const PermissionLabels* labels) { fLabels = labels; }
void SetAllowed(bool allowed) { fAllowed = allowed; }
private:
const PermissionLabels* fLabels;
bool fAllowed;
};
class Permissions {
private:
Permission* fPermissions;
int fNofPermissions;
public:
Permissions();
Permissions();
// accessors
Permission* At(int i) { return &fPermissions[i]; }
int Length() const { return fNofPermissions; }
Permission* At(int32 i) { return &fPermissions[i]; }
int32 Length() const { return fNofPermissions; }
// decode/encode pdflib permission string
void Decode(const char* s);
void Encode(BString* s);
void Decode(const char* s);
void Encode(BString& permissions);
private:
Permission* fPermissions;
int32 fNofPermissions;
};
#endif
#endif // HAVE_FULLVERSION_PDF_LIB
class DocInfoWindow : public HWindow
{
typedef HWindow inherited;
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 {
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
ADD_KEY_MSG = 'add_',
REMOVE_KEY_MSG = 'rmov',
DEFAULT_KEY_MSG = 'dflt',
OK_MSG = 'ok__',
CANCEL_MSG = 'cncl',
ADD_KEY_MSG = 'add_',
REMOVE_KEY_MSG = 'rmov',
DEFAULT_KEY_MSG = 'dflt',
};
// Virtual function overrides
public:
virtual void MessageReceived(BMessage *msg);
virtual bool QuitRequested();
virtual void Quit();
private:
BMessage *fDocInfo; // owned by parent window
BView *fTable;
BScrollView *fTableScrollView;
BMenu *fKeyList;
#if HAVE_FULLVERSION_PDF_LIB
BTextControl *fMasterPassword;
BTextControl *fUserPassword;
Permissions fPermissions;
#endif
BMessage* DocInfo() { return fDocInfo; }
BMessage* _DocInfo() { return fDocInfo; }
void _SetupDocInfoView(BBox* panel);
void _BuildTable(const BMessage& fromDocInfo);
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();
BBox* CreateTabPanel(BTabView* tabView, const char* label);
void SetupButtons(BBox* panel);
void SetupDocInfoView(BBox* panel);
#if HAVE_FULLVERSION_PDF_LIB
BTextControl* AddPasswordControl(BRect r, BView* panel, const char* name, const char* label);
void SetupPasswordView(BBox* panel);
void SetupPermissionsView(BBox* panel);
#endif
void BuildTable(BMessage *fromDocInfo);
void ReadFieldsFromTable(BMessage* doc_info);
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:
BMessage* fDocInfo; // owned by parent window
BView* fTable;
BScrollView* fTableScrollView;
BMenu* fKeyList;
#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);
BTextControl* fMasterPassword;
BTextControl* fUserPassword;
Permissions fPermissions;
#endif // HAVE_FULLVERSION_PDF_LIB
};
#endif

View File

@ -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
*

View File

@ -47,6 +47,18 @@ THE SOFTWARE.
#include "ColumnListView.h"
#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
{
public:

View File

@ -17,6 +17,8 @@
#include <Application.h>
#include <Button.h>
#include <Debug.h>
#include <Region.h>
#include <Screen.h>
#include <String.h>
#include <ScrollView.h>
#include <StringView.h>

View File

@ -20,6 +20,7 @@
#include <File.h>
#include <Node.h>
#include <Message.h>
#include <PrintJob.h>
#include <stdio.h>

View File

@ -27,11 +27,21 @@ THE SOFTWARE.
*/
#include <string.h>
#include <Debug.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)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, '_KYD')
, fWindow(window),
@ -44,34 +54,34 @@ filter_result
EscapeMessageFilter::Filter(BMessage *msg, BHandler **target)
{
int32 key;
// notify window with message fWhat if Escape key is hit
if (B_OK == msg->FindInt32("key", &key) && key == 1) {
filter_result result = B_DISPATCH_MESSAGE;
if (msg->FindInt32("key", &key) == B_OK && key == 1) {
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)
{
Init(escape_msg);
}
// --------------------------------------------------
HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel, uint32 flags, uint32 workspace, uint32 escape_msg)
HWindow::HWindow(BRect frame, const char *title, window_look look, window_feel feel,
uint32 flags, uint32 workspace, uint32 escape_msg)
: BWindow(frame, title, look, feel, flags, workspace)
{
Init(escape_msg);
}
// --------------------------------------------------
void
HWindow::Init(uint32 escape_msg)
{
@ -80,7 +90,6 @@ HWindow::Init(uint32 escape_msg)
}
// --------------------------------------------------
void
HWindow::MessageReceived(BMessage* msg)
{
@ -91,15 +100,14 @@ HWindow::MessageReceived(BMessage* msg)
}
}
// --------------------------------------------------
void
HWindow::AboutRequested()
{
const char* aboutText = AboutText();
if (aboutText == NULL) {
if (aboutText == NULL)
return;
}
BAlert *about = new BAlert("About", aboutText, "Cool");
BTextView *v = about->TextView();
if (v) {
@ -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)
{
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)
{
Init(title);
}
BlockingWindow::~BlockingWindow()
{
delete_sem(fExitSem);
}
void
BlockingWindow::Init(const char* title)
{
@ -155,45 +169,55 @@ BlockingWindow::Init(const char* title)
fReadyToQuit = false;
}
bool
BlockingWindow::QuitRequested() {
if (fReadyToQuit) {
BlockingWindow::QuitRequested()
{
if (fReadyToQuit)
return true;
} else {
// user requested to quit the window
*fResult = fUserQuitResult;
release_sem(fExitSem);
return false;
}
// user requested to quit the window
*fResult = fUserQuitResult;
release_sem(fExitSem);
return false;
}
void
BlockingWindow::Quit() {
BlockingWindow::Quit()
{
fReadyToQuit = false; // finally allow window to quit
inherited::Quit(); // and quit it
inherited::Quit(); // and quit it
}
void
BlockingWindow::Quit(status_t result) {
if (fResult) {
BlockingWindow::Quit(status_t result)
{
if (fResult)
*fResult = result;
}
release_sem(fExitSem);
}
void
BlockingWindow::SetUserQuitResult(status_t result) {
BlockingWindow::SetUserQuitResult(status_t result)
{
fUserQuitResult = result;
}
status_t
BlockingWindow::Go() {
BlockingWindow::Go()
{
status_t result = B_ERROR;
fResult = &result;
Show();
acquire_sem(fExitSem);
// here the window still exists, because QuitRequested returns false if fReadyToQuit is false
// now we can quit the window and am sure that the window thread dies before this thread
// here the window still exists, because QuitRequested returns false if
// fReadyToQuit is false, now we can quit the window and am sure that the
// window thread dies before this thread
if (Lock()) {
Quit();
} else {
@ -202,174 +226,3 @@ BlockingWindow::Go() {
// here the window does not exist, good to have the result in a local variable
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;
}