Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Systems Programming (CS 0449) User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS.

Similar presentations


Presentation on theme: "Introduction to Systems Programming (CS 0449) User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS."— Presentation transcript:

1 Introduction to Systems Programming (CS 0449) User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS Bible Book )

2 Palm OS Resources -User Interface Elements Forms Alerts Menus Tables Lists Pop-up Triggers Buttons Repeating Buttons Selector Triggers Push Buttons Check Boxes Slides Labels Form Bitmaps Fields Graffiti Shift Indicator Scroll Bars Gadgets

3 Palm Resources (User Interface Elements) Forms Alerts Menus Tables Lists/Popup Buttons Push buttons Check boxes Sliders, scrollbars Labels Look Up: Form bitmaps TextFields

4 Resource Files //This is a file used by PilRC to create a.prc file. #include "helloRsc.h" APPLICATIONICONNAME ID 100 "Hello 1" APPLICATION ID 1 "49p1" VERSION ID 1 "1.0.0g" ICONFAMILY "largeicon_1bpp.bmp" "largeicon_2bpp.bmp" "" "largeicon_8bpp.bmp" TRANSPARENT 0 255 0 SMALLICONFAMILY "smallicon_1bpp.bmp" "smallicon_2bpp.bmp" "" "smallicon_8bpp.bmp" TRANSPARENT 0 255 0

5 Resource Files (2) // Here we define the form that we need for our program. FORM ID MainForm AT (0 0 160 160) //more details next USABLE BEGIN TITLE "Hello World" END ALERT ID ByeAlert//more details after next INFORMATION BEGIN TITLE "Hello World Alert" MESSAGE "Goodbye, my friend !" BUTTONS "OK" END

6 Resource Files (3) BITMAP ID MyBitmap "picture.bmp" COMPRESS FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE "Hello World“ TABLE ID MainTable AT (0 16 160 121) ROWS 11 COLUMNS 9 COLUMNWIDTHS 12 25 12 18 12 33 17 20 9 LABEL "Enter your name here:" AUTOID AT (0 17) FONT 1 FIELD ID MyFieldName AT (PrevLeft PrevBottom 159 13) UNDERLINED AUTOSHIFT MAXCHARS 40 BUTTON "Hello" ID MyButtonHi AT (1 147 AUTO AUTO) BUTTON "Bye" ID MyButtonBye AT (PrevRight+5 PrevTop AUTO AUTO) FORMBITMAP AT (7 19) BITMAP MyBitmap END

7 Programming User Interface Elements - ALERT Programming Alerts An Alert resource dialog box could be either 1.Information. (i) 2.Confirmation. (?) 3.Warning. (!) 4.Error. (x) ALERT ID HelloAlert INFORMATION BEGIN TITLE “Hello World” (i) MESSAGE “Good Day To you, My Friend, ^1 !” BUTTONS “OK” END // ^1 resource ID –first arg in FrmCustomAlert(HelloAlert, “yourname”) ALERT ID DeleteAlert CONFIRMATION BEGIN TITLE “Please Confirm deletion” (?) MESSAGE “About to delete ^1 records from ^2 category!” “Proceed?” BUTTONS “OK” “Cancel” END // ^2 –2 nd arg in FrmCustomAlert(DeleteAlert,”5”, business”, NULL) FrmAlert ( ) is equivalent to FrmCustonAlert(AlertID, NULL, NULL, NULL) –does not take ^1, ^2, ^3 To include ^`, ^2, ^3, then use FrmCustomALert

8 Programming User Interface Elements - ALERT ALERT ID WarningAlert WARNING BEGIN TITLE “Warning Alert Dialog Box” (!) MESSAGE “Are you sure you want to delete, ^1 !” BUTTONS “Yes” “NO” END // ^1 resource ID –first arg in FrmCustomAlert(WarningAlert) ALERT ID ErrorAlert ERROR BEGIN TITLE ”Password Dialog Box” (x) MESSAGE “Incorrect Password” BUTTONS “OK” END

9 Creating Resources – Adding Objects to a Form Resource 1)BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@, RIGHT@, BOTTOM@, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON“HEX”IDHexGROUP 1 PUSHBUTTON“DEC”IDDecGROUP 1 3) CHECKBOXES: CHECKBOX “label” ID resourceID AT (Left Top Width Height)

