1 /***************************************************************************
3 BetterString.mcc - A better String gadget MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2013 by BetterString.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 BetterString class Support Site: http://www.sf.net/projects/bstring-mcc/
21 ***************************************************************************/
24 #include <clib/alib_protos.h>
25 #include <proto/intuition.h>
26 #include <proto/muimaster.h>
27 #include <libraries/mui.h>
30 #include "BetterString_mcp.h"
35 struct PrefsExchangeData
40 const ULONG Type
; // 0 = string, 1 = integer
44 static const struct PrefsExchangeData PrefsInfo
[] =
46 { ActiveBack
, MUIA_Imagedisplay_Spec
, MUICFG_BetterString_ActiveBack
, 0, (APTR
)CFG_BetterString_ActiveBack_Def
},
47 { ActiveText
, MUIA_Pendisplay_Spec
, MUICFG_BetterString_ActiveText
, 0, (APTR
)CFG_BetterString_ActiveText_Def
},
48 { InactiveBack
, MUIA_Imagedisplay_Spec
, MUICFG_BetterString_InactiveBack
, 0, (APTR
)CFG_BetterString_InactiveBack_Def
},
49 { InactiveText
, MUIA_Pendisplay_Spec
, MUICFG_BetterString_InactiveText
, 0, (APTR
)CFG_BetterString_InactiveText_Def
},
50 { Cursor
, MUIA_Pendisplay_Spec
, MUICFG_BetterString_Cursor
, 0, (APTR
)CFG_BetterString_Cursor_Def
},
51 { MarkedBack
, MUIA_Pendisplay_Spec
, MUICFG_BetterString_MarkedBack
, 0, (APTR
)CFG_BetterString_MarkedBack_Def
},
52 { MarkedText
, MUIA_Pendisplay_Spec
, MUICFG_BetterString_MarkedText
, 0, (APTR
)CFG_BetterString_MarkedText_Def
},
53 { SelectOnActive
, MUIA_Selected
, MUICFG_BetterString_SelectOnActive
, 1, (APTR
)CFG_BetterString_SelectOnActive_Def
},
54 { SelectPointer
, MUIA_Selected
, MUICFG_BetterString_SelectPointer
, 1, (APTR
)CFG_BetterString_SelectPointer_Def
}
57 DISPATCHER(_DispatcherP
)
59 struct InstData_MCP
*data
= (struct InstData_MCP
*)INST_DATA(cl
, obj
);
68 if((obj
= (Object
*)DoSuperMethodA(cl
, obj
, (Msg
)msg
)))
70 struct InstData_MCP
*data
= (struct InstData_MCP
*)INST_DATA(cl
, obj
);
73 // everything beyond muimaster 20.5500 is considered to be MUI4
74 data
->mui4x
= LIB_VERSION_IS_AT_LEAST(MUIMasterBase
, 20, 5500);
76 if((prefsobject
= CreatePrefsGroup(data
)))
80 DoMethod(obj
, OM_ADDMEMBER
, prefsobject
);
82 // This is MUI 3.9 stuff: Each registered object will get a context-menu, like normal pref-items
83 if(LIB_VERSION_IS_AT_LEAST(MUIMasterBase
, 20, 0))
85 for(i
=0; i
< NumberOfObject
; i
++)
86 DoMethod(obj
, MUIM_Mccprefs_RegisterGadget
, data
->Objects
[PrefsInfo
[i
].ObjIndex
], PrefsInfo
[i
].CfgItem
, 2, NULL
, PrefsInfo
[i
].Tag
);
92 CoerceMethod(cl
, obj
, OM_DISPOSE
);
97 case MUIM_Settingsgroup_ConfigToGadgets
:
100 Object
*configdata
= ((struct MUIP_Settingsgroup_ConfigToGadgets
*)msg
)->configdata
;
102 for(i
=0; i
< NumberOfObject
; i
++)
106 cfg_val
= (APTR
)DoMethod(configdata
, MUIM_Dataspace_Find
, PrefsInfo
[i
].CfgItem
);
108 if(PrefsInfo
[i
].Type
== 0)
110 D(DBF_STARTUP
, "0 MUIM_Dataspace_Find[%ld]: %08lx : %lx / %lx", i
, PrefsInfo
[i
].CfgItem
, cfg_val
, cfg_val
? cfg_val
: PrefsInfo
[i
].DefValue
);
112 nnset(data
->Objects
[PrefsInfo
[i
].ObjIndex
], PrefsInfo
[i
].Tag
, cfg_val
? cfg_val
: PrefsInfo
[i
].DefValue
);
116 D(DBF_STARTUP
, "1 MUIM_Dataspace_Find[%ld]: %08lx : %P / %P", i
, PrefsInfo
[i
].CfgItem
, cfg_val
, cfg_val
? *(IPTR
*)cfg_val
: (IPTR
)PrefsInfo
[i
].DefValue
);
118 nnset(data
->Objects
[PrefsInfo
[i
].ObjIndex
], PrefsInfo
[i
].Tag
, cfg_val
? *(IPTR
*)cfg_val
: (IPTR
)PrefsInfo
[i
].DefValue
);
124 case MUIM_Settingsgroup_GadgetsToConfig
:
127 Object
*configdata
= ((struct MUIP_Settingsgroup_ConfigToGadgets
*)msg
)->configdata
;
129 for(i
=0; i
< NumberOfObject
; i
++)
133 cfg_val
= xget(data
->Objects
[PrefsInfo
[i
].ObjIndex
], PrefsInfo
[i
].Tag
);
135 if(PrefsInfo
[i
].Type
== 0)
137 if(stricmp((char *)cfg_val
, PrefsInfo
[i
].DefValue
) != 0)
139 D(DBF_STARTUP
, "0 MUIM_Dataspace_Add[%ld]: %08lx : %lx", i
, PrefsInfo
[i
].CfgItem
, cfg_val
);
140 DoMethod(configdata
, MUIM_Dataspace_Add
, cfg_val
, strlen((char *)cfg_val
)+1, PrefsInfo
[i
].CfgItem
);
144 D(DBF_STARTUP
, "0 MUIM_Dataspace_Remove[%ld]: %08lx", i
, PrefsInfo
[i
].CfgItem
);
145 DoMethod(configdata
, MUIM_Dataspace_Remove
, PrefsInfo
[i
].CfgItem
);
150 if(cfg_val
!= (SIPTR
)PrefsInfo
[i
].DefValue
)
152 D(DBF_STARTUP
, "1 MUIM_Dataspace_Add[%ld]: %08lx : %lx / %lx", i
, PrefsInfo
[i
].CfgItem
, &cfg_val
, cfg_val
);
153 DoMethod(configdata
, MUIM_Dataspace_Add
, &cfg_val
, sizeof(cfg_val
), PrefsInfo
[i
].CfgItem
);
157 D(DBF_STARTUP
, "1 MUIM_Dataspace_Remove[%ld]: %08lx", i
, PrefsInfo
[i
].CfgItem
);
158 DoMethod(configdata
, MUIM_Dataspace_Remove
, PrefsInfo
[i
].CfgItem
);
163 // erase obsolete settings
164 DoMethod(configdata
, MUIM_Dataspace_Remove
, MUICFG_BetterString_Font
);
165 DoMethod(configdata
, MUIM_Dataspace_Remove
, MUICFG_BetterString_Frame
);
170 result
= DoSuperMethodA(cl
, obj
, msg
);