// Open the keysword editor. void KeywordEdit::Edit( ClsWindow& Parent, LPPARSER pParser ) { // Save parser pointer. m_pParser = pParser; // Save current case setting. m_bCase = pParser->bCaseOn; // Convert the hash table into a list. if ( Hash2List( &m_KeyLst, pParser )) { // Open the dialog. if ( DoModal( Parent, IDD_KEYWORDS ) <= 0 ) // Free the list. FreeKeyList( &m_KeyLst ); else { // Use the changes. if ( UseKeywords( &m_KeyLst ) == FALSE ) // Error... MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); // Save case setting. pParser->bCaseOn = m_bCase; // Changes where made. pSettings->Changed( pParser ); } } else // Error... MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); }
LRESULT CSidebarDlg::OnInitDialog( PROPSHEETPAGE *p ) { m_FolderHeader.Attach(GetDlgItemHandle(IDC_FOLDER_HEADER)); TCHAR szFolder[MAX_PATH]; GetLogFolder(szFolder, MAX_PATH); m_FolderLink.Attach(GetDlgItemHandle( IDC_LOGFOLDER_LINK )); m_FolderLink.SetWindowText(szFolder); m_FolderLink.ShowToolTip(); m_FolderLink.VisitedColor() = m_FolderLink.NormalColor(); m_SmallButton.Attach(GetDlgItemHandle( IDB_SMALL_SIDEBAR )); m_SmallButton.SetXPStyle(); m_SmallButton.Tip() = ClsString(_T("Show/Hide Sidebar (Ctrl+S)")); m_SmallButton.ShowToolTip(); m_SidebarHeader.Attach( GetDlgItemHandle( IDC_SIDEBAR_HEADER )); m_SidebarHeader.Gradient() = TRUE; m_SidebarHeader.BackgroundColor() = ::GetSysColor( COLOR_INACTIVECAPTION ); m_SidebarHeader.BackgroundGradient() = ::GetSysColor( COLOR_GRADIENTINACTIVECAPTION ); m_FilterText.Attach(GetDlgItemHandle(IDC_FILTER_TEXT)); m_FilterBox.Attach(GetDlgItemHandle(IDC_FILTER_BOX)); m_FilterButton.Attach(GetDlgItemHandle(IDC_FILTER_BUTTON)); m_ChangeFolderBtn.Attach(GetDlgItemHandle(IDC_CHANGE_FOLDER_BUTTON)); m_Animate.Attach(GetDlgItemHandle( IDC_ANIMATE )); m_Animate.Open((LPTSTR)IDR_DOWNLOAD_AVI); m_Animate.Play(); m_LogFileListCtrl.Attach(GetDlgItemHandle( IDC_LOGFILE_LIST )); return ClsDialog::OnInitDialog(p); }
// Refresh page contents. void SyntaxPage::RefreshData( LPPARSER pParser ) { _ASSERT_VALID( pParser ); // Save parser. m_pParser = pParser; // Setup lists. m_Blocks.SetParser( pParser ); m_Common.SetParser( pParser ); m_Blocks.SetBlockList(); m_Common.SetCommonList(); // Setup other controls. m_Escape.SetWindowText( pParser->cEscape ? ( LPCTSTR )ClsString( pParser->cEscape ) : NULL ); m_Syntax.SetCheck( pParser->bSyntaxColoring ? BST_CHECKED : BST_UNCHECKED ); // Setup the toolbar. SetupToolbar(); }
// Control Panel callback function. LONG WINAPI CALLBACK CPlApplet( HWND hWnd, UINT uMsg, LPARAM lParam1, LPARAM lParam2 ) { // What do they want... switch ( uMsg ) { case CPL_INIT: // Load brainchild.dll if (( hBrainchild = ::LoadLibrary( _T( "brainchild.dll" ))) != NULL ) { // Create memory pool. if (( pParserPool = ::GetMemoryPool( 4096L )) != NULL ) { // Initialize lists. NewList(( LPLIST )&plParsers ); // Loadup parser files. if ( ::LoadParserFiles( pParserPool, &plParsers ) == TRUE ) return TRUE; else MessageBox( hWnd, ClsString( MAKEINTRESOURCE( IDS_NO_SETTINGS )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); // Free the memory pool. ::FreeMemoryPool( pParserPool, TRUE ); } else MessageBox( hWnd, ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); // Unload the library. ::FreeLibrary( hBrainchild ); } else MessageBox( hWnd, ClsString( MAKEINTRESOURCE( IDS_NO_BRAINCHILD )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); return FALSE; case CPL_GETCOUNT: // We only support one dialog... return 1; case CPL_INQUIRE: { LPCPLINFO lpCPlInfo = ( LPCPLINFO )lParam2; // Setup the Control Panel // information... lpCPlInfo->idIcon = IDI_MAIN; lpCPlInfo->idInfo = IDS_CPL_INFO; lpCPlInfo->idName = IDS_CPL_NAME; break; } case CPL_DBLCLK: { // Create a dialog object. pSettings = new SettingsDialog; // Launch dialog box. if ( hWnd ) { ClsWindow Wnd; Wnd.Attach( hWnd ); pSettings->DoModal( Wnd, IDD_MAIN ); } else // Popup the dialog. pSettings->DoModal( IDD_MAIN ); break; } case CPL_STOP: // Free the parser list. FreeParserList( pParserPool, &plParsers ); // Free the memory pool. FreeMemoryPool( pParserPool, TRUE ); // Unload the library. FreeLibrary( hBrainchild ); // Free the dialog object. delete pSettings; break; case CPL_EXIT: break; default: break; } return 0; }
// Save page/parser contents. BOOL KeyboardPage::SavePage( ClsStdioFile *pFile, LPPARSER pParser ) { try { // Write comment. pFile->PrintF( ClsString( MAKEINTRESOURCE( IDS_COMMENT_KEYS ))); // Go through the key hashes. LPHASH pHash; LPCNODE pCNode; TCHAR szKeyString[ 64 ]; for ( int i = 0; i < HASHSIZE; i++ ) { for ( pHash = pParser->aHash[ i ]; pHash; pHash = pHash->lpNext ) { // Convert code and qualifier into // a string. ::CodeQual2Str( pHash->cCode, pHash->cQual, szKeyString, 64 ); // Write the key identifier. pFile->PrintF( _T( "Key=%s\n" ), szKeyString ); // Write the command nodes. for ( pCNode = pHash->lpCommands->lpFirst; pCNode->lpNext; pCNode = pCNode->lpNext ) { // What is the command type? switch ( pCNode->nType ) { case CTYPE_HARDCODED: // Write command and it's ID. pFile->PrintF( _T( "\tHardcoded=%ld\n" ), ::FindCommandID( pCNode->lpFunc )); break; case CTYPE_RUN: // Write command and it's // string. pFile->PrintF( _T( "\tRun=%s\n" ), pCNode->pcStr ); break; case CTYPE_TEXT: // Write command and it's // string. pFile->PrintF( _T( "\tInsertText=%s\n" ), pCNode->pcStr ); break; case CTYPE_SHELLOPEN: // Write the command and it's // string. pFile->PrintF( _T( "\tOpen=%s\n" ), pCNode->pcStr ); break; case CTYPE_END: break; } } // End the key description. pFile->PrintF( _T( "EndKey\n" ) ); } } } catch ( ClsException& e ) { // Error... UNREFERENCED_PARAMETER( e ); return FALSE; } return TRUE; }
// WM_COMMAND handler. LRESULT KeyboardPage::OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl ) { // What's up? switch ( nCtrlID ) { case EditToolbar::ETID_NEW: // Command toolbar? if ( hWndCtrl == m_ComTools ) { // Obtain button rectangle. ClsRect rc; m_ComTools.GetItemRect( 0, rc ); // Convert rectangle to screen // coordinates. m_ComTools.ClientToScreen( rc ); // Show the menu. ::TrackPopupMenuEx( m_Menu,//*m_Menu.GetSubMenu( 0 ), TPM_LEFTALIGN, rc.Left(), rc.Bottom(), GetSafeHWND(), NULL ); } else { // Show the key recorder. KeyRec kr; ClsString str; if ( kr.KeyRecord( *GetParent(), str )) AddKeyMapping( str ); } return 0; case EditToolbar::ETID_DELETE: // Command toolbar? if ( hWndCtrl == m_ComTools ) { // Get current selection. LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel()); if ( pCNode != ( LPCNODE )LB_ERR ) { // Save selection position. int nSel = m_Commands.GetCurSel(); int nPos = nSel; int nMax = m_Commands.GetCount(); // Select the next or previous // entry. if ( nSel == nMax - 1 && nSel ) nSel--; else nSel++; // Select the new item m_Commands.SetCurSel( nSel ); // Remove the node from the listview. m_Commands.DeleteString( nPos ); // Remove it from the command list. Remove(( LPNODE )pCNode ); // Free the node // data. if ( pCNode->nType != CTYPE_HARDCODED ) ::FreePooled( pParserPool, pCNode->pcStr ); // And the node itself. ::FreePooled( pParserPool, pCNode ); // Setup GUI. SetupControls(); pSettings->Changed( m_pParser ); } return 0; } else { // Get the key descriptor. TCHAR szKeyString[ 64 ]; int nSel = m_Keys.GetCurSel(), nMax = m_Keys.GetCount(); if ( nSel != LB_ERR ) { if ( m_Keys.GetText( nSel, szKeyString ) != LB_ERR ) { // Convert to a code and qualifier. TCHAR cCode, cQual; if ( ::Str2CodeQual( szKeyString, &cCode, &cQual )) { // Remove the hash. This will automatically destroy // the command-list aswell. ::RemHash( pParserPool, m_pParser->aHash, cCode, cQual ); // Remove it from the listview. m_Keys.DeleteString( nSel ); // Was it the last one? if ( nSel == nMax - 1 ) nSel--; // Select the next or previous key. m_Keys.SetCurSel( nSel ); SendMessage( WM_COMMAND, MAKEWPARAM( IDC_KEYS, LBN_SELCHANGE ), ( LPARAM )m_Keys.GetSafeHWND()); // Changes made... pSettings->Changed( m_pParser ); } } } } return 0; case EditToolbar::ETID_UP: { // Valid node? LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel()); if ( pCNode != ( LPCNODE )LB_ERR ) { // Get it's predecessor. LPCNODE pCPrev = pCNode->lpPrev; // Swap both data entries. CNODE cTemp; cTemp.nType = pCPrev->nType; cTemp.uCommand = pCPrev->uCommand; pCPrev->nType = pCNode->nType; pCPrev->uCommand = pCNode->uCommand; pCNode->nType = cTemp.nType; pCNode->uCommand = cTemp.uCommand; // Select the previous item which // in fact is the already selected // item. m_Commands.SetCurSel( m_Commands.GetCurSel() - 1 ); SetupControls(); pSettings->Changed( m_pParser ); return 0; } } case EditToolbar::ETID_DOWN: { // Valid node? LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel()); if ( pCNode != ( LPCNODE )LB_ERR ) { // Get it's successor. LPCNODE pCNext = pCNode->lpNext; // Swap both data entries. CNODE cTemp; cTemp.nType = pCNext->nType; cTemp.uCommand = pCNext->uCommand; pCNext->nType = pCNode->nType; pCNext->uCommand = pCNode->uCommand; pCNode->nType = cTemp.nType; pCNode->uCommand = cTemp.uCommand; // Select the next item which // in fact is the already selected // item. m_Commands.SetCurSel( m_Commands.GetCurSel() + 1 ); SetupControls(); pSettings->Changed( m_pParser ); return 0; } } case IDS_INSERT: CreateNode( CTYPE_TEXT, ( LPVOID )( LPCTSTR )ClsString( MAKEINTRESOURCE( IDS_NEWINSERT ))); return 0; case IDS_HARDCODED: CreateNode( CTYPE_HARDCODED, ( LPVOID )( ::GetCommandTable()->nCommandID )); return 0; case IDS_RUN: CreateNode( CTYPE_RUN, ( LPVOID )( _T( "Calc.exe" ))); return 0; case IDS_OPEN: CreateNode( CTYPE_SHELLOPEN, ( LPVOID )( _T( "ReadMe.txt" ))); return 0; case IDC_KEYS: if ( nNotifyCode == LBN_SELCHANGE ) { // Get the current selection. LPHASH pSel = GetSelection(); if ( pSel ) { // Clear the contents of the command list. m_Commands.ResetContent(); // Add commands. LPCNODE pNode; for ( pNode = pSel->lpCommands->lpFirst; pNode->lpNext; pNode = pNode->lpNext ) m_Commands.AddString(( LPCTSTR )pNode ); } } // Setup controls. SetupControls(); return 0; case IDC_COMMANDS: // Double-click? if ( nNotifyCode == LBN_DBLCLK ) { // Find the command node. LPCNODE pCNode = ( LPCNODE )m_Commands.GetItemData( m_Commands.GetCurSel()); if ( pCNode != ( LPCNODE )LB_ERR ) { // What's the type? switch ( pCNode->nType ) { case CTYPE_HARDCODED: { // Open the editor. Hardcoded h; if ( h.Select( *GetParent(), pCNode )) { // Refresh list. m_Commands.Invalidate(); pSettings->Changed( m_pParser ); } break; } case CTYPE_TEXT: { // Open the editor. TextInsert ti; HICON hIcon = ImageList_GetIcon( m_hImages, 1, ILD_NORMAL ); if ( ti.Edit( *GetParent(), pCNode, hIcon )) { // Refresh list. m_Commands.Invalidate(); pSettings->Changed( m_pParser ); } if ( hIcon ) ::DestroyIcon( hIcon ); return 0; } case CTYPE_RUN: case CTYPE_SHELLOPEN: { // Open the editor. Run r; if ( r.Edit( *GetParent(), pCNode )) { // Refresh list. m_Commands.Invalidate(); pSettings->Changed( m_pParser ); } } } } } else // Setup GUI. SetupControls(); return 0; } // Pass to the base class. return Page::OnCommand( nNotifyCode, nCtrlID, hWndCtrl ); }
// Create a command list node. void KeyboardPage::CreateNode( int nType, LPVOID lpvData ) { // Get the currently selected keyboard hash. LPHASH pHash = GetSelection(); LPCNODE pCNode = NULL; if ( pHash ) { // Allocate node. pCNode = ( LPCNODE )::AllocPooled( pParserPool, sizeof( CNODE )); if ( pCNode != NULL ) { // Setup type. pCNode->nType = nType; // Hardcoded? if ( nType == CTYPE_HARDCODED ) // Setup function. pCNode->lpFunc = ::FindCommand(( int )lpvData ); else { // Allocate string copy. pCNode->pcStr = ::CopyStringPool( pParserPool, ( LPCTSTR )lpvData ); if ( pCNode->pcStr == NULL ) { // Failure. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); ::FreePooled( pParserPool, pCNode ); pCNode = NULL; } } } else MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); } // Still there? if ( pCNode ) { // Add the node to the list. AddTail(( LPLIST )pHash->lpCommands, ( LPNODE )pCNode ); // Add it to the listview. int nSel = m_Commands.AddString(( LPCTSTR )pCNode ); if ( nSel != LB_ERR ) { // Select the entry. m_Commands.SetCurSel( nSel ); // Edit the node. SendMessage( WM_COMMAND, MAKEWPARAM( IDC_COMMANDS, LBN_DBLCLK ), ( LPARAM )m_Commands.GetSafeHWND()); // Changes have been made. pSettings->Changed( m_pParser ); SetupControls(); } else { // Show out of memory error. Guess this should be the // only reason this could fail. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); // Free the node and // it's string. if ( nType != CTYPE_HARDCODED ) ::FreePooled( pParserPool, pCNode->pcStr ); ::FreePooled( pParserPool, pCNode ); } } }
// Add a keyboard mapping. void KeyboardPage::AddKeyMapping( ClsString strKey ) { // Convert the string to a code and qualifier. TCHAR cCode, cQual; if ( ::Str2CodeQual( strKey, &cCode, &cQual ) == FALSE ) return; // Is the hash for this key already defined? LPHASH lpHash; for ( lpHash = m_pParser->aHash[ cCode & HASHMASK ]; lpHash; lpHash = lpHash->lpNext ) { // Is this the one? if ( lpHash->cCode == cCode && lpHash->cQual == cQual ) { // Find the entry in the // listview control. for ( int i = 0; ; i++ ) { // Find it in the list control. int nKey = m_Keys.FindString( 0, strKey ); if ( nKey != LB_ERR ) { // Select the key. m_Keys.SetCurSel( nKey ); SendMessage( WM_COMMAND, MAKEWPARAM( IDC_KEYS, LBN_SELCHANGE ), ( LPARAM )m_Keys.GetSafeHWND()); return; } } } } // Hash not available. Allocate // an empty command list. LPCLIST lpCList = ( LPCLIST )::AllocPooled( pParserPool, sizeof( CLIST )); if ( lpCList ) { // Initialize list. NewList(( LPLIST )lpCList ); // Add the hash to the hash table. if (( lpHash = ::AddHash( pParserPool, m_pParser->aHash, cCode, cQual, lpCList )) != NULL ) { // Add the string to the // listview control. int nAdd = m_Keys.AddString( strKey ); // Select it. m_Keys.SetCurSel( nAdd ); SendMessage( WM_COMMAND, MAKEWPARAM( IDC_KEYS, LBN_SELCHANGE ), ( LPARAM )m_Keys.GetSafeHWND()); // Changes made... pSettings->Changed( m_pParser ); return; } else // Emit an error. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); // De-allocate command list. ::FreePooled( pParserPool, lpCList ); } else // Emit an error. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); }
// Read keywords from a file. BOOL KeywordEdit::ReadKeywords( LPCTSTR pszFileName ) { // Get item position and data. int nPos = m_List.GetCurSel(); _ASSERT( nPos != LB_ERR ); LPKEYWORDS pKey = ( LPKEYWORDS )m_List.GetItemData( nPos ); ClsStdioFile file; // Valid node? if ( pKey != ( LPKEYWORDS )LB_ERR ) { try { // Open the file. file.Open( pszFileName, _T( "r" )); // Read the file... TCHAR szBuffer[ 1024 ], *pszPtr, *pszCopy; while (( pszPtr = file.GetS( szBuffer, 1024 )) != NULL ) { // Skip leading blanks. while ( _istspace( *pszPtr )) pszPtr++; // Also remove trailing // blanks. RemoveTrailingBlanks( pszPtr ); // Any text left? if ( _tcslen( pszPtr )) { // Create a copy of the // input string. if (( pszCopy = StringArrayCopy( pKey->lpaKeywords, pszPtr )) != NULL ) { // Add it to the array. if ( ::ArrayAdd( pKey->lpaKeywords, &pszCopy, 1 ) == FALSE ) { // Error... MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); break; } } else { // Error... MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); break; } } } // Close the input file. file.Close(); } catch( ClsException& ex ) { UNREFERENCED_PARAMETER( ex ); return FALSE; } } // Sort the array. ::ArraySort( pKey->lpaKeywords, ( COMPFUNC )CompareKeywords ); return TRUE; }
// WM_COMMAND message handler. LRESULT KeywordEdit::OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl ) { // What's the ID? switch ( nCtrlID ) { case EditToolbar::ETID_EDIT: { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Edit the keywords. KWEdit kwe; kwe.Edit( *this, pKW, this ); } return 0; } case EditToolbar::ETID_INSERT: { // Popup the file dialog. ClsFileDialog fd; fd.Filters() = _T( "Text files (*.txt)\0*.txt\0All files (*.*)\0*.*\0\0" ); fd.Caption().LoadString( IDS_INSERT_KEYWORDS ); if ( fd.DoModal( this, NULL, NULL, TRUE, OFN_FILEMUSTEXIST )) { // Get the selected filename. ClsString name; fd.GetName( 0, name ); // Read the file and add the read keywords // to the selected node. ReadKeywords( name ); // Make sure the keywords are // displayed. SendMessage( WM_COMMAND, MAKEWPARAM( IDC_LIST, LBN_SELCHANGE ), ( LPARAM )m_List.GetSafeHWND()); } return 0; } case EditToolbar::ETID_COLOR: { // Get the current selection. int nSel = m_List.GetCurSel(); // Only show the popup when there is // a valid selection. if ( nSel != LB_ERR ) { // Get the position of the selected entry. ClsRect rc; m_Tools.GetItemRect( 6, rc ); m_Tools.ClientToScreen( rc ); // Obtain the entry data. LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( nSel ); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Create the popup. The popup will automatically destroy // itself. new ClsColorPopup( ClsPoint( rc.Left(), rc.Bottom()), pKW->crColor, this, CS_FORE, NULL, ClsString( MAKEINTRESOURCE( IDS_CUSTOM )), NULL, TRUE, FALSE ); } } return 0; } case EditToolbar::ETID_BGCOLOR: { // Get the current selection. int nSel = m_List.GetCurSel(); // Only show the popup when there is // a valid selection. if ( nSel != LB_ERR ) { // Get the position of the selected entry. ClsRect rc; m_Tools.GetItemRect( 7, rc ); m_Tools.ClientToScreen( rc ); // Obtain the entry data. LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( nSel ); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Create the popup. The popup will automatically destroy // itself. new ClsColorPopup( ClsPoint( rc.Left(), rc.Bottom()), pKW->crBgColor, this, CS_BACK, ClsString( MAKEINTRESOURCE( IDS_TRANSPARENT )), ClsString( MAKEINTRESOURCE( IDS_CUSTOM )), NULL, TRUE, FALSE ); } } return 0; } case IDC_LIST: { // Selection change? if ( nNotifyCode == LBN_SELCHANGE ) { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { // Reset words content. m_KeyList.ResetContent(); // Add keywords. m_KeyList.SetRedraw( FALSE ); for ( int i = 0; i < ::ArrayGetSize( pKW->lpaKeywords ); i++ ) m_KeyList.AddString(( LPCTSTR )*(( LPTSTR * )::ArrayGetAt( pKW->lpaKeywords, i ))); m_KeyList.SetRedraw(); // Setup UI. SetupControls(); } } return 0; } case EditToolbar::ETID_DELETE: { // Valid entry? LPKEYWORDS pKW = ( LPKEYWORDS )m_List.GetItemData( m_List.GetCurSel()); if ( pKW != ( LPKEYWORDS )LB_ERR ) { ClsMessageBox mb; mb.Title() = ClsGetApp()->GetAppTitle(); mb.Buttons().LoadString( IDS_YESNO ); mb.Body().LoadString( IDS_KEYWORD_DELETE ); mb.Flags() = ClsMessageBox::MBF_ICONEXCLAMATION; // Sure? if ( mb.MsgBox( GetSafeHWND())) { // Save current selection // position. int nSel = m_List.GetCurSel(); int nPos = nSel; // Select the next one or // the previous one. if ( nSel == m_List.GetCount() - 1 ) nSel--; else nSel++; // Select the other item. m_List.SetCurSel( nSel ); // Setup UI. SetupControls(); // Clear the list contents m_KeyList.ResetContent(); // Reset selection. SendMessage( WM_COMMAND, MAKEWPARAM( IDC_LIST, LBN_SELCHANGE ), ( LPARAM )m_List.GetSafeHWND()); // Remove the selection. m_List.DeleteString( nPos ); // Remove the node. Remove(( LPNODE )pKW ); // Free the keyword array and the node. if ( pKW->lpaKeywords ) ::ArrayDelete( pKW->lpaKeywords ); ::FreePooled( pParserPool, pKW ); } } return 0; } case EditToolbar::ETID_NEW: { // Allocate a new node. LPKEYWORDS pKW = ( LPKEYWORDS )::AllocPooled( pParserPool, sizeof( KEYWORDS )); if ( pKW ) { // Allocate an array. pKW->lpaKeywords = ::ArrayCreate( 0, 500, sizeof( LPTSTR * )); if ( pKW->lpaKeywords ) { // Set color. pKW->crColor = ::GetSysColor( COLOR_WINDOWTEXT ); pKW->crBgColor = CLR_DEFAULT; // Add the node to the list. AddTail(( LPLIST )&m_KeyLst, ( LPNODE )pKW ); // Add it to the listview and select it. int nPos = m_List.AddString(( LPCTSTR )pKW ); m_List.SetCurSel( nPos ); // Clear the keywords list. m_KeyList.ResetContent(); // Setup UI. SetupControls(); return 0; } else ::FreePooled( pParserPool, pKW ); } // Error. MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); return 0; } case IDC_CASE: // Get value. m_bCase = ( BOOL )( m_Case.GetCheck() == BST_CHECKED ); return 0; case IDC_OK: // Return OK EndDialog( TRUE ); return 0; case IDC_CANCEL: // Cancel. EndDialog( FALSE ); return 0; } // Pass onto the base class. return ClsDialog::OnCommand( nNotifyCode, nCtrlID, hWndCtrl ); }
// Save page/parser contents. BOOL SyntaxPage::SavePage( ClsStdioFile *pFile, LPPARSER pParser ) { try { // Write colors comment. pFile->PrintF( ClsString( MAKEINTRESOURCE( IDS_COMMENT_COLORS ))); // Write colors. SaveColor( pFile, pParser, _T( "TextRGB=" ), CF_DEFAULT_TEXT, CARR_TEXT ); SaveColor( pFile, pParser, _T( "BackgroundRGB=" ), CF_DEFAULT_BACKGROUND, CARR_BACKGROUND ); SaveColor( pFile, pParser, _T( "BackgroundReadOnlyRGB=" ), CF_DEFAULT_BACKGROUND_RO, CARR_BACKGROUND_READONLY ); SaveColor( pFile, pParser, _T( "MarginRGB=" ), CF_DEFAULT_MARGIN, CARR_SELECTION_MARGIN ); SaveColor( pFile, pParser, _T( "NumberRGB=" ), CF_DEFAULT_NUMBER, CARR_NUMBER ); SaveColor( pFile, pParser, _T( "DelimiterRGB=" ), CF_DEFAULT_DELIMITER, CARR_DELIMITER ); SaveColor( pFile, pParser, _T( "SelectedTextRGB=" ), CF_DEFAULT_SELECTED_TEXT, CARR_SELECTED_TEXT ); SaveColor( pFile, pParser, _T( "SelectedBackgroundRGB=" ), CF_DEFAULT_SELECTED_BKGND, CARR_SELECTED_BKGND ); SaveColor( pFile, pParser, _T( "LineNumberRGB=" ), CF_DEFAULT_LINE_NUMBERS, CARR_LINE_NUMBERS ); SaveColor( pFile, pParser, _T( "BkgndLineNumberRGB=" ), CF_DEFAULT_LINE_NUMBERS_BKGND, CARR_BACKGROUND_LINE_NUMBERS ); SaveColor( pFile, pParser, _T( "BkgndNumberRGB="), CF_DEFAULT_BACKGROUND_NUMBER, CARR_BACKGROUND_NUMBER ); SaveColor( pFile, pParser, _T( "BkgndDelimiterRGB="), CF_DEFAULT_BACKGROUND_DELIMITER, CARR_BACKGROUND_DELIMITER ); SaveColor( pFile, pParser, _T( "BracketMatchRGB="), CF_DEFAULT_BRACKET_MATCH, CARR_BRACKET_MATCH ); SaveColor( pFile, pParser, _T( "HyperlinkRGB="), CF_DEFAULT_HYPERLINK, CARR_HYPERLINK ); SaveColor( pFile, pParser, _T( "BkgndHyperlinkRGB="), CF_DEFAULT_BACKGROUND_HYPERLINK, CARR_BACKGROUND_HYPERLINK ); SaveColor( pFile, pParser, _T( "ColumnOverflowRGB="), CF_DEFAULT_COLUMN_OVERFLOW, CARR_COLUMN_OVERFLOW ); // Write the screen and printer // fonts. pFile->PrintF( _T( "ScreenFont=%s,%ld,%ld,%ld,%ld,%ld\n" ), pParser->lfScreenFont.lfFaceName, pParser->lfScreenFont.lfHeight, pParser->lfScreenFont.lfWeight, pParser->lfScreenFont.lfCharSet, pParser->lfScreenFont.lfItalic, pParser->lfScreenFont.lfUnderline ); // Write general syntax coloring comment. pFile->PrintF( ClsString( MAKEINTRESOURCE( IDS_COMMENT_SYNTAXGENERAL ))); // Save general syntax coloring settings. if ( pParser->cEscape ) pFile->PrintF( _T( "Escape=%lc\n" ), pParser->cEscape ); pFile->PrintF( _T( "SyntaxColoring=%lc\n" ), pParser->bSyntaxColoring ? _T( 'Y' ) : _T( 'N' )); pFile->PrintF( _T( "Case=%lc\n" ), pParser->bCaseOn ? _T( 'Y' ) : _T( 'N' )); // Write blocks comment. pFile->PrintF( ClsString( MAKEINTRESOURCE( IDS_COMMENT_BLOCKS ))); // Write blocks. for ( int i = 0; i < ::ArrayGetSize( pParser->lpaBlocks ); i++ ) { // Get block. LPBLOCK lpBlock = ( LPBLOCK )::ArrayGetAt( pParser->lpaBlocks, i ); // Write block opening. if ( lpBlock->pszName ) pFile->PrintF( _T( "Block=%s\n" ), lpBlock->pszName ); else pFile->PrintF( _T( "Block\n" )); // Write color commands. pFile->PrintF( _T( "\tRGB=%ld,%ld,%ld\n" ), GetRValue( lpBlock->crColor ), GetGValue( lpBlock->crColor ), GetBValue( lpBlock->crColor )); if ( lpBlock->crBgColor == CLR_DEFAULT ) pFile->PrintF( _T( "\tBkRGB=*\n" )); else pFile->PrintF( _T( "\tBkRGB=%ld,%ld,%ld\n" ), GetRValue( lpBlock->crBgColor ), GetGValue( lpBlock->crBgColor ), GetBValue( lpBlock->crBgColor )); // Write start command. pFile->PrintF( _T( "\tStart=%s\n" ), lpBlock->pszStart ); // At the start of the line? if ( lpBlock->bStartOfLine ) pFile->PrintF( _T( "\tStartOfLine=Y\n" )); // Suppress escaping? pFile->PrintF( _T( "\tSuppressEscape=%lc\n" ), lpBlock->bSuppressEscape ? _T( 'Y' ) : _T( 'N' )); // Write end command. if ( lpBlock->pszEnd ) pFile->PrintF( _T( "\tEnd=%s\n" ), lpBlock->pszEnd == END_OF_LINE ? _T( "\\n" ) : lpBlock->pszEnd ); else pFile->PrintF( _T( ";\tEnd=\n" )); // Write block terminator. pFile->PrintF( _T( "EndBlock\n\n" )); } // Write keywords comment. pFile->PrintF( ClsString( MAKEINTRESOURCE( IDS_COMMENT_KEYWORDS ))); // Initialize buffer list. KEYLIST kl; BOOL bKeywords = FALSE; NewList(( LPLIST )&kl ); // Convert hashes. if ( KeywordEdit::Hash2List( &kl, pParser )) { // Iterate nodes. LPKEYWORDS pKW; for ( pKW = kl.lpFirst; pKW->lpNext; pKW = pKW->lpNext ) { // Keywords command written? if ( bKeywords == FALSE ) { // Write keywords command. pFile->PrintF( _T( "Keywords\n" )); bKeywords = TRUE; } // Write color values. pFile->PrintF( _T( "RGB=%ld,%ld,%ld\n" ), GetRValue( pKW->crColor ), GetGValue( pKW->crColor ), GetBValue( pKW->crColor )); if ( pKW->crBgColor == CLR_DEFAULT ) pFile->PrintF( "BkRGB=*\n" ); else pFile->PrintF( _T( "BkRGB=%ld,%ld,%ld\n" ), GetRValue( pKW->crBgColor ), GetGValue( pKW->crBgColor ), GetBValue( pKW->crBgColor )); // Write keywords from this group. for ( int i = 0; i < ::ArrayGetSize( pKW->lpaKeywords ); i++ ) pFile->PrintF( _T( "%s\n" ), *(( LPCTSTR * )::ArrayGetAt( pKW->lpaKeywords, i ))); } // Free the converted list. KeywordEdit::FreeKeyList( &kl ); } else return FALSE; // Write endkeywords command. if ( bKeywords ) pFile->PrintF( _T( "EndKeywords\n" )); } catch ( ClsException& e ) { // Error... UNREFERENCED_PARAMETER( e ); return FALSE; } return TRUE; }
// WM_COMMAND handler. LRESULT SyntaxPage::OnCommand( UINT nNotifyCode, UINT nCtrlID, HWND hWndCtrl ) { // What's the trouble... switch ( nCtrlID ) { case EditToolbar::ETID_COLOR: { // Get the current selection. int nSel = m_Common.GetCurSel(); // Only show the popup when there is // a valid selection. if ( nSel != LB_ERR ) { // Get the position of the selected entry. ClsRect rc; m_Color.GetItemRect( 6, rc ); m_Color.ClientToScreen( rc ); // Get the color index. int nColorIndex = m_Common.GetIndexArray()[ nSel ]; // Create the popup. The popup will automatically destroy // itself. new ClsColorPopup( ClsPoint( rc.Left(), rc.Bottom()), m_pParser->dwColorFlags & m_Common.GetFlagArray()[ nSel ] ? CLR_DEFAULT : m_pParser->crColors[ nColorIndex ], this, 0, ClsString( MAKEINTRESOURCE( IDS_DEFAULT )), ClsString( MAKEINTRESOURCE( IDS_CUSTOM )), NULL, TRUE, FALSE ); } return 0; } case EditToolbar::ETID_UP: // Move entry up. m_Blocks.MoveSelUp(); SetupToolbar(); return 0; case EditToolbar::ETID_DOWN: // Move entry down. m_Blocks.MoveSelDown(); SetupToolbar(); return 0; case EditToolbar::ETID_DELETE: // Remove entry. m_Blocks.RemoveSel(); SetupToolbar(); return 0; case EditToolbar::ETID_NEW: { // Create a block as follows: // // Name=New Block... // RGB=50,100,150 // Start=; // End=\n // EndBlock ClsString strName( MAKEINTRESOURCE( IDS_NEW_BLOCK )); BLOCK bBlock = { 0 }; bBlock.pszName = ( LPTSTR )::ArrayAllocMem( m_pParser->lpaBlocks, ( strName.GetStringLength() + 1 ) * sizeof( TCHAR )); if ( bBlock.pszName ) { // Copy the name. _tcscpy( bBlock.pszName, strName ); // Allocate start string. bBlock.pszStart = ( LPTSTR )::ArrayAllocMem( m_pParser->lpaBlocks, ( _tcslen( _T( ";" )) + 1 ) * sizeof( TCHAR )); if ( bBlock.pszStart ) { // Copy the name. _tcscpy( bBlock.pszStart, _T( ";" )); // Setup the length. bBlock.nStart = _tcslen( _T( ";" )); // Block end is EOL. bBlock.pszEnd = END_OF_LINE; // Add it to the array. if ( ::ArrayAdd( m_pParser->lpaBlocks, &bBlock, 1 )) { // Get the added block. LPBLOCK lpAdded = ( LPBLOCK )::ArrayGetAt( m_pParser->lpaBlocks, ::ArrayGetSize( m_pParser->lpaBlocks ) - 1 ); // Setup color. lpAdded->crColor = RGB( 50, 100, 150 ); lpAdded->crBgColor = CLR_DEFAULT; // We have to re-add the array contents since // adding items to the array may have // caused a re-allocation of the array // elements which, in turn, causes the // listview contents to be faulty. m_Blocks.ResetContent(); for ( int i = 0; i < ::ArrayGetSize( m_pParser->lpaBlocks ); i++ ) m_Blocks.AddString(( LPCTSTR )::ArrayGetAt( m_pParser->lpaBlocks, i )); // Select last added entry. m_Blocks.SetCurSel( ::ArrayGetSize( m_pParser->lpaBlocks ) - 1 ); // Setup toolbar. SetupToolbar(); // Changes made... pSettings->Changed( m_pParser ); // Edit it. BlockEdit be; if ( be.EditBlock( *GetParent(), lpAdded, m_pParser )) // Refresh the list. m_Blocks.Invalidate(); return 0; } ::ArrayFreeMem( m_pParser->lpaBlocks, bBlock.pszStart ); } ::ArrayFreeMem( m_pParser->lpaBlocks, bBlock.pszName ); } MessageBox( ClsString( MAKEINTRESOURCE( IDS_NO_MEMORY )), ClsGetApp()->GetAppTitle(), MB_ICONERROR | MB_OK ); return 0; } case IDC_COMMON: // Setup toolbar. SetupToolbar(); return 0; case IDC_BLOCKS: // Double-click? if ( nNotifyCode == LBN_DBLCLK ) { // Get the current selection. int nSel = m_Blocks.GetCurSel(); // Edit it. BlockEdit be; if ( be.EditBlock( *GetParent(), ( LPBLOCK )::ArrayGetAt( m_pParser->lpaBlocks, nSel ), m_pParser )) { // Refresh the list. m_Blocks.Invalidate(); pSettings->Changed( m_pParser ); } } else // Setup the toolbar. SetupToolbar(); return 0; case IDC_ESCAPE: { TCHAR szBuf[ 2 ] = { 0 }; // Pickup the buffer. m_Escape.GetWindowText( szBuf, 2 ); // did it really change? if ( m_pParser->cEscape != szBuf[ 0 ] ) { // Save escape character. m_pParser->cEscape = szBuf[ 0 ]; // Changes made... pSettings->Changed( m_pParser ); } return 0; } case IDC_SYNTAX: // Get setting. m_pParser->bSyntaxColoring = ( BOOL )( m_Syntax.GetCheck() == BST_CHECKED ); pSettings->Changed( m_pParser ); return 0; case IDC_FONT: { // Copy the font input. LOGFONT lf = m_pParser->lfScreenFont; // Popup font dialog. ClsFontDialog fd; if ( fd.DoModal( this, &lf, CF_BOTH | CF_FIXEDPITCHONLY | CF_INITTOLOGFONTSTRUCT )) { // Copy the contents. m_pParser->lfScreenFont = lf; // Changes made... pSettings->Changed( m_pParser ); } return 0; } case IDC_KEYWORDS: { // Open the keyword editor... KeywordEdit ke; ke.Edit( *GetParent(), m_pParser ); return 0; } } // Pass to the base class. return Page::OnCommand( nNotifyCode, nCtrlID, hWndCtrl ); }