Update of /cvsroot/htoolkit/port/src/cbits/Win32 In directory sc8-pr-cvs1:/tmp/cvs-serv30164a/src/cbits/Win32 Modified Files: Button.c CheckBox.c EditBox.c Label.c ListBox.c PopUp.c RadioBox.c Timer.c Util.c Window.c Added Files: Frame.c Log Message: MDI/SDI interface for Windows --- NEW FILE: Frame.c --- #include "Types.h" #include "Internals.h" #include "Handlers_stub.h" #define OSMenuIDEnd 500 LRESULT CALLBACK HMDIFrameFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: handleDismissProcess(); return 0; case WM_CREATE: { HMENU hMenuBar, hMenuWindow; CLIENTCREATESTRUCT clientcreate; hMenuBar = CreateMenu (); // Create the menu bar SetMenu (hWnd,hMenuBar); // and associate it with the frame window hMenuWindow = CreatePopupMenu(); // Create the "Window" menu InsertMenu (hMenuBar, // add it to the menuBar 0xFFFFFFFF, // at the end MF_BYPOSITION | MF_POPUP, // Flags (UINT) hMenuWindow, // the "Window" menu "&Window" // and set its title ); InsertMenu (hMenuWindow,0,MF_BYPOSITION | MF_STRING,OSMenuIDEnd+1,"Arrange &Icons"); // Add "Arrange Icons" command InsertMenu (hMenuWindow,0,MF_BYPOSITION | MF_STRING,OSMenuIDEnd+2,"&Tile Vertically"); // Add "Tile Vertically" command InsertMenu (hMenuWindow,0,MF_BYPOSITION | MF_STRING,OSMenuIDEnd+3,"Tile &Horizontally"); // Add "Tile Horizontally" command InsertMenu (hMenuWindow,0,MF_BYPOSITION | MF_STRING,OSMenuIDEnd+4,"&Cascade"); // Add "Cascade" command clientcreate.hWindowMenu = hMenuWindow; clientcreate.idFirstChild = OSMenuIDEnd+5; // Window ids must be generated from OSMenuIDEnd+5 ghWndClient = CreateWindow ("MDICLIENT", // The MDICLIENT window class NULL, // The window name MDIS_ALLCHILDSTYLES | WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE, 0,0, // position (x,y) 0,0, // size (w,h) hWnd, // The frame window is the parent NULL, // The menu (none at the moment) (HANDLE) ghModule, // Instance that owns the window (LPVOID) &clientcreate // The CLIENTCREATESTRUCT ); if (!ghWndClient) return -1; gActiveObjects++; } break; case WM_SIZE: { int nWidth = LOWORD(lParam); int nHeight = HIWORD(lParam); SetWindowPos(GetWindow(hWnd,GW_CHILD),NULL,0,0,nWidth,nHeight,SWP_NOZORDER); } break; case WM_COMMAND: if (HIWORD (wParam)==0 && lParam!=0) { } else switch (wParam) { case (OSMenuIDEnd+1): SendMessage (GetWindow(hWnd,GW_CHILD),WM_MDIICONARRANGE,0,0); break; case (OSMenuIDEnd+2): SendMessage (GetWindow(hWnd,GW_CHILD),WM_MDITILE,(WPARAM) MDITILE_VERTICAL,0); break; case (OSMenuIDEnd+3): SendMessage (GetWindow(hWnd,GW_CHILD),WM_MDITILE,(WPARAM) MDITILE_HORIZONTAL,0); break; case (OSMenuIDEnd+4): SendMessage (GetWindow(hWnd,GW_CHILD),WM_MDICASCADE,0,0); break; } break; case WM_DESTROY: gActiveObjects--; break; } return DefFrameProc (hWnd, GetWindow(hWnd,GW_CHILD), uMsg, wParam, lParam); }; Index: Button.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Button.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Button.c 23 Jan 2003 20:19:32 -0000 1.2 --- Button.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 7,12 **** HWND hButton; - initGUI(); - hButton = CreateWindow( "BUTTON", --- 7,10 ---- Index: CheckBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/CheckBox.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CheckBox.c 23 Jan 2003 20:19:32 -0000 1.2 --- CheckBox.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 6,11 **** HWND hCheckBox; - initGUI(); - hCheckBox = CreateWindow( "BUTTON", --- 6,9 ---- Index: EditBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/EditBox.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** EditBox.c 27 Jan 2003 22:02:44 -0000 1.3 --- EditBox.c 10 Feb 2003 22:42:10 -0000 1.4 *************** *** 7,12 **** HWND hEdit; - initGUI(); - hEdit = CreateWindowEx( WS_EX_CLIENTEDGE, --- 7,10 ---- *************** *** 31,35 **** int nLen = 1; char *buffer = "m"; /* pretend a single letter as a minimal size */ ! if (hFont) SelectObject(hDC, hFont); GetTextExtentPoint32(hDC, buffer, nLen, &sz); --- 29,33 ---- int nLen = 1; char *buffer = "m"; /* pretend a single letter as a minimal size */ ! if (hFont) SelectObject(hDC, hFont); GetTextExtentPoint32(hDC, buffer, nLen, &sz); Index: Label.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Label.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Label.c 23 Jan 2003 20:19:32 -0000 1.2 --- Label.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 7,12 **** HWND hText; - initGUI(); - hText = CreateWindow( "STATIC", --- 7,10 ---- Index: ListBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/ListBox.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ListBox.c 23 Jan 2003 20:19:32 -0000 1.2 --- ListBox.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 7,12 **** HWND hListBox; - initGUI(); - hListBox = CreateWindowEx( WS_EX_CLIENTEDGE, --- 7,10 ---- Index: PopUp.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/PopUp.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PopUp.c 23 Jan 2003 20:19:32 -0000 1.2 --- PopUp.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 7,12 **** HWND hPopUp; - initGUI(); - hPopUp = CreateWindow( "COMBOBOX", --- 7,10 ---- Index: RadioBox.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/RadioBox.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RadioBox.c 23 Jan 2003 20:19:32 -0000 1.2 --- RadioBox.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 6,11 **** HWND hCheckBox; - initGUI(); - hCheckBox = CreateWindow( "BUTTON", --- 6,9 ---- Index: Timer.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Timer.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Timer.c 21 Jan 2003 22:01:13 -0000 1.1 --- Timer.c 10 Feb 2003 22:42:10 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- #include "Timer.h" #include "Handlers_stub.h" + #include "Internals.h" static VOID CALLBACK osTimerProc(HWND hwnd, UINT msg, UINT_PTR timer, DWORD time) *************** *** 10,14 **** { TimerHandle r = (TimerHandle)SetTimer( NULL, 0, msecs, osTimerProc ); ! if (r==NULL) { printf( "Timer: failed to create timer\n" ); } return r; } --- 11,21 ---- { TimerHandle r = (TimerHandle)SetTimer( NULL, 0, msecs, osTimerProc ); ! if (!r) ! { ! printf( "Timer: failed to create timer\n" ); ! return NULL; ! } ! ! gActiveObjects++; return r; } *************** *** 17,21 **** --- 24,31 ---- { if (timer!=NULL) + { KillTimer(NULL,(UINT_PTR)timer); + gActiveObjects--; + } } Index: Util.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Util.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Util.c 23 Jan 2003 20:19:32 -0000 1.2 --- Util.c 10 Feb 2003 22:42:10 -0000 1.3 *************** *** 8,12 **** HMODULE ghModule = NULL; HFONT ghControlFont = NULL; ! static BOOL bIsRunning = FALSE; void *rmalloc (DWORD bytes) --- 8,16 ---- HMODULE ghModule = NULL; HFONT ghControlFont = NULL; ! int gDocumentInterface; ! HWND ghWndFrame; ! HWND ghWndClient; ! DWORD gActiveObjects; ! LPCSTR gAppName; void *rmalloc (DWORD bytes) *************** *** 30,33 **** --- 34,39 ---- extern LRESULT CALLBACK HWindowFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); extern LRESULT CALLBACK HDialogFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + extern LRESULT CALLBACK HMDIFrameFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + extern LRESULT CALLBACK HMDIWindowFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static ATOM classDialog = 0; *************** *** 45,49 **** */ ! void initGUI() { if (!ghModule) --- 51,55 ---- */ ! void osInit(char *AppName, int DocumentInterface) { if (!ghModule) *************** *** 65,69 **** wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);; wc.lpszMenuName = NULL; wc.lpszClassName = "HWINDOW"; --- 71,75 ---- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = "HWINDOW"; *************** *** 77,86 **** wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1);; wc.lpszMenuName = NULL; wc.lpszClassName = "HDIALOG"; classDialog = RegisterClass(&wc); // Globally, we create a logical font that is used in all controls. --- 83,116 ---- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); ! wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.lpszMenuName = NULL; wc.lpszClassName = "HDIALOG"; classDialog = RegisterClass(&wc); + // Window class for MDIFrame + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = HMDIFrameFunction; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = ghModule; + wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH) (COLOR_APPWORKSPACE+1); // For best results (Petzold) + wc.lpszMenuName = NULL; + wc.lpszClassName = "HFRAME"; + RegisterClass(&wc); + // Window class for MDIWindow + wc.style = CS_DBLCLKS; + wc.lpfnWndProc = HMDIWindowFunction; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = ghModule; + wc.hIcon = LoadIcon (NULL, IDI_APPLICATION); + wc.hCursor = LoadCursor (NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE+1); // For best results (Petzold) + wc.lpszMenuName = NULL; + wc.lpszClassName = "HMDIWINDOW"; + RegisterClass(&wc); // Globally, we create a logical font that is used in all controls. *************** *** 104,107 **** --- 134,158 ---- icc.dwICC = ICC_WIN95_CLASSES; InitCommonControlsEx(&icc); + + gActiveObjects = 0; + gAppName = strdup(AppName); + gDocumentInterface = DocumentInterface; + + if (gDocumentInterface == 2) + { + ghWndClient = NULL; + ghWndFrame = CreateWindow ( "HFRAME", + AppName, + WS_OVERLAPPEDWINDOW, + CW_USEDEFAULT,CW_USEDEFAULT, + CW_USEDEFAULT,CW_USEDEFAULT, + NULL, + NULL, + (HANDLE) ghModule, + NULL + ); + ShowWindow(ghWndFrame,SW_MAXIMIZE); + UpdateWindow(ghWndFrame); + } } }; *************** *** 123,128 **** MSG msg; ! bIsRunning = TRUE; ! while (bIsRunning) { handleMenusUpdate(); --- 174,178 ---- MSG msg; ! while (gActiveObjects > 0) { handleMenusUpdate(); *************** *** 133,141 **** DispatchMessage(&msg); ! if (!bIsRunning) return; }; ! if (!bIsRunning) return; --- 183,191 ---- DispatchMessage(&msg); ! if (gActiveObjects <= 0) return; }; ! if (gActiveObjects <= 0) return; *************** *** 146,162 **** } } - }; - - static BOOL CALLBACK fn(HWND hWnd,LPARAM lParam) - { - char buffer[20]; - - GetClassName(hWnd,buffer,sizeof(buffer)); - if ((_stricmp(buffer, "HDIALOG") == 0) || (_stricmp(buffer, "HWINDOW") == 0)) - { - DestroyWindow(hWnd); - } ! return TRUE; }; --- 196,201 ---- } } ! handleDestroyProcess(); }; *************** *** 165,170 **** void osQuit() { ! EnumThreadWindows(GetCurrentThreadId(),fn,0); doneGdiPlus(); ! bIsRunning = FALSE; } --- 204,219 ---- void osQuit() { ! if (gDocumentInterface == 2) ! { ! DestroyWindow(ghWndFrame); ! } ! ! if (gActiveObjects > 0) ! { ! printf("WARNING: There are still have active objects\n"); ! } ! doneGdiPlus(); ! ! free(gAppName); } Index: Window.c =================================================================== RCS file: /cvsroot/htoolkit/port/src/cbits/Win32/Window.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Window.c 31 Jan 2003 22:50:04 -0000 1.5 --- Window.c 10 Feb 2003 22:42:10 -0000 1.6 *************** *** 139,143 **** } ! LRESULT CALLBACK HWindowSharedFunction( BOOL isDialog, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WindowData *pData = (WindowData *) GetWindowLong(hWnd,GWL_USERDATA); --- 139,143 ---- } ! LRESULT CALLBACK HWindowSharedFunction(WNDPROC pDefWindowProc, HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { WindowData *pData = (WindowData *) GetWindowLong(hWnd,GWL_USERDATA); *************** *** 167,174 **** pData->nWindowKind = ((int) lpcs->lpCreateParams); SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); } break; case WM_CLOSE: ! handleWindowClose(hWnd); return 0; case WM_DESTROY: --- 167,176 ---- pData->nWindowKind = ((int) lpcs->lpCreateParams); SetWindowLong(hWnd,GWL_USERDATA,(LONG) pData); + + gActiveObjects++; } break; case WM_CLOSE: ! handleWindowDismiss(hWnd); return 0; case WM_DESTROY: *************** *** 180,183 **** --- 182,186 ---- handleWindowDestroy(hWnd); + gActiveObjects--; break; case WM_COMMAND: *************** *** 498,502 **** if (!pData->bInMouseMoveMode) SetCapture(hWnd); handleWindowMouse(hWnd,evMouseLeftDown,pos.x,pos.y,GetModifiers()); - SetActiveWindow(hWnd); } } --- 501,504 ---- *************** *** 688,695 **** } ! /* DAAN: Call the appropiate default window handler based on the window class. ! this enables proper handling of system keys for menu bars for example. */ ! if (isDialog) return DefDlgProc(hWnd, uMsg, wParam, lParam); ! else return DefWindowProc(hWnd, uMsg, wParam, lParam); }; --- 690,694 ---- } ! return pDefWindowProc(hWnd, uMsg, wParam, lParam); }; *************** *** 697,708 **** LRESULT CALLBACK HWindowFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! return HWindowSharedFunction( FALSE, hWnd, uMsg, wParam, lParam ); } LRESULT CALLBACK HDialogFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! return HWindowSharedFunction( TRUE, hWnd, uMsg, wParam, lParam ); } void osInvalidateWindow(WindowHandle window) --- 696,768 ---- LRESULT CALLBACK HWindowFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! switch (uMsg) ! { ! case WM_LBUTTONDOWN: ! SetActiveWindow(hWnd); ! break; ! } ! ! return HWindowSharedFunction(DefWindowProc, hWnd, uMsg, wParam, lParam ); } LRESULT CALLBACK HDialogFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { ! switch (uMsg) ! { ! case WM_LBUTTONDOWN: ! SetActiveWindow(hWnd); ! break; ! } ! ! return HWindowSharedFunction(DefDlgProc, hWnd, uMsg, wParam, lParam ); } + LRESULT CALLBACK HMDIWindowFunction(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) + { + switch (uMsg) + { + case WM_SETTEXT: + { + char *title, *s; + int nTextLen; + + s = (char *) lParam; + nTextLen = strlen(s); + title = rmalloc(strlen(gAppName)+nTextLen+6); + + strcpy(title, gAppName); + strcat(title, " - ["); + strcat(title, s); + strcat(title, "]"); + SetWindowText(ghWndFrame, title); + } + break; + case WM_MDIACTIVATE: + { + char *title; + int nTextLen; + + nTextLen = GetWindowTextLength(hWnd); + title = rmalloc(strlen(gAppName)+nTextLen+6); + + strcpy(title, gAppName); + strcat(title, " - ["); + GetWindowText(hWnd, title+strlen(title), nTextLen+1); + strcat(title, "]"); + SetWindowText(ghWndFrame, title); + } + break; + case WM_DESTROY: + SetWindowText(ghWndFrame, gAppName); + SendMessage(ghWndClient, WM_MDIREFRESHMENU, 0, 0); + DrawMenuBar(ghWndFrame); + break; + case WM_LBUTTONDOWN: + SendMessage(ghWndClient,WM_MDIACTIVATE,(WPARAM) hWnd,0); + break; + }; + + return HWindowSharedFunction(DefMDIChildProc, hWnd, uMsg, wParam, lParam ); + } void osInvalidateWindow(WindowHandle window) *************** *** 725,740 **** HWND hWnd; ! initGUI(); ! hWnd = CreateWindow( ! "HWINDOW", ! NULL, ! WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, ! CW_USEDEFAULT,0,0,0, ! NULL, ! NULL, ! ghModule, ! NULL ! ); return checkWindow(hWnd, "HWINDOW"); --- 785,822 ---- HWND hWnd; ! switch (gDocumentInterface) ! { ! case 1: // SDI ! hWnd = CreateWindow( ! "HWINDOW", ! NULL, ! WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, ! CW_USEDEFAULT,0,0,0, ! NULL, ! NULL, ! ghModule, ! NULL ! ); ! break; ! case 2: // MDI ! { ! MDICREATESTRUCT mdicreate; // The structure sent to the client window ! /* fill the MDICREATESTRUCT record */ ! mdicreate.szClass = "HMDIWINDOW"; ! mdicreate.szTitle = ""; ! mdicreate.hOwner = ghModule; ! mdicreate.x = 0; ! mdicreate.y = 0; ! mdicreate.cx = 0; ! mdicreate.cy = 0; ! mdicreate.style = WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL; ! mdicreate.lParam = 0; ! ! /* create the window */ ! hWnd = (HWND) SendMessage (ghWndClient,WM_MDICREATE,0,(LPARAM) &mdicreate); ! } ! break; ! } return checkWindow(hWnd, "HWINDOW"); *************** *** 749,754 **** HWND hDlg; - initGUI(); - // start to fill in the dlgtemplate information. Addressing by WORDs lStyle = WS_CAPTION | DS_SETFONT | WS_SYSMENU | WS_OVERLAPPEDWINDOW; --- 831,834 ---- *************** *** 776,799 **** }; - WindowHandle osCreateMDIWindow(WindowHandle mdiWindow) - { - HWND hWnd; - - initGUI(); - - hWnd = CreateWindow( - "HWINDOW", - NULL, - WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL, - CW_USEDEFAULT,0,0,0, - mdiWindow, - NULL, - ghModule, - NULL - ); - - return checkWindow(hWnd, "HWINDOW"); - }; - void osSetWindowColor(WindowHandle window, int foreColor, int backColor, int hatchStyle, BitmapHandle patBmp) { --- 856,859 ---- *************** *** 841,846 **** RECT crect, wrect; - initGUI(); - GetClientRect(window,&crect); GetWindowRect(window,&wrect); --- 901,904 ---- *************** *** 950,956 **** } ! void osCloseWindow(WindowHandle window) { ! DestroyWindow(window); } --- 1008,1020 ---- } ! BOOL osDismissWindow(WindowHandle window) { ! SendMessage(window, WM_CLOSE, 0, 0); ! return !IsWindow(window); ! } ! ! void osDestroyWindow(WindowHandle window) ! { ! DestroyWindow(window); } |