Ignore:
Timestamp:
Sep 15, 2001, 11:26:26 AM (24 years ago)
Author:
sandervl
Message:

restored old version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/shell32/control.c

    r6650 r6709  
    1 /* $Id: control.c,v 1.2 2001-09-05 13:46:56 bird Exp $ */
    21/* Control Panel management */
    32/* Eric Pouech 2001 */
     
    1716
    1817typedef struct CPlApplet {
    19     struct CPlApplet*   next;       /* linked list */
    20     HWND        hWnd;
    21     unsigned        count;      /* number of subprograms */
    22     HMODULE         hModule;    /* module of loaded applet */
    23     APPLET_PROC     proc;       /* entry point address */
    24     NEWCPLINFOA     info[1];    /* array of count information.
    25                     * dwSize field is 0 if entry is invalid */
     18    struct CPlApplet*   next;           /* linked list */
     19    HWND                hWnd;
     20    unsigned            count;          /* number of subprograms */
     21    HMODULE             hModule;        /* module of loaded applet */
     22    APPLET_PROC         proc;           /* entry point address */
     23    NEWCPLINFOA         info[1];        /* array of count information.
     24                                        * dwSize field is 0 if entry is invalid */
    2625} CPlApplet;
    2726
    2827typedef struct CPanel {
    29     CPlApplet*      first;      /* linked list */
    30     HWND        hWnd;
     28    CPlApplet*          first;          /* linked list */
     29    HWND                hWnd;
    3130    unsigned            status;
    32     CPlApplet*      clkApplet;
     31    CPlApplet*          clkApplet;
    3332    unsigned            clkSP;
    3433} CPanel;
    3534
    36 static  CPlApplet*  Control_UnloadApplet(CPlApplet* applet)
    37 {
    38     unsigned    i;
    39     CPlApplet*  next;
     35static  CPlApplet*      Control_UnloadApplet(CPlApplet* applet)
     36{
     37    unsigned    i;
     38    CPlApplet*  next;
    4039
    4140    for (i = 0; i < applet->count; i++) {
     
    5049}
    5150
    52 static CPlApplet*   Control_LoadApplet(HWND hWnd, LPCSTR cmd, CPanel* panel)
    53 {
    54     CPlApplet*  applet;
    55     unsigned    i;
    56     CPLINFO info;
     51static CPlApplet*       Control_LoadApplet(HWND hWnd, LPCSTR cmd, CPanel* panel)
     52{
     53    CPlApplet*  applet;
     54    unsigned    i;
     55    CPLINFO     info;
    5756
    5857    if (!(applet = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*applet))))
     
    6362    if (!(applet->hModule = LoadLibraryA(cmd))) {
    6463        WARN("Cannot load control panel applet %s\n", cmd);
    65     goto theError;
     64        goto theError;
    6665    }
    6766    if (!(applet->proc = (APPLET_PROC)GetProcAddress(applet->hModule, "CPlApplet"))) {
    6867        WARN("Not a valid control panel applet %s\n", cmd);
    69     goto theError;
     68        goto theError;
    7069    }
    7170    if (!applet->proc(hWnd, CPL_INIT, 0L, 0L)) {
    7271        WARN("Init of applet has failed\n");
    73     goto theError;
     72        goto theError;
    7473    }
    7574    if ((applet->count = applet->proc(hWnd, CPL_GETCOUNT, 0L, 0L)) == 0) {
    7675        WARN("No subprogram in applet\n");
    77     goto theError;
    78     }
    79 
    80     applet = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, applet,
    81             sizeof(*applet) + (applet->count - 1) * sizeof(NEWCPLINFOA));
    82 
     76        goto theError;
     77    }
     78
     79    applet = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, applet, 
     80                        sizeof(*applet) + (applet->count - 1) * sizeof(NEWCPLINFOA));
     81   
    8382    for (i = 0; i < applet->count; i++) {
    8483       applet->info[i].dwSize = sizeof(NEWCPLINFOA);
    8584       /* proc is supposed to return a null value upon success for
    86     * CPL_INQUIRE and CPL_NEWINQUIRE
    87     * However, real drivers don't seem to behave like this
    88     * So, use introspection rather than return value
    89     */
     85        * CPL_INQUIRE and CPL_NEWINQUIRE
     86        * However, real drivers don't seem to behave like this
     87        * So, use introspection rather than return value
     88        */
    9089       applet->proc(hWnd, CPL_NEWINQUIRE, i, (LPARAM)&applet->info[i]);
    9190       if (applet->info[i].hIcon == 0) {
    92        applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
    93        if (info.idIcon == 0 || info.idName == 0) {
    94            WARN("Couldn't get info from sp %u\n", i);
    95            applet->info[i].dwSize = 0;
    96        } else {
    97            /* convert the old data into the new structure */
    98            applet->info[i].dwFlags = 0;
    99            applet->info[i].dwHelpContext = 0;
    100            applet->info[i].lData = info.lData;
    101            applet->info[i].hIcon = LoadIconA(applet->hModule,
    102                         MAKEINTRESOURCEA(info.idIcon));
    103            LoadStringA(applet->hModule, info.idName,
    104                applet->info[i].szName, sizeof(applet->info[i].szName));
    105            LoadStringA(applet->hModule, info.idInfo,
    106                applet->info[i].szInfo, sizeof(applet->info[i].szInfo));
    107            applet->info[i].szHelpFile[0] = '\0';
    108        }
     91           applet->proc(hWnd, CPL_INQUIRE, i, (LPARAM)&info);
     92           if (info.idIcon == 0 || info.idName == 0) {
     93               WARN("Couldn't get info from sp %u\n", i);
     94               applet->info[i].dwSize = 0;
     95           } else {
     96               /* convert the old data into the new structure */
     97               applet->info[i].dwFlags = 0;
     98               applet->info[i].dwHelpContext = 0;
     99               applet->info[i].lData = info.lData;
     100               applet->info[i].hIcon = LoadIconA(applet->hModule,
     101                                                MAKEINTRESOURCEA(info.idIcon));
     102               LoadStringA(applet->hModule, info.idName,
     103                           applet->info[i].szName, sizeof(applet->info[i].szName));
     104               LoadStringA(applet->hModule, info.idInfo,
     105                           applet->info[i].szInfo, sizeof(applet->info[i].szInfo));
     106               applet->info[i].szHelpFile[0] = '\0';
     107           }
    109108       }
    110109    }
     
    120119}
    121120
    122 static void     Control_WndProc_Create(HWND hWnd, const CREATESTRUCTA* cs)
    123 {
    124    CPanel*  panel = (CPanel*)cs->lpCreateParams;
     121static void     Control_WndProc_Create(HWND hWnd, const CREATESTRUCTA* cs)
     122{
     123   CPanel*      panel = (CPanel*)cs->lpCreateParams;
    125124
    126125   SetWindowLongA(hWnd, 0, (LPARAM)panel);
     
    129128}
    130129
    131 #define XICON   32
    132 #define XSTEP   128
    133 #define YICON   32
    134 #define YSTEP   64
    135 
    136 static BOOL Control_Localize(const CPanel* panel, unsigned cx, unsigned cy,
    137                 CPlApplet** papplet, unsigned* psp)
    138 {
    139     unsigned    i, x = (XSTEP-XICON)/2, y = 0;
    140     CPlApplet*  applet;
    141     RECT    rc;
    142 
     130#define XICON   32
     131#define XSTEP   128
     132#define YICON   32
     133#define YSTEP   64
     134
     135static BOOL     Control_Localize(const CPanel* panel, unsigned cx, unsigned cy,
     136                                CPlApplet** papplet, unsigned* psp)
     137{
     138    unsigned    i, x = (XSTEP-XICON)/2, y = 0;
     139    CPlApplet*  applet;
     140    RECT        rc;
     141   
    143142    GetClientRect(panel->hWnd, &rc);
    144143    for (applet = panel->first; applet; applet = applet = applet->next) {
    145144        for (i = 0; i < applet->count; i++) {
    146         if (!applet->info[i].dwSize) continue;
    147         if (x + XSTEP >= rc.right - rc.left) {
    148             x = (XSTEP-XICON)/2;
    149         y += YSTEP;
    150         }
    151         if (cx >= x && cx < x + XICON && cy >= y && cy < y + YSTEP) {
    152             *papplet = applet;
    153             *psp = i;
    154         return TRUE;
    155         }
    156         x += XSTEP;
    157     }
     145            if (!applet->info[i].dwSize) continue;
     146            if (x + XSTEP >= rc.right - rc.left) {
     147                x = (XSTEP-XICON)/2;
     148                y += YSTEP;
     149            }
     150            if (cx >= x && cx < x + XICON && cy >= y && cy < y + YSTEP) {
     151                *papplet = applet;
     152                *psp = i;
     153                return TRUE;
     154            }
     155            x += XSTEP;
     156        }
    158157    }
    159158    return FALSE;
     
    162161static LRESULT Control_WndProc_Paint(const CPanel* panel, WPARAM wParam)
    163162{
    164     HDC     hdc;
    165     PAINTSTRUCT ps;
    166     RECT    rc, txtRect;
    167     unsigned    i, x = 0, y = 0;
    168     CPlApplet*  applet;
    169     HGDIOBJ hOldFont;
     163    HDC         hdc;
     164    PAINTSTRUCT ps;
     165    RECT        rc, txtRect;
     166    unsigned    i, x = 0, y = 0;
     167    CPlApplet*  applet;
     168    HGDIOBJ     hOldFont;
    170169
    171170    hdc = (wParam) ? (HDC)wParam : BeginPaint(panel->hWnd, &ps);
     
    174173    for (applet = panel->first; applet; applet = applet = applet->next) {
    175174        for (i = 0; i < applet->count; i++) {
    176         if (x + XSTEP >= rc.right - rc.left) {
    177             x = 0;
    178         y += YSTEP;
    179         }
    180         if (!applet->info[i].dwSize) continue;
    181         DrawIcon(hdc, x + (XSTEP-XICON)/2, y, applet->info[i].hIcon);
    182         txtRect.left = x;
    183         txtRect.right = x + XSTEP;
    184         txtRect.top = y + YICON;
    185         txtRect.bottom = y + YSTEP;
    186         DrawTextA(hdc, applet->info[i].szName, -1, &txtRect,
    187               DT_CENTER | DT_VCENTER);
    188         x += XSTEP;
    189     }
     175            if (x + XSTEP >= rc.right - rc.left) {
     176                x = 0;
     177                y += YSTEP;
     178            }
     179            if (!applet->info[i].dwSize) continue;
     180            DrawIcon(hdc, x + (XSTEP-XICON)/2, y, applet->info[i].hIcon);
     181            txtRect.left = x;
     182            txtRect.right = x + XSTEP;
     183            txtRect.top = y + YICON;
     184            txtRect.bottom = y + YSTEP;
     185            DrawTextA(hdc, applet->info[i].szName, -1, &txtRect,
     186                      DT_CENTER | DT_VCENTER);
     187            x += XSTEP;
     188        }
    190189    }
    191190    SelectObject(hdc, hOldFont);
     
    196195static LRESULT Control_WndProc_LButton(CPanel* panel, LPARAM lParam, BOOL up)
    197196{
    198     unsigned    i;
    199     CPlApplet*  applet;
    200 
     197    unsigned    i;
     198    CPlApplet*  applet;
     199   
    201200    if (Control_Localize(panel, LOWORD(lParam), HIWORD(lParam), &applet, &i)) {
    202201       if (up) {
    203        if (panel->clkApplet == applet && panel->clkSP == i) {
    204            applet->proc(applet->hWnd, CPL_DBLCLK, i, applet->info[i].lData);
     202           if (panel->clkApplet == applet && panel->clkSP == i) {
     203               applet->proc(applet->hWnd, CPL_DBLCLK, i, applet->info[i].lData);
     204           }
     205       } else {
     206           panel->clkApplet = applet;
     207           panel->clkSP = i;
    205208       }
    206        } else {
    207        panel->clkApplet = applet;
    208        panel->clkSP = i;
    209        }
    210209    }
    211210    return 0;
    212211}
    213212
    214 static LRESULT WINAPI   Control_WndProc(HWND hWnd, UINT wMsg,
    215                     WPARAM lParam1, LPARAM lParam2)
    216 {
    217    CPanel*  panel = (CPanel*)GetWindowLongA(hWnd, 0);
     213static LRESULT WINAPI   Control_WndProc(HWND hWnd, UINT wMsg,
     214                                        WPARAM lParam1, LPARAM lParam2)
     215{
     216   CPanel*      panel = (CPanel*)GetWindowLongA(hWnd, 0);
    218217
    219218   if (panel || wMsg == WM_CREATE) {
    220219      switch (wMsg) {
    221220      case WM_CREATE:
    222     Control_WndProc_Create(hWnd, (CREATESTRUCTA*)lParam2);
    223     return 0;
     221        Control_WndProc_Create(hWnd, (CREATESTRUCTA*)lParam2);
     222        return 0;
    224223      case WM_DESTROY:
    225     while ((panel->first = Control_UnloadApplet(panel->first)));
    226     break;
     224        while ((panel->first = Control_UnloadApplet(panel->first)));
     225        break;
    227226      case WM_PAINT:
    228     return Control_WndProc_Paint(panel, lParam1);
     227        return Control_WndProc_Paint(panel, lParam1);
    229228      case WM_LBUTTONUP:
    230     return Control_WndProc_LButton(panel, lParam2, TRUE);
     229        return Control_WndProc_LButton(panel, lParam2, TRUE);
    231230      case WM_LBUTTONDOWN:
    232     return Control_WndProc_LButton(panel, lParam2, FALSE);
     231        return Control_WndProc_LButton(panel, lParam2, FALSE);
    233232/* EPP       case WM_COMMAND: */
    234 /* EPP   return Control_WndProc_Command(mwi, lParam1, lParam2); */
     233/* EPP   return Control_WndProc_Command(mwi, lParam1, lParam2); */
    235234      }
    236235   }
     
    241240static void    Control_DoInterface(CPanel* panel, HWND hWnd, HINSTANCE hInst)
    242241{
    243     WNDCLASSA   wc;
    244     MSG     msg;
     242    WNDCLASSA   wc;
     243    MSG         msg;
    245244
    246245    wc.style = CS_HREDRAW|CS_VREDRAW;
     
    257256    if (!RegisterClassA(&wc)) return;
    258257
    259     CreateWindowExA(0, wc.lpszClassName, "Wine Control Panel",
    260             WS_OVERLAPPEDWINDOW | WS_VISIBLE,
    261             CW_USEDEFAULT, CW_USEDEFAULT,
    262             CW_USEDEFAULT, CW_USEDEFAULT,
    263             hWnd, (HMENU)0, hInst, panel);
     258    CreateWindowExA(0, wc.lpszClassName, "Wine Control Panel", 
     259                    WS_OVERLAPPEDWINDOW | WS_VISIBLE,
     260                    CW_USEDEFAULT, CW_USEDEFAULT,
     261                    CW_USEDEFAULT, CW_USEDEFAULT,
     262                    hWnd, (HMENU)0, hInst, panel);
    264263    if (!panel->hWnd) return;
    265264    while (GetMessageA(&msg, panel->hWnd, 0, 0)) {
    266265        TranslateMessage(&msg);
    267266        DispatchMessageA(&msg);
    268     if (!panel->first) break;
    269     }
    270 }
    271 
    272 static  void    Control_DoWindow(CPanel* panel, HWND hWnd, HINSTANCE hInst)
    273 {
    274     HANDLE      h;
    275     WIN32_FIND_DATAA    fd;
    276     char        buffer[MAX_PATH];
     267        if (!panel->first) break;
     268    }
     269}
     270
     271static  void    Control_DoWindow(CPanel* panel, HWND hWnd, HINSTANCE hInst)
     272{
     273    HANDLE              h;
     274    WIN32_FIND_DATAA    fd;
     275    char                buffer[MAX_PATH];
    277276
    278277    /* FIXME: should grab path somewhere from configuration */
    279278    if ((h = FindFirstFileA("c:\\windows\\system\\*.cpl", &fd)) != 0) {
    280279        do {
    281        sprintf(buffer, "c:\\windows\\system\\%s", fd.cFileName);
    282        Control_LoadApplet(hWnd, buffer, panel);
    283     } while (FindNextFileA(h, &fd));
    284     FindClose(h);
     280           sprintf(buffer, "c:\\windows\\system\\%s", fd.cFileName);
     281           Control_LoadApplet(hWnd, buffer, panel);
     282        } while (FindNextFileA(h, &fd));
     283        FindClose(h);
    285284    }
    286285
     
    288287}
    289288
    290 static  void    Control_DoLaunch(CPanel* panel, HWND hWnd, LPCSTR cmd)
     289static  void    Control_DoLaunch(CPanel* panel, HWND hWnd, LPCSTR cmd)
    291290   /* forms to parse:
    292     *   foo.cpl,@sp,str
    293     *   foo.cpl,@sp
    294     *   foo.cpl,,str
    295     *   foo.cpl @sp
    296     *   foo.cpl str
     291    *   foo.cpl,@sp,str
     292    *   foo.cpl,@sp
     293    *   foo.cpl,,str
     294    *   foo.cpl @sp
     295    *   foo.cpl str
    297296    */
    298297{
    299     char*   buffer;
    300     char*   beg = NULL;
    301     char*   end;
    302     char    ch;
    303     unsigned    sp = 0;
    304     char*   extraPmts = NULL;
     298    char*       buffer;
     299    char*       beg = NULL;
     300    char*       end;
     301    char        ch;
     302    unsigned    sp = 0;
     303    char*       extraPmts = NULL;
    305304
    306305    buffer = HeapAlloc(GetProcessHeap(), 0, strlen(cmd) + 1);
     
    310309
    311310    for (;;) {
    312     ch = *end;
    313     if (ch == ' ' || ch == ',' || ch == '\0') {
    314         *end = '\0';
    315         if (beg) {
    316             if (*beg == '@') {
    317             sp = atoi(beg + 1);
    318         } else if (*beg == '\0') {
    319             sp = 0;
    320         } else {
    321             extraPmts = beg;
    322         }
    323         }
    324         if (ch == '\0') break;
    325         beg = end + 1;
    326         if (ch == ' ') while (end[1] == ' ') end++;
    327     }
    328     end++;
     311        ch = *end;
     312        if (ch == ' ' || ch == ',' || ch == '\0') {
     313            *end = '\0';
     314            if (beg) {
     315                if (*beg == '@') {
     316                    sp = atoi(beg + 1);
     317                } else if (*beg == '\0') {
     318                    sp = 0;
     319                } else {
     320                    extraPmts = beg;
     321                }
     322            }
     323            if (ch == '\0') break;
     324            beg = end + 1;
     325            if (ch == ' ') while (end[1] == ' ') end++;
     326        }
     327        end++;
    329328    }
    330329    Control_LoadApplet(hWnd, buffer, panel);
     
    335334       assert(applet && applet->next == NULL);
    336335       if (sp >= applet->count) {
    337       WARN("Out of bounds (%u >= %u), setting to 0\n", sp, applet->count);
    338       sp = 0;
     336          WARN("Out of bounds (%u >= %u), setting to 0\n", sp, applet->count);
     337          sp = 0;
    339338       }
    340339       if (applet->info[sp].dwSize) {
    341       if (!applet->proc(applet->hWnd, CPL_STARTWPARMSA, sp, (LPARAM)extraPmts))
    342          applet->proc(applet->hWnd, CPL_DBLCLK, sp, applet->info[sp].lData);
     340          if (!applet->proc(applet->hWnd, CPL_STARTWPARMSA, sp, (LPARAM)extraPmts))
     341             applet->proc(applet->hWnd, CPL_DBLCLK, sp, applet->info[sp].lData);
    343342       }
    344343       Control_UnloadApplet(applet);
     
    348347
    349348/*************************************************************************
    350  * Control_RunDLL           [SHELL32.12]
     349 * Control_RunDLL                       [SHELL32.12]
    351350 *
    352351 */
    353352void WINAPI Control_RunDLL(HWND hWnd, HINSTANCE hInst, LPCSTR cmd, DWORD nCmdShow)
    354353{
    355     CPanel  panel;
    356 
    357     TRACE("(0x%08x, 0x%08lx, %s, 0x%08lx)\n",
    358       hWnd, (DWORD)hInst, debugstr_a(cmd), nCmdShow);
     354    CPanel      panel;
     355
     356    TRACE("(0x%08x, 0x%08lx, %s, 0x%08lx)\n", 
     357          hWnd, (DWORD)hInst, debugstr_a(cmd), nCmdShow);
    359358
    360359    memset(&panel, 0, sizeof(panel));
     
    368367
    369368/*************************************************************************
    370  * Control_FillCache_RunDLL         [SHELL32.8]
     369 * Control_FillCache_RunDLL                     [SHELL32.8]
    371370 *
    372371 */
     
    378377
    379378/*************************************************************************
    380  * RunDLL_CallEntry16               [SHELL32.122]
     379 * RunDLL_CallEntry16                           [SHELL32.122]
    381380 * the name is propably wrong
    382381 */
Note: See TracChangeset for help on using the changeset viewer.