ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

settings.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Display Control Panel
00004  * FILE:            dll/cpl/desk/settings.c
00005  * PURPOSE:         Settings property page
00006  *
00007  * PROGRAMMERS:     Trevor McCort (lycan359@gmail.com)
00008  *                  Hervé Poussineau (hpoussin@reactos.org)
00009  */
00010 
00011 #include "desk.h"
00012 
00013 typedef struct _DATA
00014 {
00015     PDISPLAY_DEVICE_ENTRY DisplayDeviceList;
00016     PDISPLAY_DEVICE_ENTRY CurrentDisplayDevice;
00017     HBITMAP hSpectrumBitmaps[NUM_SPECTRUM_BITMAPS];
00018     int cxSource[NUM_SPECTRUM_BITMAPS];
00019     int cySource[NUM_SPECTRUM_BITMAPS];
00020 } DATA, *PDATA;
00021 
00022 
00023 static VOID
00024 UpdateDisplay(IN HWND hwndDlg, PDATA pData, IN BOOL bUpdateThumb)
00025 {
00026     TCHAR Buffer[64];
00027     TCHAR Pixel[64];
00028     DWORD index;
00029 
00030     LoadString(hApplet, IDS_PIXEL, Pixel, sizeof(Pixel) / sizeof(TCHAR));
00031     _stprintf(Buffer, Pixel, pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth, pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight, Pixel);
00032     SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT, WM_SETTEXT, 0, (LPARAM)Buffer);
00033 
00034     for (index = 0; index < pData->CurrentDisplayDevice->ResolutionsCount; index++)
00035     {
00036         if (pData->CurrentDisplayDevice->Resolutions[index].dmPelsWidth == pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth &&
00037             pData->CurrentDisplayDevice->Resolutions[index].dmPelsHeight == pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight)
00038         {
00039             if (bUpdateThumb)
00040                 SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_SETPOS, TRUE, index);
00041             break;
00042         }
00043     }
00044     if (LoadString(hApplet, (2900 + pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel), Buffer, sizeof(Buffer) / sizeof(TCHAR)))
00045         SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)Buffer);
00046 }
00047 
00048 static PSETTINGS_ENTRY
00049 GetPossibleSettings(IN LPCTSTR DeviceName, OUT DWORD* pSettingsCount, OUT PSETTINGS_ENTRY* CurrentSettings)
00050 {
00051     DEVMODE devmode;
00052     DWORD NbSettings = 0;
00053     DWORD iMode = 0;
00054     DWORD dwFlags = 0;
00055     PSETTINGS_ENTRY Settings = NULL;
00056     HDC hDC;
00057     PSETTINGS_ENTRY Current;
00058     DWORD bpp, xres, yres, checkbpp;
00059     DWORD curDispFreq;
00060 
00061     /* Get current settings */
00062     *CurrentSettings = NULL;
00063     hDC = CreateIC(NULL, DeviceName, NULL, NULL);
00064     bpp = GetDeviceCaps(hDC, PLANES);
00065     bpp *= GetDeviceCaps(hDC, BITSPIXEL);
00066     xres = GetDeviceCaps(hDC, HORZRES);
00067     yres = GetDeviceCaps(hDC, VERTRES);
00068     DeleteDC(hDC);
00069 
00070     /* List all settings */
00071     devmode.dmSize = (WORD)sizeof(DEVMODE);
00072     devmode.dmDriverExtra = 0;
00073 
00074     if (!EnumDisplaySettingsEx(DeviceName, ENUM_CURRENT_SETTINGS, &devmode, dwFlags))
00075         return NULL;
00076 
00077     curDispFreq = devmode.dmDisplayFrequency;
00078 
00079     while (EnumDisplaySettingsEx(DeviceName, iMode, &devmode, dwFlags))
00080     {
00081         if ((devmode.dmBitsPerPel == 4 ||
00082              devmode.dmBitsPerPel == 8 ||
00083              devmode.dmBitsPerPel == 16 ||
00084              devmode.dmBitsPerPel == 24 ||
00085              devmode.dmBitsPerPel == 32) &&
00086              devmode.dmDisplayFrequency == curDispFreq)
00087         {
00088             checkbpp=1;
00089         }
00090         else
00091             checkbpp=0;
00092 
00093         if (devmode.dmPelsWidth < 640 ||
00094             devmode.dmPelsHeight < 480 || checkbpp == 0)
00095         {
00096             iMode++;
00097             continue;
00098         }
00099 
00100         Current = HeapAlloc(GetProcessHeap(), 0, sizeof(SETTINGS_ENTRY));
00101         if (Current != NULL)
00102         {
00103             /* Sort resolutions by increasing height, and BPP */
00104             PSETTINGS_ENTRY Previous = NULL;
00105             PSETTINGS_ENTRY Next = Settings;
00106             Current->dmPelsWidth = devmode.dmPelsWidth;
00107             Current->dmPelsHeight = devmode.dmPelsHeight;
00108             Current->dmBitsPerPel = devmode.dmBitsPerPel;
00109             Current->dmDisplayFrequency = devmode.dmDisplayFrequency;
00110             while (Next != NULL && (
00111                    Next->dmPelsWidth < Current->dmPelsWidth ||
00112                    (Next->dmPelsWidth == Current->dmPelsWidth && Next->dmPelsHeight < Current->dmPelsHeight) ||
00113                    (Next->dmPelsHeight == Current->dmPelsHeight &&
00114                     Next->dmPelsWidth == Current->dmPelsWidth &&
00115                     Next->dmBitsPerPel < Current->dmBitsPerPel )))
00116             {
00117                 Previous = Next;
00118                 Next = Next->Flink;
00119             }
00120             Current->Blink = Previous;
00121             Current->Flink = Next;
00122             if (Previous == NULL)
00123                 Settings = Current;
00124             else
00125                 Previous->Flink = Current;
00126             if (Next != NULL)
00127                 Next->Blink = Current;
00128             if (devmode.dmPelsWidth == xres && devmode.dmPelsHeight == yres && devmode.dmBitsPerPel == bpp)
00129             {
00130                 *CurrentSettings = Current;
00131             }
00132             NbSettings++;
00133         }
00134         iMode++;
00135     }
00136 
00137     *pSettingsCount = NbSettings;
00138     return Settings;
00139 }
00140 
00141 static BOOL
00142 AddDisplayDevice(IN PDATA pData, IN const DISPLAY_DEVICE *DisplayDevice)
00143 {
00144     PDISPLAY_DEVICE_ENTRY newEntry = NULL;
00145     LPTSTR description = NULL;
00146     LPTSTR name = NULL;
00147     LPTSTR key = NULL;
00148     LPTSTR devid = NULL;
00149     DWORD descriptionSize, nameSize, keySize, devidSize;
00150     PSETTINGS_ENTRY Current;
00151     DWORD ResolutionsCount = 1;
00152     DWORD i;
00153 
00154     newEntry = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(DISPLAY_DEVICE_ENTRY));
00155     if (!newEntry) goto ByeBye;
00156 
00157     newEntry->Settings = GetPossibleSettings(DisplayDevice->DeviceName, &newEntry->SettingsCount, &newEntry->CurrentSettings);
00158     if (!newEntry->Settings) goto ByeBye;
00159 
00160     newEntry->InitialSettings.dmPelsWidth = newEntry->CurrentSettings->dmPelsWidth;
00161     newEntry->InitialSettings.dmPelsHeight = newEntry->CurrentSettings->dmPelsHeight;
00162     newEntry->InitialSettings.dmBitsPerPel = newEntry->CurrentSettings->dmBitsPerPel;
00163 
00164     /* Count different resolutions */
00165     for (Current = newEntry->Settings; Current != NULL; Current = Current->Flink)
00166     {
00167         if (Current->Flink != NULL &&
00168             ((Current->dmPelsWidth != Current->Flink->dmPelsWidth) &&
00169             (Current->dmPelsHeight != Current->Flink->dmPelsHeight)))
00170         {
00171             ResolutionsCount++;
00172         }
00173     }
00174 
00175     newEntry->Resolutions = HeapAlloc(GetProcessHeap(), 0, ResolutionsCount * sizeof(RESOLUTION_INFO));
00176     if (!newEntry->Resolutions) goto ByeBye;
00177 
00178     newEntry->ResolutionsCount = ResolutionsCount;
00179 
00180     /* Fill resolutions infos */
00181     for (Current = newEntry->Settings, i = 0; Current != NULL; Current = Current->Flink)
00182     {
00183         if (Current->Flink == NULL ||
00184             (Current->Flink != NULL &&
00185             ((Current->dmPelsWidth != Current->Flink->dmPelsWidth) &&
00186             (Current->dmPelsHeight != Current->Flink->dmPelsHeight))))
00187         {
00188             newEntry->Resolutions[i].dmPelsWidth = Current->dmPelsWidth;
00189             newEntry->Resolutions[i].dmPelsHeight = Current->dmPelsHeight;
00190             i++;
00191         }
00192     }
00193     descriptionSize = (_tcslen(DisplayDevice->DeviceString) + 1) * sizeof(TCHAR);
00194     description = HeapAlloc(GetProcessHeap(), 0, descriptionSize);
00195     if (!description) goto ByeBye;
00196 
00197     nameSize = (_tcslen(DisplayDevice->DeviceName) + 1) * sizeof(TCHAR);
00198     name = HeapAlloc(GetProcessHeap(), 0, nameSize);
00199     if (!name) goto ByeBye;
00200 
00201     keySize = (_tcslen(DisplayDevice->DeviceKey) + 1) * sizeof(TCHAR);
00202     key = HeapAlloc(GetProcessHeap(), 0, keySize);
00203     if (!key) goto ByeBye;
00204 
00205     devidSize = (_tcslen(DisplayDevice->DeviceID) + 1) * sizeof(TCHAR);
00206     devid = HeapAlloc(GetProcessHeap(), 0, devidSize);
00207     if (!devid) goto ByeBye;
00208 
00209     memcpy(description, DisplayDevice->DeviceString, descriptionSize);
00210     memcpy(name, DisplayDevice->DeviceName, nameSize);
00211     memcpy(key, DisplayDevice->DeviceKey, keySize);
00212     memcpy(devid, DisplayDevice->DeviceID, devidSize);
00213     newEntry->DeviceDescription = description;
00214     newEntry->DeviceName = name;
00215     newEntry->DeviceKey = key;
00216     newEntry->DeviceID = devid;
00217     newEntry->DeviceStateFlags = DisplayDevice->StateFlags;
00218     newEntry->Flink = pData->DisplayDeviceList;
00219     pData->DisplayDeviceList = newEntry;
00220     return TRUE;
00221 
00222 ByeBye:
00223     if (newEntry != NULL)
00224     {
00225         if (newEntry->Settings != NULL)
00226         {
00227             Current = newEntry->Settings;
00228             while (Current != NULL)
00229             {
00230                 PSETTINGS_ENTRY Next = Current->Flink;
00231                 HeapFree(GetProcessHeap(), 0, Current);
00232                 Current = Next;
00233             }
00234         }
00235         if (newEntry->Resolutions != NULL)
00236             HeapFree(GetProcessHeap(), 0, newEntry->Resolutions);
00237         HeapFree(GetProcessHeap(), 0, newEntry);
00238     }
00239     if (description != NULL)
00240         HeapFree(GetProcessHeap(), 0, description);
00241     if (name != NULL)
00242         HeapFree(GetProcessHeap(), 0, name);
00243     if (key != NULL)
00244         HeapFree(GetProcessHeap(), 0, key);
00245     return FALSE;
00246 }
00247 
00248 static VOID
00249 OnDisplayDeviceChanged(IN HWND hwndDlg, IN PDATA pData, IN PDISPLAY_DEVICE_ENTRY pDeviceEntry)
00250 {
00251     PSETTINGS_ENTRY Current;
00252     DWORD index;
00253 
00254     pData->CurrentDisplayDevice = pDeviceEntry; /* Update variable */
00255 
00256     /* Fill color depths combo box */
00257     SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_RESETCONTENT, 0, 0);
00258     for (Current = pDeviceEntry->Settings; Current != NULL; Current = Current->Flink)
00259     {
00260         TCHAR Buffer[64];
00261         if (LoadString(hApplet, (2900 + Current->dmBitsPerPel), Buffer, sizeof(Buffer) / sizeof(TCHAR)))
00262         {
00263             index = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)Buffer);
00264             if (index == (DWORD)CB_ERR)
00265             {
00266                 index = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_ADDSTRING, 0, (LPARAM)Buffer);
00267                 SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_SETITEMDATA, index, Current->dmBitsPerPel);
00268             }
00269         }
00270     }
00271 
00272     /* Fill resolutions slider */
00273     SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_CLEARTICS, TRUE, 0);
00274     SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_SETRANGE, TRUE, MAKELONG(0, pDeviceEntry->ResolutionsCount - 1));
00275 
00276     UpdateDisplay(hwndDlg, pData, TRUE);
00277 }
00278 
00279 static VOID
00280 OnInitDialog(IN HWND hwndDlg)
00281 {
00282     BITMAP bitmap;
00283     DWORD Result = 0;
00284     DWORD iDevNum = 0;
00285     DWORD i;
00286     DISPLAY_DEVICE displayDevice;
00287     PDATA pData;
00288 
00289     pData = HeapAlloc(GetProcessHeap(), 0, sizeof(DATA));
00290     if (pData == NULL)
00291         return;
00292 
00293     SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pData);
00294 
00295     /* Get video cards list */
00296     pData->DisplayDeviceList = NULL;
00297     displayDevice.cb = (DWORD)sizeof(DISPLAY_DEVICE);
00298     while (EnumDisplayDevices(NULL, iDevNum, &displayDevice, 0x1))
00299     {
00300         if ((displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) != 0)
00301         {
00302             if (AddDisplayDevice(pData, &displayDevice))
00303                 Result++;
00304         }
00305         iDevNum++;
00306     }
00307 
00308     if (Result == 0)
00309     {
00310         /* No adapter found */
00311         EnableWindow(GetDlgItem(hwndDlg, IDC_SETTINGS_BPP), FALSE);
00312         EnableWindow(GetDlgItem(hwndDlg, IDC_SETTINGS_RESOLUTION), FALSE);
00313         EnableWindow(GetDlgItem(hwndDlg, IDC_SETTINGS_RESOLUTION_TEXT), FALSE);
00314         EnableWindow(GetDlgItem(hwndDlg, IDC_SETTINGS_ADVANCED), FALSE);
00315         ShowWindow(GetDlgItem(hwndDlg, IDC_SETTINGS_SPECTRUM), SW_HIDE);
00316 
00317         /* Do not initialize the color spectrum bitmaps */
00318         memset(pData->hSpectrumBitmaps, 0, sizeof(pData->hSpectrumBitmaps));
00319         return;
00320     }
00321     else if (Result == 1)
00322     {
00323         MONSL_MONINFO monitors;
00324 
00325         /* Single video adapter */
00326         SendDlgItemMessage(hwndDlg, IDC_SETTINGS_DEVICE, WM_SETTEXT, 0, (LPARAM)pData->DisplayDeviceList->DeviceDescription);
00327         OnDisplayDeviceChanged(hwndDlg, pData, pData->DisplayDeviceList);
00328 
00329         monitors.Position.x = monitors.Position.y = 0;
00330         monitors.Size.cx = pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth;
00331         monitors.Size.cy = pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight;
00332         monitors.Flags = 0;
00333         SendDlgItemMessage(hwndDlg,
00334                    IDC_SETTINGS_MONSEL,
00335                    MSLM_SETMONITORSINFO,
00336                    1,
00337                    (LPARAM)&monitors);
00338     }
00339     else /* FIXME: Incomplete! */
00340     {
00341         PMONSL_MONINFO pMonitors;
00342         DWORD i;
00343 
00344         SendDlgItemMessage(hwndDlg, IDC_SETTINGS_DEVICE, WM_SETTEXT, 0, (LPARAM)pData->DisplayDeviceList->DeviceDescription);
00345         OnDisplayDeviceChanged(hwndDlg, pData, pData->DisplayDeviceList);
00346 
00347         pMonitors = (PMONSL_MONINFO)HeapAlloc(GetProcessHeap(), 0, sizeof(MONSL_MONINFO) * Result);
00348         if (pMonitors)
00349         {
00350             DWORD hack = 1280;
00351             for (i = 0; i < Result; i++)
00352             {
00353                 pMonitors[i].Position.x = hack * i;
00354                 pMonitors[i].Position.y = 0;
00355                 pMonitors[i].Size.cx = pData->DisplayDeviceList->CurrentSettings->dmPelsWidth;
00356                 pMonitors[i].Size.cy = pData->DisplayDeviceList->CurrentSettings->dmPelsHeight;
00357                 pMonitors[i].Flags = 0;
00358             }
00359 
00360             SendDlgItemMessage(hwndDlg,
00361                        IDC_SETTINGS_MONSEL,
00362                        MSLM_SETMONITORSINFO,
00363                        Result,
00364                        (LPARAM)pMonitors);
00365 
00366             HeapFree(GetProcessHeap(), 0, pMonitors);
00367         }
00368     }
00369 
00370     /* Initialize the color spectrum bitmaps */
00371     for(i = 0; i < NUM_SPECTRUM_BITMAPS; i++)
00372     {
00373         pData->hSpectrumBitmaps[i] = LoadImageW(hApplet, MAKEINTRESOURCEW(IDB_SPECTRUM_4 + i), IMAGE_BITMAP, 0, 0, LR_DEFAULTCOLOR);
00374 
00375         if (pData->hSpectrumBitmaps[i] != NULL)
00376         {
00377             if (GetObjectW(pData->hSpectrumBitmaps[i], sizeof(BITMAP), &bitmap) != 0)
00378             {
00379                 pData->cxSource[i] = bitmap.bmWidth;
00380                 pData->cySource[i] = bitmap.bmHeight;
00381             }
00382             else
00383             {
00384                 pData->cxSource[i] = 0;
00385                 pData->cySource[i] = 0;
00386             }
00387         }
00388     }
00389 }
00390 
00391 /* Get the ID for DATA::hSpectrumBitmaps */
00392 static VOID
00393 ShowColorSpectrum(IN HDC hDC, IN LPRECT client, IN DWORD BitsPerPel, IN PDATA pData)
00394 {
00395     HDC hdcMem;
00396     INT iBitmap;
00397 
00398     hdcMem = CreateCompatibleDC(hDC);
00399 
00400     if (!hdcMem)
00401         return;
00402 
00403     switch(BitsPerPel)
00404     {
00405         case 4:  iBitmap = 0; break;
00406         case 8:  iBitmap = 1; break;
00407         default: iBitmap = 2;
00408     }
00409 
00410     if (SelectObject(hdcMem, pData->hSpectrumBitmaps[iBitmap]))
00411     {
00412         StretchBlt(hDC,
00413                client->left, client->top,
00414                client->right - client->left,
00415                client->bottom - client->top,
00416                hdcMem, 0, 0,
00417                pData->cxSource[iBitmap],
00418                pData->cySource[iBitmap], SRCCOPY);
00419     }
00420 
00421     DeleteDC(hdcMem);
00422 }
00423 
00424 static VOID
00425 OnBPPChanged(IN HWND hwndDlg, IN PDATA pData)
00426 {
00427     /* If new BPP is not compatible with resolution:
00428      * 1) try to find the nearest smaller matching resolution
00429      * 2) otherwise, get the nearest bigger resolution
00430      */
00431     PSETTINGS_ENTRY Current;
00432     DWORD dmNewBitsPerPel;
00433     DWORD index;
00434     HDC hSpectrumDC;
00435     HWND hSpectrumControl;
00436     RECT client;
00437 
00438     index = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_GETCURSEL, 0, 0);
00439     dmNewBitsPerPel = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_BPP, CB_GETITEMDATA, index, 0);
00440 
00441     /* Show a new spectrum bitmap */
00442     hSpectrumControl = GetDlgItem(hwndDlg, IDC_SETTINGS_SPECTRUM);
00443     hSpectrumDC = GetDC(hSpectrumControl);
00444     GetClientRect(hSpectrumControl, &client);
00445     ShowColorSpectrum(hSpectrumDC, &client, dmNewBitsPerPel, pData);
00446 
00447     /* Find if new parameters are valid */
00448     Current = pData->CurrentDisplayDevice->CurrentSettings;
00449     if (dmNewBitsPerPel == Current->dmBitsPerPel)
00450     {
00451         /* No change */
00452         return;
00453     }
00454 
00455     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00456 
00457     if (dmNewBitsPerPel < Current->dmBitsPerPel)
00458     {
00459         Current = Current->Blink;
00460         while (Current != NULL)
00461         {
00462             if (Current->dmBitsPerPel == dmNewBitsPerPel
00463              && Current->dmPelsHeight == pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight
00464              && Current->dmPelsWidth == pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
00465             {
00466                 pData->CurrentDisplayDevice->CurrentSettings = Current;
00467                 UpdateDisplay(hwndDlg, pData, TRUE);
00468                 return;
00469             }
00470             Current = Current->Blink;
00471         }
00472     }
00473     else
00474     {
00475         Current = Current->Flink;
00476         while (Current != NULL)
00477         {
00478             if (Current->dmBitsPerPel == dmNewBitsPerPel
00479              && Current->dmPelsHeight == pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight
00480              && Current->dmPelsWidth == pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth)
00481             {
00482                 pData->CurrentDisplayDevice->CurrentSettings = Current;
00483                 UpdateDisplay(hwndDlg, pData, TRUE);
00484                 return;
00485             }
00486             Current = Current->Flink;
00487         }
00488     }
00489 
00490     /* Search smaller resolution compatible with current color depth */
00491     Current = pData->CurrentDisplayDevice->CurrentSettings->Blink;
00492     while (Current != NULL)
00493     {
00494         if (Current->dmBitsPerPel == dmNewBitsPerPel)
00495         {
00496             pData->CurrentDisplayDevice->CurrentSettings = Current;
00497             UpdateDisplay(hwndDlg, pData, TRUE);
00498             return;
00499         }
00500         Current = Current->Blink;
00501     }
00502 
00503     /* Search bigger resolution compatible with current color depth */
00504     Current = pData->CurrentDisplayDevice->CurrentSettings->Flink;
00505     while (Current != NULL)
00506     {
00507         if (Current->dmBitsPerPel == dmNewBitsPerPel)
00508         {
00509             pData->CurrentDisplayDevice->CurrentSettings = Current;
00510             UpdateDisplay(hwndDlg, pData, TRUE);
00511             return;
00512         }
00513         Current = Current->Flink;
00514     }
00515 
00516     /* We shouldn't go there */
00517 }
00518 
00519 static VOID
00520 OnResolutionChanged(IN HWND hwndDlg, IN PDATA pData, IN DWORD NewPosition,
00521                     IN BOOL bUpdateThumb)
00522 {
00523     /* If new resolution is not compatible with color depth:
00524      * 1) try to find the nearest bigger matching color depth
00525      * 2) otherwise, get the nearest smaller color depth
00526      */
00527     PSETTINGS_ENTRY Current;
00528     DWORD dmNewPelsHeight = pData->CurrentDisplayDevice->Resolutions[NewPosition].dmPelsHeight;
00529     DWORD dmNewPelsWidth = pData->CurrentDisplayDevice->Resolutions[NewPosition].dmPelsWidth;
00530 
00531     /* Find if new parameters are valid */
00532     Current = pData->CurrentDisplayDevice->CurrentSettings;
00533     if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth)
00534     {
00535         /* No change */
00536         return;
00537     }
00538 
00539     PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
00540 
00541     if (dmNewPelsHeight < Current->dmPelsHeight)
00542     {
00543         Current = Current->Blink;
00544         while (Current != NULL)
00545         {
00546             if (Current->dmPelsHeight == dmNewPelsHeight
00547              && Current->dmPelsWidth == dmNewPelsWidth
00548              && Current->dmBitsPerPel == pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
00549             {
00550                 pData->CurrentDisplayDevice->CurrentSettings = Current;
00551                 UpdateDisplay(hwndDlg, pData, bUpdateThumb);
00552                 return;
00553             }
00554             Current = Current->Blink;
00555         }
00556     }
00557     else
00558     {
00559         Current = Current->Flink;
00560         while (Current != NULL)
00561         {
00562             if (Current->dmPelsHeight == dmNewPelsHeight
00563              && Current->dmPelsWidth == dmNewPelsWidth
00564              && Current->dmBitsPerPel == pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel)
00565             {
00566                 pData->CurrentDisplayDevice->CurrentSettings = Current;
00567                 UpdateDisplay(hwndDlg, pData, bUpdateThumb);
00568                 return;
00569             }
00570             Current = Current->Flink;
00571         }
00572     }
00573 
00574     /* Search bigger color depth compatible with current resolution */
00575     Current = pData->CurrentDisplayDevice->CurrentSettings->Flink;
00576     while (Current != NULL)
00577     {
00578         if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth)
00579         {
00580             pData->CurrentDisplayDevice->CurrentSettings = Current;
00581             UpdateDisplay(hwndDlg, pData, bUpdateThumb);
00582             return;
00583         }
00584         Current = Current->Flink;
00585     }
00586 
00587     /* Search smaller color depth compatible with current resolution */
00588     Current = pData->CurrentDisplayDevice->CurrentSettings->Blink;
00589     while (Current != NULL)
00590     {
00591         if (dmNewPelsHeight == Current->dmPelsHeight && dmNewPelsWidth == Current->dmPelsWidth)
00592         {
00593             pData->CurrentDisplayDevice->CurrentSettings = Current;
00594             UpdateDisplay(hwndDlg, pData, bUpdateThumb);
00595             return;
00596         }
00597         Current = Current->Blink;
00598     }
00599 
00600     /* We shouldn't go there */
00601 }
00602 
00603 /* Property sheet page callback */
00604 UINT CALLBACK
00605 SettingsPageCallbackProc(HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
00606 {
00607     UINT Ret = 0;
00608 
00609     switch (uMsg)
00610     {
00611         case PSPCB_CREATE:
00612             Ret = RegisterMonitorSelectionControl(hApplet);
00613             break;
00614 
00615         case PSPCB_RELEASE:
00616             UnregisterMonitorSelectionControl(hApplet);
00617             break;
00618     }
00619 
00620     return Ret;
00621 }
00622 
00623 /* Property page dialog callback */
00624 INT_PTR CALLBACK
00625 SettingsPageProc(IN HWND hwndDlg, IN UINT uMsg, IN WPARAM wParam, IN LPARAM lParam)
00626 {
00627     PDATA pData;
00628     TCHAR Message[1024], Title[256];
00629 
00630     pData = (PDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
00631 
00632     switch(uMsg)
00633     {
00634         case WM_INITDIALOG:
00635         {
00636             OnInitDialog(hwndDlg);
00637             break;
00638         }
00639         case WM_DRAWITEM:
00640         {
00641             LPDRAWITEMSTRUCT lpDrawItem;
00642             lpDrawItem = (LPDRAWITEMSTRUCT) lParam;
00643 
00644             if (lpDrawItem->CtlID == IDC_SETTINGS_SPECTRUM)
00645                 ShowColorSpectrum(lpDrawItem->hDC, &lpDrawItem->rcItem, pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel, pData);
00646             break;
00647         }
00648         case WM_COMMAND:
00649         {
00650             DWORD controlId = LOWORD(wParam);
00651             DWORD command   = HIWORD(wParam);
00652 
00653             if (controlId == IDC_SETTINGS_ADVANCED && command == BN_CLICKED)
00654                 DisplayAdvancedSettings(hwndDlg, pData->CurrentDisplayDevice);
00655             else if (controlId == IDC_SETTINGS_BPP && command == CBN_SELCHANGE)
00656                 OnBPPChanged(hwndDlg, pData);
00657             break;
00658         }
00659         case WM_HSCROLL:
00660         {
00661             switch (LOWORD(wParam))
00662             {
00663                 case TB_LINEUP:
00664                 case TB_LINEDOWN:
00665                 case TB_PAGEUP:
00666                 case TB_PAGEDOWN:
00667                 case TB_TOP:
00668                 case TB_BOTTOM:
00669                 case TB_ENDTRACK:
00670                 {
00671                     DWORD newPosition = (DWORD) SendDlgItemMessage(hwndDlg, IDC_SETTINGS_RESOLUTION, TBM_GETPOS, 0, 0);
00672                     OnResolutionChanged(hwndDlg, pData, newPosition, TRUE);
00673                     break;
00674                 }
00675 
00676                 case TB_THUMBTRACK:
00677                     OnResolutionChanged(hwndDlg, pData, HIWORD(wParam), FALSE);
00678                     break;
00679             }
00680             break;
00681         }
00682         case WM_NOTIFY:
00683         {
00684             LPNMHDR lpnm = (LPNMHDR)lParam;
00685             if (lpnm->code == (UINT)PSN_APPLY)
00686             {
00687                 if (pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth != pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth
00688                  || pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight != pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight
00689                  || pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel != pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel)
00690                 {
00691                     /* FIXME: Need to test changes */
00692                     /* Apply new settings */
00693                     LONG rc;
00694                     DEVMODE devmode;
00695                     RtlZeroMemory(&devmode, sizeof(DEVMODE));
00696                     devmode.dmSize = (WORD)sizeof(DEVMODE);
00697                     devmode.dmPelsWidth = pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth;
00698                     devmode.dmPelsHeight = pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight;
00699                     devmode.dmBitsPerPel = pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel;
00700                     devmode.dmDisplayFrequency = pData->CurrentDisplayDevice->CurrentSettings->dmDisplayFrequency;
00701                     devmode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL | DM_DISPLAYFREQUENCY;
00702                     rc = ChangeDisplaySettingsEx(
00703                         pData->CurrentDisplayDevice->DeviceName,
00704                         &devmode,
00705                         NULL,
00706                         CDS_UPDATEREGISTRY,
00707                         NULL);
00708                     switch (rc)
00709                     {
00710                         case DISP_CHANGE_SUCCESSFUL:
00711                             pData->CurrentDisplayDevice->InitialSettings.dmPelsWidth = pData->CurrentDisplayDevice->CurrentSettings->dmPelsWidth;
00712                             pData->CurrentDisplayDevice->InitialSettings.dmPelsHeight = pData->CurrentDisplayDevice->CurrentSettings->dmPelsHeight;
00713                             pData->CurrentDisplayDevice->InitialSettings.dmBitsPerPel = pData->CurrentDisplayDevice->CurrentSettings->dmBitsPerPel;
00714                             break;
00715                         case DISP_CHANGE_RESTART:
00716                             LoadString(hApplet, IDS_DISPLAY_SETTINGS, Title, sizeof(Title) / sizeof(TCHAR));
00717                             LoadString(hApplet, IDS_APPLY_NEEDS_RESTART, Message, sizeof(Message) / sizeof (TCHAR));
00718                             MessageBox(hwndDlg, Message, Title, MB_OK | MB_ICONINFORMATION);
00719                             break;
00720                         case DISP_CHANGE_FAILED:
00721                         default:
00722                             LoadString(hApplet, IDS_DISPLAY_SETTINGS, Title, sizeof(Title) / sizeof(TCHAR));
00723                             LoadString(hApplet, IDS_APPLY_FAILED, Message, sizeof(Message) / sizeof (TCHAR));
00724                             MessageBox(hwndDlg, Message, Title, MB_OK | MB_ICONSTOP);
00725                             break;
00726                     }
00727                 }
00728             }
00729             break;
00730         }
00731 
00732         case WM_CONTEXTMENU:
00733         {
00734             HWND hwndMonSel;
00735             HMENU hPopup;
00736             UINT uiCmd;
00737             POINT pt, ptClient;
00738             INT Index;
00739 
00740             pt.x = (SHORT)LOWORD(lParam);
00741             pt.y = (SHORT)HIWORD(lParam);
00742 
00743             hwndMonSel = GetDlgItem(hwndDlg,
00744                                     IDC_SETTINGS_MONSEL);
00745             if ((HWND)wParam == hwndMonSel)
00746             {
00747                 if (pt.x == -1 && pt.y == -1)
00748                 {
00749                     RECT rcMon;
00750 
00751                     Index = (INT)SendMessage(hwndMonSel,
00752                                              MSLM_GETCURSEL,
00753                                              0,
00754                                              0);
00755 
00756                     if (Index >= 0 &&
00757                         (INT)SendMessage(hwndMonSel,
00758                                          MSLM_GETMONITORRECT,
00759                                          Index,
00760                                          (LPARAM)&rcMon) > 0)
00761                     {
00762                         pt.x = rcMon.left + ((rcMon.right - rcMon.left) / 2);
00763                         pt.y = rcMon.top + ((rcMon.bottom - rcMon.top) / 2);
00764                     }
00765                     else
00766                         pt.x = pt.y = 0;
00767 
00768                     MapWindowPoints(hwndMonSel,
00769                                     NULL,
00770                                     &pt,
00771                                     1);
00772                 }
00773                 else
00774                 {
00775                     ptClient = pt;
00776                     MapWindowPoints(NULL,
00777                                     hwndMonSel,
00778                                     &ptClient,
00779                                     1);
00780 
00781                     Index = (INT)SendMessage(hwndMonSel,
00782                                              MSLM_HITTEST,
00783                                              (WPARAM)&ptClient,
00784                                              0);
00785                 }
00786 
00787                 if (Index >= 0)
00788                 {
00789                     hPopup = LoadPopupMenu(hApplet,
00790                                            MAKEINTRESOURCE(IDM_MONITOR_MENU));
00791                     if (hPopup != NULL)
00792                     {
00793                         /* FIXME: Enable/Disable menu items */
00794                         EnableMenuItem(hPopup,
00795                                        ID_MENU_ATTACHED,
00796                                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
00797                         EnableMenuItem(hPopup,
00798                                        ID_MENU_PRIMARY,
00799                                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
00800                         EnableMenuItem(hPopup,
00801                                        ID_MENU_IDENTIFY,
00802                                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
00803                         EnableMenuItem(hPopup,
00804                                        ID_MENU_PROPERTIES,
00805                                        MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
00806 
00807                         uiCmd = (UINT)TrackPopupMenu(hPopup,
00808                                                      TPM_RETURNCMD | TPM_RIGHTBUTTON,
00809                                                      pt.x,
00810                                                      pt.y,
00811                                                      0,
00812                                                      hwndDlg,
00813                                                      NULL);
00814 
00815                         switch (uiCmd)
00816                         {
00817                             case ID_MENU_ATTACHED:
00818                             case ID_MENU_PRIMARY:
00819                             case ID_MENU_IDENTIFY:
00820                             case ID_MENU_PROPERTIES:
00821                                 /* FIXME: Implement */
00822                                 break;
00823                         }
00824 
00825                         DestroyMenu(hPopup);
00826                     }
00827                 }
00828             }
00829             break;
00830         }
00831 
00832         case WM_DESTROY:
00833         {
00834             DWORD i;
00835             PDISPLAY_DEVICE_ENTRY Current = pData->DisplayDeviceList;
00836 
00837             while (Current != NULL)
00838             {
00839                 PDISPLAY_DEVICE_ENTRY Next = Current->Flink;
00840                 PSETTINGS_ENTRY CurrentSettings = Current->Settings;
00841                 while (CurrentSettings != NULL)
00842                 {
00843                     PSETTINGS_ENTRY NextSettings = CurrentSettings->Flink;
00844                     HeapFree(GetProcessHeap(), 0, CurrentSettings);
00845                     CurrentSettings = NextSettings;
00846                 }
00847                 HeapFree(GetProcessHeap(), 0, Current);
00848                 Current = Next;
00849             }
00850 
00851             for (i = 0; i < NUM_SPECTRUM_BITMAPS; i++)
00852             {
00853                 if (pData->hSpectrumBitmaps[i])
00854                     DeleteObject(pData->hSpectrumBitmaps[i]);
00855             }
00856 
00857             HeapFree(GetProcessHeap(), 0, pData);
00858         }
00859     }
00860     return FALSE;
00861 }

Generated on Sun May 27 2012 04:16:30 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.