- Add Copy & Paste functions for whole characters
authorColin Finck <colin@reactos.org>
Mon, 25 Feb 2008 18:01:06 +0000 (18:01 +0000)
committerColin Finck <colin@reactos.org>
Mon, 25 Feb 2008 18:01:06 +0000 (18:01 +0000)
- Add an "Edit" menu now that we have some more menu items belonging to this category

svn path=/trunk/; revision=32482

13 files changed:
rosapps/devutils/vgafontedit/fontwnd.c
rosapps/devutils/vgafontedit/lang/bg-BG.rc
rosapps/devutils/vgafontedit/lang/de-DE.rc
rosapps/devutils/vgafontedit/lang/en-US.rc
rosapps/devutils/vgafontedit/lang/fr-FR.rc
rosapps/devutils/vgafontedit/lang/pl-PL.rc
rosapps/devutils/vgafontedit/lang/ru-RU.rc
rosapps/devutils/vgafontedit/lang/uk-UA.rc
rosapps/devutils/vgafontedit/main.c
rosapps/devutils/vgafontedit/main.rc
rosapps/devutils/vgafontedit/mainwnd.c
rosapps/devutils/vgafontedit/precomp.h
rosapps/devutils/vgafontedit/resource.h

index 87cd309..c665a72 100644 (file)
@@ -108,6 +108,7 @@ FontWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
             case WM_CHILDACTIVATE:
                 Info->MainWndInfo->CurrentFontWnd = Info;
                 SetToolbarFileButtonState(Info->MainWndInfo, TRUE);
+                SetPasteButtonState(Info->MainWndInfo);
                 break;
 
             case WM_CREATE:
@@ -165,6 +166,7 @@ FontWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                 // Otherwise CurrentFontWnd will stay NULL, so the main window knows that no more childs are opened.
                 Info->MainWndInfo->CurrentFontWnd = NULL;
                 SetToolbarFileButtonState(Info->MainWndInfo, FALSE);
+                SetPasteButtonState(Info->MainWndInfo);
 
                 if(uMsg == WM_USER_APPCLOSE)
                 {
index cbb1560..ba92587 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Èçõîä êàòî\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "&Ïðîçîðåö"
     BEGIN
         MENUITEM "&Íàäèïëÿíå", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Îòâàðÿíå"
     IDS_TOOLTIP_SAVE, "Çàïèñ"
     IDS_TOOLTIP_EDIT_GLYPH, "Îáðàáîòêà íà çíàê"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index c52619f..83ae6b1 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Beenden\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Bearbeiten"
+    BEGIN
+        MENUITEM "Kopieren\tStrg+C", ID_EDIT_COPY
+        MENUITEM "Einfügen\tStrg+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Schriftzeichen bearbeiten...", ID_EDIT_GLYPH
+    END
+
     POPUP "&Fenster"
     BEGIN
         MENUITEM "&Überlappend", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Öffnen"
     IDS_TOOLTIP_SAVE, "Speichern"
     IDS_TOOLTIP_EDIT_GLYPH, "Schriftzeichen bearbeiten"
+    IDS_TOOLTIP_COPY, "Kopieren"
+    IDS_TOOLTIP_PASTE, "Einfügen"
 END
index 804ee7d..4fd7057 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Exit\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "&Window"
     BEGIN
         MENUITEM "&Cascade", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Open"
     IDS_TOOLTIP_SAVE, "Save"
     IDS_TOOLTIP_EDIT_GLYPH, "Edit Glyph"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index 34bd46e..759bb70 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Quitter\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "Fenêtres"
     BEGIN
         MENUITEM "En &cascade", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Ouvrir"
     IDS_TOOLTIP_SAVE, "Enregistrer"
     IDS_TOOLTIP_EDIT_GLYPH, "Éditer le glyphe"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index 50b8276..ad64371 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Wyjd\9f\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "&Okna"
     BEGIN
         MENUITEM "&Kaskadowo", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Otwórz"
     IDS_TOOLTIP_SAVE, "Zapisz"
     IDS_TOOLTIP_EDIT_GLYPH, "Edytuj Glify"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index 41ab53f..510b59d 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Âûõîä\tAlt+F4",       ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "&Îêíà"
     BEGIN
         MENUITEM "&Êàñêàäîì",           ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "Îòêðûòü"
     IDS_TOOLTIP_SAVE, "Ñîõðàíèòü"
     IDS_TOOLTIP_EDIT_GLYPH, "Ðåäàêòèðîâàòü ñèìâîë"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index 1743641..32ed65d 100644 (file)
@@ -47,6 +47,14 @@ BEGIN
         MENUITEM "Â&èõ³ä\tAlt+F4", ID_FILE_EXIT
     END
 
+    POPUP "&Edit"
+    BEGIN
+        MENUITEM "Copy\tCtrl+C", ID_EDIT_COPY
+        MENUITEM "Paste\tCtrl+V", ID_EDIT_PASTE
+        MENUITEM SEPARATOR
+        MENUITEM "Edit Glyph...", ID_EDIT_GLYPH
+    END
+
     POPUP "&³êíî"
     BEGIN
         MENUITEM "&Êàñêàäîì", ID_WINDOW_CASCADE
@@ -81,4 +89,6 @@ BEGIN
     IDS_TOOLTIP_OPEN, "³äêðèòè"
     IDS_TOOLTIP_SAVE, "Çáåðåãòè"
     IDS_TOOLTIP_EDIT_GLYPH, "Ðåäàãóâàòè ñèìâîë"
+    IDS_TOOLTIP_COPY, "Copy"
+    IDS_TOOLTIP_PASTE, "Paste"
 END
index 690776f..742cfc4 100644 (file)
@@ -8,9 +8,12 @@
 
 #include "precomp.h"
 
+static const WCHAR szCharacterClipboardFormat[] = L"RosVgaFontChar";
+
 HINSTANCE hInstance;
 HANDLE hProcessHeap;
 PWSTR szAppName;
+UINT uCharacterClipboardFormat;
 
 INT WINAPI
 wWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow)
