1 | /* $Id: graphwiz.js 69449 2017-10-27 17:00:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * JavaScript functions for the Graph Wizard.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2017 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*******************************************************************************
|
---|
29 | * Global Variables *
|
---|
30 | *******************************************************************************/
|
---|
31 | /** The previous width of the div element that we measure. */
|
---|
32 | var g_cxPreviousWidth = 0;
|
---|
33 |
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * onload function that sets g_cxPreviousWidth to the width of @a sWidthSrcId.
|
---|
37 | *
|
---|
38 | * @returns true.
|
---|
39 | * @param sWidthSrcId The ID of the element which width we should measure.
|
---|
40 | */
|
---|
41 | function graphwizOnLoadRememberWidth(sWidthSrcId)
|
---|
42 | {
|
---|
43 | var cx = getUnscaledElementWidthById(sWidthSrcId);
|
---|
44 | if (cx)
|
---|
45 | {
|
---|
46 | g_cxPreviousWidth = cx;
|
---|
47 | }
|
---|
48 | return true;
|
---|
49 | }
|
---|
50 |
|
---|
51 |
|
---|
52 | /**
|
---|
53 | * onresize callback function that scales the given graph width input field
|
---|
54 | * value according to the resized element.
|
---|
55 | *
|
---|
56 | * @returns true.
|
---|
57 | * @param sWidthSrcId The ID of the element which width we should measure
|
---|
58 | * the resize effect on.
|
---|
59 | * @param sWidthInputId The ID of the input field which values should be
|
---|
60 | * scaled.
|
---|
61 | *
|
---|
62 | * @remarks Since we're likely to get several resize calls as part of one user
|
---|
63 | * resize operation, we're likely to suffer from some rounding
|
---|
64 | * artifacts. So, should the user abort or undo the resizing, the
|
---|
65 | * width value is unlikely to be restored to the exact value it had
|
---|
66 | * prior to the resizing.
|
---|
67 | */
|
---|
68 | function graphwizOnResizeRecalcWidth(sWidthSrcId, sWidthInputId)
|
---|
69 | {
|
---|
70 | var cx = getUnscaledElementWidthById(sWidthSrcId);
|
---|
71 | if (cx)
|
---|
72 | {
|
---|
73 | var oElement = document.getElementById(sWidthInputId);
|
---|
74 | if (oElement && g_cxPreviousWidth)
|
---|
75 | {
|
---|
76 | var cxOld = oElement.value;
|
---|
77 | if (isInteger(cxOld))
|
---|
78 | {
|
---|
79 | var fpRatio = cxOld / g_cxPreviousWidth;
|
---|
80 | oElement.value = Math.round(cx * fpRatio);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | g_cxPreviousWidth = cx;
|
---|
84 | }
|
---|
85 |
|
---|
86 | return true;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Fills thegraph size (cx, cy) and dpi fields with default values.
|
---|
91 | *
|
---|
92 | * @returns false (for onclick).
|
---|
93 | * @param sWidthSrcId The ID of the element which width we should measure.
|
---|
94 | * @param sWidthInputId The ID of the graph width field (cx).
|
---|
95 | * @param sHeightInputId The ID of the graph height field (cy).
|
---|
96 | * @param sDpiInputId The ID of the graph DPI field.
|
---|
97 | */
|
---|
98 | function graphwizSetDefaultSizeValues(sWidthSrcId, sWidthInputId, sHeightInputId, sDpiInputId)
|
---|
99 | {
|
---|
100 | var cx = getUnscaledElementWidthById(sWidthSrcId);
|
---|
101 | var cDotsPerInch = getDeviceXDotsPerInch();
|
---|
102 |
|
---|
103 | if (cx)
|
---|
104 | {
|
---|
105 | setInputFieldValue(sWidthInputId, cx);
|
---|
106 | setInputFieldValue(sHeightInputId, Math.round(cx * 5 / 16)); /* See wuimain.py. */
|
---|
107 | }
|
---|
108 |
|
---|
109 | if (cDotsPerInch)
|
---|
110 | {
|
---|
111 | setInputFieldValue(sDpiInputId, cDotsPerInch);
|
---|
112 | }
|
---|
113 |
|
---|
114 | return false;
|
---|
115 | }
|
---|
116 |
|
---|