From c275217c6872e0d8110229a8bf906eb5c1512c1a Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Fri, 30 Apr 2010 22:53:12 +0200 Subject: Make doubly sure the TagPointer is nil. --- src/corelib/fpg_base.pas | 1 + 1 file changed, 1 insertion(+) diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas index 268c05dd..b0c4acee 100644 --- a/src/corelib/fpg_base.pas +++ b/src/corelib/fpg_base.pas @@ -2620,6 +2620,7 @@ begin inherited Create(AOwner); FHelpType := htKeyword; FHelpContext := 0; + FTagPointer := nil; end; end. -- cgit v1.2.3-70-g09d2 From 7d2b89c79d2d59325994e498e89b50fbc61b54f8 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Thu, 6 May 2010 22:15:08 +0200 Subject: New image for Checked menu items. --- images/menu_check_16.bmp | Bin 0 -> 822 bytes src/corelib/fpg_stdimages.pas | 5 ++++ src/corelib/stdimages.inc | 54 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 images/menu_check_16.bmp diff --git a/images/menu_check_16.bmp b/images/menu_check_16.bmp new file mode 100644 index 00000000..7fec8e3c Binary files /dev/null and b/images/menu_check_16.bmp differ diff --git a/src/corelib/fpg_stdimages.pas b/src/corelib/fpg_stdimages.pas index 5c4790c1..2682ce3f 100644 --- a/src/corelib/fpg_stdimages.pas +++ b/src/corelib/fpg_stdimages.pas @@ -149,6 +149,11 @@ begin @stdimg_menu_preferences_16, sizeof(stdimg_menu_preferences_16), 0,0); + fpgImages.AddMaskedBMP( + 'stdimg.check', + @stdimg_menu_check_16, + sizeof(stdimg_menu_check_16), 0,0); + fpgImages.AddMaskedBMP( 'stdimg.document', @stdimg_document, diff --git a/src/corelib/stdimages.inc b/src/corelib/stdimages.inc index ac3597a9..0c880278 100644 --- a/src/corelib/stdimages.inc +++ b/src/corelib/stdimages.inc @@ -2690,3 +2690,57 @@ Const 255,221,223,222,145,149,148,162,166,165,255,255,255,255,255,255,255, 255,255,255,255,255,185,187,186,148,152,150,255,255,255,255,255,255, 255,255,255,255,255,255); + +Const + stdimg_menu_check_16 : Array[0..821] of byte = ( + 66, 77, 54, 3, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, + 0, 16, 0, 0, 0, 16, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0, + 0, 3, 0, 0, 19, 11, 0, 0, 19, 11, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255, 0, 0, 0,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255, 0, 0, 0, 0, 0, 0, + 255, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255, 0, 0, 0,255, 0,255,255, 0,255, + 255, 0,255, 0, 0, 0, 0, 0, 0, 0, 0, 0,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255, 0, 0, 0, 0, 0, 0,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255, 0, 0, 0,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0, + 255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, + 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255,255, 0,255, + 255, 0,255,255, 0,255); + + -- cgit v1.2.3-70-g09d2 From fdcf31f5c1a38dd4b10a53149bd708b037f6db96 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Fri, 7 May 2010 00:58:40 +0200 Subject: Popup Menu now paints the Checkmark when a MenuItem.Checked = True. * Thanks to JP Anghel for the initial patch. * I added some mods by replacing magic numbers with a constant. * I also removed some old commented code. --- src/gui/fpg_menu.pas | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/src/gui/fpg_menu.pas b/src/gui/fpg_menu.pas index dbe92d50..3d972756 100644 --- a/src/gui/fpg_menu.pas +++ b/src/gui/fpg_menu.pas @@ -77,7 +77,7 @@ type procedure Click; function Selectable: boolean; function GetAccelChar: string; - procedure DrawText(ACanvas: TfpgCanvas; x, y: TfpgCoord); + procedure DrawText(ACanvas: TfpgCanvas; x, y: TfpgCoord; const AImgWidth: integer); function GetCommand: ICommand; procedure SetCommand(ACommand: ICommand); property Checked: boolean read FChecked write SetChecked; @@ -160,6 +160,7 @@ type procedure PrepareToShow; function VisibleCount: integer; function VisibleItem(ind: integer): TfpgMenuItem; + procedure HandleShow; override; procedure HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); override; procedure HandleLMouseDown(x, y: integer; shiftstate: TShiftState); override; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed: boolean); override; @@ -186,10 +187,14 @@ function CreateMenuBar(AOwner: TfpgWidget): TfpgMenuBar; overload; implementation - + var uFocusedPopupMenu: TfpgPopupMenu; +const + cImgWidth: integer = 16; + + function CreateMenuBar(AOwner: TfpgWidget; x, y, w, h: TfpgCoord): TfpgMenuBar; begin if AOwner = nil then @@ -258,6 +263,7 @@ begin FSeparator := False; FVisible := True; FEnabled := True; + FChecked := False; FSubMenu := nil; FOnClick := nil; end; @@ -286,11 +292,12 @@ begin Result := ''; end; -procedure TfpgMenuItem.DrawText(ACanvas: TfpgCanvas; x, y: TfpgCoord); +procedure TfpgMenuItem.DrawText(ACanvas: TfpgCanvas; x, y: TfpgCoord; const AImgWidth: integer); var s: string; p: integer; achar: string; + img: TfpgImage; begin if not Enabled then ACanvas.SetFont(fpgStyle.MenuDisabledFont) @@ -300,19 +307,23 @@ begin achar := '&'; s := Text; + if Checked then + begin + img := fpgImages.GetImage('stdimg.check'); // Do NOT localize + ACanvas.DrawImage(x-AImgWidth-2, y, img); // 2 = margin. + end; + repeat p := UTF8Pos(achar, s); if p > 0 then begin // first part of text before the & sign -// ACanvas.DrawString(x, y, UTF8Copy(s, 1, p-1)); fpgStyle.DrawString(ACanvas, x, y, UTF8Copy(s, 1, p-1), Enabled); inc(x, fpgStyle.MenuFont.TextWidth(UTF8Copy(s, 1, p-1))); if UTF8Copy(s, p+1, 1) = achar then begin // Do we need to paint a actual & sign (create via && in item text) -// ACanvas.DrawString(x, y, achar); fpgStyle.DrawString(ACanvas, x, y, achar, Enabled); inc(x, fpgStyle.MenuFont.TextWidth(achar)); end @@ -321,7 +332,6 @@ begin // Draw the HotKey text if Enabled then ACanvas.SetFont(fpgStyle.MenuAccelFont); -// ACanvas.DrawString(x, y, UTF8Copy(s, p+1, 1)); fpgStyle.DrawString(ACanvas, x, y, UTF8Copy(s, p+1, 1), Enabled); inc(x, ACanvas.Font.TextWidth(UTF8Copy(s, p+1, 1))); if Enabled then @@ -333,7 +343,6 @@ begin // Draw the remaining text after the & sign if UTF8Length(s) > 0 then -// ACanvas.DrawString(x, y, s); fpgStyle.DrawString(ACanvas, x, y, s, Enabled); end; @@ -391,6 +400,12 @@ begin Result := TfpgMenuItem(FItems.Items[ind]); end; +procedure TfpgMenuBar.HandleShow; +begin + PrepareToShow; + inherited HandleShow; +end; + procedure TfpgMenuBar.HandleMouseMove(x, y: integer; btnstate: word; shiftstate: TShiftState); var newf: integer; @@ -497,7 +512,6 @@ var n: integer; r: TfpgRect; begin - PrepareToShow; Canvas.BeginDraw; inherited HandlePaint; r.SetRect(0, 0, Width, Height); @@ -590,7 +604,7 @@ begin Canvas.FillRectangle(r); // a possible future theme option // Canvas.GradientFill(r, FLightColor, FDarkColor, gdVertical); - mi.DrawText(Canvas, r.left+4, r.top+1); + mi.DrawText(Canvas, r.left+4, r.top+1, cImgWidth); Canvas.EndDraw(r.Left, r.Top, r.Width, r.Height); Exit; //==> end; { if col=n } @@ -829,7 +843,6 @@ procedure TfpgPopupMenu.HandleLMouseUp(x, y: integer; shiftstate: TShiftState); var newf: integer; mi: TfpgMenuItem; - r: TfpgRect; begin inherited HandleLMouseUp(x, y, shiftstate); @@ -1025,25 +1038,20 @@ begin else begin x := rect.Left + FSymbolWidth + FTextMargin; - - mi.DrawText(Canvas, x, rect.top); + mi.DrawText(Canvas, x+cImgWidth, rect.top, cImgWidth); if mi.HotKeyDef <> '' then begin s := mi.HotKeyDef; fpgStyle.DrawString(Canvas, rect.Right-FMenuFont.TextWidth(s)-FTextMargin, rect.Top, s, mi.Enabled); -// Canvas.DrawString(rect.Right-FMenuFont.TextWidth(s)-FTextMargin, rect.Top, s); end; if mi.SubMenu <> nil then begin - canvas.SetColor(Canvas.TextColor); + Canvas.SetColor(Canvas.TextColor); x := (rect.height div 2) - 3; img := fpgImages.GetImage('sys.sb.right'); Canvas.DrawImage(rect.right-x-2, rect.Top + ((rect.Height-img.Height) div 2), img); -// canvas.FillTriangle(rect.right-x-2, rect.top+2, -// rect.right-2, rect.top+2+x, -// rect.right-x-2, rect.top+2+2*x); end; end; end; @@ -1205,8 +1213,8 @@ begin hkw := hkw + 10; // spacing between text and hotkey text FHeight := FMargin*2 + h; - FWidth := (FMargin+FTextMargin)*2 + FSymbolWidth + tw + hkw; - + FWidth := (FMargin+FTextMargin)*2 + FSymbolWidth + tw + hkw + cImgWidth; + uFocusedPopupMenu := self; end; -- cgit v1.2.3-70-g09d2 From 99f194504f3306189d6658fc0ef10a757ea054e9 Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Fri, 7 May 2010 01:00:47 +0200 Subject: Updated MenuTest demo * Reworked the code so the UI is managed by the UI Forms Designer * Added a new View menu with checkitem menus. * Added Toolbar and Statusbar to give basic visual effect when menu check items are toggled. * Added a Memo used as a Log output window. --- examples/gui/menutest/menutest.lpi | 10 +- examples/gui/menutest/menutest.lpr | 267 ++++++++++++++++++++++++++++++++----- 2 files changed, 241 insertions(+), 36 deletions(-) diff --git a/examples/gui/menutest/menutest.lpi b/examples/gui/menutest/menutest.lpi index f3d307af..96e0dc63 100644 --- a/examples/gui/menutest/menutest.lpi +++ b/examples/gui/menutest/menutest.lpi @@ -1,15 +1,14 @@ - - + + - @@ -45,6 +44,11 @@ + + + + +