File: hires.c

package info (click to toggle)
plucker 1.8-34
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 21,340 kB
  • sloc: ansic: 47,691; cpp: 42,310; python: 17,043; makefile: 1,521; perl: 1,492; pascal: 1,123; sh: 474; sed: 64; java: 13; csh: 6
file content (971 lines) | stat: -rw-r--r-- 24,233 bytes parent folder | download | duplicates (4)
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
/*
 * $Id: hires.c,v 1.71 2004/04/29 01:52:05 prussar Exp $
 *
 * Viewer - a part of Plucker, the free off-line HTML viewer for PalmOS
 * Copyright (c) 1998-2002, Mark Ian Lillywhite and Michael Nordstrom
 *
 * 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.
 *
 */

#include <Core/Hardware/HwrMiscFlags.h>

#include "debug.h"
#include "dimensions.h"
#include "font.h"
#include "fullscreenform.h"
#include "os.h"
#include "prefsdata.h"
#include "resourceids.h"
#include "DIA.h"
#include "util.h"
#include "const.h"

#include "hires.h"


/***********************************************************************
 *
 *      Internal Constants
 *
 ***********************************************************************/
#define HIGH_DENSITY_FEATURE_SET_VERSION        4
#define MAX_BITMAP_SIZE                         64000


/***********************************************************************
 *
 *      Local functions
 *
 ***********************************************************************/
static void DetectAcerS50OrS60( void ) HIRES_SECTION;
static void AdjustCoordStandardToNative( Coord* coord ) HIRES_SECTION;
static void AdjustBoundsStandardToNative( RectangleType* r ) HIRES_SECTION;
static Boolean PalmHiResSupported( void ) HIRES_SECTION;
static Err PalmHiResInitialize( void ) HIRES_SECTION;
static Err PalmHiResStop( void ) HIRES_SECTION;
static Boolean SonyHiResSupported( void ) HIRES_SECTION;
static Err SonyHiResInitialize( void ) HIRES_SECTION;
static Err SonyHiResStop( void ) HIRES_SECTION;
static Boolean HanderaHiResSupported( void ) HIRES_SECTION;
static Err HanderaHiResInitialize( void ) HIRES_SECTION;
static Err HanderaHiResStop( void ) HIRES_SECTION;
static void HiResUpdateMargins( void ) HIRES_SECTION;

/* duplicate functions to the original system trap call */
extern UInt16 FrmAlertSysTrap( UInt16 alertID ) SYS_TRAP( sysTrapFrmAlert );
extern UInt16 FrmCustomAlertSysTrap( UInt16 alertID, const Char* s1,
           const Char* s2, const Char* s3 ) SYS_TRAP( sysTrapFrmCustomAlert );



/***********************************************************************
 *
 *      Private variables
 *
 ***********************************************************************/

static UInt16 sonyHiResRefNum = NULL;

static HiRes hiResType = unknownHiRes;

static UInt16 nativeDensity  = kDensityLow;

static Boolean isAcerS50OrS60 = false;

static Margins hiResMargins;

static WidthsType palmHiResWidths[ NUM_ROTATE_TYPES ] = {
    { SCROLLBAR_WIDTH_HIRES_PALM, TOOLBAR_HEIGHT_HIRES_PALM,
          { TOP_MARGIN_HIRES_PALM, BOTTOM_MARGIN_HIRES_PALM,
            LEFT_MARGIN_HIRES_PALM, RIGHT_MARGIN_HIRES_PALM } }
#ifdef HAVE_ROTATE
    ,
    { SCROLLBAR_WIDTH_HIRES_PALM,
          TOOLBAR_HEIGHT_HIRES_PALM ,
          { LEFT_MARGIN_HIRES_PALM, RIGHT_MARGIN_HIRES_PALM, 0, 0 } },
    { SCROLLBAR_WIDTH_HIRES_PALM,
          TOOLBAR_HEIGHT_HIRES_PALM,
          { RIGHT_MARGIN_HIRES_PALM, LEFT_MARGIN_HIRES_PALM, 0, 0 } }
#endif
};

