Skip to content

Commit

Permalink
Added the editor accelerators and some menus
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-misik committed Jun 19, 2018
1 parent 818d21b commit 8e80d9e
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 26 deletions.
16 changes: 16 additions & 0 deletions accelerators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef ACCELERATORS_H
#define ACCELERATORS_H

#include "win_common.h"

/**
* @brief Register window to receive accelerator-generated messages
*
* @param hwnd Window handle
*/
VOID AccRegisterWindow(
HWND hwnd
);

#endif /* ACCELERATORS_H */

61 changes: 53 additions & 8 deletions lua_edit.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "lua_edit.h"
#include "resource.h"
#include "dialog_resize.h"
#include "accelerators.h"

/******************************************************************************/
/* Private */
Expand Down Expand Up @@ -107,18 +108,19 @@ static BOOL OnInitDialog(
(WPARAM)GetStockObject(ANSI_FIXED_FONT), (LPARAM)TRUE);

/* Configure auto-resize */
if(DrInit(&(lpData->dr), hwnd, 4))
if(DrInit(&(lpData->dr), hwnd, 3))
{
DrConfigureControl(&(lpData->dr), 0, IDC_LUA_EDIT, DR_ANCHOR_LEFT |
DR_ANCHOR_TOP | DR_ANCHOR_RIGHT | DR_ANCHOR_BOTTOM);
DrConfigureControl(&(lpData->dr), 1, IDC_LUA_TEST_GROUP,
DR_ANCHOR_LEFT | DR_ANCHOR_RIGHT | DR_ANCHOR_BOTTOM);
DrConfigureControl(&(lpData->dr), 2, IDC_LUA_LOGO_ICON,
DrConfigureControl(&(lpData->dr), 1, IDC_LUA_LOGO_ICON,
DR_ANCHOR_RIGHT | DR_ANCHOR_BOTTOM);
DrConfigureControl(&(lpData->dr), 3, IDC_LUA_LINK,
DrConfigureControl(&(lpData->dr), 2, IDC_LUA_LINK,
DR_ANCHOR_RIGHT | DR_ANCHOR_BOTTOM);
}

/* Register for receiving the accelerators */
AccRegisterWindow(hwnd);

return TRUE;
}

Expand Down Expand Up @@ -178,10 +180,50 @@ static INT_PTR OnMenuAccCommand(
)
{
switch(wID)
{
case IDM_EDITOR_EXIT:
OnClose(hwnd);
{
case IDM_EDITOR_NEW:
SetDlgItemText(hwnd, IDC_LUA_EDIT, TEXT(""));
return TRUE;

case IDM_EDITOR_OPEN:
return TRUE;

case IDM_EDITOR_SAVE:
return TRUE;

case IDM_EDITOR_SAVEAS:
return TRUE;

case IDM_EDITOR_EXIT:
OnClose(hwnd);
return TRUE;

case IDM_EDITOR_UNDO:
SendDlgItemMessage(hwnd, IDC_LUA_EDIT, EM_UNDO, 0, 0);
return TRUE;

case IDM_EDITOR_CUT:
case IDM_EDITOR_COPY:
/* Copy the text HERE */

if(IDM_EDITOR_COPY == wID)
return TRUE;

case IDM_EDITOR_DELETE:
SendDlgItemMessage(hwnd, IDC_LUA_EDIT, EM_REPLACESEL, TRUE,
(LPARAM)TEXT(""));
return TRUE;
return TRUE;

case IDM_EDITOR_PASTE:
return TRUE;

case IDM_EDITOR_SELALL:
SendDlgItemMessage(hwnd, IDC_LUA_EDIT, EM_SETSEL, 0, -1);
return TRUE;

case IDM_EDITOR_RUN:
return TRUE;
}
return FALSE;
}
Expand Down Expand Up @@ -238,6 +280,9 @@ static INT_PTR OnDestroy(
/* Remove pointer to non-existing data */
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)NULL);

/* Unregister from receiving the accelerators */
AccRegisterWindow(NULL);

return TRUE;
}

Expand Down
39 changes: 34 additions & 5 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,30 @@
#include "resource.h"
#include "defs.h"
#include "main_wnd.h"
#include "accelerators.h"

/**
* @brief Window handle to receive the accelerator generated messages
*
* NULL to turn off accelerator.
*/
static HWND g_hWndAcc;

/**
* @brief Accelerator table handle
*/
static HACCEL g_hAccel;

HINSTANCE g_hInstance;
HANDLE g_hHeap;

/******************************************************************************/
VOID AccRegisterWindow(
HWND hwnd
)
{
g_hWndAcc = (NULL == g_hAccel) ? NULL : hwnd;
}

