1 /* 2 * Copyright 2006, Haiku. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 */ 8 9 #include "Util.h" 10 11 #include <new> 12 13 #include "AddPathsCommand.h" 14 #include "AddStylesCommand.h" 15 #include "PathContainer.h" 16 #include "Style.h" 17 #include "StyleContainer.h" 18 #include "VectorPath.h" 19 20 using std::nothrow; 21 22 // new_style 23 void 24 new_style(rgb_color color, StyleContainer* container, 25 Style** style, AddStylesCommand** command) 26 { 27 *style = new (nothrow) Style(color); 28 if (*style) { 29 Style* styles[1]; 30 styles[0] = *style; 31 *command = new (nothrow) AddStylesCommand( 32 container, styles, 1, 33 container->CountStyles()); 34 if (*command == NULL) { 35 delete *style; 36 *style = NULL; 37 } 38 } else { 39 *command = NULL; 40 } 41 } 42 43 // new_path 44 void 45 new_path(PathContainer* container, VectorPath** path, 46 AddPathsCommand** command, VectorPath* other) 47 { 48 if (other) 49 *path = new (nothrow) VectorPath(*other); 50 else 51 *path = new (nothrow) VectorPath(); 52 53 if (*path) { 54 VectorPath* paths[1]; 55 paths[0] = *path; 56 int32 insertIndex = other ? container->IndexOf(other) + 1 57 : container->CountPaths(); 58 *command = new (nothrow) AddPathsCommand( 59 container, paths, 1, true, insertIndex); 60 if (*command == NULL) { 61 delete *path; 62 *path = NULL; 63 } 64 } else { 65 *command = NULL; 66 } 67 } 68 69 70 71 72