static WidthsType sonyHiResWidths[ NUM_ROTATE_TYPES ] = {
    { SCROLLBAR_WIDTH_HIRES_SONY, TOOLBAR_HEIGHT_HIRES_SONY,
          { TOP_MARGIN_HIRES_SONY, BOTTOM_MARGIN_HIRES_SONY,
            LEFT_MARGIN_HIRES_SONY, RIGHT_MARGIN_HIRES_SONY } }
#ifdef HAVE_ROTATE
    ,
    { SCROLLBAR_WIDTH_HIRES_SONY,
          TOOLBAR_HEIGHT_HIRES_SONY,
          { LEFT_MARGIN_HIRES_SONY, RIGHT_MARGIN_HIRES_SONY, 0, 0 } },
    { SCROLLBAR_WIDTH_HIRES_SONY,
          TOOLBAR_HEIGHT_HIRES_SONY,
          { RIGHT_MARGIN_HIRES_SONY, LEFT_MARGIN_HIRES_SONY, 0, 0 } }
#endif
};

static WidthsType handeraHiResWidths[ NUM_ROTATE_TYPES ] = {
    { SCROLLBAR_WIDTH_HIRES_HANDERA, TOOLBAR_HEIGHT_HIRES_HANDERA,
          { TOP_MARGIN_HIRES_HANDERA, BOTTOM_MARGIN_HIRES_HANDERA,
            LEFT_MARGIN_HIRES_HANDERA, RIGHT_MARGIN_HIRES_HANDERA } }
#ifdef HAVE_ROTATE
    ,
    { SCROLLBAR_WIDTH_HIRES_HANDERA,
          TOOLBAR_HEIGHT_HIRES_HANDERA,
          { LEFT_MARGIN_HIRES_HANDERA, RIGHT_MARGIN_HIRES_HANDERA, 0, 0 } },
    { SCROLLBAR_WIDTH_HIRES_HANDERA,
          TOOLBAR_HEIGHT_HIRES_HANDERA,
          { RIGHT_MARGIN_HIRES_HANDERA, LEFT_MARGIN_HIRES_HANDERA, 0, 0 } }
#endif
};




/* Since the palm still only accepts incoming events in a 160x160 screen,
   we need to translate them to the hires equivilant to handle our clicks
   properly. Except for elements such as the toolbar and scrollbar which
   still need to be in 'lowres' values in order to accept events. */
void TranslateHiResPenEvents
    (
    EventType* event  /* pointer t an EventType structure */
    )
{
    Int16 topLeftX;
    Int16 topLeftY;
    Int16 extentX;
    Int16 extentY;

    /* This is only necessary for sony and palm hires */
    if ( ( ! IsHiResTypeSony( hiResType ) &&
           ! IsHiResTypePalm( hiResType ) ) ||
         IsFullscreenformActive() )
        return;

    if ( IsHiResTypePalm( hiResType ) ) {
        if ( isAcerS50OrS60 ) {
            /* Fixes an apparent bug in Acer S60 (and presumably S50)
               handling of EvtGetPenNative().  Acer S50/S60 POSE ROM
               and SDK are apparently no longer available, so this is
               done empirically thanks to a helpful user.  It may not
               be the ideal solution. */
            event->screenX *= 2;
            event->screenY *= 2;
        }
        else {
            EvtGetPenNative( WinGetActiveWindow(), &( event->screenX ),
                &( event->screenY ), &( event->penDown ) );
        }    
    }
    else {
        topLeftX = TopLeftX() / 2;
        topLeftY = TopLeftY() / 2;
        extentX = ExtentX() / 2;
        extentY = ExtentY() / 2;

        /* Multiply our pen events by two to emulate the hires screen */
        if ( topLeftY < event->screenY &&
             event->screenY < ( topLeftY + extentY ) &&
             topLeftX < event->screenX &&
             event->screenX < ( topLeftX + extentX ) ) {
            event->screenX *= 2;
            event->screenY *= 2;
        }
    }
}




