comparison mac/dw.c @ 437:903fb3085d42

More MacOS fixes, make install now works properly. Made special test #ifdef in dwtest so I can test some things as I proceed with the MacOS port.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 28 May 2003 08:00:11 +0000
parents f225f16bebbd
children b559c06a76c2
comparison
equal deleted inserted replaced
436:98d6c00fe11e 437:903fb3085d42
556 } 556 }
557 } 557 }
558 } 558 }
559 } 559 }
560 560
561 /* Main MacOS Message loop, all events are handled here. */
562 void _doEvents(EventRecord *eventStrucPtr)
563 {
564 SignalHandler *tmp = Root;
565
566 while(tmp)
567 {
568 if(tmp->message == eventStrucPtr->what)
569 {
570 switch(eventStrucPtr->what)
571 {
572 case mouseDown:
573 break;
574 case mouseUp:
575 break;
576 case keyDown:
577 break;
578 }
579 }
580 if(tmp)
581 tmp = tmp->next;
582 }
583 }
584
561 /* 585 /*
562 * Initializes the Dynamic Windows engine. 586 * Initializes the Dynamic Windows engine.
563 * Parameters: 587 * Parameters:
564 * newthread: True if this is the only thread. 588 * newthread: True if this is the only thread.
565 * False if there is already a message loop running. 589 * False if there is already a message loop running.
572 /* 596 /*
573 * Runs a message loop for Dynamic Windows. 597 * Runs a message loop for Dynamic Windows.
574 */ 598 */
575 void API dw_main(void) 599 void API dw_main(void)
576 { 600 {
601 EventRecord eventStructure;
602 int gDone = false;
603
604 while(!gDone)
605 {
606 if(WaitNextEvent(everyEvent, &eventStructure, 180, 0))
607 _doEvents(&eventStructure);
608 }
577 } 609 }
578 610
579 /* 611 /*
580 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 612 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
581 * Parameters: 613 * Parameters:
582 * milliseconds: Number of milliseconds to run the loop for. 614 * milliseconds: Number of milliseconds to run the loop for.
583 */ 615 */
584 void API dw_main_sleep(int milliseconds) 616 void API dw_main_sleep(int milliseconds)
585 { 617 {
618 double start = (double)clock();
619
620 while(((clock() - start) / (CLOCKS_PER_SEC/1000)) <= milliseconds)
621 {
622 EventRecord eventStructure;
623 if(WaitNextEvent(everyEvent, &eventStructure, 1, 0))
624 _doEvents(&eventStructure);
625 }
586 } 626 }
587 627
588 /* 628 /*
589 * Processes a single message iteration and returns. 629 * Processes a single message iteration and returns.
590 */ 630 */
591 void API dw_main_iteration(void) 631 void API dw_main_iteration(void)
592 { 632 {
633 EventRecord eventStructure;
634
635 if(WaitNextEvent(everyEvent, &eventStructure, 0, 0))
636 _doEvents(&eventStructure);
593 } 637 }
594 638
595 /* 639 /*
596 * Free's memory allocated by dynamic windows. 640 * Free's memory allocated by dynamic windows.
597 * Parameters: 641 * Parameters:
1033 * id: An ID to be used with dw_window_from_id() or 0L. 1077 * id: An ID to be used with dw_window_from_id() or 0L.
1034 */ 1078 */
1035 HWND API dw_text_new(char *text, ULONG id) 1079 HWND API dw_text_new(char *text, ULONG id)
1036 { 1080 {
1037 HWND hwnd = 0; 1081 HWND hwnd = 0;
1038 CreateStaticTextControl (CreationWindow, &CreationRect, text, NULL, &hwnd); 1082 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1083 CreateStaticTextControl (CreationWindow, &CreationRect, cftext, NULL, &hwnd);
1084 CFRelease(cftext);
1039 return hwnd; 1085 return hwnd;
1040 } 1086 }
1041 1087
1042 /* 1088 /*
1043 * Create a new status text window (widget) to be packed. 1089 * Create a new status text window (widget) to be packed.
1046 * id: An ID to be used with dw_window_from_id() or 0L. 1092 * id: An ID to be used with dw_window_from_id() or 0L.
1047 */ 1093 */
1048 HWND API dw_status_text_new(char *text, ULONG id) 1094 HWND API dw_status_text_new(char *text, ULONG id)
1049 { 1095 {
1050 HWND hwnd = 0; 1096 HWND hwnd = 0;
1051 CreateStaticTextControl (CreationWindow, &CreationRect, text, NULL, &hwnd); 1097 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1098 CreateStaticTextControl (CreationWindow, &CreationRect, cftext, NULL, &hwnd);
1099 CFRelease(cftext);
1052 return hwnd; 1100 return hwnd;
1053 } 1101 }
1054 1102
1055 /* 1103 /*
1056 * Create a new Multiline Editbox window (widget) to be packed. 1104 * Create a new Multiline Editbox window (widget) to be packed.
1071 * id: An ID to be used with dw_window_from_id() or 0L. 1119 * id: An ID to be used with dw_window_from_id() or 0L.
1072 */ 1120 */
1073 HWND API dw_entryfield_new(char *text, ULONG id) 1121 HWND API dw_entryfield_new(char *text, ULONG id)
1074 { 1122 {
1075 HWND hwnd = 0; 1123 HWND hwnd = 0;
1076 CreateEditTextControl(CreationWindow, &CreationRect, text, FALSE, FALSE, NULL, &hwnd); 1124 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1125 CreateEditTextControl(CreationWindow, &CreationRect, cftext, FALSE, FALSE, NULL, &hwnd);
1126 CFRelease(cftext);
1077 return hwnd; 1127 return hwnd;
1078 } 1128 }
1079 1129
1080 /* 1130 /*
1081 * Create a new Entryfield (password) window (widget) to be packed. 1131 * Create a new Entryfield (password) window (widget) to be packed.
1084 * id: An ID to be used with dw_window_from_id() or 0L. 1134 * id: An ID to be used with dw_window_from_id() or 0L.
1085 */ 1135 */
1086 HWND API dw_entryfield_password_new(char *text, ULONG id) 1136 HWND API dw_entryfield_password_new(char *text, ULONG id)
1087 { 1137 {
1088 HWND hwnd = 0; 1138 HWND hwnd = 0;
1089 CreateEditTextControl(CreationWindow, &CreationRect, text, TRUE, FALSE, NULL, &hwnd); 1139 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1140 CreateEditTextControl(CreationWindow, &CreationRect, cftext, TRUE, FALSE, NULL, &hwnd);
1141 CFRelease(cftext);
1090 return hwnd; 1142 return hwnd;
1091 } 1143 }
1092 1144
1093 /* 1145 /*
1094 * Create a new Combobox window (widget) to be packed. 1146 * Create a new Combobox window (widget) to be packed.
1108 * id: An ID to be used with dw_window_from_id() or 0L. 1160 * id: An ID to be used with dw_window_from_id() or 0L.
1109 */ 1161 */
1110 HWND API dw_button_new(char *text, ULONG id) 1162 HWND API dw_button_new(char *text, ULONG id)
1111 { 1163 {
1112 HWND hwnd = 0; 1164 HWND hwnd = 0;
1113 CreatePushButtonControl(CreationWindow, &CreationRect, text, &hwnd); 1165 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1166 CreatePushButtonControl(CreationWindow, &CreationRect, cftext, &hwnd);
1167 CFRelease(cftext);
1114 return hwnd; 1168 return hwnd;
1115 } 1169 }
1116 1170
1117 /* 1171 /*
1118 * Create a new bitmap button window (widget) to be packed. 1172 * Create a new bitmap button window (widget) to be packed.
1159 * id: An ID to be used with dw_window_from_id() or 0L. 1213 * id: An ID to be used with dw_window_from_id() or 0L.
1160 */ 1214 */
1161 HWND API dw_radiobutton_new(char *text, ULONG id) 1215 HWND API dw_radiobutton_new(char *text, ULONG id)
1162 { 1216 {
1163 HWND hwnd = 0; 1217 HWND hwnd = 0;
1164 CreateRadioButtonControl(CreationWindow, &CreationRect, text, 0, FALSE, &hwnd); 1218 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1219 CreateRadioButtonControl(CreationWindow, &CreationRect, cftext, 0, FALSE, &hwnd);
1220 CFRelease(cftext);
1165 return hwnd; 1221 return hwnd;
1166 } 1222 }
1167 1223
1168 1224
1169 /* 1225 /*
1213 * id: An ID to be used with dw_window_from_id() or 0L. 1269 * id: An ID to be used with dw_window_from_id() or 0L.
1214 */ 1270 */
1215 HWND API dw_checkbox_new(char *text, ULONG id) 1271 HWND API dw_checkbox_new(char *text, ULONG id)
1216 { 1272 {
1217 HWND hwnd = 0; 1273 HWND hwnd = 0;
1218 CreateCheckBoxControl(CreationWindow, &CreationRect, text, 0, TRUE, &hwnd); 1274 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1275 CreateCheckBoxControl(CreationWindow, &CreationRect, cftext, 0, TRUE, &hwnd);
1276 CFRelease(cftext);
1219 return hwnd; 1277 return hwnd;
1220 } 1278 }
1221 1279
1222 /* 1280 /*
1223 * Create a new listbox window (widget) to be packed. 1281 * Create a new listbox window (widget) to be packed.
1262 * handle: Handle to the window. 1320 * handle: Handle to the window.
1263 * text: The text associsated with a given window. 1321 * text: The text associsated with a given window.
1264 */ 1322 */
1265 void API dw_window_set_text(HWND handle, char *text) 1323 void API dw_window_set_text(HWND handle, char *text)
1266 { 1324 {
1267 SetControlTitleWithCFString(handle, text); 1325 CFStringRef cftext = CFStringCreateWithCString(NULL, text, kCFStringEncodingDOSLatinUS);
1326 SetControlTitleWithCFString(handle, cftext);
1327 CFRelease(cftext);
1268 } 1328 }
1269 1329
1270 /* 1330 /*
1271 * Gets the text used for a given window. 1331 * Gets the text used for a given window.
1272 * Parameters: 1332 * Parameters:
2639 * env: Pointer to a DWEnv struct. 2699 * env: Pointer to a DWEnv struct.
2640 */ 2700 */
2641 void API dw_environment_query(DWEnv *env) 2701 void API dw_environment_query(DWEnv *env)
2642 { 2702 {
2643 ULONG Build; 2703 ULONG Build;
2704 char verbuf[10];
2644 2705
2645 if(!env) 2706 if(!env)
2646 return; 2707 return;
2647 2708
2709 Gestalt(gestaltSystemVersion, &Build);
2710
2711 sprintf(verbuf, "%04x", Build);
2712
2648 strcpy(env->osName,"MacOS"); 2713 strcpy(env->osName,"MacOS");
2649 env->MajorVersion = 10; 2714 env->MajorBuild = atoi(&verbuf[3]);
2650 env->MinorVersion = 0; 2715 verbuf[3] = 0;
2716 env->MinorVersion = atoi(&verbuf[2]);
2717 verbuf[2] = 0;
2718 env->MajorVersion = atoi(verbuf);
2651 2719
2652 env->MinorBuild = 0; 2720 env->MinorBuild = 0;
2653 env->MajorBuild = 0;
2654 2721
2655 strcpy(env->buildDate, __DATE__); 2722 strcpy(env->buildDate, __DATE__);
2656 strcpy(env->buildTime, __TIME__); 2723 strcpy(env->buildTime, __TIME__);
2657 env->DWMajorVersion = DW_MAJOR_VERSION; 2724 env->DWMajorVersion = DW_MAJOR_VERSION;
2658 env->DWMinorVersion = DW_MINOR_VERSION; 2725 env->DWMinorVersion = DW_MINOR_VERSION;