10 Creating Resources – Adding Objects to a Form Resource 4) Fields: FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARS maxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR] [DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll. [ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field. [HASSCROLLBAR] – update scrollbar constantly.

11 Creating Resources – Adding Objects to a Form Resource 1)BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@, RIGHT@, BOTTOM@, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON“HEX”IDHexGROUP 1 PUSHBUTTON“DEC”IDDecGROUP 1 3) CHECKBOXES: HEX DEC CHECKBOX “label” ID resourceID AT (Left Top Width Height) HEXDEC 1)BUTTONS: BUTTON “label” ID resourceID AT (Left Top Width Height) AT Positions: AUTO, CENTER, CENTER@, RIGHT@, BOTTOM@, PREVLEFT, PREVRIGHT, PREVTOP, PREVBOTTOM, PREVWIDTH,PREVHEIGHT. 2) PUSHBUTTONS: PUSHBUTTON“HEX”IDHexGROUP 1 PUSHBUTTON“DEC”IDDecGROUP 1 3) CHECKBOXES: HEX DEC CHECKBOX “label” ID resourceID AT (Left Top Width Height)

12 Creating Resources – Adding Objects to a Form Resource 4) Text Fields:Enter your name: ______________ FIELD “label” ID resourceID AT (Left Top Width Height) [ USABLE | NONUSABLE ] [LEFTALIGN | RIGHTALIGN] [ FONT fontnumber ] [EDITABLE | NONEDITABLE] [ UNDERLINED] [ SINGLELINE | MULTIPLELINES] [DYNAMICSIZE] MAXCHARS maxChars [ AUTOSHIFT ] [NUMERIC] [HASSCROLLBAR] [DYNAMICSIZE]– causes field to out fldheightChangedEvent onto the queue whenever user input causes field to scroll. [ AUTOSHIFT ]– tells system to perform graffiti auto shifting in the field. [HASSCROLLBAR] – update scrollbar constantly.

13 Programming User Interface Elements – Forms FORM ID MainForm AT (0 0 160 160) USABLE | MODAL BEGIN TITLE "CS 0449 Calculator“ FIELDIDInputFldAT(14 20 130 24) FONT 0 UNDERLINED SINGLELINE MAXCHARS 8 BUTTON "1" ID One BUTTON "F" ID HexF PUSHBUTTON“HEX”IDHexGROUP 1 PUSHBUTTON“DEC”IDDecGROUP 1 BUTTON "Exit" ID Exit END

14 Programming User Interface Elements - Forms Programming Forms 1-Switch to a new form: Erase current form and display a new one (Full-SCREEN, VIEWS-Modeless, or USABLE) 2-Display a modal dialog box: A quick prompt for user input. i.e. delete confirmation dialog box (POP-UP, MODAL-DIALOGS) - MODAL: forms and windows ignore taps outside them. User must finish the dialog and exit the form. FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE "CS 0449 Calculator“ FIELDIDInputFldAT(14 20 130 24) FONT 0 UNDERLINED SINGLELINE MAXCHARS 8 BUTTON "1" ID One BUTTON "F" ID HexF PUSHBUTTON“HEX”IDHexGROUP 1 PUSHBUTTON“DEC”IDDecGROUP 1 BUTTON "Exit" ID Exit END FORM ID MainForm AT (0 0 160 160) MODAL DEFAULTBTNID MyDeleteButtonID BEGIN TITLE “Delete Book“ LABEL “Delete Selected Book Record?” BUTTON “OK" ID DeleteBookOK BUTTON “Cancel” IDDeleteBookCancel END

15 Programming User Interface Elements - Forms Programming Forms 1-Switch to a new form: Erase current form and display a new one. 2-Display a modal dialog box: A quick prompt for user input, i.e. delete confirmation dialog box. To switch forms call: FrmGotoForm( MyOtherFormID ) What happens in OS? frmColseEvent is sent to the current form FrmHandleEvent() takes care of this event frmLoadEvent is sent to MyOtherForm from your AppHandleEvent() call: FrmInitForm() FrmSetActiveForm() FrmSetEventHandler() FrmOpenEvent -- respond by calling FrmDrawForm()

16 Event Driven Architecture PalmMain() AppEventLoop() AppHandleEvent() MainFormHandleEvent() FrmDispatchEvent() frmColseEvent FrmHandleEvent() Events frmLoadEvent FrmInitForm() FrmSetActiveForm() FrmSetEventHandler() frmOpenEvent FrmDrawForm()

17 Hiding and Showing Form Objects (page 270 – Palm OS Bible) // Hides MyButtonID when MyHideBushbuttonID tapped //... in your FormHandleEvent()... and Handling Control Groups (pp.273) on pushbuttons and check boxes. if( event -> eType == ctlSelectEvent ) { switch ( event. data. ctlSelect. controlID ) { //see what button is tapped case MyHidePushButtonID : form = GetActiveForm( ); //get active form buttonIndex =FrmGetObjectIndex( form, MyButton); ctl = GetObjectPtr (MyHidePushButtonID); if( CtlGetValue ( ctl ) ) FrmHideObject( form, buttonIndex ); //Hide Pushbutton else FrmShowObject( form, buttonIndex ); //Show Pushbutton break; case MyButton :...//do something when user taps MyButton }Related Slides for CsCalProjectRelated Slides for CsCalProject