/* Convert a standard image into a higher nativeDensity version of itself */
Boolean ConvertImageToV3
    (
    BitmapType** imagePtr   /* Pointer to a pointer to a BitmapType */
    )
{
    BitmapTypeV3* imagePtrV3;

    if ( ! IsHiResTypePalm( hiResType ) )
        return false;

    imagePtrV3 = BmpCreateBitmapV3( *imagePtr, nativeDensity,
        BmpGetBits( *imagePtr ), NULL );

    if ( imagePtrV3 == NULL )
        return false;

    *imagePtr = (BitmapType*) imagePtrV3;

    return true;
}



/* General WinDrawBitmap() routine.  Works for OS5, Sony, etc. */
void GeneralWinDrawBitmap
        (
        BitmapType* bitmap,
        Coord       x,
        Coord       y
        )
{
    Boolean       converted;
    converted = ConvertImageToV3( &bitmap );
    WinDrawBitmap( bitmap, x, y );
    if ( converted )
        BmpDelete( bitmap );
}



/* set the hardware-specific functions to their usable counterparts */
void SetHiResFunctions( void )
{
    if ( IsHiResTypePalm( hiResType ) ) {
        TopLeftX       = PalmTopLeftX;
        TopLeftY       = PalmTopLeftY;
        ExtentX        = PalmExtentX;
        ExtentY        = PalmExtentY;
        HiResStop      = PalmHiResStop;
        UpdateMargins  = HiResUpdateMargins;
    }
    else if ( IsHiResTypeSony( hiResType ) ) {
        TopLeftX       = NonPalmHiResTopLeftX;
        TopLeftY       = NonPalmHiResTopLeftY;
        ExtentX        = NonPalmHiResExtentX;
        ExtentY        = NonPalmHiResExtentY;
        HiResStop      = SonyHiResStop;
        UpdateMargins  = HiResUpdateMargins;
    }
    else if ( IsHiResTypeHandera( hiResType ) ) {
        TopLeftX       = NonPalmHiResTopLeftX;
        TopLeftY       = NonPalmHiResTopLeftY;
        ExtentX        = NonPalmHiResExtentX;
        ExtentY        = NonPalmHiResExtentY;
        HiResStop      = HanderaHiResStop;
        UpdateMargins  = HiResUpdateMargins;
    }
    else {
        SetStandardFunctions();
    }
}



/* Is this an Acer S50/S60? */
void DetectAcerS50OrS60( void )
{
    Err err;
    UInt32  deviceID;
    UInt32  manufacturerID;
    isAcerS50OrS60 = false;
    err = FtrGet( sysFtrCreator, sysFtrNumOEMCompanyID, &manufacturerID );
    if ( err == errNone && manufacturerID == acerS50OrS60ManufacturerID ) {
        err = FtrGet( sysFtrCreator, sysFtrNumOEMDeviceID, &deviceID );
        if ( err == errNone && deviceID == acerS50OrS60DeviceID )
            isAcerS50OrS60 = true;
    }
}



/* call the system-dependant initilization procedures */
Err HiResInitialize( void )
{
    Err err;

    /* It's important to note whats going on here with Palm and Sony hires
       devices. We're explicitly checking checking for Palm hires before Sony
       because we want to support the newer OS5-based Sony devices within
       PalmSource's API, not Sony's.

       Sony's OS5 devices do support both APIs but the PalmSource version has
       been deemed the new standard for hires. Partially as a result, Sony's
       OS5 devices actually support hires better under the new standard then
       their own API. Generally speaking both Palm and Sony recommend you only
       use the Sony API under Sony OS4 and earlier devices.

       Basically hiResType will never resolve to sonyHiRes even on an OS5 Sony
       device */
    err = errNoHiRes;
    if ( PalmHiResSupported() ) {
        hiResType   = palmHiRes;
        err         = PalmHiResInitialize();
        DetectAcerS50OrS60();
    }
    else if ( SonyHiResSupported() ) {
        hiResType   = sonyHiRes;
        err         = SonyHiResInitialize();
    }
    else if ( HanderaHiResSupported() ) {
        hiResType   = handeraHiRes;
        err         = HanderaHiResInitialize();
    }

    if ( err != errNone ) {
        hiResType = noHiRes;
    }


    return err;
}



