Exemplo n.º 1
0
static void SelectLayoutEngine(UINT check_item)
{
	HMENU mainMenu = ::GetMenu(getGraphVizPreview()->m_hDlg);
	// Deselect everything.
	for (UINT i = ID_LAYOUTENGINE_DOT; i <= ID_LAYOUTENGINE_CIRCO; ++i)
	{ 
		CheckMenuItem(mainMenu, i, MF_BYCOMMAND | MF_UNCHECKED);
	}
	// Select chosen.
	CheckMenuItem(mainMenu, check_item, MF_BYCOMMAND | MF_CHECKED);
    lastLayoutEngineCode = check_item;
}
void launchGraphVizPreview()
{
    try
    {
        std::vector<char> doc_text = getDocument();
        if (doc_text.empty())
        {
            ::MessageBox(NULL, TEXT("The document in the current tab is empty.  Can't send to Graphviz"), TEXT("Graphviz Plugin Error"), MB_OK | MB_APPLMODAL);
            return;
        }

        GraphVizPreview * gvp = getGraphVizPreview();
        gvp->m_npp_text = doc_text;
        gvp->graph(false);
        RedrawWindow(gvp->m_hDlg, NULL, NULL, RDW_INVALIDATE);
    }
    catch (std::exception &e)
    {
        ::MessageBoxA(NULL, e.what(), "Graphviz Plugin Error", MB_OK | MB_APPLMODAL);
    }
}
Exemplo n.º 3
0
INT_PTR CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    typedef std::pair<std::wstring, UINT> layout;
    std::vector< layout > layouts;
    layouts.push_back(layout(TEXT("dot.exe"), ID_LAYOUTENGINE_DOT));
    layouts.push_back(layout(TEXT("neato.exe"), ID_LAYOUTENGINE_NEATO));
    layouts.push_back(layout(TEXT("fdp.exe"), ID_LAYOUTENGINE_FDP));
    layouts.push_back(layout(TEXT("sfdp.exe"), ID_LAYOUTENGINE_SFDP));
    layouts.push_back(layout(TEXT("twopi.exe"), ID_LAYOUTENGINE_TWOPI));
    layouts.push_back(layout(TEXT("circo.exe"), ID_LAYOUTENGINE_CIRCO));

    static bool is_dragging = false;

    switch (uMsg)
	{

    case WM_INITDIALOG:
    {
        Init(hwnd);

        ConfigSettings settings = cfg.load();
        if (!settings.graphviz_layout.empty())
        {
            for (auto it = layouts.begin(); it != layouts.end(); ++it)
            {
                if (it->first.find(settings.graphviz_layout) == 0
                    &&
                    settings.graphviz_layout.length() == it->first.length())
                {
                    lastLayoutEngineCode = it->second;
                    lastLayoutEngine = it->first;
                }
            }
        }

        SelectLayoutEngine(lastLayoutEngineCode, hwnd);
		break;
    }
    case WM_PAINT:
    {
		getGraphVizPreview()->draw();
		break;
    }
    case WM_SIZE:
        RedrawWindow(getGraphVizPreview()->m_hDlg, NULL, NULL, RDW_INVALIDATE);
        break;
    case WM_EXITSIZEMOVE:
        RedrawWindow(getGraphVizPreview()->m_hDlg, NULL, NULL, RDW_INVALIDATE);
        break;
    case WM_MOUSEWHEEL:
    {   
        int delta = GET_WHEEL_DELTA_WPARAM(wParam);

        GraphVizPreview * pPreviewWin = getGraphVizPreview();
        
        int x = GET_X_LPARAM(lParam);
        int y = GET_Y_LPARAM(lParam);

        if (delta > 0)
            pPreviewWin->zoom(x, y, 1.5);
        else
            pPreviewWin->zoom(x, y, 0.5);

        RedrawWindow(pPreviewWin->m_hDlg, NULL, NULL, RDW_INVALIDATE);
        break;
    }
    case WM_MBUTTONDOWN:
        getGraphVizPreview()->reset_zoom();
        RedrawWindow(getGraphVizPreview()->m_hDlg, NULL, NULL, RDW_INVALIDATE);
        break;
    case WM_MOUSEMOVE:
        
        if (wParam & MK_LBUTTON || wParam & MK_RBUTTON) // is left/right mouse button down?
        {
            static int x0, y0;
            
            int x = GET_X_LPARAM(lParam);
            int y = GET_Y_LPARAM(lParam);

            if (!is_dragging)
            {
                OutputDebugString(L"start drag");
                is_dragging = true;
                x0 = x;
                y0 = y;
            }

            wchar_t sz[123];
            swprintf(sz, L"%d %d\n", x - x0, y - y0);
            OutputDebugString(sz);

            getGraphVizPreview()->drag(x0-x, y0-y);
            RedrawWindow(getGraphVizPreview()->m_hDlg, NULL, NULL, RDW_INVALIDATE);

            x0 = x;
            y0 = y;
        }
        else
        {
            if (is_dragging)
                OutputDebugString(L"end drag");
            is_dragging = false;
        }
        break;
    case WM_ERASEBKGND:
        return TRUE;    // to reduce flickering when dragging the preview
	case WM_COMMAND:
        switch (LOWORD(wParam))
        {
        case ID_FILE_SAVE:
            if (!getGraphVizPreview()->m_save_as_path.empty() && !getGraphVizPreview()->m_save_as_ext.empty())
            {
                getGraphVizPreview()->graph(true);
                break;
            }
            //else, fall through to saveas
        case ID_FILE_SAVEAS:
            if(getGraphVizPreview()->saveAs())
            {
                getGraphVizPreview()->graph(true);
            }
            break;
        case ID_FILE_EXIT:
            SendMessage(hwnd, WM_CLOSE, 0, 0);
            break;

            // layout engine switch.
        case ID_LAYOUTENGINE_DOT:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("dot.exe");
            getGraphVizPreview()->refresh();
            break;
        case ID_LAYOUTENGINE_NEATO:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("neato.exe");
            getGraphVizPreview()->refresh();
            break;
        case ID_LAYOUTENGINE_FDP:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("fdp.exe");
            getGraphVizPreview()->refresh();
            break;
        case ID_LAYOUTENGINE_SFDP:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("sfdp.exe");
            getGraphVizPreview()->refresh();
            break;
        case ID_LAYOUTENGINE_TWOPI:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("twopi.exe");
            getGraphVizPreview()->refresh();
            break;
        case ID_LAYOUTENGINE_CIRCO:
            SelectLayoutEngine(LOWORD(wParam));
            lastLayoutEngine = getGraphVizPreview()->m_layout_engine = TEXT("circo.exe");
            getGraphVizPreview()->refresh();
            break;
        case IDOK:
        case IDCANCEL:
            SendMessage(hwnd, WM_CLOSE, 0, 0);
            return TRUE;

            // custom signals not generated from UI
        case CUSTOM_DISABLE_SAVE:
        {
            HMENU mainMenu = ::GetMenu(hwnd);
            EnableMenuItem(mainMenu, ID_FILE_SAVE, 1);
            EnableMenuItem(mainMenu, ID_FILE_SAVEAS, 1);
            break;
        }
        case CUSTOM_ENABLE_SAVE:
        {
            HMENU mainMenu = ::GetMenu(hwnd);
            EnableMenuItem(mainMenu, ID_FILE_SAVE, 0);
            EnableMenuItem(mainMenu, ID_FILE_SAVEAS, 0);
            break;
        }
    }
    break;
	case WM_CLOSE:
		DestroyWindow(hwnd);
		return TRUE;

    case WM_DESTROY:
        {
            ConfigSettings settings = cfg.load();
            if (!lastLayoutEngine.empty())
                settings.graphviz_layout = lastLayoutEngine;
            cfg.save(settings);
		    //PostQuitMessage(0);
		    killGraphVizPreview();
		    return TRUE;
        }

	}

	return FALSE;
}