grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / texteditor / mcc / SetBlock.c
blob4183b8906c9e269bec0203117dfdbc967c0d5315
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 /// mSetBlock()
31 IPTR mSetBlock(struct InstData *data, struct MUIP_TextEditor_SetBlock *msg)
33 BOOL result = TRUE;
34 struct marking newblock;
36 ENTER();
38 // initialize newblock
39 newblock.enabled = FALSE;
41 // now we check&set the start variables to their corresponding values
42 if(msg->starty == MUIV_TextEditor_SetBlock_Min)
43 newblock.startline = LineNode(data, 1);
44 else if(msg->starty == MUIV_TextEditor_SetBlock_Max)
45 newblock.startline = LineNode(data, data->totallines+1);
46 else if(msg->starty >= 0 && msg->starty <= data->totallines)
47 newblock.startline = LineNode(data, msg->starty+1);
48 else
49 result = FALSE;
51 if((LONG)msg->startx == MUIV_TextEditor_SetBlock_Min)
52 newblock.startx = 0;
53 else if(newblock.startline != NULL)
55 if(msg->startx == MUIV_TextEditor_SetBlock_Max)
56 newblock.startx = (newblock.startline)->line.Length;
57 else if(msg->startx >= 0 && msg->startx <= (newblock.startline)->line.Length)
58 newblock.startx = msg->startx;
59 else
60 result = FALSE;
62 else
63 result = FALSE;
65 // now we check&set the stop variables to their corresponding values
66 if(msg->stopy == MUIV_TextEditor_SetBlock_Min)
67 newblock.stopline = LineNode(data, 1);
68 else if(msg->stopy == MUIV_TextEditor_SetBlock_Max)
69 newblock.stopline = LineNode(data, data->totallines+1);
70 else if(msg->stopy >= 0 && msg->stopy <= data->totallines)
71 newblock.stopline = LineNode(data, msg->stopy+1);
72 else
73 result = FALSE;
75 if(msg->stopx == MUIV_TextEditor_SetBlock_Min)
76 newblock.stopx = 0;
77 else if(newblock.stopline != NULL)
79 if(msg->stopx == MUIV_TextEditor_SetBlock_Max)
80 newblock.stopx = (newblock.stopline)->line.Length;
81 else if(msg->stopx >= 0 && msg->stopx <= (newblock.stopline)->line.Length)
82 newblock.stopx = msg->stopx;
83 else
84 result = FALSE;
86 else
87 result = FALSE;
89 // check if valid values had been specified for our start/stop values
90 if(result == TRUE)
92 // enable the block during the color/style changes
93 newblock.enabled = TRUE;
95 if(isFlagSet(msg->operation, MUIF_TextEditor_SetBlock_Color))
97 AddColor(data, &newblock, (UWORD)msg->value);
100 if(isFlagSet(msg->operation, MUIF_TextEditor_SetBlock_StyleBold))
102 AddStyle(data, &newblock, BOLD, msg->value != 0);
105 if(isFlagSet(msg->operation, MUIF_TextEditor_SetBlock_StyleItalic))
107 AddStyle(data, &newblock, ITALIC, msg->value != 0);
110 if(isFlagSet(msg->operation, MUIF_TextEditor_SetBlock_StyleUnderline))
112 AddStyle(data, &newblock, UNDERLINE, msg->value != 0);
115 // disable the block again
116 newblock.enabled = FALSE;
118 if(isFlagSet(msg->operation, MUIF_TextEditor_SetBlock_Flow))
120 LONG start, lines = 0;
121 struct marking newblock2;
122 struct line_node *startline;
124 data->Flow = msg->value;
126 NiceBlock(&newblock, &newblock2);
127 startline = newblock2.startline;
128 start = LineToVisual(data, startline);
132 lines += startline->visual;
133 startline->line.Flow = msg->value;
134 startline = GetNextLine(startline);
136 while(startline != GetNextLine(newblock2.stopline));
138 if(start < 1)
139 start = 1;
141 if(start-1+lines > data->maxlines)
142 lines = data->maxlines-(start-1);
144 DumpText(data, data->visual_y+start-1, start-1, start-1+lines, TRUE);
148 RETURN(result);
149 return result;