-
Notifications
You must be signed in to change notification settings - Fork 0
/
DMP.c
1168 lines (1014 loc) · 35.4 KB
/
DMP.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "debug.h"
#define CATCOMP_NUMBERS
#define CATCOMP_BLOCK
#define CATCOMP_CODE
struct LocaleInfo li;
#include "DMP_global.h"
#include "DMP.h"
#include "xml.h" // list of pointers
const char *version = VERSTAG;
STRPTR textbuf, // for localized messages
dmp_name, // DMP executable name
pointers_path; // DMP path + 'POINTERS' drawer
struct List *listbrowser_list;
struct WBStartup *WBenchMsg = NULL;
#if defined(DEBUG)
uint16 count=1; // only for debuging purpouses
#endif
//DMP_cli.c
extern void ListDMP_CLI(STRPTR, LONG);
extern void DMP_from_CLI(void);
extern void CenterMousePointer(void);
int main(int argc, char **argv)
{
textbuf = IExec->AllocVecTags(DMP_MAX_TXTB, TAG_DONE);
if(argc == 0)
{
WBenchMsg = (struct WBStartup *)argv;
}
DBUG("WBenchMsg=0x%08lx\n",WBenchMsg);
if( OpenLibs((uint32)WBenchMsg) )
{
pointers_path = IExec->AllocVecTags(DMP_MAX_PREF, TAG_DONE);
dmp_name = IExec->AllocVecTags(DMP_MAX_FNAME, TAG_DONE);
if(WBenchMsg)
{// Running from WORKBENCH
IDOS->NameFromLock(WBenchMsg->sm_ArgList->wa_Lock, pointers_path, DMP_MAX_PREF);
IDOS->AddPart(pointers_path, "POINTERS", DMP_MAX_PREF);
IUtility->Strlcpy(dmp_name, WBenchMsg->sm_ArgList->wa_Name, DMP_MAX_FNAME);
DBUG("'%s' started from WB\n",dmp_name);
DMP_from_WB();
}
else
{// Running from SHELL/CLI
IDOS->NameFromLock(IDOS->GetProgramDir(), pointers_path, DMP_MAX_PREF);
IDOS->AddPart(pointers_path, "POINTERS", DMP_MAX_PREF);
DBUG("'%s' started from CLI\n",argv[0]);
DMP_from_CLI();
}
IExec->FreeVec(pointers_path);
IExec->FreeVec(dmp_name);
}
CloseLibs();
IExec->FreeVec(textbuf);
return(RETURN_OK);
}
/* Open required (mode WB/CLI) libs/classes */
BOOL OpenLibs(uint32 gui_mode)
{
li.li_Catalog = NULL;
if( (LocaleBase = IExec->OpenLibrary("locale.library", 52)) &&
(ILocale = (struct LocaleIFace *)IExec->GetInterface(LocaleBase, "main", 1, NULL)) )
{
li.li_ILocale = ILocale;
li.li_Catalog = ILocale->OpenCatalog(NULL, "defmousepointers.catalog",
OC_BuiltInLanguage, "english",
OC_PreferExternal, TRUE,
TAG_END);
}
else
{
IDOS->PutErrStr("Failed to use catalog system. Using built-in strings.\n");
}
UtilityBase = IExec->OpenLibrary("utility.library", 52);
if(!UtilityBase)
{
IDOS->Printf(GetString(&li,MSG_ERROR_LIB),"utility.library",52);
return FALSE;
}
IUtility = (struct UtilityIFace *)IExec->GetInterface(UtilityBase, "main", 1, NULL);
if(!IUtility) {
IDOS->Printf(GetString(&li,MSG_ERROR_OPEN),"UtilityIFace");
return FALSE;
}
IntuitionBase = IExec->OpenLibrary("intuition.library", 52);
if(!IntuitionBase)
{
IDOS->Printf( GetString(&li,MSG_ERROR_LIB),"intuition.library",52 );
return FALSE;
}
IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase, "main", 1, NULL);
if(!IIntuition)
{
IDOS->Printf(GetString(&li,MSG_ERROR_OPEN),"IntuitionIFace");
return FALSE;
}
if(gui_mode)
{
IconBase = IExec->OpenLibrary("icon.library", 52);
if(!IconBase)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_LIB),"icon.library",52);
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
IIcon = (struct IconIFace *)IExec->GetInterface(IconBase, "main", 1, NULL);
if(!IIcon)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_OPEN),"IconIFace");
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
/*
DataTypesBase = IExec->OpenLibrary("datatypes.library", 52);
if(!DataTypesBase)
{
IDOS->Printf( GetString(&li,MSG_ERROR_LIB),"datatypes.library",52 );
return FALSE;
}
IDataTypes = (struct DataTypesIFace *)IExec->GetInterface(DataTypesBase, "main", 1, NULL);
if(!IDataTypes)
{
IDOS->Printf( GetString(&li,MSG_ERROR_OPEN),"DatatypesIFace" );
return FALSE;
}
*/
ButtonBase = IIntuition->OpenClass("gadgets/button.gadget", 52, &ButtonClass);
//BitMapBase = IIntuition->OpenClass("images/bitmap.image", 52, &BitMapClass);
//LabelBase = IIntuition->OpenClass("images/label.image", 52, &LabelClass);
LayoutBase = IIntuition->OpenClass("gadgets/layout.gadget", 52, &LayoutClass);
WindowBase = IIntuition->OpenClass("window.class", 52, &WindowClass);
RequesterBase = IIntuition->OpenClass("requester.class", 52, &RequesterClass);
if(!ButtonBase||!LayoutBase||!WindowBase||!RequesterBase)
{
DoMessage( (STRPTR)GetString(&li, MSG_ERROR_NOGUI), REQIMAGE_ERROR, NULL );
return FALSE;
}
ListBrowserBase = (struct Library *)IIntuition->OpenClass("gadgets/listbrowser.gadget", 52, &ListBrowserClass);
if(!ListBrowserBase)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_LIB),"listbrowser.gadget",52);
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
IListBrowser = (struct ListBrowserIFace *)IExec->GetInterface( (struct Library*)ListBrowserBase, "main", 1, NULL );
if(!IListBrowser)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_OPEN),"ListBrowserIFace");
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
ChooserBase = (struct Library *)IIntuition->OpenClass("gadgets/chooser.gadget", 52, &ChooserClass);
if(!ChooserBase)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_LIB),"chooser.gadget",52);
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
IChooser = (struct ChooserIFace *)IExec->GetInterface( (struct Library *)ChooserBase, "main", 1, NULL);
if(!IChooser)
{
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_OPEN),"ChooserIFace");
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
return FALSE;
}
}
return TRUE;
}
void CloseLibs(void)
{
//IIntuition->CloseClass(LabelBase);
//IIntuition->CloseClass(BitMapBase);
IIntuition->CloseClass(RequesterBase);
IIntuition->CloseClass(ButtonBase);
IIntuition->CloseClass(LayoutBase);
IIntuition->CloseClass(WindowBase);
IExec->DropInterface( (struct Interface *)IChooser );
IIntuition->CloseClass( (struct ClassLibrary *)ChooserBase );
IExec->DropInterface( (struct Interface *)IListBrowser );
IIntuition->CloseClass( (struct ClassLibrary *)ListBrowserBase );
if(ILocale)
{
ILocale->CloseCatalog(li.li_Catalog);
IExec->DropInterface( (struct Interface *)ILocale );
}
IExec->CloseLibrary( (struct Library *)LocaleBase );
//IExec->DropInterface( (struct Interface *)IDataTypes );
//IExec->CloseLibrary(DataTypesBase);
IExec->DropInterface( (struct Interface *)IIcon );
IExec->CloseLibrary(IconBase);
IExec->DropInterface( (struct Interface *)IUtility );
IExec->CloseLibrary(UtilityBase);
IExec->DropInterface( (struct Interface *)IIntuition );
IExec->CloseLibrary(IntuitionBase);
}
/* DefMousePointer is in WB mode */
void DMP_from_WB(void)
{
STRPTR TTarg = NULL;
int32 pointers_tot;
struct DiskObject *dobj = NULL;
BPTR file = 0;
struct List *chooser_list = NULL;
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, "PROGDIR:%s",WBenchMsg->sm_ArgList->wa_Name);
DBUG("DMP_from_WB() '%s'\n",textbuf);
dobj = IIcon->GetDiskObjectNew(textbuf); // get disk object
DBUG("dobj=0x%08lx\n",dobj);
if(dobj)
{
STRPTR theme = IExec->AllocVecTags(DMP_MAX_THEME, AVT_ClearWithValue,NULL, TAG_DONE);
// Get theme name and create fullpath
IUtility->Strlcpy(textbuf, pointers_path, DMP_MAX_TXTB);
IDOS->AddPart(textbuf, PREFS_FILENAME, DMP_MAX_TXTB);
DBUG("'%s'\n",textbuf);
if( (file=IDOS->Open(textbuf, MODE_OLDFILE)) )
{
IDOS->FGets(file, theme, DMP_MAX_THEME);
IDOS->Close(file);
}
TTarg = IIcon->FindToolType(dobj->do_ToolTypes, "WBSTARTUP"); // check for "WBSTARTUP" tooltype
if(TTarg)
{
if(theme[0] != '\0')
{
IUtility->Strlcpy(textbuf, pointers_path, DMP_MAX_TXTB);
IDOS->AddPart(textbuf, theme, DMP_MAX_TXTB); // theme drawer fullpath
ListDMP_CLI(textbuf, 0); // copy pointers to ENV:Sys/
}
CenterMousePointer();
}
else
{
chooser_list = (struct List *)IExec->AllocSysObject(ASOT_LIST, NULL);
listbrowser_list = (struct List *)IExec->AllocSysObject(ASOT_LIST, NULL);
// Get themes/drawers list and show in chooser_list
if( make_chooser_list(chooser_list) )
{
struct Node *node = getSavedThemeNode(chooser_list, theme);
DBUG("0x%08lx '%s'\n",node,theme);
pointers_tot = ListDMP_WB(theme); // get theme's/drawer's mouse pointers list
DMPwindow(pointers_tot, chooser_list, node); // show GUI and process events
free_chooser_list(chooser_list);
}
else
{
DoMessage( (STRPTR)GetString(&li, MSG_WARN_NO_POINTERTHEMES), REQIMAGE_ERROR, NULL );
}
IListBrowser->FreeListBrowserList(listbrowser_list);
IExec->FreeSysObject(ASOT_LIST, listbrowser_list);
IExec->FreeSysObject(ASOT_LIST, chooser_list);
}
IExec->FreeVec(theme);
IIcon->FreeDiskObject(dobj);
}
}
//#define IMG_W 42
//#define IMG_H 42
int32 ListDMP_WB(STRPTR theme_name)
{
STRPTR theme_drawer_name = IExec->AllocVecTags(DMP_MAX_FILE, TAG_DONE),
pointer_fullname = IExec->AllocVecTags(DMP_MAX_SRC, TAG_DONE), // fullpath + pointer name
pattern_ms = IExec->AllocVecTags(DMP_MAX_PATTERN, TAG_DONE);
int32 success = 0;
struct Node *n = NULL;
struct DiskObject *icon = NULL;
DBUG("ListDMP_WB(%s)\n",theme_name);
IUtility->Strlcpy(theme_drawer_name, pointers_path, DMP_MAX_FILE);
IDOS->AddPart(theme_drawer_name, theme_name, DMP_MAX_FILE);
IDOS->ParsePatternNoCase("def_#?pointer.info", pattern_ms, DMP_MAX_PATTERN);
APTR context = IDOS->ObtainDirContextTags(EX_StringNameInput, theme_drawer_name,
EX_DataFields, (EXF_NAME|EXF_TYPE),
EX_MatchString, pattern_ms,
TAG_END);
if(context)
{
struct ExamineData *dat;
// Re-read theme drawer, but first "clean" listbrowser_list
IListBrowser->FreeListBrowserList(listbrowser_list);
while( (dat=IDOS->ExamineDir(context)) )
{
if( EXD_IS_FILE(dat) )
{
IUtility->Strlcpy(pointer_fullname, theme_drawer_name, DMP_MAX_SRC);
IDOS->AddPart(pointer_fullname, dat->Name, DMP_MAX_SRC);
pointer_fullname[IUtility->Strlen(pointer_fullname) - 5] = '\0'; // remove '.info'
//DBUG("'%s'\n",pointer_fullname);
if( !(icon=IIcon->GetIconTags(pointer_fullname,
ICONGETA_FailIfUnavailable, TRUE,
ICONGETA_UseFriendBitMap, TRUE,
//ICONGETA_Width,IMG_W,
//ICONGETA_Height,IMG_H,
//ICONGETA_ForceScaling, TRUE,
//ICONGETA_AllowUpscaling, TRUE,
TAG_END)) ) break;
if( (n=IListBrowser->AllocListBrowserNode(TOT_COL,//TOTALCOLUMNS,
LBNA_Column,COL_IMG,
LBNCA_Image,icon->do_Gadget.GadgetRender,
//LBNCA_HorizJustify,LCJ_CENTER,
LBNA_Column,COL_TXT,
LBNCA_CopyText,TRUE, LBNCA_Text,dat->Name,
//LBNCA_HorizJustify,LCJ_CENTER,
TAG_DONE)) )
{
IExec->AddTail(listbrowser_list, n);
++success;
//DBUG("%2ld)MOUSEPOINTER='%s' [0x%08lx]\n",success,dat->Name,n);
}
}
}
if( ERROR_NO_MORE_ENTRIES != IDOS->IoErr() )
{
IDOS->Fault(IDOS->IoErr(), GetString(&li,MSG_ERROR_POINTER_DATA), textbuf, DMP_MAX_TXTB);
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
}
}
else
{
IDOS->Fault(IDOS->IoErr(), GetString(&li,MSG_ERROR_NOCONTEXT), textbuf, DMP_MAX_TXTB);
DoMessage(textbuf, REQIMAGE_ERROR, NULL);
}
IDOS->ReleaseDirContext(context);
IExec->FreeVec(pattern_ms);
IExec->FreeVec(theme_drawer_name);
IExec->FreeVec(pointer_fullname);
return(success);
}
void DMPwindow(int32 pointers_tot, struct List *list, struct Node *sel_nod)
{
Object *win_obj = NULL, *Objects[LAST_NUM];
struct Window *pwindow = NULL;
struct ColumnInfo *columninfo;
struct DiskObject *iconify = NULL;
struct MsgPort *wAppPort = NULL;
struct { int32 value; }va = {pointers_tot}; // used in OBJ(OBJ_CHOOSER_INFO): MSG_GUI_CHOOSER_INFO has '%ld' as argument
//DBUG("pointers_tot=%ld ('%s')\n",pointers_tot,dmp_name);
//DBUG("sel_nod = 0x%08lx\n",sel_nod);
// Reset icon X/Y positions so it iconifies properly on Workbench
if( (iconify=IIcon->GetIconTags(dmp_name, ICONGETA_FailIfUnavailable,FALSE, TAG_END)) )
{
iconify->do_CurrentX = NO_ICON_POSITION;
iconify->do_CurrentY = NO_ICON_POSITION;
}
wAppPort = IExec->AllocSysObjectTags(ASOT_PORT, TAG_END);
columninfo = IListBrowser->AllocLBColumnInfo(TOT_COL,
LBCIA_Column,COL_IMG,
LBCIA_Title,GetString(&li, MSG_GUI_LB_IMAGE),
LBCIA_Column,COL_TXT,
LBCIA_Title,GetString(&li, MSG_GUI_LB_NAME),
LBCIA_AutoSort,TRUE, LBCIA_Sortable,TRUE,
TAG_DONE);
win_obj = IIntuition->NewObject(WindowClass, NULL, //"window.class",
WA_ScreenTitle, VERS" "DATE,
WA_Title, "DefMousePointers",
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_SizeGadget, TRUE,
WA_DepthGadget, TRUE,
WA_Activate, TRUE,
WA_InnerWidth, 300,
//WA_InnerHeight, 460,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_IconifyGadget, TRUE, // iconify support
WINDOW_AppPort, wAppPort, // iconify support
WINDOW_Icon, iconify, // iconify support
WINDOW_Layout, IIntuition->NewObject(LayoutClass, NULL, //"layout.gadget",
LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL, //"layout.gadget",
LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_HorizAlignment, LALIGN_CENTER,
LAYOUT_BevelStyle, BVS_GROUP,
LAYOUT_Label, GetString(&li, MSG_GUI_GROUP_CHOOSER),
LAYOUT_AddChild, OBJ(OID_CHOOSER) = IIntuition->NewObject(ChooserClass, NULL, //"chooser.gadget",
GA_ID, OID_CHOOSER,
GA_RelVerify, TRUE,
GA_Underscore, 0,
CHOOSER_Labels, list, // themes/drawers list
//CHOOSER_Selected, 0,
CHOOSER_SelectedNode, sel_nod,
CHOOSER_MaxLabels, 32,
TAG_DONE),
CHILD_WeightedWidth, 0,
LAYOUT_AddChild, OBJ(OID_CHOOSER_INFO) = IIntuition->NewObject(ButtonClass, NULL,
GA_ReadOnly, TRUE,
GA_Text, GetString(&li,MSG_GUI_CHOOSER_INFO),
BUTTON_VarArgs, &va,
TAG_DONE),
TAG_DONE),
CHILD_WeightedHeight, 0,
LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL, //"layout.gadget",
LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_BevelStyle, BVS_GROUP,
LAYOUT_Label, GetString(&li, MSG_GUI_GROUP_LB),
LAYOUT_AddChild, OBJ(OID_LISTPTRS) = IIntuition->NewObject(ListBrowserClass, NULL, //"listbrowser.gadget",
GA_ID, OID_LISTPTRS,
//GA_RelVerify, TRUE,
GA_ReadOnly, TRUE,
LISTBROWSER_SortColumn, COL_TXT,
LISTBROWSER_AutoFit, TRUE,
LISTBROWSER_Labels, listbrowser_list,
LISTBROWSER_ColumnInfo, columninfo,
LISTBROWSER_ColumnTitles, TRUE,
LISTBROWSER_Selected, -1,
//LISTBROWSER_MinVisible, 5,
//LISTBROWSER_Striping, LBS_ROWS,
LISTBROWSER_HorizSeparators, TRUE,
//LISTBROWSER_VertSeparators, FALSE,
LISTBROWSER_Spacing, 4,
TAG_DONE),
CHILD_MinHeight, 300,
TAG_DONE),
LAYOUT_AddChild, IIntuition->NewObject(LayoutClass, NULL, //"layout.gadget",
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_AddChild, IIntuition->NewObject(ButtonClass, NULL, //"button.gadget",
GA_Text, GetString(&li, MSG_GUI_SAVE),
GA_ID, OID_SAVE,
GA_RelVerify, TRUE,
TAG_DONE),
LAYOUT_AddChild, IIntuition->NewObject(ButtonClass, NULL, //"button.gadget",
GA_Text, GetString(&li, MSG_GUI_USE),
GA_ID, OID_USE,
GA_RelVerify, TRUE,
TAG_DONE),
LAYOUT_AddChild, IIntuition->NewObject(ButtonClass, NULL, //"button.gadget",
GA_Text, GetString(&li, MSG_GUI_QUIT),
GA_ID, OID_QUIT,
GA_RelVerify, TRUE,
TAG_DONE),
TAG_DONE),
CHILD_WeightedHeight, 0,
TAG_DONE),
TAG_END);
if( (pwindow=(struct Window *)IIntuition->IDoMethod(win_obj, WM_OPEN, NULL)) )
{
BOOL done = TRUE;
char *res_string = NULL;
uint16 code = 0;
uint32 siggot = 0, result = WMHI_LASTMSG, res_node, res_value,
wsigmask = 0, prev_chooser;
IIntuition->GetAttr(CHOOSER_Selected, OBJ(OID_CHOOSER), &prev_chooser);
while(done)
{
IIntuition->GetAttr(WINDOW_SigMask, win_obj, &wsigmask);
siggot = IExec->Wait(wsigmask|SIGBREAKF_CTRL_C);
if(siggot & SIGBREAKF_CTRL_C)
{
done = FALSE;
break;
}
while( (result=IIntuition->IDoMethod(win_obj, WM_HANDLEINPUT, &code)) != WMHI_LASTMSG )
{
switch(result & WMHI_CLASSMASK)
{
case WMHI_CLOSEWINDOW:
done = FALSE;
break;
case WMHI_ICONIFY:
DBUG("WMHI_ICONIFY\n");
if( IIntuition->IDoMethod(win_obj, WM_ICONIFY) )
{
pwindow = NULL;
}
break;
case WMHI_UNICONIFY:
DBUG("WMHI_UNICONIFY\n");
pwindow = (struct Window *)IIntuition->IDoMethod(win_obj, WM_OPEN, NULL);
break;
case WMHI_GADGETUP:
{
IIntuition->GetAttr(CHOOSER_SelectedNode, OBJ(OID_CHOOSER), &res_node);
IChooser->GetChooserNodeAttrs( (struct Node *)res_node, CNA_Text,&res_string, TAG_DONE );
switch(result & WMHI_GADGETMASK)
{
case OID_SAVE:
{
DBUG("OID_SAVE\n");
BPTR file = 0;
STRPTR prefs_file;
done = FALSE;
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_SAVE_WARNING),res_string);
APTR lock = SleepWindow(pwindow);
res_value = DoMessage(textbuf, REQIMAGE_WARNING, (STRPTR)GetString(&li,MSG_CONT_CANCEL_GAD));
WakeWindow(pwindow, lock);
if(res_value == 0)
{
done = TRUE;
break;
}
prefs_file = IExec->AllocVecTags(DMP_MAX_PREF, TAG_DONE);
IUtility->Strlcpy(prefs_file, pointers_path, DMP_MAX_PREF);
IDOS->AddPart(prefs_file, PREFS_FILENAME, DMP_MAX_PREF);
if( (file=IDOS->Open(prefs_file, MODE_NEWFILE)) )
{
IDOS->FPrintf(file, "%s",res_string);
IDOS->Close(file);
}
IExec->FreeVec(prefs_file);
done = usePointers(res_string, pwindow);
/*if(DeletePointers() == 0)
{
DoMessage( (STRPTR)GetString(&li,MSG_ERROR_DEL_POINTERS), REQIMAGE_WARNING, NULL );
done = TRUE;
}
if(CopyPointers(res_string) != 0)
{
APTR lock = SleepWindow(pwindow);
DoMessage( (STRPTR)GetString(&li,MSG_ERROR_COPY_POINTERS), REQIMAGE_WARNING, NULL );
WakeWindow(pwindow, lock);
done = TRUE;
}*/
break;
}
case OID_USE:
DBUG("OID_USE\n");
usePointers(res_string, pwindow);
/*
DBUG("\tDELETING pointers not from theme '%s'\n",res_string);
if(DeletePointers() == 0)
{
DoMessage( (STRPTR)GetString(&li,MSG_ERROR_DEL_POINTERS), REQIMAGE_INFO, NULL );
}
if(CopyPointers(res_string) != 0)
{
APTR lock = SleepWindow(pwindow);
DoMessage( (STRPTR)GetString(&li,MSG_ERROR_COPY_POINTERS), REQIMAGE_WARNING, NULL );
WakeWindow(pwindow, lock);
}
*/
break;
case OID_QUIT:
DBUG("OID_QUIT\n");
done = FALSE;
break;
case OID_CHOOSER:
{
DBUG("OID_CHOOSER: %ld (was=%ld)\n",code,prev_chooser);
if(prev_chooser == code)
{// selector/chooser not changed! -> do nothing!
break;
}
//DBUG("\t0x%08lx '%s'\n[DETACHING LB]\n",res_node,res_string);
// Detach the listbrowser list first
IIntuition->SetAttrs(OBJ(OID_LISTPTRS), LISTBROWSER_Labels,NULL, TAG_END);
va.value = ListDMP_WB(res_string); // get new theme's/drawer's mouse pointers list
// Re-attach the listbrowser
IIntuition->SetAttrs(GAD(OID_LISTPTRS), pwindow, NULL,
LISTBROWSER_Labels,listbrowser_list, TAG_END);
//DBUG("\t[RE-ATTACHING LB]\n%ld\n",va.value);
/// Sort and refresh new listbrowser and chooser info
IIntuition->DoGadgetMethod(GAD(OID_LISTPTRS), pwindow, NULL,
LBM_SORT, NULL, COL_TXT, LBMSORT_FORWARD, NULL);
IIntuition->RefreshGadgets(GAD(OID_LISTPTRS), pwindow, NULL);
IIntuition->RefreshSetGadgetAttrs(GAD(OID_CHOOSER_INFO), pwindow, NULL,
BUTTON_VarArgs,&va, TAG_DONE);
prev_chooser = code;
break;
}
/*case OID_LISTPTRS:
{
IIntuition->GetAttr(LISTBROWSER_RelEvent, OBJ(OID_LISTPTRS), &res_value);
if(res_value == LBRE_DOUBLECLICK)
{
DBUG("OID_LISTPTRS: %ld\n",code);
IIntuition->GetAttr(LISTBROWSER_SelectedNode, OBJ(OID_LISTPTRS), (uint32 *)&res_node);
IListBrowser->GetListBrowserNodeAttrs( (struct Node *)res_node, LBNA_Column,COL_TXT,
LBNCA_Text,&res_string, TAG_DONE );
DBUG("\t0x%08lx '%s'\n",res_node,res_string);
}
break;
}*/
} // END switch(result & WMHI_GADGETMASK)
break;
} // END case WMHI_GADGETUP:
} // END switch(result & WMHI_CLASSMASK)
} // END while( (result..
} // END while(done)
} // END if( (pwindow..
IExec->FreeSysObject(ASOT_PORT, wAppPort);
wAppPort = NULL;
IIntuition->DisposeObject(win_obj);
win_obj = NULL;
pwindow = NULL;
IListBrowser->FreeLBColumnInfo(columninfo);
}
/* sort_chooslist() comparation hook */
int CompareNameNodes(struct Hook *hook, struct Node *node1, struct Node *node2)
{
STRPTR name1, name2;
IChooser->GetChooserNodeAttrs(node1, CNA_Text,&name1, TAG_DONE);
IChooser->GetChooserNodeAttrs(node2, CNA_Text,&name2, TAG_DONE);
DBUG("[0x%08lx] %-24s <-?-> [0x%08lx]'%s'\n",node1,name1,node2,name2);
return( IUtility->Stricmp(name1,name2) );
}
/* sort_chooslist() by Fredrik 'salas00' Wikstrom */
//void sort_chooserlist(int32 n, struct Hook *cmphook) {
void sort_chooserlist(int32 n, struct List *list, struct Hook *cmphook) {
struct Node *curr, *next;
int32 i, j;
DBUG("SORTING chooser_list:\n");
for(i=0; i<n; i++)
{
curr = IExec->GetHead(list);
for(j=0; j<n-1-i; j++)
{
next = IExec->GetSucc(curr);
if( (int)IUtility->CallHookPkt(cmphook,curr,next) > 0 )
//if(CompareNameNodes(curr,next) > 0)
{
IExec->Remove(curr);
IExec->Insert(list, curr, next);
}
else
{
curr = next;
}
}
}
}
/* sort_chooslist() by Thomas 'thomas' Rapp */
/*void sort_list(struct List *list, int (*compar)(const void*, const void*))
{
struct Node **array, *node,*next;
long n, i;
n = 0;
for(node=list->lh_Head; (next=node->ln_Succ); node=next)
n++;
if( (array=malloc(n * sizeof(*array))) ) {
for(i=0; i<n; i++)
array[i] = RemHead (list);
qsort(array, n, sizeof(*array), compar);
for(i=0; i<n; i++)
AddTail(list, array[i]);
free(array);
}
}
int compare_nodes(const struct Node **n1, const struct Node **n2)
{
return( Stricmp((*n1)->ln_Name,(*n2)->ln_Name) );
}*/
/* sort_chooslist() by 'OldFart' */
/*void sort_chooserlist(int32 n, struct Hook *cmphook) {
struct Node *Curr = IExec->GetHead(chooser_list);
if(Curr != NULL) {
struct Node *Next = IExec->GetSucc(Curr),
*Prev;
while(Next != NULL) {
if( (int)IUtility->CallHookPkt(cmphook,Curr,Next) > 0 ) {
IExec->Remove(Curr);
IExec->Insert(chooser_list, Curr, Next);
Prev = IExec->GetPred(Next);
while( (Prev != NULL) &&
((int)IUtility->CallHookPkt(cmphook,Prev,Next) > 0) ) {
IExec->Remove(Prev);
IExec->Insert(chooser_list, Prev, Next);
Prev = IExec->GetPred(Next);
}
}
Next = IExec->GetSucc(Curr);
}
}
}*/
/* sort_chooslist() */
/*void sort_chooserlist(int32 n) {
struct Node *n1, *n2, *n0 = IExec->GetHead(chooser_list);
STRPTR name1, name2;
int32 i, j;
for(i=n; i>0; i--) { // traverse all the chooser_list
#ifdef _WDEBUG_
IChooser->GetChooserNodeAttrs(n0, CNA_Text,&name1, TAG_DONE);
IDOS->Printf("i%ld:[0x%08lx]'%s'\n",i,n0,name1);
#endif
n2 = IExec->GetHead(chooser_list);
for(j=1; j<i; j++) {
n2 = IExec->GetSucc(n2);
IChooser->GetChooserNodeAttrs(n2, CNA_Text,&name2, TAG_DONE);
n1 = IExec->GetPred(n2);
IChooser->GetChooserNodeAttrs(n1, CNA_Text,&name1, TAG_DONE);
DBUG(" == j%ld:[0x%08lx]'%s'\n",j,n2,name2);
if(IUtility->Stricmp(name1, name2) > 0) // name-compare of node1 and node2
{
DBUG("SWAP [0x%08lx]'%s' <-> [0x%08lx]'%s'\n",n1,name1,n2,name2);
IExec->Remove(n1);
IExec->Insert(chooser_list, n1, n2);
}
}
n0 = IExec->GetSucc(n0);
}
}
*/
/* Create chooser list only with drawers contaning 'def_#?pointer.info' */
int32 make_chooser_list(struct List *list)
{
struct Node *node;
char text_err[100];
int32 themes_tot = 0;
APTR context = IDOS->ObtainDirContextTags(EX_StringNameInput, pointers_path,
EX_DataFields, (EXF_NAME|EXF_TYPE),
TAG_END);
if(context)
{
struct ExamineData *dat;
//DBUG("list=0x%08lx\n",list);
while( (dat=IDOS->ExamineDir(context)) )
{
if( EXD_IS_DIRECTORY(dat) )
{
DBUG("DRAWERNAME[%ld]='%s'\n",themes_tot,dat->Name);
if( ListDMP_WB(dat->Name) ) // lets see if it has pointer images/icons
{
if( (node=IChooser->AllocChooserNode(CNA_CopyText,TRUE, CNA_Text,dat->Name, TAG_DONE)) )
{
IExec->AddTail(list, node);
themes_tot++;
DBUG("DRAWERNAME[%ld]='%s' added to chooser [0x%08lx]\n",themes_tot,dat->Name,node);
}
}
}
}
if( ERROR_NO_MORE_ENTRIES != IDOS->IoErr() )
{
IDOS->Fault(IDOS->IoErr(), "[DMP]make_chooser_list():entries", textbuf, DMP_MAX_TXTB);
DoMessage(textbuf, REQIMAGE_WARNING, NULL);
}
if(themes_tot != 0)
{
struct Hook *prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK, ASOHOOK_Entry,CompareNameNodes, TAG_DONE);
sort_chooserlist(themes_tot, list, prhook); // sort chooser_list by name
IExec->FreeSysObject(ASOT_HOOK, prhook);
}
}
else
{
IDOS->Fault(IDOS->IoErr(), NULL, text_err, 100);
IUtility->SNPrintf(textbuf, DMP_MAX_TXTB, GetString(&li,MSG_ERROR_POINTERSDRAWER),text_err);
DoMessage(textbuf, REQIMAGE_WARNING, NULL);
}
IDOS->ReleaseDirContext(context);
return(themes_tot);
}
void free_chooser_list(struct List *list)
{
struct Node *node = NULL, *nextnode = NULL;
node = IExec->GetHead(list);
while(node)
{
nextnode = IExec->GetSucc(node);
IChooser->FreeChooserNode(node);
node = nextnode;
}
//FreeSysObject(ASOT_LIST, list);
}
/* Delete pointers not part of the new selected theme */
int32 DeletePointers(void)
{
STRPTR res_string,
pfile = IExec->AllocVecTags(DMP_MAX_FILE, TAG_DONE);
int32 i, success = 1;
struct Node *n = NULL;
DBUG("DeletePointers()\n",NULL);
n = IExec->GetHead(listbrowser_list);
for(i=0; xml_pointers[i]; i++)
{// list of all available pointers
IListBrowser->GetListBrowserNodeAttrs(n, LBNA_Column,COL_TXT, LBNCA_Text,&res_string, TAG_DONE);
DBUG("%ld) '%s' == '%s';\n",i+1,xml_pointers[i],res_string);
if(IUtility->Strnicmp(xml_pointers[i], res_string, IUtility->Strlen(res_string)) == 0)
{
n = IExec->GetSucc(n); // avoid "re-compare" matched node (pointer name)
}
else
{
IUtility->Strlcpy(pfile, "ENV:Sys/", DMP_MAX_FILE);
IDOS->AddPart(pfile, xml_pointers[i], DMP_MAX_FILE);
success &= IDOS->Delete(pfile);
DBUG("%ld)IDOS->Delete(%s) [%ld];\n",i+1,pfile,success);
}
}
IExec->FreeVec(pfile);
return success;
}
/* Get list of pointers and copy them to 'ENV:Sys/' */
int CopyPointers(CONST_STRPTR theme_drawer)
{
char *res_string = NULL;
STRPTR src_file = IExec->AllocVecTags(DMP_MAX_SRC, TAG_DONE),
dst_file = IExec->AllocVecTags(DMP_MAX_DST, TAG_DONE);
int errors = 0;
struct Node *node = IExec->GetHead(listbrowser_list);
#if defined(DEBUG)
count=1; // only for debuging purpouses
#endif
DBUG("CopyPointers('%s') .. to 'ENV:Sys/'\n",theme_drawer);
// Get SOURCE and DESTINATION files to be copied
for(; node!=NULL; node=IExec->GetSucc(node) )
{
IListBrowser->GetListBrowserNodeAttrs(node, LBNA_Column,COL_TXT, LBNCA_Text,&res_string, TAG_DONE);
// Create source fullpath+name (pointer_path+theme+pointer_filename)
IUtility->Strlcpy(src_file, pointers_path, DMP_MAX_SRC);
IDOS->AddPart(src_file, theme_drawer, DMP_MAX_SRC);
IDOS->AddPart(src_file, res_string, DMP_MAX_SRC);
// Create destination ('ENV:Sys/'+pointer_filename)
IUtility->Strlcpy(dst_file, "ENV:Sys/", DMP_MAX_DST);
IDOS->AddPart(dst_file, res_string, DMP_MAX_SRC);
errors |= BufferedCopy(src_file, dst_file);
}
IExec->FreeVec(src_file);
IExec->FreeVec(dst_file);
return errors;
}
/*****************************************/
/* This piece of code is by Tuomas Hokka */
#define BUFF_SIZE 8192
BOOL BufferedCopy(CONST_STRPTR source, CONST_STRPTR target)
{
BPTR src, tgt;
BOOL error = TRUE;
uint8 *buff;
uint32 readsize;//, count;
DBUG("SRC:'%s'\n",source);
DBUG("TO :'%s'\n",target);
tgt = IDOS->FOpen(target, MODE_NEWFILE, 0);
if(tgt != ZERO)
{
//DBUG("tgt=0x%08lx\n",tgt);
src = IDOS->FOpen(source, MODE_OLDFILE, 0);
if(src != ZERO)
{
//DBUG("src=0x%08lx\n",src);
buff = (uint8 *)IExec->AllocVecTags(BUFF_SIZE, AVT_Type,MEMF_SHARED, TAG_DONE);
if(buff != 0)
{
//DBUG["buff=0x%08lx: *",buff);
readsize = IDOS->FRead(src, buff, 1, BUFF_SIZE);
/*while(readsize == BUFF_SIZE)
{
//DBUG("*");
IDOS->FWrite(tgt, buff, 1, readsize);
readsize = IDOS->FRead(src, buff, 1, BUFF_SIZE);
}*/
//DBUG("\n");
/*count =*/ IDOS->FWrite(tgt, buff, 1, readsize);
//DBUG("bytes=%lu\n",count);
IExec->FreeVec(buff);
error = FALSE;
DBUG("copied #%ld\n",count++);
}
else
{
if(WBenchMsg)
{// WB or CLI/Shell
DoMessage( (STRPTR)GetString(&li,MSG_ERROR_BCOPY_MEM), REQIMAGE_ERROR, NULL );
//IExec->DebugPrintF("WBerror %ld\n",count++);
}
else
{
IDOS->PutErrStr( GetString(&li,MSG_ERROR_BCOPY_MEM) );
//DBUG("ERROR '%s'!!!\n",GetString(&li,MSG_ERROR_BCOPY_MEM));
}
}
IDOS->FClose(src);
}
else
{
IDOS->PrintFault(IDOS->IoErr(),"[DMP]BufferedCopy():src");
//DBUG("ERROR src\n");
}
IDOS->FClose(tgt);
}
else
{
IDOS->PrintFault(IDOS->IoErr(),"[DMP]BufferedCopy():tgt");
//DBUG("ERROR tgt\n");
}
return error;
}
/* This piece of code is by Tuomas Hokka */