diff options
Diffstat (limited to 'app/bin/linknoteui.c')
-rw-r--r-- | app/bin/linknoteui.c | 209 |
1 files changed, 101 insertions, 108 deletions
diff --git a/app/bin/linknoteui.c b/app/bin/linknoteui.c index cb98686..a47bb58 100644 --- a/app/bin/linknoteui.c +++ b/app/bin/linknoteui.c @@ -17,7 +17,7 @@ * * 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. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "custom.h" @@ -29,39 +29,42 @@ #include "track.h" #include "validator.h" -extern BOOL_T inDescribeCmd; - #define DEFAULTLINKURL "http://www.xtrkcad.org/" #define DEFAULTLINKTITLE "The XTrackCAD Homepage" - -static struct extraDataNote_t noteDataInUI; +struct { + coOrd pos; + int layer; + track_p trk; + char title[TITLEMAXIMUMLENGTH]; + char url[URLMAXIMUMLENGTH]; +} linkNoteData; static void NoteLinkBrowse(void *junk); static void NoteLinkOpen(char *url ); -static paramFloatRange_t r_1000_1000 = { -1000.0, 1000.0, 80 }; -static paramData_t linkEditPLs[] = { +static paramFloatRange_t noRangeCheck = { 0.0, 0.0, 80, PDO_NORANGECHECK_HIGH | PDO_NORANGECHECK_LOW }; +static paramData_t linkNotePLs[] = { #define I_ORIGX (0) - /*0*/ { PD_FLOAT, ¬eDataInUI.pos.x, "origx", PDO_DIM, &r_1000_1000, N_("Position X") }, + /*0*/ { PD_FLOAT, &linkNoteData.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, &linkNoteData.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, &linkNoteData.layer, "layer", PDO_NOPREF, I2VP(150), "Layer", 0 }, #define I_TITLE (3) - /*3*/ { PD_STRING, NULL, "title", PDO_NOPREF | PDO_STRINGLIMITLENGTH, I2VP(200), N_("Title"), 0, 0, TITLEMAXIMUMLENGTH-1 }, + /*3*/ { PD_STRING, &linkNoteData.title, "title", PDO_NOPREF | PDO_NOTBLANK, I2VP(200), N_("Title"), 0, 0, sizeof(linkNoteData.title ) }, #define I_URL (4) - /*4*/ { PD_STRING, NULL, "name", PDO_NOPREF | PDO_STRINGLIMITLENGTH, I2VP(200), N_("URL"), 0, 0, URLMAXIMUMLENGTH-1 }, + /*4*/ { PD_STRING, &linkNoteData.url, "name", PDO_NOPREF | PDO_NOTBLANK, I2VP(200), N_("URL"), 0, 0, sizeof(linkNoteData.url ) }, #define I_OPEN (5) /*5*/{ PD_BUTTON, NoteLinkBrowse, "openlink", PDO_DLGHORZ, NULL, N_("Open...") }, }; -static paramGroup_t linkEditPG = { "linkEdit", 0, linkEditPLs, COUNT( linkEditPLs ) }; -static wWin_p linkEditW; +static paramGroup_t linkNotePG = { "linkNote", 0, linkNotePLs, COUNT( linkNotePLs ) }; +static wWin_p linkNoteW; BOOL_T IsLinkNote(track_p trk) { - struct extraDataNote_t * xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); + struct extraDataNote_t * xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); return(xx->op == OP_NOTELINK); } @@ -74,7 +77,7 @@ IsLinkNote(track_p trk) */ static void NoteLinkBrowse(void *junk) { - NoteLinkOpen(noteDataInUI.noteData.linkData.url); + NoteLinkOpen(linkNoteData.url); } /** @@ -84,49 +87,33 @@ static void NoteLinkBrowse(void *junk) */ static void NoteLinkOpen(char *url) { - wOpenFileExternal(url); + wOpenFileExternal(url); } static void LinkDlgUpdate( - paramGroup_p pg, - int inx, - void * valueP) + paramGroup_p pg, + int inx, + void * valueP) { - switch (inx) { - case I_URL: - if (strlen(noteDataInUI.noteData.linkData.url) > URLMAXIMUMLENGTH) { - DynString message; - - DynStringMalloc(&message, 80); - DynStringPrintf(&message, _("The entered URL is too long. The maximum allowed length is %d. Please edit the entered value."), URLMAXIMUMLENGTH); - wNoticeEx(NT_ERROR, - DynStringToCStr(&message), - _("Re-edit"), - NULL); - DynStringFree(&message); + switch (inx) { + case I_URL: + if ( ! IsValidURL( linkNoteData.url ) ) { + printf( "URL %s is invalid\n", linkNoteData.url ); + paramData_p p = &linkNotePLs[I_URL]; + p->bInvalid = TRUE; + wWinPix_t h = wControlGetHeight(p->control); + wControlSetBalloon( p->control, 0, -h*3/4, "URL is invalid" ); + ParamHilite( p->group->win, p->control, TRUE ); } - - if (IsValidURL(noteDataInUI.noteData.linkData.url) && - (strlen(noteDataInUI.noteData.linkData.url) <= URLMAXIMUMLENGTH)) - { - wControlActive(linkEditPLs[I_OPEN].control, TRUE); - ParamDialogOkActive(&linkEditPG, TRUE); - } else { - wControlActive(linkEditPLs[I_OPEN].control, FALSE); - ParamDialogOkActive(&linkEditPG, FALSE); - } - break; + break; case I_ORIGX: case I_ORIGY: - UpdateLink(¬eDataInUI, OR_NOTE, FALSE); - break; - case I_LAYER: - UpdateLink(¬eDataInUI, LY_NOTE, FALSE); + // TODO: Redraw bitmap at new location break; default: break; - } + } } /** @@ -136,11 +123,8 @@ LinkDlgUpdate( static void LinkEditCancel( wWin_p junk) { - if (inDescribeCmd) { - UpdateFile(¬eDataInUI, CANCEL_NOTE, FALSE); - } ResetIfNotSticky(); - wHide(linkEditW); + wHide(linkNoteW); } /** @@ -153,48 +137,48 @@ LinkEditCancel( wWin_p junk) static void LinkEditOK(void *junk) { - UpdateLink(¬eDataInUI, OK_LINK, FALSE); - wHide(linkEditW); + track_p trk = linkNoteData.trk; + if ( trk == NULL ) { + // new note + trk = NewNote( -1, linkNoteData.pos, OP_NOTELINK ); + } + struct extraDataNote_t * xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); + xx->pos = linkNoteData.pos; + SetTrkLayer( trk, linkNoteData.layer ); + MyFree( xx->noteData.linkData.title ); + xx->noteData.linkData.title = MyStrdup( linkNoteData.title ); + MyFree( xx->noteData.linkData.url ); + xx->noteData.linkData.url = MyStrdup( linkNoteData.url ); + SetBoundingBox( trk, xx->pos, xx->pos ); + DrawNewTrack( trk ); + wHide(linkNoteW); ResetIfNotSticky(); SetFileChanged(); } -static void -CreateEditLinkDialog(track_p trk, char *title) +static void +CreateEditLinkDialog(char *title) { // create the dialog if necessary - if (!linkEditW) { - noteDataInUI.base.trkType = T_NOTE; - noteDataInUI.noteData.linkData.url = MyMalloc(URLMAXIMUMLENGTH); - noteDataInUI.noteData.linkData.title = MyMalloc(TITLEMAXIMUMLENGTH); - linkEditPLs[I_TITLE].valueP = noteDataInUI.noteData.linkData.title; - linkEditPLs[I_URL].valueP = noteDataInUI.noteData.linkData.url; - ParamRegister(&linkEditPG); - linkEditW = ParamCreateDialog(&linkEditPG, - "", - _("Done"), LinkEditOK, - LinkEditCancel, TRUE, NULL, - F_BLOCK, - LinkDlgUpdate); - } - - wWinSetTitle(linkEditPG.win, MakeWindowTitle(title)); - - // initialize the dialog fields - struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); - noteDataInUI.pos = xx->pos; - noteDataInUI.layer = xx->layer; - noteDataInUI.trk = trk; - strscpy(noteDataInUI.noteData.linkData.url, xx->noteData.linkData.url,URLMAXIMUMLENGTH ); - strscpy(noteDataInUI.noteData.linkData.title, xx->noteData.linkData.title, TITLEMAXIMUMLENGTH ); - - FillLayerList((wList_p)linkEditPLs[I_LAYER].control); - ParamLoadControls(&linkEditPG); - + if (!linkNoteW) { + ParamRegister(&linkNotePG); + linkNoteW = ParamCreateDialog(&linkNotePG, + "", + _("Done"), LinkEditOK, + LinkEditCancel, TRUE, NULL, + F_BLOCK, + LinkDlgUpdate); + } + + wWinSetTitle(linkNotePG.win, MakeWindowTitle(title)); + + FillLayerList((wList_p)linkNotePLs[I_LAYER].control); + ParamLoadControls(&linkNotePG); + // and show the dialog - wShow(linkEditW); + wShow(linkNoteW); } /** @@ -204,7 +188,7 @@ CreateEditLinkDialog(track_p trk, char *title) void ActivateLinkNote(track_p trk) { - struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); + struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); NoteLinkOpen(xx->noteData.linkData.url); } @@ -219,23 +203,31 @@ void ActivateLinkNote(track_p trk) void DescribeLinkNote(track_p trk, char * str, CSIZE_T len) { - struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); - DynString statusLine; - - DynStringMalloc(&statusLine, 80); - DynStringPrintf(&statusLine, - "Link: Layer=%d %-.80s (%s)", - GetTrkLayer(trk)+1, - xx->noteData.linkData.title, - xx->noteData.linkData.url); - strcpy(str, DynStringToCStr(&statusLine)); - DynStringFree(&statusLine); - - if (inDescribeCmd) { - NoteStateSave(trk); - - CreateEditLinkDialog(trk, _("Update link")); + struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); + DynString statusLine; + + DynStringMalloc(&statusLine, 80); + DynStringPrintf(&statusLine, + "Weblink (%d) Layer=%d %-.80s (%s)", + GetTrkIndex(trk), + GetTrkLayer(trk)+1, + xx->noteData.linkData.title, + xx->noteData.linkData.url); + strncpy(str, DynStringToCStr(&statusLine), len-1); + str[len-1] = '\0'; + DynStringFree(&statusLine); + if ( ! inDescribeCmd ) { + return; } + + linkNoteData.pos = xx->pos; + linkNoteData.layer = GetTrkLayer( trk ); + linkNoteData.trk = trk; + strscpy( linkNoteData.url, xx->noteData.linkData.url, sizeof linkNoteData.url ); + strscpy( linkNoteData.title, xx->noteData.linkData.title, + sizeof linkNoteData.title ); + + CreateEditLinkDialog(_("Update Weblink")); } /** @@ -245,12 +237,13 @@ void DescribeLinkNote(track_p trk, char * str, CSIZE_T len) * \param the newly created trk */ -void NewLinkNoteUI(track_p trk) +void NewLinkNoteUI( coOrd pos ) { - struct extraDataNote_t *xx = GET_EXTRA_DATA( trk, T_NOTE, extraDataNote_t ); - - xx->noteData.linkData.url = MyStrdup( DEFAULTLINKURL ); - xx->noteData.linkData.title = MyStrdup( DEFAULTLINKTITLE ); + linkNoteData.pos = pos; + linkNoteData.layer = curLayer; + linkNoteData.trk = NULL; + strscpy( linkNoteData.url, DEFAULTLINKURL, sizeof( linkNoteData.url ) ); + strscpy( linkNoteData.title, DEFAULTLINKTITLE, sizeof( linkNoteData.title ) ); - CreateEditLinkDialog(trk, _("Create link")); + CreateEditLinkDialog(_("Create Weblink")); } |