status.cc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /********************************************************************** <BR>
  2. This file is part of Crack dot Com's free source code release of
  3. Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
  4. information about compiling & licensing issues visit this URL</a>
  5. <PRE> If that doesn't help, contact Jonathan Clark at
  6. golgotha_source@usa.net (Subject should have "GOLG" in it)
  7. ***********************************************************************/
  8. #include "status/status.hh"
  9. i4_status_create_function_type i4_stat_fun=0;
  10. void i4_set_status_create_function(i4_status_create_function_type fun)
  11. {
  12. i4_stat_fun=fun;
  13. }
  14. i4_idle_class *i4_idle_class::first=0;
  15. i4_idle_class::i4_idle_class()
  16. {
  17. next=first;
  18. first=this;
  19. }
  20. i4_idle_class::~i4_idle_class()
  21. {
  22. if (first==this)
  23. first=first->next;
  24. else
  25. {
  26. i4_idle_class *p=first;
  27. for (;p->next && p->next!=this; p=p->next);
  28. p->next=next;
  29. }
  30. }
  31. #ifdef _WINDOWS
  32. #include <windows.h>
  33. #include <commctrl.h>
  34. #include "main/win_main.hh"
  35. #include "string/string.hh"
  36. #include "time/time.hh"
  37. enum {MAX_UPDATES=50};
  38. static int stat_y=40;
  39. class win32_status_class : public i4_status_class
  40. {
  41. public:
  42. HWND hwndPB; // handle of progress bar
  43. i4_time_class start_time;
  44. int last_p;
  45. i4_bool win_created;
  46. i4_str *description;
  47. virtual i4_bool update(float percent)
  48. {
  49. i4_time_class now;
  50. if (now.milli_diff(start_time)>500)
  51. {
  52. start_time.get();
  53. if (!win_created)
  54. {
  55. InitCommonControls();
  56. char buf[100];
  57. i4_os_string(*description, buf, 100);
  58. hwndPB = CreateWindowEx(0, PROGRESS_CLASS, buf,
  59. WS_BORDER | WS_VISIBLE, 50, stat_y,
  60. 500, 40,
  61. 0, (HMENU) 0, i4_win32_instance, NULL);
  62. // Set the range and increment of the progress bar.
  63. SendMessage(hwndPB, PBM_SETRANGE, 0, MAKELPARAM(0, MAX_UPDATES));
  64. SendMessage(hwndPB, PBM_SETSTEP, (WPARAM) 1, 0);
  65. win_created=i4_T;
  66. }
  67. }
  68. if (win_created)
  69. {
  70. int p=percent*MAX_UPDATES;
  71. while (last_p!=p)
  72. {
  73. last_p++;
  74. SendMessage(hwndPB, PBM_STEPIT, 0, 0);
  75. }
  76. }
  77. return i4_T;
  78. }
  79. win32_status_class(const i4_const_str &d)
  80. {
  81. description=new i4_str(d);
  82. win_created=i4_F;
  83. last_p=0;
  84. stat_y+=60;
  85. }
  86. virtual ~win32_status_class()
  87. {
  88. delete description;
  89. if (win_created)
  90. {
  91. while (last_p!=MAX_UPDATES)
  92. {
  93. last_p++;
  94. SendMessage(hwndPB, PBM_STEPIT, 0, 0);
  95. }
  96. DestroyWindow(hwndPB);
  97. }
  98. stat_y-=60;
  99. }
  100. };
  101. // this is operating system dependant
  102. i4_status_class *i4_create_status(const i4_const_str &description, int flags)
  103. {
  104. if (i4_stat_fun)
  105. return i4_stat_fun(description, flags);
  106. else
  107. {
  108. return new win32_status_class(description);
  109. }
  110. }
  111. #else
  112. class i4_null_status_class : public i4_status_class
  113. {
  114. public:
  115. i4_bool update(float percent)
  116. {
  117. for (i4_idle_class *p=i4_idle_class::first; p;p=p->next)
  118. p->idle();
  119. return i4_T;
  120. }
  121. };
  122. i4_status_class *i4_create_status(const i4_const_str &description, int flags)
  123. {
  124. if (i4_stat_fun)
  125. return i4_stat_fun(description, flags);
  126. else
  127. return new i4_null_status_class;
  128. }
  129. #endif