/* return what type of hires support is active */
HiRes HiResType( void )
{
    return hiResType;
}



void HiResAdjust
    (
    Coord* i,
    UInt16 type
    )
{
    if ( ( type & hiResType ) != 0 )
        AdjustCoordStandardToNative( i );
}



void HiResAdjustCurrentToNative
     (
     Coord* x
     )
{
    if ( ! IsHiResTypePalm( hiResType ) ||
         WinGetCoordinateSystem() != STANDARD )
        return;
    AdjustCoordStandardToNative( x );
}




/* Adjust native coordinates to standard if needed.  This may be an
   overestimate. */
void HiResAdjustNativeToCurrent
     (
     Coord* x
     )
{
    if ( ! IsHiResTypePalm( hiResType ) ||
         WinGetCoordinateSystem() != STANDARD )
        return;
    switch ( nativeDensity ) {
        case kDensityOneAndAHalf:
            *x = ( ( *x ) * 2 + 2 ) / 3;
            break;
        case kDensityDouble:
            *x = ( ( *x ) + 1 ) / 2;
            break;
        case kDensityTriple:
            *x = ( ( *x ) + 2 ) / 3;
            break;
        case kDensityQuadruple:
            *x = ( ( *x ) + 3 ) / 4;
            break;
        default:
            break;
    }
    return;
}




void HiResAdjustBounds
    (
    RectangleType* r,
    UInt16         type
    )
{
    if ( ( type & hiResType ) != 0 )
        AdjustBoundsStandardToNative( r );
}



/* Convert a coord from kCoordinatesStandard to kCoordinatesNative */
static void AdjustCoordStandardToNative
    (
    Coord* coord
    )
{
    switch ( nativeDensity ) {
        case kDensityOneAndAHalf:
            *coord += *coord / 2;
            break;
        case kDensityDouble:
            *coord *= 2;
            break;
        case kDensityTriple:
            *coord *= 3;
            break;
        case kDensityQuadruple:
            *coord *= 4;
            break;
        default:
            break;
    }
}



/* Convert bounds from kCoordinatesStandard to kCoordinatesDouble */
static void AdjustBoundsStandardToNative
    (
    RectangleType* r
    )
{
    AdjustCoordStandardToNative( &( r->topLeft.x ) );
    AdjustCoordStandardToNative( &( r->topLeft.y ) );
    AdjustCoordStandardToNative( &( r->extent.x ) );
    AdjustCoordStandardToNative( &( r->extent.y ) );
}



/* Identify if we support palm hires */
static Boolean PalmHiResSupported( void )
{
    if ( SupportHighDensity() && kDensityLow != PalmGetDensity() ) {
        MSG( _( "Palm HiRes supported\n" ) );
        return true;
    }
    MSG( _( "Palm HiRes not supported\n" ) );
    return false;
}



/* palm specific hires initialization procedure */
static Err PalmHiResInitialize( void )
{
    Err err;

    if ( IsHiResTypePalm( hiResType ) ) {
        LoadCustomFonts( PALM_FONTS );
        err = errNone;
    }
    else {
        err = errNoHiRes;
    }
    if ( err == errNone ) {
        nativeDensity = PalmGetDensity();
    }
    if ( err == errNone ) {
        /* Looks good, palm hires is available */
        MSG( _( "Palm HiRes initialized\n" ) );
    }
    else {
        MSG( _( "Palm HiRes failed to initialize\n" ) );
    }
    return err;
}



/* Get the nativeDensity. */
UInt16 PalmGetDensity( void )
{
    UInt32 densityValue;
    Err    err;
    err = WinScreenGetAttribute( winScreenDensity,
              &densityValue );
    if ( err == errNone )
        return ( UInt16 ) densityValue;
    else
        return kDensityLow;
}



/* palm specific hires stopping procedure */
static Err PalmHiResStop( void )
{
    /* no longer available, but support remains */
    hiResType     = noHiRes;
    nativeDensity = kDensityLow;
    SetStandardFunctions();
    nativeDensity = kDensityLow;
    return errNone;
}



