revert between 56095 -> 55830 in arch
[AROS.git] / workbench / classes / zune / texteditor / mcc / ExportBlock.c
blobcb86d763234675307ac1a6e807d72e67a4a33d3f
1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 TextEditor.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
19 $Id$
21 ***************************************************************************/
23 #include <string.h>
25 #include <proto/utility.h>
27 #include "private.h"
28 #include "Debug.h"
30 /// mExportBlock()
31 IPTR mExportBlock(struct IClass *cl, Object *obj, struct MUIP_TextEditor_ExportBlock *msg)
33 struct InstData *data = INST_DATA(cl, obj);
34 struct line_node *node;
35 struct Hook *exportHook = data->ExportHook;
36 LONG wraplen = data->ExportWrap;
37 struct ExportMessage emsg;
38 struct marking newblock;
39 ULONG flags = msg->flags;
40 void *user_data = NULL;
42 ENTER();
44 // get information about marked text
45 if(data->blockinfo.enabled == TRUE)
46 NiceBlock(&data->blockinfo, &newblock);
47 else
49 newblock.startline = data->actualline;
50 newblock.startx = data->CPos_X;
51 newblock.stopline = data->actualline;
52 newblock.stopx = data->CPos_X;
55 if(isFlagSet(flags, MUIF_TextEditor_ExportBlock_TakeBlock))
57 if(msg->starty <= data->totallines)
58 newblock.startline = LineNode(data, msg->starty+1);
60 if(msg->startx <= (newblock.startline)->line.Length)
61 newblock.startx = msg->startx;
63 if(msg->stopx <= (newblock.startline)->line.Length)
64 newblock.stopx = msg->stopx;
66 if(msg->stopy <= data->totallines)
67 newblock.stopline = LineNode(data, msg->stopy+1);
70 node = newblock.startline;
72 // clear the export message
73 memset(&emsg, 0, sizeof(emsg));
75 // now we export all selected/marked lines with
76 // the currently active export hook
77 while(node != NULL)
79 struct line_node *next = GetNextLine(node);
81 emsg.UserData = user_data;
82 emsg.Contents = node->line.Contents;
83 emsg.Length = node->line.Length;
84 emsg.Styles = node->line.Styles;
85 emsg.Colors = node->line.Colors;
86 emsg.Highlight = node->line.Highlight;
87 emsg.Flow = node->line.Flow;
88 emsg.Separator = node->line.Separator;
89 emsg.ExportWrap = wraplen;
90 emsg.Last = next == NULL || node == newblock.stopline;
92 // to make sure that for the last line we don't export the additional,
93 // artificial newline '\n' we reduce the passed length value by one.
94 if(next == NULL && emsg.Contents[node->line.Length-1] == '\n')
95 emsg.Length--;
97 // see if we have to skip some chars at the front or
98 // back of the current line node
99 if(isFlagClear(flags, MUIF_TextEditor_ExportBlock_FullLines))
101 if(node == newblock.startline)
102 emsg.SkipFront = newblock.startx;
103 else
104 emsg.SkipFront = 0;
106 if(node == newblock.stopline)
107 emsg.SkipBack = emsg.Length-newblock.stopx;
108 else
109 emsg.SkipBack = 0;
112 // call the ExportHook and exit immediately if it returns NULL
113 if((user_data = (void*)CallHookPkt(exportHook, NULL, &emsg)) == NULL)
114 break;
116 // check if the current node was the last one which
117 // was marked, and if so we go and stop our export here
118 if(node == newblock.stopline)
119 break;
121 node = next;
124 RETURN((IPTR)user_data);
125 return (IPTR)user_data;