Mail: coding styles fixes. should have no functional changes

This commit is contained in:
Philippe Saint-Pierre 2012-12-24 20:33:32 -05:00
parent 855f2c88d3
commit 5eea8a566d
2 changed files with 84 additions and 115 deletions

View File

@ -119,19 +119,14 @@ Unicode2UTF8(int32 c, char **out)
if (c < 0x80)
*(s++) = c;
else if (c < 0x800)
{
else if (c < 0x800) {
*(s++) = 0xc0 | (c >> 6);
*(s++) = 0x80 | (c & 0x3f);
}
else if (c < 0x10000)
{
} else if (c < 0x10000) {
*(s++) = 0xe0 | (c >> 12);
*(s++) = 0x80 | ((c >> 6) & 0x3f);
*(s++) = 0x80 | (c & 0x3f);
}
else if (c < 0x200000)
{
} else if (c < 0x200000) {
*(s++) = 0xf0 | (c >> 18);
*(s++) = 0x80 | ((c >> 12) & 0x3f);
*(s++) = 0x80 | ((c >> 6) & 0x3f);
@ -974,15 +969,12 @@ TTextView::KeyDown(const char *key, int32 count)
msg = Window()->CurrentMessage();
mods = msg->FindInt32("modifiers");
switch (key[0])
{
switch (key[0]) {
case B_HOME:
if (IsSelectable())
{
if (IsSelectable()) {
if (IsEditable())
BTextView::KeyDown(key, count);
else
{
else {
// scroll to the beginning
Select(0, 0);
ScrollToSelection();
@ -991,12 +983,10 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case B_END:
if (IsSelectable())
{
if (IsSelectable()) {
if (IsEditable())
BTextView::KeyDown(key, count);
else
{
else {
// scroll to the end
int32 length = TextLength();
Select(length, length);
@ -1006,19 +996,15 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case 0x02: // ^b - back 1 char
if (IsSelectable())
{
if (IsSelectable()) {
GetSelection(&start, &end);
while (!IsInitialUTF8Byte(ByteAt(--start)))
{
if (start < 0)
{
while (!IsInitialUTF8Byte(ByteAt(--start))) {
if (start < 0) {
start = 0;
break;
}
}
if (start >= 0)
{
if (start >= 0) {
Select(start, start);
ScrollToSelection();
}
@ -1026,21 +1012,16 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case B_DELETE:
if (IsSelectable())
{
if ((key[0] == B_DELETE) || (mods & B_CONTROL_KEY)) // ^d
{
if (IsEditable())
{
if (IsSelectable()) {
if ((key[0] == B_DELETE) || (mods & B_CONTROL_KEY)) {
// ^d
if (IsEditable()) {
GetSelection(&start, &end);
if (start != end)
Delete();
else
{
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++)
{
if (end > textLen)
{
else {
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++) {
if (end > textLen) {
end = textLen;
break;
}
@ -1057,12 +1038,10 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case 0x05: // ^e - end of line
if ((IsSelectable()) && (mods & B_CONTROL_KEY))
{
if (IsSelectable() && (mods & B_CONTROL_KEY)) {
if (CurrentLine() == CountLines() - 1)
Select(TextLength(), TextLength());
else
{
else {
GoToLine(CurrentLine() + 1);
GetSelection(&start, &end);
Select(start - 1, start - 1);
@ -1071,17 +1050,14 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case 0x06: // ^f - forward 1 char
if (IsSelectable())
{
if (IsSelectable()) {
GetSelection(&start, &end);
if (end > start)
start = end;
else
{
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++)
{
if (end > textLen)
{
else {
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end));
end++) {
if (end > textLen) {
end = textLen;
break;
}
@ -1094,16 +1070,14 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case 0x0e: // ^n - next line
if (IsSelectable())
{
if (IsSelectable()) {
raw = B_DOWN_ARROW;
BTextView::KeyDown(&raw, 1);
}
break;
case 0x0f: // ^o - open line
if (IsEditable())
{
if (IsEditable()) {
GetSelection(&start, &end);
Delete();
@ -1123,7 +1097,7 @@ TTextView::KeyDown(const char *key, int32 count)
fYankBuffer = NULL;
}
fLastPosition = start;
if (CurrentLine() < (CountLines() - 1)) {
if (CurrentLine() < CountLines() - 1) {
GoToLine(CurrentLine() + 1);
GetSelection(&end, &end);
end--;
@ -1161,7 +1135,7 @@ TTextView::KeyDown(const char *key, int32 count)
break;
case 0x19: // ^y yank text
if ((IsEditable()) && (fYankBuffer)) {
if (IsEditable() && fYankBuffer) {
Delete();
Insert(fYankBuffer);
ScrollToSelection();
@ -2256,7 +2230,7 @@ TTextView::AddAsContent(BEmailMessage *mail, bool wrap, uint32 charset, mail_enc
// add a newline to every line except for the ones
// that already end in newlines, and the last line
if ((text[endOffset - 1] != '\n') && (i < (numLines - 1))) {
if ((text[endOffset - 1] != '\n') && (i < numLines - 1)) {
content[contentLength++] = '\n';
// copy quote level of the first line
@ -3317,6 +3291,9 @@ TTextView::Undo(BClipboard */*clipboard*/)
char *text;
status_t status;
printf("UNDO------\n");
fUndoBuffer.PrintToStream();
status = fUndoBuffer.Undo(&text, &length, &offset, &history, &cursorPos);
if (status == B_OK) {
fUndoBuffer.Off();
@ -3367,6 +3344,9 @@ TTextView::Redo()
status_t status;
bool replaced;
printf("REDO------\n");
fUndoBuffer.PrintToStream();
status = fUndoBuffer.Redo(&text, &length, &offset, &history, &cursorPos, &replaced);
if (status == B_OK) {
fUndoBuffer.Off();

View File

@ -4,11 +4,8 @@
#include "KUndoBuffer.h"
KUndoItem::KUndoItem(const char* redo_text,
int32 length,
int32 offset,
undo_type history,
int32 cursor_pos)
KUndoItem::KUndoItem(const char* redo_text, int32 length, int32 offset,
undo_type history, int32 cursor_pos)
{
Offset = offset;
Length = length;
@ -18,25 +15,27 @@ KUndoItem::KUndoItem(const char* redo_text,
if (redo_text != NULL) {
RedoText = (char*)malloc(length);
memcpy(RedoText, redo_text, length);
if (RedoText!=NULL) {
if (RedoText != NULL)
fStatus = B_OK;
} else {
else
fStatus = B_ERROR;
}
}
}
KUndoItem::~KUndoItem()
{
free(RedoText);
}
status_t
KUndoItem::InitCheck()
{
return fStatus;
}
void
KUndoItem::Merge(const char* text, int32 length)
{
@ -53,6 +52,7 @@ KUndoBuffer::KUndoBuffer():BList(1024)
fNewItem = true;
}
KUndoBuffer::~KUndoBuffer()
{
MakeEmpty();
@ -62,34 +62,38 @@ KUndoBuffer::~KUndoBuffer()
bool
KUndoBuffer::AddItem(KUndoItem* item, int32 index)
{
for (int32 i=CountItems()-1; i>=index; i--) {
for (int32 i = CountItems() - 1; i >= index; i--)
RemoveItem(i);
}
return AddItem(item);
}
bool
KUndoBuffer::AddItem(KUndoItem* item)
{
return BList::AddItem(item);
}
void
KUndoBuffer::MakeEmpty(void)
{
for(int32 i=CountItems()-1; i>=0;i--) {
for (int32 i = CountItems() - 1; i >= 0; i--)
RemoveItem(i);
}
}
KUndoItem*
KUndoBuffer::RemoveItem(int32 index)
{
if (fIndex>=CountItems()) fIndex--;
if (fIndex >= CountItems())
fIndex--;
delete this->ItemAt(index);
return (KUndoItem*)BList::RemoveItem(index);
}
KUndoItem*
KUndoBuffer::ItemAt(int32 index) const
{
@ -103,12 +107,14 @@ KUndoBuffer::On()
fNoTouch = false;
}
void
KUndoBuffer::Off()
{
fNoTouch = true;
}
status_t
KUndoBuffer::NewUndo(const char* text, int32 length, int32 offset,
undo_type history, int32 cursor_pos)
@ -136,7 +142,7 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
status_t status = B_OK;
if (fNewItem || (fIndex < CountItems()) || (CountItems()==0)) {
if (fNewItem || fIndex < CountItems() || CountItems() == 0) {
status = NewUndo(text, length, offset, history, cursor_pos);
fNewItem = false;
} else {
@ -150,9 +156,9 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
switch(c_history) {
case K_INSERTED:
case K_REPLACED:
if ((c_offset + c_length) == offset) {
if ((c_offset + c_length) == offset)
CurrentUndoItem->Merge(text, length);
} else {
else {
status = NewUndo(text, length, offset, history,
cursor_pos);
}
@ -162,11 +168,10 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
cursor_pos);
break;
}
} else {
} else
status = NewUndo(text, length, offset, history, cursor_pos);
}
}
}
return status;
}
@ -184,14 +189,11 @@ KUndoBuffer::MakeNewUndoItem()
status_t
KUndoBuffer::Undo(char** text,
int32* length,
int32* offset,
undo_type* history,
int32* cursor_pos)
KUndoBuffer::Undo(char** text, int32* length, int32* offset,
undo_type* history, int32* cursor_pos)
{
KUndoItem* undoItem;
status_t status;
status_t status = B_ERROR;
if (fIndex > 0) {
undoItem = ItemAt(fIndex - 1);
@ -202,26 +204,19 @@ KUndoBuffer::Undo(char** text,
*history = undoItem->History;
*cursor_pos = undoItem->CursorPos + undoItem->Length;
status = B_OK;
} else {
status = B_ERROR;
}
fIndex--;
} else {
status = B_ERROR;
}
return status;
}
status_t
KUndoBuffer::Redo(char** text,
int32* length,
int32* offset,
undo_type* history,
int32* cursor_pos,
bool* replaced)
KUndoBuffer::Redo(char** text, int32* length, int32* offset,
undo_type* history, int32* cursor_pos, bool* replaced)
{
KUndoItem* undoItem;
status_t status;
status_t status = B_ERROR;
if (fIndex < CountItems()) {
undoItem = ItemAt(fIndex);
@ -231,18 +226,13 @@ KUndoBuffer::Redo(char** text,
*offset = undoItem->Offset;
*history = undoItem->History;
*cursor_pos = undoItem->CursorPos;
if ((fIndex+1) < CountItems()) {
if (fIndex + 1 < CountItems())
*replaced = ItemAt(fIndex + 1)->History == K_REPLACED;
} else {
else
*replaced = false;
}
status = B_OK;
} else {
status = B_ERROR;
}
fIndex++;
} else {
status = B_ERROR;
}
return status;
}
@ -271,12 +261,11 @@ KUndoBuffer::PrintToStream()
printf("RedoText = '");
for (int32 j = 0; j < item->Length; j++) {
uchar c = (uchar)item->RedoText[j];
if (c >= 0x20) {
if (c >= 0x20)
printf("%c", c);
} else {
else
printf("?");
}
}
printf("'\n");
}
}