~ubuntu-branches/ubuntu/quantal/xdaliclock/quantal

« back to all changes in this revision

Viewing changes to palm/daliclock.c

  • Committer: Bazaar Package Importer
  • Author(s): Aaron Lehmann
  • Date: 2003-12-21 22:19:11 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20031221221911-257w35bqczk4i0l8
Tags: 2.20-1
New upstream version fixes Xinerama problems (Closes: #217684)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Dali Clock - a melting digital clock for the Palm Pilot.
2
 
 * Copyright (c) 1991-1999 Jamie Zawinski <jwz@jwz.org>
 
1
/* Dali Clock - a melting digital clock for PalmOS.
 
2
 * Copyright (c) 1991-2002 Jamie Zawinski <jwz@jwz.org>
3
3
 *
4
4
 * Permission to use, copy, modify, distribute, and sell this software and its
5
5
 * documentation for any purpose is hereby granted without fee, provided that
15
15
# include "config.h"
16
16
#endif
17
17
 
 
18
#ifdef HACK_FRAMEBUFFER
 
19
  /* needed to access WinHandle->displayAddrV20 for ROMs earlier than 3.5 */
 
20
# define ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS
 
21
#endif
 
22
 
18
23
#include "daliclock.h"
19
24
 
20
 
/* Define this so that we get `hwrDisplayWidth' from <Hardware.h>.
21
 
   (We only use that value (which is 160, BTW) with <3.0 ROMs.) */
22
 
#define NON_PORTABLE
23
25
 
24
26
/* Make sure Err*Display* are not no-ops. */
25
27
#define ERROR_CHECK_LEVEL ERROR_CHECK_FULL
26
28
 
27
 
#include <Pilot.h>
28
 
#include <Hardware.h>
 
29
#include <PalmOS.h>
 
30
/*#include <Hardware.h>*/
29
31
#include <FeatureMgr.h>         /* for FtrGet() */
30
32
 
31
33
#ifndef HAVE_APPLAUNCHWITHCOMMAND
35
37
 
36
38
#define ROM_20 0x02003000
37
39
#define ROM_30 0x03003000
 
40
#define ROM_35 0x03503000
38
41
 
39
42
 
40
43
#define SECONDS_ONLY_MODE
57
60
  POS left[MAX_SEGS_PER_LINE], right[MAX_SEGS_PER_LINE];
58
61
};
59
62
 
60
 
typedef VoidHand FrameHandle;
 
63
typedef MemHandle FrameHandle;
61
64
struct frame {
62
65
  struct scanline scanlines [1]; /* scanlines are contiguous here */
63
66
};
76
79
struct state {
77
80
  Boolean inverted_p;
78
81
  Boolean twelve_hour_time_p;
79
 
  int show_date_p;   /* 0 = no, 1 = do, 2 = stop soon */
 
82
  enum date_state { DTime, DDateIn, DDate, DDateOut, DDateOut2, DDash }
 
83
    display_date;
80
84
  char test_hack;
81
85
  int ticks;
82
86
  long interval;
97
101
  signed char current_digits [6];
98
102
  signed char target_digits [6];
99
103
 
100
 
  SWord win_width, win_height;
 
104
  Int16 win_width, win_height;
101
105
};
102
106
 
103
107
 
346
350
static void
347
351
fill_target_digits (struct state *state)
348
352
{
349
 
  ULong seconds = TimGetSeconds ();  /* since 1/1/1904 */
 
353
  UInt32 seconds = TimGetSeconds ();  /* since 1/1/1904 */
350
354
  DateTimeType date;
351
355
 
352
356
  TimSecondsToDateTime (seconds, &date);
362
366
                                    : state->test_hack - '0');
363
367
      state->test_hack = 0;
364
368
    }
365
 
  else if (state->show_date_p == 0)
 
369
  else if (state->display_date == DTime ||
 
370
           state->display_date == DDash)