/* Identify if we support sony hires */
static Boolean SonyHiResSupported( void )
{
#ifdef HAVE_SONY_SDK
    Err                err;
    SonySysFtrSysInfoP sonySysFtrSysInfoP;

    err = FtrGet( sonySysFtrCreator, sonySysFtrNumSysInfoP,
            (UInt32 *) &sonySysFtrSysInfoP );

    /* If we're on a sony system, and have access to the HRLib.. */
    if ( err == errNone &&
         sonySysFtrSysInfoP->libr & sonySysFtrSysInfoLibrHR ) {
        MSG( _( "Sony HiRes supported\n" ) );
        return true;
    }
#endif
    MSG( _( "Sony HiRes not supported\n" ) );
    return false;
}



/* sony specific hires initialization procedure */
static Err SonyHiResInitialize( void )
{
    Err err;

#ifdef HAVE_SONY_SDK
    if ( IsHiResTypeSony( hiResType ) ) {
        err = SysLibFind( sonySysLibNameHR, &sonyHiResRefNum );
        if ( err == sysErrLibNotFound )
            err = SysLibLoad( 'libr', sonySysFileCHRLib, &sonyHiResRefNum );
        if ( err == errNone )
            err = HROpen( sonyHiResRefNum );
    }
    else {
        err = errNoHiRes;
    }

    if ( err == errNone ) {
        /* Looks good, sony hires is available */
        MSG( _( "Sony OS4 HiRes initialized\n" ) );
        LoadCustomFonts( SONY_FONTS );
        nativeDensity = kDensityDouble;
    }
    else {
        err = errNoHiRes; /* just incase HROpen fails */
        sonyHiResRefNum = NULL;
        MSG( _( "Sony HiRes failed to initialize\n" ) );
    }
#else
    sonyHiResRefNum = NULL;
    err = errNoHiRes;
#endif
    return err;
}



/* retrive value of sonyHiResRefNum */
UInt16 SonyHiResRefNum( void )
{
    return sonyHiResRefNum;
}



/* sony specific hires stopping procedure */
static Err SonyHiResStop( void )
{
#ifdef HAVE_SONY_SDK
    if ( sonyHiResRefNum == NULL ) {
        MSG( _( "Sony HiRes doesn't need to be stopped\n" ) );
        return errNoHiRes;
    }
    WinScreenMode( winScreenModeSetToDefaults, NULL, NULL, NULL, NULL );
    HRClose( sonyHiResRefNum );
    sonyHiResRefNum = NULL;
    MSG( _( "Sony HiRes stopped\n" ) );

    /* no longer available, but support remains */
    hiResType     = noHiRes;
    nativeDensity = kDensityLow;
#endif
    SetStandardFunctions();
    return errNone;
}



/* Identify if we support handera hires */
static Boolean HanderaHiResSupported( void )
{
#ifdef HAVE_HANDERA_SDK
    Err    err;
    UInt32 vgaVersion;

    err = FtrGet( TRGSysFtrID, TRGVgaFtrNum, &vgaVersion );

    /* Do something with vgaVersion? */

    if ( err == errNone ) {
        MSG( _( "Handera HiRes supported\n" ) );
        return true;
    }
#endif
    MSG( _( "Handera HiRes not supported\n" ) );
    return false;
}



/* handera specific hires initialization procedure */
static Err HanderaHiResInitialize( void )
{
    Err err;

#ifdef HAVE_HANDERA_SDK
    if ( IsHiResTypeHandera( hiResType ) )
        err = VgaSetScreenMode( screenMode1To1, rotateModeNone );
    else
        err = errNoHiRes;

    if ( err == errNone ) {
        nativeDensity = kDensityOneAndAHalf;
        MSG( _( "Handera HiRes initialized\n" ) );
    }
    else {
        MSG( _( "Handera HiRes not initialized\n" ) );
    }
#else
    err = errNoHiRes;
#endif
    return err;
}



/* handera specific hires stopping procedure */
static Err HanderaHiResStop( void )
{
#ifdef HAVE_HANDERA_SDK
    VgaSetScreenMode( screenModeScaleToFit, rotateModeNone );

    hiResType     = noHiRes;
    nativeDensity = kDensityLow;
    MSG( _( "Handera HiRes stopped\n" ) );
#endif
    SetStandardFunctions();
    return errNone;
}



