$INCLUDE "rapidq2.inc"
$ESCAPECHARS ON
$APPTYPE GUI
$TYPECHECK ON
APPLICATION.TITLE = "MenuDesigner"
$RESOURCE MenuDesigner_ico AS "c:\rapidq\ide\freeq\_res\FreeQ.ico"
$RESOURCE ARW06LT_bmp AS "Bitmaps\ARW06LT.bmp"
$RESOURCE ARW06RT_bmp AS "Bitmaps\ARW06RT.bmp"
$RESOURCE ARW06DN_bmp AS "Bitmaps\ARW06DN.bmp"
$RESOURCE ARW06UP_bmp AS "Bitmaps\ARW06UP.bmp"
$RESOURCE preview_bmp AS "Bitmaps\Preview.bmp"
$RESOURCE Menu_bmp AS "Bitmaps\MenuDesigner.bmp"
$RESOURCE New_bmp AS "Bitmaps\New.bmp"
$RESOURCE Open_bmp AS "Bitmaps\Open.bmp"
$RESOURCE Save_bmp AS "Bitmaps\Save.bmp"
$RESOURCE Options_bmp AS "Bitmaps\Options.bmp"
$RESOURCE Help_bmp AS "Bitmaps\Help.bmp"
$RESOURCE Exit_bmp AS "Bitmaps\Exit.bmp"
$INCLUDE <QINI.INC>
$INCLUDE <QXPButton.INC>
$INCLUDE "APIs.inc"
$INCLUDE "MenuDesignerDecl.inc"
$INCLUDE "MenuDesignerGlobals.inc"
$INCLUDE "frmPreview.bas"
$INCLUDE "frmMain.bas"
$INCLUDE "frmAbout.bas"
$INCLUDE "frmOptions.bas"
$INCLUDE "MenudesignerXPButtons.inc"
Inicialize
frmMain.SHOWMODAL
SUB Inicialize
Indice = 0 : Level = 0 : maxItem = 0 : CaptionStr = "" :
Archivo = "$NoName.mnu" : ArchivoMenu = "$NoName.inc"
Saved = FALSE
SetFocus(txtCaption.Handle)
myIni.Filename = Application.Path + "\\MenuDesigner.ini"
GetDefaults
END SUB
SUB GetDefaults
DIM KeyLanguage AS STRING
DIM TempStr AS STRING
DIM a AS SINGLE
IF FILEEXISTS(szFile) THEN
myIni.Section = "Defaults"
chkChecked.Checked = VAL(myIni.GET("Checked" , "0"))
chkOptChecked.Checked = chkChecked.Checked
chkEnabled.Checked = VAL(myIni.GET("Enabled" , "0"))
chkOptEnabled.Checked = chkEnabled.Checked
chkVisible.Checked = VAL(myIni.GET("Visible" , "0"))
chkOptVisible.Checked = chkVisible.Checked
txtWorkFolder.Text = myIni.GET("WorkFolder" , CURDIR$)
CHDIR txtWorkFolder.Text
Language = myIni.GET("Language" , "1")
myIni.Section = "Languages"
Languages = VAL(myIni.GET("Languages" , "1"))
cmbOptLanguage.Clear
FOR a = 1 TO Languages
TempStr = "Language" + STR$(LTRIM$(RTRIM$(a)))
KeyLanguage = myIni.GET(TempStr , "English")
cmbOptLanguage.InsertItem a - 1 , KeyLanguage
NEXT
cmbOptLanguage.ItemIndex = VAL(Language) - 1
TempStr = "Language" + Language
KeyLanguage = myIni.GET(TempStr , "English")
myIni.Section = KeyLanguage
mnuFile.CAPTION = myIni.GET("File" , "&File")
mnuFileNew.CAPTION = myIni.GET("New" , "&New")
mnuFileOpen.CAPTION = myIni.GET("Open" , "&Open")
mnuFileSave.CAPTION = myIni.GET("Save" , "&Save")
mnuFileSaveAs.CAPTION = myIni.GET("SaveAs" , "Sa&ve as")
mnuFileExit.CAPTION = myIni.GET("Exit" , "&Exit")
mnuView.CAPTION = myIni.GET("View" , "&View")
mnuViewOptions.CAPTION = myIni.GET("Options" , "&Options")
mnuViewTBar.CAPTION = myIni.GET("ToolBar" , "&ToolBar")
mnuHelp.CAPTION = myIni.GET("Help" , "&Help")
mnuHelpAbout.CAPTION = myIni.GET("About" , "&About")
cmdNew.Hint = myIni.GET("bNew" , "New")
cmdOpen.Hint = myIni.GET("bOpen" , "Open")
cmdSave.Hint = myIni.GET("bSave" , "Save")
cmdHelp.Hint = myIni.GET("bHelp" , "Help")
cmdExit.Hint = myIni.GET("bExit" , "Exit")
lblCaption.CAPTION = myIni.GET("lblCaption" , "Ca&ption:")
lblName.CAPTION = myIni.GET("lblName" , "Na&me")
chkChecked.CAPTION = myIni.GET("CChecked" , "&Checked")
chkEnabled.CAPTION = myIni.GET("CEnabled" , "&Enabled")
chkVisible.CAPTION = myIni.GET("CVisible" , "&Visible")
LblShortCut.CAPTION = myIni.GET("lblShortCut" , "&ShortCut")
cmdNext.CAPTION = myIni.GET("Next" , "&Next")
cmdInsert.CAPTION = myIni.GET("Insert" , "&Insert")
cmdDelete.CAPTION = myIni.GET("Delete" , "&Delete")
cmdPreview.CAPTION = myIni.GET("Preview" , "Previe&w")
stgItems.Cell(0 , 0) = myIni.GET("Properties" , "Properties")
stgItems.Cell(0 , 1) = myIni.GET("Name" , "Name")
stgItems.Cell(0 , 2) = myIni.GET("Caption" , "Caption")
stgItems.Cell(0 , 3) = myIni.GET("Checked" , "Checked")
stgItems.Cell(0 , 4) = myIni.GET("Enabled" , "Enabled")
stgItems.Cell(0 , 5) = myIni.GET("Visible" , "Visible")
stgItems.Cell(0 , 6) = myIni.GET("ShortCut" , "ShortCut")
stgItems.Cell(0 , 7) = myIni.GET("Level" , "Level")
cmdSaveCode.CAPTION = myIni.GET("bSaveCode" , "&Save Code")
cmdCopyCode.CAPTION = myIni.GET("bCopyCode" , "&Copy Code")
cmdClosePreview.CAPTION = myIni.GET("bClosePreview" , "C&lose Preview")
myIni.Section = "Defaults"
chkOptPreDeclares.Checked = VAL(myIni.GET("PreDeclare" , "0"))
chkOptDeclares.Checked = VAL(myIni.GET("Declares" , "1"))
chkOptOnlyMenu.Checked = VAL(myIni.GET("OnlyMenu" , "0"))
chkOptHardTabs.Checked = VAL(myIni.GET("HardTabs" , "1"))
chkOptSoftTabs.Checked = VAL(myIni.GET("SoftTabs" , "0"))
txtOptSpaces.Text = (myIni.GET("Spaces" , "3"))
txtOptSpaces.Enabled = FALSE
IF chkOptSoftTabs.Checked THEN txtOptSpaces.Enabled = TRUE
END IF
END SUB
SUB SetDefaults
myIni.Section = "Defaults"
myIni.Write("Checked" , STR$(LTRIM$(RTRIM$(chkOptChecked.Checked))))
myIni.Write("Enabled" , STR$(LTRIM$(RTRIM$(chkOptChecked.Enabled))))
myIni.Write("Visible" , STR$(LTRIM$(RTRIM$(chkOptChecked.Visible))))
myIni.Write("WorkFolder" , txtWorkFolder.Text)
myIni.Write("Language" , STR$(LTRIM$(RTRIM$(cmbOptLanguage.ItemIndex + 1))))
myIni.Write("PreDeclare" , STR$(LTRIM$(RTRIM$(chkOptPreDeclares.Checked))))
myIni.Write("Declares" , STR$(LTRIM$(RTRIM$(chkOptDeclares.Checked))))
myIni.Write("OnlyMenu" , STR$(LTRIM$(RTRIM$(chkOptOnlyMenu.Checked))))
myIni.Write("HardTabs" , STR$(LTRIM$(RTRIM$(chkOptHardTabs.Checked))))
myIni.Write("SoftTabs" , STR$(LTRIM$(RTRIM$(chkOptSoftTabs.Checked))))
myIni.Write("Spaces" , txtOptSpaces.Text)
GetDefaults
END SUB
SUB NewMenu
SetFocus(txtCaption.Handle)
Indice = 0 : Level = 0 : maxItem = 0
CaptionStr = "" : Archivo = "$NoName.mnu"
WITH stgItems
.ColCount = 2
.InsertCol(1)
.deleteCol(2)
END WITH
NewItem
WITH lstItems
.Clear
.AddItems = ""
.ItemIndex = Indice
END WITH
END SUB
SUB FileOpen
SetFocus(txtCaption.Handle)
OpenDialog.FileName = ""
IF OpenDialog.EXECUTE THEN
DIM ArchivoStrLine AS STRING
DIM File AS QFILESTREAM
DIM Count% AS SINGLE
DIM p AS SINGLE
Archivo = OpenDialog.FileName
p = rinstr(Archivo , "\\")
Archivo = MID$(OpenDialog.FileName , p + 1)
File.OPEN(Archivo , fmOpenRead)
ArchivoStrLine = File.ReadLine
File.CLOSE
Count% = TALLY(ArchivoStrLine , ",")
stgItems.ColCount = Count% + 1
stgItems.LoadFromFile Archivo , 1 , 1 , 7
lstItems.Clear
DIM a% AS SINGLE
FOR a% = 0 TO Count% - 1
stgItems.Cell(a% + 1 , 0) = "Values"
Level = VAL(stgItems.Cell(a% + 1 , 7))
lstItems.AddItems = ""
lstItems.Item(a%) = STRING$(Level , "=") + stgItems.Cell(a% + 1 , 2)
NEXT
Indice = 0
Level = VAL(stgItems.Cell(1 , 7))
lstItems.ItemIndex = Indice
WriteFields
frmMain.CAPTION = "MenuDesigner " + Archivo
END IF
END SUB
SUB SaveMenu
SetFocus(txtCaption.Handle)
IF Archivo <> "$NoName.mnu" THEN
stgItems.SaveToFile Archivo , 1 , 1 , 7
SHOWMESSAGE Archivo + " Saved"
Saved = TRUE
ELSE
SaveAs
END IF
END SUB
SUB SaveAs
SetFocus(txtCaption.Handle)
DIM ext$ AS STRING
SaveDialog.CAPTION = "Save Menu Template as..."
SaveDialog.Filter = "Menu Template (*.mnu)|*.mnu|All Files (*.*)|*.*"
IF Archivo <> "$NoName.mnu" THEN
SaveDialog.FileName = Archivo
ELSE
SaveDialog.FileName = "$NoName.mnu"
END IF
IF SaveDialog.EXECUTE THEN
Archivo = SaveDialog.FileName
ext$ = RIGHT$(Archivo , 4)
IF ext$ <> ".mnu" THEN Archivo = Archivo + ".mnu"
stgItems.SaveToFile Archivo , 1 , 1 , 7
DIM p AS SINGLE
p = rinstr(Archivo , "\\")
Archivo = MID$(Archivo , p + 1)
frmMain.CAPTION = "MenuDesigner " + Archivo
SHOWMESSAGE Archivo + " Saved"
Saved = TRUE
END IF
END SUB
SUB Options
SetFocus(txtCaption.Handle)
frmOptions.SHOWMODAL
END SUB
SUB About
SetFocus(txtCaption.Handle)
frmAbout.SHOWMODAL
END SUB
SUB ExitProgram
DIM Message AS STRING
Message = "If you have made changes to this menu." + cr + "Would you like save them?"
IF MESSAGEDLG(Message , mtWarning , mbYes OR mbNo , 0) = mrNo THEN
frmMain.CLOSE
ELSE
SaveMenu
IF Saved THEN frmMain.CLOSE
END IF
END SUB
FUNCTION ValidateMenu() AS INTEGER
DIM oldLevel AS INTEGER
DIM ActualLevel AS INTEGER
DIM Faild AS INTEGER
DIM a% AS SINGLE
oldLevel = VAL(stgItems.Cell(1 , 7))
IF oldLevel > 0 THEN
SHOWMESSAGE "Menu jump a Level"
Indice = 0
WriteFields
lstItems.ItemIndex = Indice
ValidateMenu = FALSE
EXIT FUNCTION
END IF
maxItem = stgItems.ColCount - 1
FOR a% = 1 TO maxItem
IF stgItems.Cell(a% , 1) = "" THEN
SHOWMESSAGE "Name is necesary"
Faild = TRUE
EXIT FOR
END IF
IF stgItems.Cell(a% , 2) = "" THEN
SHOWMESSAGE "Caption is necesary"
Faild = TRUE
EXIT FOR
END IF
ActualLevel = VAL(stgItems.Cell(a% , 7))
IF ActualLevel = 0 THEN
IF VAL(stgItems.Cell(a% , 6)) THEN
SHOWMESSAGE "This Item canŽt have ShortCut"
Faild = TRUE
EXIT FOR
END IF
IF VAL(stgItems.Cell(a% , 3)) THEN
SHOWMESSAGE "This Item canŽt set Checked"
Faild = TRUE
EXIT FOR
END IF
END IF
IF ActualLevel > oldLevel + 1 THEN
SHOWMESSAGE "Menu jump a Level"
Faild = TRUE
EXIT FOR
ELSE
oldLevel = ActualLevel
END IF
NEXT
IF Faild THEN
Indice = a% - 1
WriteFields
lstItems.ItemIndex = Indice
ValidateMenu = FALSE
ELSE
ValidateMenu = TRUE
END IF
END SUB
SUB WriteFields
Level = VAL(stgItems.Cell(Indice + 1 , 7))
txtName.Text = stgItems.Cell(Indice + 1 , 1)
txtCaption.Text = stgItems.Cell(Indice + 1 , 2)
chkChecked.Checked = VAL(stgItems.Cell(Indice + 1 , 3))
chkEnabled.Checked = VAL(stgItems.Cell(Indice + 1 , 4))
chkVisible.Checked = VAL(stgItems.Cell(Indice + 1 , 5))
cmbShortCut.ItemIndex = VAL(stgItems.Cell(Indice + 1 , 6))
stgItems.Row = 0 : stgItems.Col = 0
stgItems.LeftCol = Indice + 1
END SUB
SUB NewItem
DIM DefaultStr AS STRING
stgItems.Cell(Indice + 1 , 0) = "Values" : stgItems.Col = 0 : stgItems.Row = 0
txtCaption.Text = "" : txtName.Text = ""
chkChecked.Checked = chkOptChecked.Checked
chkEnabled.Checked = chkOptEnabled.Checked
chkVisible.Checked = chkOptVisible.Checked
cmbShortCut.ItemIndex = 0
WITH stgItems
.Cell(Indice + 1 , 1) = ""
.Cell(Indice + 1 , 2) = ""
IF chkChecked.Checked THEN DefaultStr = "1 -True" ELSE DefaultStr = "0 -False"
.Cell(Indice + 1 , 3) = DefaultStr
IF chkEnabled.Checked THEN DefaultStr = "1 -True" ELSE DefaultStr = "0 -False"
.Cell(Indice + 1 , 4) = DefaultStr
IF chkVisible.Checked THEN DefaultStr = "1 -True" ELSE DefaultStr = "0 -False"
.Cell(Indice + 1 , 5) = DefaultStr
.Cell(Indice + 1 , 6) = "0 -(None)"
.Cell(Indice + 1 , 7) = STR$(Level)
END WITH
END SUB
SUB MadePreviewMenu
DIM hMenu AS LONG , hSubMenu AS LONG
DIM count AS LONG
DIM retval AS LONG
DIM dwTD AS STRING
DIM s AS LONG , f AS SINGLE , g AS SINGLE
DIM Level AS SINGLE , nextLevel AS SINGLE , BackLevel AS SINGLE
DIM hd(1 TO stgItems.ColCount) AS LONG , HdParent AS LONG
DIM shCut$ AS STRING
hMenu = GetMenu(frmPreview.Handle)
IF hMenu <> 0 THEN
DestroyMenu hMenu
END IF
hMenu = CreateMenu
SetMenu frmPreview.Handle , hMenu
hd(1) = hMenu
mii.cbSize = SIZEOF(mii)
FOR s = 1 TO stgItems.ColCount - 1
Level = VAL(stgItems.Cell(s , 7))
nextLevel = VAL(stgItems.Cell(s + 1 , 7))
HdParent = hd(s)
WITH mii
.fType = MFT_STRING
IF stgItems.Cell(s , 2) = "-" THEN .fType = .fType OR MFT_SEPARATOR
IF VAL(stgItems.Cell(s , 5)) THEN
.fState = MFS_ENABLED
ELSE
.fState = MFS_DISABLED OR MFT_MENUBREAK
END IF
IF VAL(stgItems.Cell(s , 3)) THEN .fState = .fState OR MFS_CHECKED
IF (VAL(stgItems.Cell(s , 4))) = 0 THEN .fState = .fState OR MFS_GRAYED
.wID = s
shCut$ = stgItems.Cell(s , 6)
IF VAL(shCut$) > 0 THEN
g = INSTR(shCut$ , "-")
shCut$ = MID$(shCut$ , g + 1 , LEN(shCut$))
dwTD = stgItems.Cell(s , 2) + CHR$(9) + shCut$
ELSE
dwTD = stgItems.Cell(s , 2)
END IF
.dwTypeData = VARPTR(dwTD)
.cch = LEN(dwTD)
IF nextLevel > Level THEN
hSubMenu = CreatePopUpMenu
.fMask = MIIM_STATE OR MIIM_ID OR MIIM_TYPE OR MIIM_SUBMENU
.hSubMenu = hSubMenu
hd(s + 1) = hSubMenu
ELSEIF nextLevel = Level THEN
.fMask = MIIM_STATE OR MIIM_ID OR MIIM_TYPE
.hSubMenu = 0
hd(s + 1) = hd(s)
ELSEIF nextLevel < Level THEN
FOR f = s - 1 TO 1 STEP - 1
BackLevel = VAL(stgItems.Cell(f , 7))
IF BackLevel = < nextLevel THEN
.fMask = MIIM_STATE OR MIIM_ID OR MIIM_TYPE
.hSubMenu = 0
hd(s + 1) = hd(f)
EXIT FOR
END IF
NEXT
END IF
END WITH
count = GetMenuItemCount(HdParent)
retval = InsertMenuItem(HdParent , count , 1 , mii)
NEXT
retval = DrawMenuBar(frmPreview.Handle)
END SUB
SUB WriteCode
DIM s AS INTEGER , b AS INTEGER
DIM ctab1 AS STRING , ctab2 AS STRING
DIM cre AS STRING
DIM Jtext AS STRING
DIM ocli AS STRING , cli AS STRING , ccli AS STRING
DIM oldLevel AS SINGLE , nextLevel AS SINGLE
DIM shCut$ AS STRING
DIM g AS SINGLE , SelTemp AS LONG
DIM N AS LONG
DIM declares AS STRING , subs AS STRING
DIM Coment AS STRING , Procedure AS INTEGER
DIM Tabu AS STRING
cre = "CREATE " : Jtext = "END " + cre
ocli = "onclick = " : cli = "_Click"
Procedure = TRUE
IF chkOptPreDeclares.Checked THEN Coment = "'"
IF chkOptDeclares.Checked THEN Coment = ""
IF chkOptOnlyMenu.Checked THEN Procedure = FALSE
IF chkOptSoftTabs.Checked THEN Tabu = SPACE$(VAL(txtOptSpaces.Text))
rhtCode.Clear
rhtCode.AddString cre + "mnuMain as QMAINMENU"
rhtCode.AddString Tabu + "'Parent = Form"
oldLevel = - 1
stgItems.Cell(stgItems.ColCount , 7) = 0
FOR s = 1 TO stgItems.ColCount - 1
Level = VAL(stgItems.Cell(s , 7))
nextLevel = VAL(stgItems.Cell(s + 1 , 7))
ctab1 = "" : ctab2 = ""
ctab1 = STRING$(Level + 1 , "\t")
ctab2 = STRING$(Level + 2 , "\t")
IF chkOptSoftTabs.Checked THEN
ctab1 = REPLACESUBSTR$(ctab1 , "\t" , Tabu)
ctab2 = REPLACESUBSTR$(ctab2 , "\t" , Tabu)
END IF
WITH rhtCode
.AddString ctab1 + cre + stgItems.Cell(s , 1) + " as QMENUITEM "
.AddString ctab2 + "Caption = \"" + stgItems.Cell(s,2) + " \ ""
.AddString ctab2 + "Checked = " + STR$(VAL(stgItems.Cell(s , 3)))
.AddString ctab2 + "Enabled = " + STR$(VAL(stgItems.Cell(s , 4)))
.AddString ctab2 + "Visible = " + STR$(VAL(stgItems.Cell(s , 5)))
shCut$ = stgItems.Cell(s , 6)
IF VAL(shCut$) > 0 THEN
g = INSTR(shCut$ , "-")
shCut$ = MID$(shCut$ , g + 1 , LEN(shCut$))
.AddString ctab2 + "ShortCut = \"" + ShCut$ + " \ ""
END IF
IF Level = nextLevel THEN
IF stgItems.Cell(s , 2) <> "-" THEN
IF Procedure THEN
ccli = stgItems.Cell(s , 1) + cli
.AddString ctab2 + Coment + ocli + ccli
declares = declares + Coment + "DECLARE SUB " + ccli + " (Sender AS QMENUITEM)" + cr
END IF
END IF
.AddString ctab1 + Jtext
END IF
IF Level > nextLevel THEN
IF stgItems.Cell(s , 2) <> "-" THEN
IF Procedure THEN
ccli = stgItems.Cell(s , 1) + cli
.AddString ctab2 + Coment + ocli + ccli
declares = declares + Coment + "DECLARE SUB " + ccli + " (Sender AS QMENUITEM)" + cr
END IF
END IF
FOR b = Level TO nextLevel STEP - 1
ctab1 = STRING$(b + 1 , "\"t)
IF chkOptSoftTabs.Checked THEN
ctab1 = REPLACESUBSTR$(ctab1 , "\"t , Tabu)
END IF
.AddString ctab1 + Jtext
NEXT
END IF
END WITH
NEXT
WITH rhtCode
.AddString Jtext
IF Procedure THEN
SelTemp = .SelStart
.SelStart = 0
.SelLength = 0
.SelText = declares + cr
.SelStart = SelTemp
.AddString
N = INSTR(declares , " SUB ")
WHILE N > 0
subs = Coment + MID$(declares , N + 1 , INSTR(N + 1 , declares , cr) - N - 1)
.AddString subs
.AddString Coment + "END "SUB
.AddString
N = INSTR(N + 1 , declares , " SUB ")
WEND
END IF
.SelStart = 0
.HiLight
.PlainText = TRUE
.ReadOnly = 1
END WITH
END SUB
SUB gotoweb
END SUB
SUB sendemail
END SUB
|
|