comparison win/dw.c @ 153:a371875d5486

Sync up with the latest F/X sources.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 06 Nov 2002 17:28:04 +0000
parents 656de0c52c56
children 840c54766306
comparison
equal deleted inserted replaced
152:e78027768548 153:a371875d5486
48 #define THREAD_LIMIT 128 48 #define THREAD_LIMIT 128
49 COLORREF _foreground[THREAD_LIMIT]; 49 COLORREF _foreground[THREAD_LIMIT];
50 COLORREF _background[THREAD_LIMIT]; 50 COLORREF _background[THREAD_LIMIT];
51 HPEN _hPen[THREAD_LIMIT]; 51 HPEN _hPen[THREAD_LIMIT];
52 HBRUSH _hBrush[THREAD_LIMIT]; 52 HBRUSH _hBrush[THREAD_LIMIT];
53
54 #ifdef DWDEBUG
55 FILE *f;
56
57 void reopen(void)
58 {
59 fclose(f);
60 f = fopen("dw.log", "at");
61 }
62 #endif
63 53
64 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77, 54 BYTE _red[] = { 0x00, 0xbb, 0x00, 0xaa, 0x00, 0xbb, 0x00, 0xaa, 0x77,
65 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 }; 55 0xff, 0x00, 0xee, 0x00, 0xff, 0x00, 0xff, 0xaa, 0x00 };
66 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77, 56 BYTE _green[] = { 0x00, 0x00, 0xbb, 0xaa, 0x00, 0x00, 0xbb, 0xaa, 0x77,
67 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 }; 57 0x00, 0xff, 0xee, 0x00, 0x00, 0xee, 0xff, 0xaa, 0x00 };
485 { 475 {
486 char tmpbuf[100] = ""; 476 char tmpbuf[100] = "";
487 477
488 GetClassName(box->items[z].hwnd, tmpbuf, 99); 478 GetClassName(box->items[z].hwnd, tmpbuf, 99);
489 479
490 if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */ 480 if(strncmp(tmpbuf, SplitbarClassName, strlen(SplitbarClassName)+1)==0)
481 {
482 /* Then try the bottom or right box */
483 HWND mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_bottomright");
484
485 if(mybox)
486 {
487 Box *splitbox = (Box *)GetWindowLong(mybox, GWL_USERDATA);
488
489 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem))
490 return 1;
491 }
492
493 /* Try the top or left box */
494 mybox = (HWND)dw_window_get_data(box->items[z].hwnd, "_dw_topleft");
495
496 if(mybox)
497 {
498 Box *splitbox = (Box *)GetWindowLong(mybox, GWL_USERDATA);
499
500 if(splitbox && _focus_check_box(splitbox, handle, start == 3 ? 3 : 0, defaultitem))
501 return 1;
502 }
503 }
504 else if(strnicmp(tmpbuf, WC_TABCONTROL, strlen(WC_TABCONTROL))==0) /* Notebook */
491 { 505 {
492 NotebookPage **array = (NotebookPage **)GetWindowLong(box->items[z].hwnd, GWL_USERDATA); 506 NotebookPage **array = (NotebookPage **)GetWindowLong(box->items[z].hwnd, GWL_USERDATA);
493 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd); 507 int pageid = TabCtrl_GetCurSel(box->items[z].hwnd);
494 508
495 if(pageid > -1 && array && array[pageid]) 509 if(pageid > -1 && array && array[pageid])
758 772
759 /* Just in case */ 773 /* Just in case */
760 tmp->xratio = thisbox->xratio; 774 tmp->xratio = thisbox->xratio;
761 tmp->yratio = thisbox->yratio; 775 tmp->yratio = thisbox->yratio;
762 776
763 #ifdef DWDEBUG
764 if(pass > 1)
765 {
766 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",
767 *depth, thisbox->items[z].width, thisbox->items[z].height, nux, nuy, tmp->upx, tmp->upy, tmp->xratio, tmp->yratio);
768 reopen();
769 }
770 #endif
771 if(thisbox->type == BOXVERT) 777 if(thisbox->type == BOXVERT)
772 { 778 {
773 if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0) 779 if((thisbox->items[z].width-((thisbox->items[z].pad*2)+(tmp->pad*2)))!=0)
774 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)))); 780 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))));
775 } 781 }
793 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2); 799 upx = *usedpadx + (tmp->pad*2); upy = *usedpady + (tmp->pad*2);
794 } 800 }
795 801
796 (*depth)++; 802 (*depth)++;
797 803
798 #ifdef DWDEBUG
799 if(pass > 1)
800 {
801 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",
802 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, tmp->xratio, tmp->yratio);
803 reopen();
804 }
805 #endif
806
807 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy); 804 _resize_box(tmp, depth, x, y, &nux, &nuy, pass, &upx, &upy);
808 805
809 (*depth)--; 806 (*depth)--;
810 807
811 newx = x - nux; 808 newx = x - nux;
812 newy = y - nuy; 809 newy = y - nuy;
813 810
814 tmp->minwidth = thisbox->items[z].width = initialx - newx; 811 tmp->minwidth = thisbox->items[z].width = initialx - newx;
815 tmp->minheight = thisbox->items[z].height = initialy - newy; 812 tmp->minheight = thisbox->items[z].height = initialy - newy;
816
817 #ifdef DWDEBUG
818 if(pass > 1)
819 {
820 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",
821 *depth, x, y, *usedx, *usedy, *usedpadx, *usedpady, thisbox->items[z].width, thisbox->items[z].height);
822 reopen();
823 }
824 #endif
825 } 813 }
826 } 814 }
827 815
828 if(pass > 1 && *depth > 0) 816 if(pass > 1 && *depth > 0)
829 { 817 {
865 { 853 {
866 tmp->parentxratio = thisbox->items[z].xratio; 854 tmp->parentxratio = thisbox->items[z].xratio;
867 tmp->parentyratio = thisbox->items[z].yratio; 855 tmp->parentyratio = thisbox->items[z].yratio;
868 } 856 }
869 } 857 }
870
871 #ifdef DWDEBUG
872 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",
873 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);
874 reopen();
875 #endif
876 } 858 }
877 else 859 else
878 { 860 {
879 thisbox->items[z].xratio = thisbox->xratio; 861 thisbox->items[z].xratio = thisbox->xratio;
880 thisbox->items[z].yratio = thisbox->yratio; 862 thisbox->items[z].yratio = thisbox->yratio;
949 (*usedpadx) += upxmax; 931 (*usedpadx) += upxmax;
950 (*usedpady) += upymax; 932 (*usedpady) += upymax;
951 933
952 currentx += thisbox->pad; 934 currentx += thisbox->pad;
953 currenty += thisbox->pad; 935 currenty += thisbox->pad;
954
955 #ifdef DWDEBUG
956 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",
957 *depth, *usedx, *usedy, *usedpadx, *usedpady, currentx, currenty, uxmax, uymax);
958 reopen();
959 #endif
960 936
961 /* The second pass is for expansion and actual placement. */ 937 /* The second pass is for expansion and actual placement. */
962 if(pass > 1) 938 if(pass > 1)
963 { 939 {
964 /* Any SIZEEXPAND items should be set to uxmax/uymax */ 940 /* Any SIZEEXPAND items should be set to uxmax/uymax */
988 tmp->height = thisbox->items[z].height; 964 tmp->height = thisbox->items[z].height;
989 } 965 }
990 } 966 }
991 967
992 (*depth)++; 968 (*depth)++;
993
994 #ifdef DWDEBUG
995 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",
996 *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);
997 reopen();
998 #endif
999 969
1000 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy); 970 _resize_box(tmp, depth, x, y, &nux, &nuy, 3, &nupx, &nupy);
1001 971
1002 (*depth)--; 972 (*depth)--;
1003 973
1112 MoveWindow(array[pageid]->hwnd, rect.left, rect.top, 1082 MoveWindow(array[pageid]->hwnd, rect.left, rect.top,
1113 rect.right - rect.left, rect.bottom-rect.top, TRUE); 1083 rect.right - rect.left, rect.bottom-rect.top, TRUE);
1114 } 1084 }
1115 } 1085 }
1116 1086
1117 #ifdef DWDEBUG
1118 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",
1119 *depth, currentx, currenty, pad, width, height, vectorx, vectory,thisbox->type == BOXHORZ ? "Horizontal" : "Vertical");
1120 reopen();
1121 #endif
1122
1123 if(thisbox->type == BOXHORZ) 1087 if(thisbox->type == BOXHORZ)
1124 currentx += width + vectorx + (pad * 2); 1088 currentx += width + vectorx + (pad * 2);
1125 if(thisbox->type == BOXVERT) 1089 if(thisbox->type == BOXVERT)
1126 currenty += height + vectory + (pad * 2); 1090 currenty += height + vectory + (pad * 2);
1127 } 1091 }
1144 return; 1108 return;
1145 1109
1146 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx)); 1110 thisbox->xratio = ((float)(x-usedpadx))/((float)(usedx-usedpadx));
1147 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady)); 1111 thisbox->yratio = ((float)(y-usedpady))/((float)(usedy-usedpady));
1148 1112
1149 #ifdef DWDEBUG
1150 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",
1151 x, y, usedx, usedy, usedpadx, usedpady, thisbox->xratio, thisbox->yratio);
1152 reopen();
1153 #endif
1154
1155 usedpadx = usedpady = usedx = usedy = depth = 0; 1113 usedpadx = usedpady = usedx = usedy = depth = 0;
1156 1114
1157 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady); 1115 _resize_box(thisbox, &depth, x, y, &usedx, &usedy, 2, &usedpadx, &usedpady);
1158
1159 #ifdef DWDEBUG
1160 fprintf(f, "WM_SIZE Resize Box Pass 2\r\nx = %d, y = %d, usedx = %d, usedy = %d, usedpadx = %d, usedpady = %d\r\n",
1161 x, y, usedx, usedy, usedpadx, usedpady);
1162 reopen();
1163 #endif
1164 } 1116 }
1165 } 1117 }
1166 } 1118 }
1167 1119
1168 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */ 1120 /* The main window procedure for Dynamic Windows, all the resizing code is done here. */
2753 { 2705 {
2754 dw_messagebox("Dynamic Windows", "Could not initialize the object window. error code %d", GetLastError()); 2706 dw_messagebox("Dynamic Windows", "Could not initialize the object window. error code %d", GetLastError());
2755 exit(1); 2707 exit(1);
2756 } 2708 }
2757 2709
2758 #ifdef DWDEBUG
2759 f = fopen("dw.log", "wt");
2760 #endif
2761 /* We need the version to check capability like up-down controls */ 2710 /* We need the version to check capability like up-down controls */
2762 dwVersion = GetVersion(); 2711 dwVersion = GetVersion();
2763 dwComctlVer = GetDllVersion(TEXT("comctl32.dll")); 2712 dwComctlVer = GetDllVersion(TEXT("comctl32.dll"));
2764 2713
2765 for(z=0;z<THREAD_LIMIT;z++) 2714 for(z=0;z<THREAD_LIMIT;z++)
2785 while (GetMessage(&msg, NULL, 0, 0)) 2734 while (GetMessage(&msg, NULL, 0, 0))
2786 { 2735 {
2787 TranslateMessage(&msg); 2736 TranslateMessage(&msg);
2788 DispatchMessage(&msg); 2737 DispatchMessage(&msg);
2789 } 2738 }
2790
2791 #ifdef DWDEBUG
2792 fclose(f);
2793 #endif
2794 } 2739 }
2795 2740
2796 /* 2741 /*
2797 * Runs a message loop for Dynamic Windows, for a period of milliseconds. 2742 * Runs a message loop for Dynamic Windows, for a period of milliseconds.
2798 * Parameters: 2743 * Parameters:
7185 tmp = tmp->next; 7130 tmp = tmp->next;
7186 } 7131 }
7187 } 7132 }
7188 } 7133 }
7189 7134
7190 #ifdef TEST
7191 HWND mainwindow,
7192 listbox,
7193 okbutton,
7194 cancelbutton,
7195 lbbox,
7196 stext,
7197 buttonbox,
7198 testwindow,
7199 testbox,
7200 testok,
7201 testcancel,
7202 testbox2,
7203 testok2,
7204 testcancel2,
7205 notebook;
7206 int count = 2;
7207
7208 int test_callback(HWND window, void *data)
7209 {
7210 dw_window_destroy((HWND)data);
7211 /* Return -1 to allow the default handlers to return. */
7212 count--;
7213 if(!count)
7214 exit(0);
7215 return -1;
7216 }
7217
7218 /*
7219 * Let's demonstrate the functionality of this library. :)
7220 */
7221 int main(int argc, char *argv[])
7222 {
7223 ULONG flStyle = DW_FCF_SYSMENU | DW_FCF_TITLEBAR |
7224 DW_FCF_SHELLPOSITION | DW_FCF_TASKLIST | DW_FCF_DLGBORDER;
7225 int pageid;
7226
7227 dw_init(TRUE, argc, argv);
7228
7229 /* Try a little server dialog. :) */
7230 mainwindow = dw_window_new(HWND_DESKTOP, "Server", flStyle | DW_FCF_SIZEBORDER | DW_FCF_MINMAX);
7231
7232 lbbox = dw_box_new(BOXVERT, 10);
7233
7234 dw_box_pack_start(mainwindow, lbbox, 0, 0, TRUE, TRUE, 0);
7235
7236 stext = dw_text_new("Choose a server:", 0);
7237
7238 dw_window_set_style(stext, DW_DT_VCENTER, DW_DT_VCENTER);
7239
7240 dw_box_pack_start(lbbox, stext, 130, 15, FALSE, FALSE, 10);
7241
7242 listbox = dw_listbox_new(100L, FALSE);
7243
7244 dw_box_pack_start(lbbox, listbox, 130, 200, TRUE, TRUE, 10);
7245
7246 buttonbox = dw_box_new(BOXHORZ, 0);
7247
7248 dw_box_pack_start(lbbox, buttonbox, 0, 0, TRUE, TRUE, 0);
7249
7250 okbutton = dw_button_new("Ok", 1001L);
7251
7252 dw_box_pack_start(buttonbox, okbutton, 50, 30, TRUE, TRUE, 5);
7253
7254 cancelbutton = dw_button_new("Cancel", 1002L);
7255
7256 dw_box_pack_start(buttonbox, cancelbutton, 50, 30, TRUE, TRUE, 5);
7257
7258 /* Set some nice fonts and colors */
7259 dw_window_set_color(lbbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
7260 dw_window_set_color(buttonbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
7261 dw_window_set_font(stext, "9.WarpSans");
7262 dw_window_set_color(stext, DW_CLR_BLACK, DW_CLR_PALEGRAY);
7263 dw_window_set_font(listbox, "9.WarpSans");
7264 dw_window_set_font(okbutton, "9.WarpSans");
7265 dw_window_set_font(cancelbutton, "9.WarpSans");
7266
7267 dw_window_show(mainwindow);
7268
7269 dw_window_set_usize(mainwindow, 170, 340);
7270
7271 /* Another small example */
7272 flStyle |= DW_FCF_MINMAX | DW_FCF_SIZEBORDER;
7273
7274 testwindow = dw_window_new(HWND_DESKTOP, "Wow a test dialog! :) yay!", flStyle);
7275
7276 testbox = dw_box_new(BOXVERT, 0);
7277
7278 dw_box_pack_start(testwindow, testbox, 0, 0, TRUE, TRUE, 0);
7279
7280 notebook = dw_notebook_new(1010L, TRUE);
7281
7282 dw_box_pack_start(testbox, notebook, 100, 100, TRUE, TRUE, 0);
7283
7284 testbox = dw_box_new(BOXVERT, 10);
7285
7286 pageid = dw_notebook_page_new(notebook, 0L, FALSE);
7287
7288 dw_notebook_page_set_text(notebook, pageid, "Test page");
7289 dw_notebook_page_set_status_text(notebook, pageid, "Test page");
7290
7291 dw_notebook_pack(notebook, pageid, testbox);
7292
7293 testok = dw_button_new("Ok", 1003L);
7294
7295 dw_box_pack_start(testbox, testok, 60, 40, TRUE, TRUE, 10);
7296
7297 testcancel = dw_button_new("Cancel", 1004L);
7298
7299 dw_box_pack_start(testbox, testcancel, 60, 40, TRUE, TRUE, 10);
7300
7301 testbox2 = dw_box_new(BOXHORZ, 0);
7302
7303 dw_box_pack_start(testbox, testbox2, 0, 0, TRUE, TRUE, 0);
7304
7305 testok2 = dw_button_new("Ok", 1003L);
7306
7307 dw_box_pack_start(testbox2, testok2, 60, 40, TRUE, TRUE, 10);
7308
7309 dw_box_pack_splitbar_start(testbox2);
7310
7311 testcancel2 = dw_button_new("Cancel", 1004L);
7312
7313 dw_box_pack_start(testbox2, testcancel2, 60, 40, TRUE, TRUE, 10);
7314
7315 /* Set some nice fonts and colors */
7316 dw_window_set_color(testbox, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
7317 dw_window_set_color(testbox2, DW_CLR_PALEGRAY, DW_CLR_PALEGRAY);
7318 dw_window_set_font(testok, "9.WarpSans");
7319 dw_window_set_font(testcancel, "9.WarpSans");
7320 dw_window_set_font(testok2, "9.WarpSans");
7321 dw_window_set_font(testcancel2, "9.WarpSans");
7322
7323 dw_window_show(testwindow);
7324
7325 /* Setup the function callbacks */
7326 dw_signal_connect(okbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow);
7327 dw_signal_connect(cancelbutton, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow);
7328 dw_signal_connect(testok, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow);
7329 dw_signal_connect(testcancel, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow);
7330 dw_signal_connect(testok2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow);
7331 dw_signal_connect(testcancel2, "clicked", DW_SIGNAL_FUNC(test_callback), (void *)testwindow);
7332 dw_signal_connect(mainwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)mainwindow);
7333 dw_signal_connect(testwindow, "delete_event", DW_SIGNAL_FUNC(test_callback), (void *)testwindow);
7334
7335 dw_main();
7336
7337 return 0;
7338 }
7339 #endif