comparison mac/dw.c @ 565:355a6d46adb1

Changes to get the menus working. Switched to using RunApplicationEventLoop(), this may not work well with dw_main_iteration(). Will have to see as things progress. Next step is getting the layout engine working. Changes to get the menus working. Switched to using RunApplicationEventLoop(), this may not work well with dw_main_iteration(). Will have to see as things progress. Next step is getting the layout engine working.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 08 May 2004 06:53:12 +0000
parents 33b792d5c8ab
children f6de197ecbe9
comparison
equal deleted inserted replaced
564:33b792d5c8ab 565:355a6d46adb1
555 } 555 }
556 } 556 }
557 } 557 }
558 } 558 }
559 559
560 /* Main MacOS Message loop, all events are handled here. */
561 static void _doEvents(EventRecord *event)
562 {
563 SignalHandler *tmp = Root;
564
565 /* Find signal handlers */
566 while(tmp)
567 {
568 if(tmp->message == event->what)
569 {
570 switch(event->what)
571 {
572 case mouseDown:
573 break;
574 case mouseUp:
575 break;
576 case keyDown:
577 break;
578 case activateEvt:
579 break;
580 case updateEvt:
581 /*DrawWindow((WindowPtr) event->message);*/
582 break;
583 }
584 }
585 if(tmp)
586 tmp = tmp->next;
587 }
588
589 /* Handle system events */
590 switch(event->what)
591 {
592 case keyDown:
593 HiliteMenu(0);
594 case kHighLevelEvent:
595 break;
596 case diskEvt:
597 break;
598 }
599 AEProcessAppleEvent(event);
600 }
601
602 static pascal OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon) 560 static pascal OSErr QuitAppleEventHandler(const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon)
603 { 561 {
604 ExitToShell(); 562 ExitToShell();
605 } 563 }
606 564
620 &CreationRect, &CreationWindow); 578 &CreationRect, &CreationWindow);
621 CreateRootControl(CreationWindow, &RootControl); 579 CreateRootControl(CreationWindow, &RootControl);
622 HideWindow(CreationWindow); 580 HideWindow(CreationWindow);
623 if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false) != noErr) 581 if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false) != noErr)
624 ExitToShell(); 582 ExitToShell();
625 DrawMenuBar();
626 583
627 /* Save the height, width and color depth */ 584 /* Save the height, width and color depth */
628 _dw_screen_height = (*gd)->gdRect.bottom - (*gd)->gdRect.top; 585 _dw_screen_height = (*gd)->gdRect.bottom - (*gd)->gdRect.top;
629 _dw_screen_width = (*gd)->gdRect.right - (*gd)->gdRect.left; 586 _dw_screen_width = (*gd)->gdRect.right - (*gd)->gdRect.left;
630 _dw_color_depth = (*(*gd)->gdPMap)->cmpSize * (*(*gd)->gdPMap)->cmpCount; 587 _dw_color_depth = (*(*gd)->gdPMap)->cmpSize * (*(*gd)->gdPMap)->cmpCount;
634 /* 591 /*
635 * Runs a message loop for Dynamic Windows. 592 * Runs a message loop for Dynamic Windows.
636 */ 593 */
637 void API dw_main(void) 594 void API dw_main(void)
638 { 595 {
639 EventRecord eventStructure; 596 RunApplicationEventLoop();
640 int gDone = false;
641
642 while(!gDone)
643 {
644 if(WaitNextEvent(everyEvent, &eventStructure, 0xffffffff, 0))
645 _doEvents(&eventStructure);
646 }
647 } 597 }
648 598
649 /* 599 /*
650 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 600 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
651 * Parameters: 601 * Parameters:
655 { 605 {
656 double start = (double)clock(); 606 double start = (double)clock();
657 607
658 while(((((clock() - start) / CLOCKS_PER_SEC)/1000)) <= milliseconds) 608 while(((((clock() - start) / CLOCKS_PER_SEC)/1000)) <= milliseconds)
659 { 609 {
660 EventRecord eventStructure; 610 RunCurrentEventLoop(1);
661 if(WaitNextEvent(everyEvent, &eventStructure, 1, 0))
662 _doEvents(&eventStructure);
663 } 611 }
664 } 612 }
665 613
666 /* 614 /*
667 * Processes a single message iteration and returns. 615 * Processes a single message iteration and returns.
669 void API dw_main_iteration(void) 617 void API dw_main_iteration(void)
670 { 618 {
671 EventRecord eventStructure; 619 EventRecord eventStructure;
672 620
673 if(WaitNextEvent(everyEvent, &eventStructure, 0, 0)) 621 if(WaitNextEvent(everyEvent, &eventStructure, 0, 0))
674 _doEvents(&eventStructure); 622 RunCurrentEventLoop(0);
675 } 623 }
676 624
677 /* 625 /*
678 * Free's memory allocated by dynamic windows. 626 * Free's memory allocated by dynamic windows.
679 * Parameters: 627 * Parameters:
725 * dialog: Pointer to a dialog struct aquired by dw_dialog_new). 673 * dialog: Pointer to a dialog struct aquired by dw_dialog_new).
726 */ 674 */
727 void * API dw_dialog_wait(DWDialog *dialog) 675 void * API dw_dialog_wait(DWDialog *dialog)
728 { 676 {
729 void *tmp; 677 void *tmp;
730 EventRecord eventStructure;
731 678
732 while(!dialog->done) 679 while(!dialog->done)
733 { 680 {
734 if(WaitNextEvent(everyEvent, &eventStructure, 180, 0)) 681 RunCurrentEventLoop(180);
735 _doEvents(&eventStructure);
736 } 682 }
737 dw_event_close(&dialog->eve); 683 dw_event_close(&dialog->eve);
738 tmp = dialog->result; 684 tmp = dialog->result;
739 free(dialog); 685 free(dialog);
740 return tmp; 686 return tmp;
1043 HWND hwnd = 0; 989 HWND hwnd = 0;
1044 CreateTabsControl(CreationWindow, &CreationRect, kControlTabSizeSmall, kControlTabDirectionNorth, 1, NULL, &hwnd); 990 CreateTabsControl(CreationWindow, &CreationRect, kControlTabSizeSmall, kControlTabDirectionNorth, 1, NULL, &hwnd);
1045 return hwnd; 991 return hwnd;
1046 } 992 }
1047 993
994 char _removetilde(char *dest, char *src)
995 {
996 int z, cur=0;
997 char accel = '\0';
998
999 for(z=0;z<strlen(src);z++)
1000 {
1001 if(src[z] != '~')
1002 {
1003 dest[cur] = src[z];
1004 cur++;
1005 }
1006 else
1007 accel = src[z+1];
1008 }
1009 dest[cur] = 0;
1010 return accel;
1011 }
1012
1048 /* 1013 /*
1049 * Create a menu object to be popped up. 1014 * Create a menu object to be popped up.
1050 * Parameters: 1015 * Parameters:
1051 * id: An ID to be used for getting the resource from the 1016 * id: An ID to be used for getting the resource from the
1052 * resource file. 1017 * resource file.
1053 */ 1018 */
1054 HMENUI API dw_menu_new(ULONG id) 1019 HMENUI API dw_menu_new(ULONG id)
1055 { 1020 {
1056 return 0; 1021 return NewMenu(id % 256, "");
1057 } 1022 }
1058 1023
1059 /* 1024 /*
1060 * Create a menubar on a window. 1025 * Create a menubar on a window.
1061 * Parameters: 1026 * Parameters:
1087 * check: If TRUE menu is "check"able. 1052 * check: If TRUE menu is "check"able.
1088 * submenu: Handle to an existing menu to be a submenu or NULL. 1053 * submenu: Handle to an existing menu to be a submenu or NULL.
1089 */ 1054 */
1090 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) 1055 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu)
1091 { 1056 {
1092 char *buf = CToPascal(title); 1057 char accel, *buf, *tempbuf = alloca(strlen(title)+1);
1058
1059 accel = _removetilde(tempbuf, title);
1060 buf = CToPascal(tempbuf);
1093 1061
1094 if(menux == (HMENUI)-1) 1062 if(menux == (HMENUI)-1)
1095 NewMenu(id, buf); 1063 {
1064 SetMenuTitle(submenu, buf);
1065 InsertMenu(submenu, 0);
1066 }
1096 else 1067 else
1097 { 1068 {
1098 /* Add a separator if requested */ 1069 /* Add a separator if requested */
1099 if(!title || !*title) 1070 if(!title || !*title)
1100 AppendMenu(menux, "\002(-"); 1071 AppendMenu(menux, "\001-");
1101 else 1072 else
1102 AppendMenuItemText(menux, buf); 1073 {
1074 MenuItemIndex item;
1075 CFStringRef cftext = CFStringCreateWithCString(NULL, tempbuf, kCFStringEncodingDOSLatinUS);
1076
1077 AppendMenuItemTextWithCFString(menux, cftext, 0, 0, &item);
1078 CFRelease(cftext);
1079
1080 id = item;
1081 if(accel)
1082 {
1083 SetItemCmd(menux, item, accel);
1084 SetMenuItemModifiers(menux, item, kMenuOptionModifier);
1085 }
1086 }
1103 } 1087 }
1104 DrawMenuBar(); 1088 DrawMenuBar();
1105 return (HWND)id; 1089 return (HWND)id;
1106 } 1090 }
1107 1091