diff options
Diffstat (limited to 'app/bin/textnoteui.c')
-rw-r--r-- | app/bin/textnoteui.c | 210 |
1 files changed, 90 insertions, 120 deletions
diff --git a/app/bin/textnoteui.c b/app/bin/textnoteui.c index ba255ea..40390bf 100644 --- a/app/bin/textnoteui.c +++ b/app/bin/textnoteui.c @@ -2,81 +2,55 @@ * View for the text note */ - /* XTrkCad - Model Railroad CAD - * Copyright (C) 2018 Martin Fischer - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - +/* XTrkCad - Model Railroad CAD + * Copyright (C) 2018 Martin Fischer + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "custom.h" #include "dynstring.h" #include "misc.h" #include "note.h" #include "param.h" #include "shortentext.h" -#include "track.h" +#include "track.h" -static struct extraDataNote_t noteDataInUI; +struct { + coOrd pos; + int layer; + track_p trk; +} textNoteData; static paramTextData_t noteTextData = { 300, 150 }; -static paramFloatRange_t r_1000_1000 = { -1000.0, 1000.0, 80 }; -static paramData_t textEditPLs[] = { +static paramFloatRange_t noRangeCheck = { 0.0, 0.0, 80, PDO_NORANGECHECK_HIGH | PDO_NORANGECHECK_LOW }; +static paramData_t textNotePLs[] = { #define I_ORIGX (0) - /*0*/ { PD_FLOAT, ¬eDataInUI.pos.x, "origx", PDO_DIM, &r_1000_1000, N_("Position X") }, + /*0*/ { PD_FLOAT, &textNoteData.pos.x, "origx", PDO_DIM|PDO_NOPREF, &noRangeCheck, N_("Position X") }, #define I_ORIGY (1) - /*1*/ { PD_FLOAT, ¬eDataInUI.pos.y, "origy", PDO_DIM, &r_1000_1000, N_("Position Y") }, + /*1*/ { PD_FLOAT, &textNoteData.pos.y, "origy", PDO_DIM|PDO_NOPREF, &noRangeCheck, N_("Position Y") }, #define I_LAYER (2) - /*2*/ { PD_DROPLIST, ¬eDataInUI.layer, "layer", 0, I2VP(150), "Layer", 0 }, + /*2*/ { PD_DROPLIST, &textNoteData.layer, "layer", PDO_NOPREF, I2VP(150), "Layer", 0 }, #define I_TEXT (3) /*3*/ { PD_TEXT, NULL, "text", PDO_NOPREF, ¬eTextData, N_("Note") } }; -static paramGroup_t textEditPG = { "textEdit", 0, textEditPLs, COUNT( textEditPLs ) }; -static wWin_p textEditW; +static paramGroup_t textNotePG = { "textNote", 0, textNotePLs, COUNT( textNotePLs ) }; +static wWin_p textNoteW; -#define textEntry ((wText_p)textEditPLs[I_TEXT].control) - -extern BOOL_T inDescribeCmd; - -/** - * Return the current text - * - */ -static void GetNoteTextData() -{ - int len; - - if (noteDataInUI.noteData.text ) { - MyFree(noteDataInUI.noteData.text); - } - len = wTextGetSize(textEntry); - noteDataInUI.noteData.text = (char*)MyMalloc(len + 2); - wTextGetText(textEntry, noteDataInUI.noteData.text, len); - return; -} - -/** - * Check validity of entered text - * - * \return always TRUE for testing - */ -BOOL_T -IsValidText(char * text) -{ - return(TRUE); -} +#define textEntry ((wText_p)textNotePLs[I_TEXT].control) /** @@ -88,26 +62,14 @@ IsValidText(char * text) */ static void TextDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP) + paramGroup_p pg, + int inx, + void * valueP) { switch (inx) { case I_ORIGX: case I_ORIGY: - UpdateText(¬eDataInUI, OR_NOTE, FALSE); - break; - case I_LAYER: - UpdateText(¬eDataInUI, LY_NOTE, FALSE); - break; - case I_TEXT: - /** TODO: this is never called, why doesn't text update trigger this callback? */ - GetNoteTextData(); - if (IsValidText(noteDataInUI.noteData.text)) { - ParamDialogOkActive(&textEditPG, TRUE); - } else { - ParamDialogOkActive(&textEditPG, FALSE); - } + // TODO: Redraw bitmap at new location break; default: break; @@ -121,11 +83,8 @@ TextDlgUpdate( static void TextEditCancel( wWin_p junk ) { - if (inDescribeCmd) { - UpdateText(¬eDataInUI, CANCEL_NOTE, FALSE); - } ResetIfNotSticky(); - wHide(textEditW); + wHide(textNoteW); } /** @@ -138,9 +97,23 @@ TextEditCancel( wWin_p junk ) static void TextEditOK(void *junk) { - GetNoteTextData(); - UpdateText(¬eDataInUI, OK_TEXT, FALSE); - wHide(textEditW); + track_p trk = textNoteData.trk; + if ( trk == NULL ) { + // new note + trk = NewNote( -1, textNoteData.pos, OP_NOTETEXT ); + } + struct extraDataNote_t * xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); + xx->pos = textNoteData.pos; + SetTrkLayer( trk, textNoteData.layer ); + + int len = wTextGetSize(textEntry); + MyFree( xx->noteData.text ); + xx->noteData.text = (char*)MyMalloc(len + 2); + wTextGetText(textEntry, xx->noteData.text, len); + + SetBoundingBox( trk, xx->pos, xx->pos ); + DrawNewTrack( trk ); + wHide(textNoteW); ResetIfNotSticky(); SetFileChanged(); } @@ -149,41 +122,34 @@ TextEditOK(void *junk) /** * Create the edit dialog for text notes. - * + * * \param trk IN selected note * \param title IN dialog title */ static void -CreateEditTextNote(track_p trk, char *title) +CreateEditTextNote(char *title, char * textData ) { - struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); - // create the dialog if necessary - if (!textEditW) { - ParamRegister(&textEditPG); - textEditW = ParamCreateDialog(&textEditPG, - "", - _("Done"), TextEditOK, - TextEditCancel, TRUE, NULL, - F_BLOCK, - TextDlgUpdate); + if (!textNoteW) { + ParamRegister(&textNotePG); + textNoteW = ParamCreateDialog(&textNotePG, + "", + _("Done"), TextEditOK, + TextEditCancel, TRUE, NULL, + F_BLOCK, + TextDlgUpdate); } - wWinSetTitle(textEditPG.win, MakeWindowTitle(title)); - - // initialize the dialog fields - noteDataInUI.pos = xx->pos; - noteDataInUI.layer = xx->layer; - noteDataInUI.trk = trk; + wWinSetTitle(textNotePG.win, MakeWindowTitle(title)); wTextClear(textEntry); - wTextAppend(textEntry, xx->noteData.text ); + wTextAppend(textEntry, textData ); wTextSetReadonly(textEntry, FALSE); - FillLayerList((wList_p)textEditPLs[I_LAYER].control); - ParamLoadControls(&textEditPG); - + FillLayerList((wList_p)textNotePLs[I_LAYER].control); + ParamLoadControls(&textNotePG); + // and show the dialog - wShow(textEditW); + wShow(textNoteW); } /** @@ -204,35 +170,39 @@ void DescribeTextNote(track_p trk, char * str, CSIZE_T len) RemoveFormatChars(xx->noteData.text, noteText); EllipsizeString(noteText, NULL, 80); DynStringMalloc(&statusLine, 100); - - DynStringPrintf(&statusLine, - _("Note: Layer=%d %-.80s"), - GetTrkLayer(trk)+1, - noteText ); + + DynStringPrintf(&statusLine, + _("Text Note(%d) Layer=%d %-.80s"), + GetTrkIndex(trk), + GetTrkLayer(trk)+1, + noteText ); strcpy(str, DynStringToCStr(&statusLine)); DynStringFree(&statusLine); - MyFree(noteText); - - if (inDescribeCmd) { - NoteStateSave(trk); - - CreateEditTextNote(trk, _("Update comment")); + if ( ! inDescribeCmd ) { + return; } + textNoteData.pos = xx->pos; + textNoteData.layer = GetTrkLayer( trk ); + textNoteData.trk = trk; + + CreateEditTextNote(_("Update Text Note"), xx->noteData.text ); } /** * Show the UI for entering new text notes - * + * * \param xx Note object data */ -void NewTextNoteUI(track_p trk) { - struct extraDataNote_t * xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); +void NewTextNoteUI(coOrd pos ) +{ char *tmpPtrText = _("Replace this text with your note"); - xx->noteData.text = MyStrdup(tmpPtrText); + textNoteData.pos = pos; + textNoteData.layer = curLayer; + textNoteData.trk = NULL; - CreateEditTextNote(trk, _("Create Text Note")); + CreateEditTextNote(_("Create Text Note"), tmpPtrText ); } |