| 1 | /* GuiTrust.cpp |
| 2 | * |
| 3 | * Copyright (C) 2024 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "GuiTrust.h"cxx . . $ `<file>/sys/GuiTrust.h`/ |
| 20 | #include "praatP.h"cxx . . $ `<file>/sys/praatP.h`/ |
| 21 | #include "Gui.h"cxx . . $ `<file>/sys/Gui.h`/ |
| 22 | |
| 23 | GuiDialogcxx . . $ GuiDialog# GuiTrust_createDialogcxx . . $ GuiTrust_createDialog(8e940b0babaf649). (GuiWindowcxx . . $ GuiWindow# optionalParent, |
| 24 | conststring32cxx . . $ conststring32# message1, conststring32cxx . . $ conststring32# message2, conststring32cxx . . $ conststring32# message3, conststring32cxx . . $ conststring32# message4, conststring32cxx . . $ conststring32# message5, |
| 25 | conststring32cxx . . $ conststring32# option1, conststring32cxx . . $ conststring32# option2, conststring32cxx . . $ conststring32# option3, conststring32cxx . . $ conststring32# option4, conststring32cxx . . $ conststring32# option5 |
| 26 | ) { |
| 27 | constexpr int DIALOG_WIDTH = 700; |
| 28 | constexpr int BUTTON_HEIGHT = 60; |
| 29 | /* |
| 30 | Compute the height of the trust form. |
| 31 | */ |
| 32 | constexpr int SHORT_LABEL_HEIGHT = 25; |
| 33 | constexpr int STEP_LABEL_HEIGHT = 15; |
| 34 | int dialogHeight = Gui_TOP_DIALOG_SPACINGcxx . . $ `sys/Gui.h:90:10`!; |
| 35 | for (int i = 1; i <= 5; i ++) { |
| 36 | conststring32cxx . . $ conststring32# message = ( i == 1 ? message1 : i == 2 ? message2 : i == 3 ? message3 : i == 4 ? message4 : message5 ); |
| 37 | if (message) { |
| 38 | const int numberOfLines = 1 + !! str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'\n') + !! str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'“'); |
| 39 | const int labelHeight = SHORT_LABEL_HEIGHT + (numberOfLines - 1) * STEP_LABEL_HEIGHT; |
| 40 | dialogHeight += labelHeight + Gui_VERTICAL_DIALOG_SPACING_SAMEcxx . . $ `sys/Gui.h:94:9`!; |
| 41 | } |
| 42 | } |
| 43 | dialogHeight += Gui_VERTICAL_DIALOG_SPACING_DIFFERENTcxx . . $ `sys/Gui.h:95:9`!; |
| 44 | for (int i = 1; i <= 5; i ++) { |
| 45 | conststring32cxx . . $ conststring32# option = ( i == 1 ? option1 : i == 2 ? option2 : i == 3 ? option3 : i == 4 ? option4 : option5 ); |
| 46 | if (option) |
| 47 | dialogHeight += BUTTON_HEIGHT + Gui_VERTICAL_DIALOG_SPACING_SAMEcxx . . $ `sys/Gui.h:94:9`!; |
| 48 | } |
| 49 | dialogHeight += 60; // the Help button |
| 50 | /* |
| 51 | Create the dialog. |
| 52 | */ |
| 53 | int x = Gui_LEFT_DIALOG_SPACINGcxx . . $ `sys/Gui.h:85:9`!, buttonWidth = DIALOG_WIDTH - x - Gui_RIGHT_DIALOG_SPACINGcxx . . $ `sys/Gui.h:86:9`!; |
| 54 | GuiDialogcxx . . $ GuiDialog# me = GuiDialog_createcxx . . $ GuiDialog_create(9df51e4563bc0c17). (optionalParent, 150, 70, DIALOG_WIDTH, dialogHeight, |
| 55 | U"Praat Trust window: checking for security and safety", nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr, GuiDialog_Modalitycxx . . $ GuiDialog_Modality#::BLOCKINGcxx . . $ GuiDialog_Modality#BLOCKING.); |
| 56 | /* |
| 57 | Add the labels. |
| 58 | */ |
| 59 | int y = Gui_TOP_DIALOG_SPACINGcxx . . $ `sys/Gui.h:90:10`!; |
| 60 | for (int i = 1; i <= 5; i ++) { |
| 61 | conststring32cxx . . $ conststring32# message = ( i == 1 ? message1 : i == 2 ? message2 : i == 3 ? message3 : i == 4 ? message4 : message5 ); |
| 62 | if (message) { |
| 63 | const int numberOfLines = 1 + !! str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'\n') + !! str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'“'); |
| 64 | const int labelHeight = SHORT_LABEL_HEIGHT + (numberOfLines - 1) * STEP_LABEL_HEIGHT; |
| 65 | uint32cxx . . $ uint32# labelFlags = GuiLabel_CENTREcxx . . $ `sys/Gui.h:676:9`! | GuiLabel_MULTILINEcxx . . $ `sys/Gui.h:679:9`!; |
| 66 | if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'“')) |
| 67 | labelFlags |= GuiLabel_BOLDcxx . . $ `sys/Gui.h:678:9`!; |
| 68 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (me, x, x + buttonWidth, y, y + labelHeight, message, labelFlags); |
| 69 | y += labelHeight + Gui_VERTICAL_DIALOG_SPACING_SAMEcxx . . $ `sys/Gui.h:94:9`!; |
| 70 | } |
| 71 | } |
| 72 | /* |
| 73 | Add the buttons. |
| 74 | */ |
| 75 | y += Gui_VERTICAL_DIALOG_SPACING_DIFFERENTcxx . . $ `sys/Gui.h:95:9`!; |
| 76 | for (int i = 1; i <= 5; i ++) { |
| 77 | conststring32cxx . . $ conststring32# option = ( i == 1 ? option1 : i == 2 ? option2 : i == 3 ? option3 : i == 4 ? option4 : option5 ); |
| 78 | if (option) { |
| 79 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (me, x, x + buttonWidth, y, y + BUTTON_HEIGHT, |
| 80 | option, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr, GuiButton_MULTILINEcxx . . $ `sys/Gui.h:471:9`! + ( i == 1 ? GuiButton_DEFAULTcxx . . $ `sys/Gui.h:467:9`! : 0 )); |
| 81 | y += BUTTON_HEIGHT + Gui_VERTICAL_DIALOG_SPACING_SAMEcxx . . $ `sys/Gui.h:94:9`!; |
| 82 | } |
| 83 | } |
| 84 | return me; |
| 85 | } |
| 86 | |
| 87 | integercxx . . $ integer# GuiTrust_getcxx . . $ GuiTrust_get(46458cd14d966cec). (GuiWindowcxx . . $ GuiWindow# optionalParent, Editorcxx . . $ Editor# optionalTrustWindowOwningEditor, |
| 88 | conststring32cxx . . $ conststring32# message1, conststring32cxx . . $ conststring32# message2, conststring32cxx . . $ conststring32# message3, conststring32cxx . . $ conststring32# message4, conststring32cxx . . $ conststring32# message5, |
| 89 | conststring32cxx . . $ conststring32# option1, conststring32cxx . . $ conststring32# option2, conststring32cxx . . $ conststring32# option3, conststring32cxx . . $ conststring32# option4, conststring32cxx . . $ conststring32# option5, |
| 90 | Interpretercxx . . $ Interpreter# interpreter |
| 91 | ) { |
| 92 | Melder_precxx . . $ `melder/melder_assert.h:40:10`! (interpreter); |
| 93 | |
| 94 | GuiDialogcxx . . $ GuiDialog# me = GuiTrust_createDialogcxx . . $ GuiTrust_createDialog(8e940b0babaf649). (optionalParent, |
| 95 | message1, message2, message3, message4, message5, option1, option2, option3, option4, option5); |
| 96 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me); |
| 97 | const integercxx . . $ integer# clickedButtonId = GuiDialog_runcxx . . $ GuiDialog_run(4d616838d2dacc91). (me); |
| 98 | GuiThing_hidecxx . . $ GuiThing_hide(20e88c25f0ba841). (me); |
| 99 | GuiObject_destroycxx . . $ GuiObject_destroy(5d22bdacc48458e8). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget.); |
| 100 | const bool sheClickedOnClose = ( clickedButtonId == 0 ); |
| 101 | const bool sheClickedOnCancel = ( clickedButtonId == 1 ); |
| 102 | if (sheClickedOnClose || sheClickedOnCancel) { |
| 103 | Interpreter_stopcxx . . $ Interpreter_stop(448c181fe9dacca8). (interpreter); |
| 104 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"You interrupted the script."); |
| 105 | } |
| 106 | return clickedButtonId; |
| 107 | } |
| 108 | |
| 109 | /* End of file GuiTrust.cpp */ |