File: Skins.cpp

package info (click to toggle)
pose 3.0a3-3
  • links: PTS
  • area: contrib
  • in suites: potato
  • size: 15,500 kB
  • ctags: 20,548
  • sloc: ansic: 72,579; cpp: 50,198; perl: 1,336; python: 1,242; sh: 363; makefile: 290
file content (1124 lines) | stat: -rw-r--r-- 31,517 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
/* -*- mode: C++; tab-width: 4 -*- */
/* ================================================================================== */
/* Copyright (c) 1998-1999 3Com Corporation or its subsidiaries. All rights reserved. */
/* ================================================================================== */

#include "EmulatorCommon.h"
#include "Skins.h"

#include "PreferenceMgr.h"		// Preference
#include "SkinData.h"			// kPil500015Image, etc.

#include <algorithm>			// find()

struct ButtonBounds
{
	SkinElementType	fButton;
	RectangleType	fBounds;
};
typedef vector<ButtonBounds>	ButtonBoundsList;
 
struct Skinfo
{
	Skinfo () :
		fName (),
		fImageName1x (),
		fImageName2x (),
		fDevices (),
		fButtons ()
		{}

	SkinName			fName;
	string				fImageName1x;
	string				fImageName2x;
	RGBType				fBackgroundColor;
	RGBType				fHighlightColor;
	DeviceList			fDevices;
	ButtonBoundsList	fButtons;
};


typedef vector<Skinfo>	SkinList;

static Skinfo			gCurrentSkin;
static ScaleType		gCurrentScale;

static void				PrvBuildSkinList	(SkinList&);
static void				PrvGetSkins			(DeviceType type, SkinList& results);
static Bool				PrvGetNamedSkin		(DeviceType type, const SkinName& name, Skinfo& result);
static void				PrvGetDefaultSkin	(DeviceType type, Skinfo& skin);
static Bool				PrvValidSkin		(DeviceType type, const SkinName& skinName);
static void				PrvSetSkin			(const Skinfo&, ScaleType scale);
static SkinElementType	PrvTestPoint		(const PointType&, int outset);
static Bool				PrvPtInRect			(const PointType&, const AbsRectType&);


struct ResourceMap
{
	const char*	name;
	const void*	image;
	size_t		length;
};

ResourceMap kSkinResources[] =
{
	{ "Pil500016",	kPil500016Image,	kPil500016ImageSize },
	{ "Pil500032",	kPil500032Image,	kPil500032ImageSize },
	{ "PilPro16",	kPilPro16Image,		kPilPro16ImageSize },
	{ "PilPro32",	kPilPro32Image,		kPilPro32ImageSize },
	{ "Palm316",	kPalm316Image,		kPalm316ImageSize },
	{ "Palm332",	kPalm332Image,		kPalm332ImageSize },
	{ "Palm3e16",	kPalm3e16Image,		kPalm3e16ImageSize },
	{ "Palm3e32",	kPalm3e32Image,		kPalm3e32ImageSize },
	{ "Palm3x16",	kPalm3x16Image,		kPalm3x16ImageSize },
	{ "Palm3x32",	kPalm3x32Image,		kPalm3x32ImageSize },
	{ "IBMWP16",	kIBMWP16Image,		kIBMWP16ImageSize },
	{ "IBMWP32",	kIBMWP32Image,		kIBMWP32ImageSize },
	{ "Palm516",	kPalm516Image,		kPalm516ImageSize },
	{ "Palm532",	kPalm532Image,		kPalm532ImageSize },
	{ "IBMWPc316",	kIBMWPc316Image,	kIBMWPc316ImageSize },
	{ "IBMWPc332",	kIBMWPc332Image,	kIBMWPc332ImageSize },
	{ "Palm716",	kPalm716Image,		kPalm716ImageSize },
	{ "Palm732",	kPalm732Image,		kPalm732ImageSize },
	{ "Sym150016",	kSym150016Image,	kSym150016ImageSize },
	{ "Sym150032",	kSym150032Image,	kSym150032ImageSize },
	{ "Sym174016",	kSym174016Image,	kSym174016ImageSize },
	{ "Sym174032",	kSym174032Image,	kSym174032ImageSize },
	{ "ColorDev16",	kEnglishAustinSmallImage,	kEnglishAustinSmallImageSize },
	{ "ColorDev32",	kEnglishAustinLargeImage,	kEnglishAustinLargeImageSize }
};