/* palm version of TopLeftX() */
Int16 PalmTopLeftX( void )
{
    if ( WinGetCoordinateSystem() == NATIVE )
        return hiResMargins.left;
    else
        return StandardTopLeftX();
}



/* palm version of TopLeftY() */
Int16 PalmTopLeftY( void )
{
    if ( WinGetCoordinateSystem() == NATIVE )
        return hiResMargins.top;
    else
        return StandardTopLeftY();
}



/* hi-res version of UpdateMargins() */
void HiResUpdateMargins( void )
{
    if ( NUM_ROTATE_TYPES < Prefs()->rotate )
        Prefs()->rotate = ROTATE_ZERO;
    if ( IsHiResTypePalm( HiResType() ) ) {
        SetMargins( &hiResMargins, &palmHiResWidths[ Prefs()->rotate ] );
        StandardUpdateMargins();
    }
    else if ( IsHiResTypeSony( hiResType ) ) {
        SetMargins( &hiResMargins, &sonyHiResWidths[ Prefs()->rotate ] );
    }
    else if ( IsHiResTypeHandera( hiResType ) ) {
        SetMargins( &hiResMargins, &handeraHiResWidths[ Prefs()->rotate ] );
    }
}



/* palm version of ExtentX() */
Int16 PalmExtentX( void )
{
    if ( WinGetCoordinateSystem() == NATIVE )
        return MaxExtentX() - hiResMargins.right - hiResMargins.left;
    else
        return StandardExtentX();
}



/* palm version of ExtentY() */
Int16 PalmExtentY( void )
{
    if ( WinGetCoordinateSystem() == NATIVE )
        return MaxExtentY() - hiResMargins.top - hiResMargins.bottom;
    else
        return StandardExtentY();
}



/* get the current coordinate system being used for palm hires devices */
UInt16 PalmGetCoordinateSystem( void )
{
    if ( ! IsHiResTypePalm( hiResType ) )
        return STANDARD;

    return WinGetCoordinateSystem();
}



/* set the coordinate system to be used for palm hires devices */
UInt16 PalmSetCoordinateSystem
    (
    UInt16 coordSys
    )
{
    UInt16 prevCoordSys;

    if ( ! IsHiResTypePalm( hiResType ) )
        return STANDARD;

    prevCoordSys = WinSetCoordinateSystem( coordSys );

    UpdateDisplayExtent();

    return prevCoordSys;
}



/* Wrapper function to make sure FrmAlert() always displays properly */
UInt16 PalmStandardCoordFrmAlert
    (
    UInt16 alertID
    )
{
    UInt16 prevCoordSys;
    UInt16 result;

    prevCoordSys = PalmSetCoordinateSystem( STANDARD );
    result = FrmAlertSysTrap( alertID );
    PalmSetCoordinateSystem( prevCoordSys );

    return result;
}



/* Wrapper function to make sure FrmCustomAlert() always displays properly */
UInt16 PalmStandardCoordFrmCustomAlert
    (
    UInt16 alertID,
    const Char* s1,
    const Char* s2,
    const Char* s3
    )
{
    UInt16 prevCoordSys;
    UInt16 result;

    prevCoordSys = PalmSetCoordinateSystem( STANDARD );
    result = FrmCustomAlertSysTrap( alertID, s1, s2, s3 );
    PalmSetCoordinateSystem( prevCoordSys );

    return result;
}



/* non-Palm hi-res version of TopLeftX() */
Int16 NonPalmHiResTopLeftX( void )
{
    return hiResMargins.left;
}



/* non-Palm hi-res version of TopLeftY() */
Int16 NonPalmHiResTopLeftY( void )
{
    return hiResMargins.top;
}



/* non-Palm hi-res version of ExtentX() */
Int16 NonPalmHiResExtentX( void )
{
    return MaxExtentX() - hiResMargins.right - hiResMargins.left;
}