@@ -30,6 +33,10 @@ wWinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdSho
 
     hAccel = LoadAcceleratorsW( hInstance, MAKEINTRESOURCEW(IDA_MAINACCELERATORS) );
 
+    uCharacterClipboardFormat = RegisterClipboardFormatW(szCharacterClipboardFormat);
+    if(!uCharacterClipboardFormat)
+        return 1;
+
     if( InitMainWndClass() && InitFontWndClass() && InitFontBoxesWndClass() && InitEditGlyphWndClasses() )
     {
         if( CreateMainWindow(nCmdShow, &Info) )
index 90c165a..6d18af0 100644 (file)
@@ -21,6 +21,8 @@ BEGIN
     "N", ID_FILE_NEW, VIRTKEY, CONTROL
     "O", ID_FILE_OPEN, VIRTKEY, CONTROL
     "S", ID_FILE_SAVE, VIRTKEY, CONTROL
+    "C", ID_EDIT_COPY, VIRTKEY, CONTROL
+    "V", ID_EDIT_PASTE, VIRTKEY, CONTROL
 END
 
 IDB_MAIN_TOOLBAR          BITMAP    "res/toolbar.bmp"
index 2c50fb5..cda37ec 100644 (file)
@@ -88,6 +88,7 @@ SetToolbarFileButtonState(IN PMAIN_WND_INFO Info, BOOL bEnabled)
 {
     SetToolbarButtonState(Info, ID_FILE_SAVE, bEnabled);
     SetToolbarButtonState(Info, ID_EDIT_GLYPH, bEnabled);
+    SetToolbarButtonState(Info, ID_EDIT_COPY, bEnabled);
 }
 
 static VOID
@@ -143,11 +144,15 @@ InitMainWnd(IN PMAIN_WND_INFO Info)
     AddToolbarButton(Info, iStandardBitmaps + STD_FILESAVE, ID_FILE_SAVE, IDS_TOOLTIP_SAVE);
     AddToolbarSeparator(Info);
     AddToolbarButton(Info, iCustomBitmaps + TOOLBAR_EDIT_GLYPH, ID_EDIT_GLYPH, IDS_TOOLTIP_EDIT_GLYPH);
+    AddToolbarSeparator(Info);
+    AddToolbarButton(Info, iStandardBitmaps + STD_COPY, ID_EDIT_COPY, IDS_TOOLTIP_COPY);
+    AddToolbarButton(Info, iStandardBitmaps + STD_PASTE, ID_EDIT_PASTE, IDS_TOOLTIP_PASTE);
 
     SetToolbarFileButtonState(Info, FALSE);
+    SetPasteButtonState(Info);
 
     // Add the MDI client area
-    ccs.hWindowMenu = GetSubMenu(Info->hMenu, 1);
+    ccs.hWindowMenu = GetSubMenu(Info->hMenu, 2);
     ccs.idFirstChild = ID_MDI_FIRSTCHILD;
 
     Info->hMdiClient = CreateWindowExW(WS_EX_CLIENTEDGE,
@@ -172,11 +177,17 @@ InitMenuPopup(IN PMAIN_WND_INFO Info)
 {
     UINT uState;
 
-    uState = MF_BYCOMMAND | (Info->CurrentFontWnd == NULL);
+    uState = MF_BYCOMMAND | !(Info->CurrentFontWnd);
 
     EnableMenuItem(Info->hMenu, ID_FILE_CLOSE, uState);
     EnableMenuItem(Info->hMenu, ID_FILE_SAVE, uState);
     EnableMenuItem(Info->hMenu, ID_FILE_SAVE_AS, uState);
+
+    EnableMenuItem(Info->hMenu, ID_EDIT_COPY, uState);
+    EnableMenuItem(Info->hMenu, ID_EDIT_GLYPH, uState);
+
+    uState = MF_BYCOMMAND | !(Info->CurrentFontWnd && IsClipboardFormatAvailable(uCharacterClipboardFormat));
+    EnableMenuItem(Info->hMenu, ID_EDIT_PASTE, uState);
 }
 
 static VOID
@@ -248,6 +259,72 @@ DoFileSave(IN PMAIN_WND_INFO Info, IN BOOL bSaveAs)
     CloseHandle(hFile);
 }
 
+static VOID
+CopyCurrentGlyph(IN PFONT_WND_INFO FontWndInfo)
+{
+    HGLOBAL hMem;
+    PUCHAR pCharacterBits;
+
+    if(!OpenClipboard(NULL))
+        return;
+
+    EmptyClipboard();
+
+    hMem = GlobalAlloc(GMEM_MOVEABLE, 8);
+    pCharacterBits = GlobalLock(hMem);
+    RtlCopyMemory(pCharacterBits, FontWndInfo->Font->Bits + FontWndInfo->uSelectedCharacter * 8, 8);
+    GlobalUnlock(hMem);
+
+    SetClipboardData(uCharacterClipboardFormat, hMem);
+
+    CloseClipboard();
+}
+
+static VOID
+PasteIntoCurrentGlyph(IN PFONT_WND_INFO FontWndInfo)
+{
+    HGLOBAL hMem;
+
+    if(!IsClipboardFormatAvailable(uCharacterClipboardFormat))
+        return;
+
+    if(!OpenClipboard(NULL))
+        return;
+
+    hMem = GetClipboardData(uCharacterClipboardFormat);
+    if(hMem)
+    {
+        PUCHAR pCharacterBits;
+
+        pCharacterBits = GlobalLock(hMem);
+        if(pCharacterBits)
+        {
+            RECT CharacterRect;
+            UINT uFontRow;
+            UINT uFontColumn;
+
+            RtlCopyMemory(FontWndInfo->Font->Bits + FontWndInfo->uSelectedCharacter * 8, pCharacterBits, 8);
+            GlobalUnlock(hMem);
+
+            FontWndInfo->OpenInfo->bModified = TRUE;
+
+            GetCharacterPosition(FontWndInfo->uSelectedCharacter, &uFontRow, &uFontColumn);
+            GetCharacterRect(uFontRow, uFontColumn, &CharacterRect);
+            InvalidateRect(FontWndInfo->hFontBoxesWnd, &CharacterRect, FALSE);
+        }
+    }
+
+    CloseClipboard();
+}
+
+VOID
+SetPasteButtonState(IN PMAIN_WND_INFO Info)
+{
+    SetToolbarButtonState(Info,
+                          ID_EDIT_PASTE,
+                          (Info->CurrentFontWnd && IsClipboardFormatAvailable(uCharacterClipboardFormat)));
+}
+
 static BOOL
 MenuCommand(IN INT nMenuItemID, IN PMAIN_WND_INFO Info)
 {
@@ -278,11 +355,19 @@ MenuCommand(IN INT nMenuItemID, IN PMAIN_WND_INFO Info)
             PostMessage(Info->hMainWnd, WM_CLOSE, 0, 0);
             return TRUE;
 
-        // "Edit Glyph" toolbar button
+        // Edit Menu
         case ID_EDIT_GLYPH:
             EditCurrentGlyph(Info->CurrentFontWnd);
             return TRUE;
 
+        case ID_EDIT_COPY:
+            CopyCurrentGlyph(Info->CurrentFontWnd);
+            return TRUE;
+
+        case ID_EDIT_PASTE:
+            PasteIntoCurrentGlyph(Info->CurrentFontWnd);
+            return TRUE;
+
         // Window Menu
         case ID_WINDOW_TILE_HORZ:
             SendMessageW(Info->hMdiClient, WM_MDITILE, MDITILE_HORIZONTAL, 0);
@@ -349,6 +434,8 @@ MainWndSize(PMAIN_WND_INFO Info, INT cx, INT cy)
 static LRESULT CALLBACK
 MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
+    static HWND hNextClipboardViewer;
+
     PMAIN_WND_INFO Info;
 
     Info = (PMAIN_WND_INFO) GetWindowLongW(hwnd, GWLP_USERDATA);
@@ -363,6 +450,14 @@ MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
                 break;
 
+            case WM_CHANGECBCHAIN:
+                if((HWND)wParam == hNextClipboardViewer)
+                    hNextClipboardViewer = (HWND)lParam;
+                else
+                    SendMessage(hNextClipboardViewer, uMsg, wParam, lParam);
+
+                return 0;
+
             case WM_CLOSE:
                 if(Info->FirstFontWnd)
                 {
@@ -392,6 +487,8 @@ MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                 Info->hMenu = GetMenu(hwnd);
                 SetWindowLongW(hwnd, GWLP_USERDATA, (LONG)Info);
 
+                hNextClipboardViewer = SetClipboardViewer(hwnd);
+
                 InitMainWnd(Info);
                 InitResources(Info);
 
@@ -406,6 +503,13 @@ MainWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
                 PostQuitMessage(0);
                 return 0;
 
+            case WM_DRAWCLIPBOARD:
+                SetPasteButtonState(Info);
+
+                // Pass the message to the next clipboard window in the chain
+                SendMessage(hNextClipboardViewer, uMsg, wParam, lParam);
+                return 0;
+
             case WM_INITMENUPOPUP:
                 InitMenuPopup(Info);
                 break;
index f4ee5d8..c86441e 100644 (file)
@@ -147,6 +147,7 @@ VOID UnInitFontWndClass(VOID);
 extern PWSTR szAppName;
 extern HINSTANCE hInstance;
 extern HANDLE hProcessHeap;
+extern UINT uCharacterClipboardFormat;
 
 // mainwnd.c
 BOOL CreateMainWindow(IN INT nCmdShow, OUT PMAIN_WND_INFO* Info);
@@ -154,6 +155,7 @@ BOOL InitMainWndClass(VOID);
 VOID UnInitMainWndClass(VOID);
 VOID DoFileSave(IN PMAIN_WND_INFO Info, IN BOOL bSaveAs);
 VOID SetToolbarFileButtonState(IN PMAIN_WND_INFO Info, BOOL bEnabled);
+VOID SetPasteButtonState(IN PMAIN_WND_INFO Info);
 
 // misc.c
 INT AllocAndLoadString(OUT PWSTR *lpTarget, IN UINT uID);
index 189f439..a4e1f34 100644 (file)
@@ -43,6 +43,8 @@
 #define ID_FILE_EXIT              1006
 
 #define ID_EDIT_GLYPH             2001
+#define ID_EDIT_COPY              2002
+#define ID_EDIT_PASTE             2003
 
 #define ID_WINDOW_TILE_HORZ       3001
 #define ID_WINDOW_TILE_VERT       3002
@@ -71,5 +73,7 @@
 #define IDS_TOOLTIP_OPEN          11002
 #define IDS_TOOLTIP_SAVE          11003
 #define IDS_TOOLTIP_EDIT_GLYPH    11004
+#define IDS_TOOLTIP_COPY          11005
+#define IDS_TOOLTIP_PASTE         11006
 
 #endif