Skip to content

Commit

Permalink
[NEW_FEATURE] Add Character Insertion Panel.
Browse files Browse the repository at this point in the history
- Notepad-plus svn trunk @ 745
  • Loading branch information
donho committed Apr 13, 2011
1 parent ce59722 commit c532059
Show file tree
Hide file tree
Showing 16 changed files with 449 additions and 6 deletions.
2 changes: 2 additions & 0 deletions PowerEditor/src/MISC/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const bool dirDown = false;
#define generic_strtok wcstok
#define generic_strftime wcsftime
#define generic_fprintf fwprintf
#define generic_sprintf swprintf
#define generic_sscanf swscanf
#define generic_fopen _wfopen
#define generic_fgets fgetws
Expand All @@ -61,6 +62,7 @@ const bool dirDown = false;
#define generic_strtok strtok
#define generic_strftime strftime
#define generic_fprintf fprintf
#define generic_sprintf sprintf
#define generic_sscanf sscanf
#define generic_fopen fopen
#define generic_fgets fgets
Expand Down
35 changes: 34 additions & 1 deletion PowerEditor/src/Notepad_plus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(N
_recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false),
_linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false),
_autoCompleteMain(&_mainEditView), _autoCompleteSub(&_subEditView), _smartHighlighter(&_findReplaceDlg),
_isFileOpening(false), _rememberThisSession(true)
_isFileOpening(false), _rememberThisSession(true), _pAnsiCharPanel(NULL)
{
ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange));

Expand Down Expand Up @@ -142,6 +142,9 @@ Notepad_plus::~Notepad_plus()
(WcharMbcsConvertor::getInstance())->destroyInstance();
if (_pTrayIco)
delete _pTrayIco;

if (_pAnsiCharPanel)
delete _pAnsiCharPanel;
}


Expand Down Expand Up @@ -4556,3 +4559,33 @@ bool Notepad_plus::reloadLang()
_lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding());
return true;
}

void Notepad_plus::launchAnsiCharPanel()
{
if (!_pAnsiCharPanel)
{
_pAnsiCharPanel = new AnsiCharPanel();

_pAnsiCharPanel->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), &_pEditView);

tTbData data = {0};
_pAnsiCharPanel->create(&data);

::SendMessage(_pPublicInterface->getHSelf(), NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_pAnsiCharPanel->getHSelf());
// define the default docking behaviour
data.uMask = DWS_DF_CONT_BOTTOM | DWS_ICONTAB | DWS_ADDINFO;
data.hIconTab = (HICON)::LoadImage(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_FIND_RESULT_ICON), IMAGE_ICON, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
//data.pszAddInfo = _findAllResultStr;

data.pszModuleName = TEXT("dummy");

// the dlgDlg should be the index of funcItem where the current function pointer is
// in this case is DOCKABLE_DEMO_INDEX
data.dlgID = 0;
::SendMessage(_pPublicInterface->getHSelf(), NPPM_DMMREGASDCKDLG, 0, (LPARAM)&data);
}
//::SendMessage(_pAnsiCharPanel->getHSelf(), WM_SIZE, 0, 0);

_pAnsiCharPanel->display();
}

5 changes: 4 additions & 1 deletion PowerEditor/src/Notepad_plus.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#endif //SIZE_DLG_H

#include "localization.h"
#include "ansiCharPanel.h"