/* non-Palm hi-res version of ExtentY() */
Int16 NonPalmHiResExtentY( void )
{
    return MaxExtentY() - hiResMargins.top - hiResMargins.bottom;
}



/* Font list needs to be converted into VGA-specific fonts at run-time */
void HanderaConvertFontList
    (
    FontID* oldFontList,
    FontID* newFontList
    )
{
#ifdef HAVE_HANDERA_SDK
    UInt16 i;

    if ( IsHiResTypeHandera( hiResType ) ) {
        for ( i = 0; i < MAXSTYLES; i++ ) {
            if ( oldFontList[ i ] != narrowFont &&
                 oldFontList[ i ] != narrowFixedFont )
                newFontList[ i ] = VgaBaseToVgaFont( oldFontList[ i ] );
        }
    }
#endif
}



UInt16 HiResFontImage
    (
    FontID font,
    UInt16 stdImage,
    UInt16 palmHalfImage,
    UInt16 nonPalmDoubleImage
    )
{
    if ( IsHiResTypePalm( hiResType ) &&
         ( font == tinyFont_palm ||
           font == tinyBoldFont_palm ||
           font == smallFont_palm ||
           font == smallBoldFont_palm ||
           font == userStdFont_palm ) )
        return palmHalfImage;
    else
#ifdef HAVE_SONY_SDK
    if ( IsHiResTypeSony( hiResType ) &&
         ( font == hrStdFont ||
           font == hrBoldFont ||
           font == hrLargeFont ||
           font == hrLargeBoldFont ||
           font == userStdFont_sony ) )
        return nonPalmDoubleImage;
    else
#endif
#ifdef HAVE_HANDERA_SDK
    if ( IsHiResTypeHandera( hiResType ) &&
         ( font == VgaBaseToVgaFont( stdFont ) ||
           font == VgaBaseToVgaFont( boldFont ) ||
           font == VgaBaseToVgaFont( largeFont ) ||
           font == VgaBaseToVgaFont( largeBoldFont ) ) )
        return nonPalmDoubleImage;
    else
#endif
        return stdImage;
}



FontID HiResFont
    (
    FontID font
    )
{
    FontID hrFont;

#ifdef HAVE_SONY_SDK
    if ( IsHiResTypeSony( hiResType ) ) {
        switch ( font ) {
            case stdFont:
                hrFont = hrStdFont;
                break;
            case boldFont:
                hrFont = hrBoldFont;
                break;
            case largeFont:
                hrFont = hrLargeFont;
                break;
            case largeBoldFont:
                hrFont = hrLargeBoldFont;
                break;
            case symbolFont:
                hrFont = hrSymbolFont;
                break;
            default:
                hrFont = font;
                break;
        }
    }
    else
#endif
#ifdef HAVE_HANDERA_SDK
    if ( IsHiResTypeHandera( hiResType ) ) {
        hrFont = VgaBaseToVgaFont( font );
    }
    else
#endif
        hrFont = font;

    return hrFont;
}



#ifdef HAVE_SONY_SDK
#undef WinDrawBitmap
#undef WinDrawChars
#undef WinCopyRectangle
void HiResDrawBitmap( BitmapType* bitmapP, Coord x, Coord y )
{
    if ( IsHiResTypeSony( hiResType ) )
        HRWinDrawBitmap( sonyHiResRefNum, bitmapP, x, y );
    else
        WinDrawBitmap( bitmapP, x, y );
}


void HiResDrawChars( const Char* chars, UInt16 len, Coord x, Coord y )
{
    if ( IsHiResTypeSony( hiResType ) )
        HRWinDrawChars( sonyHiResRefNum, chars, len, x, y );
    else
        WinDrawChars( chars, len, x, y );
}

void HiResCopyRectangle( WinHandle srcWin, WinHandle dstWin, RectangleType* srcRect,
     Coord destX, Coord destY, WinDrawOperation mode )
{
    if ( IsHiResTypeSony( hiResType ) )
        HRWinCopyRectangle( sonyHiResRefNum, srcWin, dstWin, srcRect, destX, destY, mode );
    else
        WinCopyRectangle( srcWin, dstWin, srcRect, destX, destY, mode );
}
#endif