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,39 +4,38 @@
#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;
History = history;
CursorPos = cursor_pos;
if (redo_text!=NULL) {
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)
@ -117,9 +123,9 @@ KUndoBuffer::NewUndo(const char* text, int32 length, int32 offset,
cursor_pos);
status_t status = NewUndoItem->InitCheck();
if ( status != B_OK) {
if (status != B_OK) {
delete NewUndoItem;
return status;
return status;
}
AddItem(NewUndoItem, fIndex);
fIndex++;
@ -136,13 +142,13 @@ 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 {
KUndoItem* CurrentUndoItem;
CurrentUndoItem = ItemAt(fIndex-1);
if (CurrentUndoItem!=NULL) {
CurrentUndoItem = ItemAt(fIndex - 1);
if (CurrentUndoItem != NULL) {
int32 c_length = CurrentUndoItem->Length;
int32 c_offset = CurrentUndoItem->Offset;
undo_type c_history = CurrentUndoItem->History;
@ -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,9 +168,8 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
cursor_pos);
break;
}
} else {
} else
status = NewUndo(text, length, offset, history, cursor_pos);
}
}
}
@ -184,65 +189,50 @@ 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);
if (undoItem!=NULL) {
if (fIndex > 0) {
undoItem = ItemAt(fIndex - 1);
if (undoItem != NULL) {
*text = undoItem->RedoText;
*length = undoItem->Length;
*offset = undoItem->Offset;
*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);
if (undoItem!=NULL) {
if (undoItem != NULL) {
*text = undoItem->RedoText;
*length = undoItem->Length;
*offset = undoItem->Offset;
*history = undoItem->History;
*cursor_pos = undoItem->CursorPos;
if ((fIndex+1) < CountItems()) {
*replaced = ItemAt(fIndex+1)->History==K_REPLACED;
} else {
if (fIndex + 1 < CountItems())
*replaced = ItemAt(fIndex + 1)->History == K_REPLACED;
else
*replaced = false;
}
status = B_OK;
} else {
status = B_ERROR;
}
fIndex++;
} else {
status = B_ERROR;
}
return status;
}
@ -251,10 +241,10 @@ KUndoBuffer::Redo(char** text,
void
KUndoBuffer::PrintToStream()
{
for(int32 i=0; i<CountItems(); i++) {
for (int32 i = 0; i < CountItems(); i++) {
KUndoItem* item = ItemAt(i);
printf("%3.3d ", (int)i);
switch(item->History) {
switch (item->History) {
case K_INSERTED:
printf("INSERTED ");
break;
@ -269,13 +259,12 @@ KUndoBuffer::PrintToStream()
printf("Length = %d ", (int)item->Length);
printf("CursorPos = %d ", (int)item->CursorPos);
printf("RedoText = '");
for(int32 j=0;j<item->Length;j++) {
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");
}