DEFCONST('kDateFormat,GetDateStringSpec([ [kElementMonth, kFormatAbbr], [kElementYear, kFormatLong], [kElementDay, kFormatLong]])); // ---- End Project Data ---- // ---- File test.t ---- main := {title: "Date Protos Sample 2", viewBounds: {left: 0, top: 25, right: 234, bottom: 310}, viewFormat: 83951953, _proto: protoApp, debug: "main" }; _view000 := /* child of main */ { text: "\u00A9\u 1994 Atomic Software. All rights reserved.\n\nFree to distribute and use in your apps! Just let me know you are using it and if you enhance it.\n\nThanks\n Allan Marcus\n\nCIS: 76666,2113\nAppleLink: allan.marcus\neWorld/NewtonMail: allan.m\nInterNet: allan@apple.com\n\n* This is a modified version of Allan's original that he sent to me. See the readme for the changes that I made to it. - Hardy Macia" , viewBounds: {left: 1, top: 14, right: 237, bottom: 234}, viewJustify: 0, _proto: protoStaticText }; // ---- File protoDateTimePicker ---- // ---- File protoFloatDragNGo ---- _userproto000 := {viewBounds: {left: 0, top: 0, right: 10, bottom: 10}, viewFlags: 576, viewClickScript: func(unit) begin // only allow a drag to occur if it is in // the margin of the view // NOTE, all cooridnates are in GLOBAL space // otherwise, pass clicks through to my children local x := GetPoint(firstX, unit), y := GetPoint(firstY, unit), box := base:GlobalBox() ; if (y - box.top) < 10 OR (box.bottom - y) < 10 OR (x - box.left) < 10 OR (box.right - x) < 10 then begin InkOff(unit); base:Drag(unit, nil); self:Dirty();// to get ink dropping up // return true to say handled the click true; end else // return nil so kids can get click nil; end, declareSelf: 'base, viewJustify: 80, _proto: protoFloatNGo }; // ---- Back in File protoDateTimePicker ---- DateTimeView := {viewFlags: 576, viewBounds: {left: 0, top: 0, right: 224, bottom: 148}, OpenMe: func(returnView, myDate, myTitle) begin self.viewToSet := returnView; self.theDate:= myDate; self.theTitle := myTitle; self:Open(); // print("Open me done") end, selectedDates: [], theDate: nil, theTitle: "test", title: "clMonthView Sample", viewSetupFormScript: func() begin if not theDate or not StringToDate(theDate) then theDate:= time(); else theDate := StringToDate(theDate); selectedDates := [theDate]; if date(theDate).hour<12 then ampm.clusterValue:=0; else ampm.clusterValue:=1; setvalue(pickerTitle, 'title, theTitle); end, viewToSet: nil, Update: func(returnView, myDate, myTitle) begin self.viewToSet := returnView; self.theDate:= myDate; self.theTitle := myTitle; // self:viewSetUpFormScript(); if not theDate or not StringToDate(theDate) then theDate:= time(); else theDate := StringToDate(theDate); selectedDates := [theDate]; clock.hours := (theDate DIV 60) mod 24; clock.minutes :=theDate MOD 60; clock:dirty(); clock:setTime(); if date(theDate).hour<12 then ampm:setClusterValue(0); else ampm:setClusterValue(1); setvalue(pickerTitle, 'title, theTitle); datePicker:Refresh(); print("datetime updated") end, AutoClose: True, _proto: _userproto000, debug: "DateTimeView" }; // ---- File protoDatePicker ---- protoDatePicker := {viewFlags: 1, viewFormat: nil, viewBounds: {left: 0, top: 0, right: 120, bottom: 100}, monthChangedScript: func() begin // This will be inherited by the child month view and called every time // the user taps on a new day. It *must* be here because the user can // tap on days at the end or beginning of the previous or next month // (the blank spaces on the view) and actually change the date! // If this script isn't here to update the view and the title string, // the month with change but the display won't--confusing the heck out of // people. :Dirty(); :SetTitle(); end, monthYearSpec: GetDateStringSpec([ [kElementMonth, kFormatLong], [kElementYear, kFormatLong]]), SetTitle: // This function updates the month/year label. It should be called // whenever the user changes the date. func() begin SetValue(monthYearLabel, 'text, LongDateStr(selectedDates[0], monthYearSpec)); end, viewSetupDoneScript: func() begin if NOT selectedDates exists then self.selectedDates := [Time()]; // initialize selectedDates to current :SetTitle(); end, Refresh: // This allows scripts outside the proto to have a nice entry point for // getting the picker refreshed when the selectedDates array changes. func() begin monthView:Dirty(); :SetTitle(); end, viewclass: 74, debug: "protoDatePicker" }; monthYearLabel := /* child of protoDatePicker */ {text: "", viewBounds: {left: 0, top: 0, right: 0, bottom: 15}, viewFlags: 3, viewJustify: 8388662, _proto: protoStaticText, debug: "monthYearLabel" }; // View monthYearLabel is declared to protoDatePicker previousMonthButton := /* child of protoDatePicker */ {viewBounds: {left: 0, top: 0, right: 15, bottom: 15}, viewSetupFormScript: func() begin // initialize the icon from the system bitmap via a magic pointer. self.icon := @325; // leftBitmap end, viewFlags: 515, viewJustify: 6, viewFormat: 1, buttonPressedScript: func() begin // move to the previous month, and make sure the views redraw. selectedDates[0] := IncrementMonth(selectedDates[0], -1); monthView:dirty(); :SetTitle(); // have to call RefreshViews because this is the buttonPressedScript, // the view otherwise wouldn't get refreshed until the user lifted the // pen! If you had done this in the buttonClickScript instead, you // could skip the RefreshViews() call. RefreshViews(); end, icon: nil, _proto: protoPictureButton, debug: "previousMonthButton" }; nextMonthButton := /* child of protoDatePicker */ {icon: nil, viewBounds: {top: 0, left: -15, right: 0, bottom: 15}, viewSetupFormScript: func() begin // initialize the bitmap from the system ROMs via a magic pointer. self.icon := @326; // rightBitmap end, viewFlags: 515, viewFormat: 1, viewJustify: 38, buttonPressedScript: func() begin // move to the previous month, and make sure the views redraw. selectedDates[0] := IncrementMonth(selectedDates[0], 1); monthView:dirty(); :SetTitle(); // have to call RefreshViews because this is the buttonPressedScript, // the view otherwise wouldn't get refreshed until the user lifted the // pen! If you had done this in the buttonClickScript instead, you // could skip the RefreshViews() call. RefreshViews(); end, _proto: protoPictureButton, debug: "nextMonthButton" }; monthView := /* child of protoDatePicker */ {viewBounds: {top: 15, left: 1, right: -1, bottom: -1}, viewFlags: 513, viewFormat: nil, labelFont: ROM_fontSystem9Bold, dateFont: ROM_fontSystem9, viewJustify: 246, singleDay: true, viewclass: 80, debug: "monthView" }; // View monthView is declared to protoDatePicker // ---- Back in File protoDateTimePicker ---- datePicker := /* child of DateTimeView */ {viewBounds: {left: 9, top: 30, right: 129, bottom: 118}, viewFormat: 336, _proto: protoDatePicker, debug: "datePicker" }; // View datePicker is declared to DateTimeView // ---- File protoAdjustoButton ---- // Before Script for "_userproto001" // Copyright, © 1994 Apple Computer. All rights reserved. _userproto001 := {buttonHeight: 13, textSpacer: 8, viewSetupFormScript: func() begin viewBounds := RelBounds(viewBounds.left, viewBounds.top, StrFontWidth(text, viewFont) + textSpacer, buttonHeight) ; end, viewChangedScript: func(slot, view) begin inherited:?viewChangedScript(slot, view) ; if slot = 'text then :SyncView(); // SyncView causes the viewSetupFormScript to be called again, // which sets the size based on the text. end, _proto: protoTextButton }; // ---- Back in File protoDateTimePicker ---- _view001 := /* child of DateTimeView */ {text: "Today/Now", buttonClickScript: func() begin selectedDates := [Time()]; datePicker:Refresh(); clock.hours := (Time() DIV 60) mod 24; clock.minutes := Time() MOD 60; clock:dirty(); clock:setTime(); if date(Time()).hour<12 then ampm:setClusterValue(0); else ampm:setClusterValue(1); end, viewBounds: {left: 9, top: 132, right: 77, bottom: 144}, _proto: _userproto001 }; enter := /* child of DateTimeView */ {text: "Set", buttonClickScript: func() begin local am:=clone(getglobals().international.currentlocalebundle.timeformat.morningStr); local pm:=clone(getglobals().international.currentlocalebundle.timeformat.eveningStr); if ampm.clusterValue = 0 then x := stringtodate(longdatestr(selectedDates[0],0) && theTime.text & am); else x := stringtodate(longdatestr(selectedDates[0],0) && theTime.text & pm); viewToSet:PickedDate(x); // SetValue(viewToSet, 'text, DateNTime(x)); if autoClose then :Parent():Close(); end, viewBounds: {left: 107, top: 132, right: 161, bottom: 144}, _proto: _userproto001, debug: "enter" }; // View enter is declared to DateTimeView clock := /* child of DateTimeView */ { timeChanged: func() begin // do this so the old hands are erased... self:Dirty(); // this is just for fun, put your own stuff here... //print("H:" && hours && "M:" && minutes); :setTime(); end, hours: 14, minutes: 10, viewBounds: {left: 152, top: 26, right: 216, bottom: 90}, viewSetupFormScript: func() begin self.hours := (theDate DIV 60) mod 24; self.minutes := theDate MOD 60; self:dirty(); :setTIme(); // print("Clock set up"); end, SetTime: func() begin local myHours:=self.hours, myMinutes := self.minutes, x, y, myArray; //print(hours&minutes); if GetLocale().TimeFormat.timeCycle = kCycle12 then begin if myHours = 0 then myHours:=12; if myHours > 12 then myHours := myHours - 12; end else begin if ampm.clusterValue = 1 then begin if myHours < 12 then myHours := myHours + 12; end else begin if myHours > 11 then myHours := myHours - 12; end; end; y:=clone(getglobals().international.currentlocalebundle.timeformat.timeSepStr1); if myMinutes < 10 then x:=(myHours & y & "0" & myMinutes); else x:=(myHours & y & myMinutes); setvalue(theTime, 'text, x); end, _proto: protoSetClock, debug: "clock" }; // View clock is declared to DateTimeView theTime := /* child of DateTimeView */ {text: "00:00", viewBounds: {left: 167, top: 96, right: 202, bottom: 110}, viewFont: simpleFont9, viewJustify: 8388610, _proto: protoStaticText, debug: "theTime" }; // View theTime is declared to DateTimeView pickerTitle := /* child of DateTimeView */ {title: "Title", viewBounds: {left: 4, top: 7, right: 200, bottom: 23}, _proto: protoTitle, debug: "pickerTitle" }; // View pickerTitle is declared to DateTimeView ampm := /* child of DateTimeView */ {viewBounds: {left: 152, top: 110, right: 224, bottom: 126}, _proto: protoRadioCluster, debug: "ampm" }; // View ampm is declared to DateTimeView am := /* child of ampm */ {buttonValue: 0, viewBounds: {left: 0, top: 0, right: 32, bottom: 13}, text: "AM", viewSetupFormScript: func() begin // local x:=clone(getglobals().international.currentlocalebundle.timeformat.morningStr); // setValue(self, 'text, trimstring(x)); // print(trimstring(x)); end, _proto: protoRadioButton, debug: "am" }; pm := /* child of ampm */ {buttonValue: 1, viewBounds: {left: 35, top: 0, right: 67, bottom: 13}, text: "PM", viewSetupFormScript: func() begin // if 0 = StrLen(getglobals().international.currentlocalebundle.timeformat.eveningStr) then // setValue(self, 'text, trimstring(x)); // print(trimstring(x)); end, _proto: protoRadioButton, debug: "pm" }; // ---- Back in File test.t ---- dateTimePicker := /* child of main */ {_proto: DateTimeView, debug: "dateTimePicker"}; // View dateTimePicker is declared to main // ---- File protoDateEditorInputLine ---- dateEditorInputLine := {viewBounds: {left: 19, top: 64, right: -21, bottom: 80}, viewJustify: 8388656, labelCommands: [], labelClick: func(unit) begin if self:TrackHilite(unit) then begin if Visible(dateTimePicker) then dateTimePicker:Close(); // I didn't want to do this, but to get the date picker to open correctly // every time I needed to do the deferred action. local myView := self; AddDeferredAction(func() begin // params to OpenMe are // (the view that gets the PickedDate message, // the default date to show, and // the title for the date picker view) dateTimePicker:OpenMe(entryLine, entryLine.text, label); myView:Hilite(nil); end, '[]); end; return(true); // say I handled the click. end, label: "Date", entryFlags: 539137, Date: nil, textSetup: func() :textFormat(date);, viewSetupDoneScript: func() begin SetValue(entryLine,'viewFont,userFont10); if Visible(dateTimePicker) then dateTimePicker:Update(entryLine, entryLine.text, label); end, PickedDate: func(internalDate) // is called by datepicker when user taps "set" you must process // the internal date passed to you and display it begin Date := internalDate; SetValue(entryline,'text,:textFormat(Date)); end, textFormat: func(duhDate) if duhDate then LongDateStr(duhDate,kDateFormat); else "";, viewSetupFormScript: func() // I think I'm using this in my project that's why it is here. You can delete it. begin // date := filterFromDate; end, viewlinespacing: 12, textChanged: func() if NOT text OR StrLen(text) = 0 then date := nil; else date := StringToDate(TrimString(text));, _proto: protoLabelInputLine, debug: "dateEditorInputLine" }; // ---- Back in File test.t ---- DateTimeInputLine := /* child of main */ {viewBounds: {left: 9, top: 253, right: 222, bottom: 273}, viewJustify: 8388608, textFormat: func(duhDate) if duhDate then DateNTime(duhDate); else "";, label: "Date & Time", _proto: dateEditorInputLine, debug: "DateTimeInputLine" }; DateInputLine := /* child of main */ {viewBounds: {left: 9, top: 233, right: 222, bottom: 253}, viewJustify: 8388608, labelClick: func(unit) //changed dateTimePicker to datePicker begin if self:TrackHilite(unit) then begin if Visible(datePicker) then datePicker:Close(); // I didn't want to do this, but to get the date picker to open correctly // every time I needed to do the deferred action. The drawback is that the // button is unhilited right away local myView := self; AddDeferredAction(func() begin // params to OpenMe are // (the view that gets the PickedDate message, // the default date to show, and // the title for the date picker view) datePicker:OpenMe(entryLine, entryLine.text, label); myView:Hilite(nil); end, '[]); end; return(true); // say I handled the click. end, viewSetupDoneScript: func() begin SetValue(entryLine,'viewFont,userFont10); if Visible(datePicker) then datePicker:Update(entryLine, entryLine.text, label); end, _proto: dateEditorInputLine, debug: "DateInputLine" }; // ---- File protoDatePickerPicker ---- DateTimeView := {viewBounds: {left: 0, top: 0, right: 135, bottom: 133}, OpenMe: func(returnView, myDate, myTitle) begin self.viewToSet := returnView; self.theDate:= myDate; self.theTitle := myTitle; self:Open(); // print("Open me done") end, selectedDates: [], theDate: nil, theTitle: "test", title: "clMonthView Sample", viewSetupFormScript: func() begin if not theDate or not StringToDate(theDate) then theDate:= time(); else theDate := StringToDate(theDate); selectedDates := [theDate]; setvalue(pickerTitle, 'title, theTitle); end, viewToSet: nil, declareSelf: 'base, Update: func(returnView, myDate, myTitle) begin self.viewToSet := returnView; self.theDate:= myDate; self.theTitle := myTitle; // self:viewSetUpFormScript(); if not theDate or not StringToDate(theDate) then theDate:= time(); else theDate := StringToDate(theDate); selectedDates := [theDate]; setvalue(pickerTitle, 'title, theTitle); datePicker:Refresh(); print("datetime updated") end, AutoClose: True, _proto: _userproto000, debug: "DateTimeView" }; datePicker := /* child of DateTimeView */ {viewBounds: {left: 7, top: 22, right: 127, bottom: 110}, viewFormat: 336, _proto: protoDatePicker, debug: "datePicker" }; // View datePicker is declared to DateTimeView _view002 := /* child of DateTimeView */ {text: "Today", buttonClickScript: func() begin selectedDates := [Time()]; datePicker:Refresh(); end, viewBounds: {left: 14, top: 118, right: 65, bottom: 130}, _proto: _userproto001 }; enter := /* child of DateTimeView */ {text: "Set", buttonClickScript: func() begin print(selectedDates); viewToSet:PickedDate(selectedDates[0]); // x := stringtodate(longdatestr(selectedDates[0],0)); // SetValue(viewToSet, 'text, DateNTime(x)); if autoClose then :Parent():Close(); end, viewBounds: {left: 73, top: 118, right: 112, bottom: 130}, _proto: _userproto001, debug: "enter" }; // View enter is declared to DateTimeView _view003 := /* child of DateTimeView */ {_proto: protoClosebox}; pickerTitle := /* child of DateTimeView */ {title: "Title", viewBounds: {left: 4, top: 7, right: 200, bottom: 23}, _proto: protoTitle, debug: "pickerTitle" }; // View pickerTitle is declared to DateTimeView // ---- Back in File test.t ---- datePicker := /* child of main */ {_proto: DateTimeView, debug: "datePicker"}; // View datePicker is declared to main autoClose setter := /* child of main */ { labelCommands: ["Auto Close Date Editors on Set","Manually Close Date Editor with x"], viewBounds: {left: 20, top: 274, right: 220, bottom: 287}, labelActionScript: func(cmd) begin if cmd = 0 then dateTimePicker.AutoClose := datePicker.AutoClose := True; else dateTimePicker.AutoClose := datePicker.AutoClose := nil; end, _proto: protoLabelPicker, debug: "autoClose setter" }; // ---- Beginning of section for non used Layout files ---- // End of output