/******************************************************************************/
INT WINAPI wWinMain(
Expand Down Expand Up @@ -45,14 +64,24 @@ INT WINAPI wWinMain(
return 1;
}

/* Load the accelerator table */
g_hAccel = LoadAccelerators(g_hInstance, MAKEINTRESOURCE(IDR_ACC));
g_hWndAcc = NULL;

/* Enter the message loop */
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
if(FALSE == IsDialogMessage(g_hMainWnd, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
/* Translate dialog messages */
if(IsDialogMessage(g_hMainWnd, &msg))
continue;

/* Translate accelerator messages */
if(NULL != g_hWndAcc && TranslateAccelerator(g_hWndAcc, g_hAccel, &msg))
continue;

/* Translate and dispatch messages */
TranslateMessage(&msg);
DispatchMessage(&msg);
}

ExitProcess((UINT)(msg.wParam));
Expand Down
4 changes: 4 additions & 0 deletions main_wnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ static VOID ShowMainWnd(
ShowWindow(hWnd, SW_SHOW);
if(NULL != lpData->hwndDebug)
ShowWindow(lpData->hwndDebug, SW_SHOW);
if(NULL != lpData->hwndEdit)
ShowWindow(lpData->hwndEdit, SW_SHOW);

/* Move windows to the screen with cursor */
CenterWindow(hWnd);
Expand All @@ -233,6 +235,8 @@ static VOID ShowMainWnd(
ShowWindow(hWnd, SW_HIDE);
if(NULL != lpData->hwndDebug)
ShowWindow(lpData->hwndDebug, SW_HIDE);
if(NULL != lpData->hwndEdit)
ShowWindow(lpData->hwndEdit, SW_HIDE);
}
}

Expand Down
8 changes: 7 additions & 1 deletion resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#define IDC_LUA_EDIT 1041
#define IDC_LUA_LOGO_ICON 1042
#define IDC_LUA_LINK 1043
#define IDC_LUA_TEST_GROUP 1044
#define IDC_LESTATUSBAR 1049

/* Menus */
Expand All @@ -51,6 +50,13 @@
#define IDM_EDITOR_SAVE 4003
#define IDM_EDITOR_SAVEAS 4004
#define IDM_EDITOR_EXIT 4005
#define IDM_EDITOR_UNDO 4006
#define IDM_EDITOR_CUT 4007
#define IDM_EDITOR_COPY 4008
#define IDM_EDITOR_PASTE 4009
#define IDM_EDITOR_DELETE 4010
#define IDM_EDITOR_SELALL 4011
#define IDM_EDITOR_RUN 4012

#define IDR_TRAY_MENU 4200
#define IDM_SHOWHIDE 4201
Expand Down
40 changes: 28 additions & 12 deletions resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,10 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_LUA_EDIT, 7, 7, 446, 130,
WS_VSCROLL | ES_MULTILINE | WS_TABSTOP
GROUPBOX "Testing Tools", IDC_LUA_TEST_GROUP, 7, 143, 236, 38
LTEXT "", IDC_LUA_LOGO_ICON, 250, 143, 32, 32, SS_ICON
CONTROL "Read more about Lua language on its <a>web</a>",
LTEXT "", IDC_LUA_LOGO_ICON, 320, 143, 32, 32, SS_ICON
CONTROL "Read more about\r\nLua language on its <a>web</a>",
IDC_LUA_LINK, "SysLink", WS_VISIBLE | WS_TABSTOP,
295, 172, 150, 8
370, 155, 83, 20

CONTROL "", IDC_LESTATUSBAR, STATUSCLASSNAME, SBARS_SIZEGRIP |
WS_CHILD | WS_VISIBLE, 0, 0, 0, 0
Expand Down Expand Up @@ -154,13 +153,28 @@ IDR_EDITOR_MENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New", IDM_EDITOR_NEW
MENUITEM "&Open...", IDM_EDITOR_OPEN
MENUITEM "&Save", IDM_EDITOR_SAVE
MENUITEM "Save &As..", IDM_EDITOR_SAVEAS
MENUITEM "&New\tCtrl+N", IDM_EDITOR_NEW
MENUITEM "&Open...\tCtrl+O", IDM_EDITOR_OPEN
MENUITEM "&Save\tCtrl+S", IDM_EDITOR_SAVE
MENUITEM "Save &As...", IDM_EDITOR_SAVEAS
MENUITEM SEPARATOR
MENUITEM "E&xit", IDM_EDITOR_EXIT
END
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo\tCtrl+Z", IDM_EDITOR_UNDO
MENUITEM SEPARATOR
MENUITEM "Cu&t\tCtrl+X", IDM_EDITOR_CUT
MENUITEM "&Copy\tCtrl+C", IDM_EDITOR_COPY
MENUITEM "&Paste\tCtrl+V", IDM_EDITOR_PASTE
MENUITEM "De&lete\tDel", IDM_EDITOR_DELETE
MENUITEM SEPARATOR
MENUITEM "Select &All\tCtrl+A", IDM_EDITOR_SELALL
END
POPUP "&Script"
BEGIN
MENUITEM "&Run\tF6", IDM_EDITOR_RUN
END
END

/******************************************************************************/
Expand All @@ -179,9 +193,11 @@ END
/******************************************************************************/
IDR_ACC ACCELERATORS
BEGIN
"N", IDM_EDITOR_NEW, VIRTKEY, CONTROL, NOINVERT
"O", IDM_EDITOR_OPEN, VIRTKEY, CONTROL, NOINVERT
"S", IDM_EDITOR_SAVE, VIRTKEY, CONTROL, NOINVERT
"^N", IDM_EDITOR_NEW, VIRTKEY
"^O", IDM_EDITOR_OPEN, VIRTKEY
"^S", IDM_EDITOR_SAVE, VIRTKEY
"^A", IDM_EDITOR_SELALL, VIRTKEY
VK_F6, IDM_EDITOR_RUN, VIRTKEY
END

/******************************************************************************/
Expand Down

0 comments on commit 8e80d9e

Please sign in to comment.