Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
zelon committed Mar 14, 2015
1 parent 7792a10 commit 2ff01b6
Show file tree
Hide file tree
Showing 9 changed files with 270 additions and 430 deletions.
221 changes: 73 additions & 148 deletions ZViewer/ZViewer/src/MainWindow.cpp

Large diffs are not rendered by default.

30 changes: 8 additions & 22 deletions ZViewer/ZViewer/src/MainWindow.h
@@ -1,30 +1,16 @@
/* ------------------------------------------------------------------------
*
* Copyright 2006
*
* MainWindow.h
*
* 2006.11.4 Jinwook Kim
*
* ------------------------------------------------------------------------
*/

#pragma once

#include "../commonSrc/windowLib/ZWindow.h"

void HandCursorProc();


class CMainWindow : public ZWindow
{
class CMainWindow final : public ZWindow {
public:
CMainWindow();
~CMainWindow();
CMainWindow();
~CMainWindow();

virtual void SetWndProc();

virtual void SetWndProc();
HWND Create(HINSTANCE hInstance, HWND hParentHWND, int nCmdShow);
static HMENU CreatePopupMenu();

HWND Create(HINSTANCE hInstance, HWND hParentHWND, int nCmdShow);
static HMENU CreatePopupMenu();
protected:
static void HandCursorProc();
};
39 changes: 11 additions & 28 deletions ZViewer/ZViewer/src/TaskBar.cpp
@@ -1,36 +1,19 @@
/********************************************************************
*
* Created by zelon(Kim, Jinwook - Korea)
*
* 2008. 6. 2 created
* FileName : TaskBar.cpp
*
* http://zviewer.wimy.com
*********************************************************************/

#include "stdafx.h"
#include "stdafx.h"
#include "TaskBar.h"

/// 작업 표시줄을 보이게 해준다.
void TaskBar::ShellTrayShow()
{
/// 작업 표시줄을 보이게 해준다.
HWND h = FindWindow(TEXT("Shell_TrayWnd"), TEXT(""));
void TaskBar::Show() {
const HWND handle = FindWindow(TEXT("Shell_TrayWnd"), TEXT(""));

if ( h != INVALID_HANDLE_VALUE )
{
ShowWindow(h, SW_SHOW);
}
if ( handle != INVALID_HANDLE_VALUE ) {
ShowWindow(handle, SW_SHOW);
}
}

void TaskBar::ShellTrayHide()
{
// 작업 표시줄을 보이게 해준다.
HWND h = FindWindow(TEXT("Shell_TrayWnd"), TEXT(""));
void TaskBar::Hide() {
const HWND handle = FindWindow(TEXT("Shell_TrayWnd"), TEXT(""));

if ( h != INVALID_HANDLE_VALUE )
{
ShowWindow(h, SW_HIDE);
}
if ( handle != INVALID_HANDLE_VALUE ) {
ShowWindow(handle, SW_HIDE);
}
}

22 changes: 4 additions & 18 deletions ZViewer/ZViewer/src/TaskBar.h
@@ -1,21 +1,7 @@
/********************************************************************
*
* Created by zelon(Kim, Jinwook - Korea)
*
* 2008. 6. 2 created
* FileName : TaskBar.h
*
* http://zviewer.wimy.com
*********************************************************************/
#pragma once

/// 작업 표시줄을 관리하는 클래스
class TaskBar
{
class TaskBar final {
public:
/// 윈도우의 작업 표시줄을 보이게 해준다.
static void ShellTrayShow();

/// 윈도우의 작업 표시줄을 숨긴다.
static void ShellTrayHide();

static void Show();
static void Hide();
};
10 changes: 4 additions & 6 deletions ZViewer/ZViewer/src/ZMain.cpp
Expand Up @@ -639,7 +639,7 @@ void ZMain::ToggleFullScreen() {
if ( ZOption::GetInstance().IsFullScreen() ) {// 현재 풀스크린이면 원래 화면으로 돌아간다.
ZOption::GetInstance().SetFullScreen(!ZOption::GetInstance().IsFullScreen());

TaskBar::ShellTrayShow(); // 숨겨졌던 작업 표시줄을 보여준다.
TaskBar::Show(); // 숨겨졌던 작업 표시줄을 보여준다.

ShowForm(); // 메뉴, 상태 표시줄등을 보여준다.

Expand All @@ -662,7 +662,7 @@ void ZMain::ToggleFullScreen() {
MoveWindow(main_window_handle_, screenX, screenY, screenWidth, screenHeight, TRUE);

// 작업 표시줄을 가려준다.
TaskBar::ShellTrayHide();
TaskBar::Hide();

// 포커스를 잃으면 원래대로 돌아가야하므로 풀어놓는다.
SetWindowPos(main_window_handle_, HWND_NOTOPMOST, screenX, screenY, screenWidth, screenHeight, SWP_NOMOVE|SWP_NOSIZE);
Expand All @@ -677,7 +677,6 @@ void ZMain::ToggleFullScreen() {
m_iShowingY = 0;
}


void ZMain::ToggleSmallToScreenStretch() {
ZOption::GetInstance().ToggleSmallToBigStretchImage();
RefreshCurrentImage();
Expand All @@ -698,7 +697,6 @@ void ZMain::ToggleLoopImage() {

void ZMain::SetStatusBarText() {
TCHAR szTemp[COMMON_BUFFER_SIZE];
tstring strTemp;

// file index
{
Expand Down Expand Up @@ -945,7 +943,7 @@ void ZMain::_ProcAfterRemoveThisFile() {
}

void ZMain::OnFocusLose() {
TaskBar::ShellTrayShow();
TaskBar::Show();
}

void ZMain::OnFocusGet() {
Expand All @@ -963,7 +961,7 @@ void ZMain::OnFocusGet() {
MoveWindow(main_window_handle_, screenX, screenY, screenWidth, screenHeight, TRUE);
SetWindowPos(main_window_handle_, HWND_NOTOPMOST, screenX, screenY, screenWidth, screenHeight, SWP_NOMOVE|SWP_NOSIZE);

TaskBar::ShellTrayHide();
TaskBar::Hide();
}
}

Expand Down
174 changes: 81 additions & 93 deletions ZViewer/commonSrc/ZOption.cpp
@@ -1,126 +1,114 @@
#include "stdafx.h"
#include "ZOption.h"

ZOption & ZOption::GetInstance()
{
static ZOption inst;
return inst;
ZOption & ZOption::GetInstance() {
static ZOption inst;
return inst;
}


ZOption::ZOption()
{
/// 아래 값은 ZViewerAgent 에서만 true 이다
m_bDontSaveInstance = false;
ZOption::ZOption() {
/// 아래 값은 ZViewerAgent 에서만 true 이다
m_bDontSaveInstance = false;
}

void ZOption::LoadOption()
{
TCHAR buffer[1024];
tstring ZOption::GetOptionFileFullPath() {
TCHAR buffer[1024] = { 0, };

/// C:\Documents and Settings\USERID\Local Settings\Application Data 의 위치를 얻어온다.
if ( S_OK != SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer) )
{
m_strOptionFilename = GetProgramFolder();
}
else
{
m_strOptionFilename = buffer;
}
tstring file_path;

/// C:\Documents and Settings\USERID\Local Settings\Application Data 의 위치를 얻어온다.
if ( S_OK != SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, buffer) ) {
file_path = GetProgramFolder();
} else {
file_path = buffer;
}

file_path += TEXT("\\zviewer.ini");

return file_path;
}

m_strOptionFilename += TEXT("\\zviewer.ini");
m_bOptionChanged = false;
void ZOption::LoadOption() {
m_strOptionFilename = GetOptionFileFullPath();

/// 기본적인 옵션은 설정해둔다.
SetDefaultOption();
/// 기본적인 옵션은 설정해둔다.
SetDefaultOption();

/// Make the table that indicate which key-value is mapped to which variable
InitializeOptionMappingTable();
/// Make the table that indicate which key-value is mapped to which variable
InitializeOptionMappingTable();

/// 기본적인 옵션에서 파일에서 불러온 설정을 덮어씌운다.
LoadFromFile();
/// 기본적인 옵션에서 파일에서 불러온 설정을 덮어씌운다.
LoadFromFile();
}

/// Make the table that indicate which key-value is mapped to which variable
void ZOption::InitializeOptionMappingTable()
{
_InsertSaveOptionSetting(L"maximumcachememoryMB", &m_iMaximumCacheMemoryMB);
_InsertSaveOptionSetting(L"maximumcachefilenum", &m_iMaxCacheImageNum);
_InsertSaveOptionSetting(L"maximumcachememoryMB", &m_iMaximumCacheMemoryMB);
_InsertSaveOptionSetting(L"maximumcachefilenum", &m_iMaxCacheImageNum);

_InsertSaveOptionSetting(L"loop_view", &m_bLoopImages);
_InsertSaveOptionSetting(L"loop_view", &m_bLoopImages);

_InsertSaveOptionSetting(L"stretch_small_to_big", &m_bSmallToBigStretchImage);
_InsertSaveOptionSetting(L"stretch_big_to_small", &m_bBigToSmallStretchImage);
_InsertSaveOptionSetting(L"stretch_small_to_big", &m_bSmallToBigStretchImage);
_InsertSaveOptionSetting(L"stretch_big_to_small", &m_bBigToSmallStretchImage);

_InsertSaveOptionSetting(L"use_open_cmd_shell", &m_bUseOpenCMDInShell);
_InsertSaveOptionSetting(L"use_preview_shell", &m_bUsePreviewInShell);
_InsertSaveOptionSetting(L"use_open_cmd_shell", &m_bUseOpenCMDInShell);
_InsertSaveOptionSetting(L"use_preview_shell", &m_bUsePreviewInShell);

_InsertSaveOptionSetting(L"use_debug", &m_bUseDebug);
_InsertSaveOptionSetting(L"use_debug", &m_bUseDebug);

_InsertSaveOptionSetting(L"use_auto_rotation", &m_bUseAutoRotation);
_InsertSaveOptionSetting(L"use_auto_rotation", &m_bUseAutoRotation);

_InsertSaveOptionSetting(L"last_copy_directory", &m_strLastCopyDirectory);
_InsertSaveOptionSetting(L"last_move_directory", &m_strLastMoveDirectory);
_InsertSaveOptionSetting(L"last_copy_directory", &m_strLastCopyDirectory);
_InsertSaveOptionSetting(L"last_move_directory", &m_strLastMoveDirectory);
}

/// 기본적인 옵션을 설정해둔다. 설치 후 처음 실행되었을 때 이 값을 기준으로 zviewer.ini 파일이 만들어진다.
void ZOption::SetDefaultOption()
{
m_bUsePreviewInShell = true;
m_bUseOpenCMDInShell = false;
is_always_on_top_window_ = false;
is_slide_mode = false;
m_iSlideModePeriodMiliSeconds = 5000; ///< Default slide mode period is 5 seconds
m_bLoopImages = false;
m_bUseAutoRotation = true;
is_fullscreen_mode_ = false;
m_bUseDebug = true;
m_bBigToSmallStretchImage = false;
m_bSmallToBigStretchImage = false;
m_iMaximumCacheMemoryMB = 500;

m_iMaxCacheImageNum = 20;
void ZOption::SetDefaultOption() {
m_bUsePreviewInShell = true;
m_bUseOpenCMDInShell = false;
is_always_on_top_window_ = false;
is_slide_mode = false;
m_iSlideModePeriodMiliSeconds = 5000; ///< Default slide mode period is 5 seconds
m_bLoopImages = false;
m_bUseAutoRotation = true;
is_fullscreen_mode_ = false;
m_bUseDebug = true;
m_bBigToSmallStretchImage = false;
m_bSmallToBigStretchImage = false;
m_iMaximumCacheMemoryMB = 500;

m_iMaxCacheImageNum = 10;

#ifdef _DEBUG
m_iMaxCacheImageNum = 10;
m_iSlideModePeriodMiliSeconds = 1000;
m_bUseOpenCMDInShell = true;
m_bUseOpenCMDInShell = true;
#endif
}

void ZOption::LoadFromFile()
{
iniMap data;

/// 파일로부터 설정 불러오기가 성공했을 때만 설정을 한다.
if ( COptionFile::LoadFromFile(m_strOptionFilename, data) )
{
for ( size_t i=0; i<m_saveOptions.size(); ++i )
{
if ( data.count(m_saveOptions[i].getString()) > 0)
{
m_saveOptions[i].InsertMapToValue(data);
}
}
}
void ZOption::LoadFromFile() {
iniMap data;

/// 파일로부터 설정 불러오기가 성공했을 때만 설정을 한다.
if ( COptionFile::LoadFromFile(m_strOptionFilename, data) ) {
for ( size_t i=0; i<m_saveOptions.size(); ++i ) {
if ( data.count(m_saveOptions[i].getString()) > 0) {
m_saveOptions[i].InsertMapToValue(data);
}
}
}
}

void ZOption::SaveToFile() {
/// To prevent from saving at ZViewerAgent
if (m_bDontSaveInstance) {
return;
}

iniMap data;

for ( size_t i=0; i<m_saveOptions.size(); ++i ) {
m_saveOptions[i].InsertValueToMap(data);
}
COptionFile::SaveToFile(m_strOptionFilename, data);
}

void ZOption::SaveToFile()
{
/// ZViewerAgent 에서 마칠 때는 저장을 하지 않기 위해
if ( m_bDontSaveInstance ) return;

iniMap data;

m_bOptionChanged = true;

// 저장해야하는 옵션 중 변경된 것이 있으면
if ( m_bOptionChanged )
{
for ( size_t i=0; i<m_saveOptions.size(); ++i )
{
m_saveOptions[i].InsertValueToMap(data);
}
COptionFile::SaveToFile(m_strOptionFilename, data);
}
}
5 changes: 2 additions & 3 deletions ZViewer/commonSrc/ZOption.h
Expand Up @@ -66,6 +66,8 @@ class ZOption final {
private:
ZOption();

static tstring GetOptionFileFullPath();

template < class T >
void _InsertSaveOptionSetting(TCHAR * str, T * value) {
tstring val(str);
Expand Down Expand Up @@ -119,9 +121,6 @@ class ZOption final {
/// 이 값이 false 이면 singleton 을 끝낼 때 값을 저장하지 않는다(ZviewerAgent 의 종료 시점을 정확히 알 수 없기 때문)
bool m_bDontSaveInstance;

/// 파일로부터 옵션을 읽어들여서 바뀐 옵션이 있나.
bool m_bOptionChanged;

std::vector<StringToValue> m_saveOptions;
};

0 comments on commit 2ff01b6

Please sign in to comment.