Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

windlg.cpp

Go to the documentation of this file.
00001 /* $Id: windlg.cpp,v 1.29 2001/11/30 18:45:51 sandervl Exp $ */
00002 /*
00003  * Win32 dialog apis for OS/2
00004  *
00005  * Copyright 1999 Sander van Leeuwen
00006  *
00007  * Parts based on Wine code (990815; window\dialog.c)
00008  *
00009  * Copyright 1993, 1994, 1996 Alexandre Julliard
00010  *
00011  * Project Odin Software License can be found in LICENSE.TXT
00012  *
00013  */
00014 #include <ctype.h>
00015 #include <wchar.h>
00016 #include <os2win.h>
00017 #include <misc.h>
00018 #include <stdio.h>
00019 #include <string.h>
00020 #include <stdlib.h>
00021 #include <limits.h>
00022 #include <errno.h>
00023 #include "win32wbase.h"
00024 #include "win32dlg.h"
00025 #include <heapstring.h>
00026 #include <win\drive.h>
00027 #include <custombuild.h>
00028 
00029 #define DBG_LOCALLOG    DBG_windlg
00030 #include "dbglocal.h"
00031 
00032 static INT  DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
00033 static INT  DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
00034 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len, INT id, BOOL win32, BOOL unicode, BOOL combo );
00035 
00036 //******************************************************************************
00037 //******************************************************************************
00038 HWND WIN32API CreateDialogParamA(HINSTANCE hInst, LPCSTR lpszTemplate,
00039                                  HWND hwndOwner, DLGPROC dlgproc,
00040                                  LPARAM lParamInit)
00041 {
00042   HANDLE hrsrc = FindResourceA( hInst, lpszTemplate, RT_DIALOGA );
00043 
00044     if (!hrsrc) {
00045         dprintf(("WARNING: CreateDialogParamA: Dialog %x not found!!", lpszTemplate));
00046         return 0;
00047     }
00048 
00049     return CreateDialogIndirectParamA(hInst, (LPCDLGTEMPLATEA)LoadResource(hInst, hrsrc),
00050                                       hwndOwner, dlgproc, lParamInit);
00051 }
00052 //******************************************************************************
00053 //******************************************************************************
00054 HWND WIN32API CreateDialogParamW(HINSTANCE hInst, LPCWSTR lpszTemplate,
00055                  HWND hwndOwner, DLGPROC dlgproc,
00056                  LPARAM lParamInit)
00057 {
00058   HANDLE hrsrc = FindResourceW( hInst, lpszTemplate, RT_DIALOGW );
00059 
00060     if (!hrsrc) {
00061         dprintf(("WARNING: CreateDialogParamW: Dialog %x not found!!", lpszTemplate));
00062         return 0;
00063     }
00064     return CreateDialogIndirectParamW(hInst, (LPCDLGTEMPLATEW)LoadResource(hInst, hrsrc),
00065                                       hwndOwner, dlgproc, lParamInit);
00066 }
00067 //******************************************************************************
00068 //This function can be used by a custom Odin build to register a hook procedure
00069 //that gets called before or after dialog creation
00070 //******************************************************************************
00071 static HOOKPROC pfnDialogHook = NULL;
00072 //******************************************************************************
00073 BOOL WIN32API SetDialogHook(HOOKPROC pfnDialogProc)
00074 {
00075     dprintf(("SetDialogHook %x", pfnDialogProc));
00076     pfnDialogHook = pfnDialogProc;
00077     return TRUE;
00078 }
00079 //******************************************************************************
00080 //******************************************************************************
00081 BOOL WIN32API ClearDialogHook()
00082 {
00083     pfnDialogHook = NULL;
00084     return TRUE;
00085 }
00086 //******************************************************************************
00087 //******************************************************************************
00088 HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hInst,
00089                          LPCDLGTEMPLATEA dlgtemplate,
00090                          HWND hwndOwner, DLGPROC dlgproc,
00091                          LPARAM lParamInit)
00092 {
00093  Win32Dialog *dialog;
00094 
00095     dprintf(("CreateDialogIndirectParamA: %x %x %x %x %x", hInst, dlgtemplate, hwndOwner, dlgproc, lParamInit));
00096 
00097     if (!dlgtemplate) return 0;
00098 
00099     dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndOwner, dlgproc, lParamInit, FALSE);
00100 
00101     if(dialog == NULL)
00102     {
00103         dprintf(("Win32Dialog creation failed!!"));
00104         return 0;
00105     }
00106     if(GetLastError() != 0)
00107     {
00108         dprintf(("Win32Dialog error found (%0x)!!", GetLastError()));
00109         RELEASE_WNDOBJ(dialog);
00110         delete dialog;
00111         return 0;
00112     }
00113     HWND hwnd = dialog->getWindowHandle();
00114 
00115     if(pfnDialogHook) {
00116         dprintf(("Calling Dialog hook for dialog %x", hwnd));
00117         pfnDialogHook(HCUSTOM_POSTDIALOGCREATION, hwnd, 0);
00118     }
00119 
00120     RELEASE_WNDOBJ(dialog);
00121     return hwnd;
00122 }
00123 //******************************************************************************
00124 //******************************************************************************
00125 HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hInst,
00126                          LPCDLGTEMPLATEW dlgtemplate,
00127                          HWND hwndOwner, DLGPROC dlgproc,
00128                          LPARAM lParamInit)
00129 {
00130  Win32Dialog *dialog;
00131 
00132     dprintf(("CreateDialogIndirectParamW: %x %x %x %x %x", hInst, dlgtemplate, hwndOwner, dlgproc, lParamInit));
00133 
00134     if (!dlgtemplate) return 0;
00135 
00136     dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndOwner, dlgproc, lParamInit, TRUE);
00137 
00138     if(dialog == NULL)
00139     {
00140         dprintf(("Win32Dialog creation failed!!"));
00141         return 0;
00142     }
00143     if(GetLastError() != 0)
00144     {
00145         dprintf(("Win32Dialog error found!!"));
00146         RELEASE_WNDOBJ(dialog);
00147         delete dialog;
00148         return 0;
00149     }
00150     HWND hwnd = dialog->getWindowHandle();
00151 
00152     if(pfnDialogHook) {
00153         dprintf(("Calling Dialog hook for dialog %x", hwnd));
00154         pfnDialogHook(HCUSTOM_POSTDIALOGCREATION, hwnd, 0);
00155     }
00156 
00157     RELEASE_WNDOBJ(dialog);
00158     return hwnd;
00159 }
00160 //******************************************************************************
00161 //******************************************************************************
00162 INT  WIN32API DialogBoxIndirectParamA(HINSTANCE hInst,
00163                       LPCDLGTEMPLATEA dlgtemplate,
00164                       HWND hwndOwner, DLGPROC dlgproc,
00165                       LPARAM lParamInit)
00166 {
00167     INT result;
00168     HWND hwnd = CreateDialogIndirectParamA(hInst, dlgtemplate, hwndOwner, dlgproc,
00169                                            lParamInit);
00170     if (hwnd)
00171     {
00172         Win32Dialog *dialog;
00173 
00174         dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00175         if(!dialog || !dialog->IsDialog()) {
00176             dprintf(("DialogBoxIndirectParamA, dialog %x not found", hwnd));
00177             if(dialog) RELEASE_WNDOBJ(dialog);
00178             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00179             return 0;
00180         }
00181         result = dialog->doDialogBox();
00182         RELEASE_WNDOBJ(dialog);
00183         return result;
00184     }
00185     return -1;
00186 }
00187 //******************************************************************************
00188 //******************************************************************************
00189 INT  WIN32API DialogBoxIndirectParamW(HINSTANCE hInst, LPCDLGTEMPLATEW dlgtemplate,
00190                                       HWND hwndOwner, DLGPROC dlgproc,
00191                                       LPARAM lParamInit)
00192 {
00193     INT result;
00194     HWND hwnd = CreateDialogIndirectParamW(hInst, dlgtemplate, hwndOwner, dlgproc,
00195                                            lParamInit);
00196     if (hwnd)
00197     {
00198         Win32Dialog *dialog;
00199 
00200         dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00201         if(!dialog || !dialog->IsDialog()) {
00202             dprintf(("DialogBoxIndirectParamW, dialog %x not found", hwnd));
00203             if(dialog) RELEASE_WNDOBJ(dialog);
00204             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00205             return 0;
00206         }
00207         result = dialog->doDialogBox();
00208         RELEASE_WNDOBJ(dialog);
00209         return result;
00210     }
00211     return -1;
00212 }
00213 //******************************************************************************
00214 //******************************************************************************
00215 int WIN32API DialogBoxParamA(HINSTANCE hInst, LPCSTR lpszTemplate, HWND hwndOwner,
00216                      DLGPROC dlgproc, LPARAM  lParamInit)
00217 {
00218     INT result;
00219     HWND hwnd = CreateDialogParamA( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
00220 
00221     if (hwnd)
00222     {
00223         Win32Dialog *dialog;
00224 
00225         dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00226         if(!dialog || !dialog->IsDialog()) {
00227             dprintf(("DialogBoxParamA, dialog %x not found", hwnd));
00228             if(dialog) RELEASE_WNDOBJ(dialog);
00229             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00230             return 0;
00231         }
00232         result = dialog->doDialogBox();
00233         RELEASE_WNDOBJ(dialog);
00234         return result;
00235     }
00236     return -1;
00237 }
00238 //******************************************************************************
00239 //******************************************************************************
00240 int WIN32API DialogBoxParamW(HINSTANCE hInst, LPCWSTR lpszTemplate, HWND hwndOwner,
00241                              DLGPROC dlgproc, LPARAM lParamInit)
00242 {
00243     INT result;
00244     HWND hwnd = CreateDialogParamW( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
00245 
00246     if (hwnd)
00247     {
00248         Win32Dialog *dialog;
00249 
00250         dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00251         if(!dialog || !dialog->IsDialog()) {
00252             dprintf(("DialogBoxParamW, dialog %x not found", hwnd));
00253             if(dialog) RELEASE_WNDOBJ(dialog);
00254             SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00255             return 0;
00256         }
00257         result = dialog->doDialogBox();
00258         RELEASE_WNDOBJ(dialog);
00259         return result;
00260     }
00261     return -1;
00262 }
00263 /***********************************************************************
00264  *           MapDialogRect32   (USER32.382)
00265  */
00266 BOOL WIN32API MapDialogRect(HWND hwndDlg, LPRECT rect)
00267 {
00268   Win32Dialog *dialog;
00269   BOOL rc;
00270 #ifdef DEBUG
00271   RECT dlgRect = *rect;
00272 #endif
00273 
00274     dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwndDlg);
00275     if(!dialog || !dialog->IsDialog()) {
00276         dprintf(("MapDialogRect, window %x not found", hwndDlg));
00277         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00278         if(dialog) RELEASE_WNDOBJ(dialog);
00279         return 0;
00280     }
00281     rc = dialog->MapDialogRect(rect);
00282     dprintf(("USER32: MapDialogRect %x (%d,%d)(%d,%d) -> (%d,%d)(%d,%d)", hwndDlg, dlgRect.left, dlgRect.top, dlgRect.right, dlgRect.bottom, rect->left, rect->top, rect->right, rect->bottom));
00283     RELEASE_WNDOBJ(dialog);
00284     return rc;
00285 }
00286 //******************************************************************************
00287 //******************************************************************************
00288 BOOL WIN32API IsDlgButtonChecked( HWND hwnd, UINT id)
00289 {
00290     dprintf(("USER32:  IsDlgButtonChecked\n"));
00291 
00292     return (BOOL)SendDlgItemMessageA(hwnd, id,BM_GETCHECK,0,0);
00293 }
00294 /***********************************************************************
00295  *           DIALOG_GetNextTabItem
00296  *
00297  * Helper for GetNextDlgTabItem
00298  */
00299 static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
00300 {
00301     LONG dsStyle;
00302     LONG exStyle;
00303     UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
00304     HWND retWnd = 0;
00305     HWND hChildFirst = 0;
00306 
00307     if(!hwndCtrl) 
00308     {
00309         hChildFirst = GetWindow(hwndDlg,GW_CHILD);
00310         if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
00311     }
00312 #if 1
00313     else if (IsChild( hwndMain, hwndCtrl ))
00314     {
00315         hChildFirst = GetWindow(hwndCtrl,wndSearch);
00316         if(!hChildFirst)
00317         {
00318             if(GetParent(hwndCtrl) != hwndMain)
00319                 hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
00320             else
00321             {
00322                 if(fPrevious)
00323                     hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
00324                 else
00325                     hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
00326             }
00327         }
00328     }
00329 #else
00330     else
00331     {
00332         HWND hParent = GetParent(hwndCtrl);
00333         BOOL bValid = FALSE;
00334         while( hParent)
00335         {
00336             if(hParent == hwndMain)
00337             {
00338                 bValid = TRUE;
00339                 break;
00340             }
00341             hParent = GetParent(hParent);
00342         }
00343         if(bValid)
00344         {
00345             hChildFirst = GetWindow(hwndCtrl,wndSearch);
00346             if(!hChildFirst)
00347             {
00348                 if(GetParent(hwndCtrl) != hwndMain)
00349                     hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
00350                 else
00351                 {
00352                     if(fPrevious)
00353                         hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
00354                     else
00355                         hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
00356                 }
00357             }
00358         }       
00359     }
00360 #endif
00361     while(hChildFirst)
00362     {
00363         BOOL bCtrl = FALSE;
00364         while(hChildFirst)
00365         {
00366             dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
00367             exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
00368             if( (dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
00369             {
00370                 bCtrl=TRUE;
00371                 break;
00372             }
00373             else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
00374                 break;
00375             hChildFirst = GetWindow(hChildFirst,wndSearch);
00376         }
00377         if(hChildFirst)
00378         {
00379             if(bCtrl)
00380                 retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
00381             else
00382                 retWnd = hChildFirst;
00383         }
00384         if(retWnd) break;
00385         hChildFirst = GetWindow(hChildFirst,wndSearch);
00386     }
00387     if(!retWnd && hwndCtrl)
00388     {
00389         HWND hParent = GetParent(hwndCtrl);
00390         while(hParent)
00391         {
00392             if(hParent == hwndMain) break;
00393             retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
00394             if(retWnd) break;
00395             hParent = GetParent(hParent);
00396         }
00397         if(!retWnd)
00398             retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
00399     }
00400     return retWnd;
00401 }
00402 //******************************************************************************
00403 //******************************************************************************
00404 HWND WIN32API GetNextDlgTabItem(HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
00405 {
00406     if(!IsWindow(hwndDlg)) {
00407         dprintf(("GetNextDlgTabItem, window %x not found", hwndDlg));
00408         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00409         return 0;
00410     }
00411     dprintf(("USER32: GetNextDlgTabItem %x %x %d", hwndDlg,hwndCtrl,fPrevious));
00412     return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious); 
00413 }
00414 //******************************************************************************
00415 //Can be used for any parent-child pair
00416 //NOTE: Returns ERROR_CONTROL_ID_NOT_FOUND when child with id not found
00417 //      Does not change last error if successful
00418 //******************************************************************************
00419 HWND WIN32API GetDlgItem(HWND hwnd, int id)
00420 {
00421   Win32BaseWindow *window;
00422   HWND             hwndDlgItem;
00423 
00424     window = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00425     if(!window) {
00426         dprintf(("GetDlgItem, window %x not found", hwnd));
00427         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00428         return 0;
00429     }
00430     hwndDlgItem = window->FindWindowById(id);
00431     RELEASE_WNDOBJ(window);
00432     if(hwndDlgItem) {
00433         dprintf(("USER32: GetDlgItem %x %d returned %x\n", hwnd, id, hwndDlgItem));
00434         return hwndDlgItem;
00435     }
00436     dprintf(("USER32: GetDlgItem %x %d NOT FOUND!\n", hwnd, id));
00437     SetLastError(ERROR_CONTROL_ID_NOT_FOUND);  //verified in NT4, SP6
00438     return 0;
00439 }
00440 //******************************************************************************
00441 //******************************************************************************
00442 int WIN32API GetDlgCtrlID(HWND hwnd)
00443 {
00444   Win32BaseWindow *dlgcontrol;
00445 
00446     dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
00447     if(!dlgcontrol) {
00448         dprintf(("GetDlgCtrlID, control %x not found", hwnd));
00449         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00450         return 0;
00451     }
00452     dprintf(("USER32: GetDlgCtrlID %x", hwnd));
00453     return dlgcontrol->getWindowId();
00454 }
00455 //******************************************************************************
00456 //******************************************************************************
00457 BOOL WIN32API EndDialog(HWND hwnd, int retval)
00458 {
00459   Win32Dialog *dialog;
00460 
00461     dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
00462     if(!dialog || !dialog->IsDialog()) {
00463         dprintf(("GetDlgItem, window %x not found", hwnd));
00464         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00465         return 0;
00466     }
00467     dprintf(("USER32: EndDialog %x %d", hwnd, retval));
00468     return dialog->endDialog(retval);
00469 }
00470 //******************************************************************************
00471 //******************************************************************************
00472 BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
00473 {
00474     dprintf(("USER32: CheckDlgButton %x %d %d", hwnd, id, check));
00475 
00476     return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
00477 }
00478 //******************************************************************************
00479 //******************************************************************************
00480 BOOL WIN32API CheckRadioButton( HWND hDlg, UINT nIDFirstButton, UINT nIDLastButton, UINT  nIDCheckButton)
00481 {
00482     dprintf(("USER32: CheckRadioButton %x %d %d %d", hDlg, nIDFirstButton, nIDLastButton, nIDCheckButton));
00483 
00484     //CB: check radio buttons in interval
00485     if (nIDFirstButton > nIDLastButton)
00486     {
00487       SetLastError(ERROR_INVALID_PARAMETER);
00488       return (FALSE);
00489     }
00490 
00491     for (UINT x = nIDFirstButton;x <= nIDLastButton;x++)
00492     {
00493      SendDlgItemMessageA(hDlg,x,BM_SETCHECK,(x == nIDCheckButton) ? BST_CHECKED : BST_UNCHECKED,0);
00494     }
00495 
00496     return (TRUE);
00497 }
00498 //******************************************************************************
00499 //******************************************************************************
00500 UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
00501 {
00502     return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
00503 }
00504 //*****************************************************************************
00505 //*****************************************************************************
00506 UINT WIN32API GetDlgItemTextW(HWND   hwnd, int id, LPWSTR lpszName, UINT cch)
00507 {
00508     return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
00509 }
00510 //******************************************************************************
00511 //******************************************************************************
00512 BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL  fSigned)
00513 {
00514   char str[20];
00515 
00516     dprintf(("USER32:  SetDlgItemInt\n"));
00517 
00518     if (fSigned)
00519             sprintf( str, "%d", (INT)uValue );
00520     else    sprintf( str, "%u", uValue );
00521 
00522     return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
00523 }
00524 //******************************************************************************
00525 //******************************************************************************
00526 BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
00527 {
00528     return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
00529 }
00530 //******************************************************************************
00531 //******************************************************************************
00532 BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
00533 {
00534     return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
00535 }
00536 //******************************************************************************
00537 //******************************************************************************
00538 UINT WIN32API GetDlgItemInt(HWND hwnd, INT id, BOOL *translated, BOOL fSigned)
00539 {
00540   char str[30];
00541   char * endptr;
00542   long result = 0;
00543 
00544     dprintf(("USER32: GetDlgItemInt %x %x %x %d", hwnd, id, translated, fSigned));
00545     if (translated) *translated = FALSE;
00546 
00547     if (!SendDlgItemMessageA(hwnd, id, WM_GETTEXT, sizeof(str), (LPARAM)str))
00548         return 0;
00549 
00550     if (fSigned)
00551     {
00552         result = strtol( str, &endptr, 10 );
00553         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
00554             return 0;
00555         if (((result == LONG_MIN) || (result == LONG_MAX)) && (errno==ERANGE))
00556             return 0;
00557     }
00558     else
00559     {
00560         result = strtoul( str, &endptr, 10 );
00561         if (!endptr || (endptr == str))  /* Conversion was unsuccessful */
00562             return 0;
00563         if ((result == ULONG_MAX) && (errno == ERANGE)) return 0;
00564     }
00565     if (translated) *translated = TRUE;
00566     return (UINT)result;
00567 }
00568 //******************************************************************************
00569 //******************************************************************************
00570 HWND WIN32API GetNextDlgGroupItem( HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
00571 {
00572     HWND hwnd, retvalue;
00573 
00574     if(!IsWindow(hwndDlg) || (hwndCtrl && !IsWindow(hwndCtrl))) {
00575         dprintf(("GetNextDlgGroupItem, window %x not found", hwnd));
00576         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
00577         return 0;
00578     }
00579     dprintf(("USER32: GetNextDlgGroupItem %x %x %d", hwndDlg, hwndCtrl, fPrevious));
00580 
00581     #define WIN_GetFullHandle(a)        a
00582 
00583     hwndDlg = WIN_GetFullHandle( hwndDlg );
00584     hwndCtrl = WIN_GetFullHandle( hwndCtrl );
00585 
00586     if(hwndCtrl)
00587     {
00588         /* if the hwndCtrl is the child of the control in the hwndDlg,
00589          * then the hwndDlg has to be the parent of the hwndCtrl */
00590         if(GetParent(hwndCtrl) != hwndDlg && GetParent(GetParent(hwndCtrl)) == hwndDlg)
00591             hwndDlg = GetParent(hwndCtrl);
00592     }
00593 
00594     if (hwndCtrl)
00595     {
00596         /* Make sure hwndCtrl is a top-level child */
00597         HWND parent = GetParent( hwndCtrl );
00598         while (parent && parent != hwndDlg) parent = GetParent(parent);
00599         if (parent != hwndDlg) return 0;
00600     }
00601     else
00602     {
00603         /* No ctrl specified -> start from the beginning */
00604         if (!(hwndCtrl = GetWindow( hwndDlg, GW_CHILD ))) return 0;
00605         if (fPrevious) hwndCtrl = GetWindow( hwndCtrl, GW_HWNDLAST );
00606     }
00607 
00608     retvalue = hwndCtrl;
00609     hwnd = GetWindow( hwndCtrl, GW_HWNDNEXT );
00610     while (1)
00611     {
00612         if (!hwnd || (GetWindowLongW( hwnd, GWL_STYLE ) & WS_GROUP))
00613         {
00614             /* Wrap-around to the beginning of the group */
00615             HWND tmp;
00616 
00617             hwnd = GetWindow( hwndDlg, GW_CHILD );
00618 #ifdef __WIN32OS2__
00619             if(!hwnd) break;
00620 #endif
00621             for (tmp = hwnd; tmp; tmp = GetWindow( tmp, GW_HWNDNEXT ) )
00622             {
00623                 if (GetWindowLongW( tmp, GWL_STYLE ) & WS_GROUP) hwnd = tmp;
00624                 if (tmp == hwndCtrl) break;
00625             }
00626         }
00627         if (hwnd == hwndCtrl) break;
00628         if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_VISIBLE|WS_DISABLED)) == WS_VISIBLE)
00629         {
00630             retvalue = hwnd;
00631             if (!fPrevious) break;
00632         }
00633         hwnd = GetWindow( hwnd, GW_HWNDNEXT );
00634     }
00635     return retvalue;
00636 }
00637 /***********************************************************************
00638  *           GetDialogBaseUnits   (USER.243) (USER32.233)
00639  */
00640 DWORD WIN32API GetDialogBaseUnits(void)
00641 {
00642     return Win32Dialog::GetDialogBaseUnits();
00643 }
00644 //******************************************************************************
00645 //******************************************************************************
00646 INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
00647 {
00648     return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
00649 }
00650 //******************************************************************************
00651 //******************************************************************************
00652 int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
00653 {
00654     return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
00655 }
00656 //******************************************************************************
00657 //******************************************************************************
00658 INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
00659 {
00660     return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
00661 }
00662 //******************************************************************************
00663 //******************************************************************************
00664 INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
00665 {
00666     return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
00667 }
00668 //******************************************************************************
00669 //******************************************************************************
00670 BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
00671 {
00672     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
00673 }
00674 //******************************************************************************
00675 //******************************************************************************
00676 BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
00677 {
00678     return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
00679 }
00680 //******************************************************************************
00681 //******************************************************************************
00682 BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
00683 {
00684     return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
00685 }
00686 //******************************************************************************
00687 //******************************************************************************
00688 BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
00689 {
00690     return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
00691 }
00692 /**********************************************************************
00693  *           DIALOG_DlgDirSelect
00694  *
00695  * Helper function for DlgDirSelect*
00696  */
00697 static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
00698                                  INT id, BOOL win32, BOOL unicode,
00699                                  BOOL combo )
00700 {
00701     char *buffer, *ptr;
00702     INT item, size;
00703     BOOL ret;
00704     HWND listbox = GetDlgItem( hwnd, id );
00705 
00706     if (!listbox) return FALSE;
00707 
00708     item = SendMessageA(listbox, combo ? CB_GETCURSEL
00709                                              : LB_GETCURSEL, 0, 0 );
00710     if (item == LB_ERR) return FALSE;
00711     size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
00712                                              : LB_GETTEXTLEN, 0, 0 );
00713     if (size == LB_ERR) return FALSE;
00714 
00715     if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
00716 
00717     SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
00718                   item, (LPARAM)buffer );
00719 
00720     if ((ret = (buffer[0] == '[')) != 0)  /* drive or directory */
00721     {
00722         if (buffer[1] == '-')  /* drive */
00723         {
00724             buffer[3] = ':';
00725             buffer[4] = 0;
00726             ptr = buffer + 2;
00727         }
00728         else
00729         {
00730             buffer[strlen(buffer)-1] = '\\';
00731             ptr = buffer + 1;
00732         }
00733     }
00734     else ptr = buffer;
00735 
00736     if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
00737     else lstrcpynA( str, ptr, len );
00738 
00739     free( buffer );
00740     return ret;
00741 }
00742 
00743 
00744 /**********************************************************************
00745  *      DIALOG_DlgDirList
00746  *
00747  * Helper function for DlgDirList*
00748  */
00749 static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
00750                               INT idStatic, UINT attrib, BOOL combo )
00751 {
00752     int drive;
00753     HWND hwnd;
00754     LPSTR orig_spec = spec;
00755 
00756 #define SENDMSG(msg,wparam,lparam) \
00757     ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
00758                              : SendMessageA( hwnd, msg, wparam, lparam ))
00759 
00760     if (spec && spec[0] && (spec[1] == ':'))
00761     {
00762         drive = _toupper( spec[0] ) - 'A';
00763         spec += 2;
00764         if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
00765     }
00766     else drive = DRIVE_GetCurrentDrive();
00767 
00768     /* If the path exists and is a directory, chdir to it */
00769     if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
00770     else
00771     {
00772         char *p, *p2;
00773         p = spec;
00774         if ((p2 = strrchr( p, '\\' )) != 0) p = p2;
00775         if ((p2 = strrchr( p, '/' )) != 0) p = p2;
00776         if (p != spec)
00777         {
00778             char sep = *p;
00779             *p = 0;
00780             if (!DRIVE_Chdir( drive, spec ))
00781             {
00782                 *p = sep;  /* Restore the original spec */
00783                 return FALSE;
00784             }
00785             spec = p + 1;
00786         }
00787     }
00788 
00789     if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
00790     {
00791         SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
00792         if (attrib & DDL_DIRECTORY)
00793         {
00794             if (!(attrib & DDL_EXCLUSIVE))
00795             {
00796                 if (SENDMSG( combo ? CB_DIR : LB_DIR,
00797                              attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
00798                              (LPARAM)spec ) == LB_ERR)
00799                     return FALSE;
00800             }
00801             if (SENDMSG( combo ? CB_DIR : LB_DIR,
00802                        (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
00803                          (LPARAM)"*.*" ) == LB_ERR)
00804                 return FALSE;
00805         }
00806         else
00807         {
00808             if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
00809                          (LPARAM)spec ) == LB_ERR)
00810                 return FALSE;
00811         }
00812     }
00813 
00814     if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
00815     {
00816         char temp[512], curpath[512];
00817         int drive = DRIVE_GetCurrentDrive();
00818         strcpy( temp, "A:\\" );
00819         temp[0] += drive;
00820         lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive, sizeof(curpath)), sizeof(temp)-3 );
00821         CharLowerA( temp );
00822         /* Can't use PostMessage() here, because the string is on the stack */
00823         SetDlgItemTextA( hDlg, idStatic, temp );
00824     }
00825 
00826     if (orig_spec && (spec != orig_spec))
00827     {
00828         /* Update the original file spec */
00829         char *p = spec;
00830         while ((*orig_spec++ = *p++) != 0);
00831     }
00832 
00833     return TRUE;
00834 #undef SENDMSG
00835 }
00836 
00837 
00838 /**********************************************************************
00839  *      DIALOG_DlgDirListW
00840  *
00841  * Helper function for DlgDirList*32W
00842  */
00843 static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
00844                                INT idStatic, UINT attrib, BOOL combo )
00845 {
00846     if (spec)
00847     {
00848         LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
00849         INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
00850                                        attrib, combo );
00851         lstrcpyAtoW( spec, specA );
00852         HeapFree( GetProcessHeap(), 0, specA );
00853         return ret;
00854     }
00855     return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
00856 }
00857 //******************************************************************************
00858 //******************************************************************************
00859 

Generated on Wed Jan 23 23:17:50 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001