const long kNumSkinResources = countof(kSkinResources);


/***********************************************************************
 *
 * FUNCTION:    SkinGetSkinName
 *
 * DESCRIPTION: Get the name of the user-chosen skin for the given
 *				device type.
 *
 * PARAMETERS:  type - the device type for which we need the name
 *					of the skin to use.
 *
 * RETURNED:    The skin name.  At the very least, this will be the
 *				name of some default skin if the user hasn't made a
 *				choice or if the chosen skin is invalid.
 *
 ***********************************************************************/

SkinName SkinGetSkinName (DeviceType type)
{
	// Get the chosen skin for this device.

	Preference<SkinNameList>	pref(kPrefKeySkins);
	SkinNameList				skinNames = *pref;
	SkinName					name = skinNames[type];

	// If the name is empty or invalid, chose a default skin.

	if (!::PrvValidSkin (type, name))
	{
		Skinfo	skin;
		::PrvGetDefaultSkin (type, skin);
		name = skin.fName;
	}

	return name;
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetSkinNames
 *
 * DESCRIPTION:	Get the list of names of available skins for the given
 *				device.
 *
 * PARAMETERS:	type - the device for which the list of skins should
 *					be returned.  If kDeviceUnspecified, return all
 *					skins for all devices.
 *
 *				results - receives the list of skin names.  Any skin
 *					names are *added* to this list; the list is not
 *					cleared out first.
 *
 * RETURNED:	Nothing
 *
 ***********************************************************************/

void SkinGetSkinNames (DeviceType type, SkinNameList& results)
{
	SkinList	skins;
	::PrvGetSkins (type, skins);

	SkinList::iterator	iter = skins.begin ();
	while (iter != skins.end ())
	{
		results.push_back (iter->fName);

		++iter;
	}
}


/***********************************************************************
 *
 * FUNCTION:	SkinSetSkin
 *
 * DESCRIPTION:	Establish the skin to use, based on the current settings.
 *				All other funtions in this module will then work within
 *				the context of the specified skin.
 *
 * PARAMETERS:	None
 *
 * RETURNED:	Nothing
 *
 ***********************************************************************/

void SkinSetSkin (void)
{
	Preference<Configuration>	cfgPref (kPrefKeyLastConfiguration);
	Preference<SkinNameList>	skinsPref (kPrefKeySkins);
	Preference<ScaleType>		scalePref (kPrefKeyScale);

	SkinNameList	skins = *skinsPref;

	::SkinSetSkin (cfgPref->fDeviceType, *scalePref, skins[cfgPref->fDeviceType]);
}


void SkinSetSkin (DeviceType type, ScaleType scale, const SkinName& name)
{
	Skinfo		skin;

	if (!::PrvGetNamedSkin (type, name, skin))
	{
		::PrvGetDefaultSkin (type, skin);
	}

	::PrvSetSkin (skin, scale);
}


void PrvSetSkin (const Skinfo& skin, ScaleType scale)
{
	gCurrentSkin = skin;
	gCurrentScale = scale;
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetResourceName
 *
 * DESCRIPTION:	Return the name of the resource containing the image
 *				for the default skin.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Pointer to the resource name of the image to use.
 *
 ***********************************************************************/

const char*		SkinGetResourceName	(void)
{
	return ::SkinGetResourceName (gCurrentScale);
}


const char*		SkinGetResourceName	(ScaleType scale)
{
	if (scale == 1)
		return gCurrentSkin.fImageName1x.c_str();

	return gCurrentSkin.fImageName2x.c_str();
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetImageAsJPEG
 *
 * DESCRIPTION:	Return the name of the resource containing the image
 *				for the default skin.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Pointer to the resource name of the image to use.
 *
 ***********************************************************************/

void		SkinGetImageAsJPEG	(const void*& data, long& length)
{
	::SkinGetImageAsJPEG (gCurrentScale, data, length);
}


void		SkinGetImageAsJPEG	(ScaleType scale, const void*& data, long& length)
{
	data = NULL;
	length = 0;

	string	name (::SkinGetResourceName (scale));

	for (int ii = 0; ii < kNumSkinResources; ++ii)
	{
		if (name == kSkinResources[ii].name)
		{
			data = kSkinResources[ii].image;
			length = (long) kSkinResources[ii].length;
			break;
		}
	}
}


/***********************************************************************
 *
 * FUNCTION:	SkinDoneWithImage
 *
 * DESCRIPTION:	.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

void		SkinDoneWithImage	(const void*)
{
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetBackgroundColor
 *
 * DESCRIPTION:	Return the default background color for the current
 *				skin.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	The default background color.
 *
 ***********************************************************************/

RGBType		SkinGetBackgroundColor	(void)
{
	return gCurrentSkin.fBackgroundColor;
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetHighlightColor
 *
 * DESCRIPTION:	Return the default highlight color for the current
 *				skin.
 *
 * PARAMETERS:	None.
 *
 * RETURNED:	The default highlight color.
 *
 ***********************************************************************/

RGBType		SkinGetHighlightColor	(void)
{
	return gCurrentSkin.fHighlightColor;
}


/***********************************************************************
 *
 * FUNCTION:	SkinTestPoint
 *
 * DESCRIPTION:	Tests the given point to see what skin element it's over.
 *
 * PARAMETERS:	pt - location in the window to test.
 *
 * RETURNED:	If the point is within an element, returns the id for
 *				that element.  If an element was just missed, returns
 *				kElement_None.  Otherwise, returns kElement_Frame.
 *
 ***********************************************************************/

SkinElementType	SkinTestPoint		(const PointType& pt)
{	
	// See if we hit an element.  PrvTestPoint will return either the
	// element hit or kElement_Frame if none were hit.  If an element
	// was hit, return it.

	SkinElementType	result = ::PrvTestPoint (pt, 0);

	if (result != kElement_Frame)
		return result;

	// Test again, this time allowing for some slop around the
	// elements.  If an element was hit this time, then we hit the
	// small "dead area" we allow around the elements.  In that case,
	// we want to return kElement_None.  Otherwise, if no element was
	// hit, signal that the frame was hit.

	result = ::PrvTestPoint (pt, 5);
	if (result != kElement_Frame)
		return kElement_None;

	return kElement_Frame;
}


/***********************************************************************
 *
 * FUNCTION:	SkinWindowToTouchscreen
 *
 * DESCRIPTION:	Convert a point from window coordinates to LCD
 *				coordinates.
 *
 * PARAMETERS:	pt - point in window coordinates to convert.
 *
 * RETURNED:	The point in LCD coordinates (where the topleft corner
 *				of the LCD is 0,0 and the scale is 1x).
 *
 ***********************************************************************/

PointType		SkinWindowToTouchscreen		(const PointType& pt)
{
	PointType	result = pt;

	RectangleType	r = ::SkinGetElementRect (kElement_Touchscreen);

	result.x -= r.topLeft.x;
	result.y -= r.topLeft.y;

	if (result.x < 0)
		result.x = 0;
	
	if (result.y < 0)
		result.y = 0;
	
	if (result.x >= r.extent.x)
		result.x = r.extent.x - 1;
	
	if (result.y >= r.extent.y)
		result.y = r.extent.y - 1;

	result = ::SkinScaleDown (result);

	return result;
}


/***********************************************************************
 *
 * FUNCTION:	SkinLCDToWindow
 *
 * DESCRIPTION:	Convert a point from LCD coordinates to window
 *				coordinates.
 *
 * PARAMETERS:	pt - point in LCD coordinates to convert.
 *
 * RETURNED:	The point in window coordinates (where the topleft
 *				corner of the window is 0,0 and the scale is the
 *				scale chosen by the user).
 *
 ***********************************************************************/

PointType		SkinTouchscreenToWindow		(const PointType& lcdPt)
{
	PointType	result = lcdPt;

	RectangleType	r = ::SkinGetElementRect (kElement_Touchscreen);

	result.x += r.topLeft.x;
	result.y += r.topLeft.y;

	return result;
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetElementRect
 *
 * DESCRIPTION:	Get the bounds of the given element.
 *
 * PARAMETERS:	which - element we're querying.
 *
 * RETURNED:	Rectangle of the element's bounds.
 *
 ***********************************************************************/

RectangleType	SkinGetElementRect	(SkinElementType which)
{
	ButtonBoundsList::iterator	iter = gCurrentSkin.fButtons.begin ();
	while (iter != gCurrentSkin.fButtons.end ())
	{
		if (iter->fButton == which)
		{
			RectangleType	result = iter->fBounds;
			result = ::SkinScaleUp (result);
			return result;
		}

		++iter;
	}

	assert (false);

	RectangleType	dummy;
	return dummy;
}


/***********************************************************************
 *
 * FUNCTION:	SkinGetAbsElementRect
 *
 * DESCRIPTION:	Get the bounds of the given element.
 *
 * PARAMETERS:	which - element we're querying.
 *
 * RETURNED:	Rectangle of the element's bounds.
 *
 ***********************************************************************/

AbsRectType		SkinGetAbsElementRect	(SkinElementType which)
{
	AbsRectType		result;
	RectangleType	r = ::SkinGetElementRect (which);

	result.left		= r.topLeft.x;
	result.top		= r.topLeft.y;
	result.right	= r.topLeft.x + r.extent.x;
	result.bottom	= r.topLeft.y + r.extent.y;

	return result;
}


/***********************************************************************
 *
 * FUNCTION:	SkinScaleDown
 *
 * DESCRIPTION:	Convert a point from 1x or 2x to just 1x.
 *
 * PARAMETERS:	pt - point to change.
 *
 * RETURNED:	Normalized point.
 *
 ***********************************************************************/

PointType	SkinScaleDown	(const PointType& pt)
{
	PointType	result =
	{
		pt.x / gCurrentScale,
		pt.y / gCurrentScale
	};

#if 0
	// Note: I used to do it this way, but this runs afoul of a code
	// generation bug when using egcs 1.1.2 for x86 -- the y coordinate
	// gets trashed.

	result.x			/= gCurrentScale;
	result.y			/= gCurrentScale;
#endif

	return result;
}


RectangleType	SkinScaleDown	(const RectangleType& r)
{
	RectangleType	result = r;

	result.topLeft.x	/= gCurrentScale;
	result.topLeft.y	/= gCurrentScale;
	result.extent.x		/= gCurrentScale;
	result.extent.y		/= gCurrentScale;

	return result;
}


AbsRectType	SkinScaleDown	(const AbsRectType& r)
{
	AbsRectType	result = r;

	result.left			/= gCurrentScale;
	result.top			/= gCurrentScale;
	result.right		/= gCurrentScale;
	result.bottom		/= gCurrentScale;

	return result;
}


/***********************************************************************
 *
 * FUNCTION:	SkinScaleUp
 *
 * DESCRIPTION:	Convert a point to 1x or 2x, depending on the scaling
 *				factor.
 *
 * PARAMETERS:	pt - point to change.
 *
 * RETURNED:	Denormalized point.
 *
 ***********************************************************************/

PointType	SkinScaleUp	(const PointType& pt)
{
	PointType	result =
	{
		pt.x * gCurrentScale,
		pt.y * gCurrentScale
	};

	return result;
}


RectangleType	SkinScaleUp	(const RectangleType& r)
{
	RectangleType	result = r;

	result.topLeft.x	*= gCurrentScale;
	result.topLeft.y	*= gCurrentScale;
	result.extent.x		*= gCurrentScale;
	result.extent.y		*= gCurrentScale;

	return result;
}


AbsRectType	SkinScaleUp	(const AbsRectType& r)
{
	AbsRectType	result = r;

	result.left			*= gCurrentScale;
	result.top			*= gCurrentScale;
	result.right		*= gCurrentScale;
	result.bottom		*= gCurrentScale;

	return result;
}


/***********************************************************************
 *
 * FUNCTION:	PrvBuildSkinList
 *
 * DESCRIPTION:	Create the full list of skins known to the emulator.
 *				This list of skins includes both the built-in ones and
 *				any found on disk.
 *
 * PARAMETERS:	skins - receives the list of skins.  The list of skins
 *					is *added* to this collection; it is not cleared
 *					out first.
 *
 * RETURNED:	Nothing.
 *
 ***********************************************************************/

ButtonBounds kPilotButtons [] =
{
	{ kElement_PowerButton,		{ {   5, 287 }, {  14,  22 } } },
	{ kElement_UpButton,		{ { 104, 285 }, {  26,  12 } } },
	{ kElement_DownButton,		{ { 104, 307 }, {  26,  12 } } },
	{ kElement_App1Button,		{ {  30, 285 }, {  25,  25 } } },
	{ kElement_App2Button,		{ {  68, 285 }, {  25,  25 } } },
	{ kElement_App3Button,		{ { 139, 285 }, {  25,  25 } } },
	{ kElement_App4Button,		{ { 178, 285 }, {  25,  25 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  37,  39 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  37,  39 }, { 160, 160 } } }
};

ButtonBounds kPalmPilotButtons [] =
{
	{ kElement_PowerButton,		{ {   5, 287 }, {  14,  22 } } },
	{ kElement_UpButton,		{ { 104, 285 }, {  26,  12 } } },
	{ kElement_DownButton,		{ { 104, 307 }, {  26,  12 } } },
	{ kElement_App1Button,		{ {  30, 285 }, {  25,  25 } } },
	{ kElement_App2Button,		{ {  68, 285 }, {  25,  25 } } },
	{ kElement_App3Button,		{ { 139, 285 }, {  25,  25 } } },
	{ kElement_App4Button,		{ { 178, 285 }, {  25,  25 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  37,  39 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  37,  39 }, { 160, 160 } } }
};

ButtonBounds kPalmIIIButtons [] =
{
	{ kElement_PowerButton,		{ {  10, 295 }, {  16,  24 } } },
	{ kElement_UpButton,		{ { 110, 292 }, {  20,  21 } } },
	{ kElement_DownButton,		{ { 110, 313 }, {  20,  21 } } },
	{ kElement_App1Button,		{ {  37, 295 }, {  23,  25 } } },
	{ kElement_App2Button,		{ {  76, 297 }, {  23,  25 } } },
	{ kElement_App3Button,		{ { 141, 297 }, {  23,  25 } } },
	{ kElement_App4Button,		{ { 180, 294 }, {  23,  25 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  39,  44 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  39,  44 }, { 160, 160 } } }
};

ButtonBounds kPalmIIIxButtons [] =
{
	{ kElement_PowerButton,		{ {  10, 295 }, {  16,  24 } } },
	{ kElement_UpButton,		{ { 110, 292 }, {  20,  21 } } },
	{ kElement_DownButton,		{ { 110, 313 }, {  20,  21 } } },
	{ kElement_App1Button,		{ {  37, 295 }, {  23,  25 } } },
	{ kElement_App2Button,		{ {  76, 297 }, {  23,  25 } } },
	{ kElement_App3Button,		{ { 141, 297 }, {  23,  25 } } },
	{ kElement_App4Button,		{ { 180, 294 }, {  23,  25 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  39,  44 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  39,  44 }, { 160, 160 } } }
};

ButtonBounds kPalmVButtons [] =
{
	{ kElement_PowerButton,		{ { 173,   0 }, {  27,  11 } } },
	{ kElement_UpButton,		{ { 105, 283 }, {  25,  21 } } },
	{ kElement_DownButton,		{ { 105, 304 }, {  25,  21 } } },
	{ kElement_App1Button,		{ {  28, 285 }, {  22,  18 } } },
	{ kElement_App2Button,		{ {  68, 292 }, {  22,  18 } } },
	{ kElement_App3Button,		{ { 143, 292 }, {  22,  18 } } },
	{ kElement_App4Button,		{ { 183, 285 }, {  22,  18 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {  30,   0 }, {  22,  11 } } },
	{ kElement_Touchscreen,		{ {  36,  38 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  36,  38 }, { 160, 160 } } }
};

ButtonBounds kPalmVIIButtons [] =
{
	{ kElement_PowerButton,		{ {  10, 333 }, {  16,  24 } } },
	{ kElement_UpButton,		{ { 110, 329 }, {  20,  21 } } },
	{ kElement_DownButton,		{ { 110, 350 }, {  20,  21 } } },
	{ kElement_App1Button,		{ {  37, 332 }, {  23,  25 } } },
	{ kElement_App2Button,		{ {  76, 334 }, {  23,  25 } } },
	{ kElement_App3Button,		{ { 141, 334 }, {  23,  25 } } },
	{ kElement_App4Button,		{ { 180, 331 }, {  23,  25 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  39,  72 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  39,  72 }, { 160, 160 } } }
};

ButtonBounds kColorDevButtons [] =
{
	{ kElement_PowerButton,		{ {   1, 274 }, {  16,  24 } } },
	{ kElement_UpButton,		{ {  96, 272 }, {  32,  16 } } },
	{ kElement_DownButton,		{ {  96, 293 }, {  32,  16 } } },
	{ kElement_App1Button,		{ {  23, 270 }, {  32,  32 } } },
	{ kElement_App2Button,		{ {  60, 270 }, {  32,  32 } } },
	{ kElement_App3Button,		{ { 131, 270 }, {  32,  32 } } },
	{ kElement_App4Button,		{ { 168, 270 }, {  32,  32 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  32,  32 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  32,  32 }, { 160, 160 } } }
};

ButtonBounds kSymbol1740Buttons [] =
{
	{ kElement_PowerButton,		{ {  45, 460 }, {  16,  24 } } },
	{ kElement_PowerButton,		{ { 215, 460 }, {  16,  24 } } },
	{ kElement_UpButton,		{ {  50,  46 }, {  24,  38 } } },
	{ kElement_UpButton,		{ { 200,  46 }, {  24,  38 } } },
	{ kElement_DownButton,		{ {  37,  82 }, {  20,  28 } } },
	{ kElement_DownButton,		{ { 218,  82 }, {  20,  28 } } },
	{ kElement_App1Button,		{ {  67, 416 }, {  20,  30 } } },
	{ kElement_App2Button,		{ { 107, 427 }, {  20,  30 } } },
	{ kElement_App3Button,		{ { 147, 427 }, {  20,  30 } } },
	{ kElement_App4Button,		{ { 187, 416 }, {  20,  30 } } },
	{ kElement_CradleButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Antenna,			{ {   0,   0 }, {   0,   0 } } },
	{ kElement_ContrastButton,	{ {   0,   0 }, {   0,   0 } } },
	{ kElement_Touchscreen,		{ {  60, 149 }, { 160, 220 } } },
	{ kElement_LCD,				{ {  60, 149 }, { 160, 160 } } }
};

static RGBType	kDefaultBackgroundColor	(0x7B, 0x8C, 0x5A);
static RGBType	kDefaultHighlightColor	(0x64, 0xF0, 0xDC);
static RGBType	kAlmostWhiteColor		(0xF7, 0xF7, 0xF7);
static RGBType	kWhiteColor				(0xFF, 0xFF, 0xFF);
static RGBType	kBlackColor				(0x00, 0x00, 0x00);

void PrvBuildSkinList (SkinList& skins)
{
// -*- NEW DEVICE -*-

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "Pil500016";
		skin.fImageName2x = "Pil500032";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePilot1000);
		skin.fDevices.push_back (kDevicePilot5000);
		for (size_t ii = 0; ii < countof (kPilotButtons); ++ii)
			skin.fButtons.push_back (kPilotButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "PilPro16";
		skin.fImageName2x = "PilPro32";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmPilotPersonal);
		skin.fDevices.push_back (kDevicePalmPilotProfessional);
		skin.fDevices.push_back (kDevicePalmPilotWithUpgrade);
		for (size_t ii = 0; ii < countof (kPalmPilotButtons); ++ii)
			skin.fButtons.push_back (kPalmPilotButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "Palm316";
		skin.fImageName2x = "Palm332";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmIII);
		for (size_t ii = 0; ii < countof (kPalmIIIButtons); ++ii)
			skin.fButtons.push_back (kPalmIIIButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "Palm3x16";
		skin.fImageName2x = "Palm3x32";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmIIIx);
		for (size_t ii = 0; ii < countof (kPalmIIIxButtons); ++ii)
			skin.fButtons.push_back (kPalmIIIxButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Japanese";
		skin.fImageName1x = "IBMWP16";
		skin.fImageName2x = "IBMWP32";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmIIIx);
		for (size_t ii = 0; ii < countof (kPalmIIIxButtons); ++ii)
			skin.fButtons.push_back (kPalmIIIxButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "Palm516";
		skin.fImageName2x = "Palm532";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmV);
		for (size_t ii = 0; ii < countof (kPalmVButtons); ++ii)
			skin.fButtons.push_back (kPalmVButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Japanese";
		skin.fImageName1x = "IBMWPc316";
		skin.fImageName2x = "IBMWPc332";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmV);
		for (size_t ii = 0; ii < countof (kPalmVButtons); ++ii)
			skin.fButtons.push_back (kPalmVButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "Palm716";
		skin.fImageName2x = "Palm732";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmVII);
		skin.fDevices.push_back (kDevicePalmVIIEZ);
		for (size_t ii = 0; ii < countof (kPalmVIIButtons); ++ii)
			skin.fButtons.push_back (kPalmVIIButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Default";
		skin.fImageName1x = "ColorDev16";
		skin.fImageName2x = "ColorDev32";
		skin.fBackgroundColor = kAlmostWhiteColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDeviceAustin);
		for (size_t ii = 0; ii < countof (kColorDevButtons); ++ii)
			skin.fButtons.push_back (kColorDevButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Japanese";
		skin.fImageName1x = "IBMWP16";
		skin.fImageName2x = "IBMWP32";
		skin.fBackgroundColor = kAlmostWhiteColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDeviceAustin);
		for (size_t ii = 0; ii < countof (kPalmIIIxButtons); ++ii)
			skin.fButtons.push_back (kPalmIIIxButtons[ii]);
		skins.push_back (skin);
	}

	{
		Skinfo	skin;
		skin.fName = "Symbol 1740";
		skin.fImageName1x = "Sym174016";
		skin.fImageName2x = "Sym174032";
		skin.fBackgroundColor = kDefaultBackgroundColor;
		skin.fHighlightColor = kDefaultHighlightColor;
		skin.fDevices.push_back (kDevicePalmIII);
		for (size_t ii = 0; ii < countof (kSymbol1740Buttons); ++ii)
			skin.fButtons.push_back (kSymbol1740Buttons[ii]);
		skins.push_back (skin);
	}
}


/***********************************************************************
 *
 * FUNCTION:	PrvGetSkins
 *
 * DESCRIPTION:	Get the list of available skins for the given device.
 *
 * PARAMETERS:	type - the device for which the list of skins should
 *					be returned.  If kDeviceUnspecified, return all
 *					skins for all devices.
 *
 *				results - receives the list of skins.  Any skins are
 *					*added* to this list; the list is not cleared out
 *					first.
 *
 * RETURNED:	Nothing
 *
 ***********************************************************************/

void PrvGetSkins (DeviceType type, SkinList& results)
{
	SkinList	fullSkinList;
	::PrvBuildSkinList (fullSkinList);

	SkinList::iterator	iter = fullSkinList.begin ();
	while (iter != fullSkinList.end ())
	{
		if (type == kDeviceUnspecified ||
			find (iter->fDevices.begin (), iter->fDevices.end (), type) != iter->fDevices.end ())
		{
			results.push_back (*iter);
		}

		++iter;
	}
}


/***********************************************************************
 *
 * FUNCTION:    PrvGetNamedSkin
 *
 * DESCRIPTION: Find the Skinfo for the given device and that has the
 *				given name.
 *
 * PARAMETERS:  type - the device whose skin we're looking for.
 *
 *				name - the name of the skin to find.
 *
 *				result - reference to the Skinfo in which to place the
 *					found skin information, if any.
 *
 * RETURNED:    True if the skin could be found, false othewise.
 *
 ***********************************************************************/

Bool PrvGetNamedSkin (DeviceType type, const SkinName& name, Skinfo& result)
{
	SkinList	skins;
	::PrvGetSkins (type, skins);

	SkinList::iterator	iter = skins.begin();
	assert (iter != skins.end ());

	Skinfo		skin = *iter;	// Default to the built-in skin

	while (iter != skins.end ())
	{
		if (iter->fName == name)
		{
			result = *iter;
			return true;
		}

		++iter;
	}

	return false;
}


/***********************************************************************
 *
 * FUNCTION:    PrvGetDefaultSkin
 *
 * DESCRIPTION: Return default skin information for the given device.
 *				This function returns information in the case that
 *				a skin with a desired name could not be found.
 *
 * PARAMETERS:  type - the device whose default skin information we want.
 *
 *				skin - reference to the Skinfo in which to place the
 *					default skin information.
 *
 * RETURNED:    Nothing
 *
 ***********************************************************************/

void PrvGetDefaultSkin (DeviceType type, Skinfo& skin)
{
	SkinList	skins;
	::PrvGetSkins (type, skins);

	skin = skins[0];
}


/***********************************************************************
 *
 * FUNCTION:	PrvValidSkin
 *
 * DESCRIPTION:	Returns whether the given device has a skin with the
 *				given name.
 *
 * PARAMETERS:	type - the device type.
 *
 *				skinName - the skin name.
 *
 * RETURNED:	True if the given device has a skin with the given name.
 *				False otherwise.
 *
 ***********************************************************************/

Bool PrvValidSkin (DeviceType type, const SkinName& skinName)
{
	SkinNameList	skins;
	::SkinGetSkinNames (type, skins);

	SkinNameList::iterator	iter = skins.begin ();
	while (iter != skins.end ())
	{
		if (*iter == skinName)
		{
			return true;
		}

		++iter;
	}

	return false;
}


/***********************************************************************
 *
 * FUNCTION:	PrvTestPoint
 *
 * DESCRIPTION:	Test the given point against all of the skin elements.
 *				An optional outset value can be provided which is
 *				used to modify the element bounds before they are
 *				tested.
 *
 * PARAMETERS:	pt - window location to test.
 *
 *				outset - outset value to apply to the bounds of all
 *					the skin elements.
 *
 * RETURNED:	If one contains the given point, return that skin
 *				element.  Otherwise, return kElement_Frame.
 *
 ***********************************************************************/

SkinElementType	PrvTestPoint (const PointType& pt, int outset)
{
	ButtonBoundsList::iterator	iter = gCurrentSkin.fButtons.begin ();
	while (iter != gCurrentSkin.fButtons.end ())
	{
		RectangleType	bounds = iter->fBounds;
		bounds = ::SkinScaleUp (bounds);

		AbsRectType		r;

		r.left = bounds.topLeft.x - outset;
		r.top = bounds.topLeft.y - outset;
		r.right = bounds.topLeft.x + bounds.extent.x + outset;
		r.bottom = bounds.topLeft.y + bounds.extent.y + outset;

		if (::PrvPtInRect (pt, r))
			return iter->fButton;

		++iter;
	}

	return kElement_Frame;
}


/***********************************************************************
 *
 * FUNCTION:	PrvPtInRect
 *
 * DESCRIPTION:	Test if the given point is within the given rectangle.
 *
 * PARAMETERS:	pt - point to test.
 *
 *				r - rectangle to test against.
 *
 * RETURNED:	True if the point is within the rectangle, using a
 *				half-open interval.  False otherwise.
 *
 ***********************************************************************/

Bool	PrvPtInRect		(const PointType& pt, const AbsRectType& r)
{
	return
		pt.x >= r.left &&
		pt.y >= r.top &&
		pt.x < r.right &&
		pt.y < r.bottom;
}