Update People app to use layout API. Also do some style cleanup. Removed many message constants which weren't used. The TextControls no longer have Invocation/Modification messages, as these were being ignored anyway. Replaced some uses of c-style strings with BStrings.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37823 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
24ca4df9de
commit
7d90a09a79
@ -31,11 +31,7 @@ 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,
|
||||
M_WINDOW_QUITS
|
||||
M_UNDO, M_SELECT, M_GROUP_MENU, M_WINDOW_QUITS
|
||||
};
|
||||
|
||||
enum fields {
|
||||
@ -50,14 +46,14 @@ class TPeopleWindow;
|
||||
|
||||
class TPeopleApp : public BApplication {
|
||||
public:
|
||||
TPeopleApp(void);
|
||||
virtual ~TPeopleApp(void);
|
||||
TPeopleApp();
|
||||
virtual ~TPeopleApp();
|
||||
|
||||
virtual void AboutRequested(void);
|
||||
virtual void AboutRequested();
|
||||
virtual void ArgvReceived(int32, char**);
|
||||
virtual void MessageReceived(BMessage*);
|
||||
virtual void RefsReceived(BMessage*);
|
||||
virtual void ReadyToRun(void);
|
||||
virtual void ReadyToRun();
|
||||
TPeopleWindow* FindWindow(entry_ref);
|
||||
TPeopleWindow* NewWindow(entry_ref* = NULL);
|
||||
|
||||
|
@ -10,26 +10,31 @@
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include "PeopleView.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <fs_attr.h>
|
||||
#include <Window.h>
|
||||
#include <Box.h>
|
||||
#include <ControlLook.h>
|
||||
#include <GridLayout.h>
|
||||
#include <MenuField.h>
|
||||
#include <MenuItem.h>
|
||||
#include <PopUpMenu.h>
|
||||
#include <Query.h>
|
||||
#include <VolumeRoster.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include "PeopleView.h"
|
||||
#include "TTextControl.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
TPeopleView::TPeopleView(BRect rect, const char *title, entry_ref *ref)
|
||||
:BView(rect, title, B_FOLLOW_NONE, B_WILL_DRAW)
|
||||
TPeopleView::TPeopleView(const char* name, entry_ref *ref)
|
||||
:
|
||||
BGridView()
|
||||
{
|
||||
SetName(name);
|
||||
if (ref)
|
||||
fFile = new BFile(ref, O_RDWR);
|
||||
else
|
||||
@ -46,68 +51,60 @@ TPeopleView::~TPeopleView(void)
|
||||
void
|
||||
TPeopleView::AttachedToWindow(void)
|
||||
{
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
BGridLayout* layout = GridLayout();
|
||||
|
||||
BRect bounds = Bounds();
|
||||
|
||||
BFont font = *be_plain_font;
|
||||
int32 offset = int32(font.StringWidth(gFields[F_HPHONE].name) + 10.5);
|
||||
font_height fontHeight;
|
||||
font.GetHeight(&fontHeight);
|
||||
int32 textHeight = int32(fontHeight.ascent + fontHeight.descent
|
||||
+ fontHeight.leading + 12.5);
|
||||
BRect rect;
|
||||
int32 row = 0;
|
||||
|
||||
for (int32 i = 0; gFields[i].attribute; i++, row++) {
|
||||
const char *name = gFields[i].name;
|
||||
|
||||
rect.Set(NAME_H, NAME_V + row * textHeight,
|
||||
bounds.right - NAME_H, NAME_V + (row + 1) * textHeight);
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
fFile->ReadAttr(gFields[i].attribute, B_STRING_TYPE,
|
||||
0, text, info.size);
|
||||
}
|
||||
|
||||
fField[i] = new TTextControl(rect, name, labelOffset, text, M_DIRTY, M_NAME);
|
||||
fField[i]->SetTarget(this);
|
||||
AddChild(fField[i]);
|
||||
|
||||
fField[i] = new TTextControl(name, text);
|
||||
free(text);
|
||||
|
||||
int32 labelColumn = 0;
|
||||
int32 textViewColumn = 1;
|
||||
int32 textViewWidth = 3;
|
||||
if (i == F_STATE)
|
||||
textViewWidth = 1;
|
||||
else if (i == F_ZIP) {
|
||||
row--;
|
||||
labelColumn = 2;
|
||||
textViewColumn = 3;
|
||||
textViewWidth = 1;
|
||||
}
|
||||
|
||||
rect.right = NAME_H + offset;
|
||||
rect.left = rect.right - font.StringWidth(gFields[F_GROUP].name) - 32;
|
||||
rect.top -= 1;
|
||||
if (i != F_GROUP) {
|
||||
layout->AddItem(fField[i]->CreateLabelLayoutItem(),
|
||||
labelColumn, row, 1, 1);
|
||||
layout->AddItem(fField[i]->CreateTextViewLayoutItem(),
|
||||
textViewColumn, row, textViewWidth, 1);
|
||||
} else {
|
||||
fField[i]->SetLabel("");
|
||||
layout->AddView(fField[i], textViewColumn, row, textViewWidth, 1);
|
||||
}
|
||||
}
|
||||
|
||||
fGroups = new BPopUpMenu(gFields[F_GROUP].name);
|
||||
fGroups->SetRadioMode(false);
|
||||
BMenuField *field = new BMenuField(rect, "", "", fGroups);
|
||||
field->SetDivider(0.0);
|
||||
field->SetFont(&font);
|
||||
BMenuField *field = new BMenuField("", "", fGroups);
|
||||
field->SetEnabled(true);
|
||||
AddChild(field);
|
||||
layout->AddView(field, 0, --row);
|
||||
|
||||
float spacing = be_control_look->DefaultItemSpacing();
|
||||
layout->SetSpacing(spacing, spacing);
|
||||
// TODO: remove this after #5614 is fixed
|
||||
layout->SetInsets(spacing, spacing, spacing, spacing);
|
||||
fField[F_NAME]->MakeFocus();
|
||||
ResizeTo(bounds.right, rect.bottom - 5 + NAME_V);
|
||||
}
|
||||
|
||||
|
||||
@ -126,7 +123,7 @@ TPeopleView::MessageReceived(BMessage* msg)
|
||||
|
||||
case M_SELECT:
|
||||
for (int32 loop = 0; loop < F_END; loop++) {
|
||||
BTextView* text = (BTextView *)fField[loop]->ChildAt(0);
|
||||
BTextView* text = fField[loop]->TextView();
|
||||
if (text->IsFocus()) {
|
||||
text->Select(0, text->TextLength());
|
||||
break;
|
||||
@ -279,7 +276,7 @@ TPeopleView::SetField(int32 index, char *data, bool update)
|
||||
fField[index]->SetText(data);
|
||||
fField[index]->Update();
|
||||
} else {
|
||||
BTextView* text = (BTextView *)fField[index]->ChildAt(0);
|
||||
BTextView* text = fField[index]->TextView();
|
||||
|
||||
int32 start, end;
|
||||
text->GetSelection(&start, &end);
|
||||
@ -303,7 +300,7 @@ bool
|
||||
TPeopleView::TextSelected(void)
|
||||
{
|
||||
for (int32 loop = 0; loop < F_END; loop++) {
|
||||
BTextView* text = (BTextView*)fField[loop]->ChildAt(0);
|
||||
BTextView* text = fField[loop]->TextView();
|
||||
|
||||
int32 start, end;
|
||||
text->GetSelection(&start, &end);
|
||||
|
@ -15,17 +15,16 @@
|
||||
|
||||
#include "PeopleApp.h"
|
||||
|
||||
#define NAME_H 10
|
||||
#define NAME_V 10
|
||||
#define STATE_WIDTH 175
|
||||
#include <GridView.h>
|
||||
|
||||
|
||||
class BPopUpMenu;
|
||||
class TTextControl;
|
||||
|
||||
|
||||
class TPeopleView : public BView {
|
||||
class TPeopleView : public BGridView {
|
||||
public:
|
||||
TPeopleView(BRect rect, const char* title, entry_ref* ref);
|
||||
TPeopleView(const char* name, entry_ref* ref);
|
||||
~TPeopleView(void);
|
||||
|
||||
virtual void AttachedToWindow(void);
|
||||
|
@ -10,46 +10,53 @@
|
||||
This file may be used under the terms of the Be Sample Code License.
|
||||
*/
|
||||
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <FilePanel.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <Alert.h>
|
||||
#include <Path.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Font.h>
|
||||
#include <Clipboard.h>
|
||||
#include <TextView.h>
|
||||
#include <NodeMonitor.h>
|
||||
#include <String.h>
|
||||
#include <Volume.h>
|
||||
|
||||
#include "PeopleApp.h"
|
||||
#include "PeopleView.h"
|
||||
#include "PeopleWindow.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <Alert.h>
|
||||
#include <Clipboard.h>
|
||||
#include <ControlLook.h>
|
||||
#include <FilePanel.h>
|
||||
#include <FindDirectory.h>
|
||||
#include <Font.h>
|
||||
#include <LayoutBuilder.h>
|
||||
#include <MenuBar.h>
|
||||
#include <MenuItem.h>
|
||||
#include <NodeInfo.h>
|
||||
#include <NodeMonitor.h>
|
||||
#include <Path.h>
|
||||
#include <String.h>
|
||||
#include <TextView.h>
|
||||
#include <Volume.h>
|
||||
|
||||
#include "PeopleApp.h"
|
||||
#include "PeopleView.h"
|
||||
|
||||
|
||||
TPeopleWindow::TPeopleWindow(BRect frame, const char *title, entry_ref *ref)
|
||||
: BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE),
|
||||
:
|
||||
BWindow(frame, title, B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE
|
||||
| B_AUTO_UPDATE_SIZE_LIMITS),
|
||||
fPanel(NULL)
|
||||
{
|
||||
BMenu* menu;
|
||||
BMenuItem* item;
|
||||
|
||||
BRect rect(0, 0, 32767, 15);
|
||||
BMenuBar* menuBar = new BMenuBar(rect, "");
|
||||
BMenuBar* menuBar = new BMenuBar("");
|
||||
menu = new BMenu("File");
|
||||
menu->AddItem(item = new BMenuItem("New person" B_UTF8_ELLIPSIS, new BMessage(M_NEW), 'N'));
|
||||
menu->AddItem(item = new BMenuItem("New person" B_UTF8_ELLIPSIS,
|
||||
new BMessage(M_NEW), 'N'));
|
||||
item->SetTarget(NULL, be_app);
|
||||
menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W'));
|
||||
menu->AddSeparatorItem();
|
||||
menu->AddItem(fSave = new BMenuItem("Save", new BMessage(M_SAVE), 'S'));
|
||||
fSave->SetEnabled(FALSE);
|
||||
menu->AddItem(new BMenuItem("Save as"B_UTF8_ELLIPSIS, new BMessage(M_SAVE_AS)));
|
||||
menu->AddItem(fRevert = new BMenuItem("Revert", new BMessage(M_REVERT), 'R'));
|
||||
menu->AddItem(new BMenuItem("Save as"B_UTF8_ELLIPSIS,
|
||||
new BMessage(M_SAVE_AS)));
|
||||
menu->AddItem(fRevert = new BMenuItem("Revert",
|
||||
new BMessage(M_REVERT), 'R'));
|
||||
fRevert->SetEnabled(FALSE);
|
||||
menu->AddSeparatorItem();
|
||||
item = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q');
|
||||
@ -68,10 +75,10 @@ TPeopleWindow::TPeopleWindow(BRect frame, const char *title, entry_ref *ref)
|
||||
fCopy->SetTarget(NULL, this);
|
||||
menu->AddItem(fPaste = new BMenuItem("Paste", new BMessage(B_PASTE), 'V'));
|
||||
fPaste->SetTarget(NULL, this);
|
||||
menu->AddItem(item = new BMenuItem("Select all", new BMessage(M_SELECT), 'A'));
|
||||
menu->AddItem(item = new BMenuItem("Select all",
|
||||
new BMessage(M_SELECT), 'A'));
|
||||
item->SetTarget(NULL, this);
|
||||
menuBar->AddItem(menu);
|
||||
AddChild(menuBar);
|
||||
|
||||
if (ref) {
|
||||
fRef = new entry_ref(*ref);
|
||||
@ -80,12 +87,12 @@ TPeopleWindow::TPeopleWindow(BRect frame, const char *title, entry_ref *ref)
|
||||
} else
|
||||
fRef = NULL;
|
||||
|
||||
rect = Frame();
|
||||
rect.OffsetTo(0, menuBar->Bounds().bottom + 1);
|
||||
fView = new TPeopleView(rect, "PeopleView", fRef);
|
||||
fView = new TPeopleView("PeopleView", fRef);
|
||||
|
||||
AddChild(fView);
|
||||
ResizeTo(fView->Frame().right, fView->Frame().bottom);
|
||||
BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
|
||||
.SetInsets(0, 0, 0, 0)
|
||||
.Add(menuBar)
|
||||
.Add(fView);
|
||||
}
|
||||
|
||||
|
||||
|
@ -17,38 +17,25 @@
|
||||
#include "TTextControl.h"
|
||||
|
||||
|
||||
TTextControl::TTextControl(BRect r, const char *label, int32 offset,
|
||||
const char *text, int32 modificationMessage, int32 msg)
|
||||
: BTextControl(r, "", "", text, new BMessage(msg))
|
||||
TTextControl::TTextControl(const char *label, const char *text)
|
||||
:
|
||||
BTextControl(NULL, text, NULL)
|
||||
{
|
||||
SetModificationMessage(new BMessage(modificationMessage));
|
||||
|
||||
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);
|
||||
if (label && label[0])
|
||||
SetLabel(BString(label).Append(":"));
|
||||
SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
|
||||
|
||||
if (text == NULL)
|
||||
text = "";
|
||||
fOriginal = strdup(text);
|
||||
fOriginal = text;
|
||||
}
|
||||
|
||||
|
||||
TTextControl::~TTextControl(void)
|
||||
TTextControl::~TTextControl()
|
||||
{
|
||||
free(fOriginal);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TTextControl::AttachedToWindow(void)
|
||||
TTextControl::AttachedToWindow()
|
||||
{
|
||||
BTextControl::AttachedToWindow();
|
||||
|
||||
@ -58,9 +45,9 @@ TTextControl::AttachedToWindow(void)
|
||||
|
||||
|
||||
bool
|
||||
TTextControl::Changed(void)
|
||||
TTextControl::Changed()
|
||||
{
|
||||
return strcmp(fOriginal, Text());
|
||||
return fOriginal != Text();
|
||||
}
|
||||
|
||||
|
||||
@ -75,6 +62,5 @@ TTextControl::Revert(void)
|
||||
void
|
||||
TTextControl::Update(void)
|
||||
{
|
||||
fOriginal = (char *)realloc(fOriginal, strlen(Text()) + 1);
|
||||
strcpy(fOriginal, Text());
|
||||
fOriginal = Text();
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
//--------------------------------------------------------------------
|
||||
//
|
||||
// TextControl.h
|
||||
// TTextControl.h
|
||||
//
|
||||
// Written by: Robert Polic
|
||||
//
|
||||
@ -13,22 +13,22 @@
|
||||
#ifndef TEXTCONTROL_H
|
||||
#define TEXTCONTROL_H
|
||||
|
||||
#include <String.h>
|
||||
#include <TextControl.h>
|
||||
|
||||
class TTextControl : public BTextControl {
|
||||
public:
|
||||
TTextControl(BRect rect, const char* label, int32 length, const char* text,
|
||||
int32 modificationMessage, int32 invokationMessage);
|
||||
~TTextControl();
|
||||
TTextControl(const char* label, const char* text);
|
||||
virtual ~TTextControl();
|
||||
|
||||
virtual void AttachedToWindow(void);
|
||||
virtual void AttachedToWindow();
|
||||
|
||||
bool Changed(void);
|
||||
void Revert(void);
|
||||
void Update(void);
|
||||
bool Changed();
|
||||
void Revert();
|
||||
void Update();
|
||||
|
||||
private:
|
||||
char *fOriginal;
|
||||
BString fOriginal;
|
||||
};
|
||||
|
||||
#endif /* TEXTCONTROL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user