Fixed building of catalogs.
[AROS.git] / workbench / classes / zune / nlist / nlist_mcc / NList_func4.c
blob445e09a4a1e58ab975476e1d7493c7685eb22dcf
1 /***************************************************************************
3 NList.mcc - New List MUI Custom Class
4 Registered MUI class, Serial Number: 1d51 0x9d510030 to 0x9d5100A0
5 0x9d5100C0 to 0x9d5100FF
7 Copyright (C) 1996-2001 by Gilles Masson
8 Copyright (C) 2001-2013 by NList Open Source Team
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 2.1 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 NList classes Support Site: http://www.sf.net/projects/nlist-classes
22 $Id$
24 ***************************************************************************/
26 #include <string.h>
28 #include <exec/execbase.h>
29 #include <exec/memory.h>
30 #include <intuition/pointerclass.h>
31 #include <datatypes/pictureclass.h>
33 #include <proto/exec.h>
34 #include <proto/graphics.h>
35 #include <proto/muimaster.h>
36 #include <proto/intuition.h>
37 #include <proto/exec.h>
38 #include <proto/layers.h>
40 #include "private.h"
42 #include "NList_func.h"
44 #if !defined(__amigaos4__) && !defined(__MORPHOS__) && !defined(__AROS__)
45 LONG ObtainBestPen( struct ColorMap *cm, ULONG r, ULONG g, ULONG b, ULONG tag1Type, ... );
46 #endif
48 /****************************************************************************************/
49 /****************************************************************************************/
50 /****************************** **************************************/
51 /****************************** NList Class **************************************/
52 /****************************** **************************************/
53 /****************************************************************************************/
54 /****************************************************************************************/
56 BOOL NL_OnWindow(struct NLData *data,LONG x,LONG y)
58 BOOL onWindow = FALSE;
59 Object *obj = data->this;
61 #if defined(__MORPHOS__)
62 /* No need for hit test in MorphOS 2.0 */
63 if (SysBase->LibNode.lib_Version >= 51)
64 return TRUE;
65 #endif
67 if (data->SHOW && muiRenderInfo(obj) && _screen(obj) != NULL && _window(obj) != NULL)
69 // first check whether the mouse is over the object itself
70 if(x >= _mleft(obj) && x <= _mright(obj) && y >= _mtop(obj) && y <= _mbottom(obj))
72 // now check if the mouse is currently over the object and over the object's window
73 struct Layer_Info *li = &(_screen(obj)->LayerInfo);
74 struct Layer *layer;
76 // get the layer that belongs to the current mouse coordinates
77 LockLayerInfo(li);
78 layer = WhichLayer(li, _window(obj)->LeftEdge + x, _window(obj)->TopEdge + y);
79 UnlockLayerInfo(li);
81 if(layer != NULL && layer->Window == _window(obj))
82 onWindow = TRUE;
85 struct Window *win;
86 struct Layer *wlay,*lay;
87 ULONG lkib = LockIBase( 0 );
88 x += _window(obj)->LeftEdge;
89 y += _window(obj)->TopEdge;
90 wlay = _window(obj)->WLayer;
91 for (lay = wlay->front; wlay && lay; lay = lay->front)
92 { win = (struct Window *) lay->Window;
93 for (win = _screen(obj)->FirstWindow; win ; win = win->NextWindow)
94 { if (win->WLayer == lay)
95 { if ((x >= win->LeftEdge) && (y >= win->TopEdge) &&
96 (x < win->LeftEdge + win->Width) && (y < win->TopEdge + win->Height))
97 { UnlockIBase( lkib );
98 return (FALSE);
103 UnlockIBase( lkib );
106 return onWindow;
112 struct NImgList *GetNImage(struct NLData *data,char *ImgName)
114 struct NImgList *nimg = &data->NImage;
115 int nameLen = strlen(ImgName)+2;
117 while (nimg && nimg->ImgName && strcmp(nimg->ImgName,ImgName))
118 nimg = nimg->next;
119 if (!nimg && (nimg = (struct NImgList *)AllocVecPooled(data->Pool, sizeof(struct NImgList)+nameLen)) != NULL)
120 { nimg->ImgName = (char *) nimg;
121 nimg->ImgName = &nimg->ImgName[sizeof(struct NImgList)];
122 strlcpy(nimg->ImgName, ImgName, nameLen);
123 nimg->NImgObj = NULL;
124 nimg->width = -1;
125 nimg->height = -1;
126 nimg->dx = 0;
127 nimg->dy = 0;
128 nimg->next = data->NImage.next;
129 data->NImage.next = nimg;
131 if (nimg && !nimg->NImgObj && data->adding_member && (nimg->width != -1000))
132 { if ((data->adding_member == 1) && !data->NList_Quiet && !data->NList_Disabled && data->SETUP && data->SHOW && DoMethod(data->NL_Group,MUIM_Group_InitChange))
133 data->adding_member = 2;
134 if (data->adding_member >= 2)
136 nimg->NImgObj = MUI_NewObject(MUIC_Image,
137 MUIA_FillArea,FALSE,
138 MUIA_Image_Spec,nimg->ImgName,
140 * MUIA_InputMode,MUIV_InputMode_Toggle,
141 * MUIA_Image_State, IDS_NORMAL,
142 * MUIA_Selected, FALSE,
143 * MUIA_Image_FontMatch, TRUE,
144 * MUIA_Font, Topaz_8,
146 TAG_DONE);
147 if (nimg->NImgObj)
149 /*D(bug("%lx|OM_ADDMEMBER,nimg->NImgObj %ld\n",obj,data->adding_member));*/
150 DoMethod(data->NL_Group,OM_ADDMEMBER,nimg->NImgObj);
151 set(nimg->NImgObj, MUIA_Disabled, FALSE);
152 if (data->SHOW)
154 nimg->width = _defwidth(nimg->NImgObj);
155 nimg->height = _defheight(nimg->NImgObj);
157 else
158 data->do_images = TRUE;
160 else
161 { nimg->width = -1000;
162 nimg->height = 2;
165 else
166 data->do_images = TRUE;
168 return (nimg);
172 void DeleteNImages(struct NLData *data)
174 struct NImgList *nimg = data->NImage.next;
176 while (nimg)
178 data->NImage.next = nimg->next;
179 FreeVecPooled(data->Pool, nimg);
180 nimg = data->NImage.next;
185 struct NImgList *GetNImage2(struct NLData *data,APTR imgobj)
187 struct NImgList *nimg2 = data->NImage2;
188 while (nimg2 && (nimg2->NImgObj != imgobj) && (nimg2->ImgName != imgobj))
189 nimg2 = nimg2->next;
190 if (!nimg2 && (nimg2 = (struct NImgList *)AllocVecPooled(data->Pool, sizeof(struct NImgList))) != NULL)
191 { nimg2->NImgObj = NULL;
192 nimg2->width = -1000;
193 nimg2->height = 2;
194 nimg2->dx = 0;
195 nimg2->dy = 0;
196 nimg2->ImgName = imgobj;
197 nimg2->next = data->NImage2;
198 data->NImage2 = nimg2;
200 if (nimg2 && nimg2->ImgName && !nimg2->NImgObj && (nimg2->width == -1000) && data->adding_member)
202 if(xget((Object *)nimg2->ImgName, MUIA_Parent))
205 * D(bug("%lx|GetNImage2 %lx already attached !\n",obj,nimg2->ImgName));
208 else
209 { if ((data->adding_member == 1) && !data->NList_Quiet && !data->NList_Disabled && data->SETUP && data->SHOW && DoMethod(data->NL_Group,MUIM_Group_InitChange))
210 data->adding_member = 2;
211 if (data->adding_member >= 2)
212 { nimg2->NImgObj = (APTR) nimg2->ImgName;
213 nimg2->ImgName = NULL;
214 /*D(bug("%lx|OM_ADDMEMBER,nimg2->NImgObj %ld\n",obj,data->adding_member));*/
215 DoMethod(data->NL_Group,OM_ADDMEMBER,nimg2->NImgObj);
216 set(nimg2->NImgObj, MUIA_Disabled, FALSE);
218 if (data->SHOW)
219 { nimg2->width = _defwidth(nimg2->NImgObj);
220 nimg2->height = _defheight(nimg2->NImgObj);
222 else
223 { nimg2->width = -1;
224 nimg2->height = -1;
225 data->do_images = TRUE;
228 else
229 data->do_images = TRUE;
232 return (nimg2);
236 void DeleteNImages2(struct NLData *data)
238 struct NImgList *nimg2 = data->NImage2;
240 while (nimg2)
242 data->NImage2 = nimg2->next;
243 if (nimg2->ImgName && !nimg2->NImgObj)
244 MUI_DisposeObject((APTR) nimg2->ImgName);
245 FreeVecPooled(data->Pool, nimg2);
246 nimg2 = data->NImage2;
251 void GetNImage_Sizes(struct NLData *data)
253 if (data->SHOW)
255 struct NImgList *nimg = &data->NImage;
256 struct NImgList *nimg2 = data->NImage2;
258 while (nimg)
260 if (nimg->NImgObj)
262 nimg->width = _defwidth(nimg->NImgObj);
263 nimg->height = _defheight(nimg->NImgObj);
264 if (data->MinImageHeight < _minheight(nimg->NImgObj))
266 if (_minheight(nimg->NImgObj) > 20)
268 if (data->MinImageHeight < 20)
269 data->MinImageHeight = 20;
271 else
272 data->MinImageHeight = _minheight(nimg->NImgObj);
274 _left(nimg->NImgObj) = _left(data->NL_Group);
275 _top(nimg->NImgObj) = _top(data->NL_Group);
277 nimg = nimg->next;
280 while (nimg2)
282 if (nimg2->NImgObj && (nimg2->width != -1000))
284 nimg2->width = _defwidth(nimg2->NImgObj);
285 nimg2->height = _defheight(nimg2->NImgObj);
286 if (data->MinImageHeight < _minheight(nimg2->NImgObj))
288 if (_minheight(nimg2->NImgObj) > 30)
290 if (data->MinImageHeight < 30)
291 data->MinImageHeight = 30;
293 else
294 data->MinImageHeight = _minheight(nimg2->NImgObj);
296 _left(nimg2->NImgObj) = _left(data->NL_Group);
297 _top(nimg2->NImgObj) = _top(data->NL_Group);
299 nimg2 = nimg2->next;
302 else
303 data->do_images = TRUE;
307 void GetNImage_End(struct NLData *data)
309 if (data->adding_member == 2)
311 data->adding_member = 0;
312 /*D(bug("%lx|GNIE Group_ExitChange\n",obj));*/
313 data->nodraw++;
314 DoMethod(data->NL_Group,MUIM_Group_ExitChange);
315 data->nodraw--;
316 GetNImage_Sizes(data);
318 data->adding_member = 0;
322 void GetImages(struct NLData *data)
324 if (data->SHOW && data->do_images)
326 struct NImgList *nimg = &data->NImage;
327 struct NImgList *nimg2 = data->NImage2;
329 if (data->adding_member != 2)
330 data->adding_member = 1;
332 while (nimg)
334 if (!nimg->NImgObj)
335 GetNImage(data,nimg->ImgName);
336 nimg = nimg->next;
339 while (nimg2)
341 if (nimg2->ImgName && !nimg2->NImgObj && (nimg2->width == -1000))
342 GetNImage2(data,nimg2->ImgName);
343 nimg2 = nimg2->next;
345 data->do_images = FALSE;
347 GetNImage_End(data);
355 static void disposeBitMap(struct NLData *data,struct BitMap *bitmap, LONG width, LONG height)
357 if (bitmap)
358 { WORD ktr;
359 for (ktr = 0; ktr < bitmap->Depth; ktr++)
360 { if (bitmap->Planes[ktr])
362 /*D(bug("FreeRaster(%lx) (dispBM_planes)\n",bitmap->Planes[ktr]));*/
363 FreeRaster(bitmap->Planes[ktr], width, height);
366 FreeVecPooled(data->Pool, bitmap);
371 static void disposeBitMapImage(struct NLData *data,struct BitMapImage *bmimg)
373 if (bmimg && data->SETUP)
375 WORD ktr;
377 for (ktr = 0; ktr < bmimg->imgbmp.Depth; ktr++)
379 if (bmimg->imgbmp.Planes[ktr])
381 /*D(bug("FreeRaster(%lx) (dispBMI_planes)\n",bmimg->imgbmp.Planes[ktr]));*/
382 FreeRaster(bmimg->imgbmp.Planes[ktr], bmimg->width, bmimg->height);
385 if (bmimg->mask)
387 /*D(bug("FreeRaster(%lx) (dispBMI_mask)\n",bmimg->mask));*/
388 FreeRaster(bmimg->mask, bmimg->width, bmimg->height);
390 if (bmimg->obtainpens)
392 ktr = 0;
393 while (bmimg->obtainpens[ktr] != -3)
395 if ((bmimg->obtainpens[ktr] >= 0) || (bmimg->obtainpens[ktr] < -3))
396 ReleasePen(_screen(data->this)->ViewPort.ColorMap, (ULONG) bmimg->obtainpens[ktr]);
397 ktr++;
399 FreeVecPooled(data->Pool, bmimg->obtainpens);
401 FreeVecPooled(data->Pool, bmimg);
406 IPTR NL_CreateImage2(struct NLData *data,Object *imgobj,ULONG flags)
408 struct BitMapImage *bmimg = NULL;
410 if (imgobj)
412 if((bmimg = AllocVecPooled(data->Pool ,sizeof(struct BitMapImage))) != NULL)
414 if (GetNImage2(data,imgobj))
416 bmimg->control = MUIA_Image_Spec;
417 bmimg->width = 0;
418 bmimg->height = 0;
419 bmimg->obtainpens = (APTR) imgobj;
420 if (flags != (ULONG)~0L)
421 nnset(imgobj,MUIA_FillArea,FALSE);
423 * nnset(imgobj,MUIA_Image_FontMatch,FALSE);
424 * nnset(imgobj,MUIA_Image_FontMatchHeight,FALSE);
425 * nnset(imgobj,MUIA_Image_FontMatchWidth,FALSE);
426 * nnset(imgobj,MUIA_Image_State,IDS_SELECTED);
427 * nnset(imgobj,MUIA_Selected,FALSE);
428 * nnset(imgobj,MUIA_InputMode,MUIV_InputMode_Toggle);
431 else
433 bmimg->control = 0L;
434 FreeVecPooled(data->Pool, bmimg);
435 bmimg = NULL;
438 if (!bmimg)
439 MUI_DisposeObject((APTR) imgobj);
441 return ((IPTR) bmimg);
445 IPTR NL_CreateImage(struct NLData *data,Object *imgobj,ULONG flags)
447 SIPTR CI_BM_Width = 0;
449 if (!imgobj)
450 return(0);
452 // check if the Bitmap_Width attribute doesn't exists
453 if((flags == (ULONG)~0L) || GetAttr(MUIA_Bitmap_Width, imgobj, (IPTR *)&CI_BM_Width) == FALSE)
454 return (NL_CreateImage2(data,imgobj,flags));
456 if (imgobj && data->SETUP)
458 LONG last_numpen,last_newnumpen;
459 struct BitMap *CI_BM_Bitmap = NULL;
460 struct BitMap *bm_src = NULL;
461 struct BitMapImage *bmimg = NULL;
462 WORD *obtainpens = NULL;
463 UBYTE newdepth = 0;
464 UBYTE *CI_BC_Body = NULL;
465 LONG CI_BC_Depth = 0;
466 LONG CI_BC_Compression = 0;
467 LONG CI_BC_Masking = 0;
468 LONG CI_BM_Height = 0;
469 UBYTE *CI_BM_MappingTable = NULL;
470 ULONG *CI_BM_SourceColors = NULL;
471 LONG CI_BM_Precision = 0;
472 LONG CI_BM_Transparent = 0;
474 CI_BM_Bitmap = (struct BitMap *)xget(imgobj, MUIA_Bitmap_Bitmap);
475 CI_BM_Width = xget(imgobj, MUIA_Bitmap_Width);
476 CI_BM_Height = xget(imgobj, MUIA_Bitmap_Height);
477 CI_BM_MappingTable = (UBYTE *)xget(imgobj, MUIA_Bitmap_MappingTable);
478 CI_BM_Transparent = xget(imgobj, MUIA_Bitmap_Transparent);
479 CI_BM_SourceColors = (ULONG *)xget(imgobj, MUIA_Bitmap_SourceColors);
480 CI_BM_Precision = xget(imgobj, MUIA_Bitmap_Precision);
482 if (!CI_BM_Bitmap)
484 CI_BC_Body = (UBYTE *)xget(imgobj, MUIA_Bodychunk_Body);
485 CI_BC_Depth = xget(imgobj, MUIA_Bodychunk_Depth);
486 CI_BC_Compression = xget(imgobj, MUIA_Bodychunk_Compression);
487 CI_BC_Masking = xget(imgobj, MUIA_Bodychunk_Masking);
489 if (CI_BC_Body)
491 if((bm_src = AllocVecPooled(data->Pool, sizeof(struct BitMap))) != NULL)
493 WORD ktr;
494 BOOL bit_map_failed = FALSE;
496 InitBitMap(bm_src,CI_BC_Depth,CI_BM_Width,CI_BM_Height);
498 for (ktr = 0; ktr < bm_src->Depth; ktr++)
500 if (!(bm_src->Planes[ktr] = (PLANEPTR) AllocRaster(CI_BM_Width,CI_BM_Height)))
501 bit_map_failed = TRUE;
503 if (bit_map_failed)
505 disposeBitMap(data,bm_src,CI_BM_Width,CI_BM_Height);
506 bm_src = NULL;
508 else
510 WORD cptb,cptr,cptd,offr;
511 WORD num = 0;
512 UBYTE val = 0;
513 UBYTE type = 0;
514 UBYTE *body = CI_BC_Body;
516 for (cptr = 0; cptr < bm_src->Rows; cptr++)
518 offr = cptr * bm_src->BytesPerRow;
519 for (cptd = 0; cptd < bm_src->Depth; cptd++)
521 for (cptb = 0; cptb < bm_src->BytesPerRow; cptb++)
523 if (CI_BC_Compression == cmpByteRun1)
525 if (num > 0)
527 if (type == 0)
528 bm_src->Planes[cptd][offr+cptb] = val;
529 else
530 bm_src->Planes[cptd][offr+cptb] = *body;
531 num--;
533 else
535 while (*body == 128)
536 body++;
537 if (*body < 128)
539 num = (WORD) *body; type = 1; body++;
540 bm_src->Planes[cptd][offr+cptb] = *body;
542 else
544 num = 256 - ((WORD) *body); type = 0; body++; val = *body;
545 bm_src->Planes[cptd][offr+cptb] = val;
549 else
550 bm_src->Planes[cptd][offr+cptb] = *body;
551 body++;
554 if (CI_BC_Masking == mskHasMask)
556 for (cptb = 0; cptb < bm_src->BytesPerRow; cptb++)
558 if (CI_BC_Compression == cmpByteRun1)
560 if (num > 0)
561 num--;
562 else
564 while (*body == 128)
565 body++;
566 if (*body < 128)
568 num = (WORD) *body;
569 type = 1;
570 body++;
572 else
574 num = 256 - ((WORD) *body);
575 type = 0;
576 body++;
577 val = *body;
581 body++;
588 else
589 bm_src = NULL;
591 else
592 bm_src = CI_BM_Bitmap;
594 if (bm_src != NULL)
596 UBYTE mypen,bit1,bit2;
597 WORD cptb,cptr,cptd,offr,offr1,cptpen;
599 last_numpen = (1 << bm_src->Depth);
600 last_newnumpen = 0;
601 newdepth = bm_src->Depth;
603 if (CI_BM_MappingTable != NULL)
605 LONG num;
607 for (num = 0;num < last_numpen;num++)
609 if (last_newnumpen < CI_BM_MappingTable[num])
610 last_newnumpen = CI_BM_MappingTable[num];
612 newdepth = 0;
613 while (last_newnumpen)
615 newdepth++;
616 last_newnumpen = last_newnumpen >> 1;
619 else if (CI_BM_SourceColors != NULL)
621 ULONG *mycolor;
623 obtainpens = AllocVecPooled(data->Pool, (last_numpen+1)*sizeof(*obtainpens));
624 if (obtainpens != NULL)
626 obtainpens[last_numpen] = -3;
627 for (cptpen = 0; cptpen < last_numpen; cptpen++)
628 obtainpens[cptpen] = -1;
629 for (cptr = 0; cptr < bm_src->Rows; cptr++)
631 offr = cptr * bm_src->BytesPerRow;
632 for (cptb = 0; cptb < bm_src->BytesPerRow; cptb++)
634 bit1 = 0x80;
635 while (bit1)
636 { /* get the source dot pen number */
637 mypen = 0;
638 bit2 = 0x01;
639 for (cptd = 0; cptd < bm_src->Depth; cptd++)
641 if (bm_src->Planes[cptd][offr+cptb] & bit1)
642 mypen |= bit2;
644 bit2 = bit2 << 1;
646 /* map the pen number */
647 if (mypen == CI_BM_Transparent)
648 obtainpens[mypen] = -2;
649 else if (obtainpens[mypen] == -1)
651 mycolor = &CI_BM_SourceColors[mypen*3];
653 obtainpens[mypen] = (WORD) ObtainBestPen(_screen(data->this)->ViewPort.ColorMap,
654 mycolor[0],mycolor[1],mycolor[2],
655 OBP_Precision, CI_BM_Precision,
656 TAG_END);
657 if (obtainpens[mypen] == -1)
659 obtainpens[mypen] = (WORD) ObtainBestPen(_screen(data->this)->ViewPort.ColorMap,
660 mycolor[0],mycolor[1],mycolor[2],
661 OBP_Precision, PRECISION_GUI,
662 TAG_END);
664 if(last_newnumpen < obtainpens[mypen])
665 last_newnumpen = obtainpens[mypen];
667 bit1 = bit1 >> 1;
671 newdepth = 0;
672 while (last_newnumpen)
674 newdepth++;
675 last_newnumpen = last_newnumpen >> 1;
679 if (newdepth > 8)
680 newdepth = 8;
681 last_newnumpen = 1 << newdepth;
683 if ((newdepth > 0) && (bmimg = AllocVecPooled(data->Pool, sizeof(struct BitMapImage))) != NULL)
685 WORD ktr;
686 BOOL bmimg_failed = FALSE;
688 InitBitMap(&(bmimg->imgbmp),newdepth,CI_BM_Width,CI_BM_Height);
689 bmimg->control = MUIM_NList_CreateImage;
690 bmimg->width = CI_BM_Width;
691 bmimg->height = CI_BM_Height;
692 bmimg->obtainpens = obtainpens;
693 for (ktr = 0; ktr < bmimg->imgbmp.Depth; ktr++)
695 if (!(bmimg->imgbmp.Planes[ktr] = (PLANEPTR) AllocRaster(CI_BM_Width,CI_BM_Height)))
696 bmimg_failed = TRUE;
698 if (!(bmimg->mask = (PLANEPTR) AllocRaster(CI_BM_Width,CI_BM_Height)))
699 bmimg_failed = TRUE;
700 if (bmimg_failed)
702 disposeBitMapImage(data,bmimg);
703 bmimg = NULL;
705 else
708 int kprintf( const char *, ... );
709 kprintf( "SrcBitMap Width %ld Height %ld Depth %ld BytesPerRow %ld Rows %ld Depth %ld.\n",
710 GetBitMapAttr( bm_src, BMA_WIDTH ),
711 GetBitMapAttr( bm_src, BMA_HEIGHT ),
712 GetBitMapAttr( bm_src, BMA_DEPTH ),
713 bm_src->BytesPerRow,
714 bm_src->Rows,
715 bm_src->Depth );
716 kprintf( "BytesPerRow %ld Rows %ld.\n", bmimg->imgbmp.BytesPerRow, bmimg->imgbmp.Rows );
718 for (cptr = 0; cptr < bmimg->imgbmp.Rows; cptr++)
720 offr = cptr * bmimg->imgbmp.BytesPerRow;
721 offr1 = cptr * bm_src->BytesPerRow;
722 for (cptb = 0; cptb < bmimg->imgbmp.BytesPerRow; cptb++)
724 bit1 = 0x80;
725 while (bit1)
726 { /* get the source dot pen number */
727 mypen = 0;
728 bit2 = 0x01;
729 for (cptd = 0; cptd < bm_src->Depth; cptd++)
731 if (bm_src->Planes[cptd][offr1+cptb] & bit1) // here was bug!!!
732 mypen |= bit2;
733 bit2 = bit2 << 1;
735 /* map the pen number */
736 if (mypen == CI_BM_Transparent)
738 bmimg->mask[offr+cptb] &= ~bit1;
739 mypen = 0;
741 else
743 bmimg->mask[offr+cptb] |= bit1;
744 if (CI_BM_MappingTable)
745 mypen = (UBYTE) CI_BM_MappingTable[mypen];
746 else if (CI_BM_SourceColors && obtainpens && ((obtainpens[mypen] >= 0) || (obtainpens[mypen] < -3)))
747 mypen = (UBYTE) obtainpens[mypen];
749 /* set the dest dot pen number */
750 bit2 = 0x01;
751 for (cptd = 0; cptd < bmimg->imgbmp.Depth; cptd++)
753 if (mypen & bit2)
754 bmimg->imgbmp.Planes[cptd][offr+cptb] |= bit1;
755 else
756 bmimg->imgbmp.Planes[cptd][offr+cptb] &= ~bit1;
757 bit2 = bit2 << 1;
759 bit1 = bit1 >> 1;
767 if (!bmimg && obtainpens)
768 FreeVecPooled(data->Pool, obtainpens);
770 if (!CI_BM_Bitmap)
772 disposeBitMap(data,bm_src,CI_BM_Width,CI_BM_Height);
773 bm_src = NULL;
775 if (bmimg && (data->MinImageHeight < bmimg->height) && !flags)
776 data->MinImageHeight = bmimg->height;
778 return ((IPTR) bmimg);
781 return (0);
785 ULONG NL_DeleteImage(struct NLData *data,APTR listimg)
787 struct BitMapImage *bmimg = (struct BitMapImage *) listimg;
789 if (bmimg && (bmimg->control == MUIM_NList_CreateImage))
791 bmimg->control = 0L;
792 disposeBitMapImage(data,bmimg);
794 else if (bmimg && (bmimg->control == MUIA_Image_Spec))
796 APTR imgobj = (APTR) bmimg->obtainpens;
797 struct NImgList *nimg2 = data->NImage2,*nimgprec = NULL;
799 while (nimg2 && (nimg2->NImgObj != imgobj) && (nimg2->ImgName != imgobj))
801 nimgprec = nimg2;
802 nimg2 = nimg2->next;
804 bmimg->control = 0L;
805 if (nimg2)
807 if (nimgprec)
808 nimgprec->next = nimg2->next;
809 else
810 data->NImage2 = nimg2->next;
811 if (nimg2->NImgObj == imgobj)
813 Object *parent;
815 if((parent = (Object *)xget(imgobj, MUIA_Parent)) && (parent == data->NL_Group))
817 if (data->SETUP && DoMethod(data->NL_Group,MUIM_Group_InitChange))
819 DoMethod(data->NL_Group,OM_REMMEMBER,imgobj);
820 DoMethod(data->NL_Group,MUIM_Group_ExitChange);
822 else
823 DoMethod(data->NL_Group,OM_REMMEMBER,imgobj);
826 FreeVecPooled(data->Pool, nimg2);
828 FreeVecPooled(data->Pool, bmimg);
830 return (TRUE);
834 ULONG NL_CreateImages(struct NLData *data)
836 if (data->NList_UseImages && data->SETUP)
838 LONG pos = 0;
840 while (pos < data->LastImage)
842 if (data->NList_UseImages[pos].imgobj)
843 data->NList_UseImages[pos].bmimg = (struct BitMapImage *)
844 NL_CreateImage(data,data->NList_UseImages[pos].imgobj,data->NList_UseImages[pos].flags);
845 else
846 data->NList_UseImages[pos].bmimg = NULL;
847 pos++;
851 return(0);
855 ULONG NL_DeleteImages(struct NLData *data)
857 if (data->NList_UseImages)
859 LONG pos = 0;
861 while (pos < data->LastImage)
863 if (data->NList_UseImages[pos].bmimg)
864 NL_DeleteImage(data,(APTR) data->NList_UseImages[pos].bmimg);
865 data->NList_UseImages[pos].bmimg = NULL;
866 pos++;
870 return(0);
874 ULONG NL_UseImage(struct NLData *data,Object *imgobj,LONG imgnum,ULONG flags)
876 BOOL redraw = FALSE;
877 LONG retval = FALSE;
879 if ((imgnum >= 0) && (imgnum < 8192))
881 if (imgobj)
883 if (!data->NList_UseImages || (imgnum >= data->LastImage))
885 LONG last = imgnum + 8;
886 struct UseImage *useimages = (struct UseImage *)AllocVecPooled(data->Pool, (last+1)*sizeof(struct UseImage));
888 if (useimages)
890 LONG pos = 0;
892 while (pos < data->LastImage)
893 { useimages[pos].bmimg = data->NList_UseImages[pos].bmimg;
894 useimages[pos].imgobj = data->NList_UseImages[pos].imgobj;
895 useimages[pos].flags = data->NList_UseImages[pos].flags;
896 pos++;
899 while (pos < last)
901 useimages[pos].bmimg = 0;
902 useimages[pos].imgobj = NULL;
903 useimages[pos].flags = 0;
904 pos++;
906 if (data->NList_UseImages)
907 FreeVecPooled(data->Pool, data->NList_UseImages);
908 data->NList_UseImages = useimages;
909 data->LastImage = last;
911 else if (!data->NList_UseImages)
912 data->LastImage = 0;
914 if (imgnum < data->LastImage)
916 if (data->NList_UseImages[imgnum].bmimg)
918 NL_DeleteImage(data,(APTR) data->NList_UseImages[imgnum].bmimg);
919 redraw = TRUE;
922 data->NList_UseImages[imgnum].bmimg = NULL;
923 data->NList_UseImages[imgnum].imgobj = imgobj;
924 data->NList_UseImages[imgnum].flags = flags;
925 if (data->SETUP)
927 data->NList_UseImages[imgnum].bmimg = (struct BitMapImage *)
928 NL_CreateImage(data,data->NList_UseImages[imgnum].imgobj,data->NList_UseImages[imgnum].flags);
929 redraw = TRUE;
931 retval = TRUE;
934 else if (imgnum < data->LastImage)
936 if (data->NList_UseImages[imgnum].bmimg)
938 NL_DeleteImage(data,(APTR) data->NList_UseImages[imgnum].bmimg);
939 redraw = TRUE;
941 data->NList_UseImages[imgnum].bmimg = NULL;
942 data->NList_UseImages[imgnum].imgobj = NULL;
943 data->NList_UseImages[imgnum].flags = 0;
944 retval = TRUE;
947 else if (!imgobj && (imgnum == MUIV_NList_UseImage_All) && data->NList_UseImages)
949 LONG pos = 0;
951 while (pos < data->LastImage)
953 if (data->NList_UseImages[pos].bmimg)
955 NL_DeleteImage(data,(APTR) data->NList_UseImages[pos].bmimg);
956 redraw = TRUE;
958 data->NList_UseImages[pos].bmimg = NULL;
959 data->NList_UseImages[pos].imgobj = NULL;
960 data->NList_UseImages[pos].flags = 0;
961 pos++;
963 retval = TRUE;
965 if (redraw)
967 data->do_draw_all = data->do_draw_title = data->do_draw = TRUE;
968 data->do_parse = data->do_setcols = data->do_updatesb = data->do_wwrap = TRUE;
970 return ((ULONG)retval);
974 IPTR mNL_CreateImage(struct IClass *cl,Object *obj,struct MUIP_NList_CreateImage *msg)
976 struct NLData *data = INST_DATA(cl,obj);
977 /*DoSuperMethodA(cl,obj,(Msg) msg);*/
978 return (NL_CreateImage(data,msg->obj,msg->flags));
982 IPTR mNL_DeleteImage(struct IClass *cl,Object *obj,struct MUIP_NList_DeleteImage *msg)
984 struct NLData *data = INST_DATA(cl,obj);
985 /*DoSuperMethodA(cl,obj,(Msg) msg);*/
986 return (NL_DeleteImage(data,msg->listimg));
990 IPTR mNL_UseImage(struct IClass *cl,Object *obj,struct MUIP_NList_UseImage *msg)
992 struct NLData *data = INST_DATA(cl,obj);
993 /*DoSuperMethodA(cl,obj,(Msg) msg);*/
994 return (NL_UseImage(data,msg->obj,msg->imgnum,msg->flags));