Ignore:
Timestamp:
Sep 5, 1999, 2:03:34 PM (26 years ago)
Author:
sandervl
Message:

Dialog update

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/new/windlg.cpp

    r327 r833  
    1 /* $Id: windlg.cpp,v 1.2 1999-07-18 13:57:48 cbratschi Exp $ */
     1/* $Id: windlg.cpp,v 1.3 1999-09-05 12:03:34 sandervl Exp $ */
    22/*
    33 * Win32 dialog apis for OS/2
     
    55 * Copyright 1999 Sander van Leeuwen
    66 *
     7 * Parts based on Wine code (990815; window\dialog.c)
     8 *
     9 * Copyright 1993, 1994, 1996 Alexandre Julliard
    710 *
    811 * Project Odin Software License can be found in LICENSE.TXT
    912 *
    1013 */
     14#include <ctype.h>
    1115#include <wchar.h>
    1216#include <os2win.h>
     
    1418#include <string.h>
    1519#include <stdlib.h>
    16 
    17 //******************************************************************************
    18 //******************************************************************************
    19 BOOL WIN32API IsDlgButtonChecked( HWND arg1, UINT  arg2)
    20 {
    21 #ifdef DEBUG
    22     WriteLog("USER32:  IsDlgButtonChecked\n");
    23 #endif
     20#include "win32wbase.h"
     21#include "win32dlg.h"
     22#include <heapstring.h>
     23#include <win\drive.h>
     24
     25static INT  DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
     26static INT  DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib, BOOL combo );
     27static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len, INT id, BOOL win32, BOOL unicode, BOOL combo );
     28
     29//******************************************************************************
     30//******************************************************************************
     31HWND WIN32API CreateDialogParamA(HINSTANCE hInst, LPCSTR lpszTemplate,
     32                                 HWND hwndOwner, DLGPROC dlgproc,
     33                                 LPARAM lParamInit)
     34{
     35  HANDLE hrsrc = FindResourceA( hInst, lpszTemplate, RT_DIALOGA );
     36
     37    if (!hrsrc)
     38        return 0;
     39
     40    return CreateDialogIndirectParamA(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
     41                                      hwndOwner, dlgproc, lParamInit);
     42}
     43//******************************************************************************
     44//******************************************************************************
     45HWND WIN32API CreateDialogParamW(HINSTANCE hInst, LPCWSTR lpszTemplate,
     46                 HWND hwndOwner, DLGPROC dlgproc,
     47                 LPARAM lParamInit)
     48{
     49  HANDLE hrsrc = FindResourceW( hInst, lpszTemplate, RT_DIALOGW );
     50
     51    if (!hrsrc)
     52        return 0;
     53
     54    return CreateDialogIndirectParamW(hInst, (DLGTEMPLATE*)LoadResource(hInst, hrsrc),
     55                                      hwndOwner, dlgproc, lParamInit);
     56}
     57//******************************************************************************
     58//******************************************************************************
     59HWND WIN32API CreateDialogIndirectParamA(HINSTANCE hInst,
     60                         DLGTEMPLATE *dlgtemplate,
     61                         HWND hwndParent, DLGPROC dlgproc,
     62                         LPARAM lParamInit)
     63{
     64 Win32Dialog *dialog;
     65
     66    dprintf(("CreateDialogIndirectParamA: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
     67
     68    if (!dlgtemplate) return 0;
     69
     70    dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, FALSE);
     71
     72    if(dialog == NULL)
     73    {
     74        dprintf(("Win32Dialog creation failed!!"));
     75        return 0;
     76    }
     77    if(GetLastError() != 0)
     78    {
     79        dprintf(("Win32Dialog error found!!"));
     80        delete dialog;
     81        return 0;
     82    }
     83    return dialog->getWindowHandle();
     84}
     85//******************************************************************************
     86//******************************************************************************
     87HWND WIN32API CreateDialogIndirectParamW(HINSTANCE hInst,
     88                         DLGTEMPLATE *dlgtemplate,
     89                         HWND hwndParent, DLGPROC dlgproc,
     90                         LPARAM lParamInit)
     91{
     92 Win32Dialog *dialog;
     93
     94    dprintf(("CreateDialogIndirectParamW: %x %x %x %x %x", hInst, dlgtemplate, hwndParent, dlgproc, lParamInit));
     95
     96    if (!dlgtemplate) return 0;
     97
     98    dialog = new Win32Dialog(hInst, (LPCSTR)dlgtemplate, hwndParent, dlgproc, lParamInit, TRUE);
     99
     100    if(dialog == NULL)
     101    {
     102        dprintf(("Win32Dialog creation failed!!"));
     103        return 0;
     104    }
     105    if(GetLastError() != 0)
     106    {
     107        dprintf(("Win32Dialog error found!!"));
     108        delete dialog;
     109        return 0;
     110    }
     111    return dialog->getWindowHandle();
     112}
     113//******************************************************************************
     114//******************************************************************************
     115INT  WIN32API DialogBoxIndirectParamA(HINSTANCE hInst,
     116                      DLGTEMPLATE *dlgtemplate,
     117                      HWND hwndParent, DLGPROC dlgproc,
     118                      LPARAM lParamInit)
     119{
     120    HWND hwnd = CreateDialogIndirectParamA(hInst, dlgtemplate, hwndParent, dlgproc,
     121                                           lParamInit);
     122    //TODO:
     123    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
     124    return -1;
     125}
     126//******************************************************************************
     127//******************************************************************************
     128INT  WIN32API DialogBoxIndirectParamW(HINSTANCE hInst, DLGTEMPLATE *dlgtemplate,
     129                                      HWND hwndParent, DLGPROC dlgproc,
     130                                      LPARAM lParamInit)
     131{
     132    HWND hwnd = CreateDialogIndirectParamW(hInst, dlgtemplate, hwndParent, dlgproc,
     133                                           lParamInit);
     134    //TODO:
     135    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
     136    return -1;
     137}
     138//******************************************************************************
     139//******************************************************************************
     140int WIN32API DialogBoxParamA(HINSTANCE hInst, LPCSTR lpszTemplate, HWND hwndOwner,
     141                     DLGPROC dlgproc, LPARAM  lParamInit)
     142{
     143    HWND hwnd = CreateDialogParamA( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
     144    //TODO:
     145    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
     146    return -1;
     147}
     148//******************************************************************************
     149//******************************************************************************
     150int WIN32API DialogBoxParamW(HINSTANCE hInst, LPCWSTR lpszTemplate, HWND hwndOwner,
     151                             DLGPROC dlgproc, LPARAM lParamInit)
     152{
     153    HWND hwnd = CreateDialogParamW( hInst, lpszTemplate, hwndOwner, dlgproc, lParamInit);
     154    //TODO:
     155    if (hwnd) return 1; //return DIALOG_DoDialogBox( hwnd, owner );
     156    return -1;
     157}
     158//******************************************************************************
     159//******************************************************************************
     160BOOL WIN32API IsDlgButtonChecked( HWND hwnd, UINT id)
     161{
     162    dprintf(("USER32:  IsDlgButtonChecked\n"));
    24163    //CB: get button state
    25     return (BOOL)SendDlgItemMessageA(arg1,arg2,BM_GETCHECK,0,0);
    26 }
    27 //******************************************************************************
    28 //******************************************************************************
    29 HWND WIN32API GetNextDlgTabItem( HWND arg1, HWND arg2, BOOL  arg3)
    30 {
     164    return (BOOL)SendDlgItemMessageA(hwnd, id,BM_GETCHECK,0,0);
     165}
     166//******************************************************************************
     167//******************************************************************************
     168HWND WIN32API GetNextDlgTabItem(HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious)
     169{
     170  Win32Dialog *dialog;
     171
     172    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwndDlg);
     173    if(!dialog || !dialog->IsDialog()) {
     174        dprintf(("GetNextDlgTabItem, window %x not found", hwndDlg));
     175        return 0;
     176    }
    31177    dprintf(("USER32:  GetNextDlgTabItem\n"));
    32     //get next WS_TABSTOP
    33     return O32_GetNextDlgTabItem(arg1, arg2, arg3);
    34 }
    35 //******************************************************************************
    36 //******************************************************************************
    37 HWND WIN32API GetDlgItem(HWND arg1, int  arg2)
    38 {
    39  HWND rc;
    40     //return OSLibWinWindowFromID(arg1,arg2);
    41     rc = O32_GetDlgItem(arg1, arg2);
    42     dprintf(("USER32:  GetDlgItem %d returned %d\n", arg2, rc));
    43     return(rc);
    44 }
    45 //******************************************************************************
    46 //******************************************************************************
    47 int WIN32API GetDlgCtrlID( HWND arg1)
    48 {
     178    return dialog->getNextDlgTabItem(hwndCtrl, fPrevious);
     179}
     180//******************************************************************************
     181//******************************************************************************
     182HWND WIN32API GetDlgItem(HWND hwnd, int id)
     183{
     184  Win32Dialog *dialog;
     185  Win32BaseWindow *dlgcontrol;
     186
     187    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
     188    if(!dialog || !dialog->IsDialog()) {
     189        dprintf(("GetDlgItem, window %x not found", hwnd));
     190        return 0;
     191    }
     192    dprintf(("USER32:  GetDlgItem\n"));
     193    dlgcontrol = dialog->getDlgItem(id);
     194    if(dlgcontrol) {
     195        return dlgcontrol->getWindowHandle();
     196    }
     197    return 0;
     198}
     199//******************************************************************************
     200//******************************************************************************
     201int WIN32API GetDlgCtrlID(HWND hwnd)
     202{
     203  Win32BaseWindow *dlgcontrol;
     204
     205    dlgcontrol = Win32BaseWindow::GetWindowFromHandle(hwnd);
     206    if(!dlgcontrol) {
     207        dprintf(("GetDlgCtrlID, control %x not found", hwnd));
     208        return 0;
     209    }
    49210    dprintf(("USER32:  GetDlgCtrlID\n"));
    50     //return OSLibWinQueryWindowUShort(arg1,QWS_ID);
    51     //use internal ID -> DWORD
    52     return O32_GetDlgCtrlID(arg1);
    53 }
    54 //******************************************************************************
    55 //******************************************************************************
    56 BOOL WIN32API EndDialog( HWND arg1, int  arg2)
    57 {
    58  BOOL rc;
    59 
    60     dprintf(("USER32:  EndDialog\n"));
    61     //return OSLibDismissDialog(arg1,arg2);
    62     rc = O32_EndDialog(arg1, arg2);
    63     return(rc);
    64 }
    65 //******************************************************************************
    66 //******************************************************************************
    67 BOOL WIN32API CheckDlgButton( HWND arg1, int arg2, UINT  arg3)
    68 {
    69 #ifdef DEBUG
    70     WriteLog("USER32:  CheckDlgButton\n");
    71 #endif
     211    return dlgcontrol->getWindowId();
     212}
     213//******************************************************************************
     214//******************************************************************************
     215BOOL WIN32API EndDialog(HWND hwnd, int retval)
     216{
     217  Win32Dialog *dialog;
     218
     219    dialog = (Win32Dialog *)Win32BaseWindow::GetWindowFromHandle(hwnd);
     220    if(!dialog || !dialog->IsDialog()) {
     221        dprintf(("GetDlgItem, window %x not found", hwnd));
     222        return 0;
     223    }
     224    dprintf(("USER32: EndDialog\n"));
     225    return dialog->endDialog(retval);
     226}
     227//******************************************************************************
     228//******************************************************************************
     229BOOL WIN32API CheckDlgButton( HWND hwnd, int id, UINT check)
     230{
     231    dprintf(("USER32:  CheckDlgButton\n"));
    72232    //CB: set button state
    73     return (BOOL)SendDlgItemMessageA(arg1,arg2,BM_SETCHECK,arg3,0);
    74 }
    75 //******************************************************************************
    76 //******************************************************************************
    77 UINT WIN32API GetDlgItemTextA(HWND arg1, int arg2, LPSTR arg3, UINT arg4)
    78 {
    79  UINT rc;
    80 
    81     //WinQueryDlgItemText(arg1,arg2,arg4,arg3);
    82     rc = O32_GetDlgItemText(arg1, arg2, arg3, arg4);
    83 #ifdef DEBUG
    84     if(rc)
    85         WriteLog("USER32:  GetDlgItemTextA returned %s\n", arg3);
    86     else    WriteLog("USER32:  GetDlgItemTextA returned 0 (%d)\n", GetLastError());
    87 #endif
    88     return(rc);
    89 }
    90 //******************************************************************************
    91 //******************************************************************************
    92 BOOL WIN32API SetDlgItemInt( HWND hwndDlg, int idControl, UINT uValue, BOOL  fSigned)
    93 {
    94     char buf[30];
    95 
    96 #ifdef DEBUG
    97     WriteLog("USER32:  SetDlgItemInt\n");
    98 #endif
    99     if (fSigned) sprintf(buf,"%u",uValue);
    100     else sprintf(buf,"%d",uValue);
    101 
    102     return SetDlgItemTextA(hwndDlg,idControl,buf);
    103 }
    104 //******************************************************************************
    105 //******************************************************************************
    106 BOOL WIN32API SetDlgItemTextA( HWND arg1, int arg2, LPCSTR  arg3)
    107 {
    108 #ifdef DEBUG
    109     WriteLog("USER32:  SetDlgItemText to %s\n", arg3);
    110 #endif
    111     //WinSetDlgItemText(arg1,arg2,arg3);
    112     return O32_SetDlgItemText(arg1, arg2, arg3);
    113 }
    114 //******************************************************************************
    115 //******************************************************************************
    116 int WIN32API DlgDirListA( HWND arg1, LPSTR arg2, int arg3, int arg4, UINT  arg5)
    117 {
    118 #ifdef DEBUG
    119     WriteLog("USER32:  DlgDirListA\n");
    120 #endif
    121     return O32_DlgDirList(arg1, arg2, arg3, arg4, arg5);
    122 }
    123 //******************************************************************************
    124 //******************************************************************************
    125 int WIN32API DlgDirListComboBoxA( HWND arg1, LPSTR arg2, int arg3, int arg4, UINT  arg5)
    126 {
    127 #ifdef DEBUG
    128     WriteLog("USER32:  DlgDirListComboBoxA\n");
    129 #endif
    130     return O32_DlgDirListComboBox(arg1, arg2, arg3, arg4, arg5);
    131 }
    132 //******************************************************************************
    133 //******************************************************************************
    134 int WIN32API DlgDirListComboBoxW( HWND arg1, LPWSTR arg2, int arg3, int arg4, UINT  arg5)
    135 {
    136 #ifdef DEBUG
    137     WriteLog("USER32:  DlgDirListComboBoxW NOT WORKING\n");
    138 #endif
    139     // NOTE: This will not work as is (needs UNICODE support)
    140     return 0;
    141 //    return O32_DlgDirListComboBox(arg1, arg2, arg3, arg4, arg5);
    142 }
    143 //******************************************************************************
    144 //******************************************************************************
    145 int WIN32API DlgDirListW( HWND arg1, LPWSTR arg2, int arg3, int arg4, UINT  arg5)
    146 {
    147 #ifdef DEBUG
    148     WriteLog("USER32:  DlgDirListW NOT WORKING\n");
    149 #endif
    150     // NOTE: This will not work as is (needs UNICODE support)
    151     return 0;
    152 //    return O32_DlgDirList(arg1, arg2, arg3, arg4, arg5);
    153 }
    154 //******************************************************************************
    155 //******************************************************************************
    156 BOOL WIN32API DlgDirSelectComboBoxExA( HWND arg1, LPSTR arg2, int arg3, int  arg4)
    157 {
    158 #ifdef DEBUG
    159     WriteLog("USER32:  DlgDirSelectComboBoxExA\n");
    160 #endif
    161     return O32_DlgDirSelectComboBoxEx(arg1, arg2, arg3, arg4);
    162 }
    163 //******************************************************************************
    164 //******************************************************************************
    165 BOOL WIN32API DlgDirSelectComboBoxExW( HWND arg1, LPWSTR arg2, int arg3, int  arg4)
    166 {
    167 #ifdef DEBUG
    168     WriteLog("USER32:  DlgDirSelectComboBoxExW NOT WORKING\n");
    169 #endif
    170     // NOTE: This will not work as is (needs UNICODE support)
    171     return 0;
    172 //    return O32_DlgDirSelectComboBoxEx(arg1, arg2, arg3, arg4);
    173 }
    174 //******************************************************************************
    175 //******************************************************************************
    176 BOOL WIN32API DlgDirSelectExA( HWND arg1, LPSTR arg2, int arg3, int  arg4)
    177 {
    178 #ifdef DEBUG
    179     WriteLog("USER32:  DlgDirSelectExA\n");
    180 #endif
    181     return O32_DlgDirSelectEx(arg1, arg2, arg3, arg4);
    182 }
    183 //******************************************************************************
    184 //******************************************************************************
    185 BOOL WIN32API DlgDirSelectExW( HWND arg1, LPWSTR arg2, int arg3, int  arg4)
    186 {
    187 #ifdef DEBUG
    188     WriteLog("USER32:  DlgDirSelectExW NOT WORKING\n");
    189 #endif
    190     // NOTE: This will not work as is (needs UNICODE support)
    191     return 0;
    192 //    return O32_DlgDirSelectEx(arg1, arg2, arg3, arg4);
    193 }
    194 //******************************************************************************
    195 //******************************************************************************
    196 DWORD WIN32API GetDialogBaseUnits(void)
    197 {
    198 #ifdef DEBUG
    199     WriteLog("USER32:  GetDialogBaseUnits\n");
    200 #endif
    201     return O32_GetDialogBaseUnits();
     233    return (BOOL)SendDlgItemMessageA(hwnd, id, BM_SETCHECK, check,0);
     234}
     235//******************************************************************************
     236//******************************************************************************
     237UINT WIN32API GetDlgItemTextA(HWND hwnd, int id, LPSTR lpszName, UINT cch)
     238{
     239    return SendDlgItemMessageA( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
     240}
     241//*****************************************************************************
     242//*****************************************************************************
     243UINT WIN32API GetDlgItemTextW(HWND   hwnd, int id, LPWSTR lpszName, UINT cch)
     244{
     245    return SendDlgItemMessageW( hwnd, id, WM_GETTEXT, cch, (LPARAM)lpszName);
     246}
     247//******************************************************************************
     248//******************************************************************************
     249BOOL WIN32API SetDlgItemInt( HWND hwnd, int idControl, UINT uValue, BOOL  fSigned)
     250{
     251  char str[20];
     252
     253    dprintf(("USER32:  SetDlgItemInt\n"));
     254
     255    if (fSigned)
     256            sprintf( str, "%d", (INT)uValue );
     257    else    sprintf( str, "%u", uValue );
     258
     259    return SendDlgItemMessageA( hwnd, idControl, WM_SETTEXT, 0, (LPARAM)str );
     260}
     261//******************************************************************************
     262//******************************************************************************
     263BOOL WIN32API SetDlgItemTextA( HWND hwnd, int id, LPCSTR lpszName)
     264{
     265    return SendDlgItemMessageA( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
     266}
     267//******************************************************************************
     268//******************************************************************************
     269BOOL WIN32API SetDlgItemTextW( HWND hwnd, int id, LPCWSTR lpszName)
     270{
     271    return SendDlgItemMessageW( hwnd, id, WM_SETTEXT, 0, (LPARAM)lpszName );
    202272}
    203273//******************************************************************************
     
    210280    return O32_GetDlgItemInt(arg1, arg2, arg3, arg4);
    211281}
    212 
    213 
    214 /*****************************************************************************
    215  * Name      : UINT WIN32API GetDlgItemTextW
    216  * Purpose   : Determine the text of a window control
    217  * Parameters: HWND   arg1
    218  *             int    arg2
    219  *             LPWSTR arg3
    220  *             UINT   arg4
    221  * Variables :
    222  * Result    :
    223  * Remark    :
    224  * Status    : UNTESTED UNKNOWN STUB
    225  *
    226  * Author    : Patrick Haller [Wed, 1998/06/16 11:55]
    227  *****************************************************************************/
    228 
    229 UINT WIN32API GetDlgItemTextW(HWND   arg1,
    230                               int    arg2,
    231                               LPWSTR arg3,
    232                               UINT   arg4)
    233 {
    234   LPSTR lpBuffer;                   /* temporary buffer for the ascii result */
    235   UINT  uiResult;                   /* return value of the ascii variant     */
    236 
    237   dprintf(("USER32: GetDlgItemTextW(%08xh,%08xh,%08xh,%08xh)\n",
    238            arg1,
    239            arg2,
    240            arg3,
    241            arg4));
    242 
    243 
    244   lpBuffer = (LPSTR)malloc(arg4);              /* allocate temporary buffer */
    245   uiResult = GetDlgItemTextA(arg1,             /* call ascii variant        */
    246                              arg2,
    247                              lpBuffer,
    248                              arg4);
    249 
    250   AsciiToUnicodeN(lpBuffer,                /* now convert result to unicode */
    251                   arg3,
    252                   arg4);
    253 
    254   free(lpBuffer);                              /* free the temporary buffer */
    255 
    256   return (uiResult);                                       /* OK, that's it */
    257 }
    258282//******************************************************************************
    259283//******************************************************************************
     
    265289    return O32_GetNextDlgGroupItem(arg1, arg2, arg3);
    266290}
    267 //******************************************************************************
    268 //******************************************************************************
    269 BOOL WIN32API SetDlgItemTextW( HWND arg1, int arg2, LPCWSTR  arg3)
    270 {
    271 char *astring = UnicodeToAsciiString((LPWSTR)arg3);
    272 BOOL  rc;
    273 
    274 #ifdef DEBUG
    275     WriteLog("USER32:  SetDlgItemTextW\n");
    276 #endif
    277     // NOTE: This will not work as is (needs UNICODE support)
    278     rc = O32_SetDlgItemText(arg1, arg2, astring);
    279     FreeAsciiString(astring);
    280     return rc;
    281 }
    282 //******************************************************************************
    283 //******************************************************************************
     291/***********************************************************************
     292 *           GetDialogBaseUnits   (USER.243) (USER32.233)
     293 */
     294DWORD WIN32API GetDialogBaseUnits(void)
     295{
     296    return Win32Dialog::GetDialogBaseUnits();
     297}
     298//******************************************************************************
     299//******************************************************************************
     300INT WIN32API DlgDirListA(HWND hDlg, LPSTR spec, INT idLBox, INT idStatic, UINT attrib )
     301{
     302    return DIALOG_DlgDirList( hDlg, spec, idLBox, idStatic, attrib, FALSE );
     303}
     304//******************************************************************************
     305//******************************************************************************
     306int WIN32API DlgDirListW(HWND hDlg, LPWSTR spec, INT idLBox, INT idStatic, UINT attrib )
     307{
     308    return DIALOG_DlgDirListW( hDlg, spec, idLBox, idStatic, attrib, FALSE );
     309}
     310//******************************************************************************
     311//******************************************************************************
     312INT WIN32API DlgDirListComboBoxA(HWND hDlg, LPSTR spec, INT idCBox, INT idStatic, UINT attrib )
     313{
     314    return DIALOG_DlgDirList( hDlg, spec, idCBox, idStatic, attrib, TRUE );
     315}
     316//******************************************************************************
     317//******************************************************************************
     318INT WIN32API DlgDirListComboBoxW( HWND hDlg, LPWSTR spec, INT idCBox, INT idStatic, UINT attrib )
     319{
     320    return DIALOG_DlgDirListW( hDlg, spec, idCBox, idStatic, attrib, TRUE );
     321}
     322//******************************************************************************
     323//******************************************************************************
     324BOOL WIN32API DlgDirSelectComboBoxExA(HWND hwnd, LPSTR str, INT len, INT id )
     325{
     326    return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, TRUE );
     327}
     328//******************************************************************************
     329//******************************************************************************
     330BOOL WIN32API DlgDirSelectComboBoxExW(HWND hwnd, LPWSTR str, INT len, INT id)
     331{
     332    return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, TRUE );
     333}
     334//******************************************************************************
     335//******************************************************************************
     336BOOL WIN32API DlgDirSelectExA(HWND hwnd, LPSTR str, INT len, INT id)
     337{
     338    return DIALOG_DlgDirSelect( hwnd, str, len, id, TRUE, FALSE, FALSE );
     339}
     340//******************************************************************************
     341//******************************************************************************
     342BOOL WIN32API DlgDirSelectExW(HWND hwnd, LPWSTR str, INT len, INT id)
     343{
     344    return DIALOG_DlgDirSelect( hwnd, (LPSTR)str, len, id, TRUE, TRUE, FALSE );
     345}
     346/**********************************************************************
     347 *           DIALOG_DlgDirSelect
     348 *
     349 * Helper function for DlgDirSelect*
     350 */
     351static BOOL DIALOG_DlgDirSelect( HWND hwnd, LPSTR str, INT len,
     352                                 INT id, BOOL win32, BOOL unicode,
     353                                 BOOL combo )
     354{
     355    char *buffer, *ptr;
     356    INT item, size;
     357    BOOL ret;
     358    HWND listbox = GetDlgItem( hwnd, id );
     359
     360    if (!listbox) return FALSE;
     361
     362    item = SendMessageA(listbox, combo ? CB_GETCURSEL
     363                                             : LB_GETCURSEL, 0, 0 );
     364    if (item == LB_ERR) return FALSE;
     365    size = SendMessageA(listbox, combo ? CB_GETLBTEXTLEN
     366                                             : LB_GETTEXTLEN, 0, 0 );
     367    if (size == LB_ERR) return FALSE;
     368
     369    if (!(buffer = (char *)malloc( size+1 ))) return FALSE;
     370
     371    SendMessageA( listbox, combo ? CB_GETLBTEXT : LB_GETTEXT,
     372                  item, (LPARAM)buffer );
     373
     374    if ((ret = (buffer[0] == '[')))  /* drive or directory */
     375    {
     376        if (buffer[1] == '-')  /* drive */
     377        {
     378            buffer[3] = ':';
     379            buffer[4] = 0;
     380            ptr = buffer + 2;
     381        }
     382        else
     383        {
     384            buffer[strlen(buffer)-1] = '\\';
     385            ptr = buffer + 1;
     386        }
     387    }
     388    else ptr = buffer;
     389
     390    if (unicode) lstrcpynAtoW( (LPWSTR)str, ptr, len );
     391    else lstrcpynA( str, ptr, len );
     392
     393    free( buffer );
     394    return ret;
     395}
     396
     397
     398/**********************************************************************
     399 *      DIALOG_DlgDirList
     400 *
     401 * Helper function for DlgDirList*
     402 */
     403static INT DIALOG_DlgDirList( HWND hDlg, LPSTR spec, INT idLBox,
     404                              INT idStatic, UINT attrib, BOOL combo )
     405{
     406    int drive;
     407    HWND hwnd;
     408    LPSTR orig_spec = spec;
     409
     410#define SENDMSG(msg,wparam,lparam) \
     411    ((attrib & DDL_POSTMSGS) ? PostMessageA( hwnd, msg, wparam, lparam ) \
     412                             : SendMessageA( hwnd, msg, wparam, lparam ))
     413
     414    if (spec && spec[0] && (spec[1] == ':'))
     415    {
     416        drive = _toupper( spec[0] ) - 'A';
     417        spec += 2;
     418        if (!DRIVE_SetCurrentDrive( drive )) return FALSE;
     419    }
     420    else drive = DRIVE_GetCurrentDrive();
     421
     422    /* If the path exists and is a directory, chdir to it */
     423    if (!spec || !spec[0] || DRIVE_Chdir( drive, spec )) spec = "*.*";
     424    else
     425    {
     426        char *p, *p2;
     427        p = spec;
     428        if ((p2 = strrchr( p, '\\' ))) p = p2;
     429        if ((p2 = strrchr( p, '/' ))) p = p2;
     430        if (p != spec)
     431        {
     432            char sep = *p;
     433            *p = 0;
     434            if (!DRIVE_Chdir( drive, spec ))
     435            {
     436                *p = sep;  /* Restore the original spec */
     437                return FALSE;
     438            }
     439            spec = p + 1;
     440        }
     441    }
     442
     443    if (idLBox && ((hwnd = GetDlgItem( hDlg, idLBox )) != 0))
     444    {
     445        SENDMSG( combo ? CB_RESETCONTENT : LB_RESETCONTENT, 0, 0 );
     446        if (attrib & DDL_DIRECTORY)
     447        {
     448            if (!(attrib & DDL_EXCLUSIVE))
     449            {
     450                if (SENDMSG( combo ? CB_DIR : LB_DIR,
     451                             attrib & ~(DDL_DIRECTORY | DDL_DRIVES),
     452                             (LPARAM)spec ) == LB_ERR)
     453                    return FALSE;
     454            }
     455            if (SENDMSG( combo ? CB_DIR : LB_DIR,
     456                       (attrib & (DDL_DIRECTORY | DDL_DRIVES)) | DDL_EXCLUSIVE,
     457                         (LPARAM)"*.*" ) == LB_ERR)
     458                return FALSE;
     459        }
     460        else
     461        {
     462            if (SENDMSG( combo ? CB_DIR : LB_DIR, attrib,
     463                         (LPARAM)spec ) == LB_ERR)
     464                return FALSE;
     465        }
     466    }
     467
     468    if (idStatic && ((hwnd = GetDlgItem( hDlg, idStatic )) != 0))
     469    {
     470        char temp[512], curpath[512];
     471        int drive = DRIVE_GetCurrentDrive();
     472        strcpy( temp, "A:\\" );
     473        temp[0] += drive;
     474        lstrcpynA( temp + 3, DRIVE_GetDosCwd(curpath, drive), sizeof(temp)-3 );
     475        CharLowerA( temp );
     476        /* Can't use PostMessage() here, because the string is on the stack */
     477        SetDlgItemTextA( hDlg, idStatic, temp );
     478    }
     479
     480    if (orig_spec && (spec != orig_spec))
     481    {
     482        /* Update the original file spec */
     483        char *p = spec;
     484        while ((*orig_spec++ = *p++));
     485    }
     486
     487    return TRUE;
     488#undef SENDMSG
     489}
     490
     491
     492/**********************************************************************
     493 *      DIALOG_DlgDirListW
     494 *
     495 * Helper function for DlgDirList*32W
     496 */
     497static INT DIALOG_DlgDirListW( HWND hDlg, LPWSTR spec, INT idLBox,
     498                               INT idStatic, UINT attrib, BOOL combo )
     499{
     500    if (spec)
     501    {
     502        LPSTR specA = HEAP_strdupWtoA( GetProcessHeap(), 0, spec );
     503        INT ret = DIALOG_DlgDirList( hDlg, specA, idLBox, idStatic,
     504                                       attrib, combo );
     505        lstrcpyAtoW( spec, specA );
     506        HeapFree( GetProcessHeap(), 0, specA );
     507        return ret;
     508    }
     509    return DIALOG_DlgDirList( hDlg, NULL, idLBox, idStatic, attrib, combo );
     510}
     511//******************************************************************************
     512//******************************************************************************
     513
Note: See TracChangeset for help on using the changeset viewer.