/
DescModesListForm.m
356 lines (284 loc) · 8.76 KB
/
DescModesListForm.m
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
/*
* DescModesListForm.m --
*
* Author : Charlie Root
* Created On : Fri Aug 22 16:53:15 2003
* Last Modified By: Maxime Soule
* Last Modified On: Fri Jul 6 14:43:27 2007
* Update Count : 15
* Status : Unknown, Use with caution!
*
*
* ==================== RCS ====================
* $Author: max $
* $Log: DescModesListForm.m,v $
* Revision 1.7 2008/01/14 17:09:32 max
* Switch to new mcc.
*
* Revision 1.6 2005/11/19 16:56:19 max
* Redraws reworked.
*
* Revision 1.5 2005/08/31 19:43:06 max
* Comment cleaning.
*
* Revision 1.4 2005/08/31 19:38:52 max
* *** empty log message ***
*
* Revision 1.3 2005/08/28 10:02:26 max
* Bug with update pending event corrected.
*
* Revision 1.2 2005/08/20 13:06:50 max
* Updates are now genericaly managed by MaTiForm.
* Use new form argument passing method.
*
* Revision 1.1 2005/02/09 22:57:22 max
* First import.
*
* ==================== RCS ==================== */
#define EXTERN_DESCMODESLISTFORM
#include "DescModesListForm.h"
#include "MaTirelire.h"
#include "MaTirelireDefs.h"
#include "objRsc.h" // XXX
// Pour la méthode -showHideList:selItem:
#define NO_INIT_LIST 0x8000 // Pas d'init de la liste
#define SEL_ITEM_MASK (~NO_INIT_LIST)
@implementation DescModesListForm
- (DescModesListForm*)free
{
// Liberation de la liste
[self->oDBItem listFree:self->ppa_list];
return [super free];
}
- (Boolean)open
{
ListPtr pt_lst;
Char ra_title[32];
self->b_modes_dialog = (self->uh_form_flags & DM_MODES_LIST_FORM) != 0;
// Liste des modes
if (self->b_modes_dialog)
{
self->oDBItem = (DBItem*)[oMaTirelire mode];
SysCopyStringResource(ra_title, strTitleModesList);
}
// Liste des descriptions
else
{
self->oDBItem = (DBItem*)[oMaTirelire desc];
SysCopyStringResource(ra_title, strTitleDescList);
}
FrmCopyTitle(self->pt_frm, ra_title);
self->uh_num = 0; // On ne veut pas d'entrée "Indifférent" pour les modes
self->ppa_list = [self->oDBItem listBuildInfos:NULL num:&self->uh_num
largest:NULL];
pt_lst = [self objectPtrId:DescModesList];
LstSetDrawFunction(pt_lst, [self->oDBItem listDrawFunction]);
[self showHideList:pt_lst selItem:0];
return [super open];
}
- (void)showHideList:(ListPtr)pt_lst selItem:(UInt16)uh_sel_item
{
UInt16 uh_flags = uh_sel_item;
UInt16 ruh_show_hide_ids[4 + 1], *puh_show_hide;
puh_show_hide = ruh_show_hide_ids;
uh_sel_item &= SEL_ITEM_MASK;
if (pt_lst == NULL)
pt_lst = [self objectPtrId:DescModesList];
if ((uh_flags & NO_INIT_LIST) == 0)
// On initialise la liste et on regarde s'il y a ou non une flèche
// de scroll dans la marge de droite
[self->oDBItem rightMarginList:pt_lst num:self->uh_num
in:(struct __s_list_dbitem_buf*)self->ppa_list selItem:uh_sel_item];
// Au moins un item dans la liste
if (self->uh_num > 0)
{
/* Les disparitions d'abord */
/* Pas de + */
*puh_show_hide++ = SET_SHOW(DescModesListPlus, uh_sel_item > 0);
/* Pas de - */
*puh_show_hide++
= SET_SHOW(DescModesListMinus, uh_sel_item < self->uh_num - 1);
/* Pas de nouveau */
*puh_show_hide++
=SET_SHOW(DescModesListNew, self->uh_num < [self->oDBItem dbMaxEntries]);
/* Il faut edit */
*puh_show_hide++ = SET_SHOW(DescModesListEdit, 1);
}
// Aucun élément
else
{
*puh_show_hide++ = SET_SHOW(DescModesListPlus, 0);
*puh_show_hide++ = SET_SHOW(DescModesListEdit, 0);
*puh_show_hide++ = SET_SHOW(DescModesListMinus, 0);
*puh_show_hide++ = SET_SHOW(DescModesListNew, 1);
}
*puh_show_hide = 0;
[self showHideIds:ruh_show_hide_ids];
}
- (void)redrawForm
{
ListType *pt_lst = [self objectPtrId:DescModesList];
if (self->uh_num > 0)
LstMakeItemVisible(pt_lst, self->uh_entry_selected);
FrmDrawForm(self->pt_frm);
// Si on est sur une rom < 3.2, il faut redessiner 2 fois de suite
// la liste en cas d'ajout/suppression/édition d'élément...
if (oMaTirelire->ul_rom_version < 0x03203000)
{
if (self->b_item_edited)
{
self->b_item_edited = false;
LstDrawList(pt_lst);
}
LstDrawList(pt_lst);
}
}
//
// Used by child to know if it's new or edit action
- (UInt16)editedEntryIndex
{
return self->uh_entry_index;
}
//
// Used by child to know if it can display a new button (max items
// number not yet reached)
- (Boolean)isChildNewButton
{
return (self->uh_num < [self->oDBItem dbMaxEntries]);
}
- (Boolean)ctlSelect:(struct ctlSelect *)ps_select
{
switch (ps_select->controlID)
{
case DescModesListPlus:
[self moveItem:winUp];
break;
case DescModesListMinus:
[self moveItem:winDown];
break;
case DescModesListNew:
self->uh_entry_index = dmMaxRecordIndex;
if (self->b_modes_dialog)
FrmPopupForm(EditModeFormIdx);
else
FrmPopupForm(EditDescFormIdx);
break;
case DescModesListEdit:
{
UInt16 uh_sel_item = LstGetSelection([self objectPtrId:DescModesList]);
if (uh_sel_item != noListSelection)
{
self->uh_entry_selected = uh_sel_item; // Useful in -update: method
if (self->b_modes_dialog)
{
// On passe l'index de l'enregistrement
self->uh_entry_index = ((struct __s_list_mode_buf*)
self->ppa_list)->ruh_list2index[uh_sel_item];
FrmPopupForm(EditModeFormIdx);
}
else
{
// On passe l'index de l'enregistrement
self->uh_entry_index = ((struct __s_list_desc_buf*)
self->ppa_list)->ruh_list2index[uh_sel_item];
FrmPopupForm(EditDescFormIdx);
}
}
}
break;
case DescModesListOK:
// Retour au formulaire précédent...
[self returnToLastForm];
break;
default:
return false;
}
return true;
}
- (Boolean)lstSelect:(struct lstSelect *)ps_list_select
{
if (ps_list_select->listID == DescModesList)
{
[self showHideList:ps_list_select->pList
selItem:NO_INIT_LIST | ps_list_select->selection];
return true;
}
return false;
}
- (Boolean)callerUpdate:(struct frmCallerUpdate *)ps_update
{
if (ps_update->updateCode & frmMaTiUpdateEdit2List)
{
UInt16 uh_sel_item = self->uh_entry_selected;
// Destruction de l'ancienne liste
[self->oDBItem listFree:self->ppa_list];
// Création de la nouvelle
self->uh_num = 0; // On ne veut pas d'entrée "Indifférent" pour les modes
self->ppa_list = [self->oDBItem listBuildInfos:NULL num:&self->uh_num
largest:NULL];
// The edited item is deleted => new selected is previous if any
if ((ps_update->updateCode & frmMaTiUpdateEdit2ListDeletedItem)
&& uh_sel_item != 0)
uh_sel_item--;
// A new item was added => just after current OR at end
if (ps_update->updateCode & frmMaTiUpdateEdit2ListNewItem)
{
if (ps_update->updateCode & frmMaTiUpdateEdit2ListNewItemAfter)
uh_sel_item++;
else
uh_sel_item = self->uh_num - 1;
}
// Il s'agit d'un vrai update, pas juste un item qui bouge...
if ((ps_update->updateCode & frmMaTiUpdateEdit2ListAfterMove) == 0)
// Sert pour les OS < 3.2 voir -redrawForm
self->b_item_edited = true;
// Remplissage (le redraw va être fait avec l'événement redraw
// envoyé automatiquement par le formulaire précédent)
[self showHideList:NULL selItem:uh_sel_item];
// Cas particulier : redessin si on a juste bougé le mode/desc
if (ps_update->updateCode & frmMaTiUpdateEdit2ListRedraw)
LstDrawList([self objectPtrId:DescModesList]);
// Il faudra avertir Papa
if (self->b_modes_dialog)
self->ui_update_mati_list |= (frmMaTiUpdateList
| frmMaTiUpdateListModes);
else
self->ui_update_mati_list |= (frmMaTiUpdateList
| frmMaTiUpdateListDesc);
// Il ne faut pas que la classe mère conserve cet événement pour
// Papa, on s'en est chargé nous-mêmes une ligne au dessus.
ps_update->updateCode = 0;
}
return [super callerUpdate:ps_update];
}
- (void)moveItem:(WinDirectionType)dir
{
ListPtr pt_lst = [self objectPtrId:DescModesList];
UInt16 index = LstGetSelection(pt_lst);
if (index != noListSelection
/* Test utile uniquement pour les touches HAUT/BAS */
&& (dir == winUp
? (index > 0)
: (index < LstGetNumberOfItems(pt_lst) - 1)))
{
UInt16 uh_rec_index;
if (self->b_modes_dialog)
uh_rec_index
= ((struct __s_list_mode_buf*)self->ppa_list)->ruh_list2index[index];
else
uh_rec_index
= ((struct __s_list_desc_buf*)self->ppa_list)->ruh_list2index[index];
// The ID of selected item is just before the string
if ([self->oDBItem moveId:uh_rec_index direction:dir])
{
struct frmCallerUpdate s_update;
self->uh_entry_selected = index + (dir == winUp ? -1 : 1);
s_update.updateCode = (frmMaTiUpdateEdit2List
| frmMaTiUpdateEdit2ListAfterMove
| frmMaTiUpdateEdit2ListRedraw);
guh_pending_events++;
[self callerUpdate:&s_update]; // guh_pending_events OK
}
}
}
@end