#define MENU 0x01
#define TOOLBAR 0x02
Expand Down Expand Up @@ -165,7 +166,7 @@ struct VisibleGUIConf {

class FileDialog;
class Notepad_plus_Window;

class AnsiCharPanel;

class Notepad_plus {

Expand Down Expand Up @@ -387,6 +388,7 @@ friend class Notepad_plus_Window;
bool _rememberThisSession; // always true. except -nosession is indicated on the launch time


AnsiCharPanel *_pAnsiCharPanel;

BOOL notify(SCNotification *notification);
void specialCmd(int id);
Expand Down Expand Up @@ -570,6 +572,7 @@ friend class Notepad_plus_Window;

void wsTabConvert(bool whichWay);
void doTrim(trimOp whichPart);
void launchAnsiCharPanel();
};


Expand Down
1 change: 1 addition & 0 deletions PowerEditor/src/Notepad_plus.rc
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ BEGIN
MENUITEM SEPARATOR
MENUITEM "Column Mode...", IDM_EDIT_COLUMNMODETIP
MENUITEM "Column Editor...", IDM_EDIT_COLUMNMODE
MENUITEM "Character Panel", IDM_EDIT_CHAR_PANEL
MENUITEM SEPARATOR
MENUITEM "Set Read-Only", IDM_EDIT_SETREADONLY
MENUITEM "Clear Read-Only Flag", IDM_EDIT_CLEARREADONLY
Expand Down
6 changes: 6 additions & 0 deletions PowerEditor/src/NppCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ void Notepad_plus::command(int id)
}
break;

case IDM_EDIT_CHAR_PANEL:
{
launchAnsiCharPanel();
}
break;

case IDM_EDIT_DELETE:
_pEditView->execute(WM_CLEAR);
break;
Expand Down
2 changes: 1 addition & 1 deletion PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ BOOL CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)

_emailLink.init(_hInst, _hSelf);
//_emailLink.create(::GetDlgItem(_hSelf, IDC_AUTHOR_NAME), TEXT("mailto:don.h@free.fr"));
_emailLink.create(::GetDlgItem(_hSelf, IDC_AUTHOR_NAME), TEXT("http://notepad-plus-plus.org/members"));
_emailLink.create(::GetDlgItem(_hSelf, IDC_AUTHOR_NAME), TEXT("http://notepad-plus-plus.org/contributors"));

_pageLink.init(_hInst, _hSelf);
_pageLink.create(::GetDlgItem(_hSelf, IDC_HOME_ADDR), TEXT("http://notepad-plus-plus.org/"));
Expand Down
118 changes: 118 additions & 0 deletions PowerEditor/src/WinControls/AnsiCharPanel/ListView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#include "precompiledHeaders.h"
#include "ListView.h"


void ListView::init(HINSTANCE hInst, HWND parent)
{
Window::init(hInst, parent);
INITCOMMONCONTROLSEX icex;

// Ensure that the common control DLL is loaded.
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LISTVIEW_CLASSES;
InitCommonControlsEx(&icex);

// Create the list-view window in report view with label editing enabled.
int listViewStyles = LVS_REPORT | LVS_NOSORTHEADER\
| LVS_SINGLESEL | LVS_AUTOARRANGE\
| LVS_SHAREIMAGELISTS;

_hSelf = ::CreateWindow(WC_LISTVIEW,
TEXT(""),
WS_CHILD | listViewStyles,
0,
0,
0,
0,
_hParent,
(HMENU) NULL,
hInst,
NULL);
if (!_hSelf)
{
throw std::runtime_error("ListView::init : CreateWindowEx() function return null");
}

::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this);
_defaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticProc));

DWORD exStyle = ListView_GetExtendedListViewStyle(_hSelf);
exStyle |= LVS_EX_FULLROWSELECT | LVS_EX_BORDERSELECT ;
ListView_SetExtendedListViewStyle(_hSelf, exStyle);

LVCOLUMN lvColumn;
lvColumn.mask = LVCF_TEXT|LVCF_WIDTH;
lvColumn.cx = 45;

lvColumn.pszText = TEXT("Value");
ListView_InsertColumn(_hSelf, 0, &lvColumn);

lvColumn.pszText = TEXT("Char");
ListView_InsertColumn(_hSelf, 1, &lvColumn);

lvColumn.pszText = TEXT("Ctrl char");
lvColumn.cx = 90;
ListView_InsertColumn(_hSelf, 2, &lvColumn);

//ListView_SetImageList(_hSelf, hImaLst, LVSIL_SMALL);

//ListView_SetItemState(_hSelf, _currentIndex, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
//ListView_SetBkColor(_hSelf, lightYellow);
}

