Mercurial > dwindows
comparison os2/dw.c @ 152:e78027768548
Added MLS_LIMITVSCROLL to the MLE style.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 30 Oct 2002 12:19:26 +0000 |
parents | 656de0c52c56 |
children | a371875d5486 |
comparison
equal
deleted
inserted
replaced
151:656de0c52c56 | 152:e78027768548 |
---|---|
45 | 45 |
46 #define IS_WARP4() (aulBuffer[0] == 20 && aulBuffer[1] >= 40) | 46 #define IS_WARP4() (aulBuffer[0] == 20 && aulBuffer[1] >= 40) |
47 | 47 |
48 #ifndef min | 48 #ifndef min |
49 #define min(a, b) (((a < b) ? a : b)) | 49 #define min(a, b) (((a < b) ? a : b)) |
50 #endif | |
51 | |
52 #ifdef DWDEBUG | |
53 FILE *f; | |
54 | |
55 void reopen(void) | |
56 { | |
57 fclose(f); | |
58 f = fopen("dw.log", "a+"); | |
59 } | |
60 #endif | 50 #endif |
61 | 51 |
62 typedef struct _sighandler | 52 typedef struct _sighandler |
63 { | 53 { |
64 struct _sighandler *next; | 54 struct _sighandler *next; |
892 tmp->parentpad = tmp->pad; | 882 tmp->parentpad = tmp->pad; |
893 | 883 |
894 /* Just in case */ | 884 /* Just in case */ |
895 tmp->xratio = thisbox->xratio; | 885 tmp->xratio = thisbox->xratio; |
896 tmp->yratio = thisbox->yratio; | 886 tmp->yratio = thisbox->yratio; |
897 | |
898 #ifdef DWDEBUG | |
899 if(pass > 1) | |
900 { | |
901 fprintf(f, "FARK! depth %d\r\nwidth = %d, height = %d, nux = %d, nuy = %d, upx = %d, upy = %d xratio = %f, yratio = %f\r\n\r\n", | |
902 *depth, thisbox->items[z].width, thisbox->items[z].height, nux, nuy, tmp->upx, tmp->upy, tmp->xratio, tmp->yratio); | |
903 reopen(); | |
904 } | |
905 #endif | |
906 | 887 |
907 if(thisbox->type == BOXVERT) | 888 if(thisbox->type == BOXVERT) |
908 { | 889 { |
909 if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) | 890 if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) |
910 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))); | 891 tmp->xratio = ((float)((thisbox->items[z].width * thisbox->xratio)-((thisbox->items[z].pad*2)+(tmp->pad*2))))/((float)(thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))); |
929 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); | 910 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); |
930 } | 911 } |
931 | 912 |
932 (*depth)++; | 913 (*depth)++; |
933 | 914 |
934 #ifdef DWDEBUG | |
935 if(pass > 1) | |
936 { | |
937 fprintf(f, "Before Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n", | |
938 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio); | |
939 reopen(); | |
940 } | |
941 #endif | |
942 | |
943 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); | 915 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); |
944 | 916 |
945 (*depth)--; | 917 (*depth)--; |
946 | 918 |
947 newx = x - nux; | 919 newx = x - nux; |
948 newy = y - nuy; | 920 newy = y - nuy; |
949 | 921 |
950 tmp->minwidth = thisbox->items[z].width = initialx - newx; | 922 tmp->minwidth = thisbox->items[z].width = initialx - newx; |
951 tmp->minheight = thisbox->items[z].height = initialy - newy; | 923 tmp->minheight = thisbox->items[z].height = initialy - newy; |
952 | |
953 #ifdef DWDEBUG | |
954 if(pass > 1) | |
955 { | |
956 fprintf(f, "After Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d width = %d, height = %d\r\n\r\n", | |
957 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, thisbox->items[z].width, thisbox->items[z].height); | |
958 reopen(); | |
959 } | |
960 #endif | |
961 } | 924 } |
962 } | 925 } |
963 | 926 |
964 if(pass > 1 && *depth > 0) | 927 if(pass > 1 && *depth > 0) |
965 { | 928 { |
1001 { | 964 { |
1002 tmp->parentxratio = thisbox->items[z].xratio; | 965 tmp->parentxratio = thisbox->items[z].xratio; |
1003 tmp->parentyratio = thisbox->items[z].yratio; | 966 tmp->parentyratio = thisbox->items[z].yratio; |
1004 } | 967 } |
1005 } | 968 } |
1006 | |
1007 #ifdef DWDEBUG | |
1008 fprintf(f, "RATIO- xratio = %f, yratio = %f, width = %d, height = %d, pad = %d, box xratio = %f, box yratio = %f, parent xratio = %f, parent yratio = %f, minwidth = %d, minheight = %d, width = %d, height = %d, upx = %d, upy = %d\r\n\r\n", | |
1009 thisbox->items[z].xratio, thisbox->items[z].yratio, thisbox->items[z].width, thisbox->items[z].height, thisbox->items[z].pad, thisbox->xratio, thisbox->yratio, thisbox->parentxratio, thisbox->parentyratio, thisbox->minwidth, thisbox->minheight, thisbox->width, thisbox->height, thisbox->upx, thisbox->upy); | |
1010 reopen(); | |
1011 #endif | |
1012 } | 969 } |
1013 else | 970 else |
1014 { | 971 { |
1015 thisbox->items[z].xratio = thisbox->xratio; | 972 thisbox->items[z].xratio = thisbox->xratio; |
1016 thisbox->items[z].yratio = thisbox->yratio; | 973 thisbox->items[z].yratio = thisbox->yratio; |
1085 (*usedpadx) += upxmax; | 1042 (*usedpadx) += upxmax; |
1086 (*usedpady) += upymax; | 1043 (*usedpady) += upymax; |
1087 | 1044 |
1088 currentx += thisbox->pad; | 1045 currentx += thisbox->pad; |
1089 currenty += thisbox->pad; | 1046 currenty += thisbox->pad; |
1090 | |
1091 #ifdef DWDEBUG | |
1092 fprintf(f, "Done Calc depth %d\r\nusedx = %d, usedy = %d, usedpadx = %d, usedpady = %d, currentx = %d, currenty = %d, uxmax = %d, uymax = %d\r\n\r\n", | |
1093 *depth, *usedx, *usedy, *usedpadx, *usedpady, currentx, currenty, uxmax, uymax); | |
1094 reopen(); | |
1095 #endif | |
1096 | 1047 |
1097 /* The second pass is for expansion and actual placement. */ | 1048 /* The second pass is for expansion and actual placement. */ |
1098 if(pass > 1) | 1049 if(pass > 1) |
1099 { | 1050 { |
1100 /* Any SIZEEXPAND items should be set to uxmax/uymax */ | 1051 /* Any SIZEEXPAND items should be set to uxmax/uymax */ |
1124 tmp->height = thisbox->items[z].height; | 1075 tmp->height = thisbox->items[z].height; |
1125 } | 1076 } |
1126 } | 1077 } |
1127 | 1078 |
1128 (*depth)++; | 1079 (*depth)++; |
1129 | |
1130 #ifdef DWDEBUG | |
1131 fprintf(f, "2- Resize Box depth %d\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f,\r\nupx = %d, upy = %d, width = %d, height = %d, minwidth = %d, minheight = %d, box xratio = %f, box yratio = %f\r\n\r\n", | |
1132 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio, tmp->upx, tmp->upy, thisbox->items[z].width, thisbox->items[z].height, tmp->minwidth, tmp->minheight, thisbox->xratio, thisbox->yratio); | |
1133 reopen(); | |
1134 #endif | |
1135 | 1080 |
1136 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); | 1081 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); |
1137 | 1082 |
1138 (*depth)--; | 1083 (*depth)--; |
1139 | 1084 |
1203 | 1148 |
1204 } | 1149 } |
1205 | 1150 |
1206 } | 1151 } |
1207 | 1152 |
1208 #ifdef DWDEBUG | |
1209 fprintf(f, "Window Pos depth %d\r\ncurrentx = %d, currenty = %d, pad = %d, width = %d, height = %d, vectorx = %d, vectory = %d, Box type = %s\r\n\r\n", | |
1210 *depth, currentx, currenty, pad, width, height, vectorx, vectory,thisbox->type == BOXHORZ ? "Horizontal" : "Vertical"); | |
1211 reopen(); | |
1212 #endif | |
1213 | |
1214 if(thisbox->type == BOXHORZ) | 1153 if(thisbox->type == BOXHORZ) |
1215 currentx += width + vectorx + (pad * 2); | 1154 currentx += width + vectorx + (pad * 2); |
1216 if(thisbox->type == BOXVERT) | 1155 if(thisbox->type == BOXVERT) |
1217 currenty += height + vectory + (pad * 2); | 1156 currenty += height + vectory + (pad * 2); |
1218 } | 1157 } |
1235 return; | 1174 return; |
1236 | 1175 |
1237 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); | 1176 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); |
1238 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); | 1177 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); |
1239 | 1178 |
1240 #ifdef DWDEBUG | |
1241 fprintf(f, "WM_SIZE Resize Box Pass 1\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d xratio = %f, yratio = %f\r\n\r\n", | |
1242 x, y, usedx, usedy, usedpadx, usedpady, thisbox->xratio, thisbox->yratio); | |
1243 reopen(); | |
1244 #endif | |
1245 | |
1246 usedx = usedy = usedpadx = usedpady = depth = 0; | 1179 usedx = usedy = usedpadx = usedpady = depth = 0; |
1247 | 1180 |
1248 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); | 1181 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); |
1249 #ifdef DWDEBUG | |
1250 fprintf(f, "WM_SIZE Resize Box Pass 2\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d\r\n", | |
1251 x, y, usedx, usedy, usedpadx, usedpady); | |
1252 reopen(); | |
1253 #endif | |
1254 } | 1182 } |
1255 } | 1183 } |
1256 } | 1184 } |
1257 | 1185 |
1258 /* This procedure handles WM_QUERYTRACKINFO requests from the frame */ | 1186 /* This procedure handles WM_QUERYTRACKINFO requests from the frame */ |
2786 rc = WinRegisterClass(dwhab, SplitbarClassName, _splitwndproc, 0L, 32); | 2714 rc = WinRegisterClass(dwhab, SplitbarClassName, _splitwndproc, 0L, 32); |
2787 | 2715 |
2788 /* Get the OS/2 version. */ | 2716 /* Get the OS/2 version. */ |
2789 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_MS_COUNT,(void *)aulBuffer, 4*sizeof(ULONG)); | 2717 DosQuerySysInfo(QSV_VERSION_MAJOR, QSV_MS_COUNT,(void *)aulBuffer, 4*sizeof(ULONG)); |
2790 | 2718 |
2791 #ifdef DWDEBUG | |
2792 f = fopen("dw.log", "w"); | |
2793 #endif | |
2794 return rc; | 2719 return rc; |
2795 } | 2720 } |
2796 | 2721 |
2797 /* | 2722 /* |
2798 * Runs a message loop for Dynamic Windows. | 2723 * Runs a message loop for Dynamic Windows. |
2803 | 2728 |
2804 _dwtid = dw_thread_id(); | 2729 _dwtid = dw_thread_id(); |
2805 | 2730 |
2806 while (WinGetMsg(dwhab, &qmsg, 0, 0, 0)) | 2731 while (WinGetMsg(dwhab, &qmsg, 0, 0, 0)) |
2807 WinDispatchMsg(dwhab, &qmsg); | 2732 WinDispatchMsg(dwhab, &qmsg); |
2808 | |
2809 #ifdef DWDEBUG | |
2810 fclose(f); | |
2811 #endif | |
2812 | 2733 |
2813 WinDestroyMsgQueue(dwhmq); | 2734 WinDestroyMsgQueue(dwhmq); |
2814 WinTerminate(dwhab); | 2735 WinTerminate(dwhab); |
2815 } | 2736 } |
2816 | 2737 |
3762 HWND tmp = WinCreateWindow(HWND_OBJECT, | 3683 HWND tmp = WinCreateWindow(HWND_OBJECT, |
3763 WC_MLE, | 3684 WC_MLE, |
3764 "", | 3685 "", |
3765 WS_VISIBLE | | 3686 WS_VISIBLE | |
3766 MLS_BORDER | MLS_IGNORETAB | | 3687 MLS_BORDER | MLS_IGNORETAB | |
3767 MLS_READONLY | MLS_VSCROLL, | 3688 MLS_READONLY | MLS_VSCROLL | |
3689 MLS_LIMITVSCROLL, | |
3768 0,0,2000,1000, | 3690 0,0,2000,1000, |
3769 NULLHANDLE, | 3691 NULLHANDLE, |
3770 HWND_TOP, | 3692 HWND_TOP, |
3771 id, | 3693 id, |
3772 NULL, | 3694 NULL, |
7307 tmp = tmp->next; | 7229 tmp = tmp->next; |
7308 } | 7230 } |
7309 } | 7231 } |
7310 } | 7232 } |
7311 | 7233 |
7312 #ifdef TEST | |
7313 HWND mainwindow, | |
7314 listbox, | |
7315 okbutton, | |
7316 cancelbutton, | |
7317 lbbox, | |
7318 stext, | |
7319 buttonbox, | |
7320 testwindow, | |
7321 testbox, | |
7322 testok, | |
7323 testcancel, | |
7324 testbox2, | |
7325 testok2, | |
7326 testcancel2, | |
7327 notebook; | |
7328 int count = 2; | |
7329 | |
7330 int test_callback(HWND window, void *data) | |
7331 { | |
7332 dw_window_destroy((HWND)data); | |
7333 /* Return -1 to allow the default handlers to return. */ | |
7334 count--; | |
7335 if(!count) | |
7336 exit(0); | |
7337 return -1; | |
7338 } | |
7339 | |
7340 /* | |
7341 * Let's demonstrate the functionality of this library. :) | |
7342 */ | |
7343 int main(int argc, char *argv[]) | |
7344 { | |
7345 ULONG flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR | | |
7346 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER; | |
7347 int pageid; | |
7348 | |
7349 dw_init(TRUE, argc, argv); | |
7350 | |
7351 /* Try a little server dialog. :) */ | |
7352 mainwindow = dw_window_new(HWND_DESKTOP, "Server", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX); | |
7353 | |
7354 lbbox = dw_box_new(BOXVERT, 10); | |
7355 | |
7356 dw_box_pack_start(mainwindow, lbbox, 0, 0, TRUE, TRUE, 0); | |
7357 | |
7358 stext = dw_text_new("Choose a server:", 0); | |
7359 | |
7360 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER); | |
7361 | |
7362 dw_box_pack_start(lbbox, stext, 130, 15, FALSE, FALSE, 10); | |
7363 | |
7364 listbox = dw_listbox_new(100L, FALSE); | |
7365 | |
7366 dw_box_pack_start(lbbox, listbox, 130, 200, TRUE, TRUE, 10); | |
7367 | |
7368 buttonbox = dw_box_new(BOXHORZ, 0); | |
7369 | |
7370 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0); | |
7371 | |
7372 okbutton = dw_button_new("Ok", 1001L); | |
7373 | |
7374 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, TRUE, 5); | |
7375 | |
7376 cancelbutton = dw_button_new("Cancel", 1002L); | |
7377 | |
7378 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, TRUE, 5); | |
7379 | |
7380 /* Set some nice fonts and colors */ | |
7381 dw_window_set_color(lbbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
7382 dw_window_set_color(buttonbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
7383 dw_window_set_font(stext, "9.WarpSans"); | |
7384 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY); | |
7385 dw_window_set_font(listbox, "9.WarpSans"); | |
7386 dw_window_set_font(okbutton, "9.WarpSans"); | |
7387 dw_window_set_font(cancelbutton, "9.WarpSans"); | |
7388 | |
7389 dw_window_show(mainwindow); | |
7390 | |
7391 dw_window_set_usize(mainwindow, 170, 340); | |
7392 | |
7393 /* Another small example */ | |
7394 flStyle |= FCF_MINMAX | FCF_SIZEBORDER; | |
7395 | |
7396 testwindow = dw_window_new(HWND_DESKTOP, "Wow a test dialog! :) yay!", flStyle); | |
7397 | |
7398 testbox = dw_box_new(BOXVERT, 0); | |
7399 | |
7400 dw_box_pack_start(testwindow, testbox, 0, 0, TRUE, TRUE, 0); | |
7401 | |
7402 notebook = dw_notebook_new(1010L, TRUE); | |
7403 | |
7404 dw_box_pack_start(testbox, notebook, 100, 100, TRUE, TRUE, 0); | |
7405 | |
7406 testbox = dw_box_new(BOXVERT, 10); | |
7407 | |
7408 pageid = dw_notebook_page_new(notebook, 0L, FALSE); | |
7409 | |
7410 dw_notebook_page_set_text(notebook, pageid, "Test page"); | |
7411 dw_notebook_page_set_status_text(notebook, pageid, "Test page"); | |
7412 | |
7413 dw_notebook_pack(notebook, pageid, testbox); | |
7414 | |
7415 testok = dw_button_new("Ok", 1003L); | |
7416 | |
7417 dw_box_pack_start(testbox, testok, 60, 40, TRUE, TRUE, 10); | |
7418 | |
7419 testcancel = dw_button_new("Cancel", 1004L); | |
7420 | |
7421 dw_box_pack_start(testbox, testcancel, 60, 40, TRUE, TRUE, 10); | |
7422 | |
7423 testbox2 = dw_box_new(BOXHORZ, 0); | |
7424 | |
7425 dw_box_pack_start(testbox, testbox2, 0, 0, TRUE, TRUE, 0); | |
7426 | |
7427 testok2 = dw_button_new("Ok", 1003L); | |
7428 | |
7429 dw_box_pack_start(testbox2, testok2, 60, 40, TRUE, TRUE, 10); | |
7430 | |
7431 dw_box_pack_splitbar_start(testbox2); | |
7432 | |
7433 testcancel2 = dw_button_new("Cancel", 1004L); | |
7434 | |
7435 dw_box_pack_start(testbox2, testcancel2, 60, 40, TRUE, TRUE, 10); | |
7436 | |
7437 /* Set some nice fonts and colors */ | |
7438 dw_window_set_color(testbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
7439 dw_window_set_color(testbox2, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY); | |
7440 dw_window_set_font(testok, "9.WarpSans"); | |
7441 dw_window_set_font(testcancel, "9.WarpSans"); | |
7442 dw_window_set_font(testok2, "9.WarpSans"); | |
7443 dw_window_set_font(testcancel2, "9.WarpSans"); | |
7444 | |
7445 dw_window_show(testwindow); | |
7446 | |
7447 /* Setup the function callbacks */ | |
7448 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
7449 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
7450 dw_signal_connect(testok, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
7451 dw_signal_connect(testcancel, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
7452 dw_signal_connect(testok2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
7453 dw_signal_connect(testcancel2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
7454 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow); | |
7455 dw_signal_connect(testwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)testwindow); | |
7456 | |
7457 dw_main(); | |
7458 | |
7459 return 0; | |
7460 } | |
7461 #endif |