Skip to content

Commit

Permalink
- update and merged with changes from https://github.com/npp-plugins/…
Browse files Browse the repository at this point in the history
…plugintemplate v3.1

- corrected build warnings and some VS analysis issues
  • Loading branch information
chcg committed Dec 22, 2017
1 parent 05a11e7 commit 6b2733c
Show file tree
Hide file tree
Showing 19 changed files with 1,268 additions and 737 deletions.
16 changes: 9 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
test/*
Unicode Realeas/*
Unicode Debug/*
bin/*
ipch/*
*.opensdf
*.sdf
*.sln
*.suo

bin/
bin64/
*.opensdf
*.exp
*.lib
*.vcxproj.user
*.aps
*.zip
2 changes: 1 addition & 1 deletion DockingFeature/DockingDlgInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class DockingDlgInterface : public StaticDialog
};

protected :
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM /*wParam*/, LPARAM lParam)
{
switch (message)
{
Expand Down
4 changes: 2 additions & 2 deletions DockingFeature/GoToLineDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include "GoToLineDlg.h"
#include "PluginDefinition.h"
#include "../PluginDefinition.h"

extern NppData nppData;

BOOL CALLBACK DemoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK DemoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
Expand Down
2 changes: 1 addition & 1 deletion DockingFeature/GoToLineDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public :
};

protected :
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);

private :

Expand Down
126 changes: 73 additions & 53 deletions DockingFeature/StaticDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include <stdio.h>
#include "StaticDialog.h"

void StaticDialog::goToCenter()
{
RECT rc;
::GetClientRect(_hParent, &rc);
POINT center;
center.x = rc.left + (rc.right - rc.left)/2;
center.y = rc.top + (rc.bottom - rc.top)/2;
::ClientToScreen(_hParent, &center);
RECT rc;
::GetClientRect(_hParent, &rc);
POINT center;
center.x = rc.left + (rc.right - rc.left)/2;
center.y = rc.top + (rc.bottom - rc.top)/2;
::ClientToScreen(_hParent, &center);

int x = center.x - (_rc.right - _rc.left)/2;
int y = center.y - (_rc.bottom - _rc.top)/2;
Expand All @@ -36,17 +37,25 @@ HGLOBAL StaticDialog::makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplat
{
// Get Dlg Template resource
HRSRC hDialogRC = ::FindResource(_hInst, MAKEINTRESOURCE(dialogID), RT_DIALOG);
if (!hDialogRC)
return NULL;

HGLOBAL hDlgTemplate = ::LoadResource(_hInst, hDialogRC);
DLGTEMPLATE *pDlgTemplate = (DLGTEMPLATE *)::LockResource(hDlgTemplate);

if (!hDlgTemplate)
return NULL;

DLGTEMPLATE *pDlgTemplate = reinterpret_cast<DLGTEMPLATE *>(::LockResource(hDlgTemplate));
if (!pDlgTemplate)
return NULL;

// Duplicate Dlg Template resource
unsigned long sizeDlg = ::SizeofResource(_hInst, hDialogRC);
HGLOBAL hMyDlgTemplate = ::GlobalAlloc(GPTR, sizeDlg);
*ppMyDlgTemplate = (DLGTEMPLATE *)::GlobalLock(hMyDlgTemplate);
*ppMyDlgTemplate = reinterpret_cast<DLGTEMPLATE *>(::GlobalLock(hMyDlgTemplate));

::memcpy(*ppMyDlgTemplate, pDlgTemplate, sizeDlg);
DLGTEMPLATEEX *pMyDlgTemplateEx = (DLGTEMPLATEEX *)*ppMyDlgTemplate;

DLGTEMPLATEEX *pMyDlgTemplateEx = reinterpret_cast<DLGTEMPLATEEX *>(*ppMyDlgTemplate);
if (pMyDlgTemplateEx->signature == 0xFFFF)
pMyDlgTemplateEx->exStyle |= WS_EX_LAYOUTRTL;
else
Expand All @@ -61,38 +70,43 @@ void StaticDialog::create(int dialogID, bool isRTL)
{
DLGTEMPLATE *pMyDlgTemplate = NULL;
HGLOBAL hMyDlgTemplate = makeRTLResource(dialogID, &pMyDlgTemplate);
_hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, (DLGPROC)dlgProc, (LPARAM)this);
_hSelf = ::CreateDialogIndirectParam(_hInst, pMyDlgTemplate, _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
::GlobalFree(hMyDlgTemplate);
}
else
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, (DLGPROC)dlgProc, (LPARAM)this);
_hSelf = ::CreateDialogParam(_hInst, MAKEINTRESOURCE(dialogID), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));