18 Adding TABLE to Form //...in the resource file, add to the form definition FORM ID MainForm AT (0 0 160 160) USABLE BEGIN TITLE “Tables“ TABLE ID MainTable AT (0 16 160 121) ROWS 11 COLUMNS 9 COLUMNWIDTHS 12 25 12 18 12 33 17 20 9 BUTTON “HideRows” ID MainHideRowsButton AT(1 147 50 12) BUTTON “HideColumns” ID MainHideColumnsButton AT(56 147 64 12) LIST “X” “Y” “Z” ID MainList AT(120 141 19 33) NONUSABLE VISIBLEITEMS 3... END

19 typedef struct{// in Table.h TableItemStyleTypeitemType; FontIDfontID; Int16intValue; Char *ptr; } TableItemType; Item Type Editable by User TableItemType Fields Used by This type checkboxTableItemYesintValue customTableItemYes None, although you may store data in the intValue and ptr fields if required by yourapplication dataTableItemNointValue labelTableItemNoptr numericTableItemNointValue popupTriggerTableItemYesintValue, ptr textTableItemYesfontID, ptr textWithNoteTableItemYesfontID, ptr narrowTextTableItemYesfontID, intValue, ptr TABLE Item Types (ref: table page 397)

20 TblSetItemStyle(params) -- Set value of the table item’s itemType field Given a pointer to the table, the row and column of the item to set, and the type desired. params= (ptr to table, row of cell to set, column of cell to set, TableItemStyleType value) TblSetItemFont( ) -- Set fontID for a table item. TblSetItemInt( ) -- Set the intValue. TblSetItemPtr( ) -- Set the ptr field. TblGetItemFont( ) – Retrieve the fontID for a table item. TblGetItemInt( ) – Retrieve the intValue. TblGetItemPtr( ) -- Retrieve the ptr field. Given a pointer to the table, the row & column of the desired table item. PalmOS Table Functions: Set/Retrieve Values

21 -Usually, initializing the table is when handling the form’s frmOpenEvent -In the given table sample code, - MainFormHandleEvent initializes the form in the MainFormInit static Boolean MainFormHandleEvent(EventPtr event) { Boolean handled = false; FormPtr form; switch (event->eType) { case frmOpenEvent: form = FrmGetActiveForm(); MainFormInit(form); FrmDrawForm(form); handled = true; //other event handling omitted default: break; } return handled; } Initializing a Table Click to see MainFormInit() functionMainFormInit() Table sample codes: Table.c MainFormInit() MainFormHandleEventTable.cMainFormInit() MainFormHandleEvent

22 // allocate new memory handle for each array element and filling the handle’s contents with single training null. static Err StartApplication(void) { Int16 i, j; for (i = 0; i < numTextColumns; i++) { //num of columns for (j = 0; j < numTableRows; j++) {//num of rows Char *str; gTextHandles[i][j] = MemHandleNew(1); str = MemHandleLock(gTextHandles[i][j]); *str = '\0'; MemHandleUnlock(gTextHandles[i][j]); } return false; } Initializing a Table Array in StartApplication

23 Creating Menu Resource pg 244, PalmOS Bible MENU ID MyMenuID BEGIN PULLDOWN "Edit" BEGIN MENUITEM "Copy" ID MyMenuCopyID"C" MENUITEM "Paste" ID MyMenuPasteID"P" END PULLDOWN "Help" BEGIN MENUITEM "Help" ID MyMenuHelpID"H" MENUITEM SEPARATOR MENUITEM "About" ID MyMenuAboutID"A" END

24 Adding Menu to Form //...in the resource file, add to the form definition FORM ID MainForm AT (0 0 160 160) MENUID MyMenuID USABLE BEGIN TITLE "CsCalc by Leo"... END

25 Programming Menus pg 296, PalmOS Bible //... in your FormHandleEvent() if( event -> eType == menuEvent ) { switch ( event. data. menu. itemID ) { case MyMenuCopyID : // Do your copy business break; case MyMenuPasteID : // Do your paste business break;... }

26 Using Standard Edit Menu Sometimes we can use resources that are built in Palm OS, such as Edit menu –We still have to define the menu resource, using the correct IDs –We do not need to write code, it is built in PalmOS Details in PalmOS Bible, pg 247.


Download ppt "Introduction to Systems Programming (CS 0449) User Interface Elements (UIE) - Resources Palm OS resources ( Ch.4—PDA Programming in C Book & Ch.6,7 PalmOS."

Similar presentations


Ads by Google