void ListView::resetValues(int codepage)
{
ListView_DeleteAllItems(_hSelf);
for (int i = 0 ; i < 256 ; i++)
{
LVITEM item;
item.mask = LVIF_TEXT;
TCHAR num[8];
generic_sprintf(num, TEXT("%d"), i);
item.pszText = num;
item.iItem = i;
item.iSubItem = 0;
ListView_InsertItem(_hSelf, &item);

char ascii[8];
ascii[0] = (unsigned char)i;
ascii[1] = '\0';
#ifdef UNICODE
wchar_t wCharStr[10];
MultiByteToWideChar(codepage, 0, ascii, -1, wCharStr, sizeof(wCharStr));
ListView_SetItemText(_hSelf, i, 1, wCharStr);
#else
codepage = 0; // make it compile in ANSI Release mode
ListView_SetItemText(_hSelf, i, 1, ascii);
#endif
}
}
void ListView::destroy()
{
::DestroyWindow(_hSelf);
_hSelf = NULL;
}


LRESULT ListView::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
return ::CallWindowProc(_defaultProc, hwnd, Message, wParam, lParam);
}

44 changes: 44 additions & 0 deletions PowerEditor/src/WinControls/AnsiCharPanel/ListView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//this file is part of notepad++
//Copyright (C)2003 Don HO ( donho@altern.org )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

#ifndef LISTVIEW_H
#define LISTVIEW_H

#include "window.h"

class ListView : public Window
{
public:
ListView() : Window() {};

virtual ~ListView() {};
virtual void init(HINSTANCE hInst, HWND hwnd);
virtual void destroy();

void resetValues(int codepage = 0);

protected:
WNDPROC _defaultProc;
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);

static LRESULT CALLBACK staticProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) {
return (((ListView *)(::GetWindowLongPtr(hwnd, GWL_USERDATA)))->runProc(hwnd, Message, wParam, lParam));
};
};


#endif // LISTVIEW_H
94 changes: 94 additions & 0 deletions PowerEditor/src/WinControls/AnsiCharPanel/ansiCharPanel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
this file is part of notepad++
Copyright (C)2011 Don HO <donho@altern.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a Copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include "precompiledHeaders.h"
#include "ansiCharPanel.h"
#include "ScintillaEditView.h"

BOOL CALLBACK AnsiCharPanel::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
{
TCHAR asciiStr[2];
asciiStr[1] = '\0';

_listView.init(_hInst, _hSelf);
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
_listView.resetValues(codepage==-1?0:codepage);
_listView.display();

return TRUE;
}

case WM_NOTIFY:
{
switch (((LPNMHDR)lParam)->code)
{
case NM_DBLCLK:
{
//printStr(TEXT("OK"));
LPNMITEMACTIVATE lpnmitem = (LPNMITEMACTIVATE) lParam;
int i = lpnmitem->iItem;

if (i == -1)
return TRUE;

char charStr[2];
charStr[0] = (unsigned char)i;
charStr[1] = '\0';
wchar_t wCharStr[10];
char multiByteStr[10];
int codepage = (*_ppEditView)->getCurrentBuffer()->getEncoding();
if (codepage == -1)
{
multiByteStr[0] = charStr[0];
multiByteStr[1] = charStr[1];
}
else
{
MultiByteToWideChar(codepage, 0, charStr, -1, wCharStr, sizeof(wCharStr));
WideCharToMultiByte(CP_UTF8, 0, wCharStr, -1, multiByteStr, sizeof(multiByteStr), NULL, NULL);
}
(*_ppEditView)->execute(SCI_REPLACESEL, 0, (LPARAM)"");
int len = (i < 128)?1:strlen(multiByteStr);
(*_ppEditView)->execute(SCI_ADDTEXT, len, (LPARAM)multiByteStr);

return TRUE;
}
default:
break;
}
}
return TRUE;

case WM_SIZE:
{
int width = LOWORD(lParam);
int height = HIWORD(lParam);
::MoveWindow(_listView.getHSelf(), 0, 0, width, height, TRUE);
break;
}

default :
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}
return DockingDlgInterface::run_dlgProc(message, wParam, lParam);
}

0 comments on commit c532059

Please sign in to comment.