Skip to content

Commit

Permalink
added about box
Browse files Browse the repository at this point in the history
  • Loading branch information
kapilratnani committed May 9, 2011
1 parent 8beb217 commit d7754ac
Show file tree
Hide file tree
Showing 8 changed files with 266 additions and 19 deletions.
166 changes: 166 additions & 0 deletions Hyperlinks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Hyperlinks.cpp
//
// Copyright 2002 Neal Stublen
// All rights reserved.
//
// http://www.awesoftware.com
//

#include <windows.h>

#include "Hyperlinks.h"


#define PROP_ORIGINAL_FONT TEXT("_Hyperlink_Original_Font_")
#define PROP_ORIGINAL_PROC TEXT("_Hyperlink_Original_Proc_")
#define PROP_STATIC_HYPERLINK TEXT("_Hyperlink_From_Static_")
#define PROP_UNDERLINE_FONT TEXT("_Hyperlink_Underline_Font_")


LRESULT CALLBACK _HyperlinkParentProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WNDPROC pfnOrigProc = (WNDPROC) GetProp(hwnd, PROP_ORIGINAL_PROC);

switch (message)
{
case WM_CTLCOLORSTATIC:
{
HDC hdc = (HDC) wParam;
HWND hwndCtl = (HWND) lParam;

BOOL fHyperlink = (NULL != GetProp(hwndCtl, PROP_STATIC_HYPERLINK));
if (fHyperlink)
{
LRESULT lr = CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam);
SetTextColor(hdc, RGB(0, 0, 192));
return lr;
}

break;
}
case WM_DESTROY:
{
SetWindowLong(hwnd, GWL_WNDPROC, (LONG) pfnOrigProc);
RemoveProp(hwnd, PROP_ORIGINAL_PROC);
break;
}
}
return CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam);
}

LRESULT CALLBACK _HyperlinkProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
WNDPROC pfnOrigProc = (WNDPROC) GetProp(hwnd, PROP_ORIGINAL_PROC);

switch (message)
{
case WM_DESTROY:
{
SetWindowLong(hwnd, GWL_WNDPROC, (LONG) pfnOrigProc);
RemoveProp(hwnd, PROP_ORIGINAL_PROC);

HFONT hOrigFont = (HFONT) GetProp(hwnd, PROP_ORIGINAL_FONT);
SendMessage(hwnd, WM_SETFONT, (WPARAM) hOrigFont, 0);
RemoveProp(hwnd, PROP_ORIGINAL_FONT);

HFONT hFont = (HFONT) GetProp(hwnd, PROP_UNDERLINE_FONT);
DeleteObject(hFont);
RemoveProp(hwnd, PROP_UNDERLINE_FONT);

RemoveProp(hwnd, PROP_STATIC_HYPERLINK);

break;
}
case WM_MOUSEMOVE:
{
if (GetCapture() != hwnd)
{
HFONT hFont = (HFONT) GetProp(hwnd, PROP_UNDERLINE_FONT);
SendMessage(hwnd, WM_SETFONT, (WPARAM) hFont, FALSE);
InvalidateRect(hwnd, NULL, FALSE);
SetCapture(hwnd);
}
else
{
RECT rect;
GetWindowRect(hwnd, &rect);

POINT pt = { LOWORD(lParam), HIWORD(lParam) };
ClientToScreen(hwnd, &pt);

if (!PtInRect(&rect, pt))
{
HFONT hFont = (HFONT) GetProp(hwnd, PROP_ORIGINAL_FONT);
SendMessage(hwnd, WM_SETFONT, (WPARAM) hFont, FALSE);
InvalidateRect(hwnd, NULL, FALSE);
ReleaseCapture();
}
}
break;
}
case WM_SETCURSOR:
{
// Since IDC_HAND is not available on all operating systems,
// we will load the arrow cursor if IDC_HAND is not present.
HCURSOR hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND));
if (NULL == hCursor)
{
hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
}
SetCursor(hCursor);
return TRUE;
}
}

return CallWindowProc(pfnOrigProc, hwnd, message, wParam, lParam);
}

