Big cleanup.
Now searches all volumes for people groups. The only thing left is to make "URL:" and "E-mail:" clickable. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13136 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f32d9ec555
commit
779f323d92
|
@ -26,43 +26,52 @@
|
|||
#include "PeopleWindow.h"
|
||||
#include "PersonIcons.h"
|
||||
|
||||
//====================================================================
|
||||
|
||||
struct people_field gFields[] = {
|
||||
{ "META:name", 120, "Contact Name" },
|
||||
{ "META:nickname", 120, "Nickname" },
|
||||
{ "META:company", 120, "Company" },
|
||||
{ "META:address", 120, "Address" },
|
||||
{ "META:city", 90, "City" },
|
||||
{ "META:state", 50, "State" },
|
||||
{ "META:zip", 50, "Zip" },
|
||||
{ "META:country", 120, "Country" },
|
||||
{ "META:hphone", 90, "Home Phone" },
|
||||
{ "META:wphone", 90, "Work Phone" },
|
||||
{ "META:fax", 90, "Fax" },
|
||||
{ "META:email", 120, "E-mail" },
|
||||
{ "META:url", 120, "URL" },
|
||||
{ "META:group", 120, "Group" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
||||
TPeopleApp::TPeopleApp(void)
|
||||
:BApplication(APP_SIG)
|
||||
: BApplication(APP_SIG)
|
||||
{
|
||||
bool valid = FALSE;
|
||||
const char *str;
|
||||
int32 index = 0;
|
||||
BBitmap large_icon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
|
||||
BBitmap mini_icon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
|
||||
BDirectory dir;
|
||||
BEntry entry;
|
||||
BMessage msg;
|
||||
BMessage info;
|
||||
BMimeType mime;
|
||||
BPath path;
|
||||
BPoint pos;
|
||||
BVolume vol;
|
||||
BVolumeRoster roster;
|
||||
// TPeopleWindow *window;
|
||||
|
||||
fHaveWindow = FALSE;
|
||||
fHaveWindow = false;
|
||||
|
||||
fPosition.Set(6, TITLE_BAR_HEIGHT, 6 + WIND_WIDTH, TITLE_BAR_HEIGHT + WIND_HEIGHT);
|
||||
pos = fPosition.LeftTop();
|
||||
BPoint pos = fPosition.LeftTop();
|
||||
|
||||
find_directory(B_USER_SETTINGS_DIRECTORY, &path, true);
|
||||
dir.SetTo(path.Path());
|
||||
if (dir.FindEntry("People_data", &entry) == B_NO_ERROR) {
|
||||
fPrefs = new BFile(&entry, O_RDWR);
|
||||
fPrefs = new BFile(&entry, B_READ_WRITE);
|
||||
if (fPrefs->InitCheck() == B_NO_ERROR) {
|
||||
fPrefs->Read(&pos, sizeof(BPoint));
|
||||
if (BScreen(B_MAIN_SCREEN_ID).Frame().Contains(pos))
|
||||
fPosition.OffsetTo(pos);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
fPrefs = new BFile();
|
||||
if (dir.CreateFile("People_data", fPrefs) != B_NO_ERROR) {
|
||||
delete fPrefs;
|
||||
|
@ -70,29 +79,28 @@ TPeopleApp::TPeopleApp(void)
|
|||
}
|
||||
}
|
||||
|
||||
roster.GetBootVolume(&vol);
|
||||
fs_create_index(vol.Device(), P_NAME, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_COMPANY, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_ADDRESS, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_CITY, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_STATE, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_ZIP, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_COUNTRY, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_HPHONE, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_WPHONE, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_FAX, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_EMAIL, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_URL, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_GROUP, B_STRING_TYPE, 0);
|
||||
fs_create_index(vol.Device(), P_NICKNAME, B_STRING_TYPE, 0);
|
||||
// create indices on the boot volume
|
||||
// ToDo: on other volumes as well?
|
||||
|
||||
BVolumeRoster roster;
|
||||
BVolume volume;
|
||||
roster.GetBootVolume(&volume);
|
||||
|
||||
for (int32 i = 0; gFields[i].attribute; i++) {
|
||||
fs_create_index(volume.Device(), gFields[i].attribute, B_STRING_TYPE, 0);
|
||||
}
|
||||
|
||||
// install person mime type
|
||||
|
||||
bool valid = false;
|
||||
BMimeType mime;
|
||||
mime.SetType(B_PERSON_MIMETYPE);
|
||||
|
||||
if (mime.IsInstalled()) {
|
||||
if (mime.GetAttrInfo(&info) == B_NO_ERROR) {
|
||||
while (info.FindString("attr:name", index++, &str) == B_NO_ERROR) {
|
||||
if (!strcmp(str, P_NAME)) {
|
||||
valid = TRUE;
|
||||
if (!strcmp(str, gFields[0].attribute)) {
|
||||
valid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -101,207 +109,67 @@ TPeopleApp::TPeopleApp(void)
|
|||
}
|
||||
}
|
||||
if (!valid) {
|
||||
BBitmap largeIcon(BRect(0, 0, B_LARGE_ICON - 1, B_LARGE_ICON - 1), B_COLOR_8_BIT);
|
||||
BBitmap miniIcon(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_COLOR_8_BIT);
|
||||
|
||||
mime.Install();
|
||||
large_icon.SetBits(kLargePersonIcon, large_icon.BitsLength(), 0, B_COLOR_8_BIT);
|
||||
mini_icon.SetBits(kSmallPersonIcon, mini_icon.BitsLength(), 0, B_COLOR_8_BIT);
|
||||
largeIcon.SetBits(kLargePersonIcon, largeIcon.BitsLength(), 0, B_COLOR_8_BIT);
|
||||
miniIcon.SetBits(kSmallPersonIcon, miniIcon.BitsLength(), 0, B_COLOR_8_BIT);
|
||||
mime.SetShortDescription("Person");
|
||||
mime.SetLongDescription("Contact information for a person.");
|
||||
mime.SetIcon(&large_icon, B_LARGE_ICON);
|
||||
mime.SetIcon(&mini_icon, B_MINI_ICON);
|
||||
mime.SetIcon(&largeIcon, B_LARGE_ICON);
|
||||
mime.SetIcon(&miniIcon, B_MINI_ICON);
|
||||
mime.SetPreferredApp(APP_SIG);
|
||||
|
||||
// add relevant person fields to meta-mime type
|
||||
msg.AddString("attr:public_name", "Contact Name");
|
||||
msg.AddString("attr:name", P_NAME);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Company");
|
||||
msg.AddString("attr:name", P_COMPANY);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Address");
|
||||
msg.AddString("attr:name", P_ADDRESS);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "City");
|
||||
msg.AddString("attr:name", P_CITY);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 90);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "State");
|
||||
msg.AddString("attr:name", P_STATE);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 50);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Zip");
|
||||
msg.AddString("attr:name", P_ZIP);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 50);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Country");
|
||||
msg.AddString("attr:name", P_COUNTRY);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Home Phone");
|
||||
msg.AddString("attr:name", P_HPHONE);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 90);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Work Phone");
|
||||
msg.AddString("attr:name", P_WPHONE);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 90);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Fax");
|
||||
msg.AddString("attr:name", P_FAX);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 90);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "E-mail");
|
||||
msg.AddString("attr:name", P_EMAIL);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "URL");
|
||||
msg.AddString("attr:name", P_URL);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Group");
|
||||
msg.AddString("attr:name", P_GROUP);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
|
||||
msg.AddString("attr:public_name", "Nickname");
|
||||
msg.AddString("attr:name", P_NICKNAME);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", 120);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
for (int32 i = 0; gFields[i].attribute; i++) {
|
||||
msg.AddString("attr:public_name", gFields[i].name);
|
||||
msg.AddString("attr:name", gFields[i].attribute);
|
||||
msg.AddInt32("attr:type", B_STRING_TYPE);
|
||||
msg.AddBool("attr:viewable", true);
|
||||
msg.AddBool("attr:editable", true);
|
||||
msg.AddInt32("attr:width", gFields[i].width);
|
||||
msg.AddInt32("attr:alignment", B_ALIGN_LEFT);
|
||||
msg.AddBool("attr:extra", false);
|
||||
}
|
||||
|
||||
mime.SetAttrInfo(&msg);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TPeopleApp::~TPeopleApp(void)
|
||||
{
|
||||
if (fPrefs)
|
||||
delete fPrefs;
|
||||
delete fPrefs;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleApp::AboutRequested(void)
|
||||
void
|
||||
TPeopleApp::AboutRequested(void)
|
||||
{
|
||||
(new BAlert("", "...by Robert Polic", "Big Deal"))->Go();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleApp::ArgvReceived(int32 argc, char **argv)
|
||||
void
|
||||
TPeopleApp::ArgvReceived(int32 argc, char **argv)
|
||||
{
|
||||
char *arg;
|
||||
int32 index;
|
||||
int32 loop;
|
||||
TPeopleWindow *window = NULL;
|
||||
TPeopleWindow* window = NULL;
|
||||
|
||||
for (loop = 1; loop < argc; loop++) {
|
||||
arg = argv[loop];
|
||||
if (!strncmp(P_NAME, arg, strlen(P_NAME)))
|
||||
index = F_NAME;
|
||||
else if (!strncmp(P_COMPANY, arg, strlen(P_COMPANY)))
|
||||
index = F_COMPANY;
|
||||
else if (!strncmp(P_ADDRESS, arg, strlen(P_ADDRESS)))
|
||||
index = F_ADDRESS;
|
||||
else if (!strncmp(P_CITY, arg, strlen(P_CITY)))
|
||||
index = F_CITY;
|
||||
else if (!strncmp(P_STATE, arg, strlen(P_STATE)))
|
||||
index = F_STATE;
|
||||
else if (!strncmp(P_ZIP, arg, strlen(P_ZIP)))
|
||||
index = F_ZIP;
|
||||
else if (!strncmp(P_COUNTRY, arg, strlen(P_COUNTRY)))
|
||||
index = F_COUNTRY;
|
||||
else if (!strncmp(P_HPHONE, arg, strlen(P_HPHONE)))
|
||||
index = F_HPHONE;
|
||||
else if (!strncmp(P_WPHONE, arg, strlen(P_WPHONE)))
|
||||
index = F_WPHONE;
|
||||
else if (!strncmp(P_FAX, arg, strlen(P_FAX)))
|
||||
index = F_FAX;
|
||||
else if (!strncmp(P_EMAIL, arg, strlen(P_EMAIL)))
|
||||
index = F_EMAIL;
|
||||
else if (!strncmp(P_URL, arg, strlen(P_URL)))
|
||||
index = F_URL;
|
||||
else if (!strncmp(P_GROUP, arg, strlen(P_GROUP)))
|
||||
index = F_GROUP;
|
||||
else if (!strncmp(P_NICKNAME, arg, strlen(P_NICKNAME)))
|
||||
index = F_NICKNAME;
|
||||
else
|
||||
index = F_END;
|
||||
for (int32 loop = 1; loop < argc; loop++) {
|
||||
char* arg = argv[loop];
|
||||
|
||||
if (index != F_END) {
|
||||
int32 index;
|
||||
for (index = 0; gFields[index].attribute; index++) {
|
||||
if (!strncmp(gFields[index].attribute, arg, strlen(gFields[index].attribute)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (gFields[index].attribute != NULL) {
|
||||
if (!window)
|
||||
window = NewWindow();
|
||||
while(*arg != ' ')
|
||||
while (*arg != ' ')
|
||||
arg++;
|
||||
arg++;
|
||||
window->SetField(index, arg);
|
||||
|
@ -309,9 +177,9 @@ void TPeopleApp::ArgvReceived(int32 argc, char **argv)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleApp::MessageReceived(BMessage *msg)
|
||||
void
|
||||
TPeopleApp::MessageReceived(BMessage *msg)
|
||||
{
|
||||
switch (msg->what) {
|
||||
case M_NEW:
|
||||
|
@ -323,44 +191,44 @@ void TPeopleApp::MessageReceived(BMessage *msg)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleApp::RefsReceived(BMessage *msg)
|
||||
void
|
||||
TPeopleApp::RefsReceived(BMessage *message)
|
||||
{
|
||||
int32 item = 0;
|
||||
BFile file;
|
||||
entry_ref ref;
|
||||
TPeopleWindow *window;
|
||||
int32 index = 0;
|
||||
|
||||
while (msg->HasRef("refs", item)) {
|
||||
msg->FindRef("refs", item++, &ref);
|
||||
if ((window = FindWindow(ref)))
|
||||
window->Activate(TRUE);
|
||||
while (message->HasRef("refs", index)) {
|
||||
entry_ref ref;
|
||||
message->FindRef("refs", index++, &ref);
|
||||
|
||||
TPeopleWindow* window = FindWindow(ref);
|
||||
if (window != NULL)
|
||||
window->Activate(true);
|
||||
else {
|
||||
file.SetTo(&ref, O_RDONLY);
|
||||
if (file.InitCheck() == B_NO_ERROR)
|
||||
BFile file(&ref, B_READ_ONLY);
|
||||
if (file.InitCheck() == B_OK)
|
||||
NewWindow(&ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleApp::ReadyToRun(void)
|
||||
void
|
||||
TPeopleApp::ReadyToRun(void)
|
||||
{
|
||||
if (!fHaveWindow)
|
||||
NewWindow();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TPeopleWindow* TPeopleApp::NewWindow(entry_ref *ref)
|
||||
TPeopleWindow*
|
||||
TPeopleApp::NewWindow(entry_ref *ref)
|
||||
{
|
||||
TPeopleWindow *window;
|
||||
TPeopleWindow *window;
|
||||
|
||||
window = new TPeopleWindow(fPosition, "New Person", ref);
|
||||
window->Show();
|
||||
fHaveWindow = TRUE;
|
||||
fHaveWindow = true;
|
||||
fPosition.OffsetBy(20, 20);
|
||||
|
||||
if (fPosition.bottom > BScreen(B_MAIN_SCREEN_ID).Frame().bottom)
|
||||
|
@ -371,15 +239,15 @@ TPeopleWindow* TPeopleApp::NewWindow(entry_ref *ref)
|
|||
return window;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TPeopleWindow* TPeopleApp::FindWindow(entry_ref ref)
|
||||
TPeopleWindow*
|
||||
TPeopleApp::FindWindow(entry_ref ref)
|
||||
{
|
||||
int32 index = 0;
|
||||
TPeopleWindow *window;
|
||||
TPeopleWindow* window;
|
||||
int32 index = 0;
|
||||
|
||||
while ((window = (TPeopleWindow *)WindowAt(index++))) {
|
||||
if ((window->FindView("PeopleView")) && (window->fRef) && (*(window->fRef) == ref))
|
||||
if (window->FindView("PeopleView") != NULL && window->fRef && *window->fRef == ref)
|
||||
return window;
|
||||
}
|
||||
return NULL;
|
||||
|
|
|
@ -13,61 +13,56 @@
|
|||
#ifndef PEOPLEAPP_H
|
||||
#define PEOPLEAPP_H
|
||||
|
||||
#define B_PERSON_MIMETYPE "application/x-person"
|
||||
#define APP_SIG "application/x-vnd.Be-PEPL"
|
||||
|
||||
#define P_NAME "META:name"
|
||||
#define P_NICKNAME "META:nickname"
|
||||
#define P_COMPANY "META:company"
|
||||
#define P_ADDRESS "META:address"
|
||||
#define P_CITY "META:city"
|
||||
#define P_STATE "META:state"
|
||||
#define P_ZIP "META:zip"
|
||||
#define P_COUNTRY "META:country"
|
||||
#define P_HPHONE "META:hphone"
|
||||
#define P_WPHONE "META:wphone"
|
||||
#define P_FAX "META:fax"
|
||||
#define P_EMAIL "META:email"
|
||||
#define P_URL "META:url"
|
||||
#define P_GROUP "META:group"
|
||||
|
||||
enum MESSAGES {M_NEW = 128, M_SAVE, M_SAVE_AS, M_REVERT,
|
||||
M_UNDO, M_SELECT, M_GROUP_MENU, M_DIRTY,
|
||||
M_NAME, M_NICKNAME, M_COMPANY, M_ADDRESS,
|
||||
M_CITY, M_STATE, M_ZIP, M_COUNTRY, M_HPHONE,
|
||||
M_WPHONE, M_FAX, M_EMAIL, M_URL, M_GROUP};
|
||||
|
||||
enum FIELDS {F_NAME = 0, F_NICKNAME, F_COMPANY, F_ADDRESS,
|
||||
F_CITY, F_STATE, F_ZIP, F_COUNTRY, F_HPHONE,
|
||||
F_WPHONE, F_FAX, F_EMAIL, F_URL, F_GROUP, F_END};
|
||||
|
||||
class TPeopleWindow;
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
#include <Application.h>
|
||||
|
||||
|
||||
#define B_PERSON_MIMETYPE "application/x-person"
|
||||
#define APP_SIG "application/x-vnd.Be-PEPL"
|
||||
|
||||
struct people_field {
|
||||
const char* attribute;
|
||||
int32 width;
|
||||
const char* name;
|
||||
};
|
||||
extern people_field gFields[];
|
||||
|
||||
enum messages{
|
||||
M_NEW = 128, M_SAVE, M_SAVE_AS, M_REVERT,
|
||||
M_UNDO, M_SELECT, M_GROUP_MENU, M_DIRTY,
|
||||
M_NAME, M_NICKNAME, M_COMPANY, M_ADDRESS,
|
||||
M_CITY, M_STATE, M_ZIP, M_COUNTRY, M_HPHONE,
|
||||
M_WPHONE, M_FAX, M_EMAIL, M_URL, M_GROUP
|
||||
};
|
||||
|
||||
enum fields {
|
||||
F_NAME = 0, F_NICKNAME, F_COMPANY, F_ADDRESS,
|
||||
F_CITY, F_STATE, F_ZIP, F_COUNTRY, F_HPHONE,
|
||||
F_WPHONE, F_FAX, F_EMAIL, F_URL, F_GROUP, F_END
|
||||
};
|
||||
|
||||
class TPeopleWindow;
|
||||
|
||||
//====================================================================
|
||||
|
||||
class TPeopleApp : public BApplication {
|
||||
public:
|
||||
TPeopleApp(void);
|
||||
virtual ~TPeopleApp(void);
|
||||
|
||||
private:
|
||||
virtual void AboutRequested(void);
|
||||
virtual void ArgvReceived(int32, char**);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual void RefsReceived(BMessage*);
|
||||
virtual void ReadyToRun(void);
|
||||
TPeopleWindow *FindWindow(entry_ref);
|
||||
TPeopleWindow *NewWindow(entry_ref* = NULL);
|
||||
|
||||
bool fHaveWindow;
|
||||
BRect fPosition;
|
||||
BFile *fPrefs;
|
||||
|
||||
public:
|
||||
|
||||
BFile *fPrefs;
|
||||
|
||||
TPeopleApp(void);
|
||||
~TPeopleApp(void);
|
||||
virtual void AboutRequested(void);
|
||||
virtual void ArgvReceived(int32, char**);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual void RefsReceived(BMessage*);
|
||||
virtual void ReadyToRun(void);
|
||||
TPeopleWindow *FindWindow(entry_ref);
|
||||
TPeopleWindow *NewWindow(entry_ref* = NULL);
|
||||
private:
|
||||
bool fHaveWindow;
|
||||
BRect fPosition;
|
||||
};
|
||||
|
||||
#endif /* PEOPLEAPP_H */
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#include <PopUpMenu.h>
|
||||
#include <Query.h>
|
||||
#include <VolumeRoster.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "PeopleView.h"
|
||||
#include "TTextControl.h"
|
||||
|
||||
//====================================================================
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
TPeopleView::TPeopleView(BRect rect, char *title, entry_ref *ref)
|
||||
:BView(rect, title, B_FOLLOW_ALL, B_WILL_DRAW)
|
||||
|
@ -36,280 +36,93 @@ TPeopleView::TPeopleView(BRect rect, char *title, entry_ref *ref)
|
|||
fFile = NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TPeopleView::~TPeopleView(void)
|
||||
{
|
||||
if (fFile)
|
||||
delete fFile;
|
||||
delete fFile;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::AttachedToWindow(void)
|
||||
void
|
||||
TPeopleView::AttachedToWindow(void)
|
||||
{
|
||||
char *text;
|
||||
float offset;
|
||||
BBox *box;
|
||||
BFont font = *be_plain_font;
|
||||
BMenuField *field;
|
||||
BRect r;
|
||||
attr_info info;
|
||||
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
|
||||
r = Bounds();
|
||||
r.InsetBy(-1, -1);
|
||||
box = new BBox(r);
|
||||
AddChild(box);
|
||||
BRect bounds = Bounds();
|
||||
|
||||
offset = font.StringWidth(HPHONE_TEXT) + 18;
|
||||
BFont font = *be_plain_font;
|
||||
int32 offset = int32(font.StringWidth(HPHONE_TEXT) + 10.5);
|
||||
BRect rect;
|
||||
int32 row = 0;
|
||||
|
||||
text = (char *)malloc(1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(NAME_TEXT) - 11, NAME_V,
|
||||
NAME_H + NAME_WIDTH, NAME_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_NAME, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_NAME, B_STRING_TYPE, 0, text, info.size);
|
||||
for (int32 i = 0; gFields[i].attribute; i++, row++) {
|
||||
const char *name = gFields[i].name;
|
||||
|
||||
rect.Set(NAME_H, NAME_V + row * 25,
|
||||
bounds.right - NAME_H, NAME_V + (row + 1) * 25);
|
||||
int32 labelOffset = offset;
|
||||
|
||||
if (i == F_NAME)
|
||||
name = "Name";
|
||||
else if (i == F_GROUP) {
|
||||
name = "";
|
||||
rect.left += offset;
|
||||
labelOffset = 0;
|
||||
} else if (i == F_STATE) {
|
||||
rect.right = rect.left + STATE_WIDTH;
|
||||
row--;
|
||||
} else if (i == F_ZIP) {
|
||||
rect.left += STATE_WIDTH + 10;
|
||||
labelOffset = int32(font.StringWidth(gFields[i].name) + 10.5);
|
||||
}
|
||||
}
|
||||
fField[F_NAME] = new TTextControl(r, NAME_TEXT, 256,
|
||||
text, M_DIRTY, M_NAME);
|
||||
fField[F_NAME]->SetTarget(this);
|
||||
box->AddChild(fField[F_NAME]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(NICKNAME_TEXT) - 11, NICKNAME_V,
|
||||
NICKNAME_H + NICKNAME_WIDTH, NICKNAME_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_NICKNAME, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_NICKNAME, B_STRING_TYPE, 0, text, info.size);
|
||||
char *text = NULL;
|
||||
attr_info info;
|
||||
if (fFile && fFile->GetAttrInfo(gFields[i].attribute, &info) == B_OK) {
|
||||
text = (char *)calloc(info.size, 1);
|
||||
fFile->ReadAttr(gFields[i].attribute, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_NICKNAME] = new TTextControl(r, NICKNAME_TEXT, 256,
|
||||
text, M_DIRTY, M_NICKNAME);
|
||||
fField[F_NICKNAME]->SetTarget(this);
|
||||
box->AddChild(fField[F_NICKNAME]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(COMPANY_TEXT) - 11, COMPANY_V,
|
||||
COMPANY_H + COMPANY_WIDTH, COMPANY_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_COMPANY, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_COMPANY, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_COMPANY] = new TTextControl(r, COMPANY_TEXT, 256,
|
||||
text, M_DIRTY, M_COMPANY);
|
||||
fField[F_COMPANY]->SetTarget(this);
|
||||
box->AddChild(fField[F_COMPANY]);
|
||||
fField[i] = new TTextControl(rect, name, labelOffset, text, M_DIRTY, M_NAME);
|
||||
fField[i]->SetTarget(this);
|
||||
AddChild(fField[i]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(ADDRESS_TEXT) - 11, ADDRESS_V,
|
||||
ADDRESS_H + ADDRESS_WIDTH, ADDRESS_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_ADDRESS, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_ADDRESS, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
free(text);
|
||||
}
|
||||
fField[F_ADDRESS] = new TTextControl(r, ADDRESS_TEXT, 256,
|
||||
text, M_DIRTY, M_ADDRESS);
|
||||
fField[F_ADDRESS]->SetTarget(this);
|
||||
box->AddChild(fField[F_ADDRESS]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(CITY_TEXT) - 11, CITY_V,
|
||||
CITY_H + CITY_WIDTH, CITY_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_CITY, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_CITY, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_CITY] = new TTextControl(r, CITY_TEXT, 256,
|
||||
text, M_DIRTY, M_CITY);
|
||||
fField[F_CITY]->SetTarget(this);
|
||||
box->AddChild(fField[F_CITY]);
|
||||
rect.right = NAME_H + offset;
|
||||
rect.left = rect.right - font.StringWidth(gFields[F_GROUP].name) - 32;
|
||||
rect.top -= 1;
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(STATE_TEXT) - 11, STATE_V,
|
||||
STATE_H + STATE_WIDTH, STATE_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_STATE, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_STATE, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_STATE] = new TTextControl(r, STATE_TEXT, 256,
|
||||
text, M_DIRTY, M_STATE);
|
||||
fField[F_STATE]->SetTarget(this);
|
||||
box->AddChild(fField[F_STATE]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(ZIP_H + 11, ZIP_V,
|
||||
ZIP_H + ZIP_WIDTH, ZIP_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_ZIP, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_ZIP, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_ZIP] = new TTextControl(r, ZIP_TEXT, 256,
|
||||
text, M_DIRTY, M_ZIP);
|
||||
fField[F_ZIP]->SetTarget(this);
|
||||
box->AddChild(fField[F_ZIP]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(COUNTRY_TEXT) - 11, COUNTRY_V,
|
||||
COUNTRY_H + COUNTRY_WIDTH, COUNTRY_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_COUNTRY, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_COUNTRY, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_COUNTRY] = new TTextControl(r, COUNTRY_TEXT, 256,
|
||||
text, M_DIRTY, M_COUNTRY);
|
||||
fField[F_COUNTRY]->SetTarget(this);
|
||||
box->AddChild(fField[F_COUNTRY]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(HPHONE_TEXT) - 11, HPHONE_V,
|
||||
HPHONE_H + HPHONE_WIDTH, HPHONE_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_HPHONE, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_HPHONE, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_HPHONE] = new TTextControl(r, HPHONE_TEXT, 256,
|
||||
text, M_DIRTY, M_HPHONE);
|
||||
fField[F_HPHONE]->SetTarget(this);
|
||||
box->AddChild(fField[F_HPHONE]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(WPHONE_TEXT) - 11, WPHONE_V,
|
||||
WPHONE_H + WPHONE_WIDTH, WPHONE_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_WPHONE, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_WPHONE, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_WPHONE] = new TTextControl(r, WPHONE_TEXT, 256,
|
||||
text, M_DIRTY, M_WPHONE);
|
||||
fField[F_WPHONE]->SetTarget(this);
|
||||
box->AddChild(fField[F_WPHONE]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(FAX_TEXT) - 11, FAX_V,
|
||||
FAX_H + FAX_WIDTH, FAX_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_FAX, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_FAX, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_FAX] = new TTextControl(r, FAX_TEXT, 256,
|
||||
text, M_DIRTY, M_FAX);
|
||||
fField[F_FAX]->SetTarget(this);
|
||||
box->AddChild(fField[F_FAX]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(EMAIL_TEXT) - 11, EMAIL_V,
|
||||
EMAIL_H + EMAIL_WIDTH, EMAIL_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_EMAIL, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_EMAIL, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_EMAIL] = new TTextControl(r, EMAIL_TEXT, 256,
|
||||
text, M_DIRTY, M_EMAIL);
|
||||
fField[F_EMAIL]->SetTarget(this);
|
||||
box->AddChild(fField[F_EMAIL]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - font.StringWidth(URL_TEXT) - 11, URL_V,
|
||||
URL_H + URL_WIDTH, URL_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_URL, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_URL, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_URL] = new TTextControl(r, URL_TEXT, 256,
|
||||
text, M_DIRTY, M_URL);
|
||||
fField[F_URL]->SetTarget(this);
|
||||
box->AddChild(fField[F_URL]);
|
||||
|
||||
text = (char *)realloc(text, 1);
|
||||
text[0] = 0;
|
||||
r.Set(offset - 11, GROUP_V,
|
||||
GROUP_H + GROUP_WIDTH, GROUP_V + TEXT_HEIGHT);
|
||||
if (fFile) {
|
||||
if (fFile->GetAttrInfo(P_GROUP, &info) == B_NO_ERROR) {
|
||||
text = (char *)realloc(text, info.size);
|
||||
fFile->ReadAttr(P_GROUP, B_STRING_TYPE, 0, text, info.size);
|
||||
}
|
||||
}
|
||||
fField[F_GROUP] = new TTextControl(r, "", 256,
|
||||
text, M_DIRTY, M_GROUP);
|
||||
fField[F_GROUP]->SetTarget(this);
|
||||
box->AddChild(fField[F_GROUP]);
|
||||
free(text);
|
||||
|
||||
r.right = r.left + 3;
|
||||
r.left = r.right - font.StringWidth(GROUP_TEXT) - 20;
|
||||
r.top -= 1;
|
||||
fGroups = new BPopUpMenu("Group");
|
||||
fGroups->SetRadioMode(FALSE);
|
||||
field = new BMenuField(r, "", "", fGroups);
|
||||
fGroups = new BPopUpMenu(gFields[F_GROUP].name);
|
||||
fGroups->SetRadioMode(false);
|
||||
BMenuField *field = new BMenuField(rect, "", "", fGroups);
|
||||
field->SetDivider(0.0);
|
||||
field->SetFont(&font);
|
||||
field->SetEnabled(TRUE);
|
||||
box->AddChild(field);
|
||||
field->SetEnabled(true);
|
||||
AddChild(field);
|
||||
|
||||
fField[F_NAME]->MakeFocus();
|
||||
ResizeTo(bounds.right, rect.bottom + NAME_V);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::MessageReceived(BMessage* msg)
|
||||
void
|
||||
TPeopleView::MessageReceived(BMessage* msg)
|
||||
{
|
||||
int32 loop;
|
||||
BTextView *text;
|
||||
|
||||
switch (msg->what) {
|
||||
case M_SAVE:
|
||||
Save();
|
||||
break;
|
||||
|
||||
case M_REVERT:
|
||||
for (loop = 0; loop < F_END; loop++)
|
||||
for (int32 loop = 0; loop < F_END; loop++)
|
||||
fField[loop]->Revert();
|
||||
break;
|
||||
|
||||
case M_SELECT:
|
||||
for (loop = 0; loop < F_END; loop++) {
|
||||
text = (BTextView *)fField[loop]->ChildAt(0);
|
||||
for (int32 loop = 0; loop < F_END; loop++) {
|
||||
BTextView* text = (BTextView *)fField[loop]->ChildAt(0);
|
||||
if (text->IsFocus()) {
|
||||
text->Select(0, text->TextLength());
|
||||
break;
|
||||
|
@ -319,218 +132,162 @@ void TPeopleView::MessageReceived(BMessage* msg)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::BuildGroupMenu(void)
|
||||
void
|
||||
TPeopleView::BuildGroupMenu(void)
|
||||
{
|
||||
char *offset;
|
||||
char str[256];
|
||||
char *text;
|
||||
char *text1;
|
||||
int32 count = 0;
|
||||
int32 index;
|
||||
BEntry entry;
|
||||
BFile file;
|
||||
BMessage *msg;
|
||||
BMenuItem *item;
|
||||
BQuery query;
|
||||
BVolume vol;
|
||||
BVolumeRoster volume;
|
||||
attr_info info;
|
||||
|
||||
while ((item = fGroups->ItemAt(0))) {
|
||||
BMenuItem* item;
|
||||
while ((item = fGroups->ItemAt(0)) != NULL) {
|
||||
fGroups->RemoveItem(item);
|
||||
delete item;
|
||||
}
|
||||
|
||||
volume.GetBootVolume(&vol);
|
||||
query.SetVolume(&vol);
|
||||
sprintf(str, "%s=*", P_GROUP);
|
||||
query.SetPredicate(str);
|
||||
query.Fetch();
|
||||
const char *groupAttribute = gFields[F_GROUP].attribute;
|
||||
int32 count = 0;
|
||||
|
||||
while (query.GetNextEntry(&entry) == B_NO_ERROR) {
|
||||
file.SetTo(&entry, O_RDONLY);
|
||||
if ((file.InitCheck() == B_NO_ERROR) &&
|
||||
(file.GetAttrInfo(P_GROUP, &info) == B_NO_ERROR) &&
|
||||
(info.size > 1)) {
|
||||
text = (char *)malloc(info.size);
|
||||
text1 = text;
|
||||
file.ReadAttr(P_GROUP, B_STRING_TYPE, 0, text, info.size);
|
||||
while (1) {
|
||||
if ((offset = strstr(text, ",")))
|
||||
*offset = 0;
|
||||
if (!fGroups->FindItem(text)) {
|
||||
index = 0;
|
||||
while ((item = fGroups->ItemAt(index))) {
|
||||
if (strcmp(text, item->Label()) < 0)
|
||||
break;
|
||||
index++;
|
||||
BVolumeRoster volumeRoster;
|
||||
BVolume volume;
|
||||
while (volumeRoster.GetNextVolume(&volume) == B_OK) {
|
||||
BQuery query;
|
||||
query.SetVolume(&volume);
|
||||
|
||||
char buffer[256];
|
||||
sprintf(buffer, "%s=*", groupAttribute);
|
||||
query.SetPredicate(buffer);
|
||||
query.Fetch();
|
||||
|
||||
BEntry entry;
|
||||
while (query.GetNextEntry(&entry) == B_OK) {
|
||||
BFile file(&entry, B_READ_ONLY);
|
||||
attr_info info;
|
||||
|
||||
if (file.InitCheck() == B_OK
|
||||
&& file.GetAttrInfo(groupAttribute, &info) == B_OK
|
||||
&& info.size > 1) {
|
||||
if (info.size > sizeof(buffer))
|
||||
info.size = sizeof(buffer);
|
||||
|
||||
if (file.ReadAttr(groupAttribute, B_STRING_TYPE, 0, buffer, info.size) < B_OK)
|
||||
continue;
|
||||
|
||||
const char *text = buffer;
|
||||
while (true) {
|
||||
char* offset = strstr(text, ",");
|
||||
if (offset != NULL)
|
||||
offset[0] = '\0';
|
||||
|
||||
if (!fGroups->FindItem(text)) {
|
||||
int32 index = 0;
|
||||
while ((item = fGroups->ItemAt(index)) != NULL) {
|
||||
if (strcmp(text, item->Label()) < 0)
|
||||
break;
|
||||
index++;
|
||||
}
|
||||
BMessage* message = new BMessage(M_GROUP_MENU);
|
||||
message->AddString("group", text);
|
||||
fGroups->AddItem(new BMenuItem(text, message), index);
|
||||
count++;
|
||||
}
|
||||
msg = new BMessage(M_GROUP_MENU);
|
||||
msg->AddString("group", text);
|
||||
fGroups->AddItem(new BMenuItem(text, msg), index);
|
||||
count++;
|
||||
if (offset) {
|
||||
text = offset + 1;
|
||||
while (*text == ' ')
|
||||
text++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
if (offset) {
|
||||
text = offset + 1;
|
||||
while (*text == ' ')
|
||||
text++;
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
free(text1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!count) {
|
||||
fGroups->AddItem(item = new BMenuItem("none", new BMessage(M_GROUP_MENU)));
|
||||
item->SetEnabled(FALSE);
|
||||
item->SetEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
bool TPeopleView::CheckSave(void)
|
||||
bool
|
||||
TPeopleView::CheckSave(void)
|
||||
{
|
||||
int32 loop;
|
||||
|
||||
for (loop = 0; loop < F_END; loop++)
|
||||
for (int32 loop = 0; loop < F_END; loop++) {
|
||||
if (fField[loop]->Changed())
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
const char* TPeopleView::GetField(int32 index)
|
||||
const char*
|
||||
TPeopleView::GetField(int32 index)
|
||||
{
|
||||
if (index < F_END)
|
||||
return fField[index]->Text();
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::NewFile(entry_ref *ref)
|
||||
void
|
||||
TPeopleView::NewFile(entry_ref *ref)
|
||||
{
|
||||
if (fFile)
|
||||
delete fFile;
|
||||
fFile = new BFile(ref, O_RDWR);
|
||||
delete fFile;
|
||||
fFile = new BFile(ref, B_READ_WRITE);
|
||||
Save();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::Save(void)
|
||||
void
|
||||
TPeopleView::Save(void)
|
||||
{
|
||||
const char *text;
|
||||
|
||||
text = fField[F_NAME]->Text();
|
||||
fFile->WriteAttr(P_NAME, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_NAME]->Update();
|
||||
|
||||
text = fField[F_COMPANY]->Text();
|
||||
fFile->WriteAttr(P_COMPANY, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_COMPANY]->Update();
|
||||
|
||||
text = fField[F_ADDRESS]->Text();
|
||||
fFile->WriteAttr(P_ADDRESS, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_ADDRESS]->Update();
|
||||
|
||||
text = fField[F_CITY]->Text();
|
||||
fFile->WriteAttr(P_CITY, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_CITY]->Update();
|
||||
|
||||
text = fField[F_STATE]->Text();
|
||||
fFile->WriteAttr(P_STATE, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_STATE]->Update();
|
||||
|
||||
text = fField[F_ZIP]->Text();
|
||||
fFile->WriteAttr(P_ZIP, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_ZIP]->Update();
|
||||
|
||||
text = fField[F_COUNTRY]->Text();
|
||||
fFile->WriteAttr(P_COUNTRY, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_COUNTRY]->Update();
|
||||
|
||||
text = fField[F_HPHONE]->Text();
|
||||
fFile->WriteAttr(P_HPHONE, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_HPHONE]->Update();
|
||||
|
||||
text = fField[F_WPHONE]->Text();
|
||||
fFile->WriteAttr(P_WPHONE, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_WPHONE]->Update();
|
||||
|
||||
text = fField[F_FAX]->Text();
|
||||
fFile->WriteAttr(P_FAX, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_FAX]->Update();
|
||||
|
||||
text = fField[F_EMAIL]->Text();
|
||||
fFile->WriteAttr(P_EMAIL, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_EMAIL]->Update();
|
||||
|
||||
text = fField[F_URL]->Text();
|
||||
fFile->WriteAttr(P_URL, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_URL]->Update();
|
||||
|
||||
text = fField[F_GROUP]->Text();
|
||||
fFile->WriteAttr(P_GROUP, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_GROUP]->Update();
|
||||
|
||||
text = fField[F_NICKNAME]->Text();
|
||||
fFile->WriteAttr(P_NICKNAME, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[F_NICKNAME]->Update();
|
||||
for (int32 i = 0; gFields[i].attribute; i++) {
|
||||
const char *text = fField[i]->Text();
|
||||
fFile->WriteAttr(gFields[i].attribute, B_STRING_TYPE, 0, text, strlen(text) + 1);
|
||||
fField[i]->Update();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleView::SetField(int32 index, char *data, bool update)
|
||||
void
|
||||
TPeopleView::SetField(int32 index, char *data, bool update)
|
||||
{
|
||||
int32 end;
|
||||
int32 start;
|
||||
BTextView *text;
|
||||
|
||||
Window()->Lock();
|
||||
|
||||
if (update) {
|
||||
fField[index]->SetText(data);
|
||||
fField[index]->Update();
|
||||
}
|
||||
else {
|
||||
text = (BTextView *)fField[index]->ChildAt(0);
|
||||
} else {
|
||||
BTextView* text = (BTextView *)fField[index]->ChildAt(0);
|
||||
|
||||
int32 start, end;
|
||||
text->GetSelection(&start, &end);
|
||||
if (start != end) {
|
||||
text->Delete();
|
||||
text->Insert(data);
|
||||
}
|
||||
else if ((end = text->TextLength())) {
|
||||
} else if ((end = text->TextLength())) {
|
||||
text->Select(end, end);
|
||||
text->Insert(",");
|
||||
text->Insert(data);
|
||||
text->Select(text->TextLength(), text->TextLength());
|
||||
}
|
||||
else
|
||||
} else
|
||||
fField[index]->SetText(data);
|
||||
}
|
||||
|
||||
Window()->Unlock();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
bool TPeopleView::TextSelected(void)
|
||||
bool
|
||||
TPeopleView::TextSelected(void)
|
||||
{
|
||||
int32 end;
|
||||
int32 loop;
|
||||
int32 start;
|
||||
BTextView *text;
|
||||
for (int32 loop = 0; loop < F_END; loop++) {
|
||||
BTextView* text = (BTextView*)fField[loop]->ChildAt(0);
|
||||
|
||||
for (loop = 0; loop < F_END; loop++) {
|
||||
text = (BTextView *)fField[loop]->ChildAt(0);
|
||||
int32 start, end;
|
||||
text->GetSelection(&start, &end);
|
||||
if (start != end)
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -19,86 +19,83 @@
|
|||
#define NAME_H 10
|
||||
#define NAME_V 10
|
||||
#define NAME_WIDTH 300
|
||||
#define NAME_TEXT "Name"
|
||||
#define NAME_TEXT "Name:"
|
||||
#define NICKNAME_H 10
|
||||
#define NICKNAME_V (NAME_V + 25)
|
||||
#define NICKNAME_WIDTH 300
|
||||
#define NICKNAME_TEXT "Nickname"
|
||||
#define NICKNAME_TEXT "Nickname:"
|
||||
#define COMPANY_H 10
|
||||
#define COMPANY_V (NICKNAME_V + 25)
|
||||
#define COMPANY_WIDTH 300
|
||||
#define COMPANY_TEXT "Company"
|
||||
#define COMPANY_TEXT "Company:"
|
||||
#define ADDRESS_H 10
|
||||
#define ADDRESS_V (COMPANY_V + 25)
|
||||
#define ADDRESS_WIDTH 300
|
||||
#define ADDRESS_TEXT "Address"
|
||||
#define ADDRESS_TEXT "Address:"
|
||||
#define CITY_H 10
|
||||
#define CITY_V (ADDRESS_V + 25)
|
||||
#define CITY_WIDTH 300
|
||||
#define CITY_TEXT "City"
|
||||
#define CITY_TEXT "City:"
|
||||
#define STATE_H 10
|
||||
#define STATE_V (CITY_V + 25)
|
||||
#define STATE_WIDTH 175
|
||||
#define STATE_TEXT "State"
|
||||
#define STATE_TEXT "State:"
|
||||
#define ZIP_H (STATE_H + STATE_WIDTH)
|
||||
#define ZIP_V (CITY_V + 25)
|
||||
#define ZIP_WIDTH 125
|
||||
#define ZIP_TEXT "Zip"
|
||||
#define ZIP_TEXT "Zip:"
|
||||
#define COUNTRY_H 10
|
||||
#define COUNTRY_V (ZIP_V + 25)
|
||||
#define COUNTRY_WIDTH 300
|
||||
#define COUNTRY_TEXT "Country"
|
||||
#define COUNTRY_TEXT "Country:"
|
||||
#define HPHONE_H 10
|
||||
#define HPHONE_V (COUNTRY_V + 25)
|
||||
#define HPHONE_WIDTH 300
|
||||
#define HPHONE_TEXT "Home Phone"
|
||||
#define HPHONE_TEXT "Home Phone:"
|
||||
#define WPHONE_H 10
|
||||
#define WPHONE_V (HPHONE_V + 25)
|
||||
#define WPHONE_WIDTH 300
|
||||
#define WPHONE_TEXT "Work Phone"
|
||||
#define WPHONE_TEXT "Work Phone:"
|
||||
#define FAX_H 10
|
||||
#define FAX_V (WPHONE_V + 25)
|
||||
#define FAX_WIDTH 300
|
||||
#define FAX_TEXT "Fax"
|
||||
#define FAX_TEXT "Fax:"
|
||||
#define EMAIL_H 10
|
||||
#define EMAIL_V (FAX_V + 25)
|
||||
#define EMAIL_WIDTH 300
|
||||
#define EMAIL_TEXT "E-mail"
|
||||
#define EMAIL_TEXT "E-mail:"
|
||||
#define URL_H 10
|
||||
#define URL_V (EMAIL_V + 25)
|
||||
#define URL_WIDTH 300
|
||||
#define URL_TEXT "URL"
|
||||
#define URL_TEXT "URL:"
|
||||
#define GROUP_H 10
|
||||
#define GROUP_V (URL_V + 25)
|
||||
#define GROUP_WIDTH 300
|
||||
#define GROUP_TEXT "Group"
|
||||
#define GROUP_TEXT "Group:"
|
||||
|
||||
class TTextControl;
|
||||
|
||||
|
||||
//====================================================================
|
||||
|
||||
class TPeopleView : public BView {
|
||||
public:
|
||||
TPeopleView(BRect rect, char* title, entry_ref* ref);
|
||||
~TPeopleView(void);
|
||||
|
||||
private:
|
||||
virtual void AttachedToWindow(void);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
void BuildGroupMenu(void);
|
||||
bool CheckSave(void);
|
||||
const char* GetField(int32);
|
||||
void NewFile(entry_ref*);
|
||||
void Save(void);
|
||||
void SetField(int32, char*, bool);
|
||||
bool TextSelected(void);
|
||||
|
||||
BFile *fFile;
|
||||
BPopUpMenu *fGroups;
|
||||
TTextControl *fField[F_END];
|
||||
private:
|
||||
BFile *fFile;
|
||||
BPopUpMenu *fGroups;
|
||||
TTextControl *fField[F_END];
|
||||
|
||||
public:
|
||||
|
||||
TPeopleView(BRect, char*, entry_ref*);
|
||||
~TPeopleView(void);
|
||||
virtual void AttachedToWindow(void);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
void BuildGroupMenu(void);
|
||||
bool CheckSave(void);
|
||||
const char* GetField(int32);
|
||||
void NewFile(entry_ref*);
|
||||
void Save(void);
|
||||
void SetField(int32, char*, bool);
|
||||
bool TextSelected(void);
|
||||
};
|
||||
|
||||
#endif /* PEOPLEVIEW_H */
|
||||
|
|
|
@ -14,33 +14,29 @@
|
|||
#include <MenuItem.h>
|
||||
#include <FilePanel.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <stdio.h>
|
||||
#include <Alert.h>
|
||||
#include <Path.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Font.h>
|
||||
#include <Clipboard.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "PeopleApp.h"
|
||||
#include "PeopleView.h"
|
||||
#include "PeopleWindow.h"
|
||||
|
||||
//====================================================================
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
|
||||
:BWindow(rect, title, B_TITLED_WINDOW, B_NOT_RESIZABLE |
|
||||
B_NOT_ZOOMABLE)
|
||||
|
||||
TPeopleWindow::TPeopleWindow(BRect frame, char *title, entry_ref *ref)
|
||||
: BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
|
||||
fPanel(NULL)
|
||||
{
|
||||
BMenu *menu;
|
||||
BMenuBar *menu_bar;
|
||||
BMenuItem *item;
|
||||
BRect r;
|
||||
BMenu* menu;
|
||||
BMenuItem* item;
|
||||
|
||||
fPanel = NULL;
|
||||
|
||||
r.Set(0, 0, 32767, 15);
|
||||
menu_bar = new BMenuBar(r, "");
|
||||
BRect rect(0, 0, 32767, 15);
|
||||
BMenuBar* menuBar = new BMenuBar(rect, "");
|
||||
menu = new BMenu("File");
|
||||
menu->AddItem(item = new BMenuItem("New Person", new BMessage(M_NEW), 'N'));
|
||||
item->SetTarget(NULL, be_app);
|
||||
|
@ -53,7 +49,7 @@ TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
|
|||
fRevert->SetEnabled(FALSE);
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
|
||||
menu_bar->AddItem(menu);
|
||||
menuBar->AddItem(menu);
|
||||
|
||||
menu = new BMenu("Edit");
|
||||
menu->AddItem(fUndo = new BMenuItem("Undo", new BMessage(M_UNDO), 'Z'));
|
||||
|
@ -66,47 +62,41 @@ TPeopleWindow::TPeopleWindow(BRect rect, char *title, entry_ref *ref)
|
|||
fPaste->SetTarget(NULL, this);
|
||||
menu->AddItem(item = new BMenuItem("Select All", new BMessage(M_SELECT), 'A'));
|
||||
item->SetTarget(NULL, this);
|
||||
menu_bar->AddItem(menu);
|
||||
AddChild(menu_bar);
|
||||
menuBar->AddItem(menu);
|
||||
AddChild(menuBar);
|
||||
|
||||
if (ref) {
|
||||
fRef = new entry_ref(*ref);
|
||||
SetTitle(ref->name);
|
||||
}
|
||||
else
|
||||
} else
|
||||
fRef = NULL;
|
||||
|
||||
r = Frame();
|
||||
r.OffsetTo(0, menu_bar->Bounds().bottom + 1);
|
||||
fView = new TPeopleView(r, "PeopleView", fRef);
|
||||
rect = Frame();
|
||||
rect.OffsetTo(0, menuBar->Bounds().bottom + 1);
|
||||
fView = new TPeopleView(rect, "PeopleView", fRef);
|
||||
|
||||
ResizeBy(0, menu_bar->Bounds().bottom + 1);
|
||||
Lock();
|
||||
ResizeTo(frame.Width(), fView->Frame().bottom);
|
||||
AddChild(fView);
|
||||
Unlock();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TPeopleWindow::~TPeopleWindow(void)
|
||||
{
|
||||
if (fRef)
|
||||
delete fRef;
|
||||
if (fPanel)
|
||||
delete fPanel;
|
||||
delete fRef;
|
||||
delete fPanel;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleWindow::MenusBeginning(void)
|
||||
void
|
||||
TPeopleWindow::MenusBeginning(void)
|
||||
{
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
|
||||
enabled = fView->CheckSave();
|
||||
fSave->SetEnabled(enabled);
|
||||
fRevert->SetEnabled(enabled);
|
||||
|
||||
fUndo->SetEnabled(FALSE);
|
||||
fUndo->SetEnabled(false);
|
||||
enabled = fView->TextSelected();
|
||||
fCut->SetEnabled(enabled);
|
||||
fCopy->SetEnabled(enabled);
|
||||
|
@ -118,9 +108,9 @@ void TPeopleWindow::MenusBeginning(void)
|
|||
fView->BuildGroupMenu();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleWindow::MessageReceived(BMessage* msg)
|
||||
void
|
||||
TPeopleWindow::MessageReceived(BMessage* msg)
|
||||
{
|
||||
char str[256];
|
||||
entry_ref dir;
|
||||
|
@ -129,7 +119,7 @@ void TPeopleWindow::MessageReceived(BMessage* msg)
|
|||
BFile file;
|
||||
BNodeInfo *node;
|
||||
|
||||
switch(msg->what) {
|
||||
switch (msg->what) {
|
||||
case M_SAVE:
|
||||
if (!fRef) {
|
||||
SaveAs();
|
||||
|
@ -184,9 +174,9 @@ void TPeopleWindow::MessageReceived(BMessage* msg)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
bool TPeopleWindow::QuitRequested(void)
|
||||
bool
|
||||
TPeopleWindow::QuitRequested(void)
|
||||
{
|
||||
int32 count = 0;
|
||||
int32 index = 0;
|
||||
|
@ -203,11 +193,10 @@ bool TPeopleWindow::QuitRequested(void)
|
|||
fView->Save();
|
||||
else {
|
||||
SaveAs();
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (result == 0)
|
||||
return FALSE;
|
||||
} else if (result == 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
while ((window = (TPeopleWindow *)be_app->WindowAt(index++))) {
|
||||
|
@ -224,12 +213,12 @@ bool TPeopleWindow::QuitRequested(void)
|
|||
}
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
return TRUE;
|
||||
return true;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleWindow::DefaultName(char *name)
|
||||
void
|
||||
TPeopleWindow::DefaultName(char *name)
|
||||
{
|
||||
strncpy(name, fView->GetField(F_NAME), B_FILE_NAME_LENGTH);
|
||||
while (*name) {
|
||||
|
@ -239,16 +228,16 @@ void TPeopleWindow::DefaultName(char *name)
|
|||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleWindow::SetField(int32 index, char *text)
|
||||
void
|
||||
TPeopleWindow::SetField(int32 index, char *text)
|
||||
{
|
||||
fView->SetField(index, text, TRUE);
|
||||
fView->SetField(index, text, true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TPeopleWindow::SaveAs(void)
|
||||
void
|
||||
TPeopleWindow::SaveAs(void)
|
||||
{
|
||||
char name[B_FILE_NAME_LENGTH];
|
||||
BDirectory dir;
|
||||
|
|
|
@ -16,60 +16,64 @@
|
|||
|
||||
#include "TTextControl.h"
|
||||
|
||||
//====================================================================
|
||||
|
||||
TTextControl::TTextControl(BRect r, char *label, int32 length,
|
||||
char *text, int32 mod_msg, int32 msg)
|
||||
:BTextControl(r, "", label, text, new BMessage(msg))
|
||||
TTextControl::TTextControl(BRect r, const char *label, int32 offset,
|
||||
const char *text, int32 modificationMessage, int32 msg)
|
||||
: BTextControl(r, "", "", text, new BMessage(msg))
|
||||
{
|
||||
SetModificationMessage(new BMessage(mod_msg));
|
||||
SetModificationMessage(new BMessage(modificationMessage));
|
||||
|
||||
fLabel = (char *)malloc(strlen(label) + 1);
|
||||
strcpy(fLabel, label);
|
||||
fOriginal = (char *)malloc(strlen(text) + 1);
|
||||
strcpy(fOriginal, text);
|
||||
fLength = length;
|
||||
if (label[0]) {
|
||||
char newLabel[B_FILE_NAME_LENGTH];
|
||||
int32 length = strlen(label);
|
||||
memcpy(newLabel, label, length);
|
||||
newLabel[length] = ':';
|
||||
newLabel[length + 1] = '\0';
|
||||
|
||||
SetLabel(newLabel);
|
||||
}
|
||||
SetDivider(offset);
|
||||
SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
|
||||
if (text == NULL)
|
||||
text = "";
|
||||
fOriginal = strdup(text);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
TTextControl::~TTextControl(void)
|
||||
{
|
||||
free(fLabel);
|
||||
free(fOriginal);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TTextControl::AttachedToWindow(void)
|
||||
void
|
||||
TTextControl::AttachedToWindow(void)
|
||||
{
|
||||
BTextView *text;
|
||||
|
||||
BTextControl::AttachedToWindow();
|
||||
|
||||
SetDivider(StringWidth(fLabel) + 7);
|
||||
text = (BTextView *)ChildAt(0);
|
||||
text->SetMaxBytes(fLength - 1);
|
||||
BTextView* text = (BTextView *)ChildAt(0);
|
||||
text->SetMaxBytes(255);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
bool TTextControl::Changed(void)
|
||||
bool
|
||||
TTextControl::Changed(void)
|
||||
{
|
||||
return strcmp(fOriginal, Text());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TTextControl::Revert(void)
|
||||
void
|
||||
TTextControl::Revert(void)
|
||||
{
|
||||
if (Changed())
|
||||
SetText(fOriginal);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
void TTextControl::Update(void)
|
||||
void
|
||||
TTextControl::Update(void)
|
||||
{
|
||||
fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
|
||||
strcpy(fOriginal, Text());
|
||||
|
|
|
@ -16,21 +16,19 @@
|
|||
#include <TextControl.h>
|
||||
|
||||
class TTextControl : public BTextControl {
|
||||
public:
|
||||
TTextControl(BRect rect, const char* label, int32 length, const char* text,
|
||||
int32 modificationMessage, int32 invokationMessage);
|
||||
~TTextControl();
|
||||
|
||||
private:
|
||||
virtual void AttachedToWindow(void);
|
||||
|
||||
char *fLabel;
|
||||
char *fOriginal;
|
||||
int32 fLength;
|
||||
bool Changed(void);
|
||||
void Revert(void);
|
||||
void Update(void);
|
||||
|
||||
public:
|
||||
|
||||
TTextControl(BRect, char*, int32, char*, int32, int32);
|
||||
~TTextControl(void);
|
||||
virtual void AttachedToWindow(void);
|
||||
bool Changed(void);
|
||||
void Revert(void);
|
||||
void Update(void);
|
||||
private:
|
||||
char *fOriginal;
|
||||
};
|
||||
|
||||
#endif /* TEXTCONTROL_H */
|
||||
|
|
Loading…
Reference in New Issue