[OSK] General refactoring
authorBișoc George <fraizeraust99@gmail.com>
Tue, 16 Jul 2019 15:35:30 +0000 (17:35 +0200)
committerMark Jansen <mark.jansen@reactos.org>
Thu, 15 Aug 2019 18:35:17 +0000 (20:35 +0200)
- Replace the existing header files in favour to a pre-compiled header instead. Furthermore, move all the function prototypes in the pre-compiled header.
- As per the prototype definitions, LoadDataFromRegistry() and SaveDataToRegistry() mustn't accept any number of parameters.
- Rename rsrc.rc to osk.rc (main resource file) as most of user-mode applications name have their main resource as the same application's name anyways.
- When querying and saving the data to registry, use only one value, greatly reducing the bloat of variables (as per the Hermes Belusca's request on #1729 PR).
- Update the header description reflecting the official ReactOS Coding style guidelines.

base/applications/osk/CMakeLists.txt
base/applications/osk/main.c
base/applications/osk/main.h [deleted file]
base/applications/osk/osk.h [deleted file]
base/applications/osk/osk.rc [moved from base/applications/osk/rsrc.rc with 87% similarity]
base/applications/osk/osk_res.h
base/applications/osk/precomp.h [new file with mode: 0644]
base/applications/osk/settings.c
base/applications/osk/settings.h [deleted file]

index ff58760..293eba1 100644 (file)
@@ -1,7 +1,13 @@
 
+list(APPEND SOURCE
+    main.c
+    settings.c
+    precomp.h)
+
 file(GLOB osk_rc_deps res/*.*)
-add_rc_deps(rsrc.rc ${osk_rc_deps})
-add_executable(osk main.c settings.c rsrc.rc)
+add_rc_deps(osk.rc ${osk_rc_deps})
+add_executable(osk ${SOURCE} osk.rc)
 set_module_type(osk win32gui UNICODE)
 add_importlibs(osk comdlg32 uxtheme winmm shell32 user32 gdi32 advapi32 comctl32 msvcrt kernel32 ntdll)
+add_pch(osk precomp.h SOURCE)
 add_cd_file(TARGET osk DESTINATION reactos/system32 FOR all)
index 0a3a001..a467eb2 100644 (file)
@@ -8,26 +8,12 @@
 
 /* INCLUDES *******************************************************************/
 
-#include "osk.h"
-#include "settings.h"
+#include "precomp.h"
 
 /* GLOBALS ********************************************************************/
 
 OSK_GLOBALS Globals;
 
-/* Functions */
-int OSK_SetImage(int IdDlgItem, int IdResource);
-int OSK_DlgInitDialog(HWND hDlg);
-int OSK_DlgClose(void);
-int OSK_DlgTimer(void);
-BOOL OSK_DlgCommand(WPARAM wCommand, HWND hWndControl);
-BOOL OSK_ReleaseKey(WORD ScanCode);
-VOID OSK_RestoreDlgPlacement(HWND hDlg);
-
-INT_PTR APIENTRY OSK_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
-LRESULT APIENTRY OSK_ThemeHandler(HWND hDlg, NMCUSTOMDRAW *pNmDraw);
-int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
-
 /* FUNCTIONS ******************************************************************/
 
 /***********************************************************************
diff --git a/base/applications/osk/main.h b/base/applications/osk/main.h
deleted file mode 100644 (file)
index 5ce6a7a..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * PROJECT:         ReactOS On-Screen Keyboard
- * LICENSE:         GPL - See COPYING in the top level directory
- * PURPOSE:         On screen keyboard.
- * COPYRIGHT:       Denis ROBERT
- *                  Copyright 2019 Bișoc George (fraizeraust99 at gmail dot com)
- */
-
-#ifndef _OSKMAIN_H
-#define _OSKMAIN_H
-
-/* INCLUDES *******************************************************************/
-
-#include "osk_res.h"
-
-/* TYPES **********************************************************************/
-
-typedef struct
-{
-    HINSTANCE  hInstance;
-    HWND       hMainWnd;
-    HBRUSH     hBrushGreenLed;
-    UINT_PTR   iTimer;
-    /* FIXME: To be deleted when ReactOS will support WS_EX_NOACTIVATE */
-    HWND       hActiveWnd;
-    BOOL       bShowWarning;
-    BOOL       bIsEnhancedKeyboard;
-    BOOL       bSoundClick;
-    BOOL       bAlwaysOnTop;
-    INT        PosX;
-    INT        PosY;
-} OSK_GLOBALS;
-
-/* DEFINES ********************************************************************/
-
-extern OSK_GLOBALS Globals;
-
-#define countof(x) (sizeof(x) / sizeof((x)[0]))
-#define MAX_BUFF 256
-
-#endif
-
-/* EOF */
diff --git a/base/applications/osk/osk.h b/base/applications/osk/osk.h
deleted file mode 100644 (file)
index a435e69..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * PROJECT:         ReactOS On-Screen Keyboard
- * LICENSE:         GPL - See COPYING in the top level directory
- * PURPOSE:         On screen keyboard.
- * COPYRIGHT:       Denis ROBERT
- *                  Copyright 2019 Bișoc George (fraizeraust99 at gmail dot com)
- */
-
-#ifndef _OSK_H
-#define _OSK_H
-
-/* INCLUDES ******************************************************************/
-
-#include <stdio.h>
-
-#include <windows.h>
-#include <commctrl.h>
-#include <debug.h>
-#include <uxtheme.h>
-#include <vsstyle.h>
-
-#include "main.h"
-
-#endif
-
-/* EOF */
similarity index 87%
rename from base/applications/osk/rsrc.rc
rename to base/applications/osk/osk.rc
index 9635817..a897be3 100644 (file)
@@ -1,19 +1,12 @@
 /*
- * PROJECT:         ReactOS Kernel
+ * PROJECT:         On-Screen Keyboard
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            base/applications/osk/rsrc.rc
- * PURPOSE:         On Screen Keyboard
- * PROGRAMMERS:     Denis ROBERT
+ * PURPOSE:         On-Screen Keyboard main resource file
+ * COPYRIGHT:       Denis ROBERT
  */
 
 /* INCLUDES ******************************************************************/
-#include "windef.h"
-#include "winbase.h"
-#include "winuser.h"
-#include "main.h"
-#include "winnls.h"
-#include "commctrl.h"
-#include "osk_res.h"
+#include "precomp.h"
 
 #define REACTOS_STR_FILE_DESCRIPTION  "ReactOS On Screen Keyboard"
 #define REACTOS_STR_INTERNAL_NAME     "osk"
index 04dd6e2..21d01f3 100644 (file)
@@ -1,9 +1,8 @@
 /*
  * PROJECT:         ReactOS On-Screen Keyboard
  * LICENSE:         GPL - See COPYING in the top level directory
- * FILE:            base/applications/osk/osk_res.h
- * PURPOSE:         On screen keyboard.
- * PROGRAMMERS:     Denis ROBERT
+ * PURPOSE:         On-Screen Keyboard resource identifiers
+ * COPYRIGHT:       Denis ROBERT
  */
 
 #define MAIN_DIALOG_ENHANCED_KB             2000
diff --git a/base/applications/osk/precomp.h b/base/applications/osk/precomp.h
new file mode 100644 (file)
index 0000000..c1e7e50
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * PROJECT:         ReactOS On-Screen Keyboard
+ * LICENSE:         GPL - See COPYING in the top level directory
+ * PURPOSE:         Pre-compiled header
+ * COPYRIGHT:       Denis ROBERT
+ *                  Copyright 2019 Bișoc George (fraizeraust99 at gmail dot com)
+ */
+
+#ifndef _OSK_PRECOMP_H
+#define _OSK_PRECOMP_H
+
+/* INCLUDES *******************************************************************/
+
+#include <stdio.h>
+
+#include <windows.h>
+#include <commctrl.h>
+#include <debug.h>
+#include <uxtheme.h>
+#include <vsstyle.h>
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "winnls.h"
+#include "commctrl.h"
+
+#include "osk_res.h"
+
+/* TYPES **********************************************************************/
+
+typedef struct
+{
+    HINSTANCE  hInstance;
+    HWND       hMainWnd;
+    HBRUSH     hBrushGreenLed;
+    UINT_PTR   iTimer;
+    /* FIXME: To be deleted when ReactOS will support WS_EX_NOACTIVATE */
+    HWND       hActiveWnd;
+
+    /* On-Screen Keyboard registry settings */
+    BOOL       bShowWarning;
+    BOOL       bIsEnhancedKeyboard;
+    BOOL       bSoundClick;
+    BOOL       bAlwaysOnTop;
+    INT        PosX;
+    INT        PosY;
+} OSK_GLOBALS;
+
+/* PROTOTYPES *****************************************************************/
+
+/* main.c */
+int OSK_SetImage(int IdDlgItem, int IdResource);
+int OSK_DlgInitDialog(HWND hDlg);
+int OSK_DlgClose(void);
+int OSK_DlgTimer(void);
+BOOL OSK_DlgCommand(WPARAM wCommand, HWND hWndControl);
+BOOL OSK_ReleaseKey(WORD ScanCode);
+INT_PTR APIENTRY OSK_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
+LRESULT APIENTRY OSK_ThemeHandler(HWND hDlg, NMCUSTOMDRAW *pNmDraw);
+int WINAPI wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int);
+VOID OSK_RestoreDlgPlacement(HWND hDlg);
+
+/* settings.c */
+BOOL LoadDataFromRegistry(VOID);
+BOOL SaveDataToRegistry(VOID);
+INT_PTR CALLBACK OSK_WarningProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
+
+/* DEFINES ********************************************************************/
+
+extern OSK_GLOBALS Globals;
+
+#define countof(x) (sizeof(x) / sizeof((x)[0]))
+#define MAX_BUFF 256
+
+#endif /* _OSK_PRECOMP_H */
+
+/* EOF */
index 5d403e8..b1bcb21 100644 (file)
@@ -7,16 +7,15 @@
 
 /* INCLUDES *******************************************************************/
 
-#include "osk.h"
-#include "settings.h"
+#include "precomp.h"
 
 /* FUNCTIONS *******************************************************************/
 
-BOOL LoadDataFromRegistry()
+BOOL LoadDataFromRegistry(VOID)
 {
     HKEY hKey;
     LONG lResult;
-    DWORD dwShowWarningData, dwLayout, dwSoundOnClick, dwPositionLeft, dwPositionTop, dwAlwaysOnTop;
+    DWORD dwValue;
     DWORD cbData = sizeof(DWORD);
 
     /* Initialize the registry application settings */
@@ -47,7 +46,7 @@ BOOL LoadDataFromRegistry()
                                L"ShowWarning",
                                0,
                                0,
-                               (BYTE *)&dwShowWarningData,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -58,14 +57,14 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the data value (it can be either FALSE or TRUE depending on the data itself) */
-    Globals.bShowWarning = (dwShowWarningData != 0);
+    Globals.bShowWarning = (dwValue != 0);
 
     /* Query the key */
     lResult = RegQueryValueExW(hKey,
                                L"IsEnhancedKeyboard",
                                0,
                                0,
-                               (BYTE *)&dwLayout,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -76,14 +75,14 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the dialog layout value */
-    Globals.bIsEnhancedKeyboard = (dwLayout != 0);
+    Globals.bIsEnhancedKeyboard = (dwValue != 0);
 
     /* Query the key */
     lResult = RegQueryValueExW(hKey,
                                L"ClickSound",
                                0,
                                0,
-                               (BYTE *)&dwSoundOnClick,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -94,14 +93,14 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the sound on click value event */
-    Globals.bSoundClick = (dwSoundOnClick != 0);
+    Globals.bSoundClick = (dwValue != 0);
 
     /* Query the key */
     lResult = RegQueryValueExW(hKey,
                                L"WindowLeft",
                                0,
                                0,
-                               (BYTE *)&dwPositionLeft,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -112,13 +111,13 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the X value data of the dialog's coordinate */
-    Globals.PosX = dwPositionLeft;
+    Globals.PosX = dwValue;
 
     lResult = RegQueryValueExW(hKey,
                                L"WindowTop",
                                0,
                                0,
-                               (BYTE *)&dwPositionTop,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -129,13 +128,13 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the Y value data of the dialog's coordinate */
-    Globals.PosY = dwPositionTop;
+    Globals.PosY = dwValue;
 
     lResult = RegQueryValueExW(hKey,
                                L"AlwaysOnTop",
                                0,
                                0,
-                               (BYTE *)&dwAlwaysOnTop,
+                               (BYTE *)&dwValue,
                                &cbData);
 
     if (lResult != ERROR_SUCCESS)
@@ -146,18 +145,18 @@ BOOL LoadDataFromRegistry()
     }
 
     /* Load the window state value data */
-    Globals.bAlwaysOnTop = (dwAlwaysOnTop != 0);
+    Globals.bAlwaysOnTop = (dwValue != 0);
     
     /* If we're here then we succeed, close the key and return TRUE */
     RegCloseKey(hKey);
     return TRUE;
 }
 
-BOOL SaveDataToRegistry()
+BOOL SaveDataToRegistry(VOID)
 {
     HKEY hKey;
     LONG lResult;
-    DWORD dwShowWarningData, dwLayout, dwSoundOnClick, dwPositionLeft, dwPositionTop, dwAlwaysOnTop;
+    DWORD dwValue;
     WINDOWPLACEMENT wp;
 
     /* Set the structure length and retrieve the dialog's placement */
@@ -182,15 +181,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* The data value of the subkey will be appended to the warning dialog switch */
-    dwShowWarningData = Globals.bShowWarning;
+    dwValue = Globals.bShowWarning;
 
     /* Welcome warning box value key */
     lResult = RegSetValueExW(hKey,
                              L"ShowWarning",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwShowWarningData,
-                             sizeof(dwShowWarningData));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
@@ -200,15 +199,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* The value will be appended to the layout dialog */
-    dwLayout = Globals.bIsEnhancedKeyboard;
+    dwValue = Globals.bIsEnhancedKeyboard;
 
     /* Keyboard dialog switcher */
     lResult = RegSetValueExW(hKey,
                              L"IsEnhancedKeyboard",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwLayout,
-                             sizeof(dwLayout));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
@@ -218,15 +217,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* The value will be appended to the sound on click event */
-    dwSoundOnClick = Globals.bSoundClick;
+    dwValue = Globals.bSoundClick;
 
     /* "Sound on Click" switcher value key */
     lResult = RegSetValueExW(hKey,
                              L"ClickSound",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwSoundOnClick,
-                             sizeof(dwSoundOnClick));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
@@ -236,15 +235,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* The value will be appended to the X coordination dialog's placement */
-    dwPositionLeft = wp.rcNormalPosition.left;
+    dwValue = wp.rcNormalPosition.left;
 
     /* Position X coordination of dialog's placement value key */
     lResult = RegSetValueExW(hKey,
                              L"WindowLeft",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwPositionLeft,
-                             sizeof(dwPositionLeft));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
@@ -254,15 +253,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* The value will be appended to the Y coordination dialog's placement */
-    dwPositionTop = wp.rcNormalPosition.top;
+    dwValue = wp.rcNormalPosition.top;
 
     /* Position Y coordination of dialog's placement value key */
     lResult = RegSetValueExW(hKey,
                              L"WindowTop",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwPositionTop,
-                             sizeof(dwPositionTop));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
@@ -272,15 +271,15 @@ BOOL SaveDataToRegistry()
     }
 
     /* Window top state value */
-    dwAlwaysOnTop = Globals.bAlwaysOnTop;
+    dwValue = Globals.bAlwaysOnTop;
 
     /* "Always on Top" state value key */
     lResult = RegSetValueExW(hKey,
                              L"AlwaysOnTop",
                              0,
                              REG_DWORD,
-                             (BYTE *)&dwAlwaysOnTop,
-                             sizeof(dwAlwaysOnTop));
+                             (BYTE *)&dwValue,
+                             sizeof(dwValue));
 
     if (lResult != ERROR_SUCCESS)
     {
diff --git a/base/applications/osk/settings.h b/base/applications/osk/settings.h
deleted file mode 100644 (file)
index 05e122a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * PROJECT:         ReactOS On-Screen Keyboard
- * LICENSE:         GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
- * PURPOSE:         Settings header file with function prototypes
- * COPYRIGHT:       Copyright 2018 Bișoc George (fraizeraust99 at gmail dot com)
- */
-
-#ifndef SETTINGS_OSK_H
-#define SETTINGS_OSK_H
-
-BOOL LoadDataFromRegistry(VOID);
-BOOL SaveDataToRegistry(VOID);
-INT_PTR CALLBACK OSK_WarningProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
-
-#endif // SETTINGS_OSK_H