-
Notifications
You must be signed in to change notification settings - Fork 1
/
addresscommon.c
328 lines (294 loc) · 11.3 KB
/
addresscommon.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
/*
HappyDays - A Birthday displayer for the Palm
Copyright (C) 1999-2005 JaeMok Jeong
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/*
* Just so you know some of these routines are pulled from the Address
* source code as provided by Palm. At least that is what I started from,
* I may have touched a few lines to get it to compile with gcc without
* warnings.
*/
#include <PalmOS.h>
#include "happydaysRsc.h"
#include "happydays.h"
#include "addresscommon.h"
#include "util.h"
char *UnnamedRecordStringPtr="";
// extern Int16 GotoAddress(Int16 index);
// called from Find function(must be in main section)
/***********************************************************************
*
* FUNCTION: DrawRecordName
*
* DESCRIPTION: Draws an address book record name. It is used
* for the list view and note view.
*
* PARAMETERS: name1, name2 - first and seconds names to draw
* nameExtent - the space the names must be drawn in
* *x, y - where the names are drawn
*
* RETURNED: x is set after the last char drawn
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* roger 6/20/95 Initial Revision
* frigino 970813 Rewritten. Now includes a variable ratio for
* name1/name2 width allocation, a prioritization
* parameter, and a word break search to allow
* reclaiming of space from the low priority
* name.
* jmjeong 99/12/22 Abridged version. make the num of
* parameters small
*
***********************************************************************/
void DrawRecordName(
char* name1, char* name2,
UInt16 nameExtent, Int16 *x, Int16 y,
Boolean center, Boolean priorityIsName1)
{
Int16 name1MaxWidth;
Int16 name2MaxWidth;
Boolean ignored;
Int16 totalWidth;
Char * lowPriName;
Int16 highPriNameWidth;
Int16 lowPriNameWidth;
Int16 highPriMaxWidth;
Int16 lowPriMaxWidth;
Char * spaceP;
UInt16 shortenedFieldWidth;
UInt16 fieldSeparatorWidth;
Int16 name1Length, name1Width;
Int16 name2Length, name2Width;
shortenedFieldWidth = FntCharsWidth(shortenedFieldString,
shortenedFieldLength);
fieldSeparatorWidth = FntCharsWidth(fieldSeparatorString,
fieldSeparatorLength);
if (*name1) {
/* Only show text from the first line in the field */
name1Length = nameExtent; /* longer than possible */
name1Width = nameExtent; /* wider than possible */
FntCharsInWidth(name1, &name1Width, &name1Length, &ignored);
} else {
/* Set the name to the unnamed string */
name1 = UnnamedRecordStringPtr;
name1Length = StrLen(UnnamedRecordStringPtr);
name1Width = FntCharsWidth(UnnamedRecordStringPtr,
name1Length);
}
if (*name2) {
/* Only show text from the first line in the field */
name2Length = nameExtent; /* longer than possible */
name2Width = nameExtent; /* wider than possible */
FntCharsInWidth(name2, &name2Width, &name2Length, &ignored);
} else {
name2Length = 0;
name2Width = 0;
}
/* Check if both names fit */
totalWidth = name1Width + (*name2 ? fieldSeparatorWidth : 0) + name2Width;
/*
* If we are supposed to center the names then move in the x position
* by the amount that centers the text
*/
if (center && (nameExtent > totalWidth)) {
*x += (nameExtent - totalWidth) / 2;
}
/* Special case if only name1 is given */
if (!*name2) {
/*
* For some reason, OS3 changed the code so that it doesn't show
* ellipses if there is only name1. I liked it the old way!
*/
/* Does name1 fit in its maximum width? */
if (name1Width > nameExtent) {
/* No. Draw it to max width minus the ellipsis */
name1Width = nameExtent-shortenedFieldWidth;
FntCharsInWidth(name1, &name1Width, &name1Length, &ignored);
WinDrawChars(name1, name1Length, *x, y);
*x += name1Width;
/* Draw ellipsis */
WinDrawChars(shortenedFieldString, shortenedFieldLength, *x, y);
*x += shortenedFieldWidth;
} else {
/* Yes. Draw name1 within its width */
FntCharsInWidth(name1, &name1Width, &name1Length, &ignored);
WinDrawChars(name1, name1Length, *x, y);
*x += name1Width;
}
return;
}
/* Remove name separator width */
nameExtent -= fieldSeparatorWidth;
/* Test if both names fit */
if ((name1Width + name2Width) <= nameExtent) {
name1MaxWidth = name1Width;
name2MaxWidth = name2Width;
} else {
/*
* They dont fit. One or both needs truncation
* Establish name priorities and their allowed widths
* Change this to alter the ratio of the low and high
* priority name spaces
*/
highPriMaxWidth = (nameExtent << 1)/3; /* 1/3 to low and 2/3 to high */
lowPriMaxWidth = nameExtent-highPriMaxWidth;
/* Save working copies of names and widths based on priority */
if (priorityIsName1) {
/* Priority is name1 */
highPriNameWidth = name1Width;
lowPriName = name2;
lowPriNameWidth = name2Width;
} else {
/* Priority is name2 */
highPriNameWidth = name2Width;
lowPriName = name1;
lowPriNameWidth = name1Width;
}
/* Does high priority name fit in high priority max width? */
if (highPriNameWidth > highPriMaxWidth) {
/* No. Look for word break in low priority name */
spaceP = StrChr(lowPriName, spaceChr);
if (spaceP != NULL) {
/* Found break. Set low priority name width to break width */
lowPriNameWidth = FntCharsWidth(lowPriName, spaceP-lowPriName);
/*
* Reclaim width from low pri name width to low pri max width,
* if smaller.
*/
if (lowPriNameWidth < lowPriMaxWidth) {
lowPriMaxWidth = lowPriNameWidth;
/* Set new high pri max width */
highPriMaxWidth = nameExtent-lowPriMaxWidth;
}
}
} else {
/* Yes. Adjust maximum widths */
highPriMaxWidth = highPriNameWidth;
lowPriMaxWidth = nameExtent-highPriMaxWidth;
}
/* Convert priority widths back to name widths */
if (priorityIsName1) {
/* Priority is name1 */
name1Width = highPriNameWidth;
name2Width = lowPriNameWidth;
name1MaxWidth = highPriMaxWidth;
name2MaxWidth = lowPriMaxWidth;
} else {
/* Priority is name2 */
name1Width = lowPriNameWidth;
name2Width = highPriNameWidth;
name1MaxWidth = lowPriMaxWidth;
name2MaxWidth = highPriMaxWidth;
}
}
/* Does name1 fit in its maximum width? */
if (name1Width > name1MaxWidth) {
/* No. Draw it to max width minus the ellipsis */
name1Width = name1MaxWidth-shortenedFieldWidth;
FntCharsInWidth(name1, &name1Width, &name1Length, &ignored);
WinDrawChars(name1, name1Length, *x, y);
*x += name1Width;
/* Draw ellipsis */
WinDrawChars(shortenedFieldString, shortenedFieldLength, *x, y);
*x += shortenedFieldWidth;
} else {
/* Yes. Draw name1 within its width */
FntCharsInWidth(name1, &name1Width, &name1Length, &ignored);
WinDrawChars(name1, name1Length, *x, y);
*x += name1Width;
}
if (*name1 && *name2) {
/* Draw name separator */
WinDrawChars(fieldSeparatorString, fieldSeparatorLength, *x, y);
*x += fieldSeparatorWidth;
}
/* Draw name2 within its maximum width */
FntCharsInWidth(name2, &name2MaxWidth, &name2Length, &ignored);
WinDrawChars(name2, name2Length, *x, y);
*x += name2MaxWidth;
}
// address creator id
// the order must be same as 'happydays.rcp' file.
//
UInt32 AddrGotoCreatorId[] = {
'addr', // Built-in Addressbook
'AAlb', // Address Album
'CiAe', // AddressBkR
'addp', // Address Plus(+)
'SNms', // Super Names
'TlPh', // Teal Phone
'HnAD' // HanAD
};
Int16 GotoAddress(Int16 index)
{
GoToParamsPtr theGotoPointer;
DmSearchStateType searchInfo;
UInt16 cardNo;
LocalID dbID;
UInt32 addrID = AddrGotoCreatorId[(int)gPrefsR.addrapp];
theGotoPointer = MemPtrNew(sizeof(GoToParamsType));
if (!theGotoPointer) return -1;
/* Set the owner of the pointer to be the
system. This is required because all memory
allocated by our application is freed when
the application quits. Our application will
quit the next time through our event
handler.
*/
if ((MemPtrSetOwner(theGotoPointer, 0) == 0) &&
(DmGetNextDatabaseByTypeCreator(true, &searchInfo, 0,
addrID, true, &cardNo, &dbID)
== 0)) {
// copy all the goto information into the
// GotoParamsPtr structure
theGotoPointer->searchStrLen = 0;
theGotoPointer->dbCardNo = cardNo;
theGotoPointer->dbID = dbID;
theGotoPointer->recordNum = index;
theGotoPointer->matchPos = 0;
theGotoPointer->matchFieldNum = 0;
theGotoPointer->matchCustom = 0;
if ((DmGetNextDatabaseByTypeCreator
(true, &searchInfo,
sysFileTApplication, addrID, true, &cardNo, &dbID) == 0)) {
SysUIAppSwitch(cardNo, dbID,
sysAppLaunchCmdGoTo,
(MemPtr) theGotoPointer);
/*
* return from address? (fatal?)
SysAppLaunch(cardNo, dbID, sysAppLaunchFlagNewThread,
sysAppLaunchCmdGoTo,
(MemPtr) theGotoPointer, &ret);
*/
return 0;
}
}
MemPtrFree(theGotoPointer);
return -1;
}
void CleanupHappyDaysCache(DmOpenRef dbP)
{
UInt16 currindex = 0;
MemHandle recordH = 0;
if (dbP) {
while (1) {
recordH = DmQueryNextInCategory(dbP, &currindex,
dmAllCategories);
if (!recordH) break;
DmRemoveRecord(dbP, currindex); // remove all traces
}
}
}