comparison mac/dw.c @ 564:33b792d5c8ab

Added new functionality on MacOS, the layout engine should be working soon now.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 07 May 2004 20:57:43 +0000
parents b744c2b86df8
children 355a6d46adb1
comparison
equal deleted inserted replaced
563:d7c61755a57b 564:33b792d5c8ab
30 } SignalList; 30 } SignalList;
31 31
32 const Rect CreationRect = { 0, 0, 2000, 1000 }; 32 const Rect CreationRect = { 0, 0, 2000, 1000 };
33 WindowRef CreationWindow = 0; 33 WindowRef CreationWindow = 0;
34 ControlRef RootControl = 0; 34 ControlRef RootControl = 0;
35 int _dw_screen_width = 0, _dw_screen_height = 0, _dw_color_depth = 16;
35 36
36 /* List of signals and their equivilent MacOS event */ 37 /* List of signals and their equivilent MacOS event */
37 #define SIGNALMAX 15 38 #define SIGNALMAX 15
38 39
39 SignalList SignalTranslate[SIGNALMAX] = { 40 SignalList SignalTranslate[SIGNALMAX] = {
102 if(strcasecmp(signame, SignalTranslate[z].name) == 0) 103 if(strcasecmp(signame, SignalTranslate[z].name) == 0)
103 return SignalTranslate[z].message; 104 return SignalTranslate[z].message;
104 } 105 }
105 return 0L; 106 return 0L;
106 } 107 }
108
109 /* Creates a Pascal string from a C string */
110 char *_CToPascal(unsigned char *ptr, char *cstring)
111 {
112 unsigned char len = (char)strlen(cstring);
113
114 ptr[0] = len;
115 memcpy(&ptr[1], cstring, len+1);
116 return (char *)ptr;
117 }
118
119 #define CToPascal(a) _CToPascal(alloca(strlen(a)+2), a)
107 120
108 static void *_get_window_pointer(HWND handle) 121 static void *_get_window_pointer(HWND handle)
109 { 122 {
110 void *ret = NULL; 123 void *ret = NULL;
111 124
515 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); 528 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady);
516 } 529 }
517 } 530 }
518 } 531 }
519 532
520 static int _dw_int_pos(HWND hwnd)
521 {
522 int pos = (int)dw_window_get_data(hwnd, "_dw_percent_value");
523 int range = dw_percent_get_range(hwnd);
524 float fpos = (float)pos;
525 float frange = (float)range;
526 float fnew = (fpos/1000.0)*frange;
527 return (int)fnew;
528 }
529
530 static void _dw_int_set(HWND hwnd, int pos)
531 {
532 int inew, range = dw_percent_get_range(hwnd);
533 if(range)
534 {
535 float fpos = (float)pos;
536 float frange = (float)range;
537 float fnew = (fpos/frange)*1000.0;
538 inew = (int)fnew;
539 dw_window_set_data(hwnd, "_dw_percent_value", (void *)inew);
540 }
541 }
542
543 static void _changebox(Box *thisbox, int percent, int type) 533 static void _changebox(Box *thisbox, int percent, int type)
544 { 534 {
545 int z; 535 int z;
546 536
547 for(z=0;z<thisbox->count;z++) 537 for(z=0;z<thisbox->count;z++)
566 } 556 }
567 } 557 }
568 } 558 }
569 559
570 /* Main MacOS Message loop, all events are handled here. */ 560 /* Main MacOS Message loop, all events are handled here. */
571 static void _doEvents(EventRecord *eventStrucPtr) 561 static void _doEvents(EventRecord *event)
572 { 562 {
573 SignalHandler *tmp = Root; 563 SignalHandler *tmp = Root;
574 564
565 /* Find signal handlers */
575 while(tmp) 566 while(tmp)
576 { 567 {
577 if(tmp->message == eventStrucPtr->what) 568 if(tmp->message == event->what)
578 { 569 {
579 switch(eventStrucPtr->what) 570 switch(event->what)
580 { 571 {
581 case mouseDown: 572 case mouseDown:
582 break; 573 break;
583 case mouseUp: 574 case mouseUp:
584 break; 575 break;
585 case keyDown: 576 case keyDown:
586 break; 577 break;
578 case activateEvt:
579 break;
580 case updateEvt:
581 /*DrawWindow((WindowPtr) event->message);*/
582 break;
587 } 583 }
588 } 584 }
589 if(tmp) 585 if(tmp)
590 tmp = tmp->next; 586 tmp = tmp->next;
591 } 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)
603 {
604 ExitToShell();
592 } 605 }
593 606
594 /* 607 /*
595 * Initializes the Dynamic Windows engine. 608 * Initializes the Dynamic Windows engine.
596 * Parameters: 609 * Parameters:
597 * newthread: True if this is the only thread. 610 * newthread: True if this is the only thread.
598 * False if there is already a message loop running. 611 * False if there is already a message loop running.
599 */ 612 */
600 int API dw_init(int newthread, int argc, char *argv[]) 613 int API dw_init(int newthread, int argc, char *argv[])
601 { 614 {
602 CreateNewWindow (kDocumentWindowClass, 0, 615 GDHandle gd = GetMainDevice();
616
617 FlushEvents(everyEvent, 0);
618 InitCursor();
619 CreateNewWindow (kDocumentWindowClass, kWindowOpaqueForEventsAttribute,
603 &CreationRect, &CreationWindow); 620 &CreationRect, &CreationWindow);
604 CreateRootControl(CreationWindow, &RootControl); 621 CreateRootControl(CreationWindow, &RootControl);
605 HideWindow(CreationWindow); 622 HideWindow(CreationWindow);
623 if(AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP(QuitAppleEventHandler), 0, false) != noErr)
624 ExitToShell();
625 DrawMenuBar();
626
627 /* Save the height, width and color depth */
628 _dw_screen_height = (*gd)->gdRect.bottom - (*gd)->gdRect.top;
629 _dw_screen_width = (*gd)->gdRect.right - (*gd)->gdRect.left;
630 _dw_color_depth = (*(*gd)->gdPMap)->cmpSize * (*(*gd)->gdPMap)->cmpCount;
606 return 0; 631 return 0;
607 } 632 }
608 633
609 /* 634 /*
610 * Runs a message loop for Dynamic Windows. 635 * Runs a message loop for Dynamic Windows.
614 EventRecord eventStructure; 639 EventRecord eventStructure;
615 int gDone = false; 640 int gDone = false;
616 641
617 while(!gDone) 642 while(!gDone)
618 { 643 {
619 if(WaitNextEvent(everyEvent, &eventStructure, 180, 0)) 644 if(WaitNextEvent(everyEvent, &eventStructure, 0xffffffff, 0))
620 _doEvents(&eventStructure); 645 _doEvents(&eventStructure);
621 } 646 }
622 } 647 }
623 648
624 /* 649 /*
948 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle) 973 HWND API dw_window_new(HWND hwndOwner, char *title, ULONG flStyle)
949 { 974 {
950 WindowRef hwnd = 0; 975 WindowRef hwnd = 0;
951 ControlRef rootcontrol = 0; 976 ControlRef rootcontrol = 0;
952 977
953 CreateNewWindow (kDocumentWindowClass, flStyle, 978 CreateNewWindow (kDocumentWindowClass, flStyle | kWindowStandardHandlerAttribute,
954 &CreationRect, &hwnd); 979 &CreationRect, &hwnd);
955 CreateRootControl(hwnd, &rootcontrol); 980 CreateRootControl(hwnd, &rootcontrol);
956 dw_window_set_text((HWND)hwnd, title); 981 dw_window_set_text((HWND)hwnd, title);
957 return (HWND)hwnd; 982 return (HWND)hwnd;
958 } 983 }
963 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal). 988 * type: Either DW_VERT (vertical) or DW_HORZ (horizontal).
964 * pad: Number of pixels to pad around the box. 989 * pad: Number of pixels to pad around the box.
965 */ 990 */
966 HWND API dw_box_new(int type, int pad) 991 HWND API dw_box_new(int type, int pad)
967 { 992 {
968 ControlRef hwnd = NewControl(CreationWindow, NULL, "\p", 993 ControlRef hwnd = NewControl(CreationWindow, NULL, "",
969 true, kControlSupportsEmbedding | kControlHasSpecialBackground, 994 true, kControlSupportsEmbedding | kControlHasSpecialBackground,
970 0, 1, kControlUserPaneProc, (SInt32) 0); 995 0, 1, kControlUserPaneProc, (SInt32) 0);
971 return (HWND)hwnd; 996 return (HWND)hwnd;
972 } 997 }
973 998
1036 * Parameters: 1061 * Parameters:
1037 * location: Handle of a window frame to be attached to. 1062 * location: Handle of a window frame to be attached to.
1038 */ 1063 */
1039 HMENUI API dw_menubar_new(HWND location) 1064 HMENUI API dw_menubar_new(HWND location)
1040 { 1065 {
1041 return 0; 1066 return (HMENUI)-1;
1042 } 1067 }
1043 1068
1044 /* 1069 /*
1045 * Destroys a menu created with dw_menubar_new or dw_menu_new. 1070 * Destroys a menu created with dw_menubar_new or dw_menu_new.
1046 * Parameters: 1071 * Parameters:
1047 * menu: Handle of a menu. 1072 * menu: Handle of a menu.
1048 */ 1073 */
1049 void API dw_menu_destroy(HMENUI *menu) 1074 void API dw_menu_destroy(HMENUI *menu)
1050 { 1075 {
1076 DisposeMenu(*menu);
1051 } 1077 }
1052 1078
1053 /* 1079 /*
1054 * Adds a menuitem or submenu to an existing menu. 1080 * Adds a menuitem or submenu to an existing menu.
1055 * Parameters: 1081 * Parameters:
1061 * check: If TRUE menu is "check"able. 1087 * check: If TRUE menu is "check"able.
1062 * submenu: Handle to an existing menu to be a submenu or NULL. 1088 * submenu: Handle to an existing menu to be a submenu or NULL.
1063 */ 1089 */
1064 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu) 1090 HWND API dw_menu_append_item(HMENUI menux, char *title, ULONG id, ULONG flags, int end, int check, HMENUI submenu)
1065 { 1091 {
1066 return 0; 1092 char *buf = CToPascal(title);
1093
1094 if(menux == (HMENUI)-1)
1095 NewMenu(id, buf);
1096 else
1097 {
1098 /* Add a separator if requested */
1099 if(!title || !*title)
1100 AppendMenu(menux, "\002(-");
1101 else
1102 AppendMenuItemText(menux, buf);
1103 }
1104 DrawMenuBar();
1105 return (HWND)id;
1067 } 1106 }
1068 1107
1069 /* 1108 /*
1070 * Sets the state of a menu item check. 1109 * Sets the state of a menu item check.
1071 * Parameters: 1110 * Parameters:
1073 * id: Menuitem id. 1112 * id: Menuitem id.
1074 * check: TRUE for checked FALSE for not checked. 1113 * check: TRUE for checked FALSE for not checked.
1075 */ 1114 */
1076 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check) 1115 void API dw_menu_item_set_check(HMENUI menux, unsigned long id, int check)
1077 { 1116 {
1117 CheckMenuItem(menux, id, check);
1078 } 1118 }
1079 1119
1080 /* 1120 /*
1081 * Pops up a context menu at given x and y coordinates. 1121 * Pops up a context menu at given x and y coordinates.
1082 * Parameters: 1122 * Parameters:
1499 /* 1539 /*
1500 * Returns the width of the screen. 1540 * Returns the width of the screen.
1501 */ 1541 */
1502 int API dw_screen_width(void) 1542 int API dw_screen_width(void)
1503 { 1543 {
1504 return 0; 1544 return _dw_screen_width;
1505 } 1545 }
1506 1546
1507 /* 1547 /*
1508 * Returns the height of the screen. 1548 * Returns the height of the screen.
1509 */ 1549 */
1510 int API dw_screen_height(void) 1550 int API dw_screen_height(void)
1511 { 1551 {
1512 return 0; 1552 return _dw_screen_height;
1513 } 1553 }
1514 1554
1515 /* This should return the current color depth */ 1555 /* This should return the current color depth */
1516 unsigned long API dw_color_depth_get(void) 1556 unsigned long API dw_color_depth_get(void)
1517 { 1557 {
1518 return 0; 1558 return _dw_color_depth;
1519 } 1559 }
1520 1560
1521 1561
1522 /* 1562 /*
1523 * Sets the position of a given window (widget). 1563 * Sets the position of a given window (widget).
1871 * Parameters: 1911 * Parameters:
1872 * handle: Handle to the MLE to thaw. 1912 * handle: Handle to the MLE to thaw.
1873 */ 1913 */
1874 void API dw_mle_thaw(HWND handle) 1914 void API dw_mle_thaw(HWND handle)
1875 { 1915 {
1876 }
1877
1878 /*
1879 * Returns the range of the percent bar.
1880 * Parameters:
1881 * handle: Handle to the percent bar to be queried.
1882 */
1883 unsigned int API dw_percent_get_range(HWND handle)
1884 {
1885 return 0;
1886 } 1916 }
1887 1917
1888 /* 1918 /*
1889 * Sets the percent bar position. 1919 * Sets the percent bar position.
1890 * Parameters: 1920 * Parameters:
2604 * freq: Frequency. 2634 * freq: Frequency.
2605 * dur: Duration. 2635 * dur: Duration.
2606 */ 2636 */
2607 void API dw_beep(int freq, int dur) 2637 void API dw_beep(int freq, int dur)
2608 { 2638 {
2639 SysBeep(dur);
2609 } 2640 }
2610 2641
2611 /* Open a shared library and return a handle. 2642 /* Open a shared library and return a handle.
2612 * Parameters: 2643 * Parameters:
2613 * name: Base name of the shared library. 2644 * name: Base name of the shared library.
2713 * Parameters: 2744 * Parameters:
2714 * eve: The handle to the event returned by dw_event_new(). 2745 * eve: The handle to the event returned by dw_event_new().
2715 */ 2746 */
2716 int API dw_event_wait(HEV eve, unsigned long timeout) 2747 int API dw_event_wait(HEV eve, unsigned long timeout)
2717 { 2748 {
2718 return 0; 2749 return TRUE;
2719 } 2750 }
2720 2751
2721 /* 2752 /*
2722 * Closes a semaphore created by dw_event_new(). 2753 * Closes a semaphore created by dw_event_new().
2723 * Parameters: 2754 * Parameters:
2724 * eve: The handle to the event returned by dw_event_new(). 2755 * eve: The handle to the event returned by dw_event_new().
2725 */ 2756 */
2726 int API dw_event_close(HEV *eve) 2757 int API dw_event_close(HEV *eve)
2727 { 2758 {
2728 return TRUE; 2759 return TRUE;
2760 }
2761
2762 /* Create a named event semaphore which can be
2763 * opened from other processes.
2764 * Parameters:
2765 * eve: Pointer to an event handle to receive handle.
2766 * name: Name given to semaphore which can be opened
2767 * by other processes.
2768 */
2769 HEV API dw_named_event_new(char *name)
2770 {
2771 return 0;
2772 }
2773
2774 /* Open an already existing named event semaphore.
2775 * Parameters:
2776 * eve: Pointer to an event handle to receive handle.
2777 * name: Name given to semaphore which can be opened
2778 * by other processes.
2779 */
2780 HEV API dw_named_event_get(char *name)
2781 {
2782 return 0;
2783 }
2784
2785 /* Resets the event semaphore so threads who call wait
2786 * on this semaphore will block.
2787 * Parameters:
2788 * eve: Handle to the semaphore obtained by
2789 * an open or create call.
2790 */
2791 int API dw_named_event_reset(HEV eve)
2792 {
2793 return 0;
2794 }
2795
2796 /* Sets the posted state of an event semaphore, any threads
2797 * waiting on the semaphore will no longer block.
2798 * Parameters:
2799 * eve: Handle to the semaphore obtained by
2800 * an open or create call.
2801 */
2802 int API dw_named_event_post(HEV eve)
2803 {
2804 return 0;
2805 }
2806
2807
2808 /* Waits on the specified semaphore until it becomes
2809 * posted, or returns immediately if it already is posted.
2810 * Parameters:
2811 * eve: Handle to the semaphore obtained by
2812 * an open or create call.
2813 * timeout: Number of milliseconds before timing out
2814 * or -1 if indefinite.
2815 */
2816 int API dw_named_event_wait(HEV eve, unsigned long timeout)
2817 {
2818 return 0;
2819 }
2820
2821 /* Release this semaphore, if there are no more open
2822 * handles on this semaphore the semaphore will be destroyed.
2823 * Parameters:
2824 * eve: Handle to the semaphore obtained by
2825 * an open or create call.
2826 */
2827 int API dw_named_event_close(HEV eve)
2828 {
2829 return 0;
2830 }
2831
2832 /*
2833 * Allocates a shared memory region with a name.
2834 * Parameters:
2835 * handle: A pointer to receive a SHM identifier.
2836 * dest: A pointer to a pointer to receive the memory address.
2837 * size: Size in bytes of the shared memory region to allocate.
2838 * name: A string pointer to a unique memory name.
2839 */
2840 HSHM API dw_named_memory_new(void **dest, int size, char *name)
2841 {
2842 return 0;
2843 }
2844
2845 /*
2846 * Aquires shared memory region with a name.
2847 * Parameters:
2848 * dest: A pointer to a pointer to receive the memory address.
2849 * size: Size in bytes of the shared memory region to requested.
2850 * name: A string pointer to a unique memory name.
2851 */
2852 HSHM API dw_named_memory_get(void **dest, int size, char *name)
2853 {
2854 return 0;
2855 }
2856
2857 /*
2858 * Frees a shared memory region previously allocated.
2859 * Parameters:
2860 * handle: Handle obtained from DB_named_memory_allocate.
2861 * ptr: The memory address aquired with DB_named_memory_allocate.
2862 */
2863 int API dw_named_memory_free(HSHM handle, void *ptr)
2864 {
2865
2866 return 0;
2729 } 2867 }
2730 2868
2731 /* 2869 /*
2732 * Creates a new thread with a starting point of func. 2870 * Creates a new thread with a starting point of func.
2733 * Parameters: 2871 * Parameters: