42
Getting started with the Ribbon Library Peter Horsbøll Møller March 2015

Getting started with the ribbon library for MapBasic

Embed Size (px)

Citation preview

Page 1: Getting started with the ribbon library for MapBasic

Getting started with the Ribbon Library

Peter Horsbøll MøllerMarch 2015

Page 2: Getting started with the ribbon library for MapBasic

This will help you getting started with the Ribbon Library to develop MapBasicapplications for the new ribbon based MapInfo Pro 64 bit.

Page 3: Getting started with the ribbon library for MapBasic

Prerequisites:

Download and install:- MapInfo Pro 12.5 64 bit

Get it >>>- MapBasic 12.5.1

Get it >>>

Page 4: Getting started with the ribbon library for MapBasic

Get the Ribbon Library

You can get the Ribbon Library from:

Github.com:• https://github.com/PeterHorsbollMoller/mbRibbonExample

Community Download:• http://communitydownloads.pbinsight.com/code-exchange/download/ribbon-

library-for-mapbasic

Page 5: Getting started with the ribbon library for MapBasic

Unzip the Ribbon Library

Sample Application

Sample tables

Icons for the ribbon

Full source code

Page 6: Getting started with the ribbon library for MapBasic

Running the RibbonExample

Page 7: Getting started with the ribbon library for MapBasic

”How can I use the Ribbon Library in my own MapBasic project?

Page 8: Getting started with the ribbon library for MapBasic

Create a new file structure

Create a new base folder

Create a sub folder for your MapBasic source code

Base folder

Source code

Page 9: Getting started with the ribbon library for MapBasic

Create a file structure

Copy the Library folder from the RibbonExample to your source codefolder

Base folder

Source code

Library

Page 10: Getting started with the ribbon library for MapBasic

Use your preferred text editor to create a new Mapbasic source code file for your application

Save it to the mbcode folder as type .mb, eg. MyFirstRibbonApp.mb

Insert these lines as a start:

Compile with MapBasic 12.5.1

Create a main source code file (.mb)

Include the RibbonLib header file

Include some MapBasic header files

Will show the new Notification

Page 11: Getting started with the ribbon library for MapBasic

Use your text editor to create a new Mapbasic Project file for your application

Save it to the mbcode folder as type .mbp, eg. MyFirstRibbonApp.mbp

Insert these lines as a start:

Link with MapBasic 12.5.1

Create a MapBasic Project file (.mbp)

Name of final MapBasic application

Compiled libraries to be included

Your compiled module

Page 12: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 13: Getting started with the ribbon library for MapBasic

Adding an EndHandler

To make sure your application tidy up after itself, add an EndHandler to your application

Call the EndHandler of the RibbonLib

Page 14: Getting started with the ribbon library for MapBasic

”How do I create a new Tab and adda Group to it?”

Page 15: Getting started with the ribbon library for MapBasic

Add a new Tab to the Ribbon

1. Check if the Tab already exists2. If not, add it

Adding the new Tab

Does it already exist?

Page 16: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 17: Getting started with the ribbon library for MapBasic

1. Check if the Group already exists2. If not, add it

Add a Group to the Tab

Adding the new Group

Does it already exist?

Page 18: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 19: Getting started with the ribbon library for MapBasic

How do I add a Button to my new Group?

Page 20: Getting started with the ribbon library for MapBasic

Adding a button to a group

First you add a new button to the group

Then you set the look and behaviour of the button, such as caption, tooltips and icon

Modular level arrays

Adding a new button

Defining its look and

behaviour

Getting its Control ID for

later use

Page 21: Getting started with the ribbon library for MapBasic

The handler of the button

This handler is designed to manage several buttons calling it as it determines the ID of the button clicked by the user

Get the ID and calculate

the item number

Now do the work

Requires MAPPERLib

Page 22: Getting started with the ribbon library for MapBasic

Adding the MAPPERLib module

Include the header file in your source code

And include the compiled module in your MapBasic project file

Include MAPPERLib.def

Include MAPPERLib.mbo

Page 23: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 24: Getting started with the ribbon library for MapBasic

Adding multiple buttons

Add more elements to

the arrays

Loop the elements

Page 25: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 26: Getting started with the ribbon library for MapBasic

What about splitbuttons? Can I create these, too?

Page 27: Getting started with the ribbon library for MapBasic

Add a SplitButton with a SplitButtonGroup

I’m adding a new SplitButton control

I’m setting the icon of the SplitButton to match the icons of the first button I’lladd to it later

And I’m setting the handler of the SplitButton to match the handler of the first button, too

Finally I add a SplitButtonGroupAdding the SplitButton

Adding a SplitButtonGroup

Set icons

Set handler

Page 28: Getting started with the ribbon library for MapBasic

Adding buttons to the SplitButtonGroup

And then we add the buttons to the SplitButtonGroup

This is similar to adding buttons to a Group on a Tab

Adding the Buttons

Specify icons,

tooltips and

handlers

ControlID – needed in the handler

Page 29: Getting started with the ribbon library for MapBasic

The handler/subprocedure

The the ID of the control

Did the user use the initial

button or did he select one

from the list?

Page 30: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 31: Getting started with the ribbon library for MapBasic

”How can I easily add the standard buttons to the Tools window?”

Page 32: Getting started with the ribbon library for MapBasic

Tool Manager – Addin procedures

Each tool can publish information

Sub •AddIn_About•AddIn_Help•AddIn_DefaultCommand

Function •AddIn_Name()•AddIn_Description()•AddIn_Version()•AddIn_ImageUri()

Help File Aboutbox End

Description

Version

Image

Name

Default Command

activated thru

double click

Page 33: Getting started with the ribbon library for MapBasic

The ProgramInfo module

These standard subprocedures and functions have been added to the ProgramInfo module

Include the header file for this module in your application module

Include the ProgramInfo.def file

Page 34: Getting started with the ribbon library for MapBasic

Configure the ProgramInfo module

Specify the values for ProgramInfo to use in the dialogs

You can use the functions from ProgramInfo to get to the values, such as the application name via PRGIGetApplicationName()

Specifying values for

ProgramInfo

Use functions from ProgramInfo

to get to the values

Page 35: Getting started with the ribbon library for MapBasic

Include compiled modules in your project

You need to include several extra compiled modules in the MapBasicproject file

Reading/writing configuration files

Managing files and folders

Working with map windows

Aboutbox and programinformation

Handling strings i different languages

Working with strings

Page 36: Getting started with the ribbon library for MapBasic

Run the application in MapInfo Pro x64

Page 37: Getting started with the ribbon library for MapBasic

”Can I use my own images on the buttons?”

Page 38: Getting started with the ribbon library for MapBasic

Using custom images

You can refer to internal MapInfo images, see the MapBasic User Guide, Glossary, List of Embedded images for a list of all images

You can also refer to individual image files on disk, eg. in a sub folder of the application directory

Internal MapInfo image

Image file on disk

Page 39: Getting started with the ribbon library for MapBasic

Defines for Internal images

I have created defines for the internal images of MapInfo Pro 64 bit in a file called MI_ICONS_X64.def.

The file is included in the source code for this sample application in the Library folder and it will also be included with the RibbonLibrary Sample Application later.

Page 40: Getting started with the ribbon library for MapBasic

”Are you sharing the source code for this sample application?”

Page 41: Getting started with the ribbon library for MapBasic

Get the source code for the sample application

I have shared the source code on the Danish Pitney Bowes Software blog.

Get it here:http://blogs.pitneybowes.dk/files/2015/03/MyFirstRibbonApp.zip

Have fun!

Page 42: Getting started with the ribbon library for MapBasic

Questions?

Peter Horsbøll Møller | [email protected]