Exemple #1
0
void CNoteDlg::CloseDialog(int nVal)
{
	m_bClosing = true;		// note is being closed

	// The app in not being closed so change the note's status to 'closed'
	if (!IsAppClosing())
		SetNoteStatus(Close);

	// Display a prompt dialog asking an user if a note should be saved
	// but only if the text has been modified in the edit control
	if (m_wndEdit.GetModify())
	{
		int nRet = MessageBox(_T("The text in the note has changed.\n\nDo you want to save the changes?"), 
								_T("StickyNotes"),
								MB_YESNOCANCEL|MB_ICONEXCLAMATION);

		if (nRet == IDCANCEL)	// 'Cancel' button - do not do anything 
			return;
		if (nRet == IDYES)		// 'Yes' button - save the note's text also
			OnSave(true);
		if (nRet == IDNO)		// 'No' button - only save the note's attributes
			OnSave(false);
	}
	else
		// Text has not been modified so save the note's attributes only
		OnSave(false);			

	// Add a note's text and a note's id to the collection of recently accessed notes
	if (GetNoteText().length() != 0)
	{
		(m_pWndParent->m_RecNotes).AddItemToCollection(GetNoteText(), GetNoteID());
	}

	// Remove it from the collection of the opened notes
	m_pWndParent->RemoveFromListOfOpenNotes(GetNoteID());

	// Destroy the Note dialog
	DestroyWindow();
}
Exemple #2
0
// Handles clicking on 'Save' menu item.
// If bSaveAll is true means save note's attributes and a text,
// if bSaveAll is false means save only note's attributes
void CNoteDlg::OnSave(bool bSaveAll)
{
	vector<CNote>::iterator iter;
	bool bFound = false;

	// Let's see if this note was saved already
	for (iter = (m_pWndParent->m_vecNotes).begin(); iter != (m_pWndParent->m_vecNotes).end(); iter++)
	{
		if ((*iter).GetNoteID() == GetNoteID())	// note is in the collection
		{
			bFound = true;
			break;
		}
	}

	// Save note's text but only if the user said so
	if (bSaveAll)
		SaveNoteText();

	// Save note's size and position
	SaveNotePosition();

	// Get a note object
	CNote * pNote = this;

	// Save the note but only if the note is not empty
	if (GetNoteText().length() != 0)
	{
		if (bFound)			// note already exists
		{
			*iter = *pNote;
		}
		else				// it's a new note
		{
			// Insert a CNote object at the end of the vector
			(m_pWndParent->m_vecNotes).push_back(*pNote);
		}

		// Post a message to the parent to persist all notes
		::PostMessage(m_pWndParent->m_hWnd, WMU_PERSISTNOTES, 0, 0);
	}

	if (bSaveAll)
	{
		// Clear the modified flag for an edit control
		m_wndEdit.SetModify(FALSE);
	}
}
Exemple #3
0
bool VaultTextNoteNode::GetVisitInfo (plAgeInfoStruct * info) {

    wchar_t * mem;
    const wchar_t * str = mem = wcsdup(GetNoteText());
    
    for (unsigned i = 0; i < kNumAgeInfoFields; ++i) {
        
        wchar_t token[1024];
        switch (i) {
            case kAgeFilename: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    char ansi[1024];
                    StrToAnsi(ansi, token, arrsize(ansi));
                    info->SetAgeFilename(ansi);
                }
            }
            break;
            
            case kAgeInstName: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    char ansi[1024];
                    StrToAnsi(ansi, token, arrsize(ansi));
                    info->SetAgeInstanceName(ansi);
                }
            }
            break;
            
            case kAgeUserName: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    char ansi[1024];
                    StrToAnsi(ansi, token, arrsize(ansi));
                    info->SetAgeUserDefinedName(ansi);
                }
            }
            break;
            
            case kAgeDesc: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    char ansi[1024];
                    StrToAnsi(ansi, token, arrsize(ansi));
                    info->SetAgeDescription(ansi);
                }
            }
            break;
            
            case kAgeInstGuid: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    plUUID uuid(plString::FromWchar(token));
                    info->SetAgeInstanceGuid(&uuid);
                }
            }
            break;
            
            case kAgeLanguage: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    info->SetAgeLanguage(StrToUnsigned(token, nil, 10));
                }
            }
            break;
            
            case kAgeSequence: {
                StrTokenize(&str, token, arrsize(token), L"|", 1);
                if (StrLen(token) > 0) {
                    info->SetAgeSequenceNumber(StrToUnsigned(token, nil, 10));
                }
            }
            break;

            DEFAULT_FATAL(i);
        }
    }

    free(mem);
    return true;
}
Exemple #4
0
LRESULT CNoteDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	BOOL bRet;
	HWND hWnd;
	DWORD dwStyle;

	// Create the brush 
	m_brBkgnd.CreateSolidBrush(GetNoteColor());
	
	// Set the sizing border width/height
	m_nSizeFrame = GetSystemMetrics(SM_CXSIZEFRAME);
	
	// Center the dialog on the screen
	CenterWindow();
	
	// Retrieve the coordinates of a dialog's client area
	CRect rectDlg; 
	GetClientRect(&rectDlg);
	
	// Subclass the static control displaying current date and time and 
	// attach it to the CStaticDateTime object
	bRet = m_wndStaticDateTime.SubclassWindow(GetDlgItem(IDC_STATIC_TIME));
	ATLASSERT(bRet);
	// Set the size and position of the control
	m_wndStaticDateTime.MoveWindow(5, rectDlg.Height() - 14, rectDlg.Width() / 2, 14);
	// Set the current date and time
	m_wndStaticDateTime.SetCurrentDateTime(GetTimestamp());
	// Set the background color
	m_wndStaticDateTime.SetBkgndColor(GetNoteColor());
	
	// Subclass the bar static control and attach it to the CGradientStatic object
	bRet = m_wndStaticBar.SubclassWindow(GetDlgItem(IDC_STATIC_BAR));
	ATLASSERT(bRet);
	// Set the size and position of the control
	m_wndStaticBar.MoveWindow(42, 2, rectDlg.Width() - 66, 16);
	// Change the font
	m_wndStaticBar.ChangeFont();
	// Set the note's title
	m_wndStaticBar.SetWindowText(GetNoteTitle().c_str());

	// Subclass the edit control and attach it to the CNoteEdit object
	bRet = m_wndEdit.SubclassWindow(GetDlgItem(IDC_EDIT));
	ATLASSERT(bRet);
	// Set the ENM_LINK mask for a rich edit control to receive 
	// EN_LINK notifications
	m_wndEdit.SetEventMask(ENM_LINK);		
	// Enable automatic detection of URLs by a rich edit control
	m_wndEdit.SetAutoURLDetect();
	// Set the edit control's background color
	m_wndEdit.SetBackgroundColor(GetNoteColor());
	// Sets the initial character formatting attributes
	m_wndEdit.SetDefaultFont();
	// Set the edit control's text
	if (GetNoteRTF().length() != 0)
		m_wndEdit.SetRTF(GetNoteRTF().c_str());
	else
		m_wndEdit.SetWindowText(GetNoteText().c_str());
	// Set the size and position of the control
	m_wndEdit.MoveWindow(5, 20, rectDlg.Width() - 10, rectDlg.Height() - 40);
	
	// Create the static control holding the 'Note' bitmap
	CRect rectStatic(1, 2, 17, 18);
	hWnd = m_wndStaticNote.Create(m_hWnd, rectStatic, NULL,
		WS_CHILD|WS_VISIBLE|SS_BITMAP|SS_CENTERIMAGE|SS_NOTIFY);
	ATLASSERT(hWnd);
	
	// Create the button with the 'Close' bitmap
	rectStatic.SetRect(rectDlg.right - 21, 1, rectDlg.right - 1, 20);
	hWnd = m_wndBtnClose.Create(m_hWnd, rectStatic, NULL, 0, 0);
	ATLASSERT(hWnd);

	m_hFontClose = ::CreateFont(15, 0, 0, 0, FW_SEMIBOLD, 0, 0, 0, 1, 0, 0, 4, 
					FF_DONTCARE, _T("Marlett"));
	ATLASSERT(m_hFontClose);
	m_wndBtnClose.SetFont(m_hFontClose);
	m_wndBtnClose.SetTextColor(BLACK);
	m_wndBtnClose.SetColor(GetNoteColor());
	m_wndBtnClose.SetWindowText((TCHAR*)"\x72");		// 'x' sign
	m_wndBtnClose.SetToolTipText(_T("Close the note"));

	// Create the button with the 'Pin' bitmap
	rectStatic.SetRect(19, 1, 39, 21);
	hWnd = m_wndBtnPin.Create(m_hWnd, rectStatic, NULL, 0, 0);
	ATLASSERT(hWnd);
	// Change the button extended style
	dwStyle = BMPBTN_AUTOSIZE | BMPBTN_AUTO3D_SINGLE | BMPBTN_HOVER | BTNEX_CHECKBUTTON;
	m_wndBtnPin.SetBitmapButtonExtendedStyle(dwStyle);

	// Load the 'Pinopen' bitmap from the application's resources
	HBITMAP hBmpTemp2 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINOPEN));
	ATLASSERT(hBmpTemp2);
	// Load the 'Pinclose' bitmap from the application's resources
	HBITMAP hBmpTemp3 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINCLOSE));
	ATLASSERT(hBmpTemp3);
	// Load the 'Pinhoover' bitmap from the application's resources
	HBITMAP hBmpTemp4 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_PINHOOVER));
	ATLASSERT(hBmpTemp4);
	
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinopen = ReplaceColor(hBmpTemp2, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinopen);
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinclose = ReplaceColor(hBmpTemp3, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinclose);
	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpPinhoover = ReplaceColor(hBmpTemp4, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpPinhoover);
	
	// Create the pin button's imagelist
	m_wndBtnPin.m_ImageList.Create(20, 20, ILC_COLORDDB | ILC_MASK, 3, 1);
	// Add images to the image list.
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinopen);
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinclose);
	m_wndBtnPin.m_ImageList.Add(m_hBmpPinhoover);
	// Set normal, pressed and hover images
	m_wndBtnPin.SetImages(0, 1, 2);
	// ToolTip text
	m_wndBtnPin.SetToolTipText(_T("Keep the Note Visible"));

	// Load the 'Note' bitmap from the application's resources
	HBITMAP hBmpTemp1 = ::LoadBitmap(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDB_NOTE));
	ATLASSERT(hBmpTemp1);

	// Replace the white background color with the saved or default (yellow) note's color
	m_hBmpNote = ReplaceColor(hBmpTemp1, WHITE, GetNoteColor());
	ATLASSERT(m_hBmpNote);

	// Delete the original bitmaps
	DeleteObject(hBmpTemp1);
	DeleteObject(hBmpTemp2);
	DeleteObject(hBmpTemp3);
	DeleteObject(hBmpTemp4);

	// Draw the 'Note' bitmap in the static control
	m_wndStaticNote.SetBitmap(m_hBmpNote);
	
	// To support a transparency try to get a SetLayeredWindowAttributes function address
	// and set WS_EX_LAYERED style
	HMODULE hUser32 = GetModuleHandle(_T("User32.dll"));
	if (hUser32)
	{
		m_pfSetLayeredWindowAttributes = 
			(PFUNCSETLAYEREDWINDOWATTR)::GetProcAddress(hUser32, "SetLayeredWindowAttributes");
		if (m_pfSetLayeredWindowAttributes)
		{
			::SetWindowLong(m_hWnd, GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE)^WS_EX_LAYERED);
			// After the SetWindowLong call, the layered window will not become visible 
			// until the SetLayeredWindowAttributes function has been called for this window
			m_pfSetLayeredWindowAttributes(m_hWnd, 0, (BYTE)255, LWA_ALPHA);

			// Set the transparency of the note dialog
			MakeTransparent(GetNoteAlpha());
		}
	}

	// Register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	return TRUE;
}