Mail: coding styles fixes. should have no functional changes

This commit is contained in:
Philippe Saint-Pierre
2012-12-25 14:13:02 -05:00
parent 855f2c88d3
commit 5eea8a566d
2 changed files with 84 additions and 115 deletions
+37 -57
View File
@@ -119,19 +119,14 @@ Unicode2UTF8(int32 c, char **out)
if (c < 0x80) if (c < 0x80)
*(s++) = c; *(s++) = c;
else if (c < 0x800) else if (c < 0x800) {
{
*(s++) = 0xc0 | (c >> 6); *(s++) = 0xc0 | (c >> 6);
*(s++) = 0x80 | (c & 0x3f); *(s++) = 0x80 | (c & 0x3f);
} } else if (c < 0x10000) {
else if (c < 0x10000)
{
*(s++) = 0xe0 | (c >> 12); *(s++) = 0xe0 | (c >> 12);
*(s++) = 0x80 | ((c >> 6) & 0x3f); *(s++) = 0x80 | ((c >> 6) & 0x3f);
*(s++) = 0x80 | (c & 0x3f); *(s++) = 0x80 | (c & 0x3f);
} } else if (c < 0x200000) {
else if (c < 0x200000)
{
*(s++) = 0xf0 | (c >> 18); *(s++) = 0xf0 | (c >> 18);
*(s++) = 0x80 | ((c >> 12) & 0x3f); *(s++) = 0x80 | ((c >> 12) & 0x3f);
*(s++) = 0x80 | ((c >> 6) & 0x3f); *(s++) = 0x80 | ((c >> 6) & 0x3f);
@@ -974,15 +969,12 @@ TTextView::KeyDown(const char *key, int32 count)
msg = Window()->CurrentMessage(); msg = Window()->CurrentMessage();
mods = msg->FindInt32("modifiers"); mods = msg->FindInt32("modifiers");
switch (key[0]) switch (key[0]) {
{
case B_HOME: case B_HOME:
if (IsSelectable()) if (IsSelectable()) {
{
if (IsEditable()) if (IsEditable())
BTextView::KeyDown(key, count); BTextView::KeyDown(key, count);
else else {
{
// scroll to the beginning // scroll to the beginning
Select(0, 0); Select(0, 0);
ScrollToSelection(); ScrollToSelection();
@@ -991,12 +983,10 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case B_END: case B_END:
if (IsSelectable()) if (IsSelectable()) {
{
if (IsEditable()) if (IsEditable())
BTextView::KeyDown(key, count); BTextView::KeyDown(key, count);
else else {
{
// scroll to the end // scroll to the end
int32 length = TextLength(); int32 length = TextLength();
Select(length, length); Select(length, length);
@@ -1006,19 +996,15 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case 0x02: // ^b - back 1 char case 0x02: // ^b - back 1 char
if (IsSelectable()) if (IsSelectable()) {
{
GetSelection(&start, &end); GetSelection(&start, &end);
while (!IsInitialUTF8Byte(ByteAt(--start))) while (!IsInitialUTF8Byte(ByteAt(--start))) {
{ if (start < 0) {
if (start < 0)
{
start = 0; start = 0;
break; break;
} }
} }
if (start >= 0) if (start >= 0) {
{
Select(start, start); Select(start, start);
ScrollToSelection(); ScrollToSelection();
} }
@@ -1026,21 +1012,16 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case B_DELETE: case B_DELETE:
if (IsSelectable()) if (IsSelectable()) {
{ if ((key[0] == B_DELETE) || (mods & B_CONTROL_KEY)) {
if ((key[0] == B_DELETE) || (mods & B_CONTROL_KEY)) // ^d // ^d
{ if (IsEditable()) {
if (IsEditable())
{
GetSelection(&start, &end); GetSelection(&start, &end);
if (start != end) if (start != end)
Delete(); Delete();
else else {
{ for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++) {
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++) if (end > textLen) {
{
if (end > textLen)
{
end = textLen; end = textLen;
break; break;
} }
@@ -1057,12 +1038,10 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case 0x05: // ^e - end of line case 0x05: // ^e - end of line
if ((IsSelectable()) && (mods & B_CONTROL_KEY)) if (IsSelectable() && (mods & B_CONTROL_KEY)) {
{
if (CurrentLine() == CountLines() - 1) if (CurrentLine() == CountLines() - 1)
Select(TextLength(), TextLength()); Select(TextLength(), TextLength());
else else {
{
GoToLine(CurrentLine() + 1); GoToLine(CurrentLine() + 1);
GetSelection(&start, &end); GetSelection(&start, &end);
Select(start - 1, start - 1); Select(start - 1, start - 1);
@@ -1071,17 +1050,14 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case 0x06: // ^f - forward 1 char case 0x06: // ^f - forward 1 char
if (IsSelectable()) if (IsSelectable()) {
{
GetSelection(&start, &end); GetSelection(&start, &end);
if (end > start) if (end > start)
start = end; start = end;
else else {
{ for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end));
for (end = start + 1; !IsInitialUTF8Byte(ByteAt(end)); end++) end++) {
{ if (end > textLen) {
if (end > textLen)
{
end = textLen; end = textLen;
break; break;
} }
@@ -1094,16 +1070,14 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case 0x0e: // ^n - next line case 0x0e: // ^n - next line
if (IsSelectable()) if (IsSelectable()) {
{
raw = B_DOWN_ARROW; raw = B_DOWN_ARROW;
BTextView::KeyDown(&raw, 1); BTextView::KeyDown(&raw, 1);
} }
break; break;
case 0x0f: // ^o - open line case 0x0f: // ^o - open line
if (IsEditable()) if (IsEditable()) {
{
GetSelection(&start, &end); GetSelection(&start, &end);
Delete(); Delete();
@@ -1123,7 +1097,7 @@ TTextView::KeyDown(const char *key, int32 count)
fYankBuffer = NULL; fYankBuffer = NULL;
} }
fLastPosition = start; fLastPosition = start;
if (CurrentLine() < (CountLines() - 1)) { if (CurrentLine() < CountLines() - 1) {
GoToLine(CurrentLine() + 1); GoToLine(CurrentLine() + 1);
GetSelection(&end, &end); GetSelection(&end, &end);
end--; end--;
@@ -1161,7 +1135,7 @@ TTextView::KeyDown(const char *key, int32 count)
break; break;
case 0x19: // ^y yank text case 0x19: // ^y yank text
if ((IsEditable()) && (fYankBuffer)) { if (IsEditable() && fYankBuffer) {
Delete(); Delete();
Insert(fYankBuffer); Insert(fYankBuffer);
ScrollToSelection(); 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 // add a newline to every line except for the ones
// that already end in newlines, and the last line // 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'; content[contentLength++] = '\n';
// copy quote level of the first line // copy quote level of the first line
@@ -3317,6 +3291,9 @@ TTextView::Undo(BClipboard */*clipboard*/)
char *text; char *text;
status_t status; status_t status;
printf("UNDO------\n");
fUndoBuffer.PrintToStream();
status = fUndoBuffer.Undo(&text, &length, &offset, &history, &cursorPos); status = fUndoBuffer.Undo(&text, &length, &offset, &history, &cursorPos);
if (status == B_OK) { if (status == B_OK) {
fUndoBuffer.Off(); fUndoBuffer.Off();
@@ -3367,6 +3344,9 @@ TTextView::Redo()
status_t status; status_t status;
bool replaced; bool replaced;
printf("REDO------\n");
fUndoBuffer.PrintToStream();
status = fUndoBuffer.Redo(&text, &length, &offset, &history, &cursorPos, &replaced); status = fUndoBuffer.Redo(&text, &length, &offset, &history, &cursorPos, &replaced);
if (status == B_OK) { if (status == B_OK) {
fUndoBuffer.Off(); fUndoBuffer.Off();
+47 -58
View File
@@ -4,39 +4,38 @@
#include "KUndoBuffer.h" #include "KUndoBuffer.h"
KUndoItem::KUndoItem(const char* redo_text, KUndoItem::KUndoItem(const char* redo_text, int32 length, int32 offset,
int32 length, undo_type history, int32 cursor_pos)
int32 offset,
undo_type history,
int32 cursor_pos)
{ {
Offset = offset; Offset = offset;
Length = length; Length = length;
History = history; History = history;
CursorPos = cursor_pos; CursorPos = cursor_pos;
if (redo_text!=NULL) { if (redo_text != NULL) {
RedoText = (char*)malloc(length); RedoText = (char*)malloc(length);
memcpy(RedoText, redo_text, length); memcpy(RedoText, redo_text, length);
if (RedoText!=NULL) { if (RedoText != NULL)
fStatus = B_OK; fStatus = B_OK;
} else { else
fStatus = B_ERROR; fStatus = B_ERROR;
}
} }
} }
KUndoItem::~KUndoItem() KUndoItem::~KUndoItem()
{ {
free(RedoText); free(RedoText);
} }
status_t status_t
KUndoItem::InitCheck() KUndoItem::InitCheck()
{ {
return fStatus; return fStatus;
} }
void void
KUndoItem::Merge(const char* text, int32 length) KUndoItem::Merge(const char* text, int32 length)
{ {
@@ -53,6 +52,7 @@ KUndoBuffer::KUndoBuffer():BList(1024)
fNewItem = true; fNewItem = true;
} }
KUndoBuffer::~KUndoBuffer() KUndoBuffer::~KUndoBuffer()
{ {
MakeEmpty(); MakeEmpty();
@@ -62,34 +62,38 @@ KUndoBuffer::~KUndoBuffer()
bool bool
KUndoBuffer::AddItem(KUndoItem* item, int32 index) KUndoBuffer::AddItem(KUndoItem* item, int32 index)
{ {
for (int32 i=CountItems()-1; i>=index; i--) { for (int32 i = CountItems() - 1; i >= index; i--)
RemoveItem(i); RemoveItem(i);
}
return AddItem(item); return AddItem(item);
} }
bool bool
KUndoBuffer::AddItem(KUndoItem* item) KUndoBuffer::AddItem(KUndoItem* item)
{ {
return BList::AddItem(item); return BList::AddItem(item);
} }
void void
KUndoBuffer::MakeEmpty(void) KUndoBuffer::MakeEmpty(void)
{ {
for(int32 i=CountItems()-1; i>=0;i--) { for (int32 i = CountItems() - 1; i >= 0; i--)
RemoveItem(i); RemoveItem(i);
}
} }
KUndoItem* KUndoItem*
KUndoBuffer::RemoveItem(int32 index) KUndoBuffer::RemoveItem(int32 index)
{ {
if (fIndex>=CountItems()) fIndex--; if (fIndex >= CountItems())
fIndex--;
delete this->ItemAt(index); delete this->ItemAt(index);
return (KUndoItem*)BList::RemoveItem(index); return (KUndoItem*)BList::RemoveItem(index);
} }
KUndoItem* KUndoItem*
KUndoBuffer::ItemAt(int32 index) const KUndoBuffer::ItemAt(int32 index) const
{ {
@@ -103,12 +107,14 @@ KUndoBuffer::On()
fNoTouch = false; fNoTouch = false;
} }
void void
KUndoBuffer::Off() KUndoBuffer::Off()
{ {
fNoTouch = true; fNoTouch = true;
} }
status_t status_t
KUndoBuffer::NewUndo(const char* text, int32 length, int32 offset, KUndoBuffer::NewUndo(const char* text, int32 length, int32 offset,
undo_type history, int32 cursor_pos) undo_type history, int32 cursor_pos)
@@ -117,9 +123,9 @@ KUndoBuffer::NewUndo(const char* text, int32 length, int32 offset,
cursor_pos); cursor_pos);
status_t status = NewUndoItem->InitCheck(); status_t status = NewUndoItem->InitCheck();
if ( status != B_OK) { if (status != B_OK) {
delete NewUndoItem; delete NewUndoItem;
return status; return status;
} }
AddItem(NewUndoItem, fIndex); AddItem(NewUndoItem, fIndex);
fIndex++; fIndex++;
@@ -136,13 +142,13 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
status_t status = B_OK; 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); status = NewUndo(text, length, offset, history, cursor_pos);
fNewItem = false; fNewItem = false;
} else { } else {
KUndoItem* CurrentUndoItem; KUndoItem* CurrentUndoItem;
CurrentUndoItem = ItemAt(fIndex-1); CurrentUndoItem = ItemAt(fIndex - 1);
if (CurrentUndoItem!=NULL) { if (CurrentUndoItem != NULL) {
int32 c_length = CurrentUndoItem->Length; int32 c_length = CurrentUndoItem->Length;
int32 c_offset = CurrentUndoItem->Offset; int32 c_offset = CurrentUndoItem->Offset;
undo_type c_history = CurrentUndoItem->History; undo_type c_history = CurrentUndoItem->History;
@@ -150,9 +156,9 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
switch(c_history) { switch(c_history) {
case K_INSERTED: case K_INSERTED:
case K_REPLACED: case K_REPLACED:
if ((c_offset + c_length) == offset) { if ((c_offset + c_length) == offset)
CurrentUndoItem->Merge(text, length); CurrentUndoItem->Merge(text, length);
} else { else {
status = NewUndo(text, length, offset, history, status = NewUndo(text, length, offset, history,
cursor_pos); cursor_pos);
} }
@@ -162,9 +168,8 @@ KUndoBuffer::AddUndo(const char* text, int32 length, int32 offset,
cursor_pos); cursor_pos);
break; break;
} }
} else { } else
status = NewUndo(text, length, offset, history, cursor_pos); status = NewUndo(text, length, offset, history, cursor_pos);
}
} }
} }
@@ -184,65 +189,50 @@ KUndoBuffer::MakeNewUndoItem()
status_t status_t
KUndoBuffer::Undo(char** text, KUndoBuffer::Undo(char** text, int32* length, int32* offset,
int32* length, undo_type* history, int32* cursor_pos)
int32* offset,
undo_type* history,
int32* cursor_pos)
{ {
KUndoItem* undoItem; KUndoItem* undoItem;
status_t status; status_t status = B_ERROR;
if (fIndex>0) { if (fIndex > 0) {
undoItem = ItemAt(fIndex-1); undoItem = ItemAt(fIndex - 1);
if (undoItem!=NULL) { if (undoItem != NULL) {
*text = undoItem->RedoText; *text = undoItem->RedoText;
*length = undoItem->Length; *length = undoItem->Length;
*offset = undoItem->Offset; *offset = undoItem->Offset;
*history = undoItem->History; *history = undoItem->History;
*cursor_pos = undoItem->CursorPos + undoItem->Length; *cursor_pos = undoItem->CursorPos + undoItem->Length;
status = B_OK; status = B_OK;
} else {
status = B_ERROR;
} }
fIndex--; fIndex--;
} else {
status = B_ERROR;
} }
return status; return status;
} }
status_t status_t
KUndoBuffer::Redo(char** text, KUndoBuffer::Redo(char** text, int32* length, int32* offset,
int32* length, undo_type* history, int32* cursor_pos, bool* replaced)
int32* offset,
undo_type* history,
int32* cursor_pos,
bool* replaced)
{ {
KUndoItem* undoItem; KUndoItem* undoItem;
status_t status; status_t status = B_ERROR;
if (fIndex < CountItems()) { if (fIndex < CountItems()) {
undoItem = ItemAt(fIndex); undoItem = ItemAt(fIndex);
if (undoItem!=NULL) { if (undoItem != NULL) {
*text = undoItem->RedoText; *text = undoItem->RedoText;
*length = undoItem->Length; *length = undoItem->Length;
*offset = undoItem->Offset; *offset = undoItem->Offset;
*history = undoItem->History; *history = undoItem->History;
*cursor_pos = undoItem->CursorPos; *cursor_pos = undoItem->CursorPos;
if ((fIndex+1) < CountItems()) { if (fIndex + 1 < CountItems())
*replaced = ItemAt(fIndex+1)->History==K_REPLACED; *replaced = ItemAt(fIndex + 1)->History == K_REPLACED;
} else { else
*replaced = false; *replaced = false;
}
status = B_OK; status = B_OK;
} else {
status = B_ERROR;
} }
fIndex++; fIndex++;
} else {
status = B_ERROR;
} }
return status; return status;
} }
@@ -251,10 +241,10 @@ KUndoBuffer::Redo(char** text,
void void
KUndoBuffer::PrintToStream() KUndoBuffer::PrintToStream()
{ {
for(int32 i=0; i<CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
KUndoItem* item = ItemAt(i); KUndoItem* item = ItemAt(i);
printf("%3.3d ", (int)i); printf("%3.3d ", (int)i);
switch(item->History) { switch (item->History) {
case K_INSERTED: case K_INSERTED:
printf("INSERTED "); printf("INSERTED ");
break; break;
@@ -269,13 +259,12 @@ KUndoBuffer::PrintToStream()
printf("Length = %d ", (int)item->Length); printf("Length = %d ", (int)item->Length);
printf("CursorPos = %d ", (int)item->CursorPos); printf("CursorPos = %d ", (int)item->CursorPos);
printf("RedoText = '"); printf("RedoText = '");
for(int32 j=0;j<item->Length;j++) { for (int32 j = 0; j < item->Length; j++) {
uchar c = (uchar)item->RedoText[j]; uchar c = (uchar)item->RedoText[j];
if (c >= 0x20) { if (c >= 0x20)
printf("%c", c); printf("%c", c);
} else { else
printf("?"); printf("?");
}
} }
printf("'\n"); printf("'\n");
} }