366
371
    {
367
372
      Boolean twelve_hour_time_p = state->twelve_hour_time_p;
368
373
 
 
374
      if (state->display_date == DDash)
 
375
        state->display_date = DTime;
 
376
 
369
377
      if (twelve_hour_time_p && date.hour > 12) date.hour -= 12;
370
378
      if (twelve_hour_time_p && date.hour == 0) date.hour = 12;
371
379
      state->target_digits [0] = (date.hour - (date.hour % 10)) / 10;
389
397
      y0 = (y0 - (y0 % 10)) / 10;
390
398
      y1 = date.year % 10;
391
399
 
392
 
      if (state->show_date_p == 2)
393
 
        state->show_date_p = 0;
 
400
      if (state->display_date == DDateIn)
 
401
        state->display_date = DDate;
 
402
      if (state->display_date == DDateOut)
 
403
        state->display_date = DDateOut2;
 
404
      else if (state->display_date == DDateOut2)
 
405
        state->display_date = DDash;
394
406
 
395
407
      switch (state->date_format)
396
408
        {
438
450
static void
439
451
cache_frame_buffer (void)
440
452
{
441
 
# ifdef HAVE_SCRDISPLAYMODE
442
 
  static int mono_p = -1;
443
 
 
444
 
  if (mono_p == 0)         /* meaning we know we're not in 1-bit-mode; bail. */
445
 
    return;
446
 
  else if (mono_p == -1)   /* meaning we haven't checked yet */
447
 
    {
448
 
      DWord rom_version = 0;
449
 
      FtrGet (sysFtrCreator, sysFtrNumROMVersion, &rom_version);
450
 
 
451
 
      if (rom_version < ROM_30)  /* ROM earlier than 3.0 -- assume. */
452
 
        {
453
 
          mono_p = 1;
454
 
          frame_buffer_bytes_per_line = hwrDisplayWidth/8;
455
 
        }
456
 
      else
457
 
        {
458
 
          DWord w = 0, h = 0, d = 0;
459
 
          Boolean color = false;
460
 
          ScrDisplayMode (scrDisplayModeGet, &w, &h, &d, &color);
461
 
 
462
 
          mono_p = 0;
463
 
          if (w > 0 && h > 0 && d == 1 && color == false)
464
 
            {
465
 
              mono_p = 1;
466
 
              frame_buffer_bytes_per_line = (w+7) / 8;
467
 
            }
468
 
        }
469
 
    }
470
 
# else  /* !HAVE_SCRDISPLAYMODE */
471
 
 
472
 
  /* Didn't have a 3.0-level library at compile-time -- assume. */
473
 
  frame_buffer_bytes_per_line = hwrDisplayWidth/8;
474
 
 
475
 
# endif /* !HAVE_SCRDISPLAYMODE */
476
 
 
477
 
  /* If we got here, then we believe we're running on a monochrome system,
478
 
     and know how to access the frame buffer directly. */
479
 
 
480
 
  frame_buffer = (unsigned char *) WinGetDisplayWindow()->displayAddr;
 
453
  static int initted_p = 0;
 
454
 
 
455
  if (initted_p) return;
 
456
  initted_p = 1;
 
457
 
 
458
  {
 
459
    UInt32 rom_version = 0;
 
460
    FtrGet (sysFtrCreator, sysFtrNumROMVersion, &rom_version);
 
461
 
 
462
    frame_buffer_bytes_per_line = 0;
 
463
    frame_buffer = 0;
 
464
 
 
465
    if (rom_version < ROM_30)  /* ROM earlier than 3.0 -- assume. */
 
466
      {
 
467
#       ifndef hwrDisplayWidth
 
468
#         define hwrDisplayWidth 160
 
469
#       endif
 
470
        frame_buffer_bytes_per_line = hwrDisplayWidth/8;
 
471
      }
 
472
    else
 
473
      {
 
474
        UInt32 w = 0, h = 0, d = 0;
 
475
        Boolean color = false;
 
476
        WinScreenMode (winScreenModeGet, &w, &h, &d, &color);
 
477
        if (w > 0 && h > 0 && d == 1 && color == false)
 
478
          frame_buffer_bytes_per_line = (w+7) / 8;
 
479
      }
 
480
 
 
481
    if (frame_buffer_bytes_per_line > 0)
 
482
      {
 
483
        WinHandle w = WinGetDisplayWindow();
 
484
 
 
485
        if (!w)
 
486
          ;
 
487
        else if (rom_version < ROM_35)
 
488
          frame_buffer = (unsigned char *) w->displayAddrV20;
 
489
        else
 
490
          { /* functions from "3.5 New Feature Set" */
 
491
            BitmapPtr b = WinGetBitmap (w);
 
492
            frame_buffer = (unsigned char *) (b ? BmpGetBits (b) : 0);
 
493
          }
 
494
      }
 
495
  }
481
496
}
482
497
#endif /* HACK_FRAMEBUFFER */
483
498
 
484
499
 
485
500
static void
486
 
draw_horizontal_line (SWord x1, SWord x2, SWord y, Boolean black_p)
 
501
draw_horizontal_line (Int16 x1, Int16 x2, Int16 y, Boolean black_p)
487
502
{
488
503
  if (x1 == x2)
489
504
    return;
490
505
  else if (x1 > x2)
491
506
    {
492
 
      SWord swap = x1;
 
507
      Int16 swap = x1;
493
508
      x1 = x2;
494
509
      x2 = swap;
495
510
    }
714
729
 
715
730
# define COLON() \
716
731
  if (colonic_p) \
717
 
    draw_frame (state, state->base_frames [state->show_date_p ? 11 : 10], \
 
732
    draw_frame (state, state->base_frames \
 
733
                         [state->display_date == DTime ? 10 : 11], \
718
734
                x, y); \
719
735
  x += state->colon_width
720
736
 
747
763
  FieldPtr field;
748
764
  ControlPtr dark, light, c12, c24, secs, mdy, dmy, ymd;
749
765
 
750
 
  Handle otext, ntext;
 
766
  MemHandle otext, ntext;
751
767
  char buf[5];
752
768
  char *s;
753
769
 
761
777
      return false;
762
778
    }
763
779
 
764
 
  if (state->ticks > 10)
 
780
  if (state->ticks >= 10)
765
781
    {
766
782
      buf[0] = ((state->ticks / 10) % 10) + '0';
767
783
      buf[1] = (state->ticks % 10) + '0' ;
773
789
      buf[1] = 0;
774
790
    }
775
791
 
776
 
  ntext = (Handle) MemHandleNew (StrLen(buf)+1);
777
 
  s = (char *) MemHandleLock ((VoidHand) ntext);
 
792
  ntext = (MemHandle) MemHandleNew (StrLen(buf)+1);
 
793
  s = (char *) MemHandleLock ((MemHandle) ntext);
778
794
  StrCopy (s, buf);
779
 
  MemHandleUnlock ((VoidHand) ntext);
 
795
  MemHandleUnlock ((MemHandle) ntext);
780
796
 
781
797
  otext = FldGetTextHandle (field);
782
798
  FldSetTextHandle (field, ntext);
783
799
  /* FldDrawField (field); */
784
800
 
785
801
  if (otext) 
786
 
    MemHandleFree ((VoidHand) otext);
 
802
    MemHandleFree ((MemHandle) otext);
787
803
 
788
804
  /* Write into the checkboxes.
789
805
   */
845
861
 
846
862
  /* Parse the frames-per-second text.
847
863
   */
848
 
  s = (char *) MemHandleLock ((VoidHand) ntext);
 
864
  s = (char *) MemHandleLock ((MemHandle) ntext);
849
865
  state->ticks = 0;
850
866
  while (*s)
851
867
    {
853
869
      if (state->ticks >= 100) break;
854
870
      s++;
855
871
    }
856
 
  MemHandleUnlock ((VoidHand) ntext);
 
872
  MemHandleUnlock ((MemHandle) ntext);
857
873
 
858
874
  FrmDeleteForm (form);
859
875
 
885
901
static void
886
902
sync_to_seconds (void)
887
903
{
888
 
  ULong sec1, sec2;
 
904
  UInt32 sec1, sec2;
889
905
  sec1 = sec2 = TimGetSeconds ();
890
906
  while (sec1 == sec2)
891
907
    sec2 = TimGetSeconds ();
936
952
 
937
953
    case penDownEvent:
938
954
      if (!state->seconds_only_p)
939
 
        state->show_date_p = 1;
 
955
        state->display_date = DDateIn;
940
956
      return true;
941
957
      break;
942
958
 
943
959
    case penUpEvent:
944
 
      if (state->show_date_p)
945
 
        state->show_date_p = 2;
 
960
      if (state->display_date == DDate) /* turn off faster if already up */
 
961
        state->display_date = DDash;
 
962
      else if (state->display_date != DTime)
 
963
        state->display_date = DDateOut;
 
964
 
946
965
      return true;
947
966
      break;
948
967
 
979
998
{
980
999
  SystemPreferencesType sysPrefs;
981
1000
  struct daliclock_prefs prefs;
982
 
  Word prefs_size;
 
1001
  UInt16 prefs_size;
983
1002
  Boolean got_prefs;
984
1003
 
985
1004
  MemSet (state, sizeof(*state), 0);
1041
1060
    }
1042
1061
 
1043
1062
  state->redraw_p = true;
1044
 
  state->show_date_p = 0;
 
1063
  state->display_date = DTime;
1045
1064
  state->test_hack = 0;
1046
1065
  state->interval = SysTicksPerSecond() / state->ticks;
1047
1066
  state->tick = state->ticks;
1085
1104
static void
1086
1105
stop_app (struct state *state)
1087
1106
{
1088
 
  state->show_date_p = 0;
 
1107
  state->display_date = DTime;
1089
1108
  free_numbers (state);
1090
1109
  FrmCloseAllForms ();
1091
1110
}
1094
1113
static void
1095
1114
event_loop (struct state *state)
1096
1115
{
1097
 
  Word error;
 
1116
  UInt16 error;
1098
1117
  EventType event;
1099
1118
 
1100
1119
  long delay = 0;
1101
1120
 
1102
1121
  do {
1103
 
    ULong start, stop;
 
1122
    UInt32 start, stop;
1104
1123
    long elapsed;
1105
1124
 
1106
1125
    EvtGetEvent (&event, delay);
1124
1143
 
1125
1144
 
1126
1145
static Err
1127
 
check_rom_version (DWord required_version, Word launch_flags)
 
1146
check_rom_version (UInt32 required_version, UInt16 launch_flags)
1128
1147
{
1129
 
  DWord rom_version = 0;
 
1148
  UInt32 rom_version = 0;
1130
1149
  FtrGet (sysFtrCreator, sysFtrNumROMVersion, &rom_version);
1131
1150
  if (rom_version < required_version)
1132
1151
    {
1141
1160
             to another safe one.  The sysFileCDefaultApp is considered "safe"
1142
1161
          */
1143
1162
          if (rom_version < ROM_20)
1144
 
            {
1145
 
              Err err; /* ignored, but referenced by AppLaunchWithCommand! */
1146
 
              AppLaunchWithCommand (sysFileCDefaultApp,
1147
 
                                    sysAppLaunchCmdNormalLaunch, 0);
1148
 
            }
 
1163
            AppLaunchWithCommand (sysFileCDefaultApp,
 
1164
                                  sysAppLaunchCmdNormalLaunch, 0);
1149
1165
# endif /* HAVE_APPLAUNCHWITHCOMMAND */
1150
1166
        }
1151
1167
 
1156
1172
 
1157
1173
 
1158
1174
 
1159
 
DWord 
1160
 
PilotMain (Word cmd, Ptr cmdPBP, Word launchFlags)
 
1175
UInt32 
 
1176
PilotMain (UInt16 cmd, MemPtr cmdPBP, UInt16 launchFlags)
1161
1177
{
1162
1178
  Err error = check_rom_version (ROM_20, launchFlags);
1163
1179
  if (error)
1178
1194
    }
1179
1195
  return 0;
1180
1196
}
 
1197
 
 
1198
/* pose -load_apps daliclock.prc -run_app 'Dali Clock'
 
1199
   remember to set "ReportScreenAccess=0" in ~/.poserrc
 
1200
 */