if (!_hSelf)
{
DWORD err = ::GetLastError();
char errMsg[256];
sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %u", err);
::MessageBoxA(NULL, errMsg, "In StaticDialog::create()", MB_OK);
return;
}

::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);
// if the destination of message NPPM_MODELESSDIALOG is not its parent, then it's the grand-parent
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGADD, reinterpret_cast<WPARAM>(_hSelf));
}

BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
switch (message)
{
case WM_INITDIALOG :
case WM_INITDIALOG:
{
StaticDialog *pStaticDlg = (StaticDialog *)(lParam);
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(lParam);
pStaticDlg->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWL_USERDATA, (long)lParam);
::SetWindowLongPtr(hwnd, GWLP_USERDATA, static_cast<LONG_PTR>(lParam));
::GetWindowRect(hwnd, &(pStaticDlg->_rc));
pStaticDlg->run_dlgProc(message, wParam, lParam);
pStaticDlg->run_dlgProc(message, wParam, lParam);

return TRUE;
}

default :
default:
{
StaticDialog *pStaticDlg = (StaticDialog *)(::GetWindowLongPtr(hwnd, GWL_USERDATA));
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (!pStaticDlg)
return FALSE;
return pStaticDlg->run_dlgProc(message, wParam, lParam);
Expand All @@ -102,34 +116,40 @@ BOOL CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPAR

void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point)
{
RECT rc, rc2;
::GetWindowRect(handle, &rc);

point.x = rc.left;
point.y = rc.top;

switch (pos)
{
case ALIGNPOS_LEFT :
::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left;
break;

case ALIGNPOS_RIGHT :
::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left;
break;

case ALIGNPOS_TOP :
::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top;
break;

default : //ALIGNPOS_BOTTOM
::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top;
break;
}

::ScreenToClient(_hSelf, &point);
RECT rc, rc2;
::GetWindowRect(handle, &rc);

point.x = rc.left;
point.y = rc.top;

switch (pos)
{
case PosAlign::left:
{
::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left;
break;
}
case PosAlign::right:
{
::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left;
break;
}
case PosAlign::top:
{
::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top;
break;
}
case PosAlign::bottom:
{
::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top;
break;
}
}

::ScreenToClient(_hSelf, &point);
}

15 changes: 6 additions & 9 deletions DockingFeature/StaticDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef STATIC_DIALOG_H
#define STATIC_DIALOG_H
#pragma once

//#include "resource.h"
#include "Window.h"
#include "Notepad_plus_msgs.h"
#include "..\Notepad_plus_msgs.h"

enum PosAlign{ALIGNPOS_LEFT, ALIGNPOS_RIGHT, ALIGNPOS_TOP, ALIGNPOS_BOTTOM};
enum class PosAlign { left, right, top, bottom };

struct DLGTEMPLATEEX {
WORD dlgVer;
Expand All @@ -44,7 +42,7 @@ public :
StaticDialog() : Window() {};
~StaticDialog(){
if (isCreated()) {
::SetWindowLongPtr(_hSelf, GWL_USERDATA, (long)NULL); //Prevent run_dlgProc from doing anything, since its virtual
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (long)NULL); //Prevent run_dlgProc from doing anything, since its virtual
destroy();
}
};
Expand All @@ -62,11 +60,10 @@ public :

protected :
RECT _rc;
static BOOL CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;

void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point);
HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
};

#endif //STATIC_DIALOG_H
4 changes: 2 additions & 2 deletions NotepadSharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern NppData nppData;

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD reasonForCall,
LPVOID lpReserved )
LPVOID /*lpReserved*/ )
{
switch (reasonForCall)
{
Expand Down Expand Up @@ -169,7 +169,7 @@ extern "C" __declspec(dllexport) void beNotified(SCNotification *notifyCode)
// Please let me know if you need to access to some messages :
// http://sourceforge.net/forum/forum.php?forum_id=482781
//
extern "C" __declspec(dllexport) LRESULT messageProc(UINT Message, WPARAM wParam, LPARAM lParam)
extern "C" __declspec(dllexport) LRESULT messageProc(UINT /*Message*/, WPARAM /*wParam*/, LPARAM /*lParam*/)
{/*
if (Message == WM_MOVE)
{
Expand Down
26 changes: 0 additions & 26 deletions NotepadSharp.sln

This file was deleted.

Loading

0 comments on commit 6b2733c

Please sign in to comment.