📄 projlistgui.c
字号:
SetFieldTextFromStr(nameField,srcProjectName,false); FrmDrawForm(frm); // have to do now to be compatible with pre-3.5 FrmSetFocus(frm,FrmGetObjectIndex(frm,Fld_Project_Name)); FldSetSelection(nameField, 0, StrLen(srcProjectName)); FldSetDirty(nameField, false); hitButton=FrmDoDialog(frm); switch(hitButton) { case Btn_Choose_Name_Ok: // if they didn't enter anything, treat as cancel if (!FldDirty(nameField)) { hitButton=Btn_Choose_Name_Cancel; break; } tempName=FldGetTextPtr(nameField); // if they didn't enter anything, treat as cancel if (!tempName[0]) { hitButton=Btn_Choose_Name_Cancel; break; } SafeCopy(destProjectName,tempName,dmDBNameLength); break; case Btn_Choose_Name_Cancel: break; } FrmDeleteForm(frm); return hitButton;} // void HandleCreateNewButtonOK(void)/*Boolean FrmChooseNameHandleEvent (EventPtr e){ Boolean handled = false; FormPtr frm; frm = FrmGetActiveForm(); switch (e->eType) { case frmOpenEvent: if (OSCaps.handera) { VgaFormModify(frm, vgaFormModify160To240); } if ((ChooseNameFunction == ChooseNameRename) || (ChooseNameFunction == ChooseNameDoc)) { UInt32 stringSize=StrLen(ProjectList_Globals.fromDatabaseName); FieldPtr fldPtr = GetObjectPtr(Fld_Project_Name); FldSetSelection(fldPtr, 0, 0); FldInsert(fldPtr, ProjectList_Globals.fromDatabaseName,stringSize); FldSetSelection(fldPtr, 0, stringSize); FldSetDirty(fldPtr, false); } FrmDrawForm(frm); FrmSetFocus(frm, FrmGetObjectIndex(frm, Fld_Project_Name)); handled = true; break; case frmCloseEvent: // handled = false break; case menuEvent: handled = true; break; case ctlSelectEvent: switch(e->data.ctlSelect.controlID) { case Btn_Choose_Name_Ok:// handled = HandleChooseNameButtonOK(); break; case Btn_Choose_Name_Cancel: FrmReturnToForm(0); handled = true; break; default: break; } break; case keyDownEvent: switch (e->data.keyDown.chr) { case chrCarriageReturn: case chrLineFeed:// HandleChooseNameButtonOK(); handled = true; break; default: break; } break; default: break; } return handled;} // static Boolean FrmChooseNameHandleEvent (EventPtr e)*/void ProjectListDrawRecord (void * table, Int16 row, Int16 column, RectanglePtr bounds){ UInt16 recordNum;// Err error; ProjectListEntry *record; char noteChar; FontID currFont;// Int16 phoneX; // handle redraws after the form data has been destructed if (ProjectList_Globals.formClosing) return; // Get the record number that corresponds to the table item to draw. // The record number is stored in the "intValue" field of the item. // recordNum = TblGetRowID (table, row); record = ProjectListMODELGetRecord(recordNum); if (NULL == record) { ErrNonFatalDisplay ("Record not found"); return; } switch (column) { case projectNameColumn: currFont = FntSetFont (stdFont); WinDrawChars (record->databaseName, StrLen(record->databaseName), bounds->topLeft.x, bounds->topLeft.y); FntSetFont (currFont); break; case noteIconColumn: // Draw a note symbol if the field has a note. if (record->note[0]) { currFont = FntSetFont (symbolFont); noteChar = symbolNote; WinDrawChars (¬eChar, 1, bounds->topLeft.x, bounds->topLeft.y); FntSetFont (currFont); } break; } MemPtrUnlock(record);}void ProjectListLoadTable(FormType *frmP){ UInt16 row; UInt16 numRows; UInt16 lineHeight; UInt16 recordNum; UInt16 visibleRows; FontID currFont; TableType* tblP;// +++ FIX THIS +++ Used by code that is not compatible with PalmOS 3.1, but we do not need it yet// UInt16 attr;// Boolean masked;// +++ FIX THIS +++ Used by code that is not compatible with PalmOS 3.1, but we do not need it yet // Reloading table loses table selection ProjectList_Globals.LastSelectedRecord=noRecord; // For each row in the table, store the record number as the row id. tblP=(TablePtr) FrmGetObjectPtr(frmP,FrmGetObjectIndex(frmP,ProjectListTable)); TblUnhighlightSelection(tblP); // Make sure we haven't scrolled too far down the list of records // leaving blank lines in the table. // Try going forward to the last record that should be visible visibleRows = ProjectListNumberOfRowsInTable(tblP); recordNum = ProjectList_Globals.TopVisibleRecord; if (!ProjectListMODELSeekRecord (&recordNum, visibleRows - 1, dmSeekForward)) { // We have at least one line without a record. Fix it. // Try going backwards one page from the last record ProjectList_Globals.TopVisibleRecord = dmMaxRecordIndex; if (!ProjectListMODELSeekRecord (&ProjectList_Globals.TopVisibleRecord, visibleRows - 1, dmSeekBackward)) { // Not enough records to fill one page. Start with the first record ProjectList_Globals.TopVisibleRecord = 0; ProjectListMODELSeekRecord (&ProjectList_Globals.TopVisibleRecord, 0, dmSeekForward); } } currFont = FntSetFont (stdFont); lineHeight = FntLineHeight (); FntSetFont (currFont); numRows = TblGetNumberOfRows(tblP); recordNum = ProjectList_Globals.TopVisibleRecord; for (row = 0; row < visibleRows; row++) { if ( ! ProjectListMODELSeekRecord (&recordNum, 0, dmSeekForward)) break; // Make the row usable. TblSetRowUsable (tblP, row, true);// +++ FIX THIS +++ this code not compatible with PalmOS 3.1, but we don't need yet anyway// DmRecordInfo (ProjectListMODELGetDBRef(), recordNum, &attr, NULL, NULL);// masked = (((attr & dmRecAttrSecret) && ProjectList_Globals.PrivateRecordVisualStatus == maskPrivateRecords));// TblSetRowMasked(tblP,row,masked); // Mark the row invalid so that it will draw when we call the // draw routine. TblMarkRowInvalid (tblP, row); // Store the record number as the row id. TblSetRowID (tblP, row, recordNum); TblSetItemFont (tblP, row, projectNameColumn, stdFont); TblSetRowHeight (tblP, row, lineHeight); recordNum++; } // Hide the item that don't have any data. while (row < numRows) { TblSetRowUsable (tblP, row, false); row++; } ProjectListUpdateScrollButtons(frmP);}UInt16 ProjectListNumberOfRowsInTable (TablePtr table){ UInt16 rows; UInt16 rowsInTable; UInt16 tableHeight; FontID currFont; RectangleType r; rowsInTable = TblGetNumberOfRows (table); TblGetBounds (table, &r); tableHeight = r.extent.y; currFont = FntSetFont (stdFont); rows = tableHeight / FntLineHeight (); FntSetFont (currFont); if (rows <= rowsInTable) return (rows); else return (rowsInTable);}void ProjectListHandleOpen(void){ProjectListEntry *record;UInt16 selectedRecord;Err err; selectedRecord=ProjectListGetCurrentSelection(); if (noRecord == selectedRecord) { DEBUG1("Please select a project to open first"); return; } record=ProjectListMODELGetRecord(selectedRecord); err=OpenDB(record->cardNumber,record->databaseName,&gdbP); MemPtrUnlock(record); if(errNone == err) FrmGotoForm(FrmMain);}void ProjectListHandleNew(void){Char projectName[dmDBNameLength]; if (Btn_Choose_Name_Ok == ShowChooseNameDialog("",projectName)) { if(CreateDB(projectName)) { FrmCustomAlert(AltAlreadyExists, name, NULL, NULL); } else { // don't need to update because we are jumping to another form // FrmUpdateForm(FrmProjectList, frmUpdateTableCode); if(errNone == OpenDB(0,projectName,&gdbP)) FrmGotoForm(FrmMain); } }}void ProjectListHandleRename(void){ProjectListEntry *record;UInt16 currentSelection;Char projectName[dmDBNameLength]; // if we have a selection if (noRecord != ProjectListGetCurrentSelection()) { currentSelection = ProjectListGetCurrentSelection(); record = ProjectListMODELGetRecord(currentSelection); if (Btn_Choose_Name_Ok == ShowChooseNameDialog(record->databaseName,projectName)) { if(RenameDB(record->databaseName, projectName)) { FrmCustomAlert(AltAlreadyExists, projectName, NULL, NULL); } FrmUpdateForm(FrmProjectList, frmUpdateTableCode); } MemPtrUnlock(record); } else { DEBUG1("Please select a project to rename first"); }}void ProjectListUpdateScrollButtons( FormType* frmP ){ UInt16 row; UInt16 upIndex; UInt16 downIndex; UInt16 recordNum; Boolean scrollableUp; Boolean scrollableDown; TableType* tblP; // Update the button that scroll the list. // // If the first record displayed is not the fist record in the category, // enable the up scroller. recordNum = ProjectList_Globals.TopVisibleRecord; scrollableUp = ProjectListMODELSeekRecord (&recordNum, 1, dmSeekBackward); // Find the record in the last row of the table tblP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, ProjectListTable)); row = TblGetLastUsableRow(tblP); if (row != tblUnusableRow) recordNum = TblGetRowID(tblP, row); // If the last record displayed is not the last record in the category, // enable the down scroller. scrollableDown = ProjectListMODELSeekRecord(&recordNum, 1, dmSeekForward); // Update the scroll button. upIndex = FrmGetObjectIndex(frmP, Btn_Scroll_Up); downIndex = FrmGetObjectIndex(frmP, Btn_Scroll_Down); FrmUpdateScrollers(frmP, upIndex, downIndex, scrollableUp, scrollableDown);}/*********************************************************************** * * FUNCTION: ProjectListScroll * * DESCRIPTION: This routine scrolls the list in the direction specified. * * PARAMETERS: direction - up or dowm * units - unit amount to scroll * byLine - if true, list scrolls in line units * - if false, list scrolls in page units * * RETURNED: nothing * ***********************************************************************/void ProjectListScroll (WinDirectionType direction, UInt16 units, Boolean byLine){ TableType* tblP; FormType* frmP; UInt16 rowsInPage; UInt16 newTopVisibleRecord; // Before processing the scroll, be sure that the command bar has been closed. MenuEraseStatus(0); frmP = FrmGetActiveForm(); tblP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, ProjectListTable)); // Safe. There must be at least one row in the table. rowsInPage = ProjectListNumberOfRowsInTable(tblP) - 1; newTopVisibleRecord = ProjectList_Globals.TopVisibleRecord; // Scroll the table down. if (direction == winDown) { // Scroll down by line units if (byLine) { // Scroll down by the requested number of lines if (!ProjectListMODELSeekRecord (&newTopVisibleRecord, units, dmSeekForward)) { // Tried to scroll past bottom. Goto last record newTopVisibleRecord = dmMaxRecordIndex; ProjectListMODELSeekRecord (&newTopVisibleRecord, 1, dmSeekBackward); } } // Scroll in page units else { // Try scrolling down by the requested number of pages if (!ProjectListMODELSeekRecord (&newTopVisibleRecord, units * rowsInPage, dmSeekForward)) { // Hit bottom. Try going backwards one page from the last record newTopVisibleRecord = dmMaxRecordIndex; if (!ProjectListMODELSeekRecord (&newTopVisibleRecord, rowsInPage, dmSeekBackward)) { // Not enough records to fill one page. Goto the first record newTopVisibleRecord = 0; ProjectListMODELSeekRecord (&newTopVisibleRecord, 0, dmSeekForward); } } } } // Scroll the table up else { // Scroll up by line units if (byLine) { // Scroll up by the requested number of lines if (!ProjectListMODELSeekRecord (&newTopVisibleRecord, units, dmSeekBackward)) { // Tried to scroll past top. Goto first record newTopVisibleRecord = 0; ProjectListMODELSeekRecord (&newTopVisibleRecord, 0, dmSeekForward); } } // Scroll in page units else { // Try scrolling up by the requested number of pages if (!ProjectListMODELSeekRecord (&newTopVisibleRecord, units * rowsInPage, dmSeekBackward)) { // Hit top. Goto the first record newTopVisibleRecord = 0; ProjectListMODELSeekRecord (&newTopVisibleRecord, 0, dmSeekForward); } } } // Avoid redraw if no change if (ProjectList_Globals.TopVisibleRecord != newTopVisibleRecord) { ProjectList_Globals.TopVisibleRecord = newTopVisibleRecord; FrmUpdateForm(FrmProjectList, frmUpdateTableCode); }}void ProjectListAdjustScrollRate(void){ // Accelerate the scroll rate every 3 seconds if not already at max scroll speed UInt16 newSeconds = TimGetSeconds(); if ((ProjectList_Globals.ScrollUnits < scrollSpeedLimit) && ((newSeconds - ProjectList_Globals.LastSeconds) > scrollDelay)) { // Save new seconds ProjectList_Globals.LastSeconds = newSeconds; // increase scroll units ProjectList_Globals.ScrollUnits += scrollAcceleration; }}void ProjectListResetScrollRate(void){ // Reset last seconds ProjectList_Globals.LastSeconds = TimGetSeconds(); // Reset scroll units ProjectList_Globals.ScrollUnits = 1;}UInt16 ProjectListGetCurrentSelection(void){ FormType* frmP; TableType* tblP; Int16 selectedRow; Int16 selectedColumn; frmP = FrmGetFormPtr(FrmProjectList); tblP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, ProjectListTable)); if (!TblGetSelection(tblP,&selectedRow,&selectedColumn)) return noRecord; return TblGetRowID (tblP, selectedRow);}void ProjectListNextCategory (void){ UInt16 currentCategory; UInt16 lastCategory; ControlType* ctlP; FormType* frmP; DmOpenRef dbRef; dbRef = ProjectListMODELGetDBRef(); lastCategory = ProjectListMODELGetCurrentCategory(); currentCategory = CategoryGetNext(dbRef, lastCategory); if (currentCategory != lastCategory) { ProjectListMODELSetCurrentCategory(currentCategory); // Set the label of the category trigger. frmP = FrmGetActiveForm(); ctlP = FrmGetObjectPtr(frmP, FrmGetObjectIndex(frmP, ProjectCategoryPopup)); CategoryGetName (dbRef, currentCategory, ProjectList_Globals.CategoryName); CategorySetTriggerLabel(ctlP, ProjectList_Globals.CategoryName); // Display the new category. FrmUpdateForm(FrmProjectList, frmUpdateTableCode); }}void *GetObjectFromForm(FormPtr form, UInt16 objectID){ return FrmGetObjectPtr(form,FrmGetObjectIndex(form,objectID));}Err SetFieldTextFromStr(FieldPtr field, const Char *s, Boolean redraw){ MemHandle h; h = FldGetTextHandle(field); if (h) { Err err; FldSetTextHandle(field, NULL); err = MemHandleResize(h, StrLen(s) + 1); if (err != errNone) { FldSetTextHandle(field, h); // restore handle return err; } } else { h = MemHandleNew(StrLen(s) + 1); if (!h) return memErrNotEnoughSpace; } // at this point, we have a handle of the correct size // copy the string to the locked handle. StrCopy((Char *) MemHandleLock(h), s); // unlock the string handle. MemHandleUnlock(h); FldSetTextHandle(field, h); if (redraw) FldDrawField(field); return errNone;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -