reactos/dll/win32/riched20/row.c

93 lines
2.8 KiB
C
Raw Normal View History

/*
* RichEdit - Operations on rows of text (rows are recreated during
* wrapping and are used for displaying the document, they don't keep any
* true document content; delete all rows, rewrap all paragraphs and
* you get them back).
*
* Copyright 2004 by Krzysztof Foltman
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "editor.h"
/* I'm sure these functions would simplify some code in caret ops etc,
* I just didn't remember them when I wrote that code
*/
ME_DisplayItem *ME_RowStart(ME_DisplayItem *item) {
return ME_FindItemBackOrHere(item, diStartRow);
}
/*
ME_DisplayItem *ME_RowEnd(ME_DisplayItem *item) {
ME_DisplayItem *item2 = ME_FindItemFwd(item, diStartRowOrParagraphOrEnd);
if (!item2) return NULL;
return ME_FindItemBack(item, diRun);
}
*/
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
ME_DisplayItem *
ME_FindRowWithNumber(ME_TextEditor *editor, int nRow)
{
ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
int nCount = 0;
while (item->type == diParagraph &&
nCount + item->member.para.nRows <= nRow)
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
{
nCount += item->member.para.nRows;
item = item->member.para.next_para;
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
}
if (item->type != diParagraph)
return NULL;
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
for (item = ME_FindItemFwd(item, diStartRow); item && nCount < nRow; nCount++)
item = ME_FindItemFwd(item, diStartRow);
return item;
}
int
ME_RowNumberFromCharOfs(ME_TextEditor *editor, int nOfs)
{
ME_DisplayItem *item = ME_FindItemFwd(editor->pBuffer->pFirst, diParagraph);
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
int nRow = 0;
while (item->type == diParagraph &&
item->member.para.next_para->member.para.nCharOfs <= nOfs)
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
{
nRow += item->member.para.nRows;
item = item->member.para.next_para;
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
}
if (item->type == diParagraph)
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
{
ME_DisplayItem *next_para = item->member.para.next_para;
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
nOfs -= item->member.para.nCharOfs;
item = ME_FindItemFwd(item, diRun);
while ((item = ME_FindItemFwd(item, diStartRowOrParagraph)) != NULL)
{
if (item == next_para)
break;
Sync to Wine-20050725: Phil Krylov <phil@newstar.rinet.ru> - Added some useful TRACEs. - Allow NULL parameter for WM_SETTEXT in RichEdit. - Implemented EM_LINELENGTH RichEdit message. - Fixed EM_LINEINDEX handler and added EM_LINEFROMCHAR handler. - Implemented EM_EXLINEFROMCHAR, EM_LINEINDEX, EM_FINDTEXT, EM_FINDTEXTW, EM_FINDTEXTEX, and EM_FINDTEXTEXW messages. - Fixed a comment about EM_STREAMIN. - Implemented EM_GETLINECOUNT RichEdit message. - Fixed EM_GETCHARFORMAT for selection containing a single character. - Fixed an off-by-one error in EM_GETLINECOUNT handler. - Fixed an off-by-one error in EM_STREAMOUT handler for non-Unicode plain text output. - Fixed another couple of EM_STREAMOUT bugs. - Removed junk from UTF-8 RTF output. - Added emulation of RichEdit 1.0 behaviour when the 1.0 window class is being used. This emulation (introduced in M$ RichEdit 3.0) counts paragraph endings as 2 characters (CR+LF) instead of 1 (CR). - Added EM_GETZOOM and EM_SETZOOM RichEdit message handlers. - Added some missing but useful items to the TODO list. Felix Nawothnig <felix.nawothnig@t-online.de> - Check structure size and fix return values in EM_GETCHARFORMAT. Aric Stewart <aric@codeweavers.com> - Implementation for EM_GETTEXTEX. Daniel Remenak <dtremenak@gmail.com> - Basic handling of EM_SETTEXTEX. Stefan Huehner <stefan@huehner.org> - Make functions static to fix -Wmissing-declarations warnings. - Change some char* to const char* to fix warnigns. - Make some function static. - Fix -Wmissing-declarations warnings. svn path=/trunk/; revision=17335
2005-08-12 17:41:40 +00:00
item = ME_FindItemFwd(item, diRun);
if (item->member.run.nCharOfs > nOfs)
break;
nRow++;
}
}
return nRow;
}