00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <math.h>
00016 #include <stdlib.h>
00017 #include <stdarg.h>
00018 #include <time.h>
00019
00020 #include "CloneObjects.h"
00021 #include "GetProperty.h"
00022 #include "BuildObjects.h"
00023 #include "bcg.h"
00024 #include "SetProperty.h"
00025 #include "sciprint.h"
00026 #include "CurrentObjectsManagement.h"
00027
00028 #include "MALLOC.h"
00029
00036 double *
00037 sciCloneColormap (sciPointObj * pobj)
00038 {
00039 double *rgbmat;
00040 int m = sciGetNumColors (pobj);
00041
00042 if ((rgbmat = MALLOC (m * 3 * sizeof (double))) == NULL)
00043 {
00044 return NULL;
00045 }
00046
00047 sciGetColormap( pobj, rgbmat ) ;
00048
00049 return rgbmat;
00050 }
00051
00052
00053
00058 sciPointObj *
00059 CloneText (sciPointObj * pthis)
00060 {
00061 sciPointObj * pobj ;
00062 sciPointObj * subwinparent;
00063 sciText * ppThisText ;
00064 sciText * ppCopyText ;
00065 int foreground = sciGetForeground(pthis);
00066 int background = sciGetBackground(pthis);
00067 int nbRow ;
00068 int nbCol ;
00069
00070 subwinparent = pthis;
00071
00072 while ((sciGetEntityType(subwinparent = sciGetParent(subwinparent)) != SCI_SUBWIN)
00073 && ((int) sciGetEntityType(subwinparent) != -1));
00074 if ((int) sciGetEntityType(subwinparent) == -1)
00075 {
00076 return (sciPointObj *)NULL;
00077 }
00078
00079 sciGetTextSize( pthis, &nbRow, &nbCol ) ;
00080
00081 if (!(pobj = ConstructText (subwinparent, getStrMatData( sciGetText(pthis) ), nbRow, nbCol,
00082 sciGetTextPosX(pthis), sciGetTextPosY(pthis),sciGetAutoSize(pthis),
00083 pTEXT_FEATURE(pthis)->userSize,pTEXT_FEATURE(pthis)->centeredPos,
00084 &foreground,&background,pTEXT_FEATURE(pthis)->isboxed,
00085 sciGetIsLine(pthis), sciGetIsFilled(pthis), sciGetAlignment(pthis))))
00086 {
00087 return (sciPointObj *)NULL;
00088 }
00089 else
00090 {
00091 sciSetCurrentObj(pobj);
00092 }
00093
00094 if (sciSetBackground(pobj, sciGetBackground (pthis)) == -1)
00095 return (sciPointObj *)NULL;
00096
00097 if (sciSetForeground(pobj, sciGetForeground (pthis)) == -1)
00098 return (sciPointObj *)NULL;
00099
00100 if (sciSetFontDeciWidth(pobj, sciGetFontDeciWidth (pthis)) == -1)
00101 return (sciPointObj *)NULL;
00102
00103 if (sciSetFontOrientation(pobj, sciGetFontOrientation (pthis)) == -1)
00104 return (sciPointObj *)NULL;
00105
00106 if (sciSetFontStyle(pobj,sciGetFontStyle (pthis)) == -1)
00107 return (sciPointObj *)NULL;
00108
00109 if (sciSetFontName(pobj, sciGetFontName (pthis), sciGetFontNameLength(pthis)) == -1)
00110 return (sciPointObj *)NULL;
00111
00112
00113 ppThisText = pTEXT_FEATURE( pthis ) ;
00114 ppCopyText = pTEXT_FEATURE( pobj ) ;
00115
00116 ppCopyText->userSize[0] = ppThisText->userSize[0];
00117 ppCopyText->userSize[1] = ppThisText->userSize[1];
00118
00119
00120 if((ppThisText->size_of_user_data != 0) && (ppThisText->user_data != (int *) NULL))
00121 {
00122 int size = ppThisText->size_of_user_data;
00123
00124 if((ppCopyText->user_data = (int *) MALLOC(size*sizeof(int)))==NULL){
00125 sciprint("Can not allocate user_data for cloned object.\n");
00126 ppCopyText->user_data = (int *) NULL;
00127 ppCopyText->size_of_user_data = 0;
00128 }
00129 else{
00130 memcpy(ppCopyText->user_data, ppThisText->user_data, size);
00131 ppCopyText->size_of_user_data = pTEXT_FEATURE (pthis)->size_of_user_data;
00132 }
00133 }
00134
00135 return (sciPointObj *)pobj;
00136 }
00137
00138
00139
00142 sciPointObj *
00143 sciCloneObj (sciPointObj * pobj)
00144 {
00145 switch (sciGetEntityType (pobj))
00146 {
00147 case SCI_TEXT:
00148 return CloneText(pobj);
00149 break;
00150 case SCI_POLYLINE:
00151 return ClonePolyline(pobj);
00152 break;
00153 case SCI_ARC:
00154 return CloneArc(pobj);
00155 break;
00156 case SCI_RECTANGLE:
00157 return CloneRectangle(pobj);
00158 break;
00159 case SCI_CONSOLE:
00160 return sciCloneConsole(pobj) ;
00161 case SCI_FRAME:
00162 return sciCloneFrame(pobj) ;
00163 case SCI_WINDOW:
00164 return sciCloneWindow(pobj) ;
00165 case SCI_WINDOWFRAME:
00166 return sciCloneWindowFrame(pobj) ;
00167 case SCI_SCREEN:
00168 return sciCloneScreen(pobj) ;
00169 case SCI_AGREG:
00170
00171 case SCI_SEGS:
00172 case SCI_FEC:
00173 case SCI_GRAYPLOT:
00174 case SCI_FIGURE:
00175 case SCI_SUBWIN:
00176 case SCI_LEGEND:
00177 case SCI_TITLE:
00178 case SCI_SURFACE:
00179 case SCI_LIGHT:
00180 case SCI_AXES:
00181 case SCI_PANNER:
00182 case SCI_SBH:
00183 case SCI_SBV:
00184 case SCI_MENU:
00185 case SCI_MENUCONTEXT:
00186 case SCI_STATUSB:
00187 case SCI_LABEL:
00188 case SCI_UIMENU:
00189 default:
00190 sciprint ("This object cannot be cloned !\n");
00191 return (sciPointObj *)NULL;
00192 break;
00193 }
00194 return (sciPointObj *)NULL;
00195 }
00196
00197
00198
00203 sciPointObj *
00204 CloneRectangle (sciPointObj * pthis)
00205 {
00206 sciPointObj * pobj, *subwinparent;
00207 int foreground = sciGetForeground(pthis);
00208 int background = sciGetBackground(pthis);
00209
00210 subwinparent = pthis;
00211
00212
00213 while ((sciGetEntityType(subwinparent = sciGetParent(subwinparent)) != SCI_SUBWIN)
00214 && ((int)sciGetEntityType(subwinparent) != -1));
00215 if ((int)sciGetEntityType(subwinparent) == -1)
00216 return (sciPointObj *)NULL;
00217 if (!(pobj = ConstructRectangle (subwinparent, pRECTANGLE_FEATURE(pthis)->x,
00218 pRECTANGLE_FEATURE(pthis)->y, pRECTANGLE_FEATURE(pthis)->height,pRECTANGLE_FEATURE(pthis)->width,
00219 pRECTANGLE_FEATURE(pthis)->horzcurvature, pRECTANGLE_FEATURE(pthis)->vertcurvature,
00220 &foreground,&background,sciGetIsFilled(pthis),sciGetIsLine(pthis),0,pRECTANGLE_FEATURE(pthis)->flagstring))){
00221 return (sciPointObj *)NULL;
00222 }
00223 else {
00224 sciSetCurrentObj(pobj);};
00225 if (sciSetBackground(pobj, sciGetBackground (pthis)) == -1)
00226 return (sciPointObj *)NULL;
00227 if (sciSetForeground(pobj, sciGetForeground (pthis)) == -1)
00228 return (sciPointObj *)NULL;
00229 if (sciSetLineStyle(pobj, sciGetLineStyle (pthis)) == -1)
00230 return (sciPointObj *)NULL;
00231 if (sciSetFillStyle(pobj, sciGetFillStyle (pthis)) == -1)
00232 return (sciPointObj *)NULL;
00233 if (sciSetLineWidth(pobj, sciGetLineWidth (pthis)) == -1)
00234 return (sciPointObj *)NULL;
00235 if (sciSetIsFilled(pobj, sciGetIsFilled (pthis)) == -1)
00236 return (sciPointObj *)NULL;
00237
00238 if((pRECTANGLE_FEATURE (pthis)->size_of_user_data != 0) && (pRECTANGLE_FEATURE (pthis)->user_data != (int *) NULL))
00239 {
00240 int size = pRECTANGLE_FEATURE (pthis)->size_of_user_data;
00241
00242 if((pRECTANGLE_FEATURE (pobj)->user_data = (int *) MALLOC(size*sizeof(int)))==NULL){
00243 sciprint("Can not allocate user_data for cloned object.\n");
00244 pRECTANGLE_FEATURE (pobj)->user_data = (int *) NULL;
00245 pRECTANGLE_FEATURE (pobj)->size_of_user_data = 0;
00246 }
00247 else{
00248 memcpy(pRECTANGLE_FEATURE (pobj)->user_data, pRECTANGLE_FEATURE (pthis)->user_data, size);
00249 pRECTANGLE_FEATURE (pobj)->size_of_user_data = pRECTANGLE_FEATURE (pthis)->size_of_user_data;
00250 }
00251 }
00252
00253 return (sciPointObj *)pobj;
00254 }
00255
00256
00261 sciPointObj *
00262 ClonePolyline (sciPointObj * pthis)
00263 {
00264 sciPointObj * pobj, *subwinparent;
00265 int foreground = sciGetForeground(pthis);
00266 int background = sciGetBackground(pthis);
00267 int mark_foreground = sciGetMarkForeground(pthis);
00268 int mark_background = sciGetMarkBackground(pthis);
00269 int mark_style = sciGetMarkStyle(pthis);
00270
00271 subwinparent = pthis;
00272
00273 while ((sciGetEntityType(subwinparent = sciGetParent(subwinparent)) != SCI_SUBWIN)
00274 && ((int)sciGetEntityType(subwinparent) != -1));
00275 if ((int)sciGetEntityType(subwinparent) == -1)
00276 return (sciPointObj *)NULL;
00277
00278 if (!(pobj = ConstructPolyline (subwinparent, pPOLYLINE_FEATURE(pthis)->pvx, pPOLYLINE_FEATURE(pthis)->pvy,pPOLYLINE_FEATURE(pthis)->pvz,
00279 pPOLYLINE_FEATURE(pthis)->closed, pPOLYLINE_FEATURE(pthis)->n1,pPOLYLINE_FEATURE(pthis)->n2,pPOLYLINE_FEATURE(pthis)->plot,
00280 &foreground, &background,
00281 &mark_style, &mark_foreground, &mark_background,
00282 sciGetIsLine(pthis), sciGetIsFilled(pthis),
00283 sciGetIsMark(pthis),pPOLYLINE_FEATURE(pthis)->isinterpshaded))){
00284 return (sciPointObj *)NULL;
00285 }
00286 else {
00287 sciSetCurrentObj(pobj);};
00288
00289
00290 pPOLYLINE_FEATURE(pobj)->dim_icv = pPOLYLINE_FEATURE(pthis)->dim_icv;
00291
00292 if (sciSetBackground(pobj, sciGetBackground (pthis)) == -1)
00293 return (sciPointObj *)NULL;
00294 if (sciSetForeground(pobj, sciGetForeground (pthis)) == -1)
00295 return (sciPointObj *)NULL;
00296 if (sciSetLineStyle(pobj, sciGetLineStyle (pthis)) == -1)
00297 return (sciPointObj *)NULL;
00298 if (sciSetFillStyle(pobj, sciGetFillStyle (pthis)) == -1)
00299 return (sciPointObj *)NULL;
00300 if (sciSetLineWidth(pobj, sciGetLineWidth (pthis)) == -1)
00301 return (sciPointObj *)NULL;
00302
00303 if((pPOLYLINE_FEATURE (pthis)->size_of_user_data != 0) && (pPOLYLINE_FEATURE (pthis)->user_data != (int *) NULL))
00304 {
00305 int size = pPOLYLINE_FEATURE (pthis)->size_of_user_data;
00306
00307 if((pPOLYLINE_FEATURE (pobj)->user_data = (int *) MALLOC(size*sizeof(int)))==NULL){
00308 sciprint("Can not allocate user_data for cloned object.\n");
00309 pPOLYLINE_FEATURE (pobj)->user_data = (int *) NULL;
00310 pPOLYLINE_FEATURE (pobj)->size_of_user_data = 0;
00311 }
00312 else{
00313 memcpy(pPOLYLINE_FEATURE (pobj)->user_data, pPOLYLINE_FEATURE (pthis)->user_data, size);
00314 pPOLYLINE_FEATURE (pobj)->size_of_user_data = pPOLYLINE_FEATURE (pthis)->size_of_user_data;
00315 }
00316 }
00317
00318 return (sciPointObj *)pobj;
00319 }
00320
00321
00326 sciPointObj *
00327 CloneArc (sciPointObj * pthis)
00328 {
00329 sciPointObj * pobj, *subwinparent;
00330
00331 int foreground = sciGetForeground(pthis);
00332 int background = sciGetBackground(pthis);
00333
00334 subwinparent = pthis;
00335
00336
00337 while ((sciGetEntityType(subwinparent = sciGetParent(subwinparent)) != SCI_SUBWIN)
00338 && ((int)sciGetEntityType(subwinparent) != -1));
00339 if ((int)sciGetEntityType(subwinparent) == -1)
00340 return (sciPointObj *)NULL;
00341 if (!(pobj = ConstructArc (subwinparent, pARC_FEATURE(pthis)->x,
00342 pARC_FEATURE(pthis)->y, pARC_FEATURE(pthis)->height,pARC_FEATURE(pthis)->width,
00343 pARC_FEATURE(pthis)->alphabegin, pARC_FEATURE(pthis)->alphaend,
00344 &foreground,&background,sciGetIsFilled(pthis),sciGetIsLine(pthis)))){
00345 return (sciPointObj *)NULL;
00346 }
00347 else {
00348 sciSetCurrentObj(pobj);};
00349 if (sciSetBackground(pobj, sciGetBackground (pthis)) == -1)
00350 return (sciPointObj *)NULL;
00351 if (sciSetForeground(pobj, sciGetForeground (pthis)) == -1)
00352 return (sciPointObj *)NULL;
00353 if (sciSetLineStyle(pobj, sciGetLineStyle (pthis)) == -1)
00354 return (sciPointObj *)NULL;
00355 if (sciSetFillStyle(pobj, sciGetFillStyle (pthis)) == -1)
00356 return (sciPointObj *)NULL;
00357 if (sciSetLineWidth(pobj, sciGetLineWidth (pthis)) == -1)
00358 return (sciPointObj *)NULL;
00359 if (sciSetIsFilled(pobj, sciGetIsFilled (pthis)) == -1)
00360 return (sciPointObj *)NULL;
00361
00362 if((pARC_FEATURE (pthis)->size_of_user_data != 0) && (pARC_FEATURE (pthis)->user_data != (int *) NULL))
00363 {
00364 int size = pARC_FEATURE (pthis)->size_of_user_data;
00365
00366 if((pARC_FEATURE (pobj)->user_data = (int *) MALLOC(size*sizeof(int)))==NULL){
00367 sciprint("Can not allocate user_data for cloned object.\n");
00368 pARC_FEATURE (pobj)->user_data = (int *) NULL;
00369 pARC_FEATURE (pobj)->size_of_user_data = 0;
00370 }
00371 else{
00372 memcpy(pARC_FEATURE (pobj)->user_data, pARC_FEATURE (pthis)->user_data, size);
00373 pARC_FEATURE (pobj)->size_of_user_data = pARC_FEATURE (pthis)->size_of_user_data;
00374 }
00375 }
00376
00377 return (sciPointObj *)pobj;
00378 }
00379
00380
00381
00384 sciPointObj *
00385 sciCopyObj (sciPointObj * pobj, sciPointObj * psubwinparenttarget )
00386 {
00387 sciPointObj *pcopyobj;
00388
00389 pcopyobj = sciCloneObj ((sciPointObj *)pobj);
00390 sciDelThisToItsParent ((sciPointObj *)pcopyobj, (sciPointObj *)sciGetParent(pcopyobj));
00391 sciAddThisToItsParent ((sciPointObj *)pcopyobj, (sciPointObj *)psubwinparenttarget);
00392 return (sciPointObj *)pcopyobj;
00393 }
00394
00395
00396 int cloneGraphicContext( sciPointObj * pObjSource, sciPointObj * pObjDest )
00397 {
00398
00399 *(sciGetGraphicContext(pObjDest)) = *(sciGetGraphicContext(pObjSource)) ;
00400 return 0 ;
00401 }
00402
00403 int cloneUserData( sciPointObj * pObjSource, sciPointObj * pObjDest )
00404 {
00405 int ** srcUserData ;
00406 int * srcSize ;
00407 int ** dstUserData ;
00408 int * dstSize ;
00409 sciGetPointerToUserData( pObjSource, &srcUserData, &srcSize ) ;
00410 sciGetPointerToUserData( pObjDest , &dstUserData, &dstSize ) ;
00411 if ( *srcSize > 0 )
00412 {
00413 *dstSize = *srcSize ;
00414 if ( *dstUserData != NULL ) { FREE(*dstUserData) ; }
00415 *dstUserData = MALLOC( *srcSize * sizeof(int) ) ;
00416 if ( *dstUserData == NULL )
00417 {
00418 sciprint("Error allocating user_data, memory full.\n") ;
00419 *dstSize = 0 ;
00420 *srcUserData = NULL ;
00421 return -1 ;
00422 }
00423 memcpy( *dstUserData, *srcUserData, *srcSize ) ;
00424 }
00425 else
00426 {
00427 *dstSize = 0 ;
00428 *srcUserData = NULL ;
00429 }
00430 return 0 ;
00431 }
00432
00433 int cloneFontContext( sciPointObj * pObjSource, sciPointObj * pObjDest )
00434 {
00435
00436
00437
00438
00439 sciFont * sourceFC = sciGetFontContext( pObjSource ) ;
00440 sciFont * destFC = sciGetFontContext( pObjDest ) ;
00441
00442 if ( destFC->fontnamelen != 0 )
00443 {
00444 FREE( destFC->pfontname ) ;
00445 destFC->pfontname = NULL ;
00446 }
00447
00448
00449 if ( sourceFC->fontnamelen != 0 )
00450 {
00451 destFC->pfontname = MALLOC( sourceFC->fontnamelen * sizeof( char ) ) ;
00452 if ( destFC->pfontname == NULL )
00453 {
00454 return -1 ;
00455 }
00456 strcpy( destFC->pfontname, sourceFC->pfontname ) ;
00457 }
00458
00459 destFC->fontnamelen = sourceFC->fontnamelen ;
00460 destFC->backgroundcolor = sourceFC->backgroundcolor ;
00461 destFC->foregroundcolor = sourceFC->foregroundcolor ;
00462 destFC->fonttype = sourceFC->fonttype ;
00463 destFC->fontdeciwidth = sourceFC->fontdeciwidth ;
00464 destFC->textorientation = sourceFC->textorientation ;
00465 return 0 ;
00466 }
00467
00468 sciPointObj * sciCloneConsole( sciPointObj * pthis )
00469 {
00470 sciPointObj * newObj = NULL ;
00471 int posX ;
00472 int posY ;
00473
00474 newObj = sciConstructConsole( sciGetParent(pthis) ) ;
00475
00476 sciInitVisibility( newObj, sciGetVisibility(pthis) ) ;
00477 sciGetScreenPosition( pthis, &posX, &posY ) ;
00478 sciInitScreenPosition( newObj, posX, posY ) ;
00479
00480
00481 cloneUserData( pthis, newObj ) ;
00482
00483 return newObj ;
00484 }
00485
00486 sciPointObj * sciCloneFrame( sciPointObj * pthis )
00487 {
00488 sciPointObj * newObj = NULL ;
00489 int posX ;
00490 int posY ;
00491
00492 newObj = sciConstructFrame( sciGetParent(pthis) ) ;
00493
00494 sciInitVisibility( newObj, sciGetVisibility(pthis) ) ;
00495 sciGetScreenPosition( pthis, &posX, &posY ) ;
00496 sciInitScreenPosition( newObj, posX, posY ) ;
00497
00498
00499 cloneUserData( pthis, newObj ) ;
00500
00501 return newObj ;
00502 }
00503
00504 sciPointObj * sciCloneWindow( sciPointObj * pthis )
00505 {
00506 sciPointObj * newObj = NULL ;
00507 int posX ;
00508 int posY ;
00509
00510 newObj = sciConstructWindow( sciGetParent(pthis) ) ;
00511
00512 sciInitVisibility( newObj, sciGetVisibility(pthis) ) ;
00513 sciGetScreenPosition( pthis, &posX, &posY ) ;
00514 sciInitScreenPosition( newObj, posX, posY ) ;
00515
00516
00517 cloneUserData( pthis, newObj ) ;
00518
00519 return newObj ;
00520 }
00521
00522 sciPointObj * sciCloneWindowFrame( sciPointObj * pthis )
00523 {
00524 sciPointObj * newObj = NULL ;
00525 int posX ;
00526 int posY ;
00527
00528 newObj = sciConstructWindowFrame( sciGetParent(pthis) ) ;
00529
00530 sciInitVisibility( newObj, sciGetVisibility(pthis) ) ;
00531 sciGetScreenPosition( pthis, &posX, &posY ) ;
00532 sciInitScreenPosition( newObj, posX, posY ) ;
00533
00534
00535 cloneUserData( pthis, newObj ) ;
00536
00537 return newObj ;
00538 }
00539
00540 sciPointObj * sciCloneScreen( sciPointObj * pthis )
00541 {
00542 sciPointObj * newObj = NULL ;
00543 int posX ;
00544 int posY ;
00545
00546 newObj = sciConstructScreen( sciGetParent(pthis) ) ;
00547
00548 sciInitVisibility( newObj, sciGetVisibility(pthis) ) ;
00549 sciGetScreenPosition( pthis, &posX, &posY ) ;
00550 sciInitScreenPosition( newObj, posX, posY ) ;
00551
00552
00553 cloneUserData( pthis, newObj ) ;
00554
00555 return newObj ;
00556 }
00557