BOOL ConvertStaticToHyperlink(HWND hwndCtl)
{
// Subclass the parent so we can color the controls as we desire.

HWND hwndParent = GetParent(hwndCtl);
if (NULL != hwndParent)
{
WNDPROC pfnOrigProc = (WNDPROC) GetWindowLong(hwndParent, GWL_WNDPROC);
if (pfnOrigProc != _HyperlinkParentProc)
{
SetProp(hwndParent, PROP_ORIGINAL_PROC, (HANDLE) pfnOrigProc);
SetWindowLong(hwndParent, GWL_WNDPROC, (LONG) (WNDPROC) _HyperlinkParentProc);
}
}

// Make sure the control will send notifications.

DWORD dwStyle = GetWindowLong(hwndCtl, GWL_STYLE);
SetWindowLong(hwndCtl, GWL_STYLE, dwStyle | SS_NOTIFY);

// Subclass the existing control.

WNDPROC pfnOrigProc = (WNDPROC) GetWindowLong(hwndCtl, GWL_WNDPROC);
SetProp(hwndCtl, PROP_ORIGINAL_PROC, (HANDLE) pfnOrigProc);
SetWindowLong(hwndCtl, GWL_WNDPROC, (LONG) (WNDPROC) _HyperlinkProc);

// Create an updated font by adding an underline.

HFONT hOrigFont = (HFONT) SendMessage(hwndCtl, WM_GETFONT, 0, 0);
SetProp(hwndCtl, PROP_ORIGINAL_FONT, (HANDLE) hOrigFont);

LOGFONT lf;
GetObject(hOrigFont, sizeof(lf), &lf);
lf.lfUnderline = TRUE;

HFONT hFont = CreateFontIndirect(&lf);
SetProp(hwndCtl, PROP_UNDERLINE_FONT, (HANDLE) hFont);

// Set a flag on the control so we know what color it should be.

SetProp(hwndCtl, PROP_STATIC_HYPERLINK, (HANDLE) 1);

return TRUE;
}

BOOL ConvertStaticToHyperlink(HWND hwndParent, UINT uiCtlId)
{
return ConvertStaticToHyperlink(GetDlgItem(hwndParent, uiCtlId));
}
10 changes: 10 additions & 0 deletions Hyperlinks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Hyperlinks.h
//
// Copyright 2002 Neal Stublen
// All rights reserved.
//
// http://www.awesoftware.com
//

BOOL ConvertStaticToHyperlink(HWND hwndCtl);
BOOL ConvertStaticToHyperlink(HWND hwndParent, UINT uiCtlId);
7 changes: 6 additions & 1 deletion NppDocIt.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,23 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Hyperlinks.cpp" />
<ClCompile Include="NppDocIt.cpp" />
<ClCompile Include="PluginDefinition.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Hyperlinks.h" />
<ClInclude Include="menuCmdID.h" />
<ClInclude Include="Notepad_plus_msgs.h" />
<ClInclude Include="include\pcre.h" />
<ClInclude Include="PluginDefinition.h" />
<ClInclude Include="PluginInterface.h" />
<ClInclude Include="DockingFeature\resource.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="Scintilla.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
15 changes: 13 additions & 2 deletions NppDocIt.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<ClCompile Include="PluginDefinition.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Hyperlinks.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="menuCmdID.h">
Expand All @@ -38,11 +41,19 @@
<ClInclude Include="PluginInterface.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DockingFeature\resource.h">
<ClInclude Include="Scintilla.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Scintilla.h">
<ClInclude Include="resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Hyperlinks.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
28 changes: 27 additions & 1 deletion PluginDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "PluginDefinition.h"
#include "menuCmdID.h"
#include <iostream>
#include "Hyperlinks.h"
#include "pcre.h"
#define OVECCOUNT 60

Expand All @@ -31,11 +32,14 @@ FuncItem funcItem[nbFunc];
//
NppData nppData;

HANDLE g_hMod;

//
// Initialize your plugin data here
// It will be called while plugin loading
void pluginInit(HANDLE hModule)
{
g_hMod=hModule;
}

//
Expand Down Expand Up @@ -704,7 +708,29 @@ void insert_doc_string()
}



INT_PTR CALLBACK abtDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
ConvertStaticToHyperlink(hwndDlg,IDC_WEB);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDOK:
EndDialog(hwndDlg,wParam);
return TRUE;
case IDC_WEB:
ShellExecute(hwndDlg, TEXT("open"),TEXT("http://nppdocit.sourceforge.net/"),NULL, NULL, SW_SHOWNORMAL);
return TRUE;
}
}
return FALSE;
}

