UniversalIndentGUI 1.2.0
UniversalIndentGUI_NPPDialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002 *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
00003 *   thomas-schweitzer(at)arcor.de                                         *
00004 *                                                                         *
00005 *   This program is free software; you can redistribute it and/or modify  *
00006 *   it under the terms of the GNU General Public License version 2.0 as   *
00007 *   published by the Free Software Foundation.                            *
00008 *                                                                         *
00009 *   This program is distributed in the hope that it will be useful,       *
00010 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012 *   GNU General Public License for more details.                          *
00013 *                                                                         *
00014 *   You should have received a copy of the GNU General Public License     *
00015 *   along with this program in the file LICENSE.GPL; if not, write to the *
00016 *   Free Software Foundation, Inc.,                                       *
00017 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018 ***************************************************************************/
00019 
00020 
00021 #include "UniversalIndentGUI_NPPDialog.h"
00022 #include "resource.h"
00023 
00024 
00025 /************************* define here your toolbar layout *********************/
00026 
00027 /* messages needs to be added in resource.h */
00028 
00029 static ToolBarButtonUnit toolBarIcons[] = {
00030     {IDM_EX_UNDO, -1, -1, -1, -1, 0 /* TBSTYLE_DROPDOWN */},
00031     {IDM_EX_REDO, -1, -1, -1, -1, 0 /* TBSTYLE_DROPDOWN */}
00032 };
00033 
00034 static int stdIcons[] = {IDB_EX_UNDO, IDB_EX_REDO};
00035 
00039 static LPTSTR szToolTip[5] = {
00040     "Undo",
00041     "Redo"
00042 };
00043 
00044 void UniversalIndentGUI_NPPDialog::GetNameStrFromCmd(UINT resID, LPTSTR tip) {
00045     strcpy(tip, szToolTip[resID - IDM_EX_UNDO]);
00046 }
00047 /**************************** end of toolbar layout ****************************/
00048 
00049 
00050 
00051 
00052 /* Note: Within constructor send dialog IDD to DockingDlgInterface class */
00053 UniversalIndentGUI_NPPDialog::UniversalIndentGUI_NPPDialog(void) : DockingDlgInterface(IDD_DOCK_DLG), _hEdit(NULL), _pPluginProp(NULL), indentHandler(NULL) {
00054 }
00055 
00056 UniversalIndentGUI_NPPDialog::~UniversalIndentGUI_NPPDialog(void) {
00057 }
00058 
00059 
00060 void UniversalIndentGUI_NPPDialog::init(HINSTANCE hInst, NppData nppData, tPluginProp *pPluginProp) {
00061     _nppData = nppData;
00062     _pPluginProp = pPluginProp;
00063     DockingDlgInterface::init(hInst, nppData._nppHandle);
00064 }
00065 
00066 
00067 void UniversalIndentGUI_NPPDialog::doDialog(bool willBeShown) {
00068     if (!isCreated()) {
00069         create(&_data);
00070 
00071         // define the default docking behaviour
00072         _data.uMask         = DWS_DF_CONT_RIGHT | DWS_ICONTAB;
00073         _data.hIconTab      = (HICON) ::LoadImage(_hInst, MAKEINTRESOURCE(IDI_TABBAR), IMAGE_ICON, 0, 0, LR_LOADMAP3DCOLORS | LR_LOADTRANSPARENT);
00074         _data.pszModuleName = getPluginFileName();
00075         _data.dlgID         = TOGGLE_DOCKABLE_WINDOW_INDEX;
00076         ::SendMessage(_hParent, NPPM_DMMREGASDCKDLG, 0, (LPARAM)&_data);
00077     }
00078     display(willBeShown);
00079 }
00080 
00081 
00082 BOOL CALLBACK UniversalIndentGUI_NPPDialog::run_dlgProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam) {
00083     switch (Message)
00084     {
00085         case WM_INITDIALOG :
00086         {
00087             InitialDialog();
00088             break;
00089         }
00090         case WM_SIZE :
00091         case WM_MOVE :
00092         {
00093             RECT    rc          = {0};
00094 
00095             /* test if in side or if docked on top or bottom */
00096             if ((_iDockedPos == CONT_LEFT) || (_iDockedPos == CONT_RIGHT)) {
00097                 getClientRect(rc);
00098 
00099                 /* set position of toolbar */
00100                 _ToolBar.reSizeTo(rc);
00101                 _Rebar.reSizeTo(rc);
00102 
00103                 /* set position of edit control */
00104                 rc.top     += 26;
00105                 rc.bottom  -= 26;
00106                 ::SetWindowPos(_hEdit, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
00107             }
00108             else{
00109                 getClientRect(rc);
00110                 rc.right = rc.left + 23;
00111 
00112                 /* set position of toolbar */
00113                 _ToolBar.reSizeTo(rc);
00114                 _Rebar.reSizeTo(rc);
00115 
00116                 /* set position of edit control */
00117                 getClientRect(rc);
00118                 rc.left     += 23;
00119                 rc.right    -= 23;
00120                 ::SetWindowPos(_hEdit, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW);
00121             }
00122             break;
00123         }
00124         case WM_COMMAND :
00125         {
00126             if ((HWND)lParam == _ToolBar.getHSelf()) {
00127                 tb_cmd(LOWORD(wParam));
00128                 return TRUE;
00129             }
00130             break;
00131         }
00132         case WM_NOTIFY :
00133         {
00134             LPNMHDR     nmhdr = (LPNMHDR)lParam;
00135 
00136             if (nmhdr->hwndFrom == _hEdit) {
00137                 /* do what ever you need */
00138             }
00139             else if (nmhdr->code == TTN_GETDISPINFO) {
00140                 /* tooltip request of toolbar */
00141 
00142                 LPTOOLTIPTEXT lpttt;
00143 
00144                 lpttt = (LPTOOLTIPTEXT)nmhdr;
00145                 lpttt->hinst = _hInst;
00146 
00147                 // Specify the resource identifier of the descriptive
00148                 // text for the given button.
00149                 int resId = int(lpttt->hdr.idFrom);
00150 
00151                 TCHAR   tip[16];
00152                 GetNameStrFromCmd(resId, tip);
00153                 lpttt->lpszText = tip;
00154                 return TRUE;
00155             }
00156             else {
00157                 /* parse all other notifications to docking dialog interface */
00158 
00159                 return DockingDlgInterface::run_dlgProc(hWnd, Message, wParam, lParam);
00160             }
00161             break;
00162         }
00163         case WM_DESTROY :
00164         {
00165             /* destroy icon of tab */
00166             ::DestroyIcon(_data.hIconTab);
00167             break;
00168         }
00169         default :
00170             return DockingDlgInterface::run_dlgProc(hWnd, Message, wParam, lParam);
00171     }
00172 
00173     return FALSE;
00174 }
00175 
00176 void UniversalIndentGUI_NPPDialog::InitialDialog(void) {
00177     /* get handle of dialogs */
00178     _hEdit          = ::GetDlgItem(_hSelf, IDC_EDIT_TEMP);
00179 
00180     /* create toolbar */
00181     _ToolBar.init(_hInst, _hSelf, 16, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit), true, stdIcons, sizeof(stdIcons)/sizeof(int));
00182     _ToolBar.display();
00183     _Rebar.init(_hInst, _hSelf, &_ToolBar);
00184     _Rebar.display();
00185 }
00186 
00187 void UniversalIndentGUI_NPPDialog::tb_cmd(UINT message) {
00188     switch (message)
00189     {
00190         case IDM_EX_UNDO :
00191         {
00192             ::SendMessage(_hEdit, WM_UNDO, 0, 0);
00193             break;
00194         }
00195         case IDM_EX_REDO :
00196         {
00197             TCHAR   pszText[256];
00198             _stprintf(pszText, "Value1 = %d\r\nValue2 = %d\r\n\r\n", _pPluginProp->iValue1, _pPluginProp->iValue2);
00199             ::SendMessage(_hEdit, WM_SETTEXT, 0, (LPARAM)pszText);
00200             break;
00201         }
00202         default :
00203             break;
00204     }
00205 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines