Skip to content

Commit

Permalink
Common item window class; #258
Browse files Browse the repository at this point in the history
  • Loading branch information
vanjac committed Dec 10, 2023
1 parent 6e6edf4 commit 1f5e337
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 65 deletions.
8 changes: 0 additions & 8 deletions src/FolderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

namespace chromafiler {

const wchar_t FOLDER_WINDOW_CLASS[] = L"ChromaFile Folder";

const wchar_t PROP_SHELL_VISITED[] = L"Visited";
const wchar_t PROP_ICON_POS[] = L"IconPos";

Expand Down Expand Up @@ -59,8 +57,6 @@ bool FolderWindow::spatialView(IFolderView *const folderView) {
}

void FolderWindow::init() {
RegisterClass(tempPtr(createWindowClass(FOLDER_WINDOW_CLASS)));

for (int i = 0; i < _countof(HIDDEN_ITEM_PARSE_NAMES); i++) {
CComPtr<IShellItem> item;
if (SUCCEEDED(SHCreateItemFromParsingName(HIDDEN_ITEM_PARSE_NAMES[i], nullptr,
Expand All @@ -76,10 +72,6 @@ void FolderWindow::init() {
FolderWindow::FolderWindow(ItemWindow *const parent, IShellItem *const item)
: ItemWindow(parent, item) {}

const wchar_t * FolderWindow::className() const {
return FOLDER_WINDOW_CLASS;
}

bool FolderWindow::persistSizeInParent() const {
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions src/FolderWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ class FolderWindow : public ItemWindow, public IServiceProvider, public ICommDlg
std::unique_ptr<POINT[]> itemPositions;
};

const wchar_t * className() const override;

void listViewCreated();
static LRESULT CALLBACK listViewSubclassProc(HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam, UINT_PTR subclassID, DWORD_PTR refData);
Expand Down
29 changes: 16 additions & 13 deletions src/ItemWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace chromafiler {

const wchar_t ITEM_WINDOW_CLASS[] = L"ChromaFiler Item Window";
const wchar_t TESTPOS_CLASS[] = L"ChromaFiler Test Window";
const wchar_t WINDOW_THEME[] = L"CompositedWindow::Window";
const UINT SC_DRAGMOVE = SC_MOVE | 2; // https://stackoverflow.com/a/35880547/11525734
Expand Down Expand Up @@ -97,6 +98,17 @@ void ItemWindow::init() {

HINSTANCE hInstance = GetModuleHandle(nullptr);

WNDCLASS itemClass = {};
itemClass.lpfnWndProc = windowProc;
itemClass.hInstance = hInstance;
itemClass.lpszClassName = ITEM_WINDOW_CLASS;
if (!compositionEnabled)
itemClass.style = CS_HREDRAW; // redraw caption when resizing
// change toolbar color
if (IsWindows10OrGreater())
itemClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
RegisterClass(&itemClass);

WNDCLASS testPosClass = {};
testPosClass.lpszClassName = TESTPOS_CLASS;
testPosClass.lpfnWndProc = DefWindowProc;
Expand Down Expand Up @@ -163,19 +175,6 @@ void ItemWindow::uninit() {
RemoveFontMemResourceEx(symbolFontHandle);
}

WNDCLASS ItemWindow::createWindowClass(const wchar_t *name) {
WNDCLASS wndClass = {};
wndClass.lpfnWndProc = windowProc;
wndClass.hInstance = GetModuleHandle(nullptr);
wndClass.lpszClassName = name;
if (!compositionEnabled)
wndClass.style = CS_HREDRAW; // redraw caption when resizing
// change toolbar color
if (IsWindows10OrGreater())
wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
return wndClass;
}

void ItemWindow::flashWindow(HWND hwnd) {
PostMessage(hwnd, MSG_FLASH_WINDOW, 0, 0);
}
Expand All @@ -185,6 +184,10 @@ ItemWindow::ItemWindow(ItemWindow *const parent, IShellItem *const item)
item(item),
proxyIcon(this) {}

const wchar_t * ItemWindow::className() const {
return ITEM_WINDOW_CLASS;
}

void ItemWindow::setScratch(bool value) {
scratch = value;
}
Expand Down
3 changes: 1 addition & 2 deletions src/ItemWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class ItemWindow : public WindowImpl, public IUnknownImpl {
MSG_FLASH_WINDOW,
MSG_LAST
};
static WNDCLASS createWindowClass(const wchar_t *name);
LRESULT handleMessage(UINT message, WPARAM wParam, LPARAM lParam) override;

virtual SIZE defaultSize() const;
Expand Down Expand Up @@ -155,7 +154,7 @@ class ItemWindow : public WindowImpl, public IUnknownImpl {
CComQIPtr<IContextMenu3> contextMenu3;

private:
virtual const wchar_t * className() const = 0;
virtual const wchar_t * className() const;

bool centeredProxy() const; // requires useCustomFrame() == true

Expand Down
7 changes: 0 additions & 7 deletions src/PreviewWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace chromafiler {

// https://geelaw.blog/entries/ipreviewhandlerframe-wpf-2-interop/

const wchar_t PREVIEW_WINDOW_CLASS[] = L"ChromaFile Preview";
const wchar_t PREVIEW_CONTAINER_CLASS[] = L"ChromaFile Preview Container";

const int FACTORY_CACHE_SIZE = 4;
Expand All @@ -31,8 +30,6 @@ static FactoryCacheEntry factoryCache[FACTORY_CACHE_SIZE] = {};
static int factoryCacheIndex = 0;

void PreviewWindow::init() {
RegisterClass(tempPtr(createWindowClass(PREVIEW_WINDOW_CLASS)));

WNDCLASS containerClass = {};
containerClass.lpszClassName = PREVIEW_CONTAINER_CLASS;
containerClass.lpfnWndProc = DefWindowProc;
Expand All @@ -57,10 +54,6 @@ PreviewWindow::PreviewWindow(ItemWindow *const parent, IShellItem *const item, C
: ItemWindow(parent, item),
previewID(previewID) {}

const wchar_t * PreviewWindow::className() const {
return PREVIEW_WINDOW_CLASS;
}

void PreviewWindow::onCreate() {
ItemWindow::onCreate();

Expand Down
2 changes: 0 additions & 2 deletions src/PreviewWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class PreviewWindow : public ItemWindow, public IPreviewHandlerFrame {
void refresh() override;

private:
const wchar_t * className() const override;

void destroyPreview();

CLSID previewID;
Expand Down
8 changes: 0 additions & 8 deletions src/TextWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

namespace chromafiler {

const wchar_t TEXT_WINDOW_CLASS[] = L"ChromaFile Text";

const wchar_t PROP_WORD_WRAP[] = L"WordWrap";

const ULONG MAX_FILE_SIZE = 50'000'000;
Expand All @@ -36,8 +34,6 @@ static UINT updateSettingsMessage, findReplaceMessage;
static HMODULE hMsftedit = nullptr;

void TextWindow::init() {
RegisterClass(tempPtr(createWindowClass(TEXT_WINDOW_CLASS)));

textAccelTable = LoadAccelerators(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDR_TEXT_ACCEL));

updateSettingsMessage = checkLE(RegisterWindowMessage(L"chromafiler_TextUpdateSettings"));
Expand All @@ -61,10 +57,6 @@ TextWindow::TextWindow(ItemWindow *const parent, IShellItem *const item)
replaceBuffer[0] = 0;
}

const wchar_t * TextWindow::className() const {
return TEXT_WINDOW_CLASS;
}

const wchar_t * TextWindow::appUserModelID() const {
return L"chroma.text";
}
Expand Down
2 changes: 0 additions & 2 deletions src/TextWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class TextWindow : public ItemWindow {
void trackContextMenu(POINT pos) override;

private:
const wchar_t * className() const override;

HWND createRichEdit(bool readOnly, bool wordWrap);
bool isEditable();
CComPtr<ITextDocument> getTOMDocument();
Expand Down
13 changes: 1 addition & 12 deletions src/ThumbnailWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@

namespace chromafiler {

const wchar_t THUMBNAIL_WINDOW_CLASS[] = L"ChromaFile Thumbnail";

void ThumbnailWindow::init() {
WNDCLASS wndClass = createWindowClass(THUMBNAIL_WINDOW_CLASS);
wndClass.style |= CS_HREDRAW | CS_VREDRAW; // redraw whenever size changes
RegisterClass(&wndClass);
}

ThumbnailWindow::ThumbnailWindow(ItemWindow *const parent, IShellItem *const item)
: ItemWindow(parent, item) {}

Expand All @@ -25,10 +17,6 @@ ThumbnailWindow::~ThumbnailWindow() {
}
}

const wchar_t * ThumbnailWindow::className() const {
return THUMBNAIL_WINDOW_CLASS;
}

void ThumbnailWindow::onCreate() {
ItemWindow::onCreate();
thumbnailThread.Attach(new ThumbnailThread(item, this));
Expand All @@ -45,6 +33,7 @@ void ThumbnailWindow::onSize(SIZE size) {
RECT bodyRect = windowBody();
SIZE bodySize = rectSize(bodyRect);
thumbnailThread->requestThumbnail(bodySize);
// TODO invalidate?
}

void ThumbnailWindow::onItemChanged() {
Expand Down
4 changes: 0 additions & 4 deletions src/ThumbnailWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ namespace chromafiler {

class ThumbnailWindow : public ItemWindow {
public:
static void init();

ThumbnailWindow(ItemWindow *parent, IShellItem *item);
~ThumbnailWindow();

Expand All @@ -29,8 +27,6 @@ class ThumbnailWindow : public ItemWindow {
void refresh() override;

private:
const wchar_t * className() const override;

SRWLOCK thumbnailBitmapLock = SRWLOCK_INIT;
HBITMAP thumbnailBitmap = nullptr;

Expand Down
8 changes: 5 additions & 3 deletions src/TrayWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace chromafiler {

const wchar_t TRAY_WINDOW_CLASS[] = L"ChromaFile Tray";
const wchar_t TRAY_WINDOW_CLASS[] = L"ChromaFile Tray"; // used by installer, do not change!

const int HOTKEY_FOCUS_TRAY = 1;

Expand Down Expand Up @@ -43,8 +43,10 @@ static void snapAxis(LONG value, LONG edge, LONG *snapOffset, LONG *snapDist) {
}

void TrayWindow::init() {
WNDCLASS wndClass = createWindowClass(TRAY_WINDOW_CLASS);
wndClass.style = 0; // clear redraw style
WNDCLASS wndClass = {};
wndClass.lpfnWndProc = windowProc;
wndClass.hInstance = GetModuleHandle(nullptr);
wndClass.lpszClassName = TRAY_WINDOW_CLASS;
wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
RegisterClass(&wndClass);

Expand Down
2 changes: 0 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "main.h"
#include "FolderWindow.h"
#include "ThumbnailWindow.h"
#include "PreviewWindow.h"
#include "TextWindow.h"
#include "TrayWindow.h"
Expand Down Expand Up @@ -110,7 +109,6 @@ int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int showCommand) {
initDPI();
ItemWindow::init();
FolderWindow::init();
ThumbnailWindow::init();
PreviewWindow::init();
TextWindow::init();
TrayWindow::init();
Expand Down

0 comments on commit 1f5e337

Please sign in to comment.