tv_rename/win32/patternwindow.cpp

93 lines
2.9 KiB
C++
Raw Permalink Normal View History

2020-04-01 11:54:19 +00:00
#pragma comment( linker, "\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"" )
2020-02-25 15:11:25 +00:00
#include "patternwindow.hpp"
2020-04-01 11:54:19 +00:00
#include "../functions.hpp"
#include "../resources_windows.h"
2020-02-25 15:11:25 +00:00
#include "gui_functions.hpp"
#define ID_PATTERN_STATIC 0x0001
#define ID_PATTERN_EDIT 0x1000
#define ID_OK_BUTTON 0x1001
#define ID_CANCEL_BUTTON 0x1002
PatternWindow *PatternWindow::pw = nullptr;
PatternWindow::PatternWindow( HINSTANCE hInstance, const wchar_t *pattern,
HWND parent_window )
: parent( parent_window ) {
2020-04-01 11:54:19 +00:00
window = CreateWindowW( L"PatternWindow", _( PATTERN ),
2020-02-25 15:11:25 +00:00
WS_OVERLAPPEDWINDOW ^ WS_THICKFRAME | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, window_width,
window_height, parent, NULL, hInstance, NULL );
ShowWindow( window, SW_SHOW );
auto hFont = ( HFONT )GetStockObject( DEFAULT_GUI_FONT );
EnableWindow( parent, false );
2020-04-01 11:54:19 +00:00
setIcons( hInstance, window );
2020-02-25 15:11:25 +00:00
2020-04-01 11:54:19 +00:00
std::wstring label = _( PATTERN );
label += L":";
createLabel( label.c_str(), 5, 5, 30, 15, ID_PATTERN_STATIC, window,
hFont );
2020-02-25 15:11:25 +00:00
pattern_input =
2020-04-01 11:54:19 +00:00
createEditBox( 5, 20, 190, 20, ID_PATTERN_EDIT, window, hFont );
2020-02-25 15:11:25 +00:00
2020-04-01 11:54:19 +00:00
createButton( _( CANCEL ), window_width - 100, window_height - 88, 80, 25,
2020-02-25 15:11:25 +00:00
ID_CANCEL_BUTTON, window, hFont );
2020-04-01 11:54:19 +00:00
createButton( _( OK ), window_width - 185, window_height - 88, 80, 25,
2020-02-25 15:11:25 +00:00
ID_OK_BUTTON, window, hFont );
SendMessage( pattern_input, WM_SETTEXT, NULL, ( LPARAM )pattern );
UpdateWindow( window );
}
void PatternWindow::storePattern() {
SendMessage( pattern_input, WM_GETTEXT, ( WPARAM )2047, ( LPARAM )pattern );
}
const wchar_t *PatternWindow::getPattern() {
return pattern;
}
LRESULT CALLBACK PatternWindow::messageHandler( HWND hwnd, UINT umsg,
WPARAM wParam, LPARAM lParam ) {
switch ( umsg ) {
case WM_CREATE:
centerWindow( hwnd );
break;
case WM_COMMAND:
switch ( LOWORD( wParam ) ) {
case ID_OK_BUTTON:
2020-04-01 11:54:19 +00:00
pw->result = DIA_OK;
2020-02-25 15:11:25 +00:00
pw->storePattern();
SendMessage( hwnd, WM_CLOSE, 0, 0 );
break;
case ID_CANCEL_BUTTON:
2020-04-01 11:54:19 +00:00
pw->result = DIA_Cancel;
2020-02-25 15:11:25 +00:00
SendMessage( hwnd, WM_CLOSE, 0, 0 );
break;
}
break;
case WM_DESTROY:
PostQuitMessage( 0 );
break;
}
return DefWindowProcW( hwnd, umsg, wParam, lParam );
}
void PatternWindow::mainLoop() {
MSG msg;
while ( GetMessage( &msg, NULL, 0, 0 ) ) {
if ( !IsDialogMessage( window, &msg ) ) {
TranslateMessage( &msg );
pw = this;
DispatchMessage( &msg );
}
}
}
bool PatternWindow::accepted() {
2020-04-01 11:54:19 +00:00
return result == DIA_OK;
2020-02-25 15:11:25 +00:00
}