comparison os2/dw.c @ 1813:9cb8660c5fa3

Attempt at the same changes for OS/2 as Windows... untested.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 09 Oct 2012 04:52:52 +0000
parents 889f8d47761c
children b301d86a2683
comparison
equal deleted inserted replaced
1812:9bbe090d0250 1813:9cb8660c5fa3
608 strncmp(tmpbuf, "#10", 4)==0 || /* MLE */ 608 strncmp(tmpbuf, "#10", 4)==0 || /* MLE */
609 strncmp(tmpbuf, "#32", 4)==0 || /* Spinbutton */ 609 strncmp(tmpbuf, "#32", 4)==0 || /* Spinbutton */
610 strncmp(tmpbuf, "#37", 4)==0 || /* Container */ 610 strncmp(tmpbuf, "#37", 4)==0 || /* Container */
611 strncmp(tmpbuf, "#38", 4)== 0) /* Slider */ 611 strncmp(tmpbuf, "#38", 4)== 0) /* Slider */
612 return 1; 612 return 1;
613 if(strncmp(tmpbuf, "#40", 4)==0) /* Notebook */
614 return 2;
613 return 0; 615 return 0;
614 } 616 }
615 617
616 int _focus_check_box(Box *box, HWND handle, int start, HWND defaultitem) 618 #define _DW_DIRECTION_FORWARD -1
619 #define _DW_DIRECTION_BACKWARD 1
620
621 int _focus_check_box(Box *box, HWND handle, int start, int direction, HWND defaultitem);
622
623 /* Internal comparision function */
624 int _focus_comp(int direction, int z, int end)
625 {
626 if(direction == _DW_DIRECTION_FORWARD)
627 return z > -1;
628 return z < end;
629 }
630 int _focus_notebook(HWND hwnd, HWND handle, int start, int direction, HWND defaultitem)
631 {
632 Box *notebox;
633 HWND page = (HWND)WinSendMsg(hwnd, BKM_QUERYPAGEWINDOWHWND,
634 (MPARAM)dw_notebook_page_get(hwnd), 0);
635
636 if(page)
637 {
638 notebox = (Box *)WinQueryWindowPtr(page, QWP_USER);
639
640 if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, direction, defaultitem))
641 return 1;
642 }
643 return 0;
644 }
645
646 int _focus_check_box(Box *box, HWND handle, int start, int direction, HWND defaultitem)
617 { 647 {
618 int z; 648 int z;
619 static HWND lasthwnd, firsthwnd; 649 static HWND lasthwnd, firsthwnd;
620 static int finish_searching; 650 static int finish_searching;
651 int beg = (direction == _DW_DIRECTION_FORWARD) ? box->count-1 : 0;
652 int end = (direction == _DW_DIRECTION_FORWARD) ? -1 : box->count;
621 653
622 /* Start is 2 when we have cycled completely and 654 /* Start is 2 when we have cycled completely and
623 * need to set the focus to the last widget we found 655 * need to set the focus to the last widget we found
624 * that was valid. 656 * that was valid.
625 */ 657 */
639 lasthwnd = handle; 671 lasthwnd = handle;
640 finish_searching = 0; 672 finish_searching = 0;
641 firsthwnd = 0; 673 firsthwnd = 0;
642 } 674 }
643 675
644 for(z=box->count-1;z>-1;z--) 676 for(z=beg;_focus_comp(direction, z, end);z+=direction)
645 { 677 {
646 if(box->items[z].type == TYPEBOX) 678 if(box->items[z].type == TYPEBOX)
647 { 679 {
648 Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER); 680 Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER);
649 681
650 if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, defaultitem)) 682 if(thisbox && _focus_check_box(thisbox, handle, start == 3 ? 3 : 0, direction, defaultitem))
651 return 1; 683 return 1;
652 } 684 }
653 else 685 else
654 { 686 {
687 int type = _validate_focus(box->items[z].hwnd);
688
689 /* Special case notebook, can focus and contains items */
690 if(type == 2 && direction == _DW_DIRECTION_FORWARD && _focus_notebook(box->items[z].hwnd, handle, start, direction, defaultitem))
691 return 1;
655 if(box->items[z].hwnd == handle) 692 if(box->items[z].hwnd == handle)
656 { 693 {
657 if(lasthwnd == handle && firsthwnd) 694 if(lasthwnd == handle && firsthwnd)
658 WinSetFocus(HWND_DESKTOP, firsthwnd); 695 WinSetFocus(HWND_DESKTOP, firsthwnd);
659 else if(lasthwnd == handle && !firsthwnd) 696 else if(lasthwnd == handle && !firsthwnd)
679 WinSetFocus(HWND_DESKTOP, box->items[z].hwnd); 716 WinSetFocus(HWND_DESKTOP, box->items[z].hwnd);
680 return 1; 717 return 1;
681 } 718 }
682 } 719 }
683 720
721 lasthwnd = box->items[z].hwnd;
722
684 if(!firsthwnd) 723 if(!firsthwnd)
685 firsthwnd = box->items[z].hwnd; 724 firsthwnd = lasthwnd;
686
687 lasthwnd = box->items[z].hwnd;
688 } 725 }
689 else 726 else
690 { 727 {
691 char tmpbuf[100] = {0}; 728 char tmpbuf[100] = {0};
692 729
698 735
699 if(mybox) 736 if(mybox)
700 { 737 {
701 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER); 738 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
702 739
703 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) 740 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, direction, defaultitem))
704 return 1; 741 return 1;
705 } 742 }
706 743
707 /* Try the top or left box */ 744 /* Try the top or left box */
708 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft"); 745 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft");
709 746
710 if(mybox) 747 if(mybox)
711 { 748 {
712 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER); 749 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
713 750
714 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem)) 751 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, direction, defaultitem))
715 return 1;
716 }
717 }
718 else if(strncmp(tmpbuf, "#40", 4)==0) /* Notebook */
719 {
720 Box *notebox;
721 HWND page = (HWND)WinSendMsg(box->items[z].hwnd, BKM_QUERYPAGEWINDOWHWND,
722 (MPARAM)dw_notebook_page_get(box->items[z].hwnd), 0);
723
724 if(page)
725 {
726 notebox = (Box *)WinQueryWindowPtr(page, QWP_USER);
727
728 if(notebox && _focus_check_box(notebox, handle, start == 3 ? 3 : 0, defaultitem))
729 return 1; 752 return 1;
730 } 753 }
731 } 754 }
732 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0) /* Scrollbox */ 755 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0) /* Scrollbox */
733 { 756 {
736 759
737 if(mybox) 760 if(mybox)
738 { 761 {
739 Box *scrollbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER); 762 Box *scrollbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
740 763
741 if(scrollbox && _focus_check_box(scrollbox, handle, start == 3 ? 3 : 0, defaultitem)) 764 if(scrollbox && _focus_check_box(scrollbox, handle, start == 3 ? 3 : 0, direction, defaultitem))
742 return 1; 765 return 1;
743 } 766 }
744 } 767 }
745 } 768 }
746 } 769 /* Special case notebook, can focus and contains items */
747 } 770 if(type == 2 && direction == _DW_DIRECTION_BACKWARD && _focus_notebook(box->items[z].hwnd, handle, start, direction, defaultitem))
748 return 0;
749 }
750
751 int _focus_check_box_back(Box *box, HWND handle, int start, HWND defaultitem)
752 {
753 int z;
754 static HWND lasthwnd, firsthwnd;
755 static int finish_searching;
756
757 /* Start is 2 when we have cycled completely and
758 * need to set the focus to the last widget we found
759 * that was valid.
760 */
761 if(start == 2)
762 {
763 if(lasthwnd)
764 WinSetFocus(HWND_DESKTOP, lasthwnd);
765 return 0;
766 }
767
768 /* Start is 1 when we are entering the function
769 * for the first time, it is zero when entering
770 * the function recursively.
771 */
772 if(start == 1)
773 {
774 lasthwnd = handle;
775 finish_searching = 0;
776 firsthwnd = 0;
777 }
778
779 for(z=0;z<box->count;z++)
780 {
781 if(box->items[z].type == TYPEBOX)
782 {
783 Box *thisbox = WinQueryWindowPtr(box->items[z].hwnd, QWP_USER);
784
785 if(thisbox && _focus_check_box_back(thisbox, handle, start == 3 ? 3 : 0, defaultitem))
786 return 1; 771 return 1;
787 }
788 else
789 {
790 if(box->items[z].hwnd == handle)
791 {
792 if(lasthwnd == handle && firsthwnd)
793 WinSetFocus(HWND_DESKTOP, firsthwnd);
794 else if(lasthwnd == handle && !firsthwnd)
795 finish_searching = 1;
796 else
797 WinSetFocus(HWND_DESKTOP, lasthwnd);
798
799 /* If we aren't looking for the last handle,
800 * return immediately.
801 */
802 if(!finish_searching)
803 return 1;
804 }
805 if(_validate_focus(box->items[z].hwnd))
806 {
807 /* Start is 3 when we are looking for the
808 * first valid item in the layout.
809 */
810 if(start == 3)
811 {
812 if(!defaultitem || (defaultitem && defaultitem == box->items[z].hwnd))
813 {
814 WinSetFocus(HWND_DESKTOP, box->items[z].hwnd);
815 return 1;
816 }
817 }
818
819 if(!firsthwnd)
820 firsthwnd = box->items[z].hwnd;
821
822 lasthwnd = box->items[z].hwnd;
823 }
824 else
825 {
826 char tmpbuf[100] = {0};
827
828 WinQueryClassName(box->items[z].hwnd, 99, (PCH)tmpbuf);
829 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
830 {
831 /* Try the top or left box */
832 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft");
833
834 if(mybox)
835 {
836 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
837
838 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem))
839 return 1;
840 }
841
842 /* Then try the bottom or right box */
843 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright");
844
845 if(mybox)
846 {
847 Box *splitbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
848
849 if(splitbox && _focus_check_box_back(splitbox, handle, start == 3 ? 3 : 0, defaultitem))
850 return 1;
851 }
852 }
853 else if(strncmp(tmpbuf, "#40", 4)==0) /* Notebook */
854 {
855 Box *notebox;
856 HWND page = (HWND)WinSendMsg(box->items[z].hwnd, BKM_QUERYPAGEWINDOWHWND,
857 (MPARAM)dw_notebook_page_get(box->items[z].hwnd), 0);
858
859 if(page)
860 {
861 notebox = (Box *)WinQueryWindowPtr(page, QWP_USER);
862
863 if(notebox && _focus_check_box_back(notebox, handle, start == 3 ? 3 : 0, defaultitem))
864 return 1;
865 }
866 }
867 else if(strncmp(tmpbuf, ScrollClassName, strlen(ScrollClassName)+1)==0) /* Scrollbox */
868 {
869 /* Get the box window handle */
870 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_box");
871
872 if(mybox)
873 {
874 Box *scrollbox = (Box *)WinQueryWindowPtr(mybox, QWP_USER);
875
876 if(scrollbox && _focus_check_box_back(scrollbox, handle, start == 3 ? 3 : 0, defaultitem))
877 return 1;
878 }
879 }
880 }
881 } 772 }
882 } 773 }
883 return 0; 774 return 0;
884 } 775 }
885 776
903 } 794 }
904 795
905 /* This function finds the current widget in the 796 /* This function finds the current widget in the
906 * layout and moves the current focus to the next item. 797 * layout and moves the current focus to the next item.
907 */ 798 */
908 void _shift_focus(HWND handle) 799 void _shift_focus(HWND handle, int direction)
909 { 800 {
910 Box *thisbox; 801 Box *thisbox;
911 HWND box, lastbox = _toplevel_window(handle); 802 HWND box, lastbox = _toplevel_window(handle);
912 803
913 box = WinWindowFromID(lastbox, FID_CLIENT); 804 box = WinWindowFromID(lastbox, FID_CLIENT);
916 else 807 else
917 thisbox = WinQueryWindowPtr(lastbox, QWP_USER); 808 thisbox = WinQueryWindowPtr(lastbox, QWP_USER);
918 809
919 if(thisbox) 810 if(thisbox)
920 { 811 {
921 if(_focus_check_box(thisbox, handle, 1, 0) == 0) 812 if(_focus_check_box(thisbox, handle, 1, direction, 0) == 0)
922 _focus_check_box(thisbox, handle, 2, 0); 813 _focus_check_box(thisbox, handle, 2, direction, 0);
923 }
924 }
925
926 /* This function finds the current widget in the
927 * layout and moves the current focus to the next item.
928 */
929 void _shift_focus_back(HWND handle)
930 {
931 Box *thisbox;
932 HWND box, lastbox = _toplevel_window(handle);
933
934 box = WinWindowFromID(lastbox, FID_CLIENT);
935 if(box)
936 thisbox = WinQueryWindowPtr(box, QWP_USER);
937 else
938 thisbox = WinQueryWindowPtr(lastbox, QWP_USER);
939
940 if(thisbox)
941 {
942 if(_focus_check_box_back(thisbox, handle, 1, 0) == 0)
943 _focus_check_box_back(thisbox, handle, 2, 0);
944 } 814 }
945 } 815 }
946 816
947 /* This function will recursively search a box and add up the total height of it */ 817 /* This function will recursively search a box and add up the total height of it */
948 void _count_size(HWND box, int type, int *xsize, int *xorigsize) 818 void _count_size(HWND box, int type, int *xsize, int *xorigsize)
2613 if(_run_event(hWnd, msg, mp1, mp2) == (MRESULT)TRUE) 2483 if(_run_event(hWnd, msg, mp1, mp2) == (MRESULT)TRUE)
2614 return (MRESULT)TRUE; 2484 return (MRESULT)TRUE;
2615 if(SHORT1FROMMP(mp2) == '\t') 2485 if(SHORT1FROMMP(mp2) == '\t')
2616 { 2486 {
2617 if(CHARMSG(&msg)->fs & KC_SHIFT) 2487 if(CHARMSG(&msg)->fs & KC_SHIFT)
2618 _shift_focus_back(hWnd); 2488 _shift_focus(hWnd, _DW_DIRECTION_BACKWARD);
2619 else 2489 else
2620 _shift_focus(hWnd); 2490 _shift_focus(hWnd, _DW_DIRECTION_FORWARD);
2621 return FALSE; 2491 return FALSE;
2622 } 2492 }
2623 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault) 2493 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault)
2624 _click_default(blah->clickdefault); 2494 _click_default(blah->clickdefault);
2625 /* When you hit escape we get this value and the 2495 /* When you hit escape we get this value and the
2867 break; 2737 break;
2868 case WM_CHAR: 2738 case WM_CHAR:
2869 if(SHORT1FROMMP(mp2) == '\t') 2739 if(SHORT1FROMMP(mp2) == '\t')
2870 { 2740 {
2871 if(CHARMSG(&msg)->fs & KC_SHIFT) 2741 if(CHARMSG(&msg)->fs & KC_SHIFT)
2872 _shift_focus_back(hWnd); 2742 _shift_focus(hWnd, _DW_DIRECTION_BACKWARD);
2873 else 2743 else
2874 _shift_focus(hWnd); 2744 _shift_focus(hWnd, _DW_DIRECTION_FORWARD);
2875 return FALSE; 2745 return FALSE;
2876 } 2746 }
2877 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault) 2747 else if(SHORT1FROMMP(mp2) == '\r' && blah && blah->clickdefault)
2878 _click_default(blah->clickdefault); 2748 _click_default(blah->clickdefault);
2879 break; 2749 break;
3823 break; 3693 break;
3824 case WM_CHAR: 3694 case WM_CHAR:
3825 if(SHORT1FROMMP(mp2) == '\t') 3695 if(SHORT1FROMMP(mp2) == '\t')
3826 { 3696 {
3827 if(CHARMSG(&msg)->fs & KC_SHIFT) 3697 if(CHARMSG(&msg)->fs & KC_SHIFT)
3828 _shift_focus_back(hWnd); 3698 _shift_focus(hWnd, _DW_DIRECTION_BACKWARD);
3829 else 3699 else
3830 _shift_focus(hWnd); 3700 _shift_focus(hWnd, _DW_DIRECTION_FORWARD);
3831 return FALSE; 3701 return FALSE;
3832 } 3702 }
3833 break; 3703 break;
3834 case WM_DESTROY: 3704 case WM_DESTROY:
3835 { 3705 {
4290 } 4160 }
4291 } 4161 }
4292 if(SHORT1FROMMP(mp2) == '\t') 4162 if(SHORT1FROMMP(mp2) == '\t')
4293 { 4163 {
4294 if(CHARMSG(&msg)->fs & KC_SHIFT) 4164 if(CHARMSG(&msg)->fs & KC_SHIFT)
4295 _shift_focus_back(hwnd); 4165 _shift_focus(hwnd, _DW_DIRECTION_BACKWARD);
4296 else 4166 else
4297 _shift_focus(hwnd); 4167 _shift_focus(hwnd, _DW_DIRECTION_FORWARD);
4298 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0); 4168 WinSendMsg(hwnd, BM_SETDEFAULT, 0, 0);
4299 return FALSE; 4169 return FALSE;
4300 } 4170 }
4301 else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_LEFT || CHARMSG(&msg)->vkey == VK_UP)) 4171 else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_LEFT || CHARMSG(&msg)->vkey == VK_UP))
4302 { 4172 {
4303 _shift_focus_back(hwnd); 4173 _shift_focus_back(hwnd);
4304 return FALSE; 4174 return FALSE;
4305 } 4175 }
4306 else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_RIGHT || CHARMSG(&msg)->vkey == VK_DOWN)) 4176 else if(!(CHARMSG(&msg)->fs & KC_KEYUP) && (CHARMSG(&msg)->vkey == VK_RIGHT || CHARMSG(&msg)->vkey == VK_DOWN))
4307 { 4177 {
4308 _shift_focus(hwnd); 4178 _shift_focus(hwnd, _DW_DIRECTION_FORWARD);
4309 return FALSE; 4179 return FALSE;
4310 } 4180 }
4311 } 4181 }
4312 break; 4182 break;
4313 } 4183 }
4389 break; 4259 break;
4390 case WM_CHAR: 4260 case WM_CHAR:
4391 if(SHORT1FROMMP(mp2) == '\t') 4261 if(SHORT1FROMMP(mp2) == '\t')
4392 { 4262 {
4393 if(CHARMSG(&msg)->fs & KC_SHIFT) 4263 if(CHARMSG(&msg)->fs & KC_SHIFT)
4394 _shift_focus_back(hwnd); 4264 _shift_focus(hwnd, _DW_DIRECTION_BACKWARD);
4395 else 4265 else
4396 _shift_focus(hwnd); 4266 _shift_focus(hwnd, _DW_DIRECTION_FORWARD);
4397 return FALSE; 4267 return FALSE;
4398 } 4268 }
4399 break; 4269 break;
4400 } 4270 }
4401 4271
4402 _run_event(hwnd, msg, mp1, mp2); 4272 _run_event(hwnd, msg, mp1, mp2);
4403 4273
4274 if(oldproc)
4275 return oldproc(hwnd, msg, mp1, mp2);
4276
4277 return WinDefWindowProc(hwnd, msg, mp1, mp2);
4278 }
4279
4280 MRESULT EXPENTRY _NotebookProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
4281 {
4282 WindowData *blah = (WindowData *)WinQueryWindowPtr(hwnd, QWP_USER);
4283 PFNWP oldproc = 0;
4284
4285 if(blah)
4286 oldproc = blah->oldproc;
4287
4288 switch(msg)
4289 {
4290 case WM_CHAR:
4291 if(SHORT1FROMMP(mp2) == '\t')
4292 {
4293 if(CHARMSG(&msg)->fs & KC_SHIFT)
4294 _shift_focus(hwnd, _DW_DIRECTION_BACKWARD);
4295 else
4296 _shift_focus(hwnd, _DW_DIRECTION_FORWARD);
4297 return FALSE;
4298 }
4299 break;
4300 }
4301
4404 if(oldproc) 4302 if(oldproc)
4405 return oldproc(hwnd, msg, mp1, mp2); 4303 return oldproc(hwnd, msg, mp1, mp2);
4406 4304
4407 return WinDefWindowProc(hwnd, msg, mp1, mp2); 4305 return WinDefWindowProc(hwnd, msg, mp1, mp2);
4408 } 4306 }
6005 */ 5903 */
6006 HWND API dw_notebook_new(ULONG id, int top) 5904 HWND API dw_notebook_new(ULONG id, int top)
6007 { 5905 {
6008 ULONG flags; 5906 ULONG flags;
6009 HWND tmp; 5907 HWND tmp;
5908 WindowData *blah = calloc(1, sizeof(WindowData));
6010 5909
6011 if(top) 5910 if(top)
6012 flags = BKS_MAJORTABTOP; 5911 flags = BKS_MAJORTABTOP;
6013 else 5912 else
6014 flags = BKS_MAJORTABBOTTOM; 5913 flags = BKS_MAJORTABBOTTOM;
6033 { 5932 {
6034 /* best sizes to be determined by trial and error */ 5933 /* best sizes to be determined by trial and error */
6035 WinSendMsg(tmp, BKM_SETDIMENSIONS,MPFROM2SHORT(102, 28), MPFROMSHORT( BKA_MAJORTAB)); 5934 WinSendMsg(tmp, BKM_SETDIMENSIONS,MPFROM2SHORT(102, 28), MPFROMSHORT( BKA_MAJORTAB));
6036 } 5935 }
6037 5936
5937 blah->oldproc = WinSubclassWindow(tmp, _NotebookProc);
5938 WinSetWindowPtr(tmp, QWP_USER, blah);
6038 dw_window_set_font(tmp, DefaultFont); 5939 dw_window_set_font(tmp, DefaultFont);
6039 return tmp; 5940 return tmp;
6040 } 5941 }
6041 5942
6042 /* 5943 /*