void show_about_dlg()
{
::MessageBox(NULL, TEXT("Hello, Notepad++!"), TEXT("Notepad++ Plugin Template"), MB_OK);
::CreateDialog((HINSTANCE)g_hMod,MAKEINTRESOURCE(IDD_ABOUTDLG),nppData._nppHandle,abtDlgProc);
}
1 change: 1 addition & 0 deletions PluginDefinition.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// All difinitions of plugin interface
//
#include "PluginInterface.h"
#include "resource.h"

//-------------------------------------//
//-- STEP 1. DEFINE YOUR PLUGIN NAME --//
Expand Down
5 changes: 2 additions & 3 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
#define IDC_STATIC (-1)
#endif

#define IDD_DIALOG1 100
#define IDOK 1000
#define IDCANCEL 1001
#define IDD_ABOUTDLG 103
#define IDC_WEB 1002
53 changes: 41 additions & 12 deletions resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,59 @@
//
// Dialog resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
IDD_DIALOG1 DIALOG 0, 0, 186, 95
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
CAPTION "Dialog"
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_ABOUTDLG DIALOG 0, 0, 268, 119
STYLE DS_3DLOOK | DS_ABSALIGN | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
EXSTYLE WS_EX_WINDOWEDGE
CAPTION "About DocIt"
FONT 8, "Ms Shell Dlg"
{
DEFPUSHBUTTON "OK", IDOK, 129, 7, 50, 14
PUSHBUTTON "Cancel", IDCANCEL, 129, 24, 50, 14
DEFPUSHBUTTON "OK", IDOK, 105, 103, 50, 14
GROUPBOX "DocIt", IDC_STATIC, 14, 7, 247, 90, BS_CENTER
LTEXT "Author:", IDC_STATIC, 27, 21, 24, 8, SS_LEFT
LTEXT "Kapil Ratnani", IDC_STATIC, 104, 21, 43, 8, SS_LEFT
LTEXT "Version:", IDC_STATIC, 27, 35, 26, 8, SS_LEFT
LTEXT "0.5 Alpha", IDC_STATIC, 104, 35, 31, 8, SS_LEFT
LTEXT "Licence:", IDC_STATIC, 27, 48, 28, 8, SS_LEFT
LTEXT "GPL", IDC_STATIC, 104, 48, 15, 8, SS_LEFT
LTEXT "Special thanks to:", IDC_STATIC, 27, 63, 58, 8, SS_LEFT
LTEXT "Don Ho for Notepad++ and creators of PCRE", IDC_STATIC, 103, 63, 144, 8, SS_LEFT
LTEXT "Website:", IDC_STATIC, 28, 78, 29, 8, SS_LEFT
LTEXT "http://nppdocit.sourceforge.net/", IDC_WEB, 104, 78, 104, 8, SS_LEFT | SS_NOTIFY
}



//
// Version Information resources
//
LANGUAGE 0, SUBLANG_NEUTRAL
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
1 VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
FILEOS VOS_UNKNOWN
FILETYPE VFT_UNKNOWN
FILEVERSION 0,5,0,0
PRODUCTVERSION 0,5,0,0
FILEOS VOS__WINDOWS32
FILETYPE VFT_DLL
FILESUBTYPE VFT2_UNKNOWN
FILEFLAGSMASK 0x00000000
FILEFLAGS 0x00000000
{

BLOCK "StringFileInfo"
{
BLOCK "040901b5"
{
VALUE "Comments", "DocIt plugin for Notepad++"
VALUE "CompanyName", "Kapil Ratnani"
VALUE "FileDescription", "Notepad++ plugin"
VALUE "FileVersion", "0.5 Alpha"
VALUE "InternalName", "DocIt"
VALUE "OriginalFilename", "NppDocIt.dll"
VALUE "ProductName", "DocIt plugin for Notepad++"
VALUE "ProductVersion", "0.5 Alpha"
VALUE "SpecialBuild", "UNICODE"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0409, 0x01B5
}
}

0 comments on commit d7754ac

Please sign in to comment.